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.

2
  • 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

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.

You must log in to answer this question.

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