I am using the exam document class for creating some tests for my students. Usually in every test the last page is for student's notes so I don't want to include this page in total test pages number. For this I include in the preamble this piece of code just for the last page not to be numbered:

  {\mbox{\normalfont\bf ??}}  

Although it actually works, when I compile the whole code for the first time I get the following errors:

You can't use \numexpr' in restricted horizontal mode. ^^I\part { Undefined control sequence. ^^I\part { You can't use \numexpr' in restricted horizontal mode. \end{document} Undefined control sequence. \end{document}

When I compile again the error goes away and I get a Process exited normally message and the code does what it is supposed to do: the last page is not numbered.

There is another detail: When I compile the code for the first time with out the small code above I don't get the error of course, if I paste it after the first compilation the error never appears. The same happens in pdflatex, lualatex and xelatex. Is there a way to avoid this error?

I include a minimal (as minimal as I could do it) example:

\usepackage[a4paper, total={180mm,247mm},left=15mm,top=20mm]{geometry}  
\rfoot{Page \thepage\ of \numpages}  

    {\mbox{\normalfont\bf ??}}%  

    This is the fist page of the exam  
    this is the second page of the exam  
    \raggedright{\textbf{\underline{Student Notes:}}  

I noticed that also has something to do and with the command \newgeometry{body={185mm,257mm},centering} I have in my code, or the interaction of this command and the small code.

  • 1
    Please write a minimal working example. See link for more details what it means.
    – user202729
    Jul 14, 2022 at 12:53

1 Answer 1


The code for \numpages is

  {\mbox{\normalfont\bfseries ??}}%
}% numpages

Since \exam@lastpage is a single token, braces around it can be omitted (I consider it bad style, though).

Here's the fix:

    {\mbox{\normalfont\bfseries ??}}%

Avoid \bf that has been deprecated for about 30 years.

  • Thank you egreg! Now it works without the error message. So the problem was mainly the \def command instead of \renewcommand and the braces at the last line?
    – miltos
    Jul 14, 2022 at 16:14
  • @MiltosP. I prefer \renewcommand, but it's not a problem if you use \def. The issue were the missing braces.
    – egreg
    Jul 14, 2022 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .