tex_logos_04.gif (2422 bytes)
The \verb command

The \verb command allows us to insert short selections of literal text into a LaTeX document. For more extensive selections, for example, long pieces of code, it is necessary to use the verbatim environment..


Download the .tex file to play with or the .pdf file to see the typeset output from the .tex file.

Here is the content of the verb-command.tex file. It is largely self-documenting.

%% verb-command.tex
%% Bent E. Petersen
%% Oct 23, 2000


%% Use non-indented paragraphs

\setlength{\parskip}{10pt plus 6pt minus 4pt}

%% \jobname is the name of the current file without the extension.
%% The period serves to terminate the \jobname macro below, so no space
%% is needed in \jobname.tex

\author{Bent Petersen}
\date{Oct 23, 2000}


%% Suppress the page number on the current page. Note something
%% must be output on the page first for this command to work.
%% In our case the title has already been set by \maketitle


This document illustrates the \verb=\verb= command. It is also
an example of a (nearly) minimal \LaTeXe{} file. The \verb=\verb= command
is used to produce literal text, without
any interpretation or mangling by \TeX{}. It is particularly helpful if
you are writing about \TeX{} commands (as here), or you are inserting small
snippets of code in your document.

In the command \verb=\verb#some text#= the \verb=#= character
acts as a switch. All the text that comes between the two \verb=#=
characters is output verbatim. For example, commands are not interpreted.
Any character, which does not occur in the string \verb=some text=, 
other than the \verb=*= character,  can be used as the switch. It is even possible to
use the space character, but it is not recommended, since it is hard
to see. The equals sign \verb/=/, the forward slash \verb=/=, and the
pipe \verb=|=, are commonly used as switches.

There is a star version \verb=\verb*= of the of the \verb=\verb= command. It 
behaves exactly the same as the \verb=\verb= command except spaces are rendered
visible. They are replaced by the \verb*= = character. Thus the command
\verb|\verb*#Here is some sample text.#|
produces the output
\verb*#Here is some sample text.#

The \verb=\verb= command is only suitable for short selections of text. 
For longer selections use the \verb=verbatim= environment.

%% It is not necessary to use \verb=verbatim= here of course. I did it
%% only to guarantee that the word verbatim would be set in the same
%% font as the commands. 

Last updated Thursday, April 10, 2003
Bent E. Petersen

Back to the TeX  index page