You are on page 1of 2

Code snippets

The well-known LATEX command \verb typesets code snippets verbatim. The new command
\lstinline pretty-prints the code, for example.
var i : integer ;

\lstinline!var i:integer;!

Display code
The lstlisting environment typesets the enclosed source code.
f o r i := maxint t o 0 do
begin
{do n o t h i n g }
end ;
Write ( C a s e i n s e n s i t i v e ) ;
WritE ( P a s c a l keywords .
) ;
The environment provides an optional argument. It tells the package to peform special tasks,
for example, to print only the lines 2-5:
begin
{do n o t h i n g }
end ;

Stand alone files


Finally we come to \lstinputlisting the command used to pretty-print stand alone files. I has
one optional and one file name argument.
\lstinputlisting[lastline=4]{listings}
/ p r i n t numbers from 0 t o 10/
f o r ( i n t i =0; i <11; i ++)
System . out . p r i n t l n ( i ) ;

Figure out the appearance


This is how to control the inner work of the listing package.
f o r i := maxint t o 0 do
begin
{ do n o t h i n g }
end ;
Write (
WritE (

C a s e insensitive
P a s c a l keywords .

);
);

Seduce to use
Line numbers are available for all displayed listings, e.g. tiny numbers on the left, each second line,
with 5pt distance to the listing:
1

f o r i := maxint t o 0 do
begin
{ do n o t h i n g }
end ;

Write (
WritE (

C a s e insensitive
P a s c a l keywords .

);
);

Floating listings
Displayed listings may float:
Listing 1: A floating example
1

f o r i := maxint t o 0 do
begin
{ do n o t h i n g }
end ;

Write (
WritE (

C a s e insensitive
P a s c a l keywords .

);
);

You might also like