28.03.2013 Views

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.9. Printing literal text 111<br />

\verb=\emph{words of text}= \emph{words of text}<br />

\verb*=\emph{words of text}= \emph{words of text}<br />

where the first character after \verb or \verb* (here =) is the delimiter,<br />

such that all text up <strong>to</strong> the next occurrence of that character is printed<br />

literally. This character may not appear in the literal text, obviously.<br />

In contrast <strong>to</strong> the behavior in the verbatim environment, the literal<br />

text must be all on one line in the input text, otherwise an error message<br />

is printed. This is <strong>to</strong> indicate that you just might have forgotten <strong>to</strong> repeat<br />

the delimiting character.<br />

Important: neither the verbatim environment nor the \verb comm<strong>and</strong><br />

may be used in an argument of any other comm<strong>and</strong>!<br />

Exercise 4.16: Reproduce some input lines from this book as literal text.<br />

4.9.1 Extension packages for literal text<br />

Package: The st<strong>and</strong>ard package alltt (Section B.5.3, page 392) provides an alltt<br />

alltt environment that also prints its contents literally in a typewriter font,<br />

except that the characters \ { } retain their normal meaning. Thus LAT EX comm<strong>and</strong>s can be included within the literal text. For example,<br />

\begin{alltt}<br />

Underlining \underline{typewriter}<br />

text is also possible.<br />

Note that dollar ($) <strong>and</strong><br />

percent (%) signs are<br />

treated \emph{literally}.<br />

\end{alltt}<br />

Underlining typewriter<br />

text is also possible.<br />

Note that dollar () <strong>and</strong><br />

percent (%) signs are<br />

treated literally.<br />

Package: The st<strong>and</strong>ard package shortvrb (Section B.5.3, page 393) offers a<br />

shortvrb shorth<strong>and</strong> for the \verb comm<strong>and</strong>. After issuing \MakeShortVerb{\|},<br />

one can print short literal text with |text|. The counter comm<strong>and</strong><br />

\DeleteShortVerb{\|} then res<strong>to</strong>res the original meaning <strong>to</strong> |. Any<br />

character may be temporarily turned in<strong>to</strong> a literal switch this way.<br />

Package: One problem with the verbatim environment is that the entire litverbatim<br />

eral text is input <strong>and</strong> s<strong>to</strong>red before processing, something that can lead<br />

<strong>to</strong> memory overflows. The verbatim package in the <strong>to</strong>ols collection<br />

(Section B.5.4, page 396) re-implements the environment <strong>to</strong> avoid this<br />

problem. A minor drawback is that there must not be any other text on<br />

the same line as the \end{verbatim}.<br />

The verbatim package offers two other extra features. It provides<br />

a comment environment that simply ignores its contents, as though<br />

each line started with a % sign (Section 4.11). And it adds a comm<strong>and</strong><br />

\verbatiminput{filename} <strong>to</strong> input the specified file as literal text. This<br />

is useful for listing actual computer programs rather than copying them<br />

in<strong>to</strong> the LAT EX file.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!