Graphics, Figures & Tablesloading images in a for loop

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
StevoSn
Posts: 4
Joined: Wed Jul 07, 2010 1:33 pm

loading images in a for loop

Post by StevoSn »

Hey!
I am wondering if there's a way to use \includegraphics[]{} within a for loop. Is there actually a thing like a for loop in latex? I have quite a lot of images in a folder called 01.eps, 02.eps and so on, and want the "script" to put the images on paper.

here's a little scratch of what I mean:

\for i=1 to 10
\includegraphic[scale=0.5]{'\folder\'+int2str(i)+'eps'}
\end

is there a way to do this. I am not sure if latex can handle string manipulation.
thanks for help!!
cheers!
Stevo

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

dyama
Posts: 1
Joined: Wed Jul 07, 2010 6:37 pm

Re: loading images in a for loop

Post by dyama »

Try something like the following... I've shown pdf as the file extension. The 0 in front of argument #1 is to differentiate '01.pdf' from '1.pdf'.
Dirk

\documentclass{article}
\usepackage{ifthen}
\usepackage{graphicx}

\newcommand\addfigure[1]{\includegraphics[scale=0.5]{0#1.pdf}\\}
\begin{document}
\newcounter{count}\setcounter{count}{1}
\whiledo{\value{count}<11}{\addfigure{\thecount}\addtocounter{count}{1}}
\end{document}
StevoSn
Posts: 4
Joined: Wed Jul 07, 2010 1:33 pm

Re: loading images in a for loop

Post by StevoSn »

Hey!
Thanks a lot for this! The loop seems to work, but Latex has problems with finding the pictures, somehow.. it also puts figures of files that do not exist.. well I guess I can use if-then-else for this.. do you know how to handle error massages?
Do I ask too much from Latex? Is there a way to write a C or Python script that handles all the programming stuff and let Latex do what's made for - format my pdfs..?
Cheers!
Stevo
Post Reply