3

I load multiple source files into a document using the fancyvrb package. I found out how to include a static label. Now, I want to display the filename in the label (dynamic label based on input file). How can I achieve this?

In the following example, the label should be file_1.txt and file_2.txt instead of data.txt.

\documentclass[10pt, a4paper, twoside]{article}

\usepackage{fancyvrb}

\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}{
    label=\fbox{data.txt},
    labelposition=topline,
}

\begin{document}

\VerbatimInput{file_1.txt}
\VerbatimInput{file_2.txt}


\end{document}
Molitoris
  • 177

1 Answers1

3

I'd avoid redefining \VerbatimInput.

\documentclass{article}
\usepackage{fancyvrb}

\newcommand{\verbatiminput}[1]{%
  \VerbatimInput[
    label=\fbox{\texttt{\detokenize{#1}}},
    labelposition=topline,
    frame=single,
  ]{#1}%
}

\begin{document}

\verbatiminput{file_1.txt}

\verbatiminput{file_2.txt}

\end{document}

enter image description here

egreg
  • 1,121,712