Using the patch defining prelast for pdfpages throws an error. [Might it have to do with updates in pdfpages?]
I am using the second answer from Including a length-dependent page range using pdfpages by @Werner and edited by @DavidCarlisle.
Using the command
\includepdf[pages=1-3]{dummy-l.pdf} everything works fine. But when I try
\includepdf[pages=1-prelast]{dummy-l.pdf} instead, I receive the error:
Package pdfpages Error: Cannot find file `1-prelast'.
The goal is to read in pdfs of different lengths and color the last page of a text. When I removed \usepackage{xcolor} and all the \pagecolor{} commands, I still got the same error. However, since the color part is critical to my project I have left it in the code just in case.
Note that once this error has been fixed, I will have other questions from this project, but I didn't want to add them here.
\documentclass{amsart}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\pagecolor{white}
\usepackage{pdfpages}% http://ctan.org/pkg/pdfpages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINE “prelast” to contain the pagenumber of the next-to-last page
% in pdfpages — from answer by Werner and David Carlisle found at
% https://tex.stackexchange.com/questions/62911/including-a-length-dependent-page-range-using-pdfpages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\AM@checklast#1-\END{%
\edef\AM@tempii{\AM@trim@space{#1}}%
\expandafter\ifx\expandafter\\\AM@tempii\\
\@tempcntb=\AM@pagecount\relax
\ifAM@DVIoutput
\ifnum\AM@pagecount=1
\@tempcntb\@tempcnta
\fi
\fi
\advance\@tempcntb\@ne
\whiledo{\@tempcnta<\@tempcntb}{%
\AM@append{\the\@tempcnta}%
\advance\@tempcnta\@ne
}%
\else
\def\AM@cmp{last}%
\ifx\AM@cmp\AM@tempii
\let\AM@tempii\AM@pagecount
\else\def\AM@cmp{prelast}% <------------------------- ADDED
\ifx\AM@cmp\AM@tempii% |
\@tempcntb=\numexpr\number\AM@pagecount-1\relax% |
\edef\AM@tempii{\the\@tempcntb}% |
\fi% <---------------------------------------------------
\fi
\AM@checkinteger{\AM@tempii}%
\ifAM@integer
\@tempcntb=\AM@tempii\relax
\AM@checkpagenumber{\the\@tempcntb}%
\ifnum\@tempcnta<\@tempcntb \def\AM@rel{<}\def\AM@inc{\@ne}%
\else \def\AM@rel{>}\def\AM@inc{\m@ne}\fi
\advance\@tempcntb\AM@inc
\whiledo{\@tempcnta\AM@rel\@tempcntb}{%
\AM@append{\the\@tempcnta}%
\advance\@tempcnta\AM@inc
}%
\else
\AM@setnewdocname{\AM@temp}%
\fi
\fi
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagecolor{cyan!50!white}
Some Text
\clearpage % before changing color must be on next page
\pagecolor{white}
\includepdf[pages=1-prelast]{dummy-l.pdf} % <----- error
% can't find file `1-prelast'.
%\includepdf[pages=1-3]{dummy-l.pdf} <----- works
\pagecolor{pink}
\includepdf[pages=last]{dummy-l.pdf} % <----- works
%\includepdf[pages=4]{dummy-l.pdf} <----- works
\pagecolor{white}
Some more text.
\end{document}