2

I am trying to make a command that looks like this:

\newcommand{\pdf}[1]{ 
    \includepdf[
        scale = 0.7,
        pagecommand = 
            \begin{verbatim} 
                #1             
            \end{verbatim}
    ]{#1}
}

such that

\pdf{Test.pdf}

includes the pdf and prints the filename on top of the page.

I get the error File ended while scanning use of \@xverbatim. I also tried it without the verbatim:

\newcommand{\pdf}[1]{\includepdf[scale=0.7,pagecommand= #1 ]{#1}}

This displays the pdf correctly, but when the filename has an underscore (eg test_file.pdf), I get errors Missing $ inserted and the filename is not displayed correctly. How can I fix this?

  • 4
    You can't use verbatim as the argument to another command. What you need is \texttt{\detokenize{#1}}. – egreg Dec 5 '16 at 13:40
  • @egreg An answer? – Henri Menke Dec 5 '16 at 15:59
4

verbatim, like \verb, cannot be used in the argument to another command.

What you seem to need is just

\texttt{\detokenize{#1}}

so the underscore becomes printable:

\newcommand{\pdf}[1]{%
  \includepdf[
    scale = 0.7,
    pagecommand = \texttt{\detokenize{#1}},
  ]{#1}%
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.