2

I insert several PDFs thought my document using \includepdf. I'd like to define the <key=val> options in one variable and pass that to each \includepdf.

Right now I do something like this:

\includepdf[pages=-, frame, scale=0.8, offset=0mm -10mm, pagecommand={}]
                    {./parts/letter_1.pdf}
\includepdf[pages=-, frame, scale=0.8, offset=0mm -10mm, pagecommand={}]
                    {./parts/letter_2.pdf}

This is what I'd like to do, but this gives Package keyval Error...undefinded:

\newcommand{\PDFOptions}{pages=-, frame, scale=0.8, offset=0mm -10mm, pagecommand={}}
\includepdf[\PDFOptions]{./parts/letter_1.pdf}
\includepdf[\PDFOptions]{./parts/letter_2.pdf}
percusse
  • 157,807
cfort
  • 123
  • Can you try to replace \newcommand by \def? I believe that \newcommand comes with magic to allow optional arguments which does not work will with your use-cases.

    In addition, you may need to write \expandafter\includepdf\expandafter[\PDFOptions] .

    – Christian Feuersänger Nov 03 '17 at 14:16
  • 1
    background/references for my comments requires in-depth understanding of TeX programming, see also https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming/27589#27589 – Christian Feuersänger Nov 03 '17 at 14:17
  • 2
    @ChristianFeuersänger There's no difference whatsoever between doing that with \newcommand or \def. LaTeX won't expand the optional argument to \includepdf until it's too late for parsing the options. – egreg Nov 03 '17 at 14:19

1 Answers1

3

The simplest strategy is to do

\newcommand{\myincludepdf}[2][]{%
  \includepdf[
    pages=-,
    frame,
    scale=0.8,
    offset=0mm -10mm,
    pagecommand={},
    #1
  ]{#2}%
}

and use

\myincludepdf{./parts/letter_1.pdf}

You may also add options, for instance

\myincludepdf[pages=1-3]{./parts/letter_1.pdf}

in a special case when you don't need all pages.

egreg
  • 1,121,712