# increment figure source names

In our childhood, probably all of us made some drawings on layered sheets of paper in order to make an animation.

[edit: This is to be added to an existing document, next to the page number for example.]

To do such an page-by-page animation in a LaTeX document of 123 pages (e.g.), I would like to include images named from "image001" to "image123" in successive pages, so that:

• page 1 includes "image001"

• page 2 includes "image002"

• ...

• page 123 includes "image123".

A way to do this is would be to use a command of the form:

\includegraphics[]{\BASENAME + \PAGENUMBER + \INCREMENT}

% \BASENAME: path of folder + beginning of name
% \PAGENUMBER: page number
% \INCREMENT: number of the first page to have an image (minus one)


but I do not know how to implement such a feature.

-

Use a whiledo-loop:

\documentclass{article}
\usepackage[demo]{graphicx} %remove if you have the images
\usepackage{ifthen}
\begin{document}
\newcommand\increment{1}
\whiledo{\increment < 50}
{Image \ifnum\increment<10 0\fi\increment:
\includegraphics{image\ifnum\increment<10 0\fi\increment}\newpage
\edef\increment{\the\numexpr\increment +1}%
}

\end{document}

-
Thank you. I might no have been clear enough: I would like to add the images in an existing document, for example next to the page number. Your suggestion creates a new page for each figure. But your answer helped me understand the structure I should use. I will probably post a solution soon. – anderstood Aug 23 '13 at 8:23
@anderstood: If the graphic is in the header or footer definition something like \includegraphics{image\arabic{page}} should work (you perhaps need some additional code to handle leading zeros). – Ulrike Fischer Aug 23 '13 at 8:29
@Ultrike Fischer: I'd like to post my solution, based on your answer. How can I do this without not accepting your solution ? – anderstood Aug 23 '13 at 8:42
@anderstood: You can edit your question. Or write a answer. – Ulrike Fischer Aug 23 '13 at 8:45

There might be simpler solutions, but it is possible to add a sequence of images in the header doing so:

\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[nomessages]{fp}

\newcommand{\startImageNum}{15} % first included image is image15
\newcommand{\fileExtNumDef}{\FPeval\fileExtNum{round(\thepage + \startImageNum:0)}}