tex_logos_04.gif (2422 bytes)
The verbatim environment

The verbatim environment, \begin{verbatim} ... \end{verbatim}, permits us to insert large sections of preformated text in a LaTeX file. It is very handy for inserting large chunks of code in a document, for example, literal TeX code or the Maple code you sweated over and now want to comment on.

For short in-line phrases the \verb command is what you want.

The verbatim environment is supported directly by LaTeX but by loading the verbatim package one gets a better implementation. In addition the verbatim package provides the comment environment, which beats typing percentage signs at the beginning of each line. The verbatim package also provides the \verbatiminput command. This handy command reads in a text file and places it in an implicit verbatim environment. We illustrate this command here by having a LaTeX file read in and display itself.

If the verbatim package is not quite what you need check the moreverb package.It provides a large number of verbatim-like environments.


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 verbatim-package.tex. It is largely self-documenting.

%% verbatim-package-demo.tex
%% Bent E. Petersen
%% Oct 23, 2000

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

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


This document demonstrates the \verb=verbatim= environment
and \verb=\verbatiminput= command. It also demonstrates the
\verb=comment= environment, but you have to look at the TeX
source to see that (of course).

Here is a short piece of Maple code to demonstrate the
the \verb=verbatim= environment:
> eqn:=diff(y(t),t,t)+4*y(t)=0:
> inits:=y(0)=1,D(y)(0)=-1:
> dsolve({eqn,inits},y(t));
\mathrm{y}(t)= - \frac{1}{2}\,\sin(2\,t) + \cos(2\,t)

Put a few paragraphs you have not decided about yet here for future
work. They will not appear in the output. You can also put comments
or reminders here. For example, you may want to remind yourself that
Maple has a nice LaTeX export feature which may be more convenient
than the by-hand approach used above.

To demonstrate the \verb=\verbatiminput= command this file will
input itself, which is pretty cool. To make sure
this file can find itself to input, we use the \verb=\jobname=
command in the argument to \verb=\verbatiminput=. Thus everything
will work even if you rename this file.

Normally of course, you would use the name of the file you wish
to include.

To TeX this demo do a {\sffamily latex verbatim-package-demo}, where
{\sffamily verbatim-package-demo} is replaced by whatever name you gave
to this \LaTeXe{} file.

\section*{Here's the \LaTeXe{} source}



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

Back to the TeX index page