I need to append a draft page only if the total number of pages in the main document is odd.
The following works well
\documentclass{exam}
\usepackage{blindtext,tikz,ulem,atveryend,hyperref}
\usepackage[totpages,user]{zref}
\newcommand\DraftPage{%https://tex.stackexchange.com/a/263613/2288
\clearpage
\begingroup
\null
\thispagestyle{empty}%
\begin{tikzpicture}[remember picture,overlay]
\node at ([yshift=-2cm]current page.north) {\LARGE\textbf{\uline{Draft Page}}};
\draw[line width=5pt]
(current page.north west) -- (current page.south east);
\draw[line width=5pt]
(current page.south west) -- (current page.north east);
\end{tikzpicture}
\addtocounter{page}{-1}%
\hypersetup{pageanchor=false}%
\clearpage
\endgroup
}
\AtVeryEndDocument{
\ifodd\ztotpages
\DraftPage
\fi
}
\begin{document}
\blindtext[1-30]\\
\textbf{Total number of pages is \ztotpages.}
\DraftPage
\end{document}
until changing it to
\begin{document}
\blindtext[1-30]\\
\textbf{Total number of pages is \ztotpages.}
\end{document}
then I get on the second page a wrongly rendered appended draft page.
So, I have two questions:
1- How to make the command \DraftPage not affect the total number of pages detected by \ztotpages in the former working case? In other words. \ztotpages needs to be 1.
2- Why does the second case result in the wrong output? and how to fix it?





\mbox{}? – Diaa Mar 01 '20 at 11:37\DraftPagpage. Without it you obtain only part of image as you shown in your question. – Zarko Mar 01 '20 at 11:45\begin{document} \lipsum \lipsum %\lipsum[1-3] \textbf{Number of pages is \ztotpages.} \end{document}`. You will always get different output each time you compile. I only need to print a draft page only if the total number of pages is odd. I think it is a different question needed to be asked separately.
– Diaa Mar 01 '20 at 11:47tikzpicturewhich use optionsremember picture,overlay. After second compilation result is stable -- always the same. I use recent MikTeX with recent packages, if this matter. – Zarko Mar 01 '20 at 12:00