Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
The Listings Package

The Listings Package

Ratings:
(0)
|Views: 276|Likes:
Published by nqdinh
latex, algorithm
latex, algorithm

More info:

Published by: nqdinh on Dec 31, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/28/2010

pdf

text

original

 
The
Listings
Package
Copyright 1996–2004, Carsten HeinzCopyright 2006–2007, Brooks MosesMaintainer: Brooks Moses
<
>
2007/02/22 Version 1.4
Abstract
The
listings
package is a source code printer for L
A
TEX. You can typesetstand alone files as well as listings with an environment similar to
verbatim
as well as you can print code snippets using a command similar to
\verb
.Many parameters control the output and if your preferred programminglanguage isn’t already supported, you can make your own definition.
Brooks Moses became the maintainer of the
listings
package in 2006; see the Preface fordetails.
4.4 The printed range. . . . . . 274.5 Languages and styles. . . . . 274.6 Figure out the appearance. . 284.7 Getting all characters right. 304.8 Line numbers. . . . . . . . . 314.9 Captions. . . . . . . . . . . . 324.10 Margins and line shape. . . 334.11 Frames. . . . . . . . . . . . . 344.12 Indexing. . . . . . . . . . . . 364.13 Column alignment. . . . . . 374.14 Escaping to L
A
TEX. . . . . . 384.15 Interface to
definitions. . . . . . . 495.6
1
 
Preface
Transition of package maintenance
The TEX world lost contact with CarstenHeinz in late 2004, shortly after he released version 1.3b of the
listings
package.After many attempts to reach him had failed, Hendri Adriaens took over main-tenance of the package in accordance with the LPPL’s procedure for abandonedpackages. He then passed the maintainership of the package to Brooks Moses, whohad volunteered for the position while this procedure was going through.This release, version 1.4, is the first substantial bugfix release since I acceptedmaintainership of the package. I would like to thank the numerous people who re-ported bugs to me, and particularly those who suggested fixes. Thanks in additionto those who provided new language definitions and suggestions for improvements.
News and changes
Version 1.4 is the fourth bugfix release. There are nosubstantial changes in this version, but a number of minor changes and fixes. Theprimary news is that the documentation has been substantially copyedited, andimproved in a number of ways to document workarounds and things learned fromthe recent bug reports.A
numberbychapter
key has been added, to control whether listings are num-bered sequentially or by chapter in document classes that provide chapters.The
\lstMakeShortInline
command can be used to define single-characterinline-listing macros, much like the
shortvrb
package allows for verbatim inlinetext.A new
spaceflexible
column alignment style has been added, which is similarto the
flexible
style except that it only inserts extra space to recover the columnalignment at locations where there is already existing space.A
s
string type has been added, akin to the
s
comment type. This is used inthe Ruby language definition.The
\lst@for
routine has been sped up substantially, thanks to some codeprovided by Hendri Adriaens. Hopefully this will result in a significant speedupof the runtime of the overall package.Among the bugs fixed are the
*
option to
texcs
, which was quite badly broken;the interaction of background colors with inline listings and with frames; listingcaptions being broken in AMS document classes; and better integration of the listof listings with KOMAscript document class and other document clases that usethe
\float@addtolists
mechanism.The following languages were added:
command.com
(DOS/Windows) batchfiles, Common Intermediate Language, Lingo, Postscript, PSTricks, and SPARQL.The following dialects of existing languages were added: Ada (2005), Assembler(Motorola68k), and Mathematica (5.2). The definitions for ABAP, Fortran, Oc-tave, Python, Ruby, and TCL have been improved. Thanks go to the contributers.
Thanks
There are many people I have to thank for fruitful communication,posting their ideas, giving error reports, adding programming languages to
lstdrvrs.dtx
, and so on. Their names are listed in section3.4.
Trademarks
Trademarks appear throughout this documentation without anytrademark symbol; they are the property of their respective trademark owner.There is no intention of infringement; the usage is to the benefit of the trademarkowner.2
 
User’s guide
1 Getting started
1.1 A minimal file
Before using the
listings
package, you should be familiar with the L
A
TEX typesettingsystem. You need not to be an expert. Here is a minimal file for
listings
.
\documentclass{article}\usepackage{listings}\begin{document}\lstset{language=Pascal}% Insert Pascal examples here.\end{document}
Now type in this first example and run it through L
A
TEX.
Must I do that really? Yes and no. Some books about programming say this is good.What a mistake! Typing takes time—which is wasted if the code is clear to you. And if youneed that time to understand what is going on, the author of the book should reconsider theconcept of presenting the crucial things—you might want to say that about this guide even—or you’re simply inexperienced with programming. If only the latter case applies, you shouldspend more time on reading (good) books about programming, (good) documentations, and(good) source code from other people. Of course you should also make your own experiments.You will learn a lot. However, running the example through L
A
TEX shows whether the listingspackage is installed correctly.
The example doesn’t work. Are the two packages listings and keyval installed on yoursystem? Consult the administration tool of your TEX distribution, your system administrator,the local TEX and L
A
TEX guides, a TEX FAQ, and section4.19—in that order. If you’ve checked
all 
these sources and are still helpless, you might want to write a post to a TEX newsgrouplike
comp.text.tex
.
Should I read the software license before using the package? Yes, but read this
Getting started 
section first to decide whether you are willing to use the package.
1.2 Typesetting listings
Three types of source codes are supported: code snippets, code segments, andlistings of stand alone files. Snippets are placed inside paragraphs and the others asseparate paragraphs—the difference is the same as between text style and displaystyle formulas.
No matter what kind of source you have, if a listing contains national characters like ´e,  L, ¨a,or whatever, you must tell the package about it! Section
discusses thisissue.
Code snippets
The well-known L
A
TEX command
\verb
typesets code snippetsverbatim. The new command
\lstinline
pretty-prints the code, for example
var
i:
integer
;’ is typeset by ‘
\lstinline!var i:integer;!
’. The exclamationmarks delimit the code and can be replaced by any character not in the code;
\lstinline$var i:integer;$
gives the same result.3

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->