# How to include a file with the verbatim environment

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

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}


With the verbatim package, it is this:

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


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