8.27 verbatim



A paragraph-making environment in which LaTeX produces as output exactly what you type as input. For instance inside literal-text the backslash \ character does not start commands, it produces a printed ‘\’, and carriage returns and blanks are taken literally. The output appears in a monospaced typewriter-like font (\tt).

Symbol swearing: %&$#?!.

The only restriction on literal-text is that it cannot include the string \end{verbatim}.

You cannot use the verbatim environment in the argument to macros, for instance in the argument to a \section. This is not the same as commands being fragile (see \protect), instead it just cannot work, as the verbatim environment changes the catcode regime before processing its contents, and restore it immediately afterward, nevertheless with a macro argument the content of the argument has already be converted to a token list along the catcode regime in effect when the macro was called. However, the cprotect package can help with this.

One common use of verbatim input is to typeset computer code. Some packages offer many features not provided by the verbatim environment; two of the most popular are listings and minted. For example, they are capable of pretty-printing, line numbering, and selecting parts of files for a continuing listing.

A package that provides many more options for verbatim environments is fancyvrb. Another is verbatimbox.

For a list of all the relevant packages, see CTAN (see CTAN: The Comprehensive TeX Archive Network), particularly the topics listing (https://ctan.org/topic/listing) and verbatim (https://ctan.org/topic/verbatim).

Unofficial LaTeX2e reference manual