1

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

\begin{verbatim}
    \input{file.tex}
\end{verbatim}

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 – user36296 Nov 8 '18 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} – Steven B. Segletes Nov 8 '18 at 18:30
3

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

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
Normal sized text
\verbfilenobox[\theVerbboxLineNo: \Large]{junk.tex}
\verbfilebox[\tiny]{junk.tex}\fbox{\theverbbox}
\end{document}

enter image description here

With the verbatim package, it is this:

\documentclass{article} 
\usepackage{verbatim} 
\begin{document} 
\verbatiminput{junk.tex} 
\end{document}

enter image description here

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

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.