The TeX FAQ

Frequently Asked Question List for TeX

Formatting

Including a file verbatim in LaTeX

A good way is to use Rainer Schöpf’s verbatim package, which provides a command \verbatiminput that takes a file name as argument:

\usepackage{verbatim}
...
\verbatiminput{verb.txt}

Another way is to use the alltt environment, which requires the alltt package. The environment interprets its contents “mostly” verbatim, but executes any (La)TeX commands it finds:

\usepackage{alltt}
...
\begin{alltt}
\input{verb.txt}
\end{alltt}

of course, this is little use for inputting (La)TeX source code…

The moreverb package extends the verbatim package, providing a listing environment and a \listinginput command, which line-number the text of the file. The package also has a \verbatimtabinput command, that honours TAB characters in the input (the package’s listing environment and the \listinginput command also both honour TAB).

The sverb package provides verbatim input (without recourse to the facilities of the verbatim package):

\usepackage{sverb}
...
\verbinput{verb.txt}

The fancyvrb package offers configurable implementations of everything verbatim, sverb and moreverb have, and more besides. It is nowadays the package of choice for the discerning typesetter of verbatim text, but its wealth of facilities makes it a complex beast and study of the documentation is strongly advised.

The memoir class includes the relevant functionality of the verbatim and moreverb packages.

FAQ ID: Q-verbfile