Up: verbatim   [Contents][Index]


8.27.1 \verb

Synopsis:

\verb char literal-text char
\verb* char literal-text char

Typeset literal-text as it is input, including special characters and spaces, using the typewriter (\tt) font.

This example shows two different invocations of \verb.

This is \verb!literally! the biggest pumpkin ever.
And this is the best squash, \verb+literally!+

The first \verb has its literal-text surrounded with exclamation point, !. The second instead uses plus, +, because the exclamation point is part of literal-text.

The single-character delimiter char surrounds literal-text — it must be the same character before and after. No spaces come between \verb or \verb* and char, or between char and literal-text, or between literal-text and the second occurrence of char (the synopsis shows a space only to distinguish one component from the other). The delimiter must not appear in literal-text. The literal-text cannot include a line break.

The *-form differs only in that spaces are printed with a visible space character.

The output from this will include a character showing the spaces.

The commands's first argument is \verb*!filename with extension! and ...

For typesetting Internet addresses, urls, the package url provides an option that is better than the \verb command, since it allows line breaks.

For computer code there are many packages with advantages over \verb. One is listings, another is minted.

You cannot use \verb in the argument to a macro, for instance in the argument to a \section. It is not a question of \verb being fragile (see \protect), instead it just cannot appear there. (But the cprotect package can help with this.)


Unofficial LaTeX2e reference manual