3

I am trying to merge two PDFs into one, alternating the pages. Unfortunately, there is no option in pdfpages that would handle this, so I am using \includepdfmerge and specify the pages to add manually:

\documentclass{article}

\usepackage[final]{pdfpages}

\begin{document}

\includepdfmerge[nup=2x5,noautoscale=true,offset=-1.0mm 1mm,delta=1cm 0in]{A.pdf,1,B.pdf,1,A.pdf,2,B.pdf,2,A.pdf,3,B.pdf,3,A.pdf,4,B.pdf,4,}
\end{document} 

Of course I'd like to make this easier, so I thought I'd create a \textstring that I then insert:

\documentclass{article}

\usepackage[final]{pdfpages}
\usepackage{ifthen}

\begin{document}

\newcommand{\textstring}{A.pdf,1,}

\includepdfmerge[nup=2x5,noautoscale=true,offset=-1.0mm 1mm,delta=1cm 0in]{\textstring}
\end{document}

However, this doesn't work, I am getting

Package pdfpages Error: Cannot find file `A.pdf,1,'

So is this not possible? Am I missing something obvious?

Thorsten
  • 461
  • 1
    Maybe is this what you want? https://unix.stackexchange.com/a/92593/19195 – Sigur Dec 30 '19 at 14:43
  • The answer from https://tex.stackexchange.com/questions/125193/adding-pdf-pages-with-includegraphics-using-a-loop may be applicable here too. – Marijn Dec 30 '19 at 16:15
  • @Sigur - for some reason this doesn't seem to work on my Mac. But it would have been a nice workaround (Marijn - I have found another solution in the meantime (see below)) – Thorsten Dec 30 '19 at 17:58

2 Answers2

1

Note the extra braces in \textstring.

\documentclass{article}

\usepackage[final]{pdfpages}
\usepackage{ifthen}

\begin{document}

\newcommand{\textstring}{test.pdf,1,test2.pdf,1}%
\edef\textstring{{\textstring}}

\includepdfset{nup=2x5,offset=-1.0mm 1mm,delta=1cm 0in}%
\expandafter\includepdfmerge\textstring
\end{document}

One can also use

\expandafter\includepdfmerge\expandafter{\textstring}

instead of adding the extra braces with \def or \edef.

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
1

It seems (and I was unaware of this) that pdfpages just adds to the end of the file as default. So I found this solution: https://latex.org/forum/viewtopic.php?t=10965 which works for me. Thanks to everyone!

Thorsten
  • 461