Intro | First attempt | Text | References | Figures | Maths | Source Code | Theorems
The simplest way to include source code and similar material
verbatim, is by using the verbatim environment
and \verb macro, like this:
\begin{verbatim}
#include
int main ( int argc, int *argv[] ) {
fprintf ( 'Hello world!' ) ;
}
\end{verbatim}
We can describe an individual construct, like \verb|#include|, using
the \verb=\verb= macro.
Both the environment and the macro typesets in a typewriter font, without interpreting TeX's special characters. The argument to \verb (unlike other macros) is enclosed by two identical, but otherwise arbitrary, characters.
A better solution in most cases is to pretty-print the source code. This can be done using the listings package, cf. The LaTeX Companion for details. You may also consider the algorithmic package for pseudo-code.