I am in a tricky situation. I am using NewEnviron to separate a handful of major parts of my document. Each part has its own numbering scheme and several environment-specific commands and settings. Important for my question, all numbering schemes follow the principle page_current of page_total
If I now, however, insert pdf-documents using \includepdf
, the label for page_total
breaks if \includepdf
is executed on the last page of my document.
Here an mwe, which probably explains it a bit better.
\documentclass[fontsize=10pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mwe}
\usepackage{pdfpages}
\usepackage{environ}
\usepackage{scrlayer-scrpage}
\NewEnviron{myenvi}{%
\clearscrheadfoot%
\cfoot{\normalfont\thepage\ / \pageref{lastpage}}%
\clearpage%
\BODY%
\label{lastpage}%
}
\newcommand{\myincludepdf}[1]{\includepdf[scale=0.5, frame, pagecommand={}]{#1}}
%\newcommand{\myincludepdf}[1]{\includepdf[scale=0.5, frame, pagecommand={\label{lastpage}}]{#1}}
\begin{document}
\begin{myenvi}
\lipsum[1-15]
\myincludepdf{example-image-a4}
\end{myenvi}
\end{document}
I also tried to add my label to the post-code of includepdf. That doesn't help.
I found two ways to get it to work. But both are not satisfactory. The first one is simply to add another page to the document. Because then the \label{lastpage}
can execute again. Moreover, one can also add the \label{lastpage}
to the pagecommand-option of \includepdf. But then I get a lot of "lastpage multiply defined" warnings.
Anyone an idea how to solve this issue. I was considering using a counter or gdef or something. But I think it is not really possible to get around this problem without the help of a sidecar-file.
Is there maybe an option to directly manipulate the aux-file so that I don't produce multiple labels and only the last call of \label{lastpage}
remains?
includepdf
more than once, the warnings occur even if you don't use thepagecommand={\label{lastpage}
option. Just ignore them - warnings are warnings and not errors for a reason.