# Doing math with \pageref (finding the last page number and adding 3) [duplicate]

So I'm writing an exam. It will have some as-yet-unknown number of pages P, and an additional 3 pages of a formula sheet. So the total length is N = P +3.

I need to write "This exam has $P$ pages, plus $3$ pages of formulas, for a total of $N$ pages".

I currently have a label at the end of the exam: \label{lastpage}, and so where I have P, I can write\pageref{lastpage}.

But is there some way I can get N to be calculated automatically for me? I suspect it might exist in pgfmath, but I haven't used it in a while.

• See tex.stackexchange.com/a/250401/194703 (of course you'll need \the\numexpr(\ztotpages)+3\relax). – user194703 Sep 4 '19 at 1:38
• Thanks @Schrödinger'scat , Looks like that will work... Is there a way I can set a variable to be 3, so that I only have to make 1 change if the formula sheet length changes? If this is worth a separate question, let me know. – Joel Sep 4 '19 at 2:50
• You can just define a macro like \def\mynum{3} and then \the\numexpr(\ztotpages)+\mynum\relax. (Some users on this site have a very strange behavior I must say.) – user194703 Sep 4 '19 at 3:47

Consider using refcount; use \getpagerefnumber{LastPage} in some calculation of your choice.

\documentclass{article}

\usepackage{refcount,lastpage}
\usepackage{lipsum}

\begin{document}

Last page: \pageref{LastPage}

Final page: \number\numexpr\getpagerefnumber{LastPage}+3\relax

\sloppy\lipsum[1-50]\lipsum[1-50]\lipsum[1-50]\lipsum[1-50]\lipsum[1-50]

\end{document}
`
• This is more or less exactly what is done in tex.stackexchange.com/a/250401/194703. – user194703 Sep 4 '19 at 4:53
• @Schrödinger'scat: Nice. I'm pretty sure we can close this as a duplicate; while the question is asking for something different, the solution is pretty much the same. – Werner Sep 4 '19 at 5:22