6

How can I include the contents of a text file in my latex document as verbatim?

I tried (the text file does not contain any @)

\documentclass{article}
\begin{document}   
    \verb@
    \input{temp.txt}
    @
\end{document}

but I get the error: \verb ended by end of line.

PS: of course the above cannot work even without the error, because if it worked the output file would just contain the single line \input{temp.txt}

1 Answers1

7

Try

\documentclass[10pt]{article}

\usepackage{verbatim}

\begin{document}
\verbatiminput{temp.txt}
\end{document}

I use this regularly to include TeX source, so lots of unusual characters are handled properly - i.e literally.

Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69