TeX - LaTeX Asked by AureusPhoenix on December 23, 2020
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{normalfontthepage / 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?
Ok, found a solution. Probably also not the most elegant one, but it works.
I use the lastpage-package to check inside includepdf
whether the current page is the last one of the document or not. If that is the case, I execute label{endenvi}
and, hence, only define it once. And if a page comes after all includepdf
's the label-command inside my environment-definition executes.
Here the code:
documentclass{scrartcl}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{mwe}
usepackage{pdfpages}
usepackage{environ}
usepackage{lastpage}
usepackage{xifthen}
usepackage{scrlayer-scrpage}
NewEnviron{myenvi}{%
clearscrheadfoot%
cfoot{normalfontthepage / pageref{endenvi}}%
clearpage%
BODY%
label{endenvi}
}
newcommand{myincludepdf}[1]{includepdf[scale=0.5, frame, pagecommand={%
ifthenelse{equal{pageref{LastPage}}{thepage}}{label{endenvi}}{}}]{#1}}
begin{document}
begin{myenvi}
lipsum[1-15]
myincludepdf{example-image-a4}
myincludepdf{example-image-a4}
end{myenvi}
end{document}
Answered by AureusPhoenix on December 23, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP