# How can I create copies of a document with a running number?

I am making a questionnaire, to be filled out with pen and paper. I need 40 copies of it, with around 13 pages each. I expect that some participants might take the questionnaire apart, so I have to be able to match the pages from an exemplar to each other. I want to do it in a simple way, by printing a number from 1 to 40 in the footer of each copy.

However, I don't know how to generate different copies from the same TeX source, and I don't want to manually compile 40 times, changing the number each time. I decided to put everything between \begin{document} and \end{document} in a \foreach loop from pgffor, using a counter to print the number in the footer. This produces the 40 copies I need in a single document (not a problem from my point of view), but of course, this changes the page numbering, so the second exemplar starts at page 14 instead of page 1. As the page number is printed in the footer too, this is unacceptable.

Because I am still making some changes to the questionnaire, I might suddenly find myself with 12 or 14 pages. So, taking the page number modulo 13 for printing in the footer is a bad idea.

Any ideas how to make this work? Or will I have to fall back to the hardcoded modulo and just manually change the number if needed? I will prefer it to be really from inside LaTeX, not a script which changes the number in the .tex file and recompiles (I have to compile on different OSes). I don't care if I end up with one very long .pdf or forty small ones, as long as it isn't the same .pdf overwritten forty times.

\documentclass[a4paper,12pt]{article}

\usepackage{pgffor}
\usepackage{fancyhdr}

\newcounter{questionnaireNr}
\setcounter{questionnaireNr}{0}
\pagestyle{fancy}
\fancyfoot[C]{Questionnaire \arabic{questionnaireNr}}
\fancyfoot[R]{page \thepage}

\begin{document}
\foreach \x in {1,2,3,...40}
{
\stepcounter{questionnaireNr}

Lorem Ipsum %here are the questions
}
\end{document}

-
You can just reset the page counter in every loop, \setcounter{page}{1} is your friend! –  zeroth Mar 13 '12 at 13:56

In the start of your \foreach, add
\newpage