I would like to include a file within the verbatim environment but this of course doesn't work:


Is there way of getting LaTeX to execute \input within the verbatim environment?

Please trust me that I have good reasons for wanting to do this.

  • Maybe the listings package could be useful, it has the command \lstinputlisting to input source files Nov 8, 2018 at 18:27
  • 3
    Welcome to the site. \documentclass{article} \usepackage{verbatim} \begin{document} \verbatiminput{MYFILE.tex} \end{document}. See also the verbatimbox package: \documentclass{article} \usepackage{verbatimbox} \begin{document} \verbfilenobox[\small]{MYFILE.tex} \verbfilebox[\tiny]{MYFILE.tex}\fbox{\theverbbox} \end{document} Nov 8, 2018 at 18:30

1 Answer 1


If this file is named junk.tex, here is a plug for my verbatimbox package.

Normal sized text
\verbfilenobox[\theVerbboxLineNo: \Large]{junk.tex}

enter image description here

With the verbatim package, it is this:


enter image description here

As samcarter noted, there are other even more flexible options, such as the listings package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .