0

Is there any better solution to include all odd / even pages of a pdf file?

    \documentclass{scrartcl} 
    \usepackage{pdfpages}
\begin{document}
\includepdf[page={1,3,5,7,9,11,13,15,17,19,21,23,25,27
%\includepdf[page={2,4,6,8,10,12,14,16,18,20,22,24,26,28
}]{bCh03.pdf}
\end{document}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
sandu
  • 7,950

1 Answers1

2

I don't know of a direct solution within the pdfpages package. However, you can do this with a loop.

First you would extract the number of pages (cf. this answer by Symbol 1) by

\pdfximage{bCh03.pdf}

This stores the number of pages in the macro \pdflastximagepages, which will be required for the termination criterion. Next you need a loop. For this, create the iterator int like this

\newcounter{int}
\setcounter{int}{-1}

Then you start the loop and insert only the page corresponding to the counter

\whiledo{\not{\value{int} > \pdflastximagepages}}{
\includepdf[page={\theint}]{bCh03.pdf}
\addtocounter{int}{2}
}

If you want to add only even pages, initialize int as 2. If you want every third page to appear, increment the counter by 3. In this fashion, you can simply define an own macro

\documentclass{scrartcl}

\usepackage{pdfpages}

\newcounter{int} \newcommand{\myincludepdf}[3]{ \pdfximage{#1} \setcounter{int}{#2} \whiledo{\not{\value{int} > \pdflastximagepages}}{ \includepdf[page={\theint}]{#1} \addtocounter{int}{#3}} }

\begin{document} \myincludepdf{bCh03.pdf}{1}{2} \end{document}