I meant to restrict the overlay to all but the last page, but this setup fails due to \zref@extractdefault{abspage}{abspage}{0} stuck at 0. Is there a solution to this specific issue, and a better approach altogether?
\documentclass{article}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{zref-abspage}
\usepackage{zref-lastpage}
\makeatletter
\ExplSyntaxOn
\ProvideDocumentCommand{\OverlayTypeset}{ o m }
{
% \AtBeginShipout
\AddToHook{shipout/background}{
\int_compare:nTF
{
\zref@extractdefault{abspage}{abspage}{0}
<
\zref@extractdefault{LastPage}{abspage}{0}
}
{%
\int_show:n{\zref@extractdefault{abspage}{abspage}{0}}
\int_show:n{\zref@extractdefault{LastPage}{abspage}{0}}
\begin{tikzpicture}[remember~picture,overlay,text=red]
\node[scale=6,opacity=0.5] at (current~page.center) {#2};
\end{tikzpicture}
}
{ }
}
}
\ExplSyntaxOff
\makeatother
\OverlayTypeset{DRAFT}
\begin{document}
\lipsum[1-10]
\end{document}
log:
%[Loading MPS to PDF converter (version 2006.09.02).]
%) (/opt/texlive/2025/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
%(/opt/texlive/2025/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
%> \zref@extractdefault {abspage}{abspage}{0}=0.
%<recently read> }
%
%l.39 \end
% {document}
%?
%> \zref@extractdefault {LastPage}{abspage}{0}=2.
%<recently read> }
%
%l.39 \end
% {document}
%?
%[1{/opt/texlive/2025/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
%> \zref@extractdefault {abspage}{abspage}{0}=0.
%<recently read> }
%
%l.39 \end{document}
%
%?
%> \zref@extractdefault {LastPage}{abspage}{0}=2.
%<recently read> }
%
%l.39 \end{document}
%
%?
%[2] (./debug-119.aux) )</opt/texlive/2025/texmf-dist/fonts/type1/public/amsfont
%s/cm/cmr10.pfb>
%Output written on debug-119.pdf (2 pages, 25603 bytes).
%Transcript written on debug-119.log.
%Latexmk: Getting log file 'debug-119.log'
%Latexmk: Examining 'debug-119.fls'
%Latexmk: Examining 'debug-119.log'
%Latexmk: Log file says output to 'debug-119.pdf'
%Latexmk: Using bibtex to make bibliography file(s).
%Latexmk: Errors, so I did not complete making targets
%Collected error summary (may duplicate other messages):
% pdflatex: Command for 'pdflatex' gave return code 1
% Refer to 'debug-119.log' and/or above output for details
%
%Latexmk: Sometimes, the -f option can be used to get latexmk
% to try to force complete processing.
% But normally, you will need to correct the file(s) that caused the
% error, and then rerun latexmk.
% In some cases, it is best to clean out generated files before rerunning
% latexmk after you've corrected the files.


latexmkoutput is useless for debugging. but it tells you where the log file for pdflatex is, so you should post the complete first error from that file.