% \iffalse % % Trademarks appear throughout this documentation without any trademark % symbol, so you can't assume that a name is free. There is no intention % of infringement; the usage is to the benefit of the trademark owner. % % % S O F T W A R E L I C E N S E % ================================= % % The files listings.dtx and listings.ins and all files generated % from only these two files are referred to as `the listings package' % or simply `the package'. A `driver' is generated from lstdrvrs.dtx. % % Copyright. % The listings package is copyright 1996--2003 Carsten Heinz. The % language drivers are copyright 1997/1998/1999/2000/2001/2002/2003 % any individual author listed in the driver files. % % Distribution and warranty. % The listings package as well as lstdrvrs.dtx and all drivers are % distributed under the terms of the LaTeX Project Public License % from CTAN archives in directory macros/latex/base/lppl.txt. % Either version 1.0 or, at your option, any later version. % % Modification advice. % Permission is granted to modify the listings package as well as % lstdrvrs.dtx. You are not allowed to distribute a modified version % of the package or lstdrvrs.dtx unless you change the file names and % provide the original files. In any case it is better to contact the % address below; other users will welcome removed bugs, new features, % and additional programming languages. % % At your option. % To support further development, you might want to send me a copy of % your documents, relevant parts of it, or the crucial LaTeX sources. % Of course, I don't need examples of normal usage. % % If you distribute the package as part of a commercial product or % if you use the package to prepare a commercial document (books, % journals, and so on), I'd like to encourage you to make a donation % to the LaTeX3 fund. The size of this optional donation should depend % on the value of the package for your product. For more information % about LaTeX see % http://www.latex-project.org % % Contacts. % Send comments and ideas on the package, error reports and additional % programming languages to % % cheinz@gmx.de % % end of software license % % %<*driver> \documentclass[a4paper]{ltxdoc} \DisableCrossrefs \OnlyDescription \usepackage{lstdoc,textcomp} \makeindex \begin{document} \DocInput{listings.dtx} \end{document} % % \fi % %^^A %^^A Command/key to aspect relation %^^A ================================ %^^A %\lstisaspect[strings]{string,morestring,deletestring,stringstyle,showstringspaces} %\lstisaspect[comments]{comment,morecomment,deletecomment,commentstyle} %\lstisaspect[pod]{printpod,podcomment} %\lstisaspect[escape]{texcl,escapebegin,escapeend,escapechar,escapeinside,mathescape} %\lstisaspect[keywords]{sensitive,classoffset,keywords,morekeywords,deletekeywords,keywordstyle,ndkeywords,morendkeywords,deletendkeywords,ndkeywordstyle,keywordsprefix,otherkeywords} %\lstisaspect[emph]{emph,moreemph,deleteemph,emphstyle} %\lstisaspect[tex]{texcs,moretexcs,deletetexcs,texcsstyle} %\lstisaspect[directives]{directives,moredirectives,deletedirectives,directivestyle} %\lstisaspect[html]{tag,usekeywordsintag,tagstyle,markfirstintag} %\lstisaspect[keywordcomments]{keywordcomment,morekeywordcomment,deletekeywordcomment,keywordcommentsemicolon} %\lstisaspect[index]{index,moreindex,deleteindex,indexstyle,\string\lstindexmacro} %\lstisaspect[procnames]{procnamestyle,indexprocnames,procnamekeys,moreprocnamekeys,deleteprocnamekeys} %\lstisaspect[style]{style,\string\lstdefinestyle,\string\lst@definestyle,\string\lststylefiles} %\lstisaspect[language]{language,alsolanguage,defaultdialect,\string\lstalias,\string\lstdefinelanguage,\string\lst@definelanguage,\string\lstloadlanguages,\string\lstlanguagefiles} %\lstisaspect[formats]{format,fmtindent,\string\lstdefineformat,\string\lst@defineformat,\string\lstformatfiles} %\lstisaspect[labels]{numbers,numberstyle,numbersep,stepnumber,numberblanklines,firstnumber,\string\thelstnumber,numberfirstline} %\lstisaspect[lineshape]{xleftmargin,xrightmargin,resetmargins,linewidth,lineskip,breaklines,breakindent,breakautoindent,prebreak,postbreak} %\lstisaspect[frames]{framexleftmargin,framexrightmargin,framextopmargin,framexbottommargin,backgroundcolor,fillcolor,rulecolor,rulesepcolor,rulesep,framerule,framesep,frameshape,frameround,frame} %\lstisaspect[make]{makemacrouse} %\lstisaspect[fancyvrb]{fancyvrb,fvcmdparams,morefvcmdparams} %\lstisaspect[lgrind]{lgrindef,\string\lstlgrindeffile} %\lstisaspect[hyper]{hyperref,morehyperref,deletehyperref,hyperanchor,hyperlink} %\lstisaspect[kernel]{basewidth,fontadjust,columns,flexiblecolumns,identifierstyle,^^A % tabsize,showtabs,tab,showspaces,keepspaces,formfeed,SelectCharTable,^^A % MoreSelectCharTable,extendedchars,alsoletter,alsodigit,alsoother,excludedelims,^^A % literate,basicstyle,print,firstline,lastline,nolol,captionpos,abovecaptionskip,^^A % belowcaptionskip,label,title,caption,\string\lstlistingname,boxpos,float,^^A % floatplacement,aboveskip,belowskip,everydisplay,showlines,emptylines,gobble,name,^^A % \string\lstname,\string\lstlistlistingname,\string\lstlistoflistings,^^A % \string\lstnewenvironment,\string\lstinline,\string\lstinputlisting,lstlisting,^^A % \string\lstloadaspects,\string\lstset,\string\thelstlisting,\string\lstaspectfiles,^^A % inputencoding,delim,moredelim,deletedelim,upquote} %\lstisaspect[doc]{lstsample,lstxsample}^^A environment % %^^A %^^A The long awaited beginning of documentation %^^A ============================================= %^^A %\newbox\abstractbox %\setbox\abstractbox=\vbox{ % \begin{abstract} % The \packagename{listings} package is a source code printer for \LaTeX. % You can typeset stand alone files as well as listings with an environment % similar to \texttt{verbatim} as well as you can print code snippets using % a command similar to |\verb|. % Many parameters control the output and if your preferred programming % language isn't already supported, you can make your own definition. % \end{abstract}} % % \title{\vspace*{-2\baselineskip}The \textsf{Listings} Package} % \author{Copyright 1996--2003\\ Carsten Heinz \textless\lstemail\textgreater} % \date{2003/06/21\enspace\enspace Version 1.1\\ \box\abstractbox} % \def\lstemail{\href{mailto:cheinz@gmx.de}{\texttt{cheinz@gmx.de}}} % \ifhyper % \hypersetup{pdfsubject=Package guide,pdfauthor=Carsten Heinz } % \fi % % \csname @twocolumntrue\endcsname % \maketitle %^^A \enlargethispage{2\baselineskip} % \csname @starttoc\endcsname{toc} % \onecolumn % % % \section*{Preface} % % \paragraph{Reading this manual} % If you are experienced with the \packagename{listings} package, you should % read the next paragraph ``\emph{News and changes}''. Otherwise read section % \lstref{uGettingStarted} step by step and go on with section % \ref{uTheNextSteps}. % % \paragraph{News and changes} % This release mainly fixes bugs; only few keys have been added, refer the % table---some of them were already available to 1.0 via a patch file. % Please note that all experimental features and all \dag-marked keys might % change in future. % \begin{table}[hbp] % \footnotesize % \begin{center} % \begin{tabular}{@{}rlrl@{}} % \emph{1.0}&\emph{1.1}&\emph{1.0}&\emph{1.1}\\[1ex] % \texttt{keywordsinside} & \texttt{tag} (page \pageref{uoption:tag}) % & --- & \texttt{final}$^*$ (p.\,\pageref{uoption:final})\\ % --- & \texttt{tagstyle} (p.\,\pageref{uoption:tagstyle}) % & --- & \texttt{numberfirstline} (p.\,\pageref{uoption:numberfirstline})\\ % --- & \texttt{markfirstintag} (p.\,\pageref{uoption:markfirstintag}) % & --- & \texttt{upquote} (p.\,\pageref{uoption:upquote})\\ % \texttt{usekeywordsinside}& \texttt{usekeywordsintag} (p.\,\pageref{uoption:usekeywordsintag}) % & & \\ % & & --- & \texttt{fvcmdparams} (p.\,\pageref{uoption:fvcmdparams})\\ % & & --- & \texttt{morefvcmdparams} (p.\,\pageref{uoption:morefvcmdparams})\\[2ex] % \emph{0.21}&\emph{1.x}&\emph{0.21}&\emph{1.x}\\[1ex] % \texttt{first} & \texttt{firstline} & --- & \texttt{numbers}\\ % \texttt{last} & \texttt{lastline} & \texttt{labelstep} & \texttt{stepnumber}\\ % \texttt{stringspaces} & \texttt{showstringspaces} & \texttt{labelstyle} & \texttt{numberstyle}\\ % \texttt{visiblespaces} & \texttt{showspaces} & \cs{thelstlabel} & \cs{thelstnumber}\\ % \texttt{visibletabs} & \texttt{showtabs} & \texttt{labelsep} & \texttt{numbersep}\\ % \texttt{framerulewidth} & \texttt{framerule} & \texttt{firstlabel} & \texttt{firstnumber}\\ % \texttt{framerulesep} & \texttt{rulesep} & \texttt{advancelabel} & ---\\ % \texttt{frametextsep} & \texttt{framesep} & \texttt{spread} & ---\\ % \texttt{framespread} & superceded by & \texttt{indent} & \texttt{xleftmargin}$^3$\\ % & \texttt{framexleftmargin} & --- & \texttt{xrightmargin}\\ % & \texttt{framexrightmargin} & \texttt{wholeline} & \texttt{resetmargins}\\ % & \texttt{framextopmargin} & \texttt{defaultclass} & \texttt{classoffset}\\ % & \texttt{framexbottommargin} & \texttt{stringtest} & ---\\ % \texttt{framerulecolor} & \texttt{rulecolor}$^1$ & \texttt{outputpos} & ---\\ % --- & \texttt{columns}$^2$ % \end{tabular} % \end{center} % \parindent=20pt\relax % \par\indent $^*$ This is an option for package loading only. % \par\indent $^1$ \emph{All} color-keys require now an explicit \cs{color} command in the value. % \par\indent $^2$ Please look at section \ref{uFixedAndFlexibleColumns}. % \par\indent $^3$ Now frames are also moved! % \end{table} % % Since 2002/10/13 the following languages have been added: \texttt{erlang}, % \texttt{GCL}, \texttt{[AspectJ]Java}, \texttt{MetaPost}, \texttt{Mizar}, % \texttt{MuPAD}, \texttt{Reduce}, \texttt{Ruby}, \texttt{Scilab}, and % \texttt{Verilog}. Thanks go to the contributers. % % \vfill % \paragraph{Thanks} % There are many people I have to thank for fruitful communication, posting % their ideas, giving error reports, adding programming languages to % \texttt{lstdrvrs.dtx}, and so on. Their names are listed in section % \ref{uClosingAndCredits}. % % \paragraph{Trademarks} % Trademarks appear throughout this documentation without any trademark % symbol; they are the property of their respective trademark owner. % There is no intention of infringement; the usage is to the benefit of the % trademark owner. % % % \clearpage % % % \part{User's guide} % % % \section{Getting started}\label{uGettingStarted} % % % \subsection{A minimal file}\label{uAMinimalFile} % % Before using the \packagename{listings} package, you should be familiar with % the \LaTeX\ typesetting system. You need not to be an expert. % Here is a minimal file for \packagename{listings}. % \begin{verbatim} % \documentclass{article} % \usepackage{listings} % % \begin{document} % \lstset{language=Pascal} % % % Insert Pascal examples here. % % \end{document}\end{verbatim} % Now type in this first example and run it through \LaTeX. % \begin{advise} % \item Must I do that really? % \advisespace % Yes and no. Some books about programming say this is good. % What a mistake! Typing takes time---wasted if the code is clear to % you. And if you need that time to understand what is going on, the % author of the book should reconsider the concept of presenting the % crucial things---you might want to say that about this guide even---or % you're simply unexperienced with programming. If only the latter case % applies, you should spend 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 \LaTeX\ % shows whether the \packagename{listings} package is installed. % \item The example doesn't work. % \advisespace % Are the two packages \packagename{listings} and \packagename{keyval} % installed on your system? Consult the administration tool of your % \TeX\ distribution, your system administrator, the local \TeX\ and % \LaTeX\ guides, a \TeX\ FAQ, and section \ref{rInstallation}---in % the given order. If you've checked \emph{all} these sources and are % still helpless, you might want to write a post to a \TeX\ newsgroup % like \texttt{comp.text.tex}. % \item Should I read the software license before using the package? % \advisespace % Yes, but read this \emph{Getting started} section first to decide % whether you are willing to use the package.^^A ;-) % \end{advise} % % % \subsection{Typesetting listings} % % Three types of source codes are supported: code snippets, code segments, and % listings of stand alone files; snippets are placed inside paragraphs and the % others as separate paragraphs---the difference is the same as between text % style and display style formulas. % \begin{advise} % \item No matter what kind of source you have, if a listing contains national % characters like \'e, \L, \"a, or whatever, you must tell it the % package! Section \lstref{uSpecialCharacters} discusses this issue. % \end{advise} % % \paragraph{Code snippets} % The well-known \LaTeX\ command |\verb| typesets code snippets verbatim. % The new command |\lstinline| pretty-prints the code, for example %`\lstinline!var i:integer;!' is typeset by %`{\rstyle|\lstinline|}|!var i:integer;!|'. The exclamation marks delimit % the code and can be replaced by any character not in the code; % |\lstinline$var i:integer;$| gives the same result. % % \paragraph{Displayed code} % The \texttt{lstlisting} environment typesets the enclosed source code. Like % most examples, the following one shows verbatim \LaTeX\ code on the right % and the result on the left. You might take the right-hand side, put it into % the minimal file, and run it through \LaTeX. % \begin{lstsample}[lstlisting]{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % It can't be easier. % \begin{advise} % \item That's not true. The name `\texttt{listing}' is shorter. % \advisespace % Indeed. But other packages already define environments with that name. % To be compatible with such packages, all commands and environments of % the \packagename{listings} package use the prefix `\texttt{lst}'. % \end{advise} % The environment provides an optional argument. It tells the package to % perform special tasks, for example, to print only the lines 2--5: % \begin{lstsample}{\lstset{frame=trbl,framesep=0pt}\label{gFirstKey=ValueList}}{} % \begin{lstlisting}[firstline=2, % lastline=5] % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item Hold on! Where comes the frame from and what is it good for? % \advisespace % You can put frames around all listings except code snippets. % You will learn it later. The frame shows that empty lines at the end % of listings aren't printed. This is line 5 in the example. % \item Hey, you can't drop my empty lines! % \advisespace % You can tell the package not to drop them: % The key `\ikeyname{showlines}' controls these empty lines and is % described in section \ref{rTypesettingListings}. Warning: First % read ahead on how to use keys in general. % \item I get obscure error messages when using `\ikeyname{firstline}'. % \advisespace % That shouldn't happen. Make a bug report as described in section % \lstref{uTroubleshooting}. % \end{advise} % % \paragraph{Stand alone files} % Finally we come to |\lstinputlisting|, the command used to pretty-print % stand alone files. It has one optional and one file name argument. % Note that you possibly need to specify the relative path to the file. % Here now the result is printed below the verbatim code since both together % don't fit the text width. % \begin{lstsample}{\lstset{comment=[l]\%,columns=fullflexible}}{\lstset{alsoletter=\\,emph=\\lstinputlisting,emphstyle=\rstyle}\lstaspectindex{\lstinputlisting}{}} % \lstinputlisting[lastline=4]{listings.sty} % \end{lstsample} % \begin{advise} % \item The spacing is different in this example. % \advisespace % Yes. The two previous examples have aligned columns, i.e.~columns with % identical numbers have the same horizontal position---this package % makes small adjustments only. The columns in the example here are not % aligned. This is explained in section \ref{uFixedAndFlexibleColumns} % (keyword: full flexible column format). % \end{advise} % % Now you know all pretty-printing commands and environments. It remains % to learn the parameters which control the work of the \packagename{listings} % package. This is, however, the main task. Here are some of them. % % % \subsection{Figure out the appearance}\label{gFigureOutTheAppearance} % % Keywords are typeset bold, comments in italic shape, and spaces in strings % appear as \textvisiblespace. You don't like these settings? Look at this: %\ifcolor % \begin{lstxsample}[basicstyle,keywordstyle,identifierstyle,commentstyle,stringstyle,showstringspaces] % \lstset{% general command to set parameter(s) % basicstyle=\small, % print whole listing small % keywordstyle=\color{black}\bfseries\underbar, % % underlined bold black keywords % identifierstyle=, % nothing happens % commentstyle=\color{white}, % white comments % stringstyle=\ttfamily, % typewriter type for strings % showstringspaces=false} % no special string spaces % \end{lstxsample} %\else % \begin{lstxsample}[basicstyle,keywordstyle,identifierstyle,commentstyle,stringstyle,showstringspaces] % \lstset{% general command to set parameter(s) % basicstyle=\small, % print whole listing small % keywordstyle=\bfseries\underbar, % % underlined bold keywords % identifierstyle=, % nothing happens % commentstyle=\itshape, % default % stringstyle=\ttfamily, % typewriter type for strings % showstringspaces=false} % no special string spaces % \end{lstxsample} %\fi % \begin{lstsample}{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} %\ifcolor % \begin{advise} % \item You've requested white coloured comments, but I can see the comment % on the left side. % \advisespace % There are a couple of possible reasons: % (1) You've printed the documentation on nonwhite paper. % (2) If you are viewing this documentation as a \texttt{.dvi}-file, your % viewer seems to have problems with colour specials. Try to print % the page on white paper. % (3) If a printout on white paper shows the comment, the colour % specials aren't suitable for your printer or printer driver. % Recreate the documentation and try it again---and ensure that % the \packagename{color} package is well-configured. % \end{advise} %\fi % The styles use two different kinds of commands. |\ttfamily| and |\bfseries| % both take no arguments but |\underbar| does; it underlines the following % argument. In general, the \emph{very last} command might read exactly one % argument, namely some material the package typesets. There's one exception. % The last command of \ikeyname{basicstyle} \emph{must not} read any % tokens---or you will get deep in trouble. % \begin{advise} % \item `|basicstyle=\small|' looks fine, but comments look really bad with % `|commentstyle=\tiny|' and empty basic style, say. % \advisespace % Don't use different font sizes in a single listing. % \item But I really want it! % \advisespace % No, you don't. %^^A The package adjusts internal data after selecting the basic style at %^^A the beginning of each listing. This is a problem if you change the %^^A font size for comments or strings, for example. %^^A Section \ref{rColumnAlignment} shows how to overcome this. %^^A But once again: Don't use different font sizes in a single listing %^^A unless you really know what you are doing. % \end{advise} % % \paragraph{Warning}\label{wStrikingStyles} % You should be very careful with striking styles; the last example is rather % moderate---it can get horrible. \emph{Always use decent highlighting.} % Unfortunately it is difficult to give more recommendations since they depend % on the type of document you're creating. Slides or other presentations often % require more striking styles than books, for example. % In the end, it's \emph{you} who have to find the golden mean! % % % \subsection{Seduce to use}\label{gSeduceToUse} % % You know all pretty-printing commands and some main parameters. Here now % comes a small and incomplete overview of other features. The table of % contents and the index also provide information. % % \paragraph{Line numbers} % are available for all displayed listings, e.g.~tiny numbers on the left, each % second line, with 5pt distance to the listing: % \begin{lstxsample}[numbers,numberstyle,stepnumber,numbersep] % \lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item I can't get rid of line numbers in subsequent listings. % \advisespace % `|numbers=none|' turns them off. % \item Can I use these keys in the optional arguments? % \advisespace % Of course. Note that optional arguments modify values for one % particular listing only: you change the appearance, step or distance % of line numbers for a single listing. The previous values are % restored afterwards. % \end{advise} % The environment allows you to interrupt your listings: you can end a listing % and continue it later with the correct line number even if there are other % listings in between. Read section \ref{uLineNumbers} for a thorough % discussion. % % \paragraph{Floating listings} % Displayed listings may float: % \begin{lstsample}{\lstset{frame=tb}}{} % \begin{lstlisting}[float,caption=A floating example] % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % Don't care about the parameter \ikeyname{caption} now. And if you put the % example into the minimal file and run it through \LaTeX, please don't wonder: % you'll miss the horizontal rules since they are described elsewhere. % \begin{advise} % \item \LaTeX's float mechanism allows to determine the placement of floats. % What's about that? % \advisespace % You can write `|float=tp|', for example. % \end{advise} % % \paragraph{Other features} % There are still features not mentioned so far: automatic breaking of long % lines, the possibility to use \LaTeX\ code in listings, automated indexing, % or personal language definitions. % One more little teaser? Here you are. But note that the result is not % produced by the \LaTeX\ code on the right alone. The main parameter is % hidden. % \begin{lstsample}{\lstset{literate={:=}{{$\gets$}}1 {<=}{{$\leq$}}1 {>=}{{$\geq$}}1 {<>}{{$\neq$}}1}}{} % \begin{lstlisting} % if (i<=0) then i := 1; % if (i>=0) then i := 0; % if (i<>0) then i := 0; % \end{lstlisting} % \end{lstsample} % % You're not sure whether you should use \packagename{listings}? % Read the next section! % % % \subsection{Alternatives} % % \begin{advise} % \item Why do you list alternatives? % \advisespace % Well, it's always good to know the competitors.^^A :-) % \item I've read the descriptions below and the \packagename{listings} package % seems to incorporate all the features. Why should I use one of the % other programs? % \advisespace % Firstly, the descriptions give a taste and not a complete overview, % secondly, \packagename{listings} lacks some properties, and, eventually, % you should use the program matching your needs most precisely. % \end{advise} % This package is certainly not the final utility for typesetting source code. % Other programs do their job very well---if you are not satisfied with % \packagename{listings}. Some are independent of \LaTeX, other come as % separate program plus \LaTeX\ package, and other more are packages which % don't pretty-print the source code. The second type inlcudes converters, % cross compilers, and preprocessors. Such programs create \LaTeX\ files % you can use in your document or stand alone ready-to-run \LaTeX\ files. % % Note that I'm not dealing with any literate programming tool here, which % could also be an alternative. However, you should have heard of the % \texttt{WEB} system, the tool Prof.~Donald E.~Knuth developed and made use % of to document and implement \TeX. % % \paragraph{\packagename{a2ps}} % started as `ASCII to PostScript' converter, but today you can invoke the % program with \texttt{--pretty-print=}\meta{language} option. If your % favourite programming language is not already supported, you can write your % own so-called style sheet. You can request line numbers, borders, headers, % multiple pages per sheet, and many more. You can even print symbols like % $\forall$ or $\alpha$ instead of their verbose forms. If you just want % program listings and not a document with some listings, this is the best % choice. % % Visit the home page at % \href{http://www.infres.enst.fr/~demaille/a2ps}^^A % {http://www.infres.enst.fr/\textasciitilde demaille/a2ps}. % % \paragraph{\packagename{LGrind}} % is a cross compiler and comes with many predefined programming languages. % For example, you can put the code on the right in your document, invoke % \packagename{LGrind} with \texttt{-e} option (and file names), and run the % created file through \LaTeX. You should get a result similar to the % left-hand side: % \begin{center} % \begin{minipage}{0.45\linewidth} %\iflgrind % \LGindent=0pt % \LGinlinefalse\LGbegin\lgrinde % \L{\LB{\K{for}_\V{i}:=\V{maxint}_\K{to}_\N{0}_\K{do}}} % \L{\LB{\K{begin}}} % \L{\LB{____\C{}\{_do_nothing_\}\CE{}}} % \L{\LB{\K{end};}} % \L{\LB{}} % \L{\LB{\V{Write}(\S{}{'}Case_insensitive_{'}\SE{});}} % \L{\LB{\V{WritE}(\S{}{'}Pascal_keywords.{'}\SE{});}} % \endlgrinde\LGend %\else % \packagename{LGrind} not installed. %\fi % \end{minipage} % \begin{minipage}{0.45\linewidth} % \begin{verbatim} % %[ % for i:=maxint to 0 do % begin % { do nothing } % end; % % Write('Case insensitive '); % WritE('Pascal keywords.'); % %]\end{verbatim} % \end{minipage} % \end{center} % If you use |%(| and |%)| instead of |%[| and |%]|, you get a code snippet % instead of a displayed listing. Moreover you can get line numbers to the % left or right, use arbitrary \LaTeX\ code in the source code, print symbols % instead of verbose names, make font setup, and more. You will (have to) % like it (if you don't like \packagename{listings}). % % Note that \packagename{LGrind} contains code with a no-sell license and is % thus nonfree software. It is available via ftp from % \href{ftp://ftp.dante.de/tex-archive/nonfree/support/lgrind} % {\textrm{CTAN}/nonfree/support/lgrind}. % % \paragraph{\packagename{cvt2ltx}} % is a family of `source code to \LaTeX' converters for C, Objective C, \Cpp, % IDL and Perl. Different styles, line numbers and other qualifiers can be % chosen by command-line option. Unfortunately it isn't documented how other % programming languages can be added. % % Available via ftp from % \href{ftp://axp3.sv.fh-mannheim.de/cvt2latex}^^A % {ftp://axp3.sv.fh-mannheim.de/cvt2latex}. % % \paragraph{\packagename{\Cpp2\LaTeX}} % is a C/\Cpp\ to \LaTeX\ converter. You can specify the fonts for comments, % directives, keywords, and strings, or the size of a tabulator. But as far as % I know you can't number lines. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/support/C++2LaTeX-1_1pl1}^^A % {\textrm{CTAN}/support/C++2LaTeX-1\textunderscore 1pl1}. % % \paragraph{\packagename{S\LaTeX}} % is a pretty-printing Scheme program (invokes \LaTeX\ automatically) % especially designed for Scheme and other Lisp dialects. It supports stand % alone files, text and display listings, and you can even nest the % commands/environments if you use \LaTeX\ code in comments, for example. % Keywords, constants, variables, and symbols are definable and use of % different styles is possible. No line numbers. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/support/slatex}^^A % {\textrm{CTAN}/support/slatex}. % % \paragraph{\packagename{tiny\textunderscore c2ltx}} % is a C/\Cpp/Java to \LaTeX\ converter based on \packagename{cvt2ltx} (or the % other way round?). It supports line numbers, block comments, \LaTeX\ code % in/as comments, and smart line breaking. Font selection and tabulators are % hard-coded, i.e.~you have to rebuild the program if you want to change the % appearance. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/support/tiny_c2l}^^A % {\textrm{CTAN}/support/tiny\textunderscore c2l}. % % \paragraph{\packagename{listing}} % ---note the missing \packagename{s}---is not a pretty-printer and the % aphorism about documentation at the end of \texttt{listing.sty} is not % true.\space ^^A :-) % It defines |\listoflistings| and a nonfloating environment for listings. % All font selection and indention must be done by hand. However, it's % useful if you have another tool doing that work, e.g.~\packagename{LGrind}. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/other/misc}^^A % {\textrm{CTAN}/macros/latex/contrib/other/misc}. % % \paragraph{\packagename{alg}} % provides essentially the same functionality as \packagename{algorithms}. % So read the next paragraph and note that the syntax will be different. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/other/alg}^^A % {\textrm{CTAN}/macros/latex/contrib/other/alg}. % % \paragraph{\packagename{algorithms}} % goes a quite different way. You describe an algorithm and the package % formats it, for example % \begin{center} % \begin{minipage}{0.45\linewidth} %\ifalgorithmic % \begin{algorithmic} % \IF {$i\leq0$} % \STATE $i\gets1$ % \ELSE\IF {$i\geq0$} % \STATE $i\gets0$ % \ENDIF\ENDIF % \end{algorithmic} %\else % \packagename{algorithms} not installed. %\fi % \end{minipage} % \begin{minipage}{0.45\linewidth} % \begin{verbatim} %\begin{algorithmic} %\IF{$i\leq0$} %\STATE $i\gets1$ %\ELSE\IF{$i\geq0$} %\STATE $i\gets0$ %\ENDIF\ENDIF %\end{algorithmic}\end{verbatim} % \end{minipage} % \end{center} % As this example shows, you get a good looking algorithm even from a bad % looking input. The package provides a lot more constructs like |for|-loops, % |while|-loops, or comments. You can request line numbers, `ruled', `boxed' % and floating algorithms, a list of algorithms, and you can customize the % terms \textbf{if}, \textbf{then}, and so on. % % Available from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/supported/algorithms}^^A % {\textrm{CTAN}/macros/latex/contrib/supported/algorithms}. % % \paragraph{\packagename{pretprin}} % is a package for pretty-printing texts in formal languages---as the title % in TUGboat, Volume 19 (1998), No.~3 states. It provides environments which % pretty-print \emph{and} format the source code. Analyzers for Pascal and % Prolog are defined; adding other languages is easy---if you are or get a bit % familiar with automatons and formal languages. % % Available from % \href{http://www.mimuw.edu.pl/~wolinski/pretprin.html}^^A % {http://www.mimuw.edu.pl/\textasciitilde wolinski/pretprin.html}. % % \paragraph{\packagename{alltt}} % defines an environment similar to \texttt{verbatim} except that |\|, |{| and % |}| have their usual meanings. This means that you can use commands in the % verbatims, e.g.~select different fonts or enter math mode. % % This package is part of the \LaTeX\ base distribution. % % \paragraph{\packagename{moreverb}} % requires \packagename{verbatim} and provides verbatim output to a file, % `boxed' verbatims and line numbers. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/supported/moreverb}^^A % {\textrm{CTAN}/macros/latex/contrib/supported/moreverb}. % % \paragraph{\packagename{verbatim}} % defines an improved version of the standard \texttt{verbatim} environment and % a command to input files verbatim. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/required/tools}^^A % {\textrm{CTAN}/macros/latex/required/tools}. % % \paragraph{\packagename{fancyvrb}} % is, roughly spoken, a super set of \packagename{alltt}, % \packagename{moreverb}, and \packagename{verbatim}, but many more parameters % control the output. The package provides frames, line numbers on the left or % on the right, automatic line breaking (difficult), and more. For example, an % interface to \packagename{listings} exists, i.e.~you can pretty-print source % code automatically. % The package \packagename{fvrb-ex} builds above \packagename{fancyvrb} and % defines environments to present examples similar to the ones in this guide. % % Available via ftp from % \href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/supported/fancyvrb}^^A % {\textrm{CTAN}/macros/latex/contrib/supported/fancyvrb}. % % % \section{The next steps}\label{uTheNextSteps} % % Now, before actually using the \packagename{listings} package, you should % \emph{really} read the software license. It does not cost much time and % provides information you probably need to know. % % % \subsection{Software license}\label{uSoftwareLicense} % % The files \texttt{listings.dtx} and \texttt{listings.ins} and all % files generated from only these two files are referred to as `the % \packagename{listings} package' or simply `the package'. A `driver' % is generated from \texttt{lstdrvrs.dtx}. % % \paragraph{Copyright} % The \packagename{listings} package is copyright 1996--2003 Carsten Heinz. % The drivers are copyright any individual author listed in the driver files. % % \paragraph{Distribution} % The \packagename{listings} package as well as \texttt{lstdrvrs.dtx} and all % drivers are distributed under the terms of the \LaTeX\ Project Public % License from CTAN archives in directory |macros/latex/base/lppl.txt|, % either version 1.0 or any later version. % % \paragraph{Modification advice} % Permission is granted to modify the \packagename{listings} package as well % as \texttt{lstdrvrs.dtx}. You are not allowed to distribute a modified % version of the \packagename{listings} package or \texttt{lstdrvrs.dtx} % unless you change the file names \emph{and} provide the original files. % In any case it is better to contact the address below; other users will % welcome removed bugs, new features, and additional programming languages. % % \paragraph{At your option} % To support further development, you might want to send me a copy of % your documents, relevant parts of it, or the crucial \LaTeX{} sources. % Of course, I don't need examples of normal usage. % % If you distribute the package as part of a commercial product or % if you use the package to prepare a commercial document (books, % journals, and so on), I'd like to encourage you to make a donation % to the \LaTeX3 fund. The size of this optional donation should depend % on the value of the package for your product. For more information % about \LaTeX3 see % \href{http://www.latex-project.org}^^A % {http://www.latex-project.org}. % % \paragraph{Contacts} % Read section \lstref{uTroubleshooting} on how to submit a bug report. % Send all other comments, ideas, and additional programming languages to % \emph{Carsten Heinz, Tellweg 6, 42275 Wuppertal, Germany} or preferably to % \lstemail\ using \texttt{listings} as part of the subject. % % \paragraph{Mailing list} % This is mainly an announcement list regarding new versions, bugs, patches, % and work-arounds. So I recommend it for system administrators, maintainers % of \LaTeX\ installations, or people who absolutely need the latest bugs. % To join the list, send an email to \lstemail\ with subject % \texttt{subscribe listings}. % % % \subsection{Package loading}\label{uPackageLoading} % % As usual in \LaTeX, the package is loaded by % |\usepackage[|\meta{options}|]{listings}|, % where |[|\meta{options}|]| is optional and gives a comma separated list of % options. Each either loads an additional \packagename{listings} aspect, or % changes default properties. Usually you don't have to take care of such % options. But in some cases it could be necessary: if you want to compile % documents created with an earlier version of this package or if you use % special features. Here's an incomplete list of possible options. % \begin{advise} % \item Where is a list of all options? % \advisespace % In the developer's guide since they were introduced to debug the % package more easily. Read section \ref{uHowTos} on how to get that % guide. % \end{advise} % \begin{description} % \item[\normalfont\texttt{0.21}]\leavevmode % % compiles a document created with version 0.21. % % \item[\normalfont\texttt{draft}]\leavevmode % % The package prints no stand alone files, but shows the captions and % defines the corresponding labels. % Note that a global |\documentclass|-option \texttt{draft} is % recognized, so you don't need to repeat it as a package option. % % \item[\normalfont\texttt{final}]\leavevmode\label{uoption:final} % % Overwrites a global \texttt{draft} option. % % \item[\normalfont\texttt{savemem}]\leavevmode % % tries to save some of \TeX's memory. If you switch between languages % often, it could also reduce compile time. But all this depends on the % particular document and its listings. % \end{description} % Note that various experimental features also need explicit loading via % options. Read the respective lines in section \ref{rExperimentalFeatures}. % % \medbreak % After package loading it is recommend to load all used dialects of programming % languages with the following command. It is faster to load several languages % with one command than loading each language on demand. % \begin{syntax} % \item {\rstyle\icmdname\lstloadlanguages}\marg{comma separated list of languages} % % Each language is of the form \oarg{dialect}\meta{language}. Without % the optional \oarg{dialect} the package loads a default dialect. So % write `|[Visual]C++|' if you want Visual \Cpp\ and `|[ISO]C++|' for % ISO \Cpp. Both together can be loaded by the command % |\lstloadlanguages{[Visual]C++,[ISO]C++}|. % % Table \ref{uPredefinedLanguages} on page \pageref{uPredefinedLanguages} % shows all defined languages and their dialects. % \end{syntax} %^^A After or even before language loading, you might want to define default %^^A dialects---just to be independent of configuration files. % % % \subsection{The key=value interface}\label{uTheKey=ValueInterface} % % This package uses the \packagename{keyval} package from the % \packagename{graphics} bundle by David Carlisle. Each parameter is % controlled by an associated key and a user supplied value. For example, % \ikeyname{firstline} is a key and |2| a valid value for this key. % % The command {\rstyle\icmdname\lstset} gets a comma separated list of % ``key|=|value'' pairs. The first list with more than a single entry is on % page \pageref{gFirstKey=ValueList}: |firstline=2,lastline=5|. % \begin{advise} % \item So I can write `|\lstset{firstline=2,lastline=5}|' once for all? % \advisespace % No. `\ikeyname{firstline}' and `\ikeyname{lastline}' belong to a small % set of % keys which are used on individual listings. However, your command is % not illegal---it has no effect. You have to use these keys inside the % optional argument of the environment or input command. % \item What's about a better example of a key|=|value list? % \advisespace % There is one in section \ref{gFigureOutTheAppearance}. % \item `|language=[77]Fortran|' does not work inside an optional argument. % \advisespace % You must put braces around the value if a value with optional argument % is used inside an optional argument. In the case here write % `|language={[77]Fortran}|' to select Fortran 77. % \item If I use the `\ikeyname{language}' key inside an optional argument, the % language isn't active when I typeset the next listing. % \advisespace % All parameters set via `|\lstset|' keep their values up to the end of % the current environment or group. Afterwards the previous values are % restored. The optional parameters of the two pretty-printing commands % and the `\texttt{lstlisting}' environment take effect on the particular % listing only, i.e.~values are restored immediately. For example, you % can select a main language and change it for special listings. % \item \icmdname\lstinline\ has an optional argument? % \advisespace % Yes. And from this fact comes a limitation: you can't use the left % bracket `|[|' as delimiter except you specify at least an empty % optional argument as in `|\lstinline[][var i:integer;[|'. % If you forget this, you will either get a ``runaway argument'' error % from \TeX, or an error message from the \packagename{keyval} package. % \end{advise} % % % \subsection{Programming languages}\label{uProgrammingLanguages} % % You already know how to activate programming languages---at least Pascal. % An optional parameter selects particular dialects of a language. For example, % |language=[77]Fortran| selects Fortran 77 and |language=[XSC]Pascal| does the % same for Pascal XSC. The general form is % {\rstyle\ikeyname{language}}|=|\oarg{dialect}\meta{language}. % If you want to get rid of keyword, comment, and string detection, use % |language={}| as argument to |\lstset| or as optional argument. % % Table \ref{uPredefinedLanguages} shows all predefined languages and dialects. % Use the listed names as \meta{language} and \meta{dialect}, respectively. If % no dialect or `empty' is given in the table, just don't specify a dialect. % Each underlined dialect is default; it is selected if you leave out % the optional argument. The predefined defaults are the newest language % versions or standard dialects. %^^A %^^A Make table of predefined languages. %^^A %\let\lstlanguages\empty %\makeatletter %\@for\lst@temp:={lstlang1.sty,lstlang2.sty,lstlang3.sty}\do % {\IfFileExists\lst@temp{}{\let\lstlanguages\relax}} %\makeatother %\ifx\lstlanguages\relax % \PackageWarningNoLine{Listings} % {Standard drivers not available.\MessageBreak % Please check your installation.\MessageBreak % Compilation aborted} % \csname @@end\expandafter\endcsname %\fi %\lstscanlanguages\lstlanguages{lstlang1.sty,lstlang2.sty,lstlang3.sty}{}^^A %\def\topfigrule{\hrule\kern-0.4pt\relax}^^A %\let\botfigrule\topfigrule %\belowcaptionskip=\smallskipamount % \begin{table}[tb] % \small % \caption{Predefined languages. % Note that some definitions are preliminary, for example HTML and XML. % Each underlined dialect is default dialect}\label{uPredefinedLanguages}^^A % \makeatletter % \setbox\@tempboxa\hbox{^^A % \InputIfFileExists{listings.cfg}{\lst@InputCatcodes}{}}^^A % \lstprintlanguages\lstlanguages % \end{table} %^^A %^^A end of table %^^A %\lstset{defaultdialect=[doc]Pascal}^^A restore % \begin{advise} % \item How can I define default dialects? % \advisespace % Check section \ref{rLanguagesAndStyles} for `\keyname{defaultdialect}'. % \item I have C code mixed with assembler lines. Can \packagename{listings} % pretty-print such source code, i.e.~highlight keywords and comments of % both languages? % \advisespace % `\ikeyname{alsolanguage}|=|\oarg{dialect}\meta{language}' selects a % language additionally to the active one. So you only have to write a % language definition for your assembler dialect, which doesn't interfere % with the definition of C, say. Moreover you might want to use the key % `\keyname{classoffset}' described in section \ref{rLanguagesAndStyles}. % \item How can I define my own language? % \advisespace % This is discussed in section \ref{rLanguageDefinitions}. And if you % think that other people could benefit by your definition, you might % want to send it to the address in section \ref{uSoftwareLicense}. % Then it will be published under the \LaTeX\ Project Public License. % \end{advise} % Note that the arguments \meta{language} and \meta{dialect} are case % insensitive and that spaces have no effect. % % % \subsection{Special characters}\label{uSpecialCharacters} % % % \paragraph{Tabulators} % You might get unexpected output if your sources contain tabulators. % The package assumes tabulator stops at columns 9, 17, 25, 33, and so on. % This is predefined via |tabsize=8|. If you change the eight to the number % $n$, you will get tabulator stops at columns $n+1,2n+1,3n+1,$ and so on. % \begin{lstsample}[tabsize]{}{} % \lstset{tabsize=2} % \begin{lstlisting} % 123456789 % { one tabulator } % { two tabs } % 123 { 123 + two tabs } % \end{lstlisting} % \end{lstsample} % For better illustration, the left-hand side uses |tabsize=2| but the verbatim % code |tabsize=4|. Note that |\lstset| modifies the values for all following % listings in the same environment or group. This is no problem here since the % examples are typeset inside minipages. If you want to change settings for a % single listing, use the optional argument. % % % \paragraph{Visible tabulators and spaces} % One can make spaces and tabulators visible: % \begin{lstsample}[showspaces,showtabs,tab]{}{} % \lstset{showspaces=true, % showtabs=true, % tab=\rightarrowfill} % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % If you request \ikeyname{showspaces} but no \ikeyname{showtabs}, % tabulators are converted to visible spaces. % The default definition of \ikeyname{tab} produces a `wide visible space' % \lstinline[showtabs]! !. So you might want to use |$\to$|, |$\dashv$| % or something else instead. % \begin{advise} % \item Some sort of advice: (1) You should really indent lines of source code % to make listings more readable. (2) Don't indent some lines with % spaces and others via tabulators. Changing the tabulator size (of your % editor or pretty-printing tool) completely disturbs the columns. % (3) As a consequence, never share your files with differently tab sized % people!^^A true only if you use tabulators, just :-) % \item To make the \LaTeX\ code more readable, I indent the environments' % program listings. How can I remove that indention in the output? % \advisespace % Read `How to gobble characters' in section \ref{uHowTos}. % \end{advise} % % % \paragraph{Form feeds} % Another special character is a form feed causing an empty line by default. % {\rstyle\ikeyname{formfeed}}|=\newpage| would result in a new page every % form feed. Please note that such definitions (even the default) might get % in conflict with frames. % % % \paragraph{National characters} % If you type in such characters directly as characters of codes 128--255 and % use them also in listings, let the package know it---or you'll get really % funny results. {\rstyle\ikeyname{extendedchars}}|=true| allows and % |extendedchars=false| prohibits extended characters in listings. If you use % them, you should load \packagename{fontenc}, \packagename{inputenc} and/or % any other package which defines the characters. % \begin{advise} % \item I have problems using \packagename{inputenc} together with % \packagename{listings}. % \advisespace % This could be a compatibility problem. Make a bug report as described % in section \lstref{uTroubleshooting}. % \end{advise} % The extended characters don't cover Arabic, Chinese, Hebrew, Japanese, and so % on. Read section \ref{uNationalCharacters} for details on work-arounds. % % % \subsection{Line numbers}\label{uLineNumbers} % % You already know the keys \ikeyname{numbers}, \ikeyname{numberstyle}, % \ikeyname{stepnumber}, and \ikeyname{numbersep} from section % \ref{gSeduceToUse}. Here now we deal with continued listings. % You have two options to get consistent line numbering across listings. % % \begin{lstsample}[firstnumber]{\lstset{numbers=left,numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} % \begin{lstlisting}[firstnumber=100] % for i:=maxint to 0 do % begin % { do nothing } % end; % % \end{lstlisting} % And we continue the listing: % \begin{lstlisting}[firstnumber=last] % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % In the example, \ikeyname{firstnumber} is initially set to 100; some lines % later the value is \texttt{last}, which continues the numbering of the last % listing. Note that the empty line at the end of the first part is not printed % here, but it counts for line numbering. You should also notice that you can % write |\lstset{firstnumber=last}| once and get consecutively numbered code % lines---except you specify something different for a particular listing. % % On the other hand you can use |firstnumber=auto| and name your listings. % Listings with identical names (case sensitive!) share a line counter. % \begin{lstsample}[name]{\lstset{numbers=left,numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} % \begin{lstlisting}[name=Test] % for i:=maxint to 0 do % begin % { do nothing } % end; % % \end{lstlisting} % And we continue the listing: % \begin{lstlisting}[name=Test] % Write('Case insensitive '); % WritE('Pascal keywords.'); % \end{lstlisting} % \end{lstsample} % The next |Test| listing goes on with line number {\makeatletter\lstno@Test}, % no matter whether there are other listings in between. % \begin{advise} % \item Okay. And how can I get decreasing line numbers? % \advisespace % Sorry, what? % \advisespace % Decreasing line numbers as on page \pageref{rDecreasingLabels}. % \advisespace % May I suggest to demonstrate your individuality by other means? % If you differ, you should try a negative `\ikeyname{stepnumber}' % (together with `\ikeyname{firstnumber}'). % \end{advise} % % Read section \ref{uHowTos} on how to reference line numbers. % % % \subsection{Layout elements} % % It's always a good idea to structure the layout by vertical space, % horizontal lines, or different type sizes and typefaces. The best to stress % whole listings are---not all at once---colours, frames, vertical space, and % captions. The latter are also good to refer to listings, of course. % % \paragraph{Vertical space} % The keys {\rstyle\ikeyname{aboveskip}} and {\rstyle\ikeyname{belowskip}} % control the vertical space above and below displayed listings. Both keys get % a dimension or skip as value and are initialized to |\medskipamount|. % % \paragraph{Frames} % The key \ikeyname{frame} takes the verbose values \keyvalue{none}, % \keyvalue{leftline}, \keyvalue{topline}, \keyvalue{bottomline}, % \keyvalue{lines} (top and bottom), \keyvalue{single} for single frames, or % \keyvalue{shadowbox}. % \begin{lstsample}[frame]{}{} % \begin{lstlisting}[frame=single] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item The rules aren't aligned. % \advisespace % This could be a bug of this package or a problem with your % \texttt{.dvi} driver. \emph{Before} sending a bug report to the package % author, modify the parameters described in section \ref{rFrames} % heavily. And do this step by step! % For example, begin with `|framerule=10mm|'. If the rules are % misaligned by the same (small) amount as before, the problem does not % come from the rule width. So continue with the next parameter. % \end{advise} % Alternatively you can control the rules at the \texttt{t}op, \texttt{r}ight, % \texttt{b}ottom, and \texttt{l}eft directly by using the four initial letters % for single rules and their upper case versions for double rules. % \begin{lstsample}[frame]{}{} % \begin{lstlisting}[frame=trBL] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % Note that a corner is drawn if and only if both adjacent rules are requested. % You might think that the lines should be drawn up to the edge, but what's % about round corners? The key \ikeyname{frameround} must get exactly four % characters as value. The first character is attached to the upper right % corner and it continues clockwise. `\texttt{t}' as character makes the % corresponding corner round. % \begin{lstsample}[frameround]{}{} % \lstset{frameround=fttt} % \begin{lstlisting}[frame=trBL] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % Note that \ikeyname{frameround} has been used together with |\lstset| and thus % the value affects all following listings in the same group or environment. % Since the listing is inside a \texttt{minipage} here, this is no problem. % \begin{advise} % \item Dont' use frames all the time, in particular not with short listings. % This would emphasize nothing. Use frames for $10\%$ or even less of % your listings, for your most important ones. % \item If you use frames on floating listings, do you really want frames? % \advisespace % No, I want to separate floats from text. % \advisespace % Then it is better to redefine \LaTeX's `|\topfigrule|' and % `|\botfigrule|'. For example, you could write % `|\renewcommand*\topfigrule{\hrule\kern-0.4pt\relax}|' and make the % same definition for |\botfigrule|. % \end{advise} % % \paragraph{Captions} % Now we come to \ikeyname{caption} and \ikeyname{label}. You might guess that % they can be used in the same manner as \LaTeX's |\caption| and |\label| % commands: % \begin{lstsample}[caption,label]{\lstset{xleftmargin=.05\linewidth}}{} % \begin{lstlisting}[caption={Useless code},label=useless] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % Afterwards you could refer to the listing via |\ref{useless}|. By default % such a listing gets an entry in the list of listings, which can be printed % with the command {\rstyle\icmdname\lstlistoflistings}. The key % {\rstyle\ikeyname{nolol}} suppresses an entry for both the environment or % the input command. Moreover, you can specify a short caption for the list % of listings: % \keyname{caption}|={|\oarg{short}\meta{long}|}|. % Note that the whole value is enclosed in braces since an optional value is % used in an optional argument. % % If you don't want the label \texttt{\lstlistingname} plus number, you should % use \ikeyname{title}: % \begin{lstsample}[title]{\lstset{xleftmargin=.05\linewidth}}{} % \begin{lstlisting}[title={`Caption' without label}] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item Something goes wrong with `\keyname{title}' in my document: in front of % the title is a delimiter. % \advisespace % The result depends on the document class; some are not compatible. % Contact the package author for a work-around. % \end{advise} % % \paragraph{Colours} % One more element. You need the \packagename{color} package and can then % request coloured background via % \ikeyname{backgroundcolor}|=|\meta{color command}. % \begin{advise} % \item Great! I love colours. % \advisespace % Fine, yes, really. And I like to remind you of the warning about % striking styles on page \pageref{wStrikingStyles}. % \end{advise} %\ifcolor % \begin{lstxsample}[backgroundcolor] % \lstset{backgroundcolor=\color{yellow}} % \end{lstxsample} %\else % \begin{verbatim} % color package not installed\end{verbatim} %\fi % \begin{lstsample}{}{} % \begin{lstlisting}[frame=single, % framerule=0pt] % for i:=maxint to 0 do % begin % j:=square(root(i)); % end; % \end{lstlisting} % \end{lstsample} % The example also shows how to get coloured space around the whole listing: % use a frame whose rules has no width. % % % \subsection{Emphasize identifiers}\label{uEmphasizeIdentifiers} % % Recall the pretty-printing commands and environment. |\lstinline| prints % code snippets, |\lstinputlisting| whole files, and \texttt{lstlisting} % pieces of code which reside in the \LaTeX\ file. And what are these % different `types' of source code good for? Well, it just happens that a % sentence contains a code fragment. Whole files are typically included in or % as an appendix. Nevertheless some books about programming also include such % listings in normal text sections---to increase the number of pages. % Nowadays source code should be shipped on disk or CD-ROM and only the main % header or interface files should be typeset for reference. So, please, don't % misuse the \packagename{listings} package. But let's get back to the topic. % % Obviously `\texttt{lstlisting} source code' isn't used to make an executable % program from. Such source code has some kind of educational purpose or even % didactic. % \begin{advise} % \item What's the difference between educational and didactic? % \advisespace % Something educational can be good or bad, true or false. % Didactic is true by definition.^^A :-) % \end{advise} % Usually \emph{keywords} are highlighted when the package typesets a piece of % source code. This isn't necessary for readers knowing the programming % language well. The main matter is the presentation of interface, library or % other functions or variables. If this is your concern, here come the right % keys. Let's say, you want to emphasize the functions |square| and |root|, % for example, by underlining them. Then you could do it like this: % \begin{lstxsample}[emph,emphstyle] % \lstset{emph={square,root},emphstyle=\underbar} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % j:=square(root(i)); % end; % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item Note that the list of identifiers |{square,root}| is enclosed in % braces. Otherwise the \packagename{keyval} package would complain % about an undefined key \keyname{root} since the comma finishes the % key=value pair. % Note also that you \emph{must} put braces around the value if you % use an optional argument of a key inside an optional argument of a % pretty-printing command. Though it is not necessary, the following % example uses these braces. They are typically forgotten when they % become necessary, % \end{advise} % % Both keys have an optional \meta{class number} argument for multiple % identifier lists: %\ifcolor % \begin{lstxsample}[emph,emphstyle] % \lstset{emph={square}, emphstyle=\color{red}, % emph={[2]root,base},emphstyle={[2]\color{blue}}} % \end{lstxsample} %\else % \begin{lstxsample}[emph,emphstyle] % \lstset{emph={square}, emphstyle=\underbar, % emph={[2]root,base},emphstyle={[2]\fbox}} % \end{lstxsample} %\fi % \begin{lstsample}{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % j:=square(root(i)); % end; % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item What is the maximal \meta{class number}? % \advisespace % $2^{31}-1=2\,147\,483\,647$. But \TeX's memory will exceed before you % can define so many different classes. % \end{advise} % % One final hint: Keep the lists of identifiers disjoint. Never use a keyword % in an `emphasize' list or one name in two different lists. Even if your % source code is highlighted as expected, there is no guarantee that it is % still the case if you change the order of your listings or if you use the % next release of this package. % % %\iffalse % \subsection{*Listing alignment}\label{uListingAlignment} % % The examples are typeset with centered \texttt{minipage}s. That's the reason % why you can't see that line numbers are printed in the margin. Now we % separate the minipage margin and the minipage by a vertical rule: % \begin{lstsample}{\lstset{frame=l,framesep=0pt,numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} % Some text before % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % The listing is lined up with the normal text. The parameter \ikeyname{xleftmargin} % moves the listing to the right (or left if the dimension is negative). % \begin{lstsample}{\lstset{frame=l,framesep=0pt,numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} % Some text before % \begin{lstlisting}[xleftmargin=15pt] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % % \begin{lstlisting}{ } % Write('Insensitive'); % WritE('keywords.'); % \end{lstlisting} % \end{lstsample} % Note again that optional arguments change settings for single listings. % % If you use environments like \texttt{itemize} or \texttt{enumerate}, there % is `natural' indention coming from these environments. By default the % \packagename{listings} package respects this. But you might use % |resetmargins=true| (or |false|) to make your own decision. You can use it % together with |xleftmargin|, of course. % \begin{advise} % \item I get heavy overfull |\hbox|es from some listings. % \advisespace % This comes from long lines in your listings. You have some options % to get rid of the overful |\hbox|es. Firstly I recommend to typeset % listings in smaller fonts than the surrounding text, for example % `|basicstyle=\small|'. Secondly you might want to use the flexible % column format. Thirdly you can increase the line width or set it % explicitly, refer section \ref{rMarginsAndLineShape}. % If all this doesn't help, you might want to change % `\ikeyname{basewidth}', but be careful! The two unknown items are % explained in the next section. % \end{advise} % % You might need to control the vertical position of listings with the % \ikeyname{boxpos} key, for example, if you use them in \texttt{minipage} or % \texttt{tabular} environments. Here `listings' means \texttt{lstlisting} or % |\lstinputlisting|. As the following example shows, you can even place such % listings inside paragraphs, but you must force the package to do this by % enclosing the listing in |\hbox{| and |}|. % \begin{advise} % \item Is it good form to use the \TeX-primitive `|\hbox|' in a \LaTeX\ % document? % \advisespace % No, it's not. But \LaTeX's `|\mbox|' does not work in this example: % \end{advise} % \begin{lstsample}{}{} % Here are some multi-line listings inside a paragraph. % The `boxpos' key controls their vertical alignment: % \hbox{\begin{lstlisting}[boxpos=c] % center % center % \end{lstlisting}} % \hbox{\begin{lstlisting}[boxpos=b] % bottom baseline % bottom baseline % \end{lstlisting}} % \hbox{\begin{lstlisting}[boxpos=t] % top baseline % top baseline % \end{lstlisting}} % \end{lstsample} %\fi % % % \subsection{Indexing}\label{uIndexing} % % is just like emphasizing identifiers---I mean the usage: % \begin{lstxsample}[index] % \lstset{index={square},index={[2]root}} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % j:=square(root(i)); % end; % \end{lstlisting} % \end{lstsample} % Of course, you can't see anything here. You will have to look at the index. % \begin{advise} % \item Why the `\ikeyname{index}' key is able to work with multiple identifier % lists? % \advisespace % This question is strongly related to the `{\rstyle\ikeyname{indexstyle}}' % key. Someone might want to create multiple indexes or want to insert % prefixes like `|constants|', `|functions|', `|keywords|', and so on. % The `\ikeyname{indexstyle}' key works like the other style keys except % that the last token \emph{must} take an argument, namely the % (printable form of the) current identifier. % % You can define `|\newcommand\indexkeywords[1]{\index{keywords, #1}}|' % and make similar definitions for constant or function names. Then % `|indexstyle=[1]\indexkeywords|' might meet your purpose. This becomes % easier if you want to create multiple indexes with the % \packagename{index} package % (\href{ftp://ftp.dante.de/tex-archive/macros/latex/contrib/supported/camel} % {CTAN/macros/latex/contrib/supported/camel}). % If you have defined appropriate new indexes, it is possible to write % `|indexstyle=\index[keywords]|', for example. % % \item Let's say, I want to index all keywords. It would be annoying to % type in all the keywords again, specifically if the used programming % language changes frequently. % \advisespace % Just read ahead. % \end{advise} % The \ikeyname{index} key has in fact two optional arguments. The first is the % well-known \meta{class number}, the second is a comma separated list of other % keyword classes whose identifiers are indexed. The indexed identifiers then % change automatically with the defined keywords---not automagically, it's not % an illusion.^^A :-) % % Eventually you need to know the names of the keyword classes. It's usually % the key name followed by a class number, for example, |emph2|, |emph3|, % \ldots, |keywords2| or |index5|. But there is no number for the first order % classes |keywords|, |emph|, |directives|, and so on. % \begin{advise} % \item `|index=[keywords]|' does not work. % \advisespace % The package can't guess which optional argument you mean. Hence you % must specify both if you want to use the second one. You should try % `|index=[1][keywords]|'. % \end{advise} % % % \subsection{Fixed and flexible columns}\label{uFixedAndFlexibleColumns} % % The first thing a reader notices---except different styles for keywords, % etc.---is the column alignment. Arne John Glenstrup invented the flexible % column format in 1997. Since then some efforts were made to develop this % branch farther. Currently three column formats are provided: fixed, flexible, % and full flexible. Take a close look at the following examples. % \begin{center} % \lstset{style={},language={}} % \def\sample{\begin{lstlisting}^^J WOMEN\ \ are^^A % ^^J \ \ \ \ \ \ \ MEN^^A % ^^J WOMEN are^^A % ^^J better MEN^^J \end{lstlisting}} % \begin{tabular}{@{}c@{\qquad\quad}c@{\qquad\quad}c@{\qquad\quad}c@{}} % {\rstyle\ikeyname{columns}}|=| & \texttt{fixed} & \texttt{flexible} & \texttt{fullflexible}\\ % & (at {\makeatletter\lst@widthfixed}) % & (at {\makeatletter\lst@widthflexible}) % & (at {\makeatletter\lst@widthflexible})\\ % \noalign{\medskip} % \lstset{basicstyle=\ttfamily,basewidth=0.51em}\sample % & \lstset{columns=fixed}\sample % & \lstset{columns=flexible}\sample % & \lstset{columns=fullflexible}\sample % \end{tabular} % \end{center} % \begin{advise} % \item Why are women better men? % \advisespace % Do you want to philosophize? Well, have I ever said that the % statement ``women are better men'' is true? I can't even remember this % about ``women are men'' \ldots ^^A ;-)) % \end{advise} % In the abstract one can say: The fixed column format ruins the spacing % intended by the font designer, while the flexible formats ruin the column % alignment (possibly) intended by the programmer. Common to all is that the % input characters are translated into a sequence of basic output units like % \begingroup \lstset{gobble=6,xleftmargin=\leftmargini} % \makeatletter %^^A Make \fbox around each output unit. % \fboxsep=0pt % \def\lst@alloverstyle#1{\fbox{\kern-\fboxrule\strut#1}\kern-\fboxrule} % \begin{lstlisting}[basewidth=1em] % if x=y then write('align') % else print('align'); % \end{lstlisting} % Now, the fixed format puts $n$ characters into a box of width $n\times{} % $`base width', where the base width is {\makeatletter\lst@widthfixed} in the % example. The format shrinks and stretches the space between the characters % to make them fit the box. As shown in the example, some character strings look % \hbox to 2em{b\hss a\hss d} % or % \hbox to 2em{w\hss o\hss r\hss s\hss e}, % but the output is vertically aligned. % \endgroup % % If you don't need or like this, you should use a flexible format. All % characters are typeset at their natural width. In particular, they never % overlap. If a word requires more space than reserved, the rest of the line % simply moves to the right. The difference between the two formats is that the % full flexible format cares about nothing else and the normal flexible format % tries to fix the column alignment if a character string needs less space % than `reserved'. In the flexible example above, the two MENs are vertically % aligned since some space has been inserted in the fourth line to fix the % alignment. In the full flexible format, the two MENs are not aligned. % % Note that both flexible modes printed the two blanks in the first line as a % single blank, but for different reasons: the normal flexible format fixes % the column alignment and the full flexible format doesn't care about the % second space. % % % \section{Advanced techniques}\label{uAdvancedTechniques} % % % \subsection{Style definitions} % % It is obvious that a pretty-printing tool like this requires some kind of % language selection and definition. The first has already been described and % the latter is convered by the next section. However, it is very convenient % to have the same for printing styles: at a central place of your document % they can be modified easily and the changes take effect on all listings. % % Similar to languages, % {\rstyle\ikeyname{style}}|=|\meta{style name} % activates a previously defined style. A definition is as easy: % {\rstyle|\lstdefinestyle|}\marg{style name}\marg{key=value list}. % Keys not used in such a definition are untouched by the corresponding style % selection, of course. For example, you could write % \begin{verbatim} % \lstdefinestyle{numbers} % {numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=10pt} % \lstdefinestyle{nonumbers} % {numbers=none}\end{verbatim} % and switch from listings with line numbers to listings without ones and vice % versa simply by |style=nonumbers| and |style=numbers|, respectively. % \begin{advise} % \item You could even write % `|\lstdefinestyle{C++}{language=C++,style=numbers}|'. % Style and language names are independent of each other and so might % coincide. Moreover it is possible to activate other styles. % % \item It's easy to crash the package using styles. Write % '|\lstdefinestyle{crash}{style=crash}|' and '|\lstset{style=crash}|'. % \TeX's capacity will exceed, sorry [parameter stack size]. Only bad % boys use such recursive calls, but only good girls use this package. % Thus the problem is of minor interest.^^A :-) % \end{advise} % % % \subsection{Language definitions}\label{uLanguageDefinitions} % % This is like style definitions except for an optional dialect name and an % optional base language---and, of course, a different command name and % specialized keys. In the simple case it's % {\rstyle|\lstdefinelanguage|}\marg{language name}\marg{key=value list}. % For many programming languages it is sufficient to specify keywords and % standard function names, comments, and strings. Let's look at an example. % \begin{lstxsample}[morekeywords,sensitive,morecomment,morestring] % \lstdefinelanguage{rock} % {morekeywords={one,two,three,four,five,six,seven,eight, % nine,ten,eleven,twelve,o,clock,rock,around,the,tonight}, % sensitive=false, % morecomment=[l]{//}, % morecomment=[s]{/*}{*/}, % morestring=[b]", % } % \end{lstxsample} % \begingroup \csname lst@EndWriteFile\endcsname % \bigbreak % % \noindent % There isn't much to say about keywords. They are defined like identifiers % you want to emphasize. Additionally you need to specify whether they are % case sensitive or not. And yes: you could insert |[2]| in front of the % keyword \texttt{one} to define the keywords as `second order' and print them % in |keywordstyle={[2]...}|. % \begin{advise} % \item I get a `\texttt{Missing = inserted for }|\ifnum|' error when I select % my language. % \advisespace % Did you forget the comma after `|keywords={...}|'? And if you encounter % unexpected characters after selecting a language (or style), you have % probably forgotten a different comma or you have given to many % arguments to a key, for example, |morecomment=[l]{--}{!}|. % \end{advise} % % So let's turn to comments and strings. Each value starts with a % \emph{mandatory} \oarg{type} argument followed by a changing number of % opening and closing delimiters. Note that each delimiter (pair) requires a % key=value on its own, even if types are equal. Hence, you'll need to insert % \texttt{morestring=[b]'} if single quotes open and close string or character % literals in the same way as double quotes do in the example. % % Eventually you need to know the types and their numbers of delimiters. The % reference guide contains full lists, here we discuss only the most common. % For strings these are {\rstyle\texttt{b}} and {\rstyle\texttt{d}} with one % delimiter each. This delimiter opens and closes the string and inside a % string it is either escaped by a \texttt backslash or it is \texttt doubled. % The comment type {\rstyle\texttt{l}} requires exactly one delimiter, which % starts a comment on any column. This comment goes up to the end of line. % The other two most common comment types are {\rstyle\texttt{s}} and % {\rstyle\texttt{n}} with two delimiters each. The first delimiter opens a % comment which is terminated by the second delimiter. In contrast to the % \texttt s-type, \texttt n-type comments can be nested. % \begin{lstxsample}[b,d,l,s,n] % \lstset{morecomment=[l]{//}, % morecomment=[s]{/*}{*/}, % morecomment=[n]{(*}{*)}, % morestring=[b]", % morestring=[d]'} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % "str\"ing " not a string % 'str''ing ' not a string % // comment line % /* comment/**/ not a comment % (* nested (**) still comment % comment *) not a comment % \end{lstlisting} % \end{lstsample} % \begin{advise} % \item Is it \emph{that} easy? % \advisespace % Almost. There are some troubles you can run into. For example, if % `\texttt{-*}' starts a comment line and `\texttt{-*-}' a string % (unlikely but possible), then you must define the shorter delimiter % first. % Another problem: by default some characters are not allowed inside % keywords, for example `\texttt{-}', `\texttt{:}', `\texttt{.}', and % so on. The reference guide covers this problem by introducing some % more keys, which let you adjust the standard character table % appropriately. But note that white space characters are prohibited % inside keywords. % \end{advise} % Finally remember that this section is only an introduction to language % definitions. There are more keys and possibilities. % % % \subsection{Delimiters}\label{uDelimiters} % % You already know two special delimiter classes: comments and strings. % However, their full syntax hasn't been described so far. For example, % \ikeyname{commentstyle} applies to all comments---except you specify % something different. The \emph{optional} \oarg{style} argument follows the % \emph{mandatory} \oarg{type} argument. %\ifcolor % \begin{lstxsample} % \lstset{morecomment=[l][keywordstyle]{//}, % morecomment=[s][\color{white}]{/*}{*/}} % \end{lstxsample} %\else % \begin{lstxsample} % \lstset{morecomment=[l][keywordstyle]{//}, % morecomment=[s][\underbar]{/*}{*/}} % \end{lstxsample} %\fi % \begin{lstsample}{}{} % \begin{lstlisting} % // bold comment line % a single /* comment */ % \end{lstlisting} % \end{lstsample} % As you can see, you have the choice between specifying the style explicitly % by \LaTeX\ commands or implicitly by other style keys. But, you're right, % some implicitly defined styles have no seperate keys, for example the second % order keyword style. Here---and never with the number 1---you just append % the order to the base key: \texttt{keywordstyle2}. % % You ask for an application? Here you are: one can define different printing % styles for `subtypes' of a comment, for example %\ifcolor % \begin{lstxsample} % \lstset{morecomment=[s][\color{blue}]{/*+}{*/}, % morecomment=[s][\color{red}]{/*-}{*/}} % \end{lstxsample} %\else % \begin{lstxsample} % \lstset{morecomment=[s][\upshape]{/*+}{*/}, % morecomment=[s][\bfseries]{/*-}{*/}} % \end{lstxsample} %\fi % \begin{lstsample}{\lstset{morecomment=[s]{/*}{*/}}}{} % \begin{lstlisting} % /* normal comment */ % /*+ keep cool */ % /*- danger! */ % \end{lstlisting} % \end{lstsample} % Here, the comment style is not applied to the second and third line. % \begin{advise} % \item Please remember that both `extra' comments must be defined \emph{after} % the normal comment, since the delimiter `\texttt{/*}' is a substring of % `\texttt{/*+}' and `\texttt{/*-}'. % % \item I have another question. Is `\texttt{language=}\meta{different % language}' the only way to remove such additional delimiters? % \advisespace % Call {\rstyle\ikeyname{deletecomment}} and/or % {\rstyle\ikeyname{deletestring}} with the same arguments to remove % the delimiters (but you don't need to provide the optional style % argument). % \end{advise} % Eventually, you might want to use the prefix \texttt{i} on any comment type. % Then the comment is not only invisible, it is completely discarded from the % output! % \begin{lstxsample}[is] % \lstset{morecomment=[is]{/*}{*/}} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % begin /* comment */ end % begin/* comment */end % \end{lstlisting} % \end{lstsample} % % Okay, and now for the real challenges. More general delimiters can be defined % by the key {\rstyle\ikeyname{moredelim}}. Legal types are {\rstyle\texttt{l}} % and {\rstyle\texttt{s}}. These types can be preceded by an \texttt{i}, but % this time \emph{only the delimiters} are discarded from the output. This way % you can select styles by markers. % \begin{lstxsample} % \lstset{moredelim=[is][\ttfamily]{|}{|}} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % roman |typewriter| % \end{lstlisting} % \end{lstsample} % You can even let the package detect keywords, comments, strings, and other % delimiters inside the contents. % \begin{lstxsample} % \lstset{moredelim=*[s][\itshape]{/*}{*/}} % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % /* begin % (* comment *) % ' string ' */ % \end{lstlisting} % \end{lstsample} % Moreover, you can force the styles being applied cumulative. % \begin{lstxsample} % \lstset{moredelim=**[is][\ttfamily]{|}{|}, % cumulative % moredelim=*[s][\itshape]{/*}{*/}} % not so % \end{lstxsample} % \begin{lstsample}{}{} % \begin{lstlisting} % /* begin % ' string ' % |typewriter| */ % % | begin % ' string ' % /*typewriter*/ | % \end{lstlisting} % \end{lstsample} % Look carefully at the output and note the differences. The second % \texttt{begin} is not printed in bold typewriter type since standard % \LaTeX\ has no such font. % % This suffices for an introduction. Now go and find some more applications. % % % \subsection{Closing and credits}\label{uClosingAndCredits} % % You've seen a lot of keys but you are far away from knowing all of them. % The next step is the real use of the \packagename{listings} package. % Please take the following advices. Firstly, look up the known commands and % keys in the reference guide to get a notion of the notation there. Secondly, % poke about around these keys to learn some other parameters. Then, hopefully, % you'll be prepared if you encounter any problems or need some special things. % % \begin{advise} % \item % There is one question `you' haven't asked all the last pages: who is to % blame. The author has written the guides, coded the \packagename{listings} % package and some language drivers. Other people defined more languages or % contributed their ideas; many others made bug reports, but only the first % bug finder is listed. %^^A %^^A Thanks for error reports (first bug finder only), new programming %^^A languages, etc. %^^A Special thanks for communication which lead to kernel extensions. %^^A % Special thanks go to (alphabetical order) % \begin{quote} % \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth % \lstthanks{Andreas~Bartelt}{Andreas.Bartelt@Informatik.Uni-Oldenburg.DE}, % \lstthanks{Jan~Braun}{Jan.Braun@tu-bs.de}, % \lstthanks{Denis~Girou}{Denis.Girou@idris.fr}, % \lstthanks{Arne~John~Glenstrup}{panic@diku.dk}, % \lstthanks{Frank~Mittelbach}{frank.mittelbach@latex-project.org}, % \lstthanks{Rolf~Niepraschk}{niepraschk@PTB.DE}, % \lstthanks{Rui~Oliveira}{rco@di.uminho.pt}, % \lstthanks{Jens~Schwarzer}{schwarzer@schwarzer.dk}, and % \lstthanks{Boris~Veytsman}{boris@plmsc.psu.edu}. % \end{quote} % Moreover I wish to thank % \begin{quote} % \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth % \lstthanks{Bj{\o}rn~{\AA}dlandsvik}{bjorn@imr.no}, % \lstthanks{Gaurav~Aggarwal}{gaurav@ics.uci.edu}, % \lstthanks{Jason~Alexander}{jalex@ea.oac.uci.edu}, % \lstthanks{Donald~Arseneau}{ASND@erich.triumf.ca}, % \lstthanks{Claus~Atzenbeck}{Claus.Atzenbeck@stud.uni-regensburg.de}, % \lstthanks{Peter~Bartke}{bartke@inf.fu-berlin.de} (big thankyou), ^^A beta tester % \lstthanks{Oliver~Baum}{oli.baum@web.de}, % \lstthanks{Ralph~Becket}{rbeck@microsoft.com}, % \lstthanks{Olaf~Trygve~Berglihn}{olafb@pvv.org}, ^^A {1999/11/29}{3-char comment delimiter don't work (Python)} % \lstthanks{Geraint~Paul~Bevan}{geraint@users.sf.net}, % \lstthanks{Peter~Biechele}{peter.biechele@physik.uni-freiburg.de}, % \lstthanks{Kai~Below}{below@tu-harburg.de}, % \lstthanks{Beat~Birkhofer}{beat@birkhofer.ch}, % \lstthanks{Fr\'ed\'eric~Boulanger}{Frederic.Boulanger@supelec.fr}, % \lstthanks{Martin~Brodbeck}{Martin.Brodbeck@gmx.de}, % \lstthanks{Walter~E.~Brown}{WB@fnal.gov}, % \lstthanks{Achim~D.~Brucker}{brucker@informatik.uni-freiburg.de}, % \lstthanks{David~Carlisle}{davidc@nag.co.uk}, % \lstthanks{Bradford~Chamberlain}{brad@cs.washington.edu}, % \lstthanks{Patrick~Cousot}{Patrick.Cousot@wanadoo.fr}, % \lstthanks{Xavier~Cr\'egut}{cregut@enseeiht.fr}, % \lstthanks{Holger~Danielsson}{dani@fbg.schwerte.de}, % \lstthanks{Andreas~Deininger}{deininger@uni-kassel.de}, % \lstthanks{Robert~Denham}{Robert.Denham@dnr.qld.gov.au}, % \lstthanks{Detlev~Dr\"oge}{droege@informatik.uni-koblenz.de}, % \lstthanks{Anders~Edenbrandt}{Anders.Edenbrandt@dna.lth.se}, % \lstthanks{Mark~van~Eijk}{mark@luon.net}, % \lstthanks{Norbert~Eisinger}{Norbert.Eisinger@informatik.uni-muenchen.de}, % \lstthanks{Thomas~Esser}{te@dbs.uni-hannover.de}, % \lstthanks{Chris~Edwards}{edwch00p@infoscience.otago.ac.nz}, % \lstthanks{David~John~Evans}{Matrix.Software@dial.pipex.com}, % \lstthanks{Robert~Frank}{rf7@ukc.ac.uk}, % \lstthanks{Daniel~Gazard}{gazard_d@epita.fr}, % \lstthanks{Daniel~Gerigk}{Daniel.Gerigk@ePost.de}, % \lstthanks{KP~Gores}{kp.gores@web.de}, % \lstthanks{Adam~Grabowski}{adam@mizar.org}, % \lstthanks{Jean-Philippe~Grivet}{grivet@cnrs-orleans.fr}, % \lstthanks{Christian~Gudrian}{Christian.Gudrian@kawo1.rwth-aachen.de}, % \lstthanks{Jonathan~de~Halleux}{dehalleux@auto.ucl.ac.be}, % \lstthanks{Carsten~Hamm}{carsten.hamm@siemens.com}, % \lstthanks{Martina~Hansel}{Martina.Hansel@fhtw-berlin.de}, % \lstthanks{Harald~Harders}{h.harders@tu-bs.de}, % \lstthanks{Christian~Haul}{haul@dvs1.informatik.tu-darmstadt.de}, % \lstthanks{Aidan~Philip~Heerdegen}{Aidan.Heerdegen@anu.edu.au}, % \lstthanks{Jim~Hefferon}{Hefferon9@aol.com}, % \lstthanks{Heiko~Heil}{info@heiko-heil.de}, % \lstthanks{J\"urgen~Heim}{heim@astro.uni-tuebingen.de}, % \lstthanks{Alvaro~Herrera}{alvherre@dcc.uchile.cl}, % \lstthanks{Dr.~Jobst~Hoffmann}{HOFFMANN@rz.rwth-aachen.de}, % \lstthanks{Torben~Hoffmann}{toho@it.dtu.dk}, % \lstthanks{Richard~Hoefter}{hoefter@gmx.de}, % \lstthanks{Berthold~H\"ollmann}{bhoel@starship.python.net}, % \lstthanks{Hermann~H\"uttler}{hermann.huettler@gmx.net}, % \lstthanks{Ralf~Imh\"auser}{snoopy@tribal.line.org}, % \lstthanks{R.~Isernhagen}{R.Isernhagen@FH-Wolfenbuettel.DE}, % \lstthanks{Oldrich~Jedlicka}{ojedlick@students.zcu.cz}, % \lstthanks{Dirk~Jesko}{jesko@iti.cs.uni-magdeburg.de}, % \lstthanks{Christian~Kaiser}{chk@combit.net}, % \lstthanks{Marcin~Kasperski}{Marcin.Kasperski@softax.com.pl}, % \lstthanks{Christian~Kindinger}{chkind@uni-wuppertal.de}, % \lstthanks{Steffen~Klupsch}{steffen@vlsi.informatik.tu-darmstadt.de}, % \lstthanks{Peter~K\"oller}{pkoeller@metaprojekt.de} (big thankyou), ^^A beta tester % \lstthanks{Stefan~Lagotzki}{info@lagotzki.de}, % \lstthanks{Rene~H.~Larsen}{rhl@traceroute.dk}, % \lstthanks{Olivier~Lecarme}{ol@i3s.unice.fr}, % \lstthanks{Thomas~Leduc}{Thomas.Leduc@lsv.ens-cachan.fr}, % \lstthanks{Dr.~Peter~Leibner}{Peter.Leibner@sta.siemens.de}, % \lstthanks{Thomas~Leonhardt}{leonhardt@informatik.tu-darmstadt.de} (big thankyou), ^^A beta tester % \lstthanks{Magnus~Lewis-Smith}{Magnus.Lewis-Smith@pace.co.uk}, % \lstthanks{Knut~Lickert}{knut.lickert@gmx.de}, % \lstthanks{Dan~Luecking}{luecking@uark.edu}, % \lstthanks{Kris~Luyten}{no email available}, % \lstthanks{Jos\'e~Romildo~Malaquias}{romildo@urano.iceb.ufop.br}, % \lstthanks{Andreas~Matthias}{amat@kabsi.at}, % \lstthanks{Knut~M\"uller}{knut@physik3.gwdg.de}, % \lstthanks{Svend~Tollak~Munkejord}{svendm@efisms.energy.sintef.no}, % \lstthanks{Gerd~Neugebauer}{gerd.neugebauer@gmx.de}, % \lstthanks{Torsten~Neuer}{tneuer@inwise.de}, % \lstthanks{Michael~Niedermair}{m.g.n@gmx.de}, % \lstthanks{Heiko~Oberdiek}{oberdiek@ruf.uni-freiburg.de}, % \lstthanks{Markus~Pahlow}{pahlowm@mar.dfo-mpo.gc.ca}, % \lstthanks{Zvezdan~V.~Petkovic}{zpetkovic@acm.org}, % \lstthanks{Michael~Piefel}{piefel@informatik.hu-berlin.de}, % \lstthanks{Michael~Piotrowski}{mxp@linguistik.uni-erlangen.de}, % \lstthanks{Manfred~Piringer}{sz0490@rrze.uni-erlangen.de}, % \lstthanks{Vincent~Poirriez}{Vincent.Poirriez@univ-valenciennes.fr}, % \lstthanks{Adam~Prugel-Bennett}{apb@ecs.soton.ac.uk}, % \lstthanks{Ralf~Quast}{rquast@hs.uni-hamburg.de}, % \lstthanks{Aslak~Raanes}{araanes@ifi.ntnu.no}, % \lstthanks{Venkatesh~Prasad~Ranganath}{vranganath@cox.net}, % \lstthanks{Georg~Rehm}{Georg.Rehm@germanistik.uni-giessen.de}, % \lstthanks{Fermin~Reig}{reig@ics.uci.edu}, % \lstthanks{Detlef~Reimers}{dreimers@aol.com}, % \lstthanks{Stephen~Reindl}{stephen.reindl@vodafone.com}, % \lstthanks{Peter~Ruckdeschel}{Peter.Ruckdeschel@uni-bayreuth.de}, % \lstthanks{Magne~Rudshaug}{magne@ife.no}, % \lstthanks{Vespe~Savikko}{vespe@cs.tut.fi}, % \lstthanks{Gunther~Schmidl}{gschmidl@gmx.at}, % \lstthanks{Walter~Schmidt}{wschmi@arcor.de}, % \lstthanks{Jochen~Schneider}{jschneider@ds3.etech.haw-hamburg.de}, % \lstthanks{Benjamin~Schubert}{benjamin.schubert@berlin.de}, % \lstthanks{Uwe~Siart}{uwe.siart@ei.tum.de}, % \lstthanks{Richard~Stallman}{no address}, % \lstthanks{Martin~Steffen}{ms@informatik.uni-kiel.de}, % \lstthanks{Andreas~Stephan}{Andreas.Stephan@victoria.de}, % \lstthanks{Stefan~Stoll}{stoll@phys.chem.ethz.ch}, % \lstthanks{Enrico~Straube}{no email available}, % \lstthanks{Martin~S\"u\ss kraut}{Edon.Myder@web.de}, % \lstthanks{Gabriel~Tauro}{gabriel@informatik.uni-jena.de}, % \lstthanks{Winfried~Theis}{theis@statistik.uni-dortmund.de}, % \lstthanks{Jens~T.~Berger~Thielemann}{jensthi@ifi.uio.no}, % \lstthanks{Arnaud~Tisserand}{arnaud.tisserand@ens-lyon.fr}, % \lstthanks{Kalle~Tuulos}{kalle.tuulos@nic.fi}, % \lstthanks{Gregory~Van~Vooren}{Gregory.VanVooren@rug.ac.be}, % \lstthanks{Thorsten~Vitt}{vitt@informatik.hu-berlin.de}, % \lstthanks{Herbert~Voss}{voss@perce.de} (big thankyou), ^^A beta tester % \lstthanks{Herfried~Karl~Wagner}{hirf@gmx.at}, % \lstthanks{Dominique~de~Waleffe}{ddw@miscrit.be}, % \lstthanks{Michael~Weber}{mweber@informatik.hu-berlin.de}, % \lstthanks{Sonja~Weidmann}{Sonja.Weidmann@gmx.de}, % \lstthanks{Herbert~Weinhandl}{weinhand@grz08u.unileoben.ac.at}, % \lstthanks{Robert~Wenner}{robert.wenner@gmx.de}, % \lstthanks{Michael~Wiese}{wiese@itwm.uni-kl.de}, % \lstthanks{J\"orn~Wilms}{wilms@rocinante.colorado.edu}, % \lstthanks{Kai~Wollenweber}{kai@ece.WPI.EDU}, % \lstthanks{Ulrich~G.~Wortmann}{uliw@erdw.ethz.ch}, and % \lstthanks{Timothy~Van~Zandt}{tvz@econ.insead.edu}. % \end{quote} % There are probably other people who contributed to this package. % If I've missed your name, send an email. % \end{advise} % % % \part{Reference guide} % % % \section{Main reference}\label{rMainReference} % % Your first training is completed. Now that you've left the User's guide, the % friend telling you what to do has gone. Get more practice and become a % journeyman!^^A :-) % \begin{advise} % \item Actually, the friend hasn't gone. There are still some advices, but % only from time to time. % \end{advise} % % % \subsection{How to read the reference} % % Commands, keys and environments are presented as follows. % \begin{syntax} % \item[1.0,default,hints] \texttt{command}, \texttt{environment} or % \keyname{key} with \meta{parameters} % % This field contains the explanation; here we describe the other fields. % % If present, the label in the left margin provides extra information: % `\textit{addon}' indicates additionally introduced functionality, % `\textit{changed}' a modified key, `\textit{data}' a command just % containing data (which is therefore adjustable via |\renewcommand|), % and so on. Some keys and functionality are `\emph{bug}'-marked or % with a \dag-sign. These features might change in future or could be % removed, so use them with care. % % If there is verbatim text touching the right margin, it is the % predefined value. Note that some keys default to this value every % listing, namely the keys which can be used on individual listings only. % % The label in the right margin is the current version number and marks % newly introduced features. % \end{syntax} % Regarding the parameters, please keep in mind the following: % \begin{enumerate} % \item A list always means a comma separated list. You must put braces around % such a list. Otherwise you'll get in trouble with the % \packagename{keyval} package; it complains about an undefined key. % \item You must put parameter braces around the whole value of a key if you % use an \oarg{optional argument} of a key inside an optional % \oarg{key=value list}: % |\begin{lstlisting}[caption=|{\rstyle|{|}|[one]two|{\rstyle|}|}|]|. % \item Brackets `|[ ]|' usually enclose optional arguments and must be typed % in verbatim. Normal brackets `[ ]' always indicate an optional argument % and must not be typed in. Thus |[*]| must be typed in exactly as is, % but [|*|] just gets |*| if you use this argument. % \item A vertical rule indicates an alternative, e.g.~^^A % \meta{\alternative{true,false}} allows either \texttt{true} or % \texttt{false} as arguments. % \item If you want to enter one of the special characters |{}#%\|, this % character must be escaped with a backslash. This means that you must % write |\}| for the single character `right brace'---but of course not % for the closing paramater character. % \end{enumerate} % % % \subsection{Typesetting listings}\label{rTypesettingListings} % % \begin{syntax} % \item[0.19] \rcmdname\lstset\marg{key=value list} % % sets the values of the specified keys, see also section % \ref{uTheKey=ValueInterface}. % The parameters keep their values up to the end of the current group. % In opposition, all optional \meta{key=value list}s below modify the % parameters for single listings only. % % \item[0.18] \rcmdname\lstinline\oarg{key=value list}\meta{character}\meta{source code}\meta{same character} % % works like |\verb| but respects the active language and style. These % listings use flexible columns except requested differently in the % optional argument. You can write `|\lstinline!var i:integer;!|' and % get `\lstinline!var i:integer;!'. % % Since the command first looks ahead for an optional argument, you must % provide at least an empty one if you want to use |[| as % \meta{character}. % % \dag\ An experimental implementation has been done to support the % syntax |\lstinline|\oarg{key=value list}\marg{source code}. Try it if % you want and report success and failure. A known limitation is that % inside another argument the last source code token must not be an % explicit space token---and, of course, using a listing inside another % argument is itself experimental, see section \ref{rListingsInsideArguments}. % % \item[0.15] |\begin{|\texttt{\rstyle lstlisting}|}|\oarg{key=value list} % % \leavevmode\hspace*{-\leftmargini}|\end{|\texttt{\rstyle lstlisting}|}| % % typesets the code in between as a displayed listing. % % In contrast to the environment of the \packagename{verbatim} package, % \LaTeX\ code on the same line and after the end of environment is % typeset respectively executed. % % \item[0.1] \rcmdname\lstinputlisting\oarg{key=value list}\marg{file name} % % typesets the stand alone source code file as a displayed listing. % \end{syntax} % % % \subsection{Space and placement} % % \begin{syntax} % \item[0.20,floatplacement] \rkeyname{float}|=|[|*|]\meta{subset of \textup{\texttt{tbph}}}\syntaxor\rkeyname{float} % % makes sense on individual displayed listings only and lets them float. % The argument controls where \LaTeX\ is \emph{allowed} to put the float: % at the top or bottom of the current/next page, on a separate page, or % here where the listing is. % % The optional star can be used to get a double-column float in a % two-column document. % % \item[0.21,tbp] \rkeyname{floatplacement}|=|\meta{place specifiers} % % is used as place specifier if \keyname{float} is used without value. % % \item[0.21,\medskipamount] \rkeyname{aboveskip}|=|\meta{dimension} % \item[0.21,\medskipamount] \rkeyname{belowskip}|=|\meta{dimension} % % define the space above and below displayed listings. % % \item[0.17,0pt,\dag] \rkeyname{lineskip}|=|\meta{dimension} % % specifies additional space between lines in listings. % % \item[0.18,c,\dag] \rkeyname{boxpos}|=|\meta{\alternative{b,c,t}} % % Sometimes the \packagename{listings} package puts a |\hbox| around a % listing---or it couldn't be printed or even processed correctly. % The key determines the vertical alignment to the surrounding material: % bottom baseline, centered or top baseline. % \end{syntax} % % % \subsection{The printed range} % % \begin{syntax} % \item[0.12,true] \rkeyname{print}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{print} % % controls whether an individual displayed listing is typeset. Even if % set false, the respective caption is printed and the label is defined. % % Note: If the package is loaded without the \texttt{draft} option, you % can use this key together with |\lstset|. In the other case the key % can only be used to typeset particular listings despite of the % \texttt{draft} option. % % \item[0.1,1] \rkeyname{firstline}|=|\meta{number} % \item[0.1,9999999] \rkeyname{lastline}|=|\meta{number} % % can be used on individual listings only. They determine the physical % input lines used to print displayed listings. % % \item[0.20,false] \rkeyname{showlines}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{showlines} % % If true, the package prints empty lines at the end of listings. % Otherwise these lines are dropped (but they count for line numbering). % % \item[1.0] \rkeyname{emptylines}|=|[|*|]\meta{number} % % sets the maximum of empty lines allowed. If there is a block of more % than \meta{number} empty lines, only \meta{number} ones are printed. % Without the optional star, line numbers can be disturb when blank % lines are omitted; with the star, the lines keep their original % numbers. % % \item[0.19,0] \rkeyname{gobble}|=|\meta{number} % % gobbles \meta{number} characters at the beginning of each % \emph{environment} code line. This key has no effect on \cs{lstinline} % or \cs{lstinputlisting}. % % Tabulators expand to \ikeyname{tabsize} spaces before they are gobbled. % Code lines with less than \ikeyname{gobble} characters are considered % empty, but never indent the end of environment by more characters. % \end{syntax} % % % \subsection{Languages and styles}\label{rLanguagesAndStyles} % % Please note that the arguments \meta{language}, \meta{dialect}, and % \meta{style name} are case insensitive and that spaces have no effect. % \begin{syntax} % \item[0.18,{{}}] \rkeyname{style}|=|\meta{style name} % % activates the key=value list stored with |\lstdefinestyle|. % % \item[0.19] \rcmdname\lstdefinestyle\marg{style name}\marg{key=value list} % % stores the key=value list. % % \item[0.17,{{}}] \rkeyname{language}|=|\oarg{dialect}\meta{language} % % activates a (dialect of a) programming language. The `empty' default % language detects no keywords, no comments, no strings, and so on. % Without specifying \meta{dialect}, the package chooses a default % dialect. % % Table \ref{uPredefinedLanguages} on page \pageref{uPredefinedLanguages} % lists all languages and dialects provided by \texttt{lstdrvrs.dtx}. % The predefined default dialects are underlined. % % \item[0.21] \rkeyname{alsolanguage}|=|\oarg{dialect}\meta{language} % % selects the (dialect of a) programming language additionally to the % current active one. Note that some language definitions interfere with % each other and are plainly incompatible. % % Take a look at the \ikeyname{classoffset} key in section % \ref{rFigureOutTheAppearance} if you want to highlight the keywords % of the languages differently. % % \item[0.19] \rkeyname{defaultdialect}|=|\oarg{dialect}\meta{language} % % defines \meta{dialect} as default dialect for \meta{language}. % If you have defined a default dialect other than empty, for example % |defaultdialect=[iama]fool|, you can't select the empty dialect, even % not with |language=[]fool|. % \end{syntax} % % Eventually here's a small list of language specific keys. % \begin{syntax} % \item[0.19,false,optional] \rkeyname{printpod}|=|\meta{\alternative{true,false}} % % prints or drops PODs in Perl. % % \item[0.20,true,{renamed,optional}] \rkeyname{usekeywordsintag}|=|\meta{\alternative{true,false}}\label{uoption:usekeywordsintag} % % The package either use the first order keywords in tags or prints all % identifiers inside |<>| in keyword style. % % \item[1.1,{{}},optional] \rkeyname{tagstyle}|=|\meta{style}\label{uoption:tagstyle} % % determines the style in which tags and their content is printed. % % \item[1.1,false,optional] \rkeyname{markfirstintag}|=|\meta{style}\label{uoption:markfirstintag} % % prints the first name in tags with keyword style. % % \item[0.20,true,optional] \rkeyname{makemacrouse}|=|\meta{\alternative{true,false}} % % Make specific: Macro use of identifiers, which are defined as first % order keywords, also prints the surrounding |$(| and |)| in keyword % style. e.g.~you could get % \textbf{\textdollar(}\textbf{strip} \textdollar(BIBS)\textbf{)}. % If deactivated you get % \textdollar(\textbf{strip} \textdollar(BIBS)). % \end{syntax} % % % \subsection{Figure out the appearance}\label{rFigureOutTheAppearance} % % \begin{syntax} % \item[0.18,{{}}] \rkeyname{basicstyle}|=|\meta{basic style} % % is selected at the beginning of each listing. You could use % |\footnotesize|, |\small|, |\itshape|, |\ttfamily|, or something like % that. The last token of \meta{basic style} must not read any following % characters. % % \item[0.18,{{}}] \rkeyname{identifierstyle}|=|\meta{style} % \item[0.11,\itshape] \rkeyname{commentstyle}|=|\meta{style} % \item[0.12,{{}}] \rkeyname{stringstyle}|=|\meta{style} % % determine the style for non-keywords, comments, and strings. The % \emph{last} token might be an one-parameter command like |\textbf| or % |\underbar|. % % \item[0.11,\bfseries] \rkeyname{keywordstyle}|=|\oarg{number}\meta{style} % \item[0.19,keywordstyle] \rkeyname{ndkeywordstyle}|=|\meta{style} % % are used to print keywords and second order keywords (if defined). % The optional \meta{number} argument is the class number to which the % style should be applied. % |ndkeywordstyle=...| is equivalent to |keywordstyle=[2]...|. % % \item[1.0,0] \rkeyname{classoffset}|=|\meta{number} % % is added to all class numbers before the styles, keywords, identifiers, % etc.~are assigned. The example below defines the keywords directly; % you could do it indirectly by selection two different languages. % \end{syntax} %\ifcolor % \begin{lstxsample} % \lstset{classoffset=0, % morekeywords={one,three,five},keywordstyle=\color{red}, % classoffset=1, % morekeywords={two,four,six},keywordstyle=\color{blue}, % classoffset=0}% restore default % \end{lstxsample} %\else % \begin{lstxsample} % \lstset{classoffset=0, % morekeywords={one,three,five},keywordstyle=\itshape, % classoffset=1, % morekeywords={two,four,six},keywordstyle=\bfseries}, % classoffset=0}% restore default % \end{lstxsample} %\fi % \begin{lstsample}{}{} % \begin{lstlisting} % one two three % four five six % \end{lstlisting} % \end{lstsample} % % \begin{syntax} % \item[0.20,keywordstyle,optional] \rkeyname{texcsstyle}|=|\meta{style} % \item[0.20,keywordstyle,optional] \rkeyname{directivestyle}|=|\meta{style} % % determine the style of \TeX\ control sequences and directives. % Note that these key are present only if you've chosen an appropriate % language. % % \item[0.21] \rkeyname{emph}|=|\oarg{number}\marg{identifier list} % \item[0.21] \rkeyname{moreemph}|=|\oarg{number}\marg{identifier list} % \item[0.21] \rkeyname{deleteemph}|=|\oarg{number}\marg{identifier list} % \item[0.21] \rkeyname{emphstyle}|=|\oarg{number}\marg{style} % % define, add and remove the \meta{identifier list} from `emphasize % class \meta{number}' respectively define the style for that class. % If you don't give an optional argument, the package assumes % \meta{number}$\,=1$. % % These keys are described more detailed in section % \ref{uEmphasizeIdentifiers}. % % \item[1.0] \rkeyname{delim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt][\texttt[\meta{style}\texttt]]\meta{delimiter\textup(s\textup)} % \item[1.0] \rkeyname{moredelim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt][\texttt[\meta{style}\texttt]]\meta{delimiter\textup(s\textup)} % \item[1.0] \rkeyname{deletedelim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt]\meta{delimiter\textup(s\textup)} % % deletes all previously defined delimiters (but neither strings nor % comments) and defines the user supplied delimiter, adds the specified % delimiter, or removes it. % % In the first two cases \meta{style} is used to print the delimited % code (and the delimiters). Here, \meta{style} could be something like % |\bfseries| or |\itshape|, or it could refer to other styles via % \texttt{keywordstyle}, \texttt{keywordstyle2}, \texttt{emphstyle}, % etc. % % Supported types are \texttt{l} and \texttt{s}, see the comment keys in % section \ref{uLanguageDefinitions} for an explanation. If you use the % prefix \texttt i, i.e.~\texttt{il} or \texttt{is}, the delimiters are % not printed, which is some kind of invisibility. % % If you use one optional star, the package will detect keywords, % comments, and strings inside the delimited code. With both optional % stars, aditionally the style is applied cumulative, see section % \ref{uDelimiters}. % \end{syntax} % % % \subsection{Getting all characters right} % % \begin{syntax} % \item[0.18,false] \rkeyname{extendedchars}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{extendedchars} % % allows or prohibits extended characters in listings, that means % (national) characters of codes 128--255. If you use extended % characters, you should load \packagename{fontenc} and/or % \packagename{inputenc}, for example. % % \item[1.0,{{}}] \rkeyname{inputencoding}|=|\meta{encoding} % % determines the input encoding. The usage of this key requires the % \packagename{inputenc} package; nothing happens if it's not loaded. % % \item[1.1,false] \rkeyname{upquote}|=|\meta{\alternative{true,false}}\label{uoption:upquote} % % determines whether the left and right quote are printed |`'| or % \texttt{\textasciigrave\textquotesingle}. % This key requires the \packagename{textcomp} package. % % \item[0.12,8] \rkeyname{tabsize}|=|\meta{number} % % sets tabulator stops at columns $\meta{number}+1$, $2\cdot\meta{number}+1$, $3\cdot\meta{number}+1$, and so on. % Each tabulator in a listing moves the current column to the next % tabulator stop. % % \item[0.20,false] \rkeyname{showtabs}|=|\meta{\alternative{true,false}} % % make tabulators visible or invisible. A visible tabulator looks like % \lstinline[showtabs]! !, but that can be changed. If you choose % invisible tabulators but visible spaces, tabulators are converted to % an appropriate number of spaces. % % \item[0.20] \rkeyname{tab}|=|\meta{tokens} % % \meta{tokens} is used to print a visible tabulator. You might want to use |$\to$|, |$\mapsto$|, |$\dashv$| or something like that instead of the strange default definition. % % \item[0.20,false] \rkeyname{showspaces}|=|\meta{\alternative{true,false}} % % lets all blank spaces appear {\textvisiblespace} or as blank spaces. % % \item[0.12,true] \rkeyname{showstringspaces}|=|\meta{\alternative{true,false}} % % lets blank spaces in strings appear {\textvisiblespace} or as blank % spaces. % % \item[0.19,\bigbreak] \rkeyname{formfeed}|=|\meta{tokens} % % Whenever a listing contains a form feed \meta{tokens} is executed. % \end{syntax} % % % \subsection{Line numbers}\label{rLineNumbers} % % \begin{syntax} % \item[1.0,none] \rkeyname{numbers}|=|\meta{\alternative{none,left,right}} % % makes the package either print no line numbers, or put them on the % left or the right side of a listing. % % \item[0.16,1] \rkeyname{stepnumber}|=|\meta{number} % % All lines with ``line number $\equiv 0$ modulo \meta{number}'' get a % line number. % If you turn line numbers on and off with \keyname{numbers}, the % parameter \keyname{stepnumber} will keep its value. Alternatively you % can turn them off via |stepnumber=0| and on with a nonzero number and % keep the value of \keyname{numbers}. % % \item[1.1,false] \rkeyname{numberfirstline}|=|\meta{\alternative{true,false}}\label{uoption:numberfirstline} % % The first line of each listing gets numbered (if numbers are on at all) % even if the line number is not divisible by \keyname{stepnumber}. % % \item[0.16,{{}}] \rkeyname{numberstyle}|=|\meta{style} % % determines the font and size of the numbers. % % \item[0.19,10pt] \rkeyname{numbersep}|=|\meta{dimension} % % is the distance between number and listing. % % \item[1.0,true] \rkeyname{numberblanklines}|=|\meta{\alternative{true,false}} % % If this is set to false, blank lines get no printed line number. % % \item[0.20,auto] \rkeyname{firstnumber}|=|\meta{\alternative{auto,last,\normalfont\meta{number}}} % % \texttt{auto} lets the package choose the first number: a new listing % starts with number one, a named listing continues the most recent % same-named listing (see below), and a stand alone file begins with % the number corresponding to the first input line. % % \texttt{last} continues the numbering of the most recent listing and % \meta{number} sets it to the number. % % \item[1.0] \rkeyname{name}|=|\meta{name} % % names a listing. Displayed environment-listings with the same name % share a line counter. % % \item[0.20,\arabic{lstnumber},data] \rcmdname\thelstnumber % % prints the lines' numbers. % \end{syntax} % We show an example on how to redefine |\thelstnumber|. But if you test it, % you won't get the result shown on the left. % \begin{lstxsample} % \renewcommand*\thelstnumber{\oldstylenums{\the\value{lstnumber}}} % \end{lstxsample} % \begin{lstsample}{\lstset{stepnumber=-1}\label{rDecreasingLabels}}{} % \begin{lstlisting}[numbers=left, % firstnumber=753] % begin { empty lines } % % % % % % % end; { empty lines } % \end{lstlisting} % \end{lstsample} % % \begin{advise} % \item % The example shows a sequence $n,n+1,\ldots,n+7$ of 8 three-digit figures such that the sequence contains each digit $0,1,\ldots,9$. % But 8 is not minimal with that property. % Find the minimal number and prove that it is minimal. % How many minimal sequences do exist? % % Now look at the generalized problem: % Let $k\in\{1,\ldots,10\}$ be given. % Find the minimal number $m\in\{1,\ldots,10\}$ such that there is a sequence $n,{n+1},\ldots,\allowbreak{n+m-1}$ of $m$ $k$-digit figures which contains each digit $\{0,\ldots,9\}$. % Prove that the number is minimal. % How many minimal sequences do exist? % % If you solve this problem with a computer, write a \TeX\ program! % \end{advise} % % % \subsection{Captions} % % In despite of \LaTeX\ standard behaviour, captions and floats are independent % from each other here; you can use captions with non-floating listings. % \begin{syntax} % \item[0.21] \rkeyname{title}|=|\meta{title text} % % is used for a title without any numbering or label. % % \item[0.20] \rkeyname{caption}|={|\oarg{short}\meta{caption text}|}| % % The caption is made of \cs{lstlistingname} followed by a running % number, a seperator, and \meta{caption text}. Either the caption text % or, if present, \meta{short} will be used for the list of listings. % % \item[0.21] \rkeyname{label}|=|\meta{name} % % makes a listing referable via |\ref|\marg{name}. % % \item[0.16] \rcmdname\lstlistoflistings % % prints a list of listings. Each entry is with descending priority % either the short caption, the caption, the file name or the name of the % listing, see also the key \keyname{name} in section \ref{rLineNumbers}. % % \item[1.0] \rkeyname{nolol}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{nolol} % % If true, the listing does not make it into the list of listings. % % \item[0.16,Listings,data] \rcmdname\lstlistlistingname % % The header name for the list of listings. % % \item[0.20,Listing,data] \rcmdname\lstlistingname % % The caption label for listings. % % \item[0.20,\arabic{lstlisting},data] \rcmdname\thelstlisting % % prints the running number of the caption. % % \item[0.19] \rcmdname\lstname % % prints the name of the current listing which is either the file name or % the name defined by the \keyname{name} key. This command can be used to % define a caption or title template, for example by % |\lstset{caption=\lstname}|. % % \item[0.20,t] \rkeyname{captionpos}|=|\meta{subset of \textup{\texttt{tb}}} % % specifies the positions of the caption: top and/or bottom of the % listing. % % \item[0.20,\smallskipamount] \rkeyname{abovecaptionskip}|=|\meta{dimension} % \item[0.20,\smallskipamount] \rkeyname{belowcaptionskip}|=|\meta{dimension} % % is the vertical space above respectively below each caption. % \end{syntax} % % % \subsection{Margins and line shape}\label{rMarginsAndLineShape} % % \begin{syntax} % \item[0.21,\linewidth] \rkeyname{linewidth}|=|\meta{dimension} % % defines the base line width for listings. The following three keys are % taken into account additionally. % % \item[0.19,0pt] \rkeyname{xleftmargin}|=|\meta{dimension} % \item[1.0,0pt] \rkeyname{xrightmargin}|=|\meta{dimension} % % The dimensions are used as extra margins on the left and right. Line % numbers and frames both move respectively shrink or grow accordingly. % % \item[0.19,false] \rkeyname{resetmargins}|=|\meta{\alternative{true,false}} % % If true indention from list environments like \texttt{enumerate} or % \texttt{itemize} is reset, i.e.~not used. % % \item[0.20,false] \rkeyname{breaklines}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{breaklines} % % activates or deactivates automatic line breaking of long lines. % % \item[0.20,{{}}] \rkeyname{prebreak}|=|\meta{tokens} % \item[0.20,{{}}] \rkeyname{postbreak}|=|\meta{tokens} % % \meta{tokens} appear at the end of the current line respectively at the beginning of the next (broken part of the) line. % % You must not use dynamic space (in particular spaces) since internally we use |\discretionary|. % However |\space| is redefined to be used inside \meta{tokens}. % % \item[0.20,20pt] \rkeyname{breakindent}|=|\meta{dimension} % % is the indention of the second, third, \ldots\ line of broken lines. % % \item[0.20,true] \rkeyname{breakautoindent}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{breakautoindent} % % activates or deactivates automatic indention of broken lines. This % indention is used additionally to \ikeyname{breakindent}, see the % example below. % Visible spaces or visible tabulators might set this auto % indention to zero. % \end{syntax} % In the following example we use tabulators to create long lines, but the % verbatim part uses |tabsize=1|. % \begin{lstxsample} % \lstset{postbreak=\space, breakindent=5pt, breaklines} % \end{lstxsample} % \begin{lstsample}{\lstset{string=[d]",tabsize=6}}{\lstset{tabsize=1}\hfuzz=1in} % \begin{lstlisting} % "A long string is broken!" % "Another long line." % \end{lstlisting} % % \begin{lstlisting}[breakautoindent % =false] % { Now auto indention is off. } % \end{lstlisting} % \end{lstsample} % % % \subsection{Frames}\label{rFrames} % % \begin{syntax} % \item[1.0,none] \rkeyname{frame}|=|\meta{\alternative{none,leftline,topline,bottomline,lines,single,shadowbox}} % % draws either no frame, a single line on the left, at the top, at the % bottom, at the top and bottom, a whole single frame, or a shadowbox. % % Note that \packagename{fancyvrb} supports the same frame types except % \texttt{shadowbox}. The shadow color is \keyname{rulesepcolor}, see % below. % % \item[0.19,{{}}] \rkeyname{frame}|=|\meta{subset of \textup{\texttt{trblTRBL}}} % % The characters \texttt{trblTRBL} are attached to lines at the top and % bottom of a listing and to lines on the right and left. Upper case % characters are used to draw double rules. So |frame=tlrb| draws a % single frame and |frame=TL| double lines at the top and on the left. % % Note that frames usually reside outside the listing's space. % % \item[0.20,ffff] \rkeyname{frameround}|=|\meta{\alternative{t,f}}\meta{\alternative{t,f}}\meta{\alternative{t,f}}\meta{\alternative{t,f}} % % The four letters are attached to the top right, bottom right, bottom % left and top left corner. In this order. \texttt{t} makes the % according corner round. If you use round corners, the rule width is % controlled via |\thinlines| and |\thicklines|. % % Note: The size of the quarter circles depends on \keyname{framesep} % and is independent of the extra margins of a frame. The size is % possibly adjusted to fit \LaTeX's circle sizes. % % \item[0.19,3pt] \rkeyname{framesep}|=|\meta{dimension} % \item[0.19,2pt] \rkeyname{rulesep}|=|\meta{dimension} % % control the space between frame and listing and between double rules. % % \item[0.19,0.4pt] \rkeyname{framerule}|=|\meta{dimension} % % controls the width of the rules. % % \item[1.0,0pt] \rkeyname{framexleftmargin}|=|\meta{dimension} % \item[1.0,0pt] \rkeyname{framexrightmargin}|=|\meta{dimension} % \item[1.0,0pt] \rkeyname{framextopmargin}|=|\meta{dimension} % \item[1.0,0pt] \rkeyname{framexbottommargin}|=|\meta{dimension} % % are the dimensions which are used additionally to \keyname{framesep} % to make up the margin of a frame. % % \item[0.21] \rkeyname{backgroundcolor}|=|\meta{color command} % \item[0.21] \rkeyname{rulecolor}|=|\meta{color command} % \item[1.0] \rkeyname{fillcolor}|=|\meta{color command} % \item[1.0] \rkeyname{rulesepcolor}|=|\meta{color command} % % specify the colour of the background, the rules, the space between % `text box' and first rule, and of the space between two rules, % respectively. % Note that the value requires a |\color| command, for example % \keyname{rulecolor}|=\color{blue}|. % \end{syntax} % \ikeyname{frame} does not work with |fancyvrb=true| or when the package % internally makes a |\hbox| around the listing! And there are certainly more % problems with other commands. Take the time to make a (bug) report. %\ifcolor % \begin{lstxsample} % \lstset{framexleftmargin=5mm, frame=shadowbox, rulesepcolor=\color{blue}} % \end{lstxsample} %\else % \lstset{framexleftmargin=5mm, frame=shadowbox} %\fi % \begin{lstsample}{}{} % \begin{lstlisting}[numbers=left] % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % % Do you want exotic frames? % Try the following key if you want for example % \begin{lstsample}{\lstset{frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}}}{} % \begin{lstlisting} % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % \begin{syntax} % \item[0.20,,\dag] \rkeyname{frameshape}|=|\marg{top shape}\marg{left shape}\marg{right shape}\marg{bottom shape} % % gives you full control over the drawn frame parts. % The arguments are not case sensitive. % % Both \meta{left shape} and \meta{right shape} are `left-to-right' % \alternative{y,n} character sequences (or empty). Each |y| lets the % package draw a rule, otherwise the rule is blank. These vertical rules % are drawn `left-to-right' according to the specified shapes. % The example above uses |yny|. % % \meta{top shape} and \meta{bottom shape} are `left-rule-right' % sequences (or empty). The first `left-rule-right' sequence is attached % to the most inner rule, the second to the next, and so on. % Each sequence has three characters: `rule' is either |y| or |n|; % `left' and `right' are |y|, |n| or |r| (which makes a corner round). % The example uses |RYRYNYYYY| for both shapes: % |RYR| describes the most inner (top and bottom) frame shape, |YNY| % the middle, and |YYY| the most outer. % \end{syntax} % To summarize, the example above used % \begin{verbatim} % \lstset{frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}}\end{verbatim} % Note that you are not resticted to two or three levels. % However you'll get in trouble if you use round corners when they are too big. % % % \subsection{Indexing} % % \begin{syntax} % \item[0.19] \rkeyname{index}|=|\oarg{number}\oarg{keyword classes}\marg{identifiers} % \item[0.21] \rkeyname{moreindex}|=|\oarg{number}\oarg{keyword classes}\marg{identifiers} % \item[0.21] \rkeyname{deleteindex}|=|\oarg{number}\oarg{keyword classes}\marg{identifiers} % % define, add and remove \meta{identifiers} and \meta{keyword classes} % from the index class list \meta{number}. If you don't specify the % optional number, the package assumes \meta{number} $=1$. % % Each appearance of the explicitly given identifiers and each appearance % of the identifiers of the specified \meta{keyword classes} is indexed. % For example, you could write |index=[1][keywords]| to index all % keywords. Note that |[1]| is required here---otherwise we couldn't use % the second optional argument. % % \item[0.19,\lstindexmacro] \rkeyname{indexstyle}|=|\oarg{number}\meta{tokens \textup(one-parameter command\textup)} % % \meta{tokens} actually indexes the identifiers for the list % \meta{number}. In contrast to the style keys, \meta{tokens} % \emph{must} read exactly one parameter, namely the identifier. % Default definition is\icmdname{\lstindexmacro}\vspace*{-\itemsep} % \begin{verbatim} % \newcommand\lstindexmacro[1]{\index{{\ttfamily#1}}}\end{verbatim} % \vspace*{-\itemsep}which you shouldn't modify. % Define your own indexing commands and use them as argument to this key. % \end{syntax} % Section \ref{uIndexing} describes this feature in detail. % % % \subsection{Column alignment}\label{rColumnAlignment} % % \begin{syntax} % \item[1.0,{[c]fixed}] \rkeyname{columns}|=|\oarg{\alternative{c,l,r}}\meta{\alternative{fixed,flexible,fullflexible}} % % selects the respective column format, refer section % \ref{uFixedAndFlexibleColumns}. % % The optional |c|, |l|, or |r| controls the horizontal orientation of % smallest output units (keywords, identifiers, etc.). The arguments work % as follows, where vertical bars visualize the effect: % $\vert$\lstinline[columns={[c]fixed}]!listing!$\vert$, % $\vert$\lstinline[columns={[l]fixed}]!listing!$\vert$, and % $\vert$\lstinline[columns={[r]fixed}]!listing!$\vert$ % in fixed column mode, % $\vert$\lstinline[columns={[c]flexible}]!listing!$\vert$, % $\vert$\lstinline[columns={[l]flexible}]!listing!$\vert$, and % $\vert$\lstinline[columns={[r]flexible}]!listing!$\vert$ % with flexible columns, and % $\vert$\lstinline[columns={[c]fullflexible}]!listing!$\vert$, % $\vert$\lstinline[columns={[l]fullflexible}]!listing!$\vert$, and % $\vert$\lstinline[columns={[r]fullflexible}]!listing!$\vert$ % with full flexible columns. % % \item[0.18,false] \rkeyname{flexiblecolumns}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{flexiblecolumns} % % selects the most recently selected flexible or fixed column format, % refer to section \ref{uFixedAndFlexibleColumns}. % % \item[0.21,false,\dag] \rkeyname{keepspaces}|=|\meta{\alternative{true,false}} % % |keepspaces=true| tells the package not to drop spaces to fix column % alignment and always converts tabulators to spaces. % % \item[0.16] \rkeyname{basewidth}|=|\meta{dimension}\syntaxor % \item[0.18,{{0.6em,0.45em}}] \rkeyname{basewidth}|={|\meta{fixed}|,|\meta{flexible mode}|}| % % sets the width of a single character box for fixed and flexible column % mode (both to the same value or individually). % % \item[0.20,false] \rkeyname{fontadjust}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{fontadjust} % % If true the package adjusts the base width every font selection. % This makes sense only if \ikeyname{basewidth} is given in font specific % units like `em' or `ex'---otherwise this boolean has no effect. % % After loading the package, it doesn't adjust the width every font % selection: it looks at \ikeyname{basewidth} each listing and uses the % value for the whole listing. This is possibly inadequate if the style % keys in section \ref{rFigureOutTheAppearance} make heavy font size % changes, see the example below. % % Note that this key might disturb the column alignment and might have an % effect on the keywords' appearance! % \end{syntax} % \begin{lstsample}{\lstset{basicstyle=\normalsize}}{} % \lstset{commentstyle=\scriptsize} % \begin{lstlisting} % { scriptsize font % doesn't look good } % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % \begin{lstsample}{\lstset{basicstyle=\normalsize,commentstyle=\scriptsize}}{} % \begin{lstlisting}[fontadjust] % { scriptsize font % looks better now } % for i:=maxint to 0 do % begin % { do nothing } % end; % \end{lstlisting} % \end{lstsample} % % % \subsection{Escaping to \LaTeX}\label{rEscapingToLaTeX} % % \textbf{Note:} {\itshape Any escape to \LaTeX\ may disturb the column % alignment since the package can't control the spacing there.} % \begin{syntax} % \item[0.18,false] \rkeyname{texcl}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{texcl} % % activates or deactivates \LaTeX\ comment lines. If activated, comment % line delimiters are printed as usual, but the comment line text (up to % the end of line) is read as \LaTeX\ code and typeset in comment style. % \end{syntax} % The example uses \Cpp\ comment lines (but doesn't say how to define them). % Without |\upshape| we would get \textit{calculate} since the comment style % is |\itshape|. % \begin{lstsample}{\lstset{morecomment=[l]//}}{} % \begin{lstlisting}[texcl] % // \upshape calculate $a_{ij}$ % A[i][j] = A[j][j]/A[i][j]; % \end{lstlisting} % \end{lstsample} % % \begin{syntax} % \item[0.19,false] \rkeyname{mathescape}|=|\meta{\alternative{true,false}} % % activates or deactivates special behaviour of the dollar sign. % If activated a dollar sign acts as \TeX's text math shift. % % This key is useful if you want to typeset formulas in listings. % % \item[0.19,{{}}] \rkeyname{escapechar}|=|\meta{character}\syntaxor\rkeyname{escapechar}|={}| % % If not empty the given character escapes the user to \LaTeX: all code % between two such characters is interpreted as \LaTeX\ code. Note that % \TeX's special characters must be entered with a preceding backslash, % e.g.~|escapechar=\%|. % % \item[0.20,{{}}] \rkeyname{escapeinside}|=|\meta{character}\meta{character}\syntaxor\rkeyname{escapeinside}|={}| % % Is a generalization of \ikeyname{escapechar}. If the value is not % empty, the package escapes to \LaTeX\ between the first and second % character. % % \item[0.20,{{}}] \rkeyname{escapebegin}|=|\meta{tokens} % \item[0.20,{{}}] \rkeyname{escapeend}|=|\meta{tokens} % % The tokens are executed at the beginning respectively at the end of % each escape, in particular for \ikeyname{texcl}. % See section \ref{uNationalCharacters} for an application. % \end{syntax} % % \begin{lstsample}{\lstset{morecomment=[l]//}}{} % \begin{lstlisting}[mathescape] % // calculate $a_{ij}$ % $a_{ij} = a_{jj}/a_{ij}$; % \end{lstlisting} % \end{lstsample} % % \begin{lstsample}{\lstset{morecomment=[l]//}}{} % \begin{lstlisting}[escapechar=\%] % // calc%ulate $a_{ij}$% % %$a_{ij} = a_{jj}/a_{ij}$%; % \end{lstlisting} % \end{lstsample} % % \begin{lstsample}{\lstset{morecomment=[l]//}}{} % \lstset{escapeinside=`'} % \begin{lstlisting} % // calc`ulate $a_{ij}$' % `$a_{ij} = a_{jj}/a_{ij}$'; % \end{lstlisting} % \end