10

I am passing a file name in the command line which contains underscores and would like to print the name of the file in the resulting PDF. So, need some expansion magic so that the output is:

enter image description here

The MWE produces:

enter image description here

In case it matters, the actual use case is with extract pages to incorporate the original file name in the extract PDF.

Code: MWE

\providecommand\FileName{A_B}
\documentclass{article}
\usepackage{verbdef}

\verbdef\MyVerb|\FileName|

\begin{document}
    \MyVerb\ (This should be ``\verb|A_B|", not ``\verb|\FileName|".)
\end{document}

Code: Actual Use Case

\providecommand*{\FileName}{A_B}%
\providecommand*{\PageRange}{2}% "3,67-70,80" for example (without the quotes)
\documentclass{article}
\usepackage{pdfpages}

\begin{document}
    \includepdf[pages={\PageRange},picturecommand={\FileName}]{"\FileName"}
\end{document}
13

\verb has no effect on tokens (even if you expanded \FileName), so you want something more like this

\def\FileName{A_B}
\documentclass{article}
\usepackage[T1]{fontenc}



\begin{document}
  \texttt{\detokenize\expandafter{\FileName}}
\end{document}

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.