Consider the \includepdf macro from the pdfpages package. If I do
\includepdf[pages=1-]{blank.pdf}
there is no problem. However, if I do
\def\foo{{1-}}
\includepdf[pages=\foo]{blank.pdf}
I get the error
! Missing = inserted for \ifnum.
I earlier thought that the problem was that \includepdf wasn't expanding the macro argument to pages, but now I'm wondering if that is indeed the case. Because if I try
\includepdf[pages=\expanded{\foo}]{blank.pdf}
it makes no visible difference.
I've tried running with \tracingmacros=1 and it looks like in both cases \foo at least gets expanded, but it's unclear what goes wrong after that. MWE follows.
\documentclass{article}
\usepackage{grffile}
\usepackage{pdfpages}
\begin{document}
\tracingmacros=1
\def\foo{{1-}}
\includepdf[pages=\foo]{blank.pdf}
% \includepdf[pages=\expanded{\foo}]{blank.pdf}
\tracingmacros=0
\end{document}
And here is part of the \tracingmacros=1 output corresponding to the version with \expanded, namely
\includepdf[pages=\foo]{blank.pdf}
Output follows:
\foo ->{1-}
\AM@trim@spacei #1->\AM@trim@spaceii #1 \END
#1<-{1-}
\AM@trim@spaceii #1 #2\END ->#1
#1<-1-
#2<-
\AM@checkinteger #1->\ifcat _\ifnum 9<1#1_\else A\fi \AM@integertrue \else \AM@
integerfalse \fi
#1<-\AM@tempi
\AM@tempi ->1-
\AM@integertrue ->\let \ifAM@integer \iftrue
\AM@checkpagenumber #1->\ifnum #1>\AM@pagecount \relax \ifthenelse {\boolean {A
M@pkg@draft} \and \boolean {AM@survey}}{}{\PackageError {pdfpages} {Page #1 of
`\AM@currentdocname ' does not exist} {You have set a wrong page number in the
`pages' option. Document \MessageBreak `\AM@currentdocname ' does not have #1 p
ages.}}\fi
#1<-\AM@tempi
\AM@tempi ->1-
! Missing = inserted for \ifnum.
<to be read again>
As can be seen, \foo does get expanded in this case.
Related question earlier asked by me: "Passing arguments using pgfkeys to a macro for including PDF files, using pdfpages".
-, which it doesn't find because it's hidden between{...}. Then when checking the value of the page it assumes there is no-and tries to do\ifnum 1->\AM@pagecount, which is invalid. Probably if you remove the extra set of braces it will work. – Phelype Oleinik Sep 16 '19 at 13:13\expandedwork? Am I applying it incorrectly? – Faheem Mitha Sep 16 '19 at 13:16\foothe macros for detecting a range see\expanded{\foo}which has no hyphen as well. – egreg Sep 16 '19 at 13:17\expandedthere doesn't help. I understand. But if the values are not expanded, why does1-show up in the output of\tracingmacros=1? – Faheem Mitha Sep 16 '19 at 13:19