Problem description
In trying to calculate the progress of a Beamer presentation, one can use
\pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertdocumentendpage)}
where \prog
tracks the percentage value of the progress.
To take into account that a presentation may possibly contain an appendix, and to exclude slides therein from the calculation of \prog
, I naturally thought that one can simply change \insertdocumentendpage
to \insertpresentationendpage
, or \insertappendixstartpage-1
when an appendix does exist. However, doing so results in an error:
Package PGF Math Error: Unknown operator `=' or `=4' (in '100*(3)/({\beamer@tempcount =4\relax 0})').
If \insertappendixendpage
is used, there is no error (but the value of \prog
will be wrong).
The following MWE contains no appendix, so the four \insert<...>
s should have the same value. However, uncommenting either of the last two frames results in the abovementioned error.
\documentclass{beamer}
\begin{document}
\frame{
\pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertdocumentendpage)}
progress = \prog
}
\frame{
\pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertappendixendpage)}
progress = \prog
}
% \frame{
% \pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertappendixstartpage-1)}
% progress = \prog
% }
% \frame{
% \pgfmathtruncatemacro{\prog}{100*(\insertpagenumber)/(\insertpresentationendpage)}
% progress = \prog
% }
\end{document}
Question
Why is this the case, and how can I correct it?
Edit (based on Tom Bombadil's long comment)
Try adding this outside of a frame:
\typeout{======================================}
\show\insertdocumentendpage
\typeout{======================================}
\show\insertpresentationendpage
\typeout{======================================}
\show\insertappendixstartpage
\typeout{======================================}
The equal signs are just there so it's easier to find in the .log file. This will return
======================================
> \insertdocumentendpage=\long macro:
->\beamer@endpageofdocument .
l.27 \show\insertdocumentendpage
======================================
> \insertpresentationendpage=\long macro:
->{\ifx \beamer@startpageofappendix \@empty \beamer@tempcount =\beamer@endpageo
fdocument \relax \else \beamer@prevpage \beamer@startpageofappendix \relax \fi
\the \beamer@tempcount }.
l.29 \show\insertpresentationendpage
======================================
> \insertappendixstartpage=\long macro:
->{\ifx \beamer@startpageofappendix \@empty \beamer@tempcount =\beamer@endpageo
fdocument \relax \else \beamer@tempcount =\beamer@startpageofappendix \relax \f
i \the \beamer@tempcount }.
l.31 \show\insertappendixstartpage
======================================
Apparently, the problem is related to the fact that \insertdocumentendpage
just returns a value, while \insertpresentationendpage
and \insertappendixstartpage
return an expression that needs to be evaluated first. So the question can be refined to either
- How can one force
\pgfmathparse
to evaluate this first? or - How can one save the result of such an expression in a macro?
\xdef\x{\insertappendixstartpage} \x
returns a number as expected, but a\pgfmathsetmacro{\prog}{\x}
afterwards fails in the same way.