Background: I want a way to obtain the number of pages of the PDF that
is included using \includepdf (from the pdfpages package). To be
clear, I mean the PDF consisting of the (possibly proper) subset of
the pages of the original PDF that is passed as an argument to
\includepdf. E.g. if a 10 page document is an argument to
\includepdf, and only three pages are selected, I want the value
three.
The reason for this, is that I want to programmatically add a blank page at the end of an document with an odd number of pages, but not to the end of a document with an even number of pages. So I technically only need to know whether the number is even or odd, not the actual number.
See MWE below. I have called the hypothetical macro that contains the
number of pages \numberofpages.
Since TeX has effectively global scope, I'm assuming that the macro
will return the number of pages corresponding to the most recent
invocation of \includepdf.
\documentclass[12pt]{article}
\usepackage{pdfpages}
\def\Filename{example-image-a4-numbered.pdf}
\def\numberofpages{}
\begin{document}
\includepdf[pages={2-4, 6}]{\Filename}
\numberofpages % 4
\includepdf[pages={4-6}]{\Filename}
\numberofpages % 3
\clearpage\ifodd\value{page}\else\null\clearpage\fienough? – campa Feb 05 '21 at 12:08\includepdf, to optionally add a blank page after each inclusion. Would that work? – Faheem Mitha Feb 05 '21 at 13:35\includpdfon a previous page is not relevant. – David Carlisle Feb 05 '21 at 14:13