# Empty document, only pagenumber, 500 pages needed

I need a document with 500 empty pages, only the pagenumbering in the foot of the page.

This MWE shows 2 pages in the way I'd like to get all 500:

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\begin{document}
\mbox{}

\newpage

\mbox{}
\newpage

\end{document}


Can somebody write e.g. a loop for 500 pages? Cave: the \mbox{} is necessary, otherwise there is no pagenumber or even a PDF of 0 pages...

(The purpose is to add pagenumbers to an already printed document: I'll put the 500 pages again into the printer and thus get a printed document with pagenumbers. I'm trying to help a poor guy here who otherwise had to write the pagenumbers manually into 40 folders à 500 pages.)

• \count0=500 \loop\ifnum\count0>0 \null\clearpage\advance\count0 by -1 \repeat (done from memory, not sure if it works) Jul 5 '16 at 11:31
• This question would have been even more awesome if you had simply refused to explain yourself. "Trust me. Never mind why I need it.".
– pipe
Jul 6 '16 at 2:08

Use a primitive \loop with \repeat and \unless testing.

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\newcounter{loopcntr}

\begin{document}
\loop\unless\ifnum\value{loopcntr}=500
\mbox{}
\newpage
\repeat

\end{document}


Here's a variant with pgffor and forloop packages:

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\usepackage{pgffor}
\usepackage{forloop}

\newcounter{loopcntr}

\begin{document}

\foreach \x in {1,...,500} {%
\mbox{}
\newpage
}

\forloop{loopcntr}{1}{\value{loopcntr} < 501}{%
\mbox{}
\newpage
}

\end{document}

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\begin{document}

\def\x{\ifnum\value{page}<501\mbox{}\clearpage\expandafter\x\fi}
\x

\end{document}

• A nice trick, I have to remember this ;-)
– user31729
Jul 5 '16 at 11:49

A variant with package multido (50 bytes):

\documentclass[DIV=20, fontsize=16]{scrartcl}
\usepackage{lmodern}
\usepackage[automark]{scrlayer-scrpage}
\cfoot{}
\ofoot[\pagemark]{\pagemark}

\usepackage{multido}

\begin{document}

\multido{}{500}{\null\newpage}

\end{document}


With expl3:

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{expl3}

\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\begin{document}

\ExplSyntaxOn
\prg_replicate:nn { 500 } { \mbox{}\newpage }
\ExplSyntaxOff

\end{document}


With no package and no assignment, but with e-TeX:

\documentclass[pagenumber=footright, DIV=20, fontsize=16]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}

\ofoot[\pagemark]{\pagemark}
\cfoot[]{}

\begin{document}

\def\x#1{%
\ifnum#1>0
\null\clearpage
\expandafter\x\expandafter{\the\numexpr#1-1\expandafter}\fi
}
\x{1}
\end{document}


With a simple variant, you can get a sequence that expands to 500 copies of \null\clearpage:

\def\x#1{%
\ifnum#1>0
\unexpanded{\null\clearpage}%
\expandafter\x\expandafter{\the\numexpr#1-1\expandafter}\fi
}
\edef\fivehundredemptypages{\x{500}}


The following is how I'd do it. It's very similar to David Carlisle's answer, but in a way which makes the recursion slightly clearer to me (trying to remember how \expandafter works always gives me a headache!).

\begin{document}

\def\x{\ifnum \count0>500
\let\next\relax
\else
\null\clearpage
\let\next\x
\fi
\next}
\x

\end{document}


Also Knuth explicitly guarantees that this is tail-recursive (though I don't doubt that the \expandafter one is, too).

• Much less efficient than the \expandafter version. ;-) Jul 5 '16 at 22:41
• @egreg Is it? Oooh: why? Do you mean one whole \let each time round the loop (in which case ouch, but I may be able to take the hit (premature optimisation and the root of all evil and all that)); or is there something blowing up in there that I can't spot? Jul 5 '16 at 23:34
• I don't think that efficiency is an issue here, unless a document with $10^{12}$ pages should be generated ;-) (+1)
– user31729
Jul 6 '16 at 3:02
• @NormanGray I was indeed referring to a \let for any cycle. Jul 6 '16 at 5:36
• +1 for the strict relation between expandafter and headache. Jul 7 '16 at 6:50