| 1 |
% \iffalse |
| 2 |
% |
| 3 |
% Trademarks appear throughout this documentation without any trademark |
| 4 |
% symbol, so you can't assume that a name is free. There is no intention |
| 5 |
% of infringement; the usage is to the benefit of the trademark owner. |
| 6 |
% |
| 7 |
% |
| 8 |
% S O F T W A R E L I C E N S E |
| 9 |
% ================================= |
| 10 |
% |
| 11 |
% The files listings.dtx and listings.ins and all files generated |
| 12 |
% from only these two files are referred to as `the listings package' |
| 13 |
% or simply `the package'. lstdrvrs.dtx and the files generated from |
| 14 |
% that file are `drivers'. |
| 15 |
% |
| 16 |
% The listings package is copyright 1996--2004 Carsten Heinz, and |
| 17 |
% continued maintenance on the package is copyright 2006--2007 Brooks |
| 18 |
% Moses. From 2013 on copyright is Jobst Hoffmann, who is the maintainer |
| 19 |
% since july 2013. The drivers are copyright 1997/1998/1999/2000/2001/ |
| 20 |
% 2002/2003/2004/2006/2007/2013 any individual author listed in the |
| 21 |
% driver files. |
| 22 |
% |
| 23 |
% The listings package and its drivers may be distributed and/or modified |
| 24 |
% under the conditions of the LaTeX Project Public License, either version |
| 25 |
% 1.3c of this license or (at your option) any later version. |
| 26 |
% The latest version of this license is in |
| 27 |
% http://www.latex-project.org/lppl.txt |
| 28 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 29 |
% version 2003/12/01 or later. |
| 30 |
% |
| 31 |
% The package has the LPPL maintenance status "maintained". |
| 32 |
% |
| 33 |
% The Current Maintainer is Jobst Hoffmann <j.hoffmann(at)fh-aachen.de>. |
| 34 |
% |
| 35 |
% end of software license |
| 36 |
% |
| 37 |
% |
| 38 |
%<*driver> |
| 39 |
\documentclass[a4paper]{ltxdoc} |
| 40 |
% \DisableCrossrefs |
| 41 |
% \OnlyDescription |
| 42 |
|
| 43 |
\usepackage{lstdoc} % the basic support package for generating |
| 44 |
% the documentation of this package |
| 45 |
\usepackage{textcomp} % needed for upquote apostrophes |
| 46 |
\usepackage{mdframed} % frames for external files |
| 47 |
\usepackage{moreverb} % writing external files |
| 48 |
\usepackage{xcolor} % because of coloring the background |
| 49 |
\usepackage{tablefootnote} % because of \tablefootnote |
| 50 |
|
| 51 |
\makeindex |
| 52 |
|
| 53 |
\begin{document} |
| 54 |
\DocInput{listings.dtx} |
| 55 |
\end{document} |
| 56 |
%</driver> |
| 57 |
% \fi |
| 58 |
% |
| 59 |
%^^A |
| 60 |
%^^A Command/key to aspect relation |
| 61 |
%^^A ================================ |
| 62 |
%^^A |
| 63 |
%\lstisaspect[strings]{string,morestring,deletestring,stringstyle,showstringspaces} |
| 64 |
%\lstisaspect[comments]{comment,morecomment,deletecomment,commentstyle} |
| 65 |
%\lstisaspect[comment styles]{b,d,l,n,s,ib,id,il,in,is} |
| 66 |
%\lstisaspect[pod]{printpod,podcomment} |
| 67 |
%\lstisaspect[escape]{texcl,escapebegin,escapeend,escapechar,escapeinside,mathescape} |
| 68 |
%\lstisaspect[keywords]{sensitive,classoffset,keywords,morekeywords,^^A |
| 69 |
% deletekeywords,keywordstyle,ndkeywords,morendkeywords,deletendkeywords,^^A |
| 70 |
% ndkeywordstyle,keywordsprefix,otherkeywords} |
| 71 |
%\lstisaspect[emph]{emph,moreemph,deleteemph,emphstyle} |
| 72 |
%\lstisaspect[tex]{texcs,moretexcs,deletetexcs,texcsstyle} |
| 73 |
%\lstisaspect[directives]{directives,moredirectives,deletedirectives,directivestyle} |
| 74 |
%\lstisaspect[html]{tag,usekeywordsintag,tagstyle,markfirstintag} |
| 75 |
%\lstisaspect[keywordcomments]{keywordcomment,morekeywordcomment,^^A |
| 76 |
% deletekeywordcomment,keywordcommentsemicolon} |
| 77 |
%\lstisaspect[index]{index,moreindex,deleteindex,indexstyle,\string\lstindexmacro} |
| 78 |
%\lstisaspect[procnames]{procnamestyle,indexprocnames,procnamekeys,^^A |
| 79 |
% moreprocnamekeys,deleteprocnamekeys} |
| 80 |
%\lstisaspect[style]{style,\string\lstdefinestyle,\string\lst@definestyle,^^A |
| 81 |
% \string\lststylefiles} |
| 82 |
%\lstisaspect[language]{language,alsolanguage,defaultdialect,^^A |
| 83 |
% \string\lstalias,\string\lstdefinelanguage,\string\lst@definelanguage,^^A |
| 84 |
% \string\lstloadlanguages,\string\lstlanguagefiles} |
| 85 |
%\lstisaspect[formats]{format,fmtindent,\string\lstdefineformat,^^A |
| 86 |
% \string\lst@defineformat,\string\lstformatfiles} |
| 87 |
%\lstisaspect[labels]{numbers,numberstyle,numbersep,stepnumber,^^A |
| 88 |
% numberblanklines,firstnumber,\string\thelstnumber,numberfirstline} |
| 89 |
%\lstisaspect[lineshape]{xleftmargin,xrightmargin,resetmargins,linewidth,^^A |
| 90 |
% lineskip,breaklines,breakindent,breakautoindent,prebreak,postbreak,^^A |
| 91 |
% breakatwhitespace} |
| 92 |
%\lstisaspect[frames]{framexleftmargin,framexrightmargin,framextopmargin,^^A |
| 93 |
% framexbottommargin,backgroundcolor,fillcolor,rulecolor,rulesepcolor,^^A |
| 94 |
% rulesep,framerule,framesep,frameshape,frameround,frame} |
| 95 |
%\lstisaspect[make]{makemacrouse} |
| 96 |
%\lstisaspect[fancyvrb]{fancyvrb,fvcmdparams,morefvcmdparams} |
| 97 |
%\lstisaspect[lgrind]{lgrindef,\string\lstlgrindeffile} |
| 98 |
%\lstisaspect[hyper]{hyperref,morehyperref,deletehyperref,hyperanchor,hyperlink} |
| 99 |
%\lstisaspect[kernel]{basewidth,fontadjust,columns,flexiblecolumns,identifierstyle,^^A |
| 100 |
% tabsize,showtabs,tab,showspaces,keepspaces,formfeed,SelectCharTable,^^A |
| 101 |
% MoreSelectCharTable,extendedchars,alsoletter,alsodigit,alsoother,excludedelims,^^A |
| 102 |
% literate,basicstyle,print,firstline,lastline,linerange,^^A |
| 103 |
% consecutivenumbers,nolol,captionpos,abovecaptionskip,^^A |
| 104 |
% belowcaptionskip,label,title,caption,\string\lstlistingname,^^A |
| 105 |
% \string\lstlistingnamestyle,boxpos,float,^^A |
| 106 |
% floatplacement,aboveskip,belowskip,everydisplay,showlines,emptylines,gobble,name,^^A |
| 107 |
% \string\lstname,\string\lstlistlistingname,\string\lstlistoflistings,^^A |
| 108 |
% \string\lstnewenvironment,\string\lstinline,\string\lstinputlisting,lstlisting,^^A |
| 109 |
% \string\lstloadaspects,\string\lstset,\string\thelstlisting,\string\lstaspectfiles,^^A |
| 110 |
% inputencoding,inputpath,delim,moredelim,deletedelim,upquote,numberbychapter,^^A |
| 111 |
% \string\lstMakeShortInline,\string\lstDeleteShortInline} |
| 112 |
%\lstisaspect[doc]{lstsample,lstxsample}^^A environment |
| 113 |
%\lstisaspect[experimental]{includerangemarker,rangebeginprefix,rangebeginsuffix,^^A |
| 114 |
% rangeendprefix,rangeendsuffix,rangeprefix,rangesuffix} |
| 115 |
% |
| 116 |
%^^A |
| 117 |
%^^A The long awaited beginning of documentation |
| 118 |
%^^A ============================================= |
| 119 |
%^^A |
| 120 |
%\newbox\abstractbox |
| 121 |
%\setbox\abstractbox=\vbox{% |
| 122 |
% \begin{abstract} |
| 123 |
% The \packagename{listings} package is a source code printer for \LaTeX. |
| 124 |
% You can typeset stand alone files as well as listings with an environment |
| 125 |
% similar to \texttt{verbatim} as well as you can print code snippets using |
| 126 |
% a command similar to |\verb|. |
| 127 |
% Many parameters control the output and if your preferred programming |
| 128 |
% language isn't already supported, you can make your own definition. |
| 129 |
% \end{abstract}} |
| 130 |
% |
| 131 |
% \title{\vspace*{-2\baselineskip}The \packagename{Listings} Package} |
| 132 |
% \author{Copyright 1996--2004, Carsten Heinz% |
| 133 |
% \\ Copyright 2006--2007, Brooks Moses |
| 134 |
% \\ Copyright 2013--, Jobst Hoffmann |
| 135 |
% \\ Maintainer: Jobst Hoffmann\thanks{Jobst % |
| 136 |
% Hoffmann became the maintainer of the \packagename{listings} |
| 137 |
% package in 2013; see the Preface for details.}~ % |
| 138 |
% \textless\lstemail\textgreater} |
| 139 |
% \date{2025/11/14\enspace\enspace Version 1.11b\ \box\abstractbox} |
| 140 |
% \def\lstemail{\href{mailto:[email protected]}{\texttt{j.hoffmann(at)fh-aachen.de}}} |
| 141 |
% \ifhyper |
| 142 |
% \hypersetup{pdftitle=The Listings Package v1.11, |
| 143 |
% pdfsubject=Package guide, |
| 144 |
% pdfauthor=Jobst Hoffmann <j.hoffmann(at)fh-aachen.de>,% |
| 145 |
% pdfkeywords={source code formatter, programming languages}} |
| 146 |
% \fi |
| 147 |
% |
| 148 |
% \csname @twocolumntrue\endcsname |
| 149 |
% \maketitle |
| 150 |
%^^A \enlargethispage{2\baselineskip} |
| 151 |
% \csname @starttoc\endcsname{toc} |
| 152 |
% \onecolumn |
| 153 |
% |
| 154 |
% |
| 155 |
% \section*{Preface} |
| 156 |
% |
| 157 |
% \paragraph{Transition of package maintenance} |
| 158 |
% The \TeX\ world lost contact with Carsten Heinz in late 2004, shortly after |
| 159 |
% he released version 1.3b of the \packagename{listings} package. After many |
| 160 |
% attempts to reach him had failed, Hendri Adriaens took over maintenance of |
| 161 |
% the package in accordance with the LPPL's procedure for abandoned packages. |
| 162 |
% He then passed the maintainership of the package to Brooks Moses, who had |
| 163 |
% volunteered for the position while this procedure was going through. The |
| 164 |
% result is known as listings version 1.4. |
| 165 |
% |
| 166 |
% This release, version 1.5, is a minor maintenance release since |
| 167 |
% I accepted maintainership of the package. I would like to thank Stephan |
| 168 |
% Hennig who supported the Lua language definitions. He is the one who |
| 169 |
% asked for the integration of a new language and gave the impetus to me to |
| 170 |
% become the maintainer of this package. |
| 171 |
% |
| 172 |
% |
| 173 |
% \paragraph{News and changes} |
| 174 |
% Version 1.5 is the fifth bugfix release. There are no changes |
| 175 |
% in this version, but two extensions: support of modern Fortran (2003, |
| 176 |
% 2008) and Lua. |
| 177 |
% |
| 178 |
% |
| 179 |
% \vfill |
| 180 |
% \paragraph{Thanks} |
| 181 |
% There are many people I have to thank for fruitful communication, posting |
| 182 |
% their ideas, giving error reports, adding programming languages to |
| 183 |
% \texttt{lstdrvrs.dtx}, and so on. Their names are listed in section |
| 184 |
% \ref{uClosingAndCredits}. |
| 185 |
% |
| 186 |
% \paragraph{Trademarks} |
| 187 |
% Trademarks appear throughout this documentation without any trademark |
| 188 |
% symbol; they are the property of their respective trademark owner. |
| 189 |
% There is no intention of infringement; the usage is to the benefit of the |
| 190 |
% trademark owner. |
| 191 |
% |
| 192 |
% |
| 193 |
% \clearpage |
| 194 |
% |
| 195 |
% |
| 196 |
% \part{User's guide} |
| 197 |
% |
| 198 |
% |
| 199 |
% \section{Getting started}\label{uGettingStarted} |
| 200 |
% |
| 201 |
% |
| 202 |
% \subsection{A minimal file}\label{uAMinimalFile} |
| 203 |
% |
| 204 |
% Before using the \packagename{listings} package, you should be familiar with |
| 205 |
% the \LaTeX\ typesetting system. You need not to be an expert. |
| 206 |
% Here is a minimal file for \packagename{listings}. |
| 207 |
% \begin{verbatim} |
| 208 |
% \documentclass{article} |
| 209 |
% \usepackage{listings} |
| 210 |
% |
| 211 |
% \begin{document} |
| 212 |
% \lstset{language=Pascal} |
| 213 |
% |
| 214 |
% % Insert Pascal examples here. |
| 215 |
% |
| 216 |
% \end{document}\end{verbatim} |
| 217 |
% Now type in this first example and run it through \LaTeX. |
| 218 |
% \begin{advise} |
| 219 |
% \item Must I do that really? |
| 220 |
% \advisespace |
| 221 |
% Yes and no. Some books about programming say this is good. |
| 222 |
% What a mistake! Typing takes time---which is wasted if the code is clear to |
| 223 |
% you. And if you need that time to understand what is going on, the |
| 224 |
% author of the book should reconsider the concept of presenting the |
| 225 |
% crucial things---you might want to say that about this guide even---or |
| 226 |
% you're simply inexperienced with programming. If only the latter case |
| 227 |
% applies, you should spend more time on reading (good) books about |
| 228 |
% programming, (good) documentations, and (good) source code from other |
| 229 |
% people. Of course you should also make your own experiments. |
| 230 |
% You will learn a lot. However, running the example through \LaTeX\ |
| 231 |
% shows whether the \packagename{listings} package is installed correctly. |
| 232 |
% \item The example doesn't work. |
| 233 |
% \advisespace |
| 234 |
% Are the two packages \packagename{listings} and \packagename{keyval} |
| 235 |
% installed on your system? Consult the administration tool of your |
| 236 |
% \TeX\ distribution, your system administrator, the local \TeX\ and |
| 237 |
% \LaTeX\ guides, a \TeX\ FAQ, and section \ref{rInstallation}---in |
| 238 |
% that order. If you've checked \emph{all} these sources and are |
| 239 |
% still helpless, you might want to write a post to a \TeX\ newsgroup |
| 240 |
% like \texttt{comp.text.tex}. |
| 241 |
% \item Should I read the software license before using the package? |
| 242 |
% \advisespace |
| 243 |
% Yes, but read this \emph{Getting started} section first to decide |
| 244 |
% whether you are willing to use the package.^^A ;-) |
| 245 |
% \end{advise} |
| 246 |
% |
| 247 |
% |
| 248 |
% \subsection{Typesetting listings} |
| 249 |
% |
| 250 |
% Three types of source codes are supported: code snippets, code segments, and |
| 251 |
% listings of stand alone files. Snippets are placed inside paragraphs and the |
| 252 |
% others as separate paragraphs---the difference is the same as between text |
| 253 |
% style and display style formulas. |
| 254 |
% \begin{advise} |
| 255 |
% \item No matter what kind of source you have, if a listing contains national |
| 256 |
% characters like \'e, \L, \"a, or whatever, you must tell the |
| 257 |
% package about it! Section \lstref{uSpecialCharacters} discusses this issue. |
| 258 |
% \end{advise} |
| 259 |
% |
| 260 |
% \paragraph{Code snippets} |
| 261 |
% The well-known \LaTeX\ command |\verb| typesets code snippets verbatim. |
| 262 |
% The new command |\lstinline| pretty-prints the code, for example |
| 263 |
%`\lstinline!var i:integer;!' is typeset by |
| 264 |
%`{\rstyle|\lstinline|}|!var i:integer;!|'. The exclamation marks delimit |
| 265 |
% the code and can be replaced by any character not in the code; |
| 266 |
% |\lstinline$var i:integer;$| gives the same result. |
| 267 |
% |
| 268 |
% \paragraph{Displayed code} |
| 269 |
% The \texttt{lstlisting} environment typesets the enclosed source code. Like |
| 270 |
% most examples, the following one shows verbatim \LaTeX\ code on the right |
| 271 |
% and the result on the left. You might take the right-hand side, put it into |
| 272 |
% the minimal file, and run it through \LaTeX. |
| 273 |
% \begin{lstsample}[lstlisting]{}{} |
| 274 |
% \begin{lstlisting} |
| 275 |
% for i:=maxint to 0 do |
| 276 |
% begin |
| 277 |
% { do nothing } |
| 278 |
% end; |
| 279 |
% |
| 280 |
% Write('Case insensitive '); |
| 281 |
% WritE('Pascal keywords.'); |
| 282 |
% \end{lstlisting} |
| 283 |
% \end{lstsample} |
| 284 |
% It can't be easier. |
| 285 |
% \begin{advise} |
| 286 |
% \item That's not true. The name `\texttt{listing}' is shorter. |
| 287 |
% \advisespace |
| 288 |
% Indeed. But other packages already define environments with that name. |
| 289 |
% To be compatible with such packages, all commands and environments of |
| 290 |
% the \packagename{listings} package use the prefix `\texttt{lst}'. |
| 291 |
% \end{advise} |
| 292 |
% The environment provides an optional argument. It tells the package to |
| 293 |
% perform special tasks, for example, to print only the lines 2--5: |
| 294 |
% \begin{lstsample}{\lstset{frame=trbl,framesep=0pt}\label{gFirstKey=ValueList}}{} |
| 295 |
% \begin{lstlisting}[firstline=2, |
| 296 |
% lastline=5] |
| 297 |
% for i:=maxint to 0 do |
| 298 |
% begin |
| 299 |
% { do nothing } |
| 300 |
% end; |
| 301 |
% |
| 302 |
% Write('Case insensitive '); |
| 303 |
% WritE('Pascal keywords.'); |
| 304 |
% \end{lstlisting} |
| 305 |
% \end{lstsample} |
| 306 |
% \begin{advise} |
| 307 |
% \item Hold on! Where comes the frame from and what is it good for? |
| 308 |
% \advisespace |
| 309 |
% You can put frames around all listings except code snippets. |
| 310 |
% You will learn how later. The frame shows that empty lines at the end |
| 311 |
% of listings aren't printed. This is line 5 in the example. |
| 312 |
% \item Hey, you can't drop my empty lines! |
| 313 |
% \advisespace |
| 314 |
% You can tell the package not to drop them: |
| 315 |
% The key `\ikeyname{showlines}' controls these empty lines and is |
| 316 |
% described in section \ref{rTypesettingListings}. Warning: First |
| 317 |
% read ahead on how to use keys in general. |
| 318 |
% \item I get obscure error messages when using `\ikeyname{firstline}'. |
| 319 |
% \advisespace |
| 320 |
% That shouldn't happen. Make a bug report as described in section |
| 321 |
% \lstref{uTroubleshooting}. |
| 322 |
% \end{advise} |
| 323 |
% |
| 324 |
% \paragraph{Stand alone files} |
| 325 |
% Finally we come to |\lstinputlisting|, the command used to pretty-print |
| 326 |
% stand alone files. It has one optional and one file name argument. |
| 327 |
% Note that you possibly need to specify the relative path to the file. |
| 328 |
% Here now the result is printed below the verbatim code since both together |
| 329 |
% don't fit the text width. |
| 330 |
% \begin{lstsample}{\lstset{comment=[l]\%,columns=fullflexible}}^^A |
| 331 |
% {\lstset{alsoletter=\\,emph=\\lstinputlisting,emphstyle=\rstyle}^^A |
| 332 |
% \lstaspectindex{\lstinputlisting}{}} |
| 333 |
% \lstinputlisting[lastline=4]{listings.sty} |
| 334 |
% \end{lstsample} |
| 335 |
% \begin{advise} |
| 336 |
% \item The spacing is different in this example. |
| 337 |
% \advisespace |
| 338 |
% Yes. The two previous examples have aligned columns, i.e.~columns with |
| 339 |
% identical numbers have the same horizontal position---this package |
| 340 |
% makes small adjustments only. The columns in the example here are not |
| 341 |
% aligned. This is explained in section \ref{uFixedAndFlexibleColumns} |
| 342 |
% (keyword: full flexible column format). |
| 343 |
% \end{advise} |
| 344 |
% |
| 345 |
% Now you know all pretty-printing commands and environments. It remains |
| 346 |
% to learn the parameters which control the work of the \packagename{listings} |
| 347 |
% package. This is, however, the main task. Here are some of them. |
| 348 |
% |
| 349 |
% |
| 350 |
% \subsection{Figure out the appearance}\label{gFigureOutTheAppearance} |
| 351 |
% |
| 352 |
% Keywords are typeset bold, comments in italic shape, and spaces in strings |
| 353 |
% appear as \textvisiblespace. You don't like these settings? Look at this: |
| 354 |
%\ifcolor |
| 355 |
% \begin{lstxsample}[basicstyle,keywordstyle,identifierstyle,commentstyle,^^A |
| 356 |
% stringstyle,showstringspaces] |
| 357 |
% \lstset{% general command to set parameter(s) |
| 358 |
% basicstyle=\small, % print whole listing small |
| 359 |
% keywordstyle=\color{black}\bfseries\underbar, |
| 360 |
% % underlined bold black keywords |
| 361 |
% identifierstyle=, % nothing happens |
| 362 |
% commentstyle=\color{white}, % white comments |
| 363 |
% stringstyle=\ttfamily, % typewriter type for strings |
| 364 |
% showstringspaces=false} % no special string spaces |
| 365 |
% \end{lstxsample} |
| 366 |
%\else |
| 367 |
% \begin{lstxsample}[basicstyle,keywordstyle,identifierstyle,commentstyle,^^A |
| 368 |
% stringstyle,showstringspaces] |
| 369 |
% \lstset{% general command to set parameter(s) |
| 370 |
% basicstyle=\small, % print whole listing small |
| 371 |
% keywordstyle=\bfseries\underbar, |
| 372 |
% % underlined bold keywords |
| 373 |
% identifierstyle=, % nothing happens |
| 374 |
% commentstyle=\itshape, % default |
| 375 |
% stringstyle=\ttfamily, % typewriter type for strings |
| 376 |
% showstringspaces=false} % no special string spaces |
| 377 |
% \end{lstxsample} |
| 378 |
%\fi |
| 379 |
% \begin{lstsample}{}{} |
| 380 |
% \begin{lstlisting} |
| 381 |
% for i:=maxint to 0 do |
| 382 |
% begin |
| 383 |
% { do nothing } |
| 384 |
% end; |
| 385 |
% |
| 386 |
% Write('Case insensitive '); |
| 387 |
% WritE('Pascal keywords.'); |
| 388 |
% \end{lstlisting} |
| 389 |
% \end{lstsample} |
| 390 |
%\ifcolor |
| 391 |
% \begin{advise} |
| 392 |
% \item You've requested white coloured comments, but I can see the comment |
| 393 |
% on the left side. |
| 394 |
% \advisespace |
| 395 |
% There are a couple of possible reasons: |
| 396 |
% (1) You've printed the documentation on nonwhite paper. |
| 397 |
% (2) If you are viewing this documentation as a \texttt{.dvi}-file, your |
| 398 |
% viewer seems to have problems with colour specials. Try to print |
| 399 |
% the page on white paper. |
| 400 |
% (3) If a printout on white paper shows the comment, the colour |
| 401 |
% specials aren't suitable for your printer or printer driver. |
| 402 |
% Recreate the documentation and try it again---and ensure that |
| 403 |
% the \packagename{color} package is well-configured. |
| 404 |
% \end{advise} |
| 405 |
%\fi |
| 406 |
% The styles use two different kinds of commands. |\ttfamily| and |\bfseries| |
| 407 |
% both take no arguments but |\underbar| does; it underlines the following |
| 408 |
% argument. In general, the \emph{very last} command may read exactly one |
| 409 |
% argument, namely some material the package typesets. There's one exception. |
| 410 |
% The last command of \ikeyname{basicstyle} \emph{must not} read any |
| 411 |
% tokens---or you will get deep in trouble. |
| 412 |
% \begin{advise} |
| 413 |
% \item `|basicstyle=\small|' looks fine, but comments look really bad with |
| 414 |
% `|commentstyle=\tiny|' and empty basic style, say. |
| 415 |
% \advisespace |
| 416 |
% Don't use different font sizes in a single listing. |
| 417 |
% \item But I really want it! |
| 418 |
% \advisespace |
| 419 |
% No, you don't. |
| 420 |
%^^A The package adjusts internal data after selecting the basic style at |
| 421 |
%^^A the beginning of each listing. This is a problem if you change the |
| 422 |
%^^A font size for comments or strings, for example. |
| 423 |
%^^A Section \ref{rColumnAlignment} shows how to overcome this. |
| 424 |
%^^A But once again: Don't use different font sizes in a single listing |
| 425 |
%^^A unless you really know what you are doing. |
| 426 |
% \end{advise} |
| 427 |
% |
| 428 |
% \paragraph{Warning}\label{wStrikingStyles} |
| 429 |
% You should be very careful with striking styles; the recent example is rather |
| 430 |
% moderate---it can get horrible. \emph{Always use decent highlighting.} |
| 431 |
% Unfortunately it is difficult to give more recommendations since they depend |
| 432 |
% on the type of document you're creating. Slides or other presentations often |
| 433 |
% require more striking styles than books, for example. |
| 434 |
% In the end, it's \emph{you} who have to find the golden mean! |
| 435 |
% |
| 436 |
% |
| 437 |
% \subsection{Seduce to use}\label{gSeduceToUse} |
| 438 |
% |
| 439 |
% You know all pretty-printing commands and some main parameters. Here now |
| 440 |
% comes a small and incomplete overview of other features. The table of |
| 441 |
% contents and the index also provide information. |
| 442 |
% |
| 443 |
% \paragraph{Line numbers} |
| 444 |
% are available for all displayed listings, e.g.~tiny numbers on the left, each |
| 445 |
% second line, with 5pt distance to the listing: |
| 446 |
% \begin{lstxsample}[numbers,numberstyle,stepnumber,numbersep] |
| 447 |
% \lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt} |
| 448 |
% \end{lstxsample} |
| 449 |
% \begin{lstsample}{}{} |
| 450 |
% \begin{lstlisting} |
| 451 |
% for i:=maxint to 0 do |
| 452 |
% begin |
| 453 |
% { do nothing } |
| 454 |
% end; |
| 455 |
% |
| 456 |
% Write('Case insensitive '); |
| 457 |
% WritE('Pascal keywords.'); |
| 458 |
% \end{lstlisting} |
| 459 |
% \end{lstsample} |
| 460 |
% \begin{advise} |
| 461 |
% \item I can't get rid of line numbers in subsequent listings. |
| 462 |
% \advisespace |
| 463 |
% `|numbers=none|' turns them off. |
| 464 |
% \item Can I use these keys in the optional arguments? |
| 465 |
% \advisespace |
| 466 |
% Of course. Note that optional arguments modify values for one |
| 467 |
% particular listing only: you change the appearance, step or distance |
| 468 |
% of line numbers for a single listing. The previous values are |
| 469 |
% restored afterwards. |
| 470 |
% \end{advise} |
| 471 |
% The environment allows you to interrupt your listings: you can end a listing |
| 472 |
% and continue it later with the correct line number even if there are other |
| 473 |
% listings in between. Read section \ref{uLineNumbers} for a thorough |
| 474 |
% discussion. |
| 475 |
% |
| 476 |
% \paragraph{Floating listings} |
| 477 |
% Displayed listings may float: |
| 478 |
% \begin{lstsample}{\lstset{frame=tb}}{} |
| 479 |
% \begin{lstlisting}[float,caption=A floating example] |
| 480 |
% for i:=maxint to 0 do |
| 481 |
% begin |
| 482 |
% { do nothing } |
| 483 |
% end; |
| 484 |
% |
| 485 |
% Write('Case insensitive '); |
| 486 |
% WritE('Pascal keywords.'); |
| 487 |
% \end{lstlisting} |
| 488 |
% \end{lstsample} |
| 489 |
% Don't care about the parameter \ikeyname{caption} now. And if you put the |
| 490 |
% example into the minimal file and run it through \LaTeX, please don't wonder: |
| 491 |
% you'll miss the horizontal rules since they are described elsewhere. |
| 492 |
% \begin{advise} |
| 493 |
% \item \LaTeX's float mechanism allows one to determine the placement of floats. |
| 494 |
% How can I do that with these? |
| 495 |
% \advisespace |
| 496 |
% You can write `|float=tp|', for example. |
| 497 |
% \end{advise} |
| 498 |
% |
| 499 |
% \paragraph{Other features} |
| 500 |
% There are still features not mentioned so far: automatic breaking of long |
| 501 |
% lines, the possibility to use \LaTeX\ code in listings, automated indexing, |
| 502 |
% or personal language definitions. |
| 503 |
% One more little teaser? Here you are. But note that the result is not |
| 504 |
% produced by the \LaTeX\ code on the right alone. The main parameter is |
| 505 |
% hidden. |
| 506 |
% \begin{lstsample}{^^A |
| 507 |
% \lstset{literate={:=}{{$\gets$}}1 {<=}{{$\leq$}}1 {>=}{{$\geq$}}1 ^^A |
| 508 |
% {<>}{{$\neq$}}1}}{} |
| 509 |
% \begin{lstlisting} |
| 510 |
% if (i<=0) then i := 1; |
| 511 |
% if (i>=0) then i := 0; |
| 512 |
% if (i<>0) then i := 0; |
| 513 |
% \end{lstlisting} |
| 514 |
% \end{lstsample} |
| 515 |
% |
| 516 |
% You're not sure whether you should use \packagename{listings}? |
| 517 |
% Read the next section! |
| 518 |
% |
| 519 |
% |
| 520 |
% \subsection{Alternatives} |
| 521 |
% |
| 522 |
% \begin{advise} |
| 523 |
% \item Why do you list alternatives? |
| 524 |
% \advisespace |
| 525 |
% Well, it's always good to know the competitors.^^A :-) |
| 526 |
% \item I've read the descriptions below and the \packagename{listings} package |
| 527 |
% seems to incorporate all the features. Why should I use one of the |
| 528 |
% other programs? |
| 529 |
% \advisespace |
| 530 |
% Firstly, the descriptions give a taste and not a complete overview, |
| 531 |
% secondly, \packagename{listings} lacks some properties, and, ultimately, |
| 532 |
% you should use the program matching your needs most precisely. |
| 533 |
% \end{advise} |
| 534 |
% This package is certainly not the final utility for typesetting source code. |
| 535 |
% Other programs do their job very well, if you are not satisfied with |
| 536 |
% \packagename{listings}. Some are independent of \LaTeX, others come as |
| 537 |
% separate program plus \LaTeX\ package, and others are packages which |
| 538 |
% don't pretty-print the source code. The second type includes converters, |
| 539 |
% cross compilers, and preprocessors. Such programs create \LaTeX\ files |
| 540 |
% you can use in your document or stand alone ready-to-run \LaTeX\ files. |
| 541 |
% |
| 542 |
% Note that I'm not dealing with any literate programming tools here, which |
| 543 |
% could also be alternatives. However, you should have heard of the |
| 544 |
% \texttt{WEB} system, the tool Prof.~Donald E.~Knuth developed and made use |
| 545 |
% of to document and implement \TeX. |
| 546 |
% |
| 547 |
% \paragraph{\href{http://www.infres.enst.fr/~demaille/a2ps}{\packagename{a2ps}}} |
| 548 |
% started as `ASCII to PostScript' converter, but today you can invoke the |
| 549 |
% program with \texttt{--pretty-print=}\meta{language} option. If your |
| 550 |
% favourite programming language is not already supported, you can write your |
| 551 |
% own so-called style sheet. You can request line numbers, borders, headers, |
| 552 |
% multiple pages per sheet, and many more. You can even print symbols like |
| 553 |
% $\forall$ or $\alpha$ instead of their verbose forms. If you just want |
| 554 |
% program listings and not a document with some listings, this is the best |
| 555 |
% choice. |
| 556 |
% |
| 557 |
% \paragraph{\href{http://mirror.ctan.org/support/lgrind}{\packagename{LGrind}}} |
| 558 |
% is a cross compiler and comes with many predefined programming languages. |
| 559 |
% For example, you can put the code on the right in your document, invoke |
| 560 |
% \packagename{LGrind} with \texttt{-e} option (and file names), and run the |
| 561 |
% created file through \LaTeX. You should get a result similar to the |
| 562 |
% left-hand side: |
| 563 |
% \begin{center} |
| 564 |
% \begin{minipage}{0.45\linewidth} |
| 565 |
%\iflgrind |
| 566 |
% \LGindent=0pt |
| 567 |
% \LGinlinefalse\LGbegin\lgrinde |
| 568 |
% \L{\LB{\K{for}_\V{i}:=\V{maxint}_\K{to}_\N{0}_\K{do}}} |
| 569 |
% \L{\LB{\K{begin}}} |
| 570 |
% \L{\LB{____\C{}\{_do_nothing_\}\CE{}}} |
| 571 |
% \L{\LB{\K{end};}} |
| 572 |
% \L{\LB{}} |
| 573 |
% \L{\LB{\V{Write}(\S{}{'}Case_insensitive_{'}\SE{});}} |
| 574 |
% \L{\LB{\V{WritE}(\S{}{'}Pascal_keywords.{'}\SE{});}} |
| 575 |
% \endlgrinde\LGend |
| 576 |
%\else |
| 577 |
% \packagename{LGrind} not installed. |
| 578 |
%\fi |
| 579 |
% \end{minipage} |
| 580 |
% \begin{minipage}{0.45\linewidth} |
| 581 |
% \begin{verbatim} |
| 582 |
% %[ |
| 583 |
% for i:=maxint to 0 do |
| 584 |
% begin |
| 585 |
% { do nothing } |
| 586 |
% end; |
| 587 |
% |
| 588 |
% Write('Case insensitive '); |
| 589 |
% WritE('Pascal keywords.'); |
| 590 |
% %]\end{verbatim} |
| 591 |
% \end{minipage} |
| 592 |
% \end{center} |
| 593 |
% If you use |%(| and |%)| instead of |%[| and |%]|, you get a code snippet |
| 594 |
% instead of a displayed listing. Moreover you can get line numbers to the |
| 595 |
% left or right, use arbitrary \LaTeX\ code in the source code, print symbols |
| 596 |
% instead of verbose names, make font setup, and more. You will (have to) |
| 597 |
% like it (if you don't like \packagename{listings}). |
| 598 |
% |
| 599 |
% Note that \packagename{LGrind} contains code with a no-sell license and is |
| 600 |
% thus nonfree software. |
| 601 |
% |
| 602 |
% \paragraph{\href{ftp://axp3.sv.fh-mannheim.de/cvt2latex}{\packagename{cvt2ltx}}} |
| 603 |
% is a family of `source code to \LaTeX' converters for C, Objective C, \Cpp, |
| 604 |
% IDL and Perl. Different styles, line numbers and other qualifiers can be |
| 605 |
% chosen by command-line option. Unfortunately it isn't documented how other |
| 606 |
% programming languages can be added. |
| 607 |
% |
| 608 |
% \paragraph{\href{http://mirror.ctan.org/support/C++2LaTeX-1_1pl1}{\packagename{\Cpp2\LaTeX}}} |
| 609 |
% is a C/\Cpp\ to \LaTeX\ converter. You can specify the fonts for comments, |
| 610 |
% directives, keywords, and strings, or the size of a tabulator. But as far as |
| 611 |
% I know you can't number lines. |
| 612 |
% |
| 613 |
% \paragraph{\href{http://mirror.ctan.org/support/slatex}{\packagename{S\LaTeX}}} |
| 614 |
% is a pretty-printing Scheme program (which invokes \LaTeX\ automatically) |
| 615 |
% especially designed for Scheme and other Lisp dialects. It supports stand |
| 616 |
% alone files, text and display listings, and you can even nest the |
| 617 |
% commands/environments if you use \LaTeX\ code in comments, for example. |
| 618 |
% Keywords, constants, variables, and symbols are definable and use of |
| 619 |
% different styles is possible. No line numbers. |
| 620 |
% |
| 621 |
% \paragraph{\href{http://mirror.ctan.org/support/tiny_c2l}^^A |
| 622 |
% {\packagename{tiny\textunderscore c2ltx}}} |
| 623 |
% is a C/\Cpp/Java to \LaTeX\ converter based on \packagename{cvt2ltx} (or the |
| 624 |
% other way round?). It supports line numbers, block comments, \LaTeX\ code |
| 625 |
% in/as comments, and smart line breaking. Font selection and tabulators are |
| 626 |
% hard-coded, i.e.~you have to rebuild the program if you want to change the |
| 627 |
% appearance. |
| 628 |
% |
| 629 |
% \paragraph{\href{http://mirror.ctan.org/macros/latex/contrib/misc}{\packagename{listing}}} |
| 630 |
% ---note the missing \packagename{s}---is not a pretty-printer and the |
| 631 |
% aphorism about documentation at the end of \texttt{listing.sty} is not |
| 632 |
% true.\space ^^A :-) |
| 633 |
% It defines |\listoflistings| and a nonfloating environment for listings. |
| 634 |
% All font selection and indention must be done by hand. However, it's |
| 635 |
% useful if you have another tool doing that work, e.g.~\packagename{LGrind}. |
| 636 |
% |
| 637 |
% \paragraph{\href{http://mirror.ctan.org/macros/latex/contrib/alg}{\packagename{alg}}} |
| 638 |
% provides essentially the same functionality as \packagename{algorithms}. |
| 639 |
% So read the next paragraph and note that the syntax will be different. |
| 640 |
% |
| 641 |
% \paragraph{\href{http://mirror.ctan.org/macros/latex/contrib/algorithms}^^A |
| 642 |
% {\packagename{algorithms}}} |
| 643 |
% goes a quite different way. You describe an algorithm and the package |
| 644 |
% formats it, for example |
| 645 |
% \begin{center} |
| 646 |
% \begin{minipage}{0.45\linewidth} |
| 647 |
%\ifalgorithmicpkg |
| 648 |
% \begin{algorithmic} |
| 649 |
% \IF {$i\leq0$} |
| 650 |
% \STATE $i\gets1$ |
| 651 |
% \ELSE\IF {$i\geq0$} |
| 652 |
% \STATE $i\gets0$ |
| 653 |
% \ENDIF\ENDIF |
| 654 |
% \end{algorithmic} |
| 655 |
%\else |
| 656 |
% \packagename{algorithms} not installed. |
| 657 |
%\fi |
| 658 |
% \end{minipage} |
| 659 |
% \begin{minipage}{0.45\linewidth} |
| 660 |
% \begin{quote} |
| 661 |
% |\begin{algorithmic}|\\ |
| 662 |
% | \IF{$i\leq0$}|\\ |
| 663 |
% | \STATE $i\gets1$|\\ |
| 664 |
% | \ELSE\IF{$i\geq0$}|\\ |
| 665 |
% | \STATE $i\gets0$|\\ |
| 666 |
% | \ENDIF\ENDIF|\\ |
| 667 |
% |\end{algorithmic}| |
| 668 |
%\end{quote} |
| 669 |
% \end{minipage} |
| 670 |
% \end{center} |
| 671 |
% As this example shows, you get a good looking algorithm even from a bad |
| 672 |
% looking input. The package provides a lot more constructs like |for|-loops, |
| 673 |
% |while|-loops, or comments. You can request line numbers, `ruled', `boxed' |
| 674 |
% and floating algorithms, a list of algorithms, and you can customize the |
| 675 |
% terms \textbf{if}, \textbf{then}, and so on. |
| 676 |
% |
| 677 |
% \paragraph{\href{http://www.mimuw.edu.pl/~wolinski/pretprin.html}^^A |
| 678 |
% {\packagename{pretprin}}} |
| 679 |
% is a package for pretty-printing texts in formal languages---as the title |
| 680 |
% in TUGboat, Volume 19 (1998), No.~3 states. It provides environments which |
| 681 |
% pretty-print \emph{and} format the source code. Analyzers for Pascal and |
| 682 |
% Prolog are defined; adding other languages is easy---if you are or get a bit |
| 683 |
% familiar with automatons and formal languages. |
| 684 |
% |
| 685 |
% \paragraph{\packagename{alltt}} |
| 686 |
% defines an environment similar to \texttt{verbatim} except that |\|, |{| and |
| 687 |
% |}| have their usual meanings. This means that you can use commands in the |
| 688 |
% verbatims, e.g.~select different fonts or enter math mode. |
| 689 |
% |
| 690 |
% \paragraph{\href{http://mirror.ctan.org/macros/latex/contrib/moreverb}^^A |
| 691 |
% {\packagename{moreverb}}} |
| 692 |
% requires \packagename{verbatim} and provides verbatim output to a file, |
| 693 |
% `boxed' verbatims and line numbers. |
| 694 |
% |
| 695 |
% \paragraph{\packagename{verbatim}} |
| 696 |
% defines an improved version of the standard \texttt{verbatim} environment and |
| 697 |
% a command to input files verbatim. |
| 698 |
% |
| 699 |
% \paragraph{\href{http://mirror.ctan.org/macros/latex/contrib/fancyvrb}^^A |
| 700 |
% {\packagename{fancyvrb}}} |
| 701 |
% is, roughly speaking, a superset of \packagename{alltt}, |
| 702 |
% \packagename{moreverb}, and \packagename{verbatim}, but many more parameters |
| 703 |
% control the output. The package provides frames, line numbers on the left or |
| 704 |
% on the right, automatic line breaking (difficult), and more. For example, an |
| 705 |
% interface to \packagename{listings} exists, i.e.~you can pretty-print source |
| 706 |
% code automatically. |
| 707 |
% The package \packagename{fvrb-ex} builds on \packagename{fancyvrb} and |
| 708 |
% defines environments to present examples similar to the ones in this guide. |
| 709 |
% |
| 710 |
% |
| 711 |
% \section{The next steps}\label{uTheNextSteps} |
| 712 |
% |
| 713 |
% Now, before actually using the \packagename{listings} package, you should |
| 714 |
% \emph{really} read the software license. It does not cost much time and |
| 715 |
% provides information you probably need to know. |
| 716 |
% |
| 717 |
% |
| 718 |
% \subsection{Software license}\label{uSoftwareLicense} |
| 719 |
% |
| 720 |
% The files \texttt{listings.dtx} and \texttt{listings.ins} and all |
| 721 |
% files generated from only these two files are referred to as `the |
| 722 |
% \packagename{listings} package' or simply `the package'. |
| 723 |
% \texttt{lstdrvrs.dtx} and the files generated from that file are |
| 724 |
% `drivers'. |
| 725 |
% |
| 726 |
% \paragraph{Copyright} |
| 727 |
% The \packagename{listings} package is copyright 1996--2004 Carsten Heinz, |
| 728 |
% and copyright 2006 Brooks Moses. The drivers are copyright any individual |
| 729 |
% author listed in the driver files. |
| 730 |
% |
| 731 |
% \paragraph{Distribution and modification} |
| 732 |
% The \packagename{listings} package and its drivers may be distributed |
| 733 |
% and/or modified under the conditions of the LaTeX Project Public License, |
| 734 |
% either version 1.3c of this license or (at your option) any later version. |
| 735 |
% The latest version of this license is in |
| 736 |
% \href{http://www.latex-project.org/lppl.txt}{http://www.latex-project.org/lppl.txt} |
| 737 |
% and version 1.3c or later is part of all distributions of LaTeX version |
| 738 |
% 2003/12/01 or later. |
| 739 |
% |
| 740 |
% \paragraph{Contacts} |
| 741 |
% Read section \lstref{uTroubleshooting} on how to submit a bug report. |
| 742 |
% Send all other comments, ideas, and additional programming languages to |
| 743 |
% \lstemail\ using \texttt{listings} as part of the subject. |
| 744 |
% |
| 745 |
% |
| 746 |
% \subsection{Package loading}\label{uPackageLoading} |
| 747 |
% |
| 748 |
% As usual in \LaTeX, the package is loaded by |
| 749 |
% |\usepackage[|\meta{options}|]{listings}|, |
| 750 |
% where |[|\meta{options}|]| is optional and gives a comma separated list of |
| 751 |
% options. Each either loads an additional \packagename{listings} aspect, or |
| 752 |
% changes default properties. Usually you don't have to take care of such |
| 753 |
% options. But in some cases it could be necessary: if you want to compile |
| 754 |
% documents created with an earlier version of this package or if you use |
| 755 |
% special features. Here's an incomplete list of possible options. |
| 756 |
% \begin{advise} |
| 757 |
% \item Where is a list of all of the options? |
| 758 |
% \advisespace |
| 759 |
% In the developer's guide since they were introduced to debug the |
| 760 |
% package more easily. Read section \ref{uHowTos} on how to get that |
| 761 |
% guide. |
| 762 |
% \end{advise} |
| 763 |
% \begin{description} |
| 764 |
% \item[\normalfont\texttt{0.21}]\leavevmode |
| 765 |
% |
| 766 |
% invokes a compatibility mode for compiling documents written for |
| 767 |
% \packagename{listings} version 0.21. |
| 768 |
% |
| 769 |
% \item[\normalfont\texttt{draft}]\leavevmode |
| 770 |
% |
| 771 |
% The package prints no stand alone files, but shows the captions and |
| 772 |
% defines the corresponding labels. |
| 773 |
% Note that a global |\documentclass|-option \texttt{draft} is |
| 774 |
% recognized, so you don't need to repeat it as a package option. |
| 775 |
% |
| 776 |
% \item[\normalfont\texttt{final}]\leavevmode\label{uoption:final} |
| 777 |
% |
| 778 |
% Overwrites a global \texttt{draft} option. |
| 779 |
% |
| 780 |
% \item[\normalfont\texttt{savemem}]\leavevmode |
| 781 |
% |
| 782 |
% tries to save some of \TeX's memory. If you switch between languages |
| 783 |
% often, it could also reduce compile time. But all this depends on the |
| 784 |
% particular document and its listings. |
| 785 |
% \end{description} |
| 786 |
% Note that various experimental features also need explicit loading via |
| 787 |
% options. Read the respective lines in section \ref{rExperimentalFeatures}. |
| 788 |
% |
| 789 |
% \medbreak |
| 790 |
% After package loading it is recommend to load all used dialects of programming |
| 791 |
% languages with the following command. It is faster to load several languages |
| 792 |
% with one command than loading each language on demand. |
| 793 |
% \begin{syntax} |
| 794 |
% \item {\rstyle\icmdname\lstloadlanguages}\marg{comma separated list of languages} |
| 795 |
% |
| 796 |
% Each language is of the form \oarg{dialect}\meta{language}. Without |
| 797 |
% the optional \oarg{dialect} the package loads a default dialect. So |
| 798 |
% write `|[Visual]C++|' if you want Visual \Cpp\ and `|[ISO]C++|' for |
| 799 |
% ISO \Cpp. Both together can be loaded by the command |
| 800 |
% |\lstloadlanguages{[Visual]C++,[ISO]C++}|. |
| 801 |
% |
| 802 |
% Table \ref{uPredefinedLanguages} on page \pageref{uPredefinedLanguages} |
| 803 |
% shows all defined languages and their dialects. |
| 804 |
% \end{syntax} |
| 805 |
%^^A After or even before language loading, you might want to define default |
| 806 |
%^^A dialects---just to be independent of configuration files. |
| 807 |
% |
| 808 |
% |
| 809 |
% \subsection{The key=value interface}\label{uTheKey=ValueInterface} |
| 810 |
% |
| 811 |
% This package uses the \packagename{keyval} package from the |
| 812 |
% \packagename{graphics} bundle by David Carlisle. Each parameter is |
| 813 |
% controlled by an associated key and a user supplied value. For example, |
| 814 |
% \ikeyname{firstline} is a key and |2| a valid value for this key. |
| 815 |
% |
| 816 |
% The command {\rstyle\icmdname\lstset} gets a comma separated list of |
| 817 |
% ``key|=|value'' pairs. The first list with more than a single entry is on |
| 818 |
% page \pageref{gFirstKey=ValueList}: |firstline=2,lastline=5|. |
| 819 |
% \begin{advise} |
| 820 |
% \item So I can write `|\lstset{firstline=2,lastline=5}|' once for all? |
| 821 |
% \advisespace |
| 822 |
% No. `\ikeyname{firstline}' and `\ikeyname{lastline}' belong to a small |
| 823 |
% set of |
| 824 |
% keys which are only used on individual listings. However, your command is |
| 825 |
% not illegal---it has no effect. You have to use these keys inside the |
| 826 |
% optional argument of the environment or input command. |
| 827 |
% \item What's about a better example of a key|=|value list? |
| 828 |
% \advisespace |
| 829 |
% There is one in section \ref{gFigureOutTheAppearance}. |
| 830 |
% \item `|language=[77]Fortran|' does not work inside an optional argument. |
| 831 |
% \advisespace |
| 832 |
% You must put braces around the value if a value with optional argument |
| 833 |
% is used inside an optional argument. In the case here write |
| 834 |
% `|language={[77]Fortran}|' to select Fortran 77. |
| 835 |
% \item If I use the `\ikeyname{language}' key inside an optional argument, the |
| 836 |
% language isn't active when I typeset the next listing. |
| 837 |
% \advisespace |
| 838 |
% All parameters set via `|\lstset|' keep their values up to the end of |
| 839 |
% the current environment or group. Afterwards the previous values are |
| 840 |
% restored. The optional parameters of the two pretty-printing commands |
| 841 |
% and the `\texttt{lstlisting}' environment take effect on the particular |
| 842 |
% listing only, i.e.~values are restored immediately. For example, you |
| 843 |
% can select a main language and change it for special listings. |
| 844 |
% \item \icmdname\lstinline\ has an optional argument? |
| 845 |
% \advisespace |
| 846 |
% Yes. And from this fact comes a limitation: you can't use the left |
| 847 |
% bracket `|[|' as delimiter unless you specify at least an empty |
| 848 |
% optional argument as in `|\lstinline[][var i:integer;[|'. |
| 849 |
% If you forget this, you will either get a ``runaway argument'' error |
| 850 |
% from \TeX, or an error message from the \packagename{keyval} package. |
| 851 |
% \end{advise} |
| 852 |
% |
| 853 |
% |
| 854 |
% \subsection{Programming languages}\label{uProgrammingLanguages} |
| 855 |
% |
| 856 |
% You already know how to activate programming languages---at least Pascal. |
| 857 |
% An optional parameter selects particular dialects of a language. For example, |
| 858 |
% |language=[77]Fortran| selects Fortran 77 and |language=[XSC]Pascal| does the |
| 859 |
% same for Pascal XSC. The general form is |
| 860 |
% {\rstyle\ikeyname{language}}|=|\oarg{dialect}\meta{language}. |
| 861 |
% If you want to get rid of keyword, comment, and string detection, use |
| 862 |
% |language={}| as an argument to |\lstset| or as optional argument. |
| 863 |
% |
| 864 |
% Table \ref{uPredefinedLanguages} shows all predefined languages and dialects. |
| 865 |
% Use the listed names as \meta{language} and \meta{dialect}, respectively. If |
| 866 |
% no dialect or `empty' is given in the table, just don't specify a dialect. |
| 867 |
% Each underlined dialect is default; it is selected if you leave out |
| 868 |
% the optional argument. The predefined defaults are the newest language |
| 869 |
% versions or standard dialects. |
| 870 |
%^^A |
| 871 |
%^^A Make table of predefined languages. |
| 872 |
%^^A |
| 873 |
%\let\lstlanguages\empty |
| 874 |
%\makeatletter |
| 875 |
%\@for\lst@temp:={lstlang1.sty,lstlang2.sty,lstlang3.sty}\do |
| 876 |
% {\IfFileExists\lst@temp{}{\let\lstlanguages\relax}} |
| 877 |
%\makeatother |
| 878 |
%\ifx\lstlanguages\relax |
| 879 |
% \PackageWarningNoLine{Listings} |
| 880 |
% {Standard drivers not available.\MessageBreak |
| 881 |
% Please check your installation.\MessageBreak |
| 882 |
% Compilation aborted} |
| 883 |
% \csname @@end\expandafter\endcsname |
| 884 |
%\fi |
| 885 |
%\lstscanlanguages\lstlanguages{lstlang1.sty,lstlang2.sty,lstlang3.sty}{}^^A |
| 886 |
%\def\topfigrule{\hrule\kern-0.4pt\relax}^^A |
| 887 |
%\let\botfigrule\topfigrule |
| 888 |
%\belowcaptionskip=\smallskipamount |
| 889 |
% \begin{table}[tbhp] |
| 890 |
% \small |
| 891 |
% \caption{Predefined languages. |
| 892 |
% Note that some definitions are preliminary, for example HTML and XML. |
| 893 |
% Each underlined dialect is the default dialect.}^^A |
| 894 |
% \label{uPredefinedLanguages}^^A |
| 895 |
% \makeatletter |
| 896 |
% \setbox\@tempboxa\hbox{^^A |
| 897 |
% \InputIfFileExists{listings.cfg}{\lst@InputCatcodes}{}}^^A |
| 898 |
% \lstprintlanguages\lstlanguages |
| 899 |
% \end{table} |
| 900 |
%^^A |
| 901 |
%^^A end of table |
| 902 |
%^^A |
| 903 |
%\lstset{defaultdialect=[doc]Pascal}^^A restore |
| 904 |
% \begin{advise} |
| 905 |
% \item How can I define default dialects? |
| 906 |
% \advisespace |
| 907 |
% Check section \ref{rLanguagesAndStyles} for `\keyname{defaultdialect}'. |
| 908 |
% \item I have C code mixed with assembler lines. Can \packagename{listings} |
| 909 |
% pretty-print such source code, i.e.~highlight keywords and comments of |
| 910 |
% both languages? |
| 911 |
% \advisespace |
| 912 |
% `\ikeyname{alsolanguage}|=|\oarg{dialect}\meta{language}' selects a |
| 913 |
% language additionally to the active one. So you only have to write a |
| 914 |
% language definition for your assembler dialect, which doesn't interfere |
| 915 |
% with the definition of C, say. Moreover you might want to use the key |
| 916 |
% `\keyname{classoffset}' described in section \ref{rLanguagesAndStyles}. |
| 917 |
% \item How can I define my own language? |
| 918 |
% \advisespace |
| 919 |
% This is discussed in section \ref{rLanguageDefinitions}. And if you |
| 920 |
% think that other people could benefit by your definition, you might |
| 921 |
% want to send it to the address in section \ref{uSoftwareLicense}. |
| 922 |
% Then it will be published under the \LaTeX\ Project Public License. |
| 923 |
% \end{advise} |
| 924 |
% Note that the arguments \meta{language} and \meta{dialect} are case |
| 925 |
% insensitive and that spaces have no effect. |
| 926 |
% |
| 927 |
% There is at least one language (VDM, Vienna Development Language, |
| 928 |
% \url{https://en.wikipedia.org/wiki/Vienna_Development_Method}^^A |
| 929 |
% \footnote{\lsthelper{Vladimir Nikishkin}{2019/11/15}% |
| 930 |
% {bug report in the listings package documentation} informed that the |
| 931 |
% previous mentioned URL \url{http://www.vdmportal.org} doesn't point |
| 932 |
% to a VDM specific page anymore.}) which is not directly supported by |
| 933 |
% the \packagename{listings} package. It needs a package for its own: |
| 934 |
% \packagename{vdmlisting}. On the other hand \packagename{vdmlisting} uses |
| 935 |
% the \packagename{listings} package and so it should be mentioned in this |
| 936 |
% context. |
| 937 |
% |
| 938 |
% |
| 939 |
% \subsubsection{Preferences}\label{uPreferences} |
| 940 |
% |
| 941 |
% Sometimes authors of language support provide their own configuration |
| 942 |
% preferences. These may come either from their personal experience or |
| 943 |
% from the settings in an IDE and can be defined as a \packagename{listings} |
| 944 |
% style. From version 1.5b of the \packagename{listings} package on these |
| 945 |
% styles are provided as files with the name |
| 946 |
% |listings-|\meta{language}|.prf|, \meta{language} is the name of the |
| 947 |
% supported programming language in lowercase letters. |
| 948 |
% |
| 949 |
% So if a user of the \packagename{listings} package wants to use these |
| 950 |
% preferences, she/he can say for example when using Python |
| 951 |
% \begin{quote} |
| 952 |
% |\input{listings-python.prf}| |
| 953 |
% \end{quote} |
| 954 |
% at the end of her/his private/project oriented |lstlocal.cfg| |
| 955 |
% configuration file as long as the file |listings-python.prf| resides in |
| 956 |
% the \TeX{} search path. Of course that file can be changed according to |
| 957 |
% the user's preferences. |
| 958 |
% |
| 959 |
% At the moment there are eight such preferences files: |
| 960 |
% \begin{enumerate} |
| 961 |
% \item |listings-acm.prf| |
| 962 |
% \item |listings-bash.prf| |
| 963 |
% \item |listings-fortran.prf| |
| 964 |
% \item |listings-hansl.prf| |
| 965 |
% \item |listings-lua.prf| |
| 966 |
% \item |listings-python.prf| |
| 967 |
% \item |listings-rexx.prf| |
| 968 |
% \item |listings-riscv.prf| |
| 969 |
% \end{enumerate} |
| 970 |
% All contributors are invited to supply more personal preferences. |
| 971 |
% |
| 972 |
% |
| 973 |
% \subsection{Special characters}\label{uSpecialCharacters} |
| 974 |
% |
| 975 |
% |
| 976 |
% \paragraph{Tabulators} |
| 977 |
% You might get unexpected output if your sources contain tabulators. |
| 978 |
% The package assumes tabulator stops at columns 9, 17, 25, 33, and so on. |
| 979 |
% This is predefined via |tabsize=8|. If you change the eight to the number |
| 980 |
% $n$, you will get tabulator stops at columns $n+1,2n+1,3n+1,$ and so on. |
| 981 |
% \begin{lstsample}[tabsize]{}{} |
| 982 |
% \lstset{tabsize=2} |
| 983 |
% \begin{lstlisting} |
| 984 |
% 123456789 |
| 985 |
% { one tabulator } |
| 986 |
% { two tabs } |
| 987 |
% 123 { 123 + two tabs } |
| 988 |
% \end{lstlisting} |
| 989 |
% \end{lstsample} |
| 990 |
% For better illustration, the left-hand side uses |tabsize=2| but the verbatim |
| 991 |
% code |tabsize=4|. Note that |\lstset| modifies the values for all following |
| 992 |
% listings in the same environment or group. This is no problem here since the |
| 993 |
% examples are typeset inside minipages. If you want to change settings for a |
| 994 |
% single listing, use the optional argument. |
| 995 |
% |
| 996 |
% |
| 997 |
% \paragraph{Visible tabulators and spaces} |
| 998 |
% One can make spaces and tabulators visible: |
| 999 |
% \begin{lstsample}[showspaces,showtabs,tab]{}{} |
| 1000 |
% \lstset{showspaces=true, |
| 1001 |
% showtabs=true, |
| 1002 |
% tab=\rightarrowfill} |
| 1003 |
% \begin{lstlisting} |
| 1004 |
% for i:=maxint to 0 do |
| 1005 |
% begin |
| 1006 |
% { do nothing } |
| 1007 |
% end; |
| 1008 |
% \end{lstlisting} |
| 1009 |
% \end{lstsample} |
| 1010 |
% If you request \ikeyname{showspaces} but no \ikeyname{showtabs}, |
| 1011 |
% tabulators are converted to visible spaces. |
| 1012 |
% The default definition of \ikeyname{tab} produces a `wide visible space' |
| 1013 |
% \lstinline[showtabs]! !. So you might want to use |$\to$|, |$\dashv$| |
| 1014 |
% or something else instead. |
| 1015 |
% \begin{advise} |
| 1016 |
% \item Some sort of advice: (1) You should really indent lines of source code |
| 1017 |
% to make listings more readable. (2) Don't indent some lines with |
| 1018 |
% spaces and others via tabulators. Changing the tabulator size (of your |
| 1019 |
% editor or pretty-printing tool) completely disturbs the columns. |
| 1020 |
% (3) As a consequence, never share your files with differently tab sized |
| 1021 |
% people!^^A true only if you use tabulators, just :-) |
| 1022 |
% \item To make the \LaTeX\ code more readable, I indent the environments' |
| 1023 |
% program listings. How can I remove that indention in the output? |
| 1024 |
% \advisespace |
| 1025 |
% Read `How to gobble characters' in section \ref{uHowTos}. |
| 1026 |
% \end{advise} |
| 1027 |
% |
| 1028 |
% |
| 1029 |
% \paragraph{Form feeds} |
| 1030 |
% Another special character is a form feed causing an empty line by default. |
| 1031 |
% {\rstyle\ikeyname{formfeed}}|=\newpage| would result in a new page every |
| 1032 |
% form feed. Please note that such definitions (even the default) might get |
| 1033 |
% in conflict with frames. |
| 1034 |
% |
| 1035 |
% |
| 1036 |
% \paragraph{National characters} |
| 1037 |
% If you type in such characters directly as characters of codes 128--255 and |
| 1038 |
% use them also in listings, let the package know it---or you'll get really |
| 1039 |
% funny results. {\rstyle\ikeyname{extendedchars}}|=true| allows and |
| 1040 |
% |extendedchars=false| prohibits \packagename{listings} from handling |
| 1041 |
% extended characters in listings. If you use them, you should load |
| 1042 |
% \packagename{fontenc}, \packagename{inputenc} and/or |
| 1043 |
% any other package which defines the characters. |
| 1044 |
% \begin{advise} |
| 1045 |
% \item I have problems using \packagename{inputenc} together with |
| 1046 |
% \packagename{listings}. |
| 1047 |
% \advisespace |
| 1048 |
% This could be a compatibility problem. Make a bug report as described |
| 1049 |
% in section \lstref{uTroubleshooting}. |
| 1050 |
% \end{advise} |
| 1051 |
% The extended characters don't cover Arabic, Chinese, Hebrew, Japanese, and so |
| 1052 |
% on---specifically, any encoding which uses multiple bytes per character. |
| 1053 |
% |
| 1054 |
% Thus, if you use the a package that supports multibyte characters, such as |
| 1055 |
% the \packagename{CJK} or \packagename {ucs} packages for Chinese and |
| 1056 |
% UTF-8 characters, you must avoid letting \packagename{listings} |
| 1057 |
% process the extended characters. It is generally best to also specify |
| 1058 |
% |extendedchars=false| to avoid having \packagename{listings} get entangled |
| 1059 |
% in the other package's extended-character treatment. |
| 1060 |
% |
| 1061 |
% If you do have a listing contained within a CJK environment, and want to have |
| 1062 |
% CJK characters inside the listing, you can place them within a comment that |
| 1063 |
% escapes to \LaTeX -- see section \ref{rEscapingToLaTeX} for how to do that. |
| 1064 |
% (If the listing is not inside a CJK environment, you can simply put a small |
| 1065 |
% CJK environment within the escaped-to-\LaTeX portion of the comment.) |
| 1066 |
% |
| 1067 |
% Similarly, if you are using UTF-8 extended characters in a listing, they must |
| 1068 |
% be placed within an escape to \LaTeX. |
| 1069 |
% |
| 1070 |
% Also, section \ref{uNationalCharacters} has a few details on how to work with |
| 1071 |
% extended characters in the context of $\Lambda$. |
| 1072 |
% |
| 1073 |
% |
| 1074 |
% \subsection{Line numbers}\label{uLineNumbers} |
| 1075 |
% |
| 1076 |
% You already know the keys \ikeyname{numbers}, \ikeyname{numberstyle}, |
| 1077 |
% \ikeyname{stepnumber}, and \ikeyname{numbersep} from section |
| 1078 |
% \ref{gSeduceToUse}. Here now we deal with continued listings. |
| 1079 |
% You have two options to get consistent line numbering across listings. |
| 1080 |
% |
| 1081 |
% \begin{lstsample}[firstnumber]{\lstset{numbers=left,numberstyle=\tiny,^^A |
| 1082 |
% stepnumber=2,numbersep=5pt}}{} |
| 1083 |
% \begin{lstlisting}[firstnumber=100] |
| 1084 |
% for i:=maxint to 0 do |
| 1085 |
% begin |
| 1086 |
% { do nothing } |
| 1087 |
% end; |
| 1088 |
% |
| 1089 |
% \end{lstlisting} |
| 1090 |
% And we continue the listing: |
| 1091 |
% \begin{lstlisting}[firstnumber=last] |
| 1092 |
% Write('Case insensitive '); |
| 1093 |
% WritE('Pascal keywords.'); |
| 1094 |
% \end{lstlisting} |
| 1095 |
% \end{lstsample} |
| 1096 |
% In the example, \ikeyname{firstnumber} is initially set to 100; some lines |
| 1097 |
% later the value is \texttt{last}, which continues the numbering of the last |
| 1098 |
% listing. Note that the empty line at the end of the first part is not printed |
| 1099 |
% here, but it counts for line numbering. You should also notice that you can |
| 1100 |
% write |\lstset{firstnumber=last}| once and get consecutively numbered code |
| 1101 |
% lines---except you specify something different for a particular listing. |
| 1102 |
% |
| 1103 |
% On the other hand you can use |firstnumber=auto| and name your listings. |
| 1104 |
% Listings with identical names (case sensitive!) share a line counter. |
| 1105 |
% \begin{lstsample}[name]{\lstset{numbers=left,numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} |
| 1106 |
% \begin{lstlisting}[name=Test] |
| 1107 |
% for i:=maxint to 0 do |
| 1108 |
% begin |
| 1109 |
% { do nothing } |
| 1110 |
% end; |
| 1111 |
% |
| 1112 |
% \end{lstlisting} |
| 1113 |
% And we continue the listing---note |
| 1114 |
% the blank line at the end of the |
| 1115 |
% previous code: |
| 1116 |
% \begin{lstlisting}[name=Test] |
| 1117 |
% Write('Case insensitive '); |
| 1118 |
% WritE('Pascal keywords.'); |
| 1119 |
% \end{lstlisting} |
| 1120 |
% \end{lstsample} |
| 1121 |
% The next |Test| listing would go on with line number {\makeatletter\lstno@Test}, |
| 1122 |
% no matter whether there are other listings in between. |
| 1123 |
% |
| 1124 |
% You can also select the lines to be printed, the options |
| 1125 |
% `\ikeyname{linerange}' and `\ikeyname{consecutivenumbers}' are your |
| 1126 |
% friend. In a presentation for example you don't need comments for your |
| 1127 |
% programs, so you prefer the line numbers being consecutively numbered, |
| 1128 |
% but the results should reflect the behaviour of the program---you omit |
| 1129 |
% parts of the lengthy output. So |
| 1130 |
% you may have the following program and its results. |
| 1131 |
% \begin{lstsample}[name]{\lstset{numbers=left,numberstyle=\tiny,stepnumber=1,numbersep=5pt}}{} |
| 1132 |
% \begin{lstlisting}[name=Test, |
| 1133 |
% language={[ansi]C}, |
| 1134 |
% linerange={1-4,6-7,10-14, |
| 1135 |
% 17-19,21-22}, |
| 1136 |
% firstnumber=1] |
| 1137 |
% #include <stdio.h> |
| 1138 |
% #include <stdlib.h> |
| 1139 |
% |
| 1140 |
% int main(int argc,char* argv[]){ |
| 1141 |
% /* declaring variables */ |
| 1142 |
% int i; |
| 1143 |
% int limit; |
| 1144 |
% |
| 1145 |
% /* checking arguments */ |
| 1146 |
% if ( argc > 1 ) { |
| 1147 |
% limit = atoi(argv[1]); |
| 1148 |
% } else { |
| 1149 |
% limit = 100; |
| 1150 |
% } |
| 1151 |
% |
| 1152 |
% /* counting lines */ |
| 1153 |
% for (i = 1;i <= limit;i++) { |
| 1154 |
% printf("Line no. %3.0d\n", i); |
| 1155 |
% } |
| 1156 |
% |
| 1157 |
% return 0; |
| 1158 |
% } |
| 1159 |
% |
| 1160 |
% \end{lstlisting} |
| 1161 |
% And these are the results: |
| 1162 |
% \begin{lstlisting}[language={}, |
| 1163 |
% linerange={1-2,6-7}, |
| 1164 |
% consecutivenumbers=false] |
| 1165 |
% Line no. 1 |
| 1166 |
% Line no. 2 |
| 1167 |
% Line no. 3 |
| 1168 |
% Line no. 4 |
| 1169 |
% Line no. 5 |
| 1170 |
% Line no. 6 |
| 1171 |
% Line no. 7 |
| 1172 |
% \end{lstlisting} |
| 1173 |
% \end{lstsample} |
| 1174 |
% |
| 1175 |
% \begin{advise} |
| 1176 |
% \item Okay. And how can I get decreasing line numbers? |
| 1177 |
% \advisespace |
| 1178 |
% Sorry, what? |
| 1179 |
% \advisespace |
| 1180 |
% Decreasing line numbers as on page \pageref{rDecreasingLabels}. |
| 1181 |
% \advisespace |
| 1182 |
% May I suggest to demonstrate your individuality by other means? |
| 1183 |
% If you differ, you should try a negative `\ikeyname{stepnumber}' |
| 1184 |
% (together with `\ikeyname{firstnumber}'). |
| 1185 |
% \end{advise} |
| 1186 |
% |
| 1187 |
% Read section \ref{uHowTos} on how to reference line numbers. |
| 1188 |
% |
| 1189 |
% |
| 1190 |
% \subsection{Layout elements} |
| 1191 |
% |
| 1192 |
% It's always a good idea to structure the layout by vertical space, |
| 1193 |
% horizontal lines, or different type sizes and typefaces. The best to stress |
| 1194 |
% whole listings are---not all at once---colours, frames, vertical space, and |
| 1195 |
% captions. The latter are also good to refer to listings, of course. |
| 1196 |
% |
| 1197 |
% \paragraph{Vertical space} |
| 1198 |
% The keys {\rstyle\ikeyname{aboveskip}} and {\rstyle\ikeyname{belowskip}} |
| 1199 |
% control the vertical space above and below displayed listings. Both keys get |
| 1200 |
% a dimension or skip as value and are initialized to |\medskipamount|. |
| 1201 |
% |
| 1202 |
% \paragraph{Frames} |
| 1203 |
% The key \ikeyname{frame} takes the verbose values \keyvalue{none}, |
| 1204 |
% \keyvalue{leftline}, \keyvalue{topline}, \keyvalue{bottomline}, |
| 1205 |
% \keyvalue{lines} (top and bottom), \keyvalue{single} for single frames, or |
| 1206 |
% \keyvalue{shadowbox}. |
| 1207 |
% \begin{lstsample}[frame]{}{} |
| 1208 |
% \begin{lstlisting}[frame=single] |
| 1209 |
% for i:=maxint to 0 do |
| 1210 |
% begin |
| 1211 |
% { do nothing } |
| 1212 |
% end; |
| 1213 |
% \end{lstlisting} |
| 1214 |
% \end{lstsample} |
| 1215 |
% \begin{advise} |
| 1216 |
% \item The rules aren't aligned. |
| 1217 |
% \advisespace |
| 1218 |
% This could be a bug of this package or a problem with your |
| 1219 |
% \texttt{.dvi} driver. \emph{Before} sending a bug report to the package |
| 1220 |
% author, modify the parameters described in section \ref{rFrames} |
| 1221 |
% heavily. And do this step by step! |
| 1222 |
% For example, begin with `|framerule=10mm|'. If the rules are |
| 1223 |
% misaligned by the same (small) amount as before, the problem does not |
| 1224 |
% come from the rule width. So continue with the next parameter. Also, |
| 1225 |
% Adobe Acrobat sometimes has single-pixel rounding errors which can |
| 1226 |
% cause small misalignments at the corners when PDF files are displayed |
| 1227 |
% on screen; these are unfortunately normal. |
| 1228 |
% \end{advise} |
| 1229 |
% Alternatively you can control the rules at the \texttt{t}op, \texttt{r}ight, |
| 1230 |
% \texttt{b}ottom, and \texttt{l}eft directly by using the four initial letters |
| 1231 |
% for single rules and their upper case versions for double rules. |
| 1232 |
% \begin{lstsample}[frame]{}{} |
| 1233 |
% \begin{lstlisting}[frame=trBL] |
| 1234 |
% for i:=maxint to 0 do |
| 1235 |
% begin |
| 1236 |
% { do nothing } |
| 1237 |
% end; |
| 1238 |
% \end{lstlisting} |
| 1239 |
% \end{lstsample} |
| 1240 |
% Note that a corner is drawn if and only if both adjacent rules are requested. |
| 1241 |
% You might think that the lines should be drawn up to the edge, but what's |
| 1242 |
% about round corners? The key \ikeyname{frameround} must get exactly four |
| 1243 |
% characters as value. The first character is attached to the upper right |
| 1244 |
% corner and it continues clockwise. `\texttt{t}' as character makes the |
| 1245 |
% corresponding corner round. |
| 1246 |
% \begin{lstsample}[frameround]{}{} |
| 1247 |
% \lstset{frameround=fttt} |
| 1248 |
% \begin{lstlisting}[frame=trBL] |
| 1249 |
% for i:=maxint to 0 do |
| 1250 |
% begin |
| 1251 |
% { do nothing } |
| 1252 |
% end; |
| 1253 |
% \end{lstlisting} |
| 1254 |
% \end{lstsample} |
| 1255 |
% Note that \ikeyname{frameround} has been used together with |\lstset| and thus |
| 1256 |
% the value affects all following listings in the same group or environment. |
| 1257 |
% Since the listing is inside a \texttt{minipage} here, this is no problem. |
| 1258 |
% \begin{advise} |
| 1259 |
% \item Don't use frames all the time, and in particular not with short listings. |
| 1260 |
% This would emphasize nothing. Use frames for $10\%$ or even less of |
| 1261 |
% your listings, for your most important ones. |
| 1262 |
% \item If you use frames on floating listings, do you really want frames? |
| 1263 |
% \advisespace |
| 1264 |
% No, I want to separate floats from text. |
| 1265 |
% \advisespace |
| 1266 |
% Then it is better to redefine \LaTeX's `|\topfigrule|' and |
| 1267 |
% `|\botfigrule|'. For example, you could write |
| 1268 |
% `|\renewcommand*\topfigrule{\hrule\kern-0.4pt\relax}|' and make the |
| 1269 |
% same definition for |\botfigrule|. |
| 1270 |
% \end{advise} |
| 1271 |
% |
| 1272 |
% \paragraph{Captions} |
| 1273 |
% Now we come to \ikeyname{caption} and \ikeyname{label}. You might guess |
| 1274 |
% (correctly) that they can be used in the same manner as \LaTeX's |
| 1275 |
% |\caption| and |\label| commands, although here it is also possible to |
| 1276 |
% have a caption regardless of whether or not the listing is in a |
| 1277 |
% float:\footnote{You should keep in mind that according to |
| 1278 |
% \cite{Mittelbach:companion} \ldots{} if the caption's text fits on one |
| 1279 |
% line, the text is centered; if the text does not fit on a single line, it |
| 1280 |
% will be typeset as a paragraph with a width equal to the line width.} |
| 1281 |
% \begin{lstsample}[caption,label]{\lstset{xleftmargin=.05\linewidth}}{} |
| 1282 |
% \begin{lstlisting}[caption={Useless code},label=useless] |
| 1283 |
% for i:=maxint to 0 do |
| 1284 |
% begin |
| 1285 |
% { do nothing } |
| 1286 |
% end; |
| 1287 |
% \end{lstlisting} |
| 1288 |
% \end{lstsample} |
| 1289 |
% Afterwards you could refer to the listing via |\ref{useless}|. By default |
| 1290 |
% such a listing gets an entry in the list of listings, which can be printed |
| 1291 |
% with the command {\rstyle\icmdname\lstlistoflistings}. The key |
| 1292 |
% {\rstyle\ikeyname{nolol}} suppresses an entry for both the environment or |
| 1293 |
% the input command. Moreover, you can specify a short caption for the list |
| 1294 |
% of listings: |
| 1295 |
% \keyname{caption}|={|\oarg{short}\meta{long}|}|. |
| 1296 |
% Note that the whole value is enclosed in braces since an optional value is |
| 1297 |
% used in an optional argument. |
| 1298 |
% |
| 1299 |
% If you don't want the label \texttt{\lstlistingname} plus number, you should |
| 1300 |
% use \ikeyname{title}: |
| 1301 |
% \begin{lstsample}[title]{\lstset{xleftmargin=.05\linewidth}}{} |
| 1302 |
% \begin{lstlisting}[title={`Caption' without label}] |
| 1303 |
% for i:=maxint to 0 do |
| 1304 |
% begin |
| 1305 |
% { do nothing } |
| 1306 |
% end; |
| 1307 |
% \end{lstlisting} |
| 1308 |
% \end{lstsample} |
| 1309 |
% \begin{advise} |
| 1310 |
% \item Something goes wrong with `\keyname{title}' in my document: in front of |
| 1311 |
% the title is a delimiter. |
| 1312 |
% \advisespace |
| 1313 |
% The result depends on the document class; some are not compatible. |
| 1314 |
% Contact the package author for a work-around. |
| 1315 |
% \end{advise} |
| 1316 |
% |
| 1317 |
% \paragraph{Colours} |
| 1318 |
% One more element. You need the \packagename{color} package and can then |
| 1319 |
% request coloured background via |
| 1320 |
% \ikeyname{backgroundcolor}|=|\meta{color command}. |
| 1321 |
% \begin{advise} |
| 1322 |
% \item Great! I love colours. |
| 1323 |
% \advisespace |
| 1324 |
% Fine, yes, really. And I like to remind you of the warning about |
| 1325 |
% striking styles on page \pageref{wStrikingStyles}. |
| 1326 |
% \end{advise} |
| 1327 |
%\ifcolor |
| 1328 |
% \begin{lstxsample}[backgroundcolor] |
| 1329 |
% \lstset{backgroundcolor=\color{yellow}} |
| 1330 |
% \end{lstxsample} |
| 1331 |
%\else |
| 1332 |
% \begin{verbatim} |
| 1333 |
% color package not installed\end{verbatim} |
| 1334 |
%\fi |
| 1335 |
% \begin{lstsample}{}{} |
| 1336 |
% \begin{lstlisting}[frame=single, |
| 1337 |
% framerule=0pt] |
| 1338 |
% for i:=maxint to 0 do |
| 1339 |
% begin |
| 1340 |
% j:=square(root(i)); |
| 1341 |
% end; |
| 1342 |
% \end{lstlisting} |
| 1343 |
% \end{lstsample} |
| 1344 |
% The example also shows how to get coloured space around the whole listing: |
| 1345 |
% use a frame whose rules have no width. |
| 1346 |
% |
| 1347 |
% |
| 1348 |
% \subsection{Emphasize identifiers}\label{uEmphasizeIdentifiers} |
| 1349 |
% |
| 1350 |
% Recall the pretty-printing commands and environment. |\lstinline| prints |
| 1351 |
% code snippets, |\lstinputlisting| whole files, and \texttt{lstlisting} |
| 1352 |
% pieces of code which reside in the \LaTeX\ file. And what are these |
| 1353 |
% different `types' of source code good for? Well, it just happens that a |
| 1354 |
% sentence contains a code fragment. Whole files are typically included in or |
| 1355 |
% as an appendix. Nevertheless some books about programming also include such |
| 1356 |
% listings in normal text sections---to increase the number of pages. |
| 1357 |
% Nowadays source code should be shipped on disk or CD-ROM and only the main |
| 1358 |
% header or interface files should be typeset for reference. So, please, don't |
| 1359 |
% misuse the \packagename{listings} package. But let's get back to the topic. |
| 1360 |
% |
| 1361 |
% Obviously `\texttt{lstlisting} source code' isn't used to make an executable |
| 1362 |
% program from. Such source code has some kind of educational purpose or even |
| 1363 |
% didactic. |
| 1364 |
% \begin{advise} |
| 1365 |
% \item What's the difference between educational and didactic? |
| 1366 |
% \advisespace |
| 1367 |
% Something educational can be good or bad, true or false. |
| 1368 |
% Didactic is true by definition.^^A :-) |
| 1369 |
% \end{advise} |
| 1370 |
% Usually \emph{keywords} are highlighted when the package typesets a piece of |
| 1371 |
% source code. This isn't necessary for readers who know the programming |
| 1372 |
% language well. The main matter is the presentation of interface, library or |
| 1373 |
% other functions or variables. If this is your concern, here come the right |
| 1374 |
% keys. Let's say, you want to emphasize the functions |square| and |root|, |
| 1375 |
% for example, by underlining them. Then you could do it like this: |
| 1376 |
% \begin{lstxsample}[emph,emphstyle] |
| 1377 |
% \lstset{emph={square,root},emphstyle=\underbar} |
| 1378 |
% \end{lstxsample} |
| 1379 |
% \begin{lstsample}{}{} |
| 1380 |
% \begin{lstlisting} |
| 1381 |
% for i:=maxint to 0 do |
| 1382 |
% begin |
| 1383 |
% j:=square(root(i)); |
| 1384 |
% end; |
| 1385 |
% \end{lstlisting} |
| 1386 |
% \end{lstsample} |
| 1387 |
% \begin{advise} |
| 1388 |
% \item Note that the list of identifiers |{square,root}| is enclosed in |
| 1389 |
% braces. Otherwise the \packagename{keyval} package would complain |
| 1390 |
% about an undefined key \keyname{root} since the comma finishes the |
| 1391 |
% key=value pair. |
| 1392 |
% Note also that you \emph{must} put braces around the value if you |
| 1393 |
% use an optional argument of a key inside an optional argument of a |
| 1394 |
% pretty-printing command. Though it is not necessary, the following |
| 1395 |
% example uses these braces. They are typically forgotten when they |
| 1396 |
% become necessary, |
| 1397 |
% \end{advise} |
| 1398 |
% |
| 1399 |
% Both keys have an optional \meta{class number} argument for multiple |
| 1400 |
% identifier lists: |
| 1401 |
%\ifcolor |
| 1402 |
% \begin{lstxsample}[emph,emphstyle] |
| 1403 |
% \lstset{emph={square}, emphstyle=\color{red}, |
| 1404 |
% emph={[2]root,base},emphstyle={[2]\color{blue}}} |
| 1405 |
% \end{lstxsample} |
| 1406 |
%\else |
| 1407 |
% \begin{lstxsample}[emph,emphstyle] |
| 1408 |
% \lstset{emph={square}, emphstyle=\underbar, |
| 1409 |
% emph={[2]root,base},emphstyle={[2]\fbox}} |
| 1410 |
% \end{lstxsample} |
| 1411 |
%\fi |
| 1412 |
% \begin{lstsample}{}{} |
| 1413 |
% \begin{lstlisting} |
| 1414 |
% for i:=maxint to 0 do |
| 1415 |
% begin |
| 1416 |
% j:=square(root(i)); |
| 1417 |
% end; |
| 1418 |
% \end{lstlisting} |
| 1419 |
% \end{lstsample} |
| 1420 |
% \begin{advise} |
| 1421 |
% \item What is the maximal \meta{class number}? |
| 1422 |
% \advisespace |
| 1423 |
% $2^{31}-1=2\,147\,483\,647$. But \TeX's memory will exceed before you |
| 1424 |
% can define so many different classes. |
| 1425 |
% \end{advise} |
| 1426 |
% |
| 1427 |
% One final hint: Keep the lists of identifiers disjoint. Never use a keyword |
| 1428 |
% in an `emphasize' list or one name in two different lists. Even if your |
| 1429 |
% source code is highlighted as expected, there is no guarantee that it is |
| 1430 |
% still the case if you change the order of your listings or if you use the |
| 1431 |
% next release of this package. |
| 1432 |
% |
| 1433 |
% |
| 1434 |
%\iffalse |
| 1435 |
% \subsection{*Listing alignment}\label{uListingAlignment} |
| 1436 |
% |
| 1437 |
% The examples are typeset with centered \texttt{minipage}s. That's the reason |
| 1438 |
% why you can't see that line numbers are printed in the margin. Now we |
| 1439 |
% separate the minipage margin and the minipage by a vertical rule: |
| 1440 |
% \begin{lstsample}{\lstset{frame=l,framesep=0pt,numberstyle=\tiny,stepnumber=2,^^A |
| 1441 |
% numbersep=5pt}}{} |
| 1442 |
% Some text before |
| 1443 |
% \begin{lstlisting} |
| 1444 |
% for i:=maxint to 0 do |
| 1445 |
% begin |
| 1446 |
% { do nothing } |
| 1447 |
% end; |
| 1448 |
% \end{lstlisting} |
| 1449 |
% \end{lstsample} |
| 1450 |
% The listing is lined up with the normal text. The parameter \ikeyname{xleftmargin} |
| 1451 |
% moves the listing to the right (or left if the dimension is negative). |
| 1452 |
% \begin{lstsample}{\lstset{frame=l,framesep=0pt,numberstyle=\tiny,stepnumber=2,^^A |
| 1453 |
% numbersep=5pt}}{} |
| 1454 |
% Some text before |
| 1455 |
% \begin{lstlisting}[xleftmargin=15pt] |
| 1456 |
% for i:=maxint to 0 do |
| 1457 |
% begin |
| 1458 |
% { do nothing } |
| 1459 |
% end; |
| 1460 |
% \end{lstlisting} |
| 1461 |
% |
| 1462 |
% \begin{lstlisting}{ } |
| 1463 |
% Write('Insensitive'); |
| 1464 |
% WritE('keywords.'); |
| 1465 |
% \end{lstlisting} |
| 1466 |
% \end{lstsample} |
| 1467 |
% Note again that optional arguments change settings for single listings. |
| 1468 |
% |
| 1469 |
% If you use environments like \texttt{itemize} or \texttt{enumerate}, there |
| 1470 |
% is `natural' indention coming from these environments. By default the |
| 1471 |
% \packagename{listings} package respects this. But you might use |
| 1472 |
% |resetmargins=true| (or |false|) to make your own decision. You can use it |
| 1473 |
% together with |xleftmargin|, of course. |
| 1474 |
% \begin{advise} |
| 1475 |
% \item I get heavy overfull |\hbox|es from some listings. |
| 1476 |
% \advisespace |
| 1477 |
% This comes from long lines in your listings. You have some options |
| 1478 |
% to get rid of the overful |\hbox|es. Firstly I recommend to typeset |
| 1479 |
% listings in smaller fonts than the surrounding text, for example |
| 1480 |
% `|basicstyle=\small|'. Secondly you might want to use the flexible |
| 1481 |
% column format. Thirdly you can increase the line width or set it |
| 1482 |
% explicitly, refer section \ref{rMarginsAndLineShape}. |
| 1483 |
% If all this doesn't help, you might want to change |
| 1484 |
% `\ikeyname{basewidth}', but be careful! The two unknown items are |
| 1485 |
% explained in the next section. |
| 1486 |
% \end{advise} |
| 1487 |
% |
| 1488 |
% You might need to control the vertical position of listings with the |
| 1489 |
% \ikeyname{boxpos} key, for example, if you use them in \texttt{minipage} or |
| 1490 |
% \texttt{tabular} environments. Here `listings' means \texttt{lstlisting} or |
| 1491 |
% |\lstinputlisting|. As the following example shows, you can even place such |
| 1492 |
% listings inside paragraphs, but you must force the package to do this by |
| 1493 |
% enclosing the listing in |\hbox{| and |}|. |
| 1494 |
% \begin{advise} |
| 1495 |
% \item Is it good form to use the \TeX-primitive `|\hbox|' in a \LaTeX\ |
| 1496 |
% document? |
| 1497 |
% \advisespace |
| 1498 |
% No, it's not. But \LaTeX's `|\mbox|' does not work in this example: |
| 1499 |
% \end{advise} |
| 1500 |
% \begin{lstsample}{}{} |
| 1501 |
% Here are some multi-line listings inside a paragraph. |
| 1502 |
% The `boxpos' key controls their vertical alignment: |
| 1503 |
% \hbox{\begin{lstlisting}[boxpos=c] |
| 1504 |
% center |
| 1505 |
% center |
| 1506 |
% \end{lstlisting}} |
| 1507 |
% \hbox{\begin{lstlisting}[boxpos=b] |
| 1508 |
% bottom baseline |
| 1509 |
% bottom baseline |
| 1510 |
% \end{lstlisting}} |
| 1511 |
% \hbox{\begin{lstlisting}[boxpos=t] |
| 1512 |
% top baseline |
| 1513 |
% top baseline |
| 1514 |
% \end{lstlisting}} |
| 1515 |
% \end{lstsample} |
| 1516 |
%\fi |
| 1517 |
% |
| 1518 |
% |
| 1519 |
% \subsection{Indexing}\label{uIndexing} |
| 1520 |
% |
| 1521 |
% Indexing is just like emphasizing identifiers---I mean the usage: |
| 1522 |
% \begin{lstxsample}[index] |
| 1523 |
% \lstset{index={square},index={[2]root}} |
| 1524 |
% \end{lstxsample} |
| 1525 |
% \begin{lstsample}{}{} |
| 1526 |
% \begin{lstlisting} |
| 1527 |
% for i:=maxint to 0 do |
| 1528 |
% begin |
| 1529 |
% j:=square(root(i)); |
| 1530 |
% end; |
| 1531 |
% \end{lstlisting} |
| 1532 |
% \end{lstsample} |
| 1533 |
% Of course, you can't see anything here. You will have to look at the index. |
| 1534 |
% \begin{advise} |
| 1535 |
% \item Why is the `\ikeyname{index}' key able to work with multiple identifier |
| 1536 |
% lists? |
| 1537 |
% \advisespace |
| 1538 |
% This question is strongly related to the `{\rstyle\ikeyname{indexstyle}}' |
| 1539 |
% key. Someone might want to create multiple indexes or want to insert |
| 1540 |
% prefixes like `|constants|', `|functions|', `|keywords|', and so on. |
| 1541 |
% The `\ikeyname{indexstyle}' key works like the other style keys except |
| 1542 |
% that the last token \emph{must} take an argument, namely the |
| 1543 |
% (printable form of the) current identifier. |
| 1544 |
% |
| 1545 |
% You can define `|\newcommand\indexkeywords[1]{\index{keywords, #1}}|' |
| 1546 |
% and make similar definitions for constant or function names. Then |
| 1547 |
% `|indexstyle=[1]\indexkeywords|' might meet your purpose. This becomes |
| 1548 |
% easier if you want to create multiple indexes with the |
| 1549 |
% \href{http://mirror.ctan.org/macros/latex/contrib/camel} |
| 1550 |
% {\packagename{index}} package. |
| 1551 |
% If you have defined appropriate new indexes, it is possible to write |
| 1552 |
% `|indexstyle=\index[keywords]|', for example. |
| 1553 |
% |
| 1554 |
% \item Let's say, I want to index all keywords. It would be annoying to |
| 1555 |
% type in all the keywords again, specifically if the used programming |
| 1556 |
% language changes frequently. |
| 1557 |
% \advisespace |
| 1558 |
% Just read ahead. |
| 1559 |
% \end{advise} |
| 1560 |
% The \ikeyname{index} key has in fact two optional arguments. The first is the |
| 1561 |
% well-known \meta{class number}, the second is a comma separated list of other |
| 1562 |
% keyword classes whose identifiers are indexed. The indexed identifiers then |
| 1563 |
% change automatically with the defined keywords---not automagically, it's not |
| 1564 |
% an illusion.^^A :-) |
| 1565 |
% |
| 1566 |
% Eventually you need to know the names of the keyword classes. It's usually |
| 1567 |
% the key name followed by a class number, for example, |emph2|, |emph3|, |
| 1568 |
% \ldots, |keywords2| or |index5|. But there is no number for the first order |
| 1569 |
% classes |keywords|, |emph|, |directives|, and so on. |
| 1570 |
% \begin{advise} |
| 1571 |
% \item `|index=[keywords]|' does not work. |
| 1572 |
% \advisespace |
| 1573 |
% The package can't guess which optional argument you mean. Hence you |
| 1574 |
% must specify both if you want to use the second one. You should try |
| 1575 |
% `|index=[1][keywords]|'. |
| 1576 |
% \end{advise} |
| 1577 |
% |
| 1578 |
% |
| 1579 |
% \subsection{Fixed and flexible columns}\label{uFixedAndFlexibleColumns} |
| 1580 |
% |
| 1581 |
% The first thing a reader notices---except different styles for keywords, |
| 1582 |
% etc.---is the column alignment. Arne John Glenstrup invented the flexible |
| 1583 |
% column format in 1997. Since then some efforts were made to develop this |
| 1584 |
% branch farther. Currently four column formats are provided: fixed, flexible, |
| 1585 |
% space-flexible, and full flexible. Take a close look at the following |
| 1586 |
% examples. |
| 1587 |
% \begin{center} |
| 1588 |
% \def\sample{\begin{lstlisting}^^J WOMEN\ \ are^^A |
| 1589 |
% ^^J \ \ \ \ \ \ \ MEN^^A |
| 1590 |
% ^^J WOMEN are^^A |
| 1591 |
% ^^J better MEN^^J \end{lstlisting}} |
| 1592 |
% \newdimen\lstdocwidth |
| 1593 |
% \lstdocwidth=80pt |
| 1594 |
% \lstset{style={},language={}} |
| 1595 |
% \hbox{\begin{minipage}[t]{\lstdocwidth} |
| 1596 |
% \centering% |
| 1597 |
% \texttt{{\rstyle\ikeyname{columns}}=}\\ |
| 1598 |
% \phantom{(at ?)}\\ |
| 1599 |
% {\lstset{basicstyle=\ttfamily, basewidth=0.51em} |
| 1600 |
% \sample} |
| 1601 |
% \end{minipage} |
| 1602 |
% \quad |
| 1603 |
% \begin{minipage}[t]{\lstdocwidth} |
| 1604 |
% \centering% |
| 1605 |
% \texttt{fixed}\\ |
| 1606 |
% (at {\makeatletter\lst@widthfixed})\\ |
| 1607 |
% {\lstset{columns=fixed} |
| 1608 |
% \sample} |
| 1609 |
% \end{minipage} |
| 1610 |
% \quad |
| 1611 |
% \begin{minipage}[t]{\lstdocwidth} |
| 1612 |
% \centering% |
| 1613 |
% \texttt{flexible}\\ |
| 1614 |
% (at {\makeatletter\lst@widthflexible})\\ |
| 1615 |
% {\lstset{columns=flexible} |
| 1616 |
% \sample} |
| 1617 |
% \end{minipage} |
| 1618 |
% \quad |
| 1619 |
% \begin{minipage}[t]{\lstdocwidth} |
| 1620 |
% \centering% |
| 1621 |
% \texttt{fullflexible}\\ |
| 1622 |
% (at {\makeatletter\lst@widthflexible})\\ |
| 1623 |
% {\lstset{columns=fullflexible} |
| 1624 |
% \sample} |
| 1625 |
% \end{minipage}} |
| 1626 |
% \end{center} |
| 1627 |
% \begin{advise} |
| 1628 |
% \item Why are women better men? |
| 1629 |
% \advisespace |
| 1630 |
% Do you want to philosophize? Well, have I ever said that the |
| 1631 |
% statement ``women are better men'' is true? I can't even remember this |
| 1632 |
% about ``women are men'' \ldots . ^^A ;-) |
| 1633 |
% \end{advise} |
| 1634 |
% In the abstract one can say: The fixed column format ruins the spacing |
| 1635 |
% intended by the font designer, while the flexible formats ruin the column |
| 1636 |
% alignment (possibly) intended by the programmer. Common to all is that the |
| 1637 |
% input characters are translated into a sequence of basic output units like |
| 1638 |
% \begingroup \lstset{gobble=6,xleftmargin=\leftmargini} |
| 1639 |
% \makeatletter |
| 1640 |
%^^A Make \fbox around each output unit. |
| 1641 |
% \fboxsep=0pt |
| 1642 |
% \def\lst@alloverstyle#1{\fbox{\kern-\fboxrule\strut#1}\kern-\fboxrule} |
| 1643 |
% \begin{lstlisting}[basewidth=1em] |
| 1644 |
% if x=y then write('align') |
| 1645 |
% else print('align'); |
| 1646 |
% \end{lstlisting} |
| 1647 |
% Now, the fixed format puts $n$ characters into a box of width $n\times{} |
| 1648 |
% $`base width', where the base width is {\makeatletter\lst@widthfixed} in the |
| 1649 |
% example. The format shrinks and stretches the space between the characters |
| 1650 |
% to make them fit the box. As shown in the example, some character strings look |
| 1651 |
% \hbox to 2em{b\hss a\hss d} |
| 1652 |
% or |
| 1653 |
% \hbox to 2em{w\hss o\hss r\hss s\hss e}, |
| 1654 |
% but the output is vertically aligned. |
| 1655 |
% \endgroup |
| 1656 |
% |
| 1657 |
% If you don't need or like this, you should use a flexible format. All |
| 1658 |
% characters are typeset at their natural width. In particular, they never |
| 1659 |
% overlap. If a word requires more space than reserved, the rest of the line |
| 1660 |
% simply moves to the right. The difference between the three formats is that |
| 1661 |
% the full flexible format cares about nothing else, while the normal flexible |
| 1662 |
% and space-flexible formats try to fix the column alignment if a character |
| 1663 |
% string needs less space than `reserved'. The normal flexible format will |
| 1664 |
% insert make-up space to fix the alignment at spaces, before and after |
| 1665 |
% identifiers, and before and after sequences of other characters; the |
| 1666 |
% space-flexible format will only insert make-up space by stretching |
| 1667 |
% existing spaces. In the flexible example above, the two MENs are vertically |
| 1668 |
% aligned since some space has been inserted in the fourth line to fix the |
| 1669 |
% alignment. In the full flexible format, the two MENs are not aligned. |
| 1670 |
% |
| 1671 |
% Note that both flexible modes printed the two blanks in the first line as a |
| 1672 |
% single blank, but for different reasons: the normal flexible format fixes |
| 1673 |
% the column alignment (as would the space-flexible format), and the full |
| 1674 |
% flexible format doesn't care about the second space. |
| 1675 |
% |
| 1676 |
% |
| 1677 |
% \section{Advanced techniques}\label{uAdvancedTechniques} |
| 1678 |
% |
| 1679 |
% |
| 1680 |
% \subsection{Style definitions} |
| 1681 |
% |
| 1682 |
% It is obvious that a pretty-printing tool like this requires some kind of |
| 1683 |
% language selection and definition. The first has already been described and |
| 1684 |
% the latter is convered by the next section. However, it is very convenient |
| 1685 |
% to have the same for printing styles: at a central place of your document |
| 1686 |
% they can be modified easily and the changes take effect on all listings. |
| 1687 |
% |
| 1688 |
% Similar to languages, |
| 1689 |
% {\rstyle\ikeyname{style}}|=|\meta{style name} |
| 1690 |
% activates a previously defined style. A definition is as easy: |
| 1691 |
% {\rstyle|\lstdefinestyle|}\marg{style name}\marg{key=value list}. |
| 1692 |
% Keys not used in such a definition are untouched by the corresponding style |
| 1693 |
% selection, of course. For example, you could write |
| 1694 |
% \begin{verbatim} |
| 1695 |
% \lstdefinestyle{numbers} |
| 1696 |
% {numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=10pt} |
| 1697 |
% \lstdefinestyle{nonumbers} |
| 1698 |
% {numbers=none}\end{verbatim} |
| 1699 |
% and switch from listings with line numbers to listings without ones and vice |
| 1700 |
% versa simply by |style=nonumbers| and |style=numbers|, respectively. |
| 1701 |
% \begin{advise} |
| 1702 |
% \item You could even write |
| 1703 |
% `|\lstdefinestyle{C++}{language=C++,style=numbers}|'. |
| 1704 |
% Style and language names are independent of each other and so might |
| 1705 |
% coincide. Moreover it is possible to activate other styles. |
| 1706 |
% |
| 1707 |
% \item It's easy to crash the package using styles. Write |
| 1708 |
% '|\lstdefinestyle{crash}{style=crash}|' and '|\lstset{style=crash}|'. |
| 1709 |
% \TeX's capacity will exceed, sorry [parameter stack size]. Only bad |
| 1710 |
% boys use such recursive calls, but only good girls use this package. |
| 1711 |
% Thus the problem is of minor interest.^^A :-) |
| 1712 |
% \end{advise} |
| 1713 |
% |
| 1714 |
% |
| 1715 |
% \subsection{Language definitions}\label{uLanguageDefinitions} |
| 1716 |
% |
| 1717 |
% These are like style definitions except for an optional dialect name and an |
| 1718 |
% optional base language---and, of course, a different command name and |
| 1719 |
% specialized keys. In the simple case it's |
| 1720 |
% {\rstyle|\lstdefinelanguage|}\marg{language name}\marg{key=value list}. |
| 1721 |
% For many programming languages it is sufficient to specify keywords and |
| 1722 |
% standard function names, comments, and strings. Let's look at an example. |
| 1723 |
% \begin{lstxsample}[morekeywords,sensitive,morecomment,morestring] |
| 1724 |
% \lstdefinelanguage{rock} |
| 1725 |
% {morekeywords={one,two,three,four,five,six,seven,eight, |
| 1726 |
% nine,ten,eleven,twelve,o,clock,rock,around,the,tonight}, |
| 1727 |
% sensitive=false, |
| 1728 |
% morecomment=[l]{//}, |
| 1729 |
% morecomment=[s]{/*}{*/}, |
| 1730 |
% morestring=[b]", |
| 1731 |
% } |
| 1732 |
% \end{lstxsample} |
| 1733 |
% \begingroup \csname lst@EndWriteFile\endcsname |
| 1734 |
% \bigbreak |
| 1735 |
% |
| 1736 |
% \noindent |
| 1737 |
% There isn't much to say about keywords. They are defined like identifiers |
| 1738 |
% you want to emphasize. Additionally you need to specify whether they are |
| 1739 |
% case sensitive or not. And yes: you could insert |[2]| in front of the |
| 1740 |
% keyword \texttt{one} to define the keywords as `second order' and print them |
| 1741 |
% in |keywordstyle={[2]...}|. |
| 1742 |
% \begin{advise} |
| 1743 |
% \item I get a `\texttt{Missing = inserted for }|\ifnum|' error when I select |
| 1744 |
% my language. |
| 1745 |
% \advisespace |
| 1746 |
% Did you forget the comma after `|keywords={...}|'? And if you encounter |
| 1747 |
% unexpected characters after selecting a language (or style), you have |
| 1748 |
% probably forgotten a different comma or you have given to many |
| 1749 |
% arguments to a key, for example, |morecomment=[l]{--}{!}|. |
| 1750 |
% \end{advise} |
| 1751 |
% |
| 1752 |
% So let's turn to comments and strings. Each value starts with a |
| 1753 |
% \emph{mandatory} \oarg{type} argument followed by a changing number of |
| 1754 |
% opening and closing delimiters. Note that each delimiter (pair) requires a |
| 1755 |
% key=value on its own, even if types are equal. Hence, you'll need to insert |
| 1756 |
% \texttt{morestring=[b]'} if single quotes open and close string or character |
| 1757 |
% literals in the same way as double quotes do in the example. |
| 1758 |
% |
| 1759 |
% Eventually you need to know the types and their numbers of delimiters. The |
| 1760 |
% reference guide contains full lists, here we discuss only the most common. |
| 1761 |
% For strings these are {\rstyle\texttt{b}} and {\rstyle\texttt{d}} with one |
| 1762 |
% delimiter each. This delimiter opens and closes the string and inside a |
| 1763 |
% string it is either escaped by a \texttt backslash or it is \texttt doubled. |
| 1764 |
% The comment type {\rstyle\texttt{l}} requires exactly one delimiter, which |
| 1765 |
% starts a comment on any column. This comment goes up to the end of line. |
| 1766 |
% The other two most common comment types are {\rstyle\texttt{s}} and |
| 1767 |
% {\rstyle\texttt{n}} with two delimiters each. The first delimiter opens a |
| 1768 |
% comment which is terminated by the second delimiter. In contrast to the |
| 1769 |
% \texttt s-type, \texttt n-type comments can be nested. |
| 1770 |
% \begin{lstxsample}[b,d,l,s,n] |
| 1771 |
% \lstset{morecomment=[l]{//}, |
| 1772 |
% morecomment=[s]{/*}{*/}, |
| 1773 |
% morecomment=[n]{(*}{*)}, |
| 1774 |
% morestring=[b]", |
| 1775 |
% morestring=[d]'} |
| 1776 |
% \end{lstxsample} |
| 1777 |
% \begin{lstsample}{}{} |
| 1778 |
% \begin{lstlisting} |
| 1779 |
% "str\"ing " not a string |
| 1780 |
% 'str''ing ' not a string |
| 1781 |
% // comment line |
| 1782 |
% /* comment/**/ not a comment |
| 1783 |
% (* nested (**) still comment |
| 1784 |
% comment *) not a comment |
| 1785 |
% \end{lstlisting} |
| 1786 |
% \end{lstsample} |
| 1787 |
% \begin{advise} |
| 1788 |
% \item Is it \emph{that} easy? |
| 1789 |
% \advisespace |
| 1790 |
% Almost. There are some troubles you can run into. For example, if |
| 1791 |
% `\texttt{-*}' starts a comment line and `\texttt{-*-}' a string |
| 1792 |
% (unlikely but possible), then you must define the shorter delimiter |
| 1793 |
% first. |
| 1794 |
% Another problem: by default some characters are not allowed inside |
| 1795 |
% keywords, for example `\texttt{-}', `\texttt{:}', `\texttt{.}', and |
| 1796 |
% so on. The reference guide covers this problem by introducing some |
| 1797 |
% more keys, which let you adjust the standard character table |
| 1798 |
% appropriately. But note that white space characters are prohibited |
| 1799 |
% inside keywords. |
| 1800 |
% \end{advise} |
| 1801 |
% Finally remember that this section is only an introduction to language |
| 1802 |
% definitions. There are more keys and possibilities. |
| 1803 |
% |
| 1804 |
% |
| 1805 |
% \subsection{Delimiters}\label{uDelimiters} |
| 1806 |
% |
| 1807 |
% You already know two special delimiter classes: comments and strings. |
| 1808 |
% However, their full syntax hasn't been described so far. For example, |
| 1809 |
% \ikeyname{commentstyle} applies to all comments---unless you specify |
| 1810 |
% something different. The \emph{optional} \oarg{style} argument follows the |
| 1811 |
% \emph{mandatory} \oarg{type} argument. |
| 1812 |
%\ifcolor |
| 1813 |
% \begin{lstxsample} |
| 1814 |
% \lstset{morecomment=[l][keywordstyle]{//}, |
| 1815 |
% morecomment=[s][\color{white}]{/*}{*/}} |
| 1816 |
% \end{lstxsample} |
| 1817 |
%\else |
| 1818 |
% \begin{lstxsample} |
| 1819 |
% \lstset{morecomment=[l][keywordstyle]{//}, |
| 1820 |
% morecomment=[s][\underbar]{/*}{*/}} |
| 1821 |
% \end{lstxsample} |
| 1822 |
%\fi |
| 1823 |
% \begin{lstsample}{}{} |
| 1824 |
% \begin{lstlisting} |
| 1825 |
% // bold comment line |
| 1826 |
% a single /* comment */ |
| 1827 |
% \end{lstlisting} |
| 1828 |
% \end{lstsample} |
| 1829 |
% As you can see, you have the choice between specifying the style explicitly |
| 1830 |
% by \LaTeX\ commands or implicitly by other style keys. But, you're right, |
| 1831 |
% some implicitly defined styles have no separate keys, for example the second |
| 1832 |
% order keyword style. Here---and never with the number 1---you just append |
| 1833 |
% the order to the base key: \texttt{keywordstyle2}. |
| 1834 |
% |
| 1835 |
% You ask for an application? Here you are: one can define different printing |
| 1836 |
% styles for `subtypes' of a comment, for example |
| 1837 |
%\ifcolor |
| 1838 |
% \begin{lstxsample} |
| 1839 |
% \lstset{morecomment=[s][\color{blue}]{/*+}{*/}, |
| 1840 |
% morecomment=[s][\color{red}]{/*-}{*/}} |
| 1841 |
% \end{lstxsample} |
| 1842 |
%\else |
| 1843 |
% \begin{lstxsample} |
| 1844 |
% \lstset{morecomment=[s][\upshape]{/*+}{*/}, |
| 1845 |
% morecomment=[s][\bfseries]{/*-}{*/}} |
| 1846 |
% \end{lstxsample} |
| 1847 |
%\fi |
| 1848 |
% \begin{lstsample}{\lstset{morecomment=[s]{/*}{*/}}}{} |
| 1849 |
% \begin{lstlisting} |
| 1850 |
% /* normal comment */ |
| 1851 |
% /*+ keep cool */ |
| 1852 |
% /*- danger! */ |
| 1853 |
% \end{lstlisting} |
| 1854 |
% \end{lstsample} |
| 1855 |
% Here, the comment style is not applied to the second and third line. |
| 1856 |
% \begin{advise} |
| 1857 |
% \item Please remember that both `extra' comments must be defined \emph{after} |
| 1858 |
% the normal comment, since the delimiter `\texttt{/*}' is a substring of |
| 1859 |
% `\texttt{/*+}' and `\texttt{/*-}'. |
| 1860 |
% |
| 1861 |
% \item I have another question. Is `\texttt{language=}\meta{different |
| 1862 |
% language}' the only way to remove such additional delimiters? |
| 1863 |
% \advisespace |
| 1864 |
% Call {\rstyle\ikeyname{deletecomment}} and/or |
| 1865 |
% {\rstyle\ikeyname{deletestring}} with the same arguments to remove |
| 1866 |
% the delimiters (but you don't need to provide the optional style |
| 1867 |
% argument). |
| 1868 |
% \end{advise} |
| 1869 |
% Eventually, you might want to use the prefix \texttt{i} on any comment type. |
| 1870 |
% Then the comment is not only invisible, it is completely discarded from the |
| 1871 |
% output! |
| 1872 |
% \begin{lstxsample}[is] |
| 1873 |
% \lstset{morecomment=[is]{/*}{*/}} |
| 1874 |
% \end{lstxsample} |
| 1875 |
% \begin{lstsample}{}{} |
| 1876 |
% \begin{lstlisting} |
| 1877 |
% begin /* comment */ end |
| 1878 |
% begin/* comment */end |
| 1879 |
% \end{lstlisting} |
| 1880 |
% \end{lstsample} |
| 1881 |
% |
| 1882 |
% Okay, and now for the real challenges. More general delimiters can be defined |
| 1883 |
% by the key {\rstyle\ikeyname{moredelim}}. Legal types are {\rstyle\texttt{l}} |
| 1884 |
% and {\rstyle\texttt{s}}. These types can be preceded by an \texttt{i}, but |
| 1885 |
% this time \emph{only the delimiters} are discarded from the output. This way |
| 1886 |
% you can select styles by markers. |
| 1887 |
% \begin{lstxsample} |
| 1888 |
% \lstset{moredelim=[is][\ttfamily]{|}{|}} |
| 1889 |
% \end{lstxsample} |
| 1890 |
% \begin{lstsample}{}{} |
| 1891 |
% \begin{lstlisting} |
| 1892 |
% roman |typewriter| |
| 1893 |
% \end{lstlisting} |
| 1894 |
% \end{lstsample} |
| 1895 |
% You can even let the package detect keywords, comments, strings, and other |
| 1896 |
% delimiters inside the contents. |
| 1897 |
% \begin{lstxsample} |
| 1898 |
% \lstset{moredelim=*[s][\itshape]{/*}{*/}} |
| 1899 |
% \end{lstxsample} |
| 1900 |
% \begin{lstsample}{}{} |
| 1901 |
% \begin{lstlisting} |
| 1902 |
% /* begin |
| 1903 |
% (* comment *) |
| 1904 |
% ' string ' */ |
| 1905 |
% \end{lstlisting} |
| 1906 |
% \end{lstsample} |
| 1907 |
% Moreover, you can force the styles to be applied cumulatively. |
| 1908 |
% \begin{lstxsample} |
| 1909 |
% \lstset{moredelim=**[is][\ttfamily]{|}{|}, % cumulative |
| 1910 |
% moredelim=*[s][\itshape]{/*}{*/}} % not so |
| 1911 |
% \end{lstxsample} |
| 1912 |
% \begin{lstsample}{}{} |
| 1913 |
% \begin{lstlisting} |
| 1914 |
% /* begin |
| 1915 |
% ' string ' |
| 1916 |
% |typewriter| */ |
| 1917 |
% |
| 1918 |
% | begin |
| 1919 |
% ' string ' |
| 1920 |
% /*typewriter*/ | |
| 1921 |
% \end{lstlisting} |
| 1922 |
% \end{lstsample} |
| 1923 |
% Look carefully at the output and note the differences. The second |
| 1924 |
% \texttt{begin} is not printed in bold typewriter type since standard |
| 1925 |
% \LaTeX\ has no such font. |
| 1926 |
% |
| 1927 |
% This suffices for an introduction. Now go and find some more applications. |
| 1928 |
% |
| 1929 |
% |
| 1930 |
% \subsection{Closing and credits}\label{uClosingAndCredits} |
| 1931 |
% |
| 1932 |
% You've seen a lot of keys but you are far away from knowing all of them. |
| 1933 |
% The next step is the real use of the \packagename{listings} package. |
| 1934 |
% Please take the following advice. Firstly, look up the known commands and |
| 1935 |
% keys in the reference guide to get a notion of the notation there. Secondly, |
| 1936 |
% poke around with these keys to learn some other parameters. Then, hopefully, |
| 1937 |
% you'll be prepared if you encounter any problems or need some special things. |
| 1938 |
% |
| 1939 |
% \begin{advise} |
| 1940 |
% \item |
| 1941 |
% There is one question `you' haven't asked all the last pages: who is to |
| 1942 |
% blame. Carsten Heinz wrote the guides, coded the \packagename{listings} |
| 1943 |
% package and wrote some language drivers. Brooks Moses took over the |
| 1944 |
% maintaining for several years, Jobst Hoffmann currently maintains |
| 1945 |
% the package. Other people defined more languages |
| 1946 |
% or contributed their ideas; many others made bug reports, but only the first |
| 1947 |
% bug finder is listed. |
| 1948 |
%^^A |
| 1949 |
%^^A Thanks for error reports (first bug finder only), new programming |
| 1950 |
%^^A languages, etc. |
| 1951 |
%^^A Special thanks for communication which lead to kernel extensions, and to |
| 1952 |
%^^A Hendri Adriaens for reviving maintenance on the package. |
| 1953 |
%^^A |
| 1954 |
% Special thanks go to (alphabetical order) |
| 1955 |
% \begin{quote} |
| 1956 |
% \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth |
| 1957 |
% \lstthanks{Hendri~Adriaens}{-}, |
| 1958 |
% \lstthanks{Andreas~Bartelt}{[email protected]}, |
| 1959 |
% \lstthanks{Jan~Braun}{[email protected]}, |
| 1960 |
% \lstthanks{Denis~Girou}{[email protected]}, |
| 1961 |
% \lstthanks{Arne~John~Glenstrup}{[email protected]}, |
| 1962 |
% \lstthanks{Frank~Mittelbach}{[email protected]}, |
| 1963 |
% \lstthanks{Rolf~Niepraschk}{[email protected]}, |
| 1964 |
% \lstthanks{Rui~Oliveira}{[email protected]}, |
| 1965 |
% \lstthanks{Jens~Schwarzer}{[email protected]}, and |
| 1966 |
% \lstthanks{Boris~Veytsman}{[email protected]}. |
| 1967 |
% \end{quote} |
| 1968 |
% Moreover we wish to thank |
| 1969 |
% \begin{quote} |
| 1970 |
% \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth |
| 1971 |
% \lstthanks{Nasser~M.~Abbasi}{[email protected]}, |
| 1972 |
% \lstthanks{Bj{\o}rn~{\AA}dlandsvik}{[email protected]}, |
| 1973 |
% \lstthanks{Omair-Inam~Abdul-Matin}{-}, |
| 1974 |
% \lstthanks{Gaurav~Aggarwal}{[email protected]}, |
| 1975 |
% \lstthanks{Jason~Alexander}{[email protected]}, |
| 1976 |
% \lstthanks{Andrei~Alexandrescu}{-}, |
| 1977 |
% \lstthanks{Holger~Arndt}{-}, |
| 1978 |
% \lstthanks{Donald~Arseneau}{[email protected]}, |
| 1979 |
% \lstthanks{David~Aspinall}{[email protected]}, |
| 1980 |
% \lstthanks{Frank~Atanassow}{-}, |
| 1981 |
% \lstthanks{Claus~Atzenbeck}{[email protected]}, |
| 1982 |
% \lstthanks{Michael~Bachmann}{-}, |
| 1983 |
% \lstthanks{Luca~Balzerani}{-}, |
| 1984 |
% \lstthanks{Peter~Bartke}{[email protected]} (big thankyou), ^^A beta tester |
| 1985 |
% \lstthanks{Jean-Yves~Baudais}{[email protected]}, |
| 1986 |
% \lstthanks{Heiko~Bauke}{-}, |
| 1987 |
% \lstthanks{Oliver~Baum}{[email protected]}, |
| 1988 |
% \lstthanks{Ralph~Becket}{[email protected]}, |
| 1989 |
% \lstthanks{Andres~Becerra~Sandoval}{[email protected]}, |
| 1990 |
% \lstthanks{Kai~Below}{[email protected]}, |
| 1991 |
% \lstthanks{Matthias~Bethke}{-}, |
| 1992 |
% \lstthanks{Javier~Bezos}{[email protected]}, |
| 1993 |
% \lstthanks{Olaf~Trygve~Berglihn}{[email protected]}, |
| 1994 |
% ^^A {1999/11/29}{3-char comment delimiter don't work (Python)} |
| 1995 |
% \lstthanks{Karl~Berry}{[email protected]}, |
| 1996 |
% \lstthanks{Geraint~Paul~Bevan}{[email protected]}, |
| 1997 |
% \lstthanks{Peter~Biechele}{[email protected]}, |
| 1998 |
% \lstthanks{Beat~Birkhofer}{[email protected]}, |
| 1999 |
% \lstthanks{Fr\'ed\'eric~Boulanger}{[email protected]}, |
| 2000 |
% \lstthanks{Byron~K.~Boulton}{[email protected]}, |
| 2001 |
% \lstthanks{Joachim~Breitner}{-}, |
| 2002 |
% \lstthanks{Martin~Brodbeck}{[email protected]}, |
| 2003 |
% \lstthanks{Walter~E.~Brown}{[email protected]}, |
| 2004 |
% \lstthanks{Achim~D.~Brucker}{[email protected]}, |
| 2005 |
% \lstthanks{J\'an Bu\v{s}a}{-}, |
| 2006 |
% \lstthanks{Thomas~ten~Cate}{-}, |
| 2007 |
% \lstthanks{David~Carlisle}{[email protected]}, |
| 2008 |
% \lstthanks{Bradford~Chamberlain}{[email protected]}, |
| 2009 |
% \lstthanks{Brian~Christensen}{-}, |
| 2010 |
% \lstthanks{Neil~Conway}{-}, |
| 2011 |
% \lstthanks{Patrick~Cousot}{[email protected]}, |
| 2012 |
% \lstthanks{Xavier~Cr\'egut}{[email protected]}, |
| 2013 |
% \lstthanks{Christopher~Creutzig}{-}, |
| 2014 |
% \lstthanks{Holger~Danielsson}{[email protected]}, |
| 2015 |
% \lstthanks{Andreas~Deininger}{[email protected]}, |
| 2016 |
% \lstthanks{Robert~Denham}{[email protected]}, |
| 2017 |
% \lstthanks{Detlev~Dr\"oge}{[email protected]}, |
| 2018 |
% \lstthanks{Anders~Edenbrandt}{[email protected]}, |
| 2019 |
% \lstthanks{Mark~van~Eijk}{[email protected]}, |
| 2020 |
% \lstthanks{Norbert~Eisinger}{[email protected]}, |
| 2021 |
% \lstthanks{Brian~Elmegaard}{-}, |
| 2022 |
% \lstthanks{Jon~Ericson}{[email protected]}, |
| 2023 |
% \lstthanks{Luc~Van~Eycken}{[email protected]} |
| 2024 |
% \lstthanks{Thomas~Esser}{[email protected]}, |
| 2025 |
% \lstthanks{Chris~Edwards}{[email protected]}, |
| 2026 |
% \lstthanks{David~John~Evans}{[email protected]}, |
| 2027 |
% \lstthanks{Tanguy~Fautr\'e}{[email protected]}, |
| 2028 |
% \lstthanks{Ulrike~Fischer}{[email protected]}, |
| 2029 |
% \lstthanks{Robert~Frank}{[email protected]}, |
| 2030 |
% \lstthanks{Michael~Franke}{-}, |
| 2031 |
% \lstthanks{Ignacio~Fern\'andez~Galv\'an}{-}, |
| 2032 |
% \lstthanks{Martine~Gautier}{-} |
| 2033 |
% \lstthanks{Daniel~Gazard}{[email protected]}, |
| 2034 |
% \lstthanks{Daniel~Gerigk}{[email protected]}, |
| 2035 |
% \lstthanks{Dr.~Christoph~Giess}{-}, |
| 2036 |
% \lstthanks{KP~Gores}{[email protected]}, |
| 2037 |
% \lstthanks{Adam~Grabowski}{[email protected]}, |
| 2038 |
% \lstthanks{Jean-Philippe~Grivet}{[email protected]}, |
| 2039 |
% \lstthanks{Christian~Gudrian}{[email protected]}, |
| 2040 |
% \lstthanks{Jonathan~de~Halleux}{[email protected]}, |
| 2041 |
% \lstthanks{Carsten~Hamm}{[email protected]}, |
| 2042 |
% \lstthanks{Martina~Hansel}{[email protected]}, |
| 2043 |
% \lstthanks{Harald~Harders}{[email protected]}, |
| 2044 |
% \lstthanks{Christian~Haul}{[email protected]}, |
| 2045 |
% \lstthanks{Aidan~Philip~Heerdegen}{[email protected]}, |
| 2046 |
% \lstthanks{Jim~Hefferon}{[email protected]}, |
| 2047 |
% \lstthanks{Heiko~Heil}{[email protected]}, |
| 2048 |
% \lstthanks{J\"urgen~Heim}{[email protected]}, |
| 2049 |
% \lstthanks{Martin~Heller}{-}, |
| 2050 |
% \lstthanks{Stephan~Hennig}{-}, |
| 2051 |
% \lstthanks{Alvaro~Herrera}{[email protected]}, |
| 2052 |
% \lstthanks{Richard~Hoefter}{[email protected]}, |
| 2053 |
% \lstthanks{Dr.~Jobst~Hoffmann}{[email protected]}, |
| 2054 |
% \lstthanks{Torben~Hoffmann}{[email protected]}, |
| 2055 |
% \lstthanks{Morten~H\o gholm}{-}, |
| 2056 |
% \lstthanks{Berthold~H\"ollmann}{[email protected]}, |
| 2057 |
% \lstthanks{G\'erard~Huet}{-}, |
| 2058 |
% \lstthanks{Hermann~H\"uttler}{[email protected]}, |
| 2059 |
% \lstthanks{Ralf~Imh\"auser}{[email protected]}, |
| 2060 |
% \lstthanks{R.~Isernhagen}{[email protected]}, |
| 2061 |
% \lstthanks{Oldrich~Jedlicka}{[email protected]}, |
| 2062 |
% \lstthanks{Dirk~Jesko}{[email protected]}, |
| 2063 |
% \lstthanks{Lo\"\i c~Joly}{-}, |
| 2064 |
% \lstthanks{Christian~Kaiser}{[email protected]}, |
| 2065 |
% \lstthanks{Bekir~Karaoglu}{[email protected]}, |
| 2066 |
% \lstthanks{Marcin~Kasperski}{[email protected]}, |
| 2067 |
% \lstthanks{Christian~Kindinger}{[email protected]}, |
| 2068 |
% \lstthanks{Steffen~Klupsch}{[email protected]}, |
| 2069 |
% \lstthanks{Markus~Kohm}{-}, |
| 2070 |
% \lstthanks{Peter~K\"oller}{[email protected]} (big thankyou), ^^A beta tester |
| 2071 |
% \lstthanks{Reinhard~Kotucha}{[email protected]}, |
| 2072 |
% \lstthanks{Stefan~Lagotzki}{[email protected]}, |
| 2073 |
% \lstthanks{Tino~Langer}{[email protected]}, |
| 2074 |
% \lstthanks{Rene~H.~Larsen}{[email protected]}, |
| 2075 |
% \lstthanks{Olivier~Lecarme}{[email protected]}, |
| 2076 |
% \lstthanks{Thomas~Leduc}{[email protected]}, |
| 2077 |
% \lstthanks{Qing~Lee}{-}, |
| 2078 |
% \lstthanks{Dr.~Peter~Leibner}{[email protected]}, |
| 2079 |
% \lstthanks{Thomas~Leonhardt}{[email protected]} |
| 2080 |
% (big thankyou), ^^A beta tester |
| 2081 |
% \lstthanks{Magnus~Lewis-Smith}{[email protected]}, |
| 2082 |
% \lstthanks{Knut~Lickert}{[email protected]}, |
| 2083 |
% \lstthanks{Benjamin~Lings}{-}, |
| 2084 |
% \lstthanks{Dan~Luecking}{[email protected]}, |
| 2085 |
% \lstthanks{Peter~L\"offler}{-}, |
| 2086 |
% \lstthanks{Markus~Luisser}{-}, |
| 2087 |
% \lstthanks{Kris~Luyten}{no email available}, |
| 2088 |
% \lstthanks{Jos\'e~Romildo~Malaquias}{[email protected]}, |
| 2089 |
% \lstthanks{Andreas~Matthias}{[email protected]}, |
| 2090 |
% \lstthanks{Patrick~TJ~McPhee}{[email protected]}, |
| 2091 |
% ^^A \lstthanks{Brooks~Moses}{-}, |
| 2092 |
% \lstthanks{Riccardo~Murri}{[email protected]}, |
| 2093 |
% \lstthanks{Knut~M\"uller}{[email protected]}, |
| 2094 |
% \lstthanks{Svend~Tollak~Munkejord}{[email protected]}, |
| 2095 |
% \lstthanks{Gerd~Neugebauer}{[email protected]}, |
| 2096 |
% \lstthanks{Torsten~Neuer}{[email protected]}, |
| 2097 |
% \lstthanks{Enzo~Nicosia}{-}, |
| 2098 |
% \lstthanks{Michael~Niedermair}{[email protected]}, |
| 2099 |
% \lstthanks{Xavier~Noria}{[email protected]}, |
| 2100 |
% \lstthanks{Heiko~Oberdiek}{[email protected]}, |
| 2101 |
% \lstthanks{Xavier~Olive}{-}, |
| 2102 |
% \lstthanks{Sebastian Ørsted}{[email protected]}, |
| 2103 |
% \lstthanks{Alessio~Pace}{-}, |
| 2104 |
% \lstthanks{Markus~Pahlow}{[email protected]}, |
| 2105 |
% \lstthanks{Morten~H.~Pedersen}{[email protected]}, |
| 2106 |
% \lstthanks{Xiaobo~Peng}{-}, |
| 2107 |
% \lstthanks{Zvezdan~V.~Petkovic}{[email protected]}, |
| 2108 |
% \lstthanks{Michael~Piefel}{[email protected]}, |
| 2109 |
% \lstthanks{Michael~Piotrowski}{[email protected]}, |
| 2110 |
% \lstthanks{Manfred~Piringer}{[email protected]}, |
| 2111 |
% \lstthanks{Ivo~Pletikosi\'c}{[email protected]}, |
| 2112 |
% \lstthanks{Vincent~Poirriez}{[email protected]}, |
| 2113 |
% \lstthanks{Adam~Prugel-Bennett}{[email protected]}, |
| 2114 |
% \lstthanks{Ralf~Quast}{[email protected]}, |
| 2115 |
% \lstthanks{Aslak~Raanes}{[email protected]}, |
| 2116 |
% \lstthanks{Venkatesh~Prasad~Ranganath}{[email protected]}, |
| 2117 |
% \lstthanks{Tobias~Rapp}{-}, |
| 2118 |
% \lstthanks{Jeffrey~Ratcliffe}{-}, |
| 2119 |
% \lstthanks{Georg~Rehm}{[email protected]}, |
| 2120 |
% \lstthanks{Fermin~Reig}{[email protected]}, |
| 2121 |
% \lstthanks{Detlef~Reimers}{[email protected]}, |
| 2122 |
% \lstthanks{Stephen~Reindl}{[email protected]}, |
| 2123 |
% \lstthanks{Franz~Rinnerthaler}{-}, |
| 2124 |
% \lstthanks{Peter~Ruckdeschel}{[email protected]}, |
| 2125 |
% \lstthanks{Magne~Rudshaug}{[email protected]}, |
| 2126 |
% \lstthanks{Jonathan~Sauer}{[email protected]}, |
| 2127 |
% \lstthanks{Vespe~Savikko}{[email protected]}, |
| 2128 |
% \lstthanks{Mark~Schade}{-}, |
| 2129 |
% \lstthanks{Gunther~Schmidl}{[email protected]}, |
| 2130 |
% \lstthanks{Andreas~Schmidt}{-}, |
| 2131 |
% \lstthanks{Walter~Schmidt}{[email protected]}, |
| 2132 |
% \lstthanks{Christian~Schneider}{-}, |
| 2133 |
% \lstthanks{Jochen~Schneider}{[email protected]}, |
| 2134 |
% \lstthanks{Sven~Schreiber}{[email protected]}, |
| 2135 |
% \lstthanks{Benjamin~Schubert}{[email protected]}, |
| 2136 |
% \lstthanks{Sebastian~Schubert}{-}, |
| 2137 |
% \lstthanks{Uwe~Siart}{[email protected]}, |
| 2138 |
% \lstthanks{Axel~Sommerfeldt}{[email protected]}, |
| 2139 |
% \lstthanks{Richard~Stallman}{-}, |
| 2140 |
% \lstthanks{Nigel~Stanger}{[email protected]}, |
| 2141 |
% \lstthanks{Martin~Steffen}{[email protected]}, |
| 2142 |
% \lstthanks{Andreas~Stephan}{[email protected]}, |
| 2143 |
% \lstthanks{Stefan~Stoll}{[email protected]}, |
| 2144 |
% \lstthanks{Enrico~Straube}{no email available}, |
| 2145 |
% \lstthanks{Werner~Struckmann}{[email protected]}, |
| 2146 |
% \lstthanks{Martin~S\"u\ss kraut}{[email protected]}, |
| 2147 |
% \lstthanks{Gabriel~Tauro}{[email protected]}, |
| 2148 |
% \lstthanks{Winfried~Theis}{[email protected]}, |
| 2149 |
% \lstthanks{Jens~T.~Berger~Thielemann}{[email protected]}, |
| 2150 |
% \lstthanks{William~Thimbleby}{-}, |
| 2151 |
% \lstthanks{Arnaud~Tisserand}{[email protected]}, |
| 2152 |
% \lstthanks{Jens~Troeger}{-}, |
| 2153 |
% \lstthanks{Kalle~Tuulos}{[email protected]}, |
| 2154 |
% \lstthanks{Gregory~Van~Vooren}{[email protected]}, |
| 2155 |
% \lstthanks{Timothy~Van~Zandt}{[email protected]}, |
| 2156 |
% \lstthanks{J\"org~Viermann}{-}, |
| 2157 |
% \lstthanks{Thorsten~Vitt}{[email protected]}, |
| 2158 |
% \lstthanks{Herbert~Voss}{[email protected]} (big thankyou), ^^A beta tester |
| 2159 |
% \lstthanks{Edsko~de~Vries}{[email protected]}, |
| 2160 |
% \lstthanks{Herfried~Karl~Wagner}{[email protected]}, |
| 2161 |
% \lstthanks{Dominique~de~Waleffe}{[email protected]}, |
| 2162 |
% \lstthanks{Bernhard~Walle}{-}, |
| 2163 |
% \lstthanks{Jared~Warren}{[email protected]}, |
| 2164 |
% \lstthanks{Michael~Weber}{[email protected]}, |
| 2165 |
% \lstthanks{Sonja~Weidmann}{[email protected]}, |
| 2166 |
% \lstthanks{Andreas~Weidner}{-}, |
| 2167 |
% \lstthanks{Herbert~Weinhandl}{[email protected]}, |
| 2168 |
% \lstthanks{Robert~Wenner}{[email protected]}, |
| 2169 |
% \lstthanks{Michael~Wiese}{[email protected]}, |
| 2170 |
% \lstthanks{James~Willans}{-}, |
| 2171 |
% \lstthanks{J\"orn~Wilms}{[email protected]}, |
| 2172 |
% \lstthanks{Kai~Wollenweber}{[email protected]}, |
| 2173 |
% \lstthanks{Ulrich~G.~Wortmann}{[email protected]}, |
| 2174 |
% \lstthanks{Cameron~H.G.~Wright}{-}, |
| 2175 |
% \lstthanks{Joseph~Wright}{[email protected]}, |
| 2176 |
% \lstthanks{Andrew~Zabolotny}{-}, and |
| 2177 |
% \lstthanks{Florian~Z\"ahringer}{-}. |
| 2178 |
% \end{quote} |
| 2179 |
% There are probably other people who contributed to this package. |
| 2180 |
% If I've missed your name, send an email. |
| 2181 |
% \end{advise} |
| 2182 |
% |
| 2183 |
% |
| 2184 |
% \part{Reference guide} |
| 2185 |
% |
| 2186 |
% |
| 2187 |
% \section{Main reference}\label{rMainReference} |
| 2188 |
% |
| 2189 |
% Your first training is completed. Now that you've left the User's guide, the |
| 2190 |
% friend telling you what to do has gone. Get more practice and become a |
| 2191 |
% journeyman!^^A :-) |
| 2192 |
% \begin{advise} |
| 2193 |
% \item Actually, the friend hasn't gone. There are still some advices, but |
| 2194 |
% only from time to time. |
| 2195 |
% \end{advise} |
| 2196 |
% |
| 2197 |
% |
| 2198 |
% \subsection{How to read the reference} |
| 2199 |
% |
| 2200 |
% Commands, keys and environments are presented as follows. |
| 2201 |
% \begin{syntax} |
| 2202 |
% \item[1.0,default,hints] \texttt{command}, \texttt{environment} or |
| 2203 |
% \keyname{key} with \meta{parameters} |
| 2204 |
% |
| 2205 |
% This field contains the explanation; here we describe the other fields. |
| 2206 |
% |
| 2207 |
% If present, the label in the left margin provides extra information: |
| 2208 |
% `\textit{addon}' indicates additionally introduced functionality, |
| 2209 |
% `\textit{changed}' a modified key, `\textit{data}' a command just |
| 2210 |
% containing data (which is therefore adjustable via |\renewcommand|), |
| 2211 |
% and so on. Some keys and functionality are `\emph{bug}'-marked or |
| 2212 |
% with a \dag-sign. These features might change in future or could be |
| 2213 |
% removed, so use them with care. |
| 2214 |
% |
| 2215 |
% If there is verbatim text touching the right margin, it is the |
| 2216 |
% predefined value. Note that some keys default to this value every |
| 2217 |
% listing, namely the keys which can be used on individual listings only. |
| 2218 |
% \end{syntax} |
| 2219 |
% Regarding the parameters, please keep in mind the following: |
| 2220 |
% \begin{enumerate} |
| 2221 |
% \item A list always means a comma separated list. You must put braces around |
| 2222 |
% such a list. Otherwise you'll get in trouble with the |
| 2223 |
% \packagename{keyval} package; it complains about an undefined key. |
| 2224 |
% \item You must put parameter braces around the whole value of a key if you |
| 2225 |
% use an \oarg{optional argument} of a key inside an optional |
| 2226 |
% \oarg{key=value list}: |
| 2227 |
% |\begin{lstlisting}[caption=|{\rstyle|{|}|[one]two|{\rstyle|}|}|]|. |
| 2228 |
% \item Brackets `|[ ]|' usually enclose optional arguments and must be typed |
| 2229 |
% in verbatim. Normal brackets `[ ]' always indicate an optional argument |
| 2230 |
% and must not be typed in. Thus |[*]| must be typed in exactly as is, |
| 2231 |
% but [|*|] just gets |*| if you use this argument. |
| 2232 |
% \item A vertical rule indicates an alternative, e.g.~^^A |
| 2233 |
% \meta{\alternative{true,false}} allows either \texttt{true} or |
| 2234 |
% \texttt{false} as arguments. |
| 2235 |
% \item If you want to enter one of the special characters |{}#%\|, this |
| 2236 |
% character must be escaped with a backslash. This means that you must |
| 2237 |
% write |\}| for the single character `right brace'---but of course not |
| 2238 |
% for the closing paramater character. |
| 2239 |
% \end{enumerate} |
| 2240 |
% |
| 2241 |
% |
| 2242 |
% \subsection{Typesetting listings}\label{rTypesettingListings} |
| 2243 |
% |
| 2244 |
% \begin{syntax} |
| 2245 |
% \item[0.19] \rcmdname\lstset\marg{key=value list} |
| 2246 |
% |
| 2247 |
% sets the values of the specified keys, see also section |
| 2248 |
% \ref{uTheKey=ValueInterface}. The parameters keep their values up to |
| 2249 |
% the end of the current group. In contrast, all optional |
| 2250 |
% \meta{key=value list}s below modify the parameters for single |
| 2251 |
% listings only. |
| 2252 |
% |
| 2253 |
% \item[0.18] |
| 2254 |
% \rcmdname\lstinline\oarg{key=value list}\meta{character}^^A |
| 2255 |
% \meta{source code}\meta{same character} |
| 2256 |
% |
| 2257 |
% works like |\verb| but respects the active language and style. |
| 2258 |
% These listings use flexible columns unless requested differently |
| 2259 |
% in the optional argument, and do not support frames or background |
| 2260 |
% colors. You can write `|\lstinline!var i:integer;!|' and get |
| 2261 |
% `\lstinline!var i:integer;!'. |
| 2262 |
% |
| 2263 |
% Since the command first looks ahead for an optional argument, you |
| 2264 |
% must provide at least an empty one if you want to use |[| as |
| 2265 |
% \meta{character}. |
| 2266 |
% |
| 2267 |
% \dag\ An experimental implementation has been done to support the |
| 2268 |
% syntax |\lstinline|\oarg{key=value list}\marg{source code}. Try it |
| 2269 |
% if you want and report success and failure. A known limitation is |
| 2270 |
% that inside another argument the last source code token must not |
| 2271 |
% be an explicit space token---and, of course, using a listing inside |
| 2272 |
% another argument is itself experimental, see section |
| 2273 |
% \ref{rListingsInsideArguments}. |
| 2274 |
% |
| 2275 |
% Another limitation is that this feature can't be used in cells of a |
| 2276 |
% |tabular|-environment. See section \ref{uListingsArguments} for a |
| 2277 |
% workaround. |
| 2278 |
% |
| 2279 |
% See also section \ref{rShortInline} for commands to create short |
| 2280 |
% analogs for the |\lstinline| command. |
| 2281 |
% |
| 2282 |
% \item[0.15] |\begin{|\texttt{\rstyle lstlisting}|}|\oarg{key=value |
| 2283 |
% list} |
| 2284 |
% |
| 2285 |
% \leavevmode\hspace*{-\leftmargini}|\end{|\texttt{\rstyle |
| 2286 |
% lstlisting}|}| |
| 2287 |
% |
| 2288 |
% typesets the code in between as a displayed listing. |
| 2289 |
% |
| 2290 |
% In contrast to the environment of the \packagename{verbatim} |
| 2291 |
% package, \LaTeX\ code on the same line and after the end of |
| 2292 |
% environment is typeset respectively executed. |
| 2293 |
% |
| 2294 |
% \item[0.1] \rcmdname\lstinputlisting\oarg{key=value list}\marg{file |
| 2295 |
% name} |
| 2296 |
% |
| 2297 |
% typesets the stand alone source code file as a displayed listing. |
| 2298 |
% \end{syntax} |
| 2299 |
% |
| 2300 |
% |
| 2301 |
% \subsection{Options} |
| 2302 |
% |
| 2303 |
% The following sections describe all the keys that can be used to |
| 2304 |
% influence the appearance of the listing. |
| 2305 |
% |
| 2306 |
% |
| 2307 |
% \subsubsection{Searching for files} |
| 2308 |
% |
| 2309 |
% \begin{syntax} |
| 2310 |
% \item[1.8, {}] \rkeyname{inputpath}|=|\meta{path} |
| 2311 |
% |
| 2312 |
% defines the path, where the file given by \meta{file name} resides. |
| 2313 |
% |
| 2314 |
% \rkeyname{inputpath} overrules the |TEXINPUTS| environment variable, |
| 2315 |
% which means that a file residing on one of the paths given by |
| 2316 |
% |TEXINPUTS| isn't found anymore, if \meta{path} isn't part of |
| 2317 |
% |TEXINPUTS|. |
| 2318 |
% |
| 2319 |
% \rkeyname{inputpath} set as option of \rcmdname\lstinputlisting{} |
| 2320 |
% overrules the value set by \rcmdname\lstset. |
| 2321 |
% \end{syntax} |
| 2322 |
% |
| 2323 |
% |
| 2324 |
% \subsubsection{Space and placement} |
| 2325 |
% |
| 2326 |
% \begin{syntax} |
| 2327 |
% \item[0.20,floatplacement] \rkeyname{float}|=|[|*|]\meta{subset of |
| 2328 |
% \textup{\texttt{tbph}}}\syntaxor\rkeyname{float} |
| 2329 |
% |
| 2330 |
% makes sense on individual displayed listings only and lets them |
| 2331 |
% float. The argument controls where \LaTeX\ is \emph{allowed} to put |
| 2332 |
% the float: at the top or bottom of the current/next page, on a |
| 2333 |
% separate page, or here where the listing is. |
| 2334 |
% |
| 2335 |
% The optional star can be used to get a double-column float in a |
| 2336 |
% two-column document. |
| 2337 |
% |
| 2338 |
% \item[0.21,tbp] \rkeyname{floatplacement}|=|\meta{place specifiers} |
| 2339 |
% |
| 2340 |
% is used as place specifier if \keyname{float} is used without value. |
| 2341 |
% |
| 2342 |
% \item[0.21,\medskipamount] \rkeyname{aboveskip}|=|\meta{dimension} |
| 2343 |
% \item[0.21,\medskipamount] \rkeyname{belowskip}|=|\meta{dimension} |
| 2344 |
% |
| 2345 |
% define the space above and below displayed listings. |
| 2346 |
% |
| 2347 |
% \item[0.17,0pt,\dag] \rkeyname{lineskip}|=|\meta{dimension} |
| 2348 |
% |
| 2349 |
% specifies additional space between lines in listings. |
| 2350 |
% |
| 2351 |
% \item[0.18,c,\dag] \rkeyname{boxpos}|=|\meta{\alternative{b,c,t}} |
| 2352 |
% |
| 2353 |
% Sometimes the \packagename{listings} package puts a |\hbox| around a |
| 2354 |
% listing---or it couldn't be printed or even processed correctly. The |
| 2355 |
% key determines the vertical alignment to the surrounding material: |
| 2356 |
% bottom baseline, centered or top baseline. |
| 2357 |
% \end{syntax} |
| 2358 |
% |
| 2359 |
% |
| 2360 |
% \subsubsection{The printed range} |
| 2361 |
% |
| 2362 |
% \begin{syntax} |
| 2363 |
% \item[0.12,true] |
| 2364 |
% \rkeyname{print}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{print} |
| 2365 |
% |
| 2366 |
% controls whether an individual displayed listing is typeset. Even if |
| 2367 |
% set false, the respective caption is printed and the label is |
| 2368 |
% defined. |
| 2369 |
% |
| 2370 |
% Note: If the package is loaded without the \texttt{draft} option, you |
| 2371 |
% can use this key together with |\lstset|. In the other case the key |
| 2372 |
% can be used to typeset particular listings despite using the |
| 2373 |
% \texttt{draft} option. |
| 2374 |
% |
| 2375 |
% \item[0.1,1] \rkeyname{firstline}|=|\meta{number} |
| 2376 |
% \item[0.1,9999999] \rkeyname{lastline}|=|\meta{number} |
| 2377 |
% |
| 2378 |
% can be used on individual listings only. They determine the physical |
| 2379 |
% input lines used to print displayed listings. |
| 2380 |
% |
| 2381 |
% \item[1.2;1.9] |
| 2382 |
% \rkeyname{linerange}|={|\meta{first1}\texttt-\meta{last1}\texttt,^^A |
| 2383 |
% \meta{first2}\texttt-\meta{last2}\texttt, and so |
| 2384 |
% on|}|\label{uoption:linerange} |
| 2385 |
% |
| 2386 |
% can be used on individual listings only. The given line ranges of the |
| 2387 |
% listing are displayed. The intervals must be sorted and must not |
| 2388 |
% intersect. |
| 2389 |
% |
| 2390 |
% In fact each part of the triplet \meta{first}\texttt-\meta{last} may |
| 2391 |
% be omitted. Omitting \meta{first} or \meta{last} means, that the |
| 2392 |
% range begins at line no. 1 and ends at \meta{last} or begins at |
| 2393 |
% \meta{first} ends at the last line of the file, a single number |
| 2394 |
% means, that the range begins and ends at the line given by the |
| 2395 |
% number, whereas omitting \meta{first} or \meta{last} means the range |
| 2396 |
% begins at line no. 1 and ends at the last line of the file. |
| 2397 |
% |
| 2398 |
% \item[1.8, true] |
| 2399 |
% \rkeyname{consecutivenumbers}|=|\meta{\alternative{true,false}}^^A |
| 2400 |
% \syntaxor\rkeyname{consecutivenumbers}\label{uoption:consecutivenumbers} |
| 2401 |
% |
| 2402 |
% can be used on individual listings only. Its use makes sense only if |
| 2403 |
% also \rkeyname{linerange} is used. The default (true) value means that |
| 2404 |
% the line numbering for \emph{all} lineranges happens to be consecutively, |
| 2405 |
% e\,g. 1, 2, 3,\ldots. If it is set to false, different ranges get |
| 2406 |
% their own numbering (see sec. \ref{uLineNumbers}). |
| 2407 |
% |
| 2408 |
% \item[0.20,false] |
| 2409 |
% \rkeyname{showlines}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{showlines} |
| 2410 |
% |
| 2411 |
% If true, the package prints empty lines at the end of listings. |
| 2412 |
% Otherwise these lines are dropped (but they count for line |
| 2413 |
% numbering). |
| 2414 |
% |
| 2415 |
% \item[1.0] \rkeyname{emptylines}|=|[|*|]\meta{number} |
| 2416 |
% |
| 2417 |
% sets the maximum of empty lines allowed. If there is a block of more |
| 2418 |
% than \meta{number} empty lines, only \meta{number} ones are printed. |
| 2419 |
% Without the optional star, line numbers can be disturbed when blank |
| 2420 |
% lines are omitted; with the star, the lines keep their original |
| 2421 |
% numbers. |
| 2422 |
% |
| 2423 |
% \item[0.19,0] \rkeyname{gobble}|=|\meta{number} |
| 2424 |
% |
| 2425 |
% gobbles \meta{number} characters at the beginning of each |
| 2426 |
% \emph{environment} code line. This key has no effect on |
| 2427 |
% \cs{lstinline} or \cs{lstinputlisting}. |
| 2428 |
% |
| 2429 |
% Tabulators expand to \ikeyname{tabsize} spaces before they are |
| 2430 |
% gobbled. Code lines with fewer than \ikeyname{gobble} characters are |
| 2431 |
% considered empty. Never indent the end of environment by more |
| 2432 |
% characters. |
| 2433 |
% \end{syntax} |
| 2434 |
% |
| 2435 |
% |
| 2436 |
% \subsubsection{Languages and styles}\label{rLanguagesAndStyles} |
| 2437 |
% |
| 2438 |
% Please note that the arguments \meta{language}, \meta{dialect}, and |
| 2439 |
% \meta{style name} are case insensitive and that spaces have no effect. |
| 2440 |
% \begin{syntax} |
| 2441 |
% \item[0.18,{{}}] \rkeyname{style}|=|\meta{style name} |
| 2442 |
% |
| 2443 |
% activates the key=value list stored with |\lstdefinestyle|. |
| 2444 |
% |
| 2445 |
% \item[0.19] \rcmdname\lstdefinestyle\marg{style name}\marg{key=value list} |
| 2446 |
% |
| 2447 |
% stores the key=value list. |
| 2448 |
% |
| 2449 |
% \item[0.17,{{}}] \rkeyname{language}|=|\oarg{dialect}\meta{language} |
| 2450 |
% |
| 2451 |
% activates a (dialect of a) programming language. The `empty' default |
| 2452 |
% language detects no keywords, no comments, no strings, and so on; it |
| 2453 |
% may be useful for typesetting plain text. |
| 2454 |
% If \meta{dialect} is not specified, the package chooses the default |
| 2455 |
% dialect, or the empty dialect if there is no default dialect. |
| 2456 |
% |
| 2457 |
% Table \ref{uPredefinedLanguages} on page \pageref{uPredefinedLanguages} |
| 2458 |
% lists all languages and dialects provided by \texttt{lstdrvrs.dtx}. |
| 2459 |
% The predefined default dialects are underlined. |
| 2460 |
% |
| 2461 |
% \item[0.21] \rkeyname{alsolanguage}|=|\oarg{dialect}\meta{language} |
| 2462 |
% |
| 2463 |
% activates a (dialect of a) programming language in addition to the |
| 2464 |
% current active one. Note that some language definitions interfere with |
| 2465 |
% each other and are plainly incompatible; for instance, if one is case |
| 2466 |
% sensitive and the other is not. |
| 2467 |
% |
| 2468 |
% Take a look at the \ikeyname{classoffset} key in section |
| 2469 |
% \ref{rFigureOutTheAppearance} if you want to highlight the keywords |
| 2470 |
% of the languages differently. |
| 2471 |
% |
| 2472 |
% \item[0.19] \rkeyname{defaultdialect}|=|\oarg{dialect}\meta{language} |
| 2473 |
% |
| 2474 |
% defines \meta{dialect} as default dialect for \meta{language}. |
| 2475 |
% If you have defined a default dialect other than empty, for example |
| 2476 |
% |defaultdialect=[iama]fool|, you can't select the empty dialect, even |
| 2477 |
% not with |language=[]fool|. |
| 2478 |
% \end{syntax} |
| 2479 |
% |
| 2480 |
% Finally, here's a small list of language-specific keys. |
| 2481 |
% \begin{syntax} |
| 2482 |
% \item[0.19,false,optional] |
| 2483 |
% \rkeyname{printpod}|=|\meta{\alternative{true,false}} |
| 2484 |
% |
| 2485 |
% prints or drops PODs in Perl. |
| 2486 |
% |
| 2487 |
% \item[0.20,true,{renamed,optional}] |
| 2488 |
% \rkeyname{usekeywordsintag}|=|\meta{\alternative{true,false}}^^A |
| 2489 |
% \label{uoption:usekeywordsintag} |
| 2490 |
% |
| 2491 |
% The package either use the first order keywords in tags or prints all |
| 2492 |
% identifiers inside |<>| in keyword style. |
| 2493 |
% |
| 2494 |
% \item[1.1,{{}},optional] |
| 2495 |
% \rkeyname{tagstyle}|=|\meta{style}\label{uoption:tagstyle} |
| 2496 |
% |
| 2497 |
% determines the style in which tags and their content is printed. |
| 2498 |
% |
| 2499 |
% \item[1.1,false,optional] |
| 2500 |
% \rkeyname{markfirstintag}|=|\meta{style}\label{uoption:markfirstintag} |
| 2501 |
% |
| 2502 |
% prints the first name in tags with keyword style. |
| 2503 |
% |
| 2504 |
% \item[0.20,true,optional] |
| 2505 |
% \rkeyname{makemacrouse}|=|\meta{\alternative{true,false}} |
| 2506 |
% |
| 2507 |
% Make specific: Macro use of identifiers, which are defined as first |
| 2508 |
% order keywords, also prints the surrounding |
| 2509 |
% |$(| and |)| in keyword style. e.g.~you could get |
| 2510 |
% \textbf{\textdollar(}\textbf{strip} \textdollar(BIBS)\textbf{)}. If |
| 2511 |
% deactivated you get \textdollar(\textbf{strip} \textdollar(BIBS)). |
| 2512 |
% \end{syntax} |
| 2513 |
% |
| 2514 |
% |
| 2515 |
% \subsubsection{Figure out the appearance}\label{rFigureOutTheAppearance} |
| 2516 |
% |
| 2517 |
% \begin{syntax} |
| 2518 |
% \item[0.18,{{}}] \rkeyname{basicstyle}|=|\meta{basic style} |
| 2519 |
% |
| 2520 |
% is selected at the beginning of each listing. You could use |
| 2521 |
% |\footnotesize|, |\small|, |\itshape|, |\ttfamily|, or something like |
| 2522 |
% that. The last token of \meta{basic style} must not read any |
| 2523 |
% following characters. |
| 2524 |
% |
| 2525 |
% \item[0.18,{{}}] \rkeyname{identifierstyle}|=|\meta{style} |
| 2526 |
% \item[0.11,\itshape] \rkeyname{commentstyle}|=|\meta{style} |
| 2527 |
% \item[0.12,{{}}] \rkeyname{stringstyle}|=|\meta{style} |
| 2528 |
% |
| 2529 |
% determines the style for non-keywords, comments, and strings. The |
| 2530 |
% \emph{last} token can be an one-parameter command like |\textbf| or |
| 2531 |
% |\underbar|. |
| 2532 |
% |
| 2533 |
% \item[0.11,\bfseries,addon] |
| 2534 |
% \rkeyname{keywordstyle}|=|\oarg{number}[\textasteriskcentered]^^A |
| 2535 |
% \meta{style}\label{roption:keywordstyle} |
| 2536 |
% |
| 2537 |
% is used to print keywords. The optional \meta{number} argument is |
| 2538 |
% the class number to which the style should be applied. |
| 2539 |
% |
| 2540 |
% Add-on: If you use the optional star after the (optional) class |
| 2541 |
% number, the keywords are printed uppercase\,---\,even if a language |
| 2542 |
% is case sensitive and defines lowercase keywords only. Maybe there |
| 2543 |
% should also be an option for lowercase keywords \ldots |
| 2544 |
% |
| 2545 |
% \item[0.19,keywordstyle,deprecated] |
| 2546 |
% \rkeyname{ndkeywordstyle}|=|\meta{style} |
| 2547 |
% |
| 2548 |
% is equivalent to |keywordstyle=2|\meta{style}. |
| 2549 |
% |
| 2550 |
% \item[1.0,0] \rkeyname{classoffset}|=|\meta{number} |
| 2551 |
% |
| 2552 |
% is added to all class numbers before the styles, keywords, |
| 2553 |
% identifiers, etc.~are assigned. The example below defines the |
| 2554 |
% keywords directly; you could do it indirectly by selecting two |
| 2555 |
% different languages. |
| 2556 |
% \end{syntax} |
| 2557 |
%\ifcolor |
| 2558 |
% \begin{lstxsample} |
| 2559 |
% \lstset{classoffset=0, |
| 2560 |
% morekeywords={one,three,five},keywordstyle=\color{red}, |
| 2561 |
% classoffset=1, |
| 2562 |
% morekeywords={two,four,six},keywordstyle=\color{blue}, |
| 2563 |
% classoffset=0}% restore default |
| 2564 |
% \end{lstxsample} |
| 2565 |
%\else |
| 2566 |
% \begin{lstxsample} |
| 2567 |
% \lstset{classoffset=0, |
| 2568 |
% morekeywords={one,three,five},keywordstyle=\itshape, |
| 2569 |
% classoffset=1, |
| 2570 |
% morekeywords={two,four,six},keywordstyle=\bfseries}, |
| 2571 |
% classoffset=0}% restore default |
| 2572 |
% \end{lstxsample} |
| 2573 |
%\fi |
| 2574 |
% \begin{lstsample}{}{} |
| 2575 |
% \begin{lstlisting} |
| 2576 |
% one two three |
| 2577 |
% four five six |
| 2578 |
% \end{lstlisting} |
| 2579 |
% \end{lstsample} |
| 2580 |
% |
| 2581 |
% \begin{syntax} |
| 2582 |
% \item[0.20,keywordstyle,{addon,bug,optional}] |
| 2583 |
% \rkeyname{texcsstyle}|=|[|*|]\oarg{class |
| 2584 |
% number}\meta{style}\label{roption:texcsstyle} |
| 2585 |
% \item[0.20,keywordstyle,optional] |
| 2586 |
% \rkeyname{directivestyle}|=|\meta{style} |
| 2587 |
% |
| 2588 |
% determine the style of \TeX\ control sequences and directives. Note |
| 2589 |
% that these keys are present only if you've chosen an appropriate |
| 2590 |
% language. |
| 2591 |
% |
| 2592 |
% The optional star of |texcsstyle| also highlights the backslash in |
| 2593 |
% front of the control sequence name. Note that this option is set for |
| 2594 |
% all |texcs| lists. |
| 2595 |
% |
| 2596 |
% Bug: \texttt{texcs\ldots} interferes with other keyword lists. If, |
| 2597 |
% for example, \texttt{emph} contains the word \texttt{foo}, then the |
| 2598 |
% control sequence |\foo| will show up in \texttt{emphstyle}. |
| 2599 |
% |
| 2600 |
% \item[0.21] \rkeyname{emph}|=|\oarg{number}\marg{identifier list} |
| 2601 |
% \item[0.21] \rkeyname{moreemph}|=|\oarg{number}\marg{identifier list} |
| 2602 |
% \item[0.21] \rkeyname{deleteemph}|=|\oarg{number}\marg{identifier list} |
| 2603 |
% \item[0.21] \rkeyname{emphstyle}|=|\oarg{number}\marg{style} |
| 2604 |
% |
| 2605 |
% respectively define, add or remove the \meta{identifier list} from |
| 2606 |
% `emphasize class \meta{number}', or define the style for that class. |
| 2607 |
% If you don't give an optional argument, the package assumes |
| 2608 |
% \meta{number}$\,=1$. |
| 2609 |
% |
| 2610 |
% These keys are described more detailed in section |
| 2611 |
% \ref{uEmphasizeIdentifiers}. |
| 2612 |
% |
| 2613 |
% \item[1.0] |
| 2614 |
% \rkeyname{delim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt]^^A |
| 2615 |
% [\texttt[\meta{style}\texttt]]\meta{delimiter\textup(s\textup)} |
| 2616 |
% \item[1.0] |
| 2617 |
% \rkeyname{moredelim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt]^^A |
| 2618 |
% [\texttt[\meta{style}\texttt]]\meta{delimiter\textup(s\textup)} |
| 2619 |
% \item[1.0] |
| 2620 |
% \rkeyname{deletedelim}|=|[\texttt*[\texttt*]]\texttt[\meta{type}\texttt]^^A |
| 2621 |
% \meta{delimiter\textup(s\textup)} |
| 2622 |
% |
| 2623 |
% define, add, or remove user supplied delimiters. (Note that this |
| 2624 |
% does not affect strings or comments.) |
| 2625 |
% |
| 2626 |
% In the first two cases \meta{style} is used to print the delimited |
| 2627 |
% code (and the delimiters). Here, \meta{style} could be something like |
| 2628 |
% |\bfseries| or |\itshape|, or it could refer to other styles via |
| 2629 |
% \texttt{keywordstyle}, \texttt{keywordstyle2}, \texttt{emphstyle}, |
| 2630 |
% etc. |
| 2631 |
% |
| 2632 |
% Supported types are \texttt{l} and \texttt{s}, see the comment keys |
| 2633 |
% in section \ref{uLanguageDefinitions} for an explanation. If you use |
| 2634 |
% the prefix \texttt i, i.e.~\texttt{il} or \texttt{is}, the delimiters |
| 2635 |
% are not printed, which is some kind of invisibility. |
| 2636 |
% |
| 2637 |
% If you use one optional star, the package will detect keywords, |
| 2638 |
% comments, and strings inside the delimited code. With both optional |
| 2639 |
% stars, aditionally the style is applied cumulatively; see section |
| 2640 |
% \ref{uDelimiters}. |
| 2641 |
% \end{syntax} |
| 2642 |
% |
| 2643 |
% |
| 2644 |
% \subsubsection{Getting all characters right} |
| 2645 |
% |
| 2646 |
% \begin{syntax} |
| 2647 |
% \item[0.18,true] |
| 2648 |
% \rkeyname{extendedchars}|=|\meta{\alternative{true,false}}^^A |
| 2649 |
% \syntaxor\rkeyname{extendedchars} |
| 2650 |
% |
| 2651 |
% allows or prohibits extended characters in listings, that means |
| 2652 |
% (national) characters of codes 128--255. If you use extended |
| 2653 |
% characters, you should load \packagename{fontenc} and/or |
| 2654 |
% \packagename{inputenc}, for example. |
| 2655 |
% |
| 2656 |
% \item[1.0,{{}}] \rkeyname{inputencoding}|=|\meta{encoding} |
| 2657 |
% |
| 2658 |
% determines the input encoding. The usage of this key requires the |
| 2659 |
% \packagename{inputenc} package; nothing happens if it's not loaded. |
| 2660 |
% |
| 2661 |
% \item[1.1,false] |
| 2662 |
% \rkeyname{upquote}|=|\meta{\alternative{true,false}}\label{uoption:upquote} |
| 2663 |
% |
| 2664 |
% determines whether the left and right quote are printed |`'| (false) or |
| 2665 |
% \texttt{\textasciigrave\textquotesingle} (true). This key requires the |
| 2666 |
% \packagename{textcomp} package if true, for more information have a |
| 2667 |
% look at page \pageref{sec:upquote}. |
| 2668 |
% |
| 2669 |
% \item[0.12,8] \rkeyname{tabsize}|=|\meta{number} |
| 2670 |
% |
| 2671 |
% sets tabulator stops at columns |
| 2672 |
% $\meta{number}+1$, $2\cdot\meta{number}+1$, |
| 2673 |
% $3\cdot\meta{number}+1$, and so on. Each tabulator in a listing |
| 2674 |
% moves the current column to the next tabulator stop. |
| 2675 |
% |
| 2676 |
% \item[0.20,false] \rkeyname{showtabs}|=|\meta{\alternative{true,false}} |
| 2677 |
% |
| 2678 |
% make tabulators visible or invisible. A visible tabulator looks like |
| 2679 |
% \lstinline[showtabs]! !, but that can be changed. If you choose |
| 2680 |
% invisible tabulators but visible spaces, tabulators are converted to |
| 2681 |
% an appropriate number of spaces. |
| 2682 |
% |
| 2683 |
% \item[0.20] \rkeyname{tab}|=|\meta{tokens} |
| 2684 |
% |
| 2685 |
% \meta{tokens} is used to print a visible tabulator. You might want to |
| 2686 |
% use |$\to$|, |$\mapsto$|, |
| 2687 |
% |$\dashv$| or something like that instead of the strange default |
| 2688 |
% definition. |
| 2689 |
% |
| 2690 |
% \item[0.20,false] |
| 2691 |
% \rkeyname{showspaces}|=|\meta{\alternative{true,false}} |
| 2692 |
% |
| 2693 |
% lets all blank spaces appear {\textvisiblespace} or as blank spaces. |
| 2694 |
% |
| 2695 |
% \item[0.12,true] |
| 2696 |
% \rkeyname{showstringspaces}|=|\meta{\alternative{true,false}} |
| 2697 |
% |
| 2698 |
% lets blank spaces in strings appear {\textvisiblespace} or as blank |
| 2699 |
% spaces. |
| 2700 |
% |
| 2701 |
% \item[0.19,\bigbreak] \rkeyname{formfeed}|=|\meta{tokens} |
| 2702 |
% |
| 2703 |
% Whenever a listing contains a form feed, \meta{tokens} is executed. |
| 2704 |
% \end{syntax} |
| 2705 |
% |
| 2706 |
% |
| 2707 |
% \subsubsection{Line numbers}\label{rLineNumbers} |
| 2708 |
% |
| 2709 |
% \begin{syntax} |
| 2710 |
% \item[1.0,none] |
| 2711 |
% \rkeyname{numbers}|=|\meta{\alternative{none,left,right}} |
| 2712 |
% |
| 2713 |
% makes the package either print no line numbers, or put them on the |
| 2714 |
% left or the right side of a listing. |
| 2715 |
% |
| 2716 |
% \item[0.16,1] \rkeyname{stepnumber}|=|\meta{number} |
| 2717 |
% |
| 2718 |
% All lines with ``line number $\equiv |
| 2719 |
% 0$ modulo \meta{number}'' get a line number. If you turn line |
| 2720 |
% numbers on and off with \keyname{numbers}, the parameter |
| 2721 |
% \keyname{stepnumber} will keep its value. Alternatively you can turn |
| 2722 |
% them off via |stepnumber=0| and on with a nonzero number, and keep |
| 2723 |
% the value of \keyname{numbers}. |
| 2724 |
% |
| 2725 |
% \item[1.1,false] |
| 2726 |
% \rkeyname{numberfirstline}|=|\meta{\alternative{true,false}}^^A |
| 2727 |
% \label{uoption:numberfirstline} |
| 2728 |
% |
| 2729 |
% The first line of each listing gets numbered (if numbers are on at |
| 2730 |
% all) even if the line number is not divisible by |
| 2731 |
% \keyname{stepnumber}. |
| 2732 |
% |
| 2733 |
% \item[0.16,{{}}] \rkeyname{numberstyle}|=|\meta{style} |
| 2734 |
% |
| 2735 |
% determines the font and size of the numbers. |
| 2736 |
% |
| 2737 |
% \item[0.19,10pt] \rkeyname{numbersep}|=|\meta{dimension} |
| 2738 |
% |
| 2739 |
% is the distance between number and listing. |
| 2740 |
% |
| 2741 |
% \item[1.0,true] |
| 2742 |
% \rkeyname{numberblanklines}|=|\meta{\alternative{true,false}} |
| 2743 |
% |
| 2744 |
% If this is set to false, blank lines get no printed line number. |
| 2745 |
% |
| 2746 |
% \item[0.20,auto] |
| 2747 |
% \rkeyname{firstnumber}|=|\meta{\alternative{auto,last,\normalfont\meta{number}}} |
| 2748 |
% |
| 2749 |
% \begin{description} |
| 2750 |
% \item[\texttt{auto}] lets the package choose the first number: a |
| 2751 |
% new listing starts with number one, a named listing continues the |
| 2752 |
% most recent same-named listing (see below), and a stand alone |
| 2753 |
% file begins with the number corresponding to the first input |
| 2754 |
% line. |
| 2755 |
% \item[\texttt{last}] continues the numbering of the most recent |
| 2756 |
% listing and |
| 2757 |
% \item[\meta{number}] sets it to the (logical) number. |
| 2758 |
% \end{description} |
| 2759 |
% |
| 2760 |
% \item[1.0,{{}}] \rkeyname{name}|=|\meta{name} |
| 2761 |
% |
| 2762 |
% can be used on individual listings only, it names a |
| 2763 |
% listing. Displayed environment-listings with the same name share a |
| 2764 |
% line counter if the option |firstnumber=auto| is in effect. |
| 2765 |
% |
| 2766 |
% \item[0.20,\arabic{lstnumber},data] \rcmdname\thelstnumber |
| 2767 |
% |
| 2768 |
% prints the lines' numbers. |
| 2769 |
% \end{syntax} |
| 2770 |
% We show an example on how to redefine |\thelstnumber|. But if you test it, |
| 2771 |
% you won't get the result shown on the left, because internally |
| 2772 |
% |stepnumber=-1| has been set. |
| 2773 |
% \begin{lstxsample} |
| 2774 |
% \renewcommand*\thelstnumber{\oldstylenums{\the\value{lstnumber}}} |
| 2775 |
% \end{lstxsample} |
| 2776 |
% \begin{lstsample}{\lstset{stepnumber=-1}\label{rDecreasingLabels}}{} |
| 2777 |
% \begin{lstlisting}[numbers=left, |
| 2778 |
% firstnumber=753] |
| 2779 |
% begin { empty lines } |
| 2780 |
% |
| 2781 |
% |
| 2782 |
% |
| 2783 |
% |
| 2784 |
% |
| 2785 |
% |
| 2786 |
% end; { empty lines } |
| 2787 |
% \end{lstlisting} |
| 2788 |
% \end{lstsample} |
| 2789 |
% |
| 2790 |
% \begin{advise} |
| 2791 |
% \item The example shows a sequence |
| 2792 |
% $n,n+1,\ldots,n+7$ of 8 three-digit figures such that the sequence |
| 2793 |
% contains each digit |
| 2794 |
% $0,1,\ldots,9$. But 8 is not minimal with that property. Find the |
| 2795 |
% minimal number and prove that it is minimal. How many minimal |
| 2796 |
% sequences do exist? |
| 2797 |
% |
| 2798 |
% Now look at the generalized problem: Let |
| 2799 |
% $k\in\{1,\ldots,10\}$ be given. Find the minimal number |
| 2800 |
% $m\in\{1,\ldots,10\}$ such that there is a sequence |
| 2801 |
% $n,{n+1},\ldots,\allowbreak{n+m-1}$ of $m$ |
| 2802 |
% $k$-digit figures which contains each digit |
| 2803 |
% $\{0,\ldots,9\}$. Prove that the number is minimal. How many |
| 2804 |
% minimal sequences do exist? |
| 2805 |
% |
| 2806 |
% If you solve this problem with a computer, write a \TeX\ program! |
| 2807 |
% \end{advise} |
| 2808 |
% |
| 2809 |
% |
| 2810 |
% \subsubsection{Captions} |
| 2811 |
% |
| 2812 |
% In despite of \LaTeX\ standard behaviour, captions and floats are independent |
| 2813 |
% from each other here; you can use captions with non-floating listings. |
| 2814 |
% \begin{syntax} |
| 2815 |
% \item[0.21] \rkeyname{title}|=|\meta{title text} |
| 2816 |
% |
| 2817 |
% is used for a title without any numbering or label. |
| 2818 |
% |
| 2819 |
% \item[0.20] \rkeyname{caption}|={|\oarg{short}\meta{caption text}|}| |
| 2820 |
% |
| 2821 |
% The caption is made of \cs{lstlistingname} followed by a running |
| 2822 |
% number, a separator, and \meta{caption text}. Either the caption text |
| 2823 |
% or, if present, \meta{short} will be used for the list of listings. |
| 2824 |
% |
| 2825 |
% \item[0.21] \rkeyname{label}|=|\meta{name} |
| 2826 |
% |
| 2827 |
% makes a listing referable via |\ref|\marg{name}. |
| 2828 |
% |
| 2829 |
% \item[0.16] \rcmdname\lstlistoflistings |
| 2830 |
% |
| 2831 |
% prints a list of listings. Each entry is with descending priority |
| 2832 |
% either the short caption, the caption, the file name, or the name of |
| 2833 |
% the listing, see also the key \keyname{name} in section |
| 2834 |
% \ref{rLineNumbers}. From version v1.10 of this package on the list of |
| 2835 |
% listings can be prepared by means of the \packagename{tocbasic} package |
| 2836 |
% \cite[Chapter 15]{Kohm:scrguide}, for more information have a look at |
| 2837 |
% page \pageref{sec:tocbasic}. |
| 2838 |
% |
| 2839 |
% \item[1.0] \rkeyname{nolol}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{nolol} |
| 2840 |
% |
| 2841 |
% If true, the listing does not make it into the list of listings. |
| 2842 |
% |
| 2843 |
% \item[0.16,Listings,data] \rcmdname\lstlistlistingname |
| 2844 |
% |
| 2845 |
% The header name for the list of listings. |
| 2846 |
% |
| 2847 |
% \item[0.20,Listing,data] \rcmdname\lstlistingname |
| 2848 |
% |
| 2849 |
% The caption label for listings. |
| 2850 |
% |
| 2851 |
% \item[,{{}},data] \rcmdname\lstlistingnamestyle |
| 2852 |
% |
| 2853 |
% customizes the style of the caption label for program listings in a |
| 2854 |
% simple way, something like |\small|, |\bfseries| or a combination |
| 2855 |
% of several commands. If there is a need for a complete |
| 2856 |
% customization of the label (justification, fonts, margins, \ldots), |
| 2857 |
% one should use the \packagename{caption} package by A.~Sommerfeldt |
| 2858 |
% \cite{Sommerfeldt:caption}. |
| 2859 |
% |
| 2860 |
% \item[0.20,\arabic{lstlisting},data] \rcmdname\thelstlisting |
| 2861 |
% |
| 2862 |
% prints the running number of the caption. |
| 2863 |
% |
| 2864 |
% \item[1.4,true] \rkeyname{numberbychapter}|=|\meta{\alternative{true,false}} |
| 2865 |
% |
| 2866 |
% If true, and |\thechapter| exists, listings are numbered by chapter. |
| 2867 |
% Otherwise, they are numbered sequentially from the beginning of the |
| 2868 |
% document. This key can only be used before |\begin{document}|. |
| 2869 |
% |
| 2870 |
% \item[0.19] \rcmdname\lstname |
| 2871 |
% |
| 2872 |
% prints the name of the current listing which is either the file name or |
| 2873 |
% the name defined by the \keyname{name} key. This command can be used to |
| 2874 |
% define a caption or title template, for example by |
| 2875 |
% |\lstset{caption=\lstname}|. |
| 2876 |
% |
| 2877 |
% \item[0.20,t] \rkeyname{captionpos}|=|\meta{subset of \textup{\texttt{tb}}} |
| 2878 |
% |
| 2879 |
% specifies the positions of the caption: top and/or bottom of the |
| 2880 |
% listing. |
| 2881 |
% |
| 2882 |
% \item[0.20,\smallskipamount] \rkeyname{abovecaptionskip}|=|\meta{dimension} |
| 2883 |
% \item[0.20,\smallskipamount] \rkeyname{belowcaptionskip}|=|\meta{dimension} |
| 2884 |
% |
| 2885 |
% is the vertical space respectively above or below each caption. |
| 2886 |
% \end{syntax} |
| 2887 |
% |
| 2888 |
% |
| 2889 |
% \subsubsection{Margins and line shape}\label{rMarginsAndLineShape} |
| 2890 |
% |
| 2891 |
% \begin{syntax} |
| 2892 |
% \item[0.21,\linewidth] \rkeyname{linewidth}|=|\meta{dimension} |
| 2893 |
% |
| 2894 |
% defines the base line width for listings. The following three keys |
| 2895 |
% are taken into account additionally. |
| 2896 |
% |
| 2897 |
% \item[0.19,0pt] \rkeyname{xleftmargin}|=|\meta{dimension} |
| 2898 |
% \item[1.0,0pt] \rkeyname{xrightmargin}|=|\meta{dimension} |
| 2899 |
% |
| 2900 |
% The dimensions are used as extra margins on the left and right. Line |
| 2901 |
% numbers and frames are both moved accordingly. |
| 2902 |
% |
| 2903 |
% \item[0.19,false] |
| 2904 |
% \rkeyname{resetmargins}|=|\meta{\alternative{true,false}} |
| 2905 |
% |
| 2906 |
% If true, indention from list environments like \texttt{enumerate} or |
| 2907 |
% \texttt{itemize} is reset, i.e.~not used. |
| 2908 |
% |
| 2909 |
% \item[0.20,false] |
| 2910 |
% \rkeyname{breaklines}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{breaklines} |
| 2911 |
% |
| 2912 |
% activates or deactivates automatic line breaking of long lines. |
| 2913 |
% |
| 2914 |
% \item[1.2,false] |
| 2915 |
% \rkeyname{breakatwhitespace}|=|\meta{\alternative{true,false}}^^A |
| 2916 |
% \syntaxor\rkeyname{breakatwhitespace}\label{uoption:breakatwhitespace} |
| 2917 |
% |
| 2918 |
% If true, it allows line breaks only at white space. |
| 2919 |
% |
| 2920 |
% \item[0.20,{{}}] \rkeyname{prebreak}|=|\meta{tokens} |
| 2921 |
% \item[0.20,{{}}] \rkeyname{postbreak}|=|\meta{tokens} |
| 2922 |
% |
| 2923 |
% \meta{tokens} appear at the end of the current line respectively at |
| 2924 |
% the beginning of the next (broken part of the) line. |
| 2925 |
% |
| 2926 |
% You must not use dynamic space (in particular spaces) since |
| 2927 |
% internally we use |\discretionary|. However |\space| is redefined to |
| 2928 |
% be used inside \meta{tokens}. |
| 2929 |
% |
| 2930 |
% \item[0.20,20pt] \rkeyname{breakindent}|=|\meta{dimension} |
| 2931 |
% |
| 2932 |
% is the indention of the second, third, \ldots\ line of broken lines. |
| 2933 |
% |
| 2934 |
% \item[0.20,true] |
| 2935 |
% \rkeyname{breakautoindent}|=|\meta{\alternative{true,false}}^^A |
| 2936 |
% \syntaxor\rkeyname{breakautoindent} |
| 2937 |
% |
| 2938 |
% activates or deactivates automatic indention of broken lines. This |
| 2939 |
% indention is used additionally to \ikeyname{breakindent}, see the |
| 2940 |
% example below. Visible spaces or visible tabulators might set this |
| 2941 |
% auto indention to zero. |
| 2942 |
% \end{syntax} |
| 2943 |
% In the following example we use tabulators to create long lines, but the |
| 2944 |
% verbatim part uses |tabsize=1|. |
| 2945 |
% \begin{lstxsample} |
| 2946 |
% \lstset{postbreak=\space, breakindent=5pt, breaklines} |
| 2947 |
% \end{lstxsample} |
| 2948 |
% \begin{lstsample}{\lstset{string=[d]",tabsize=6}}{\lstset{tabsize=1}\hfuzz=1in} |
| 2949 |
% \begin{lstlisting} |
| 2950 |
% "A long string is broken!" |
| 2951 |
% "Another long line." |
| 2952 |
% \end{lstlisting} |
| 2953 |
% |
| 2954 |
% \begin{lstlisting}[breakautoindent |
| 2955 |
% =false] |
| 2956 |
% { Now auto indention is off. } |
| 2957 |
% \end{lstlisting} |
| 2958 |
% \end{lstsample} |
| 2959 |
% |
| 2960 |
% |
| 2961 |
% \subsubsection{Frames}\label{rFrames} |
| 2962 |
% |
| 2963 |
% \begin{syntax} |
| 2964 |
% \item[1.0,none] |
| 2965 |
% \rkeyname{frame}|=|\meta{\alternative{none,leftline,topline,bottomline,^^A |
| 2966 |
% lines,single,shadowbox}} |
| 2967 |
% |
| 2968 |
% draws either no frame, a single line on the left, at the top, at the |
| 2969 |
% bottom, at the top and bottom, a whole single frame, or a shadowbox. |
| 2970 |
% |
| 2971 |
% Note that \packagename{fancyvrb} supports the same frame types except |
| 2972 |
% \texttt{shadowbox}. The shadow color is \keyname{rulesepcolor}, see |
| 2973 |
% below. |
| 2974 |
% |
| 2975 |
% \item[0.19,{{}}] \rkeyname{frame}|=|\meta{subset of |
| 2976 |
% \textup{\texttt{trblTRBL}}} |
| 2977 |
% |
| 2978 |
% The characters \texttt{trblTRBL} designate lines at the top and |
| 2979 |
% bottom of a listing and to lines on the right and left. Upper case |
| 2980 |
% characters are used to draw double rules. So |frame=tlrb| draws a |
| 2981 |
% single frame and |frame=TL| double lines at the top and on the left. |
| 2982 |
% |
| 2983 |
% Note that frames usually reside outside the listing's space. |
| 2984 |
% |
| 2985 |
% \item[0.20,ffff] |
| 2986 |
% \rkeyname{frameround}|=|\meta{\alternative{t,f}}\meta{\alternative{t,f}}^^A |
| 2987 |
% \meta{\alternative{t,f}}\meta{\alternative{t,f}} |
| 2988 |
% |
| 2989 |
% The four letters designate the top right, bottom right, bottom left |
| 2990 |
% and top left corner. In this order. \texttt{t} makes the according |
| 2991 |
% corner round. If you use round corners, the rule width is controlled |
| 2992 |
% via |\thinlines| and |\thicklines|. |
| 2993 |
% |
| 2994 |
% Note: The size of the quarter circles depends on \keyname{framesep} |
| 2995 |
% and is independent of the extra margins of a frame. The size is |
| 2996 |
% possibly adjusted to fit \LaTeX's circle sizes. |
| 2997 |
% |
| 2998 |
% \item[0.19,3pt] \rkeyname{framesep}|=|\meta{dimension} |
| 2999 |
% \item[0.19,2pt] \rkeyname{rulesep}|=|\meta{dimension} |
| 3000 |
% |
| 3001 |
% control the space between frame and listing and between double rules. |
| 3002 |
% |
| 3003 |
% \item[0.19,0.4pt] \rkeyname{framerule}|=|\meta{dimension} |
| 3004 |
% |
| 3005 |
% controls the width of the rules. |
| 3006 |
% |
| 3007 |
% \item[1.0,0pt] \rkeyname{framexleftmargin}|=|\meta{dimension} |
| 3008 |
% \item[1.0,0pt] \rkeyname{framexrightmargin}|=|\meta{dimension} |
| 3009 |
% \item[1.0,0pt] \rkeyname{framextopmargin}|=|\meta{dimension} |
| 3010 |
% \item[1.0,0pt] \rkeyname{framexbottommargin}|=|\meta{dimension} |
| 3011 |
% |
| 3012 |
% are the dimensions which are used additionally to \keyname{framesep} |
| 3013 |
% to make up the margin of a frame. |
| 3014 |
% |
| 3015 |
% \item[0.21] \rkeyname{backgroundcolor}|=|\meta{color command} |
| 3016 |
% \item[0.21] \rkeyname{rulecolor}|=|\meta{color command} |
| 3017 |
% \item[1.0] \rkeyname{fillcolor}|=|\meta{color command} |
| 3018 |
% \item[1.0] \rkeyname{rulesepcolor}|=|\meta{color command} |
| 3019 |
% |
| 3020 |
% specify the colour of the background, the rules, the space between |
| 3021 |
% `text box' and first rule, and of the space between two rules, |
| 3022 |
% respectively. Note that the value requires a |\color| command, for |
| 3023 |
% example \keyname{rulecolor}|=\color{blue}|. |
| 3024 |
% \end{syntax} |
| 3025 |
% \ikeyname{frame} does not work with |fancyvrb=true| or when the package |
| 3026 |
% internally makes a |\hbox| around the listing! And there are certainly more |
| 3027 |
% problems with other commands; please take the time to make a (bug) report. |
| 3028 |
%\ifcolor |
| 3029 |
% \begin{lstxsample} |
| 3030 |
% \lstset{framexleftmargin=5mm, frame=shadowbox, rulesepcolor=\color{blue}} |
| 3031 |
% \end{lstxsample} |
| 3032 |
%\else |
| 3033 |
% \lstset{framexleftmargin=5mm, frame=shadowbox} |
| 3034 |
%\fi |
| 3035 |
% \begin{lstsample}{}{} |
| 3036 |
% \begin{lstlisting}[numbers=left] |
| 3037 |
% for i:=maxint to 0 do |
| 3038 |
% begin |
| 3039 |
% { do nothing } |
| 3040 |
% end; |
| 3041 |
% \end{lstlisting} |
| 3042 |
% \end{lstsample} |
| 3043 |
% |
| 3044 |
% Note here the use of |framexleftmargin| to include the line numbers inside |
| 3045 |
% the frame. |
| 3046 |
% |
| 3047 |
% Do you want exotic frames? Try the following key if you want, for example, |
| 3048 |
% \begin{lstsample}{\lstset{frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}}}{} |
| 3049 |
% \begin{lstlisting} |
| 3050 |
% for i:=maxint to 0 do |
| 3051 |
% begin |
| 3052 |
% { do nothing } |
| 3053 |
% end; |
| 3054 |
% \end{lstlisting} |
| 3055 |
% \end{lstsample} |
| 3056 |
% \begin{syntax} |
| 3057 |
% \item[0.20,,\dag] \rkeyname{frameshape}|=|\marg{top shape}\marg{left |
| 3058 |
% shape}\marg{right shape}\marg{bottom shape} |
| 3059 |
% |
| 3060 |
% gives you full control over the drawn frame parts. The arguments are |
| 3061 |
% not case sensitive. |
| 3062 |
% |
| 3063 |
% Both \meta{left shape} and \meta{right shape} are `left-to-right' |
| 3064 |
% \alternative{y,n} character sequences (or empty). Each |y| lets the |
| 3065 |
% package draw a rule, otherwise the rule is blank. These vertical |
| 3066 |
% rules are drawn `left-to-right' according to the specified shapes. |
| 3067 |
% The example above uses |yny|. |
| 3068 |
% |
| 3069 |
% \meta{top shape} and \meta{bottom shape} are `left-rule-right' |
| 3070 |
% sequences (or empty). The first `left-rule-right' sequence is |
| 3071 |
% attached to the most inner rule, the second to the next, and so on. |
| 3072 |
% Each sequence has three characters: `rule' is either |y| or |n|; |
| 3073 |
% `left' and `right' are |y|, |n| or |r| (which makes a corner round). |
| 3074 |
% The example uses |RYRYNYYYY| for both shapes: |RYR| describes the |
| 3075 |
% most inner (top and bottom) frame shape, |YNY| the middle, and |YYY| |
| 3076 |
% the most outer. |
| 3077 |
% \end{syntax} |
| 3078 |
% To summarize, the example above used |
| 3079 |
% \begin{verbatim} |
| 3080 |
% \lstset{frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}}\end{verbatim} |
| 3081 |
% Note that you are not resticted to two or three levels. |
| 3082 |
% However you'll get in trouble if you use round corners when they are too big. |
| 3083 |
% |
| 3084 |
% |
| 3085 |
% \subsubsection{Indexing} |
| 3086 |
% |
| 3087 |
% \begin{syntax} |
| 3088 |
% \item[0.19] \rkeyname{index}|=|\oarg{number}\oarg{keyword |
| 3089 |
% classes}\marg{identifiers} |
| 3090 |
% \item[0.21] \rkeyname{moreindex}|=|\oarg{number}\oarg{keyword |
| 3091 |
% classes}\marg{identifiers} |
| 3092 |
% \item[0.21] \rkeyname{deleteindex}|=|\oarg{number}\oarg{keyword |
| 3093 |
% classes}\marg{identifiers} |
| 3094 |
% |
| 3095 |
% define, add and remove \meta{identifiers} and \meta{keyword classes} |
| 3096 |
% from the index class list \meta{number}. If you don't specify the |
| 3097 |
% optional number, the package assumes \meta{number} $=1$. |
| 3098 |
% |
| 3099 |
% Each appearance of the explicitly given identifiers and each |
| 3100 |
% appearance of the identifiers of the specified \meta{keyword classes} |
| 3101 |
% is indexed. For example, you could write |index=[1][keywords]| to |
| 3102 |
% index all keywords. Note that |[1]| is required here---otherwise we |
| 3103 |
% couldn't use the second optional argument. |
| 3104 |
% |
| 3105 |
% \item[0.19,\lstindexmacro] |
| 3106 |
% \rkeyname{indexstyle}|=|\oarg{number}\meta{tokens |
| 3107 |
% \textup(one-parameter command\textup)} |
| 3108 |
% |
| 3109 |
% \meta{tokens} actually indexes the identifiers for the list |
| 3110 |
% \meta{number}. In contrast to the style keys, \meta{tokens} |
| 3111 |
% \emph{must} read exactly one parameter, namely the identifier. |
| 3112 |
% Default definition is\icmdname{\lstindexmacro}\vspace*{-\itemsep} |
| 3113 |
% \begin{verbatim} |
| 3114 |
% \newcommand\lstindexmacro[1]{\index{{\ttfamily#1}}}\end{verbatim} |
| 3115 |
% \vspace*{-\itemsep}which you shouldn't modify. |
| 3116 |
% Define your own indexing commands and use them as argument to this key. |
| 3117 |
% \end{syntax} |
| 3118 |
% Section \ref{uIndexing} describes this feature in detail. |
| 3119 |
% |
| 3120 |
% |
| 3121 |
% \subsubsection{Column alignment}\label{rColumnAlignment} |
| 3122 |
% |
| 3123 |
% \begin{syntax} |
| 3124 |
% \item[1.0,{[c]fixed}] |
| 3125 |
% \rkeyname{columns}|=|\oarg{\alternative{c,l,r}}\meta{alignment} |
| 3126 |
% |
| 3127 |
% selects the column alignment. The \meta{alignment} can be |fixed|, |
| 3128 |
% |flexible|, |spaceflexible|, or |fullflexible|; see section |
| 3129 |
% \ref{uFixedAndFlexibleColumns} for details. |
| 3130 |
% |
| 3131 |
% The optional |c|, |l|, or |r| controls the horizontal orientation of |
| 3132 |
% smallest output units (keywords, identifiers, etc.). The arguments |
| 3133 |
% work as follows, where vertical bars visualize the effect: |
| 3134 |
% $\vert$\lstinline[columns={[c]fixed}]!listing!$\vert$, |
| 3135 |
% $\vert$\lstinline[columns={[l]fixed}]!listing!$\vert$, and |
| 3136 |
% $\vert$\lstinline[columns={[r]fixed}]!listing!$\vert$ in fixed column |
| 3137 |
% mode, |
| 3138 |
% $\vert$\lstinline[columns={[c]flexible}]!listing!$\vert$, |
| 3139 |
% $\vert$\lstinline[columns={[l]flexible}]!listing!$\vert$, and |
| 3140 |
% $\vert$\lstinline[columns={[r]flexible}]!listing!$\vert$ with |
| 3141 |
% flexible columns, and |
| 3142 |
% $\vert$\lstinline[columns={[c]fullflexible}]!listing!$\vert$, |
| 3143 |
% $\vert$\lstinline[columns={[l]fullflexible}]!listing!$\vert$, and |
| 3144 |
% $\vert$\lstinline[columns={[r]fullflexible}]!listing!$\vert$ with |
| 3145 |
% space-flexible or full flexible columns (which ignore the optional |
| 3146 |
% argument, since they do not add extra space around printable |
| 3147 |
% characters). |
| 3148 |
% |
| 3149 |
% \item[0.18,false] |
| 3150 |
% \rkeyname{flexiblecolumns}|=|\meta{\alternative{true,false}}^^A |
| 3151 |
% \syntaxor\rkeyname{flexiblecolumns} |
| 3152 |
% |
| 3153 |
% selects the most recently selected flexible or fixed column format, |
| 3154 |
% refer to section \ref{uFixedAndFlexibleColumns}. |
| 3155 |
% |
| 3156 |
% \item[0.21,false,\dag] |
| 3157 |
% \rkeyname{keepspaces}|=|\meta{\alternative{true,false}} |
| 3158 |
% |
| 3159 |
% |keepspaces=true| tells the package not to drop spaces to fix column |
| 3160 |
% alignment and always converts tabulators to spaces. |
| 3161 |
% |
| 3162 |
% \item[0.16] \rkeyname{basewidth}|=|\meta{dimension}\syntaxor |
| 3163 |
% \item[0.18,{{0.6em,0.45em}}] |
| 3164 |
% \rkeyname{basewidth}|={|\meta{fixed}|,|\meta{flexible mode}|}| |
| 3165 |
% |
| 3166 |
% sets the width of a single character box for fixed and flexible |
| 3167 |
% column mode (both to the same value or individually). |
| 3168 |
% |
| 3169 |
% \item[0.20,false] |
| 3170 |
% \rkeyname{fontadjust}|=|\meta{\alternative{true,false}}^^A |
| 3171 |
% \syntaxor\rkeyname{fontadjust} |
| 3172 |
% |
| 3173 |
% If true the package adjusts the base width every font selection. |
| 3174 |
% This makes sense only if \ikeyname{basewidth} is given in font |
| 3175 |
% specific units like `em' or `ex'---otherwise this boolean has no |
| 3176 |
% effect. |
| 3177 |
% |
| 3178 |
% After loading the package, it doesn't adjust the width every font |
| 3179 |
% selection: it looks at \ikeyname{basewidth} each listing and uses the |
| 3180 |
% value for the whole listing. This is possibly inadequate if the style |
| 3181 |
% keys in section \ref{rFigureOutTheAppearance} make heavy font size |
| 3182 |
% changes, see the example below. |
| 3183 |
% |
| 3184 |
% Note that this key might disturb the column alignment and might have |
| 3185 |
% an effect on the keywords' appearance! |
| 3186 |
% \end{syntax} |
| 3187 |
% \begin{lstsample}{\lstset{basicstyle=\normalsize}}{} |
| 3188 |
% \lstset{commentstyle=\scriptsize} |
| 3189 |
% \begin{lstlisting} |
| 3190 |
% { scriptsize font |
| 3191 |
% doesn't look good } |
| 3192 |
% for i:=maxint to 0 do |
| 3193 |
% begin |
| 3194 |
% { do nothing } |
| 3195 |
% end; |
| 3196 |
% \end{lstlisting} |
| 3197 |
% \end{lstsample} |
| 3198 |
% \begin{lstsample}{\lstset{basicstyle=\normalsize,commentstyle=\scriptsize}}{} |
| 3199 |
% \begin{lstlisting}[fontadjust] |
| 3200 |
% { scriptsize font |
| 3201 |
% looks better now } |
| 3202 |
% for i:=maxint to 0 do |
| 3203 |
% begin |
| 3204 |
% { do nothing } |
| 3205 |
% end; |
| 3206 |
% \end{lstlisting} |
| 3207 |
% \end{lstsample} |
| 3208 |
% |
| 3209 |
% |
| 3210 |
% \subsubsection{Escaping to \LaTeX}\label{rEscapingToLaTeX} |
| 3211 |
% |
| 3212 |
% \textbf{Note:} {\itshape Any escape to \LaTeX\ may disturb the column |
| 3213 |
% alignment since the package can't control the spacing there.} |
| 3214 |
% \begin{syntax} |
| 3215 |
% \item[0.18,false] \rkeyname{texcl}|=|\meta{\alternative{true,false}}\syntaxor\rkeyname{texcl} |
| 3216 |
% |
| 3217 |
% activates or deactivates \LaTeX\ comment lines. If activated, comment |
| 3218 |
% line delimiters are printed as usual, but the comment line text (up to |
| 3219 |
% the end of line) is read as \LaTeX\ code and typeset in comment style. |
| 3220 |
% \end{syntax} |
| 3221 |
% The example uses \Cpp\ comment lines (but doesn't say how to define them). |
| 3222 |
% Without |\upshape| we would get \textit{calculate} since the comment style |
| 3223 |
% is |\itshape|. |
| 3224 |
% \begin{lstsample}{\lstset{morecomment=[l]//}}{} |
| 3225 |
% \begin{lstlisting}[texcl] |
| 3226 |
% // \upshape calculate $a_{ij}$ |
| 3227 |
% A[i][j] = A[j][j]/A[i][j]; |
| 3228 |
% \end{lstlisting} |
| 3229 |
% \end{lstsample} |
| 3230 |
% |
| 3231 |
% \begin{syntax} |
| 3232 |
% \item[0.19,false] |
| 3233 |
% \rkeyname{mathescape}|=|\meta{\alternative{true,false}} |
| 3234 |
% |
| 3235 |
% activates or deactivates special behaviour of the dollar sign. If |
| 3236 |
% activated a dollar sign acts as \TeX's text math shift. |
| 3237 |
% |
| 3238 |
% This key is useful if you want to typeset formulas in listings. |
| 3239 |
% |
| 3240 |
% \item[0.19,{{}}] |
| 3241 |
% \rkeyname{escapechar}|=|\meta{character}\syntaxor\rkeyname{escapechar}|={}| |
| 3242 |
% |
| 3243 |
% If not empty the given character escapes the user to \LaTeX: all code |
| 3244 |
% between two such characters is interpreted as \LaTeX\ code. Note that |
| 3245 |
% \TeX's special characters must be entered with a preceding backslash, |
| 3246 |
% e.g.~|escapechar=\%|. |
| 3247 |
% |
| 3248 |
% \item[0.20,{{}}] |
| 3249 |
% \rkeyname{escapeinside}|=|\meta{character}\meta{character}^^A |
| 3250 |
% \syntaxor\rkeyname{escapeinside}|={}| |
| 3251 |
% |
| 3252 |
% Is a generalization of \ikeyname{escapechar}. If the value is not |
| 3253 |
% empty, the package escapes to \LaTeX\ between the first and second |
| 3254 |
% character. |
| 3255 |
% |
| 3256 |
% \item[0.20,{{}}] \rkeyname{escapebegin}|=|\meta{tokens} |
| 3257 |
% \item[0.20,{{}}] \rkeyname{escapeend}|=|\meta{tokens} |
| 3258 |
% |
| 3259 |
% The tokens are executed at the beginning respectively at the end of |
| 3260 |
% each escape, in particular for \ikeyname{texcl}. See section |
| 3261 |
% \ref{uNationalCharacters} for an application. |
| 3262 |
% \end{syntax} |
| 3263 |
% |
| 3264 |
% \begin{lstsample}{\lstset{morecomment=[l]//}}{} |
| 3265 |
% \begin{lstlisting}[mathescape] |
| 3266 |
% // calculate $a_{ij}$ |
| 3267 |
% $a_{ij} = a_{jj}/a_{ij}$; |
| 3268 |
% \end{lstlisting} |
| 3269 |
% \end{lstsample} |
| 3270 |
% |
| 3271 |
% \begin{lstsample}{\lstset{morecomment=[l]//}}{} |
| 3272 |
% \begin{lstlisting}[escapechar=\%] |
| 3273 |
% // calc%ulate $a_{ij}$% |
| 3274 |
% %$a_{ij} = a_{jj}/a_{ij}$%; |
| 3275 |
% \end{lstlisting} |
| 3276 |
% \end{lstsample} |
| 3277 |
% |
| 3278 |
% \begin{lstsample}{\lstset{morecomment=[l]//}}{} |
| 3279 |
% \lstset{escapeinside=`'} |
| 3280 |
% \begin{lstlisting} |
| 3281 |
% // calc`ulate $a_{ij}$' |
| 3282 |
% `$a_{ij} = a_{jj}/a_{ij}$'; |
| 3283 |
% \end{lstlisting} |
| 3284 |
% \end{lstsample} |
| 3285 |
% In the first example the comment line up to $a_{ij}$ has been typeset by the |
| 3286 |
% \packagename{listings} package in comment style. The $a_{ij}$ itself is |
| 3287 |
% typeset in `\TeX\ math mode' without comment style. About half of the |
| 3288 |
% comment line of the second example has been typeset by this package, and |
| 3289 |
% the rest is in `\LaTeX\ mode'. |
| 3290 |
% |
| 3291 |
% To avoid problems with the current and future version of this package: |
| 3292 |
% \begin{enumerate} |
| 3293 |
% \item Don't use any commands of the \packagename{listings} package when you |
| 3294 |
% have escaped to \LaTeX. |
| 3295 |
% \item Any environment must start and end inside the same escape. |
| 3296 |
% \item You might use |\def|, |\edef|, etc., but do not assume that the |
| 3297 |
% definitions are present later, unless they are |\global|. |
| 3298 |
% \item |\if \else \fi|, groups, math shifts |$| and |$$|, \ldots\ must be |
| 3299 |
% balanced within each escape. |
| 3300 |
% \item \ldots |
| 3301 |
% \end{enumerate} |
| 3302 |
% Expand that list yourself and mail me about new items. |
| 3303 |
% |
| 3304 |
% |
| 3305 |
% \subsection{Interface to \packagename{fancyvrb}} |
| 3306 |
% |
| 3307 |
% The \packagename{fancyvrb} package---fancy verbatims---from Timothy van Zandt |
| 3308 |
% provides macros for reading, writing and typesetting verbatim code. It has |
| 3309 |
% some remarkable features the \packagename{listings} package doesn't have. |
| 3310 |
% (Some are possible, but you must find somebody who will implement them |;-)|. |
| 3311 |
% \begin{syntax} |
| 3312 |
% \item[0.19] \rkeyname{fancyvrb}|=|\meta{\alternative{true,false}} |
| 3313 |
% |
| 3314 |
% activates or deactivates the interface. If active, verbatim code is |
| 3315 |
% read by \packagename{fancyvrb} but typeset by \packagename{listings}, |
| 3316 |
% i.e.~with emphasized keywords, strings, comments, and so on. |
| 3317 |
% Internally we use a very special definition of |
| 3318 |
% |\FancyVerbFormatLine|. |
| 3319 |
% |
| 3320 |
% This interface works with |Verbatim|, |BVerbatim| and |LVerbatim|. |
| 3321 |
% But you shouldn't use \packagename{fancyvrb}'s |
| 3322 |
% \keyname{defineactive}. (As far as I can see it doesn't matter since |
| 3323 |
% it does nothing at all, but for safety \ldots .) If |
| 3324 |
% \packagename{fancyvrb} and \packagename{listings} provide similar |
| 3325 |
% functionality, you should use \packagename{fancyvrb}'s. |
| 3326 |
% |
| 3327 |
% \item[1.1,{\overlay 1}] |
| 3328 |
% \rkeyname{fvcmdparams}|=|\meta{command$_1$}\meta{number$_1$}^^A |
| 3329 |
% \ldots\label{uoption:fvcmdparams} |
| 3330 |
% \item[1.1] |
| 3331 |
% \rkeyname{morefvcmdparams}|=|\meta{command$_1$}\meta{number$_1$}^^A |
| 3332 |
% \ldots\label{uoption:morefvcmdparams} |
| 3333 |
% |
| 3334 |
% If you use \packagename{fancyvrb}'s \keyname{commandchars}, you must |
| 3335 |
% tell the \packagename{listings} package how many arguments each |
| 3336 |
% command takes. If a command takes no arguments, there is nothing to |
| 3337 |
% do. |
| 3338 |
% |
| 3339 |
% The first (third, fifth, \ldots) parameter to the keys is the command |
| 3340 |
% and the second (fourth, sixth, \ldots) is the number of arguments |
| 3341 |
% that command takes. So, if you want to use |\textcolor{red}{keyword}| |
| 3342 |
% with the \packagename{fancyvrb}-\packagename{listings} interface, you |
| 3343 |
% should write |\lstset{morefvcmdparams=\textcolor 2}|. |
| 3344 |
% \end{syntax} |
| 3345 |
% |
| 3346 |
% \iffancyvrb |
| 3347 |
% \begin{lstsample}{}{} |
| 3348 |
% \lstset{morecomment=[l]\ }% :-) |
| 3349 |
% \fvset{commandchars=\\\{\}} |
| 3350 |
% |
| 3351 |
% \begin{BVerbatim} |
| 3352 |
% First verbatim line. |
| 3353 |
% \fbox{Second} verbatim line. |
| 3354 |
% \end{BVerbatim} |
| 3355 |
% |
| 3356 |
% \par\vspace{72.27pt} |
| 3357 |
% |
| 3358 |
% \lstset{fancyvrb} |
| 3359 |
% \begin{BVerbatim} |
| 3360 |
% First verbatim line. |
| 3361 |
% \fbox{Second} verbatim line. |
| 3362 |
% \end{BVerbatim} |
| 3363 |
% \lstset{fancyvrb=false} |
| 3364 |
% \end{lstsample} |
| 3365 |
% The lines typeset by the \packagename{listings} package are wider since the |
| 3366 |
% default \ikeyname{basewidth} doesn't equal the width of a single typewriter type |
| 3367 |
% character. Moreover, note that the first space begins a comment as defined at |
| 3368 |
% the beginning of the example. |
| 3369 |
% \else |
| 3370 |
% \begin{center} |
| 3371 |
% \packagename{fancyvrb} seems to be unavailable on your platform, thus the |
| 3372 |
% example couldn't be printed here. |
| 3373 |
% \end{center} |
| 3374 |
% \fi |
| 3375 |
% |
| 3376 |
% |
| 3377 |
% \subsection{Environments}\label{rEnvironments} |
| 3378 |
% |
| 3379 |
% If you want to define your own pretty-printing environments, try the |
| 3380 |
% following command. The syntax comes from \LaTeX's |\newenvironment|. |
| 3381 |
% \begin{syntax} |
| 3382 |
% \item[0.19] \rcmdname\lstnewenvironment\\ |
| 3383 |
% \marg{name}\oarg{number}\oarg{opt.~default~arg.}\\ |
| 3384 |
% |{|\meta{starting code}|}|\\ |
| 3385 |
% |{|\meta{ending code}|}| |
| 3386 |
% \end{syntax} |
| 3387 |
% As a simple example we could just select a particular language. |
| 3388 |
% \begin{lstxsample} |
| 3389 |
% \lstnewenvironment{pascal} |
| 3390 |
% {\lstset{language=pascal}} |
| 3391 |
% {} |
| 3392 |
% \end{lstxsample} |
| 3393 |
% \begin{lstsample}{}{} |
| 3394 |
% \begin{pascal} |
| 3395 |
% for i:=maxint to 0 do |
| 3396 |
% begin |
| 3397 |
% { do nothing } |
| 3398 |
% end; |
| 3399 |
% \end{pascal} |
| 3400 |
% \end{lstsample} |
| 3401 |
% Doing other things is as easy, for example, using more keys and adding an |
| 3402 |
% optional argument to adjust settings each listing: |
| 3403 |
% \begin{verbatim} |
| 3404 |
%\lstnewenvironment{pascalx}[1][] |
| 3405 |
% {\lstset{language=pascal,numbers=left,numberstyle=\tiny,float,#1}} |
| 3406 |
% {}\end{verbatim} |
| 3407 |
% |
| 3408 |
% |
| 3409 |
% \subsection{Short Inline Listing Commands}\label{rShortInline} |
| 3410 |
% |
| 3411 |
% Short equivalents of |\lstinline| can also be defined, in a manner similar |
| 3412 |
% to the short verbatim macros provided by \packagename{shortvrb}. |
| 3413 |
% |
| 3414 |
% \begin{syntax} |
| 3415 |
% \item[1.4] \rcmdname\lstMakeShortInline[\oarg{options}]\meta{character} |
| 3416 |
% |
| 3417 |
% defines \meta{character} to be an equivalent of |
| 3418 |
% |\lstinline|[\oarg{options}]\meta{character}, |
| 3419 |
% allowing for a convenient syntax when using lots of inline listings. |
| 3420 |
% |
| 3421 |
% \item[1.4] \rcmdname\lstDeleteShortInline\meta{character} |
| 3422 |
% |
| 3423 |
% removes a definition of \meta{character} created by |\lstMakeShortInline|, |
| 3424 |
% and returns \meta{character} to its previous meaning. |
| 3425 |
% \end{syntax} |
| 3426 |
% |
| 3427 |
% |
| 3428 |
% \subsection{Language definitions}\label{rLanguageDefinitions} |
| 3429 |
% |
| 3430 |
% You should first read section \ref{uLanguageDefinitions} for an introduction |
| 3431 |
% to language definitions. Otherwise you're probably unprepared for the full |
| 3432 |
% syntax of |\lstdefinelanguage|. |
| 3433 |
% \begin{syntax} |
| 3434 |
% \item[0.19] \rcmdname\lstdefinelanguage\syntaxnewline[\oarg{dialect}]^^A |
| 3435 |
% \marg{language}\syntaxnewline[\oarg{base dialect}^^A |
| 3436 |
% \marg{and base language}]\syntaxnewline\marg{key=value list}^^A |
| 3437 |
% \syntaxnewline[\oarg{list of required aspects ^^A |
| 3438 |
% \textup(keywordcomments,texcs,etc.\textup)}] |
| 3439 |
% |
| 3440 |
% defines the (given dialect of the) programming language \meta{language}. |
| 3441 |
% If the language definition is based on another definition, you must |
| 3442 |
% specify the whole \oarg{base dialect}\marg{and base language}. Note |
| 3443 |
% that an empty \meta{base dialect} uses the default dialect! |
| 3444 |
% |
| 3445 |
% The last optional argument should specify all required aspects. This is |
| 3446 |
% a delicate point since the aspects are described in the developer's |
| 3447 |
% guide. You might use existing languages as templates. For example, |
| 3448 |
% ANSI C uses \aspectname{keywords}, \aspectname{comments}, |
| 3449 |
% \aspectname{strings} and \aspectname{directives}. |
| 3450 |
% |
| 3451 |
% \icmdname{\lst@definelanguage} has the same syntax and is used to |
| 3452 |
% define languages in the driver files. |
| 3453 |
% |
| 3454 |
% \begin{advise} |
| 3455 |
% \item Where should I put my language definition? |
| 3456 |
% \advisespace |
| 3457 |
% If you need the language for one particular document, put it into |
| 3458 |
% the preamble of that document. Otherwise create the local file |
| 3459 |
% `\texttt{lstlang0.sty}' or add the definition to that file, but use |
| 3460 |
% `|\lst@definelanguage|' instead of `|\lstdefinelanguage|'. |
| 3461 |
% However, you might want to send the definition to the address in |
| 3462 |
% section \ref{uSoftwareLicense}. Then it will be included with the |
| 3463 |
% rest of the languages distributed with the package, and published under |
| 3464 |
% the \LaTeX\ Project Public License. |
| 3465 |
% \end{advise} |
| 3466 |
% |
| 3467 |
% \item[0.18] \rcmdname\lstalias\marg{alias}\marg{language} |
| 3468 |
% |
| 3469 |
% defines an alias for a programming language. Each \meta{alias} is |
| 3470 |
% redirected to the same dialect of \meta{language}. |
| 3471 |
% It's also possible to define an alias for one particular dialect only: |
| 3472 |
% |
| 3473 |
% \item[0.18] \rcmdname\lstalias\oarg{alias dialect}\marg{alias}\oarg{dialect}\marg{language} |
| 3474 |
% |
| 3475 |
% Here all four parameters are \emph{nonoptional} and an alias with empty |
| 3476 |
% \meta{dialect} will select the default dialect. Note that aliases |
| 3477 |
% cannot be chained: The two aliases `|\lstalias{foo1}{foo2}|' and |
| 3478 |
% `|\lstalias{foo2}{foo3}|' will \emph{not} redirect |foo1| to |foo3|. |
| 3479 |
% \end{syntax} |
| 3480 |
% All remaining keys in this section are intended for building language |
| 3481 |
% definitions. \emph{No other key should be used in such a definition!} |
| 3482 |
% |
| 3483 |
% |
| 3484 |
% \paragraph{Keywords} |
| 3485 |
% We begin with keyword building keys. Note: {\itshape If you want to enter |
| 3486 |
% {\upshape|\|, |{|, |}|, |%|, |#|} or {\upshape|&|} as (part of) an argument |
| 3487 |
% to the keywords below, you must do it with a preceding backslash!} |
| 3488 |
% \begin{syntax} |
| 3489 |
% \item[1.0,,{\dag bug}] \rkeyname{keywordsprefix}|=|\meta{prefix} |
| 3490 |
% |
| 3491 |
% All identifiers starting with \meta{prefix} will be printed as first |
| 3492 |
% order keywords. |
| 3493 |
% |
| 3494 |
% Bugs: Currently there are several limitations. (1) The prefix is |
| 3495 |
% always case sensitive. (2) Only one prefix can be defined at a time. |
| 3496 |
% (3) If used `standalone' outside a language definition, the key might |
| 3497 |
% work only after selecting a nonempty language (and switching back to |
| 3498 |
% the empty language if necessary). (4) The key does not respect the |
| 3499 |
% value of \keyname{classoffset} and has no optional class |
| 3500 |
% \meta{number} argument. |
| 3501 |
% |
| 3502 |
% \item[0.11] \rkeyname{keywords}|=|\oarg{number}\marg{list of keywords} |
| 3503 |
% \item[0.11] \rkeyname{morekeywords}|=|\oarg{number}\marg{list of |
| 3504 |
% keywords} |
| 3505 |
% \item[0.18] \rkeyname{deletekeywords}|=|\oarg{number}\marg{list of |
| 3506 |
% keywords} |
| 3507 |
% |
| 3508 |
% define, add to or remove the keywords from keyword list |
| 3509 |
% \meta{number}. The use of \keyname{keywords} is discouraged since it |
| 3510 |
% deletes all previously defined keywords in the list and is thus |
| 3511 |
% incompatible with the \keyname{alsolanguage} key. |
| 3512 |
% |
| 3513 |
% Please note the keys \ikeyname{alsoletter} and \ikeyname{alsodigit} |
| 3514 |
% below if you use unusual charaters in keywords. |
| 3515 |
% |
| 3516 |
% \item[0.19,,deprecated] \rkeyname{ndkeywords}|=|\marg{list of keywords} |
| 3517 |
% \item[0.19,,deprecated] \rkeyname{morendkeywords}|=|\marg{list of |
| 3518 |
% keywords} |
| 3519 |
% \item[0.19,,deprecated] \rkeyname{deletendkeywords}|=|\marg{list of |
| 3520 |
% keywords} |
| 3521 |
% |
| 3522 |
% define, add to or remove the keywords from keyword list 2; note that |
| 3523 |
% this is equivalent to |keywords=[2]|\ldots etc. The use of |
| 3524 |
% \keyname{ndkeywords} is strongly discouraged. |
| 3525 |
% |
| 3526 |
% \item[0.19,,{addon,optional}] \rkeyname{texcs}|=|\oarg{class |
| 3527 |
% number}\marg{list of control sequences \textup(without |
| 3528 |
% backslashes\textup)} |
| 3529 |
% \item[0.20,,{addon,optional}] \rkeyname{moretexcs}|=|\oarg{class |
| 3530 |
% number}\marg{list of control sequences \textup(without |
| 3531 |
% backslashes\textup)} |
| 3532 |
% \item[0.21,,{addon,optional}] \rkeyname{deletetexcs}|=|\oarg{class |
| 3533 |
% number}\marg{list of control sequences \textup(without |
| 3534 |
% backslashes\textup)} |
| 3535 |
% |
| 3536 |
% Ditto for control sequences in \TeX\ and \LaTeX. |
| 3537 |
% |
| 3538 |
% \item[0.18,,optional] \rkeyname{directives}|=|\marg{list of compiler |
| 3539 |
% directives} |
| 3540 |
% \item[0.21,,optional] \rkeyname{moredirectives}|=|\marg{list of |
| 3541 |
% compiler directives} |
| 3542 |
% \item[0.21,,optional] \rkeyname{deletedirectives}|=|\marg{list of |
| 3543 |
% compiler directives} |
| 3544 |
% |
| 3545 |
% defines compiler directives in C, \Cpp, Objective-C, and POV. |
| 3546 |
% |
| 3547 |
% \item[0.14] \rkeyname{sensitive}|=|\meta{\alternative{true,false}} |
| 3548 |
% |
| 3549 |
% makes the keywords, control sequences, and directives case sensitive |
| 3550 |
% and insensitive, respectively. This key affects the keywords, control |
| 3551 |
% sequences, and directives only when a listing is processed. In all |
| 3552 |
% other situations they are case sensitive, for example, |
| 3553 |
% |deletekeywords={save,Test}| removes `save' and `Test', but neither |
| 3554 |
% `SavE' nor `test'. |
| 3555 |
% |
| 3556 |
% \item[0.19] \rkeyname{alsoletter}|=|\marg{character sequence} |
| 3557 |
% \item[0.19] \rkeyname{alsodigit}|=|\marg{character sequence} |
| 3558 |
% \item[0.19] \rkeyname{alsoother}|=|\marg{character sequence} |
| 3559 |
% |
| 3560 |
% All identifiers (keywords, directives, and such) consist of a letter |
| 3561 |
% followed by alpha-numeric characters (letters and digits). For |
| 3562 |
% example, if you write |keywords={one-two,\#include}|, the minus sign |
| 3563 |
% must become a digit and the sharp a letter since the keywords can't |
| 3564 |
% be detected otherwise. |
| 3565 |
% |
| 3566 |
% Table \ref{rStdCharTable} show the standard configuration of the |
| 3567 |
% \packagename{listings} package. The three keys overwrite the default |
| 3568 |
% behaviour. Each character of the sequence becomes a letter, digit and |
| 3569 |
% other, respectively. |
| 3570 |
% |
| 3571 |
% \item[0.20] \rkeyname{otherkeywords}|=|\marg{keywords} |
| 3572 |
% |
| 3573 |
% Defines keywords that contain other characters, or start with digits. |
| 3574 |
% Each given `keyword' is printed in keyword style, but without |
| 3575 |
% changing the `letter', `digit' and `other' status of the |
| 3576 |
% characters. This key is designed to define keywords like |=>|, |->|, |
| 3577 |
% |-->|, |--|, |::|, and so on. If one keyword is a subsequence of |
| 3578 |
% another (like |--| and |-->|), you must specify the shorter first. |
| 3579 |
% |
| 3580 |
% \item[0.20,,{renamed,optional}] |
| 3581 |
% \rkeyname{tag}|=|\meta{character}\meta{character}^^A |
| 3582 |
% \syntaxor\rkeyname{tag}|={}|\label{uoption:tag} |
| 3583 |
% |
| 3584 |
% The first order keywords are active only between the first and second |
| 3585 |
% character. This key is used for HTML. |
| 3586 |
% \end{syntax} |
| 3587 |
% |
| 3588 |
% \begin{table}[tb] |
| 3589 |
% \caption{Standard character table}\label{rStdCharTable} |
| 3590 |
% \begin{tabular}{ll} |
| 3591 |
% class & characters\\ |
| 3592 |
% \noalign{\smallskip} |
| 3593 |
% letter & \texttt{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\\ |
| 3594 |
% & \texttt{a b c d e f g h i j k l m n o p q r s t u v w x y z}\\ |
| 3595 |
% & \texttt{@ \textdollar\ } |_|\\ |
| 3596 |
% digit & \texttt{0 1 2 3 4 5 6 7 8 9}\\ |
| 3597 |
% other & \texttt{!\ " \#\ \%\ \&\ ' ( ) * + , - .\ / :\ ; < = > ?}\\ |
| 3598 |
% & {\catcode`\|=12\texttt{[ \char92\ ] \textasciicircum\ \char123\ |
| 3599 |
% | \char125\ \textasciitilde}}\\ |
| 3600 |
% space & \texttt{chr(32)}\footnotemark{}\\ |
| 3601 |
% tabulator & \texttt{chr(9)}\\ |
| 3602 |
% form feed & \texttt{chr(12)}\\ |
| 3603 |
% \noalign{\smallskip} |
| 3604 |
% \end{tabular} |
| 3605 |
% \par\noindent |
| 3606 |
% Note: Extended characters of codes 128--255 (if defined) are \emph{currently} |
| 3607 |
% letters. |
| 3608 |
% \end{table} |
| 3609 |
% \footnotetext{Here and at other places |chr(|\meta{number}|)| means a |
| 3610 |
% Pascal function which returns the character which has ASCII value |
| 3611 |
% \meta{number}.} |
| 3612 |
% |
| 3613 |
% |
| 3614 |
% \paragraph{Strings}\label{uStrings} |
| 3615 |
% \begin{syntax} |
| 3616 |
% \item[0.12] |
| 3617 |
% \rkeyname{string}|=|\oarg{\alternative{b,d,m,bd,s}}\marg{delimiter |
| 3618 |
% \textup(character\textup)} |
| 3619 |
% \item[0.21] |
| 3620 |
% \rkeyname{morestring}|=|\oarg{\alternative{b,d,m,bd,s}}\marg{delimiter} |
| 3621 |
% \item[0.21] |
| 3622 |
% \rkeyname{deletestring}|=|\oarg{\alternative{b,d,m,bd,s}}\marg{delimiter} |
| 3623 |
% |
| 3624 |
% define, add to or delete the delimiter from the list of string |
| 3625 |
% delimiters. Starting and ending delimiters are the same, i.e.~in the |
| 3626 |
% source code the delimiters must match each other. |
| 3627 |
% |
| 3628 |
% The optional argument is the type and controls the how the delimiter |
| 3629 |
% itself is represented in a string or character literal: it is escaped |
| 3630 |
% by a |b|ackslash, |d|oubled (or both is allowed via |bd|). |
| 3631 |
% Alternately, the type can refer to an unusual form of delimiter: |
| 3632 |
% |s|tring delimiters (akin to the |s| comment type) or |m|atlab-style |
| 3633 |
% delimiters. The latter is a special type for Ada and Matlab and |
| 3634 |
% possibly other languages where the string delimiters are also used |
| 3635 |
% for other purposes. It is equivalent to |d|, except that a string |
| 3636 |
% does not start after a letter, a right parenthesis, a right bracket, |
| 3637 |
% or some other characters. |
| 3638 |
% \end{syntax} |
| 3639 |
% |
| 3640 |
% |
| 3641 |
% \paragraph{Comments} |
| 3642 |
% \begin{syntax} |
| 3643 |
% \item[0.13] |
| 3644 |
% \rkeyname{comment}|=|\oarg{type}\meta{delimiter\textup(s\textup)} |
| 3645 |
% \item[0.21] |
| 3646 |
% \rkeyname{morecomment}|=|\oarg{type}\meta{delimiter\textup(s\textup)} |
| 3647 |
% \item[0.21] |
| 3648 |
% \rkeyname{deletecomment}|=|\oarg{type}\meta{delimiter\textup(s\textup)} |
| 3649 |
% |
| 3650 |
% Ditto for comments, but some types require more than a single |
| 3651 |
% delimiter. The following overview uses \keyname{morecomment} as the |
| 3652 |
% example, but the examples apply to \keyname{comment} and |
| 3653 |
% \keyname{deletecomment} as well. |
| 3654 |
% |
| 3655 |
% \item[0.13] \rkeyname{morecomment}|=[l]|\meta{delimiter} |
| 3656 |
% |
| 3657 |
% The delimiter starts a comment line, which in general starts with the |
| 3658 |
% delimiter and ends at end of line. If the character sequence |//| |
| 3659 |
% should start a comment line (like in \Cpp, Comal 80 or Java), |
| 3660 |
% |morecomment=[l]//| is the correct declaration. For Matlab it would |
| 3661 |
% be |morecomment=[l]\%|---note the preceding backslash. |
| 3662 |
% |
| 3663 |
% \item[0.13] \rkeyname{morecomment}|=[s]|\marg{delimiter}\marg{delimiter} |
| 3664 |
% |
| 3665 |
% Here we have two delimiters. The second ends a comment starting with |
| 3666 |
% the first delimiter. If you require two such comments you can use |
| 3667 |
% this type twice. C, Java, PL/I, Prolog and SQL all define single |
| 3668 |
% comments via |morecomment=[s]{/*}{*/}|, and Algol does it with |
| 3669 |
% |morecomment=[s]{\#}{\#}|, which means that the sharp delimits both |
| 3670 |
% beginning and end of a single comment. |
| 3671 |
% |
| 3672 |
% \item[0.13] \rkeyname{morecomment}|=[n]|\marg{delimiter}\marg{delimiter} |
| 3673 |
% |
| 3674 |
% is similar to type |s|, but comments can be nested. Identical |
| 3675 |
% arguments are not allowed---think a while about it! Modula-2 and |
| 3676 |
% Oberon-2 use |morecomment=[n]{(*}{*)}|. |
| 3677 |
% |
| 3678 |
% \item[0.18] \rkeyname{morecomment}|=[f]|\meta{delimiter} |
| 3679 |
% \item[0.18] \rkeyname{morecomment}|=[f][commentstyle]|\oarg{n=preceding |
| 3680 |
% columns}\meta{delimiter} |
| 3681 |
% |
| 3682 |
% The delimiter starts a comment line if and only if it appears on a |
| 3683 |
% fixed column-number, namely if it is in column $n$ (zero based). |
| 3684 |
% |
| 3685 |
% \item[0.17,,optional] \rkeyname{keywordcomment}|=|\marg{keywords} |
| 3686 |
% \item[0.21,,optional] \rkeyname{morekeywordcomment}|=|\marg{keywords} |
| 3687 |
% \item[0.21,,optional] \rkeyname{deletekeywordcomment}|=|\marg{keywords} |
| 3688 |
% |
| 3689 |
% A keyword comment begins with a keyword and ends with the same |
| 3690 |
% keyword. Consider |keywordcomment={comment,co}|. Then |
| 3691 |
% `\textbf{comment}\allowbreak\ldots\textbf{comment}' and |
| 3692 |
% `\textbf{co}\ldots\textbf{co}' are comments. |
| 3693 |
% |
| 3694 |
% \item[0.17,,optional] |
| 3695 |
% \rkeyname{keywordcommentsemicolon}|=|\marg{keywords}\marg{keywords}^^A |
| 3696 |
% \marg{keywords} |
| 3697 |
% |
| 3698 |
% The definition of a `keyword comment semicolon' requires three |
| 3699 |
% keyword lists, e.g.~|{end}{else,end}{comment}|. A semicolon always |
| 3700 |
% ends such a comment. Any keyword of the first argument begins a |
| 3701 |
% comment and any keyword of the second argument ends it (and a |
| 3702 |
% semicolon also); a comment starting with any keyword of the third |
| 3703 |
% argument is terminated with the next semicolon only. In the example |
| 3704 |
% all possible comments are `\textbf{end}\ldots\textbf{else}', |
| 3705 |
% `\textbf{end}\ldots\textbf{end}' (does not start a comment again) and |
| 3706 |
% `\textbf{comment}\ldots;' and `\textbf{end}\ldots;'. Maybe a curious |
| 3707 |
% definition, but Algol and Simula use such comments. |
| 3708 |
% |
| 3709 |
% Note: The keywords here need not to be a subset of the defined |
| 3710 |
% keywords. They won't appear in keyword style if they aren't. |
| 3711 |
% |
| 3712 |
% \item[0.17,,optional] |
| 3713 |
% \rkeyname{podcomment}|=|\meta{\alternative{true,false}} |
| 3714 |
% |
| 3715 |
% activates or deactivates PODs---Perl specific. |
| 3716 |
% \end{syntax} |
| 3717 |
% |
| 3718 |
% |
| 3719 |
% \subsection{Installation}\label{rInstallation} |
| 3720 |
% |
| 3721 |
% \paragraph{Software installation} |
| 3722 |
% \begin{enumerate} |
| 3723 |
% \item Following the \TeX\ directory structure (TDS), you should put the files |
| 3724 |
% of the \packagename{listings} package into directories as follows: |
| 3725 |
% \begin{center} |
| 3726 |
% \begin{tabular}{lcl} |
| 3727 |
% \texttt{listings.pdf}&$\to$&\texttt{texmf/doc/latex/listings}\\ |
| 3728 |
% \texttt{listings.dtx}, \texttt{listings.ins},\\ |
| 3729 |
% \texttt{listings.ind}, \texttt{lstpatch.sty},\\ |
| 3730 |
% \texttt{lstdrvrs.dtx}&$\to$&\texttt{texmf/source/latex/listings} |
| 3731 |
% \end{tabular} |
| 3732 |
% \end{center} |
| 3733 |
% Note that you may not have a patch file \texttt{lstpatch.sty}. |
| 3734 |
% If you don't use the TDS, simply adjust the directories below. |
| 3735 |
% \item Create the directory \texttt{texmf/tex/latex/listings} or, if it exists |
| 3736 |
% already, remove all |
| 3737 |
% files except \texttt{lst}\meta{whatever}\texttt{0.sty} and |
| 3738 |
% \texttt{lstlocal.cfg} from it. |
| 3739 |
% \item Change the working directory to \texttt{texmf/source/latex/listings} |
| 3740 |
% and run \texttt{listings.ins} through \TeX. |
| 3741 |
% \item Move the generated files to \texttt{texmf/tex/latex/listings} if this |
| 3742 |
% is not already done. |
| 3743 |
% \begin{center} |
| 3744 |
% \begin{tabular}{lcl} |
| 3745 |
% \texttt{listings.sty}, \texttt{lstmisc.sty}, |
| 3746 |
% &&\qquad(kernel and add-ons)\\ |
| 3747 |
% \texttt{listings.cfg}, |
| 3748 |
% &&\qquad(configuration file)\\ |
| 3749 |
% \texttt{lstlang}\meta{number}\texttt{.sty}, |
| 3750 |
% &&\qquad(language drivers)\\ |
| 3751 |
% \texttt{lstpatch.sty}&$\to$&\texttt{texmf/tex/latex/listings} |
| 3752 |
% \end{tabular} |
| 3753 |
% \end{center} |
| 3754 |
% \item If your \TeX\ implementation uses a file name database, update it. |
| 3755 |
% \item If you receive a patch file later on, put it where |
| 3756 |
% \texttt{listings.sty} is (and update the file name database). |
| 3757 |
% \end{enumerate} |
| 3758 |
% Note that \packagename{listings} requires at least version 1.10 of the |
| 3759 |
% \packagename{keyval} package included in the \packagename{graphics} bundle by |
| 3760 |
% David Carlisle. |
| 3761 |
% |
| 3762 |
% |
| 3763 |
% \paragraph{Software configuration} |
| 3764 |
% Read this only if you encounter problems with the standard configuration or |
| 3765 |
% if you want the package to suit foreign languages, for example. |
| 3766 |
% |
| 3767 |
% Never modify a file from the \packagename{listings} package, in particular |
| 3768 |
% not the configuration file. Each new installation or new version overwrites |
| 3769 |
% it. The software license allows modification, but I can't recommend it. |
| 3770 |
% It's better to create one or more of the files |
| 3771 |
% \begin{center} |
| 3772 |
% \begin{tabular}{lcl} |
| 3773 |
% \texttt{lstmisc0.sty} & for & local add-ons |
| 3774 |
% (see the developer's guide),\\ |
| 3775 |
% \texttt{lstlang0.sty} & for & local language definitions |
| 3776 |
% (see \ref{rLanguageDefinitions}), and\\ |
| 3777 |
% \texttt{lstlocal.cfg} & as & local configuration file |
| 3778 |
% \end{tabular} |
| 3779 |
% \end{center} |
| 3780 |
% and put them in the same directory as the other \packagename{listings} files. |
| 3781 |
% These three files are not touched by a new installation unless you remove them. |
| 3782 |
% If \texttt{lstlocal.cfg} exists, it is loaded after \texttt{listings.cfg}. |
| 3783 |
% You might want to change one of the following parameters. |
| 3784 |
% \begin{syntax} |
| 3785 |
% \item[,,data] \rcmdname\lstaspectfiles\quad contains~\rlap{\texttt{\lstaspectfiles}} |
| 3786 |
% \item[,,data] \rcmdname\lstlanguagefiles\quad contains~\rlap{\texttt{\lstlanguagefiles}} |
| 3787 |
% |
| 3788 |
% The package uses the specified files to find add-ons and language |
| 3789 |
% definitions. |
| 3790 |
% \end{syntax} |
| 3791 |
% Moreover, you might want to adjust |
| 3792 |
% \icmdname\lstlistlistingname, |
| 3793 |
% \icmdname\lstlistingname, |
| 3794 |
% \icmdname\lstlistingnamestyle, |
| 3795 |
% \ikeyname{defaultdialect}, |
| 3796 |
% \icmdname\lstalias, or |
| 3797 |
% \icmdname\lstalias |
| 3798 |
% \ as described in earlier sections. |
| 3799 |
% |
| 3800 |
% |
| 3801 |
% \section{Experimental features}\label{rExperimentalFeatures} |
| 3802 |
% |
| 3803 |
% This section describes the more or less unestablished parts of this package. |
| 3804 |
% It's unlikely that they will all be removed (unless stated explicitly), but |
| 3805 |
% they are liable to (heavy) changes and improvements. Such features have been |
| 3806 |
% \dag-marked in the last sections. So, if you find anything \dag-marked here, |
| 3807 |
% you should be very, very careful. |
| 3808 |
% |
| 3809 |
% |
| 3810 |
% \subsection{Listings inside arguments}\label{rListingsInsideArguments} |
| 3811 |
% |
| 3812 |
% There are some things to consider if you want to use |\lstinline| or the |
| 3813 |
% listing environment inside arguments. Since \TeX\ reads the argument before |
| 3814 |
% the `\lst-macro' is executed, this package can't do anything to preserve the |
| 3815 |
% input: spaces shrink to one space, the tabulator and the end of line are |
| 3816 |
% converted to spaces, \TeX's comment character is not printable, and so on. |
| 3817 |
% Hence, \emph{you} must work a bit more. You have to put a backslash in front |
| 3818 |
% of each of the following four characters: |\{}%|. Moreover you must protect |
| 3819 |
% spaces in the same manner if: (i) there are two or more spaces following each |
| 3820 |
% other or (ii) the space is the first character in the line. |
| 3821 |
% That's not enough: Each line must be terminated with a `line feed' |^^J|. |
| 3822 |
% And you can't escape to \LaTeX\ inside such listings! |
| 3823 |
% |
| 3824 |
% The easiest examples are with |\lstinline| since we need no line feed. |
| 3825 |
% \begin{verbatim} |
| 3826 |
%\footnote{\lstinline{var i:integer;} and |
| 3827 |
% \lstinline!protected\ \ spaces! and |
| 3828 |
% \fbox{\lstinline!\\\{\}\%!}}\end{verbatim} |
| 3829 |
% yields\lstset{language=Pascal}\footnote{\lstinline{var i:integer;} and |
| 3830 |
% \lstinline!protected\ \ spaces! and |
| 3831 |
% \fbox{\lstinline!\\\{\}\%!}} |
| 3832 |
% if the current language is Pascal. Note that this example shows another |
| 3833 |
% experimental feature: use of argument braces as delimiters. This is |
| 3834 |
% described in section \ref{rTypesettingListings}. |
| 3835 |
% |
| 3836 |
% And now an environment example: |
| 3837 |
% \begin{lstsample}{\lstset{language={}}}{} |
| 3838 |
% \fbox{% |
| 3839 |
% \begin{lstlisting}^^J |
| 3840 |
% \ !"#$\%&'()*+,-./^^J |
| 3841 |
% 0123456789:;<=>?^^J |
| 3842 |
% @ABCDEFGHIJKLMNO^^J |
| 3843 |
% PQRSTUVWXYZ[\\]^_^^J |
| 3844 |
% `abcdefghijklmno^^J |
| 3845 |
% pqrstuvwxyz\{|\}~^^J |
| 3846 |
% \end{lstlisting}} |
| 3847 |
% \end{lstsample} |
| 3848 |
% \begin{advise} |
| 3849 |
% \item You might wonder that this feature is still experimental. The reason: |
| 3850 |
% You shouldn't use listings inside arguments; it's not always safe. |
| 3851 |
% \end{advise} |
| 3852 |
% |
| 3853 |
% |
| 3854 |
% \subsection{\dag\ Export of identifiers}\label{rExportOfIdentifiers} |
| 3855 |
% |
| 3856 |
% It would be nice to export function or procedure names. In general that's a |
| 3857 |
% dream so far. The problem is that programming languages use various syntaxes |
| 3858 |
% for function and procedure declaration or definition. A general interface is |
| 3859 |
% completely out of the scope of this package---that's the work of a compiler |
| 3860 |
% and not of a pretty-printing tool. However, it is possible for particular |
| 3861 |
% languages: in Pascal, for instance, each function or procedure definition and |
| 3862 |
% variable declaration is preceded by a particular keyword. |
| 3863 |
% Note that you must request the following keys with the \texttt{procnames} option: |
| 3864 |
% |\usepackage[procnames]{listings}|. |
| 3865 |
% \begin{syntax} |
| 3866 |
% \item[0.19,{{}},{\dag optional}] \rkeyname{procnamekeys}|=|\marg{keywords} |
| 3867 |
% \item[0.21,,\dag optional] \rkeyname{moreprocnamekeys}|=|\marg{keywords} |
| 3868 |
% \item[0.21,,\dag optional] \rkeyname{deleteprocnamekeys}|=|\marg{keywords} |
| 3869 |
% |
| 3870 |
% each specified keyword indicates a function or procedure definition. |
| 3871 |
% Any identifier following such a keyword appears in `procname' style. |
| 3872 |
% For Pascal you might use\vspace{-.5\baselineskip} |
| 3873 |
% \begin{verbatim} |
| 3874 |
% procnamekeys={program,procedure,function}\end{verbatim} |
| 3875 |
% |
| 3876 |
% \item[0.19,keywordstyle,\dag optional] \rkeyname{procnamestyle}|=|\meta{style} |
| 3877 |
% |
| 3878 |
% defines the style in which procedure and function names appear. |
| 3879 |
% |
| 3880 |
% \item[0.19,false,\dag optional] \rkeyname{indexprocnames}|=|\meta{\alternative{true,false}} |
| 3881 |
% |
| 3882 |
% If activated, procedure and function names are also indexed. |
| 3883 |
% \end{syntax} |
| 3884 |
% \begin{TODO} |
| 3885 |
% The \aspectname{procnames} aspect is unsatisfactory (and has been unchanged |
| 3886 |
% at least since 2000). It marks and indexes the function definitions so far, but |
| 3887 |
% it would be possible to mark also the following function calls, for example. |
| 3888 |
% A key could control whether function names are added to a special keyword |
| 3889 |
% class, which then appears in `procname' style. But should these names be |
| 3890 |
% added globally? There are good reasons for both. Of course, we would also |
| 3891 |
% need a key to reset the name list. |
| 3892 |
% \end{TODO} |
| 3893 |
% |
| 3894 |
% |
| 3895 |
% \subsection{\dag\ Hyperlink references}\label{rHyperReferences} |
| 3896 |
% |
| 3897 |
% This very small aspect must be requested via the \texttt{hyper} option since it |
| 3898 |
% is experimental. One possibility for the future is to combine this aspect |
| 3899 |
% with \aspectname{procnames}. Then it should be possible to click on a |
| 3900 |
% function name and jump to its definition, for example. |
| 3901 |
% \begin{syntax} |
| 3902 |
% \item[0.21,,{\dag optional}] \rkeyname{hyperref}|=|\marg{identifiers} |
| 3903 |
% \item[0.21,,{\dag optional}] \rkeyname{morehyperref}|=|\marg{identifiers} |
| 3904 |
% \item[0.21,,{\dag optional}] \rkeyname{deletehyperref}|=|\marg{identifiers} |
| 3905 |
% |
| 3906 |
% hyperlink the specified identifiers (via \packagename{hyperref} |
| 3907 |
% package). A `click' on such an identifier jumps to the previous |
| 3908 |
% occurrence. |
| 3909 |
% |
| 3910 |
% \item[0.21,\hyper@@anchor,{\dag optional}] \rkeyname{hyperanchor}|=|\meta{two-parameter macro} |
| 3911 |
% \item[0.21,\hyperlink,{\dag optional}] \rkeyname{hyperlink}|=|\meta{two-parameter macro} |
| 3912 |
% |
| 3913 |
% set a hyperlink anchor and link, respectively. |
| 3914 |
% The defaults are suited for the \packagename{hyperref} package. |
| 3915 |
% \end{syntax} |
| 3916 |
% |
| 3917 |
% |
| 3918 |
% \subsection{Literate programming} |
| 3919 |
% |
| 3920 |
% We begin with an example and hide the crucial key=value list. |
| 3921 |
% \begin{lstsample}{% |
| 3922 |
% \lstset{literate={:=}{{$\gets$}}1 {<=}{{$\leq$}}1 {>=}{{$\geq$}}1 ^^A |
| 3923 |
% {<>}{{$\neq$}}1}}{} |
| 3924 |
% \begin{lstlisting} |
| 3925 |
% var i:integer; |
| 3926 |
% |
| 3927 |
% if (i<=0) i := 1; |
| 3928 |
% if (i>=0) i := 0; |
| 3929 |
% if (i<>0) i := 0; |
| 3930 |
% \end{lstlisting} |
| 3931 |
% \end{lstsample} |
| 3932 |
% Funny, isn't it? We could leave |i := 0| in our listings instead of |
| 3933 |
% i| |$\gets$| |0, but that's not literate! ^^A :-) |
| 3934 |
% Now you might want to know how this has been done. Have a \emph{close} |
| 3935 |
% look at the following key. |
| 3936 |
% \begin{syntax} |
| 3937 |
% \item[0.20,,\dag] \rkeyname{literate}|=|[|*|]\meta{replacement |
| 3938 |
% item}\ldots\meta{replacement item} |
| 3939 |
% |
| 3940 |
% First note that there are no commas between the items. Each item |
| 3941 |
% consists of three arguments: \marg{replace}\marg{replacement |
| 3942 |
% text}\marg{length}. \meta{replace} is the original character |
| 3943 |
% sequence. Instead of printing these characters, we use |
| 3944 |
% \meta{replacement text}, which takes the width of \meta{length} |
| 3945 |
% characters in the output. |
| 3946 |
% |
| 3947 |
% Each `printing unit' in \meta{replacement text} \emph{must} be in |
| 3948 |
% braces unless it's a single character. For example, you must put |
| 3949 |
% braces around |$\leq$|. If you want to replace |<-1->| by |
| 3950 |
% |$\leftarrow1\rightarrow$|, the replacement item would be |
| 3951 |
% |{<-1->}{{$\leftarrow$}1{$\rightarrow$}}3|. Note the braces around |
| 3952 |
% the arrows. |
| 3953 |
% |
| 3954 |
% If one \meta{replace} is a subsequence of another \meta{replace}, you |
| 3955 |
% must define the shorter sequence first. For example, |{-}| must be |
| 3956 |
% defined before |{--}| and this before |{-->}|. |
| 3957 |
% |
| 3958 |
% The optional star indicates that literate replacements should not be |
| 3959 |
% made in strings, comments, and other delimited text. |
| 3960 |
% \end{syntax} |
| 3961 |
% In the example above, I've used |
| 3962 |
% \begin{verbatim} |
| 3963 |
% literate={:=}{{$\gets$}}1 {<=}{{$\leq$}}1 {>=}{{$\geq$}}1 {<>}{{$\neq$}}1\end{verbatim} |
| 3964 |
% \begin{TODO} |
| 3965 |
% Of course, it's good to have keys for adding and removing single |
| 3966 |
% \meta{replacement item}s. Maybe the key(s) should work in the same fashion |
| 3967 |
% as the string and comment definitions, i.e.~one item per key=value. |
| 3968 |
% This way it would be easier to provide better auto-detection in case of a |
| 3969 |
% subsequence. |
| 3970 |
% \end{TODO} |
| 3971 |
% |
| 3972 |
% |
| 3973 |
% \subsection{\packagename{LGrind} definitions}\label{rLGrindDefinitions} |
| 3974 |
% |
| 3975 |
% Yes, it's a nasty idea to steal language definitions from other programs. |
| 3976 |
% Nevertheless, it's possible for the \packagename{LGrind} definition |
| 3977 |
% file---at least partially. Please note that this file must be found by |
| 3978 |
% \TeX. |
| 3979 |
% \begin{syntax} |
| 3980 |
% \item[0.21,,{optional}] \rkeyname{lgrindef}|=|\meta{language} |
| 3981 |
% |
| 3982 |
% scans the \texttt{lgrindef} language definition file for |
| 3983 |
% \meta{language} and activates it if present. Note that not all |
| 3984 |
% \packagename{LGrind} capabilities have a \packagename{listings} |
| 3985 |
% analogue. |
| 3986 |
% |
| 3987 |
% Note that `Linda' language doesn't work properly since it defines |
| 3988 |
% compiler directives with preceding `|#|' as keywords. |
| 3989 |
% |
| 3990 |
% \item[0.21,lgrindef.,{data,optional}] \rcmdname\lstlgrindeffile |
| 3991 |
% |
| 3992 |
% contains the (path and) name of the definition file. |
| 3993 |
% \end{syntax} |
| 3994 |
% |
| 3995 |
% |
| 3996 |
% \subsection{\dag\ Automatic formatting} |
| 3997 |
% |
| 3998 |
% \lstloadaspects{formats}^^A |
| 3999 |
% The automatic source code formatting is far away from being good. First of |
| 4000 |
% all, there are no general rules on how source code should be formatted. So |
| 4001 |
% `format definitions' must be flexible. This flexibility requires a complex |
| 4002 |
% interface, a powerful `format definition' parser, and lots of code lines |
| 4003 |
% behind the scenes. Currently, format definitions aren't flexible enough |
| 4004 |
% (possibly not the definitions but the results). A single `format item' has |
| 4005 |
% the form |
| 4006 |
% \begin{itemize}\item[] |
| 4007 |
% \meta{input chars}|=|\oarg{exceptional chars}\meta{pre}\oarg{^^A |
| 4008 |
% \texttt{\string\string}}\meta{post} |
| 4009 |
% \end{itemize} |
| 4010 |
% Whenever \meta{input chars} aren't followed by one of the \meta{exceptional |
| 4011 |
% chars}, formatting is done according to the rest of the value. If |\string| |
| 4012 |
% isn't specified, the input characters aren't printed (except it's an |
| 4013 |
% identifier or keyword). Otherwise \meta{pre} is `executed' before printing |
| 4014 |
% the original character string and \meta{post} afterwards. These two are |
| 4015 |
% `subsets' of |
| 4016 |
% \begin{itemize} |
| 4017 |
% \item |\newline| ---ensuring a new line; |
| 4018 |
% \item |\space| ---ensuring a whitespace; |
| 4019 |
% \item |\indent| ---increasing indention; |
| 4020 |
% \item |\noindent| ---descreasing indention. |
| 4021 |
% \end{itemize} |
| 4022 |
% Now we can give an example.\lstaspectindex{\lstdefineformat}{}\lstaspectindex{format}{} |
| 4023 |
% \begin{lstxsample} |
| 4024 |
% \lstdefineformat{C}{% |
| 4025 |
% \{=\newline\string\newline\indent,% |
| 4026 |
% \}=\newline\noindent\string\newline,% |
| 4027 |
% ;=[\ ]\string\space} |
| 4028 |
% \end{lstxsample} |
| 4029 |
% \begin{lstsample}{\lstset{language={}}}{} |
| 4030 |
% \begin{lstlisting}[format=C] |
| 4031 |
% for (int i=0;i<10; i++){/* wait */}; |
| 4032 |
% \end{lstlisting} |
| 4033 |
% \end{lstsample} |
| 4034 |
% Not good. But there is a (too?) simple work-around: |
| 4035 |
% \begin{lstxsample} |
| 4036 |
% \lstdefineformat{C}{% |
| 4037 |
% \{=\newline\string\newline\indent,% |
| 4038 |
% \}=[;]\newline\noindent\string\newline,% |
| 4039 |
% \};=\newline\noindent\string\newline,% |
| 4040 |
% ;=[\ ]\string\space} |
| 4041 |
% \end{lstxsample} |
| 4042 |
% \begin{lstsample}{\lstset{language={}}}{} |
| 4043 |
% \begin{lstlisting}[format=C] |
| 4044 |
% for (int i=0;i<10; i++){/* wait */}; |
| 4045 |
% \end{lstlisting} |
| 4046 |
% \end{lstsample} |
| 4047 |
% Sometimes the problem is just to find a suitable format definition. |
| 4048 |
% Further formatting is complicated. |
| 4049 |
% Here are only three examples with increasing level of difficulty. |
| 4050 |
% \begin{enumerate} |
| 4051 |
% \item Insert horizontal space to separate function/procedure name and |
| 4052 |
% following parenthesis or to separate arguments of a function, |
| 4053 |
% e.g.~add the space after a comma (if inside function call). |
| 4054 |
% \item Smart breaking of long lines. Consider long `and/or' expressions. |
| 4055 |
% Formatting should follow the logical structure! |
| 4056 |
% \item Context sensitive formatting rules. It can be annoying if empty |
| 4057 |
% or small blocks take three or more lines in the output---think of |
| 4058 |
% scrolling down all the time. So it would be nice if the block |
| 4059 |
% formatting was context sensitive. |
| 4060 |
% \end{enumerate} |
| 4061 |
% Note that this is a very first and clumsy attempt to provide automatic |
| 4062 |
% formatting---clumsy since the problem isn't trivial. Any ideas are welcome. |
| 4063 |
% Implementations also. Eventually you should know that you must request format |
| 4064 |
% definitions at package loading, e.g.~via |\usepackage[formats]{listings}|. |
| 4065 |
% |
| 4066 |
% \subsection{Arbitrary linerange markers}\label{rArbitraryLinerangeMarkers} |
| 4067 |
% |
| 4068 |
% Instead of using \keyname{linerange} with line numbers, one can use text |
| 4069 |
% markers. Each such marker consists of a \meta{prefix}, a \meta{text}, and a |
| 4070 |
% \meta{suffix}. You once (or more) define prefixes and suffixes and then use |
| 4071 |
% the marker text instead of the line numbers. |
| 4072 |
% \begin{lstxsample} |
| 4073 |
% \lstset{rangeprefix=\{\ ,% curly left brace plus space |
| 4074 |
% rangesuffix=\ \}}% space plus curly right brace |
| 4075 |
% \end{lstxsample} |
| 4076 |
% \begin{lstsample}{}{} |
| 4077 |
% \begin{lstlisting}% |
| 4078 |
% [linerange=loop\ 2-end] |
| 4079 |
% { loop 1 } |
| 4080 |
% for i:=maxint to 0 do |
| 4081 |
% begin |
| 4082 |
% { do nothing } |
| 4083 |
% end; |
| 4084 |
% { end } |
| 4085 |
% { loop 2 } |
| 4086 |
% for i:=maxint to 0 do |
| 4087 |
% begin |
| 4088 |
% { do nothing } |
| 4089 |
% end; |
| 4090 |
% { end } |
| 4091 |
% \end{lstlisting} |
| 4092 |
% \end{lstsample} |
| 4093 |
% Note that \TeX's special characters like the curly braces, the space, the |
| 4094 |
% percent sign, and such must be escaped with a backslash. |
| 4095 |
% \begin{syntax} |
| 4096 |
% \item[1.2] \rkeyname{rangebeginprefix}|=|\meta{prefix} |
| 4097 |
% \item[1.2] \rkeyname{rangebeginsuffix}|=|\meta{suffix} |
| 4098 |
% \item[1.2] \rkeyname{rangeendprefix}|=|\meta{prefix} |
| 4099 |
% \item[1.2] \rkeyname{rangeendsuffix}|=|\meta{suffix} |
| 4100 |
% |
| 4101 |
% define individual prefixes and suffixes for the begin- and end-marker. |
| 4102 |
% |
| 4103 |
% \item[1.2] \rkeyname{rangeprefix}|=|\meta{prefix} |
| 4104 |
% \item[1.2] \rkeyname{rangesuffix}|=|\meta{suffix} |
| 4105 |
% |
| 4106 |
% define identical prefixes and suffixes for the begin- and end-marker. |
| 4107 |
% |
| 4108 |
% \item[1.2,true] \rkeyname{includerangemarker}|=|\meta{\alternative{true,false}} |
| 4109 |
% |
| 4110 |
% shows or hides the markers in the output. |
| 4111 |
% |
| 4112 |
% \textbf{Remark:} If |firstnumber| is set, it refers to |
| 4113 |
% the line which contains the marker. So if one wants to start a range with |
| 4114 |
% the number 1, one has to set |includerangemarker=false, firstnumber=0|. |
| 4115 |
% \end{syntax} |
| 4116 |
% \begin{lstsample}{\lstset{rangeprefix=\{\ ,rangesuffix=\ \}}}{} |
| 4117 |
% \begin{lstlisting}% |
| 4118 |
% [linerange=loop\ 1-end, |
| 4119 |
% includerangemarker=false, |
| 4120 |
% frame=single] |
| 4121 |
% { loop 1 } |
| 4122 |
% for i:=maxint to 0 do |
| 4123 |
% begin |
| 4124 |
% { do nothing } |
| 4125 |
% end; |
| 4126 |
% { end } |
| 4127 |
% \end{lstlisting} |
| 4128 |
% \end{lstsample} |
| 4129 |
% |
| 4130 |
% |
| 4131 |
% \subsection{Multicolumn Listings}\label{rMulticolumnListings} |
| 4132 |
% |
| 4133 |
% When the \packagename{multicol} package is loaded, it can be used to typeset |
| 4134 |
% multi-column listings. These are specified with the |multicols| key. For |
| 4135 |
% example: |
| 4136 |
% \begin{lstsample}{}{} |
| 4137 |
% \begin{lstlisting}[multicols=2] |
| 4138 |
% if (i < 0) |
| 4139 |
% i = 0 |
| 4140 |
% j = 1 |
| 4141 |
% end if |
| 4142 |
% if (j < 0) |
| 4143 |
% j = 0 |
| 4144 |
% end if |
| 4145 |
% \end{lstlisting} |
| 4146 |
% \end{lstsample} |
| 4147 |
% |
| 4148 |
% The multicolumn option is known to fail with some keys. |
| 4149 |
% |
| 4150 |
% \begin{advise} |
| 4151 |
% \item Which keys? |
| 4152 |
% \advisespace |
| 4153 |
% Unfortunately, I don't know. Carsten left the code for this option |
| 4154 |
% in the version 1.3b patch file with only that cryptic note for |
| 4155 |
% documentation. Bug reports would be welcome, though I don't promise |
| 4156 |
% that they're fixable. ---Brooks |
| 4157 |
% \end{advise} |
| 4158 |
% |
| 4159 |
% |
| 4160 |
%\iffalse |
| 4161 |
% \section{Forthcoming ?} |
| 4162 |
% |
| 4163 |
% This section is rather rudimentary. It just lists some things I don't want |
| 4164 |
% to forget. |
| 4165 |
% |
| 4166 |
% First of all, I'd like to support even more languages, for example Maple, |
| 4167 |
% PostScript, and so on. Fortunately my lifetime is limited, so other |
| 4168 |
% people may do that work. Please (e-)mail me your language definitions. |
| 4169 |
% |
| 4170 |
% Then, there are several ideas for the future. Some have already been stated |
| 4171 |
% as `to do's; some came from other people and are stated below; some more are |
| 4172 |
% far from being implemented, |
| 4173 |
% e.g.~\keyname{linerange}|=|\oarg{inter}\marg{line range list} |
| 4174 |
% which prints all lines in the range and executes \meta{inter} when omitting |
| 4175 |
% some code lines. The main problem here are frames and background colours; |
| 4176 |
% what should happen to them? In fact, the problem is how this can be coded. |
| 4177 |
% Another idea is to change the background colour (or the basic style) for |
| 4178 |
% particular code blocks. This, too, is not easy. |
| 4179 |
% |
| 4180 |
%^^A Auto-detect whether surplus space (from spaces and tabs) isn't needed to fix |
| 4181 |
%^^A alignment of wide character combinations like |==| or |<>|. |
| 4182 |
%^^A |
| 4183 |
%^^A Make package compatible to calc package. |
| 4184 |
%^^A |
| 4185 |
%^^A Rewrite \lst@LAS, \lst@DefDriver, \lst@Require to distinguish loading |
| 4186 |
%^^A of languages (which don't need base languages at once) and aspects |
| 4187 |
%^^A (which need required aspects to be loaded). |
| 4188 |
% |
| 4189 |
% \lsthelper{Vincent~Poirriez}{1999/11/18}{code examples inside caml comments}: |
| 4190 |
% Inside caml comments, |[| and |]| should print the code in |
| 4191 |
% between in basicstyle (or another newly introduced style). Nesting of these |
| 4192 |
% `code example delimiters' is allowed, e.g.~|(* [[x;y]] *)|. |
| 4193 |
% |
| 4194 |
% \lsthelper{Claus~Atzenbeck}{1999/12/03}{`extendedchars=false' doesn't issue |
| 4195 |
% warning when extended characters are used}: issue warning in final mode if |
| 4196 |
% \ikeyname{extendedchars}|=false| but extended chars are used. |
| 4197 |
% |
| 4198 |
% \lsthelper{Andreas~Matthias}{2000/01/04}{define header/footer to print |
| 4199 |
% the listing name}: Make the header/footer print the listing name. Some |
| 4200 |
% people asked for continued captions. |
| 4201 |
%\fi |
| 4202 |
% |
| 4203 |
% |
| 4204 |
% \part{Tips and tricks} |
| 4205 |
% |
| 4206 |
% Note: This part of the documentation is under construction. |
| 4207 |
% Section \ref{uHowTos} must be sorted by topic and ordered in some way. |
| 4208 |
% Moreover a new section `Examples' is planned, but not written. |
| 4209 |
% Lack of time is the main problem \ldots |
| 4210 |
% |
| 4211 |
% |
| 4212 |
% \section{Troubleshooting}\label{uTroubleshooting} |
| 4213 |
% |
| 4214 |
% If you're faced with a problem with the \packagename{listings} package, there are |
| 4215 |
% some steps you should undergo before you make a bug report. First you should |
| 4216 |
% consult the reference guide to see whether the problem is already known. If not, |
| 4217 |
% create a \emph{minimal} file which reproduces the problem. Follow these |
| 4218 |
% instructions: |
| 4219 |
% \begin{enumerate} |
| 4220 |
% \item Start from the minimal file in section \ref{uAMinimalFile}. |
| 4221 |
% \item Add the \LaTeX\ code which causes the problem, but keep it short. |
| 4222 |
% In particular, keep the number of additional packages small. |
| 4223 |
% \item Remove some code from the file (and the according packages) until the |
| 4224 |
% problem disappears. Then you've found a crucial piece. |
| 4225 |
% \item Add this piece of code again and start over with step 3 until all code |
| 4226 |
% and all packages are substantial. |
| 4227 |
% \item You now have a minimal file. Send a bug report to the address on the |
| 4228 |
% first page of this documentation and include the minimal file together |
| 4229 |
% with the created \texttt{.log}-file. If you use a very special package |
| 4230 |
% (i.e.~one not on CTAN), also include the package if its software license |
| 4231 |
% allows it. |
| 4232 |
% \end{enumerate} |
| 4233 |
% |
| 4234 |
% |
| 4235 |
% \section{Bugs and workarounds}\label{uBugsWorkarounds} |
| 4236 |
% |
| 4237 |
% \subsection{Listings inside arguments}\label{uListingsArguments} |
| 4238 |
% |
| 4239 |
% A long time it wasn't possible to use \verb-\lstinline{...}- in a cell |
| 4240 |
% of a table\makeatletter\@ifundefined{r@uProcessingInline}{}{% |
| 4241 |
% (see section \ref{uProcessingInline} on page \pageref{uProcessingInline} |
| 4242 |
% for more information)},% |
| 4243 |
% \makeatother% |
| 4244 |
% but there was a recommended workaround. This workaround is still |
| 4245 |
% functional, but now one can use \verb-\lstinline{...}- and of course |
| 4246 |
% \verb-\lstinline|...|- directly: |
| 4247 |
% \begin{lstsample}[lstlisting]{}{} |
| 4248 |
% \newcommand\foo{\lstinline{t}} |
| 4249 |
% \newcommand\foobar[2][]{\lstinline[#1]{#2}} |
| 4250 |
% |
| 4251 |
% \begin{tabular}{ll} |
| 4252 |
% \lstinline|r| & a first variable (standard)\\ |
| 4253 |
% \lstinline[language=java]|int s;| & a standard declaration \\ |
| 4254 |
% \foo & a second variable (workaround)\\ |
| 4255 |
% \foobar[language=java]{int u;} & a (workaraond) declaration \\ |
| 4256 |
% \lstinline{v} & another variable using braces\\ |
| 4257 |
% \lstinline[language=java]{int w;} & an additional braced declaration |
| 4258 |
% \end{tabular} |
| 4259 |
% \end{lstsample} |
| 4260 |
% |
| 4261 |
% |
| 4262 |
% \subsection{Listings with a background colour and \LaTeX{} escaped |
| 4263 |
% formulas} |
| 4264 |
% \label{uListingsBackgroundColour} |
| 4265 |
% |
| 4266 |
% If there is any text escaped to \LaTeX{} with some coloured background |
| 4267 |
% and surrounding frames, then there are gaps in the background as well as |
| 4268 |
% in the lines making up the frame. |
| 4269 |
% \begin{lstsample}[lstlisting]{}{} |
| 4270 |
% \begin{lstlisting}[language=C, mathescape, |
| 4271 |
% backgroundcolor=\color{yellow!10}, frame=tlb] |
| 4272 |
% /* the following code computes $\displaystyle\sum_{i=1}^{n}i$ */ |
| 4273 |
% for (i = 1; i <= limit; i++) { |
| 4274 |
% sum += i; |
| 4275 |
% } |
| 4276 |
% \end{lstlisting} |
| 4277 |
% \end{lstsample} |
| 4278 |
% |
| 4279 |
% At the moment there is only one workaround: |
| 4280 |
% \begin{itemize} |
| 4281 |
% \item Write your code into an external file \meta{filename}. |
| 4282 |
% \item Input your code by |\lstinputlisting|\meta{filename} into your |
| 4283 |
% document and surround it with a frame generated by |\begin{mdframed}| |
| 4284 |
% \ldots{} |\end{mdframed}|. |
| 4285 |
% \end{itemize} |
| 4286 |
% \begin{lstsample}[lstlisting]{}{} |
| 4287 |
% \begin{verbatimwrite}{temp.c} |
| 4288 |
% /* the following code computes $\displaystyle\sum_{i=1}^{n}i$ */ |
| 4289 |
% for (i = 1; i <= limit; i++) { |
| 4290 |
% sum += i; |
| 4291 |
% } |
| 4292 |
% \end{verbatimwrite} |
| 4293 |
% \begin{mdframed}[backgroundcolor=yellow!10, rightline=false] |
| 4294 |
% \lstinputlisting[language=C,mathescape,frame={}]{./temp.c} |
| 4295 |
% \end{mdframed} |
| 4296 |
% \end{lstsample} |
| 4297 |
% For more information about the |verbatimwrite| environment have a look at |
| 4298 |
% \cite{Fairbairns:moreverb}, the |mdframed| environment is deeply discussed in |
| 4299 |
% \cite{DanielSchubert:mdframed}. |
| 4300 |
% |
| 4301 |
% |
| 4302 |
% \section{How tos}\label{uHowTos} |
| 4303 |
% |
| 4304 |
% |
| 4305 |
% \subsubsection*{How to reference line numbers} |
| 4306 |
% Perhaps you want to put |\label{|\meta{whatever}|}| into a \LaTeX\ escape which is |
| 4307 |
% inside a comment whose delimiters aren't printed? If you did that, the compiler |
| 4308 |
% won't see the \LaTeX\ code since it would be inside a comment, and the |
| 4309 |
% \packagename{listings} package wouldn't print anything since the delimiters would |
| 4310 |
% be dropped and |\label| doesn't produce any printable output, but you could still |
| 4311 |
% reference the line number. Well, your wish is granted. |
| 4312 |
% |
| 4313 |
% In Pascal, for example, you could make the package recognize the `special' |
| 4314 |
% comment delimiters |(*@| and |@*)| as begin-escape and end-escape sequences. |
| 4315 |
% Then you can use this special comment for |\label|s and other things. |
| 4316 |
% \begin{lstsample}{\lstset{numberstyle=\tiny,stepnumber=2,numbersep=5pt}}{} |
| 4317 |
% \lstset{escapeinside={(*@}{@*)}} |
| 4318 |
% |
| 4319 |
% \begin{lstlisting} |
| 4320 |
% for i:=maxint to 0 do |
| 4321 |
% begin |
| 4322 |
% { comment }(*@\label{comment}@*) |
| 4323 |
% end; |
| 4324 |
% \end{lstlisting} |
| 4325 |
% Line \ref{comment} shows a comment. |
| 4326 |
% \end{lstsample} |
| 4327 |
% \begin{advise} |
| 4328 |
% \item Can I use `|(*@|' and `|*)|' instead? |
| 4329 |
% \advisespace |
| 4330 |
% Yes. |
| 4331 |
% \item Can I use `|(*|' and `|*)|' instead? |
| 4332 |
% \advisespace |
| 4333 |
% Sure. If you want this. |
| 4334 |
% \item Can I use `|{@|' and `|@}|' instead? |
| 4335 |
% \advisespace |
| 4336 |
% No, never! The second delimiter is not allowed. The character `|@|' is |
| 4337 |
% defined to check whether the escape is over. But reading the lonely |
| 4338 |
% `end-argument' brace, \TeX\ encounters the error `\texttt{Argument of @ |
| 4339 |
% has an extra \char125}'. Sorry. |
| 4340 |
% \item Can I use `|{|' and `|}|' instead? |
| 4341 |
% \advisespace |
| 4342 |
% No. Again the second delimiter is not allowed. Here now \TeX\ would |
| 4343 |
% give you a `\texttt{Runaway argument}' error. Since `|}|' is defined to |
| 4344 |
% check whether the escape is over, it won't work as `end-argument' brace. |
| 4345 |
% \item And how can I use a comment line? |
| 4346 |
% \advisespace |
| 4347 |
% For example, write `|escapeinside={//*}{\^^M}|'. Here |\^^M| represents |
| 4348 |
% the end of line character. |
| 4349 |
% \end{advise} |
| 4350 |
% |
| 4351 |
% |
| 4352 |
% \subsubsection*{How to gobble characters} |
| 4353 |
% To make your \LaTeX\ code more readable, you might want to indent your |
| 4354 |
% \texttt{lstlisting} listings. This indention should not show up in the |
| 4355 |
% pretty-printed listings, however, so it must be removed. If you indent each code |
| 4356 |
% line by three characters, you can remove them via |gobble=3|: |
| 4357 |
% \begin{lstsample}{}{\lstset{showspaces}} |
| 4358 |
% \begin{lstlisting}[gobble=3] |
| 4359 |
% 1 for i:=maxint to 0 do |
| 4360 |
% 2 begin |
| 4361 |
% 3 { do nothing } |
| 4362 |
% 123end; |
| 4363 |
% |
| 4364 |
% Write('Case insensitive '); |
| 4365 |
% WritE('Pascal keywords.'); |
| 4366 |
% \end{lstlisting} |
| 4367 |
% \end{lstsample} |
| 4368 |
% Note that empty lines and the beginning and the end of the environment |
| 4369 |
% need not respect the indention. However, never indent the end by more than |
| 4370 |
% `\ikeyname{gobble}' characters. Moreover note that tabulators expand to |
| 4371 |
% |tabsize| spaces before we gobble. |
| 4372 |
% \begin{advise} |
| 4373 |
% \item Could I use `\ikeyname{gobble}' together with `|\lstinputlisting|'? |
| 4374 |
% \advisespace |
| 4375 |
% Yes, but it has no effect. |
| 4376 |
% |
| 4377 |
% \item Note that `\ikeyname{gobble}' can also be set via `|\lstset|'. |
| 4378 |
% \end{advise} |
| 4379 |
% |
| 4380 |
% |
| 4381 |
% \subsubsection*{How to include graphics} |
| 4382 |
% \lsthelper{Herbert~Weinhandl}{1999/09/06}{listings + eps} found a very easy |
| 4383 |
% way to include graphics in listings. Thanks for contributing this idea---an |
| 4384 |
% idea I would never have had. |
| 4385 |
% |
| 4386 |
% Some programming languages allow the dollar sign to be part of an identifier. |
| 4387 |
% But except for intermediate function names or library functions, this |
| 4388 |
% character is most often unused. The \packagename{listings} package defines |
| 4389 |
% the \ikeyname{mathescape} key, which lets `|$|' escape to \TeX's math mode. |
| 4390 |
% This makes the dollar character an excellent candidate for our purpose here: |
| 4391 |
% use a package which can include a graphic, set \ikeyname{mathescape} true, |
| 4392 |
% and include the graphic between two dollar signs, which are inside a comment. |
| 4393 |
% |
| 4394 |
% The following example is originally from a header file I got from Herbert. |
| 4395 |
% For the presentation here I use the \texttt{lstlisting} environment and an |
| 4396 |
% excerpt from the header file. The |\includegraphics| command is from |
| 4397 |
% David Carlisle's \packagename{graphics} bundle. |
| 4398 |
% \begin{verbatim} |
| 4399 |
% \begin{lstlisting}[mathescape=true] |
| 4400 |
% /* |
| 4401 |
% $ \includegraphics[height=1cm]{defs-p1.eps} $ |
| 4402 |
% */ |
| 4403 |
% typedef struct { |
| 4404 |
% Atom_T *V_ptr; /* pointer to Vacancy in grid */ |
| 4405 |
% Atom_T *x_ptr; /* pointer to (A|B) Atom in grid */ |
| 4406 |
% } ABV_Pair_T; |
| 4407 |
% \end{lstlisting}\end{verbatim} |
| 4408 |
% The result looks pretty good. Unfortunately you can't see it, because the |
| 4409 |
% graphic wasn't available when the manual was typeset. |
| 4410 |
% |
| 4411 |
% |
| 4412 |
% \subsubsection*{How to get closed frames on each page} |
| 4413 |
% The package supports closed frames only for listings which don't cross pages. |
| 4414 |
% If a listing is split on two pages, there is neither a bottom rule at the |
| 4415 |
% bottom of a page, nor a top rule on the following page. If you insist on |
| 4416 |
% these rules, you might want to use \texttt{framed.sty} by Donald Arseneau. |
| 4417 |
% Then you could write |
| 4418 |
% \begin{verbatim} |
| 4419 |
% \begin{framed} |
| 4420 |
% \begin{lstlisting} |
| 4421 |
% or \lstinputlisting{...} |
| 4422 |
% \end{lstlisting} |
| 4423 |
% \end{framed}\end{verbatim} |
| 4424 |
% The package also provides a \texttt{shaded} environment. If you use it, you |
| 4425 |
% shouldn't forget to define \texttt{shadecolor} with the \packagename{color} |
| 4426 |
% package. |
| 4427 |
% |
| 4428 |
% |
| 4429 |
% \subsubsection*{How to print national characters with $\Lambda$ and |
| 4430 |
% \packagename{listings}}\label{uNationalCharacters} |
| 4431 |
% |
| 4432 |
% Apart from typing in national characters directly, you can use the `escape' |
| 4433 |
% feature described in section \ref{rEscapingToLaTeX}. |
| 4434 |
% The keys \ikeyname{escapechar}, \ikeyname{escapeinside}, and \ikeyname{texcl} |
| 4435 |
% allow partial usage of \LaTeX\ code. |
| 4436 |
% |
| 4437 |
% Now, if you use $\Lambda$ (Lambda, the \LaTeX\ variant for Omega) and want, |
| 4438 |
% for example, Arabic comment lines, you need not write |\begin{arab}| |
| 4439 |
% \ldots\ |\end{arab}| each escaped comment line. This can be automated: |
| 4440 |
% \begin{verbatim} |
| 4441 |
% \lstset{escapebegin=\begin{arab},escapeend=\end{arab}} |
| 4442 |
% |
| 4443 |
% \begin{lstlisting}[texcl] |
| 4444 |
% // Replace text by Arabic comment. |
| 4445 |
% for (int i=0; i<1; i++) { }; |
| 4446 |
% \end{lstlisting}\end{verbatim} |
| 4447 |
% If your programming language doesn't have comment lines, you'll have to use |
| 4448 |
% \ikeyname{escapechar} or \ikeyname{escapeinside}: |
| 4449 |
% \begin{verbatim} |
| 4450 |
% \lstset{escapebegin=\begin{greek},escapeend=\end{greek}} |
| 4451 |
% |
| 4452 |
% \begin{lstlisting}[escapeinside=`'] |
| 4453 |
% /* `Replace text by Greek comment.' */ |
| 4454 |
% for (int i=0; i<1; i++) { }; |
| 4455 |
% \end{lstlisting}\end{verbatim} |
| 4456 |
% Note that the delimiters |`| and |'| are essential here. The example doesn't |
| 4457 |
% work without them. There is a more clever way if the comment delimiters of |
| 4458 |
% the programming language are single characters, like the braces in Pascal: |
| 4459 |
% \begin{verbatim} |
| 4460 |
% \lstset{escapebegin=\textbraceleft\begin{arab}, |
| 4461 |
% escapeend=\end{arab}\textbraceright} |
| 4462 |
% |
| 4463 |
% \begin{lstlisting}[escapeinside=\{\}] |
| 4464 |
% for i:=maxint to 0 do |
| 4465 |
% begin |
| 4466 |
% { Replace text by Arabic comment. } |
| 4467 |
% end; |
| 4468 |
% \end{lstlisting}\end{verbatim} |
| 4469 |
% Please note that the `interface' to $\Lambda$ is completely untested. |
| 4470 |
% Reports are welcome! |
| 4471 |
% |
| 4472 |
% |
| 4473 |
% \subsubsection*{How to get bold typewriter type keywords} |
| 4474 |
% Use the \href{http://mirror.ctan.org/fonts/luximono}{\packagename{LuxiMono}} package. |
| 4475 |
% |
| 4476 |
% \iffalse |
| 4477 |
% Many people asked for bold typewriter fonts since they aren't included in |
| 4478 |
% the \LaTeX\ standard distribution. Here now one answer on how to use them |
| 4479 |
% in spite of that. |
| 4480 |
% \begin{advise} |
| 4481 |
% \item Please note that I personally don't regard the following as a good |
| 4482 |
% solution. Such a bold typewriter type is too heavy. It would be better |
| 4483 |
% to use a light version of \texttt{cmtt} as basic font and \texttt{cmtt} |
| 4484 |
% or a \emph{slightly} heavier type for keywords. |
| 4485 |
% |
| 4486 |
% \item Why don't you tell us how to use the better solution? |
| 4487 |
% \advisespace |
| 4488 |
% A light version of \texttt{cmtt} doesn't exist. If it's once available, |
| 4489 |
% you can do a similar job as described below. |
| 4490 |
% \end{advise} |
| 4491 |
% First of all, you'll need Metafont source files for bold typewriter, e.g.~ |
| 4492 |
% \texttt{cmbtt8.mf}, \texttt{cmbtt9.mf} and \texttt{cmbtt10.mf} from |
| 4493 |
% \href{http://mirror.ctan.org/fonts/cm/mf-extra/bold} |
| 4494 |
% {CTAN/fonts/cm/mf-extra/bold}. |
| 4495 |
% Secondly you have to create \texttt{.tfm}-files, i.e.~run the Metafont |
| 4496 |
% program on these sources. This is possibly done automatically when you use |
| 4497 |
% the fonts in a document. Finally you must tell \LaTeX\ that you've installed |
| 4498 |
% bold typewriter fonts. Just use |
| 4499 |
% \begin{verbatim} |
| 4500 |
% \DeclareFontShape{OT1}{cmtt}{bx}{n} |
| 4501 |
% {<5><6><7><8>cmbtt8% |
| 4502 |
% <9>cmbtt9% |
| 4503 |
% <10><10.95>cmbtt10% |
| 4504 |
% <12><14.4><17.28><20.74><24.88>cmbtt10% |
| 4505 |
% }{}\end{verbatim} |
| 4506 |
% in the preamble of your document. If you use these fonts often, you might |
| 4507 |
% want to make a local copy of \texttt{ot1cmtt.fd} and replace the declaration |
| 4508 |
% there. But note that you're not allowed to distributed the modified file |
| 4509 |
% under its original name! |
| 4510 |
% \fi |
| 4511 |
% |
| 4512 |
% |
| 4513 |
% \subsubsection*{How to work with plain text} |
| 4514 |
% If you want to use \packagename{listings} to set plain text (perhaps with |
| 4515 |
% line numbers, or like |verbatim| but with line wrapping, or so forth, use |
| 4516 |
% the empty language: |\lstset{language=}|. |
| 4517 |
% |
| 4518 |
% |
| 4519 |
% \subsubsection*{How to get the developer's guide} |
| 4520 |
% In the \emph{source directory} of the listings package, i.e.~where |
| 4521 |
% the \texttt{.dtx} files are, create the file \texttt{ltxdoc.cfg} with the |
| 4522 |
% following contents. |
| 4523 |
% \begin{verbatim} |
| 4524 |
% \AtBeginDocument{\AlsoImplementation}\end{verbatim} |
| 4525 |
% Then run \texttt{listings.dtx} through \LaTeX\ twice, run Makeindex (with |
| 4526 |
% the |-s gind.ist| option), and then run \LaTeX\ one last time on |
| 4527 |
% \texttt{listings.dtx}. This creates the whole documentation including User's |
| 4528 |
% guide, Reference guide, Developer's guide, and Implementation. |
| 4529 |
% |
| 4530 |
% If you can run the (GNU) make program, executing the command |
| 4531 |
% \begin{verbatim} |
| 4532 |
% make all\end{verbatim} |
| 4533 |
% or |
| 4534 |
% \begin{verbatim} |
| 4535 |
% make listings-devel.pdf\end{verbatim} |
| 4536 |
% or |
| 4537 |
% \begin{verbatim} |
| 4538 |
% make pdf-devel\end{verbatim} |
| 4539 |
% gives the same result---it is called \texttt{listings-devel.pdf}. |
| 4540 |
% |
| 4541 |
% |
| 4542 |
% \subsubsection*{How to copy and paste from a document} |
| 4543 |
% \label{sec:upquote} |
| 4544 |
% If you want to provide a document containing listings formatted by this |
| 4545 |
% package (\packagename{listings}) as source for copy and paste, you should |
| 4546 |
% be sure to set the key |upquote| to |true| and have |
| 4547 |
% |\usepackage{textcomp}| in the preamble of the document. Otherwise the |
| 4548 |
% pair |`'| of curly quotation marks is associated with Unicode positions |
| 4549 |
% U+2018 and U+2019 \cite{CovingtonMittelbachKuhn:upquote}. These |
| 4550 |
% characters are seldom used as delimiters in modern programming languages. |
| 4551 |
% |
| 4552 |
% |
| 4553 |
% \subsubsection*{How to change the layout of the list of listings} |
| 4554 |
% \label{sec:tocbasic} |
| 4555 |
% If you put the command |\lstlistoflistings| into your document, the list |
| 4556 |
% of listings is automatically generated and printed at that point. If you |
| 4557 |
% are using the standard \LaTeX{} classes the list is prepared by |
| 4558 |
% |\addtocontents| commands or a variation, if you also load the package |
| 4559 |
% \packagename{float}. In both cases the layout is the one defined by |
| 4560 |
% L. Lamport. |
| 4561 |
% |
| 4562 |
% If you want to change the layout of this list, you can use the package |
| 4563 |
% \packagename{tocbasic} as described in \cite[Chapter |
| 4564 |
% 15.3]{Kohm:scrguide}. \packagename{tocbasic} is automatically loaded, if |
| 4565 |
% you are using one of the KOMA classes. |
| 4566 |
% |
| 4567 |
% |
| 4568 |
% \makeatletter |
| 4569 |
%^^A \def\index@prologue{\section*{Index}\markboth{Index}{Index}} |
| 4570 |
% \def\index@prologue{\part{Index}\markboth{Index}{Index}} |
| 4571 |
% \makeatother |
| 4572 |
%^^A \StopEventually{\lstcheckreference\setcounter{IndexColumns}{2}\PrintIndex} |
| 4573 |
% \StopEventually{% |
| 4574 |
% \nocite{MF23} |
| 4575 |
% \begin{thebibliography}{MDB01} |
| 4576 |
% |
| 4577 |
% \bibitem[CMK12]{CovingtonMittelbachKuhn:upquote} |
| 4578 |
% Michael A. Covington, Frank Mittelbach and Markus G. Kuhn. |
| 4579 |
% \newblock{\packagename{upquote} -- upright-quote and grave-accent glyphs |
| 4580 |
% in verbatim}, 2012. |
| 4581 |
% |
| 4582 |
% \bibitem[DS13]{DanielSchubert:mdframed} |
| 4583 |
% Marco Daniel and Elke Schubert. |
| 4584 |
% \newblock{The \packagename{mdframed} package}, 2013. |
| 4585 |
% |
| 4586 |
% \bibitem[Fai11]{Fairbairns:moreverb} |
| 4587 |
% Robin Fairbairns. |
| 4588 |
% \newblock{The \packagename{moreverb} package}, 2011. |
| 4589 |
% |
| 4590 |
% \bibitem[Koh23]{Kohm:scrguide} |
| 4591 |
% Markus Kohm. |
| 4592 |
% \newblock{KOMA-Script -- The Guide}, 2023. |
| 4593 |
% |
| 4594 |
% \bibitem[MF23]{MittelbachFischer:companion} |
| 4595 |
% Frank Mittelbach and Ulrike Fischer. |
| 4596 |
% \newblock{The \LaTeX-Companion} Part I and II, 2023. |
| 4597 |
% |
| 4598 |
% \bibitem[Mi04]{Mittelbach:companion} |
| 4599 |
% Frank Mittelbach, Michel Goossens, Johannes Braams, |
| 4600 |
% David P. Carlisle, and Chris Rowley. |
| 4601 |
% \newblock{The \LaTeX-Companion}, 2004. |
| 4602 |
% |
| 4603 |
% \bibitem[Som11]{Sommerfeldt:caption} |
| 4604 |
% Axel Sommerfeldt. |
| 4605 |
% \newblock{Customizing captions of floating environments}, 2011. |
| 4606 |
% \end{thebibliography} |
| 4607 |
% \setcounter{IndexColumns}{2}\PrintIndex} |
| 4608 |
% |
| 4609 |
% |
| 4610 |
% \part{Developer's guide} |
| 4611 |
% |
| 4612 |
% First I must apologize for this developer's guide since some parts are not |
| 4613 |
% explained as well as possible. But note that you are in a pretty good shape: |
| 4614 |
% this developer's guide exists! ^^A :-) |
| 4615 |
% You might want to peek into section \ref{dPackageExtensions} before reading |
| 4616 |
% section \ref{dBasicConcepts}. |
| 4617 |
% |
| 4618 |
% |
| 4619 |
% \section{Basic concepts}\label{dBasicConcepts} |
| 4620 |
% |
| 4621 |
% The functionality of the \packagename{listings} package appears to be |
| 4622 |
% divided into two parts: on the one hand commands which actually typeset |
| 4623 |
% listings and on the other via |\lstset| adjustable parameters. Both could |
| 4624 |
% be implemented in terms of \lst-aspects, which are simply collections of |
| 4625 |
% public keys and commands and internal hooks and definitions. The package |
| 4626 |
% defines a couple of aspects, in particular the kernel, the main engine. |
| 4627 |
% Other aspects drive this engine, and language and style definitions tell |
| 4628 |
% the aspects how to drive. The relations between car, driver and assistant |
| 4629 |
% driver are exactly reproduced---and I'll be your driving instructor. |
| 4630 |
% |
| 4631 |
% |
| 4632 |
% \subsection{Package loading}\label{dPackageLoading} |
| 4633 |
% |
| 4634 |
% Each option in |\usepackage[|\meta{options}|]{listings}| loads an aspect or |
| 4635 |
% \emph{prevents} the package from loading it if the aspect name is |
| 4636 |
% \emph{preceded by an exclamation mark}. This mechanism was designed to clear |
| 4637 |
% up the dependencies of different package parts and to debug the package. For |
| 4638 |
% this reason there is another option: |
| 4639 |
% \begin{syntax} |
| 4640 |
% \item[0.21,,option] \texttt{noaspects}\leavevmode |
| 4641 |
% |
| 4642 |
% deletes the list of aspects to load. Note that, for example, the |
| 4643 |
% option lists |0.21,!labels,noaspects| and |noaspects| are essentially |
| 4644 |
% the same: the kernel is loaded and no other aspect. |
| 4645 |
% \end{syntax} |
| 4646 |
% This is especially useful for aspect-testing since we can load exactly the |
| 4647 |
% required parts. Note, however, that an aspect is loaded later if a predefined |
| 4648 |
% programming language requests it. One can load aspects also by hand: |
| 4649 |
% \begin{syntax} |
| 4650 |
% \item[0.20] |\lstloadaspects|\marg{comma separated list of aspect names} |
| 4651 |
% |
| 4652 |
% loads the specified aspects if they are not already loaded. |
| 4653 |
% \end{syntax} |
| 4654 |
% Here now is a list of all aspects and related keys and commands---in the hope |
| 4655 |
% that this list is complete. |
| 4656 |
% \begin{description} |
| 4657 |
% \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth\relax |
| 4658 |
% \item[\aspectname{strings}]\leavevmode |
| 4659 |
% |
| 4660 |
% \lstprintaspectkeysandcmds{strings} |
| 4661 |
% |
| 4662 |
% \item[\aspectname{comments}]\leavevmode |
| 4663 |
% |
| 4664 |
% \lstprintaspectkeysandcmds{comments} |
| 4665 |
% |
| 4666 |
% \item[\aspectname{pod}]\leavevmode |
| 4667 |
% |
| 4668 |
% \lstprintaspectkeysandcmds{pod} |
| 4669 |
% |
| 4670 |
% \item[\aspectname{escape}]\leavevmode |
| 4671 |
% |
| 4672 |
% \lstprintaspectkeysandcmds{escape} |
| 4673 |
% |
| 4674 |
% \item[\aspectname{writefile}] requires 1 |\toks|, 1 |\write| |
| 4675 |
% |
| 4676 |
% |\lst@BeginWriteFile|, |\lst@BeginAlsoWriteFile|, |\lst@EndWriteFile| |
| 4677 |
% |
| 4678 |
% \item[\aspectname{style}]\leavevmode |
| 4679 |
% |
| 4680 |
% empty style, \lstprintaspectkeysandcmds{style} |
| 4681 |
% |
| 4682 |
% \item[\aspectname{language}]\leavevmode |
| 4683 |
% |
| 4684 |
% empty language, \lstprintaspectkeysandcmds{language} |
| 4685 |
% |
| 4686 |
% \item[\aspectname{keywords}]\leavevmode |
| 4687 |
% |
| 4688 |
% \lstprintaspectkeysandcmds{keywords} |
| 4689 |
% |
| 4690 |
% \item[\aspectname{emph}] requires \aspectname{keywords} |
| 4691 |
% |
| 4692 |
% \lstprintaspectkeysandcmds{emph} |
| 4693 |
% |
| 4694 |
% \item[\aspectname{html}] requires \aspectname{keywords} |
| 4695 |
% |
| 4696 |
% \lstprintaspectkeysandcmds{html} |
| 4697 |
% |
| 4698 |
% \item[\aspectname{tex}] requires \aspectname{keywords} |
| 4699 |
% |
| 4700 |
% \lstprintaspectkeysandcmds{tex} |
| 4701 |
% |
| 4702 |
% \item[\aspectname{directives}] requires \aspectname{keywords} |
| 4703 |
% |
| 4704 |
% \lstprintaspectkeysandcmds{directives} |
| 4705 |
% |
| 4706 |
% \item[\aspectname{index}] requires \aspectname{keywords} |
| 4707 |
% |
| 4708 |
% \lstprintaspectkeysandcmds{index} |
| 4709 |
% |
| 4710 |
% \item[\aspectname{procnames}] requires \aspectname{keywords} |
| 4711 |
% |
| 4712 |
% \lstprintaspectkeysandcmds{procnames} |
| 4713 |
% |
| 4714 |
% \item[\aspectname{keywordcomments}] |
| 4715 |
% requires \aspectname{keywords}, \aspectname{comments} |
| 4716 |
% |
| 4717 |
% \lstprintaspectkeysandcmds{keywordcomments} |
| 4718 |
% |
| 4719 |
% \item[\aspectname{labels}] requires 2 |\count| |
| 4720 |
% |
| 4721 |
% \lstprintaspectkeysandcmds{labels} |
| 4722 |
% |
| 4723 |
% \item[\aspectname{lineshape}] requires 2 |\dimen| |
| 4724 |
% |
| 4725 |
% \lstprintaspectkeysandcmds{lineshape} |
| 4726 |
% |
| 4727 |
% \item[\aspectname{frames}] requires \aspectname{lineshape} |
| 4728 |
% |
| 4729 |
% \lstprintaspectkeysandcmds{frames} |
| 4730 |
% |
| 4731 |
% \item[\aspectname{make}] requires \aspectname{keywords} |
| 4732 |
% |
| 4733 |
% \lstprintaspectkeysandcmds{make} |
| 4734 |
% |
| 4735 |
% \item[\aspectname{doc}] requires \aspectname{writefile} and 1 |\box| |
| 4736 |
% |
| 4737 |
% \lstprintaspectkeysandcmds{doc} |
| 4738 |
% |
| 4739 |
% \item[\aspectname{0.21}] defines old keys in terms of the new ones. |
| 4740 |
% \item[\aspectname{fancyvrb}] requires 1 |\box| |
| 4741 |
% |
| 4742 |
% \lstprintaspectkeysandcmds{fancyvrb} |
| 4743 |
% |
| 4744 |
% \item[\aspectname{lgrind}]\leavevmode |
| 4745 |
% |
| 4746 |
% \lstprintaspectkeysandcmds{lgrind} |
| 4747 |
% |
| 4748 |
% \item[\aspectname{hyper}] requires \aspectname{keywords} |
| 4749 |
% |
| 4750 |
% \lstprintaspectkeysandcmds{hyper} |
| 4751 |
% \end{description} |
| 4752 |
% The kernel allocates 6 |\count|, 4 |\dimen| and 1 |\toks|. |
| 4753 |
% Moreover it defines the following keys, commands, and environments: |
| 4754 |
% \begin{itemize}\item[] |
| 4755 |
% \hyphenpenalty=10000\relax \rightskip=0pt plus \linewidth\relax |
| 4756 |
% \lstprintaspectkeysandcmds{kernel}, \keyname{fancyvrb} |
| 4757 |
% \end{itemize} |
| 4758 |
% |
| 4759 |
% |
| 4760 |
% \subsection{How to define \lst-aspects}\label{dHowToDefineLstAspects} |
| 4761 |
% |
| 4762 |
% There are at least three ways to add new functionality: (a) you write an |
| 4763 |
% aspect of general interest, send it to me, and I'll just paste it into the |
| 4764 |
% implementation; (b) you write a `local' aspect not of general interest; or |
| 4765 |
% (c) you have an idea for an aspect and make me writing it. (a) and (b) are |
| 4766 |
% good choices.^^A :-) |
| 4767 |
% |
| 4768 |
% An aspect definition starts with |\lst@BeginAspect| plus arguments and ends |
| 4769 |
% with the next |\lst@EndAspect|. In particular, aspect definitions can't be |
| 4770 |
% nested. |
| 4771 |
% \begin{syntax} |
| 4772 |
% \item[0.20] |\lst@BeginAspect|[\oarg{list of required aspects}]\marg{aspect name} |
| 4773 |
% \item[0.20] |\lst@EndAspect| |
| 4774 |
% \end{syntax} |
| 4775 |
% The optional list is a comma separated list of required aspect names. |
| 4776 |
% The complete aspect is not defined in each of the following cases: |
| 4777 |
% \begin{enumerate} |
| 4778 |
% \item \meta{aspect name} is empty. |
| 4779 |
% \item The aspect is already defined. |
| 4780 |
% \item A required aspect is neither defined nor loadable via |
| 4781 |
% |\lstloadaspects|. |
| 4782 |
% \end{enumerate} |
| 4783 |
% Consequently you can't define a part of an aspect and later on another part. |
| 4784 |
% But it is possible to define aspect $A_1$ and later aspect $A_2$ which |
| 4785 |
% requires $A_1$. |
| 4786 |
% \begin{advise} |
| 4787 |
% \item Put local add-ons into `\texttt{lstmisc0.sty}'---this file is searched |
| 4788 |
% first by default. If you want to make add-ons for one particular |
| 4789 |
% document just replace the surrounding `|\lst@BeginAspect|' and |
| 4790 |
% `|\lst@EndAspect|' by `|\makeatletter|' and `|\makeatother|' and use |
| 4791 |
% the definitions in the preamble of your document. However, you have to |
| 4792 |
% load required aspects on your own. |
| 4793 |
% \end{advise} |
| 4794 |
% You can put any \TeX\ material in between the two commands, but note that |
| 4795 |
% definitions must be |\global| if you need them later---\LaTeX's |\newcommand| |
| 4796 |
% makes local definitions and can't be preceded by |\global|. So use the |
| 4797 |
% following commands, |\gdef|, and commands described in later sections. |
| 4798 |
% \begin{syntax} |
| 4799 |
% \item[0.20] |\lst@UserCommand|\meta{macro}\meta{parameter text}\marg{replacement text} |
| 4800 |
% |
| 4801 |
% The macro is (mainly) equivalent to |\gdef|. The purpose is to |
| 4802 |
% distinguish user commands and internal global definitions. |
| 4803 |
% |
| 4804 |
% \item[0.19] |\lst@Key|\marg{key name}\marg{init value}[\oarg{default value}]\marg{definition} |
| 4805 |
% \item[0.19] |\lst@Key|\marg{key name}|\relax|[\oarg{default value}]\marg{definition} |
| 4806 |
% |
| 4807 |
% defines a key using the \packagename{keyval} package from David |
| 4808 |
% Carlisle. \meta{definition} is the replacement text of a macro with |
| 4809 |
% one parameter. The argument is either the value from `key=value' or |
| 4810 |
% \meta{default value} if no `=value' is given. The helper macros |
| 4811 |
% |\lstKV@...| below might simplify \meta{definition}. |
| 4812 |
% |
| 4813 |
% The key is not initialized if the second argument is |\relax|. |
| 4814 |
% Otherwise \meta{init value} is the initial value given to the key. |
| 4815 |
% Note that we locally switch to |\globalsdefs=1| to ensure that |
| 4816 |
% initialization is not effected by grouping. |
| 4817 |
% |
| 4818 |
% \item[0.19] |\lst@AddToHook|\marg{name of hook}\marg{\TeX\ material} |
| 4819 |
% |
| 4820 |
% adds \TeX\ material at predefined points. Section \ref{dHooks} lists |
| 4821 |
% all hooks and where they are defined respectively executed. |
| 4822 |
% |\lst@AddToHook{A}{\csa}| before |\lst@AddToHook{A}{\csb}| |
| 4823 |
% \emph{does not} guarantee that |\csa| is executed before |\csb|. |
| 4824 |
% |
| 4825 |
% \item[0.20] |\lst@AddToHookExe|\marg{name of hook}\marg{\TeX\ material} |
| 4826 |
% |
| 4827 |
% also executes \meta{\TeX\ material} for initialization. You might use |
| 4828 |
% local variables---local in the sense of \TeX\ and/or usual programming |
| 4829 |
% languages---but when the code is executed for initialization all |
| 4830 |
% assignments are global: we set |\globaldefs| locally to one. |
| 4831 |
% |
| 4832 |
% \item[0.20] |\lst@UseHook|\marg{name of hook} |
| 4833 |
% |
| 4834 |
% executes the hook. |
| 4835 |
% \end{syntax} |
| 4836 |
% \begin{advise} |
| 4837 |
% \item Let's look at two examples. The first extends the package by adding |
| 4838 |
% some hook-material. If you want status messages, you might write |
| 4839 |
% \begin{verbatim} |
| 4840 |
% \lst@AddToHook{Init}{\message{\MessageBreak Processing listing ...}} |
| 4841 |
% \lst@AddToHook{DeInit}{\message{complete.\MessageBreak}}\end{verbatim} |
| 4842 |
% The second example introduces two keys to let the user control the |
| 4843 |
% messages. The macro |\lst@AddTo| is described in section |
| 4844 |
% \ref{dGeneralPurposeMacros}. |
| 4845 |
% \begin{verbatim} |
| 4846 |
% \lst@BeginAspect{message} |
| 4847 |
% \lst@Key{message}{Annoying message.}{\gdef\lst@message{#1}} |
| 4848 |
% \lst@Key{moremessage}\relax{\lst@AddTo\lst@message{\MessageBreak#1}} |
| 4849 |
% \lst@AddToHook{Init}{\typeout{\MessageBreak\lst@message}} |
| 4850 |
% \lst@EndAspect\end{verbatim} |
| 4851 |
% However, there are certainly aspects which are more useful. |
| 4852 |
% \end{advise} |
| 4853 |
% The following macros can be used in the \meta{definition} argument of the |
| 4854 |
% |\lst@Key| command to evaluate the argument. The additional prefix |KV| |
| 4855 |
% refers to the \packagename{keyval} package. |
| 4856 |
% \begin{syntax} |
| 4857 |
% \item[0.19] |\lstKV@SetIf|\marg{value}\meta{if macro} |
| 4858 |
% |
| 4859 |
% \meta{if macro} becomes |\iftrue| if the first character of |
| 4860 |
% \meta{value} equals |t| or |T|. Otherwise it becomes |\iffalse|. |
| 4861 |
% Usually you will use |#1| as \meta{value}. |
| 4862 |
% |
| 4863 |
% \item[1.0] \cs{lstKV@SwitchCases}\marg{value}\\ |
| 4864 |
% |{|\meta{string 1}|:|\meta{execute 1}|\\|\\ |
| 4865 |
% | |\meta{string 2}|:|\meta{execute 2}|\\|\\ |
| 4866 |
% \hbox to 3em{\hfill\vdots}\\ |
| 4867 |
% | |\meta{string $n$}|;|\meta{execute $n$}|}|\marg{else} |
| 4868 |
% |
| 4869 |
% Either execute \meta{else} or the \meta{value} matching part. |
| 4870 |
% |
| 4871 |
% This implementation is based on a hint of \lsthelper{David~Carlisle}{2016/05/25}{% |
| 4872 |
% http://tex.stackexchange.com/questions/311383/^^A |
| 4873 |
% adding-frame-none-to-lstlisting-options-in-lstdefinestyle^^A |
| 4874 |
% -gives-error-with-tabu} to avoid the problem of the original |
| 4875 |
% implementation of C. Heinz\label{gAmpersand}: |
| 4876 |
% \begin{quote} |
| 4877 |
% \cs{lstKV@SwitchCases}\marg{value}\\ |
| 4878 |
% |{|\meta{string 1}|&|\meta{execute 1}|\\|\\ |
| 4879 |
% | |\meta{string 2}|&|\meta{execute 2}|\\|\\ |
| 4880 |
% \hbox to 3em{\hfill\vdots}\\ |
| 4881 |
% | |\meta{string $n$}|&|\meta{execute $n$}|}|\marg{else} |
| 4882 |
% \end{quote} |
| 4883 |
% The problem arose when the listing was part of a tabular |
| 4884 |
% environment, as found out by |
| 4885 |
% \lsthelper{Nasser~M.~Abbasi}{2016/05/25}{possible bug in listings |
| 4886 |
% package}. |
| 4887 |
% |
| 4888 |
% \item[0.20] |\lstKV@TwoArg|\marg{value}\marg{subdefinition} |
| 4889 |
% \item[0.20] |\lstKV@ThreeArg|\marg{value}\marg{subdefinition} |
| 4890 |
% \item[0.20] |\lstKV@FourArg|\marg{value}\marg{subdefinition} |
| 4891 |
% |
| 4892 |
% \meta{subdefinition} is the replacement text of a macro with two, |
| 4893 |
% three, and four parameters. We call this macro with the arguments given |
| 4894 |
% by \meta{value}. Empty arguments are added if necessary. |
| 4895 |
% |
| 4896 |
% \item[0.19] |\lstKV@OptArg|\oarg{default arg.}\marg{value}\marg{subdefinition} |
| 4897 |
% |
| 4898 |
% |[|\meta{default arg.}|]| is \emph{not} optional. \meta{subdefinition} |
| 4899 |
% is the replacement text of a macro with parameter text |[##1]##2|. |
| 4900 |
% Note that the macro parameter character |#| is doubled since used |
| 4901 |
% within another macro. \meta{subdefinition} accesses these arguments |
| 4902 |
% via |##1| and |##2|. |
| 4903 |
% |
| 4904 |
% \meta{value} is usually the argument |#1| passed by the |
| 4905 |
% \packagename{keyval} package. If \meta{value} has no optional argument, |
| 4906 |
% \meta{default arg.} is inserted to provide the arguments to |
| 4907 |
% \meta{subdefinition}. |
| 4908 |
% |
| 4909 |
% \item[0.21] |\lstKV@XOptArg|\oarg{default arg.}\marg{value}\meta{submacro} |
| 4910 |
% |
| 4911 |
% Same as |\lstKV@OptArg| but the third argument \meta{submacro} is |
| 4912 |
% already a definition and not replacement text. |
| 4913 |
% |
| 4914 |
% \item[0.20] |\lstKV@CSTwoArg|\marg{value}\marg{subdefinition} |
| 4915 |
% |
| 4916 |
% \meta{value} is a \texttt comma \texttt separated list of one or two |
| 4917 |
% arguments. These are given to the subdefinition which is the |
| 4918 |
% replacement text of a macro with two parameters. An empty second |
| 4919 |
% argument is added if necessary. |
| 4920 |
% \end{syntax} |
| 4921 |
% \begin{advise} |
| 4922 |
% \item One more example. The key `\keyname{sensitive}' belongs to the aspect |
| 4923 |
% \aspectname{keywords}. Therefore it is defined in between |
| 4924 |
% `|\lst@BeginAspect{keywords}|' and `|\lst@EndAspect|', which is not shown |
| 4925 |
% here. |
| 4926 |
% \begin{verbatim} |
| 4927 |
% \lst@Key{sensitive}\relax[t]{\lstKV@SetIf{#1}\lst@ifsensitive} |
| 4928 |
% \lst@AddToHookExe{SetLanguage}{\let\lst@ifsensitive\iftrue}\end{verbatim} |
| 4929 |
% The last line is equivalent to |
| 4930 |
% \begin{verbatim} |
| 4931 |
% \lst@AddToHook{SetLanguage}{\let\lst@ifsensitive\iftrue} |
| 4932 |
% \global\let\lst@ifsensitive\iftrue\end{verbatim} |
| 4933 |
% We initialize the variable globally since the user might request an |
| 4934 |
% aspect in a group. Afterwards the variable is used locally---there is |
| 4935 |
% no |\global| in \meta{\TeX\ material}. Note that we could define and |
| 4936 |
% init the key as follows: |
| 4937 |
% \begin{verbatim} |
| 4938 |
% \lst@Key{sensitive}t[t]{\lstKV@SetIf{#1}\lst@ifsensitive} |
| 4939 |
% \lst@AddToHook{SetLanguage}{\let\lst@ifsensitive\iftrue}\end{verbatim} |
| 4940 |
%\end{advise} |
| 4941 |
% |
| 4942 |
% |
| 4943 |
% \subsection{Internal modes}\label{dInternalModes} |
| 4944 |
% |
| 4945 |
% You probably know \TeX's conditional commands |\ifhmode|, |\ifvmode|, |
| 4946 |
% |\ifmmode|, and |\ifinner|. They tell you whether \TeX\ is in (restricted) |
| 4947 |
% horizontal or (internal) vertical or in (nondisplay) mathematical mode. For |
| 4948 |
% example, true |\ifhmode| and true |\ifinner| indicate restricted horizontal |
| 4949 |
% mode, which means that you are in a |\hbox|. The typical user doesn't care |
| 4950 |
% about such modes; \TeX/\LaTeX\ manages all this. But since you're reading the |
| 4951 |
% developer's guide, we discuss the analogue for the \packagename{listings} |
| 4952 |
% package now. It uses modes to distinguish comments from strings, `comment |
| 4953 |
% lines' from `single comments', and so on. |
| 4954 |
% |
| 4955 |
% The package is in `no mode' before reading the source code. In the phase of |
| 4956 |
% initialization it goes to `processing mode'. Afterwards the mode depends on |
| 4957 |
% the actual source code. For example, consider the line |
| 4958 |
% \begin{verbatim} |
| 4959 |
% "string" // comment\end{verbatim} |
| 4960 |
% and assume \texttt{language=C++}. Reading the string delimiter, the package |
| 4961 |
% enters `string mode' and processes the string. The matching closing delimiter |
| 4962 |
% leaves the mode, i.e.\ switches back to the general `processing mode'. Coming |
| 4963 |
% to the two slashes, the package detects a comment line; it therefore enters |
| 4964 |
% `comment line mode' and outputs the slashes. Usually this mode lasts to the |
| 4965 |
% end of line. |
| 4966 |
% |
| 4967 |
% But with \texttt{textcl=true} the \aspectname{escape} aspect immediately |
| 4968 |
% leaves `comment line mode', interrupts the current mode sequence, and enters |
| 4969 |
% `\TeX\ comment line mode'. At the end of line we reenter the previous mode |
| 4970 |
% sequence `no mode' $\to$ 'processing mode'. This escape to \LaTeX\ works |
| 4971 |
% since `no mode' implies that \TeX's characters and catcodes are present, |
| 4972 |
% whereas `processing mode' means that \packagename{listings}' characters and |
| 4973 |
% catcodes are active. |
| 4974 |
% |
| 4975 |
% \begin{table}[htbp] |
| 4976 |
% \caption{Internal modes}\label{dDefinedInternalModes} |
| 4977 |
% \def\lsttabspace{\hspace*{1em}\hfill} |
| 4978 |
% \begin{tabular}{@{}lp{0.56\linewidth}@{}} |
| 4979 |
% aspect\lsttabspace\meta{mode name} & Usage/We are processing \ldots\\ |
| 4980 |
% \noalign{\smallskip} |
| 4981 |
% kernel\lsttabspace |\lst@nomode| & |
| 4982 |
% If this mode is active, \TeX's `character table' is present; the other |
| 4983 |
% implication is not true. Any other mode \emph{may} imply that catcodes |
| 4984 |
% and\nobreak/\allowbreak or definitions of characters are changed. |
| 4985 |
% \\ |
| 4986 |
% \lsttabspace |\lst@Pmode| & |
| 4987 |
% is a general processing mode. If active we are processing a listing, |
| 4988 |
% but haven't entered a more special mode. |
| 4989 |
% \\ |
| 4990 |
% \lsttabspace |\lst@GPmode| & |
| 4991 |
% general purpose mode for language definitions. |
| 4992 |
% \\ |
| 4993 |
% \aspectname{pod}\lsttabspace |\lst@PODmode| & |
| 4994 |
% \ldots~a POD---Perl specific. |
| 4995 |
% \\ |
| 4996 |
% \aspectname{escape}\lsttabspace |\lst@TeXLmode| & |
| 4997 |
% \ldots~a comment line, but \TeX's character table is present---except |
| 4998 |
% the EOL character, which is needed to terminate this mode. |
| 4999 |
% \\ |
| 5000 |
% \lsttabspace |\lst@TeXmode| & |
| 5001 |
% indicates that \TeX's character table is present (except one user |
| 5002 |
% specified character, which is needed to terminate this mode). |
| 5003 |
% \\ |
| 5004 |
% \aspectname{directives}\lsttabspace |\lst@CDmode| & |
| 5005 |
% indicates that the current line began with a compiler directive. |
| 5006 |
% \\ |
| 5007 |
% \aspectname{keywordcomments}\lsttabspace |\lst@KCmode| & |
| 5008 |
% \ldots~a keyword comment. |
| 5009 |
% \\ |
| 5010 |
% \lsttabspace |\lst@KCSmode| & |
| 5011 |
% \ldots~a keyword comment which can be terminated by a semicolon only. |
| 5012 |
% \\ |
| 5013 |
% \aspectname{html}\lsttabspace |\lst@htmlmode| & |
| 5014 |
% Active if we are between \texttt{<} and \texttt{>}. |
| 5015 |
% |
| 5016 |
% Previous documentations used the mode name |\lst@insidemode| at this |
| 5017 |
% place, but the name |\lst@insidemode| isn't referenced in any documentation |
| 5018 |
% and so it is now (from v1.10c on) assumed as an overseen |
| 5019 |
% documentation error. |
| 5020 |
% \\ |
| 5021 |
% \aspectname{make}\lsttabspace |\lst@makemode| & |
| 5022 |
% Used to indicate a keyword. |
| 5023 |
% \end{tabular} |
| 5024 |
% \end{table} |
| 5025 |
% Table \ref{dDefinedInternalModes} lists all static modes and which aspects |
| 5026 |
% they belong to. Most features use dynamically created mode numbers, for |
| 5027 |
% example all strings and comments. Each aspect may define its own mode(s) |
| 5028 |
% simply by allocating it/\allowbreak them inside the aspect definition. |
| 5029 |
% \begin{syntax} |
| 5030 |
% \item[0.19] |\lst@NewMode|\meta{mode \textup(control sequence\textup)} |
| 5031 |
% |
| 5032 |
% defines a new static mode, which is a nonnegative integer assigned to |
| 5033 |
% \meta{mode}. \meta{mode} should have the prefix \texttt{lst@} and |
| 5034 |
% suffix \texttt{mode}. |
| 5035 |
% |
| 5036 |
% \item[0.21] |\lst@UseDynamicMode|\marg{token\textup(s\textup)} |
| 5037 |
% |
| 5038 |
% inserts a dynamic mode number as argument to the token(s). |
| 5039 |
% |
| 5040 |
% This macro cannot be used to get a mode number when an aspect is |
| 5041 |
% loaded or defined. It can only be used every listing in the process |
| 5042 |
% of initialization, e.g.~to define comments when the character table |
| 5043 |
% is selected. |
| 5044 |
% |
| 5045 |
% \item[0.19,,changed] |\lst@EnterMode|\meta{mode}\marg{start tokens} |
| 5046 |
% |
| 5047 |
% opens a group level, enters the mode, and executes \meta{start tokens}. |
| 5048 |
% |
| 5049 |
% Use |\lst@modetrue| in \meta{start tokens} to prohibit future mode |
| 5050 |
% changes---except leaving the mode, of course. You must test yourself |
| 5051 |
% whether you're allowed to enter, see below. |
| 5052 |
% |
| 5053 |
% \item[0.19] |\lst@LeaveMode| |
| 5054 |
% |
| 5055 |
% returns to the previous mode by closing a group level if and only if |
| 5056 |
% the current mode isn't |\lst@nomode| already. You must test yourself |
| 5057 |
% whether you're allowed to leave a mode, see below. |
| 5058 |
% |
| 5059 |
%\iffalse |
| 5060 |
% \item[0.19] |\lst@LeaveAllModes| |
| 5061 |
% |
| 5062 |
% returns to |\lst@nomode|. |
| 5063 |
% This is some kind of emergency macro, so don't use it! |
| 5064 |
%\fi |
| 5065 |
% |
| 5066 |
% \item[0.19] |\lst@InterruptModes| |
| 5067 |
% \item[0.19] |\lst@ReenterModes| |
| 5068 |
% |
| 5069 |
% The first command returns to |\lst@nomode|, but saves the current mode |
| 5070 |
% sequence on a special stack. Afterwards the second macro returns to the |
| 5071 |
% previous mode. In between these commands you may enter any mode you |
| 5072 |
% want. In particular you can interrupt modes, enter some modes, and say |
| 5073 |
% `interrupt modes' again. Then two re-enters will take you back in front |
| 5074 |
% of the first `interrupt modes'. |
| 5075 |
% |
| 5076 |
% Remember that |\lst@nomode| implies that \TeX's character table is |
| 5077 |
% active. |
| 5078 |
% \end{syntax} |
| 5079 |
% Some variables show the internal state of processing. You are allowed to read |
| 5080 |
% them, but \emph{direct write access is prohibited}. Note: |\lst@ifmode| is |
| 5081 |
% \emph{not} obsolete since there is no relation between the boolean and the |
| 5082 |
% current mode. It will happen that we enter a mode without setting |
| 5083 |
% |\lst@ifmode| true, and we'll set it true without assigning any mode! |
| 5084 |
% \begin{syntax} |
| 5085 |
% \item[0.18,,counter] |\lst@mode| |
| 5086 |
% |
| 5087 |
% keeps the current mode number. Use |\ifnum\lst@mode=|\meta{mode name} |
| 5088 |
% to test against a mode. Don't modify the counter directly! |
| 5089 |
% |
| 5090 |
% \item[0.18,,boolean] |\lst@ifmode| |
| 5091 |
% |
| 5092 |
% No mode change is allowed if this boolean is true---except leaving the |
| 5093 |
% current mode. Use |\lst@modetrue| to modify this variable, but do it |
| 5094 |
% only in \meta{start tokens}. |
| 5095 |
% |
| 5096 |
% \item[1.0,,boolean] |\lst@ifLmode| |
| 5097 |
% |
| 5098 |
% Indicates whether the current mode ends at end of line. |
| 5099 |
% \end{syntax} |
| 5100 |
% |
| 5101 |
% |
| 5102 |
% \subsection{Hooks}\label{dHooks} |
| 5103 |
% |
| 5104 |
% Several problems arise if you want to define an aspect. |
| 5105 |
% You should and/or must |
| 5106 |
% (a) find additional functionality (of general interest) and implement it, |
| 5107 |
% (b) create the user interface, and |
| 5108 |
% (c) interface with the \packagename{listings} package, i.e.~find correct |
| 5109 |
% hooks and insert appropriate \TeX\ material. |
| 5110 |
% (a) is out of the scope of this developer's guide. The commands |\lstKV@...| |
| 5111 |
% in section \ref{dHowToDefineLstAspects} might help you with (b). Here now we |
| 5112 |
% describe all hooks of the \packagename{listings} package. |
| 5113 |
% |
| 5114 |
% All hooks are executed inside an overall group. This group starts somewhere |
| 5115 |
% near the beginning and ends somewhere at the end of each listing. Don't make |
| 5116 |
% any other assumptions on grouping. So define variables globally if it's |
| 5117 |
% necessary---and be alert of side effects if you don't use your own groups. |
| 5118 |
% \begin{syntax} |
| 5119 |
% \item \hookname{AfterBeginComment} |
| 5120 |
% |
| 5121 |
% is executed after the package has entered comment mode. |
| 5122 |
% The starting delimiter is usually typeset when the hook is called. |
| 5123 |
% |
| 5124 |
% \item \hookname{BoxUnsafe} |
| 5125 |
% |
| 5126 |
% Contains all material to deactivate all commands and registers which |
| 5127 |
% are possibly unsafe inside |\hbox|. It is used whenever the package |
| 5128 |
% makes a box around a listing and for \packagename{fancyvrb} support. |
| 5129 |
% |
| 5130 |
% \item \hookname{DeInit} |
| 5131 |
% |
| 5132 |
% Called at the very end of a listing but before closing the box from |
| 5133 |
% \hookname{BoxUnsafe} or ending a float. |
| 5134 |
% |
| 5135 |
% \item \hookname{DetectKeywords} |
| 5136 |
% |
| 5137 |
% This \hookname{Output} subhook is executed if and only if mode changes |
| 5138 |
% are allowed, i.e.~if and only if the package doesn't process a comment, |
| 5139 |
% string, and so on---see section \ref{dInternalModes}. |
| 5140 |
% |
| 5141 |
% \item \hookname{DisplayStyle} |
| 5142 |
% |
| 5143 |
% deactivates/activates features for displaystyle listings. |
| 5144 |
% |
| 5145 |
% \item \hookname{EmptyStyle} |
| 5146 |
% |
| 5147 |
% Executed to select the `empty' style---except the user has redefined |
| 5148 |
% the style. |
| 5149 |
% |
| 5150 |
% \item \hookname{EndGroup} |
| 5151 |
% |
| 5152 |
% Executed whenever the package closes a group, e.g.~at end of comment or |
| 5153 |
% string. |
| 5154 |
% |
| 5155 |
% \item \hookname{EOL} |
| 5156 |
% |
| 5157 |
% Called at each end of \emph{input} line, right before |
| 5158 |
% \hookname{InitVarsEOL}. |
| 5159 |
% |
| 5160 |
% \item \hookname{EveryLine} |
| 5161 |
% |
| 5162 |
% Executed at the beginning of each \emph{output} line, i.e.~more than |
| 5163 |
% once for broken lines. This hook must not change the horizontal or |
| 5164 |
% vertical position. |
| 5165 |
% |
| 5166 |
% \item \hookname{EveryPar} |
| 5167 |
% |
| 5168 |
% Executed once for each input line when the output starts. This hook |
| 5169 |
% must not change the horizontal or vertical position. |
| 5170 |
% |
| 5171 |
%^^A \item \hookname{ExcludeDelims} |
| 5172 |
%^^A |
| 5173 |
%^^A Executed by the \keyname{excludedelims} key before the excluded |
| 5174 |
%^^A delimiters are determined. |
| 5175 |
%^^A |
| 5176 |
% \item \hookname{ExitVars} |
| 5177 |
% |
| 5178 |
% Executed right before \hookname{DeInit}. |
| 5179 |
% |
| 5180 |
% \item \hookname{FontAdjust} |
| 5181 |
% |
| 5182 |
% adjusts font specific internal values (currently |\lst@width| only). |
| 5183 |
% |
| 5184 |
% \item \hookname{Init} |
| 5185 |
% |
| 5186 |
% Executed once each listing to initialize things before the character |
| 5187 |
% table is changed. It is called after \hookname{PreInit} and before |
| 5188 |
% \hookname{InitVars}. |
| 5189 |
% |
| 5190 |
% \item \hookname{InitVars} |
| 5191 |
% |
| 5192 |
% Called to init variables each listing. |
| 5193 |
% |
| 5194 |
% \item \hookname{InitVarsBOL} |
| 5195 |
% |
| 5196 |
% initializes variables at the beginning of each input line. |
| 5197 |
% |
| 5198 |
% \item \hookname{InitVarsEOL} |
| 5199 |
% |
| 5200 |
% updates variables at the end of each input line. |
| 5201 |
% |
| 5202 |
% \item \hookname{ModeTrue} |
| 5203 |
% |
| 5204 |
% executed by the package when mode changes become illegal. |
| 5205 |
% Here keyword detection is switched off for comments and strings. |
| 5206 |
% |
| 5207 |
% \item \hookname{OnEmptyLine} |
| 5208 |
% |
| 5209 |
% executed \emph{before} the package outputs an empty line. |
| 5210 |
% |
| 5211 |
% \item \hookname{OnNewLine} |
| 5212 |
% |
| 5213 |
% executed \emph{before} the package starts one or more new lines, |
| 5214 |
% i.e.~before saying |\par\noindent\hbox{}| (roughly speaking). |
| 5215 |
% |
| 5216 |
% \item \hookname{Output} |
| 5217 |
% |
| 5218 |
% Called before an identifier is printed. |
| 5219 |
% If you want a special printing style, modify |\lst@thestyle|. |
| 5220 |
% |
| 5221 |
% \item \hookname{OutputBox} |
| 5222 |
% |
| 5223 |
% used inside each output box. Currently it is only used to make the |
| 5224 |
% package work together with Lambda---hopefully. |
| 5225 |
% |
| 5226 |
% \item \hookname{OutputOther} |
| 5227 |
% |
| 5228 |
% Called before other character strings are printed. |
| 5229 |
% If you want a special printing style, modify |\lst@thestyle|. |
| 5230 |
% |
| 5231 |
% \item \hookname{PostOutput} |
| 5232 |
% |
| 5233 |
% Called after printing an identifier or any other output unit. |
| 5234 |
% |
| 5235 |
% \item \hookname{PostTrackKeywords} |
| 5236 |
% |
| 5237 |
% is a very special \hookname{Init} subhook to insert keyword tests and |
| 5238 |
% define keywords on demand. |
| 5239 |
% This hook is called after \hookname{TrackKeywords}. |
| 5240 |
% |
| 5241 |
% \item \hookname{PreInit} |
| 5242 |
% |
| 5243 |
% Called right before \hookname{Init} hook. |
| 5244 |
% |
| 5245 |
% \item \hookname{PreSet} |
| 5246 |
% |
| 5247 |
% Each typesetting command/environment calls this hook to initialize |
| 5248 |
% internals before any user supplied key is set. |
| 5249 |
% |
| 5250 |
% \item \hookname{SelectCharTable} |
| 5251 |
% |
| 5252 |
% is executed after the package has selected the standard character |
| 5253 |
% table. Aspects adjust the character table here and define string and |
| 5254 |
% comment delimiters, and such. |
| 5255 |
% |
| 5256 |
% \item \hookname{SetFormat} |
| 5257 |
% |
| 5258 |
% Called before internal assignments for setting a format are made. |
| 5259 |
% This hook determines which parameters are reset every format selection. |
| 5260 |
% |
| 5261 |
% \item \hookname{SetStyle} |
| 5262 |
% |
| 5263 |
% Called before internal assignments for setting a style are made. |
| 5264 |
% This hook determines which parameters are reset every style selection. |
| 5265 |
% |
| 5266 |
% \item \hookname{SetLanguage} |
| 5267 |
% |
| 5268 |
% Called before internal assignments for setting a language are made. |
| 5269 |
% This hook determines which parameters are reset every language |
| 5270 |
% selection. |
| 5271 |
% |
| 5272 |
% \item \hookname{TextStyle} |
| 5273 |
% |
| 5274 |
% deactivates/activates features for textstyle listings. |
| 5275 |
% |
| 5276 |
% \item \hookname{TrackKeywords} |
| 5277 |
% |
| 5278 |
% is a very special \hookname{Init} subhook to insert keyword tests and |
| 5279 |
% define keywords on demand. |
| 5280 |
% This hook is called before \hookname{PostTrackKeywords}. |
| 5281 |
% \end{syntax} |
| 5282 |
% |
| 5283 |
% |
| 5284 |
% \subsection{Character tables}\label{dCharacterTables} |
| 5285 |
% |
| 5286 |
% Now you know how a car looks like, and you can get a driving license if you |
| 5287 |
% take some practice. But you will have difficulties if you want to make heavy |
| 5288 |
% alterations to the car. So let's take a closer look and come to the most |
| 5289 |
% difficult part: the engine. We'll have a look at the big picture and fill in |
| 5290 |
% the details step by step. For our purpose it's good to override \TeX's |
| 5291 |
% character table. First we define a standard character table which contains |
| 5292 |
% \begin{itemize} |
| 5293 |
% \item letters: characters identifiers are out of, |
| 5294 |
% \item digits: characters for identifiers or numerical constants, |
| 5295 |
% \item spaces: characters treated as blank spaces, |
| 5296 |
% \item tabulators: characters treated as tabulators, |
| 5297 |
% \item form feeds: characters treated as form feed characters, and |
| 5298 |
% \item others: all other characters. |
| 5299 |
% \end{itemize} |
| 5300 |
% This character table is altered depending on the current programming language. |
| 5301 |
% We may define string and comment delimiters or other special characters. |
| 5302 |
% Table \ref{rStdCharTable} on page \pageref{rStdCharTable} shows the standard |
| 5303 |
% character table. It can be modified with the keys \keyname{alsoletter}, |
| 5304 |
% \keyname{alsodigit}, and \keyname{alsoother}. |
| 5305 |
% |
| 5306 |
% How do these `classes' work together? Let's say that the current character |
| 5307 |
% string is `|tr|'. Then letter `|y|' simply appends the letter and we get |
| 5308 |
% `|try|'. The next nonletter (and nondigit) causes the output of the |
| 5309 |
% characters. Then we collect all coming nonletters until reaching a letter |
| 5310 |
% again. This causes the output of the nonletters, and so on. Internally each |
| 5311 |
% character becomes active in the sense of \TeX\ and is defined to do the right |
| 5312 |
% thing, e.g.~we say |
| 5313 |
% \begin{verbatim} |
| 5314 |
% \def A{\lst@ProcessLetter A}\end{verbatim} |
| 5315 |
% where the first `|A|' is active and the second has letter catcode 11. |
| 5316 |
% The macro |\lst@ProcessLetter| gets one token and treats it as a letter. |
| 5317 |
% The following macros exist, where the last three get no explicit argument. |
| 5318 |
% \begin{syntax} |
| 5319 |
% \item[0.18] |\lst@ProcessLetter| \meta{spec.\ token} |
| 5320 |
% \item[0.18] |\lst@ProcessDigit| \meta{spec.\ token} |
| 5321 |
% \item[0.18] |\lst@ProcessOther| \meta{spec.\ token} |
| 5322 |
% \item[0.18] |\lst@ProcessTabulator| |
| 5323 |
% \item[0.18] |\lst@ProcessSpace| |
| 5324 |
% \item[0.20] |\lst@ProcessFormFeed| |
| 5325 |
% \end{syntax} |
| 5326 |
% \meta{spec.\ token} is supposed to do two things. Usually it expands to |
| 5327 |
% a printable version of the character. But if |\lst@UM| is equivalent to |
| 5328 |
% |\@empty|, \meta{spec.\ token} must expand to a \emph{character token}. |
| 5329 |
% For example, the sharp usually expands to |\#|, which is defined via |
| 5330 |
% |\chardef| and is not a character token. But if |\lst@UM| is equivalent to |
| 5331 |
% |\@empty|, the sharp expands to the character `|#|' (catcode 12). Note: |
| 5332 |
% \emph{Changes to} |\lst@UM| \emph{must be locally.} However, there should |
| 5333 |
% be no need to do such basic things yourself. The \packagename{listings} |
| 5334 |
% package provides advanced macros which use that feature, |
| 5335 |
% e.g.~|\lst@InstallKeywords| in section \ref{dKeywordsAndWorkingIdentifiers}. |
| 5336 |
% |
| 5337 |
% \begin{syntax} |
| 5338 |
% \item[0.18] |\lst@Def|\marg{character code}\meta{parameter text}\marg{definition} |
| 5339 |
% \item[0.18] |\lst@Let|\marg{character code}\meta{token} |
| 5340 |
% |
| 5341 |
% defines the specified character respectively assigns \meta{token}. |
| 5342 |
% The catcode table if not affected. Be careful if your definition has |
| 5343 |
% parameters: it is not safe to read more than one character ahead. |
| 5344 |
% Moreover, the argument can be \emph{arbitrary}; sometimes it's the next |
| 5345 |
% source code character, sometimes it's some code of the |
| 5346 |
% \packagename{listings} package, e.g.~|\relax|, |\@empty|, |\else|, |
| 5347 |
% |\fi|, and so on. Therefore don't use \TeX's ord-operator |`| on such |
| 5348 |
% an argument, e.g.~don't write |\ifnum`#1=65| to test against `|A|'. |
| 5349 |
% |
| 5350 |
% |\lst@Def| and |\lst@Let| are relatively slow. The real definition of |
| 5351 |
% the standard character table differs from the following example, but it |
| 5352 |
% could begin with |
| 5353 |
% \begin{verbatim} |
| 5354 |
% \lst@Def{9}{\lst@ProcessTabulator} |
| 5355 |
% \lst@Def{32}{\lst@ProcessSpace} |
| 5356 |
% \lst@Def{48}{\lst@ProcessDigit 0} |
| 5357 |
% \lst@Def{65}{\lst@ProcessLetter A}\end{verbatim} |
| 5358 |
% |
| 5359 |
%\iffalse |
| 5360 |
% \item[0.20] |\lst@activecharstrue| |
| 5361 |
% \item[0.20] |\lst@activecharsfalse| |
| 5362 |
% |
| 5363 |
% control whether selecting the character table also makes all characters |
| 5364 |
% active (standard/extended). This is usually true and therefore default. |
| 5365 |
% Only the \packagename{fancyvrb} interface sets it locally false. |
| 5366 |
%\fi |
| 5367 |
% \end{syntax} |
| 5368 |
% That's enough for the moment. Section \ref{dUsefulInternalDefinitions} |
| 5369 |
% presents advanced definitions to manipulate the character table, in |
| 5370 |
% particular how to add new comment or string types. |
| 5371 |
% |
| 5372 |
% |
| 5373 |
% \subsection{On the output} |
| 5374 |
% |
| 5375 |
% The \packagename{listings} package uses some variables to keep the output |
| 5376 |
% data. Write access is not recommended. Let's start with the easy ones. |
| 5377 |
% \begin{syntax} |
| 5378 |
% \item[0.17,,data] |\lst@lastother| |
| 5379 |
% |
| 5380 |
% equals \meta{spec.\ token} version of the last processed |
| 5381 |
% nonidentifier-character. Since programming languages redefine the |
| 5382 |
% standard character table, we use the original \meta{spec.\ token}. |
| 5383 |
% For example, if a double quote was processed last, |\lst@lastother| |
| 5384 |
% is not equivalent to the macro which enters and leaves string mode. |
| 5385 |
% It's equivalent to |\lstum@"|, where |"| belongs to the control |
| 5386 |
% sequence. Remember that \meta{spec.\ token} expands either to a |
| 5387 |
% printable or to a token character. |
| 5388 |
% |
| 5389 |
% |\lst@lastother| is equivalent to |\@empty| if such a character is not |
| 5390 |
% available, e.g.~at the beginning of a line. Sometimes an indentifier |
| 5391 |
% has already been printed after processing the last `other' character, |
| 5392 |
% i.e.~the character is far, far away. In this case |\lst@lastother| |
| 5393 |
% equals |\relax|. |
| 5394 |
% |
| 5395 |
% \item[0.17] |\lst@outputspace| |
| 5396 |
% |
| 5397 |
% Use this predefined \meta{spec.\ token} (obviously for character code |
| 5398 |
% 32) to test against |\lst@lastother|. |
| 5399 |
% |
| 5400 |
% \item[0.20] |\lstum@backslash| |
| 5401 |
% |
| 5402 |
% Use this predefined \meta{spec.\ token} (for character code 92) to test |
| 5403 |
% against |\lst@lastother|. In the replacement text for |\lst@Def| one |
| 5404 |
% could write |\ifx| |\lst@lastother| |\lstum@backslash| \ldots\ to test |
| 5405 |
% whether the last character has been a backslash. |
| 5406 |
% |
| 5407 |
% \item[0.20] |\lst@SaveOutputDef|\marg{character code}\meta{macro} |
| 5408 |
% |
| 5409 |
% Stores the \meta{spec.\ token} corresponding to \meta{character code} |
| 5410 |
% in \meta{macro}. This is the only safe way to get a correct meaning to |
| 5411 |
% test against |\lst@lastother|, for example |
| 5412 |
% |\lst@SaveOutputDef{"5C}\lstum@backslash|. |
| 5413 |
% |
| 5414 |
% You'll get a ``runaway argument'' error if \meta{character code} is not |
| 5415 |
% between 33 and 126 (inclusive). |
| 5416 |
% \end{syntax} |
| 5417 |
% Now let's turn to the macros dealing a bit more with the output data and |
| 5418 |
% state. |
| 5419 |
% \begin{syntax} |
| 5420 |
% \item[1.0] |\lst@XPrintToken| |
| 5421 |
% |
| 5422 |
% outputs the current character string and resets it. This macro keeps |
| 5423 |
% track of all variables described here. |
| 5424 |
% |
| 5425 |
% \item[0.18,,token] |\lst@token| |
| 5426 |
% |
| 5427 |
% contains the current character string. Each `character' usually |
| 5428 |
% expands to its printable version, but it must expand to a character |
| 5429 |
% token if |\lst@UM| is equivalent to |\@empty|. |
| 5430 |
% |
| 5431 |
% \item[0.12,,counter] |\lst@length| |
| 5432 |
% |
| 5433 |
% is the length of the current character string. |
| 5434 |
% |
| 5435 |
% \item[0.12,,dimension] |\lst@width| |
| 5436 |
% |
| 5437 |
% is the width of a single character box. |
| 5438 |
% |
| 5439 |
% \item[0.20,,global dimension] |\lst@currlwidth| |
| 5440 |
% |
| 5441 |
% is the width of so far printed line. |
| 5442 |
% |
| 5443 |
% \item[0.18,,global counter] |\lst@column| |
| 5444 |
% \item[0.12,,global counter] |\lst@pos| (nonpositive) |
| 5445 |
% |
| 5446 |
% |\lst@column|$-$|\lst@pos| is the length of the so far printed line. |
| 5447 |
% We use two counters since this simplifies tabulator handling: |
| 5448 |
% |\lst@pos| is a nonpositive representative of `length of so far |
| 5449 |
% printed line' modulo \keyname{tabsize}. |
| 5450 |
% It's usually not the biggest nonpositive representative. |
| 5451 |
% |
| 5452 |
% \item[0.20] |\lst@CalcColumn| |
| 5453 |
% |
| 5454 |
% |\@tempcnta| gets |\lst@column| $-$ |\lst@pos| $+$ |\lst@length|. |
| 5455 |
% This is the current column number minus one, or the current column |
| 5456 |
% number zero based. |
| 5457 |
% |
| 5458 |
% \item[0.18,,global dimension] |\lst@lostspace| |
| 5459 |
% |
| 5460 |
% equals `lost' space: desired current line width minus real line width. |
| 5461 |
% Whenever this dimension is positive the flexible column format can use |
| 5462 |
% this space to fix the column alignment. |
| 5463 |
% \end{syntax} |
| 5464 |
% |
| 5465 |
% |
| 5466 |
% \section{Package extensions}\label{dPackageExtensions} |
| 5467 |
% |
| 5468 |
% |
| 5469 |
% \subsection{Keywords and working identifiers}\label{dKeywordsAndWorkingIdentifiers} |
| 5470 |
% |
| 5471 |
% The \aspectname{keywords} aspect defines two main macros. Their respective |
| 5472 |
% syntax is shown on the left. On the right you'll find examples how the |
| 5473 |
% package actually defines some keys. |
| 5474 |
% \begin{syntax} |
| 5475 |
% \item[0.21] \cs{lst@InstallFamily} |
| 5476 |
% |
| 5477 |
% \marg{prefix}\syntaxfill \texttt k\\ |
| 5478 |
% \marg{name}\syntaxfill |{keywords}|\\ |
| 5479 |
% \marg{style name}\syntaxfill |{keywordstyle}|\\ |
| 5480 |
% \marg{style init}\syntaxfill |\bfseries|\\ |
| 5481 |
% \marg{default style name}\syntaxfill |{keywordstyle}|\\ |
| 5482 |
% \marg{working procedure}\syntaxfill |{}|\\ |
| 5483 |
% \meta{\alternative{l,o}}\syntaxfill |l|\\ |
| 5484 |
% \meta{\alternative{d,o}}\syntaxfill |d| |
| 5485 |
% |
| 5486 |
% installs either a keyword or `working' class of identifiers according |
| 5487 |
% to whether \meta{working procedure} is empty. |
| 5488 |
% |
| 5489 |
% The three keys \meta{name}, \keyname{more}\meta{name} and |
| 5490 |
% \keyname{delete}\meta{name}, and if not empty \meta{style name} are |
| 5491 |
% defined. The first order member of the latter one is initialized with |
| 5492 |
% \meta{style init} if not equivalent to |\relax|. If the user leaves a |
| 5493 |
% class style undefined, \meta{default style name} is used instead. |
| 5494 |
% Thus, make sure that this style is always defined. In the example, |
| 5495 |
% the first order keywordstyle is set to |\bfseries| and is the default |
| 5496 |
% for all other classes. |
| 5497 |
% |
| 5498 |
% If \meta{working procedure} is not empty, this code is executed when |
| 5499 |
% reaching such an (user defined) identifier. \meta{working procedure} |
| 5500 |
% takes exactly one argument, namely the class number to which the |
| 5501 |
% actual identifier belongs to. If the code uses variables and requires |
| 5502 |
% values from previous calls, you must define these variables |
| 5503 |
% |\global|ly. It's not sure whether working procedures are executed |
| 5504 |
% inside a (separate) group or not. |
| 5505 |
% |
| 5506 |
% \texttt l indicates a language key, i.e.~the lists are reset every |
| 5507 |
% language selection. \texttt o stands for `other' key. The keyword |
| 5508 |
% respectively working test is either installed at the |
| 5509 |
% \hookname{DetectKeyword} or \hookname{Output} hook according to |
| 5510 |
% \meta{\alternative{d,o}}. |
| 5511 |
% |
| 5512 |
% \item[0.20] \cs{lst@InstallKeywords} |
| 5513 |
% |
| 5514 |
% \marg{prefix}\syntaxfill \texttt{cs}\\ |
| 5515 |
% \marg{name}\syntaxfill |{texcs}|\\ |
| 5516 |
% \marg{style name}\syntaxfill |{texcsstyle}|\\ |
| 5517 |
% \marg{style init}\syntaxfill |\relax|\\ |
| 5518 |
% \marg{default style name}\syntaxfill |{keywordstyle}|\\ |
| 5519 |
% \marg{working procedure}\syntaxfill see below\\ |
| 5520 |
% \meta{\alternative{l,o}}\syntaxfill |l|\\ |
| 5521 |
% \meta{\alternative{d,o}}\syntaxfill |d| |
| 5522 |
% |
| 5523 |
% Same parameters, same functionality with one execption. The macro |
| 5524 |
% installs exactly one keyword class and not a whole family. Therefore |
| 5525 |
% the argument to \meta{working procedure} is constant (currently |
| 5526 |
% empty). |
| 5527 |
% |
| 5528 |
% The working procedure of the example reads as |
| 5529 |
% follows.\vspace*{-.5\baselineskip} |
| 5530 |
% \begin{verbatim} |
| 5531 |
% {\ifx\lst@lastother\lstum@backslash |
| 5532 |
% \let\lst@thestyle\lst@texcsstyle |
| 5533 |
% \fi}\end{verbatim} |
| 5534 |
% % \vspace*{-.5\baselineskip} |
| 5535 |
% What does this procedure do? First of all it is called only if a keyword |
| 5536 |
% from the user supplied list (or language definition) is found. The |
| 5537 |
% procedure now checks for a preceding backslash and sets the output style |
| 5538 |
% accordingly. |
| 5539 |
% |
| 5540 |
% \iffalse |
| 5541 |
% \item[0.20] |\lst@InstallTest|\marg{prefix}\syntaxbreak |
| 5542 |
% |\lst@|\meta{name}|@list||\lst@|\meta{name}~|\lst@g|\meta{name}|@list|^^A |
| 5543 |
% |\lst@g|\meta{name}\syntaxbreak |
| 5544 |
% |\lst@g|\meta{name}|@sty|~\meta{\alternative{w,s}}\meta{\alternative{d,o}} |
| 5545 |
% |
| 5546 |
% installs a `working identifier' test or keyword style depending on |
| 5547 |
% \meta{\alternative{w,s}}. |\lst@g|\meta{name}|@sty| contains the |
| 5548 |
% working procedure or style macro. Note that the behaviour of the tests |
| 5549 |
% depends on the \texttt{savemem} option. The keyword respectively |
| 5550 |
% working test is either installed at the \hookname{DetectKeyword} or |
| 5551 |
% \hookname{Output} hook according to \meta{\alternative{d,o}}. |
| 5552 |
% |
| 5553 |
% ^^A Either each call of this macro or each different \meta{prefix} |
| 5554 |
% inserts ^^A another test (depending on the \texttt{savemem} option). |
| 5555 |
% |
| 5556 |
% |\lst@|\meta{name} contains the current identifier list and |
| 5557 |
% |\lst@|\meta{name}|@list| a `|\lst@|\meta{$n_i$}|\lst@g|\meta{$n_i$}' |
| 5558 |
% sequence of currently used classes. If no other classes are used, this |
| 5559 |
% equals |\lst@|\meta{name}|\lst@g|\meta{name}. The global versions |
| 5560 |
% |\lst@g|\ldots\ are used to keep track of the keywords. (This |
| 5561 |
% description needs improvement.) |
| 5562 |
% \fi |
| 5563 |
% \end{syntax} |
| 5564 |
% |
| 5565 |
% |
| 5566 |
% \subsection{Delimiters} |
| 5567 |
% |
| 5568 |
% We describe two stages: adding a new delimiter type to an existing class of |
| 5569 |
% delimiters and writing a new class. Each class has its name; currently exist |
| 5570 |
% \texttt{Comment}, \texttt{String}, and \texttt{Delim}. As you know, the |
| 5571 |
% latter and the first both provide the type \texttt l, but there is no string |
| 5572 |
% which starts with the given delimiter and ends at end of line. So we'll add |
| 5573 |
% it now! |
| 5574 |
% |
| 5575 |
% First of all we extend the list of string types by |
| 5576 |
% \begin{verbatim} |
| 5577 |
% \lst@AddTo\lst@stringtypes{,l}\end{verbatim} |
| 5578 |
% Then we must provide the macro which takes the user supplied delimiter and |
| 5579 |
% makes appropriate definitions. The command name consists of the prefix |
| 5580 |
% |\lst@|, the delimiter name, |DM| for using dynamic modes, and |@| followed |
| 5581 |
% by the type. |
| 5582 |
% \begin{verbatim} |
| 5583 |
% \gdef\lst@StringDM@l#1#2\@empty#3#4#5{% |
| 5584 |
% \lst@CArg #2\relax\lst@DefDelimB{}{}{}#3{#1}{#5\lst@Lmodetrue}}\end{verbatim} |
| 5585 |
% You can put these three lines into a \texttt{.sty}-file or surround them by |
| 5586 |
% |\makeatletter| and |\makeatother| in the preamble of a document. |
| 5587 |
% And that's all! |
| 5588 |
%{\makeatletter |
| 5589 |
%\lst@AddTo\lst@stringtypes{,l} |
| 5590 |
%\gdef\lst@StringDM@l#1#2\@empty#3#4#5{^^A |
| 5591 |
% \lst@CArg #2\relax\lst@DefDelimB{}{}{}#3{#1}{#5\lst@Lmodetrue}} |
| 5592 |
%} |
| 5593 |
% \begin{lstsample}{}{} |
| 5594 |
% \lstset{string=[l]//} |
| 5595 |
% \begin{lstlisting} |
| 5596 |
% // This is a string. |
| 5597 |
% This isn't a string. |
| 5598 |
% \end{lstlisting} |
| 5599 |
% \end{lstsample} |
| 5600 |
% You want more details, of course. Let's begin with the arguments. |
| 5601 |
% \begin{itemize} |
| 5602 |
% \item The first argument \emph{after} |\@empty| is used to start the |
| 5603 |
% delimiter. It's provided by the delimiter class. |
| 5604 |
% \item The second argument \emph{after} |\@empty| is used to end the |
| 5605 |
% delimiter. It's also provided by the delimiter class. We didn't |
| 5606 |
% need it in the example, see the explanation below. |
| 5607 |
% \item The third argument \emph{after} |\@empty| is |
| 5608 |
% \marg{style}\meta{start tokens}. |
| 5609 |
% This with a preceding |\def\lst@currstyle| is used as argument to |
| 5610 |
% |\lst@EnterMode|. The delimiter class also provides it. In the |
| 5611 |
% example we `extended' |#5| by |\lst@Lmodetrue| (line mode true). |
| 5612 |
% The mode automatically ends at end of line, so we didn't need the |
| 5613 |
% end-delimiter argument. |
| 5614 |
% \end{itemize} |
| 5615 |
% And now for the other arguments. In case of dynamic modes, the first argument |
| 5616 |
% is the mode number. Then follow the user supplied delimiter(s) whose number |
| 5617 |
% must match the remaining arguments up to |\@empty|. For non-dynamic modes, |
| 5618 |
% you must either allocate a static mode yourself or use a predefined mode |
| 5619 |
% number. The delimiters then start with the first argument. |
| 5620 |
% |
| 5621 |
% Eventually let's look at the replacement text of the macro. The sequence |
| 5622 |
% |\lst@CArg #2\relax| puts two required arguments after |\lst@DefDelimB|. |
| 5623 |
% The syntax of the latter macro is |
| 5624 |
% \begin{syntax} |
| 5625 |
% \item[1.0] \cs{lst@DefDelimB} |
| 5626 |
% |
| 5627 |
% |{|\meta{1st}\meta{2nd}\marg{rest}|}|\syntaxfill |{//{}}|\\ |
| 5628 |
% \meta{save 1st}\syntaxfill |\lst@c/0|\\ |
| 5629 |
% \marg{execute}\syntaxfill|{}|\\ |
| 5630 |
% \marg{delim~exe~modetrue}\syntaxfill|{}|\\ |
| 5631 |
% \marg{delim~exe~modefalse}\syntaxfill|{}|\\ |
| 5632 |
% \meta{start-delimiter macro}\syntaxfill|#3|\\ |
| 5633 |
% \meta{mode number}\syntaxfill |{#1}|\\ |
| 5634 |
% |{|\marg{style}\meta{start tokens}|}|\syntaxfill |{#5\lst@Lmodetrue}| |
| 5635 |
% |
| 5636 |
% defines \meta{1st}\meta{2nd}\meta{rest} as starting-delimiter. |
| 5637 |
% \meta{execute} is executed when the package comes to \meta{1st}. |
| 5638 |
% \meta{delim~exe~modetrue} and \meta{delim~exe~modefalse} are |
| 5639 |
% executed only if the whole delimiter \meta{1st}\meta{2nd}\meta{rest} |
| 5640 |
% is found. Exactly one of them is called depending on |\lst@ifmode|. |
| 5641 |
% |
| 5642 |
% By default the package enters the mode if the delimiter is found |
| 5643 |
% \emph{and} |\lst@ifmode| is false. Internally we make an appropriate |
| 5644 |
% definition of |\lst@bnext|, which can be gobbled by placing |
| 5645 |
% |\@gobblethree| at the very end of \meta{delim exe modefalse}. |
| 5646 |
% One can provide an own definition (and gobble the default). |
| 5647 |
% |
| 5648 |
% \meta{save 1st} must be an undefined macro and is used internally to |
| 5649 |
% store the previous meaning of \meta{1st}. The arguments \meta{2nd} |
| 5650 |
% and/or \meta{rest} are empty if the delimiter has strictly less than |
| 5651 |
% three characters. All characters of \meta{1st}\meta{2nd}\meta{rest} |
| 5652 |
% must already be active (if not empty). |
| 5653 |
% That's not a problem since the macro |\lst@CArgX| does this job. |
| 5654 |
% |
| 5655 |
% \item[1.0] \cs{lst@DefDelimE} |
| 5656 |
% |
| 5657 |
% |{|\meta{1st}\meta{2nd}\marg{rest}|}|\\ |
| 5658 |
% \meta{save 1st}\\ |
| 5659 |
% \marg{execute}\\ |
| 5660 |
% \marg{delim~exe~modetrue}\\ |
| 5661 |
% \marg{delim~exe~modefalse}\\ |
| 5662 |
% \meta{end-delimiter macro}\\ |
| 5663 |
% \meta{mode number} |
| 5664 |
% |
| 5665 |
% Ditto for ending-delimiter with slight differences: |
| 5666 |
% \meta{delim~exe~modetrue} and \meta{delim~exe~modefalse} are executed |
| 5667 |
% depending on whether |\lst@mode| equals \meta{mode}. |
| 5668 |
% |
| 5669 |
% The package ends the mode if the delimiter is found and |\lst@mode| |
| 5670 |
% equals \meta{mode}. Internally we make an appropriate definition of |
| 5671 |
% |\lst@enext| (not |\lst@bnext|), which can be gobbled by placing |
| 5672 |
% |\@gobblethree| at the very end of \meta{delim exe modetrue}. |
| 5673 |
% |
| 5674 |
% \item[1.0] \cs{lst@DefDelimBE} |
| 5675 |
% |
| 5676 |
% followed by the same eight arguments as for |\lst@DefDelimB| and \ldots\\ |
| 5677 |
% \meta{end-delimiter macro} |
| 5678 |
% |
| 5679 |
% This is a combination of |\lst@DefDelimB| and |\lst@DefDelimE| for the |
| 5680 |
% case of starting and ending delimiter being the same. |
| 5681 |
% \end{syntax} |
| 5682 |
% We finish the first stage by examining two easy examples. |
| 5683 |
% \texttt d-type strings are defined by |
| 5684 |
% \begin{verbatim} |
| 5685 |
% \gdef\lst@StringDM@d#1#2\@empty#3#4#5{% |
| 5686 |
% \lst@CArg #2\relax\lst@DefDelimBE{}{}{}#3{#1}{#5}#4}\end{verbatim} |
| 5687 |
% (and an entry in the list of string types). |
| 5688 |
% Not a big deal. Ditto \texttt d-type comments: |
| 5689 |
% \begin{verbatim} |
| 5690 |
% \gdef\lst@CommentDM@s#1#2#3\@empty#4#5#6{% |
| 5691 |
% \lst@CArg #2\relax\lst@DefDelimB{}{}{}#4{#1}{#6}% |
| 5692 |
% \lst@CArg #3\relax\lst@DefDelimE{}{}{}#5{#1}}\end{verbatim} |
| 5693 |
% Here we just need to use both |\lst@DefDelimB| and |\lst@DefDelimE|. |
| 5694 |
% \goodbreak |
| 5695 |
% |
| 5696 |
% So let's get to the second stage. For illustration, here's the definition of |
| 5697 |
% the \texttt{Delim} class. The respective first argument to the service macro |
| 5698 |
% makes it delete all delimiters of the class, add the delimiter, or delete |
| 5699 |
% the particular delimiter only. |
| 5700 |
% \begin{verbatim} |
| 5701 |
% \lst@Key{delim}\relax{\lst@DelimKey\@empty{#1}} |
| 5702 |
% \lst@Key{moredelim}\relax{\lst@DelimKey\relax{#1}} |
| 5703 |
% \lst@Key{deletedelim}\relax{\lst@DelimKey\@nil{#1}}\end{verbatim} |
| 5704 |
% The service macro itself calls another macro with appropriate arguments. |
| 5705 |
% \begin{verbatim} |
| 5706 |
% \gdef\lst@DelimKey#1#2{% |
| 5707 |
% \lst@Delim{}#2\relax{Delim}\lst@delimtypes #1% |
| 5708 |
% {\lst@BeginDelim\lst@EndDelim} |
| 5709 |
% i\@empty{\lst@BeginIDelim\lst@EndIDelim}}\end{verbatim} |
| 5710 |
% We have to look at those arguments. Above you can see the actual arguments |
| 5711 |
% for the \texttt{Delim} class, below are the \texttt{Comment} class ones. |
| 5712 |
% Note that the user supplied value covers the second and third line of |
| 5713 |
% arguments. |
| 5714 |
% \begin{syntax} |
| 5715 |
% \item[0.21,,changed] \cs{lst@Delim} |
| 5716 |
% |
| 5717 |
% \meta{default style macro}\syntaxfill \cs{lst@commentstyle}\\ \relax |
| 5718 |
% [\texttt*[\texttt*]]\texttt[\meta{type}\texttt][\texttt[\meta{style}^^A |
| 5719 |
% \texttt][\texttt[\meta{type option}\texttt]]]\\ |
| 5720 |
% \meta{delimiter\textup(s\textup)}\cs{relax}\syntaxfill|#2|\cs{relax}\\ |
| 5721 |
% \marg{delimiter name}\syntaxfill|{Comment}|\\ |
| 5722 |
% \meta{delimiter types macro}\syntaxfill\texttt{\cs{lst@commenttypes}}\\ |
| 5723 |
% \alternative{\cs{@empty},\cs{@nil},\cs{relax}}\syntaxfill|#1|\\ |
| 5724 |
% \marg{begin- and end-delim macro}\syntaxfill|{|\cs{lst@BeginComment}^^A |
| 5725 |
% \cs{lst@EndComment}|}|\\ |
| 5726 |
% \meta{extra prefix}\syntaxfill |i|\\ |
| 5727 |
% \meta{extra conversion}\syntaxfill |\@empty|\\ |
| 5728 |
% \marg{begin- and end-delim macro}\syntaxfill|{|\cs{lst@BeginIComment}^^A |
| 5729 |
% \cs{lst@EndIComment}|}| |
| 5730 |
% |
| 5731 |
% Most arguments should be clear. We'll discuss the last four. Both |
| 5732 |
% \marg{begin- and end-delim macro} must contain exactly two control |
| 5733 |
% sequences, which are given to |\lst@|\meta{name}[|DM|]|@|\meta{type} |
| 5734 |
% to begin and end a delimiter. These are the arguments |#3| and |#4| |
| 5735 |
% in our first example of |\lst@StringDM@l|. Depending on whether the |
| 5736 |
% user chosen type starts with \meta{extra prefix}, the first two or |
| 5737 |
% the last control sequences are used. |
| 5738 |
% |
| 5739 |
% By default the package takes the delimiter(s), makes the characters |
| 5740 |
% active, and places them after |
| 5741 |
% |\lst@|\meta{name}[|DM|]|@|\meta{type}. If the user type starts with |
| 5742 |
% \meta{extra prefix}, \meta{extra conversion} might change the |
| 5743 |
% definition of |\lst@next| to choose a different conversion. The |
| 5744 |
% default is equivalent to |\lst@XConvert| with |\lst@false|. |
| 5745 |
% |
| 5746 |
% Note that \meta{type} never starts with \meta{extra prefix} since it |
| 5747 |
% is discarded. The functionality must be fully implemented by choosing |
| 5748 |
% a different \marg{begin- and end-delim macro} pair. |
| 5749 |
% \end{syntax} |
| 5750 |
% You might need to know the syntaxes of the \meta{begin- and end-delim macro}s. |
| 5751 |
% They are called as follows. |
| 5752 |
% \begin{syntax} |
| 5753 |
% \item[0.21] |\lst@Begin|\meta{whatever} |
| 5754 |
% |
| 5755 |
% \marg{mode} |
| 5756 |
% |{|\marg{style}\meta{start tokens}|}| |
| 5757 |
% \meta{delimiter}|\@empty| |
| 5758 |
% |
| 5759 |
% \item[0.21] |\lst@End|\meta{whatever} |
| 5760 |
% |
| 5761 |
% \marg{mode} |
| 5762 |
% \meta{delimiter}|\@empty| |
| 5763 |
% \end{syntax} |
| 5764 |
% The existing macros are internally defined in terms of |\lst@DelimOpen| and |
| 5765 |
% |\lst@DelimClose|, see the implementation. |
| 5766 |
% |
| 5767 |
% |
| 5768 |
% \subsection{Getting the kernel run} |
| 5769 |
% |
| 5770 |
% If you want new pretty-printing environments, you should be happy with |
| 5771 |
% section \ref{rEnvironments}. New commands like |\lstinline| or |
| 5772 |
% |\lstinputlisting| are more difficult. Roughly speaking you must follow |
| 5773 |
% these steps. |
| 5774 |
% \begin{enumerate} |
| 5775 |
% \item Open a group to make all changes local. |
| 5776 |
% \item \meta{Do whatever you want.} |
| 5777 |
% \item Call |\lsthk@PreSet| in any case. |
| 5778 |
% \item Now you \emph{might } want to (but need not) use |\lstset| to set some |
| 5779 |
% new values. |
| 5780 |
% \item \meta{Do whatever you want.} |
| 5781 |
% \item Execute |\lst@Init\relax| to finish initialization. |
| 5782 |
% \item \meta{Do whatever you want.} |
| 5783 |
% \item Eventually comes the source code, which is processed by the kernel. |
| 5784 |
% You must ensure that the characters are either not already read or all |
| 5785 |
% active. Moreover \emph{you} must install a way to detect the end of the |
| 5786 |
% source code. If you've reached the end, you must \ldots |
| 5787 |
% \item \ldots\ call |\lst@DeInit| to shutdown the kernel safely. |
| 5788 |
% \item \meta{Do whatever you want.} |
| 5789 |
% \item Close the group from the beginning. |
| 5790 |
% \end{enumerate} |
| 5791 |
% For example, consider the |\lstinline| command in case of being not inside an |
| 5792 |
% argument. Then the steps are as follows. |
| 5793 |
% \begin{enumerate} |
| 5794 |
% \item |\leavevmode\bgroup| opens a group. |
| 5795 |
% \item |\def\lst@boxpos{b}| `baseline' aligns the listing. |
| 5796 |
% \item |\lsthk@PreSet| |
| 5797 |
% \item |\lstset{flexiblecolumns,#1}| (|#1| is the user provided |
| 5798 |
% key=value list) |
| 5799 |
% \item |\lsthk@TextStyle| deactivates all features not safe here. |
| 5800 |
% \item |\lst@Init\relax| |
| 5801 |
% \item |\lst@Def{`#1}{\lst@DeInit\egroup}| installs the `end inline' |
| 5802 |
% detection, where |#1| is the next character after |\lstinline|. |
| 5803 |
% Moreover |chr(13)| is redefined to end the fragment in the same way but |
| 5804 |
% also issues an error message. |
| 5805 |
% \item Now comes the source code and \ldots |
| 5806 |
% \item \ldots\ |\lst@DeInit| (from |\lst@Def| above) ends the code snippet |
| 5807 |
% correctly. |
| 5808 |
% \item Nothing. |
| 5809 |
% \item |\egroup| (also from |\lst@Def|) closes the group. |
| 5810 |
% \end{enumerate} |
| 5811 |
% The real definition is different since we allow source code inside arguments. |
| 5812 |
% Read also section \ref{iTheInputCommand} if you really want to write |
| 5813 |
% pretty-printing commands. |
| 5814 |
% |
| 5815 |
% |
| 5816 |
% \section{Useful internal definitions}\label{dUsefulInternalDefinitions} |
| 5817 |
% |
| 5818 |
% This section requires an update. |
| 5819 |
% |
| 5820 |
% |
| 5821 |
% \subsection{General purpose macros}\label{dGeneralPurposeMacros} |
| 5822 |
% |
| 5823 |
% \begin{syntax} |
| 5824 |
% \item[0.19] |\lst@AddTo|\meta{macro}\marg{\TeX~material} |
| 5825 |
% |
| 5826 |
% adds \meta{\TeX~material} globally to the contents of \meta{macro}. |
| 5827 |
% |
| 5828 |
% \item[0.20] |\lst@Extend|\meta{macro}\marg{\TeX~material} |
| 5829 |
% |
| 5830 |
% calls |\lst@AddTo| after the first token of \meta{\TeX~material} is |
| 5831 |
% |\expand|ed|after|. For example, |\lst@Extend \a \b| merges the |
| 5832 |
% contents of the two macros and stores it globally in |\a|. |
| 5833 |
% |
| 5834 |
% \item[0.19] |\lst@lAddTo|\meta{macro}\marg{\TeX~material} |
| 5835 |
% \item[0.20] |\lst@lExtend|\meta{macro}\marg{\TeX~material} |
| 5836 |
% |
| 5837 |
% are local versions of |\lst@AddTo| and |\lst@Extend|. |
| 5838 |
% |
| 5839 |
% \item[0.18] |\lst@DeleteKeysIn|\meta{macro}\meta{macro \textup(keys to |
| 5840 |
% remove\textup)} |
| 5841 |
% |
| 5842 |
% Both macros contain a comma separated list of keys (or keywords). All |
| 5843 |
% keys appearing in the second macro are removed (locally) from the |
| 5844 |
% first. |
| 5845 |
% |
| 5846 |
% \item[0.19] |\lst@ReplaceIn|\meta{macro}\meta{macro \textup(containing |
| 5847 |
% replacement list\textup)} |
| 5848 |
% \item[0.20] |\lst@ReplaceInArg|\meta{macro}\marg{replacement list} |
| 5849 |
% |
| 5850 |
% The replacement list has the form |
| 5851 |
% $a_1b_1$\ldots$a_nb_n$, where each $a_i$ and |
| 5852 |
% $b_i$ is a character sequence (enclosed in braces if necessary) and |
| 5853 |
% may contain macros, but the first token of |
| 5854 |
% $b_i$ must not be equivalent to |\@empty|. Each sequence |
| 5855 |
% $a_i$ inside the first macro is (locally) replaced by |
| 5856 |
% $b_i$. The suffix |Arg| refers to the \emph{braced} second argument |
| 5857 |
% instead of a (nonbraced) macro. It's a hint that we get the `real' |
| 5858 |
% argument and not a `pointer' to the argument. |
| 5859 |
% |
| 5860 |
% \item[0.20] |\lst@IfSubstring|\marg{character |
| 5861 |
% sequence}\meta{macro}\marg{then}\marg{else} |
| 5862 |
% |
| 5863 |
% \meta{then} is executed if \meta{character sequence} is a substring |
| 5864 |
% of the contents of \meta{macro}. Otherwise \meta{else} is called. |
| 5865 |
% |
| 5866 |
% \item[0.12] |\lst@IfOneOf|\meta{character |
| 5867 |
% sequence}|\relax|\meta{macro}\marg{then}\marg{else} |
| 5868 |
% |
| 5869 |
% |\relax| terminates the first parameter here since it is faster than |
| 5870 |
% enclosing it in braces. \meta{macro} contains a comma separated list |
| 5871 |
% of identifiers. If the character sequence is one of these |
| 5872 |
% indentifiers, \meta{then} is executed, and otherwise \meta{else}. |
| 5873 |
% |
| 5874 |
% \item[0.21] |\lst@Swap|\marg{tok1}\marg{tok2} |
| 5875 |
% |
| 5876 |
% changes places of the following two tokens or arguments |
| 5877 |
% \emph{without} inserting braces. For example, |\lst@Swap{abc}{def}| |
| 5878 |
% expands to |defabc|. |
| 5879 |
% |
| 5880 |
% \item[0.18] |\lst@IfNextChars|\meta{macro}\marg{then}\marg{else} |
| 5881 |
% \item[0.19] |\lst@IfNextCharsArg|\marg{character |
| 5882 |
% sequence}\marg{then}\marg{else} |
| 5883 |
% |
| 5884 |
% Both macros execute either \meta{then} or \meta{else} according to |
| 5885 |
% whether the given character sequence respectively the contents of the |
| 5886 |
% given macro is found (after the three arguments). Note an important |
| 5887 |
% difference between these macros and \LaTeX's |\@ifnextchar|: We |
| 5888 |
% remove the characters behind the arguments until it is possible to |
| 5889 |
% decide which part must be executed. However, we save these characters |
| 5890 |
% in the macro |\lst@eaten|, so they can be inserted using \meta{then} |
| 5891 |
% or \meta{else}. |
| 5892 |
% |
| 5893 |
% \item[0.19] |\lst@IfNextCharActive|\marg{then}\marg{else} |
| 5894 |
% |
| 5895 |
% executes \meta{then} if next character is active, and \meta{else} |
| 5896 |
% otherwise. |
| 5897 |
% |
| 5898 |
% \item[0.20] |\lst@DefActive|\meta{macro}\marg{character sequence} |
| 5899 |
% |
| 5900 |
% stores the character sequence in \meta{macro}, but all characters |
| 5901 |
% become active. The string \emph{must not} contain a begin group, end |
| 5902 |
% group or escape character (|{}\|); it may contain a left brace, right |
| 5903 |
% brace or backslash with other meaning (= catcode). This command would |
| 5904 |
% be quite surplus if \meta{character sequence} is not already read by |
| 5905 |
% \TeX\ since such catcodes can be changed easily. It is explicitly |
| 5906 |
% allowed that the charcaters have been read, e.g.~in |
| 5907 |
% |\def\test{\lst@DefActive\temp{ABC}}|! |
| 5908 |
% |
| 5909 |
% Note that this macro changes |\lccode|s 0--9 without restoring them. |
| 5910 |
% |
| 5911 |
% \item[0.20] |\lst@DefOther|\meta{macro}\marg{character sequence} |
| 5912 |
% |
| 5913 |
% stores \meta{character sequence} in \meta{macro}, but all characters |
| 5914 |
% have catcode 12. Moreover all spaces are removed and control |
| 5915 |
% sequences are converted to their name without preceding |
| 5916 |
% backslash. For example, |\{ Chip \}| leads to |{Chip}| where all |
| 5917 |
% catcodes are 12---internally the primitive |\meaning| is used. |
| 5918 |
% |
| 5919 |
% \iffalse |
| 5920 |
% \item[0.19] |\lst@MakeActive|\marg{character sequence} |
| 5921 |
% |
| 5922 |
% stores the character sequence in |\lst@arg| and has the same |
| 5923 |
% restrictions as |\lst@DefActive|. If fact, the latter definition uses |
| 5924 |
% this macro here. \fi |
| 5925 |
% \end{syntax} |
| 5926 |
% |
| 5927 |
% |
| 5928 |
% \subsection{Character tables manipulated}\label{dCharacterTablesManipulated} |
| 5929 |
% |
| 5930 |
% \begin{syntax} |
| 5931 |
% \item[0.20] |\lst@SaveDef|\marg{character code}\meta{macro} |
| 5932 |
% |
| 5933 |
% Saves the current definition of the specified character in |
| 5934 |
% \meta{macro}. You should always save a character definition before |
| 5935 |
% you redefine it! And use the saved version instead of writing |
| 5936 |
% directly |\lst@Process|\ldots---the character could already be |
| 5937 |
% redefined and thus not equivalent to its standard definition. |
| 5938 |
% |
| 5939 |
% \item[0.20] |\lst@DefSaveDef|\marg{character |
| 5940 |
% code}\meta{macro}\meta{parameter text}\marg{definition} |
| 5941 |
% \item[0.20] |\lst@LetSaveDef|\marg{character |
| 5942 |
% code}\meta{macro}\meta{token} |
| 5943 |
% |
| 5944 |
% combine |\lst@SaveDef| and |\lst@Def| respectively |\lst@Let|. |
| 5945 |
% \end{syntax} |
| 5946 |
% Of course I shouldn't forget to mention \emph{where} to alter the character |
| 5947 |
% table. Hook material at \hookname{SelectCharTable} makes permanent changes, |
| 5948 |
% i.e.~it effects all languages. The following two keys can be used in any |
| 5949 |
% language definition and effects the particular language only. |
| 5950 |
% \begin{syntax} |
| 5951 |
% \item[0.20] |SelectCharTable=|\meta{\TeX\ code} |
| 5952 |
% \item[0.20] |MoreSelectCharTable=|\meta{\TeX\ code} |
| 5953 |
% |
| 5954 |
% uses \meta{\TeX\ code} (additionally) to select the character table. |
| 5955 |
% The code is executed after the standard character table is selected, |
| 5956 |
% but possibly before other aspects make more changes. Since previous |
| 5957 |
% meanings are always saved and executed inside the new definition, this |
| 5958 |
% should be harmless. |
| 5959 |
% \end{syntax} |
| 5960 |
% Here come two rather useless examples. Each point (full stop) will cause a |
| 5961 |
% message `|.|' on the terminal and in the |.log| file if language |useless| is |
| 5962 |
% active: |
| 5963 |
% \begin{verbatim} |
| 5964 |
% \lstdefinelanguage{useless} |
| 5965 |
% {SelectCharTable=\lst@DefSaveDef{46}% save chr(46) ... |
| 5966 |
% \lsts@point % ... in \lsts@point and ... |
| 5967 |
% {\message{.}\lsts@point}% ... use new definition |
| 5968 |
% }\end{verbatim} |
| 5969 |
% If you want to count points, you could write |
| 5970 |
% \begin{verbatim} |
| 5971 |
% \newcount\lst@points % \global |
| 5972 |
% \lst@AddToHook{Init}{\global\lst@points\z@} |
| 5973 |
% \lst@AddToHook{DeInit}{\message{Number of points: \the\lst@points}} |
| 5974 |
% \lstdefinelanguage[2]{useless} |
| 5975 |
% {SelectCharTable=\lst@DefSaveDef{46}\lsts@point |
| 5976 |
% {\global\advance\lst@points\@ne \lsts@point} |
| 5977 |
% }\end{verbatim} |
| 5978 |
% |% \global| indicates that the allocated counter is used globally. We zero |
| 5979 |
% the counter at the beginning of each listing, display a message about the |
| 5980 |
% current value at the end of a listing, and each processed point advances the |
| 5981 |
% counter by one. |
| 5982 |
% |
| 5983 |
% \begin{syntax} |
| 5984 |
% \item[0.21] |\lst@CArg|\meta{active characters}|\relax|\meta{macro} |
| 5985 |
% |
| 5986 |
% The string of active characters is split into \meta{1st}, \meta{2nd}, |
| 5987 |
% and \marg{rest}. If one doesn't exist, an empty argument is |
| 5988 |
% used. Then \meta{macro} is called with |
| 5989 |
% |{|\meta{1st}\meta{2nd}\marg{rest}|}| plus a yet undefined control |
| 5990 |
% sequence \meta{save 1st}. This macro is intended to hold the current |
| 5991 |
% definition of \meta{1st}, so \meta{1st} can be redefined without |
| 5992 |
% loosing information. |
| 5993 |
% |
| 5994 |
% \item[0.19] |\lst@CArgX|\meta{characters}|\relax|\meta{macro} |
| 5995 |
% |
| 5996 |
% makes \meta{characters} active before calling |\lst@CArg|. |
| 5997 |
% |
| 5998 |
% \item[0.21] |\lst@CDef{|\meta{1st}\meta{2nd}\marg{rest}|}|\meta{save |
| 5999 |
% 1st}\marg{execute}\marg{pre}\marg{post} |
| 6000 |
% |
| 6001 |
% should be used in connection with |\lst@CArg| or |\lst@CArgX|, |
| 6002 |
% i.e.~as \meta{macro} there. \meta{1st}, \meta{2nd}, and \meta{rest} |
| 6003 |
% must be active characters and \meta{save 1st} must be an undefined |
| 6004 |
% control sequence. |
| 6005 |
% |
| 6006 |
% Whenever the package reaches the character \meta{1st} (in a listing), |
| 6007 |
% \meta{execute} is executed. If the package detects the whole string |
| 6008 |
% \meta{1st}\meta{2nd}\meta{rest}, we additionally execute \meta{pre}, |
| 6009 |
% then the string, and finally \meta{post}. |
| 6010 |
% |
| 6011 |
% \item[0.21] |\lst@CDefX|\meta{1st}\meta{2nd}\marg{rest}\meta{save |
| 6012 |
% 1st}\marg{execute}\marg{pre}\marg{post} |
| 6013 |
% |
| 6014 |
% Ditto except that we execute \meta{pre} and \meta{post} without the |
| 6015 |
% original string if we reach \meta{1st}\meta{2nd}\meta{rest}. This |
| 6016 |
% means that the string is replaced by \meta{pre}\meta{post} (with |
| 6017 |
% preceding \meta{execute}). |
| 6018 |
% \end{syntax} |
| 6019 |
% As the final example, here's the definition of |\lst@DefDelimB|. |
| 6020 |
% \begin{verbatim} |
| 6021 |
% \gdef\lst@DefDelimB#1#2#3#4#5#6#7#8{% |
| 6022 |
% \lst@CDef{#1}#2% |
| 6023 |
% {#3}% |
| 6024 |
% {\let\lst@bnext\lst@CArgEmpty |
| 6025 |
% \lst@ifmode #4\else |
| 6026 |
% #5% |
| 6027 |
% \def\lst@bnext{#6{#7}{#8}}% |
| 6028 |
% \fi |
| 6029 |
% \lst@bnext}% |
| 6030 |
% \@empty}\end{verbatim} |
| 6031 |
% You got it? |
| 6032 |
% |
| 6033 |
% |
| 6034 |
% \part{Implementation} |
| 6035 |
% |
| 6036 |
% |
| 6037 |
% \CheckSum{12443} |
| 6038 |
%^^A |
| 6039 |
%^^A Don't index TeX-primitives. |
| 6040 |
%^^A |
| 6041 |
% \DoNotIndex{\advance,\afterassignment,\aftergroup,\batchmode,\begingroup} |
| 6042 |
% \DoNotIndex{\box,\catcode,\char,\chardef,\closeout,\copy,\count,\csname,\def} |
| 6043 |
% \DoNotIndex{\dimen,\discretionary,\divide,\dp,\edef,\else,\end,\endcsname} |
| 6044 |
% \DoNotIndex{\endgroup,\endinput,\endlinechar,\escapechar,\everypar} |
| 6045 |
% \DoNotIndex{\expandafter,\fi,\gdef,\global,\globaldefs,\hbadness,\hbox} |
| 6046 |
% \DoNotIndex{\hrulefill,\hss,\ht} |
| 6047 |
% \DoNotIndex{\if,\ifdim,\iffalse,\ifhmode,\ifinner,\ifnum,\ifodd,\iftrue} |
| 6048 |
% \DoNotIndex{\ifvoid,\ifx,\ignorespaces,\immediate,\input,\jobname,\kern} |
| 6049 |
% \DoNotIndex{\lccode,\leftskip,\let,\long,\lower,\lowercase,\meaning,\message} |
| 6050 |
% \DoNotIndex{\multiply,\muskip,\noexpand,\noindent,\openout,\par,\parfillskip} |
| 6051 |
% \DoNotIndex{\parshape,\parskip,\raise,\read,\relax,\rightskip,\setbox,\skip} |
| 6052 |
% \DoNotIndex{\string,\the,\toks,\uppercase,\vbox,\vcenter,\vrule,\vtop,\wd} |
| 6053 |
% \DoNotIndex{\write,\xdef} |
| 6054 |
% |
| 6055 |
%^^A |
| 6056 |
%^^A Don't index LaTeX's private definitions. |
| 6057 |
%^^A |
| 6058 |
% \DoNotIndex{\@@end,\@@par,\@M,\@arabic,\@circlefnt,\@currentlabel} |
| 6059 |
% \DoNotIndex{\@currenvir,\@depth,\@doendpe,\@dottedtocline,\@eha,\@ehc} |
| 6060 |
% \DoNotIndex{\@empty,\@firstofone,\@firstoftwo,\@float,\@for,\@getcirc} |
| 6061 |
% \DoNotIndex{\@gobble,\@gobbletwo,\@halfwidth,\@height,\@ifnextchar} |
| 6062 |
% \DoNotIndex{\@ifundefined,\@ignoretrue,\@makecaption,\@makeother,\@namedef} |
| 6063 |
% \DoNotIndex{\@ne,\@noligs,\@notprerr,\@onlypreamble,\@secondoftwo,\@spaces} |
| 6064 |
% \DoNotIndex{\@starttoc,\@totalleftmargin,\@undefined,\@whilenum} |
| 6065 |
% \DoNotIndex{\@wholewidth,\@width} |
| 6066 |
% \DoNotIndex{\c@chapter,\c@figure,\c@page,\end@float,\f@family,\filename@area} |
| 6067 |
% \DoNotIndex{\filename@base,\filename@ext,\filename@parse,\if@twoside} |
| 6068 |
% \DoNotIndex{\l@ngrel@x,\m@ne,\new@command,\nfss@catcodes,\tw@,\thr@@} |
| 6069 |
% \DoNotIndex{\z@,\zap@space} |
| 6070 |
% |
| 6071 |
%^^A |
| 6072 |
%^^A Don't index LaTeX's package definitions. |
| 6073 |
%^^A |
| 6074 |
% \DoNotIndex{\AtEndOfPackage} |
| 6075 |
% \DoNotIndex{\CurrentOption,\DeclareOption,\IfFileExists,\InputIfFileExists} |
| 6076 |
% \DoNotIndex{\MessageBreak,\NeedsTeXFormat,\PackageError,\PackageWarning} |
| 6077 |
% \DoNotIndex{\ProcessOptions,\ProvidesFile,\ProvidesPackage,\RequirePackage} |
| 6078 |
% |
| 6079 |
%^^A |
| 6080 |
%^^A Don't index LaTeX's public definitions. |
| 6081 |
%^^A |
| 6082 |
% \DoNotIndex{\abovecaptionskip,\active,\addcontentsline,\addtocounter,\begin} |
| 6083 |
% \DoNotIndex{\belowcaptionskip,\bfseries,\bgroup,\bigbreak,\chapter} |
| 6084 |
% \DoNotIndex{\contentsname,\do,\egroup,\footnotesize,\index,\itshape} |
| 6085 |
% \DoNotIndex{\linewidth,\llap,\makeatletter,\newbox,\newcommand,\newcount} |
| 6086 |
% \DoNotIndex{\newcounter,\newdimen,\newtoks,\newwrite,\nointerlineskip} |
| 6087 |
% \DoNotIndex{\normalbaselines,\normalfont,\numberline,\pretolerance,\protect} |
| 6088 |
% \DoNotIndex{\qquad,\refstepcounter,\removelastskip,\renewcommand,\rlap} |
| 6089 |
% \DoNotIndex{\small,\smallbreak,\smallskipamount,\smash,\space,\strut} |
| 6090 |
% \DoNotIndex{\strutbox,\tableofcontents,\textasciicircum,\textasciitilde} |
| 6091 |
% \DoNotIndex{\textasteriskcentered,\textbackslash,\textbar,\textbraceleft} |
| 6092 |
% \DoNotIndex{\textbraceright,\textdollar,\textendash,\textgreater,\textless} |
| 6093 |
% \DoNotIndex{\textunderscore,\textvisiblespace,\thechapter,\ttdefault} |
| 6094 |
% \DoNotIndex{\ttfamily,\typeout,\value,\vphantom} |
| 6095 |
% |
| 6096 |
%^^A |
| 6097 |
%^^A Don't index definitions from other packages. |
| 6098 |
%^^A |
| 6099 |
% \DoNotIndex{\MakePercentComment,\MakePercentIgnore} |
| 6100 |
% |
| 6101 |
%^^A |
| 6102 |
%^^A Don't index 0.19 definitions. |
| 6103 |
%^^A |
| 6104 |
% \DoNotIndex{\listlistingsname,\listoflistings,\lstbox,\lstbox@} |
| 6105 |
% \DoNotIndex{\lstlanguage@} |
| 6106 |
% |
| 6107 |
%^^A |
| 6108 |
%^^A Don't index 0.20 subdefinitions. |
| 6109 |
%^^A |
| 6110 |
% \DoNotIndex{\lst@ATH@,\lst@BOLGobble@,\lst@BOLGobble@@,\lst@CArg@,\lst@CArg@@} |
| 6111 |
% \DoNotIndex{\lst@CBC@,\lst@CBC@@,\lst@CCECUse@,\lst@CCPutMacro@,\lst@DefLang@} |
| 6112 |
% \DoNotIndex{\lst@DefLang@@,\lst@DefOther@,\lst@DeleteKeysIn@,\lst@Escape@} |
| 6113 |
% \DoNotIndex{\lstframe@,\lst@frameH@,\lst@frameL@,\lst@frameR@} |
| 6114 |
% \DoNotIndex{\lst@FillFixed@,\lst@FindAlias@,\lst@FVConvert@} |
| 6115 |
% \DoNotIndex{\lst@IfNextChars@,\lst@IfNextChars@@,\lst@InsideConvert@} |
| 6116 |
% \DoNotIndex{\lst@InstallKeywords@,\lst@Key@,\lst@KeywordTestI@} |
| 6117 |
% \DoNotIndex{\lst@MakeActive@,\lst@MakeMoreKeywords@} |
| 6118 |
% \DoNotIndex{\lst@RC@,\lst@RC@@,\lst@ReplaceIn@,\lst@ReplaceInput@} |
| 6119 |
% \DoNotIndex{\lst@ReportAllocs@,\lst@SKS@,\lst@SKS@@,\lst@UBC@} |
| 6120 |
% \DoNotIndex{\lst@WorkingTestI@,\lstalias@,\lstalias@@,\lstalso@} |
| 6121 |
% \DoNotIndex{\lstdefinestyle@,\lstenv@BOLGobble@@} |
| 6122 |
% \DoNotIndex{\lstenv@ProcessJ@,\lstinline@,\lstKV@OptArg@,\lstKV@SetIf@} |
| 6123 |
% \DoNotIndex{\lstlang@,\lstnewenvironment@,\lst@outputpos,\lstset@} |
| 6124 |
% |
| 6125 |
% |
| 6126 |
% \section{Overture} |
| 6127 |
% |
| 6128 |
% \paragraph{Registers} |
| 6129 |
% For each aspect, the required numbers of registers are listed in section |
| 6130 |
% \lstref{dPackageLoading}. Furthermore, the \packagename{keyval} package |
| 6131 |
% allocates one token register. The macros, boxes and counters |
| 6132 |
% |\@temp|\ldots|a|/|b|, the dimensions |\@tempdim|\ldots, and the macro |
| 6133 |
% |\@gtempa| are also used, see the index. |
| 6134 |
% |
| 6135 |
% \paragraph{Naming conventions} |
| 6136 |
% Let's begin with definitions for the user. All these public macros have |
| 6137 |
% lower case letters and contain |lst|. Private macros and variables use the |
| 6138 |
% following prefixes (not up-to-date?): |
| 6139 |
% \begin{itemize} |
| 6140 |
% \item |\lst@| for a general macro or variable, |
| 6141 |
% \item |\lstenv@| if it is defined for the listing environment, |
| 6142 |
% \item |\lsts@| for |s|aved character meanings, |
| 6143 |
% \item |\lsthk@|\meta{name of hook} holds hook material, |
| 6144 |
% \item |\lst|\meta{prefix}|@| for various kinds of keywords and working |
| 6145 |
% identifiers. |
| 6146 |
% \item |\lstlang@|\meta{language}|@|\meta{dialect} contains a language and |
| 6147 |
% \item |\lststy@|\meta{the style} contains style definition, |
| 6148 |
% \item |\lstpatch@|\meta{aspect} to patch an aspect, |
| 6149 |
% |
| 6150 |
% \item |\lsta@|\meta{language}|$|\meta{dialect} contains alias, |
| 6151 |
% \item |\lsta@|\meta{language} contains alias for all dialects of a language, |
| 6152 |
% \item |\lstdd@|\meta{language} contains default dialect of a language |
| 6153 |
% (if present). |
| 6154 |
% \end{itemize} |
| 6155 |
% To distinguish procedure-like macros from data-macros, the name of procedure |
| 6156 |
% macros use upper case letters with each beginning word, e.g.~|\lst@AddTo|. |
| 6157 |
% A macro with suffix |@| is the main working-procedure for another definition, |
| 6158 |
% for example |\lstMakeShortInline@| does the main work for |\lstMakeShortInline|. |
| 6159 |
% |
| 6160 |
% \paragraph{Preamble} |
| 6161 |
% All files generated from this \texttt{listings.dtx} will get a header. |
| 6162 |
% \begin{macrocode} |
| 6163 |
%<*kernel|misc> |
| 6164 |
%% Please read the software license in listings.dtx or listings.pdf. |
| 6165 |
%% |
| 6166 |
%% (w)(c) 1996--2004 Carsten Heinz and/or any other author listed |
| 6167 |
%% elsewhere in this file. |
| 6168 |
%% (c) 2006 Brooks Moses |
| 6169 |
%% (c) 2013- Jobst Hoffmann |
| 6170 |
%% |
| 6171 |
%% Send comments and ideas on the package, error reports and additional |
| 6172 |
%% programming languages to Jobst Hoffmann at <[email protected]>. |
| 6173 |
%% |
| 6174 |
%</kernel|misc> |
| 6175 |
% \end{macrocode} |
| 6176 |
% |
| 6177 |
% \paragraph{Identification} |
| 6178 |
% All files will have same date and version. |
| 6179 |
% \begin{macrocode} |
| 6180 |
%<*kernel|misc|doc> |
| 6181 |
\def\filedate{2025/11/14} |
| 6182 |
\def\fileversion{1.11b} |
| 6183 |
%</kernel|misc|doc> |
| 6184 |
% \end{macrocode} |
| 6185 |
% What we need and who we are. |
| 6186 |
% \begin{macrocode} |
| 6187 |
%<*kernel> |
| 6188 |
\NeedsTeXFormat{LaTeX2e} |
| 6189 |
\AtEndOfPackage{\ProvidesPackage{listings} |
| 6190 |
[\filedate\space\fileversion\space(Carsten Heinz)]} |
| 6191 |
% \end{macrocode} |
| 6192 |
% \begin{macro}{\lst@CheckVersion} |
| 6193 |
% can be used by the various driver files to guarantee the correct version. |
| 6194 |
% \begin{macrocode} |
| 6195 |
\def\lst@CheckVersion#1{\edef\reserved@a{#1}% |
| 6196 |
\ifx\lst@version\reserved@a \expandafter\@gobble |
| 6197 |
\else \expandafter\@firstofone \fi} |
| 6198 |
% \end{macrocode} |
| 6199 |
% \begin{macrocode} |
| 6200 |
\let\lst@version\fileversion |
| 6201 |
%</kernel> |
| 6202 |
% \end{macrocode} |
| 6203 |
% \end{macro} |
| 6204 |
% For example by the miscellaneous file |
| 6205 |
% \begin{macrocode} |
| 6206 |
%<*misc> |
| 6207 |
\ProvidesFile{lstmisc.sty} |
| 6208 |
[\filedate\space\fileversion\space(Carsten Heinz)] |
| 6209 |
\lst@CheckVersion\fileversion% |
| 6210 |
{\typeout{^^J% |
| 6211 |
***^^J% |
| 6212 |
*** This file requires `listings.sty' version \fileversion.^^J% |
| 6213 |
*** You have a serious problem, so I'm exiting...^^J% |
| 6214 |
***^^J}% |
| 6215 |
\batchmode\@@end} |
| 6216 |
%</misc> |
| 6217 |
% \end{macrocode} |
| 6218 |
% or by the dummy patch. |
| 6219 |
% \begin{macrocode} |
| 6220 |
%<*patch> |
| 6221 |
\ProvidesFile{lstpatch.sty} |
| 6222 |
[\filedate\space\fileversion\space(Carsten Heinz)] |
| 6223 |
\lst@CheckVersion\lst@version{} |
| 6224 |
%%% intentionally empty |
| 6225 |
%</patch> |
| 6226 |
% \end{macrocode} |
| 6227 |
% \begin{macrocode} |
| 6228 |
%<*doc> |
| 6229 |
\ProvidesPackage{lstdoc} |
| 6230 |
[\filedate\space\fileversion\space(Carsten Heinz)] |
| 6231 |
%</doc> |
| 6232 |
% \end{macrocode} |
| 6233 |
% |
| 6234 |
% \paragraph{Category codes} |
| 6235 |
% We define two macros to ensure correct catcodes when we input other files of |
| 6236 |
% the \packagename{listings} package. |
| 6237 |
% |
| 6238 |
% \begin{macro}{\lst@InputCatcodes} |
| 6239 |
% |@| and |"| become letters. Tabulators and EOLs are ignored; this avoids |
| 6240 |
% unwanted spaces---in the case I've forgotten a comment character. |
| 6241 |
% \begin{macrocode} |
| 6242 |
%<*kernel> |
| 6243 |
\def\lst@InputCatcodes{% |
| 6244 |
\makeatletter \catcode`\"12% |
| 6245 |
\catcode`\^^@\active |
| 6246 |
\catcode`\^^I9% |
| 6247 |
\catcode`\^^L9% |
| 6248 |
\catcode`\^^M9% |
| 6249 |
\catcode`\%14% |
| 6250 |
\catcode`\~\active} |
| 6251 |
% \end{macrocode} |
| 6252 |
% \end{macro} |
| 6253 |
% |
| 6254 |
% \begin{macro}{\lst@RestoreCatcodes} |
| 6255 |
% To load the kernel, we will change some catcodes and lccodes. We |
| 6256 |
% restore them at the end of package |
| 6257 |
% loading. \lsthelper{Jobst~Hoffmann}{2000/11/17} {incompatibility with |
| 6258 |
% typehtml package} reported an incompatibility with the |
| 6259 |
% \packagename{typehtml} package, which is resolved by |\lccode`\/`\/| |
| 6260 |
% below. The incompatibility with the \packagename{typehtml} package |
| 6261 |
% was tested again by the current maintainer |
| 6262 |
% (\lsthelper{Jobst~Hoffmann}{2024/10/16} {incompatibility with |
| 6263 |
% typehtml package not more found}) because of a mail from |
| 6264 |
% \lsthelper{Sebastian Ørsted}{2024/10/03}{Bug in listings}, the |
| 6265 |
% incompatibility no longer appeared after the removing the following |
| 6266 |
% line from the |\edef|: |
| 6267 |
% \begin{verbatim} |
| 6268 |
% \noexpand\lccode`\noexpand\/`\noexpand\/\end{verbatim} |
| 6269 |
% So |\lst@RestoreCatcodes| is defined as in v0.21 with a small change |
| 6270 |
% introduced in v1.4 (see p. \pageref{catcode12}). |
| 6271 |
% \begin{macrocode} |
| 6272 |
\def\lst@RestoreCatcodes#1{% |
| 6273 |
\ifx\relax#1\else |
| 6274 |
\noexpand\catcode`\noexpand#1\the\catcode`#1\relax |
| 6275 |
\expandafter\lst@RestoreCatcodes |
| 6276 |
\fi} |
| 6277 |
\edef\lst@RestoreCatcodes{% |
| 6278 |
\lst@RestoreCatcodes\"\^^I\^^M\~\^^@\relax |
| 6279 |
\catcode12\active} |
| 6280 |
% \end{macrocode} |
| 6281 |
% Now we are ready for |
| 6282 |
% \begin{macrocode} |
| 6283 |
\lst@InputCatcodes |
| 6284 |
\AtEndOfPackage{\lst@RestoreCatcodes} |
| 6285 |
%</kernel> |
| 6286 |
% \end{macrocode} |
| 6287 |
% \end{macro} |
| 6288 |
% |
| 6289 |
% \paragraph{Statistics} |
| 6290 |
% \begin{macro}{\lst@GetAllocs} |
| 6291 |
% \begin{macro}{\lst@ReportAllocs} |
| 6292 |
% are used to show the allocated registers. |
| 6293 |
% \begin{macrocode} |
| 6294 |
%<*info> |
| 6295 |
\def\lst@GetAllocs{% |
| 6296 |
\edef\lst@allocs{% |
| 6297 |
0\noexpand\count\the\count10,1\noexpand\dimen\the\count11,% |
| 6298 |
2\noexpand\skip\the\count12,3\noexpand\muskip\the\count13,% |
| 6299 |
4\noexpand\box\the\count14,5\noexpand\toks\the\count15,% |
| 6300 |
6\noexpand\read\the\count16,7\noexpand\write\the\count17}} |
| 6301 |
\def\lst@ReportAllocs{% |
| 6302 |
\message{^^JAllocs:}\def\lst@temp{none}% |
| 6303 |
\expandafter\lst@ReportAllocs@\lst@allocs,\z@\relax\z@,} |
| 6304 |
\def\lst@ReportAllocs@#1#2#3,{% |
| 6305 |
\ifx#2\relax \message{\lst@temp^^J}\else |
| 6306 |
\@tempcnta\count1#1\relax \advance\@tempcnta -#3\relax |
| 6307 |
\ifnum\@tempcnta=\z@\else |
| 6308 |
\let\lst@temp\@empty |
| 6309 |
\message{\the\@tempcnta \string#2,}% |
| 6310 |
\fi |
| 6311 |
\expandafter\lst@ReportAllocs@ |
| 6312 |
\fi} |
| 6313 |
\lst@GetAllocs |
| 6314 |
% \end{macrocode} |
| 6315 |
% \end{macro}\end{macro} |
| 6316 |
% \begingroup |
| 6317 |
% \begin{macrocode} |
| 6318 |
%</info> |
| 6319 |
% \end{macrocode} |
| 6320 |
% \endgroup |
| 6321 |
% |
| 6322 |
% \paragraph{Miscellaneous} |
| 6323 |
% \begin{macro}{\@lst} |
| 6324 |
% Just a definition to save memory space. |
| 6325 |
% \begin{macrocode} |
| 6326 |
%<*kernel> |
| 6327 |
\def\@lst{lst} |
| 6328 |
%</kernel> |
| 6329 |
% \end{macrocode} |
| 6330 |
% \end{macro} |
| 6331 |
% |
| 6332 |
% |
| 6333 |
% \section{General problems} |
| 6334 |
% |
| 6335 |
% All definitions in this section belong to the kernel. |
| 6336 |
% \begin{macrocode} |
| 6337 |
%<*kernel> |
| 6338 |
% \end{macrocode} |
| 6339 |
% |
| 6340 |
% |
| 6341 |
%^^A \subsection{Quick `if parameter empty'} |
| 6342 |
%^^A |
| 6343 |
%^^A There are many situations where you have to look whether a macro parameter is empty. |
| 6344 |
%^^A We have at least two possibilities to test |#1|, for example: |
| 6345 |
%^^A \begin{center} |
| 6346 |
%^^A \begin{minipage}{0.35\linewidth} |
| 6347 |
%^^A \begin{verbatim} |
| 6348 |
%^^A\def\test{#1}% |
| 6349 |
%^^A\ifx \test\empty |
| 6350 |
%^^A % #1 is empty |
| 6351 |
%^^A\else |
| 6352 |
%^^A % #1 is not empty |
| 6353 |
%^^A\fi\end{verbatim} |
| 6354 |
%^^A \end{minipage} |
| 6355 |
%^^A \hskip2em\vrule\hskip2em |
| 6356 |
%^^A \begin{minipage}{0.35\linewidth} |
| 6357 |
%^^A \begin{verbatim} |
| 6358 |
%^^A\ifx \empty#1\empty |
| 6359 |
%^^A % #1 is empty |
| 6360 |
%^^A\else |
| 6361 |
%^^A % #1 is not empty |
| 6362 |
%^^A\fi\end{verbatim} |
| 6363 |
%^^A \end{minipage} |
| 6364 |
%^^A \end{center} |
| 6365 |
%^^A where |\empty| is defined by |\def\empty{}|, of course. |
| 6366 |
%^^A The left variant should be clear and works in any case. |
| 6367 |
%^^A The right-hand side works correct if and only if the first token of |#1| is |
| 6368 |
%^^A not equivalent to |\empty|. |
| 6369 |
%^^A This granted, the |\ifx| is true if and only if |#1| is empty (since |\empty| |
| 6370 |
%^^A left from |#1| is (not) compared with |\empty| on the right). |
| 6371 |
%^^A The two |\empty|s might be replaced by any other macro, which is not |
| 6372 |
%^^A equivalent to the first token of the argument. |
| 6373 |
%^^A But the definition of that macro shouldn't be too complex since this would |
| 6374 |
%^^A slow down the |\ifx|. |
| 6375 |
%^^A The right example needs about $45\%$ of the left's time. |
| 6376 |
%^^A Note that this \TeX{}nique lost its importance from version 0.18 on and that |
| 6377 |
%^^A other packages use |!| or |\relax| instead of |\empty|, for example. |
| 6378 |
%^^A |
| 6379 |
%^^A This \TeX nique is described in ``The \TeX book'' on page 376. |
| 6380 |
% |
| 6381 |
% |
| 6382 |
% \subsection{Substring tests}\label{iSubstringTests} |
| 6383 |
% |
| 6384 |
% \lstset{language=TeX,gobble=4,xleftmargin=20pt,columns=[l]fullflexible,^^A |
| 6385 |
% mathescape,keywordstyle=\ttfamily,texcsstyle=\bfseries} |
| 6386 |
% \let\texverb\lstinline |
| 6387 |
% \lstnewenvironment{texcode}[1][]{\lstset{#1}}{} |
| 6388 |
% \lstset{keywords={def,key}} |
| 6389 |
% |
| 6390 |
% It's easy to decide whether a given character sequence is a substring of |
| 6391 |
% another string. For example, for the substring \texverb|def| we could say |
| 6392 |
% \begin{texcode} |
| 6393 |
% \def \lst@temp#1def#2\relax{% |
| 6394 |
% \ifx \@empty#2\@empty |
| 6395 |
% % "def" is not a substring |
| 6396 |
% \else |
| 6397 |
% % "def" is a substring |
| 6398 |
% \fi} |
| 6399 |
% |
| 6400 |
% \lst@temp $\meta{another\ string}$def\relax |
| 6401 |
% \end{texcode} |
| 6402 |
% When \TeX\ passes the arguments |#1| and |#2|, the second is empty if |
| 6403 |
% and only if \texverb|def| is not a substring. Without the additional |
| 6404 |
% \texverb|def\relax|, one would get a ``runaway argument'' error if |
| 6405 |
% \meta{another string} doesn't contain \texverb|def|. |
| 6406 |
% |
| 6407 |
% We use substring tests mainly in the special case of an identifier and a |
| 6408 |
% comma separated list of keys or keywords: |
| 6409 |
% \begin{texcode}[keywords=key] |
| 6410 |
% \def \lst@temp#1,key,#2\relax{% |
| 6411 |
% \ifx \@empty#2\@empty |
| 6412 |
% % `key' is not a keyword |
| 6413 |
% \else |
| 6414 |
% % `key' is a keyword |
| 6415 |
% \fi} |
| 6416 |
% |
| 6417 |
% \lst@temp,$\meta{list\ of\ keywords}$,key,\relax |
| 6418 |
% \end{texcode} |
| 6419 |
% This works very well and is quite fast. But we can reduce run time in the |
| 6420 |
% case that \texttt{key} is a keyword. Then |#2| takes the rest of the string, |
| 6421 |
% namely all keywords after \texttt{key}. |
| 6422 |
% Since \TeX\ inserts |#2| between the \texverb|\@empty|s, it must drop all of |
| 6423 |
% |#2| except the first character---which is compared with \texverb|\@empty|. |
| 6424 |
% We can redirect this rest to a third parameter: |
| 6425 |
% \begin{texcode}[keywords=key] |
| 6426 |
% \def \lst@temp#1,key,#2#3\relax{% |
| 6427 |
% \ifx \@empty#2% |
| 6428 |
% % "key" is not a keyword |
| 6429 |
% \else |
| 6430 |
% % "key" is a keyword |
| 6431 |
% \fi} |
| 6432 |
% |
| 6433 |
% \lst@temp,$\meta{list\ of\ keywords}$,key,\@empty\relax |
| 6434 |
% \end{texcode} |
| 6435 |
% That's a bit faster and an improvement for version 0.20. |
| 6436 |
% |
| 6437 |
% \begin{macro}{\lst@IfSubstring} |
| 6438 |
% The implementation should be clear from the discussion above. |
| 6439 |
% \begin{macrocode} |
| 6440 |
\def\lst@IfSubstring#1#2{% |
| 6441 |
\def\lst@temp##1#1##2##3\relax{% |
| 6442 |
\ifx \@empty##2\expandafter\@secondoftwo |
| 6443 |
\else \expandafter\@firstoftwo \fi}% |
| 6444 |
\expandafter\lst@temp#2#1\@empty\relax} |
| 6445 |
% \end{macrocode} |
| 6446 |
% \end{macro} |
| 6447 |
% |
| 6448 |
% \begin{macro}{\lst@IfOneOf} |
| 6449 |
% Ditto. |
| 6450 |
% \begin{macrocode} |
| 6451 |
\def\lst@IfOneOf#1\relax#2{% |
| 6452 |
\def\lst@temp##1,#1,##2##3\relax{% |
| 6453 |
\ifx \@empty##2\expandafter\@secondoftwo |
| 6454 |
\else \expandafter\@firstoftwo \fi}% |
| 6455 |
\expandafter\lst@temp\expandafter,#2,#1,\@empty\relax} |
| 6456 |
% \end{macrocode} |
| 6457 |
% \end{macro} |
| 6458 |
% \begin{REMOVED} |
| 6459 |
% One day, if there is need for a case insensitive key(word) test again, we |
| 6460 |
% can use two |\uppercase|s to normalize the first parameter: |
| 6461 |
% \begin{verbatim} |
| 6462 |
%\def\lst@IfOneOfInsensitive#1\relax#2{% |
| 6463 |
% \uppercase{\def\lst@temp##1,#1},##2##3\relax{% |
| 6464 |
% \ifx \@empty##2\expandafter\@secondoftwo |
| 6465 |
% \else \expandafter\@firstoftwo \fi}% |
| 6466 |
% \uppercase{% |
| 6467 |
% \expandafter\lst@temp\expandafter,#2,#1},\@empty\relax}\end{verbatim} |
| 6468 |
% Here we assume that macro |#2| already contains capital characters only, see |
| 6469 |
% the definition of |\lst@MakeMacroUppercase| at the very end of section |
| 6470 |
% \ref{iMakingTests}. If we \emph{must not} assume that, we could simply |
| 6471 |
% insert an |\expandafter| between the second |\uppercase| and the following |
| 6472 |
% brace. But this slows down the tests! |
| 6473 |
% \end{REMOVED} |
| 6474 |
% |
| 6475 |
% \begin{macro}{\lst@DeleteKeysIn} |
| 6476 |
% The submacro does the main work; we only need to expand the second |
| 6477 |
% macro---the list of keys to remove---and append the terminator |\relax|. |
| 6478 |
% \begin{macrocode} |
| 6479 |
\def\lst@DeleteKeysIn#1#2{% |
| 6480 |
\expandafter\lst@DeleteKeysIn@\expandafter#1#2,\relax,} |
| 6481 |
% \end{macrocode} |
| 6482 |
% `Replacing' the very last |\lst@DeleteKeysIn@| by |\lst@RemoveCommas| |
| 6483 |
% terminates the loop here. Note: The |\@empty| after |#2| ensures that this |
| 6484 |
% macro also works if |#2| is empty. |
| 6485 |
% \begin{macrocode} |
| 6486 |
\def\lst@DeleteKeysIn@#1#2,{% |
| 6487 |
\ifx\relax#2\@empty |
| 6488 |
\expandafter\@firstoftwo\expandafter\lst@RemoveCommas |
| 6489 |
\else |
| 6490 |
\ifx\@empty#2\@empty\else |
| 6491 |
% \end{macrocode} |
| 6492 |
% If we haven't reached the end of the list and if the key is not empty, we |
| 6493 |
% define a temporary macro which removes all appearances. |
| 6494 |
% \begin{macrocode} |
| 6495 |
\def\lst@temp##1,#2,##2{% |
| 6496 |
##1% |
| 6497 |
\ifx\@empty##2\@empty\else |
| 6498 |
\expandafter\lst@temp\expandafter,% |
| 6499 |
\fi ##2}% |
| 6500 |
\edef#1{\expandafter\lst@temp\expandafter,#1,#2,\@empty}% |
| 6501 |
\fi |
| 6502 |
\fi |
| 6503 |
\lst@DeleteKeysIn@#1} |
| 6504 |
% \end{macrocode} |
| 6505 |
% \end{macro} |
| 6506 |
% \begin{OLDDEF} |
| 6507 |
% The following modification needs about $50\%$ more run time. |
| 6508 |
% It doesn't use |\edef| and thus also works with |\{| inside |#1|. |
| 6509 |
% However, we don't need that at the moment. |
| 6510 |
% \begin{verbatim} |
| 6511 |
% \def\lst@temp##1,#2,##2{% |
| 6512 |
% \ifx\@empty##2% |
| 6513 |
% \lst@lAddTo#1{##1}% |
| 6514 |
% \else |
| 6515 |
% \lst@lAddTo#1{,##1}% |
| 6516 |
% \expandafter\lst@temp\expandafter,% |
| 6517 |
% \fi ##2}% |
| 6518 |
% \let\@tempa#1\let#1\@empty |
| 6519 |
% \expandafter\lst@temp\expandafter,\@tempa,#2,\@empty\end{verbatim} |
| 6520 |
% \end{OLDDEF} |
| 6521 |
% |
| 6522 |
% \begin{macro}{\lst@RemoveCommas} |
| 6523 |
% The macro drops commas at the beginning and assigns the new value to |#1|. |
| 6524 |
% \begin{macrocode} |
| 6525 |
\def\lst@RemoveCommas#1{\edef#1{\expandafter\lst@RC@#1\@empty}} |
| 6526 |
\def\lst@RC@#1{\ifx,#1\expandafter\lst@RC@ \else #1\fi} |
| 6527 |
% \end{macrocode} |
| 6528 |
% \end{macro} |
| 6529 |
% \begin{OLDDEF} |
| 6530 |
% The following version works with |\{| inside the macro |#1|. |
| 6531 |
% \begin{verbatim} |
| 6532 |
%\def\lst@RemoveCommas#1{\expandafter\lst@RC@#1\@empty #1} |
| 6533 |
%\def\lst@RC@#1{% |
| 6534 |
% \ifx,#1\expandafter\lst@RC@ |
| 6535 |
% \else\expandafter\lst@RC@@\expandafter#1\fi} |
| 6536 |
%\def\lst@RC@@#1\@empty#2{\def#2{#1}}\end{verbatim} |
| 6537 |
% \end{OLDDEF} |
| 6538 |
% |
| 6539 |
% \begin{macro}{\lst@ReplaceIn} |
| 6540 |
% \begin{macro}{\lst@ReplaceInArg} |
| 6541 |
% These macros are similar to |\lst@DeleteKeysIn|, except that \ldots |
| 6542 |
% \begin{macrocode} |
| 6543 |
\def\lst@ReplaceIn#1#2{% |
| 6544 |
\expandafter\lst@ReplaceIn@\expandafter#1#2\@empty\@empty} |
| 6545 |
\def\lst@ReplaceInArg#1#2{\lst@ReplaceIn@#1#2\@empty\@empty} |
| 6546 |
% \end{macrocode} |
| 6547 |
% \ldots\space we replace |#2| by |#3| instead of |,#2,| by a single comma |
| 6548 |
% (which removed the key |#2| above). |
| 6549 |
% \begin{macrocode} |
| 6550 |
\def\lst@ReplaceIn@#1#2#3{% |
| 6551 |
\ifx\@empty#3\relax\else |
| 6552 |
\def\lst@temp##1#2##2{% |
| 6553 |
\ifx\@empty##2% |
| 6554 |
\lst@lAddTo#1{##1}% |
| 6555 |
\else |
| 6556 |
\lst@lAddTo#1{##1#3}\expandafter\lst@temp |
| 6557 |
\fi ##2}% |
| 6558 |
\let\@tempa#1\let#1\@empty |
| 6559 |
\expandafter\lst@temp\@tempa#2\@empty |
| 6560 |
\expandafter\lst@ReplaceIn@\expandafter#1% |
| 6561 |
\fi} |
| 6562 |
% \end{macrocode} |
| 6563 |
% \end{macro} |
| 6564 |
% \end{macro} |
| 6565 |
% |
| 6566 |
% |
| 6567 |
% \subsection{Flow of control} |
| 6568 |
% |
| 6569 |
% \begin{macro}{\@gobblethree} |
| 6570 |
% is defined if and only if undefined. |
| 6571 |
% \begin{macrocode} |
| 6572 |
\providecommand*\@gobblethree[3]{} |
| 6573 |
% \end{macrocode} |
| 6574 |
% \end{macro} |
| 6575 |
% |
| 6576 |
% \begin{macro}{\lst@GobbleNil} |
| 6577 |
% \begin{macrocode} |
| 6578 |
\def\lst@GobbleNil#1\@nil{} |
| 6579 |
% \end{macrocode} |
| 6580 |
% \end{macro} |
| 6581 |
% |
| 6582 |
% \begin{macro}{\lst@Swap} |
| 6583 |
% is just this: |
| 6584 |
% \begin{macrocode} |
| 6585 |
\def\lst@Swap#1#2{#2#1} |
| 6586 |
% \end{macrocode} |
| 6587 |
% \end{macro} |
| 6588 |
% |
| 6589 |
% \begin{macro}{\lst@if} |
| 6590 |
% \begin{macro}{\lst@true} |
| 6591 |
% \begin{macro}{\lst@false} |
| 6592 |
% A general |\if| for temporary use. |
| 6593 |
% \begin{macrocode} |
| 6594 |
\def\lst@true{\let\lst@if\iftrue} |
| 6595 |
\def\lst@false{\let\lst@if\iffalse} |
| 6596 |
\lst@false |
| 6597 |
% \end{macrocode} |
| 6598 |
% \end{macro} |
| 6599 |
% \end{macro} |
| 6600 |
% \end{macro} |
| 6601 |
% |
| 6602 |
% \begin{macro}{\lst@IfNextCharsArg} |
| 6603 |
% is quite easy: We define a macro and call |\lst@IfNextChars|. |
| 6604 |
% \begin{macrocode} |
| 6605 |
\def\lst@IfNextCharsArg#1{% |
| 6606 |
\def\lst@tofind{#1}\lst@IfNextChars\lst@tofind} |
| 6607 |
% \end{macrocode} |
| 6608 |
% \end{macro} |
| 6609 |
% |
| 6610 |
% \begin{macro}{\lst@IfNextChars} |
| 6611 |
% We save the arguments and start a loop. |
| 6612 |
% \begin{macrocode} |
| 6613 |
\def\lst@IfNextChars#1#2#3{% |
| 6614 |
\let\lst@tofind#1\def\@tempa{#2}\def\@tempb{#3}% |
| 6615 |
\let\lst@eaten\@empty \lst@IfNextChars@} |
| 6616 |
% \end{macrocode} |
| 6617 |
% Expand the characters we are looking for. |
| 6618 |
% \begin{macrocode} |
| 6619 |
\def\lst@IfNextChars@{\expandafter\lst@IfNextChars@@\lst@tofind\relax} |
| 6620 |
% \end{macrocode} |
| 6621 |
% Now we can refine |\lst@tofind| and append the input character |#3| to |
| 6622 |
% |\lst@eaten|. |
| 6623 |
% \begin{macrocode} |
| 6624 |
\def\lst@IfNextChars@@#1#2\relax#3{% |
| 6625 |
\def\lst@tofind{#2}\lst@lAddTo\lst@eaten{#3}% |
| 6626 |
\ifx#1#3% |
| 6627 |
% \end{macrocode} |
| 6628 |
% If characters are the same, we either call |\@tempa| or continue the test. |
| 6629 |
% \begin{macrocode} |
| 6630 |
\ifx\lst@tofind\@empty |
| 6631 |
\let\lst@next\@tempa |
| 6632 |
\else |
| 6633 |
\let\lst@next\lst@IfNextChars@ |
| 6634 |
\fi |
| 6635 |
\expandafter\lst@next |
| 6636 |
\else |
| 6637 |
% \end{macrocode} |
| 6638 |
% If the characters are different, we call |\@tempb|. |
| 6639 |
% \begin{macrocode} |
| 6640 |
\expandafter\@tempb |
| 6641 |
\fi} |
| 6642 |
% \end{macrocode} |
| 6643 |
% \end{macro} |
| 6644 |
% |
| 6645 |
% \begin{macro}{\lst@IfNextCharActive} |
| 6646 |
% We compare the character |#3| with its active version |\lowercase{~}|. |
| 6647 |
% Note that the right brace between |\ifx~| and |#3| ends the |\lowercase|. |
| 6648 |
% The |\endgroup| restores the |\lccode|. |
| 6649 |
% \begin{macrocode} |
| 6650 |
\def\lst@IfNextCharActive#1#2#3{% |
| 6651 |
\begingroup \lccode`\~=`#3\lowercase{\endgroup |
| 6652 |
\ifx~}#3% |
| 6653 |
\def\lst@next{#1}% |
| 6654 |
\else |
| 6655 |
\def\lst@next{#2}% |
| 6656 |
\fi \lst@next #3} |
| 6657 |
% \end{macrocode} |
| 6658 |
% \end{macro} |
| 6659 |
% |
| 6660 |
% \begin{macro}{\lst@for} |
| 6661 |
% A for-loop with expansion of the loop-variable. This was improved due to |
| 6662 |
% a suggestion by \lsthelper{Hendri~Adriaens}{2006/03/31}{speedup of |
| 6663 |
% \lst@for}. |
| 6664 |
% \begin{macrocode} |
| 6665 |
\def\lst@for#1\do#2{% |
| 6666 |
\def\lst@forbody##1{#2}% |
| 6667 |
\def\@tempa{#1}% |
| 6668 |
\ifx\@tempa\@empty\else\expandafter\lst@f@r#1,\@nil,\fi |
| 6669 |
} |
| 6670 |
\def\lst@f@r#1,{% |
| 6671 |
\def\@tempa{#1}% |
| 6672 |
\ifx\@tempa\@nnil\else\lst@forbody{#1}\expandafter\lst@f@r\fi |
| 6673 |
} |
| 6674 |
% \end{macrocode} |
| 6675 |
% \end{macro} |
| 6676 |
% |
| 6677 |
% |
| 6678 |
% \subsection{Catcode changes}\label{iCatcodeChanges} |
| 6679 |
% |
| 6680 |
% A character gets its catcode right after reading it and \TeX\ has no |
| 6681 |
% primitive command to change attached catcodes. However, we can replace these |
| 6682 |
% characters by characters with same ASCII codes and different catcodes. |
| 6683 |
% It's not the same but suffices since the result is the same. |
| 6684 |
% Here we treat the very special case that all characters become active. |
| 6685 |
% If we want \texverb|\lst@arg| to contain an active version of the character |
| 6686 |
% |#1|, a prototype macro could be |
| 6687 |
% \begin{texcode} |
| 6688 |
% \def\lst@MakeActive#1{\lccode`\~=`#1\lowercase{\def\lst@arg{~}}} |
| 6689 |
% \end{texcode} |
| 6690 |
% The |\lowercase| changes the ASCII code of |~| to the one of |#1| since we |
| 6691 |
% have said that |#1| is the lower case version of |~|. |
| 6692 |
% Fortunately the |\lowercase| doesn't change the catcode, so we have an active |
| 6693 |
% version of |#1|. |
| 6694 |
% Note that |~| is usually active. |
| 6695 |
% |
| 6696 |
% \begin{macro}{\lst@MakeActive} |
| 6697 |
% We won't do this character by character. |
| 6698 |
% To increase speed we change nine characters at the same time (if nine |
| 6699 |
% characters are left). |
| 6700 |
% \begin{TODO} |
| 6701 |
% This was introduced when the delimiters were converted each listings. Now |
| 6702 |
% this conversion is done only each language selection. So we might want to |
| 6703 |
% implement a character by character conversion again to decrease the memory |
| 6704 |
% usage. |
| 6705 |
% \end{TODO} |
| 6706 |
% We get the argument, empty |\lst@arg| and begin a loop. |
| 6707 |
% \begin{macrocode} |
| 6708 |
\def\lst@MakeActive#1{% |
| 6709 |
\let\lst@temp\@empty \lst@MakeActive@#1% |
| 6710 |
\relax\relax\relax\relax\relax\relax\relax\relax\relax} |
| 6711 |
% \end{macrocode} |
| 6712 |
% There are nine |\relax|es since |\lst@MakeActive@| has nine parameters and we |
| 6713 |
% don't want any problems in the case that |#1| is empty. |
| 6714 |
% We need nine active characters now instead of a single |~|. |
| 6715 |
% We make these catcode changes local and define the coming macro |\global|. |
| 6716 |
% \begin{macrocode} |
| 6717 |
\begingroup |
| 6718 |
\catcode`\^^@=\active \catcode`\^^A=\active \catcode`\^^B=\active |
| 6719 |
\catcode`\^^C=\active \catcode`\^^D=\active \catcode`\^^E=\active |
| 6720 |
\catcode`\^^F=\active \catcode`\^^G=\active \catcode`\^^H=\active |
| 6721 |
% \end{macrocode} |
| 6722 |
% First we |\let| the next operation be |\relax|. |
| 6723 |
% This aborts our loop for processing all characters (default and possibly |
| 6724 |
% changed later). |
| 6725 |
% Then we look if we have at least one character. |
| 6726 |
% If this is not the case, the loop terminates and all is done. |
| 6727 |
% \begin{macrocode} |
| 6728 |
\gdef\lst@MakeActive@#1#2#3#4#5#6#7#8#9{\let\lst@next\relax |
| 6729 |
\ifx#1\relax |
| 6730 |
\else \lccode`\^^@=`#1% |
| 6731 |
% \end{macrocode} |
| 6732 |
% Otherwise we say that |^^@|=|chr(0)| is the lower case version of the first |
| 6733 |
% character. |
| 6734 |
% Then we test the second character. |
| 6735 |
% If there is none, we append the lower case |^^@| to |\lst@temp|. |
| 6736 |
% Otherwise we say that |^^A|=|chr(1)| is the lower case version of the second |
| 6737 |
% character and we test the next argument, and so on. |
| 6738 |
% \begin{macrocode} |
| 6739 |
\ifx#2\relax |
| 6740 |
\lowercase{\lst@lAddTo\lst@temp{^^@}}% |
| 6741 |
\else \lccode`\^^A=`#2% |
| 6742 |
\ifx#3\relax |
| 6743 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A}}% |
| 6744 |
\else \lccode`\^^B=`#3% |
| 6745 |
\ifx#4\relax |
| 6746 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B}}% |
| 6747 |
\else \lccode`\^^C=`#4% |
| 6748 |
\ifx#5\relax |
| 6749 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C}}% |
| 6750 |
\else \lccode`\^^D=`#5% |
| 6751 |
\ifx#6\relax |
| 6752 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C^^D}}% |
| 6753 |
\else \lccode`\^^E=`#6% |
| 6754 |
\ifx#7\relax |
| 6755 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C^^D^^E}}% |
| 6756 |
\else \lccode`\^^F=`#7% |
| 6757 |
\ifx#8\relax |
| 6758 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C^^D^^E^^F}}% |
| 6759 |
\else \lccode`\^^G=`#8% |
| 6760 |
\ifx#9\relax |
| 6761 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C^^D^^E^^F^^G}}% |
| 6762 |
% \end{macrocode} |
| 6763 |
% If nine characters are present, we append (lower case versions of) nine |
| 6764 |
% active characters and call this macro again via redefining |\lst@next|. |
| 6765 |
% \begin{macrocode} |
| 6766 |
\else \lccode`\^^H=`#9% |
| 6767 |
\lowercase{\lst@lAddTo\lst@temp{^^@^^A^^B^^C^^D^^E^^F^^G^^H}}% |
| 6768 |
\let\lst@next\lst@MakeActive@ |
| 6769 |
\fi \fi \fi \fi \fi \fi \fi \fi \fi |
| 6770 |
\lst@next} |
| 6771 |
\endgroup |
| 6772 |
% \end{macrocode} |
| 6773 |
% This |\endgroup| restores the catcodes of |chr(0)|--|chr(8)|, but not the |
| 6774 |
% catcodes of the characters inside |\lst@MakeActive@| since they are already |
| 6775 |
% read. |
| 6776 |
% |
| 6777 |
% Note: A conversion from an arbitrary `catcode--character code' table back to |
| 6778 |
% \TeX's catcodes is possible if we test against the character codes (either |
| 6779 |
% via |\ifnum| or |\ifcase|). |
| 6780 |
% But control sequences and begin and end group characters definitely need |
| 6781 |
% some special treatment. |
| 6782 |
% However I haven't checked the details. |
| 6783 |
% So just ignore this and don't bother me for this note. :\,--\,) |
| 6784 |
% \end{macro} |
| 6785 |
% |
| 6786 |
% \begin{macro}{\lst@DefActive} |
| 6787 |
% An easy application of |\lst@MakeActive|. |
| 6788 |
% \begin{macrocode} |
| 6789 |
\def\lst@DefActive#1#2{\lst@MakeActive{#2}\let#1\lst@temp} |
| 6790 |
% \end{macrocode} |
| 6791 |
% \end{macro} |
| 6792 |
% |
| 6793 |
% \begin{macro}{\lst@DefOther} |
| 6794 |
% We use the fact that |\meaning| produces catcode 12 characters except spaces |
| 6795 |
% stay spaces. |\escapechar| is modified locally to suppress the output of an |
| 6796 |
% escape character. Finally we remove spaces via \LaTeX's |\zap@space|, which |
| 6797 |
% was proposed by \lsthelper{Rolf~Niepraschk}{1997/04/24}{use \zap@space}---not |
| 6798 |
% in this context, but that doesn't matter. |
| 6799 |
% \begin{macrocode} |
| 6800 |
\def\lst@DefOther#1#2{% |
| 6801 |
\begingroup \def#1{#2}\escapechar\m@ne \expandafter\endgroup |
| 6802 |
\expandafter\lst@DefOther@\meaning#1\relax#1} |
| 6803 |
\def\lst@DefOther@#1>#2\relax#3{\edef#3{\zap@space#2 \@empty}} |
| 6804 |
% \end{macrocode} |
| 6805 |
% \end{macro} |
| 6806 |
% |
| 6807 |
% |
| 6808 |
%\ifhyper |
| 6809 |
% \subsection{Applications to \ref*{iCatcodeChanges}}\label{iApplicationsTo} |
| 6810 |
%\else |
| 6811 |
% \subsection{Applications to \ref{iCatcodeChanges}}\label{iApplicationsTo} |
| 6812 |
%\fi |
| 6813 |
% |
| 6814 |
% If an environment is used inside an argument, the listing is already read and |
| 6815 |
% we can do nothing to preserve the catcodes. |
| 6816 |
% However, under certain circumstances the environment can be used inside an |
| 6817 |
% argument---that's at least what I've said in the User's guide. |
| 6818 |
% And now I have to work for it coming true. |
| 6819 |
% Moreover we define an analogous conversion macro for the |
| 6820 |
% \packagename{fancyvrb} mode. |
| 6821 |
% \begin{syntax} |
| 6822 |
% \item[0.19] |\lst@InsideConvert{|\meta{\TeX\ material \textup(already read\textup)}|}| |
| 6823 |
% |
| 6824 |
% \emph{appends} a verbatim version of the argument to |\lst@arg|, but all |
| 6825 |
% appended characters are active. Since it's not a character to character |
| 6826 |
% conversion, `verbatim' needs to be explained. All characters can be |
| 6827 |
% typed in as they are except |\|, |{|, |}| and |%|. If you want one of |
| 6828 |
% these, you must write |\\|, |\{|, |\}| and |\%| instead. |
| 6829 |
% If two spaces should follow each other, the second (third, fourth, |
| 6830 |
% \ldots) space must be entered with a preceding backslash. |
| 6831 |
% |
| 6832 |
% \item[0.19] |\lst@XConvert{|\meta{\TeX\ material \textup(already read\textup)}|}| |
| 6833 |
% |
| 6834 |
% \emph{appends} a `verbatim' version of the argument to |\lst@arg|. |
| 6835 |
% Here \TeX\ material is allowed to be put inside argument braces like |
| 6836 |
% |{(*}{*)}|. The contents of these arguments are converted, the braces |
| 6837 |
% stay as curly braces. |
| 6838 |
% |
| 6839 |
% If |\lst@if| is true, each second argument is treated differently. |
| 6840 |
% Only the first character (of the delimiter) becomes active. |
| 6841 |
% \end{syntax} |
| 6842 |
% |
| 6843 |
% \begin{macro}{\lst@InsideConvert} |
| 6844 |
% If \texttt{mathescape} is not on, we call (near the end of this definition) a |
| 6845 |
% submacro similar to |\zap@space| to replace single spaces by active spaces. |
| 6846 |
% Otherwise we check whether the code contains a pair |$...$| and call the |
| 6847 |
% appropriate macro. |
| 6848 |
% \begin{macrocode} |
| 6849 |
\def\lst@InsideConvert#1{% |
| 6850 |
\lst@ifmathescape |
| 6851 |
\lst@InsideConvert@e#1$\@nil |
| 6852 |
\lst@if |
| 6853 |
\lst@InsideConvert@ey#1\@nil |
| 6854 |
\else |
| 6855 |
\lst@InsideConvert@#1 \@empty |
| 6856 |
\expandafter\@gobbletwo |
| 6857 |
\fi |
| 6858 |
\expandafter\lst@next |
| 6859 |
\else |
| 6860 |
\lst@InsideConvert@#1 \@empty |
| 6861 |
\fi} |
| 6862 |
\begingroup \lccode`\~=`\ \relax \lowercase{% |
| 6863 |
% \end{macrocode} |
| 6864 |
% We make |#1| active and append these characters (plus an active space) to |
| 6865 |
% |\lst@arg|. |
| 6866 |
% If we haven't found the end |\@empty| of the input, we continue the process. |
| 6867 |
% \begin{macrocode} |
| 6868 |
\gdef\lst@InsideConvert@#1 #2{% |
| 6869 |
\lst@MakeActive{#1}% |
| 6870 |
\ifx\@empty#2% |
| 6871 |
\lst@lExtend\lst@arg{\lst@temp}% |
| 6872 |
\else |
| 6873 |
\lst@lExtend\lst@arg{\lst@temp~}% |
| 6874 |
\expandafter\lst@InsideConvert@ |
| 6875 |
\fi #2} |
| 6876 |
% \end{macrocode} |
| 6877 |
% Finally we end the |\lowercase| and close a group. |
| 6878 |
% \begin{macrocode} |
| 6879 |
}\endgroup |
| 6880 |
% \end{macrocode} |
| 6881 |
% The next definition has been used above to check for |$...$| and the following |
| 6882 |
% one keeps the math contents from being converted. This feature was requested by |
| 6883 |
% \lsthelper{Dr.~Jobst~Hoffmann}{}{}. |
| 6884 |
% \begin{macrocode} |
| 6885 |
\def\lst@InsideConvert@e#1$#2\@nil{% |
| 6886 |
\ifx\@empty#2\@empty \lst@false \else \lst@true \fi} |
| 6887 |
\def\lst@InsideConvert@ey#1$#2$#3\@nil{% |
| 6888 |
\lst@InsideConvert@#1 \@empty |
| 6889 |
\lst@lAddTo\lst@arg{% |
| 6890 |
\lst@ifdropinput\else |
| 6891 |
\lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken |
| 6892 |
\setbox\@tempboxa=\hbox\bgroup$\lst@escapebegin |
| 6893 |
#2% |
| 6894 |
\lst@escapeend$\egroup \lst@CalcLostSpaceAndOutput |
| 6895 |
\lst@whitespacefalse |
| 6896 |
\fi}% |
| 6897 |
\def\lst@next{\lst@InsideConvert{#3}}% |
| 6898 |
} |
| 6899 |
% \end{macrocode} |
| 6900 |
% \end{macro} |
| 6901 |
% |
| 6902 |
% \begin{macro}{\lst@XConvert} |
| 6903 |
% Check for an argument \ldots |
| 6904 |
% \begin{macrocode} |
| 6905 |
\def\lst@XConvert{\@ifnextchar\bgroup \lst@XConvertArg\lst@XConvert@} |
| 6906 |
% \end{macrocode} |
| 6907 |
% \ldots, convert the argument, add it together with group delimiters to |
| 6908 |
% |\lst@arg|, and we continue the conversion. |
| 6909 |
% \begin{macrocode} |
| 6910 |
\def\lst@XConvertArg#1{% |
| 6911 |
{\lst@false \let\lst@arg\@empty |
| 6912 |
\lst@XConvert#1\@nil |
| 6913 |
\global\let\@gtempa\lst@arg}% |
| 6914 |
\lst@lExtend\lst@arg{\expandafter{\@gtempa}}% |
| 6915 |
\lst@XConvertNext} |
| 6916 |
% \end{macrocode} |
| 6917 |
% Having no |\bgroup|, we look whether we've found the end of the input, and |
| 6918 |
% convert one token ((non)active character or control sequence) and continue. |
| 6919 |
% \begin{macrocode} |
| 6920 |
\def\lst@XConvert@#1{% |
| 6921 |
\ifx\@nil#1\else |
| 6922 |
\begingroup\lccode`\~=`#1\lowercase{\endgroup |
| 6923 |
\lst@lAddTo\lst@arg~}% |
| 6924 |
\expandafter\lst@XConvertNext |
| 6925 |
\fi} |
| 6926 |
\def\lst@XConvertNext{% |
| 6927 |
\lst@if \expandafter\lst@XConvertX |
| 6928 |
\else \expandafter\lst@XConvert \fi} |
| 6929 |
% \end{macrocode} |
| 6930 |
% Now we make only the first character active. |
| 6931 |
% \begin{macrocode} |
| 6932 |
\def\lst@XConvertX#1{% |
| 6933 |
\ifx\@nil#1\else |
| 6934 |
\lst@XConvertX@#1\relax |
| 6935 |
\expandafter\lst@XConvert |
| 6936 |
\fi} |
| 6937 |
\def\lst@XConvertX@#1#2\relax{% |
| 6938 |
\begingroup\lccode`\~=`#1\lowercase{\endgroup |
| 6939 |
\lst@XCConvertX@@~}{#2}} |
| 6940 |
\def\lst@XCConvertX@@#1#2{\lst@lAddTo\lst@arg{{#1#2}}} |
| 6941 |
% \end{macrocode} |
| 6942 |
% \end{macro} |
| 6943 |
% |
| 6944 |
% |
| 6945 |
% \subsection{Driver file handling*} |
| 6946 |
% |
| 6947 |
% The \packagename{listings} package is split into several driver files, |
| 6948 |
% miscellaneous (= aspect) files, and one kernel file. |
| 6949 |
% All these files can be loaded partially and on demand---except the kernel |
| 6950 |
% which provides this functionality. |
| 6951 |
% \begin{syntax} |
| 6952 |
% \item[0.21] |\lst@Require|\marg{name}\marg{prefix}\marg{feature |
| 6953 |
% list}\meta{alias}\meta{file list macro} |
| 6954 |
% |
| 6955 |
% tries to load all items of \meta{feature list} from the files listed |
| 6956 |
% in \meta{file list macro}. Each item has the form |
| 6957 |
% [\oarg{sub}]\meta{feature}. |\lst@if| equals |\iftrue| if and only |
| 6958 |
% if all items were loadable. |
| 6959 |
% |
| 6960 |
% The macro \meta{alias} gets an item as argument and must define |
| 6961 |
% appropriate versions of |\lst@oalias| and |\lst@malias|. In fact the |
| 6962 |
% feature associated with these definitions is loaded. You can use |
| 6963 |
% \meta{alias}=|\lst@NoAlias| for no substitution. |
| 6964 |
% |
| 6965 |
% \meta{prefix} identifies the type internally and \meta{name} is used |
| 6966 |
% for messages. |
| 6967 |
% |
| 6968 |
% For example, |\lstloadaspects| uses the following arguments where |
| 6969 |
% |#1| is the list of aspects: |{aspects}|\allowbreak|a|\allowbreak |
| 6970 |
% |{#1}|\allowbreak|\lst@NoAlias|\allowbreak|\lstaspectfiles|. |
| 6971 |
% |
| 6972 |
% \item[0.20] |\lst@DefDriver|\marg{name}\marg{prefix}\meta{interface |
| 6973 |
% macro}|\if|\alternative{true,false} |
| 6974 |
% |
| 6975 |
% \item[0.21] |
| 6976 |
% |\lst@IfRequired|\oarg{sub}\marg{feature}\marg{then}\marg{else} |
| 6977 |
% |
| 6978 |
% is used inside a driver file by the aspect, language, or whatever |
| 6979 |
% else defining commands. \meta{then} is executed if and only if |
| 6980 |
% \oarg{sub}\marg{feature} has been requested via |\lst@Require|. |
| 6981 |
% Otherwise \meta{else} is executed---which is also the case for |
| 6982 |
% subsequent calls with the same \oarg{sub}\marg{feature}. |
| 6983 |
% |
| 6984 |
% \meta{then} and \meta{else} may use |\lst@prefix| (read access only). |
| 6985 |
% |
| 6986 |
% |\lst@BeginAspect| in section \ref{iAspectCommands} and |
| 6987 |
% |\lst@DefDriver| serve as examples. |
| 6988 |
% \end{syntax} |
| 6989 |
% |
| 6990 |
% \begin{macro}{\lst@Require} |
| 6991 |
% Initialize variables (if required items aren't empty), \ldots |
| 6992 |
% \begin{macrocode} |
| 6993 |
\def\lst@Require#1#2#3#4#5{% |
| 6994 |
\begingroup |
| 6995 |
\aftergroup\lst@true |
| 6996 |
\ifx\@empty#3\@empty\else |
| 6997 |
\def\lst@prefix{#2}\let\lst@require\@empty |
| 6998 |
% \end{macrocode} |
| 6999 |
% \ldots\space and for each nonempty item: determine alias and add it to |
| 7000 |
% |\lst@require| if it isn't loaded. |
| 7001 |
% \begin{macrocode} |
| 7002 |
\edef\lst@temp{\expandafter\zap@space#3 \@empty}% |
| 7003 |
\lst@for\lst@temp\do{% |
| 7004 |
\ifx\@empty##1\@empty\else \lstKV@OptArg[]{##1}{% |
| 7005 |
#4[####1]{####2}% |
| 7006 |
\@ifundefined{\@lst\lst@prefix @\lst@malias $\lst@oalias}% |
| 7007 |
{\edef\lst@require{\lst@require,\lst@malias $\lst@oalias}}% |
| 7008 |
{}}% |
| 7009 |
\fi}% |
| 7010 |
% \end{macrocode} |
| 7011 |
% Init things and input files if and as long as it is necessary. |
| 7012 |
% \begin{macrocode} |
| 7013 |
\global\let\lst@loadaspects\@empty |
| 7014 |
\lst@InputCatcodes |
| 7015 |
\ifx\lst@require\@empty\else |
| 7016 |
\lst@for{#5}\do{% |
| 7017 |
\ifx\lst@require\@empty\else |
| 7018 |
\InputIfFileExists{##1}{}{}% |
| 7019 |
\fi}% |
| 7020 |
\fi |
| 7021 |
% \end{macrocode} |
| 7022 |
% Issue error and call |\lst@false| (after closing the local group) if some |
| 7023 |
% items weren't loadable. |
| 7024 |
% \begin{macrocode} |
| 7025 |
\ifx\lst@require\@empty\else |
| 7026 |
\PackageError{Listings}{Couldn't load requested #1}% |
| 7027 |
{The following #1s weren't loadable:^^J\@spaces |
| 7028 |
\lst@require^^JThis may cause errors in the sequel.}% |
| 7029 |
\aftergroup\lst@false |
| 7030 |
\fi |
| 7031 |
% \end{macrocode} |
| 7032 |
% Request aspects. |
| 7033 |
% \begin{macrocode} |
| 7034 |
\ifx\lst@loadaspects\@empty\else |
| 7035 |
\lst@RequireAspects\lst@loadaspects |
| 7036 |
\fi |
| 7037 |
\fi |
| 7038 |
\endgroup} |
| 7039 |
% \end{macrocode} |
| 7040 |
% \end{macro} |
| 7041 |
% |
| 7042 |
% \begin{macro}{\lst@IfRequired} |
| 7043 |
% uses |\lst@IfOneOf| and adds some code to \meta{then} part: |
| 7044 |
% delete the now loaded item from the list and define |
| 7045 |
% |\lst|\meta{prefix}|@|\meta{feature}|$|\meta{sub}. |
| 7046 |
% \begin{macrocode} |
| 7047 |
\def\lst@IfRequired[#1]#2{% |
| 7048 |
\lst@NormedDef\lst@temp{[#1]#2}% |
| 7049 |
\expandafter\lst@IfRequired@\lst@temp\relax} |
| 7050 |
\def\lst@IfRequired@[#1]#2\relax#3{% |
| 7051 |
\lst@IfOneOf #2$#1\relax\lst@require |
| 7052 |
{\lst@DeleteKeysIn@\lst@require#2$#1,\relax,% |
| 7053 |
\global\expandafter\let |
| 7054 |
\csname\@lst\lst@prefix @#2$#1\endcsname\@empty |
| 7055 |
#3}} |
| 7056 |
% \end{macrocode} |
| 7057 |
% \end{macro} |
| 7058 |
% |
| 7059 |
% \begin{macro}{\lst@require} |
| 7060 |
% \begin{macrocode} |
| 7061 |
\let\lst@require\@empty |
| 7062 |
% \end{macrocode} |
| 7063 |
% \end{macro} |
| 7064 |
% |
| 7065 |
% \begin{macro}{\lst@NoAlias} |
| 7066 |
% just defines |\lst@oalias| and |\lst@malias|. |
| 7067 |
% \begin{macrocode} |
| 7068 |
\def\lst@NoAlias[#1]#2{% |
| 7069 |
\lst@NormedDef\lst@oalias{#1}\lst@NormedDef\lst@malias{#2}} |
| 7070 |
% \end{macrocode} |
| 7071 |
% \end{macro} |
| 7072 |
% |
| 7073 |
% \begin{macro}{\lst@LAS} |
| 7074 |
% \begin{macrocode} |
| 7075 |
\gdef\lst@LAS#1#2#3#4#5#6#7{% |
| 7076 |
\lst@Require{#1}{#2}{#3}#4#5% |
| 7077 |
#4#3% |
| 7078 |
\@ifundefined{lst#2@\lst@malias$\lst@oalias}% |
| 7079 |
{\PackageError{Listings}% |
| 7080 |
{#1 \ifx\@empty\lst@oalias\else \lst@oalias\space of \fi |
| 7081 |
\lst@malias\space undefined}% |
| 7082 |
{The #1 is not loadable. \@ehc}}% |
| 7083 |
{#6\csname\@lst#2@\lst@malias $\lst@oalias\endcsname #7}} |
| 7084 |
% \end{macrocode} |
| 7085 |
% \end{macro} |
| 7086 |
% |
| 7087 |
% \begin{macro}{\lst@RequireAspects} |
| 7088 |
% \begin{macro}{\lstloadaspects} |
| 7089 |
% make use of the just developped definitions. |
| 7090 |
% \begin{macrocode} |
| 7091 |
\def\lst@RequireAspects#1{% |
| 7092 |
\lst@Require{aspect}{asp}{#1}\lst@NoAlias\lstaspectfiles} |
| 7093 |
\let\lstloadaspects\lst@RequireAspects |
| 7094 |
% \end{macrocode} |
| 7095 |
% \end{macro} |
| 7096 |
% \end{macro} |
| 7097 |
% |
| 7098 |
% \begin{macro}{\lstaspectfiles} |
| 7099 |
% This macro is defined if and only if it's undefined yet. |
| 7100 |
% \begin{macrocode} |
| 7101 |
\@ifundefined{lstaspectfiles} |
| 7102 |
{\newcommand\lstaspectfiles{lstmisc0.sty,lstmisc.sty}}{} |
| 7103 |
% \end{macrocode} |
| 7104 |
% \end{macro} |
| 7105 |
% |
| 7106 |
% \begin{macro}{\lst@DefDriver} |
| 7107 |
% Test the next character and reinsert the arguments. |
| 7108 |
% \begin{macrocode} |
| 7109 |
\gdef\lst@DefDriver#1#2#3#4{% |
| 7110 |
\@ifnextchar[{\lst@DefDriver@{#1}{#2}#3#4}% |
| 7111 |
{\lst@DefDriver@{#1}{#2}#3#4[]}} |
| 7112 |
% \end{macrocode} |
| 7113 |
% We set |\lst@if| locally true if the item has been requested. |
| 7114 |
% \begin{macrocode} |
| 7115 |
\gdef\lst@DefDriver@#1#2#3#4[#5]#6{% |
| 7116 |
\def\lst@name{#1}\let\lst@if#4% |
| 7117 |
\lst@NormedDef\lst@driver{\@lst#2@#6$#5}% |
| 7118 |
\lst@IfRequired[#5]{#6}{\begingroup \lst@true}% |
| 7119 |
{\begingroup}% |
| 7120 |
\lst@setcatcodes |
| 7121 |
\@ifnextchar[{\lst@XDefDriver{#1}#3}{\lst@DefDriver@@#3}} |
| 7122 |
% \end{macrocode} |
| 7123 |
% Note that |\lst@XDefDriver| takes optional `base' arguments, but eventually |
| 7124 |
% calls |\lst@DefDriver@@|. We define the item (in case of need), and |
| 7125 |
% |\endgroup| resets some catcodes and |\lst@if|, i.e.~|\lst@XXDefDriver| knows |
| 7126 |
% whether called by a public or internal command. |
| 7127 |
% \begin{macrocode} |
| 7128 |
\gdef\lst@DefDriver@@#1#2{% |
| 7129 |
\lst@if |
| 7130 |
\global\@namedef{\lst@driver}{#1{#2}}% |
| 7131 |
\fi |
| 7132 |
\endgroup |
| 7133 |
\@ifnextchar[\lst@XXDefDriver\@empty} |
| 7134 |
% \end{macrocode} |
| 7135 |
% We get the aspect argument, and (if not empty) load the aspects immediately |
| 7136 |
% if called by a public command or extend the list of required aspects or |
| 7137 |
% simply ignore the argument if the item leaves undefined. |
| 7138 |
% \begin{macrocode} |
| 7139 |
\gdef\lst@XXDefDriver[#1]{% |
| 7140 |
\ifx\@empty#1\@empty\else |
| 7141 |
\lst@if |
| 7142 |
\lstloadaspects{#1}% |
| 7143 |
\else |
| 7144 |
\@ifundefined{\lst@driver}{}% |
| 7145 |
{\xdef\lst@loadaspects{\lst@loadaspects,#1}}% |
| 7146 |
\fi |
| 7147 |
\fi} |
| 7148 |
% \end{macrocode} |
| 7149 |
% We insert an additional `also'key=value pair. |
| 7150 |
% \begin{macrocode} |
| 7151 |
\gdef\lst@XDefDriver#1#2[#3]#4#5{\lst@DefDriver@@#2{also#1=[#3]#4,#5}} |
| 7152 |
% \end{macrocode} |
| 7153 |
% \end{macro} |
| 7154 |
% |
| 7155 |
% |
| 7156 |
% \subsection{Aspect commands}\label{iAspectCommands} |
| 7157 |
% |
| 7158 |
% This section contains commands used in defining `\lst-aspects'. |
| 7159 |
% \begin{macro}{\lst@UserCommand} |
| 7160 |
% is mainly equivalent to |\gdef|. |
| 7161 |
% \begin{macrocode} |
| 7162 |
%<!info>\let\lst@UserCommand\gdef |
| 7163 |
%<info>\def\lst@UserCommand#1{\message{\string#1,}\gdef#1} |
| 7164 |
% \end{macrocode} |
| 7165 |
% \end{macro} |
| 7166 |
% |
| 7167 |
% \begin{macro}{\lst@BeginAspect} |
| 7168 |
% A straight-forward implementation: |
| 7169 |
% \begin{macrocode} |
| 7170 |
\newcommand*\lst@BeginAspect[2][]{% |
| 7171 |
\def\lst@curraspect{#2}% |
| 7172 |
\ifx \lst@curraspect\@empty |
| 7173 |
\expandafter\lst@GobbleAspect |
| 7174 |
\else |
| 7175 |
% \end{macrocode} |
| 7176 |
% If \meta{aspect name} is not empty, there are certain other conditions not to |
| 7177 |
% define the aspect (as described in section \ref{dHowToDefineLstAspects}). |
| 7178 |
% \begin{macrocode} |
| 7179 |
%<!info> \let\lst@next\@empty |
| 7180 |
%<info> \def\lst@next{% |
| 7181 |
%<info> \message{^^JDefine lst-aspect `#2':}\lst@GetAllocs}% |
| 7182 |
\lst@IfRequired[]{#2}% |
| 7183 |
{\lst@RequireAspects{#1}% |
| 7184 |
\lst@if\else \let\lst@next\lst@GobbleAspect \fi}% |
| 7185 |
{\let\lst@next\lst@GobbleAspect}% |
| 7186 |
\expandafter\lst@next |
| 7187 |
\fi} |
| 7188 |
% \end{macrocode} |
| 7189 |
% \end{macro} |
| 7190 |
% |
| 7191 |
% \begin{macro}{\lst@EndAspect} |
| 7192 |
% finishes an aspect definition. |
| 7193 |
% \begin{macrocode} |
| 7194 |
\def\lst@EndAspect{% |
| 7195 |
\csname\@lst patch@\lst@curraspect\endcsname |
| 7196 |
%<info> \lst@ReportAllocs |
| 7197 |
\let\lst@curraspect\@empty} |
| 7198 |
% \end{macrocode} |
| 7199 |
% \end{macro} |
| 7200 |
% |
| 7201 |
% \begin{macro}{\lst@GobbleAspect} |
| 7202 |
% drops all code up to the next |\lst@EndAspect|. |
| 7203 |
% \begin{macrocode} |
| 7204 |
\long\def\lst@GobbleAspect#1\lst@EndAspect{\let\lst@curraspect\@empty} |
| 7205 |
% \end{macrocode} |
| 7206 |
% \end{macro} |
| 7207 |
% |
| 7208 |
% \begin{macro}{\lst@Key} |
| 7209 |
% The command simply defines the key. But we must take care of an optional |
| 7210 |
% parameter and the initialization argument |#2|. |
| 7211 |
% \begin{macrocode} |
| 7212 |
\def\lst@Key#1#2{% |
| 7213 |
%<info> \message{#1,}% |
| 7214 |
\@ifnextchar[{\lstKV@def{#1}{#2}}% |
| 7215 |
{\def\lst@temp{\lst@Key@{#1}{#2}} |
| 7216 |
\afterassignment\lst@temp |
| 7217 |
\global\@namedef{KV@\@lst @#1}####1}} |
| 7218 |
% \end{macrocode} |
| 7219 |
% Now comes a renamed and modified copy from a \packagename{keyval} macro: |
| 7220 |
% We need global key definitions. |
| 7221 |
% \begin{macrocode} |
| 7222 |
\def\lstKV@def#1#2[#3]{% |
| 7223 |
\global\@namedef{KV@\@lst @#1@default\expandafter}\expandafter |
| 7224 |
{\csname KV@\@lst @#1\endcsname{#3}}% |
| 7225 |
\def\lst@temp{\lst@Key@{#1}{#2}}\afterassignment\lst@temp |
| 7226 |
\global\@namedef{KV@\@lst @#1}##1} |
| 7227 |
% \end{macrocode} |
| 7228 |
% We initialize the key if the first token of |#2| is not |\relax|. |
| 7229 |
% \begin{macrocode} |
| 7230 |
\def\lst@Key@#1#2{% |
| 7231 |
\ifx\relax#2\@empty\else |
| 7232 |
\begingroup \globaldefs\@ne |
| 7233 |
\csname KV@\@lst @#1\endcsname{#2}% |
| 7234 |
\endgroup |
| 7235 |
\fi} |
| 7236 |
% \end{macrocode} |
| 7237 |
% \end{macro} |
| 7238 |
% |
| 7239 |
% \begin{macro}{\lst@UseHook} |
| 7240 |
% is very, very, \ldots, very (hundreds of times) easy. |
| 7241 |
% \begin{macrocode} |
| 7242 |
\def\lst@UseHook#1{\csname\@lst hk@#1\endcsname} |
| 7243 |
% \end{macrocode} |
| 7244 |
% \end{macro} |
| 7245 |
% |
| 7246 |
% \begin{macro}{\lst@AddToHook} |
| 7247 |
% \begin{macro}{\lst@AddToHookExe} |
| 7248 |
% \begin{macro}{\lst@AddToHookAtTop} |
| 7249 |
% All use the same submacro. |
| 7250 |
% \begin{macrocode} |
| 7251 |
\def\lst@AddToHook{\lst@ATH@\iffalse\lst@AddTo} |
| 7252 |
\def\lst@AddToHookExe{\lst@ATH@\iftrue\lst@AddTo} |
| 7253 |
\def\lst@AddToHookAtTop{\lst@ATH@\iffalse\lst@AddToAtTop} |
| 7254 |
% \end{macrocode} |
| 7255 |
% If and only if the boolean value is true, the hook material is executed |
| 7256 |
% globally. |
| 7257 |
% \begin{macrocode} |
| 7258 |
\long\def\lst@ATH@#1#2#3#4{% |
| 7259 |
\@ifundefined{\@lst hk@#3}{% |
| 7260 |
%<info> \message{^^Jnew hook `#3',^^J}% |
| 7261 |
\expandafter\gdef\csname\@lst hk@#3\endcsname{}}{}% |
| 7262 |
\expandafter#2\csname\@lst hk@#3\endcsname{#4}% |
| 7263 |
\def\lst@temp{#4}% |
| 7264 |
#1% \iftrue|false |
| 7265 |
\begingroup \globaldefs\@ne \lst@temp \endgroup |
| 7266 |
\fi} |
| 7267 |
% \end{macrocode} |
| 7268 |
% \end{macro} |
| 7269 |
% \end{macro} |
| 7270 |
% \end{macro} |
| 7271 |
% |
| 7272 |
% \begin{macro}{\lst@AddTo} |
| 7273 |
% Note that the definition is global! |
| 7274 |
% \begin{macrocode} |
| 7275 |
\long\def\lst@AddTo#1#2{% |
| 7276 |
\expandafter\gdef\expandafter#1\expandafter{#1#2}} |
| 7277 |
% \end{macrocode} |
| 7278 |
% \end{macro} |
| 7279 |
% |
| 7280 |
% \begin{macro}{\lst@AddToAtTop} |
| 7281 |
% We need a couple of |\expandafter|s now. Simply note that we have\\ |
| 7282 |
% {\small\hspace*{2em}|\expandafter\gdef\expandafter#1\expandafter{\lst@temp| |
| 7283 |
% $\langle$\textit{contents of }|#1|$\rangle$|}|}\\ |
| 7284 |
% after the `first phase' of expansion. |
| 7285 |
% \begin{macrocode} |
| 7286 |
\def\lst@AddToAtTop#1#2{\def\lst@temp{#2}% |
| 7287 |
\expandafter\expandafter\expandafter\gdef |
| 7288 |
\expandafter\expandafter\expandafter#1% |
| 7289 |
\expandafter\expandafter\expandafter{\expandafter\lst@temp#1}} |
| 7290 |
% \end{macrocode} |
| 7291 |
% \end{macro} |
| 7292 |
% |
| 7293 |
% \begin{macro}{\lst@lAddTo} |
| 7294 |
% A local version of |\lst@AddTo| \ldots |
| 7295 |
% \begin{macrocode} |
| 7296 |
\def\lst@lAddTo#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} |
| 7297 |
% \end{macrocode} |
| 7298 |
% \end{macro} |
| 7299 |
% |
| 7300 |
% \begin{macro}{\lst@Extend} |
| 7301 |
% \begin{macro}{\lst@lExtend} |
| 7302 |
% \ldots\space and here we expand the first token of the second argument first. |
| 7303 |
% \begin{macrocode} |
| 7304 |
\def\lst@Extend#1#2{% |
| 7305 |
\expandafter\lst@AddTo\expandafter#1\expandafter{#2}} |
| 7306 |
\def\lst@lExtend#1#2{% |
| 7307 |
\expandafter\lst@lAddTo\expandafter#1\expandafter{#2}} |
| 7308 |
% \end{macrocode} |
| 7309 |
% \begin{TODO} |
| 7310 |
% This should never be changed to |
| 7311 |
% \begin{verbatim} |
| 7312 |
% \def\lst@Extend#1{% |
| 7313 |
% \expandafter\lst@AddTo\expandafter#1\expandafter} |
| 7314 |
% \def\lst@lExtend#1{% |
| 7315 |
% \expandafter\lst@lAddTo\expandafter#1}\end{verbatim} |
| 7316 |
% The first is not equivalent in case that the second argument is a single |
| 7317 |
% (= non-braced) control sequence, and the second isn't in case of a braced |
| 7318 |
% second argument. |
| 7319 |
% \end{TODO} |
| 7320 |
% \end{macro} |
| 7321 |
% \end{macro} |
| 7322 |
% |
| 7323 |
% |
| 7324 |
% \subsection{Interfacing with \packagename{keyval}} |
| 7325 |
% |
| 7326 |
% The \packagename{keyval} package passes the value via the one and only |
| 7327 |
% paramater |#1| to the definition part of the key macro. The following |
| 7328 |
% commands may be used to analyse the value. Note that we need at least version |
| 7329 |
% 1.10 of the \packagename{keyval} package. Note also that the package removes |
| 7330 |
% a naming conflict with AMS classes---reported by \lsthelper{Ralf~Quast} |
| 7331 |
% {1998/01/08}{\keywords conflicts with AMS classes}. |
| 7332 |
% \begingroup |
| 7333 |
% \begin{macrocode} |
| 7334 |
\RequirePackage{keyval}[1997/11/10] |
| 7335 |
% \end{macrocode} |
| 7336 |
% \endgroup |
| 7337 |
% |
| 7338 |
% \begin{macro}{\lstKV@TwoArg} |
| 7339 |
% \begin{macro}{\lstKV@ThreeArg} |
| 7340 |
% \begin{macro}{\lstKV@FourArg} |
| 7341 |
% Define temporary macros and call with given arguments |#1|. We add empty |
| 7342 |
% arguments for the case that the user doesn't provide enough. |
| 7343 |
% \begin{macrocode} |
| 7344 |
\def\lstKV@TwoArg#1#2{\gdef\@gtempa##1##2{#2}\@gtempa#1{}{}} |
| 7345 |
\def\lstKV@ThreeArg#1#2{\gdef\@gtempa##1##2##3{#2}\@gtempa#1{}{}{}} |
| 7346 |
\def\lstKV@FourArg#1#2{\gdef\@gtempa##1##2##3##4{#2}\@gtempa#1{}{}{}{}} |
| 7347 |
% \end{macrocode} |
| 7348 |
% There's one question: What are the global definitions good for? |\lst@Key| |
| 7349 |
% might set |\globaldefs| to one and possibly calls this macro. That's the |
| 7350 |
% reason why we use global definitions here and below. |
| 7351 |
% \end{macro} |
| 7352 |
% \end{macro} |
| 7353 |
% \end{macro} |
| 7354 |
% |
| 7355 |
% \begin{macro}{\lstKV@OptArg} |
| 7356 |
% We define the temporary macro |\@gtempa| and insert default argument if |
| 7357 |
% necessary. |
| 7358 |
% \begin{macrocode} |
| 7359 |
\def\lstKV@OptArg[#1]#2#3{% |
| 7360 |
\gdef\@gtempa[##1]##2{#3}\lstKV@OptArg@{#1}#2\@} |
| 7361 |
\def\lstKV@OptArg@#1{\@ifnextchar[\lstKV@OptArg@@{\lstKV@OptArg@@[#1]}} |
| 7362 |
\def\lstKV@OptArg@@[#1]#2\@{\@gtempa[#1]{#2}} |
| 7363 |
% \end{macrocode} |
| 7364 |
% \end{macro} |
| 7365 |
% |
| 7366 |
% \begin{macro}{\lstKV@XOptArg} |
| 7367 |
% Here |#3| is already a definition with at least two parameters whose first |
| 7368 |
% is enclosed in brackets. |
| 7369 |
% \begin{macrocode} |
| 7370 |
\def\lstKV@XOptArg[#1]#2#3{% |
| 7371 |
\global\let\@gtempa#3\lstKV@OptArg@{#1}#2\@} |
| 7372 |
% \end{macrocode} |
| 7373 |
% \end{macro} |
| 7374 |
% |
| 7375 |
% \begin{macro}{\lstKV@CSTwoArg} |
| 7376 |
% Just define temporary macro and call it. |
| 7377 |
% \begin{macrocode} |
| 7378 |
\def\lstKV@CSTwoArg#1#2{% |
| 7379 |
\gdef\@gtempa##1,##2,##3\relax{#2}% |
| 7380 |
\@gtempa#1,,\relax} |
| 7381 |
% \end{macrocode} |
| 7382 |
% \end{macro} |
| 7383 |
% |
| 7384 |
% \begin{macro}{\lstKV@SetIf} |
| 7385 |
% We simply test the lower case first character of |#1|. |
| 7386 |
% \begin{macrocode} |
| 7387 |
\def\lstKV@SetIf#1{\lstKV@SetIf@#1\relax} |
| 7388 |
\def\lstKV@SetIf@#1#2\relax#3{\lowercase{% |
| 7389 |
\expandafter\let\expandafter#3% |
| 7390 |
\csname if\ifx #1t}true\else false\fi\endcsname} |
| 7391 |
% \end{macrocode} |
| 7392 |
% \end{macro} |
| 7393 |
% |
| 7394 |
% \begin{macro}{\lstKV@SwitchCases} |
| 7395 |
% is implemented as a substring test. The original version used an |&|, |
| 7396 |
% which produced a bug---see p.~\pageref{gAmpersand}. |
| 7397 |
% \begin{macrocode} |
| 7398 |
\def\lstKV@SwitchCases#1#2#3{% |
| 7399 |
\def\lst@temp##1\\#1:##2\\##3##4\@nil{% |
| 7400 |
\ifx\@empty##3% |
| 7401 |
#3% |
| 7402 |
\else |
| 7403 |
##2% |
| 7404 |
\fi |
| 7405 |
}% |
| 7406 |
\lst@temp\\#2\\#1:\\\@empty\@nil} |
| 7407 |
% \end{macrocode} |
| 7408 |
% \end{macro} |
| 7409 |
% |
| 7410 |
% \begin{macro}{\lstset} |
| 7411 |
% Finally this main user interface macro. |
| 7412 |
% We change catcodes for reading the argument. |
| 7413 |
% \begin{macrocode} |
| 7414 |
\lst@UserCommand\lstset{\begingroup \lst@setcatcodes \lstset@} |
| 7415 |
\def\lstset@#1{\endgroup \ifx\@empty#1\@empty\else\setkeys{lst}{#1}\fi} |
| 7416 |
% \end{macrocode} |
| 7417 |
% \end{macro} |
| 7418 |
% |
| 7419 |
% \begin{macro}{\lst@setcatcodes} |
| 7420 |
% contains all catcode changes for |\lstset|. The equal-sign has been added |
| 7421 |
% after a bug report by \lsthelper{Bekir~Karaoglu}{2003/09/16}{keyval problems |
| 7422 |
% with [turkish]{babel}}---babel's active equal sign clashes with keyval's |
| 7423 |
% usage. |\catcode`\"=12\relax| has been removed after a bug report by |
| 7424 |
% \lsthelper{Heiko~Bauke}{2004/06/27}{listings und ngerman}\,---\,hopefully |
| 7425 |
% this introduces no other bugs. |
| 7426 |
% \begin{macrocode} |
| 7427 |
\def\lst@setcatcodes{\makeatletter \catcode`\==12\relax} |
| 7428 |
% \end{macrocode} |
| 7429 |
% \begin{TODO} |
| 7430 |
% Change more catcodes? |
| 7431 |
% \end{TODO} |
| 7432 |
% \end{macro} |
| 7433 |
% |
| 7434 |
% |
| 7435 |
% \subsection{Internal modes} |
| 7436 |
% |
| 7437 |
% \begin{macro}{\lst@NewMode} |
| 7438 |
% We simply use |\chardef| for a mode definition. The counter |\lst@mode| |
| 7439 |
% mainly keeps the current mode number. But it is also used to advance the |
| 7440 |
% number in the macro |\lst@newmode|---we don't waste another counter. |
| 7441 |
% \begin{macrocode} |
| 7442 |
\def\lst@NewMode#1{% |
| 7443 |
\ifx\@undefined#1% |
| 7444 |
\lst@mode\lst@newmode\relax \advance\lst@mode\@ne |
| 7445 |
\xdef\lst@newmode{\the\lst@mode}% |
| 7446 |
\global\chardef#1=\lst@mode |
| 7447 |
\lst@mode\lst@nomode |
| 7448 |
\fi} |
| 7449 |
% \end{macrocode} |
| 7450 |
% \end{macro} |
| 7451 |
% |
| 7452 |
% \begin{macro}{\lst@mode} |
| 7453 |
% \begin{macro}{\lst@nomode} |
| 7454 |
% We allocate the counter and the first mode. |
| 7455 |
% \begin{macrocode} |
| 7456 |
\newcount\lst@mode |
| 7457 |
\def\lst@newmode{\m@ne}% init |
| 7458 |
\lst@NewMode\lst@nomode % init (of \lst@mode :-) |
| 7459 |
% \end{macrocode} |
| 7460 |
% \end{macro} |
| 7461 |
% \end{macro} |
| 7462 |
% |
| 7463 |
% \begin{macro}{\lst@UseDynamicMode} |
| 7464 |
% For dynamic modes we must not use the counter |\lst@mode| (since possibly |
| 7465 |
% already valued). |\lst@dynamicmode| substitutes |\lst@newmode| and is a local |
| 7466 |
% definition here, \ldots |
| 7467 |
% \begin{macrocode} |
| 7468 |
\def\lst@UseDynamicMode{% |
| 7469 |
\@tempcnta\lst@dynamicmode\relax \advance\@tempcnta\@ne |
| 7470 |
\edef\lst@dynamicmode{\the\@tempcnta}% |
| 7471 |
\expandafter\lst@Swap\expandafter{\expandafter{\lst@dynamicmode}}} |
| 7472 |
% \end{macrocode} |
| 7473 |
% \ldots\ initialized each listing with the current `value' of |\lst@newmode|. |
| 7474 |
% \begin{macrocode} |
| 7475 |
\lst@AddToHook{InitVars}{\let\lst@dynamicmode\lst@newmode} |
| 7476 |
% \end{macrocode} |
| 7477 |
% \end{macro} |
| 7478 |
% |
| 7479 |
% \begin{macro}{\lst@EnterMode} |
| 7480 |
% Each mode opens a group level, stores the mode number and execute mode |
| 7481 |
% specific tokens. Moreover we keep all these changes in mind (locally) and |
| 7482 |
% adjust internal variables if the user wants it. |
| 7483 |
% \begin{macrocode} |
| 7484 |
\def\lst@EnterMode#1#2{% |
| 7485 |
\bgroup \lst@mode=#1\relax #2% |
| 7486 |
\lst@FontAdjust |
| 7487 |
\lst@lAddTo\lst@entermodes{\lst@EnterMode{#1}{#2}}} |
| 7488 |
% \end{macrocode} |
| 7489 |
% \begin{macrocode} |
| 7490 |
\lst@AddToHook{InitVars}{\let\lst@entermodes\@empty} |
| 7491 |
\let\lst@entermodes\@empty % init |
| 7492 |
% \end{macrocode} |
| 7493 |
% The initialization has been added after a bug report from |
| 7494 |
% \lsthelper{Herfried~Karl~Wagner}{2002/05/11}{undefined control sequence |
| 7495 |
% \lst@entermodes}. |
| 7496 |
% \end{macro} |
| 7497 |
% |
| 7498 |
% \begin{macro}{\lst@LeaveMode} |
| 7499 |
% We simply close the group and call |\lsthk@EndGroup| if and only if the |
| 7500 |
% current mode is not |\lst@nomode|. |
| 7501 |
% \begin{macrocode} |
| 7502 |
\def\lst@LeaveMode{% |
| 7503 |
\ifnum\lst@mode=\lst@nomode\else |
| 7504 |
\egroup \expandafter\lsthk@EndGroup |
| 7505 |
\fi} |
| 7506 |
% \end{macrocode} |
| 7507 |
% \begin{macrocode} |
| 7508 |
\lst@AddToHook{EndGroup}{}% init |
| 7509 |
% \end{macrocode} |
| 7510 |
% \end{macro} |
| 7511 |
% |
| 7512 |
% \begin{macro}{\lst@InterruptModes} |
| 7513 |
% We put the current mode sequence on a stack and leave all modes. |
| 7514 |
% \begin{macrocode} |
| 7515 |
\def\lst@InterruptModes{% |
| 7516 |
\lst@Extend\lst@modestack{\expandafter{\lst@entermodes}}% |
| 7517 |
\lst@LeaveAllModes} |
| 7518 |
% \end{macrocode} |
| 7519 |
% \begin{macrocode} |
| 7520 |
\lst@AddToHook{InitVars}{\global\let\lst@modestack\@empty} |
| 7521 |
% \end{macrocode} |
| 7522 |
% \end{macro} |
| 7523 |
% |
| 7524 |
% \begin{macro}{\lst@ReenterModes} |
| 7525 |
% If the stack is not empty, we leave all modes and pop the topmost element |
| 7526 |
% (which is the last element of |\lst@modestack|). |
| 7527 |
% \begin{macrocode} |
| 7528 |
\def\lst@ReenterModes{% |
| 7529 |
\ifx\lst@modestack\@empty\else |
| 7530 |
\lst@LeaveAllModes |
| 7531 |
\global\let\@gtempa\lst@modestack |
| 7532 |
\global\let\lst@modestack\@empty |
| 7533 |
\expandafter\lst@ReenterModes@\@gtempa\relax |
| 7534 |
\fi} |
| 7535 |
\def\lst@ReenterModes@#1#2{% |
| 7536 |
\ifx\relax#2\@empty |
| 7537 |
% \end{macrocode} |
| 7538 |
% If we've reached |\relax|, we've also found the last element: we execute |#1| |
| 7539 |
% and gobble |{#2}|=|{\relax}| after |\fi|. |
| 7540 |
% \begin{macrocode} |
| 7541 |
\gdef\@gtempa##1{#1}% |
| 7542 |
\expandafter\@gtempa |
| 7543 |
\else |
| 7544 |
% \end{macrocode} |
| 7545 |
% Otherwise we just add the element to |\lst@modestack| and continue the loop. |
| 7546 |
% \begin{macrocode} |
| 7547 |
\lst@AddTo\lst@modestack{{#1}}% |
| 7548 |
\expandafter\lst@ReenterModes@ |
| 7549 |
\fi |
| 7550 |
{#2}} |
| 7551 |
% \end{macrocode} |
| 7552 |
% \end{macro} |
| 7553 |
% |
| 7554 |
% \begin{macro}{\lst@LeaveAllModes} |
| 7555 |
% Leaving all modes means closing groups until the mode equals |\lst@nomode|. |
| 7556 |
% \begin{macrocode} |
| 7557 |
\def\lst@LeaveAllModes{% |
| 7558 |
\ifnum\lst@mode=\lst@nomode |
| 7559 |
\expandafter\lsthk@EndGroup |
| 7560 |
\else |
| 7561 |
\expandafter\egroup\expandafter\lst@LeaveAllModes |
| 7562 |
\fi} |
| 7563 |
% \end{macrocode} |
| 7564 |
% We need that macro to end a listing correctly. |
| 7565 |
% \begin{macrocode} |
| 7566 |
\lst@AddToHook{ExitVars}{\lst@LeaveAllModes} |
| 7567 |
% \end{macrocode} |
| 7568 |
% \end{macro} |
| 7569 |
% |
| 7570 |
% \begin{macro}{\lst@Pmode} |
| 7571 |
% \begin{macro}{\lst@GPmode} |
| 7572 |
% The `processing' and the general purpose mode. |
| 7573 |
% \begin{macrocode} |
| 7574 |
\lst@NewMode\lst@Pmode |
| 7575 |
\lst@NewMode\lst@GPmode |
| 7576 |
% \end{macrocode} |
| 7577 |
% \end{macro} |
| 7578 |
% \end{macro} |
| 7579 |
% |
| 7580 |
% \begin{macro}{\lst@modetrue} |
| 7581 |
% The usual macro to value a boolean except that we also execute a hook. |
| 7582 |
% \begin{macrocode} |
| 7583 |
\def\lst@modetrue{\let\lst@ifmode\iftrue \lsthk@ModeTrue} |
| 7584 |
\let\lst@ifmode\iffalse % init |
| 7585 |
\lst@AddToHook{ModeTrue}{}% init |
| 7586 |
% \end{macrocode} |
| 7587 |
% \end{macro} |
| 7588 |
% |
| 7589 |
% \begin{macro}{\lst@ifLmode} |
| 7590 |
% Comment lines use a static mode. It terminates at end of line. |
| 7591 |
% \begin{macrocode} |
| 7592 |
\def\lst@Lmodetrue{\let\lst@ifLmode\iftrue} |
| 7593 |
\let\lst@ifLmode\iffalse % init |
| 7594 |
\lst@AddToHook{EOL}{\@whilesw \lst@ifLmode\fi \lst@LeaveMode} |
| 7595 |
% \end{macrocode} |
| 7596 |
% \end{macro} |
| 7597 |
% |
| 7598 |
% |
| 7599 |
% \subsection{Diverse helpers} |
| 7600 |
% |
| 7601 |
% \begin{macro}{\lst@NormedDef} |
| 7602 |
% works like |\def| (without any parameters!) but normalizes the replacement |
| 7603 |
% text by making all characters lower case and stripping off spaces. |
| 7604 |
% \begin{macrocode} |
| 7605 |
\def\lst@NormedDef#1#2{\lowercase{\edef#1{\zap@space#2 \@empty}}} |
| 7606 |
% \end{macrocode} |
| 7607 |
% \end{macro} |
| 7608 |
% |
| 7609 |
% \begin{macro}{\lst@NormedNameDef} |
| 7610 |
% works like |\global\@namedef| (again without any parameters!) but normalizes |
| 7611 |
% both the macro name and the replacement text. |
| 7612 |
% \begin{macrocode} |
| 7613 |
\def\lst@NormedNameDef#1#2{% |
| 7614 |
\lowercase{\edef\lst@temp{\zap@space#1 \@empty}% |
| 7615 |
\expandafter\xdef\csname\lst@temp\endcsname{\zap@space#2 \@empty}}} |
| 7616 |
% \end{macrocode} |
| 7617 |
% \end{macro} |
| 7618 |
% |
| 7619 |
% \begin{macro}{\lst@GetFreeMacro} |
| 7620 |
% Initialize |\@tempcnta| and |\lst@freemacro|, \ldots |
| 7621 |
% \begin{macrocode} |
| 7622 |
\def\lst@GetFreeMacro#1{% |
| 7623 |
\@tempcnta\z@ \def\lst@freemacro{#1\the\@tempcnta}% |
| 7624 |
\lst@GFM@} |
| 7625 |
% \end{macrocode} |
| 7626 |
% \ldots\space and either build the control sequence or advance the counter and |
| 7627 |
% continue. |
| 7628 |
% \begin{macrocode} |
| 7629 |
\def\lst@GFM@{% |
| 7630 |
\expandafter\ifx \csname\lst@freemacro\endcsname \relax |
| 7631 |
\edef\lst@freemacro{\csname\lst@freemacro\endcsname}% |
| 7632 |
\else |
| 7633 |
\advance\@tempcnta\@ne |
| 7634 |
\expandafter\lst@GFM@ |
| 7635 |
\fi} |
| 7636 |
% \end{macrocode} |
| 7637 |
% \end{macro} |
| 7638 |
% |
| 7639 |
% \begin{macro}{\lst@gtempboxa} |
| 7640 |
% \begin{macrocode} |
| 7641 |
\newbox\lst@gtempboxa |
| 7642 |
% \end{macrocode} |
| 7643 |
% \begin{macrocode} |
| 7644 |
%</kernel> |
| 7645 |
% \end{macrocode} |
| 7646 |
% \end{macro} |
| 7647 |
% |
| 7648 |
% |
| 7649 |
% \section{Doing output} |
| 7650 |
% |
| 7651 |
% |
| 7652 |
% \subsection{Basic registers and keys} |
| 7653 |
% |
| 7654 |
% \begin{macrocode} |
| 7655 |
%<*kernel> |
| 7656 |
% \end{macrocode} |
| 7657 |
% |
| 7658 |
% \paragraph{The current character string} |
| 7659 |
% is kept in a token register and a counter holds its length. |
| 7660 |
% Here we define the macros to put characters into the output queue. |
| 7661 |
% |
| 7662 |
% \begin{macro}{\lst@token} |
| 7663 |
% \begin{macro}{\lst@length} |
| 7664 |
% are allocated here. Quite a useful comment, isn't it? |
| 7665 |
% \begin{macrocode} |
| 7666 |
\newtoks\lst@token \newcount\lst@length |
| 7667 |
% \end{macrocode} |
| 7668 |
% \end{macro} |
| 7669 |
% \end{macro} |
| 7670 |
% |
| 7671 |
% \begin{macro}{\lst@ResetToken} |
| 7672 |
% \begin{macro}{\lst@lastother} |
| 7673 |
% The two registers get empty respectively zero at the beginning of each line. |
| 7674 |
% After receiving a report from \lsthelper{Claus~Atzenbeck}{1999/11/24}{HTML: |
| 7675 |
% output unit repeated after >}---I removed such a bug many times---I decided |
| 7676 |
% to reset these registers in the \hookname{EndGroup} hook, too. |
| 7677 |
% \begin{macrocode} |
| 7678 |
\def\lst@ResetToken{\lst@token{}\lst@length\z@} |
| 7679 |
% \end{macrocode} |
| 7680 |
% \begin{macrocode} |
| 7681 |
\lst@AddToHook{InitVarsBOL}{\lst@ResetToken \let\lst@lastother\@empty} |
| 7682 |
\lst@AddToHook{EndGroup}{\lst@ResetToken \let\lst@lastother\@empty} |
| 7683 |
% \end{macrocode} |
| 7684 |
% The macro |\lst@lastother| will be equivalent to the last `other' character, |
| 7685 |
% which leads us to |\lst@ifletter|. |
| 7686 |
% \end{macro} |
| 7687 |
% \end{macro} |
| 7688 |
% |
| 7689 |
% \begin{macro}{\lst@ifletter} |
| 7690 |
% indicates whether the token contains an identifier or other characters. |
| 7691 |
% \begin{macrocode} |
| 7692 |
\def\lst@lettertrue{\let\lst@ifletter\iftrue} |
| 7693 |
\def\lst@letterfalse{\let\lst@ifletter\iffalse} |
| 7694 |
\lst@AddToHook{InitVars}{\lst@letterfalse} |
| 7695 |
% \end{macrocode} |
| 7696 |
% \end{macro} |
| 7697 |
% |
| 7698 |
% \begin{macro}{\lst@Append} |
| 7699 |
% puts the argument into the output queue. |
| 7700 |
% \begin{macrocode} |
| 7701 |
\def\lst@Append#1{\advance\lst@length\@ne |
| 7702 |
\lst@token=\expandafter{\the\lst@token#1}} |
| 7703 |
% \end{macrocode} |
| 7704 |
% \end{macro} |
| 7705 |
% |
| 7706 |
% \begin{macro}{\lst@AppendOther} |
| 7707 |
% Depending on the current state, we first output the character string as an |
| 7708 |
% identifier. Then we save the `argument' via |\futurelet| and call the macro |
| 7709 |
% |\lst@Append| to do the rest. |
| 7710 |
% \begin{macrocode} |
| 7711 |
\def\lst@AppendOther{% |
| 7712 |
\lst@ifletter \lst@Output\lst@letterfalse \fi |
| 7713 |
\futurelet\lst@lastother\lst@Append} |
| 7714 |
% \end{macrocode} |
| 7715 |
% \end{macro} |
| 7716 |
% |
| 7717 |
% \begin{macro}{\lst@AppendLetter} |
| 7718 |
% We output a non-identifier string if necessary and call |\lst@Append|. |
| 7719 |
% \begin{macrocode} |
| 7720 |
\def\lst@AppendLetter{% |
| 7721 |
\lst@ifletter\else \lst@OutputOther\lst@lettertrue \fi |
| 7722 |
\lst@Append} |
| 7723 |
% \end{macrocode} |
| 7724 |
% \end{macro} |
| 7725 |
% |
| 7726 |
% \begin{macro}{\lst@SaveToken} |
| 7727 |
% \begin{macro}{\lst@RestoreToken} |
| 7728 |
% If a group end appears and ruins the character string, we can use these |
| 7729 |
% macros to save and restore the contents. |\lst@thestyle| is the current |
| 7730 |
% printing style and must be saved and restored, too. |
| 7731 |
% \begin{macrocode} |
| 7732 |
\def\lst@SaveToken{% |
| 7733 |
\global\let\lst@gthestyle\lst@thestyle |
| 7734 |
\global\let\lst@glastother\lst@lastother |
| 7735 |
\xdef\lst@RestoreToken{\noexpand\lst@token{\the\lst@token}% |
| 7736 |
\noexpand\lst@length\the\lst@length\relax |
| 7737 |
\noexpand\let\noexpand\lst@thestyle |
| 7738 |
\noexpand\lst@gthestyle |
| 7739 |
\noexpand\let\noexpand\lst@lastother |
| 7740 |
\noexpand\lst@glastother}} |
| 7741 |
% \end{macrocode} |
| 7742 |
% Now -- that means after a bug report by \lsthelper{Rolf~Niepraschk} |
| 7743 |
% {2002/04/12}{\RequirePackage is missing keywordstyle when near the top of |
| 7744 |
% a page} -- |\lst@lastother| is also saved and restored. |
| 7745 |
% \end{macro} |
| 7746 |
% \end{macro} |
| 7747 |
% |
| 7748 |
% \begin{macro}{\lst@IfLastOtherOneOf} |
| 7749 |
% Finally, this obvious implementation. |
| 7750 |
% \begin{macrocode} |
| 7751 |
\def\lst@IfLastOtherOneOf#1{\lst@IfLastOtherOneOf@ #1\relax} |
| 7752 |
\def\lst@IfLastOtherOneOf@#1{% |
| 7753 |
\ifx #1\relax |
| 7754 |
\expandafter\@secondoftwo |
| 7755 |
\else |
| 7756 |
\ifx\lst@lastother#1% |
| 7757 |
\lst@IfLastOtherOneOf@t |
| 7758 |
\else |
| 7759 |
\expandafter\expandafter\expandafter\lst@IfLastOtherOneOf@ |
| 7760 |
\fi |
| 7761 |
\fi} |
| 7762 |
\def\lst@IfLastOtherOneOf@t#1\fi\fi#2\relax{\fi\fi\@firstoftwo} |
| 7763 |
% \end{macrocode} |
| 7764 |
% \end{macro} |
| 7765 |
% |
| 7766 |
% |
| 7767 |
% \paragraph{The current position} |
| 7768 |
% is either the dimension |\lst@currlwidth|, which is the horizontal position |
| 7769 |
% without taking the current character string into account, or it's the current |
| 7770 |
% column starting with number 0. This is |\lst@column| $-$ |\lst@pos| $+$ |
| 7771 |
% |\lst@length|. Moreover we have |\lst@lostspace| which is the difference |
| 7772 |
% between the current and the desired line width. We define macros to insert |
| 7773 |
% this lost space. |
| 7774 |
% |
| 7775 |
% \begin{macro}{\lst@currlwidth} |
| 7776 |
% \begin{macro}{\lst@column} |
| 7777 |
% \begin{macro}{\lst@pos} |
| 7778 |
% the current line width and two counters. |
| 7779 |
% \begin{macrocode} |
| 7780 |
\newdimen\lst@currlwidth % \global |
| 7781 |
\newcount\lst@column \newcount\lst@pos % \global |
| 7782 |
\lst@AddToHook{InitVarsBOL} |
| 7783 |
{\global\lst@currlwidth\z@ \global\lst@pos\z@ \global\lst@column\z@} |
| 7784 |
% \end{macrocode} |
| 7785 |
% \end{macro} |
| 7786 |
% \end{macro} |
| 7787 |
% \end{macro} |
| 7788 |
% |
| 7789 |
% \begin{macro}{\lst@CalcColumn} |
| 7790 |
% sets |\@tempcnta| to the current column. |
| 7791 |
% Note that |\lst@pos| will be nonpositive. |
| 7792 |
% \begin{macrocode} |
| 7793 |
\def\lst@CalcColumn{% |
| 7794 |
\@tempcnta\lst@column |
| 7795 |
\advance\@tempcnta\lst@length |
| 7796 |
\advance\@tempcnta-\lst@pos} |
| 7797 |
% \end{macrocode} |
| 7798 |
% \end{macro} |
| 7799 |
% |
| 7800 |
% \begin{macro}{\lst@lostspace} |
| 7801 |
% Whenever this dimension is positive we can insert space. A negative `lost |
| 7802 |
% space' means that the printed line is wider than expected. |
| 7803 |
% \begin{macrocode} |
| 7804 |
\newdimen\lst@lostspace % \global |
| 7805 |
\lst@AddToHook{InitVarsBOL}{\global\lst@lostspace\z@} |
| 7806 |
% \end{macrocode} |
| 7807 |
% \end{macro} |
| 7808 |
% |
| 7809 |
% \begin{macro}{\lst@UseLostSpace} |
| 7810 |
% We insert space and reset it if and only if |\lst@lostspace| is positive. |
| 7811 |
% \begin{macrocode} |
| 7812 |
\def\lst@UseLostSpace{\ifdim\lst@lostspace>\z@ \lst@InsertLostSpace \fi} |
| 7813 |
% \end{macrocode} |
| 7814 |
% \end{macro} |
| 7815 |
% |
| 7816 |
% \begin{macro}{\lst@InsertLostSpace} |
| 7817 |
% \begin{macro}{\lst@InsertHalfLostSpace} |
| 7818 |
% Ditto, but insert even if negative. |\lst@Kern| will be defined very soon. |
| 7819 |
% \begin{macrocode} |
| 7820 |
\def\lst@InsertLostSpace{% |
| 7821 |
\lst@Kern\lst@lostspace \global\lst@lostspace\z@} |
| 7822 |
\def\lst@InsertHalfLostSpace{% |
| 7823 |
\global\[email protected]\lst@lostspace \lst@Kern\lst@lostspace} |
| 7824 |
% \end{macrocode} |
| 7825 |
% \end{macro} |
| 7826 |
% \end{macro} |
| 7827 |
% |
| 7828 |
% |
| 7829 |
% \paragraph{Column widths} |
| 7830 |
% Here we deal with the width of a single column, which equals the width of a |
| 7831 |
% single character box. Keep in mind that there are fixed and flexible column |
| 7832 |
% formats. |
| 7833 |
% |
| 7834 |
% \begin{macro}{\lst@width} |
| 7835 |
% \begin{lstkey}{basewidth} |
| 7836 |
% \keyname{basewidth} assigns the values to macros and tests whether they are |
| 7837 |
% negative. |
| 7838 |
% \begin{macrocode} |
| 7839 |
\newdimen\lst@width |
| 7840 |
\lst@Key{basewidth}{0.6em,0.45em}{\lstKV@CSTwoArg{#1}% |
| 7841 |
{\def\lst@widthfixed{##1}\def\lst@widthflexible{##2}% |
| 7842 |
\ifx\lst@widthflexible\@empty |
| 7843 |
\let\lst@widthflexible\lst@widthfixed |
| 7844 |
\fi |
| 7845 |
\def\lst@temp{\PackageError{Listings}% |
| 7846 |
{Negative value(s) treated as zero}% |
| 7847 |
\@ehc}% |
| 7848 |
\let\lst@error\@empty |
| 7849 |
\ifdim \lst@widthfixed<\z@ |
| 7850 |
\let\lst@error\lst@temp \let\lst@widthfixed\z@ |
| 7851 |
\fi |
| 7852 |
\ifdim \lst@widthflexible<\z@ |
| 7853 |
\let\lst@error\lst@temp \let\lst@widthflexible\z@ |
| 7854 |
\fi |
| 7855 |
\lst@error}} |
| 7856 |
% \end{macrocode} |
| 7857 |
% We set the dimension in a special hook. |
| 7858 |
% \begin{macrocode} |
| 7859 |
\lst@AddToHook{FontAdjust} |
| 7860 |
{\lst@width=\lst@ifflexible\lst@widthflexible |
| 7861 |
\else\lst@widthfixed\fi \relax} |
| 7862 |
% \end{macrocode} |
| 7863 |
% \end{lstkey} |
| 7864 |
% \end{macro} |
| 7865 |
% |
| 7866 |
% \begin{lstkey}{fontadjust} |
| 7867 |
% \begin{macro}{\lst@FontAdjust} |
| 7868 |
% This hook is controlled by a switch and is always executed at |
| 7869 |
% \hookname{InitVars}. |
| 7870 |
% \begin{macrocode} |
| 7871 |
\lst@Key{fontadjust}{false}[t]{\lstKV@SetIf{#1}\lst@iffontadjust} |
| 7872 |
\def\lst@FontAdjust{\lst@iffontadjust \lsthk@FontAdjust \fi} |
| 7873 |
% \end{macrocode} |
| 7874 |
% \begin{macrocode} |
| 7875 |
\lst@AddToHook{InitVars}{\lsthk@FontAdjust} |
| 7876 |
% \end{macrocode} |
| 7877 |
% \end{macro} |
| 7878 |
% \end{lstkey} |
| 7879 |
% |
| 7880 |
% |
| 7881 |
% \subsection{Low- and mid-level output} |
| 7882 |
% |
| 7883 |
% \paragraph{Doing the output} |
| 7884 |
% means putting the character string into a box register, updating all internal |
| 7885 |
% data, and eventually giving the box to \TeX. |
| 7886 |
% |
| 7887 |
% \begin{macro}{\lst@OutputBox} |
| 7888 |
% \begin{macro}{\lst@alloverstyle} |
| 7889 |
% The lowest level is the output of a box register. |
| 7890 |
% Here we use |\box#1| as argument to |\lst@alloverstyle|. |
| 7891 |
% \begin{macrocode} |
| 7892 |
\def\lst@OutputBox#1{\lst@alloverstyle{\box#1}} |
| 7893 |
% \end{macrocode} |
| 7894 |
% \begin{ALTERNATIVE} |
| 7895 |
% Instead of |\global\advance\lst@currlwidth| |\wd|\meta{box number} in |
| 7896 |
% both definitions |\lst@Kern| and |\lst@CalcLostSpaceAndOutput|, we could |
| 7897 |
% also advance the dimension here. But I decided not to do so since it |
| 7898 |
% simplifies possible redefinitions of |\lst@OutputBox|: we need not to care |
| 7899 |
% about |\lst@currlwidth|. |
| 7900 |
% \end{ALTERNATIVE} |
| 7901 |
% \begin{macrocode} |
| 7902 |
\def\lst@alloverstyle#1{#1}% init |
| 7903 |
% \end{macrocode} |
| 7904 |
% \end{macro} |
| 7905 |
% \end{macro} |
| 7906 |
% |
| 7907 |
% \begin{macro}{\lst@Kern} |
| 7908 |
% has been used to insert `lost space'. |
| 7909 |
% It must not use |\@tempboxa| since that \ldots |
| 7910 |
% \begin{macrocode} |
| 7911 |
\def\lst@Kern#1{% |
| 7912 |
\setbox\z@\hbox{{\lst@currstyle{\kern#1}}}% |
| 7913 |
\global\advance\lst@currlwidth \wd\z@ |
| 7914 |
\lst@OutputBox\z@} |
| 7915 |
% \end{macrocode} |
| 7916 |
% \end{macro} |
| 7917 |
% |
| 7918 |
% \begin{macro}{\lst@CalcLostSpaceAndOutput} |
| 7919 |
% \ldots\space is used here. |
| 7920 |
% We keep track of |\lst@lostspace|, |\lst@currlwidth| and |\lst@pos|. |
| 7921 |
% \begin{macrocode} |
| 7922 |
\def\lst@CalcLostSpaceAndOutput{% |
| 7923 |
\global\advance\lst@lostspace \lst@length\lst@width |
| 7924 |
\global\advance\lst@lostspace-\wd\@tempboxa |
| 7925 |
\global\advance\lst@currlwidth \wd\@tempboxa |
| 7926 |
\global\advance\lst@pos -\lst@length |
| 7927 |
% \end{macrocode} |
| 7928 |
% Before |\@tempboxa| is output, we insert space if there is enough lost space. |
| 7929 |
% This possibly invokes |\lst@Kern| via `insert half lost space', which is the |
| 7930 |
% reason for why we mustn't use |\@tempboxa| above. By redefinition we prevent |
| 7931 |
% |\lst@OutputBox| from using any special style in |\lst@Kern|. |
| 7932 |
% \begin{macrocode} |
| 7933 |
\setbox\@tempboxa\hbox{\let\lst@OutputBox\box |
| 7934 |
\ifdim\lst@lostspace>\z@ \lst@leftinsert \fi |
| 7935 |
\box\@tempboxa |
| 7936 |
\ifdim\lst@lostspace>\z@ \lst@rightinsert \fi}% |
| 7937 |
% \end{macrocode} |
| 7938 |
% Finally we can output the new box. |
| 7939 |
% \begin{macrocode} |
| 7940 |
\lst@OutputBox\@tempboxa \lsthk@PostOutput} |
| 7941 |
% \end{macrocode} |
| 7942 |
% \begin{macrocode} |
| 7943 |
\lst@AddToHook{PostOutput}{}% init |
| 7944 |
% \end{macrocode} |
| 7945 |
% \end{macro} |
| 7946 |
% |
| 7947 |
% \begin{macro}{\lst@OutputToken} |
| 7948 |
% Now comes a mid-level definition. |
| 7949 |
% Here we use |\lst@token| to set |\@tempboxa| and eventually output the box. |
| 7950 |
% We take care of font adjustment and special output styles. |
| 7951 |
% Yet unknown macros are defined in the following subsections. |
| 7952 |
% \begin{macrocode} |
| 7953 |
\def\lst@OutputToken{% |
| 7954 |
\lst@TrackNewLines \lst@OutputLostSpace |
| 7955 |
\lst@ifgobbledws |
| 7956 |
\lst@gobbledwhitespacefalse |
| 7957 |
\lst@@discretionary |
| 7958 |
\fi |
| 7959 |
\lst@CheckMerge |
| 7960 |
{\lst@thestyle{\lst@FontAdjust |
| 7961 |
\setbox\@tempboxa\lst@hbox |
| 7962 |
{\lsthk@OutputBox |
| 7963 |
\lst@lefthss |
| 7964 |
\expandafter\lst@FillOutputBox\the\lst@token\@empty |
| 7965 |
\lst@righthss}% |
| 7966 |
\lst@CalcLostSpaceAndOutput}}% |
| 7967 |
\lst@ResetToken} |
| 7968 |
% \end{macrocode} |
| 7969 |
% \begin{macrocode} |
| 7970 |
\lst@AddToHook{OutputBox}{}% init |
| 7971 |
% \end{macrocode} |
| 7972 |
% \begin{macrocode} |
| 7973 |
\def\lst@gobbledwhitespacetrue{\global\let\lst@ifgobbledws\iftrue} |
| 7974 |
\def\lst@gobbledwhitespacefalse{\global\let\lst@ifgobbledws\iffalse} |
| 7975 |
\lst@AddToHookExe{InitBOL}{\lst@gobbledwhitespacefalse}% init |
| 7976 |
% \end{macrocode} |
| 7977 |
% \end{macro} |
| 7978 |
% |
| 7979 |
% |
| 7980 |
% \paragraph{Delaying the output} |
| 7981 |
% means saving the character string somewhere and pushing it back when |
| 7982 |
% neccessary. We may also attach the string to the next output box without |
| 7983 |
% affecting style detection: both will be printed in the style of the upcoming |
| 7984 |
% output. We will call this `merging'. |
| 7985 |
% |
| 7986 |
% \begin{macro}{\lst@Delay} |
| 7987 |
% \begin{macro}{\lst@Merge} |
| 7988 |
% To delay or merge |#1|, we process it as usual and simply save the state |
| 7989 |
% in macros. For delayed characters we also need the currently `active' |
| 7990 |
% output routine. Both definitions first check whether there are already |
| 7991 |
% delayed or `merged' characters. |
| 7992 |
% \begin{macrocode} |
| 7993 |
\def\lst@Delay#1{% |
| 7994 |
\lst@CheckDelay |
| 7995 |
#1% |
| 7996 |
\lst@GetOutputMacro\lst@delayedoutput |
| 7997 |
\edef\lst@delayed{\the\lst@token}% |
| 7998 |
\edef\lst@delayedlength{\the\lst@length}% |
| 7999 |
\lst@ResetToken} |
| 8000 |
% \end{macrocode} |
| 8001 |
% \begin{macrocode} |
| 8002 |
\def\lst@Merge#1{% |
| 8003 |
\lst@CheckMerge |
| 8004 |
#1% |
| 8005 |
\edef\lst@merged{\the\lst@token}% |
| 8006 |
\edef\lst@mergedlength{\the\lst@length}% |
| 8007 |
\lst@ResetToken} |
| 8008 |
% \end{macrocode} |
| 8009 |
% \end{macro} |
| 8010 |
% \end{macro} |
| 8011 |
% |
| 8012 |
% \begin{macro}{\lst@MergeToken} |
| 8013 |
% Here we put the things together again. |
| 8014 |
% \begin{macrocode} |
| 8015 |
\def\lst@MergeToken#1#2{% |
| 8016 |
\advance\lst@length#2% |
| 8017 |
\lst@lExtend#1{\the\lst@token}% |
| 8018 |
\expandafter\lst@token\expandafter{#1}% |
| 8019 |
\let#1\@empty} |
| 8020 |
% \end{macrocode} |
| 8021 |
% \end{macro} |
| 8022 |
% |
| 8023 |
% \begin{macro}{\lst@CheckDelay} |
| 8024 |
% We need to print delayed characters. The mode depends on the current output |
| 8025 |
% macro. If it equals the saved definition, we put the delayed characters in |
| 8026 |
% front of the character string (we merge them) since there has been no |
| 8027 |
% letter-to-other or other-to-letter leap. Otherwise we locally reset the |
| 8028 |
% current character string, merge this empty string with the delayed one, |
| 8029 |
% and output it. |
| 8030 |
% \begin{macrocode} |
| 8031 |
\def\lst@CheckDelay{% |
| 8032 |
\ifx\lst@delayed\@empty\else |
| 8033 |
\lst@GetOutputMacro\@gtempa |
| 8034 |
\ifx\lst@delayedoutput\@gtempa |
| 8035 |
\lst@MergeToken\lst@delayed\lst@delayedlength |
| 8036 |
\else |
| 8037 |
{\lst@ResetToken |
| 8038 |
\lst@MergeToken\lst@delayed\lst@delayedlength |
| 8039 |
\lst@delayedoutput}% |
| 8040 |
\let\lst@delayed\@empty |
| 8041 |
\fi |
| 8042 |
\fi} |
| 8043 |
% \end{macrocode} |
| 8044 |
% \end{macro} |
| 8045 |
% |
| 8046 |
% \begin{macro}{\lst@CheckMerge} |
| 8047 |
% All this is easier for |\lst@merged|. |
| 8048 |
% \begin{macrocode} |
| 8049 |
\def\lst@CheckMerge{% |
| 8050 |
\ifx\lst@merged\@empty\else |
| 8051 |
\lst@MergeToken\lst@merged\lst@mergedlength |
| 8052 |
\fi} |
| 8053 |
% \end{macrocode} |
| 8054 |
% \begin{macrocode} |
| 8055 |
\let\lst@delayed\@empty % init |
| 8056 |
\let\lst@merged\@empty % init |
| 8057 |
% \end{macrocode} |
| 8058 |
% \end{macro} |
| 8059 |
% |
| 8060 |
% |
| 8061 |
% \subsection{Column formats} |
| 8062 |
% |
| 8063 |
% It's time to deal with fixed and flexible column modes. |
| 8064 |
% A couple of open definitions are now filled in. |
| 8065 |
% |
| 8066 |
% \begin{macro}{\lst@column@fixed} |
| 8067 |
% switches to the fixed column format. The definitions here control how the |
| 8068 |
% output of the above definitions looks like. |
| 8069 |
% \begin{macrocode} |
| 8070 |
\def\lst@column@fixed{% |
| 8071 |
\lst@flexiblefalse |
| 8072 |
\lst@width\lst@widthfixed\relax |
| 8073 |
\let\lst@OutputLostSpace\lst@UseLostSpace |
| 8074 |
\let\lst@FillOutputBox\lst@FillFixed |
| 8075 |
\let\lst@hss\hss |
| 8076 |
\def\lst@hbox{\hbox to\lst@length\lst@width}} |
| 8077 |
% \end{macrocode} |
| 8078 |
% \end{macro} |
| 8079 |
% |
| 8080 |
% \begin{macro}{\lst@FillFixed} |
| 8081 |
% Filling up a fixed mode box is easy. |
| 8082 |
% \begin{macrocode} |
| 8083 |
\def\lst@FillFixed#1{#1\lst@FillFixed@} |
| 8084 |
% \end{macrocode} |
| 8085 |
% While not reaching the end (|\@empty| from above), we insert dynamic space, |
| 8086 |
% output the argument and call the submacro again. |
| 8087 |
% \begin{macrocode} |
| 8088 |
\def\lst@FillFixed@#1{% |
| 8089 |
\ifx\@empty#1\else \lst@hss#1\expandafter\lst@FillFixed@ \fi} |
| 8090 |
% \end{macrocode} |
| 8091 |
% \end{macro} |
| 8092 |
% |
| 8093 |
% \begin{macro}{\lst@column@flexible} |
| 8094 |
% The first flexible format. |
| 8095 |
% \begin{macrocode} |
| 8096 |
\def\lst@column@flexible{% |
| 8097 |
\lst@flexibletrue |
| 8098 |
\lst@width\lst@widthflexible\relax |
| 8099 |
\let\lst@OutputLostSpace\lst@UseLostSpace |
| 8100 |
\let\lst@FillOutputBox\@empty |
| 8101 |
\let\lst@hss\@empty |
| 8102 |
\let\lst@hbox\hbox} |
| 8103 |
% \end{macrocode} |
| 8104 |
% \end{macro} |
| 8105 |
% |
| 8106 |
% \begin{macro}{\lst@column@fullflexible} |
| 8107 |
% This column format inserts no lost space except at the beginning of a line. |
| 8108 |
% \begin{macrocode} |
| 8109 |
\def\lst@column@fullflexible{% |
| 8110 |
\lst@column@flexible |
| 8111 |
\def\lst@OutputLostSpace{\lst@ifnewline \lst@UseLostSpace\fi}% |
| 8112 |
\let\lst@leftinsert\@empty |
| 8113 |
\let\lst@rightinsert\@empty} |
| 8114 |
% \end{macrocode} |
| 8115 |
% \end{macro} |
| 8116 |
% |
| 8117 |
% \begin{macro}{\lst@column@spaceflexible} |
| 8118 |
% This column format only inserts lost space by stretching (invisible) |
| 8119 |
% existing spaces; it does not insert lost space between identifiers |
| 8120 |
% and other characters where the original does not have a space. It |
| 8121 |
% was suggested by \lsthelper{Andrei~Alexandrescu}{2007-02-26}{-}. |
| 8122 |
% \begin{macrocode} |
| 8123 |
\def\lst@column@spaceflexible{% |
| 8124 |
\lst@column@flexible |
| 8125 |
\def\lst@OutputLostSpace{% |
| 8126 |
\lst@ifwhitespace |
| 8127 |
\ifx\lst@outputspace\lst@visiblespace |
| 8128 |
\else |
| 8129 |
\lst@UseLostSpace |
| 8130 |
\fi |
| 8131 |
\else |
| 8132 |
\lst@ifnewline \lst@UseLostSpace\fi |
| 8133 |
\fi}% |
| 8134 |
\let\lst@leftinsert\@empty |
| 8135 |
\let\lst@rightinsert\@empty} |
| 8136 |
% \end{macrocode} |
| 8137 |
% \end{macro} |
| 8138 |
% |
| 8139 |
% Thus, we have the column formats. Now we define macros to use them. |
| 8140 |
% |
| 8141 |
% \begin{macro}{\lst@outputpos} |
| 8142 |
% This macro sets the `output-box-positioning' parameter (the old key |
| 8143 |
% \keyname{outputpos}). We test for |l|, |c| and |r|. |
| 8144 |
% The fixed formats use |\lst@lefthss| and |\lst@righthss|, whereas the |
| 8145 |
% flexibles need |\lst@leftinsert| and |\lst@rightinsert|. |
| 8146 |
% \begin{macrocode} |
| 8147 |
\def\lst@outputpos#1#2\relax{% |
| 8148 |
\def\lst@lefthss{\lst@hss}\let\lst@righthss\lst@lefthss |
| 8149 |
\let\lst@rightinsert\lst@InsertLostSpace |
| 8150 |
\ifx #1c% |
| 8151 |
\let\lst@leftinsert\lst@InsertHalfLostSpace |
| 8152 |
\else\ifx #1r% |
| 8153 |
\let\lst@righthss\@empty |
| 8154 |
\let\lst@leftinsert\lst@InsertLostSpace |
| 8155 |
\let\lst@rightinsert\@empty |
| 8156 |
\else |
| 8157 |
\let\lst@lefthss\@empty |
| 8158 |
\let\lst@leftinsert\@empty |
| 8159 |
\ifx #1l\else \PackageWarning{Listings}% |
| 8160 |
{Unknown positioning for output boxes}% |
| 8161 |
\fi |
| 8162 |
\fi\fi} |
| 8163 |
% \end{macrocode} |
| 8164 |
% \end{macro} |
| 8165 |
% |
| 8166 |
% \begin{macro}{\lst@ifflexible} |
| 8167 |
% indicates the column mode but does not distinguish between different fixed |
| 8168 |
% or flexible modes. |
| 8169 |
% \begin{macrocode} |
| 8170 |
\def\lst@flexibletrue{\let\lst@ifflexible\iftrue} |
| 8171 |
\def\lst@flexiblefalse{\let\lst@ifflexible\iffalse} |
| 8172 |
% \end{macrocode} |
| 8173 |
% \end{macro} |
| 8174 |
% |
| 8175 |
% \begin{lstkey}{columns} |
| 8176 |
% This is done here: check optional parameter and then build the control |
| 8177 |
% sequence of the column format. |
| 8178 |
% \begin{macrocode} |
| 8179 |
\lst@Key{columns}{[c]fixed}{\lstKV@OptArg[]{#1}{% |
| 8180 |
\ifx\@empty##1\@empty\else \lst@outputpos##1\relax\relax \fi |
| 8181 |
\expandafter\let\expandafter\lst@arg |
| 8182 |
\csname\@lst @column@##2\endcsname |
| 8183 |
% \end{macrocode} |
| 8184 |
% We issue a warning or save the definition for later. |
| 8185 |
% \begin{macrocode} |
| 8186 |
\lst@arg |
| 8187 |
\ifx\lst@arg\relax |
| 8188 |
\PackageWarning{Listings}{Unknown column format `##2'}% |
| 8189 |
\else |
| 8190 |
\lst@ifflexible |
| 8191 |
\let\lst@columnsflexible\lst@arg |
| 8192 |
\else |
| 8193 |
\let\lst@columnsfixed\lst@arg |
| 8194 |
\fi |
| 8195 |
\fi}} |
| 8196 |
% \end{macrocode} |
| 8197 |
% \begin{macrocode} |
| 8198 |
\let\lst@columnsfixed\lst@column@fixed % init |
| 8199 |
\let\lst@columnsflexible\lst@column@flexible % init |
| 8200 |
% \end{macrocode} |
| 8201 |
% \end{lstkey} |
| 8202 |
% |
| 8203 |
% \begin{lstkey}{flexiblecolumns} |
| 8204 |
% Nothing else but a key to switch between the last flexible and fixed mode. |
| 8205 |
% \begin{macrocode} |
| 8206 |
\lst@Key{flexiblecolumns}\relax[t]{% |
| 8207 |
\lstKV@SetIf{#1}\lst@ifflexible |
| 8208 |
\lst@ifflexible \lst@columnsflexible |
| 8209 |
\else \lst@columnsfixed \fi} |
| 8210 |
% \end{macrocode} |
| 8211 |
% \end{lstkey} |
| 8212 |
% |
| 8213 |
% |
| 8214 |
% \subsection{New lines} |
| 8215 |
% |
| 8216 |
% \begin{macro}{\lst@newlines} |
| 8217 |
% This counter holds the number of `new lines' (cr+lf) we have to perform. |
| 8218 |
% \begin{macrocode} |
| 8219 |
\newcount\lst@newlines |
| 8220 |
\lst@AddToHook{InitVars}{\global\lst@newlines\z@} |
| 8221 |
\lst@AddToHook{InitVarsBOL}{\global\advance\lst@newlines\@ne} |
| 8222 |
% \end{macrocode} |
| 8223 |
% \end{macro} |
| 8224 |
% |
| 8225 |
% \begin{macro}{\lst@NewLine} |
| 8226 |
% This is how we start a new line: begin new paragraph and output an empty |
| 8227 |
% box. If low-level definition |\lst@OutputBox| just gobbles the box , we |
| 8228 |
% don't start a new line. This is used to drop the whole output. |
| 8229 |
% \begin{macrocode} |
| 8230 |
\def\lst@NewLine{% |
| 8231 |
\ifx\lst@OutputBox\@gobble\else |
| 8232 |
\par\noindent \hbox{}% |
| 8233 |
\fi |
| 8234 |
\global\advance\lst@newlines\m@ne |
| 8235 |
\lst@newlinetrue} |
| 8236 |
% \end{macrocode} |
| 8237 |
% Define |\lst@newlinetrue| and reset if after output. |
| 8238 |
% \begin{macrocode} |
| 8239 |
\def\lst@newlinetrue{\global\let\lst@ifnewline\iftrue} |
| 8240 |
\lst@AddToHookExe{PostOutput}{\global\let\lst@ifnewline\iffalse}% init |
| 8241 |
% \end{macrocode} |
| 8242 |
% \end{macro} |
| 8243 |
% |
| 8244 |
% \begin{macro}{\lst@TrackNewLines} |
| 8245 |
% If |\lst@newlines| is positive, we execute the hook and insert the |
| 8246 |
% new lines. |
| 8247 |
% \begin{macrocode} |
| 8248 |
\def\lst@TrackNewLines{% |
| 8249 |
\ifnum\lst@newlines>\z@ |
| 8250 |
\lsthk@OnNewLine |
| 8251 |
\lst@DoNewLines |
| 8252 |
\fi} |
| 8253 |
\lst@AddToHook{OnNewLine}{}% init |
| 8254 |
% \end{macrocode} |
| 8255 |
% \end{macro} |
| 8256 |
% |
| 8257 |
% \begin{lstkey}{emptylines} |
| 8258 |
% \lsthelper{Adam~Prugel-Bennett}{2001/02/19}{spacing of empty lines} asked for |
| 8259 |
% such a key---if I didn't misunderstood him. We check for the optional star |
| 8260 |
% and set |\lst@maxempty| and switch. |
| 8261 |
% \begin{macrocode} |
| 8262 |
\lst@Key{emptylines}\maxdimen{% |
| 8263 |
\@ifstar{\lst@true\@tempcnta\@gobble#1\relax\lst@GobbleNil}% |
| 8264 |
{\lst@false\@tempcnta#1\relax\lst@GobbleNil}#1\@nil |
| 8265 |
\advance\@tempcnta\@ne |
| 8266 |
\edef\lst@maxempty{\the\@tempcnta\relax}% |
| 8267 |
\let\lst@ifpreservenumber\lst@if} |
| 8268 |
% \end{macrocode} |
| 8269 |
% \end{lstkey} |
| 8270 |
% |
| 8271 |
% \begin{macro}{\lst@DoNewLines} |
| 8272 |
% First we take care of |\lst@maxempty| and then of the remaining empty lines. |
| 8273 |
% \begin{macrocode} |
| 8274 |
\def\lst@DoNewLines{% |
| 8275 |
\@whilenum\lst@newlines>\lst@maxempty \do |
| 8276 |
{\lst@ifpreservenumber |
| 8277 |
\lsthk@OnEmptyLine |
| 8278 |
\global\advance\c@lstnumber\lst@advancelstnum |
| 8279 |
\fi |
| 8280 |
\global\advance\lst@newlines\m@ne}% |
| 8281 |
\@whilenum \lst@newlines>\@ne \do |
| 8282 |
{\lsthk@OnEmptyLine \lst@NewLine}% |
| 8283 |
\ifnum\lst@newlines>\z@ \lst@NewLine \fi} |
| 8284 |
\lst@AddToHook{OnEmptyLine}{}% init |
| 8285 |
% \end{macrocode} |
| 8286 |
% \end{macro} |
| 8287 |
% |
| 8288 |
% |
| 8289 |
% \subsection{High-level output} |
| 8290 |
% |
| 8291 |
% \begin{lstkey}{identifierstyle} |
| 8292 |
% A simple key. |
| 8293 |
% \begin{macrocode} |
| 8294 |
\lst@Key{identifierstyle}{}{\def\lst@identifierstyle{#1}} |
| 8295 |
\lst@AddToHook{EmptyStyle}{\let\lst@identifierstyle\@empty} |
| 8296 |
% \end{macrocode} |
| 8297 |
% \end{lstkey} |
| 8298 |
% |
| 8299 |
% \begin{macro}{\lst@GotoTabStop} |
| 8300 |
% Here we look whether the line already contains printed characters. |
| 8301 |
% If true, we output a box with the width of a blank space. |
| 8302 |
% \begin{macrocode} |
| 8303 |
\def\lst@GotoTabStop{% |
| 8304 |
\ifnum\lst@newlines=\z@ |
| 8305 |
\setbox\@tempboxa\hbox{\lst@outputspace}% |
| 8306 |
\setbox\@tempboxa\hbox to\wd\@tempboxa{{\lst@currstyle{\hss}}}% |
| 8307 |
\lst@CalcLostSpaceAndOutput |
| 8308 |
% \end{macrocode} |
| 8309 |
% It's probably not clear why it is sufficient to output a single space to go |
| 8310 |
% to the next tabulator stop. Just note that the space lost by this process is |
| 8311 |
% `lost space' in the sense above and therefore will be inserted before the |
| 8312 |
% next characters are output. |
| 8313 |
% \begin{macrocode} |
| 8314 |
\else |
| 8315 |
% \end{macrocode} |
| 8316 |
% Otherwise (no printed characters) we only need to advance |\lst@lostspace|, |
| 8317 |
% which is inserted by |\lst@OutputToken| above, and update the column. |
| 8318 |
% \begin{macrocode} |
| 8319 |
\global\advance\lst@lostspace \lst@length\lst@width |
| 8320 |
\global\advance\lst@column\lst@length \lst@length\z@ |
| 8321 |
\fi} |
| 8322 |
% \end{macrocode} |
| 8323 |
% Note that this version works also in flexible column mode. |
| 8324 |
% In fact, it's mainly the flexible version of \packagename{listings} 0.20. |
| 8325 |
% \begin{TODO} |
| 8326 |
% Use |\lst@ifnewline| instead of |\ifnum\lst@newlines=\z@|? |
| 8327 |
% \end{TODO} |
| 8328 |
% \end{macro} |
| 8329 |
% |
| 8330 |
% \begin{macro}{\lst@OutputOther} |
| 8331 |
% becomes easy with the previous definitions. |
| 8332 |
% \begin{macrocode} |
| 8333 |
\def\lst@OutputOther{% |
| 8334 |
\lst@CheckDelay |
| 8335 |
\ifnum\lst@length=\z@\else |
| 8336 |
\let\lst@thestyle\lst@currstyle |
| 8337 |
\lsthk@OutputOther |
| 8338 |
\lst@OutputToken |
| 8339 |
\fi} |
| 8340 |
% \end{macrocode} |
| 8341 |
% \begin{macrocode} |
| 8342 |
\lst@AddToHook{OutputOther}{}% init |
| 8343 |
\let\lst@currstyle\relax % init |
| 8344 |
% \end{macrocode} |
| 8345 |
% \end{macro} |
| 8346 |
% |
| 8347 |
% \begin{macro}{\lst@Output} |
| 8348 |
% We might use identifier style as default. |
| 8349 |
% \begin{macrocode} |
| 8350 |
\def\lst@Output{% |
| 8351 |
\lst@CheckDelay |
| 8352 |
\ifnum\lst@length=\z@\else |
| 8353 |
\ifx\lst@currstyle\relax |
| 8354 |
\let\lst@thestyle\lst@identifierstyle |
| 8355 |
\else |
| 8356 |
\let\lst@thestyle\lst@currstyle |
| 8357 |
\fi |
| 8358 |
\lsthk@Output |
| 8359 |
\lst@OutputToken |
| 8360 |
\fi |
| 8361 |
\let\lst@lastother\relax} |
| 8362 |
% \end{macrocode} |
| 8363 |
% Note that |\lst@lastother| becomes equivalent to |\relax| and not equivalent |
| 8364 |
% to |\@empty| as everywhere else. I don't know whether this will be important |
| 8365 |
% in the future or not. |
| 8366 |
% \begin{macrocode} |
| 8367 |
\lst@AddToHook{Output}{}% init |
| 8368 |
% \end{macrocode} |
| 8369 |
% \end{macro} |
| 8370 |
% |
| 8371 |
% \begin{macro}{\lst@GetOutputMacro} |
| 8372 |
% Just saves the output macro to be used. |
| 8373 |
% \begin{macrocode} |
| 8374 |
\def\lst@GetOutputMacro#1{% |
| 8375 |
\lst@ifletter \global\let#1\lst@Output |
| 8376 |
\else \global\let#1\lst@OutputOther\fi} |
| 8377 |
% \end{macrocode} |
| 8378 |
% \end{macro} |
| 8379 |
% |
| 8380 |
% \begin{macro}{\lst@PrintToken} |
| 8381 |
% outputs the current character string in letter or nonletter mode. |
| 8382 |
% \begin{macrocode} |
| 8383 |
\def\lst@PrintToken{% |
| 8384 |
\lst@ifletter \lst@Output \lst@letterfalse |
| 8385 |
\else \lst@OutputOther \let\lst@lastother\@empty \fi} |
| 8386 |
% \end{macrocode} |
| 8387 |
% \end{macro} |
| 8388 |
% |
| 8389 |
% \begin{macro}{\lst@XPrintToken} |
| 8390 |
% is a special definition to print also merged characters. |
| 8391 |
% \begin{macrocode} |
| 8392 |
\def\lst@XPrintToken{% |
| 8393 |
\lst@PrintToken \lst@CheckMerge |
| 8394 |
\ifnum\lst@length=\z@\else \lst@PrintToken \fi} |
| 8395 |
% \end{macrocode} |
| 8396 |
% \end{macro} |
| 8397 |
% |
| 8398 |
% |
| 8399 |
% \subsection{Dropping the whole output} |
| 8400 |
% |
| 8401 |
% \begin{macro}{\lst@BeginDropOutput} |
| 8402 |
% It's sometimes useful to process a part of a listing as usual, but to drop |
| 8403 |
% the output. This macro does the main work and gets one argument, namely the |
| 8404 |
% internal mode it enters. We save |\lst@newlines|, restore it |\aftergroup| |
| 8405 |
% and redefine one macro, namely |\lst@OutputBox|. After a bug report from |
| 8406 |
% \lsthelper{Gunther~Schmidl}{2002/02/27}{collapsing empty lines don't work |
| 8407 |
% with printpod=false} |
| 8408 |
% \begin{macrocode} |
| 8409 |
\def\lst@BeginDropOutput#1{% |
| 8410 |
\xdef\lst@BDOnewlines{\the\lst@newlines}% |
| 8411 |
\global\let\lst@BDOifnewline\lst@ifnewline |
| 8412 |
\lst@EnterMode{#1}% |
| 8413 |
{\lst@modetrue |
| 8414 |
\let\lst@OutputBox\@gobble |
| 8415 |
\aftergroup\lst@BDORestore}} |
| 8416 |
% \end{macrocode} |
| 8417 |
% Restoring the date is quite easy: |
| 8418 |
% \begin{macrocode} |
| 8419 |
\def\lst@BDORestore{% |
| 8420 |
\global\lst@newlines\lst@BDOnewlines |
| 8421 |
\global\let\lst@ifnewline\lst@BDOifnewline} |
| 8422 |
% \end{macrocode} |
| 8423 |
% \end{macro} |
| 8424 |
% |
| 8425 |
% \begin{macro}{\lst@EndDropOutput} |
| 8426 |
% is equivalent to |\lst@LeaveMode|. |
| 8427 |
% \begin{macrocode} |
| 8428 |
\let\lst@EndDropOutput\lst@LeaveMode |
| 8429 |
% \end{macrocode} |
| 8430 |
% \begin{macrocode} |
| 8431 |
%</kernel> |
| 8432 |
% \end{macrocode} |
| 8433 |
% \end{macro} |
| 8434 |
% |
| 8435 |
% |
| 8436 |
% \subsection{Writing to an external file} |
| 8437 |
% |
| 8438 |
% \begin{aspect}{writefile} |
| 8439 |
% Now it would be good to know something about character classes since we need |
| 8440 |
% to access the true input characters, for example a tabulator and not the |
| 8441 |
% spaces it `expands' to. |
| 8442 |
% \begin{macrocode} |
| 8443 |
%<*misc> |
| 8444 |
\lst@BeginAspect{writefile} |
| 8445 |
% \end{macrocode} |
| 8446 |
% |
| 8447 |
% \begin{macro}{\lst@WF} |
| 8448 |
% \begin{macro}{\lst@WFtoken} |
| 8449 |
% The contents of the token will be written to file. |
| 8450 |
% \begin{macrocode} |
| 8451 |
\newtoks\lst@WFtoken % global |
| 8452 |
\lst@AddToHook{InitVarsBOL}{\global\lst@WFtoken{}} |
| 8453 |
% \end{macrocode} |
| 8454 |
% \begin{macrocode} |
| 8455 |
\newwrite\lst@WF |
| 8456 |
\global\let\lst@WFifopen\iffalse % init |
| 8457 |
% \end{macrocode} |
| 8458 |
% \end{macro} |
| 8459 |
% \end{macro} |
| 8460 |
% |
| 8461 |
% \begin{macro}{\lst@WFWriteToFile} |
| 8462 |
% To do this, we have to expand the contents and then expand this via |\edef|. |
| 8463 |
% Empty |\lst@UM| ensures that special characters (underscore, dollar, etc.) |
| 8464 |
% are written correctly. |
| 8465 |
% \begin{macrocode} |
| 8466 |
\gdef\lst@WFWriteToFile{% |
| 8467 |
\begingroup |
| 8468 |
\let\lst@UM\@empty |
| 8469 |
\expandafter\edef\expandafter\lst@temp\expandafter{\the\lst@WFtoken}% |
| 8470 |
\immediate\write\lst@WF{\lst@temp}% |
| 8471 |
\endgroup |
| 8472 |
\global\lst@WFtoken{}} |
| 8473 |
% \end{macrocode} |
| 8474 |
% \end{macro} |
| 8475 |
% |
| 8476 |
% \begin{macro}{\lst@WFAppend} |
| 8477 |
% Similar to |\lst@Append| but uses |\lst@WFtoken|. |
| 8478 |
% \begin{macrocode} |
| 8479 |
\gdef\lst@WFAppend#1{% |
| 8480 |
\global\lst@WFtoken=\expandafter{\the\lst@WFtoken#1}} |
| 8481 |
% \end{macrocode} |
| 8482 |
% \end{macro} |
| 8483 |
% |
| 8484 |
% \begin{macro}{\lst@BeginWriteFile} |
| 8485 |
% \begin{macro}{\lst@BeginAlsoWriteFile} |
| 8486 |
% use different macros for |\lst@OutputBox| (not) to drop the output. |
| 8487 |
% \begin{macrocode} |
| 8488 |
\gdef\lst@BeginWriteFile{\lst@WFBegin\@gobble} |
| 8489 |
\gdef\lst@BeginAlsoWriteFile{\lst@WFBegin\lst@OutputBox} |
| 8490 |
% \end{macrocode} |
| 8491 |
% \end{macro} |
| 8492 |
% \end{macro} |
| 8493 |
% |
| 8494 |
% \begin{macro}{\lst@WFBegin} |
| 8495 |
% Here \ldots |
| 8496 |
% \begin{macrocode} |
| 8497 |
\begingroup \catcode`\^^I=11 |
| 8498 |
\gdef\lst@WFBegin#1#2{% |
| 8499 |
\begingroup |
| 8500 |
\let\lst@OutputBox#1% |
| 8501 |
% \end{macrocode} |
| 8502 |
% \ldots\space we have to update |\lst@WFtoken| and \ldots |
| 8503 |
% \begin{macrocode} |
| 8504 |
\def\lst@Append##1{% |
| 8505 |
\advance\lst@length\@ne |
| 8506 |
\expandafter\lst@token\expandafter{\the\lst@token##1}% |
| 8507 |
\ifx ##1\lst@outputspace \else |
| 8508 |
\lst@WFAppend##1% |
| 8509 |
\fi}% |
| 8510 |
\lst@lAddTo\lst@PreGotoTabStop{\lst@WFAppend{^^I}}% |
| 8511 |
\lst@lAddTo\lst@ProcessSpace{\lst@WFAppend{ }}% |
| 8512 |
% \end{macrocode} |
| 8513 |
% \ldots\space need different `EOL' and `DeInit' definitions to write the |
| 8514 |
% token register to file. |
| 8515 |
% \begin{macrocode} |
| 8516 |
\let\lst@DeInit\lst@WFDeInit |
| 8517 |
\let\lst@MProcessListing\lst@WFMProcessListing |
| 8518 |
% \end{macrocode} |
| 8519 |
% Finally we open the file if necessary. |
| 8520 |
% \begin{macrocode} |
| 8521 |
\lst@WFifopen\else |
| 8522 |
\immediate\openout\lst@WF=#2\relax |
| 8523 |
\global\let\lst@WFifopen\iftrue |
| 8524 |
\@gobbletwo\fi\fi |
| 8525 |
\fi} |
| 8526 |
\endgroup |
| 8527 |
% \end{macrocode} |
| 8528 |
% \end{macro} |
| 8529 |
% |
| 8530 |
% \begin{macro}{\lst@EndWriteFile} |
| 8531 |
% closes the file and restores original definitions. |
| 8532 |
% \begin{macrocode} |
| 8533 |
\gdef\lst@EndWriteFile{% |
| 8534 |
\immediate\closeout\lst@WF \endgroup |
| 8535 |
\global\let\lst@WFifopen\iffalse} |
| 8536 |
% \end{macrocode} |
| 8537 |
% \end{macro} |
| 8538 |
% |
| 8539 |
% \begin{macro}{\lst@WFMProcessListing} |
| 8540 |
% \begin{macro}{\lst@WFDeInit} |
| 8541 |
% write additionally |\lst@WFtoken| to external file. |
| 8542 |
% \begin{macrocode} |
| 8543 |
\global\let\lst@WFMProcessListing\lst@MProcessListing |
| 8544 |
\global\let\lst@WFDeInit\lst@DeInit |
| 8545 |
\lst@AddToAtTop\lst@WFMProcessListing{\lst@WFWriteToFile} |
| 8546 |
\lst@AddToAtTop\lst@WFDeInit{% |
| 8547 |
\ifnum\lst@length=\z@\else \lst@WFWriteToFile \fi} |
| 8548 |
% \end{macrocode} |
| 8549 |
% \end{macro} |
| 8550 |
% \end{macro} |
| 8551 |
% |
| 8552 |
% \begin{macrocode} |
| 8553 |
\lst@EndAspect |
| 8554 |
%</misc> |
| 8555 |
% \end{macrocode} |
| 8556 |
% \end{aspect} |
| 8557 |
% |
| 8558 |
% |
| 8559 |
% \section{Character classes}\label{iCharacterClasses} |
| 8560 |
% |
| 8561 |
% In this section, we define how the basic character classes do behave, before |
| 8562 |
% turning over to the selection of character tables and how to specialize |
| 8563 |
% characters. |
| 8564 |
% |
| 8565 |
% |
| 8566 |
% \subsection{Letters, digits and others} |
| 8567 |
% |
| 8568 |
% \begin{macrocode} |
| 8569 |
%<*kernel> |
| 8570 |
% \end{macrocode} |
| 8571 |
% |
| 8572 |
% \begin{macro}{\lst@ProcessLetter} |
| 8573 |
% We put the letter, which is not a whitespace, into the output queue. |
| 8574 |
% \begin{macrocode} |
| 8575 |
\def\lst@ProcessLetter{\lst@whitespacefalse \lst@AppendLetter} |
| 8576 |
% \end{macrocode} |
| 8577 |
% \end{macro} |
| 8578 |
% |
| 8579 |
% \begin{macro}{\lst@ProcessOther} |
| 8580 |
% Ditto. |
| 8581 |
% \begin{macrocode} |
| 8582 |
\def\lst@ProcessOther{\lst@whitespacefalse \lst@AppendOther} |
| 8583 |
% \end{macrocode} |
| 8584 |
% \end{macro} |
| 8585 |
% |
| 8586 |
% \begin{macro}{\lst@ProcessDigit} |
| 8587 |
% A digit appends the character to the current character string. But we must |
| 8588 |
% use the right macro. This allows digits to be part of an identifier or |
| 8589 |
% a numerical constant. |
| 8590 |
% \begin{macrocode} |
| 8591 |
\def\lst@ProcessDigit{% |
| 8592 |
\lst@whitespacefalse |
| 8593 |
\lst@ifletter \expandafter\lst@AppendLetter |
| 8594 |
\else \expandafter\lst@AppendOther\fi} |
| 8595 |
% \end{macrocode} |
| 8596 |
% \end{macro} |
| 8597 |
% |
| 8598 |
% \begin{macro}{\lst@ifwhitespace} |
| 8599 |
% indicates whether the last processed character has been white space. |
| 8600 |
% \begin{macrocode} |
| 8601 |
\def\lst@whitespacetrue{\global\let\lst@ifwhitespace\iftrue} |
| 8602 |
\def\lst@whitespacefalse{\global\let\lst@ifwhitespace\iffalse} |
| 8603 |
\lst@AddToHook{InitVarsBOL}{\lst@whitespacetrue} |
| 8604 |
% \end{macrocode} |
| 8605 |
% \end{macro} |
| 8606 |
% |
| 8607 |
% |
| 8608 |
% \subsection{Whitespaces} |
| 8609 |
% |
| 8610 |
% Here we have to take care of two things: dropping empty lines at the end of |
| 8611 |
% a listing and the different column formats. Both use |\lst@lostspace|. Lines |
| 8612 |
% containing only tabulators and spaces should be viewed as empty. In order to |
| 8613 |
% achieve this, tabulators and spaces at the beginning of a line don't output |
| 8614 |
% any characters but advance |\lst@lostspace|. Whenever this dimension is |
| 8615 |
% positive we insert that space before the character string is output. Thus, |
| 8616 |
% if there are only tabulators and spaces, the line is `empty' since we |
| 8617 |
% haven't done any output. |
| 8618 |
% |
| 8619 |
% We have to do more for flexible columns. Whitespaces can fix the column |
| 8620 |
% alignment: if the real line is wider than expected, a tabulator is at least |
| 8621 |
% one space wide; all remaining space fixes the alignment. If there are two or |
| 8622 |
% more space characters, at least one is printed; the others fix the column |
| 8623 |
% alignment. |
| 8624 |
% |
| 8625 |
% |
| 8626 |
% \paragraph{Tabulators} |
| 8627 |
% are processed in three stages. You have already seen the last stage |
| 8628 |
% |\lst@GotoTabStop|. The other two calculate the necessary width and take care |
| 8629 |
% of visible tabulators and spaces. |
| 8630 |
% |
| 8631 |
% \begin{lstkey}{tabsize} |
| 8632 |
% We check for a legal argument before saving it. Default tabsize is 8 as |
| 8633 |
% proposed by \lsthelper{Rolf~Niepraschk}{1997/04/24}{tabsize=8}. |
| 8634 |
% \begin{macrocode} |
| 8635 |
\lst@Key{tabsize}{8} |
| 8636 |
{\ifnum#1>\z@ \def\lst@tabsize{#1}\else |
| 8637 |
\PackageError{Listings}{Strict positive integer expected}% |
| 8638 |
{You can't use `#1' as tabsize. \@ehc}% |
| 8639 |
\fi} |
| 8640 |
% \end{macrocode} |
| 8641 |
% \end{lstkey} |
| 8642 |
% |
| 8643 |
% \begin{lstkey}{showtabs} |
| 8644 |
% \begin{lstkey}{tab} |
| 8645 |
% Two more user keys for tab control. |
| 8646 |
% \begin{macrocode} |
| 8647 |
\lst@Key{showtabs}f[t]{\lstKV@SetIf{#1}\lst@ifshowtabs} |
| 8648 |
\lst@Key{tab}{\kern.06em\hbox{\vrule\@height.3ex}% |
| 8649 |
\hrulefill\hbox{\vrule\@height.3ex}} |
| 8650 |
{\def\lst@tab{#1}} |
| 8651 |
% \end{macrocode} |
| 8652 |
% \end{lstkey} |
| 8653 |
% \end{lstkey} |
| 8654 |
% |
| 8655 |
% \begin{macro}{\lst@ProcessTabulator} |
| 8656 |
% A tabulator outputs the preceding characters, which decrements |\lst@pos| by |
| 8657 |
% the number of printed characters. |
| 8658 |
% \begin{macrocode} |
| 8659 |
\def\lst@ProcessTabulator{% |
| 8660 |
\lst@XPrintToken \lst@whitespacetrue |
| 8661 |
% \end{macrocode} |
| 8662 |
% Then we calculate how many columns we need to reach the next tabulator stop: |
| 8663 |
% we add |\lst@tabsize| until |\lst@pos| is strict positive. In other words, |
| 8664 |
% |\lst@pos| is the column modulo |tabsize| and we're looking for a positive |
| 8665 |
% representative. We assign it to |\lst@length| and reset |\lst@pos| in the |
| 8666 |
% submacro. |
| 8667 |
% \begin{macrocode} |
| 8668 |
\global\advance\lst@column -\lst@pos |
| 8669 |
\@whilenum \lst@pos<\@ne \do |
| 8670 |
{\global\advance\lst@pos\lst@tabsize}% |
| 8671 |
\lst@length\lst@pos |
| 8672 |
\lst@PreGotoTabStop} |
| 8673 |
% \end{macrocode} |
| 8674 |
% \end{macro} |
| 8675 |
% |
| 8676 |
% \begin{macro}{\lst@PreGotoTabStop} |
| 8677 |
% Visible tabs print |\lst@tab|. |
| 8678 |
% \begin{macrocode} |
| 8679 |
\def\lst@PreGotoTabStop{% |
| 8680 |
\lst@ifshowtabs |
| 8681 |
\lst@TrackNewLines |
| 8682 |
\setbox\@tempboxa\hbox to\lst@length\lst@width |
| 8683 |
{{\lst@currstyle{\hss\lst@tab}}}% |
| 8684 |
\lst@CalcLostSpaceAndOutput |
| 8685 |
\else |
| 8686 |
% \end{macrocode} |
| 8687 |
% If we are advised to keep spaces, we insert the correct number of them. |
| 8688 |
% \begin{macrocode} |
| 8689 |
\lst@ifkeepspaces |
| 8690 |
\@tempcnta\lst@length \lst@length\z@ |
| 8691 |
\@whilenum \@tempcnta>\z@ \do |
| 8692 |
{\lst@AppendOther\lst@outputspace |
| 8693 |
\advance\@tempcnta\m@ne}% |
| 8694 |
\lst@OutputOther |
| 8695 |
\else |
| 8696 |
\lst@GotoTabStop |
| 8697 |
\fi |
| 8698 |
\fi |
| 8699 |
\lst@length\z@ \global\lst@pos\z@} |
| 8700 |
% \end{macrocode} |
| 8701 |
% \end{macro} |
| 8702 |
% |
| 8703 |
% |
| 8704 |
% \paragraph{Spaces} |
| 8705 |
% are implemented as described at the beginning of this subsection. But first |
| 8706 |
% we define some user keys. |
| 8707 |
% |
| 8708 |
% \begin{macro}{\lst@outputspace} |
| 8709 |
% \begin{macro}{\lst@visiblespace} |
| 8710 |
% \lsthelper{Denis Bitouz\'e}{2020/09/12}{`lst@visiblespace: |
| 8711 |
% `verbvisiblespace instead of `textvisiblespace} pointed out, that, |
| 8712 |
% with Lua\LaTeX{} and some monospaced font which doesn't have an |
| 8713 |
% appropriate glyph in slot 32, `showspaces' hasn't any effect by using |
| 8714 |
% |\textvisiblespace|. So now we're using |\verbvisiblespace| as a default |
| 8715 |
% definition for the first macro, the test for the fontfamily |
| 8716 |
% |\lst@ttfamily| is deleted, because in most of the cases it lead to |
| 8717 |
% the (wrong) output of |\char32|. The definition of |\verbvisible| |
| 8718 |
% from latex.ltx takes the different behaviour of the modern \TeX{} |
| 8719 |
% engines into account and defines a valid |\verbvisiblespace| |
| 8720 |
% \begin{macrocode} |
| 8721 |
\def\lst@outputspace{\ } |
| 8722 |
\def\lst@visiblespace{\verbvisiblespace} |
| 8723 |
% \end{macrocode} |
| 8724 |
% \end{macro} |
| 8725 |
% \end{macro} |
| 8726 |
% |
| 8727 |
% \begin{lstkey}{showspaces} |
| 8728 |
% \begin{lstkey}{keepspaces} |
| 8729 |
% \ldots\space which is modified on user's request. |
| 8730 |
% \begin{macrocode} |
| 8731 |
\lst@Key{showspaces}{false}[t]{\lstKV@SetIf{#1}\lst@ifshowspaces} |
| 8732 |
\lst@Key{keepspaces}{false}[t]{\lstKV@SetIf{#1}\lst@ifkeepspaces} |
| 8733 |
\lst@AddToHook{Init} |
| 8734 |
{\lst@ifshowspaces |
| 8735 |
\let\lst@outputspace\lst@visiblespace |
| 8736 |
\lst@keepspacestrue |
| 8737 |
\fi} |
| 8738 |
\def\lst@keepspacestrue{\let\lst@ifkeepspaces\iftrue} |
| 8739 |
% \end{macrocode} |
| 8740 |
% \end{lstkey} |
| 8741 |
% \end{lstkey} |
| 8742 |
% |
| 8743 |
% \begin{macro}{\lst@ProcessSpace} |
| 8744 |
% We look whether spaces fix the column alignment or not. In the latter case |
| 8745 |
% we append a space; otherwise \ldots |
| 8746 |
% \lsthelper{Andrei~Alexandrescu}{2007/02/27}{-} tested the |spaceflexible| |
| 8747 |
% column setting and found a bug that resulted from |\lst@PrintToken| and |
| 8748 |
% |\lst@whitespacetrue| being out of order here. |
| 8749 |
% \begin{macrocode} |
| 8750 |
\def\lst@ProcessSpace{% |
| 8751 |
\lst@ifkeepspaces |
| 8752 |
\lst@PrintToken |
| 8753 |
\lst@whitespacetrue |
| 8754 |
\lst@AppendOther\lst@outputspace |
| 8755 |
\lst@PrintToken |
| 8756 |
\else \ifnum\lst@newlines=\z@ |
| 8757 |
% \end{macrocode} |
| 8758 |
% \ldots\space we append a `special space' if the line isn't empty. |
| 8759 |
% \begin{macrocode} |
| 8760 |
\lst@AppendSpecialSpace |
| 8761 |
\else \ifnum\lst@length=\z@ |
| 8762 |
% \end{macrocode} |
| 8763 |
% If the line is empty, we check whether there are characters in the output |
| 8764 |
% queue. If there are no characters we just advance |\lst@lostspace|. |
| 8765 |
% Otherwise we append the space. |
| 8766 |
% \begin{macrocode} |
| 8767 |
\global\advance\lst@lostspace\lst@width |
| 8768 |
\global\advance\lst@pos\m@ne |
| 8769 |
\lst@whitespacetrue |
| 8770 |
\else |
| 8771 |
\lst@AppendSpecialSpace |
| 8772 |
\fi |
| 8773 |
\fi \fi} |
| 8774 |
% \end{macrocode} |
| 8775 |
% Note that this version works for fixed and flexible column output. |
| 8776 |
% \end{macro} |
| 8777 |
% |
| 8778 |
% \begin{macro}{\lst@AppendSpecialSpace} |
| 8779 |
% If there are at least two white spaces, we output preceding characters and |
| 8780 |
% advance |\lst@lostspace| to avoid alignment problems. Otherwise we append |
| 8781 |
% a space to the current character string. Also, |\lst@whitespacetrue| has |
| 8782 |
% been moved after |\lst@PrintToken| so that the token-printer can correctly |
| 8783 |
% check whether it is printing whitespace or not; this was preventing the |
| 8784 |
% |spaceflexible| column setting from working correctly. |
| 8785 |
% \begin{macrocode} |
| 8786 |
\def\lst@AppendSpecialSpace{% |
| 8787 |
\lst@ifwhitespace |
| 8788 |
\lst@PrintToken |
| 8789 |
\global\advance\lst@lostspace\lst@width |
| 8790 |
\global\advance\lst@pos\m@ne |
| 8791 |
\lst@gobbledwhitespacetrue |
| 8792 |
\else |
| 8793 |
\lst@PrintToken |
| 8794 |
\lst@whitespacetrue |
| 8795 |
\lst@AppendOther\lst@outputspace |
| 8796 |
\lst@PrintToken |
| 8797 |
\fi} |
| 8798 |
% \end{macrocode} |
| 8799 |
% \end{macro} |
| 8800 |
% |
| 8801 |
% |
| 8802 |
% \paragraph{Form feeds} |
| 8803 |
% has been introduced after communication with |
| 8804 |
% \lsthelper{Jan~Braun}{1998/04/27}{formfeed}. |
| 8805 |
% |
| 8806 |
% \begin{lstkey}{formfeed} |
| 8807 |
% let the user make adjustments. |
| 8808 |
% \begin{macrocode} |
| 8809 |
\lst@Key{formfeed}{\bigbreak}{\def\lst@formfeed{#1}} |
| 8810 |
% \end{macrocode} |
| 8811 |
% \end{lstkey} |
| 8812 |
% |
| 8813 |
% \begin{macro}{\lst@ProcessFormFeed} |
| 8814 |
% Here we execute some macros according to whether a new line has already |
| 8815 |
% begun or not. No |\lst@EOLUpdate| is used in the else branch |
| 8816 |
% anymore---\lsthelper{Kalle~Tuulos}{2001/01/14}{form feed gobbles following |
| 8817 |
% output unit} sent the bug report. |
| 8818 |
% \begin{macrocode} |
| 8819 |
\def\lst@ProcessFormFeed{% |
| 8820 |
\lst@XPrintToken |
| 8821 |
\ifnum\lst@newlines=\z@ |
| 8822 |
\lst@EOLUpdate \lsthk@InitVarsBOL |
| 8823 |
\fi |
| 8824 |
\lst@formfeed |
| 8825 |
\lst@whitespacetrue} |
| 8826 |
% \end{macrocode} |
| 8827 |
% \end{macro} |
| 8828 |
% |
| 8829 |
% |
| 8830 |
% \subsection{Character tables}\label{iCharacterTables} |
| 8831 |
% |
| 8832 |
% |
| 8833 |
% \subsubsection{The standard table} |
| 8834 |
% |
| 8835 |
% The standard character table is selected by |\lst@SelectStdCharTable|, which |
| 8836 |
% expands to a token sequence |
| 8837 |
% \ldots|\def| |A{\lst@ProcessLetter| |A}|\ldots\space |
| 8838 |
% where the first A is active and the second has catcode 12. We use the |
| 8839 |
% following macros to build the character table. |
| 8840 |
% \begin{syntax} |
| 8841 |
% \item[0.19] |\lst@CCPut|\meta{class |
| 8842 |
% macro}\meta{$c_1$}\ldots\meta{$c_k$}|\z@| |
| 8843 |
% |
| 8844 |
% extends the standard character table by the characters with codes |
| 8845 |
% \meta{$c_1$}\ldots\meta{$c_k$} making each character use \meta{class |
| 8846 |
% macro}. All these characters must be printable via |
| 8847 |
% |\char|\meta{$c_i$}. |
| 8848 |
% |
| 8849 |
% \item[0.20] |
| 8850 |
% |\lst@CCPutMacro|\meta{class$_1$}\meta{$c_1$}\meta{definition$_1$}^^A |
| 8851 |
% \ldots|\@empty\z@\@empty| |
| 8852 |
% |
| 8853 |
% also extends the standard character table: the character |
| 8854 |
% \meta{$c_i$} will use |
| 8855 |
% \meta{class$_i$} and is printed via |
| 8856 |
% \meta{definition$_i$}. These definitions must be \meta{spec. token}s |
| 8857 |
% in the sense of section \ref{dCharacterTables}. |
| 8858 |
% \end{syntax} |
| 8859 |
% |
| 8860 |
% \begin{macro}{\lst@Def} |
| 8861 |
% \begin{macro}{\lst@Let} |
| 8862 |
% For speed we won't use these helpers too often. |
| 8863 |
% \begin{macrocode} |
| 8864 |
\def\lst@Def#1{\lccode`\~=#1\lowercase{\def~}} |
| 8865 |
\def\lst@Let#1{\lccode`\~=#1\lowercase{\let~}} |
| 8866 |
% \end{macrocode} |
| 8867 |
% \end{macro} |
| 8868 |
% \end{macro} |
| 8869 |
% |
| 8870 |
% \begingroup |
| 8871 |
% The definition of the space below doesn't hurt anything. But other aspects, |
| 8872 |
% for example \aspectname{lineshape} and \aspectname{formats}, redefine also |
| 8873 |
% the macro |\space|. Now, if \LaTeX\ calls |\try@load@fontshape|, the |.log| |
| 8874 |
% messages would show some strange things since \LaTeX\ uses |\space| in these |
| 8875 |
% messages. The following addition ensures that |\space| expands to a space |
| 8876 |
% and not to something different. This was one more bug reported by |
| 8877 |
% \lsthelper{Denis~Girou}{1999/09/16}{bad font info message with breaklines}. |
| 8878 |
% \begin{macrocode} |
| 8879 |
\lst@AddToAtTop{\try@load@fontshape}{\def\space{ }} |
| 8880 |
% \end{macrocode} |
| 8881 |
% \endgroup |
| 8882 |
% |
| 8883 |
% \begin{macro}{\lst@SelectStdCharTable} |
| 8884 |
% The first three standard characters. |\lst@Let| has been replaced by |
| 8885 |
% |\lst@Def| after a bug report from \lsthelper{Chris~Edwards}{2002/02/15} |
| 8886 |
% {tabulators show up with firstline>1}. |
| 8887 |
% \begin{macrocode} |
| 8888 |
\def\lst@SelectStdCharTable{% |
| 8889 |
\lst@Def{9}{\lst@ProcessTabulator}% |
| 8890 |
\lst@Def{12}{\lst@ProcessFormFeed}% |
| 8891 |
\lst@Def{32}{\lst@ProcessSpace}} |
| 8892 |
% \end{macrocode} |
| 8893 |
% \end{macro} |
| 8894 |
% |
| 8895 |
% \begin{macro}{\lst@CCPut} |
| 8896 |
% The first argument gives the character class, then follow the |
| 8897 |
% codes. |
| 8898 |
% |
| 8899 |
% \lsthelper{Joseph~Wright}{2016/04/04}{unguarded setting of |lccode|} |
| 8900 |
% pointed to a bug which came up on TeX StackExchange |
| 8901 |
% (|http://tex.stackexchange.com/questions/302437/textcase-lstings-and-tilde|). Other |
| 8902 |
% than in |\lst@CCPutMacro| the |\lccode| settings weren't local and caused |
| 8903 |
% the error. |
| 8904 |
% \begin{macrocode} |
| 8905 |
\def\lst@CCPut#1#2{% |
| 8906 |
\ifnum#2=\z@ |
| 8907 |
\expandafter\@gobbletwo |
| 8908 |
\else |
| 8909 |
\begingroup\lccode`\~=#2\lccode`\/=#2\lowercase{\endgroup\lst@CCPut@~{#1/}}% |
| 8910 |
\fi |
| 8911 |
\lst@CCPut#1} |
| 8912 |
\def\lst@CCPut@#1#2{\lst@lAddTo\lst@SelectStdCharTable{\def#1{#2}}} |
| 8913 |
% \end{macrocode} |
| 8914 |
% Now we insert more standard characters. |
| 8915 |
% \begin{macrocode} |
| 8916 |
\lst@CCPut \lst@ProcessOther |
| 8917 |
{"21}{"22}{"28}{"29}{"2B}{"2C}{"2E}{"2F} |
| 8918 |
{"3A}{"3B}{"3D}{"3F}{"5B}{"5D} |
| 8919 |
\z@ |
| 8920 |
\lst@CCPut \lst@ProcessDigit |
| 8921 |
{"30}{"31}{"32}{"33}{"34}{"35}{"36}{"37}{"38}{"39} |
| 8922 |
\z@ |
| 8923 |
\lst@CCPut \lst@ProcessLetter |
| 8924 |
{"40}{"41}{"42}{"43}{"44}{"45}{"46}{"47} |
| 8925 |
{"48}{"49}{"4A}{"4B}{"4C}{"4D}{"4E}{"4F} |
| 8926 |
{"50}{"51}{"52}{"53}{"54}{"55}{"56}{"57} |
| 8927 |
{"58}{"59}{"5A} |
| 8928 |
{"61}{"62}{"63}{"64}{"65}{"66}{"67} |
| 8929 |
{"68}{"69}{"6A}{"6B}{"6C}{"6D}{"6E}{"6F} |
| 8930 |
{"70}{"71}{"72}{"73}{"74}{"75}{"76}{"77} |
| 8931 |
{"78}{"79}{"7A} |
| 8932 |
\z@ |
| 8933 |
% \end{macrocode} |
| 8934 |
% \end{macro} |
| 8935 |
% |
| 8936 |
% \begin{macro}{\lst@CCPutMacro} |
| 8937 |
% Now we come to a delicate point. The characters not inserted yet aren't |
| 8938 |
% printable (|_|, |$|, \ldots) or aren't printed well (|*|, |-|, \ldots) if we |
| 8939 |
% enter these characters. Thus we use proper macros to print the characters. |
| 8940 |
% Works perfectly. The problem is that the current character string is |
| 8941 |
% printable for speed, for example |_| is already replaced by a macro version, |
| 8942 |
% but the new keyword tests need the original characters. |
| 8943 |
% |
| 8944 |
% The solution: We define |\def _{\lst@ProcessLetter\lst@um_}| where the first |
| 8945 |
% underscore is active and the second belongs to the control sequence. |
| 8946 |
% Moreover we have |\def\lst@um_{\lst@UM _}| where the second underscore has |
| 8947 |
% the usual meaning. Now the keyword tests can access the original character |
| 8948 |
% simply by making |\lst@UM| empty. The default definition gets the following |
| 8949 |
% token and builds the control sequence |\lst@um_@|, which we'll define to |
| 8950 |
% print the character. Easy, isn't it?^^A ;-) |
| 8951 |
% |
| 8952 |
% The following definition does all this for us. The first parameter gives the |
| 8953 |
% character class, the second the character code, and the last the definition |
| 8954 |
% which actually prints the character. We build the names |\lst@um_| and |
| 8955 |
% |\lst@um_@| and give them to a submacro. |
| 8956 |
% \begin{macrocode} |
| 8957 |
\def\lst@CCPutMacro#1#2#3{% |
| 8958 |
\ifnum#2=\z@ \else |
| 8959 |
\begingroup\lccode`\~=#2\relax \lccode`\/=#2\relax |
| 8960 |
\lowercase{\endgroup\expandafter\lst@CCPutMacro@ |
| 8961 |
\csname\@lst @um/\expandafter\endcsname |
| 8962 |
\csname\@lst @um/@\endcsname /~}#1{#3}% |
| 8963 |
\expandafter\lst@CCPutMacro |
| 8964 |
\fi} |
| 8965 |
% \end{macrocode} |
| 8966 |
% The arguments are now |\lst@um_|, |\lst@um_@|, nonactive character, active |
| 8967 |
% character, character class and printing definition. We add |\def _{| |
| 8968 |
% |\lst@ProcessLetter| |\lst@um_}| to |\lst@SelectStdCharTable| (and similarly |
| 8969 |
% other special characters), define |\def\lst@um_{\lst@UM _}| and |\lst@um_@|. |
| 8970 |
% \begin{macrocode} |
| 8971 |
\def\lst@CCPutMacro@#1#2#3#4#5#6{% |
| 8972 |
\lst@lAddTo\lst@SelectStdCharTable{\def#4{#5#1}}% |
| 8973 |
\def#1{\lst@UM#3}% |
| 8974 |
\def#2{#6}} |
| 8975 |
% \end{macrocode} |
| 8976 |
% The default definition of |\lst@UM|: |
| 8977 |
% \begin{macrocode} |
| 8978 |
\def\lst@UM#1{\csname\@lst @um#1@\endcsname} |
| 8979 |
% \end{macrocode} |
| 8980 |
% And all remaining standard characters. \lsthelper{Peter |
| 8981 |
% Cock}{2024/09/18}{Upright double-quotes in LaTeX listings} |
| 8982 |
% pointed to the discussion in |
| 8983 |
% \url{https://tex.stackexchange.com/questions/166790/how-can-i-get-straight-double-quotes-in-listings} |
| 8984 |
% about the lack of support for upright double quotes which are now |
| 8985 |
% implemented by the lines below. |
| 8986 |
% \begin{macrocode} |
| 8987 |
\lst@CCPutMacro |
| 8988 |
\lst@ProcessOther {"22}{\lst@ifupquote \textquotedbl |
| 8989 |
\else \char34\relax \fi} |
| 8990 |
\lst@ProcessOther {"23}\# |
| 8991 |
\lst@ProcessLetter{"24}\textdollar |
| 8992 |
\lst@ProcessOther {"25}\% |
| 8993 |
\lst@ProcessOther {"26}\& |
| 8994 |
\lst@ProcessOther {"27}{\lst@ifupquote \textquotesingle |
| 8995 |
\else \char39\relax \fi} |
| 8996 |
\lst@ProcessOther {"2A}{\lst@ttfamily*\textasteriskcentered} |
| 8997 |
% \end{macrocode} |
| 8998 |
% \lsthelper{Ulrike~Fischer}{2020/02/19}{Inkompabilität von breqn/flexisym |
| 8999 |
% mit listings} pointed out the incompatibility between |
| 9000 |
% \packagename{flexisym} and \packagename{listings}: \packagename{flexisym} |
| 9001 |
% changes the math code while \packagename{listings} changes the |
| 9002 |
% meaning. So the minus character vanishes. Replacing the original |$-$| by |
| 9003 |
% |\textminus| should remedy the problem. |
| 9004 |
% \begin{macrocode} |
| 9005 |
\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{\textminus}} |
| 9006 |
\lst@ProcessOther {"3C}{\lst@ttfamily<\textless} |
| 9007 |
\lst@ProcessOther {"3E}{\lst@ttfamily>\textgreater} |
| 9008 |
\lst@ProcessOther {"5C}{\lst@ttfamily{\char92}\textbackslash} |
| 9009 |
\lst@ProcessOther {"5E}\textasciicircum |
| 9010 |
\lst@ProcessLetter{"5F}{\lst@ttfamily{\char95}\textunderscore} |
| 9011 |
% or \char"5F |
| 9012 |
\lst@ProcessOther {"60}{\lst@ifupquote \textasciigrave |
| 9013 |
\else \char96\relax \fi} |
| 9014 |
\lst@ProcessOther {"7B}{\lst@ttfamily{\char123}\textbraceleft} |
| 9015 |
\lst@ProcessOther {"7C}{\lst@ttfamily|\textbar} |
| 9016 |
\lst@ProcessOther {"7D}{\lst@ttfamily{\char125}\textbraceright} |
| 9017 |
\lst@ProcessOther {"7E}\textasciitilde |
| 9018 |
\lst@ProcessOther {"7F}- |
| 9019 |
\@empty\z@\@empty |
| 9020 |
% \end{macrocode} |
| 9021 |
% \end{macro} |
| 9022 |
% |
| 9023 |
% \begin{macro}{\lst@ttfamily} |
| 9024 |
% What is this ominous macro? It prints either the first or the second |
| 9025 |
% argument. In |\ttfamily| it ensures that |----| is typeset |----| and not |
| 9026 |
% $-$$-$$-$$-$ as in version 0.17. Bug encountered by |
| 9027 |
% \lsthelper{Dr.~Jobst~Hoffmann}{1998/03/30}{|\lst@minus| and |\ttfamily|}. |
| 9028 |
% Furthermore I added |\relax| after receiving an error report from |
| 9029 |
% \lsthelper{Magnus~Lewis-Smith}{1999/08/06}{! Bad character code (920).} |
| 9030 |
% \begin{macrocode} |
| 9031 |
\def\lst@ttfamily#1#2{\ifx\f@family\ttdefault#1\relax\else#2\fi} |
| 9032 |
% \end{macrocode} |
| 9033 |
% |\ttdefault| is defined |\long|, so the |\ifx| doesn't work since |\f@family| |
| 9034 |
% isn't |\long|! We go around this problem by redefining |\ttdefault| locally: |
| 9035 |
% \begin{macrocode} |
| 9036 |
\lst@AddToHook{Init}{\edef\ttdefault{\ttdefault}} |
| 9037 |
% \end{macrocode} |
| 9038 |
% \end{macro} |
| 9039 |
% |
| 9040 |
% \begin{lstkey}{upquote} |
| 9041 |
% is used above to decide which quote to print. We print an error message if |
| 9042 |
% the necessary \packagename{textcomp} commands are not available. This key |
| 9043 |
% has been added after an email from \lsthelper{Frank~Mittelbach}{2003/06/18} |
| 9044 |
% {listings and upquote}. |
| 9045 |
% \begin{macrocode} |
| 9046 |
\lst@Key{upquote}{false}[t]{\lstKV@SetIf{#1}\lst@ifupquote |
| 9047 |
\lst@ifupquote |
| 9048 |
\@ifundefined{textasciigrave}% |
| 9049 |
{\let\KV@lst@upquote\@gobble |
| 9050 |
\lstKV@SetIf f\lst@ifupquote \@gobble\fi |
| 9051 |
\PackageError{Listings}{Option `upquote' requires `textcomp' |
| 9052 |
package.\MessageBreak The option has been disabled}% |
| 9053 |
{Add \string\usepackage{textcomp} to your preamble.}}% |
| 9054 |
{}% |
| 9055 |
\fi} |
| 9056 |
% \end{macrocode} |
| 9057 |
% If an \packagename{upquote} package is loaded, the \keyname{upquote} option |
| 9058 |
% is enabled by default. |
| 9059 |
% \begin{macrocode} |
| 9060 |
\AtBeginDocument{% |
| 9061 |
\@ifpackageloaded{upquote}{\RequirePackage{textcomp}% |
| 9062 |
\lstset{upquote}}{}% |
| 9063 |
\@ifpackageloaded{upquote2}{\lstset{upquote}}{}} |
| 9064 |
% \end{macrocode} |
| 9065 |
% \end{lstkey} |
| 9066 |
% |
| 9067 |
% \begin{macro}{\lst@ifactivechars} |
| 9068 |
% A simple switch. |
| 9069 |
% \begin{macrocode} |
| 9070 |
\def\lst@activecharstrue{\let\lst@ifactivechars\iftrue} |
| 9071 |
\def\lst@activecharsfalse{\let\lst@ifactivechars\iffalse} |
| 9072 |
\lst@activecharstrue |
| 9073 |
% \end{macrocode} |
| 9074 |
% \end{macro} |
| 9075 |
% |
| 9076 |
% \begin{macro}{\lst@SelectCharTable} |
| 9077 |
% We select the standard character table and switch to active catcodes. |
| 9078 |
% \begin{macrocode} |
| 9079 |
\def\lst@SelectCharTable{% |
| 9080 |
\lst@SelectStdCharTable |
| 9081 |
\lst@ifactivechars |
| 9082 |
\catcode9\active \catcode12\active \catcode13\active |
| 9083 |
\@tempcnta=32\relax |
| 9084 |
\@whilenum\@tempcnta<128\do |
| 9085 |
{\catcode\@tempcnta\active\advance\@tempcnta\@ne}% |
| 9086 |
\fi |
| 9087 |
\lst@ifec \lst@DefEC \fi |
| 9088 |
% \end{macrocode} |
| 9089 |
% The following line and the according macros below have been added after a |
| 9090 |
% bug report from \lsthelper{Fr\'ed\'eric~Boulanger}{2001/02/27}{ligatures}. |
| 9091 |
% The assignment to |\do@noligs| was changed to |\do| after a bug report from |
| 9092 |
% \lsthelper{Peter~Ruckdeschel}{2002/04/12}{problems with simultanous use of |
| 9093 |
% seminar.sty and listings.sty}. This bugfix was kindly provided by |
| 9094 |
% \lsthelper{Timothy~Van~Zandt}{2002/04/13}{Re: ...}. |
| 9095 |
% \begin{macrocode} |
| 9096 |
\let\do\lst@do@noligs \verbatim@nolig@list |
| 9097 |
% \end{macrocode} |
| 9098 |
% There are two ways to adjust the standard table: inside the hook or with |
| 9099 |
% |\lst@DeveloperSCT|. We use these macros and initialize the backslash if |
| 9100 |
% necessary. |\lst@DefRange| has been moved outside the hook after a bug report |
| 9101 |
% by \lsthelper{Michael~Bachmann}{2004/07/21}{Keine label-Referenzierung |
| 9102 |
% m\"oglich...}\phantomsection\label{rLst@DefRange-moved}. |
| 9103 |
% ^^A \phantomsection is used to correct the hyperref link |
| 9104 |
% \begin{macrocode} |
| 9105 |
\lsthk@SelectCharTable |
| 9106 |
\lst@DeveloperSCT\lst@DefRange |
| 9107 |
\ifx\lst@Backslash\relax\else |
| 9108 |
\lst@LetSaveDef{"5C}\lsts@backslash\lst@Backslash |
| 9109 |
\fi} |
| 9110 |
% \end{macrocode} |
| 9111 |
% \end{macro} |
| 9112 |
% |
| 9113 |
% \begin{lstkey}{SelectCharTable} |
| 9114 |
% \begin{lstkey}{MoreSelectCharTable} |
| 9115 |
% The keys to adjust |\lst@DeveloperSCT|. |
| 9116 |
% \begin{macrocode} |
| 9117 |
\lst@Key{SelectCharTable}{}{\def\lst@DeveloperSCT{#1}} |
| 9118 |
\lst@Key{MoreSelectCharTable}\relax{\lst@lAddTo\lst@DeveloperSCT{#1}} |
| 9119 |
% \end{macrocode} |
| 9120 |
% \begin{macrocode} |
| 9121 |
\lst@AddToHook{SetLanguage}{\let\lst@DeveloperSCT\@empty} |
| 9122 |
% \end{macrocode} |
| 9123 |
% \end{lstkey} |
| 9124 |
% \end{lstkey} |
| 9125 |
% |
| 9126 |
% \begin{macro}{\lst@do@noligs} |
| 9127 |
% To prevent ligatures, this macro inserts the token |\lst@NoLig| in front of |
| 9128 |
% |\lst@Process|\meta{whatever}\meta{spec.~token}. This is done by |
| 9129 |
% |\verbatim@nolig@list| for certain characters. Note that the submacro is |
| 9130 |
% a special kind of a local |\lst@AddToAtTop|. The submacro definition was |
| 9131 |
% fixed thanks to \lsthelper{Peter~Bartke}{2002/04/10}{bad `noligs' handling}. |
| 9132 |
% \begin{macrocode} |
| 9133 |
\def\lst@do@noligs#1{% |
| 9134 |
\begingroup \lccode`\~=`#1\lowercase{\endgroup |
| 9135 |
\lst@do@noligs@~}} |
| 9136 |
\def\lst@do@noligs@#1{% |
| 9137 |
\expandafter\expandafter\expandafter\def |
| 9138 |
\expandafter\expandafter\expandafter#1% |
| 9139 |
\expandafter\expandafter\expandafter{\expandafter\lst@NoLig#1}} |
| 9140 |
% \end{macrocode} |
| 9141 |
% \end{macro} |
| 9142 |
% |
| 9143 |
% \begin{macro}{\lst@NoLig} |
| 9144 |
% When this extra macro is processed, it adds |\lst@nolig| to the output queue |
| 9145 |
% without increasing its length. For keyword detection this must expand to |
| 9146 |
% nothing if |\lst@UM| is empty. |
| 9147 |
% \begin{macrocode} |
| 9148 |
\def\lst@NoLig{\advance\lst@length\m@ne \lst@Append\lst@nolig} |
| 9149 |
\def\lst@nolig{\lst@UM\@empty}% |
| 9150 |
% \end{macrocode} |
| 9151 |
% But the usual meaning of |\lst@UM| builds the following control sequence, |
| 9152 |
% which prevents ligatures in the manner of \LaTeX's |\do@noligs|. |
| 9153 |
% \begin{macrocode} |
| 9154 |
\@namedef{\@lst @um@}{\leavevmode\kern\z@} |
| 9155 |
% \end{macrocode} |
| 9156 |
% \end{macro} |
| 9157 |
% |
| 9158 |
% \begin{macro}{\lst@SaveOutputDef} |
| 9159 |
% To get the \meta{spec.~token} meaning of character |#1|, we look for |\def| |
| 9160 |
% `active character |#1|' in |\lst@SelectStdCharTable|, get the replacement |
| 9161 |
% text, strip off the character class via |\@gobble|, and assign the meaning. |
| 9162 |
% Note that you get a ``runaway argument'' error if an illegal \meta{character |
| 9163 |
% code}=|#1| is used. |
| 9164 |
% \begin{macrocode} |
| 9165 |
\def\lst@SaveOutputDef#1#2{% |
| 9166 |
\begingroup \lccode`\~=#1\relax \lowercase{\endgroup |
| 9167 |
\def\lst@temp##1\def~##2##3\relax}{% |
| 9168 |
\global\expandafter\let\expandafter#2\@gobble##2\relax}% |
| 9169 |
\expandafter\lst@temp\lst@SelectStdCharTable\relax} |
| 9170 |
% \end{macrocode} |
| 9171 |
% \end{macro} |
| 9172 |
% |
| 9173 |
% \begin{macro}{\lstum@backslash} |
| 9174 |
% A commonly used character. |
| 9175 |
% \begin{macrocode} |
| 9176 |
\lst@SaveOutputDef{"5C}\lstum@backslash |
| 9177 |
% \end{macrocode} |
| 9178 |
% \end{macro} |
| 9179 |
% |
| 9180 |
% |
| 9181 |
% \subsubsection{National characters} |
| 9182 |
% |
| 9183 |
% \begin{lstkey}{extendedchars} |
| 9184 |
% The user key to activate extended characters 128--255. |
| 9185 |
% \begin{macrocode} |
| 9186 |
\lst@Key{extendedchars}{true}[t]{\lstKV@SetIf{#1}\lst@ifec} |
| 9187 |
% \end{macrocode} |
| 9188 |
% \end{lstkey} |
| 9189 |
% |
| 9190 |
% \begin{macro}{\lst@DefEC} |
| 9191 |
% Currently each character in the range 128--255 is treated as a letter. |
| 9192 |
% \begin{macrocode} |
| 9193 |
\def\lst@DefEC{% |
| 9194 |
\lst@CCECUse \lst@ProcessLetter |
| 9195 |
^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f% |
| 9196 |
^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f% |
| 9197 |
^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af% |
| 9198 |
^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf% |
| 9199 |
^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf% |
| 9200 |
^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df% |
| 9201 |
^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef% |
| 9202 |
^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff% |
| 9203 |
^^00} |
| 9204 |
% \end{macrocode} |
| 9205 |
% \end{macro} |
| 9206 |
% |
| 9207 |
% \begin{macro}{\lst@CCECUse} |
| 9208 |
% Reaching end of list (|^^00|) we terminate the loop. |
| 9209 |
% Otherwise we do the same as in |\lst@CCPut| if the character is not active. |
| 9210 |
% But if the character is active, we save the meaning before redefinition. |
| 9211 |
% \begin{macrocode} |
| 9212 |
\def\lst@CCECUse#1#2{% |
| 9213 |
\ifnum`#2=\z@ |
| 9214 |
\expandafter\@gobbletwo |
| 9215 |
\else |
| 9216 |
\ifnum\catcode`#2=\active |
| 9217 |
\lccode`\~=`#2\lccode`\/=`#2\lowercase{\lst@CCECUse@#1~/}% |
| 9218 |
\else |
| 9219 |
\lst@ifactivechars \catcode`#2=\active \fi |
| 9220 |
\lccode`\~=`#2\lccode`\/=`#2\lowercase{\def~{#1/}}% |
| 9221 |
\fi |
| 9222 |
\fi |
| 9223 |
\lst@CCECUse#1} |
| 9224 |
% \end{macrocode} |
| 9225 |
% We save the meaning as mentioned. Here we must also use the `|\lst@UM| |
| 9226 |
% construction' since extended characters could often appear in words = |
| 9227 |
% identifiers. Bug reported by \lsthelper{Denis~Girou}{1999/07/26} |
| 9228 |
% {incompatibility with inputenc}. |
| 9229 |
% \begin{macrocode} |
| 9230 |
\def\lst@CCECUse@#1#2#3{% |
| 9231 |
\expandafter\def\csname\@lst @EC#3\endcsname{\lst@UM#3}% |
| 9232 |
\expandafter\let\csname\@lst @um#3@\endcsname #2% |
| 9233 |
\edef#2{\noexpand#1% |
| 9234 |
\expandafter\noexpand\csname\@lst @EC#3\endcsname}} |
| 9235 |
% \end{macrocode} |
| 9236 |
% \lsthelper{Daniel~Gerigk}{2001/10/25}{extendedchars do not work} and |
| 9237 |
% \lsthelper{Heiko~Oberdiek}{2001/10/26}{extendedchars do not work: um@\#3@ |
| 9238 |
% must be @um\#3@} reported an error and a solution, respectively. |
| 9239 |
% \end{macro} |
| 9240 |
% |
| 9241 |
% |
| 9242 |
% \subsubsection{Catcode problems} |
| 9243 |
% |
| 9244 |
% \begin{macro}{\lst@nfss@catcodes} |
| 9245 |
% \lsthelper{Anders~Edenbrandt}{1997/04/22}{preload of .fd files} found a bug |
| 9246 |
% with \texttt{.fd}-files. Since we change catcodes and these files are read |
| 9247 |
% on demand, we must reset the catcodes before the files are input. We use a |
| 9248 |
% local redefinition of |\nfss@catcodes|. |
| 9249 |
% \begin{macrocode} |
| 9250 |
\lst@AddToHook{Init} |
| 9251 |
{\let\lsts@nfss@catcodes\nfss@catcodes |
| 9252 |
\let\nfss@catcodes\lst@nfss@catcodes} |
| 9253 |
% \end{macrocode} |
| 9254 |
% The |&|-character had turned into |\&| after a bug report by \lsthelper |
| 9255 |
% {David~Aspinall}{2003/07/17}{loading of .fd file inside tabular produces |
| 9256 |
% error}. |
| 9257 |
% \begin{macrocode} |
| 9258 |
\def\lst@nfss@catcodes{% |
| 9259 |
\lst@makeletter |
| 9260 |
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\relax |
| 9261 |
\@makeother (\@makeother )\@makeother ,\@makeother :\@makeother\&% |
| 9262 |
\@makeother 0\@makeother 1\@makeother 2\@makeother 3\@makeother 4% |
| 9263 |
\@makeother 5\@makeother 6\@makeother 7\@makeother 8\@makeother 9% |
| 9264 |
\@makeother =\lsts@nfss@catcodes} |
| 9265 |
% \end{macrocode} |
| 9266 |
% The investigation of a bug reported by \lsthelper{Christian~Gudrian} |
| 9267 |
% {2000/11/16}{problems with mathpple} showed that the equal sign needs |
| 9268 |
% to have `other' catcode, as assigned above. |
| 9269 |
% \lsthelper{Svend~Tollak~Munkejord}{2002/04/17}{package incompatible with |
| 9270 |
% Lucida .fd files} reported problems with Lucida .fd-files, while |
| 9271 |
% \lsthelper{Heiko~Oberdiek}{2002/04/17}{Re: listings fails with Lucida |
| 9272 |
% font} analysed the bug, which above led to the line starting with |
| 9273 |
% |\@makeaother (|. |
| 9274 |
% |
| 9275 |
% The name of |\lst@makeletter| is an imitation of \LaTeX's |\@makeother|. |
| 9276 |
% \begin{macrocode} |
| 9277 |
\def\lst@makeletter#1{% |
| 9278 |
\ifx\relax#1\else\catcode`#111\relax \expandafter\lst@makeletter\fi} |
| 9279 |
% \end{macrocode} |
| 9280 |
% \end{macro} |
| 9281 |
% |
| 9282 |
% \begin{lstkey}{useoutput} |
| 9283 |
% \begin{macro}{\output} |
| 9284 |
% Another problem was first reported by \lsthelper{Marcin~Kasperski} |
| 9285 |
% {1999/04/28}{listings spoil toc}. It is also catcode related and |
| 9286 |
% \lsthelper{Donald~Arseneau}{1999/05/13}{comp.text.tex Re: delayed write and |
| 9287 |
% catcode changes} let me understand it. The point is that \TeX\ seems to use |
| 9288 |
% the \emph{currently} active catcode table when it writes non-|\immediate| |
| 9289 |
% |\write|s to file and not the catcodes involved when \emph{reading} the |
| 9290 |
% characters. |
| 9291 |
% So a section heading |\L a| was written |\La| if a listing was split on two |
| 9292 |
% pages since a non-standard catcode table was in use when writing |\La| to |
| 9293 |
% file, the previously attached catcodes do not matter. One more bug was that |
| 9294 |
% accents in page headings or footers were lost when a listing was split on |
| 9295 |
% two pages. \lsthelper{Denis~Girou}{1999/08/03}{Accents lost in heading if |
| 9296 |
% listing split on two pages} found this latter bug. A similar problem with |
| 9297 |
% the tilde was reported by \lsthelper{Thorsten~Vitt}{2001/06/25}{fancyhdr + |
| 9298 |
% listings crossing pages ==> ~ in header, not space}. |
| 9299 |
% |
| 9300 |
% We can choose between three possibilities. |
| 9301 |
% \lsthelper{Donald~Arseneau}{2006/09/14}{cannot select output routine 1} |
| 9302 |
% noted a bug here in the |\ifcase| argument. |
| 9303 |
% \begin{macrocode} |
| 9304 |
\lst@Key{useoutput}{2}{\edef\lst@useoutput{\ifcase0#1 0\or 1\else 2\fi}} |
| 9305 |
% \end{macrocode} |
| 9306 |
% The first does not modify the existing output routine. |
| 9307 |
% \begin{macrocode} |
| 9308 |
\lst@AddToHook{Init} |
| 9309 |
{\edef\lst@OrgOutput{\the\output}% |
| 9310 |
\ifcase\lst@useoutput\relax |
| 9311 |
\or |
| 9312 |
% \end{macrocode} |
| 9313 |
% The second possibility is as follows: We interrupt the current modes---in |
| 9314 |
% particular |\lst@Pmode| with modified catcode table---, call the original |
| 9315 |
% output routine and reenter the mode. This must be done with a little care. |
| 9316 |
% First we have to close the group which \TeX\ opens at the beginning of the |
| 9317 |
% output routine. A single |\egroup| gives an `unbalanced output routine' |
| 9318 |
% error. But |\expandafter\egroup| works. Again it was |
| 9319 |
% \lsthelper{Donald~Arseneau}{2001/01/10}{comp.text.tex Re: \output puzzle} |
| 9320 |
% who gave the explaination: The |\expandafter| set the token type of |\bgroup| |
| 9321 |
% to |backed_up|, which prevents \TeX's from recovering from an unbalanced |
| 9322 |
% output routine. \lsthelper{Heiko~Oberdiek}{2001/01/05}{comp.text.tex Re: |
| 9323 |
% \output puzzle} reported that |\csname| |egroup||\endcsname| does the trick, |
| 9324 |
% too. |
| 9325 |
% |
| 9326 |
% However, since \TeX\ checks the contents of |\box| 255 when we close the |
| 9327 |
% group (`output routine didn't use all of |\box| 255'), we have to save it |
| 9328 |
% temporaryly. |
| 9329 |
% \begin{macrocode} |
| 9330 |
\output{\global\setbox\lst@gtempboxa\box\@cclv |
| 9331 |
\expandafter\egroup |
| 9332 |
% \end{macrocode} |
| 9333 |
% Now we can interrupt the mode, but we have to save the current character |
| 9334 |
% string and the current style. |
| 9335 |
% \begin{macrocode} |
| 9336 |
\lst@SaveToken |
| 9337 |
\lst@InterruptModes |
| 9338 |
% \end{macrocode} |
| 9339 |
% We restore the contents, use the original output routine, and \ldots |
| 9340 |
% \begin{macrocode} |
| 9341 |
\setbox\@cclv\box\lst@gtempboxa |
| 9342 |
\bgroup\lst@OrgOutput\egroup |
| 9343 |
% \end{macrocode} |
| 9344 |
% \ldots\space open a group matching the |}| which \TeX\ inserts at the end of |
| 9345 |
% the output routine. We reenter modes and restore the character string and |
| 9346 |
% style |\aftergroup|. Moreover we need to reset |\pagegoal|---added after a |
| 9347 |
% bug report by \lsthelper{Jochen~Schneider}{2002/03/09}{de.comp.text.tex: |
| 9348 |
% Problem mit Listings-Paket 1.0-Beta; unmotivated pagebreak with preceding |
| 9349 |
% float}. |
| 9350 |
% \begin{macrocode} |
| 9351 |
\bgroup |
| 9352 |
\aftergroup\pagegoal\aftergroup\vsize |
| 9353 |
\aftergroup\lst@ReenterModes\aftergroup\lst@RestoreToken}% |
| 9354 |
\else |
| 9355 |
% \end{macrocode} |
| 9356 |
% The third option is to restore all catcodes and meanings inside a modified |
| 9357 |
% output routine and to call the original routine afterwards. |
| 9358 |
% \begin{macrocode} |
| 9359 |
\output{\lst@RestoreOrigCatcodes |
| 9360 |
\lst@ifec \lst@RestoreOrigExtendedCatcodes \fi |
| 9361 |
\lst@OrgOutput}% |
| 9362 |
\fi} |
| 9363 |
% \end{macrocode} |
| 9364 |
% Note that this output routine isn't used too often. It is executed only if |
| 9365 |
% it's possible that a listing is split on two pages: if a listing ends at |
| 9366 |
% the bottom or begins at the top of a page, or if a listing is really split. |
| 9367 |
% \end{macro} |
| 9368 |
% \end{lstkey} |
| 9369 |
% |
| 9370 |
% \begin{macro}{\lst@GetChars} |
| 9371 |
% \begin{macro}{\lst@ScanChars} |
| 9372 |
% \begin{lstkey}{rescanchars} |
| 9373 |
% To make the third |\output|-option work, we have to scan the catcodes and |
| 9374 |
% also the meanings of active characters: |
| 9375 |
% \begin{macrocode} |
| 9376 |
\def\lst@GetChars#1#2#3{% |
| 9377 |
\let#1\@empty |
| 9378 |
\@tempcnta#2\relax \@tempcntb#3\relax |
| 9379 |
\loop \ifnum\@tempcnta<\@tempcntb\relax |
| 9380 |
\lst@lExtend#1{\expandafter\catcode\the\@tempcnta=}% |
| 9381 |
\lst@lExtend#1{\the\catcode\@tempcnta\relax}% |
| 9382 |
\ifnum\the\catcode\@tempcnta=\active |
| 9383 |
\begingroup\lccode`\~=\@tempcnta |
| 9384 |
\lowercase{\endgroup |
| 9385 |
\lst@lExtend#1{\expandafter\let\expandafter~\csname |
| 9386 |
lstecs@\the\@tempcnta\endcsname}% |
| 9387 |
\expandafter\let\csname lstecs@\the\@tempcnta\endcsname~}% |
| 9388 |
\fi |
| 9389 |
\advance\@tempcnta\@ne |
| 9390 |
\repeat} |
| 9391 |
% \end{macrocode} |
| 9392 |
% \label{catcode12}As per a bug report by \lsthelper{Benjamin~Lings}{2004/10/15}% |
| 9393 |
% {\usepackage{xy,listings} yields: "Forbidden control sequence...."}, we |
| 9394 |
% deactivate |\outer| definition of |^^L| temporarily (inside and outside |
| 9395 |
% of |\lst@ScanChars|) and restore the catcode at end of package via the |
| 9396 |
% |\lst@RestoreCatcodes| command. |
| 9397 |
% \begin{macrocode} |
| 9398 |
\begingroup \catcode12=\active\let^^L\@empty |
| 9399 |
\gdef\lst@ScanChars{% |
| 9400 |
\let\lsts@ssL^^L% |
| 9401 |
\def^^L{\par}% |
| 9402 |
\lst@GetChars\lst@RestoreOrigCatcodes\@ne {128}% |
| 9403 |
\let^^L\lsts@ssL |
| 9404 |
\lst@GetChars\lst@RestoreOrigExtendedCatcodes{128}{256}} |
| 9405 |
\endgroup |
| 9406 |
% \end{macrocode} |
| 9407 |
% The scan can be issued by hand and at the beginning of a document. |
| 9408 |
% \begin{macrocode} |
| 9409 |
\lst@Key{rescanchars}\relax{\lst@ScanChars} |
| 9410 |
\AtBeginDocument{\lst@ScanChars} |
| 9411 |
% \end{macrocode} |
| 9412 |
% \end{lstkey} |
| 9413 |
% \end{macro} |
| 9414 |
% \end{macro} |
| 9415 |
% |
| 9416 |
% |
| 9417 |
% \subsubsection{Adjusting the table} |
| 9418 |
% |
| 9419 |
% We begin with modifiers for the basic character classes. |
| 9420 |
% |
| 9421 |
% \begin{lstkey}{alsoletter} |
| 9422 |
% \begin{lstkey}{alsodigit} |
| 9423 |
% \begin{lstkey}{alsoother} |
| 9424 |
% The macros |\lst@also|\ldots\space will hold |\def|\meta{char}|{|\ldots|}| |
| 9425 |
% sequences, which adjusts the standard character table. |
| 9426 |
% \begin{macrocode} |
| 9427 |
\lst@Key{alsoletter}\relax{% |
| 9428 |
\lst@DoAlso{#1}\lst@alsoletter\lst@ProcessLetter} |
| 9429 |
\lst@Key{alsodigit}\relax{% |
| 9430 |
\lst@DoAlso{#1}\lst@alsodigit\lst@ProcessDigit} |
| 9431 |
\lst@Key{alsoother}\relax{% |
| 9432 |
\lst@DoAlso{#1}\lst@alsoother\lst@ProcessOther} |
| 9433 |
% \end{macrocode} |
| 9434 |
% This is done at \hookname{SelectCharTable} and every language selection |
| 9435 |
% the macros get empty. |
| 9436 |
% \begin{macrocode} |
| 9437 |
\lst@AddToHook{SelectCharTable} |
| 9438 |
{\lst@alsoother \lst@alsodigit \lst@alsoletter} |
| 9439 |
\lst@AddToHookExe{SetLanguage}% init |
| 9440 |
{\let\lst@alsoletter\@empty |
| 9441 |
\let\lst@alsodigit\@empty |
| 9442 |
\let\lst@alsoother\@empty} |
| 9443 |
% \end{macrocode} |
| 9444 |
% The service macro starts a loop and \ldots |
| 9445 |
% \begin{macrocode} |
| 9446 |
\def\lst@DoAlso#1#2#3{% |
| 9447 |
\lst@DefOther\lst@arg{#1}\let#2\@empty |
| 9448 |
\expandafter\lst@DoAlso@\expandafter#2\expandafter#3\lst@arg\relax} |
| 9449 |
\def\lst@DoAlso@#1#2#3{% |
| 9450 |
\ifx\relax#3\expandafter\@gobblethree \else |
| 9451 |
% \end{macrocode} |
| 9452 |
% \ldots\space while not reaching |\relax| we use the \TeX nique from |
| 9453 |
% |\lst@SaveOutputDef| to replace the class by |#2|. Eventually we append |
| 9454 |
% the new definition to |#1|. |
| 9455 |
% \begin{macrocode} |
| 9456 |
\begingroup \lccode`\~=`#3\relax \lowercase{\endgroup |
| 9457 |
\def\lst@temp##1\def~##2##3\relax{% |
| 9458 |
\edef\lst@arg{\def\noexpand~{\noexpand#2\expandafter |
| 9459 |
\noexpand\@gobble##2}}}}% |
| 9460 |
\expandafter\lst@temp\lst@SelectStdCharTable\relax |
| 9461 |
\lst@lExtend#1{\lst@arg}% |
| 9462 |
\fi |
| 9463 |
\lst@DoAlso@#1#2} |
| 9464 |
% \end{macrocode} |
| 9465 |
% \end{lstkey} |
| 9466 |
% \end{lstkey} |
| 9467 |
% \end{lstkey} |
| 9468 |
% |
| 9469 |
% \begin{macro}{\lst@SaveDef} |
| 9470 |
% \begin{macro}{\lst@DefSaveDef} |
| 9471 |
% \begin{macro}{\lst@LetSaveDef} |
| 9472 |
% These macros can be used in language definitions to make special changes. |
| 9473 |
% They save the definition and define or assign a new one. |
| 9474 |
% \begin{macrocode} |
| 9475 |
\def\lst@SaveDef#1#2{% |
| 9476 |
\begingroup \lccode`\~=#1\relax \lowercase{\endgroup\let#2~}} |
| 9477 |
\def\lst@DefSaveDef#1#2{% |
| 9478 |
\begingroup \lccode`\~=#1\relax \lowercase{\endgroup\let#2~\def~}} |
| 9479 |
\def\lst@LetSaveDef#1#2{% |
| 9480 |
\begingroup \lccode`\~=#1\relax \lowercase{\endgroup\let#2~\let~}} |
| 9481 |
% \end{macrocode} |
| 9482 |
% \end{macro} |
| 9483 |
% \end{macro} |
| 9484 |
% \end{macro} |
| 9485 |
% |
| 9486 |
% Now we get to the more powerful definitions. |
| 9487 |
% |
| 9488 |
% \begin{macro}{\lst@CDef} |
| 9489 |
% Here we unfold the first parameter \meta{1st}\marg{2nd}\marg{rest} and say |
| 9490 |
% that this input string is `replaced' by \meta{save 1st}\marg{2nd}^^A |
| 9491 |
% \marg{rest}---plus \meta{execute}, \meta{pre}, and \meta{post}. This main |
| 9492 |
% work is done by |\lst@CDefIt|. |
| 9493 |
% \begin{macrocode} |
| 9494 |
\def\lst@CDef#1{\lst@CDef@#1} |
| 9495 |
\def\lst@CDef@#1#2#3#4{\lst@CDefIt#1{#2}{#3}{#4#2#3}#4} |
| 9496 |
% \end{macrocode} |
| 9497 |
% \end{macro} |
| 9498 |
% |
| 9499 |
% \begin{macro}{\lst@CDefX} |
| 9500 |
% drops the input string. |
| 9501 |
% \begin{macrocode} |
| 9502 |
\def\lst@CDefX#1{\lst@CDefX@#1} |
| 9503 |
\def\lst@CDefX@#1#2#3{\lst@CDefIt#1{#2}{#3}{}} |
| 9504 |
% \end{macrocode} |
| 9505 |
% \end{macro} |
| 9506 |
% |
| 9507 |
% \begin{macro}{\lst@CDefIt} |
| 9508 |
% is the main working procedure for the previous macros. It redefines the |
| 9509 |
% sequence |#1#2#3| of characters. At least |#1| must be active; the other two |
| 9510 |
% arguments might be empty, not equivalent to empty! |
| 9511 |
% \begin{macrocode} |
| 9512 |
\def\lst@CDefIt#1#2#3#4#5#6#7#8{% |
| 9513 |
\ifx\@empty#2\@empty |
| 9514 |
% \end{macrocode} |
| 9515 |
% For a single character we just execute the arguments in the correct order. |
| 9516 |
% You might want to go back to section \ref{dCharacterTablesManipulated} to |
| 9517 |
% look them up. |
| 9518 |
% \begin{macrocode} |
| 9519 |
\def#1{#6\def\lst@next{#7#4#8}\lst@next}% |
| 9520 |
\else \ifx\@empty#3\@empty |
| 9521 |
% \end{macrocode} |
| 9522 |
% For a two character sequence we test whether \meta{pre} and \meta{post} |
| 9523 |
% must be executed. |
| 9524 |
% \begin{macrocode} |
| 9525 |
\def#1##1{% |
| 9526 |
#6% |
| 9527 |
\ifx##1#2\def\lst@next{#7#4#8}\else |
| 9528 |
\def\lst@next{#5##1}\fi |
| 9529 |
\lst@next}% |
| 9530 |
\else |
| 9531 |
% \end{macrocode} |
| 9532 |
% We do the same for an arbitrary character sequence---except that we have to |
| 9533 |
% use |\lst@IfNextCharsArg| instead of |\ifx|\ldots|\fi|. |
| 9534 |
% \begin{macrocode} |
| 9535 |
\def#1{% |
| 9536 |
#6% |
| 9537 |
\lst@IfNextCharsArg{#2#3}{#7#4#8}% |
| 9538 |
{\expandafter#5\lst@eaten}}% |
| 9539 |
\fi \fi} |
| 9540 |
% \end{macrocode} |
| 9541 |
% \end{macro} |
| 9542 |
% |
| 9543 |
% \begin{macro}{\lst@CArgX} |
| 9544 |
% We make |#1#2| active and call |\lst@CArg|. |
| 9545 |
% \begin{macrocode} |
| 9546 |
\def\lst@CArgX#1#2\relax{% |
| 9547 |
\lst@DefActive\lst@arg{#1#2}% |
| 9548 |
\expandafter\lst@CArg\lst@arg\relax} |
| 9549 |
% \end{macrocode} |
| 9550 |
% \end{macro} |
| 9551 |
% |
| 9552 |
% \begin{macro}{\lst@CArg} |
| 9553 |
% arranges the first two arguments for |\lst@CDef|[|X|]. We get an undefined |
| 9554 |
% macro and use |\@empty\@empty\relax| as delimiter for the submacro. |
| 9555 |
% \begin{macrocode} |
| 9556 |
\def\lst@CArg#1#2\relax{% |
| 9557 |
\lccode`\/=`#1\lowercase{\def\lst@temp{/}}% |
| 9558 |
\lst@GetFreeMacro{lst@c\lst@temp}% |
| 9559 |
\expandafter\lst@CArg@\lst@freemacro#1#2\@empty\@empty\relax} |
| 9560 |
% \end{macrocode} |
| 9561 |
% Save meaning of \meta{1st}=|#2| in \meta{save 1st}=|#1| and call the macro |
| 9562 |
% |#6| with correct arguments. From version 1.0 on, |#2|, |#3| and |#4| |
| 9563 |
% (respectively empty arguments) are tied together with group braces. |
| 9564 |
% This allows us to save two arguments in other definitions, for example in |
| 9565 |
% |\lst@DefDelimB|. |
| 9566 |
% \begin{macrocode} |
| 9567 |
\def\lst@CArg@#1#2#3#4\@empty#5\relax#6{% |
| 9568 |
\let#1#2% |
| 9569 |
\ifx\@empty#3\@empty |
| 9570 |
\def\lst@next{#6{#2{}{}}}% |
| 9571 |
\else |
| 9572 |
\def\lst@next{#6{#2#3{#4}}}% |
| 9573 |
\fi |
| 9574 |
\lst@next #1} |
| 9575 |
% \end{macrocode} |
| 9576 |
% \end{macro} |
| 9577 |
% |
| 9578 |
% \begin{macro}{\lst@CArgEmpty} |
| 9579 |
% `executes' an |\@empty|-delimited argument. We will use it for the delimiters. |
| 9580 |
% \begin{macrocode} |
| 9581 |
\def\lst@CArgEmpty#1\@empty{#1} |
| 9582 |
% \end{macrocode} |
| 9583 |
% \end{macro} |
| 9584 |
% |
| 9585 |
% |
| 9586 |
% \subsection{Delimiters} |
| 9587 |
% |
| 9588 |
% Here we start with general definitions common to all delimiters. |
| 9589 |
% |
| 9590 |
% \begin{lstkey}{excludedelims} |
| 9591 |
% controls which delimiters are not printed in \meta{whatever}style. We just |
| 9592 |
% define |\lst@ifex|\meta{whatever} to be true. Such switches are set false |
| 9593 |
% in the \hookname{ExcludeDelims} hook and are handled by the individual |
| 9594 |
% delimiters. |
| 9595 |
% \begin{macrocode} |
| 9596 |
\lst@Key{excludedelims}\relax |
| 9597 |
{\lsthk@ExcludeDelims \lst@NormedDef\lst@temp{#1}% |
| 9598 |
\expandafter\lst@for\lst@temp\do |
| 9599 |
{\expandafter\let\csname\@lst @ifex##1\endcsname\iftrue}} |
| 9600 |
% \end{macrocode} |
| 9601 |
% \end{lstkey} |
| 9602 |
% |
| 9603 |
% \begin{macro}{\lst@DelimPrint} |
| 9604 |
% And this macro might help in doing so. |#1| is |\lst@ifex|\meta{whatever} |
| 9605 |
% (plus |\else|) or just |\iffalse|, and |#2| will be the delimiter. The |
| 9606 |
% temporary mode change ensures that the characters can't end the current |
| 9607 |
% delimiter or start a new one. |
| 9608 |
% \begin{macrocode} |
| 9609 |
\def\lst@DelimPrint#1#2{% |
| 9610 |
#1% |
| 9611 |
\begingroup |
| 9612 |
\lst@mode\lst@nomode \lst@modetrue |
| 9613 |
#2\lst@XPrintToken |
| 9614 |
\endgroup |
| 9615 |
\lst@ResetToken |
| 9616 |
\fi} |
| 9617 |
% \end{macrocode} |
| 9618 |
% \end{macro} |
| 9619 |
% |
| 9620 |
% \begin{macro}{\lst@DelimOpen} |
| 9621 |
% We print preceding characters and the delimiter, enter the appropriate mode, |
| 9622 |
% print the delimiter again, and execute |#3|. In fact, the arguments |#1| and |
| 9623 |
% |#2| will ensure that the delimiter is printed only once. |
| 9624 |
% \begin{macrocode} |
| 9625 |
\def\lst@DelimOpen#1#2#3#4#5#6\@empty{% |
| 9626 |
\lst@TrackNewLines \lst@XPrintToken |
| 9627 |
\lst@DelimPrint#1{#6}% |
| 9628 |
\lst@EnterMode{#4}{\def\lst@currstyle#5}% |
| 9629 |
\lst@DelimPrint{#1#2}{#6}% |
| 9630 |
#3} |
| 9631 |
% \end{macrocode} |
| 9632 |
% \end{macro} |
| 9633 |
% |
| 9634 |
% \begin{macro}{\lst@DelimClose} |
| 9635 |
% is the same in reverse order. |
| 9636 |
% \begin{macrocode} |
| 9637 |
\def\lst@DelimClose#1#2#3\@empty{% |
| 9638 |
\lst@TrackNewLines \lst@XPrintToken |
| 9639 |
\lst@DelimPrint{#1#2}{#3}% |
| 9640 |
\lst@LeaveMode |
| 9641 |
\lst@DelimPrint{#1}{#3}} |
| 9642 |
% \end{macrocode} |
| 9643 |
% \end{macro} |
| 9644 |
% |
| 9645 |
% \begin{macro}{\lst@BeginDelim} |
| 9646 |
% \begin{macro}{\lst@EndDelim} |
| 9647 |
% These definitions are applications of |\lst@DelimOpen| and |\lst@DelimClose|: |
| 9648 |
% the delimiters have the same style as the delimited text. |
| 9649 |
% \begin{macrocode} |
| 9650 |
\def\lst@BeginDelim{\lst@DelimOpen\iffalse\else{}} |
| 9651 |
\def\lst@EndDelim{\lst@DelimClose\iffalse\else} |
| 9652 |
% \end{macrocode} |
| 9653 |
% \end{macro} |
| 9654 |
% \end{macro} |
| 9655 |
% |
| 9656 |
% \begin{macro}{\lst@BeginIDelim} |
| 9657 |
% \begin{macro}{\lst@EndIDelim} |
| 9658 |
% Another application: no delimiter is printed. |
| 9659 |
% \begin{macrocode} |
| 9660 |
\def\lst@BeginIDelim{\lst@DelimOpen\iffalse{}{}} |
| 9661 |
\def\lst@EndIDelim{\lst@DelimClose\iffalse{}} |
| 9662 |
% \end{macrocode} |
| 9663 |
% \end{macro} |
| 9664 |
% \end{macro} |
| 9665 |
% |
| 9666 |
% \begin{macro}{\lst@DefDelims} |
| 9667 |
% This macro defines all delimiters and is therefore reset every language |
| 9668 |
% selection. |
| 9669 |
% \begin{macrocode} |
| 9670 |
\lst@AddToHook{SelectCharTable}{\lst@DefDelims} |
| 9671 |
\lst@AddToHookExe{SetLanguage}{\let\lst@DefDelims\@empty} |
| 9672 |
% \end{macrocode} |
| 9673 |
% \end{macro} |
| 9674 |
% |
| 9675 |
% \begin{macro}{\lst@Delim} |
| 9676 |
% First we set default values: no |\lst@modetrue|, cumulative style, and no |
| 9677 |
% argument to |\lst@Delim|[|DM|]|@|\meta{type}. |
| 9678 |
% \begin{macrocode} |
| 9679 |
\def\lst@Delim#1{% |
| 9680 |
\lst@false \let\lst@cumulative\@empty \let\lst@arg\@empty |
| 9681 |
% \end{macrocode} |
| 9682 |
% These are the correct settings for the double-star-form, so we immediately |
| 9683 |
% call the submacro in this case. Otherwise we either just suppress cumulative |
| 9684 |
% style, or even indicate the usage of |\lst@modetrue| with |\lst@true|. |
| 9685 |
% \begin{macrocode} |
| 9686 |
\@ifstar{\@ifstar{\lst@Delim@{#1}}% |
| 9687 |
{\let\lst@cumulative\relax |
| 9688 |
\lst@Delim@{#1}}}% |
| 9689 |
{\lst@true\lst@Delim@{#1}}} |
| 9690 |
% \end{macrocode} |
| 9691 |
% The type argument is saved for later use. We check against the optional |
| 9692 |
% \meta{style} argument using |#1| as default, define |\lst@delimstyle| and |
| 9693 |
% look for the optional \meta{type option}, which is just saved in |\lst@arg|. |
| 9694 |
% \begin{macrocode} |
| 9695 |
\def\lst@Delim@#1[#2]{% |
| 9696 |
\gdef\lst@delimtype{#2}% |
| 9697 |
\@ifnextchar[\lst@Delim@sty |
| 9698 |
{\lst@Delim@sty[#1]}} |
| 9699 |
\def\lst@Delim@sty[#1]{% |
| 9700 |
\def\lst@delimstyle{#1}% |
| 9701 |
\ifx\@empty#1\@empty\else |
| 9702 |
\lst@Delim@sty@ #1\@nil |
| 9703 |
\fi |
| 9704 |
\@ifnextchar[\lst@Delim@option |
| 9705 |
\lst@Delim@delim} |
| 9706 |
\def\lst@Delim@option[#1]{\def\lst@arg{[#1]}\lst@Delim@delim} |
| 9707 |
% \end{macrocode} |
| 9708 |
% |[| and |]| in the replacement text above have been added after a bug report |
| 9709 |
% by \lsthelper{Stephen~Reindl}{2002/05/28}{\inaccessible using Cobol}. |
| 9710 |
% |
| 9711 |
% The definition of |\lst@delimstyle| depends on whether the first token is a |
| 9712 |
% control sequence. Here we possibly build |\lst@|\meta{style}. |
| 9713 |
% \begin{macrocode} |
| 9714 |
\def\lst@Delim@sty@#1#2\@nil{% |
| 9715 |
\if\relax\noexpand#1\else |
| 9716 |
\edef\lst@delimstyle{\expandafter\noexpand |
| 9717 |
\csname\@lst @\lst@delimstyle\endcsname}% |
| 9718 |
\fi} |
| 9719 |
% \end{macrocode} |
| 9720 |
% \end{macro} |
| 9721 |
% |
| 9722 |
% \begin{macro}{\lst@Delim@delim} |
| 9723 |
% Eventually this macro is called. First we might need to delete a bunch of |
| 9724 |
% delimiters. If there is no delimiter, we might delete a subclass. |
| 9725 |
% \begin{macrocode} |
| 9726 |
\def\lst@Delim@delim#1\relax#2#3#4#5#6#7#8{% |
| 9727 |
\ifx #4\@empty \lst@Delim@delall{#2}\fi |
| 9728 |
\ifx\@empty#1\@empty |
| 9729 |
\ifx #4\@nil |
| 9730 |
\@ifundefined{\@lst @#2DM@\lst@delimtype}% |
| 9731 |
{\lst@Delim@delall{#2@\lst@delimtype}}% |
| 9732 |
{\lst@Delim@delall{#2DM@\lst@delimtype}}% |
| 9733 |
\fi |
| 9734 |
\else |
| 9735 |
% \end{macrocode} |
| 9736 |
% If the delimiter is not empty, we convert the delimiter and append it to |
| 9737 |
% |\lst@arg|. Ditto |\lst@Begin|\ldots, |\lst@End|\ldots, and the style and |
| 9738 |
% mode selection. |
| 9739 |
% \begin{macrocode} |
| 9740 |
\expandafter\lst@Delim@args\expandafter |
| 9741 |
{\lst@delimtype}{#1}{#5}#6{#7}{#8}#4% |
| 9742 |
% \end{macrocode} |
| 9743 |
% If the type is known, we either choose dynamic or static mode and use the |
| 9744 |
% contents of |\lst@arg| as arguments. All this is put into |\lst@delim|. |
| 9745 |
% \begin{macrocode} |
| 9746 |
\let\lst@delim\@empty |
| 9747 |
\expandafter\lst@IfOneOf\lst@delimtype\relax#3% |
| 9748 |
{\@ifundefined{\@lst @#2DM@\lst@delimtype}% |
| 9749 |
{\lst@lExtend\lst@delim{\csname\@lst @#2@\lst@delimtype |
| 9750 |
\expandafter\endcsname\lst@arg}}% |
| 9751 |
{\lst@lExtend\lst@delim{\expandafter\lst@UseDynamicMode |
| 9752 |
\csname\@lst @#2DM@\lst@delimtype |
| 9753 |
\expandafter\endcsname\lst@arg}}% |
| 9754 |
% \end{macrocode} |
| 9755 |
% Now, depending on the mode |#4| we either remove this particular delimiter or |
| 9756 |
% append it to all current ones. |
| 9757 |
% \begin{macrocode} |
| 9758 |
\ifx #4\@nil |
| 9759 |
\let\lst@temp\lst@DefDelims \let\lst@DefDelims\@empty |
| 9760 |
\expandafter\lst@Delim@del\lst@temp\@empty\@nil\@nil\@nil |
| 9761 |
\else |
| 9762 |
\lst@lExtend\lst@DefDelims\lst@delim |
| 9763 |
\fi}% |
| 9764 |
% \end{macrocode} |
| 9765 |
% An unknown type issues an error. |
| 9766 |
% \begin{macrocode} |
| 9767 |
{\PackageError{Listings}{Illegal type `\lst@delimtype'}% |
| 9768 |
{#2 types are #3.}}% |
| 9769 |
\fi} |
| 9770 |
% \end{macrocode} |
| 9771 |
% \end{macro} |
| 9772 |
% |
| 9773 |
% \begin{macro}{\lst@Delim@args} |
| 9774 |
% Now let's look how we add the arguments to |\lst@arg|. First we initialize |
| 9775 |
% the conversion just to make all characters active. But if the first character |
| 9776 |
% of the type equals |#4|, \ldots |
| 9777 |
% \begin{macrocode} |
| 9778 |
\def\lst@Delim@args#1#2#3#4#5#6#7{% |
| 9779 |
\begingroup |
| 9780 |
\lst@false \let\lst@next\lst@XConvert |
| 9781 |
% \end{macrocode} |
| 9782 |
% \ldots\ we remove that character from |\lst@delimtype|, and |#5| might select |
| 9783 |
% a different conversion setting or macro. |
| 9784 |
% \begin{macrocode} |
| 9785 |
\@ifnextchar #4{\xdef\lst@delimtype{\expandafter\@gobble |
| 9786 |
\lst@delimtype}% |
| 9787 |
#5\lst@next#2\@nil |
| 9788 |
\lst@lAddTo\lst@arg{\@empty#6}% |
| 9789 |
\lst@GobbleNil}% |
| 9790 |
% \end{macrocode} |
| 9791 |
% Since we are in the `special' case above, we've also added the special |
| 9792 |
% |\lst@Begin|\ldots\space and |\lst@End|\ldots\space macros to |\lst@arg| |
| 9793 |
% (and |\@empty| as a brake for the delimiter). No special task must be done |
| 9794 |
% if the characters are not equal. |
| 9795 |
% \begin{macrocode} |
| 9796 |
{\lst@next#2\@nil |
| 9797 |
\lst@lAddTo\lst@arg{\@empty#3}% |
| 9798 |
\lst@GobbleNil}% |
| 9799 |
#1\@nil |
| 9800 |
% \end{macrocode} |
| 9801 |
% We always transfer the arguments to the outside of the group and append the |
| 9802 |
% style and mode selection if and only if we're not deleting a delimiter. |
| 9803 |
% Therefor we expand the delimiter style. |
| 9804 |
% \begin{macrocode} |
| 9805 |
\global\let\@gtempa\lst@arg |
| 9806 |
\endgroup |
| 9807 |
\let\lst@arg\@gtempa |
| 9808 |
\ifx #7\@nil\else |
| 9809 |
\expandafter\lst@Delim@args@\expandafter{\lst@delimstyle}% |
| 9810 |
\fi} |
| 9811 |
% \end{macrocode} |
| 9812 |
% Recall that the style is `selected' by |\def\lst@currstyle#5|, and this |
| 9813 |
% `argument' |#5| is to be added now. Depending on the settings at the very |
| 9814 |
% beginning, we use either |{\meta{style}}\lst@modetrue|---which selects the |
| 9815 |
% style and deactivates keyword detection---, or |{}\meta{style}|---which |
| 9816 |
% defines an empty style macro and executes the style for cumulative styles---, |
| 9817 |
% or |{\meta{style}|---which just defines the style macro. Note that we have to |
| 9818 |
% use two extra group levels below: one is discarded directly by |\lst@lAddTo| |
| 9819 |
% and the other by |\lst@Delim|[|DM|]|@|\meta{type}. |
| 9820 |
% \begin{macrocode} |
| 9821 |
\def\lst@Delim@args@#1{% |
| 9822 |
\lst@if |
| 9823 |
\lst@lAddTo\lst@arg{{{#1}\lst@modetrue}}% |
| 9824 |
\else |
| 9825 |
\ifx\lst@cumulative\@empty |
| 9826 |
\lst@lAddTo\lst@arg{{{}#1}}% |
| 9827 |
\else |
| 9828 |
\lst@lAddTo\lst@arg{{{#1}}}% |
| 9829 |
\fi |
| 9830 |
\fi} |
| 9831 |
% \end{macrocode} |
| 9832 |
% \end{macro} |
| 9833 |
% |
| 9834 |
% \begin{macro}{\lst@Delim@del} |
| 9835 |
% To delete a particular delimiter, we iterate down the list of delimiters and |
| 9836 |
% compare the current item with the user supplied. |
| 9837 |
% \begin{macrocode} |
| 9838 |
\def\lst@Delim@del#1\@empty#2#3#4{% |
| 9839 |
\ifx #2\@nil\else |
| 9840 |
\def\lst@temp{#1\@empty#2#3}% |
| 9841 |
\ifx\lst@temp\lst@delim\else |
| 9842 |
\lst@lAddTo\lst@DefDelims{#1\@empty#2#3{#4}}% |
| 9843 |
\fi |
| 9844 |
\expandafter\lst@Delim@del |
| 9845 |
\fi} |
| 9846 |
% \end{macrocode} |
| 9847 |
% \end{macro} |
| 9848 |
% |
| 9849 |
% \begin{macro}{\lst@Delim@delall} |
| 9850 |
% To delete a whole class of delimiters, we first expand the control sequence |
| 9851 |
% name, init some other data, and call a submacro to do the work. |
| 9852 |
% \begin{macrocode} |
| 9853 |
\def\lst@Delim@delall#1{% |
| 9854 |
\begingroup |
| 9855 |
\edef\lst@delim{\expandafter\string\csname\@lst @#1\endcsname}% |
| 9856 |
\lst@false \global\let\@gtempa\@empty |
| 9857 |
\expandafter\lst@Delim@delall@\lst@DefDelims\@empty |
| 9858 |
\endgroup |
| 9859 |
\let\lst@DefDelims\@gtempa} |
| 9860 |
% \end{macrocode} |
| 9861 |
% We first discard a preceding |\lst@UseDynamicMode|. |
| 9862 |
% \begin{macrocode} |
| 9863 |
\def\lst@Delim@delall@#1{% |
| 9864 |
\ifx #1\@empty\else |
| 9865 |
\ifx #1\lst@UseDynamicMode |
| 9866 |
\lst@true |
| 9867 |
\let\lst@next\lst@Delim@delall@do |
| 9868 |
\else |
| 9869 |
\def\lst@next{\lst@Delim@delall@do#1}% |
| 9870 |
\fi |
| 9871 |
\expandafter\lst@next |
| 9872 |
\fi} |
| 9873 |
% \end{macrocode} |
| 9874 |
% Then we can check whether (the following) |\lst@|\meta{delimiter name}\ldots\ |
| 9875 |
% matches the delimiter class given by |\lst@delim|. |
| 9876 |
% \begin{macrocode} |
| 9877 |
\def\lst@Delim@delall@do#1#2\@empty#3#4#5{% |
| 9878 |
\expandafter\lst@IfSubstring\expandafter{\lst@delim}{\string#1}% |
| 9879 |
{}% |
| 9880 |
{\lst@if \lst@AddTo\@gtempa\lst@UseDynamicMode \fi |
| 9881 |
\lst@AddTo\@gtempa{#1#2\@empty#3#4{#5}}}% |
| 9882 |
\lst@false \lst@Delim@delall@} |
| 9883 |
% \end{macrocode} |
| 9884 |
% \end{macro} |
| 9885 |
% |
| 9886 |
% \begin{macro}{\lst@DefDelimB} |
| 9887 |
% Here we put the arguments together to fit |\lst@CDef|. Note that the very |
| 9888 |
% last argument |\@empty| to |\lst@CDef| is a brake for |\lst@CArgEmpty| |
| 9889 |
% and |\lst@DelimOpen|. |
| 9890 |
% \begin{macrocode} |
| 9891 |
\gdef\lst@DefDelimB#1#2#3#4#5#6#7#8{% |
| 9892 |
\lst@CDef{#1}#2% |
| 9893 |
{#3}% |
| 9894 |
{\let\lst@bnext\lst@CArgEmpty |
| 9895 |
\lst@ifmode #4\else |
| 9896 |
#5% |
| 9897 |
\def\lst@bnext{#6{#7}{#8}}% |
| 9898 |
\fi |
| 9899 |
\lst@bnext}% |
| 9900 |
\@empty} |
| 9901 |
% \end{macrocode} |
| 9902 |
% After a bug report from \lsthelper{Vespe~Savikko}{2000/11/06}{bad output of |
| 9903 |
% doc-strings if HTML and Python are loaded} I added braces around |#7|. |
| 9904 |
% \end{macro} |
| 9905 |
% |
| 9906 |
% \begin{macro}{\lst@DefDelimE} |
| 9907 |
% The |\ifnum #7=\lst@mode| in the 5th line ensures that the delimiters |
| 9908 |
% match each other. |
| 9909 |
% \begin{macrocode} |
| 9910 |
\gdef\lst@DefDelimE#1#2#3#4#5#6#7{% |
| 9911 |
\lst@CDef{#1}#2% |
| 9912 |
{#3}% |
| 9913 |
{\let\lst@enext\lst@CArgEmpty |
| 9914 |
\ifnum #7=\lst@mode% |
| 9915 |
#4% |
| 9916 |
\let\lst@enext#6% |
| 9917 |
\else |
| 9918 |
#5% |
| 9919 |
\fi |
| 9920 |
\lst@enext}% |
| 9921 |
\@empty} |
| 9922 |
% \end{macrocode} |
| 9923 |
% \begin{macrocode} |
| 9924 |
\lst@AddToHook{Init}{\let\lst@bnext\relax \let\lst@enext\relax} |
| 9925 |
% \end{macrocode} |
| 9926 |
% \end{macro} |
| 9927 |
% |
| 9928 |
% \begin{macro}{\lst@DefDelimBE} |
| 9929 |
% This service macro will actually define all string delimiters. |
| 9930 |
% \begin{macrocode} |
| 9931 |
\gdef\lst@DefDelimBE#1#2#3#4#5#6#7#8#9{% |
| 9932 |
\lst@CDef{#1}#2% |
| 9933 |
{#3}% |
| 9934 |
{\let\lst@bnext\lst@CArgEmpty |
| 9935 |
\ifnum #7=\lst@mode |
| 9936 |
#4% |
| 9937 |
\let\lst@bnext#9% |
| 9938 |
\else |
| 9939 |
\lst@ifmode\else |
| 9940 |
#5% |
| 9941 |
\def\lst@bnext{#6{#7}{#8}}% |
| 9942 |
\fi |
| 9943 |
\fi |
| 9944 |
\lst@bnext}% |
| 9945 |
\@empty} |
| 9946 |
% \end{macrocode} |
| 9947 |
% \end{macro} |
| 9948 |
% |
| 9949 |
% \begin{macro}{\lst@delimtypes} |
| 9950 |
% is the list of general delimiter types. |
| 9951 |
% \begin{macrocode} |
| 9952 |
\gdef\lst@delimtypes{s,l} |
| 9953 |
% \end{macrocode} |
| 9954 |
% \end{macro} |
| 9955 |
% |
| 9956 |
% \begin{macro}{\lst@DelimKey} |
| 9957 |
% We just put together the arguments for |\lst@Delim|. |
| 9958 |
% \begin{macrocode} |
| 9959 |
\gdef\lst@DelimKey#1#2{% |
| 9960 |
\lst@Delim{}#2\relax |
| 9961 |
{Delim}\lst@delimtypes #1% |
| 9962 |
{\lst@BeginDelim\lst@EndDelim} |
| 9963 |
i\@empty{\lst@BeginIDelim\lst@EndIDelim}} |
| 9964 |
% \end{macrocode} |
| 9965 |
% \end{macro} |
| 9966 |
% |
| 9967 |
% \begin{lstkey}{delim} |
| 9968 |
% \begin{lstkey}{moredelim} |
| 9969 |
% \begin{lstkey}{deletedelim} |
| 9970 |
% all use |\lst@DelimKey|. |
| 9971 |
% \begin{macrocode} |
| 9972 |
\lst@Key{delim}\relax{\lst@DelimKey\@empty{#1}} |
| 9973 |
\lst@Key{moredelim}\relax{\lst@DelimKey\relax{#1}} |
| 9974 |
\lst@Key{deletedelim}\relax{\lst@DelimKey\@nil{#1}} |
| 9975 |
% \end{macrocode} |
| 9976 |
% \end{lstkey} |
| 9977 |
% \end{lstkey} |
| 9978 |
% \end{lstkey} |
| 9979 |
% |
| 9980 |
% \begin{macro}{\lst@DelimDM@l} |
| 9981 |
% \begin{macro}{\lst@DelimDM@s} |
| 9982 |
% Nohting special here. |
| 9983 |
% \begin{macrocode} |
| 9984 |
\gdef\lst@DelimDM@l#1#2\@empty#3#4#5{% |
| 9985 |
\lst@CArg #2\relax\lst@DefDelimB{}{}{}#3{#1}{#5\lst@Lmodetrue}} |
| 9986 |
% \end{macrocode} |
| 9987 |
% \begin{macrocode} |
| 9988 |
\gdef\lst@DelimDM@s#1#2#3\@empty#4#5#6{% |
| 9989 |
\lst@CArg #2\relax\lst@DefDelimB{}{}{}#4{#1}{#6}% |
| 9990 |
\lst@CArg #3\relax\lst@DefDelimE{}{}{}#5{#1}} |
| 9991 |
% \end{macrocode} |
| 9992 |
% \begin{macrocode} |
| 9993 |
%</kernel> |
| 9994 |
% \end{macrocode} |
| 9995 |
% \end{macro} |
| 9996 |
% \end{macro} |
| 9997 |
% |
| 9998 |
% |
| 9999 |
% \subsubsection{Strings} |
| 10000 |
% |
| 10001 |
% \begin{aspect}{strings} |
| 10002 |
% Just starting a new aspect. |
| 10003 |
% \begin{macrocode} |
| 10004 |
%<*misc> |
| 10005 |
\lst@BeginAspect{strings} |
| 10006 |
% \end{macrocode} |
| 10007 |
% |
| 10008 |
% \begin{macro}{\lst@stringtypes} |
| 10009 |
% is the list of \ldots\space string types? The several valid string |
| 10010 |
% types are defined on page~\pageref{uStrings}. |
| 10011 |
% \begin{macrocode} |
| 10012 |
\gdef\lst@stringtypes{d,b,m,bd,db,s} |
| 10013 |
% \end{macrocode} |
| 10014 |
% \end{macro} |
| 10015 |
% |
| 10016 |
% \begin{macro}{\lst@StringKey} |
| 10017 |
% We just put together the arguments for |\lst@Delim|. |
| 10018 |
% \begin{macrocode} |
| 10019 |
\gdef\lst@StringKey#1#2{% |
| 10020 |
\lst@Delim\lst@stringstyle #2\relax |
| 10021 |
{String}\lst@stringtypes #1% |
| 10022 |
{\lst@BeginString\lst@EndString}% |
| 10023 |
\@@end\@empty{}} |
| 10024 |
% \end{macrocode} |
| 10025 |
% \end{macro} |
| 10026 |
% |
| 10027 |
% \begin{lstkey}{string} |
| 10028 |
% \begin{lstkey}{morestring} |
| 10029 |
% \begin{lstkey}{deletestring} |
| 10030 |
% all use |\lst@StringKey|. |
| 10031 |
% \begin{macrocode} |
| 10032 |
\lst@Key{string}\relax{\lst@StringKey\@empty{#1}} |
| 10033 |
\lst@Key{morestring}\relax{\lst@StringKey\relax{#1}} |
| 10034 |
\lst@Key{deletestring}\relax{\lst@StringKey\@nil{#1}} |
| 10035 |
% \end{macrocode} |
| 10036 |
% \end{lstkey} |
| 10037 |
% \end{lstkey} |
| 10038 |
% \end{lstkey} |
| 10039 |
% |
| 10040 |
% \begin{lstkey}{stringstyle} |
| 10041 |
% You shouldn't need comments on the following two lines, do you? |
| 10042 |
% \begin{macrocode} |
| 10043 |
\lst@Key{stringstyle}{}{\def\lst@stringstyle{#1}} |
| 10044 |
\lst@AddToHook{EmptyStyle}{\let\lst@stringstyle\@empty} |
| 10045 |
% \end{macrocode} |
| 10046 |
% \end{lstkey} |
| 10047 |
% |
| 10048 |
% \begin{lstkey}{showstringspaces} |
| 10049 |
% Thanks to \lsthelper{Knut~M\"uller}{1997/04/28}{\blankstringtrue} for |
| 10050 |
% reporting problems with |\blankstringtrue| (now |showstringspaces=false|). |
| 10051 |
% The problem has gone. |
| 10052 |
% \begin{macrocode} |
| 10053 |
\lst@Key{showstringspaces}t[t]{\lstKV@SetIf{#1}\lst@ifshowstringspaces} |
| 10054 |
% \end{macrocode} |
| 10055 |
% \end{lstkey} |
| 10056 |
% |
| 10057 |
% \begin{macro}{\lst@BeginString} |
| 10058 |
% Note that the tokens after |\lst@DelimOpen| are arguments! The only special |
| 10059 |
% here is that we switch to `keepspaces' after starting a string, if necessary. |
| 10060 |
% A bug reported by \lsthelper{Vespe~Savikko}{2000/09/27}{stringstyle used also |
| 10061 |
% on previous other characters} has gone due to the use of |\lst@DelimOpen|. |
| 10062 |
% \begin{macrocode} |
| 10063 |
\gdef\lst@BeginString{% |
| 10064 |
\lst@DelimOpen |
| 10065 |
\lst@ifexstrings\else |
| 10066 |
{\lst@ifshowstringspaces |
| 10067 |
\lst@keepspacestrue |
| 10068 |
\let\lst@outputspace\lst@visiblespace |
| 10069 |
\fi}} |
| 10070 |
% \end{macrocode} |
| 10071 |
% \begin{macrocode} |
| 10072 |
\lst@AddToHookExe{ExcludeDelims}{\let\lst@ifexstrings\iffalse} |
| 10073 |
% \end{macrocode} |
| 10074 |
% \end{macro} |
| 10075 |
% |
| 10076 |
% \begin{macro}{\lst@EndString} |
| 10077 |
% Again the two tokens following |\lst@DelimClose| are arguments. |
| 10078 |
% \begin{macrocode} |
| 10079 |
\gdef\lst@EndString{\lst@DelimClose\lst@ifexstrings\else} |
| 10080 |
% \end{macrocode} |
| 10081 |
% \end{macro} |
| 10082 |
% |
| 10083 |
% And now all the |\lst@StringDM@|\meta{type} definitions. |
| 10084 |
% |
| 10085 |
% \begin{macro}{\lst@StringDM@d} |
| 10086 |
% `d' means no extra work.; the first three arguments after |\lst@DefDelimBE| |
| 10087 |
% are left empty. The others are used to start and end the string. |
| 10088 |
% \begin{macrocode} |
| 10089 |
\gdef\lst@StringDM@d#1#2\@empty#3#4#5{% |
| 10090 |
\lst@CArg #2\relax\lst@DefDelimBE{}{}{}#3{#1}{#5}#4} |
| 10091 |
% \end{macrocode} |
| 10092 |
% \end{macro} |
| 10093 |
% |
| 10094 |
% \begin{macro}{\lst@StringDM@b} |
| 10095 |
% The |\lst@ifletter|\ldots|\fi| has been inserted after bug reports by |
| 10096 |
% \lsthelper{Daniel~Gerigk}{2001/10/25}{improper strings in C++} and |
| 10097 |
% \lsthelper{Peter~Bartke}{2001/11/01}{improper strings in C++}. If the last |
| 10098 |
% other character is a backslash (4th line), we gobble the `end string' token |
| 10099 |
% sequence. |
| 10100 |
% \begin{macrocode} |
| 10101 |
\gdef\lst@StringDM@b#1#2\@empty#3#4#5{% |
| 10102 |
\let\lst@ifbstring\iftrue |
| 10103 |
\lst@CArg #2\relax\lst@DefDelimBE |
| 10104 |
{\lst@ifletter \lst@Output \lst@letterfalse \fi}% |
| 10105 |
{\ifx\lst@lastother\lstum@backslash |
| 10106 |
\expandafter\@gobblethree |
| 10107 |
\fi}{}#3{#1}{#5}#4} |
| 10108 |
% \end{macrocode} |
| 10109 |
% \begin{macrocode} |
| 10110 |
\global\let\lst@ifbstring\iffalse % init |
| 10111 |
% \end{macrocode} |
| 10112 |
% \lsthelper{Heiko~Heil}{2002/02/08}{string '\\' does not finish after the |
| 10113 |
% delimiter} reported problems with double backslashes. So: |
| 10114 |
% \begin{macrocode} |
| 10115 |
\lst@AddToHook{SelectCharTable}{% |
| 10116 |
\lst@ifbstring |
| 10117 |
\lst@CArgX \\\\\relax \lst@CDefX{}% |
| 10118 |
{\lst@ProcessOther\lstum@backslash |
| 10119 |
\lst@ProcessOther\lstum@backslash |
| 10120 |
\let\lst@lastother\relax}% |
| 10121 |
{}% |
| 10122 |
\fi} |
| 10123 |
% \end{macrocode} |
| 10124 |
% The reset of |\lst@lastother| has been added after a bug reports by |
| 10125 |
% \lsthelper{Hermann~H\"uttler}{2002/10/05}{C++-string "... \\" does not |
| 10126 |
% end with second double quote} and \lsthelper{Dan~Luecking}{2003/01/15} |
| 10127 |
% {string "\\" doesn't end after the second quote}. |
| 10128 |
% \end{macro} |
| 10129 |
% |
| 10130 |
% \begin{macro}{\lst@StringDM@bd} |
| 10131 |
% \begin{macro}{\lst@StringDM@db} |
| 10132 |
% are just the same and the same as |\lst@StringDM@b|. |
| 10133 |
% \begin{macrocode} |
| 10134 |
\global\let\lst@StringDM@bd\lst@StringDM@b |
| 10135 |
\global\let\lst@StringDM@db\lst@StringDM@bd |
| 10136 |
% \end{macrocode} |
| 10137 |
% \end{macro}\end{macro} |
| 10138 |
% |
| 10139 |
% \begin{macro}{\lst@StringDM@m} |
| 10140 |
% is for Matlab. We enter string mode only if the last character is not in |
| 10141 |
% the following list of exceptional characters: letters, digits, period, |
| 10142 |
% quote, right parenthesis, right bracket, and right brace. The first list |
| 10143 |
% has been extended after bug reports from \lsthelper{Christian~Kindinger} |
| 10144 |
% {2002/03/??}{]' starts a string in Matlab}, \lsthelper{Benjamin~Schubert} |
| 10145 |
% {2003/02/05}{.' starts a string in Matlab}, and \lsthelper{Stefan~Stoll} |
| 10146 |
% {2003/02/18}{any of 0123456789\}' plus quote start a string in Matlab}. |
| 10147 |
% \begin{macrocode} |
| 10148 |
\gdef\lst@StringDM@m#1#2\@empty#3#4#5{% |
| 10149 |
\lst@CArg #2\relax\lst@DefDelimBE{}{}% |
| 10150 |
{\let\lst@next\@gobblethree |
| 10151 |
\lst@ifletter\else |
| 10152 |
\lst@IfLastOtherOneOf{)].0123456789\lstum@rbrace'}% |
| 10153 |
{}% |
| 10154 |
{\let\lst@next\@empty}% |
| 10155 |
\fi |
| 10156 |
\lst@next}#3{#1}{#5}#4} |
| 10157 |
% \end{macrocode} |
| 10158 |
% \end{macro} |
| 10159 |
% |
| 10160 |
% \begin{macro}{\lst@StringDM@s} |
| 10161 |
% is for string-delimited strings, just as for comments. This is needed |
| 10162 |
% for Ruby, and possibly other languages. |
| 10163 |
% \begin{macrocode} |
| 10164 |
\gdef\lst@StringDM@s#1#2#3\@empty#4#5#6{% |
| 10165 |
\lst@CArg #2\relax\lst@DefDelimB{}{}{}#4{#1}{#6}% |
| 10166 |
\lst@CArg #3\relax\lst@DefDelimE{}{}{}#5{#1}} |
| 10167 |
% \end{macrocode} |
| 10168 |
% \end{macro} |
| 10169 |
% |
| 10170 |
% \begin{macro}{\lstum@rbrace} |
| 10171 |
% This has been used above. |
| 10172 |
% \begin{macrocode} |
| 10173 |
\lst@SaveOutputDef{"7D}\lstum@rbrace |
| 10174 |
% \end{macrocode} |
| 10175 |
% \end{macro} |
| 10176 |
% |
| 10177 |
% \begin{macrocode} |
| 10178 |
\lst@EndAspect |
| 10179 |
%</misc> |
| 10180 |
% \end{macrocode} |
| 10181 |
% \end{aspect} |
| 10182 |
% |
| 10183 |
% |
| 10184 |
% \begin{aspect}{mf} |
| 10185 |
% For MetaFont and MetaPost we now define macros to print the input-filenames |
| 10186 |
% in stringstyle. |
| 10187 |
% \begin{macrocode} |
| 10188 |
%<*misc> |
| 10189 |
\lst@BeginAspect{mf} |
| 10190 |
% \end{macrocode} |
| 10191 |
% |
| 10192 |
% \begin{macro}{\lst@mfinputmode} |
| 10193 |
% \begin{macro}{\lst@String@mf} |
| 10194 |
% \begin{macrocode} |
| 10195 |
\lst@AddTo\lst@stringtypes{,mf} |
| 10196 |
\lst@NewMode\lst@mfinputmode |
| 10197 |
% \end{macrocode} |
| 10198 |
% \begin{macrocode} |
| 10199 |
\gdef\lst@String@mf#1\@empty#2#3#4{% |
| 10200 |
\lst@CArg #1\relax\lst@DefDelimB |
| 10201 |
{}{}{\lst@ifletter \expandafter\@gobblethree \fi}% |
| 10202 |
\lst@BeginStringMFinput\lst@mfinputmode{#4\lst@Lmodetrue}% |
| 10203 |
\@ifundefined{lsts@semicolon}% |
| 10204 |
{\lst@DefSaveDef{`\;}\lsts@semicolon{% ; and space end the filename |
| 10205 |
\ifnum\lst@mode=\lst@mfinputmode |
| 10206 |
\lst@XPrintToken |
| 10207 |
\expandafter\lst@LeaveMode |
| 10208 |
\fi |
| 10209 |
\lsts@semicolon}% |
| 10210 |
\lst@DefSaveDef{`\ }\lsts@space{% |
| 10211 |
\ifnum\lst@mode=\lst@mfinputmode |
| 10212 |
\lst@XPrintToken |
| 10213 |
\expandafter\lst@LeaveMode |
| 10214 |
\fi |
| 10215 |
\lsts@space}% |
| 10216 |
}{}} |
| 10217 |
% \end{macrocode} |
| 10218 |
% \end{macro} |
| 10219 |
% \end{macro} |
| 10220 |
% |
| 10221 |
% \begin{macro}{\lst@BeginStringMFinput} |
| 10222 |
% It remains to define this macro. In contrast to |\lst@PrintDelim|, we don't |
| 10223 |
% use |\lst@modetrue| to allow keyword detection here. |
| 10224 |
% \begin{macrocode} |
| 10225 |
\gdef\lst@BeginStringMFinput#1#2#3\@empty{% |
| 10226 |
\lst@TrackNewLines \lst@XPrintToken |
| 10227 |
\begingroup |
| 10228 |
\lst@mode\lst@nomode |
| 10229 |
#3\lst@XPrintToken |
| 10230 |
\endgroup |
| 10231 |
\lst@ResetToken |
| 10232 |
\lst@EnterMode{#1}{\def\lst@currstyle#2}% |
| 10233 |
\lst@ifshowstringspaces |
| 10234 |
\lst@keepspacestrue |
| 10235 |
\let\lst@outputspace\lst@visiblespace |
| 10236 |
\fi} |
| 10237 |
% \end{macrocode} |
| 10238 |
% \end{macro} |
| 10239 |
% |
| 10240 |
% \begin{macrocode} |
| 10241 |
\lst@EndAspect |
| 10242 |
%</misc> |
| 10243 |
% \end{macrocode} |
| 10244 |
% \end{aspect} |
| 10245 |
% |
| 10246 |
% |
| 10247 |
% \subsubsection{Comments} |
| 10248 |
% |
| 10249 |
% \begin{aspect}{comments} |
| 10250 |
% That's what we are working on. |
| 10251 |
% \begin{macrocode} |
| 10252 |
%<*misc> |
| 10253 |
\lst@BeginAspect{comments} |
| 10254 |
% \end{macrocode} |
| 10255 |
% |
| 10256 |
% \begin{macro}{\lst@commentmode} |
| 10257 |
% is a general purpose mode for comments. |
| 10258 |
% \begin{macrocode} |
| 10259 |
\lst@NewMode\lst@commentmode |
| 10260 |
% \end{macrocode} |
| 10261 |
% \end{macro} |
| 10262 |
% |
| 10263 |
% \begin{macro}{\lst@commenttypes} |
| 10264 |
% Via \keyname{comment} available comment types: \textbf line, \textbf fixed |
| 10265 |
% column, \textbf single, and \textbf nested and all with |
| 10266 |
% preceding \textbf i for invisible comments. |
| 10267 |
% \begin{macrocode} |
| 10268 |
\gdef\lst@commenttypes{l,f,s,n} |
| 10269 |
% \end{macrocode} |
| 10270 |
% \end{macro} |
| 10271 |
% |
| 10272 |
% \begin{macro}{\lst@CommentKey} |
| 10273 |
% We just put together the arguments for |\lst@Delim|. |
| 10274 |
% \begin{macrocode} |
| 10275 |
\gdef\lst@CommentKey#1#2{% |
| 10276 |
\lst@Delim\lst@commentstyle #2\relax |
| 10277 |
{Comment}\lst@commenttypes #1% |
| 10278 |
{\lst@BeginComment\lst@EndComment}% |
| 10279 |
i\@empty{\lst@BeginInvisible\lst@EndInvisible}} |
| 10280 |
% \end{macrocode} |
| 10281 |
% \end{macro} |
| 10282 |
% |
| 10283 |
% \begin{lstkey}{comment} |
| 10284 |
% \begin{lstkey}{morecomment} |
| 10285 |
% \begin{lstkey}{deletecomment} |
| 10286 |
% The keys are easy since defined in terms of |\lst@CommentKey|. |
| 10287 |
% \begin{macrocode} |
| 10288 |
\lst@Key{comment}\relax{\lst@CommentKey\@empty{#1}} |
| 10289 |
\lst@Key{morecomment}\relax{\lst@CommentKey\relax{#1}} |
| 10290 |
\lst@Key{deletecomment}\relax{\lst@CommentKey\@nil{#1}} |
| 10291 |
% \end{macrocode} |
| 10292 |
% \end{lstkey} |
| 10293 |
% \end{lstkey} |
| 10294 |
% \end{lstkey} |
| 10295 |
% |
| 10296 |
% \begin{lstkey}{commentstyle} |
| 10297 |
% Any hints necessary? |
| 10298 |
% \begin{macrocode} |
| 10299 |
\lst@Key{commentstyle}{}{\def\lst@commentstyle{#1}} |
| 10300 |
\lst@AddToHook{EmptyStyle}{\let\lst@commentstyle\itshape} |
| 10301 |
% \end{macrocode} |
| 10302 |
% \end{lstkey} |
| 10303 |
% |
| 10304 |
% \begin{macro}{\lst@BeginComment} |
| 10305 |
% \begin{macro}{\lst@EndComment} |
| 10306 |
% Once more the three tokens following |\lst@DelimOpen| are arguments. |
| 10307 |
% \begin{macrocode} |
| 10308 |
\gdef\lst@BeginComment{% |
| 10309 |
\lst@DelimOpen |
| 10310 |
\lst@ifexcomments\else |
| 10311 |
\lsthk@AfterBeginComment} |
| 10312 |
% \end{macrocode} |
| 10313 |
% Ditto. |
| 10314 |
% \begin{macrocode} |
| 10315 |
\gdef\lst@EndComment{\lst@DelimClose\lst@ifexcomments\else} |
| 10316 |
% \end{macrocode} |
| 10317 |
% \begin{macrocode} |
| 10318 |
\lst@AddToHook{AfterBeginComment}{} |
| 10319 |
\lst@AddToHookExe{ExcludeDelims}{\let\lst@ifexcomments\iffalse} |
| 10320 |
% \end{macrocode} |
| 10321 |
% \end{macro} |
| 10322 |
% \end{macro} |
| 10323 |
% |
| 10324 |
% \begin{macro}{\lst@BeginInvisible} |
| 10325 |
% \begin{macro}{\lst@EndInvisible} |
| 10326 |
% Print preceding characters and begin dropping the output. |
| 10327 |
% \begin{macrocode} |
| 10328 |
\gdef\lst@BeginInvisible#1#2#3\@empty{% |
| 10329 |
\lst@TrackNewLines \lst@XPrintToken |
| 10330 |
\lst@BeginDropOutput{#1}} |
| 10331 |
% \end{macrocode} |
| 10332 |
% Don't print the delimiter and end dropping the output. |
| 10333 |
% \begin{macrocode} |
| 10334 |
\gdef\lst@EndInvisible#1\@empty{\lst@EndDropOutput} |
| 10335 |
% \end{macrocode} |
| 10336 |
% \end{macro} |
| 10337 |
% \end{macro} |
| 10338 |
% |
| 10339 |
% Now we provide all |\lst@Comment|[|DM|]|@|\meta{type} macros. |
| 10340 |
% |
| 10341 |
% \begin{macro}{\lst@CommentDM@l} |
| 10342 |
% is easy---thanks to |\lst@CArg| and |\lst@DefDelimB|. Note that the |
| 10343 |
% `end comment' argument |#4| is not used here. |
| 10344 |
% \begin{macrocode} |
| 10345 |
\gdef\lst@CommentDM@l#1#2\@empty#3#4#5{% |
| 10346 |
\lst@CArg #2\relax\lst@DefDelimB{}{}{}#3{#1}{#5\lst@Lmodetrue}} |
| 10347 |
% \end{macrocode} |
| 10348 |
% \end{macro} |
| 10349 |
% |
| 10350 |
% \begin{macro}{\lst@CommentDM@f} |
| 10351 |
% is slightly more work. First we provide the number of preceding columns. |
| 10352 |
% \begin{macrocode} |
| 10353 |
\gdef\lst@CommentDM@f#1{% |
| 10354 |
\@ifnextchar[{\lst@Comment@@f{#1}}% |
| 10355 |
{\lst@Comment@@f{#1}[0]}} |
| 10356 |
% \end{macrocode} |
| 10357 |
% We define the comment in the same way as above, but we enter comment mode |
| 10358 |
% if and only if the character is in column |#2| (counting from zero). |
| 10359 |
% \begin{macrocode} |
| 10360 |
\gdef\lst@Comment@@f#1[#2]#3\@empty#4#5#6{% |
| 10361 |
\lst@CArg #3\relax\lst@DefDelimB{}{}% |
| 10362 |
{\lst@CalcColumn |
| 10363 |
\ifnum #2=\@tempcnta\else |
| 10364 |
\expandafter\@gobblethree |
| 10365 |
\fi}% |
| 10366 |
#4{#1}{#6\lst@Lmodetrue}} |
| 10367 |
% \end{macrocode} |
| 10368 |
% \end{macro} |
| 10369 |
% |
| 10370 |
% \begin{macro}{\lst@CommentDM@s} |
| 10371 |
% Nothing special here. |
| 10372 |
% \begin{macrocode} |
| 10373 |
\gdef\lst@CommentDM@s#1#2#3\@empty#4#5#6{% |
| 10374 |
\lst@CArg #2\relax\lst@DefDelimB{}{}{}#4{#1}{#6}% |
| 10375 |
\lst@CArg #3\relax\lst@DefDelimE{}{}{}#5{#1}} |
| 10376 |
% \end{macrocode} |
| 10377 |
% \end{macro} |
| 10378 |
% |
| 10379 |
% \begin{macro}{\lst@CommentDM@n} |
| 10380 |
% We either give an error message or define the nested comment. |
| 10381 |
% \begin{macrocode} |
| 10382 |
\gdef\lst@CommentDM@n#1#2#3\@empty#4#5#6{% |
| 10383 |
\ifx\@empty#3\@empty\else |
| 10384 |
\def\@tempa{#2}\def\@tempb{#3}% |
| 10385 |
\ifx\@tempa\@tempb |
| 10386 |
\PackageError{Listings}{Identical delimiters}% |
| 10387 |
{These delimiters make no sense with nested comments.}% |
| 10388 |
\else |
| 10389 |
\lst@CArg #2\relax\lst@DefDelimB |
| 10390 |
{}% |
| 10391 |
% \end{macrocode} |
| 10392 |
% Note that the following |\@gobble| eats an |\else| from |\lst@DefDelimB|. |
| 10393 |
% \begin{macrocode} |
| 10394 |
{\ifnum\lst@mode=#1\relax \expandafter\@gobble \fi}% |
| 10395 |
{}#4{#1}{#6}% |
| 10396 |
\lst@CArg #3\relax\lst@DefDelimE{}{}{}#5{#1}% |
| 10397 |
\fi |
| 10398 |
\fi} |
| 10399 |
% \end{macrocode} |
| 10400 |
% \end{macro} |
| 10401 |
% |
| 10402 |
% \begin{macrocode} |
| 10403 |
\lst@EndAspect |
| 10404 |
%</misc> |
| 10405 |
% \end{macrocode} |
| 10406 |
% \end{aspect} |
| 10407 |
% |
| 10408 |
% |
| 10409 |
% \subsubsection{PODs} |
| 10410 |
% |
| 10411 |
% \begin{aspect}{pod} |
| 10412 |
% PODs are defined as a separate aspect. |
| 10413 |
% \begin{macrocode} |
| 10414 |
%<*misc> |
| 10415 |
\lst@BeginAspect{pod} |
| 10416 |
% \end{macrocode} |
| 10417 |
% |
| 10418 |
% \begin{lstkey}{printpod} |
| 10419 |
% \begin{lstkey}{podcomment} |
| 10420 |
% We begin with the user keys, which I introduced after communication with |
| 10421 |
% \lsthelper{Michael~Piotrowski}{1997/11/11}{printpod}. |
| 10422 |
% \begin{macrocode} |
| 10423 |
\lst@Key{printpod}{false}[t]{\lstKV@SetIf{#1}\lst@ifprintpod} |
| 10424 |
\lst@Key{podcomment}{false}[t]{\lstKV@SetIf{#1}\lst@ifpodcomment} |
| 10425 |
\lst@AddToHookExe{SetLanguage}{\let\lst@ifpodcomment\iffalse} |
| 10426 |
% \end{macrocode} |
| 10427 |
% \end{lstkey} |
| 10428 |
% \end{lstkey} |
| 10429 |
% |
| 10430 |
% \begin{macro}{\lst@PODmode} |
| 10431 |
% is the static mode for PODs. |
| 10432 |
% \begin{macrocode} |
| 10433 |
\lst@NewMode\lst@PODmode |
| 10434 |
% \end{macrocode} |
| 10435 |
% \end{macro} |
| 10436 |
% |
| 10437 |
% We adjust some characters if the user has selected |podcomment=true|. |
| 10438 |
% \begin{macrocode} |
| 10439 |
\lst@AddToHook{SelectCharTable} |
| 10440 |
{\lst@ifpodcomment |
| 10441 |
\lst@CArgX =\relax\lst@DefDelimB{}{}% |
| 10442 |
% \end{macrocode} |
| 10443 |
% The following code is executed if we've found an equality sign and haven't |
| 10444 |
% entered a mode (in fact if mode changes are allowed): We `begin drop output' |
| 10445 |
% and gobble the usual begin of comment sequence (via |\@gobblethree|) if PODs |
| 10446 |
% aren't be printed. Moreover we gobble it if the current column number is not |
| 10447 |
% zero---|\@tempcnta| is valued below. |
| 10448 |
% \begin{macrocode} |
| 10449 |
{\ifnum\@tempcnta=\z@ |
| 10450 |
\lst@ifprintpod\else |
| 10451 |
\def\lst@bnext{\lst@BeginDropOutput\lst@PODmode}% |
| 10452 |
\expandafter\expandafter\expandafter\@gobblethree |
| 10453 |
\fi |
| 10454 |
\else |
| 10455 |
\expandafter\@gobblethree |
| 10456 |
\fi}% |
| 10457 |
\lst@BeginComment\lst@PODmode{{\lst@commentstyle}}% |
| 10458 |
% \end{macrocode} |
| 10459 |
% If we come to |=|, we calculate the current column number (zero based). |
| 10460 |
% \begin{macrocode} |
| 10461 |
\lst@CArgX =cut\^^M\relax\lst@DefDelimE |
| 10462 |
{\lst@CalcColumn}% |
| 10463 |
% \end{macrocode} |
| 10464 |
% If there is additionally |cut|+EOL and if we are in |\lst@PODmode| but not in |
| 10465 |
% column one, we must gobble the `end comment sequence'. |
| 10466 |
% \begin{macrocode} |
| 10467 |
{\ifnum\@tempcnta=\z@\else |
| 10468 |
\expandafter\@gobblethree |
| 10469 |
\fi}% |
| 10470 |
{}% |
| 10471 |
\lst@EndComment\lst@PODmode |
| 10472 |
\fi} |
| 10473 |
% \end{macrocode} |
| 10474 |
% |
| 10475 |
% \begin{macrocode} |
| 10476 |
\lst@EndAspect |
| 10477 |
%</misc> |
| 10478 |
% \end{macrocode} |
| 10479 |
% \end{aspect} |
| 10480 |
% |
| 10481 |
% |
| 10482 |
% \subsubsection{Tags} |
| 10483 |
% |
| 10484 |
% \begin{aspect}{html} |
| 10485 |
% Support for HTML and other `markup languages'. |
| 10486 |
% \begin{macrocode} |
| 10487 |
%<*misc> |
| 10488 |
\lst@BeginAspect[keywords]{html} |
| 10489 |
% \end{macrocode} |
| 10490 |
% |
| 10491 |
% \begin{macro}{\lst@tagtypes} |
| 10492 |
% Again we begin with the list of tag types. It's rather short. |
| 10493 |
% \begin{macrocode} |
| 10494 |
\gdef\lst@tagtypes{s} |
| 10495 |
% \end{macrocode} |
| 10496 |
% \end{macro} |
| 10497 |
% |
| 10498 |
% \begin{macro}{\lst@TagKey} |
| 10499 |
% Again we just put together the arguments for |\lst@Delim| and \ldots |
| 10500 |
% \begin{macrocode} |
| 10501 |
\gdef\lst@TagKey#1#2{% |
| 10502 |
\lst@Delim\lst@tagstyle #2\relax |
| 10503 |
{Tag}\lst@tagtypes #1% |
| 10504 |
{\lst@BeginTag\lst@EndTag}% |
| 10505 |
\@@end\@empty{}} |
| 10506 |
% \end{macrocode} |
| 10507 |
% \end{macro} |
| 10508 |
% |
| 10509 |
% \begin{lstkey}{tag} |
| 10510 |
% \ldots\ we use the definition here. |
| 10511 |
% \begin{macrocode} |
| 10512 |
\lst@Key{tag}\relax{\lst@TagKey\@empty{#1}} |
| 10513 |
% \end{macrocode} |
| 10514 |
% \end{lstkey} |
| 10515 |
% |
| 10516 |
% \begin{lstkey}{tagstyle} |
| 10517 |
% You shouldn't need comments on the following two lines, do you? |
| 10518 |
% \begin{macrocode} |
| 10519 |
\lst@Key{tagstyle}{}{\def\lst@tagstyle{#1}} |
| 10520 |
\lst@AddToHook{EmptyStyle}{\let\lst@tagstyle\@empty} |
| 10521 |
% \end{macrocode} |
| 10522 |
% \end{lstkey} |
| 10523 |
% |
| 10524 |
% \begin{macro}{\lst@BeginTag} |
| 10525 |
% The special things here are: (1) We activate keyword detection inside tags |
| 10526 |
% and (2) we initialize the switch |\lst@iffirstintag| if necessary. |
| 10527 |
% \begin{macrocode} |
| 10528 |
\gdef\lst@BeginTag{% |
| 10529 |
\lst@DelimOpen |
| 10530 |
\lst@ifextags\else |
| 10531 |
{\let\lst@ifkeywords\iftrue |
| 10532 |
\lst@ifmarkfirstintag \lst@firstintagtrue \fi}} |
| 10533 |
% \end{macrocode} |
| 10534 |
% \begin{macrocode} |
| 10535 |
\lst@AddToHookExe{ExcludeDelims}{\let\lst@ifextags\iffalse} |
| 10536 |
% \end{macrocode} |
| 10537 |
% \end{macro} |
| 10538 |
% |
| 10539 |
% \begin{macro}{\lst@EndTag} |
| 10540 |
% is just like the other |\lst@End|\meta{whatever} definitions. |
| 10541 |
% \begin{macrocode} |
| 10542 |
\gdef\lst@EndTag{\lst@DelimClose\lst@ifextags\else} |
| 10543 |
% \end{macrocode} |
| 10544 |
% \end{macro} |
| 10545 |
% |
| 10546 |
% \begin{lstkey}{usekeywordsintag} |
| 10547 |
% \begin{lstkey}{markfirstintag} |
| 10548 |
% The second key has already been `used'. |
| 10549 |
% \begin{macrocode} |
| 10550 |
\lst@Key{usekeywordsintag}t[t]{\lstKV@SetIf{#1}\lst@ifusekeysintag} |
| 10551 |
\lst@Key{markfirstintag}f[t]{\lstKV@SetIf{#1}\lst@ifmarkfirstintag} |
| 10552 |
% \end{macrocode} |
| 10553 |
% For this, we install a (global) switch, \ldots |
| 10554 |
% \begin{macrocode} |
| 10555 |
\gdef\lst@firstintagtrue{\global\let\lst@iffirstintag\iftrue} |
| 10556 |
\global\let\lst@iffirstintag\iffalse |
| 10557 |
% \end{macrocode} |
| 10558 |
% \ldots\ which is reset by the output of an identifier but not by other |
| 10559 |
% output. |
| 10560 |
% \begin{macrocode} |
| 10561 |
\lst@AddToHook{PostOutput}{\lst@tagresetfirst} |
| 10562 |
\lst@AddToHook{Output} |
| 10563 |
{\gdef\lst@tagresetfirst{\global\let\lst@iffirstintag\iffalse}} |
| 10564 |
\lst@AddToHook{OutputOther}{\gdef\lst@tagresetfirst{}} |
| 10565 |
% \end{macrocode} |
| 10566 |
% Now we only need to test against this switch in the \hookname{Output} hook. |
| 10567 |
% \begin{macrocode} |
| 10568 |
\lst@AddToHook{Output} |
| 10569 |
{\ifnum\lst@mode=\lst@tagmode |
| 10570 |
\lst@iffirstintag \let\lst@thestyle\lst@gkeywords@sty \fi |
| 10571 |
% \end{macrocode} |
| 10572 |
% Moreover we check here, whether the keyword style is always to be used. |
| 10573 |
% \begin{macrocode} |
| 10574 |
\lst@ifusekeysintag\else \let\lst@thestyle\lst@gkeywords@sty\fi |
| 10575 |
\fi} |
| 10576 |
% \end{macrocode} |
| 10577 |
% \end{lstkey} |
| 10578 |
% \end{lstkey} |
| 10579 |
% |
| 10580 |
% \begin{macro}{\lst@tagmode} |
| 10581 |
% We allocate the mode and \ldots |
| 10582 |
% \begin{macrocode} |
| 10583 |
\lst@NewMode\lst@tagmode |
| 10584 |
% \end{macrocode} |
| 10585 |
% deactivate keyword detection if any tag delimiter is defined (see below). |
| 10586 |
% \begin{macrocode} |
| 10587 |
\lst@AddToHook{Init}{\global\let\lst@ifnotag\iftrue} |
| 10588 |
\lst@AddToHook{SelectCharTable}{\let\lst@ifkeywords\lst@ifnotag} |
| 10589 |
% \end{macrocode} |
| 10590 |
% \end{macro} |
| 10591 |
% |
| 10592 |
% \begin{macro}{\lst@Tag@s} |
| 10593 |
% The definition of the one and only delimiter type is not that interesting. |
| 10594 |
% Compared with the others we set |\lst@ifnotag| and enter tag mode only if |
| 10595 |
% we aren't in tag mode. |
| 10596 |
% \begin{macrocode} |
| 10597 |
\gdef\lst@Tag@s#1#2\@empty#3#4#5{% |
| 10598 |
\global\let\lst@ifnotag\iffalse |
| 10599 |
\lst@CArg #1\relax\lst@DefDelimB {}{}% |
| 10600 |
{\ifnum\lst@mode=\lst@tagmode \expandafter\@gobblethree \fi}% |
| 10601 |
#3\lst@tagmode{#5}% |
| 10602 |
\lst@CArg #2\relax\lst@DefDelimE {}{}{}#4\lst@tagmode}% |
| 10603 |
% \end{macrocode} |
| 10604 |
% \end{macro} |
| 10605 |
% |
| 10606 |
% \begin{macro}{\lst@BeginCDATA} |
| 10607 |
% This macro is used by the XML language definition. |
| 10608 |
% \begin{macrocode} |
| 10609 |
\gdef\lst@BeginCDATA#1\@empty{% |
| 10610 |
\lst@TrackNewLines \lst@PrintToken |
| 10611 |
\lst@EnterMode\lst@GPmode{}\let\lst@ifmode\iffalse |
| 10612 |
\lst@mode\lst@tagmode #1\lst@mode\lst@GPmode\relax\lst@modetrue} |
| 10613 |
% \end{macrocode} |
| 10614 |
% \end{macro} |
| 10615 |
% |
| 10616 |
% \begin{macrocode} |
| 10617 |
\lst@EndAspect |
| 10618 |
%</misc> |
| 10619 |
% \end{macrocode} |
| 10620 |
% \end{aspect} |
| 10621 |
% |
| 10622 |
% |
| 10623 |
% \subsection{Replacing input} |
| 10624 |
% |
| 10625 |
% \begingroup |
| 10626 |
% \begin{macrocode} |
| 10627 |
%<*kernel> |
| 10628 |
% \end{macrocode} |
| 10629 |
% \endgroup |
| 10630 |
% |
| 10631 |
% \begin{macro}{\lst@ReplaceInput} |
| 10632 |
% is defined in terms of |\lst@CArgX| and |\lst@CDefX|. |
| 10633 |
% \begin{macrocode} |
| 10634 |
\def\lst@ReplaceInput#1{\lst@CArgX #1\relax\lst@CDefX{}{}} |
| 10635 |
% \end{macrocode} |
| 10636 |
% \end{macro} |
| 10637 |
% |
| 10638 |
% \begin{lstkey}{literate} |
| 10639 |
% \lsthelper{Jason~Alexander}{1999/03/10}{literate programming} asked for |
| 10640 |
% something like that. The key looks for a star and saves the argument. |
| 10641 |
% \begin{macrocode} |
| 10642 |
\def\lst@Literatekey#1\@nil@{\let\lst@ifxliterate\lst@if |
| 10643 |
\def\lst@literate{#1}} |
| 10644 |
\lst@Key{literate}{}{\@ifstar{\lst@true \lst@Literatekey} |
| 10645 |
{\lst@false\lst@Literatekey}#1\@nil@} |
| 10646 |
\lst@AddToHook{SelectCharTable} |
| 10647 |
{\ifx\lst@literate\@empty\else |
| 10648 |
\expandafter\lst@Literate\lst@literate{}\relax\z@ |
| 10649 |
\fi} |
| 10650 |
% \end{macrocode} |
| 10651 |
% Internally we don't make use of the `replace input' feature any more. |
| 10652 |
%^^A We print the preceding text, assign token and length, and output it. |
| 10653 |
% \begin{macrocode} |
| 10654 |
\def\lst@Literate#1#2#3{% |
| 10655 |
\ifx\relax#2\@empty\else |
| 10656 |
\lst@CArgX #1\relax\lst@CDef |
| 10657 |
{} |
| 10658 |
{\let\lst@next\@empty |
| 10659 |
\lst@ifxliterate |
| 10660 |
\lst@ifmode \let\lst@next\lst@CArgEmpty \fi |
| 10661 |
\fi |
| 10662 |
\ifx\lst@next\@empty |
| 10663 |
\ifx\lst@OutputBox\@gobble\else |
| 10664 |
\lst@XPrintToken \let\lst@scanmode\lst@scan@m |
| 10665 |
\lst@token{#2}\lst@length#3\relax |
| 10666 |
\lst@XPrintToken |
| 10667 |
\fi |
| 10668 |
\let\lst@next\lst@CArgEmptyGobble |
| 10669 |
\fi |
| 10670 |
\lst@next}% |
| 10671 |
\@empty |
| 10672 |
\expandafter\lst@Literate |
| 10673 |
\fi} |
| 10674 |
\def\lst@CArgEmptyGobble#1\@empty{} |
| 10675 |
% \end{macrocode} |
| 10676 |
% Note that we check |\lst@OutputBox| for being |\@gobble|. This is due to |
| 10677 |
% a bug report by \lsthelper{Jared~Warren}{2003/07/10}{literate replacement |
| 10678 |
% produces "ghosts"}. |
| 10679 |
% \end{lstkey} |
| 10680 |
% |
| 10681 |
% \begin{macro}{\lst@BeginDropInput} |
| 10682 |
% We deactivate all `process' macros. |\lst@modetrue| does this for all |
| 10683 |
% up-coming string delimiters, comments, and so on. |
| 10684 |
% \begin{macrocode} |
| 10685 |
\def\lst@BeginDropInput#1{% |
| 10686 |
\lst@EnterMode{#1}% |
| 10687 |
{\lst@modetrue |
| 10688 |
\let\lst@OutputBox\@gobble |
| 10689 |
\let\lst@ifdropinput\iftrue |
| 10690 |
\let\lst@ProcessLetter\@gobble |
| 10691 |
\let\lst@ProcessDigit\@gobble |
| 10692 |
\let\lst@ProcessOther\@gobble |
| 10693 |
\let\lst@ProcessSpace\@empty |
| 10694 |
\let\lst@ProcessTabulator\@empty |
| 10695 |
\let\lst@ProcessFormFeed\@empty}} |
| 10696 |
\let\lst@ifdropinput\iffalse % init |
| 10697 |
% \end{macrocode} |
| 10698 |
% \end{macro} |
| 10699 |
% |
| 10700 |
% \begingroup |
| 10701 |
% \begin{macrocode} |
| 10702 |
%</kernel> |
| 10703 |
% \end{macrocode} |
| 10704 |
% \endgroup |
| 10705 |
% |
| 10706 |
% |
| 10707 |
% \subsection{Escaping to \LaTeX} |
| 10708 |
% |
| 10709 |
% \begin{aspect}{escape} |
| 10710 |
% We now define the \ldots\ damned \ldots\ the aspect has escaped! |
| 10711 |
% \begin{macrocode} |
| 10712 |
%<*misc> |
| 10713 |
\lst@BeginAspect{escape} |
| 10714 |
% \end{macrocode} |
| 10715 |
% |
| 10716 |
% \begin{lstkey}{texcl} |
| 10717 |
% Communication with \lsthelper{J\"orn~Wilms}{1997/07/07}{\TeX\ comments} is |
| 10718 |
% responsible for this key. The definition and the first hooks are easy. |
| 10719 |
% \begin{macrocode} |
| 10720 |
\lst@Key{texcl}{false}[t]{\lstKV@SetIf{#1}\lst@iftexcl} |
| 10721 |
\lst@AddToHook{TextStyle}{\let\lst@iftexcl\iffalse} |
| 10722 |
\lst@AddToHook{EOL} |
| 10723 |
{\ifnum\lst@mode=\lst@TeXLmode |
| 10724 |
\expandafter\lst@escapeend |
| 10725 |
\expandafter\lst@LeaveAllModes |
| 10726 |
\expandafter\lst@ReenterModes |
| 10727 |
\fi} |
| 10728 |
% \end{macrocode} |
| 10729 |
% If the user wants \TeX\ comment lines, we print the comment separator and |
| 10730 |
% interrupt the normal processing. |
| 10731 |
% \begin{macrocode} |
| 10732 |
\lst@AddToHook{AfterBeginComment} |
| 10733 |
{\lst@iftexcl \lst@ifLmode \lst@ifdropinput\else |
| 10734 |
\lst@PrintToken |
| 10735 |
\lst@LeaveMode \lst@InterruptModes |
| 10736 |
\lst@EnterMode{\lst@TeXLmode}{\lst@modetrue\lst@commentstyle}% |
| 10737 |
\expandafter\expandafter\expandafter\lst@escapebegin |
| 10738 |
\fi \fi \fi} |
| 10739 |
% \end{macrocode} |
| 10740 |
% \begin{macrocode} |
| 10741 |
\lst@NewMode\lst@TeXLmode |
| 10742 |
% \end{macrocode} |
| 10743 |
% \end{lstkey} |
| 10744 |
% |
| 10745 |
% \begin{macro}{\lst@ActiveCDefX} |
| 10746 |
% Same as |\lst@CDefX| but we both make |#1| active and assign a new catcode. |
| 10747 |
% \begin{macrocode} |
| 10748 |
\gdef\lst@ActiveCDefX#1{\lst@ActiveCDefX@#1} |
| 10749 |
\gdef\lst@ActiveCDefX@#1#2#3{% |
| 10750 |
\catcode`#1\active\lccode`\~=`#1% |
| 10751 |
\lowercase{\lst@CDefIt~}{#2}{#3}{}} |
| 10752 |
% \end{macrocode} |
| 10753 |
% \end{macro} |
| 10754 |
% |
| 10755 |
% \begin{macro}{\lst@Escape} |
| 10756 |
% gets four arguments all in all. The first and second are the `begin' and |
| 10757 |
% `end' escape sequences, the third is executed when the escape starts, and the |
| 10758 |
% fourth right before ending it. We use the same mechanism as for \TeX\ comment |
| 10759 |
% lines. The |\lst@ifdropinput| test has been added after a bug report by |
| 10760 |
% \lsthelper{Michael~Weber}{2002/03/26}{escape on lines < firstline corrupts |
| 10761 |
% output}. The |\lst@newlines\z@| was added due to a bug report by |
| 10762 |
% \lsthelper{Frank~Atanassow}{2004/10/07}{space after mathescape is not |
| 10763 |
% preserved}. |
| 10764 |
% \begin{macrocode} |
| 10765 |
\gdef\lst@Escape#1#2#3#4{% |
| 10766 |
\lst@CArgX #1\relax\lst@CDefX |
| 10767 |
{}% |
| 10768 |
{\lst@ifdropinput\else |
| 10769 |
\lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken |
| 10770 |
\lst@InterruptModes |
| 10771 |
\lst@EnterMode{\lst@TeXmode}{\lst@modetrue}% |
| 10772 |
% \end{macrocode} |
| 10773 |
% Now we must define the character sequence to end the escape. |
| 10774 |
% \begin{macrocode} |
| 10775 |
\ifx\^^M#2% |
| 10776 |
\lst@CArg #2\relax\lst@ActiveCDefX |
| 10777 |
{}% |
| 10778 |
{\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes}% |
| 10779 |
{\lst@MProcessListing}% |
| 10780 |
\else |
| 10781 |
\lst@CArg #2\relax\lst@ActiveCDefX |
| 10782 |
{}% |
| 10783 |
{\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes |
| 10784 |
\lst@newlines\z@ \lst@whitespacefalse}% |
| 10785 |
{}% |
| 10786 |
\fi |
| 10787 |
#3\lst@escapebegin |
| 10788 |
\fi}% |
| 10789 |
{}} |
| 10790 |
% \end{macrocode} |
| 10791 |
% The |\lst@whitespacefalse| above was added after a bug report from |
| 10792 |
% \lsthelper{Martin~Steffen}{2001/04/07}{mathescape drops subsequent space}. |
| 10793 |
% \begin{macrocode} |
| 10794 |
\lst@NewMode\lst@TeXmode |
| 10795 |
% \end{macrocode} |
| 10796 |
% \end{macro} |
| 10797 |
% |
| 10798 |
% \begin{lstkey}{escapebegin} |
| 10799 |
% \begin{lstkey}{escapeend} |
| 10800 |
% The keys simply store the arguments. |
| 10801 |
% \begin{macrocode} |
| 10802 |
\lst@Key{escapebegin}{}{\def\lst@escapebegin{#1}} |
| 10803 |
\lst@Key{escapeend}{}{\def\lst@escapeend{#1}} |
| 10804 |
% \end{macrocode} |
| 10805 |
% \end{lstkey} |
| 10806 |
% \end{lstkey} |
| 10807 |
% |
| 10808 |
% \begin{lstkey}{escapechar} |
| 10809 |
% The introduction of this key is due to a communication with \lsthelper |
| 10810 |
% {Rui~Oliveira}{1998/06/05}{escape characters}. We define |\lst@DefEsc| and |
| 10811 |
% execute it after selecting the standard character table. |
| 10812 |
% \begin{macrocode} |
| 10813 |
\lst@Key{escapechar}{} |
| 10814 |
{\ifx\@empty#1\@empty |
| 10815 |
\let\lst@DefEsc\relax |
| 10816 |
\else |
| 10817 |
\def\lst@DefEsc{\lst@Escape{#1}{#1}{}{}}% |
| 10818 |
\fi} |
| 10819 |
\lst@AddToHook{TextStyle}{\let\lst@DefEsc\@empty} |
| 10820 |
\lst@AddToHook{SelectCharTable}{\lst@DefEsc} |
| 10821 |
% \end{macrocode} |
| 10822 |
% \end{lstkey} |
| 10823 |
% |
| 10824 |
% \begin{lstkey}{escapeinside} |
| 10825 |
% Nearly the same. |
| 10826 |
% \begin{macrocode} |
| 10827 |
\lst@Key{escapeinside}{}{\lstKV@TwoArg{#1}% |
| 10828 |
{\let\lst@DefEsc\@empty |
| 10829 |
\ifx\@empty##1@empty\else \ifx\@empty##2\@empty\else |
| 10830 |
\def\lst@DefEsc{\lst@Escape{##1}{##2}{}{}}% |
| 10831 |
\fi\fi}} |
| 10832 |
% \end{macrocode} |
| 10833 |
% \end{lstkey} |
| 10834 |
% |
| 10835 |
% \begin{lstkey}{mathescape} |
| 10836 |
% This is a switch and checked after character table selection. We use |
| 10837 |
% |\lst@Escape| with math shifts as arguments, but all inside |\hbox| |
| 10838 |
% to determine the correct width. |
| 10839 |
% \begin{macrocode} |
| 10840 |
\lst@Key{mathescape}{false}[t]{\lstKV@SetIf{#1}\lst@ifmathescape} |
| 10841 |
\lst@AddToHook{SelectCharTable} |
| 10842 |
{\lst@ifmathescape \lst@Escape{\$}{\$}% |
| 10843 |
{\setbox\@tempboxa=\hbox\bgroup$}% |
| 10844 |
{$\egroup \lst@CalcLostSpaceAndOutput}\fi} |
| 10845 |
% \end{macrocode} |
| 10846 |
% \end{lstkey} |
| 10847 |
% |
| 10848 |
% \begin{macrocode} |
| 10849 |
\lst@EndAspect |
| 10850 |
%</misc> |
| 10851 |
% \end{macrocode} |
| 10852 |
% \end{aspect} |
| 10853 |
% |
| 10854 |
% |
| 10855 |
% \section{Keywords} |
| 10856 |
% |
| 10857 |
% |
| 10858 |
% \subsection{Making tests}\label{iMakingTests} |
| 10859 |
% |
| 10860 |
% \begin{aspect}{keywords} |
| 10861 |
% We begin a new and very important aspect. |
| 10862 |
% First of all we need to initialize some variables in order to work around a |
| 10863 |
% bug reported by \lsthelper{Beat~Birkhofer}{2001/06/15}{savemem doesn't work}. |
| 10864 |
% \begin{macrocode} |
| 10865 |
%<*misc> |
| 10866 |
\lst@BeginAspect{keywords} |
| 10867 |
% \end{macrocode} |
| 10868 |
% \begin{macrocode} |
| 10869 |
\global\let\lst@ifsensitive\iftrue % init |
| 10870 |
\global\let\lst@ifsensitivedefed\iffalse % init % \global |
| 10871 |
% \end{macrocode} |
| 10872 |
% All keyword tests take the following three arguments. |
| 10873 |
% \begin{macroargs} |
| 10874 |
% \item \meta{prefix} |
| 10875 |
% \item |\lst@|\meta{name}|@list| (a list of macros which contain the keywords) |
| 10876 |
% \item |\lst@g|\meta{name}|@sty| (global style macro) |
| 10877 |
% \end{macroargs} |
| 10878 |
% We begin with non memory-saving tests. |
| 10879 |
% \begingroup |
| 10880 |
% \begin{macrocode} |
| 10881 |
\lst@ifsavemem\else |
| 10882 |
% \end{macrocode} |
| 10883 |
% \endgroup |
| 10884 |
% |
| 10885 |
% \begin{macro}{\lst@KeywordTest} |
| 10886 |
% Fast keyword tests take advance of the |\lst@UM| construction in section |
| 10887 |
% \ref{iCharacterTables}. If |\lst@UM| is empty, all `use macro' characters |
| 10888 |
% expand to their original characters. Since |\lst|\meta{prefix}|@|\meta{keyword} |
| 10889 |
% will be equivalent to the appropriate style, we only need to build the control |
| 10890 |
% sequence |\lst|\meta{prefix}|@|\meta{current token} and assign it to |
| 10891 |
% |\lst@thestyle|. |
| 10892 |
% \begin{macrocode} |
| 10893 |
\gdef\lst@KeywordTest#1#2#3{% |
| 10894 |
\begingroup \let\lst@UM\@empty |
| 10895 |
\global\expandafter\let\expandafter\@gtempa |
| 10896 |
\csname\@lst#1@\the\lst@token\endcsname |
| 10897 |
\endgroup |
| 10898 |
\ifx\@gtempa\relax\else |
| 10899 |
\let\lst@thestyle\@gtempa |
| 10900 |
\fi} |
| 10901 |
% \end{macrocode} |
| 10902 |
% Note that we need neither |#2| nor |#3| here. |
| 10903 |
% \end{macro} |
| 10904 |
% |
| 10905 |
% \begin{macro}{\lst@KEYWORDTEST} |
| 10906 |
% Case insensitive tests make the current character string upper case and give |
| 10907 |
% it to a submacro similar to |\lst@KeywordTest|. |
| 10908 |
% \begin{macrocode} |
| 10909 |
\gdef\lst@KEYWORDTEST{% |
| 10910 |
\uppercase\expandafter{\expandafter |
| 10911 |
\lst@KEYWORDTEST@\the\lst@token}\relax} |
| 10912 |
\gdef\lst@KEYWORDTEST@#1\relax#2#3#4{% |
| 10913 |
\begingroup \let\lst@UM\@empty |
| 10914 |
\global\expandafter\let\expandafter\@gtempa |
| 10915 |
\csname\@lst#2@#1\endcsname |
| 10916 |
\endgroup |
| 10917 |
\ifx\@gtempa\relax\else |
| 10918 |
\let\lst@thestyle\@gtempa |
| 10919 |
\fi} |
| 10920 |
% \end{macrocode} |
| 10921 |
% \end{macro} |
| 10922 |
% |
| 10923 |
% \begin{macro}{\lst@WorkingTest} |
| 10924 |
% \begin{macro}{\lst@WORKINGTEST} |
| 10925 |
% The same except that |\lst|\meta{prefix}|@|\meta{current token} might be |
| 10926 |
% a working procedure; it is executed. |
| 10927 |
% \begin{macrocode} |
| 10928 |
\gdef\lst@WorkingTest#1#2#3{% |
| 10929 |
\begingroup \let\lst@UM\@empty |
| 10930 |
\global\expandafter\let\expandafter\@gtempa |
| 10931 |
\csname\@lst#1@\the\lst@token\endcsname |
| 10932 |
\endgroup |
| 10933 |
\@gtempa} |
| 10934 |
% \end{macrocode} |
| 10935 |
% \begin{macrocode} |
| 10936 |
\gdef\lst@WORKINGTEST{% |
| 10937 |
\uppercase\expandafter{\expandafter |
| 10938 |
\lst@WORKINGTEST@\the\lst@token}\relax} |
| 10939 |
\gdef\lst@WORKINGTEST@#1\relax#2#3#4{% |
| 10940 |
\begingroup \let\lst@UM\@empty |
| 10941 |
\global\expandafter\let\expandafter\@gtempa |
| 10942 |
\csname\@lst#2@#1\endcsname |
| 10943 |
\endgroup |
| 10944 |
\@gtempa} |
| 10945 |
% \end{macrocode} |
| 10946 |
% \end{macro} |
| 10947 |
% \end{macro} |
| 10948 |
% |
| 10949 |
% \begin{macro}{\lst@DefineKeywords} |
| 10950 |
% Eventually we need macros which define and undefine |
| 10951 |
% |\lst|\meta{prefix}|@|\meta{keyword}. Here the arguments are |
| 10952 |
% \begin{macroargs} |
| 10953 |
% \item \meta{prefix} |
| 10954 |
% \item |\lst@|\meta{name} (a keyword list) |
| 10955 |
% \item |\lst@g|\meta{name}|@sty| |
| 10956 |
% \end{macroargs} |
| 10957 |
% We make the keywords upper case if necessary, \ldots |
| 10958 |
% \begin{macrocode} |
| 10959 |
\gdef\lst@DefineKeywords#1#2#3{% |
| 10960 |
\lst@ifsensitive |
| 10961 |
\def\lst@next{\lst@for#2}% |
| 10962 |
\else |
| 10963 |
\def\lst@next{\uppercase\expandafter{\expandafter\lst@for#2}}% |
| 10964 |
\fi |
| 10965 |
\lst@next\do |
| 10966 |
% \end{macrocode} |
| 10967 |
% \ldots\space iterate through the list, and make |
| 10968 |
% |\lst|\meta{prefix}|@|\meta{keyword} (if undefined) equivalent to |
| 10969 |
% |\lst@g|\meta{name}|@sty| which is possibly a working macro. |
| 10970 |
% \begin{macrocode} |
| 10971 |
{\expandafter\ifx\csname\@lst#1@##1\endcsname\relax |
| 10972 |
\global\expandafter\let\csname\@lst#1@##1\endcsname#3% |
| 10973 |
\fi}} |
| 10974 |
% \end{macrocode} |
| 10975 |
% \end{macro} |
| 10976 |
% |
| 10977 |
% \begin{macro}{\lst@UndefineKeywords} |
| 10978 |
% We make the keywords upper case if necessary, \ldots |
| 10979 |
% \begin{macrocode} |
| 10980 |
\gdef\lst@UndefineKeywords#1#2#3{% |
| 10981 |
\lst@ifsensitivedefed |
| 10982 |
\def\lst@next{\lst@for#2}% |
| 10983 |
\else |
| 10984 |
\def\lst@next{\uppercase\expandafter{\expandafter\lst@for#2}}% |
| 10985 |
\fi |
| 10986 |
\lst@next\do |
| 10987 |
% \end{macrocode} |
| 10988 |
% \ldots\space iterate through the list, and `undefine' |
| 10989 |
% |\lst|\meta{prefix}|@|\meta{keyword} if it's equivalent to |
| 10990 |
% |\lst@g|\meta{name}|@sty|. |
| 10991 |
% \begin{macrocode} |
| 10992 |
{\expandafter\ifx\csname\@lst#1@##1\endcsname#3% |
| 10993 |
\global\expandafter\let\csname\@lst#1@##1\endcsname\relax |
| 10994 |
\fi}} |
| 10995 |
% \end{macrocode} |
| 10996 |
% Thanks to \lsthelper{Magnus~Lewis-Smith}{1999/09/08}{keywords do not |
| 10997 |
% undefine} a wrong |#2| in the replacement text could be changed to |#3|. |
| 10998 |
% \end{macro} |
| 10999 |
% |
| 11000 |
% \begingroup |
| 11001 |
% And now memory-saving tests. |
| 11002 |
% \begin{macrocode} |
| 11003 |
\fi |
| 11004 |
\lst@ifsavemem |
| 11005 |
% \end{macrocode} |
| 11006 |
% \endgroup |
| 11007 |
% |
| 11008 |
% \begin{macro}{\lst@IfOneOutOf} |
| 11009 |
% The definition here is similar to |\lst@IfOneOf|, but its second argument |
| 11010 |
% is a |\lst@|\meta{name}|@list|. Therefore we test a list of macros here. |
| 11011 |
% \begin{macrocode} |
| 11012 |
\gdef\lst@IfOneOutOf#1\relax#2{% |
| 11013 |
\def\lst@temp##1,#1,##2##3\relax{% |
| 11014 |
\ifx\@empty##2\else \expandafter\lst@IOOOfirst \fi}% |
| 11015 |
\def\lst@next{\lst@IfOneOutOf@#1\relax}% |
| 11016 |
\expandafter\lst@next#2\relax\relax} |
| 11017 |
% \end{macrocode} |
| 11018 |
% We either execute the \meta{else} part or make the next test. |
| 11019 |
% \begin{macrocode} |
| 11020 |
\gdef\lst@IfOneOutOf@#1\relax#2#3{% |
| 11021 |
\ifx#2\relax |
| 11022 |
\expandafter\@secondoftwo |
| 11023 |
\else |
| 11024 |
\expandafter\lst@temp\expandafter,#2,#1,\@empty\relax |
| 11025 |
\expandafter\lst@next |
| 11026 |
\fi} |
| 11027 |
\ifx\iffalse\else\fi |
| 11028 |
\gdef\lst@IOOOfirst#1\relax#2#3{\fi#2} |
| 11029 |
% \end{macrocode} |
| 11030 |
% The line |\ifx\iffalse\else\fi| balances the |\fi| inside |\lst@IOOOfirst|. |
| 11031 |
% \end{macro} |
| 11032 |
% |
| 11033 |
% \begin{macro}{\lst@IFONEOUTOF} |
| 11034 |
% As in |\lst@IFONEOF| we need two |\uppercase|s here. |
| 11035 |
% \begin{macrocode} |
| 11036 |
\gdef\lst@IFONEOUTOF#1\relax#2{% |
| 11037 |
\uppercase{\def\lst@temp##1,#1},##2##3\relax{% |
| 11038 |
\ifx\@empty##2\else \expandafter\lst@IOOOfirst \fi}% |
| 11039 |
\def\lst@next{\lst@IFONEOUTOF@#1\relax}% |
| 11040 |
\expandafter\lst@next#2\relax} |
| 11041 |
\gdef\lst@IFONEOUTOF@#1\relax#2#3{% |
| 11042 |
\ifx#2\relax |
| 11043 |
\expandafter\@secondoftwo |
| 11044 |
\else |
| 11045 |
\uppercase |
| 11046 |
{\expandafter\lst@temp\expandafter,#2,#1,\@empty\relax}% |
| 11047 |
\expandafter\lst@next |
| 11048 |
\fi} |
| 11049 |
% \end{macrocode} |
| 11050 |
% Note: The third last line uses the fact that keyword lists (not the list |
| 11051 |
% of keyword lists) are already made upper case if keywords are insensitive. |
| 11052 |
% \end{macro} |
| 11053 |
% |
| 11054 |
% \begin{macro}{\lst@KWTest} |
| 11055 |
% is a helper for the keyword and working identifier tests. We expand the |
| 11056 |
% token and call |\lst@IfOneOf|. The tests below will append appropriate |
| 11057 |
% \meta{then} and \meta{else} arguments. |
| 11058 |
% \begin{macrocode} |
| 11059 |
\gdef\lst@KWTest{% |
| 11060 |
\begingroup \let\lst@UM\@empty |
| 11061 |
\expandafter\xdef\expandafter\@gtempa\expandafter{\the\lst@token}% |
| 11062 |
\endgroup |
| 11063 |
\expandafter\lst@IfOneOutOf\@gtempa\relax} |
| 11064 |
% \end{macrocode} |
| 11065 |
% \end{macro} |
| 11066 |
% |
| 11067 |
% \begin{macro}{\lst@KeywordTest} |
| 11068 |
% \begin{macro}{\lst@KEYWORDTEST} |
| 11069 |
% are fairly easy now. Note that we don't need |#1|=\meta{prefix} here. |
| 11070 |
% \begin{macrocode} |
| 11071 |
\gdef\lst@KeywordTest#1#2#3{\lst@KWTest #2{\let\lst@thestyle#3}{}} |
| 11072 |
\global\let\lst@KEYWORDTEST\lst@KeywordTest |
| 11073 |
% \end{macrocode} |
| 11074 |
% For case insensitive tests we assign the insensitive version to |
| 11075 |
% |\lst@IfOneOutOf|. Thus we need no extra definition here. |
| 11076 |
% \end{macro} |
| 11077 |
% \end{macro} |
| 11078 |
% |
| 11079 |
% \begin{macro}{\lst@WorkingTest} |
| 11080 |
% \begin{macro}{\lst@WORKINGTEST} |
| 11081 |
% Ditto. |
| 11082 |
% \begin{macrocode} |
| 11083 |
\gdef\lst@WorkingTest#1#2#3{\lst@KWTest #2#3{}} |
| 11084 |
\global\let\lst@WORKINGTEST\lst@WorkingTest |
| 11085 |
% \end{macrocode} |
| 11086 |
% \end{macro} |
| 11087 |
% \end{macro} |
| 11088 |
% |
| 11089 |
% \begingroup |
| 11090 |
% \begin{macrocode} |
| 11091 |
\fi |
| 11092 |
% \end{macrocode} |
| 11093 |
% \endgroup |
| 11094 |
% |
| 11095 |
% \begin{lstkey}{sensitive} |
| 11096 |
% is a switch, preset \texttt{true} every language selection. |
| 11097 |
% \begin{macrocode} |
| 11098 |
\lst@Key{sensitive}\relax[t]{\lstKV@SetIf{#1}\lst@ifsensitive} |
| 11099 |
\lst@AddToHook{SetLanguage}{\let\lst@ifsensitive\iftrue} |
| 11100 |
% \end{macrocode} |
| 11101 |
% We select case insensitive definitions if necessary. |
| 11102 |
% \begin{macrocode} |
| 11103 |
\lst@AddToHook{Init} |
| 11104 |
{\lst@ifsensitive\else |
| 11105 |
\let\lst@KeywordTest\lst@KEYWORDTEST |
| 11106 |
\let\lst@WorkingTest\lst@WORKINGTEST |
| 11107 |
\let\lst@IfOneOutOf\lst@IFONEOUTOF |
| 11108 |
\fi} |
| 11109 |
% \end{macrocode} |
| 11110 |
% \end{lstkey} |
| 11111 |
% |
| 11112 |
% \begin{macro}{\lst@MakeMacroUppercase} |
| 11113 |
% makes the contents of |#1| (if defined) upper case. |
| 11114 |
% \begin{macrocode} |
| 11115 |
\gdef\lst@MakeMacroUppercase#1{% |
| 11116 |
\ifx\@undefined#1\else \uppercase\expandafter |
| 11117 |
{\expandafter\def\expandafter#1\expandafter{#1}}% |
| 11118 |
\fi} |
| 11119 |
% \end{macrocode} |
| 11120 |
% \end{macro} |
| 11121 |
% |
| 11122 |
% |
| 11123 |
% \subsection{Installing tests} |
| 11124 |
% |
| 11125 |
% \begin{macro}{\lst@InstallTest} |
| 11126 |
% The arguments are |
| 11127 |
% \begin{macroargs} |
| 11128 |
% \item \meta{prefix} |
| 11129 |
% \item |\lst@|\meta{name}|@list| |
| 11130 |
% \item |\lst@|\meta{name} |
| 11131 |
% \item |\lst@g|\meta{name}|@list| |
| 11132 |
% \item |\lst@g|\meta{name} |
| 11133 |
% \item |\lst@g|\meta{name}|@sty| |
| 11134 |
% \item \alternative{w,s} (working procedure or style) |
| 11135 |
% \item \alternative{d,o} (\hookname{DetectKeywords} or \hookname{Output} hook) |
| 11136 |
% \end{macroargs} |
| 11137 |
% We just insert hook material. The tests will be inserted on demand. |
| 11138 |
% \begin{macrocode} |
| 11139 |
\gdef\lst@InstallTest#1#2#3#4#5#6#7#8{% |
| 11140 |
\lst@AddToHook{TrackKeywords}{\lst@TrackKeywords{#1}#2#4#6#7#8}% |
| 11141 |
\lst@AddToHook{PostTrackKeywords}{\lst@PostTrackKeywords#2#3#4#5}} |
| 11142 |
% \end{macrocode} |
| 11143 |
% \begin{macrocode} |
| 11144 |
\lst@AddToHook{Init}{\lsthk@TrackKeywords\lsthk@PostTrackKeywords} |
| 11145 |
\lst@AddToHook{TrackKeywords} |
| 11146 |
{\global\let\lst@DoDefineKeywords\@empty}% init |
| 11147 |
\lst@AddToHook{PostTrackKeywords} |
| 11148 |
{\lst@DoDefineKeywords |
| 11149 |
\global\let\lst@DoDefineKeywords\@empty}% init |
| 11150 |
% \end{macrocode} |
| 11151 |
% We have to detect the keywords somewhere. |
| 11152 |
% \begin{macrocode} |
| 11153 |
\lst@AddToHook{Output}{\lst@ifkeywords \lsthk@DetectKeywords \fi} |
| 11154 |
\lst@AddToHook{DetectKeywords}{}% init |
| 11155 |
\lst@AddToHook{ModeTrue}{\let\lst@ifkeywords\iffalse} |
| 11156 |
\lst@AddToHookExe{Init}{\let\lst@ifkeywords\iftrue} |
| 11157 |
% \end{macrocode} |
| 11158 |
% \end{macro} |
| 11159 |
% |
| 11160 |
% \begin{macro}{\lst@InstallTestNow} |
| 11161 |
% actually inserts a test. |
| 11162 |
% \begin{macroargs} |
| 11163 |
% \item \meta{prefix} |
| 11164 |
% \item |\lst@|\meta{name}|@list| |
| 11165 |
% \item |\lst@g|\meta{name}|@sty| |
| 11166 |
% \item \alternative{w,s} (working procedure or style) |
| 11167 |
% \item \alternative{d,o} (\hookname{DetectKeywords} or \hookname{Output} hook) |
| 11168 |
% \end{macroargs} |
| 11169 |
% For example, |#4#5|=|sd| will add |
| 11170 |
% |\lst@KeywordTest{|\meta{prefix}|}| |
| 11171 |
% |\lst@|\meta{name}|@list| |\lst@g|\meta{name}|@sty| |
| 11172 |
% to the \hookname{DetectKeywords} hook. |
| 11173 |
% \begin{macrocode} |
| 11174 |
\gdef\lst@InstallTestNow#1#2#3#4#5{% |
| 11175 |
\@ifundefined{\string#2#1}% |
| 11176 |
{\global\@namedef{\string#2#1}{}% |
| 11177 |
\edef\@tempa{% |
| 11178 |
\noexpand\lst@AddToHook{\ifx#5dDetectKeywords\else Output\fi}% |
| 11179 |
{\ifx #4w\noexpand\lst@WorkingTest |
| 11180 |
\else\noexpand\lst@KeywordTest \fi |
| 11181 |
{#1}\noexpand#2\noexpand#3}}% |
| 11182 |
% \end{macrocode} |
| 11183 |
% If we are advised to save memory, we insert a test for each \meta{name}. |
| 11184 |
% Otherwise we install the tests according to \meta{prefix}. |
| 11185 |
% \begin{macrocode} |
| 11186 |
\lst@ifsavemem |
| 11187 |
\@tempa |
| 11188 |
\else |
| 11189 |
\@ifundefined{\@lst#1@if@ins}% |
| 11190 |
{\@tempa \global\@namedef{\@lst#1@if@ins}{}}% |
| 11191 |
{}% |
| 11192 |
\fi} |
| 11193 |
{}} |
| 11194 |
% \end{macrocode} |
| 11195 |
% \end{macro} |
| 11196 |
% |
| 11197 |
% \begin{macro}{\lst@TrackKeywords} |
| 11198 |
% Now it gets a bit tricky. We expand the class list |\lst@|\meta{name}|@list| |
| 11199 |
% behind |\lst@TK@{|\meta{prefix}|}||\lst@g|\meta{name}|@sty| and use two |
| 11200 |
% |\relax|es as terminators. This will define the keywords of all the classes |
| 11201 |
% as keywords of type \meta{prefix}. More details come soon. |
| 11202 |
% \begin{macrocode} |
| 11203 |
\gdef\lst@TrackKeywords#1#2#3#4#5#6{% |
| 11204 |
\lst@false |
| 11205 |
\def\lst@arg{{#1}#4}% |
| 11206 |
\expandafter\expandafter\expandafter\lst@TK@ |
| 11207 |
\expandafter\lst@arg#2\relax\relax |
| 11208 |
% \end{macrocode} |
| 11209 |
% And nearly the same to undefine all out-dated keywords, which is necessary |
| 11210 |
% only if we don't save memory. |
| 11211 |
% \begin{macrocode} |
| 11212 |
\lst@ifsavemem\else |
| 11213 |
\def\lst@arg{{#1}#4#2}% |
| 11214 |
\expandafter\expandafter\expandafter\lst@TK@@ |
| 11215 |
\expandafter\lst@arg#3\relax\relax |
| 11216 |
\fi |
| 11217 |
% \end{macrocode} |
| 11218 |
% Finally we install the keyword test if keywords changed, in particular if |
| 11219 |
% they are defined the first time. Note that |\lst@InstallTestNow| inserts a |
| 11220 |
% test only once. |
| 11221 |
% \begin{macrocode} |
| 11222 |
\lst@if \lst@InstallTestNow{#1}#2#4#5#6\fi} |
| 11223 |
% \end{macrocode} |
| 11224 |
% Back to the current keywords. Global macros |\lst@g|\meta{id} contain |
| 11225 |
% globally defined keywords, whereas |\lst@|\meta{id} conatin the true |
| 11226 |
% keywords. This way we can keep track of the keywords: If keywords or |
| 11227 |
% \keyname{sensitive} changed, we undefine the old (= globally defined) |
| 11228 |
% keywords and define the true ones. The arguments of |\lst@TK@| are |
| 11229 |
% \begin{macroargs} |
| 11230 |
% \item \meta{prefix} |
| 11231 |
% \item |\lst@g|\meta{name}|@sty| |
| 11232 |
% \item |\lst@|\meta{id} |
| 11233 |
% \item |\lst@g|\meta{id} |
| 11234 |
% \end{macroargs} |
| 11235 |
% Thanks to \lsthelper{Holger~Arndt}{2004/05/27}{bad \lst@UndefineKeywords |
| 11236 |
% \lst@DefineKeywords sequence if keyword crosses orders in two languages} |
| 11237 |
% the definition of keywords is now delayed via |\lst@DoDefineKeywords|. |
| 11238 |
% \begin{macrocode} |
| 11239 |
\gdef\lst@TK@#1#2#3#4{% |
| 11240 |
\ifx\lst@ifsensitive\lst@ifsensitivedefed |
| 11241 |
\ifx#3#4\else |
| 11242 |
\lst@true |
| 11243 |
\lst@ifsavemem\else |
| 11244 |
\lst@UndefineKeywords{#1}#4#2% |
| 11245 |
\lst@AddTo\lst@DoDefineKeywords{\lst@DefineKeywords{#1}#3#2}% |
| 11246 |
\fi |
| 11247 |
\fi |
| 11248 |
\else |
| 11249 |
\ifx#3\relax\else |
| 11250 |
\lst@true |
| 11251 |
\lst@ifsavemem\else |
| 11252 |
\lst@UndefineKeywords{#1}#4#2% |
| 11253 |
\lst@AddTo\lst@DoDefineKeywords{\lst@DefineKeywords{#1}#3#2}% |
| 11254 |
\fi |
| 11255 |
\fi |
| 11256 |
\fi |
| 11257 |
% \end{macrocode} |
| 11258 |
% We don't define and undefine keywords if we try to save memory. But we |
| 11259 |
% possibly need to make them upper case, which again wastes some memory. |
| 11260 |
% \begin{macrocode} |
| 11261 |
\lst@ifsavemem \ifx#3\relax\else |
| 11262 |
\lst@ifsensitive\else \lst@MakeMacroUppercase#3\fi |
| 11263 |
\fi \fi |
| 11264 |
% \end{macrocode} |
| 11265 |
% Reaching the end of the class list, we end the loop. |
| 11266 |
% \begin{macrocode} |
| 11267 |
\ifx#3\relax |
| 11268 |
\expandafter\@gobblethree |
| 11269 |
\fi |
| 11270 |
\lst@TK@{#1}#2} |
| 11271 |
% \end{macrocode} |
| 11272 |
% Here now we undefine the out-dated keywords. While not reaching the end of |
| 11273 |
% the global list, we look whether the keyword class |#4#5| is still in use or |
| 11274 |
% needs to be undefined. Our arguments are |
| 11275 |
% \begin{macroargs} |
| 11276 |
% \item \meta{prefix} |
| 11277 |
% \item |\lst@g|\meta{name}|@sty| |
| 11278 |
% \item |\lst@|\meta{name}|@list| |
| 11279 |
% \item |\lst@|\meta{id} |
| 11280 |
% \item |\lst@g|\meta{id} |
| 11281 |
% \end{macroargs} |
| 11282 |
% \begin{macrocode} |
| 11283 |
\gdef\lst@TK@@#1#2#3#4#5{% |
| 11284 |
\ifx#4\relax |
| 11285 |
\expandafter\@gobblefour |
| 11286 |
\else |
| 11287 |
\lst@IfSubstring{#4#5}#3{}{\lst@UndefineKeywords{#1}#5#2}% |
| 11288 |
\fi |
| 11289 |
\lst@TK@@{#1}#2#3} |
| 11290 |
% \end{macrocode} |
| 11291 |
% Keywords are up-to-date after \hookname{InitVars}. |
| 11292 |
% \begin{macrocode} |
| 11293 |
\lst@AddToHook{InitVars} |
| 11294 |
{\global\let\lst@ifsensitivedefed\lst@ifsensitive} |
| 11295 |
% \end{macrocode} |
| 11296 |
% \end{macro} |
| 11297 |
% |
| 11298 |
% \begin{macro}{\lst@PostTrackKeywords} |
| 11299 |
% After updating all the keywords, the global keywords and the global list |
| 11300 |
% become equivalent to the local ones. |
| 11301 |
% \begin{macrocode} |
| 11302 |
\gdef\lst@PostTrackKeywords#1#2#3#4{% |
| 11303 |
\lst@ifsavemem\else |
| 11304 |
\global\let#3#1% |
| 11305 |
\global\let#4#2% |
| 11306 |
\fi} |
| 11307 |
% \end{macrocode} |
| 11308 |
% \end{macro} |
| 11309 |
% |
| 11310 |
% |
| 11311 |
% \subsection{Classes and families} |
| 11312 |
% |
| 11313 |
% \begin{lstkey}{classoffset} |
| 11314 |
% just stores the argument in a macro. |
| 11315 |
% \begin{macrocode} |
| 11316 |
\lst@Key{classoffset}\z@{\def\lst@classoffset{#1}} |
| 11317 |
% \end{macrocode} |
| 11318 |
% \end{lstkey} |
| 11319 |
% |
| 11320 |
% \begin{macro}{\lst@InstallFamily} |
| 11321 |
% Recall the parameters |
| 11322 |
% \begin{macroargs} |
| 11323 |
% \item \meta{prefix} |
| 11324 |
% \item \meta{name} |
| 11325 |
% \item \meta{style name} |
| 11326 |
% \item \meta{style init} |
| 11327 |
% \item \meta{default style name} |
| 11328 |
% \item \meta{working procedure} |
| 11329 |
% \item \alternative{l,o} (language or other key) |
| 11330 |
% \item \alternative{d,o} (\hookname{DetectKeywords} or \hookname{Output} hook) |
| 11331 |
% \end{macroargs} |
| 11332 |
% First we define the keys and the style key \meta{style name} if and only if |
| 11333 |
% the name is not empty. |
| 11334 |
% \begin{macrocode} |
| 11335 |
\gdef\lst@InstallFamily#1#2#3#4#5{% |
| 11336 |
\lst@Key{#2}\relax{\lst@UseFamily{#2}##1\relax\lst@MakeKeywords}% |
| 11337 |
\lst@Key{more#2}\relax |
| 11338 |
{\lst@UseFamily{#2}##1\relax\lst@MakeMoreKeywords}% |
| 11339 |
\lst@Key{delete#2}\relax |
| 11340 |
{\lst@UseFamily{#2}##1\relax\lst@DeleteKeywords}% |
| 11341 |
\ifx\@empty#3\@empty\else |
| 11342 |
\lst@Key{#3}{#4}{\lstKV@OptArg[\@ne]{##1}% |
| 11343 |
{\@tempcnta\lst@classoffset \advance\@tempcnta####1\relax |
| 11344 |
\@namedef{lst@#3\ifnum\@tempcnta=\@ne\else \the\@tempcnta |
| 11345 |
\fi}{####2}}}% |
| 11346 |
\fi |
| 11347 |
\expandafter\lst@InstallFamily@ |
| 11348 |
\csname\@lst @#2@data\expandafter\endcsname |
| 11349 |
\csname\@lst @#5\endcsname {#1}{#2}{#3}} |
| 11350 |
% \end{macrocode} |
| 11351 |
% Now we check whether \meta{working procedure} is empty. Accordingly we use |
| 11352 |
% \texttt working procedure or \texttt style in the `data' definition. |
| 11353 |
% The working procedure is defined right here if necessary. |
| 11354 |
% \begin{macrocode} |
| 11355 |
\gdef\lst@InstallFamily@#1#2#3#4#5#6#7#8{% |
| 11356 |
\gdef#1{{#3}{#4}{#5}#2#7}% |
| 11357 |
\long\def\lst@temp##1{#6}% |
| 11358 |
\ifx\lst@temp\@gobble |
| 11359 |
\lst@AddTo#1{s#8}% |
| 11360 |
\else |
| 11361 |
\lst@AddTo#1{w#8}% |
| 11362 |
\global\@namedef{lst@g#4@wp}##1{#6}% |
| 11363 |
\fi} |
| 11364 |
% \end{macrocode} |
| 11365 |
% Nothing else is defined here, all the rest is done on demand. |
| 11366 |
% \end{macro} |
| 11367 |
% |
| 11368 |
% \begin{macro}{\lst@UseFamily} |
| 11369 |
% We look for the optional class number, provide this member, \ldots |
| 11370 |
% \begin{macrocode} |
| 11371 |
\gdef\lst@UseFamily#1{% |
| 11372 |
\def\lst@family{#1}% |
| 11373 |
\@ifnextchar[\lst@UseFamily@{\lst@UseFamily@[\@ne]}} |
| 11374 |
\gdef\lst@UseFamily@[#1]{% |
| 11375 |
\@tempcnta\lst@classoffset \advance\@tempcnta#1\relax |
| 11376 |
\lst@ProvideFamily\lst@family |
| 11377 |
% \end{macrocode} |
| 11378 |
% \ldots\space and build the control sequences \ldots |
| 11379 |
% \begin{macrocode} |
| 11380 |
\lst@UseFamily@a |
| 11381 |
{\lst@family\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi}} |
| 11382 |
\gdef\lst@UseFamily@a#1{% |
| 11383 |
\expandafter\lst@UseFamily@b |
| 11384 |
\csname\@lst @#1@list\expandafter\endcsname |
| 11385 |
\csname\@lst @#1\expandafter\endcsname |
| 11386 |
\csname\@lst @#1@also\expandafter\endcsname |
| 11387 |
\csname\@lst @g#1\endcsname} |
| 11388 |
% \end{macrocode} |
| 11389 |
% \ldots\space required for |\lst@MakeKeywords| and |#6|. |
| 11390 |
% \begin{macrocode} |
| 11391 |
\gdef\lst@UseFamily@b#1#2#3#4#5\relax#6{\lstKV@XOptArg[]{#5}#6#1#2#3#4} |
| 11392 |
% \end{macrocode} |
| 11393 |
% \end{macro} |
| 11394 |
% |
| 11395 |
% \begin{macro}{\lst@ProvideFamily} |
| 11396 |
% provides the member `|\the\@tempcnta|' of the family |#1|. We do nothing if |
| 11397 |
% the member already exists. Otherwise we expand the data macro defined above. |
| 11398 |
% Note that we don't use the counter if it equals one. Since a bug report by |
| 11399 |
% \lsthelper{Kris~Luyten}{2002/08/03}{Undefined control sequence \lst@thestyle} |
| 11400 |
% keyword families use the prefix |lstfam| instead of |lst|. The marker |
| 11401 |
% |\lstfam@#1|\oarg{number} is defined globally since a bug report by |
| 11402 |
% \lsthelper{Edsko~de~Vries}{2003/07/20}{bad keywords with language selections |
| 11403 |
% only in optional arguments}. |
| 11404 |
% \begin{macrocode} |
| 11405 |
\gdef\lst@ProvideFamily#1{% |
| 11406 |
\@ifundefined{lstfam@#1\ifnum\@tempcnta=\@ne\else\the\@tempcnta\fi}% |
| 11407 |
{\global\@namedef{lstfam@#1\ifnum\@tempcnta=\@ne\else |
| 11408 |
\the\@tempcnta\fi}{}% |
| 11409 |
\expandafter\expandafter\expandafter\lst@ProvideFamily@ |
| 11410 |
\csname\@lst @#1@data\endcsname |
| 11411 |
{\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi}}% |
| 11412 |
{}}% |
| 11413 |
% \end{macrocode} |
| 11414 |
% Now we have the following arguments |
| 11415 |
% \begin{macroargs} |
| 11416 |
% \item \meta{prefix} |
| 11417 |
% \item \meta{name} |
| 11418 |
% \item \meta{style name} |
| 11419 |
% \item \meta{default style name} |
| 11420 |
% \item \alternative{l,o} (language or other key) |
| 11421 |
% \item \alternative{w,s} (working procedure or style) |
| 11422 |
% \item \alternative{d,o} (\hookname{DetectKeywords} or \hookname{Output} hook) |
| 11423 |
% \item |\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi| |
| 11424 |
% \end{macroargs} |
| 11425 |
% We define |\lst@g|\meta{name}\meta{number}|@sty| to call either |
| 11426 |
% |\lst@g|\meta{name}|@wp| with the number as argument or |
| 11427 |
% |\lst@|\meta{style name}\meta{number} where the number belongs to the control |
| 11428 |
% sequence. |
| 11429 |
% \begin{macrocode} |
| 11430 |
\gdef\lst@ProvideFamily@#1#2#3#4#5#6#7#8{% |
| 11431 |
\expandafter\xdef\csname\@lst @g#2#8@sty\endcsname |
| 11432 |
{\if #6w% |
| 11433 |
\expandafter\noexpand\csname\@lst @g#2@wp\endcsname{#8}% |
| 11434 |
\else |
| 11435 |
\expandafter\noexpand\csname\@lst @#3#8\endcsname |
| 11436 |
\fi}% |
| 11437 |
% \end{macrocode} |
| 11438 |
% We ensure the existence of the style macro. This is done in the |
| 11439 |
% \hookname{Init} hook by assigning the default style if necessary. |
| 11440 |
% \begin{macrocode} |
| 11441 |
\ifx\@empty#3\@empty\else |
| 11442 |
\edef\lst@temp{\noexpand\lst@AddToHook{Init}{% |
| 11443 |
\noexpand\lst@ProvideStyle\expandafter\noexpand |
| 11444 |
\csname\@lst @#3#8\endcsname\noexpand#4}}% |
| 11445 |
\lst@temp |
| 11446 |
\fi |
| 11447 |
% \end{macrocode} |
| 11448 |
% We call a submacro to do the rest. It requires some control sequences. |
| 11449 |
% \begin{macrocode} |
| 11450 |
\expandafter\lst@ProvideFamily@@ |
| 11451 |
\csname\@lst @#2#8@list\expandafter\endcsname |
| 11452 |
\csname\@lst @#2#8\expandafter\endcsname |
| 11453 |
\csname\@lst @#2#8@also\expandafter\endcsname |
| 11454 |
\csname\@lst @g#2#8@list\expandafter\endcsname |
| 11455 |
\csname\@lst @g#2#8\expandafter\endcsname |
| 11456 |
\csname\@lst @g#2#8@sty\expandafter\endcsname |
| 11457 |
{#1}#5#6#7} |
| 11458 |
% \end{macrocode} |
| 11459 |
% Now we have (except that \meta{number} is possibly always missing) |
| 11460 |
% \begin{macroargs} |
| 11461 |
% \item |\lst@|\meta{name}\meta{number}|@list| |
| 11462 |
% \item |\lst@|\meta{name}\meta{number} |
| 11463 |
% \item |\lst@|\meta{name}\meta{number}|@also| |
| 11464 |
% \item |\lst@g|\meta{name}\meta{number}|@list| |
| 11465 |
% \item |\lst@g|\meta{name}\meta{number} |
| 11466 |
% \item |\lst@g|\meta{name}\meta{number}|@sty| |
| 11467 |
% \item \meta{prefix} |
| 11468 |
% \item \alternative{l,o} (language or other key) |
| 11469 |
% \item \alternative{w,s} (working procedure or style) |
| 11470 |
% \item \alternative{d,o} (\hookname{DetectKeywords} or \hookname{Output} hook) |
| 11471 |
% \end{macroargs} |
| 11472 |
% Note that |#9| and `|#10|' are read by |\lst@InstallTest|. We initialize all |
| 11473 |
% required `variables' (at \hookname{SetLanguage}) and install the test (which |
| 11474 |
% definition is in fact also delayed). |
| 11475 |
% \begin{macrocode} |
| 11476 |
\gdef\lst@ProvideFamily@@#1#2#3#4#5#6#7#8{% |
| 11477 |
\gdef#1{#2#5}\global\let#2\@empty \global\let#3\@empty % init |
| 11478 |
\gdef#4{#2#5}\global\let#5\@empty % init |
| 11479 |
\if #8l\relax |
| 11480 |
\lst@AddToHook{SetLanguage}{\def#1{#2#5}\let#2\@empty}% |
| 11481 |
\fi |
| 11482 |
\lst@InstallTest{#7}#1#2#4#5#6} |
| 11483 |
% \end{macrocode} |
| 11484 |
% \end{macro} |
| 11485 |
% |
| 11486 |
% \begin{macro}{\lst@InstallKeywords} |
| 11487 |
% Now we take advance of the optional argument construction above. Thus, we |
| 11488 |
% just insert |[\@ne]| as \meta{number} in the definitions of the keys. |
| 11489 |
% \begin{macrocode} |
| 11490 |
\gdef\lst@InstallKeywords#1#2#3#4#5{% |
| 11491 |
\lst@Key{#2}\relax |
| 11492 |
{\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeKeywords}% |
| 11493 |
\lst@Key{more#2}\relax |
| 11494 |
{\lst@UseFamily{#2}[\@ne]##1\relax\lst@MakeMoreKeywords}% |
| 11495 |
\lst@Key{delete#2}\relax |
| 11496 |
{\lst@UseFamily{#2}[\@ne]##1\relax\lst@DeleteKeywords}% |
| 11497 |
\ifx\@empty#3\@empty\else |
| 11498 |
\lst@Key{#3}{#4}{\@namedef{lst@#3}{##1}}% |
| 11499 |
\fi |
| 11500 |
\expandafter\lst@InstallFamily@ |
| 11501 |
\csname\@lst @#2@data\expandafter\endcsname |
| 11502 |
\csname\@lst @#5\endcsname {#1}{#2}{#3}} |
| 11503 |
% \end{macrocode} |
| 11504 |
% \end{macro} |
| 11505 |
% |
| 11506 |
% \begin{macro}{\lst@ProvideStyle} |
| 11507 |
% If the style macro |#1| is not defined, it becomes equivalent to |#2|. |
| 11508 |
% \begin{macrocode} |
| 11509 |
\gdef\lst@ProvideStyle#1#2{% |
| 11510 |
\ifx#1\@undefined \let#1#2% |
| 11511 |
\else\ifx#1\relax \let#1#2\fi\fi} |
| 11512 |
% \end{macrocode} |
| 11513 |
% \end{macro} |
| 11514 |
% |
| 11515 |
% Finally we define |\lst@MakeKeywords|, \ldots, |\lst@DeleteKeywords|. |
| 11516 |
% We begin with two helper. |
| 11517 |
% |
| 11518 |
% \begin{macro}{\lst@BuildClassList} |
| 11519 |
% After |#1| follows a comma separated list of keyword classes terminated by |
| 11520 |
% |,\relax,|, e.g.~|keywords2,emph1,\relax,|. For each \meta{item} in this |
| 11521 |
% list we \emph{append} the two macros |\lst@|\meta{item}|\lst@g|\meta{item} |
| 11522 |
% to |#1|. |
| 11523 |
% \begin{macrocode} |
| 11524 |
\gdef\lst@BuildClassList#1#2,{% |
| 11525 |
\ifx\relax#2\@empty\else |
| 11526 |
\ifx\@empty#2\@empty\else |
| 11527 |
\lst@lExtend#1{\csname\@lst @#2\expandafter\endcsname |
| 11528 |
\csname\@lst @g#2\endcsname}% |
| 11529 |
\fi |
| 11530 |
\expandafter\lst@BuildClassList\expandafter#1 |
| 11531 |
\fi} |
| 11532 |
% \end{macrocode} |
| 11533 |
% \end{macro} |
| 11534 |
% |
| 11535 |
% \begin{macro}{\lst@DeleteClassesIn} |
| 11536 |
% deletes pairs of tokens, namely the arguments |#2#3| to the submacro. |
| 11537 |
% \begin{macrocode} |
| 11538 |
\gdef\lst@DeleteClassesIn#1#2{% |
| 11539 |
\expandafter\lst@DCI@\expandafter#1#2\relax\relax} |
| 11540 |
\gdef\lst@DCI@#1#2#3{% |
| 11541 |
\ifx#2\relax |
| 11542 |
\expandafter\@gobbletwo |
| 11543 |
\else |
| 11544 |
% \end{macrocode} |
| 11545 |
% If we haven't reached the end of the class list, we define a temporary macro |
| 11546 |
% which removes all appearances. |
| 11547 |
% \begin{macrocode} |
| 11548 |
\def\lst@temp##1#2#3##2{% |
| 11549 |
\lst@lAddTo#1{##1}% |
| 11550 |
\ifx ##2\relax\else |
| 11551 |
\expandafter\lst@temp |
| 11552 |
\fi ##2}% |
| 11553 |
\let\@tempa#1\let#1\@empty |
| 11554 |
\expandafter\lst@temp\@tempa#2#3\relax |
| 11555 |
\fi |
| 11556 |
\lst@DCI@#1} |
| 11557 |
% \end{macrocode} |
| 11558 |
% \end{macro} |
| 11559 |
% |
| 11560 |
% \begin{macro}{\lst@MakeKeywords} |
| 11561 |
% We empty some macros and make use of |\lst@MakeMoreKeywords|. |
| 11562 |
% Note that this and the next two definitions have the following arguments: |
| 11563 |
% \begin{macroargs} |
| 11564 |
% \item class list (in brackets) |
| 11565 |
% \item keyword list |
| 11566 |
% \item |\lst@|\meta{name}|@list| |
| 11567 |
% \item |\lst@|\meta{name} |
| 11568 |
% \item |\lst@|\meta{name}|@also| |
| 11569 |
% \item |\lst@g|\meta{name} |
| 11570 |
% \end{macroargs} |
| 11571 |
% \begin{macrocode} |
| 11572 |
\gdef\lst@MakeKeywords[#1]#2#3#4#5#6{% |
| 11573 |
\def#3{#4#6}\let#4\@empty \let#5\@empty |
| 11574 |
\lst@MakeMoreKeywords[#1]{#2}#3#4#5#6} |
| 11575 |
% \end{macrocode} |
| 11576 |
% \end{macro} |
| 11577 |
% |
| 11578 |
% \begin{macro}{\lst@MakeMoreKeywords} |
| 11579 |
% We append classes and keywords. |
| 11580 |
% \begin{macrocode} |
| 11581 |
\gdef\lst@MakeMoreKeywords[#1]#2#3#4#5#6{% |
| 11582 |
\lst@BuildClassList#3#1,\relax,% |
| 11583 |
\lst@DefOther\lst@temp{,#2}\lst@lExtend#4\lst@temp} |
| 11584 |
% \end{macrocode} |
| 11585 |
% \end{macro} |
| 11586 |
% |
| 11587 |
% \begin{macro}{\lst@DeleteKeywords} |
| 11588 |
% We convert the keyword arguments via |\lst@MakeKeywords| and remove the |
| 11589 |
% classes and keywords. |
| 11590 |
% \begin{macrocode} |
| 11591 |
\gdef\lst@DeleteKeywords[#1]#2#3#4#5#6{% |
| 11592 |
\lst@MakeKeywords[#1]{#2}\@tempa\@tempb#5#6% |
| 11593 |
\lst@DeleteClassesIn#3\@tempa |
| 11594 |
\lst@DeleteKeysIn#4\@tempb} |
| 11595 |
% \end{macrocode} |
| 11596 |
% \end{macro} |
| 11597 |
% |
| 11598 |
% |
| 11599 |
% \subsection{Main families and classes} |
| 11600 |
% |
| 11601 |
% |
| 11602 |
% \paragraph{Keywords} |
| 11603 |
% |
| 11604 |
% \begin{lstkey}{keywords} |
| 11605 |
% Defining the keyword family gets very, very easy. |
| 11606 |
% \begin{macrocode} |
| 11607 |
\lst@InstallFamily k{keywords}{keywordstyle}\bfseries{keywordstyle}{}ld |
| 11608 |
% \end{macrocode} |
| 11609 |
% The following macro sets a keywordstyle, which \ldots |
| 11610 |
% \begin{macrocode} |
| 11611 |
\gdef\lst@DefKeywordstyle#1#2\@nil@{% |
| 11612 |
\@namedef{lst@keywordstyle\ifnum\@tempcnta=\@ne\else\the\@tempcnta |
| 11613 |
\fi}{#1#2}}% |
| 11614 |
% \end{macrocode} |
| 11615 |
% \ldots\space is put together here. If we detect a star after the class |
| 11616 |
% number, we insert code to make the keyword uppercase. |
| 11617 |
% \begin{macrocode} |
| 11618 |
\lst@Key{keywordstyle}{\bfseries}{\lstKV@OptArg[\@ne]{#1}% |
| 11619 |
{\@tempcnta\lst@classoffset \advance\@tempcnta##1\relax |
| 11620 |
\@ifstar{\lst@DefKeywordstyle{\uppercase\expandafter{% |
| 11621 |
\expandafter\lst@token |
| 11622 |
\expandafter{\the\lst@token}}}}% |
| 11623 |
{\lst@DefKeywordstyle{}}##2\@nil@}} |
| 11624 |
% \end{macrocode} |
| 11625 |
% \end{lstkey} |
| 11626 |
% |
| 11627 |
% \begin{lstkey}{ndkeywords} |
| 11628 |
% Second order keywords use the same trick as |\lst@InstallKeywords|. |
| 11629 |
% \begin{macrocode} |
| 11630 |
\lst@Key{ndkeywords}\relax |
| 11631 |
{\lst@UseFamily{keywords}[\tw@]#1\relax\lst@MakeKeywords}% |
| 11632 |
\lst@Key{morendkeywords}\relax |
| 11633 |
{\lst@UseFamily{keywords}[\tw@]#1\relax\lst@MakeMoreKeywords}% |
| 11634 |
\lst@Key{deletendkeywords}\relax |
| 11635 |
{\lst@UseFamily{keywords}[\tw@]#1\relax\lst@DeleteKeywords}% |
| 11636 |
\lst@Key{ndkeywordstyle}\relax{\@namedef{lst@keywordstyle2}{#1}}% |
| 11637 |
% \end{macrocode} |
| 11638 |
% \lsthelper{Dr.~Peter~Leibner}{1999/11/05}{undefined \lst@UseKeywords, |
| 11639 |
% Illegal parameter number (##1)} reported two bugs: |\lst@UseKeywords| and |
| 11640 |
% |##1| became |\lst@UseFamily| and |#1|. |
| 11641 |
% \end{lstkey} |
| 11642 |
% |
| 11643 |
% \begin{lstkey}{keywordsprefix} |
| 11644 |
% is implemented experimentally. The one and only prefix indicates its |
| 11645 |
% presence by making |\lst@prefixkeyword| empty. We can catch this information |
| 11646 |
% in the \keyname{Output} hook. |
| 11647 |
% \begin{macrocode} |
| 11648 |
\lst@Key{keywordsprefix}\relax{\lst@DefActive\lst@keywordsprefix{#1}} |
| 11649 |
\global\let\lst@keywordsprefix\@empty |
| 11650 |
\lst@AddToHook{SelectCharTable} |
| 11651 |
{\ifx\lst@keywordsprefix\@empty\else |
| 11652 |
\expandafter\lst@CArg\lst@keywordsprefix\relax |
| 11653 |
\lst@CDef{}% |
| 11654 |
{\lst@ifletter\else |
| 11655 |
\global\let\lst@prefixkeyword\@empty |
| 11656 |
\fi}% |
| 11657 |
{}% |
| 11658 |
\fi} |
| 11659 |
\lst@AddToHook{Init}{\global\let\lst@prefixkeyword\relax} |
| 11660 |
\lst@AddToHook{Output} |
| 11661 |
{\ifx\lst@prefixkeyword\@empty |
| 11662 |
\let\lst@thestyle\lst@gkeywords@sty |
| 11663 |
\global\let\lst@prefixkeyword\relax |
| 11664 |
\fi}% |
| 11665 |
% \end{macrocode} |
| 11666 |
% \end{lstkey} |
| 11667 |
% |
| 11668 |
% \begin{lstkey}{otherkeywords} |
| 11669 |
% Thanks to \lsthelper{Bradford~Chamberlain}{2001/07/07}{otherkeywords={@,@^} |
| 11670 |
% does not work} we now iterate down the list of `other keywords' and make each |
| 11671 |
% active---instead of making the whole argument active. We append the active |
| 11672 |
% token sequence to |\lst@otherkeywords| to define each `other' keyword. |
| 11673 |
% \begin{macrocode} |
| 11674 |
\lst@Key{otherkeywords}{}{% |
| 11675 |
\let\lst@otherkeywords\@empty |
| 11676 |
\lst@for{#1}\do{% |
| 11677 |
\lst@MakeActive{##1}% |
| 11678 |
\lst@lExtend\lst@otherkeywords{% |
| 11679 |
\expandafter\lst@CArg\lst@temp\relax\lst@CDef |
| 11680 |
{}\lst@PrintOtherKeyword\@empty}}} |
| 11681 |
\lst@AddToHook{SelectCharTable}{\lst@otherkeywords} |
| 11682 |
% \end{macrocode} |
| 11683 |
% |\lst@PrintOtherkeyword| has been changed to |\lst@PrintOtherKeyword| after a |
| 11684 |
% bug report by \lsthelper{Peter~Bartke}{2001/11/06}{undefined control sequence |
| 11685 |
% \lst@PrintOtherkeyword}. |
| 11686 |
% \end{lstkey} |
| 11687 |
% |
| 11688 |
% \begin{macro}{\lst@PrintOtherKeyword} |
| 11689 |
% print preceding characters, prepare the output and typeset the argument in |
| 11690 |
% keyword style. \lsthelper{James~Willans}{2004/07/23}{problem: otherkeywords} |
| 11691 |
% reported problems when the output routine is invoked within |\begingroup| and |
| 11692 |
% |\endgroup|. Now the definition is restructured. |
| 11693 |
% \begin{macrocode} |
| 11694 |
\gdef\lst@PrintOtherKeyword#1\@empty{% |
| 11695 |
\lst@XPrintToken |
| 11696 |
\begingroup |
| 11697 |
\lst@modetrue \lsthk@TextStyle |
| 11698 |
\let\lst@ProcessDigit\lst@ProcessLetter |
| 11699 |
\let\lst@ProcessOther\lst@ProcessLetter |
| 11700 |
\lst@lettertrue |
| 11701 |
#1% |
| 11702 |
\lst@SaveToken |
| 11703 |
\endgroup |
| 11704 |
\lst@RestoreToken |
| 11705 |
\global\let\lst@savedcurrstyle\lst@currstyle |
| 11706 |
\let\lst@currstyle\lst@gkeywords@sty |
| 11707 |
\lst@Output |
| 11708 |
\let\lst@currstyle\lst@savedcurrstyle} |
| 11709 |
% \end{macrocode} |
| 11710 |
% \begin{TODO} |
| 11711 |
% Which part of \hookname{TextStyle} hook is required? Is it required anymore, |
| 11712 |
% i.e.after the restruction? Need to move it elsewhere? |
| 11713 |
% \end{TODO} |
| 11714 |
% \end{macro} |
| 11715 |
% |
| 11716 |
% \begin{macrocode} |
| 11717 |
\lst@EndAspect |
| 11718 |
%</misc> |
| 11719 |
% \end{macrocode} |
| 11720 |
% \end{aspect} |
| 11721 |
% |
| 11722 |
% |
| 11723 |
% \paragraph{The emphasize family} |
| 11724 |
% |
| 11725 |
% \begin{aspect}{emph} |
| 11726 |
% is just one macro call here. |
| 11727 |
% \begin{macrocode} |
| 11728 |
%<*misc> |
| 11729 |
\lst@BeginAspect[keywords]{emph} |
| 11730 |
\lst@InstallFamily e{emph}{emphstyle}{}{emphstyle}{}od |
| 11731 |
\lst@EndAspect |
| 11732 |
%</misc> |
| 11733 |
% \end{macrocode} |
| 11734 |
% \end{aspect} |
| 11735 |
% |
| 11736 |
% |
| 11737 |
% \paragraph{\TeX\ control sequences} |
| 11738 |
% |
| 11739 |
% \begin{aspect}{tex} |
| 11740 |
% Here we check the last `other' processed token. |
| 11741 |
% \begin{macrocode} |
| 11742 |
%<*misc> |
| 11743 |
\lst@BeginAspect[keywords]{tex} |
| 11744 |
% \end{macrocode} |
| 11745 |
% \begin{macrocode} |
| 11746 |
\lst@InstallFamily {cs}{texcs}{texcsstyle}\relax{keywordstyle} |
| 11747 |
{\ifx\lst@lastother\lstum@backslash |
| 11748 |
\expandafter\let\expandafter\lst@thestyle |
| 11749 |
\csname lst@texcsstyle#1\endcsname |
| 11750 |
\fi} |
| 11751 |
ld |
| 11752 |
% \end{macrocode} |
| 11753 |
% The style-key checks for the optional star (which must be in front of |
| 11754 |
% the optional class argument). |
| 11755 |
% \begin{macrocode} |
| 11756 |
\lst@Key{texcsstyle}\relax |
| 11757 |
{\@ifstar{\lst@true\lst@DefTexcsstyle}% |
| 11758 |
{\lst@false\lst@DefTexcsstyle}#1\@nil@} |
| 11759 |
\gdef\lst@DefTexcsstyle#1\@nil@{% |
| 11760 |
\let\lst@iftexcsincludebs\lst@if |
| 11761 |
\lstKV@OptArg[\@ne]{#1}% |
| 11762 |
{\@tempcnta\lst@classoffset \advance\@tempcnta##1\relax |
| 11763 |
\@namedef{lst@texcsstyle\ifnum\@tempcnta=\@ne\else |
| 11764 |
\the\@tempcnta \fi}{##2}}}% |
| 11765 |
\global\let\lst@iftexcsincludebs\iffalse |
| 11766 |
% \end{macrocode} |
| 11767 |
% To make the backslash belong to the control sequence, it is merged with |
| 11768 |
% the following token. This option was suggested by \lsthelper{Morten~H\o gholm} |
| 11769 |
% {2004/07/16}{defining new (colored) texcs}. |
| 11770 |
% \lsthelper{Christian~Schneider}{2006/09/08}{-} pointed out that the original |
| 11771 |
% implementation was broken when the identifier was preceded by an ``other'' |
| 11772 |
% character. To fix this (and other bugs), we first output whatever is in the |
| 11773 |
% current token before merging. |
| 11774 |
% \begin{macrocode} |
| 11775 |
\let\lst@iftexcsincludebs\iffalse |
| 11776 |
\lst@AddToHook{SelectCharTable} |
| 11777 |
{\lst@iftexcsincludebs \ifx\@empty\lst@texcs\else |
| 11778 |
\lst@DefSaveDef{`\\}\lsts@texcsbs |
| 11779 |
{\lst@ifletter |
| 11780 |
\lst@Output |
| 11781 |
\else |
| 11782 |
\lst@OutputOther |
| 11783 |
\fi |
| 11784 |
\lst@Merge\lsts@texcsbs}% |
| 11785 |
\fi \fi} |
| 11786 |
% \end{macrocode} |
| 11787 |
% \begin{macrocode} |
| 11788 |
\lst@EndAspect |
| 11789 |
%</misc> |
| 11790 |
% \end{macrocode} |
| 11791 |
% \end{aspect} |
| 11792 |
% |
| 11793 |
% |
| 11794 |
% \paragraph{Compiler directives} |
| 11795 |
% |
| 11796 |
% \begin{aspect}{directives} |
| 11797 |
% \begin{lstkey}{directives} |
| 11798 |
% First some usual stuff. |
| 11799 |
% \begin{macrocode} |
| 11800 |
%<*misc> |
| 11801 |
\lst@BeginAspect[keywords]{directives} |
| 11802 |
% \end{macrocode} |
| 11803 |
% The initialization of |\lst@directives| has been added after a bug report |
| 11804 |
% from \lsthelper{Kris~Luyten}{2002/07/30}{Undefined control sequence |
| 11805 |
% \lst@thestyle caused by undefined \lst@directives after loading C}. |
| 11806 |
% \begin{macrocode} |
| 11807 |
\lst@NewMode\lst@CDmode |
| 11808 |
\lst@AddToHook{EOL}{\ifnum\lst@mode=\lst@CDmode \lst@LeaveMode \fi} |
| 11809 |
\lst@InstallKeywords{d}{directives}{directivestyle}\relax{keywordstyle} |
| 11810 |
{\ifnum\lst@mode=\lst@CDmode |
| 11811 |
\let\lst@thestyle\lst@directivestyle |
| 11812 |
\fi} |
| 11813 |
ld |
| 11814 |
\global\let\lst@directives\@empty % init |
| 11815 |
% \end{macrocode} |
| 11816 |
% Now we define a new delimiter for directives: We enter `directive mode' |
| 11817 |
% only in the first column. |
| 11818 |
% \begin{macrocode} |
| 11819 |
\lst@AddTo\lst@delimtypes{,directive} |
| 11820 |
\gdef\lst@Delim@directive#1\@empty#2#3#4{% |
| 11821 |
\lst@CArg #1\relax\lst@DefDelimB |
| 11822 |
{\lst@CalcColumn}% |
| 11823 |
{}% |
| 11824 |
{\ifnum\@tempcnta=\z@ |
| 11825 |
\def\lst@bnext{#2\lst@CDmode{#4\lst@Lmodetrue}% |
| 11826 |
\let\lst@currstyle\lst@directivestyle}% |
| 11827 |
\fi |
| 11828 |
\@gobblethree}% |
| 11829 |
#2\lst@CDmode{#4\lst@Lmodetrue}} |
| 11830 |
% \end{macrocode} |
| 11831 |
% We introduce a new string type (thanks to \lsthelper{R.~Isernhagen} |
| 11832 |
% {1999/11/12}{float isn't keyword in #include <float>}), which \ldots |
| 11833 |
% \begin{macrocode} |
| 11834 |
\lst@AddTo\lst@stringtypes{,directive} |
| 11835 |
\gdef\lst@StringDM@directive#1#2#3\@empty{% |
| 11836 |
\lst@CArg #2\relax\lst@CDef |
| 11837 |
{}% |
| 11838 |
% \end{macrocode} |
| 11839 |
% \ldots\space is active only in |\lst@CDmode|: |
| 11840 |
% \begin{macrocode} |
| 11841 |
{\let\lst@bnext\lst@CArgEmpty |
| 11842 |
\ifnum\lst@mode=\lst@CDmode |
| 11843 |
\def\lst@bnext{\lst@BeginString{#1}}% |
| 11844 |
\fi |
| 11845 |
\lst@bnext}% |
| 11846 |
\@empty |
| 11847 |
\lst@CArg #3\relax\lst@CDef |
| 11848 |
{}% |
| 11849 |
{\let\lst@enext\lst@CArgEmpty |
| 11850 |
\ifnum #1=\lst@mode |
| 11851 |
\let\lst@bnext\lst@EndString |
| 11852 |
\fi |
| 11853 |
\lst@bnext}% |
| 11854 |
\@empty} |
| 11855 |
% \end{macrocode} |
| 11856 |
% \end{lstkey} |
| 11857 |
% |
| 11858 |
% \begin{macrocode} |
| 11859 |
\lst@EndAspect |
| 11860 |
%</misc> |
| 11861 |
% \end{macrocode} |
| 11862 |
% \end{aspect} |
| 11863 |
% |
| 11864 |
% |
| 11865 |
% \subsection{Keyword comments} |
| 11866 |
% |
| 11867 |
% \begin{aspect}{keywordcomments} |
| 11868 |
% includes both comment types and is possibly split into this and |dkcs|. |
| 11869 |
% \begin{macrocode} |
| 11870 |
%<*misc> |
| 11871 |
\lst@BeginAspect[keywords,comments]{keywordcomments} |
| 11872 |
% \end{macrocode} |
| 11873 |
% |
| 11874 |
% \begin{macro}{\lst@BeginKC} |
| 11875 |
% \begin{macro}{\lst@BeginKCS} |
| 11876 |
% Starting a keyword comment is easy, but: (1) The submacros are called |
| 11877 |
% outside of two group levels, and \ldots |
| 11878 |
% \begin{macrocode} |
| 11879 |
\lst@NewMode\lst@KCmode \lst@NewMode\lst@KCSmode |
| 11880 |
\gdef\lst@BeginKC{\aftergroup\aftergroup\aftergroup\lst@BeginKC@}% |
| 11881 |
\gdef\lst@BeginKC@{% |
| 11882 |
\lst@ResetToken |
| 11883 |
\lst@BeginComment\lst@KCmode{{\lst@commentstyle}\lst@modetrue}% |
| 11884 |
\@empty}% |
| 11885 |
\gdef\lst@BeginKCS{\aftergroup\aftergroup\aftergroup\lst@BeginKCS@}% |
| 11886 |
\gdef\lst@BeginKCS@{% |
| 11887 |
\lst@ResetToken |
| 11888 |
\lst@BeginComment\lst@KCSmode{{\lst@commentstyle}\lst@modetrue}% |
| 11889 |
\@empty}% |
| 11890 |
% \end{macrocode} |
| 11891 |
% (2) we must ensure that the comment starts after printing the comment |
| 11892 |
% delimiter since it could be a keyword. We assign |\lst@BeginKC|[|S|] to |
| 11893 |
% |\lst@KCpost|, which is executed and reset in \hookname{PostOutput}. |
| 11894 |
% \begin{macrocode} |
| 11895 |
\lst@AddToHook{PostOutput}{\lst@KCpost \global\let\lst@KCpost\@empty} |
| 11896 |
\global\let\lst@KCpost\@empty % init |
| 11897 |
% \end{macrocode} |
| 11898 |
% \end{macro} |
| 11899 |
% \end{macro} |
| 11900 |
% |
| 11901 |
% \begin{macro}{\lst@EndKC} |
| 11902 |
% leaves the comment mode before the (temporaryly saved) comment delimiter is |
| 11903 |
% printed. |
| 11904 |
% \begin{macrocode} |
| 11905 |
\gdef\lst@EndKC{\lst@SaveToken \lst@LeaveMode \lst@RestoreToken |
| 11906 |
\let\lst@thestyle\lst@identifierstyle \lsthk@Output} |
| 11907 |
% \end{macrocode} |
| 11908 |
% \end{macro} |
| 11909 |
% |
| 11910 |
% \begin{lstkey}{keywordcomment} |
| 11911 |
% The delimiters must be identical here, thus we use |\lst@KCmatch|. Note the |
| 11912 |
% last argument |o| to |\lst@InstallKeywords|: The working test is installed |
| 11913 |
% in the \hookname{Output} hook and not in \hookname{DetectKeywords}. |
| 11914 |
% Otherwise we couldn't detect the ending delimiter since keyword detection is |
| 11915 |
% done if and only if mode changes are allowed. |
| 11916 |
% \begin{macrocode} |
| 11917 |
\lst@InstallKeywords{kc}{keywordcomment}{}\relax{} |
| 11918 |
{\ifnum\lst@mode=\lst@KCmode |
| 11919 |
\edef\lst@temp{\the\lst@token}% |
| 11920 |
\ifx\lst@temp\lst@KCmatch |
| 11921 |
\lst@EndKC |
| 11922 |
\fi |
| 11923 |
\else |
| 11924 |
\lst@ifmode\else |
| 11925 |
\xdef\lst@KCmatch{\the\lst@token}% |
| 11926 |
\global\let\lst@KCpost\lst@BeginKC |
| 11927 |
\fi |
| 11928 |
\fi} |
| 11929 |
lo |
| 11930 |
% \end{macrocode} |
| 11931 |
% \end{lstkey} |
| 11932 |
% |
| 11933 |
% \begin{lstkey}{keywordcommentsemicolon} |
| 11934 |
% The key simply stores the keywords. After a bug report by \lsthelper |
| 11935 |
% {Norbert~Eisinger}{2002/11/26}{keywordcommentsemicolon active after |
| 11936 |
% language change} the initialization in \hookname{SetLanguage} has been |
| 11937 |
% added. |
| 11938 |
% \begin{macrocode} |
| 11939 |
\lst@Key{keywordcommentsemicolon}{}{\lstKV@ThreeArg{#1}% |
| 11940 |
{\def\lst@KCAkeywordsB{##1}% |
| 11941 |
\def\lst@KCAkeywordsE{##2}% |
| 11942 |
\def\lst@KCBkeywordsB{##3}% |
| 11943 |
\def\lst@KCkeywords{##1##2##3}}} |
| 11944 |
\lst@AddToHook{SetLanguage}{% |
| 11945 |
\let\lst@KCAkeywordsB\@empty \let\lst@KCAkeywordsE\@empty |
| 11946 |
\let\lst@KCBkeywordsB\@empty \let\lst@KCkeywords\@empty} |
| 11947 |
% \end{macrocode} |
| 11948 |
% We define an appropriate semicolon if this keyword comment type is defined. |
| 11949 |
% Appropriate means that we leave any keyword comment mode if active. |
| 11950 |
% \lsthelper{Oldrich~Jedlicka}{2001/12/12}{keywordcomment(semicolon) fails} |
| 11951 |
% reported a bug and provided the fix, the two |\@empty|s. |
| 11952 |
% \begin{macrocode} |
| 11953 |
\lst@AddToHook{SelectCharTable} |
| 11954 |
{\ifx\lst@KCkeywords\@empty\else |
| 11955 |
\lst@DefSaveDef{`\;}\lsts@EKC |
| 11956 |
{\lst@XPrintToken |
| 11957 |
\ifnum\lst@mode=\lst@KCmode \lst@EndComment\@empty \else |
| 11958 |
\ifnum\lst@mode=\lst@KCSmode \lst@EndComment\@empty |
| 11959 |
\fi \fi |
| 11960 |
\lsts@EKC}% |
| 11961 |
\fi} |
| 11962 |
% \end{macrocode} |
| 11963 |
% The `working identifier' macros enter respectively leave comment mode. |
| 11964 |
% \begin{macrocode} |
| 11965 |
\gdef\lst@KCAWorkB{% |
| 11966 |
\lst@ifmode\else \global\let\lst@KCpost\lst@BeginKC \fi} |
| 11967 |
\gdef\lst@KCBWorkB{% |
| 11968 |
\lst@ifmode\else \global\let\lst@KCpost\lst@BeginKCS \fi} |
| 11969 |
\gdef\lst@KCAWorkE{\ifnum\lst@mode=\lst@KCmode \lst@EndKC \fi} |
| 11970 |
% \end{macrocode} |
| 11971 |
% Now we install the tests and initialize the given macros. |
| 11972 |
% \begin{macrocode} |
| 11973 |
\lst@ProvideFamily@@ |
| 11974 |
\lst@KCAkeywordsB@list\lst@KCAkeywordsB \lst@KC@also |
| 11975 |
\lst@gKCAkeywordsB@list\lst@gKCAkeywordsB \lst@KCAWorkB |
| 11976 |
{kcb}owo % prefix, other key, working procedure, Output hook |
| 11977 |
\lst@ProvideFamily@@ |
| 11978 |
\lst@KCAkeywordsE@list\lst@KCAkeywordsE \lst@KC@also |
| 11979 |
\lst@gKCAkeywordsE@list\lst@gKCAkeywordsE \lst@KCAWorkE |
| 11980 |
{kce}owo |
| 11981 |
\lst@ProvideFamily@@ |
| 11982 |
\lst@KCBkeywordsB@list\lst@KCBkeywordsB \lst@KC@also |
| 11983 |
\lst@gKCBkeywordsB@list\lst@gKCBkeywordsB \lst@KCBWorkB |
| 11984 |
{kcs}owo |
| 11985 |
% \end{macrocode} |
| 11986 |
% \end{lstkey} |
| 11987 |
% |
| 11988 |
% \begin{macrocode} |
| 11989 |
\lst@EndAspect |
| 11990 |
%</misc> |
| 11991 |
% \end{macrocode} |
| 11992 |
% \end{aspect} |
| 11993 |
% |
| 11994 |
% |
| 11995 |
% \subsection{Export of identifiers} |
| 11996 |
% |
| 11997 |
% \begin{aspect}{index} |
| 11998 |
% \begin{macro}{\lstindexmacro} |
| 11999 |
% One more `keyword' class. |
| 12000 |
% \begin{macrocode} |
| 12001 |
%<*misc> |
| 12002 |
\lst@BeginAspect[keywords]{index} |
| 12003 |
\lst@InstallFamily w{index}{indexstyle}\lstindexmacro{indexstyle} |
| 12004 |
{\csname\@lst @indexstyle#1\expandafter\endcsname |
| 12005 |
\expandafter{\the\lst@token}} |
| 12006 |
od |
| 12007 |
\lst@UserCommand\lstindexmacro#1{\index{{\ttfamily#1}}} |
| 12008 |
\lst@EndAspect |
| 12009 |
%</misc> |
| 12010 |
% \end{macrocode} |
| 12011 |
% \end{macro} |
| 12012 |
% \end{aspect} |
| 12013 |
% |
| 12014 |
% \begin{aspect}{procnames} |
| 12015 |
% \begin{lstkey}{procnamestyle} |
| 12016 |
% \begin{lstkey}{procnamekeys} |
| 12017 |
% \begin{lstkey}{indexprocnames} |
| 12018 |
% The `idea' here is the usage of a global |\lst@ifprocname|, indicating a |
| 12019 |
% preceding `procedure keyword'. All the other is known stuff. |
| 12020 |
% \begin{macrocode} |
| 12021 |
%<*misc> |
| 12022 |
\lst@BeginAspect[keywords]{procnames} |
| 12023 |
\gdef\lst@procnametrue{\global\let\lst@ifprocname\iftrue} |
| 12024 |
\gdef\lst@procnamefalse{\global\let\lst@ifprocname\iffalse} |
| 12025 |
\lst@AddToHook{Init}{\lst@procnamefalse} |
| 12026 |
\lst@AddToHook{DetectKeywords} |
| 12027 |
{\lst@ifprocname |
| 12028 |
\let\lst@thestyle\lst@procnamestyle |
| 12029 |
\lst@ifindexproc \csname\@lst @gindex@sty\endcsname \fi |
| 12030 |
\lst@procnamefalse |
| 12031 |
\fi} |
| 12032 |
% \end{macrocode} |
| 12033 |
% And these are the two implemented keys: |
| 12034 |
% \begin{macrocode} |
| 12035 |
\lst@Key{procnamestyle}{}{\def\lst@procnamestyle{#1}} |
| 12036 |
\lst@Key{indexprocnames}{false}[t]{\lstKV@SetIf{#1}\lst@ifindexproc} |
| 12037 |
\lst@AddToHook{Init}{\lst@ifindexproc \lst@indexproc \fi} |
| 12038 |
\gdef\lst@indexproc{% |
| 12039 |
\@ifundefined{lst@indexstyle1}% |
| 12040 |
{\@namedef{lst@indexstyle1}##1{}}% |
| 12041 |
{}} |
| 12042 |
% \end{macrocode} |
| 12043 |
% The default definition of |\lst@indexstyle| above has been moved outside the |
| 12044 |
% hook after a bug report from \lsthelper{Ulrich~G.~Wortmann}{2002/01/22} |
| 12045 |
% {procnames doesn't work}. |
| 12046 |
% \begin{macrocode} |
| 12047 |
\lst@InstallKeywords w{procnamekeys}{}\relax{} |
| 12048 |
{\global\let\lst@PNpost\lst@procnametrue} |
| 12049 |
od |
| 12050 |
\lst@AddToHook{PostOutput}{\lst@PNpost\global\let\lst@PNpost\@empty} |
| 12051 |
\global\let\lst@PNpost\@empty % init |
| 12052 |
\lst@EndAspect |
| 12053 |
%</misc> |
| 12054 |
% \end{macrocode} |
| 12055 |
% \end{lstkey} |
| 12056 |
% \end{lstkey} |
| 12057 |
% \end{lstkey} |
| 12058 |
% \end{aspect} |
| 12059 |
% |
| 12060 |
% |
| 12061 |
% \section{More aspects and keys} |
| 12062 |
% |
| 12063 |
% \begin{lstkey}{basicstyle} |
| 12064 |
% \begin{lstkey}{inputencoding} |
| 12065 |
% There is no better place to define these keys, I think. |
| 12066 |
% \begin{macrocode} |
| 12067 |
%<*kernel> |
| 12068 |
\lst@Key{basicstyle}\relax{\def\lst@basicstyle{#1}} |
| 12069 |
\lst@Key{inputencoding}\relax{\def\lst@inputenc{#1}} |
| 12070 |
\lst@AddToHook{Init} |
| 12071 |
{\lst@basicstyle |
| 12072 |
\ifx\lst@inputenc\@empty\else |
| 12073 |
\@ifundefined{inputencoding}{}% |
| 12074 |
{\inputencoding\lst@inputenc}% |
| 12075 |
\fi} |
| 12076 |
\lst@AddToHookExe{EmptyStyle} |
| 12077 |
{\let\lst@basicstyle\@empty |
| 12078 |
\let\lst@inputenc\@empty} |
| 12079 |
\lst@Key{multicols}{}{\@tempcnta=0#1\relax\def\lst@multicols{#1}} |
| 12080 |
%</kernel> |
| 12081 |
% \end{macrocode} |
| 12082 |
% Michael Niedermair asked for a key like \keyname{inputencoding}. |
| 12083 |
% \end{lstkey} |
| 12084 |
% \end{lstkey} |
| 12085 |
% |
| 12086 |
% |
| 12087 |
% \subsection{Styles and languages} |
| 12088 |
% |
| 12089 |
% \begin{aspect}{style} |
| 12090 |
% We begin with style definition and selection. |
| 12091 |
% \begin{macrocode} |
| 12092 |
%<*misc> |
| 12093 |
\lst@BeginAspect{style} |
| 12094 |
% \end{macrocode} |
| 12095 |
% |
| 12096 |
% \begin{macro}{\lststylefiles} |
| 12097 |
% This macro is defined if and only if it's undefined yet. |
| 12098 |
% \begin{macrocode} |
| 12099 |
\@ifundefined{lststylefiles} |
| 12100 |
{\lst@UserCommand\lststylefiles{lststy0.sty}}{} |
| 12101 |
% \end{macrocode} |
| 12102 |
% \end{macro} |
| 12103 |
% |
| 12104 |
% \begin{macro}{\lstdefinestyle} |
| 12105 |
% \begin{macro}{\lst@definestyle} |
| 12106 |
% \begin{macro}{\lst@DefStyle} |
| 12107 |
% are defined in terms of |\lst@DefStyle|, which is defined via |
| 12108 |
% |\lst@DefDriver|. |
| 12109 |
% \begin{macrocode} |
| 12110 |
\lst@UserCommand\lstdefinestyle{\lst@DefStyle\iftrue} |
| 12111 |
\lst@UserCommand\lst@definestyle{\lst@DefStyle\iffalse} |
| 12112 |
\gdef\lst@DefStyle{\lst@DefDriver{style}{sty}\lstset} |
| 12113 |
% \end{macrocode} |
| 12114 |
% The `empty' style calls the initial empty hook \hookname{EmptyStyle}. |
| 12115 |
% \begin{macrocode} |
| 12116 |
\global\@namedef{lststy@$}{\lsthk@EmptyStyle} |
| 12117 |
\lst@AddToHook{EmptyStyle}{}% init |
| 12118 |
% \end{macrocode} |
| 12119 |
% \end{macro} |
| 12120 |
% \end{macro} |
| 12121 |
% \end{macro} |
| 12122 |
% |
| 12123 |
% \begin{lstkey}{style} |
| 12124 |
% is an application of |\lst@LAS|. We just specify the hook and an empty |
| 12125 |
% argument as `pre' and `post' code. |
| 12126 |
% \begin{macrocode} |
| 12127 |
\lst@Key{style}\relax{% |
| 12128 |
\lst@LAS{style}{sty}{[]{#1}}\lst@NoAlias\lststylefiles |
| 12129 |
\lsthk@SetStyle |
| 12130 |
{}} |
| 12131 |
% \end{macrocode} |
| 12132 |
% \begin{macrocode} |
| 12133 |
\lst@AddToHook{SetStyle}{}% init |
| 12134 |
% \end{macrocode} |
| 12135 |
% \end{lstkey} |
| 12136 |
% |
| 12137 |
% \begin{macrocode} |
| 12138 |
\lst@EndAspect |
| 12139 |
%</misc> |
| 12140 |
% \end{macrocode} |
| 12141 |
% \end{aspect} |
| 12142 |
% |
| 12143 |
% \begin{aspect}{language} |
| 12144 |
% Now we deal with commands used in defining and selecting programming |
| 12145 |
% languages, in particular with aliases. |
| 12146 |
% \begin{macrocode} |
| 12147 |
%<*misc> |
| 12148 |
\lst@BeginAspect{language} |
| 12149 |
% \end{macrocode} |
| 12150 |
% |
| 12151 |
% \begin{macro}{\lstlanguagefiles} |
| 12152 |
% This macro is defined if and only if it's undefined yet. |
| 12153 |
% \begin{macrocode} |
| 12154 |
\@ifundefined{lstdriverfiles} |
| 12155 |
{\lst@UserCommand\lstlanguagefiles{lstlang0.sty}}{} |
| 12156 |
% \end{macrocode} |
| 12157 |
% \end{macro} |
| 12158 |
% |
| 12159 |
% \begin{macro}{\lstdefinelanguage} |
| 12160 |
% \begin{macro}{\lst@definelanguage} |
| 12161 |
% \begin{macro}{\lst@DefLang} |
| 12162 |
% are defined in terms of |\lst@DefLang|, which is defined via |
| 12163 |
% |\lst@DefDriver|. |
| 12164 |
% \begin{macrocode} |
| 12165 |
\lst@UserCommand\lstdefinelanguage{\lst@DefLang\iftrue} |
| 12166 |
\lst@UserCommand\lst@definelanguage{\lst@DefLang\iffalse} |
| 12167 |
\gdef\lst@DefLang{\lst@DefDriver{language}{lang}\lstset} |
| 12168 |
% \end{macrocode} |
| 12169 |
% Now we can provide the `empty' language. |
| 12170 |
% \begin{macrocode} |
| 12171 |
\lstdefinelanguage{}{} |
| 12172 |
% \end{macrocode} |
| 12173 |
% \end{macro} |
| 12174 |
% \end{macro} |
| 12175 |
% \end{macro} |
| 12176 |
% |
| 12177 |
% \begin{lstkey}{language} |
| 12178 |
% \begin{lstkey}{alsolanguage} |
| 12179 |
% is mainly an application of |\lst@LAS|. |
| 12180 |
% \begin{macrocode} |
| 12181 |
\lst@Key{language}\relax{\lstKV@OptArg[]{#1}% |
| 12182 |
{\lst@LAS{language}{lang}{[##1]{##2}}\lst@FindAlias\lstlanguagefiles |
| 12183 |
\lsthk@SetLanguage |
| 12184 |
{\lst@FindAlias[##1]{##2}% |
| 12185 |
\let\lst@language\lst@malias |
| 12186 |
\let\lst@dialect\lst@oalias}}} |
| 12187 |
% \end{macrocode} |
| 12188 |
% Ditto, we simply don't execute |\lsthk@SetLanguage|. |
| 12189 |
% \begin{macrocode} |
| 12190 |
\lst@Key{alsolanguage}\relax{\lstKV@OptArg[]{#1}% |
| 12191 |
{\lst@LAS{language}{lang}{[##1]{##2}}\lst@FindAlias\lstlanguagefiles |
| 12192 |
{}% |
| 12193 |
{\lst@FindAlias[##1]{##2}% |
| 12194 |
\let\lst@language\lst@malias |
| 12195 |
\let\lst@dialect\lst@oalias}}} |
| 12196 |
% \end{macrocode} |
| 12197 |
% \begin{macrocode} |
| 12198 |
\lst@AddToHook{SetLanguage}{}% init |
| 12199 |
% \end{macrocode} |
| 12200 |
% \end{lstkey} |
| 12201 |
% \end{lstkey} |
| 12202 |
% |
| 12203 |
% \begin{macro}{\lstalias} |
| 12204 |
% Now we concentrate on aliases and default dialects. |
| 12205 |
% |\lsta@|\meta{language}|$|\meta{dialect} and |\lsta@|\meta{language} contain |
| 12206 |
% the aliases of a particular dialect respectively a complete language. |
| 12207 |
% We'll use a |$|-character to separate a language name from its dialect. |
| 12208 |
% Thanks to \lsthelper{Walter~E.~Brown}{2004/02/25}{\lstalias |
| 12209 |
% (+\lstdefinelanguage) fails} for reporting a problem with the argument |
| 12210 |
% delimiter `[' in a previous definition of |\lstalias@|. |
| 12211 |
% \begin{macrocode} |
| 12212 |
\lst@UserCommand\lstalias{\@ifnextchar[\lstalias@\lstalias@@} |
| 12213 |
\gdef\lstalias@[#1]#2{\lstalias@b #2$#1} |
| 12214 |
\gdef\lstalias@b#1[#2]#3{\lst@NormedNameDef{lsta@#1}{#3$#2}} |
| 12215 |
\gdef\lstalias@@#1#2{\lst@NormedNameDef{lsta@#1}{#2}} |
| 12216 |
% \end{macrocode} |
| 12217 |
% \end{macro} |
| 12218 |
% |
| 12219 |
% \begin{lstkey}{defaultdialect} |
| 12220 |
% We simply store the dialect. |
| 12221 |
% \begin{macrocode} |
| 12222 |
\lst@Key{defaultdialect}\relax |
| 12223 |
{\lstKV@OptArg[]{#1}{\lst@NormedNameDef{lstdd@##2}{##1}}} |
| 12224 |
% \end{macrocode} |
| 12225 |
% \end{lstkey} |
| 12226 |
% |
| 12227 |
% \begin{macro}{\lst@FindAlias} |
| 12228 |
% Now we have to find a language. First we test for a complete language alias, |
| 12229 |
% then we set the default dialect if necessary. |
| 12230 |
% \begin{macrocode} |
| 12231 |
\gdef\lst@FindAlias[#1]#2{% |
| 12232 |
\lst@NormedDef\lst@oalias{#1}% |
| 12233 |
\lst@NormedDef\lst@malias{#2}% |
| 12234 |
\@ifundefined{lsta@\lst@malias}{}% |
| 12235 |
{\edef\lst@malias{\csname\@lst a@\lst@malias\endcsname}}% |
| 12236 |
% \end{macrocode} |
| 12237 |
% \begin{macrocode} |
| 12238 |
\ifx\@empty\lst@oalias \@ifundefined{lstdd@\lst@malias}{}% |
| 12239 |
{\edef\lst@oalias{\csname\@lst dd@\lst@malias\endcsname}}% |
| 12240 |
\fi |
| 12241 |
% \end{macrocode} |
| 12242 |
% Now we are ready for an alias of a single dialect. |
| 12243 |
% \begin{macrocode} |
| 12244 |
\edef\lst@temp{\lst@malias $\lst@oalias}% |
| 12245 |
\@ifundefined{lsta@\lst@temp}{}% |
| 12246 |
{\edef\lst@temp{\csname\@lst a@\lst@temp\endcsname}}% |
| 12247 |
% \end{macrocode} |
| 12248 |
% Finally we again set the default dialect---for the case of a dialect alias. |
| 12249 |
% \begin{macrocode} |
| 12250 |
\expandafter\lst@FindAlias@\lst@temp $} |
| 12251 |
\gdef\lst@FindAlias@#1$#2${% |
| 12252 |
\def\lst@malias{#1}\def\lst@oalias{#2}% |
| 12253 |
\ifx\@empty\lst@oalias \@ifundefined{lstdd@\lst@malias}{}% |
| 12254 |
{\edef\lst@oalias{\csname\@lst dd@\lst@malias\endcsname}}% |
| 12255 |
\fi} |
| 12256 |
% \end{macrocode} |
| 12257 |
% \end{macro} |
| 12258 |
% |
| 12259 |
% \begin{macro}{\lst@RequireLanguages} |
| 12260 |
% This definition will be equivalent to |\lstloadlanguages|. We requested the |
| 12261 |
% given list of languages and load additionally required aspects. |
| 12262 |
% \begin{macrocode} |
| 12263 |
\gdef\lst@RequireLanguages#1{% |
| 12264 |
\lst@Require{language}{lang}{#1}\lst@FindAlias\lstlanguagefiles |
| 12265 |
\ifx\lst@loadaspects\@empty\else |
| 12266 |
\lst@RequireAspects\lst@loadaspects |
| 12267 |
\fi} |
| 12268 |
% \end{macrocode} |
| 12269 |
% \end{macro} |
| 12270 |
% |
| 12271 |
% \begin{macro}{\lstloadlanguages} |
| 12272 |
% is the same as |\lst@RequireLanguages|. |
| 12273 |
% \begin{macrocode} |
| 12274 |
\global\let\lstloadlanguages\lst@RequireLanguages |
| 12275 |
% \end{macrocode} |
| 12276 |
% \end{macro} |
| 12277 |
% |
| 12278 |
% \begin{macrocode} |
| 12279 |
\lst@EndAspect |
| 12280 |
%</misc> |
| 12281 |
% \end{macrocode} |
| 12282 |
% \end{aspect} |
| 12283 |
% |
| 12284 |
% |
| 12285 |
% \subsection{Format definitions*} |
| 12286 |
% |
| 12287 |
% \begin{aspect}{formats} |
| 12288 |
% \begin{macrocode} |
| 12289 |
%<*misc> |
| 12290 |
\lst@BeginAspect{formats} |
| 12291 |
% \end{macrocode} |
| 12292 |
% |
| 12293 |
% \begin{macro}{\lstformatfiles} |
| 12294 |
% This macro is defined if and only if it's undefined yet. |
| 12295 |
% \begin{macrocode} |
| 12296 |
\@ifundefined{lstformatfiles} |
| 12297 |
{\lst@UserCommand\lstformatfiles{lstfmt0.sty}}{} |
| 12298 |
% \end{macrocode} |
| 12299 |
% \end{macro} |
| 12300 |
% |
| 12301 |
% \begin{macro}{\lstdefineformat} |
| 12302 |
% \begin{macro}{\lst@defineformat} |
| 12303 |
% \begin{macro}{\lst@DefFormat} |
| 12304 |
% are defined in terms of |\lst@DefFormat|, which is defined via |
| 12305 |
% |\lst@DefDriver|. |
| 12306 |
% \begin{macrocode} |
| 12307 |
\lst@UserCommand\lstdefineformat{\lst@DefFormat\iftrue} |
| 12308 |
\lst@UserCommand\lst@defineformat{\lst@DefFormat\iffalse} |
| 12309 |
\gdef\lst@DefFormat{\lst@DefDriver{format}{fmt}\lst@UseFormat} |
| 12310 |
% \end{macrocode} |
| 12311 |
% We provide the `empty' format. |
| 12312 |
% \begin{macrocode} |
| 12313 |
\lstdefineformat{}{} |
| 12314 |
% \end{macrocode} |
| 12315 |
% \end{macro} |
| 12316 |
% \end{macro} |
| 12317 |
% \end{macro} |
| 12318 |
% |
| 12319 |
% \begin{lstkey}{format} |
| 12320 |
% is an application of |\lst@LAS|. We just specify the hook as `pre' and an |
| 12321 |
% empty argument as `post' code. |
| 12322 |
% \begin{macrocode} |
| 12323 |
\lst@Key{format}\relax{% |
| 12324 |
\lst@LAS{format}{fmt}{[]{#1}}\lst@NoAlias\lstformatfiles |
| 12325 |
\lsthk@SetFormat |
| 12326 |
{}} |
| 12327 |
% \end{macrocode} |
| 12328 |
% \begin{macrocode} |
| 12329 |
\lst@AddToHook{SetFormat}{\let\lst@fmtformat\@empty}% init |
| 12330 |
% \end{macrocode} |
| 12331 |
% \end{lstkey} |
| 12332 |
% |
| 12333 |
% |
| 12334 |
% \paragraph{Helpers} |
| 12335 |
% Our goal is to define the yet unkown |\lst@UseFormat|. This definition |
| 12336 |
% will parse the user supplied format. We start with some general macros. |
| 12337 |
% |
| 12338 |
% \begin{macro}{\lst@fmtSplit} |
| 12339 |
% splits the content of the macro |#1| at |#2| in the preceding characters |
| 12340 |
% |\lst@fmta| and the following ones |\lst@fmtb|. |\lst@if| is false if and |
| 12341 |
% only if |#1| doesn't contain |#2|. |
| 12342 |
% \begin{macrocode} |
| 12343 |
\gdef\lst@fmtSplit#1#2{% |
| 12344 |
\def\lst@temp##1#2##2\relax##3{% |
| 12345 |
\ifnum##3=\z@ |
| 12346 |
\ifx\@empty##2\@empty |
| 12347 |
\lst@false |
| 12348 |
\let\lst@fmta#1% |
| 12349 |
\let\lst@fmtb\@empty |
| 12350 |
\else |
| 12351 |
\expandafter\lst@temp#1\relax\@ne |
| 12352 |
\fi |
| 12353 |
\else |
| 12354 |
\def\lst@fmta{##1}\def\lst@fmtb{##2}% |
| 12355 |
\fi}% |
| 12356 |
\lst@true |
| 12357 |
\expandafter\lst@temp#1#2\relax\z@} |
| 12358 |
% \end{macrocode} |
| 12359 |
% \end{macro} |
| 12360 |
% |
| 12361 |
% \begin{macro}{\lst@IfNextCharWhitespace} |
| 12362 |
% is defined in terms of |\lst@IfSubstring|. |
| 12363 |
% \begin{macrocode} |
| 12364 |
\gdef\lst@IfNextCharWhitespace#1#2#3{% |
| 12365 |
\lst@IfSubstring#3\lst@whitespaces{#1}{#2}#3} |
| 12366 |
% \end{macrocode} |
| 12367 |
% And here come all white space characters. |
| 12368 |
% \begin{macrocode} |
| 12369 |
\begingroup |
| 12370 |
\catcode`\^^I=12\catcode`\^^J=12\catcode`\^^M=12\catcode`\^^L=12\relax% |
| 12371 |
\lst@DefActive\lst@whitespaces{\ ^^I^^J^^M}% add ^^L |
| 12372 |
\global\let\lst@whitespaces\lst@whitespaces% |
| 12373 |
\endgroup |
| 12374 |
% \end{macrocode} |
| 12375 |
% \end{macro} |
| 12376 |
% |
| 12377 |
% \begin{macro}{\lst@fmtIfIdentifier} |
| 12378 |
% tests the first character of |#1| |
| 12379 |
% \begin{macrocode} |
| 12380 |
\gdef\lst@fmtIfIdentifier#1{% |
| 12381 |
\ifx\relax#1\@empty |
| 12382 |
\expandafter\@secondoftwo |
| 12383 |
\else |
| 12384 |
\expandafter\lst@fmtIfIdentifier@\expandafter#1% |
| 12385 |
\fi} |
| 12386 |
% \end{macrocode} |
| 12387 |
% against the `letters' |_|, |@|, |A|,\ldots,|Z| and |a|,\ldots,|z|. |
| 12388 |
% \begin{macrocode} |
| 12389 |
\gdef\lst@fmtIfIdentifier@#1#2\relax{% |
| 12390 |
\let\lst@next\@secondoftwo |
| 12391 |
\ifnum`#1=`_\else |
| 12392 |
\ifnum`#1<64\else |
| 12393 |
\ifnum`#1<91\let\lst@next\@firstoftwo\else |
| 12394 |
\ifnum`#1<97\else |
| 12395 |
\ifnum`#1<123\let\lst@next\@firstoftwo\else |
| 12396 |
\fi \fi \fi \fi \fi |
| 12397 |
\lst@next} |
| 12398 |
% \end{macrocode} |
| 12399 |
% \end{macro} |
| 12400 |
% |
| 12401 |
% \begin{macro}{\lst@fmtIfNextCharIn} |
| 12402 |
% is required for the optional \meta{exceptional characters}. |
| 12403 |
% The implementation is easy---refer section \ref{iSubstringTests}. |
| 12404 |
% \begin{macrocode} |
| 12405 |
\gdef\lst@fmtIfNextCharIn#1{% |
| 12406 |
\ifx\@empty#1\@empty \expandafter\@secondoftwo \else |
| 12407 |
\def\lst@next{\lst@fmtIfNextCharIn@{#1}}% |
| 12408 |
\expandafter\lst@next\fi} |
| 12409 |
\gdef\lst@fmtIfNextCharIn@#1#2#3#4{% |
| 12410 |
\def\lst@temp##1#4##2##3\relax{% |
| 12411 |
\ifx \@empty##2\expandafter\@secondoftwo |
| 12412 |
\else \expandafter\@firstoftwo \fi}% |
| 12413 |
\lst@temp#1#4\@empty\relax{#2}{#3}#4} |
| 12414 |
% \end{macrocode} |
| 12415 |
% \end{macro} |
| 12416 |
% |
| 12417 |
% \begin{macro}{\lst@fmtCDef} |
| 12418 |
% We need derivations of |\lst@CDef| and |\lst@CDefX|: we have to test the |
| 12419 |
% next character against the sequence |#5| of exceptional characters. |
| 12420 |
% These tests are inserted here. |
| 12421 |
% \begin{macrocode} |
| 12422 |
\gdef\lst@fmtCDef#1{\lst@fmtCDef@#1} |
| 12423 |
\gdef\lst@fmtCDef@#1#2#3#4#5#6#7{% |
| 12424 |
\lst@CDefIt#1{#2}{#3}% |
| 12425 |
{\lst@fmtIfNextCharIn{#5}{#4#2#3}{#6#4#2#3#7}}% |
| 12426 |
#4% |
| 12427 |
{}{}{}} |
| 12428 |
% \end{macrocode} |
| 12429 |
% \end{macro} |
| 12430 |
% |
| 12431 |
% \begin{macro}{\lst@fmtCDefX} |
| 12432 |
% The same but `drop input'. |
| 12433 |
% \begin{macrocode} |
| 12434 |
\gdef\lst@fmtCDefX#1{\lst@fmtCDefX@#1} |
| 12435 |
\gdef\lst@fmtCDefX@#1#2#3#4#5#6#7{% |
| 12436 |
\let#4#1% |
| 12437 |
\ifx\@empty#2\@empty |
| 12438 |
\def#1{\lst@fmtIfNextCharIn{#5}{#4}{#6#7}}% |
| 12439 |
\else \ifx\@empty#3\@empty |
| 12440 |
\def#1##1{% |
| 12441 |
\ifx##1#2% |
| 12442 |
\def\lst@next{\lst@fmtIfNextCharIn{#5}{#4##1}% |
| 12443 |
{#6#7}}% |
| 12444 |
\else |
| 12445 |
\def\lst@next{#4##1}% |
| 12446 |
\fi |
| 12447 |
\lst@next}% |
| 12448 |
\else |
| 12449 |
\def#1{% |
| 12450 |
\lst@IfNextCharsArg{#2#3}% |
| 12451 |
{\lst@fmtIfNextCharIn{#5}{\expandafter#4\lst@eaten}% |
| 12452 |
{#6#7}}% |
| 12453 |
{\expandafter#4\lst@eaten}}% |
| 12454 |
\fi \fi} |
| 12455 |
% \end{macrocode} |
| 12456 |
% \end{macro} |
| 12457 |
% |
| 12458 |
% |
| 12459 |
% \paragraph{The parser} |
| 12460 |
% applies |\lst@fmtSplit| to cut a format definition into items, items into |
| 12461 |
% `input' and `output', and `output' into `pre' and 'post'. This should be |
| 12462 |
% clear if you are in touch with format definitions. |
| 12463 |
% |
| 12464 |
% \begin{macro}{\lst@UseFormat} |
| 12465 |
% Now we can start with the parser. |
| 12466 |
% \begin{macrocode} |
| 12467 |
\gdef\lst@UseFormat#1{% |
| 12468 |
\def\lst@fmtwhole{#1}% |
| 12469 |
\lst@UseFormat@} |
| 12470 |
\gdef\lst@UseFormat@{% |
| 12471 |
\lst@fmtSplit\lst@fmtwhole,% |
| 12472 |
% \end{macrocode} |
| 12473 |
% We assign the rest of the format definition, \ldots |
| 12474 |
% \begin{macrocode} |
| 12475 |
\let\lst@fmtwhole\lst@fmtb |
| 12476 |
\ifx\lst@fmta\@empty\else |
| 12477 |
% \end{macrocode} |
| 12478 |
% \ldots\space split the item at the equal sign, and work on the item. |
| 12479 |
% \begin{macrocode} |
| 12480 |
\lst@fmtSplit\lst@fmta=% |
| 12481 |
\ifx\@empty\lst@fmta\else |
| 12482 |
% \end{macrocode} |
| 12483 |
% \begin{TODO} |
| 12484 |
% Insert |\let\lst@arg\@empty| |\expandafter\lst@XConvert\lst@fmtb\@nil| |
| 12485 |
% |\let\lst@fmtb\lst@arg|. |
| 12486 |
% \end{TODO} |
| 12487 |
% \begin{macrocode} |
| 12488 |
\expandafter\lstKV@XOptArg\expandafter[\expandafter]% |
| 12489 |
\expandafter{\lst@fmtb}\lst@UseFormat@b |
| 12490 |
\fi |
| 12491 |
\fi |
| 12492 |
% \end{macrocode} |
| 12493 |
% Finally we process the next item if the rest is not empty. |
| 12494 |
% \begin{macrocode} |
| 12495 |
\ifx\lst@fmtwhole\@empty\else |
| 12496 |
\expandafter\lst@UseFormat@ |
| 12497 |
\fi} |
| 12498 |
% \end{macrocode} |
| 12499 |
% We make |\lst@fmtc| contain the preceding characters as a braced argument. |
| 12500 |
% To add more arguments, we first split the replacement tokens at the control |
| 12501 |
% sequence |\string|. |
| 12502 |
% \begin{macrocode} |
| 12503 |
\gdef\lst@UseFormat@b[#1]#2{% |
| 12504 |
\def\lst@fmtc{{#1}}\lst@lExtend\lst@fmtc{\expandafter{\lst@fmta}}% |
| 12505 |
\def\lst@fmtb{#2}% |
| 12506 |
\lst@fmtSplit\lst@fmtb\string |
| 12507 |
% \end{macrocode} |
| 12508 |
% We append an empty argument or |\lst@fmtPre| with `|\string|-preceding' |
| 12509 |
% tokens as argument. We do the same for the tokens after |\string|. |
| 12510 |
% \begin{macrocode} |
| 12511 |
\ifx\@empty\lst@fmta |
| 12512 |
\lst@lAddTo\lst@fmtc{{}}% |
| 12513 |
\else |
| 12514 |
\lst@lExtend\lst@fmtc{\expandafter |
| 12515 |
{\expandafter\lst@fmtPre\expandafter{\lst@fmta}}}% |
| 12516 |
\fi |
| 12517 |
\ifx\@empty\lst@fmtb |
| 12518 |
\lst@lAddTo\lst@fmtc{{}}% |
| 12519 |
\else |
| 12520 |
\lst@lExtend\lst@fmtc{\expandafter |
| 12521 |
{\expandafter\lst@fmtPost\expandafter{\lst@fmtb}}}% |
| 12522 |
\fi |
| 12523 |
% \end{macrocode} |
| 12524 |
% Eventually we extend |\lst@fmtformat| appropriately. Note that |\lst@if| |
| 12525 |
% still indicates whether the replacement tokens contain |\string|. |
| 12526 |
% \begin{macrocode} |
| 12527 |
\expandafter\lst@UseFormat@c\lst@fmtc} |
| 12528 |
% \end{macrocode} |
| 12529 |
% \begin{macrocode} |
| 12530 |
\gdef\lst@UseFormat@c#1#2#3#4{% |
| 12531 |
\lst@fmtIfIdentifier#2\relax |
| 12532 |
{\lst@fmtIdentifier{#2}% |
| 12533 |
\lst@if\else \PackageWarning{Listings}% |
| 12534 |
{Cannot drop identifier in format definition}% |
| 12535 |
\fi}% |
| 12536 |
{\lst@if |
| 12537 |
\lst@lAddTo\lst@fmtformat{\lst@CArgX#2\relax\lst@fmtCDef}% |
| 12538 |
\else |
| 12539 |
\lst@lAddTo\lst@fmtformat{\lst@CArgX#2\relax\lst@fmtCDefX}% |
| 12540 |
\fi |
| 12541 |
\lst@DefActive\lst@fmtc{#1}% |
| 12542 |
\lst@lExtend\lst@fmtformat{\expandafter{\lst@fmtc}{#3}{#4}}}} |
| 12543 |
% \end{macrocode} |
| 12544 |
% \begin{macrocode} |
| 12545 |
\lst@AddToHook{SelectCharTable}{\lst@fmtformat} |
| 12546 |
\global\let\lst@fmtformat\@empty |
| 12547 |
% \end{macrocode} |
| 12548 |
% \end{macro} |
| 12549 |
% |
| 12550 |
% |
| 12551 |
% \paragraph{The formatting} |
| 12552 |
% |
| 12553 |
% \begin{macro}{\lst@fmtPre} |
| 12554 |
% \begin{macrocode} |
| 12555 |
\gdef\lst@fmtPre#1{% |
| 12556 |
\lst@PrintToken |
| 12557 |
\begingroup |
| 12558 |
\let\newline\lst@fmtEnsureNewLine |
| 12559 |
\let\space\lst@fmtEnsureSpace |
| 12560 |
\let\indent\lst@fmtIndent |
| 12561 |
\let\noindent\lst@fmtNoindent |
| 12562 |
#1% |
| 12563 |
\endgroup} |
| 12564 |
% \end{macrocode} |
| 12565 |
% \end{macro} |
| 12566 |
% |
| 12567 |
% \begin{macro}{\lst@fmtPost} |
| 12568 |
% \begin{macrocode} |
| 12569 |
\gdef\lst@fmtPost#1{% |
| 12570 |
\global\let\lst@fmtPostOutput\@empty |
| 12571 |
\begingroup |
| 12572 |
\def\newline{\lst@AddTo\lst@fmtPostOutput\lst@fmtEnsureNewLine}% |
| 12573 |
\def\space{\aftergroup\lst@fmtEnsurePostSpace}% |
| 12574 |
\def\indent{\lst@AddTo\lst@fmtPostOutput\lst@fmtIndent}% |
| 12575 |
\def\noindent{\lst@AddTo\lst@fmtPostOutput\lst@fmtNoindent}% |
| 12576 |
\aftergroup\lst@PrintToken |
| 12577 |
#1% |
| 12578 |
\endgroup} |
| 12579 |
% \end{macrocode} |
| 12580 |
% \begin{macrocode} |
| 12581 |
\lst@AddToHook{Init}{\global\let\lst@fmtPostOutput\@empty} |
| 12582 |
\lst@AddToHook{PostOutput} |
| 12583 |
{\lst@fmtPostOutput \global\let\lst@fmtPostOutput\@empty} |
| 12584 |
% \end{macrocode} |
| 12585 |
% \end{macro} |
| 12586 |
% |
| 12587 |
% \begin{macro}{\lst@fmtEnsureSpace} |
| 12588 |
% \begin{macro}{\lst@fmtEnsurePostSpace} |
| 12589 |
% \begin{macrocode} |
| 12590 |
\gdef\lst@fmtEnsureSpace{% |
| 12591 |
\lst@ifwhitespace\else \expandafter\lst@ProcessSpace \fi} |
| 12592 |
\gdef\lst@fmtEnsurePostSpace{% |
| 12593 |
\lst@IfNextCharWhitespace{}{\lst@ProcessSpace}} |
| 12594 |
% \end{macrocode} |
| 12595 |
% \end{macro} |
| 12596 |
% \end{macro} |
| 12597 |
% |
| 12598 |
% \begin{lstkey}{fmtindent} |
| 12599 |
% \begin{macro}{\lst@fmtIndent} |
| 12600 |
% \begin{macro}{\lst@fmtNoindent} |
| 12601 |
% \begin{macrocode} |
| 12602 |
\lst@Key{fmtindent}{20pt}{\def\lst@fmtindent{#1}} |
| 12603 |
\newdimen\lst@fmtcurrindent |
| 12604 |
\lst@AddToHook{InitVars}{\global\lst@fmtcurrindent\z@} |
| 12605 |
\gdef\lst@fmtIndent{\global\advance\lst@fmtcurrindent\lst@fmtindent} |
| 12606 |
\gdef\lst@fmtNoindent{\global\advance\lst@fmtcurrindent-\lst@fmtindent} |
| 12607 |
% \end{macrocode} |
| 12608 |
% \end{macro} |
| 12609 |
% \end{macro} |
| 12610 |
% \end{lstkey} |
| 12611 |
% |
| 12612 |
% \begin{macro}{\lst@fmtEnsureNewLine} |
| 12613 |
% \begin{macrocode} |
| 12614 |
\gdef\lst@fmtEnsureNewLine{% |
| 12615 |
\global\advance\lst@newlines\@ne |
| 12616 |
\global\advance\lst@newlinesensured\@ne |
| 12617 |
\lst@fmtignoretrue} |
| 12618 |
% \end{macrocode} |
| 12619 |
% \begin{macrocode} |
| 12620 |
\lst@AddToAtTop\lst@DoNewLines{% |
| 12621 |
\ifnum\lst@newlines>\lst@newlinesensured |
| 12622 |
\global\advance\lst@newlines-\lst@newlinesensured |
| 12623 |
\fi |
| 12624 |
\global\lst@newlinesensured\z@} |
| 12625 |
\newcount\lst@newlinesensured % global |
| 12626 |
\lst@AddToHook{Init}{\global\lst@newlinesensured\z@} |
| 12627 |
% \end{macrocode} |
| 12628 |
% \begin{macrocode} |
| 12629 |
\gdef\lst@fmtignoretrue{\let\lst@fmtifignore\iftrue} |
| 12630 |
\gdef\lst@fmtignorefalse{\let\lst@fmtifignore\iffalse} |
| 12631 |
\lst@AddToHook{InitVars}{\lst@fmtignorefalse} |
| 12632 |
\lst@AddToHook{Output}{\lst@fmtignorefalse} |
| 12633 |
% \end{macrocode} |
| 12634 |
% \end{macro} |
| 12635 |
% |
| 12636 |
% \begin{macro}{\lst@fmtUseLostSpace} |
| 12637 |
% \begin{macrocode} |
| 12638 |
\gdef\lst@fmtUseLostSpace{% |
| 12639 |
\lst@ifnewline \kern\lst@fmtcurrindent \global\lst@lostspace\z@ |
| 12640 |
\else |
| 12641 |
\lst@OldOLS |
| 12642 |
\fi} |
| 12643 |
\lst@AddToHook{Init} |
| 12644 |
{\lst@true |
| 12645 |
\ifx\lst@fmtformat\@empty \ifx\lst@fmt\@empty \lst@false \fi\fi |
| 12646 |
\lst@if |
| 12647 |
\let\lst@OldOLS\lst@OutputLostSpace |
| 12648 |
\let\lst@OutputLostSpace\lst@fmtUseLostSpace |
| 12649 |
\let\lst@ProcessSpace\lst@fmtProcessSpace |
| 12650 |
\fi} |
| 12651 |
% \end{macrocode} |
| 12652 |
% \begin{TODO} |
| 12653 |
% This `lost space' doesn't use |\lst@alloverstyle| yet! |
| 12654 |
% \end{TODO} |
| 12655 |
% \end{macro} |
| 12656 |
% |
| 12657 |
% \begin{macro}{\lst@fmtProcessSpace} |
| 12658 |
% \begin{macrocode} |
| 12659 |
\gdef\lst@fmtProcessSpace{% |
| 12660 |
\lst@ifletter |
| 12661 |
\lst@Output |
| 12662 |
\lst@fmtifignore\else |
| 12663 |
\lst@AppendOther\lst@outputspace |
| 12664 |
\fi |
| 12665 |
\else \lst@ifkeepspaces |
| 12666 |
\lst@AppendOther\lst@outputspace |
| 12667 |
\else \ifnum\lst@newlines=\z@ |
| 12668 |
\lst@AppendSpecialSpace |
| 12669 |
\else \ifnum\lst@length=\z@ |
| 12670 |
\global\advance\lst@lostspace\lst@width |
| 12671 |
\global\advance\lst@pos\m@ne |
| 12672 |
\else |
| 12673 |
\lst@AppendSpecialSpace |
| 12674 |
\fi |
| 12675 |
\fi \fi \fi |
| 12676 |
\lst@whitespacetrue} |
| 12677 |
% \end{macrocode} |
| 12678 |
% \end{macro} |
| 12679 |
% |
| 12680 |
% |
| 12681 |
% \paragraph{Formatting identifiers} |
| 12682 |
% |
| 12683 |
% \begin{macro}{\lst@fmtIdentifier} |
| 12684 |
% We install a (keyword) test for the `format identifiers'. |
| 12685 |
% \begin{macrocode} |
| 12686 |
\lst@InstallTest{f} |
| 12687 |
\lst@fmt@list\lst@fmt \lst@gfmt@list\lst@gfmt |
| 12688 |
\lst@gfmt@wp |
| 12689 |
wd |
| 12690 |
\gdef\lst@fmt@list{\lst@fmt\lst@gfmt}\global\let\lst@fmt\@empty |
| 12691 |
\gdef\lst@gfmt@list{\lst@fmt\lst@gfmt}\global\let\lst@gfmt\@empty |
| 12692 |
% \end{macrocode} |
| 12693 |
% The working procedure expands |\lst@fmt$|\meta{string} (and defines |
| 12694 |
% |\lst@PrintToken| to do nothing). |
| 12695 |
% \begin{macrocode} |
| 12696 |
\gdef\lst@gfmt@wp{% |
| 12697 |
\begingroup \let\lst@UM\@empty |
| 12698 |
\let\lst@PrintToken\@empty |
| 12699 |
\csname\@lst @fmt$\the\lst@token\endcsname |
| 12700 |
\endgroup} |
| 12701 |
% \end{macrocode} |
| 12702 |
% This control sequence is probably defined as `working identifier'. |
| 12703 |
% \begin{macrocode} |
| 12704 |
\gdef\lst@fmtIdentifier#1#2#3#4{% |
| 12705 |
\lst@DefOther\lst@fmta{#2}\edef\lst@fmt{\lst@fmt,\lst@fmta}% |
| 12706 |
\@namedef{\@lst @fmt$\lst@fmta}{#3#4}} |
| 12707 |
% \end{macrocode} |
| 12708 |
% |\lst@fmt$|\meta{identifier} expands to a |\lst@fmtPre|/|\lst@fmtPost| |
| 12709 |
% sequence defined by |#2| and |#3|. |
| 12710 |
% \end{macro} |
| 12711 |
% |
| 12712 |
% \begin{macrocode} |
| 12713 |
\lst@EndAspect |
| 12714 |
%</misc> |
| 12715 |
% \end{macrocode} |
| 12716 |
% \end{aspect} |
| 12717 |
% |
| 12718 |
% |
| 12719 |
% |
| 12720 |
% \subsection{Line numbers} |
| 12721 |
% |
| 12722 |
% \begin{aspect}{labels} |
| 12723 |
% \lsthelper{Rolf~Niepraschk}{1997/04/24}{line numbers} asked for line |
| 12724 |
% number, the relevant keys and `\textit{data}' commands are described in |
| 12725 |
% section \ref{rLineNumbers}, here is their implementation. |
| 12726 |
% \begin{macrocode} |
| 12727 |
%<*misc> |
| 12728 |
\lst@BeginAspect{labels} |
| 12729 |
% \end{macrocode} |
| 12730 |
% |
| 12731 |
% \begin{lstkey}{numbers} |
| 12732 |
% Depending on the argument we define |\lst@PlaceNumber| to print the line |
| 12733 |
% number. |
| 12734 |
% \begin{macrocode} |
| 12735 |
\lst@Key{numbers}{none}{% |
| 12736 |
\let\lst@PlaceNumber\@empty |
| 12737 |
\lstKV@SwitchCases{#1}% |
| 12738 |
{none:\\% |
| 12739 |
left:\def\lst@PlaceNumber{\llap{\normalfont |
| 12740 |
\lst@numberstyle{\thelstnumber}\kern\lst@numbersep}}\\% |
| 12741 |
right:\def\lst@PlaceNumber{\rlap{\normalfont |
| 12742 |
\kern\linewidth \kern\lst@numbersep |
| 12743 |
\lst@numberstyle{\thelstnumber}}}% |
| 12744 |
}{\PackageError{Listings}{value `#1' for keyword `numbers' not supported}\@ehc}} |
| 12745 |
% \end{macrocode} |
| 12746 |
% \end{lstkey} |
| 12747 |
% |
| 12748 |
% \begin{lstkey}{stepnumber} |
| 12749 |
% \begin{lstkey}{numberfirstline} |
| 12750 |
% \begin{lstkey}{numberstyle} |
| 12751 |
% \begin{lstkey}{numbersep} |
| 12752 |
% \begin{lstkey}{numberblanklines} |
| 12753 |
% Definition of the keys. |
| 12754 |
% \begin{macrocode} |
| 12755 |
\lst@Key{stepnumber}{1}{\def\lst@stepnumber{#1\relax}} |
| 12756 |
\lst@Key{numberfirstline}{f}[t]{\lstKV@SetIf{#1}\lst@ifnumberfirstline} |
| 12757 |
\lst@Key{numberstyle}{}{\def\lst@numberstyle{#1}} |
| 12758 |
\lst@Key{numbersep}{10pt}{\def\lst@numbersep{#1}} |
| 12759 |
\lst@Key{numberblanklines}{true}[t] |
| 12760 |
{\lstKV@SetIf{#1}\lst@ifnumberblanklines} |
| 12761 |
% \end{macrocode} |
| 12762 |
% If we use the `empty' style, the listing must start at line 1, so: |
| 12763 |
% \begin{macrocode} |
| 12764 |
\lst@AddToHook{EmptyStyle}{\let\lst@stepnumber\@ne} |
| 12765 |
% \end{macrocode} |
| 12766 |
% Later on we use this to prevent numbering of the first line for a second |
| 12767 |
% time. |
| 12768 |
% \begin{macrocode} |
| 12769 |
\gdef\lst@numberfirstlinefalse{\let\lst@ifnumberfirstline\iffalse} |
| 12770 |
% \end{macrocode} |
| 12771 |
% \end{lstkey} |
| 12772 |
% \end{lstkey} |
| 12773 |
% \end{lstkey} |
| 12774 |
% \end{lstkey} |
| 12775 |
% \end{lstkey} |
| 12776 |
% |
| 12777 |
% \begin{lstkey}{firstnumber} |
| 12778 |
% We select the first number according to the argument. |
| 12779 |
% \begin{macrocode} |
| 12780 |
\lst@Key{firstnumber}{auto}{% |
| 12781 |
\lstKV@SwitchCases{#1}% |
| 12782 |
{auto:\let\lst@firstnumber\@undefined\\% |
| 12783 |
last:\let\lst@firstnumber\c@lstnumber |
| 12784 |
}{\def\lst@firstnumber{#1\relax}}} |
| 12785 |
\lst@AddToHook{PreSet}{\let\lst@advancenumber\z@} |
| 12786 |
% \end{macrocode} |
| 12787 |
% |\lst@firstnumber| is now set to |\lst@lineno| instead of |\lst@firstline|, |
| 12788 |
% as per changes in |lstpatch.sty| from 1.3b pertaining to linerange markers. |
| 12789 |
% \begin{macrocode} |
| 12790 |
\lst@AddToHook{PreInit} |
| 12791 |
{\ifx\lst@firstnumber\@undefined |
| 12792 |
\def\lst@firstnumber{\lst@lineno}% |
| 12793 |
\fi} |
| 12794 |
% \end{macrocode} |
| 12795 |
% \end{lstkey} |
| 12796 |
% |
| 12797 |
% The key |name| is defined in section \ref{sec:list-listings}, the data |
| 12798 |
% command |\thelstnumber| below on page \pageref{iTheLstNumber}. |
| 12799 |
% |
| 12800 |
% \begin{macro}{\lst@SetFirstNumber} |
| 12801 |
% \begin{macro}{\lst@SaveFirstNumber} |
| 12802 |
% \lsthelper{Boris~Veytsman}{1998/03/25}{continue line numbering: a.c b.c a.c} |
| 12803 |
% proposed to continue line numbers according to listing names. We define the |
| 12804 |
% label number of the first printing line here. A bug reported by |
| 12805 |
% \lsthelper{Jens~Schwarzer}{2001/05/29}{wrong line numbering of lstlisting |
| 12806 |
% with first>1} has been removed by replacing |\@ne| by |\lst@firstline|. |
| 12807 |
% \begin{macrocode} |
| 12808 |
\gdef\lst@SetFirstNumber{% |
| 12809 |
\ifx\lst@firstnumber\@undefined |
| 12810 |
\@tempcnta 0\csname\@lst no@\lst@intname\endcsname\relax |
| 12811 |
\ifnum\@tempcnta=\z@ \@tempcnta\lst@firstline |
| 12812 |
\else \lst@nololtrue \fi |
| 12813 |
\advance\@tempcnta\lst@advancenumber |
| 12814 |
\edef\lst@firstnumber{\the\@tempcnta\relax}% |
| 12815 |
\fi} |
| 12816 |
% \end{macrocode} |
| 12817 |
% The current label is stored in|\lstno@|\meta{name}. If the name is empty, |
| 12818 |
% we use a space instead, which leaves |\lstno@| undefined. |
| 12819 |
% \begin{macrocode} |
| 12820 |
\gdef\lst@SaveFirstNumber{% |
| 12821 |
\expandafter\xdef |
| 12822 |
\csname\@lst no\ifx\lst@intname\@empty @ \else @\lst@intname\fi |
| 12823 |
\endcsname{\the\c@lstnumber}} |
| 12824 |
% \end{macrocode} |
| 12825 |
% \end{macro} |
| 12826 |
% \end{macro} |
| 12827 |
% |
| 12828 |
% \begin{macro}{\thelstnumber} |
| 12829 |
% \begin{macro}{\c@lstnumber} |
| 12830 |
% \label{iTheLstNumber}% |
| 12831 |
% This counter keeps the current label number. We use it as current label to |
| 12832 |
% make line numbers referenced by |\ref|. This was proposed by |
| 12833 |
% \lsthelper{Boris~Veytsman}{1998/03/25}{make line numbers referenced via |
| 12834 |
% \label and \ref}. We now use |\refstepcounter| to do the job---thanks to a |
| 12835 |
% bug report from \lsthelper{Christian~Gudrian}{2000/11/13}{\ref{lst:line} |
| 12836 |
% jumps to top of listing and not to the line}. |
| 12837 |
% \begin{macrocode} |
| 12838 |
\newcounter{lstnumber}% \global |
| 12839 |
\global\c@lstnumber\@ne % init |
| 12840 |
\renewcommand*\thelstnumber{\@arabic\c@lstnumber} |
| 12841 |
\lst@AddToHook{EveryPar} |
| 12842 |
{\global\advance\c@lstnumber\lst@advancelstnum |
| 12843 |
\global\advance\c@lstnumber\m@ne \refstepcounter{lstnumber}% |
| 12844 |
\lst@SkipOrPrintLabel}% |
| 12845 |
\global\let\lst@advancelstnum\@ne |
| 12846 |
% \end{macrocode} |
| 12847 |
% Note that the counter advances \emph{before} the label is printed and not |
| 12848 |
% afterwards. Otherwise we have wrong references---reported by |
| 12849 |
% \lsthelper{Gregory~Van~Vooren}{1999/06/04}{reference one unit too large}. |
| 12850 |
% \begin{macrocode} |
| 12851 |
\lst@AddToHook{Init}{\def\@currentlabel{\thelstnumber}} |
| 12852 |
% \end{macrocode} |
| 12853 |
% \lsthelper{Felix Freiberger}{2025/03/12}{LaTeX listings package: cleveref |
| 12854 |
% can no longer reference individual lines} referred to the article |
| 12855 |
% \url{https://tex.stackexchange.com/q/738349/30156} with the title |
| 12856 |
% ``\packagename{cleveref} could no longer reference lines in |
| 12857 |
% |lstlisting|''. \lsthelper{Ulrike Fischer}{2025/03/05}{cleveref no longer |
| 12858 |
% can reference line in lstlisting} provided a valid solution with the |
| 12859 |
% following line. |
| 12860 |
% \begin{macrocode} |
| 12861 |
\lst@AddToHook{Init}{\def\@currentcounter{lstnumber}} |
| 12862 |
% \end{macrocode} |
| 12863 |
% The label number is initialized and we ensure correct line numbers for |
| 12864 |
% continued listings. An apparently-extraneous advancement of the line |
| 12865 |
% number by \verb|-\lst@advancelstnum| when \texttt{firstnumber=last} is |
| 12866 |
% specified was removed, following a bug report by \lsthelper{Joachim~Breitner}% |
| 12867 |
% {2006/05/14}{failure to continue counting correctly}. |
| 12868 |
% \begin{macrocode} |
| 12869 |
\lst@AddToHook{InitVars} |
| 12870 |
{\global\c@lstnumber\lst@firstnumber |
| 12871 |
\global\advance\c@lstnumber\lst@advancenumber |
| 12872 |
\global\advance\c@lstnumber-\lst@advancelstnum} |
| 12873 |
\lst@AddToHook{ExitVars} |
| 12874 |
{\global\advance\c@lstnumber\lst@advancelstnum} |
| 12875 |
% \end{macrocode} |
| 12876 |
% \lsthelper{Walter~E.~Brown}{2001/05/22}{pdftex 3.14159-14f warning: |
| 12877 |
% destination with the same identifier} reported problems with pdftex and |
| 12878 |
% \packagename{hyperref}. A bad default of |\theHlstlabel| was the reason. |
| 12879 |
% \lsthelper{Heiko~Oberdiek}{2001/11/08}{pdftex warning: destination with |
| 12880 |
% the same identifier} found another bug which was due to the localization |
| 12881 |
% of |\lst@neglisting|. He also provided the following fix, replacing |
| 12882 |
% |\thelstlisting| with the |\ifx| \ldots\ |\fi| construction. |
| 12883 |
% \lsthelper{Ivo~Pletikosi\'c}{2015/08/18}{listings + hyperref, lstmisc.sty} |
| 12884 |
% reported another problem with the redefinition of |\thelstlisting|. |
| 12885 |
% \lsthelper{Heiko~Oberdiek}{2001/11/08}% |
| 12886 |
% {http://tex.stackexchange.com/questions/261437/renewing-the-thelstlisting^^A |
| 12887 |
% -command-when-hyperref-is-on} |
| 12888 |
% again provided a fix: |\thelstlisting| must be replaced by |\theHlstlisting|. |
| 12889 |
% \begin{macrocode} |
| 12890 |
\AtBeginDocument{% |
| 12891 |
\def\theHlstnumber{\ifx\lst@@caption\@empty \lst@neglisting |
| 12892 |
\else \theHlstlisting \fi |
| 12893 |
.\thelstnumber}} |
| 12894 |
% \end{macrocode} |
| 12895 |
% \end{macro} |
| 12896 |
% \end{macro} |
| 12897 |
% |
| 12898 |
% \begin{macro}{\lst@skipnumbers} |
| 12899 |
% There are more things to do. We calculate how many lines must skip their |
| 12900 |
% label. The formula is |
| 12901 |
% $$|\lst@skipnumbers|= |
| 12902 |
% \textrm{\emph{first printing line}}\bmod|\lst@stepnumber|.$$ |
| 12903 |
% Note that we use a nonpositive representative for |\lst@skipnumbers|. |
| 12904 |
% \begin{macrocode} |
| 12905 |
\newcount\lst@skipnumbers % \global |
| 12906 |
\lst@AddToHook{Init} |
| 12907 |
{\ifnum \z@>\lst@stepnumber |
| 12908 |
\let\lst@advancelstnum\m@ne |
| 12909 |
\edef\lst@stepnumber{-\lst@stepnumber}% |
| 12910 |
\fi |
| 12911 |
\ifnum \z@<\lst@stepnumber |
| 12912 |
\global\lst@skipnumbers\lst@firstnumber |
| 12913 |
\global\divide\lst@skipnumbers\lst@stepnumber |
| 12914 |
\global\multiply\lst@skipnumbers-\lst@stepnumber |
| 12915 |
\global\advance\lst@skipnumbers\lst@firstnumber |
| 12916 |
\ifnum\lst@skipnumbers>\z@ |
| 12917 |
\global\advance\lst@skipnumbers -\lst@stepnumber |
| 12918 |
\fi |
| 12919 |
% \end{macrocode} |
| 12920 |
% If |\lst@stepnumber| is zero, no line numbers are printed: |
| 12921 |
% \begin{macrocode} |
| 12922 |
\else |
| 12923 |
\let\lst@SkipOrPrintLabel\relax |
| 12924 |
\fi} |
| 12925 |
% \end{macrocode} |
| 12926 |
% \end{macro} |
| 12927 |
% |
| 12928 |
% \begin{macro}{\lst@SkipOrPrintLabel} |
| 12929 |
% But default is this. We use the fact that |\lst@skipnumbers| is nonpositive. |
| 12930 |
% The counter advances every line and if that counter is zero, we print a line |
| 12931 |
% number and decrement the counter by |\lst@stepnumber|. |
| 12932 |
% \begin{macrocode} |
| 12933 |
\gdef\lst@SkipOrPrintLabel{% |
| 12934 |
\ifnum\lst@skipnumbers=\z@ |
| 12935 |
\global\advance\lst@skipnumbers-\lst@stepnumber\relax |
| 12936 |
\lst@PlaceNumber |
| 12937 |
\lst@numberfirstlinefalse |
| 12938 |
\else |
| 12939 |
% \end{macrocode} |
| 12940 |
% If the first line of a listing should get a number, it gets it here. |
| 12941 |
% \begin{macrocode} |
| 12942 |
\lst@ifnumberfirstline |
| 12943 |
\lst@PlaceNumber |
| 12944 |
\lst@numberfirstlinefalse |
| 12945 |
\fi |
| 12946 |
\fi |
| 12947 |
\global\advance\lst@skipnumbers\@ne}% |
| 12948 |
% \end{macrocode} |
| 12949 |
% \begin{macrocode} |
| 12950 |
\lst@AddToHook{OnEmptyLine}{% |
| 12951 |
\lst@ifnumberblanklines\else \ifnum\lst@skipnumbers=\z@ |
| 12952 |
\global\advance\lst@skipnumbers-\lst@stepnumber\relax |
| 12953 |
\fi\fi} |
| 12954 |
% \end{macrocode} |
| 12955 |
% \end{macro} |
| 12956 |
% |
| 12957 |
% \begin{macrocode} |
| 12958 |
\lst@EndAspect |
| 12959 |
%</misc> |
| 12960 |
% \end{macrocode} |
| 12961 |
% \end{aspect} |
| 12962 |
% |
| 12963 |
% |
| 12964 |
% \subsection{Line shape and line breaking} |
| 12965 |
% |
| 12966 |
% \begin{macro}{\lst@parshape} |
| 12967 |
% We define a default version of |\lst@parshape| for the case that the |
| 12968 |
% \aspectname{lineshape} aspect is not loaded. We use this parshape every line |
| 12969 |
% (in fact every paragraph). Furthermore we must repeat the parshape if we |
| 12970 |
% close a group level---or the shape is forgotten. |
| 12971 |
% \begin{macrocode} |
| 12972 |
%<*kernel> |
| 12973 |
\def\lst@parshape{\parshape\@ne \z@ \linewidth} |
| 12974 |
\lst@AddToHookAtTop{EveryLine}{\lst@parshape} |
| 12975 |
\lst@AddToHookAtTop{EndGroup}{\lst@parshape} |
| 12976 |
%</kernel> |
| 12977 |
% \end{macrocode} |
| 12978 |
% \end{macro} |
| 12979 |
% |
| 12980 |
% \begin{aspect}{lineshape} |
| 12981 |
% Our first aspect in this section. |
| 12982 |
% \begin{macrocode} |
| 12983 |
%<*misc> |
| 12984 |
\lst@BeginAspect{lineshape} |
| 12985 |
% \end{macrocode} |
| 12986 |
% |
| 12987 |
% \begin{lstkey}{xleftmargin} |
| 12988 |
% \begin{lstkey}{xrightmargin} |
| 12989 |
% \begin{lstkey}{resetmargins} |
| 12990 |
% \begin{lstkey}{linewidth} |
| 12991 |
% Usual stuff. |
| 12992 |
% \begin{macrocode} |
| 12993 |
\lst@Key{xleftmargin}{\z@}{\def\lst@xleftmargin{#1}} |
| 12994 |
\lst@Key{xrightmargin}{\z@}{\def\lst@xrightmargin{#1}} |
| 12995 |
\lst@Key{resetmargins}{false}[t]{\lstKV@SetIf{#1}\lst@ifresetmargins} |
| 12996 |
% \end{macrocode} |
| 12997 |
% The margins become zero if we make an exact box around the listing. |
| 12998 |
% \begin{macrocode} |
| 12999 |
\lst@AddToHook{BoxUnsafe}{\let\lst@xleftmargin\z@ |
| 13000 |
\let\lst@xrightmargin\z@} |
| 13001 |
\lst@AddToHook{TextStyle}{% |
| 13002 |
\let\lst@xleftmargin\z@ \let\lst@xrightmargin\z@ |
| 13003 |
\let\lst@ifresetmargins\iftrue} |
| 13004 |
% \end{macrocode} |
| 13005 |
% Added above hook after bug report from \lsthelper{Magnus~Lewis-Smith} |
| 13006 |
%{1999/08/06}{|\lstinline| indented} and \lsthelper{Jos\'e~Romildo~Malaquias} |
| 13007 |
%{2000/08/22}{|\lstinline| indented (resetmargins)} respectively. |
| 13008 |
% \begin{macrocode} |
| 13009 |
\lst@Key{linewidth}\linewidth{\def\lst@linewidth{#1}} |
| 13010 |
\lst@AddToHook{PreInit}{\linewidth\lst@linewidth\relax} |
| 13011 |
% \end{macrocode} |
| 13012 |
% \end{lstkey} |
| 13013 |
% \end{lstkey} |
| 13014 |
% \end{lstkey} |
| 13015 |
% \end{lstkey} |
| 13016 |
% |
| 13017 |
% \begin{macro}{\lst@parshape} |
| 13018 |
% The definition itself is easy. |
| 13019 |
% \begin{macrocode} |
| 13020 |
\gdef\lst@parshape{% |
| 13021 |
\parshape\@ne \@totalleftmargin \linewidth} |
| 13022 |
% \end{macrocode} |
| 13023 |
% We calculate the line width and (inner/outer) indent for a listing. |
| 13024 |
% \begin{macrocode} |
| 13025 |
\lst@AddToHook{Init} |
| 13026 |
{\lst@ifresetmargins |
| 13027 |
\advance\linewidth\@totalleftmargin |
| 13028 |
\advance\linewidth\rightmargin |
| 13029 |
\@totalleftmargin\z@ |
| 13030 |
\fi |
| 13031 |
\advance\linewidth-\lst@xleftmargin |
| 13032 |
\advance\linewidth-\lst@xrightmargin |
| 13033 |
\advance\@totalleftmargin\lst@xleftmargin\relax} |
| 13034 |
% \end{macrocode} |
| 13035 |
% \end{macro} |
| 13036 |
% |
| 13037 |
% \begin{lstkey}{lineskip} |
| 13038 |
% The introduction of this key is due to communication with |
| 13039 |
% \lsthelper{Andreas~Bartelt}{1997/09/11}{problem with redefed \parskip; |
| 13040 |
% \lstlineskip introduced}. Version 1.0 implements this feature by |
| 13041 |
% redefining |\baselinestretch|. |
| 13042 |
% \begin{macrocode} |
| 13043 |
\lst@Key{lineskip}{\z@}{\def\lst@lineskip{#1\relax}} |
| 13044 |
\lst@AddToHook{Init} |
| 13045 |
{\parskip\z@ |
| 13046 |
\ifdim\z@=\lst@lineskip\else |
| 13047 |
\@tempdima\baselineskip |
| 13048 |
\advance\@tempdima\lst@lineskip |
| 13049 |
% \end{macrocode} |
| 13050 |
% The following three lines simulate the `bad' |\divide| |\@tempdima| |
| 13051 |
% |\strip@pt| |\baselineskip| |\relax|. Thanks to \lsthelper{Peter~Bartke} |
| 13052 |
% {2002/04/10}{bad use of \strip@pt} for the bug report. |
| 13053 |
% \begin{macrocode} |
| 13054 |
\multiply\@tempdima\@cclvi |
| 13055 |
\divide\@tempdima\baselineskip\relax |
| 13056 |
\multiply\@tempdima\@cclvi |
| 13057 |
% \end{macrocode} |
| 13058 |
% \begin{macrocode} |
| 13059 |
\edef\baselinestretch{\strip@pt\@tempdima}% |
| 13060 |
\selectfont |
| 13061 |
\fi} |
| 13062 |
% \end{macrocode} |
| 13063 |
% \end{lstkey} |
| 13064 |
% |
| 13065 |
% \begin{lstkey}{breaklines} |
| 13066 |
% \begin{lstkey}{breakindent} |
| 13067 |
% \begin{lstkey}{breakautoindent} |
| 13068 |
% \begin{lstkey}{breakatwhitespace} |
| 13069 |
% \begin{lstkey}{prebreak} |
| 13070 |
% \begin{lstkey}{postbreak} |
| 13071 |
% As usual we have no problems in announcing more keys. |
| 13072 |
% \keyname{breakatwhitespace} is due to \lsthelper{Javier~Bezos}{2003/09/23} |
| 13073 |
% {breaklines breaks at odd places}. Unfortunately a previous definition of |
| 13074 |
% that key was wrong as \lsthelper{Franz~Rinnerthaler}{2004/03/12} |
| 13075 |
% {breakatwhitespace has no effect} and \lsthelper{Ulrike~Fischer}{2004/07/11} |
| 13076 |
% {breakatwhitespace has no effect} reported. |
| 13077 |
% \begin{macrocode} |
| 13078 |
\lst@Key{breaklines}{false}[t]{\lstKV@SetIf{#1}\lst@ifbreaklines} |
| 13079 |
\lst@Key{breakindent}{20pt}{\def\lst@breakindent{#1}} |
| 13080 |
\lst@Key{breakautoindent}{t}[t]{\lstKV@SetIf{#1}\lst@ifbreakautoindent} |
| 13081 |
\lst@Key{breakatwhitespace}{false}[t]% |
| 13082 |
{\lstKV@SetIf{#1}\lst@ifbreakatwhitespace} |
| 13083 |
\lst@Key{prebreak}{}{\def\lst@prebreak{#1}} |
| 13084 |
\lst@Key{postbreak}{}{\def\lst@postbreak{#1}} |
| 13085 |
% \end{macrocode} |
| 13086 |
% We assign some different macros and (if necessary) suppress ``underfull |
| 13087 |
% |\hbox|'' messages (and use different pretolerance): |
| 13088 |
% \begin{macrocode} |
| 13089 |
\lst@AddToHook{Init} |
| 13090 |
{\lst@ifbreaklines |
| 13091 |
\hbadness\@M \pretolerance\@M |
| 13092 |
\@rightskip\@flushglue \rightskip\@rightskip % \raggedright |
| 13093 |
\leftskip\z@skip \parindent\z@ |
| 13094 |
% \end{macrocode} |
| 13095 |
% A |\raggedright| above has been replaced by setting the values by hand after |
| 13096 |
% a bug report from \lsthelper{Morten~H\o gholm}{2004/09/06}{ltugboat.cls and |
| 13097 |
% listings}. |
| 13098 |
% |
| 13099 |
% We use the normal parshape and the calculated |\lst@breakshape| (see below). |
| 13100 |
% \begin{macrocode} |
| 13101 |
\def\lst@parshape{\parshape\tw@ \@totalleftmargin\linewidth |
| 13102 |
\lst@breakshape}% |
| 13103 |
\else |
| 13104 |
\let\lst@discretionary\@empty |
| 13105 |
\fi} |
| 13106 |
\lst@AddToHook{OnNewLine} |
| 13107 |
{\lst@ifbreaklines \lst@breakNewLine \fi} |
| 13108 |
% \end{macrocode} |
| 13109 |
% \end{lstkey}\end{lstkey}\end{lstkey}\end{lstkey} |
| 13110 |
% \end{lstkey}\end{lstkey} |
| 13111 |
% |
| 13112 |
% \begin{macro}{\lst@discretionary} |
| 13113 |
% \begin{macro}{\lst@spacekern} |
| 13114 |
% Here comes the whole magic: We set a discretionary break after each `output |
| 13115 |
% unit'. However we redefine |\space| to be used inside |\discretionary| and |
| 13116 |
% use \hookname{EveryLine} hook. After a bug report by \lsthelper{Carsten~Hamm} |
| 13117 |
% {2002/04/19}{wrong frame rules with breaklines and xleftmargin>0pt} I've |
| 13118 |
% added |\kern-\lst@xleftmargin|, which became |\kern-\@totalleftmargin| after |
| 13119 |
% a bug report by \lsthelper{Christian~Kaiser}{2002/12/13}{wrong frame inside |
| 13120 |
% itemize with breaklines=true}. |
| 13121 |
% \begin{macrocode} |
| 13122 |
\gdef\lst@discretionary{% |
| 13123 |
\lst@ifbreakatwhitespace |
| 13124 |
\lst@ifwhitespace \lst@@discretionary \fi |
| 13125 |
\else |
| 13126 |
\lst@@discretionary |
| 13127 |
\fi}% |
| 13128 |
\gdef\lst@@discretionary{% |
| 13129 |
\discretionary{\let\space\lst@spacekern\lst@prebreak}% |
| 13130 |
{\llap{\lsthk@EveryLine |
| 13131 |
\kern\lst@breakcurrindent \kern-\@totalleftmargin}% |
| 13132 |
\let\space\lst@spacekern\lst@postbreak}{}} |
| 13133 |
\lst@AddToHook{PostOutput}{\lst@discretionary} |
| 13134 |
\gdef\lst@spacekern{\kern\lst@width} |
| 13135 |
% \end{macrocode} |
| 13136 |
% \begin{ALTERNATIVE} |
| 13137 |
% |\penalty\@M \hskip\z@ plus 1fil \penalty0\hskip\z@ plus-1fil| \emph{before} |
| 13138 |
% each `output unit' (i.e.~before |\hbox{...}| in the output macros) also break |
| 13139 |
% the lines as desired. But we wouldn't have |prebreak| and |postbreak|. |
| 13140 |
% \end{ALTERNATIVE} |
| 13141 |
% \end{macro}\end{macro} |
| 13142 |
% |
| 13143 |
% \begin{macro}{\lst@breakNewLine} |
| 13144 |
% We use \keyname{breakindent}, and additionally the current line indention |
| 13145 |
% (coming from white spaces at the beginning of the line) if `auto indent' is |
| 13146 |
% on. |
| 13147 |
% \begin{macrocode} |
| 13148 |
\gdef\lst@breakNewLine{% |
| 13149 |
\@tempdima\lst@breakindent\relax |
| 13150 |
\lst@ifbreakautoindent \advance\@tempdima\lst@lostspace \fi |
| 13151 |
% \end{macrocode} |
| 13152 |
% Now we calculate the margin and line width of the wrapped part \ldots |
| 13153 |
% \begin{macrocode} |
| 13154 |
\@tempdimc-\@tempdima \advance\@tempdimc\linewidth |
| 13155 |
\advance\@tempdima\@totalleftmargin |
| 13156 |
% \end{macrocode} |
| 13157 |
% \ldots\space and store it in |\lst@breakshape|. |
| 13158 |
% \begin{macrocode} |
| 13159 |
\xdef\lst@breakshape{\noexpand\lst@breakcurrindent \the\@tempdimc}% |
| 13160 |
\xdef\lst@breakcurrindent{\the\@tempdima}} |
| 13161 |
\global\let\lst@breakcurrindent\z@ % init |
| 13162 |
% \end{macrocode} |
| 13163 |
% The initialization of |\lst@breakcurrindent| has been added after a bug |
| 13164 |
% report by \lsthelper{Alvaro~Herrera}{2002/12/09}{`undefined control |
| 13165 |
% sequence \lst@breakcurrindent' with fancyvrb and breaklines}. |
| 13166 |
% \begin{TODO} |
| 13167 |
% We could speed this up by allocating two global dimensions. |
| 13168 |
% \end{TODO} |
| 13169 |
% \end{macro} |
| 13170 |
% |
| 13171 |
% \begin{macro}{\lst@breakshape} |
| 13172 |
% \lsthelper{Andreas~Deininger}{2000/08/25}{`breaklines,first>1' leads to |
| 13173 |
% ``undefined control sequence'' error} reported a problem which is resolved |
| 13174 |
% by providing a default break shape. |
| 13175 |
% \begin{macrocode} |
| 13176 |
\gdef\lst@breakshape{\@totalleftmargin \linewidth} |
| 13177 |
% \end{macrocode} |
| 13178 |
% \end{macro} |
| 13179 |
% |
| 13180 |
% \begin{macro}{\lst@breakProcessOther} |
| 13181 |
% is the same as |\lst@ProcessOther| except that it also outputs the current |
| 13182 |
% token string. This inserts a potential linebreak point. |
| 13183 |
% Only the closing parenthesis uses this macro yet. |
| 13184 |
% \begin{macrocode} |
| 13185 |
\gdef\lst@breakProcessOther#1{\lst@ProcessOther#1\lst@OutputOther} |
| 13186 |
\lst@AddToHook{SelectCharTable} |
| 13187 |
{\lst@ifbreaklines \lst@Def{`)}{\lst@breakProcessOther)}\fi} |
| 13188 |
% \end{macrocode} |
| 13189 |
% A bug reported by \lsthelper{Gabriel~Tauro}{2001/04/18}{unexpected `)' if |
| 13190 |
% the character appears before first printed line} has been removed by using |
| 13191 |
% |\lst@ProcessOther| instead of |\lst@AppendOther|. |
| 13192 |
% \end{macro} |
| 13193 |
% |
| 13194 |
% \begin{macrocode} |
| 13195 |
\lst@EndAspect |
| 13196 |
%</misc> |
| 13197 |
% \end{macrocode} |
| 13198 |
% \end{aspect} |
| 13199 |
% |
| 13200 |
% |
| 13201 |
% \subsection{Frames} |
| 13202 |
% |
| 13203 |
% \begin{aspect}{frames} |
| 13204 |
% Another aspect. |
| 13205 |
% \begin{macrocode} |
| 13206 |
%<*misc> |
| 13207 |
\lst@BeginAspect[lineshape]{frames} |
| 13208 |
% \end{macrocode} |
| 13209 |
% |
| 13210 |
% \begin{lstkey}{framexleftmargin} |
| 13211 |
% \begin{lstkey}{framexrightmargin} |
| 13212 |
% \begin{lstkey}{framextopmargin} |
| 13213 |
% \begin{lstkey}{framexbottommargin} |
| 13214 |
% These keys just save the argument. |
| 13215 |
% \begin{macrocode} |
| 13216 |
\lst@Key{framexleftmargin}{\z@}{\def\lst@framexleftmargin{#1}} |
| 13217 |
\lst@Key{framexrightmargin}{\z@}{\def\lst@framexrightmargin{#1}} |
| 13218 |
\lst@Key{framextopmargin}{\z@}{\def\lst@framextopmargin{#1}} |
| 13219 |
\lst@Key{framexbottommargin}{\z@}{\def\lst@framexbottommargin{#1}} |
| 13220 |
% \end{macrocode} |
| 13221 |
% \end{lstkey} |
| 13222 |
% \end{lstkey} |
| 13223 |
% \end{lstkey} |
| 13224 |
% \end{lstkey} |
| 13225 |
% |
| 13226 |
% \begin{lstkey}{backgroundcolor} |
| 13227 |
% \lsthelper{Ralf~Imh\"auser}{2000/01/08}{coloured background} inspired the |
| 13228 |
% key \keyname{backgroundcolor}. All keys save the argument, and \ldots |
| 13229 |
% \begin{macrocode} |
| 13230 |
\lst@Key{backgroundcolor}{}{\def\lst@bkgcolor{#1}} |
| 13231 |
\lst@Key{fillcolor}{}{\def\lst@fillcolor{#1}} |
| 13232 |
\lst@Key{rulecolor}{}{\def\lst@rulecolor{#1}} |
| 13233 |
\lst@Key{rulesepcolor}{}{\def\lst@rulesepcolor{#1}} |
| 13234 |
% \end{macrocode} |
| 13235 |
% \ldots\space some have default settings if they are empty. |
| 13236 |
% \begin{macrocode} |
| 13237 |
\lst@AddToHook{Init}{% |
| 13238 |
\ifx\lst@fillcolor\@empty |
| 13239 |
\let\lst@fillcolor\lst@bkgcolor |
| 13240 |
\fi |
| 13241 |
\ifx\lst@rulesepcolor\@empty |
| 13242 |
\let\lst@rulesepcolor\lst@fillcolor |
| 13243 |
\fi} |
| 13244 |
% \end{macrocode} |
| 13245 |
% \end{lstkey} |
| 13246 |
% |
| 13247 |
% \begin{lstkey}{rulesep} |
| 13248 |
% \begin{lstkey}{framerule} |
| 13249 |
% \begin{lstkey}{framesep} |
| 13250 |
% \begin{lstkey}{frameshape} |
| 13251 |
% Another set of keys, which mainly save their respective argument. |
| 13252 |
% \keyname{frameshape} capitalizes all letters, and checks whether at least one |
| 13253 |
% round corner is specified. Eventually we define |\lst@frame| to be empty if |
| 13254 |
% and only if there is no frameshape. |
| 13255 |
% \begin{macrocode} |
| 13256 |
\lst@Key{rulesep}{2pt}{\def\lst@rulesep{#1}} |
| 13257 |
\lst@Key{framerule}{.4pt}{\def\lst@framerulewidth{#1}} |
| 13258 |
\lst@Key{framesep}{3pt}{\def\lst@frametextsep{#1}} |
| 13259 |
\lst@Key{frameshape}{}{% |
| 13260 |
\let\lst@xrulecolor\@empty |
| 13261 |
\lstKV@FourArg{#1}% |
| 13262 |
{\uppercase{\def\lst@frametshape{##1}}% |
| 13263 |
\uppercase{\def\lst@framelshape{##2}}% |
| 13264 |
\uppercase{\def\lst@framershape{##3}}% |
| 13265 |
\uppercase{\def\lst@framebshape{##4}}% |
| 13266 |
\let\lst@ifframeround\iffalse |
| 13267 |
\lst@IfSubstring R\lst@frametshape{\let\lst@ifframeround\iftrue}{}% |
| 13268 |
\lst@IfSubstring R\lst@framebshape{\let\lst@ifframeround\iftrue}{}% |
| 13269 |
\def\lst@frame{##1##2##3##4}}} |
| 13270 |
% \end{macrocode} |
| 13271 |
% \end{lstkey} |
| 13272 |
% \end{lstkey} |
| 13273 |
% \end{lstkey} |
| 13274 |
% \end{lstkey} |
| 13275 |
% |
| 13276 |
% \begin{lstkey}{frameround} |
| 13277 |
% \begin{lstkey}{frame} |
| 13278 |
% We have to do some conversion here. |
| 13279 |
% \begin{macrocode} |
| 13280 |
\lst@Key{frameround}\relax |
| 13281 |
{\uppercase{\def\lst@frameround{#1}}% |
| 13282 |
\expandafter\lstframe@\lst@frameround ffff\relax} |
| 13283 |
\global\let\lst@frameround\@empty |
| 13284 |
% \end{macrocode} |
| 13285 |
% In case of an verbose argument, we use the |trbl|-subset replacement. |
| 13286 |
% \begin{macrocode} |
| 13287 |
\lst@Key{frame}\relax{% |
| 13288 |
\let\lst@xrulecolor\@empty |
| 13289 |
\lstKV@SwitchCases{#1}% |
| 13290 |
{none:\let\lst@frame\@empty\\% |
| 13291 |
leftline:\def\lst@frame{l}\\% |
| 13292 |
topline:\def\lst@frame{t}\\% |
| 13293 |
bottomline:\def\lst@frame{b}\\% |
| 13294 |
lines:\def\lst@frame{tb}\\% |
| 13295 |
single:\def\lst@frame{trbl}\\% |
| 13296 |
shadowbox:\def\lst@frame{tRBl}% |
| 13297 |
\def\lst@xrulecolor{\lst@rulesepcolor}% |
| 13298 |
\def\lst@rulesep{\lst@frametextsep}% |
| 13299 |
}{\def\lst@frame{#1}}% |
| 13300 |
\expandafter\lstframe@\lst@frameround ffff\relax} |
| 13301 |
% \end{macrocode} |
| 13302 |
% Adding |t|, |r|, |b|, and |l| in case of their upper case versions makes |
| 13303 |
% later tests easier. |
| 13304 |
% \begin{macrocode} |
| 13305 |
\gdef\lstframe@#1#2#3#4#5\relax{% |
| 13306 |
\lst@IfSubstring T\lst@frame{\edef\lst@frame{t\lst@frame}}{}% |
| 13307 |
\lst@IfSubstring R\lst@frame{\edef\lst@frame{r\lst@frame}}{}% |
| 13308 |
\lst@IfSubstring B\lst@frame{\edef\lst@frame{b\lst@frame}}{}% |
| 13309 |
\lst@IfSubstring L\lst@frame{\edef\lst@frame{l\lst@frame}}{}% |
| 13310 |
% \end{macrocode} |
| 13311 |
% We now check top and bottom frame rules, \ldots |
| 13312 |
% \begin{macrocode} |
| 13313 |
\let\lst@frametshape\@empty \let\lst@framebshape\@empty |
| 13314 |
\lst@frameCheck |
| 13315 |
ltr\lst@framelshape\lst@frametshape\lst@framershape #4#1% |
| 13316 |
\lst@frameCheck |
| 13317 |
LTR\lst@framelshape\lst@frametshape\lst@framershape #4#1% |
| 13318 |
\lst@frameCheck |
| 13319 |
lbr\lst@framelshape\lst@framebshape\lst@framershape #3#2% |
| 13320 |
\lst@frameCheck |
| 13321 |
LBR\lst@framelshape\lst@framebshape\lst@framershape #3#2% |
| 13322 |
% \end{macrocode} |
| 13323 |
% \ldots\space look for round corners \ldots |
| 13324 |
% \begin{macrocode} |
| 13325 |
\let\lst@ifframeround\iffalse |
| 13326 |
\lst@IfSubstring R\lst@frametshape{\let\lst@ifframeround\iftrue}{}% |
| 13327 |
\lst@IfSubstring R\lst@framebshape{\let\lst@ifframeround\iftrue}{}% |
| 13328 |
% \end{macrocode} |
| 13329 |
% and define left and right frame shape. |
| 13330 |
% \begin{macrocode} |
| 13331 |
\let\lst@framelshape\@empty \let\lst@framershape\@empty |
| 13332 |
\lst@IfSubstring L\lst@frame |
| 13333 |
{\def\lst@framelshape{YY}}% |
| 13334 |
{\lst@IfSubstring l\lst@frame{\def\lst@framelshape{Y}}{}}% |
| 13335 |
\lst@IfSubstring R\lst@frame |
| 13336 |
{\def\lst@framershape{YY}}% |
| 13337 |
{\lst@IfSubstring r\lst@frame{\def\lst@framershape{Y}}{}}} |
| 13338 |
% \end{macrocode} |
| 13339 |
% Now comes the macro used to define top and bottom frame shape. |
| 13340 |
% It extends the macro |#5|. |
| 13341 |
% The last two arguments show whether left and right corners are round. |
| 13342 |
% |#4| and |#6| are temporary macros. |
| 13343 |
% |#1#2#3| are the three characters we test for. |
| 13344 |
% \begin{macrocode} |
| 13345 |
\gdef\lst@frameCheck#1#2#3#4#5#6#7#8{% |
| 13346 |
\lst@IfSubstring #1\lst@frame |
| 13347 |
{\if #7T\def#4{R}\else \def#4{Y}\fi}% |
| 13348 |
{\def#4{N}}% |
| 13349 |
\lst@IfSubstring #3\lst@frame |
| 13350 |
{\if #8T\def#6{R}\else \def#6{Y}\fi}% |
| 13351 |
{\def#6{N}}% |
| 13352 |
\lst@IfSubstring #2\lst@frame{\edef#5{#5#4Y#6}}{}} |
| 13353 |
% \end{macrocode} |
| 13354 |
% For text style listings all frames and the background color are |
| 13355 |
% deactivated -- added after bug reports by \lsthelper{Stephen~Reindl}% |
| 13356 |
% {2002/06/04}{frames not deactivated for text style listings} and |
| 13357 |
% \lsthelper{Thomas~ten~Cate}{2006/07/14}{inline listings get background |
| 13358 |
% color after a line break} |
| 13359 |
% \begin{macrocode} |
| 13360 |
\lst@AddToHook{TextStyle} |
| 13361 |
{\let\lst@frame\@empty |
| 13362 |
\let\lst@frametshape\@empty |
| 13363 |
\let\lst@framershape\@empty |
| 13364 |
\let\lst@framebshape\@empty |
| 13365 |
\let\lst@framelshape\@empty |
| 13366 |
\let\lst@bkgcolor\@empty} |
| 13367 |
% \end{macrocode} |
| 13368 |
% \end{lstkey} |
| 13369 |
% \end{lstkey} |
| 13370 |
% |
| 13371 |
% As per a bug report by \lsthelper{Ignacio~Fern\'andez~Galv\'an}{2006/07/26}% |
| 13372 |
% {Frame with background color has slight hole on left side}, the small section |
| 13373 |
% of background color to the left of the margin is now drawn before the left |
| 13374 |
% side of the frame is drawn, so that they overlap correctly in Acrobat. |
| 13375 |
% |
| 13376 |
% \begin{macro}{\lst@frameMakeBoxV} |
| 13377 |
% \begin{macrocode} |
| 13378 |
\gdef\lst@frameMakeBoxV#1#2#3{% |
| 13379 |
\setbox#1\hbox{% |
| 13380 |
\color@begingroup \lst@rulecolor |
| 13381 |
\ifx\lst@framelshape\@empty |
| 13382 |
\else |
| 13383 |
\llap{% |
| 13384 |
\lst@frameBlock\lst@fillcolor\lst@frametextsep{#2}{#3}% |
| 13385 |
\kern\lst@framexleftmargin}% |
| 13386 |
\fi |
| 13387 |
\llap{\setbox\z@\hbox{\vrule\@width\z@\@height#2\@depth#3% |
| 13388 |
\lst@frameL}% |
| 13389 |
\rlap{\lst@frameBlock\lst@rulesepcolor{\wd\z@}% |
| 13390 |
{\ht\z@}{\dp\z@}}% |
| 13391 |
\box\z@ |
| 13392 |
\kern\lst@frametextsep\relax |
| 13393 |
\kern\lst@framexleftmargin}% |
| 13394 |
\rlap{\kern-\lst@framexleftmargin |
| 13395 |
\@tempdima\linewidth |
| 13396 |
\advance\@tempdima\lst@framexleftmargin |
| 13397 |
\advance\@tempdima\lst@framexrightmargin |
| 13398 |
\lst@frameBlock\lst@bkgcolor\@tempdima{#2}{#3}% |
| 13399 |
\ifx\lst@framershape\@empty |
| 13400 |
\kern\lst@frametextsep\relax |
| 13401 |
\else |
| 13402 |
\lst@frameBlock\lst@fillcolor\lst@frametextsep{#2}{#3}% |
| 13403 |
\fi |
| 13404 |
\setbox\z@\hbox{\vrule\@width\z@\@height#2\@depth#3% |
| 13405 |
\lst@frameR}% |
| 13406 |
\rlap{\lst@frameBlock\lst@rulesepcolor{\wd\z@}% |
| 13407 |
{\ht\z@}{\dp\z@}}% |
| 13408 |
\box\z@}% |
| 13409 |
\color@endgroup}} |
| 13410 |
% \end{macrocode} |
| 13411 |
% \end{macro} |
| 13412 |
% |
| 13413 |
% \begin{macro}{\lst@frameBlock} |
| 13414 |
% \begin{macrocode} |
| 13415 |
\gdef\lst@frameBlock#1#2#3#4{% |
| 13416 |
\color@begingroup |
| 13417 |
#1% |
| 13418 |
\setbox\z@\hbox{\vrule\@height#3\@depth#4% |
| 13419 |
\ifx#1\@empty \@width\z@ \kern#2\relax |
| 13420 |
\else \@width#2\relax \fi}% |
| 13421 |
\box\z@ |
| 13422 |
\color@endgroup} |
| 13423 |
% \end{macrocode} |
| 13424 |
% \end{macro} |
| 13425 |
% |
| 13426 |
% \begin{macro}{\lst@frameR} |
| 13427 |
% typesets right rules. |
| 13428 |
% We only need to iterate through |\lst@framershape|. |
| 13429 |
% \begin{macrocode} |
| 13430 |
\gdef\lst@frameR{% |
| 13431 |
\expandafter\lst@frameR@\lst@framershape\relax |
| 13432 |
\kern-\lst@rulesep} |
| 13433 |
\gdef\lst@frameR@#1{% |
| 13434 |
\ifx\relax#1\@empty\else |
| 13435 |
\if #1Y\lst@framevrule \else \kern\lst@framerulewidth \fi |
| 13436 |
\kern\lst@rulesep |
| 13437 |
\expandafter\lst@frameR@b |
| 13438 |
\fi} |
| 13439 |
\gdef\lst@frameR@b#1{% |
| 13440 |
\ifx\relax#1\@empty |
| 13441 |
\else |
| 13442 |
\if #1Y\color@begingroup |
| 13443 |
\lst@xrulecolor |
| 13444 |
\lst@framevrule |
| 13445 |
\color@endgroup |
| 13446 |
\else |
| 13447 |
\kern\lst@framerulewidth |
| 13448 |
\fi |
| 13449 |
\kern\lst@rulesep |
| 13450 |
\expandafter\lst@frameR@ |
| 13451 |
\fi} |
| 13452 |
% \end{macrocode} |
| 13453 |
% \end{macro} |
| 13454 |
% |
| 13455 |
% \begin{macro}{\lst@frameL} |
| 13456 |
% Ditto left rules. |
| 13457 |
% \begin{macrocode} |
| 13458 |
\gdef\lst@frameL{% |
| 13459 |
\kern-\lst@rulesep |
| 13460 |
\expandafter\lst@frameL@\lst@framelshape\relax} |
| 13461 |
\gdef\lst@frameL@#1{% |
| 13462 |
\ifx\relax#1\@empty\else |
| 13463 |
\kern\lst@rulesep |
| 13464 |
\if#1Y\lst@framevrule \else \kern\lst@framerulewidth \fi |
| 13465 |
\expandafter\lst@frameL@ |
| 13466 |
\fi} |
| 13467 |
% \end{macrocode} |
| 13468 |
% \end{macro} |
| 13469 |
% |
| 13470 |
% \begin{macro}{\lst@frameH} |
| 13471 |
% This is the central macro used to draw top and bottom frame rules. |
| 13472 |
% The first argument is either |T| or |B| and the second contains the shape. |
| 13473 |
% We use |\@tempcntb| as size counter. |
| 13474 |
% \begin{macrocode} |
| 13475 |
\gdef\lst@frameH#1#2{% |
| 13476 |
\global\let\lst@framediml\z@ \global\let\lst@framedimr\z@ |
| 13477 |
\setbox\z@\hbox{}\@tempcntb\z@ |
| 13478 |
\expandafter\lst@frameH@\expandafter#1#2\relax\relax\relax |
| 13479 |
\@tempdimb\lst@frametextsep\relax |
| 13480 |
\advance\@tempdimb\lst@framerulewidth\relax |
| 13481 |
\@tempdimc-\@tempdimb |
| 13482 |
\advance\@tempdimc\ht\z@ |
| 13483 |
\advance\@tempdimc\dp\z@ |
| 13484 |
\setbox\z@=\hbox{% |
| 13485 |
\lst@frameHBkg\lst@fillcolor\@tempdimb\@firstoftwo |
| 13486 |
\if#1T\rlap{\raise\dp\@tempboxa\box\@tempboxa}% |
| 13487 |
\else\rlap{\lower\ht\@tempboxa\box\@tempboxa}\fi |
| 13488 |
\lst@frameHBkg\lst@rulesepcolor\@tempdimc\@secondoftwo |
| 13489 |
\advance\@tempdimb\ht\@tempboxa |
| 13490 |
\if#1T\rlap{\raise\lst@frametextsep\box\@tempboxa}% |
| 13491 |
\else\rlap{\lower\@tempdimb\box\@tempboxa}\fi |
| 13492 |
\rlap{\box\z@}% |
| 13493 |
}} |
| 13494 |
\gdef\lst@frameH@#1#2#3#4{% |
| 13495 |
\ifx\relax#4\@empty\else |
| 13496 |
\lst@frameh \@tempcntb#1#2#3#4% |
| 13497 |
\advance\@tempcntb\@ne |
| 13498 |
\expandafter\lst@frameH@\expandafter#1% |
| 13499 |
\fi} |
| 13500 |
\gdef\lst@frameHBkg#1#2#3{% |
| 13501 |
\setbox\@tempboxa\hbox{% |
| 13502 |
\kern-\lst@framexleftmargin |
| 13503 |
#3{\kern-\lst@framediml\relax}{\@tempdima\z@}% |
| 13504 |
\ifdim\lst@framediml>\@tempdimb |
| 13505 |
#3{\@tempdima\lst@framediml \advance\@tempdima-\@tempdimb |
| 13506 |
\lst@frameBlock\lst@rulesepcolor\@tempdima\@tempdimb\z@}% |
| 13507 |
{\kern-\lst@framediml |
| 13508 |
\advance\@tempdima\lst@framediml\relax}% |
| 13509 |
\fi |
| 13510 |
#3{\@tempdima\z@ |
| 13511 |
\ifx\lst@framelshape\@empty\else |
| 13512 |
\advance\@tempdima\@tempdimb |
| 13513 |
\fi |
| 13514 |
\ifx\lst@framershape\@empty\else |
| 13515 |
\advance\@tempdima\@tempdimb |
| 13516 |
\fi}% |
| 13517 |
{\ifdim\lst@framedimr>\@tempdimb |
| 13518 |
\advance\@tempdima\lst@framedimr\relax |
| 13519 |
\fi}% |
| 13520 |
\advance\@tempdima\linewidth |
| 13521 |
\advance\@tempdima\lst@framexleftmargin |
| 13522 |
\advance\@tempdima\lst@framexrightmargin |
| 13523 |
\lst@frameBlock#1\@tempdima#2\z@ |
| 13524 |
#3{\ifdim\lst@framedimr>\@tempdimb |
| 13525 |
\@tempdima-\@tempdimb |
| 13526 |
\advance\@tempdima\lst@framedimr\relax |
| 13527 |
\lst@frameBlock\lst@rulesepcolor\@tempdima\@tempdimb\z@ |
| 13528 |
\fi}{}% |
| 13529 |
}} |
| 13530 |
% \end{macrocode} |
| 13531 |
% \end{macro} |
| 13532 |
% |
| 13533 |
% \begin{macro}{\lst@frameh} |
| 13534 |
% This is the low-level macro used to draw top and bottom frame rules. |
| 13535 |
% It \emph{adds} one rule plus corners to box 0. |
| 13536 |
% The first parameter gives the size of the corners and the second is either |
| 13537 |
% |T| or |B|. |
| 13538 |
% |#3#4#5| is a left-to-right description of the frame and is in |
| 13539 |
% $\{$\texttt{Y,N,R}$\}\times\{$\texttt{Y,N}$\}\times\{$\texttt{Y,N,R}$\}$. |
| 13540 |
% We move to the correct horizontal position, set the left corner, the |
| 13541 |
% horizontal line, and the right corner. |
| 13542 |
% \begin{macrocode} |
| 13543 |
\gdef\lst@frameh#1#2#3#4#5{% |
| 13544 |
\lst@frameCalcDimA#1% |
| 13545 |
\lst@ifframeround \@getcirc\@tempdima \fi |
| 13546 |
% \end{macrocode} |
| 13547 |
% \begin{macrocode} |
| 13548 |
\setbox\z@\hbox{% |
| 13549 |
\begingroup |
| 13550 |
\setbox\z@\hbox{% |
| 13551 |
\kern-\lst@framexleftmargin |
| 13552 |
\color@begingroup |
| 13553 |
\ifnum#1=\z@ \lst@rulecolor \else \lst@xrulecolor \fi |
| 13554 |
% \end{macrocode} |
| 13555 |
% |\lst@frameCorner| gets four arguments: |
| 13556 |
% |\llap|, |TL| or |BL|, the corner type $\in\{$\texttt{Y,N,R}$\}$, and the |
| 13557 |
% size |#1|. |
| 13558 |
% \begin{macrocode} |
| 13559 |
\lst@frameCornerX\llap{#2L}#3#1% |
| 13560 |
\ifdim\lst@framediml<\@tempdimb |
| 13561 |
\xdef\lst@framediml{\the\@tempdimb}% |
| 13562 |
\fi |
| 13563 |
\begingroup |
| 13564 |
\if#4Y\else \let\lst@framerulewidth\z@ \fi |
| 13565 |
\@tempdima\lst@framexleftmargin |
| 13566 |
\advance\@tempdima\lst@framexrightmargin |
| 13567 |
\advance\@tempdima\linewidth |
| 13568 |
\vrule\@width\@tempdima\@height\lst@framerulewidth \@depth\z@ |
| 13569 |
\endgroup |
| 13570 |
\lst@frameCornerX\rlap{#2R}#5#1% |
| 13571 |
\ifdim\lst@framedimr<\@tempdimb |
| 13572 |
\xdef\lst@framedimr{\the\@tempdimb}% |
| 13573 |
\fi |
| 13574 |
\color@endgroup}% |
| 13575 |
% \end{macrocode} |
| 13576 |
% \begin{macrocode} |
| 13577 |
\if#2T\rlap{\raise\dp\z@\box\z@}% |
| 13578 |
\else\rlap{\lower\ht\z@\box\z@}\fi |
| 13579 |
\endgroup |
| 13580 |
\box\z@}} |
| 13581 |
% \end{macrocode} |
| 13582 |
% \end{macro} |
| 13583 |
% |
| 13584 |
% \begin{macro}{\lst@frameCornerX} |
| 13585 |
% typesets a single corner and returns |\@tempdimb|, the width of the corner. |
| 13586 |
% \begin{macrocode} |
| 13587 |
\gdef\lst@frameCornerX#1#2#3#4{% |
| 13588 |
\setbox\@tempboxa\hbox{\csname\@lst @frame\if#3RR\fi #2\endcsname}% |
| 13589 |
\@tempdimb\wd\@tempboxa |
| 13590 |
\if #3R% |
| 13591 |
#1{\box\@tempboxa}% |
| 13592 |
\else |
| 13593 |
\if #3Y\expandafter#1\else |
| 13594 |
\@tempdimb\z@ \expandafter\vphantom \fi |
| 13595 |
{\box\@tempboxa}% |
| 13596 |
\fi} |
| 13597 |
% \end{macrocode} |
| 13598 |
% \end{macro} |
| 13599 |
% |
| 13600 |
% \begin{macro}{\lst@frameCalcDimA} |
| 13601 |
% calculates an all over width; used by |\lst@frameh| and |\lst@frameInit|. |
| 13602 |
% \begin{macrocode} |
| 13603 |
\gdef\lst@frameCalcDimA#1{% |
| 13604 |
\@tempdima\lst@rulesep |
| 13605 |
\advance\@tempdima\lst@framerulewidth |
| 13606 |
\multiply\@tempdima#1\relax |
| 13607 |
\advance\@tempdima\lst@frametextsep |
| 13608 |
\advance\@tempdima\lst@framerulewidth |
| 13609 |
\multiply\@tempdima\tw@} |
| 13610 |
% \end{macrocode} |
| 13611 |
% \end{macro} |
| 13612 |
% |
| 13613 |
% \begin{macro}{\lst@frameInit} |
| 13614 |
% First we look which frame types we have on the left and on the right. |
| 13615 |
% We speed up things if there are no vertical rules. |
| 13616 |
% \begin{macrocode} |
| 13617 |
\lst@AddToHook{Init}{\lst@frameInit} |
| 13618 |
\newbox\lst@framebox |
| 13619 |
\gdef\lst@frameInit{% |
| 13620 |
\ifx\lst@framelshape\@empty \let\lst@frameL\@empty \fi |
| 13621 |
\ifx\lst@framershape\@empty \let\lst@frameR\@empty \fi |
| 13622 |
\def\lst@framevrule{\vrule\@width\lst@framerulewidth\relax}% |
| 13623 |
% \end{macrocode} |
| 13624 |
% We adjust values to round corners if necessary. |
| 13625 |
% \begin{macrocode} |
| 13626 |
\lst@ifframeround |
| 13627 |
\lst@frameCalcDimA\z@ \@getcirc\@tempdima |
| 13628 |
\@tempdimb\@tempdima \divide\@tempdimb\tw@ |
| 13629 |
\advance\@tempdimb -\@wholewidth |
| 13630 |
\edef\lst@frametextsep{\the\@tempdimb}% |
| 13631 |
\edef\lst@framerulewidth{\the\@wholewidth}% |
| 13632 |
% \end{macrocode} |
| 13633 |
% \begin{macrocode} |
| 13634 |
\lst@frameCalcDimA\@ne \@getcirc\@tempdima |
| 13635 |
\@tempdimb\@tempdima \divide\@tempdimb\tw@ |
| 13636 |
\advance\@tempdimb -\tw@\@wholewidth |
| 13637 |
\advance\@tempdimb -\lst@frametextsep |
| 13638 |
\edef\lst@rulesep{\the\@tempdimb}% |
| 13639 |
\fi |
| 13640 |
% \end{macrocode} |
| 13641 |
% \begin{macrocode} |
| 13642 |
\lst@frameMakeBoxV\lst@framebox{\ht\strutbox}{\dp\strutbox}% |
| 13643 |
\def\lst@framelr{\copy\lst@framebox}% |
| 13644 |
% \end{macrocode} |
| 13645 |
% Finally we typeset the rules (+ corners). |
| 13646 |
% We possibly need to insert negative |\vskip| to remove space between |
| 13647 |
% preceding text and top rule. |
| 13648 |
% \begin{TODO} |
| 13649 |
% Use |\vspace| instead of |\vskip|? |
| 13650 |
% \end{TODO} |
| 13651 |
% \begin{macrocode} |
| 13652 |
\ifx\lst@frametshape\@empty\else |
| 13653 |
\lst@frameH T\lst@frametshape |
| 13654 |
\ifvoid\z@\else |
| 13655 |
\par\lst@parshape |
| 13656 |
\@tempdima-\baselineskip \advance\@tempdima\ht\z@ |
| 13657 |
\ifdim\prevdepth<\@cclvi\p@\else |
| 13658 |
\advance\@tempdima\prevdepth |
| 13659 |
\fi |
| 13660 |
\ifdim\@tempdima<\z@ |
| 13661 |
\vskip\@tempdima\vskip\lineskip |
| 13662 |
\fi |
| 13663 |
\noindent\box\z@\par |
| 13664 |
\lineskiplimit\maxdimen \lineskip\z@ |
| 13665 |
\fi |
| 13666 |
\lst@frameSpreadV\lst@framextopmargin |
| 13667 |
\fi} |
| 13668 |
% \end{macrocode} |
| 13669 |
% |\parshape\lst@parshape| ensures that the top rules correctly indented. |
| 13670 |
% The bug was reported by \lsthelper{Marcin~Kasperski}{1999/04/28}{top rules |
| 13671 |
% indented right inside itemize}. |
| 13672 |
% |
| 13673 |
% We typeset left and right rules every line. |
| 13674 |
% \begin{macrocode} |
| 13675 |
\lst@AddToHook{EveryLine}{\lst@framelr} |
| 13676 |
\global\let\lst@framelr\@empty |
| 13677 |
% \end{macrocode} |
| 13678 |
% \end{macro} |
| 13679 |
% |
| 13680 |
% \begin{macro}{\lst@frameExit} |
| 13681 |
% The rules at the bottom. |
| 13682 |
% \begin{macrocode} |
| 13683 |
\lst@AddToHook{DeInit} |
| 13684 |
{\ifx\lst@framebshape\@empty\else \lst@frameExit \fi} |
| 13685 |
\gdef\lst@frameExit{% |
| 13686 |
\lst@frameSpreadV\lst@framexbottommargin |
| 13687 |
\lst@frameH B\lst@framebshape |
| 13688 |
\ifvoid\z@\else |
| 13689 |
\everypar{}\par\lst@parshape\nointerlineskip\noindent\box\z@ |
| 13690 |
\fi} |
| 13691 |
% \end{macrocode} |
| 13692 |
% \end{macro} |
| 13693 |
% |
| 13694 |
% \begin{macro}{\lst@frameSpreadV} |
| 13695 |
% sets rules for vertical spread. |
| 13696 |
% \begin{macrocode} |
| 13697 |
\gdef\lst@frameSpreadV#1{% |
| 13698 |
\ifdim\z@=#1\else |
| 13699 |
\everypar{}\par\lst@parshape\nointerlineskip\noindent |
| 13700 |
\lst@frameMakeBoxV\z@{#1}{\z@}% |
| 13701 |
\box\z@ |
| 13702 |
\fi} |
| 13703 |
% \end{macrocode} |
| 13704 |
% \end{macro} |
| 13705 |
% |
| 13706 |
% \begin{macro}{\lst@frameTR} |
| 13707 |
% \begin{macro}{\lst@frameBR} |
| 13708 |
% \begin{macro}{\lst@frameBL} |
| 13709 |
% \begin{macro}{\lst@frameTL} |
| 13710 |
% These macros make a vertical and horizontal rule. |
| 13711 |
% The implicit argument |\@tempdima| gives the size of two corners and is |
| 13712 |
% provided by |\lst@frameh|. |
| 13713 |
% \begin{macrocode} |
| 13714 |
\gdef\lst@frameTR{% |
| 13715 |
\vrule\@width.5\@tempdima\@height\lst@framerulewidth\@depth\z@ |
| 13716 |
\kern-\lst@framerulewidth |
| 13717 |
\raise\lst@framerulewidth\hbox{% |
| 13718 |
\vrule\@width\lst@framerulewidth\@height\z@\@depth.5\@tempdima}} |
| 13719 |
\gdef\lst@frameBR{% |
| 13720 |
\vrule\@width.5\@tempdima\@height\lst@framerulewidth\@depth\z@ |
| 13721 |
\kern-\lst@framerulewidth |
| 13722 |
\vrule\@width\lst@framerulewidth\@height.5\@tempdima\@depth\z@} |
| 13723 |
\gdef\lst@frameBL{% |
| 13724 |
\vrule\@width\lst@framerulewidth\@height.5\@tempdima\@depth\z@ |
| 13725 |
\kern-\lst@framerulewidth |
| 13726 |
\vrule\@width.5\@tempdima\@height\lst@framerulewidth\@depth\z@} |
| 13727 |
\gdef\lst@frameTL{% |
| 13728 |
\raise\lst@framerulewidth\hbox{% |
| 13729 |
\vrule\@width\lst@framerulewidth\@height\z@\@depth.5\@tempdima}% |
| 13730 |
\kern-\lst@framerulewidth |
| 13731 |
\vrule\@width.5\@tempdima\@height\lst@framerulewidth\@depth\z@} |
| 13732 |
% \end{macrocode} |
| 13733 |
% \end{macro}\end{macro}\end{macro}\end{macro} |
| 13734 |
% |
| 13735 |
% \begin{macro}{\lst@frameRoundT} |
| 13736 |
% \begin{macro}{\lst@frameRoundB} |
| 13737 |
% are helper macros to typeset round corners. We set height and depth to |
| 13738 |
% the visible parts of the circle font. |
| 13739 |
% \begin{macrocode} |
| 13740 |
\gdef\lst@frameRoundT{% |
| 13741 |
\setbox\@tempboxa\hbox{\@circlefnt\char\@tempcnta}% |
| 13742 |
\ht\@tempboxa\lst@framerulewidth |
| 13743 |
\box\@tempboxa} |
| 13744 |
\gdef\lst@frameRoundB{% |
| 13745 |
\setbox\@tempboxa\hbox{\@circlefnt\char\@tempcnta}% |
| 13746 |
\dp\@tempboxa\z@ |
| 13747 |
\box\@tempboxa} |
| 13748 |
% \end{macrocode} |
| 13749 |
% \end{macro} |
| 13750 |
% \end{macro} |
| 13751 |
% |
| 13752 |
% \begin{macro}{\lst@frameRTR} |
| 13753 |
% \begin{macro}{\lst@frameRBR} |
| 13754 |
% \begin{macro}{\lst@frameRBL} |
| 13755 |
% \begin{macro}{\lst@frameRTL} |
| 13756 |
% The round corners. |
| 13757 |
% \begin{macrocode} |
| 13758 |
\gdef\lst@frameRTR{% |
| 13759 |
\hb@[email protected]\@tempdima{\kern-\lst@framerulewidth |
| 13760 |
\kern.5\@tempdima \lst@frameRoundT \hss}} |
| 13761 |
\gdef\lst@frameRBR{% |
| 13762 |
\hb@[email protected]\@tempdima{\kern-\lst@framerulewidth |
| 13763 |
\advance\@tempcnta\@ne \kern.5\@tempdima \lst@frameRoundB \hss}} |
| 13764 |
\gdef\lst@frameRBL{% |
| 13765 |
\advance\@tempcnta\tw@ \lst@frameRoundB |
| 13766 |
\kern-.5\@tempdima} |
| 13767 |
\gdef\lst@frameRTL{% |
| 13768 |
\advance\@tempcnta\thr@@\lst@frameRoundT |
| 13769 |
\kern-.5\@tempdima} |
| 13770 |
% \end{macrocode} |
| 13771 |
% \end{macro}\end{macro}\end{macro}\end{macro} |
| 13772 |
% |
| 13773 |
% \begin{macrocode} |
| 13774 |
\lst@EndAspect |
| 13775 |
%</misc> |
| 13776 |
% \end{macrocode} |
| 13777 |
% \end{aspect} |
| 13778 |
% |
| 13779 |
% |
| 13780 |
% \subsection{Macro use for make} |
| 13781 |
% |
| 13782 |
% \begin{aspect}{make} |
| 13783 |
% \begin{macro}{\lst@makemode} |
| 13784 |
% \begin{macro}{\lst@ifmakekey} |
| 13785 |
% If we've entered the special mode for Make, we save whether the last |
| 13786 |
% identifier has been a first order keyword. |
| 13787 |
% \begin{macrocode} |
| 13788 |
%<*misc> |
| 13789 |
\lst@BeginAspect[keywords]{make} |
| 13790 |
% \end{macrocode} |
| 13791 |
% \begin{macrocode} |
| 13792 |
\lst@NewMode\lst@makemode |
| 13793 |
\lst@AddToHook{Output}{% |
| 13794 |
\ifnum\lst@mode=\lst@makemode |
| 13795 |
\ifx\lst@thestyle\lst@gkeywords@sty |
| 13796 |
\lst@makekeytrue |
| 13797 |
\fi |
| 13798 |
\fi} |
| 13799 |
% \end{macrocode} |
| 13800 |
% \begin{macrocode} |
| 13801 |
\gdef\lst@makekeytrue{\let\lst@ifmakekey\iftrue} |
| 13802 |
\gdef\lst@makekeyfalse{\let\lst@ifmakekey\iffalse} |
| 13803 |
\global\lst@makekeyfalse % init |
| 13804 |
% \end{macrocode} |
| 13805 |
% \end{macro}\end{macro} |
| 13806 |
% |
| 13807 |
% \begin{lstkey}{makemacrouse} |
| 13808 |
% adjusts the character table if necessary |
| 13809 |
% \begin{macrocode} |
| 13810 |
\lst@Key{makemacrouse}f[t]{\lstKV@SetIf{#1}\lst@ifmakemacrouse} |
| 13811 |
% \end{macrocode} |
| 13812 |
% \end{lstkey} |
| 13813 |
% |
| 13814 |
% \begin{macro}{\lst@MakeSCT} |
| 13815 |
% If `macro use' is on, the opening |$(| prints preceding characters, enters |
| 13816 |
% the special mode and merges the two characters with the following output. |
| 13817 |
% |
| 13818 |
% \begin{macrocode} |
| 13819 |
\gdef\lst@MakeSCT{% |
| 13820 |
\lst@ifmakemacrouse |
| 13821 |
\lst@ReplaceInput{$(}{% |
| 13822 |
\lst@PrintToken |
| 13823 |
\lst@EnterMode\lst@makemode{\lst@makekeyfalse}% |
| 13824 |
\lst@Merge{\lst@ProcessOther\$\lst@ProcessOther(}}% |
| 13825 |
% \end{macrocode} ^^A $ |
| 13826 |
% The closing parenthesis tests for the mode and either processes |)| as usual |
| 13827 |
% or outputs it right here (in keyword style if a keyword was between |$(| and |
| 13828 |
% |)|). |
| 13829 |
% \begin{macrocode} |
| 13830 |
\lst@ReplaceInput{)}{% |
| 13831 |
\ifnum\lst@mode=\lst@makemode |
| 13832 |
\lst@PrintToken |
| 13833 |
\begingroup |
| 13834 |
\lst@ProcessOther)% |
| 13835 |
\lst@ifmakekey |
| 13836 |
\let\lst@currstyle\lst@gkeywords@sty |
| 13837 |
\fi |
| 13838 |
\lst@OutputOther |
| 13839 |
\endgroup |
| 13840 |
\lst@LeaveMode |
| 13841 |
\else |
| 13842 |
\expandafter\lst@ProcessOther\expandafter)% |
| 13843 |
\fi}% |
| 13844 |
% \end{macrocode} |
| 13845 |
% If \keyname{makemacrouse} is off then both |$(| are just `others'. |
| 13846 |
% \begin{macrocode} |
| 13847 |
\else |
| 13848 |
\lst@ReplaceInput{$(}{\lst@ProcessOther\$\lst@ProcessOther(}% |
| 13849 |
\fi} |
| 13850 |
% \end{macrocode} ^^A $ |
| 13851 |
% \end{macro} |
| 13852 |
% |
| 13853 |
% \begin{macrocode} |
| 13854 |
\lst@EndAspect |
| 13855 |
%</misc> |
| 13856 |
% \end{macrocode} |
| 13857 |
% \end{aspect} |
| 13858 |
% |
| 13859 |
% |
| 13860 |
% \section{Typesetting a listing} |
| 13861 |
% \label{sec:typesetting-listing} |
| 13862 |
% |
| 13863 |
% \begingroup |
| 13864 |
% \begin{macrocode} |
| 13865 |
%<*kernel> |
| 13866 |
% \end{macrocode} |
| 13867 |
% \endgroup |
| 13868 |
% \begin{macro}{\lst@lineno} |
| 13869 |
% \begin{lstkey}{print} |
| 13870 |
% \begin{lstkey}{firstline} |
| 13871 |
% \begin{lstkey}{lastline} |
| 13872 |
% The `current line' counter and three option keys. |
| 13873 |
% \begin{macrocode} |
| 13874 |
\newcount\lst@lineno % \global |
| 13875 |
\lst@AddToHook{InitVars}{\global\lst@lineno\@ne} |
| 13876 |
% \end{macrocode} |
| 13877 |
% \begin{macrocode} |
| 13878 |
\lst@Key{print}{true}[t]{\lstKV@SetIf{#1}\lst@ifprint} |
| 13879 |
\lst@Key{firstline}\relax{\def\lst@firstline{#1\relax}} |
| 13880 |
\lst@Key{lastline}\relax{\def\lst@lastline{#1\relax}} |
| 13881 |
% \end{macrocode} |
| 13882 |
% Initialize the linerange with reasonable values |
| 13883 |
% \begin{macrocode} |
| 13884 |
\lst@AddToHook{PreSet} |
| 13885 |
{% |
| 13886 |
\def\lst@firstline{1\relax} |
| 13887 |
\def\lst@lastline{9999999\relax} |
| 13888 |
\let\lst@linerange\@empty |
| 13889 |
} |
| 13890 |
% \end{macrocode} |
| 13891 |
% \end{lstkey} |
| 13892 |
% \end{lstkey} |
| 13893 |
% \end{lstkey} |
| 13894 |
% |
| 13895 |
% \begin{lstkey}{nolol} |
| 13896 |
% is just another key with an obvious meaning here. We'll use it below, |
| 13897 |
% of course. |
| 13898 |
% \begin{macrocode} |
| 13899 |
\lst@Key{nolol}{false}[t]{\lstKV@SetIf{#1}\lst@ifnolol} |
| 13900 |
\def\lst@nololtrue{\let\lst@ifnolol\iftrue} |
| 13901 |
\let\lst@ifnolol\iffalse % init |
| 13902 |
% \end{macrocode} |
| 13903 |
% \end{lstkey} |
| 13904 |
% \end{macro} |
| 13905 |
% |
| 13906 |
% |
| 13907 |
% \subsection{Dealing with lineranges} |
| 13908 |
% \label{sec:lineranges} |
| 13909 |
% |
| 13910 |
% The following code is just copied from the current development version, and |
| 13911 |
% from the |lstpatch.sty| file that Carsten left in version 1.3b for doing |
| 13912 |
% line ranges with numbers and range markers. It uses some more keys: |
| 13913 |
% |
| 13914 |
% \begin{lstkey}{linerange} |
| 13915 |
% \begin{lstkey}{consecutivenumbers} |
| 13916 |
% \begin{lstkey}{rangeprefix} |
| 13917 |
% \begin{lstkey}{rangesuffix} |
| 13918 |
% \begin{lstkey}{rangebeginprefix} |
| 13919 |
% \begin{lstkey}{rangebeginsuffix} |
| 13920 |
% \begin{lstkey}{rangeendprefix} |
| 13921 |
% \begin{lstkey}{rangeendsuffix} |
| 13922 |
% \begin{lstkey}{includerangemarker} |
| 13923 |
% First, the options that control the line-range handling. |
| 13924 |
% \begin{macrocode} |
| 13925 |
\lst@Key{linerange}\relax{\lstKV@OptArg[]{#1}{% |
| 13926 |
\def\lst@interrange{##1}\def\lst@linerange{##2,}}} |
| 13927 |
\lst@Key{consecutivenumbers}{true}[t]{% |
| 13928 |
\lstKV@SetIf{#1}\lst@ifconsecutivenumbers} |
| 13929 |
% \end{macrocode} |
| 13930 |
% The next options are needed for an easy description of arbitrary linerange |
| 13931 |
% markers: |
| 13932 |
% \begin{macrocode} |
| 13933 |
\lst@Key{rangeprefix}\relax{\def\lst@rangebeginprefix{#1}% |
| 13934 |
\def\lst@rangeendprefix{#1}} |
| 13935 |
\lst@Key{rangesuffix}\relax{\def\lst@rangebeginsuffix{#1}% |
| 13936 |
\def\lst@rangeendsuffix{#1}} |
| 13937 |
\lst@Key{rangebeginprefix}{}{\def\lst@rangebeginprefix{#1}} |
| 13938 |
\lst@Key{rangebeginsuffix}{}{\def\lst@rangebeginsuffix{#1}} |
| 13939 |
\lst@Key{rangeendprefix}{}{\def\lst@rangeendprefix{#1}} |
| 13940 |
\lst@Key{rangeendsuffix}{}{\def\lst@rangeendsuffix{#1}} |
| 13941 |
\lst@Key{includerangemarker}{true}[t]{\lstKV@SetIf{#1}% |
| 13942 |
\lst@ifincluderangemarker} |
| 13943 |
% \end{macrocode} |
| 13944 |
% The line range is known---it is set either explicitly (by numbers or by |
| 13945 |
% arbitrary linerange markers) or implicitly from the default values (1 and |
| 13946 |
% 999999). |\lst@GetLineInterval| parses the known line range recursively, |
| 13947 |
% because there may be a comma separated list of pairs. |
| 13948 |
% \begin{macrocode} |
| 13949 |
\lst@AddToHook{Init} |
| 13950 |
{% |
| 13951 |
\ifx\lst@linerange\@empty |
| 13952 |
\edef\lst@linerange{{\lst@firstline}-{\lst@lastline},}% |
| 13953 |
\fi% |
| 13954 |
\lst@GetLineInterval% |
| 13955 |
}% |
| 13956 |
\def\lst@GetLineInterval{\expandafter\lst@GLI\lst@linerange\@nil} |
| 13957 |
% \end{macrocode} |
| 13958 |
% Splitting the comma separated list of pairs is done by |
| 13959 |
% \begin{macrocode} |
| 13960 |
\def\lst@GLI#1,#2\@nil{% GLI: get line interval |
| 13961 |
% \end{macrocode} |
| 13962 |
% The list is split into two parts: the first element (\#1) of the list and |
| 13963 |
% the rest of the list (\#2) which is stored in |\lst@linerange| to be |
| 13964 |
% processed later. |
| 13965 |
% \begin{macrocode} |
| 13966 |
\def\lst@linerange{#2}\lst@GLI@#1--\@nil% |
| 13967 |
} |
| 13968 |
% \end{macrocode} |
| 13969 |
% Further parsing is done by |lst@GLI@|, the argument is |#1--\@nil| that |
| 13970 |
% is the first element of the list augmented by a sentinel. This |
| 13971 |
% argument is parsed with the template |#1-#2-#3\@nil|. |
| 13972 |
% |
| 13973 |
% \begin{macrocode} |
| 13974 |
\def\lst@GLI@#1-#2-#3\@nil{% |
| 13975 |
% \end{macrocode} |
| 13976 |
% A linerange given as e.\,g. `|12-21|' leads to the argument |
| 13977 |
% |12-21--\@nil|, so it is parsed as \#1\(\leftarrow\) |12|, |
| 13978 |
% \#2\(\leftarrow\)|21|, and \#3\(\leftarrow\)|-|. |
| 13979 |
% |
| 13980 |
% Otherwise it is possible to define a range by arbitrary linerange markers |
| 13981 |
% like `|start-end|' which leads to the argument |
| 13982 |
% |12-21--\@nil|, so it is parsed as \#1\(\leftarrow\) |12|, |
| 13983 |
% \#2\(\leftarrow\)|21|, and \#3\(\leftarrow\)|-|. |
| 13984 |
|
| 13985 |
|
| 13986 |
% First we test, if the linerange starts with a number (consisting of -, 1, |
| 13987 |
% 2, 3, \ldots) or an arbitrary linerange marker. If a linerange starts |
| 13988 |
% erroneously with a `|-|' character, the argument \#1 isn't set and so the |
| 13989 |
% range starts with 1, so giving a perhaps expected result, but the |
| 13990 |
% definition of a linerange must always consist at least of the three parts |
| 13991 |
% \meta{first}, `|-|', and \meta{last}. |
| 13992 |
% \begin{macrocode} |
| 13993 |
\lst@IfNumber{#1}% |
| 13994 |
{% |
| 13995 |
\ifx\@empty#1\@empty |
| 13996 |
\let\lst@firstline\@ne |
| 13997 |
\else |
| 13998 |
\def\lst@firstline{#1\relax} |
| 13999 |
\fi |
| 14000 |
% \end{macrocode} |
| 14001 |
% Now we know the starting number of the linerange. \#3 isn't set with a |
| 14002 |
% linerange consisting of a single number, in all other cases \#2 defines |
| 14003 |
% the last line (explicitly or implicitly). |
| 14004 |
% \begin{macrocode} |
| 14005 |
\ifx\@empty#3\@empty |
| 14006 |
\def\lst@lastline{9999999\relax} |
| 14007 |
\ifx\@empty#2\@empty |
| 14008 |
\let\lst@lastline\lst@firstline |
| 14009 |
\fi |
| 14010 |
\else% |
| 14011 |
\ifx\@empty#2\@empty |
| 14012 |
\def\lst@lastline{9999999\relax} |
| 14013 |
\else % doesn't happen(?) |
| 14014 |
\def\lst@lastline{#2\relax} |
| 14015 |
\fi |
| 14016 |
\fi |
| 14017 |
}% |
| 14018 |
% \end{macrocode} |
| 14019 |
% If we've found an arbitrary linerange marker, we set firstline and lastline to |
| 14020 |
% 9999999. This prevents (almost) anything from being printed for now. |
| 14021 |
% \begin{macrocode} |
| 14022 |
{% |
| 14023 |
\def\lst@firstline{9999999\relax} |
| 14024 |
\let\lst@lastline\lst@firstline |
| 14025 |
% \end{macrocode} |
| 14026 |
% We add the prefixes and suffixes to the markers. |
| 14027 |
% \begin{macrocode} |
| 14028 |
\let\lst@rangebegin\lst@rangebeginprefix |
| 14029 |
\lst@AddTo\lst@rangebegin{#1}% |
| 14030 |
\lst@Extend\lst@rangebegin\lst@rangebeginsuffix |
| 14031 |
\ifx\@empty#3\@empty |
| 14032 |
\let\lst@rangeend\lst@rangeendprefix |
| 14033 |
\lst@AddTo\lst@rangeend{#1} |
| 14034 |
\lst@Extend\lst@rangeend\lst@rangeendsuffix |
| 14035 |
\else |
| 14036 |
\ifx\@empty#2\@empty |
| 14037 |
\let\lst@rangeend\@empty |
| 14038 |
\else |
| 14039 |
\let\lst@rangeend\lst@rangeendprefix |
| 14040 |
\lst@AddTo\lst@rangeend{#2}% |
| 14041 |
\lst@Extend\lst@rangeend\lst@rangeendsuffix |
| 14042 |
\fi |
| 14043 |
\fi |
| 14044 |
% \end{macrocode} |
| 14045 |
% The following definition will be executed in the |
| 14046 |
% \hookname{SelectCharTable} hook and here right now if we are already |
| 14047 |
% processing a listing. |
| 14048 |
% \begin{macrocode} |
| 14049 |
\global\def\lst@DefRange{% |
| 14050 |
\expandafter\lst@CArgX\lst@rangebegin\relax\lst@DefRangeB}% |
| 14051 |
\ifnum\lst@mode=\lst@Pmode \expandafter\lst@DefRange \fi% |
| 14052 |
}% |
| 14053 |
} |
| 14054 |
% \end{macrocode} |
| 14055 |
% \end{lstkey} |
| 14056 |
% \end{lstkey} |
| 14057 |
% \end{lstkey} |
| 14058 |
% \end{lstkey} |
| 14059 |
% \end{lstkey} |
| 14060 |
% \end{lstkey} |
| 14061 |
% \end{lstkey} |
| 14062 |
% \end{lstkey} |
| 14063 |
% \end{lstkey} |
| 14064 |
% |
| 14065 |
% \begin{macro}{\lst@DefRange} |
| 14066 |
% |\lst@DefRange| is not inserted via a hook anymore. Instead it is now called |
| 14067 |
% directly from |\lst@SelectCharTable|. This was necessary to get rid of an |
| 14068 |
% interference with the escape-to-LaTeX-feature. The bug was reported by |
| 14069 |
% \lsthelper{Michael~Bachmann}{2004/07/21}{Keine label-Referenzierung |
| 14070 |
% m\"oglich...}. Another change is due to the same bug: |\lst@DefRange| is |
| 14071 |
% redefined globally when the begin of code is found, see below. The bug was |
| 14072 |
% reported by \lsthelper{Tobias~Rapp}{2004/04/06}{undetected end of range if |
| 14073 |
% listing crosses page break} and \lsthelper{Markus~Luisser}{2004/08/13}{Bug mit |
| 14074 |
% 'linerangemarker' in umgebrochenen listings}. |
| 14075 |
% \begin{macrocode} |
| 14076 |
\lst@AddToHookExe{DeInit}{\global\let\lst@DefRange\@empty} |
| 14077 |
% \end{macrocode} |
| 14078 |
% |
| 14079 |
% Actually defining the marker (via |\lst@GLI@|, |\lst@DefRange|, |
| 14080 |
% |\lst@CArgX| as seen above) is similar to |\lst@DefDelimB|---except that |
| 14081 |
% we unfold the first parameter and use different \meta{execute}, |
| 14082 |
% \meta{pre}, and \meta{post} statements. |
| 14083 |
% \begin{macrocode} |
| 14084 |
\def\lst@DefRangeB#1#2{\lst@DefRangeB@#1#2} |
| 14085 |
\def\lst@DefRangeB@#1#2#3#4{% |
| 14086 |
\lst@CDef{#1{#2}{#3}}#4{}{% |
| 14087 |
\lst@ifincluderangemarker |
| 14088 |
\lst@LeaveMode |
| 14089 |
\let#1#4% |
| 14090 |
\lst@DefRangeEnd |
| 14091 |
\lst@InitLstNumber |
| 14092 |
\else |
| 14093 |
\@tempcnta\lst@lineno \advance\@tempcnta\@ne |
| 14094 |
\edef\lst@firstline{\the\@tempcnta\relax}% |
| 14095 |
\gdef\lst@OnceAtEOL{\let#1#4\lst@DefRangeEnd}% |
| 14096 |
\lst@InitLstNumber |
| 14097 |
\fi |
| 14098 |
\global\let\lst@DefRange\lst@DefRangeEnd |
| 14099 |
\lst@CArgEmpty% |
| 14100 |
}% |
| 14101 |
\@empty% |
| 14102 |
} |
| 14103 |
% \end{macrocode} |
| 14104 |
% \end{macro} |
| 14105 |
% |
| 14106 |
% \begin{macro}{\lst@SetFirstNumber} |
| 14107 |
% Modify labels and define |\lst@InitLstNumber| used above according to an |
| 14108 |
% error reported by |
| 14109 |
% \lsthelper{Omair-Inam~Abdul-Matin}{2004/05/10}{experimental linerange |
| 14110 |
% feature does not work with firstnumber}. |
| 14111 |
% \begin{macrocode} |
| 14112 |
\def\lstpatch@labels{% |
| 14113 |
\gdef\lst@SetFirstNumber{% |
| 14114 |
\ifx\lst@firstnumber\@undefined |
| 14115 |
\@tempcnta 0\csname\@lst no@\lst@intname\endcsname\relax |
| 14116 |
\ifnum\@tempcnta=\z@ \else |
| 14117 |
\lst@nololtrue |
| 14118 |
\advance\@tempcnta\lst@advancenumber |
| 14119 |
\edef\lst@firstnumber{\the\@tempcnta\relax} |
| 14120 |
\fi |
| 14121 |
\fi |
| 14122 |
} |
| 14123 |
} |
| 14124 |
% \end{macrocode} |
| 14125 |
% \end{macro} |
| 14126 |
% |
| 14127 |
% \begin{macro}{\lst@InitLstNumber} |
| 14128 |
% \begin{macrocode} |
| 14129 |
\def\lst@InitLstNumber{% |
| 14130 |
\global\c@lstnumber\lst@firstnumber |
| 14131 |
\global\advance\c@lstnumber\lst@advancenumber |
| 14132 |
\global\advance\c@lstnumber-\lst@advancelstnum |
| 14133 |
\ifx \lst@firstnumber\c@lstnumber |
| 14134 |
\global\advance\c@lstnumber-\lst@advancelstnum |
| 14135 |
\fi% |
| 14136 |
% \end{macrocode} |
| 14137 |
% \lsthelper{Byron~K.~Boulton}{2013/11/21}{line numbers off by one} |
| 14138 |
% reported, that the line numbers are off by one, if they are displayed when |
| 14139 |
% a linerange is given by patterns and |includerangemarker=false| is |
| 14140 |
% set. Adding this test corrects this behaviour. |
| 14141 |
% \begin{macrocode} |
| 14142 |
\lst@ifincluderangemarker\else% |
| 14143 |
\global\advance\c@lstnumber by 1% |
| 14144 |
\fi% |
| 14145 |
} |
| 14146 |
% \end{macrocode} |
| 14147 |
% \end{macro} |
| 14148 |
% |
| 14149 |
% The end-marker is defined if and only if it's not empty. The definition is |
| 14150 |
% similar to |\lst@DefDelimE|---with the above exceptions and except that we |
| 14151 |
% define the re-entry point |\lst@DefRangeE@@| as it is defined in the new |
| 14152 |
% version of |\lst@MProcessListing| above. |
| 14153 |
% \begin{macrocode} |
| 14154 |
\def\lst@DefRangeEnd{% |
| 14155 |
\ifx\lst@rangeend\@empty\else |
| 14156 |
\expandafter\lst@CArgX\lst@rangeend\relax\lst@DefRangeE |
| 14157 |
\fi} |
| 14158 |
\def\lst@DefRangeE#1#2{\lst@DefRangeE@#1#2} |
| 14159 |
\def\lst@DefRangeE@#1#2#3#4{% |
| 14160 |
\lst@CDef{#1#2{#3}}#4{}% |
| 14161 |
{\let#1#4% |
| 14162 |
\edef\lst@lastline{\the\lst@lineno\relax}% |
| 14163 |
\lst@DefRangeE@@}% |
| 14164 |
\@empty} |
| 14165 |
\def\lst@DefRangeE@@#1\@empty{% |
| 14166 |
\lst@ifincluderangemarker |
| 14167 |
#1\lst@XPrintToken |
| 14168 |
\fi |
| 14169 |
\lst@LeaveModeToPmode |
| 14170 |
\lst@BeginDropInput{\lst@Pmode}} |
| 14171 |
\def\lst@LeaveModeToPmode{% |
| 14172 |
\ifnum\lst@mode=\lst@Pmode |
| 14173 |
\expandafter\lsthk@EndGroup |
| 14174 |
\else |
| 14175 |
\expandafter\egroup\expandafter\lst@LeaveModeToPmode |
| 14176 |
\fi} |
| 14177 |
% \end{macrocode} |
| 14178 |
% |
| 14179 |
% Sometimes it is good to have two or more excerpts of one program numbered |
| 14180 |
% consecutively, i.\,e. 1--11 instead of 3--5, 12--17, 20--21. So we |
| 14181 |
% introduce |\lst@DisplayConsecutiveNumbersOrNot|, which corrects the |
| 14182 |
% displayed line numbers to be always equal to the input line numbers |
| 14183 |
% \begin{macrocode} |
| 14184 |
\def\lst@DisplayConsecutiveNumbersOrNot{% |
| 14185 |
\lst@ifconsecutivenumbers\else% |
| 14186 |
\c@lstnumber=\numexpr-1+\lst@lineno |
| 14187 |
\fi% |
| 14188 |
} |
| 14189 |
% \end{macrocode} |
| 14190 |
% |
| 14191 |
% Eventually we shouldn't forget to install |\lst@OnceAtEOL|, which must |
| 14192 |
% also be called in |\lst@MSkipToFirst|. |
| 14193 |
% \begin{macrocode} |
| 14194 |
\lst@AddToHook{EOL}{\lst@OnceAtEOL\global\let\lst@OnceAtEOL\@empty} |
| 14195 |
\gdef\lst@OnceAtEOL{}% Init |
| 14196 |
% \end{macrocode} |
| 14197 |
% The following code was introduced in listings version 1.4. The code |
| 14198 |
% resembles the lines 14031--14061 of version 1.3c, but contains loops: |
| 14199 |
% \newline|\def\lst@next{...}\expandafter\lst@next|.\newline |
| 14200 |
% In fact that code will never be expanded, because there are two analoguous |
| 14201 |
% definitions in section \ref{iTheInputCommand} below, so they override |
| 14202 |
% these two commands. |
| 14203 |
% \begin{macrocode} |
| 14204 |
\def\lst@MSkipToFirst{% |
| 14205 |
\global\advance\lst@lineno\@ne |
| 14206 |
\ifnum \lst@lineno=\lst@firstline |
| 14207 |
\def\lst@next{\lst@LeaveMode \global\lst@newlines\z@ |
| 14208 |
\lst@OnceAtEOL \global\let\lst@OnceAtEOL\@empty |
| 14209 |
\lst@InitLstNumber % Added to work with modified \lsthk@PreInit. |
| 14210 |
\lsthk@InitVarsBOL |
| 14211 |
\lst@BOLGobble}% |
| 14212 |
\expandafter\lst@next |
| 14213 |
\fi} |
| 14214 |
\def\lst@SkipToFirst{% |
| 14215 |
\ifnum \lst@lineno<\lst@firstline |
| 14216 |
\def\lst@next{\lst@BeginDropInput\lst@Pmode |
| 14217 |
\lst@Let{13}\lst@MSkipToFirst |
| 14218 |
\lst@Let{10}\lst@MSkipToFirst}% |
| 14219 |
\expandafter\lst@next |
| 14220 |
\else |
| 14221 |
\expandafter\lst@BOLGobble |
| 14222 |
\fi} |
| 14223 |
% \end{macrocode} |
| 14224 |
% |
| 14225 |
% Finally the service macro |\lst@IfNumber|: |
| 14226 |
% \begin{macrocode} |
| 14227 |
\def\lst@IfNumber#1{% |
| 14228 |
\ifx\@empty#1\@empty |
| 14229 |
\let\lst@next\@firstoftwo |
| 14230 |
\else |
| 14231 |
\lst@IfNumber@#1\@nil |
| 14232 |
\fi |
| 14233 |
\lst@next} |
| 14234 |
\def\lst@IfNumber@#1#2\@nil{% |
| 14235 |
\let\lst@next\@secondoftwo |
| 14236 |
\ifnum`#1>47\relax \ifnum`#1>57\relax\else |
| 14237 |
\let\lst@next\@firstoftwo |
| 14238 |
\fi\fi} |
| 14239 |
% \end{macrocode} |
| 14240 |
% |
| 14241 |
% |
| 14242 |
% \subsection{Floats, boxes and captions} |
| 14243 |
% |
| 14244 |
% \begin{lstkey}{captionpos} |
| 14245 |
% \begin{lstkey}{abovecaptionskip} |
| 14246 |
% \begin{lstkey}{belowcaptionskip} |
| 14247 |
% \begin{lstkey}{label} |
| 14248 |
% \begin{lstkey}{title} |
| 14249 |
% \begin{lstkey}{caption} |
| 14250 |
% Some keys and \ldots |
| 14251 |
% \begin{macrocode} |
| 14252 |
\lst@Key{captionpos}{t}{\def\lst@captionpos{#1}} |
| 14253 |
\lst@Key{abovecaptionskip}\smallskipamount{% |
| 14254 |
\def\lst@abovecaption{#1}} |
| 14255 |
\lst@Key{belowcaptionskip}\smallskipamount{% |
| 14256 |
\def\lst@belowcaption{#1}} |
| 14257 |
% \end{macrocode} |
| 14258 |
% \lsthelper{Rolf~Niepraschk}{2000/01/10}{key: title} proposed |
| 14259 |
% \keyname{title}. |
| 14260 |
% \begin{macrocode} |
| 14261 |
\lst@Key{label}\relax{\def\lst@label{#1}} |
| 14262 |
\lst@Key{title}\relax{\def\lst@title{#1}\let\lst@caption\relax} |
| 14263 |
\lst@Key{caption}\relax{\lstKV@OptArg[{#1}]{#1}% |
| 14264 |
{\def\lst@caption{##2}\def\lst@@caption{##1}}% |
| 14265 |
\let\lst@title\@empty} |
| 14266 |
\lst@AddToHookExe{TextStyle} |
| 14267 |
{\let\lst@caption\@empty \let\lst@@caption\@empty |
| 14268 |
\let\lst@title\@empty \let\lst@label\@empty} |
| 14269 |
% \end{macrocode} |
| 14270 |
% \end{lstkey} |
| 14271 |
% \end{lstkey} |
| 14272 |
% \end{lstkey} |
| 14273 |
% \end{lstkey} |
| 14274 |
% \end{lstkey} |
| 14275 |
% \end{lstkey} |
| 14276 |
% |
| 14277 |
% \begin{macro}{\thelstlisting} |
| 14278 |
% \begin{macro}{\lstlistingname} |
| 14279 |
% \begin{macro}{\lstlistingnamestyle} |
| 14280 |
% \begin{lstkey}{numberbychapter} |
| 14281 |
% \ldots\space and how the caption numbers look like. I switched to |
| 14282 |
% |\@ifundefined| (instead of |\ifx| |\@undefined|) after an error report from |
| 14283 |
% \lsthelper{Denis~Girou}{1999/07/26}{incompatible if hyperref loaded before |
| 14284 |
% listings}. |
| 14285 |
% |
| 14286 |
% This is set |\AtBeginDocument| so that the user can specify whether or not |
| 14287 |
% the counter should be reset at each chapter before the counter is defined, |
| 14288 |
% using the |numberbychapter| key. |
| 14289 |
% \begin{macrocode} |
| 14290 |
\AtBeginDocument{% |
| 14291 |
\@ifundefined{thechapter}{\let\lst@ifnumberbychapter\iffalse}{} |
| 14292 |
\lst@ifnumberbychapter |
| 14293 |
\newcounter{lstlisting}[chapter] |
| 14294 |
\gdef\thelstlisting% |
| 14295 |
{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@lstlisting} |
| 14296 |
\else |
| 14297 |
\newcounter{lstlisting} |
| 14298 |
\gdef\thelstlisting{\@arabic\c@lstlisting} |
| 14299 |
\fi} |
| 14300 |
% \end{macrocode} |
| 14301 |
% \begin{macrocode} |
| 14302 |
\lst@UserCommand\lstlistingname{Listing} |
| 14303 |
\lst@UserCommand\lstlistingnamestyle{} |
| 14304 |
% \end{macrocode} |
| 14305 |
% \begin{macrocode} |
| 14306 |
\lst@Key{numberbychapter}{true}[t]{% |
| 14307 |
\lstKV@SetIf{#1}\lst@ifnumberbychapter} |
| 14308 |
% \end{macrocode} |
| 14309 |
% \end{lstkey} |
| 14310 |
% \end{macro} |
| 14311 |
% \end{macro} |
| 14312 |
% \end{macro} |
| 14313 |
% |
| 14314 |
% \begin{macro}{\lst@MakeCaption} |
| 14315 |
% Before defining this macro, we ensure that some other control sequences |
| 14316 |
% exist---\lsthelper{Adam~Prugel-Bennett}{2001/02/19}{\abovecaptionskip |
| 14317 |
% undefined in slides.cls} reported problems with the slides document class. |
| 14318 |
% In particular we allocate above- and belowcaption skip registers and define |
| 14319 |
% |\@makecaption|, which is an exact copy of the definition in the article |
| 14320 |
% class. To respect the LPPL: you should have a copy of this class on your |
| 14321 |
% \TeX\ system or you can obtain a copy from the CTAN, e.g.~from the ftp-server |
| 14322 |
% \texttt{ftp.dante.de}. |
| 14323 |
% |
| 14324 |
% Axel Sommerfeldt proposed a couple of improvements regarding captions and |
| 14325 |
% titles. The first is to separate the definitions of the skip registers and |
| 14326 |
% |\@makecaption|. |
| 14327 |
% \begin{macrocode} |
| 14328 |
\@ifundefined{abovecaptionskip}{% |
| 14329 |
\newskip\abovecaptionskip% |
| 14330 |
\newskip\belowcaptionskip% |
| 14331 |
}{} |
| 14332 |
\@ifundefined{@makecaption}{% |
| 14333 |
\long\def\@makecaption#1#2{% |
| 14334 |
\vskip\abovecaptionskip% |
| 14335 |
\sbox\@tempboxa{#1: #2}% |
| 14336 |
\ifdim \wd\@tempboxa >\hsize% |
| 14337 |
#1: #2\par% |
| 14338 |
\else% |
| 14339 |
\global \@minipagefalse% |
| 14340 |
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% |
| 14341 |
\fi% |
| 14342 |
\vskip\belowcaptionskip}% |
| 14343 |
}{} |
| 14344 |
% \end{macrocode} |
| 14345 |
% The introduction of |\fnum@lstlisting| is also due to Axel. Previously the |
| 14346 |
% replacement text was used directly in |\lst@MakeCaption|. A |\noindent| has |
| 14347 |
% been moved elsewhere and became |\@parboxrestore| after a bug report from |
| 14348 |
% \lsthelper{Frank~Mittelbach}{2004/02/13}{Re: Info: Inkompatibilit\"at |
| 14349 |
% zwischen caption und listings}. \lsthelper{Karl Berry}{2019/08/18}{bold |
| 14350 |
% "listings 1"?} asked for the ability of customizing the label. So |
| 14351 |
% |\lstlistingnamestyle| was introduced in front of |\lstlistingname|. |
| 14352 |
% \begin{macrocode} |
| 14353 |
\def\fnum@lstlisting{% |
| 14354 |
{\lstlistingnamestyle\lstlistingname |
| 14355 |
\ifx\lst@@caption\@empty\else~\thelstlisting\fi}% |
| 14356 |
} |
| 14357 |
% \end{macrocode} |
| 14358 |
% Hardcoding the extension makes it hard to use a different one, e.g., for the |
| 14359 |
% appendix. \lsthelper{Markus Kohm}{2023/09/05}{extended listings also |
| 14360 |
% actively supporting tocbasic} suggested to define and use |\ext@lstlisting| |
| 14361 |
% instead. |
| 14362 |
% \begin{macrocode} |
| 14363 |
\def\ext@lstlisting{lol} |
| 14364 |
% \end{macrocode} |
| 14365 |
% Captions are set only for display style listings -- thanks to |
| 14366 |
% \lsthelper{Peter~L\"offler}{2004/04/24}{pdfTeX warning (dest): name{figure.1} |
| 14367 |
% has been referenced but does not exist} for reporting the bug and to |
| 14368 |
% \lsthelper{Axel~Sommerfeldt}{2004/02/27}{Re: caption + listings + hyperref} |
| 14369 |
% for analyzing the bug. |
| 14370 |
% We |\refstepcounter| the listing counter if and only if |\lst@@caption| is |
| 14371 |
% not empty. Otherwise we ensure correct hyper-references, |
| 14372 |
% see |\lst@HRefStepCounter| below. We do this once a listing, namely at the |
| 14373 |
% top. |
| 14374 |
% \begin{macrocode} |
| 14375 |
\def\lst@MakeCaption#1{% |
| 14376 |
\lst@ifdisplaystyle |
| 14377 |
\ifx #1t \allowbreak% |
| 14378 |
\ifx\lst@@caption\@empty\expandafter\lst@HRefStepCounter \else |
| 14379 |
\expandafter\refstepcounter |
| 14380 |
\fi {lstlisting}% |
| 14381 |
\ifx\lst@label\@empty\else \label{\lst@label}\fi |
| 14382 |
% \end{macrocode} |
| 14383 |
% The following code has been moved here from the \hookname{Init} hook after |
| 14384 |
% a bug report from \lsthelper{Rolf~Niepraschk}{2003/06/11}{pagebreak between |
| 14385 |
% caption and listing}. Moreover the initialization of |\lst@name| et al have |
| 14386 |
% been inserted here after a bug report from \lsthelper{Werner~Struckmann} |
| 14387 |
% {2003/06/25}{undefined control sequence \lst@name}. |
| 14388 |
% We make a `lol' entry if the name is neither empty nor a single space. But |
| 14389 |
% we test |\lst@|(|@|)|caption| and |\lst@ifnolol| first. |
| 14390 |
% \begin{macrocode} |
| 14391 |
\let\lst@arg\lst@intname \lst@ReplaceIn\lst@arg\lst@filenamerpl |
| 14392 |
\global\let\lst@name\lst@arg \global\let\lstname\lst@name |
| 14393 |
\lst@ifnolol\else |
| 14394 |
\ifx\lst@@caption\@empty |
| 14395 |
\ifx\lst@caption\@empty |
| 14396 |
\ifx\lst@intname\@empty \else \def\lst@temp{ }% |
| 14397 |
\ifx\lst@intname\lst@temp \else |
| 14398 |
\addcontentsline{\ext@lstlisting}{lstlisting}\lst@name |
| 14399 |
\fi\fi |
| 14400 |
\fi |
| 14401 |
\else |
| 14402 |
\addcontentsline{\ext@lstlisting}{lstlisting}% |
| 14403 |
{\protect\numberline{\thelstlisting}\lst@@caption}% |
| 14404 |
\fi |
| 14405 |
\fi |
| 14406 |
\fi |
| 14407 |
% \end{macrocode} |
| 14408 |
% We make a caption if and only if the caption is not empty and the user |
| 14409 |
% requested a caption at |#1| $\in\{\mathtt t,\mathtt b\}$. To disallow |
| 14410 |
% pagebreaks between caption (or title) and a listing, we redefine the |
| 14411 |
% primitive |\vskip| locally to insert |\nobreak|s. Note that we allow |
| 14412 |
% pagebreaks in front of a `top-caption' and after a `bottom-caption'. |
| 14413 |
% Also, the |\ignorespaces| in the |\@makecaption| call is added to match |
| 14414 |
% what \LaTeX\ does in |\@caption|; the AMSbook class (and perhaps others) |
| 14415 |
% assume this is present and attempt to strip it off when testing for an |
| 14416 |
% empty caption, causing a bug noted by \lsthelper{Xiaobo~Peng}{2006/06/29}% |
| 14417 |
% {captions not shown with amsbook class}. |
| 14418 |
% \begin{TODO} |
| 14419 |
% This redefinition is a brute force method. Is there a better one? |
| 14420 |
% \end{TODO} |
| 14421 |
% \begin{macrocode} |
| 14422 |
\ifx\lst@caption\@empty\else |
| 14423 |
\lst@IfSubstring #1\lst@captionpos |
| 14424 |
{\begingroup \let\@@vskip\vskip |
| 14425 |
\def\vskip{\afterassignment\lst@vskip \@tempskipa}% |
| 14426 |
\def\lst@vskip{\nobreak\@@vskip\@tempskipa\nobreak}% |
| 14427 |
\par\@parboxrestore\normalsize\normalfont % \noindent (AS) |
| 14428 |
%%\ifx #1t\allowbreak \fi |
| 14429 |
\ifx\lst@title\@empty |
| 14430 |
\lst@makecaption\fnum@lstlisting{% |
| 14431 |
\ignorespaces \lst@caption} |
| 14432 |
\else |
| 14433 |
\lst@maketitle\lst@title % (AS) |
| 14434 |
\fi |
| 14435 |
\ifx #1b\allowbreak \fi |
| 14436 |
\endgroup}{}% |
| 14437 |
\fi |
| 14438 |
\fi} |
| 14439 |
% \end{macrocode} |
| 14440 |
% I've inserted |\normalsize| after a bug report from |
| 14441 |
% \lsthelper{Andreas~Matthias}{2000/01/04}{caption affected by basicstyle} |
| 14442 |
% and moved it in front of |\@makecaption| after receiving another from |
| 14443 |
% \lsthelper{Sonja~Weidmann}{2000/02/01}{listings and caption packages |
| 14444 |
% not compatible}. |
| 14445 |
% \end{macro} |
| 14446 |
% |
| 14447 |
% \begin{macro}{\lst@makecaption} |
| 14448 |
% \begin{macro}{\lst@maketitle} |
| 14449 |
% Axel proposed the first definition. The other two are default definitions. |
| 14450 |
% They may be adjusted to make \packagename{listings} compatible with other |
| 14451 |
% packages and classes. |
| 14452 |
% Markus proposed to also define |\@captype|, so his |
| 14453 |
% |\raggedlstlistingcaption| could be used. |
| 14454 |
% \begin{macrocode} |
| 14455 |
\def\lst@makecaption{\def\@captype{lstlisting}\@makecaption} |
| 14456 |
\def\lst@maketitle{\@makecaption\lst@title@dropdelim} |
| 14457 |
\def\lst@title@dropdelim#1{\ignorespaces} |
| 14458 |
% \end{macrocode} |
| 14459 |
% The following \packagename{caption}(\packagename{2}) support comes also from |
| 14460 |
% Axel. |
| 14461 |
% \begin{macrocode} |
| 14462 |
\AtBeginDocument{% |
| 14463 |
\@ifundefined{captionlabelfalse}{}{% |
| 14464 |
\def\lst@maketitle{\captionlabelfalse\@makecaption\@empty}}% |
| 14465 |
\@ifundefined{caption@startrue}{}{% |
| 14466 |
\def\lst@maketitle{\caption@startrue\@makecaption\@empty}}% |
| 14467 |
} |
| 14468 |
% \end{macrocode} |
| 14469 |
% \end{macro}\end{macro} |
| 14470 |
% |
| 14471 |
% \begin{macro}{\lst@HRefStepCounter} |
| 14472 |
% This macro sets the listing number to a negative value since the user |
| 14473 |
% shouldn't refer to such a listing. If the \packagename{hyperref} package |
| 14474 |
% is present, we use `lstlisting.' (argument from above) concatenated with |
| 14475 |
% the current (negative) number to hyperref to. |
| 14476 |
% The groups have been added to prevent other packages (namely |
| 14477 |
% \packagename{tabularx}) from reading the locally changed counter |
| 14478 |
% and writing it back globally. Thanks to \lsthelper{Michael~Niedermair} |
| 14479 |
% {2001/09/18}{strange numbering of listings} for the report. Unfortunately |
| 14480 |
% this localization led to another bug, see |\theHlstnumber|. |
| 14481 |
% \begin{macrocode} |
| 14482 |
\def\lst@HRefStepCounter#1{% |
| 14483 |
\begingroup |
| 14484 |
\c@lstlisting\lst@neglisting |
| 14485 |
\advance\c@lstlisting\m@ne \xdef\lst@neglisting{\the\c@lstlisting}% |
| 14486 |
\ifx\hyper@refstepcounter\@undefined\else |
| 14487 |
\hyper@refstepcounter{#1}% |
| 14488 |
\fi |
| 14489 |
\endgroup |
| 14490 |
} |
| 14491 |
\gdef\lst@neglisting{\z@}% init, \z@ can be used both for 0pt and 0, |
| 14492 |
% remember: _neg_ative number, but no |
| 14493 |
% counter! |
| 14494 |
% \end{macrocode} |
| 14495 |
% \end{macro} |
| 14496 |
% |
| 14497 |
% \begin{lstkey}{boxpos} |
| 14498 |
% \begin{macro}{\lst@boxtrue} |
| 14499 |
% sets the vertical alignment of the (possibly) used box respectively indicates |
| 14500 |
% that a box is used. |
| 14501 |
% \begin{macrocode} |
| 14502 |
\lst@Key{boxpos}{c}{\def\lst@boxpos{#1}} |
| 14503 |
% \end{macrocode} |
| 14504 |
% \begin{macrocode} |
| 14505 |
\def\lst@boxtrue{\let\lst@ifbox\iftrue} |
| 14506 |
\let\lst@ifbox\iffalse |
| 14507 |
% \end{macrocode} |
| 14508 |
% \end{macro}\end{lstkey} |
| 14509 |
% |
| 14510 |
% \begin{lstkey}{float} |
| 14511 |
% \begin{lstkey}{floatplacement} |
| 14512 |
% Matthias Zenger asked for double-column floats, so I've inserted some code. |
| 14513 |
% We first check for a star \ldots |
| 14514 |
% \begin{macrocode} |
| 14515 |
\lst@Key{float}\relax[\lst@floatplacement]{% |
| 14516 |
\lstKV@SwitchCases{#1}% |
| 14517 |
{true:\let\lst@floatdefault\lst@floatplacement |
| 14518 |
\let\lst@float\lst@floatdefault\\% |
| 14519 |
false:\let\lst@floatdefault\relax |
| 14520 |
\let\lst@float\lst@floatdefault |
| 14521 |
}{\def\lst@next{\@ifstar{\let\lst@beginfloat\@dblfloat |
| 14522 |
\let\lst@endfloat\end@dblfloat |
| 14523 |
\lst@KFloat}% |
| 14524 |
{\let\lst@beginfloat\@float |
| 14525 |
\let\lst@endfloat\end@float |
| 14526 |
\lst@KFloat}} |
| 14527 |
\edef\lst@float{#1}% |
| 14528 |
\expandafter\lst@next\lst@float\relax}} |
| 14529 |
% \end{macrocode} |
| 14530 |
% \ldots\ and define |\lst@float|. |
| 14531 |
% \begin{macrocode} |
| 14532 |
\def\lst@KFloat#1\relax{% |
| 14533 |
\ifx\@empty#1\@empty |
| 14534 |
\let\lst@float\lst@floatplacement |
| 14535 |
\else |
| 14536 |
\def\lst@float{#1}% |
| 14537 |
\fi} |
| 14538 |
% \end{macrocode} |
| 14539 |
% The setting |\lst@AddToHook{PreSet}{\let\lst@float\relax}| has been |
| 14540 |
% changed on request of \lsthelper{Tanguy~Fautr\'e}{2004/02/02}{listings |
| 14541 |
% not following float directive?}. This also led to some adjustments above. |
| 14542 |
% \begin{macrocode} |
| 14543 |
\lst@Key{floatplacement}{tbp}{\def\lst@floatplacement{#1}} |
| 14544 |
\lst@AddToHook{PreSet}{\let\lst@float\lst@floatdefault} |
| 14545 |
\lst@AddToHook{TextStyle}{\let\lst@float\relax} |
| 14546 |
\let\lst@floatdefault\relax % init |
| 14547 |
% \end{macrocode} |
| 14548 |
% |\lst@doendpe| is set according to |\lst@float| -- thanks to |
| 14549 |
% \lsthelper{Andreas~Schmidt}{2004/05/15}{wrong spacing when a floating listing |
| 14550 |
% follows \section} and \lsthelper{Heiko~Oberdiek}{2004/05/18}{dito}. |
| 14551 |
% \begin{macrocode} |
| 14552 |
\lst@AddToHook{DeInit}{% |
| 14553 |
\ifx\lst@float\relax |
| 14554 |
\global\let\lst@doendpe\@doendpe |
| 14555 |
\else |
| 14556 |
\global\let\lst@doendpe\@empty |
| 14557 |
\fi} |
| 14558 |
% \end{macrocode} |
| 14559 |
% The float type |\ftype@lstlisting| is set according to whether the |
| 14560 |
% \packagename{float} package is loaded and whether \texttt{figure} and |
| 14561 |
% \texttt{table} floats are defined. This is done at |\begin{document}| to |
| 14562 |
% make the code independent of the order of package loading. |
| 14563 |
% \begin{macrocode} |
| 14564 |
\AtBeginDocument{% |
| 14565 |
\@ifundefined{c@float@type}% |
| 14566 |
{\edef\ftype@lstlisting{\ifx\c@figure\@undefined 1\else 4\fi}} |
| 14567 |
{\edef\ftype@lstlisting{\the\c@float@type}% |
| 14568 |
\addtocounter{float@type}{\value{float@type}}}% |
| 14569 |
} |
| 14570 |
% \end{macrocode} |
| 14571 |
% \end{lstkey} |
| 14572 |
% \end{lstkey} |
| 14573 |
% |
| 14574 |
% |
| 14575 |
% \subsection{Init and EOL} |
| 14576 |
% |
| 14577 |
% \begin{lstkey}{aboveskip} |
| 14578 |
% \begin{lstkey}{belowskip} |
| 14579 |
% We define and initialize these keys and prevent extra spacing for `inline' |
| 14580 |
% listings (in particular if \packagename{fancyvrb} interface is active, |
| 14581 |
% problem reported by \lsthelper{Denis~Girou}{1999/08/03}{wrong spacing}). |
| 14582 |
% \begin{macrocode} |
| 14583 |
\lst@Key{aboveskip}\medskipamount{\def\lst@aboveskip{#1}} |
| 14584 |
\lst@Key{belowskip}\medskipamount{\def\lst@belowskip{#1}} |
| 14585 |
\lst@AddToHook{TextStyle} |
| 14586 |
{\let\lst@aboveskip\z@ \let\lst@belowskip\z@} |
| 14587 |
% \end{macrocode} |
| 14588 |
% \end{lstkey}\end{lstkey} |
| 14589 |
% |
| 14590 |
% \begin{lstkey}{everydisplay} |
| 14591 |
% \begin{macro}{\lst@ifdisplaystyle} |
| 14592 |
% Some things depend on display-style listings. |
| 14593 |
% \begin{macrocode} |
| 14594 |
\lst@Key{everydisplay}{}{\def\lst@EveryDisplay{#1}} |
| 14595 |
\lst@AddToHook{TextStyle}{\let\lst@ifdisplaystyle\iffalse} |
| 14596 |
\lst@AddToHook{DisplayStyle}{\let\lst@ifdisplaystyle\iftrue} |
| 14597 |
\let\lst@ifdisplaystyle\iffalse |
| 14598 |
% \end{macrocode} |
| 14599 |
% \end{macro} |
| 14600 |
% \end{lstkey} |
| 14601 |
% |
| 14602 |
% \begin{macro}{\lst@Init} |
| 14603 |
% Begin a float or multicolumn environment if requested. |
| 14604 |
% \begin{macrocode} |
| 14605 |
\def\lst@Init#1{% |
| 14606 |
\begingroup |
| 14607 |
\ifx\lst@float\relax\else |
| 14608 |
\edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\lst@float]}% |
| 14609 |
\expandafter\@tempa |
| 14610 |
\fi |
| 14611 |
\ifx\lst@multicols\@empty\else |
| 14612 |
\edef\lst@next{\noexpand\multicols{\lst@multicols}} |
| 14613 |
\expandafter\lst@next |
| 14614 |
\fi |
| 14615 |
% \end{macrocode} |
| 14616 |
% In restricted horizontal \TeX\ mode we switch to |\lst@boxtrue|. |
| 14617 |
% In that case we make appropriate box(es) around the listing. |
| 14618 |
% \begin{macrocode} |
| 14619 |
\ifhmode\ifinner \lst@boxtrue \fi\fi |
| 14620 |
\lst@ifbox |
| 14621 |
\lsthk@BoxUnsafe |
| 14622 |
\hbox to\z@\bgroup |
| 14623 |
$\if t\lst@boxpos \vtop |
| 14624 |
\else \if b\lst@boxpos \vbox |
| 14625 |
\else \vcenter \fi\fi |
| 14626 |
\bgroup \par\noindent |
| 14627 |
\else |
| 14628 |
\lst@ifdisplaystyle |
| 14629 |
\lst@EveryDisplay |
| 14630 |
\par\penalty-50\relax |
| 14631 |
\vspace\lst@aboveskip |
| 14632 |
\fi |
| 14633 |
\fi |
| 14634 |
% \end{macrocode} ^^A$ to make emacs font locking happy |
| 14635 |
% Moved |\vspace| after |\par|---or we can get an empty line atop listings. |
| 14636 |
% Bug reported by \lsthelper{Jim~Hefferon}{1999/08/27}{empty line before |
| 14637 |
% listings with |\lstinputlisting|}. |
| 14638 |
% |
| 14639 |
% Now make the top caption. |
| 14640 |
% \begin{macrocode} |
| 14641 |
\normalbaselines |
| 14642 |
\abovecaptionskip\lst@abovecaption\relax |
| 14643 |
\belowcaptionskip\lst@belowcaption\relax |
| 14644 |
\lst@MakeCaption t% |
| 14645 |
% \end{macrocode} |
| 14646 |
% Some initialization. |
| 14647 |
% I removed |\par\nointerlineskip| |\normalbaselines| after bug report from |
| 14648 |
% \lsthelper{Jim~Hefferon}{1999/08/23}{bad vertical space after lstlisting}. |
| 14649 |
% He reported the same problem as Aidan Philip Heerdegen (see below), but I |
| 14650 |
% immediately saw the bug here since Jim used |\parskip|$\,\neq0$. |
| 14651 |
% \begin{macrocode} |
| 14652 |
\lsthk@PreInit \lsthk@Init |
| 14653 |
\lst@ifdisplaystyle |
| 14654 |
\global\let\lst@ltxlabel\@empty |
| 14655 |
\if@inlabel |
| 14656 |
\lst@ifresetmargins |
| 14657 |
\leavevmode |
| 14658 |
\else |
| 14659 |
\xdef\lst@ltxlabel{\the\everypar}% |
| 14660 |
\lst@AddTo\lst@ltxlabel{% |
| 14661 |
\global\let\lst@ltxlabel\@empty |
| 14662 |
\everypar{\lsthk@EveryLine\lsthk@EveryPar}}% |
| 14663 |
\fi |
| 14664 |
\fi |
| 14665 |
\everypar\expandafter{\lst@ltxlabel |
| 14666 |
\lsthk@EveryLine\lsthk@EveryPar}% |
| 14667 |
\else |
| 14668 |
\everypar{}\let\lst@NewLine\@empty |
| 14669 |
\fi |
| 14670 |
\lsthk@InitVars \lsthk@InitVarsBOL |
| 14671 |
% \end{macrocode} |
| 14672 |
% The end of line character |chr(13)|=|^^M| controls the processing, see the |
| 14673 |
% definition of |\lst@MProcessListing| below. |
| 14674 |
% The argument |#1| is either |\relax| or |\lstenv@backslash|. |
| 14675 |
% \begin{macrocode} |
| 14676 |
\lst@Let{13}\lst@MProcessListing |
| 14677 |
\let\lst@Backslash#1% |
| 14678 |
\lst@EnterMode{\lst@Pmode}{\lst@SelectCharTable}% |
| 14679 |
\lst@InitFinalize} |
| 14680 |
% \end{macrocode} |
| 14681 |
% Note: From version 0.19 on `listing processing' is implemented as an internal |
| 14682 |
% mode, namely a mode with special character table. Since a bug report from |
| 14683 |
% \lsthelper{Fermin~Reig}{2002/09/04}{bad top frame inside figure+centering} |
| 14684 |
% |\rightskip| and the others are reset via \hookname{PreInit} and not via |
| 14685 |
% \hookname{InitVars}. |
| 14686 |
% \begin{macrocode} |
| 14687 |
\let\lst@InitFinalize\@empty % init |
| 14688 |
\lst@AddToHook{PreInit} |
| 14689 |
{\rightskip\z@ \leftskip\z@ \parfillskip=\z@ plus 1fil |
| 14690 |
\let\par\@@par} |
| 14691 |
\lst@AddToHook{EveryLine}{}% init |
| 14692 |
\lst@AddToHook{EveryPar}{}% init |
| 14693 |
% \end{macrocode} |
| 14694 |
% \end{macro} |
| 14695 |
% |
| 14696 |
% \begin{lstkey}{showlines} |
| 14697 |
% lets the user control whether empty lines at the end of a listing are |
| 14698 |
% printed. But you know that if you've read the User's guide. |
| 14699 |
% \begin{macrocode} |
| 14700 |
\lst@Key{showlines}f[t]{\lstKV@SetIf{#1}\lst@ifshowlines} |
| 14701 |
% \end{macrocode} |
| 14702 |
% \end{lstkey} |
| 14703 |
% |
| 14704 |
% \begin{macro}{\lst@DeInit} |
| 14705 |
% Output the remaining characters and update all things. First I missed to |
| 14706 |
% to use |\lst@ifdisplaystyle| here, but then \lsthelper{KP~Gores}{2001/07/11} |
| 14707 |
% {\csname{par} after each \lstinline} reported a problem. |
| 14708 |
% The |\everypar| has been put behind |\lsthk@ExitVars| after a bug report by |
| 14709 |
% \lsthelper{Michael~Niedermair}{2002/05/14}{listings.sty und caption} and |
| 14710 |
% I've added |\normalbaselines| after a bug report by \lsthelper{Georg~Rehm} |
| 14711 |
% {2002/05/14}{listings.sty und lange captions} and |\normalcolor| after a |
| 14712 |
% report by \lsthelper{Walter~E.~Brown}{2004/03/01}{captions at bottom of |
| 14713 |
% listings inherit color from basicstyle}. |
| 14714 |
% \begin{macrocode} |
| 14715 |
\def\lst@DeInit{% |
| 14716 |
\lst@XPrintToken \lst@EOLUpdate |
| 14717 |
\global\advance\lst@newlines\m@ne |
| 14718 |
\lst@ifshowlines |
| 14719 |
\lst@DoNewLines |
| 14720 |
\else |
| 14721 |
\setbox\@tempboxa\vbox{\lst@DoNewLines}% |
| 14722 |
\fi |
| 14723 |
\lst@ifdisplaystyle \par\removelastskip \fi |
| 14724 |
\lsthk@ExitVars\everypar{}\lsthk@DeInit\normalbaselines\normalcolor |
| 14725 |
% \end{macrocode} |
| 14726 |
% Place the bottom caption. |
| 14727 |
% \begin{macrocode} |
| 14728 |
\lst@MakeCaption b% |
| 14729 |
% \end{macrocode} |
| 14730 |
% Close the boxes if necessary and make a rule to get the right width. |
| 14731 |
% I added the |\par\nointerlineskip| (and removed |\nointerlineskip| later |
| 14732 |
% again) after receiving a bug report from \lsthelper{Aidan~Philip~Heerdegen} |
| 14733 |
% {1999/07/23}{wrong vertical spacing}. |\everypar{}| is due to a bug report |
| 14734 |
% from \lsthelper{Sonja~Weidmann}{2000/02/01}{listings and caption packages |
| 14735 |
% not compatible}. |
| 14736 |
% \begin{macrocode} |
| 14737 |
\lst@ifbox |
| 14738 |
\egroup $\hss \egroup |
| 14739 |
\vrule\@width\lst@maxwidth\@height\z@\@depth\z@ |
| 14740 |
\else |
| 14741 |
\lst@ifdisplaystyle |
| 14742 |
\par\penalty-50\vspace\lst@belowskip |
| 14743 |
\fi |
| 14744 |
\fi |
| 14745 |
% \end{macrocode} |
| 14746 |
% End the multicolumn environment and/or float if necessary. |
| 14747 |
% \begin{macrocode} |
| 14748 |
\ifx\lst@multicols\@empty\else |
| 14749 |
\def\lst@next{\global\let\@checkend\@gobble |
| 14750 |
\endmulticols |
| 14751 |
\global\let\@checkend\lst@@checkend} |
| 14752 |
\expandafter\lst@next |
| 14753 |
\fi |
| 14754 |
\ifx\lst@float\relax\else |
| 14755 |
\expandafter\lst@endfloat |
| 14756 |
\fi |
| 14757 |
\endgroup} |
| 14758 |
\let\lst@@checkend\@checkend |
| 14759 |
% \end{macrocode} |
| 14760 |
% \end{macro} |
| 14761 |
% |
| 14762 |
% \begin{macro}{\lst@maxwidth} |
| 14763 |
% is to be allocated, initialized and updated. |
| 14764 |
% \begin{macrocode} |
| 14765 |
\newdimen\lst@maxwidth % \global |
| 14766 |
\lst@AddToHook{InitVars}{\global\lst@maxwidth\z@} |
| 14767 |
\lst@AddToHook{InitVarsEOL} |
| 14768 |
{\ifdim\lst@currlwidth>\lst@maxwidth |
| 14769 |
\global\lst@maxwidth\lst@currlwidth |
| 14770 |
\fi} |
| 14771 |
% \end{macrocode} |
| 14772 |
% \end{macro} |
| 14773 |
% |
| 14774 |
% \begin{macro}{\lst@EOLUpdate} |
| 14775 |
% What do you think this macro does? |
| 14776 |
% \begin{macrocode} |
| 14777 |
\def\lst@EOLUpdate{\lsthk@EOL \lsthk@InitVarsEOL} |
| 14778 |
% \end{macrocode} |
| 14779 |
% \end{macro} |
| 14780 |
% |
| 14781 |
% \begin{macro}{\lst@MProcessListing} |
| 14782 |
% This is what we have to do at EOL while processing a listing. |
| 14783 |
% We output all remaining characters and update the variables. |
| 14784 |
% If we've reached the last line, we check whether there is a next line |
| 14785 |
% interval to input or not. |
| 14786 |
% \begin{macrocode} |
| 14787 |
\def\lst@MProcessListing{% |
| 14788 |
\lst@XPrintToken \lst@EOLUpdate \lsthk@InitVarsBOL |
| 14789 |
\global\advance\lst@lineno\@ne |
| 14790 |
\ifnum \lst@lineno>\lst@lastline |
| 14791 |
\lst@ifdropinput \lst@LeaveMode \fi |
| 14792 |
\ifx\lst@linerange\@empty |
| 14793 |
\expandafter\expandafter\expandafter\lst@EndProcessListing |
| 14794 |
\else |
| 14795 |
\lst@interrange |
| 14796 |
\lst@GetLineInterval |
| 14797 |
\expandafter\expandafter\expandafter\lst@SkipToFirst |
| 14798 |
\fi |
| 14799 |
\else |
| 14800 |
\expandafter\lst@BOLGobble |
| 14801 |
\fi} |
| 14802 |
% \end{macrocode} |
| 14803 |
% \end{macro} |
| 14804 |
% |
| 14805 |
% \begin{macro}{\lst@EndProcessListing} |
| 14806 |
% Default definition is |\endinput|. |
| 14807 |
% This works for |\lstinputlisting|. |
| 14808 |
% \begin{macrocode} |
| 14809 |
\let\lst@EndProcessListing\endinput |
| 14810 |
% \end{macrocode} |
| 14811 |
% \end{macro} |
| 14812 |
% |
| 14813 |
% \begin{lstkey}{gobble} |
| 14814 |
% The key sets the number of characters to gobble each line. |
| 14815 |
% \begin{macrocode} |
| 14816 |
\lst@Key{gobble}{0}{\def\lst@gobble{#1}} |
| 14817 |
% \end{macrocode} |
| 14818 |
% \end{lstkey} |
| 14819 |
% |
| 14820 |
% \begin{macro}{\lst@BOLGobble} |
| 14821 |
% If the number is positive, we set a temporary counter and start a loop. |
| 14822 |
% \begin{macrocode} |
| 14823 |
\def\lst@BOLGobble{% |
| 14824 |
\ifnum\lst@gobble>\z@ |
| 14825 |
\@tempcnta\lst@gobble\relax |
| 14826 |
\expandafter\lst@BOLGobble@ |
| 14827 |
\fi} |
| 14828 |
% \end{macrocode} |
| 14829 |
% A nonpositive number terminates the loop (by not continuing). |
| 14830 |
% Note: This is not the macro just used in |\lst@BOLGobble|. |
| 14831 |
% \begin{macrocode} |
| 14832 |
\def\lst@BOLGobble@@{% |
| 14833 |
\ifnum\@tempcnta>\z@ |
| 14834 |
\expandafter\lst@BOLGobble@ |
| 14835 |
\fi} |
| 14836 |
% \end{macrocode} |
| 14837 |
% If we gobble a backslash, we have to look whether this backslash ends an |
| 14838 |
% environment. Whether the coming characters equal e.g.~|end{lstlisting}|, |
| 14839 |
% we either end the environment or insert all just eaten characters after the |
| 14840 |
% `continue loop' macro. |
| 14841 |
% \begin{macrocode} |
| 14842 |
\def\lstenv@BOLGobble@@{% |
| 14843 |
\lst@IfNextChars\lstenv@endstring{\lstenv@End}% |
| 14844 |
{\advance\@tempcnta\m@ne \expandafter\lst@BOLGobble@@\lst@eaten}} |
| 14845 |
% \end{macrocode} |
| 14846 |
% Now comes the loop: if we read |\relax|, EOL or FF, the next operation is |
| 14847 |
% exactly the same token. Note that for FF (and tabs below) we test against |
| 14848 |
% a macro which contains |\lst@ProcessFormFeed|. This was a bug analyzed by |
| 14849 |
% \lsthelper{Heiko~Oberdiek}{2002/04/16}{Re: first experience ...}. |
| 14850 |
% \begin{macrocode} |
| 14851 |
\def\lst@BOLGobble@#1{% |
| 14852 |
\let\lst@next#1% |
| 14853 |
\ifx \lst@next\relax\else |
| 14854 |
\ifx \lst@next\lst@MProcessListing\else |
| 14855 |
\ifx \lst@next\lst@processformfeed\else |
| 14856 |
% \end{macrocode} |
| 14857 |
% Otherwise we use one of the two submacros. |
| 14858 |
% \begin{macrocode} |
| 14859 |
\ifx \lst@next\lstenv@backslash |
| 14860 |
\let\lst@next\lstenv@BOLGobble@@ |
| 14861 |
\else |
| 14862 |
\let\lst@next\lst@BOLGobble@@ |
| 14863 |
% \end{macrocode} |
| 14864 |
% Now we really gobble characters. A tabulator decreases the temporary counter |
| 14865 |
% by |\lst@tabsize| (and deals with remaining amounts, if necessary), \ldots |
| 14866 |
% \begin{macrocode} |
| 14867 |
\ifx #1\lst@processtabulator |
| 14868 |
\advance\@tempcnta-\lst@tabsize\relax |
| 14869 |
\ifnum\@tempcnta<\z@ |
| 14870 |
\lst@length-\@tempcnta \lst@PreGotoTabStop |
| 14871 |
\fi |
| 14872 |
% \end{macrocode} |
| 14873 |
% \ldots\space whereas any other character decreases the counter by one. |
| 14874 |
% \begin{macrocode} |
| 14875 |
\else |
| 14876 |
\advance\@tempcnta\m@ne |
| 14877 |
\fi |
| 14878 |
\fi \fi \fi \fi |
| 14879 |
\lst@next} |
| 14880 |
% \end{macrocode} |
| 14881 |
% \begin{macrocode} |
| 14882 |
\def\lst@processformfeed{\lst@ProcessFormFeed} |
| 14883 |
\def\lst@processtabulator{\lst@ProcessTabulator} |
| 14884 |
% \end{macrocode} |
| 14885 |
% \end{macro} |
| 14886 |
% |
| 14887 |
% |
| 14888 |
% \subsection{List of listings}% |
| 14889 |
% \label{sec:list-listings} |
| 14890 |
% |
| 14891 |
% \begin{lstkey}{name} |
| 14892 |
% \begin{macro}{\lstname} |
| 14893 |
% \begin{macro}{\lst@name} |
| 14894 |
% \begin{macro}{\lst@intname} |
| 14895 |
% Each pretty-printing command values |\lst@intname| before setting any keys. |
| 14896 |
% \begin{macrocode} |
| 14897 |
\lst@Key{name}\relax{\def\lst@intname{#1}} |
| 14898 |
\lst@AddToHookExe{PreSet}{\global\let\lst@intname\@empty} |
| 14899 |
\lst@AddToHook{PreInit}{% |
| 14900 |
\let\lst@arg\lst@intname \lst@ReplaceIn\lst@arg\lst@filenamerpl |
| 14901 |
\global\let\lst@name\lst@arg \global\let\lstname\lst@name} |
| 14902 |
% \end{macrocode} |
| 14903 |
% Use of |\lst@ReplaceIn| removes a bug first reported by |
| 14904 |
% \lsthelper{Magne~Rudshaug}{1998/01/09}{_ and list of listings}. |
| 14905 |
% Here is the replacement list. |
| 14906 |
% \begin{macrocode} |
| 14907 |
\def\lst@filenamerpl{_\textunderscore $\textdollar -\textendash} |
| 14908 |
% \end{macrocode} ^^A $ |
| 14909 |
% \end{macro} |
| 14910 |
% \end{macro} |
| 14911 |
% \end{macro} |
| 14912 |
% \end{lstkey} |
| 14913 |
% |
| 14914 |
% \begin{macro}{\l@lstlisting} |
| 14915 |
% prints one `lol' line. |
| 14916 |
% \begin{macrocode} |
| 14917 |
\def\l@lstlisting#1#2{\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}} |
| 14918 |
% \end{macrocode} |
| 14919 |
% \end{macro} |
| 14920 |
% |
| 14921 |
% \begin{macro}{\lstlistlistingname} |
| 14922 |
% contains simply the header name. |
| 14923 |
% \begin{macrocode} |
| 14924 |
\lst@UserCommand\lstlistlistingname{Listings} |
| 14925 |
% \end{macrocode} |
| 14926 |
% \end{macro} |
| 14927 |
% |
| 14928 |
% \begin{macro}{\lstlistoflistings} |
| 14929 |
% We make local adjustments and call |\tableofcontents|. This way, |
| 14930 |
% redefinitions of that macro (e.g.~without any |\MakeUppercase| inside) |
| 14931 |
% also take effect on the list of listings. |
| 14932 |
% \begin{macrocode} |
| 14933 |
\lst@UserCommand\lstlistoflistings{\bgroup |
| 14934 |
\let\contentsname\lstlistlistingname |
| 14935 |
\let\lst@temp\@starttoc |
| 14936 |
\def\@starttoc##1{\lst@temp{\ext@lstlisting}}% |
| 14937 |
\tableofcontents \egroup} |
| 14938 |
% \end{macrocode} |
| 14939 |
% For \packagename{KOMA}-script classes, we define it a la \packagename{KOMA} |
| 14940 |
% thanks to a bug report by |
| 14941 |
% \lsthelper{Tino~Langer}{2003/11/01}{koma-script's listsleft option does not |
| 14942 |
% affect lol}. \lsthelper{Markus~Kohm}{2006/08/12}{koma-script support is |
| 14943 |
% broken} suggested a much-improved version of this, which also works with |
| 14944 |
% the \packagename{float} package. The following few comments are from Markus. |
| 14945 |
% |
| 14946 |
% Make use of |\float@listhead| if defined (e.g. using float) |
| 14947 |
% \begin{macrocode} |
| 14948 |
\@ifundefined{float@listhead}{}{% |
| 14949 |
\renewcommand*{\lstlistoflistings}{% |
| 14950 |
\begingroup |
| 14951 |
% \end{macrocode} |
| 14952 |
% Switch to one-column mode if the switch for switching is available. |
| 14953 |
% \begin{macrocode} |
| 14954 |
\@ifundefined{@restonecoltrue}{}{% |
| 14955 |
\if@twocolumn |
| 14956 |
\@restonecoltrue\onecolumn |
| 14957 |
\else |
| 14958 |
\@restonecolfalse |
| 14959 |
\fi |
| 14960 |
}% |
| 14961 |
\float@listhead{\lstlistlistingname}% |
| 14962 |
% \end{macrocode} |
| 14963 |
% Set |\parskip| to 0pt (should be!), |\parindent| to 0pt (better but not always |
| 14964 |
% needed), |\parfillskip| to 0pt plus 1fil (should be!). |
| 14965 |
% \begin{macrocode} |
| 14966 |
\parskip\z@\parindent\z@\parfillskip \z@ \@plus 1fil% |
| 14967 |
\@starttoc{\ext@lstlisting}% |
| 14968 |
% \end{macrocode} |
| 14969 |
% Switch back to twocolumn (see above). |
| 14970 |
% \begin{macrocode} |
| 14971 |
\@ifundefined{@restonecoltrue}{}{% |
| 14972 |
\if@restonecol\twocolumn\fi |
| 14973 |
}% |
| 14974 |
\endgroup |
| 14975 |
}% |
| 14976 |
} |
| 14977 |
% \end{macrocode} |
| 14978 |
% Make use of package tocbasic if loaded: |
| 14979 |
% \begin{macrocode} |
| 14980 |
\AtBeginDocument{% |
| 14981 |
\@ifpackageloaded{tocbasic}{% |
| 14982 |
\addtotoclist[float]{\ext@lstlisting}% |
| 14983 |
\renewcommand*{\lstlistoflistings}{\listoftoc[{\lstlistlistingname}]{lol}}% |
| 14984 |
\DeclareTOCStyleEntry[level=1,numwidth=2.3em,indent=1.5em]{default}{lstlisting}% |
| 14985 |
}{}% |
| 14986 |
} |
| 14987 |
% \end{macrocode} |
| 14988 |
% \end{macro} |
| 14989 |
% |
| 14990 |
% \begin{macro}{\float@addtolists} |
| 14991 |
% The \packagename{float} package defines a generic way for packages to add |
| 14992 |
% things (such as chapter names) to all of the lists of floats other than the |
| 14993 |
% standard figure and table lists. Each package that defines a list of |
| 14994 |
% floats adds a command to |\float@addtolists|, and then packages (such as |
| 14995 |
% the KOMA-script document classes) which wish to add things to all lists of |
| 14996 |
% floats can then use it, without needing to be aware of all of the possible |
| 14997 |
% lists that could exist. Thanks to \lsthelper{Markus~Kohm}{2007/02/25}{-} |
| 14998 |
% for the suggestion. |
| 14999 |
% |
| 15000 |
% Unfortunately, \packagename{float} defines this with |\newcommand|; thus, |
| 15001 |
% to avoid conflict, we have to redefine it after \packagename{float} is |
| 15002 |
% loaded. |\AtBeginDocument| is the easiest way to do this. Again, thanks |
| 15003 |
% to Markus for the advice. |
| 15004 |
% \begin{macrocode} |
| 15005 |
\AtBeginDocument{% |
| 15006 |
\@ifundefined{KOMAClassName}{% |
| 15007 |
\@ifundefined{float@addtolists}{% |
| 15008 |
\gdef\float@addtolists#1{\addtocontents{\ext@lstlisting}{#1}}% |
| 15009 |
}{% |
| 15010 |
\let\orig@float@addtolists\float@addtolists |
| 15011 |
\gdef\float@addtolists#1{% |
| 15012 |
\addtocontents{\ext@lstlisting}{#1}% |
| 15013 |
\orig@float@addtolists{#1}}}% |
| 15014 |
}{}% |
| 15015 |
}% |
| 15016 |
% \end{macrocode} |
| 15017 |
% \end{macro} |
| 15018 |
% |
| 15019 |
% |
| 15020 |
% \subsection{Inline listings}\label{iInlineListings} |
| 15021 |
% |
| 15022 |
% \subsubsection{Processing inline listings}\label{uProcessingInline} |
| 15023 |
% |
| 15024 |
% \begin{macro}{\lstinline} |
| 15025 |
% In addition to |\lsthk@PreSet|, we use |boxpos=b| and |
| 15026 |
% flexiblecolumns. I've inserted |\leavevmode| after bug report from |
| 15027 |
% \lsthelper{Michael~Weber} {1999/12/16}{wrong spacing in list |
| 15028 |
% environments}. \lsthelper{Olivier~Lecarme} {2001/07/30}{inconsistent |
| 15029 |
% `break' when \lstinline is used inside caption} reported a problem |
| 15030 |
% which has gone after removing |\let| |\lst@newlines| |\@empty| (now |
| 15031 |
% |\lst@newlines| is a counter!). Unfortunately I don't know the reason |
| 15032 |
% for inserting this code some time ago! At the end of the macro we |
| 15033 |
% check the delimiter.\footnote{This is text of the original author |
| 15034 |
% Carsten Heinz.} |
| 15035 |
% |
| 15036 |
% Then came an experimental version which allowed braces, but |
| 15037 |
% \lsthelper{Luc~Van~Eycken}{2014/01/22}{\rcmdname\lstinline{} in |
| 15038 |
% alignments} reported, that the experimental implementation of |
| 15039 |
% |\lstinline| with braces instead of characters surrounding the source |
| 15040 |
% code resulted in an error if used in a tabular environment. |
| 15041 |
% |
| 15042 |
% He found that this error comes from the master counter (cf. appendix |
| 15043 |
% D (Dirty Tricks), item 5. (Brace hacks), of the TeXbook |
| 15044 |
% (p. 385-386)). Adding the following line after testing the next |
| 15045 |
% character (line no. 7 in the following outcommented snippet) |
| 15046 |
%\begin{verbatim} |
| 15047 |
%\ifnum`{=0}\fi% |
| 15048 |
%\end{verbatim} |
| 15049 |
% remedies the wrong behaviour. But \lsthelper{Qing~Lee}{2014/06/28}{-} |
| 15050 |
% pointed out, that this breaks code like the one shown in section |
| 15051 |
% \ref{uListingsArguments} on page \pageref{uListingsArguments} and |
| 15052 |
% proposed another solution which in turn broke the code provided by |
| 15053 |
% Luc: |
| 15054 |
%\begin{verbatim} |
| 15055 |
% \renewcommand\lstinline[1][]{% |
| 15056 |
% \leavevmode\bgroup % \hbox\bgroup --> \bgroup |
| 15057 |
% \def\lst@boxpos{b}% |
| 15058 |
% \lsthk@PreSet\lstset{flexiblecolumns,#1}% |
| 15059 |
% \lsthk@TextStyle |
| 15060 |
% \ifnum\iffalse{\fi`}=\z@\fi |
| 15061 |
% \@ifnextchar\bgroup{% |
| 15062 |
% \ifnum`{=\z@}\fi% |
| 15063 |
% \afterassignment\lst@InlineG \let\@let@token}{% |
| 15064 |
% \ifnum`{=\z@}\fi\lstinline@}% |
| 15065 |
%} |
| 15066 |
%\end{verbatim} |
| 15067 |
% So finally the old code came back and the people, who needed a |
| 15068 |
% |\lstinline| with braces, should use the workaround from section |
| 15069 |
% \ref{uListingsArguments} on page \pageref{uListingsArguments}. |
| 15070 |
% |
| 15071 |
% This long outstanding deficiency is now repaired by |
| 15072 |
% \lsthelper{user5028841}{2024/05/05}{Regarding the Listings package} |
| 15073 |
% who provided a solution by using special characters as begin and end |
| 15074 |
% of a group: |
| 15075 |
% \begin{macrocode} |
| 15076 |
\edef\lst@temp{\the\catcode`\^^@} |
| 15077 |
\catcode`\^^@=1 |
| 15078 |
\newcommand\lstinline[1][]{% |
| 15079 |
\leavevmode\bgroup % \hbox\bgroup --> \bgroup |
| 15080 |
\def\lst@boxpos{b}% |
| 15081 |
\lsthk@PreSet\lstset{flexiblecolumns,#1}% |
| 15082 |
\lsthk@TextStyle |
| 15083 |
\@ifnextchar\bgroup{% |
| 15084 |
\afterassignment\lst@InlineG \romannumeral`^^@\iffalse}\fi |
| 15085 |
\let\@let@token}% |
| 15086 |
\lstinline@} |
| 15087 |
% \end{macrocode} |
| 15088 |
% Here we restore the previous catcode of |\^^@|: |
| 15089 |
% \begin{macrocode} |
| 15090 |
\catcode`\^^@=\lst@temp |
| 15091 |
% \end{macrocode} |
| 15092 |
% \end{macro} |
| 15093 |
% \begin{macro}{\lst@inline@} |
| 15094 |
% This is the standard method after processing the optional arguments |
| 15095 |
% of |\lstinline|. |
| 15096 |
% \begin{macrocode} |
| 15097 |
\def\lstinline@#1{% |
| 15098 |
\lst@Init\relax |
| 15099 |
\lst@IfNextCharActive{\lst@InlineM#1}{\lst@InlineJ#1}} |
| 15100 |
% \end{macrocode} |
| 15101 |
% \begin{macrocode} |
| 15102 |
\lst@AddToHook{TextStyle}{}% init |
| 15103 |
\lst@AddToHook{SelectCharTable}{\lst@inlinechars} |
| 15104 |
\global\let\lst@inlinechars\@empty |
| 15105 |
% \end{macrocode} |
| 15106 |
% \end{macro} |
| 15107 |
% |
| 15108 |
% \begin{macro}{\lst@InlineM} |
| 15109 |
% \begin{macro}{\lst@InlineJ} |
| 15110 |
% treat the cases of `normal' inlines and inline listings inside an |
| 15111 |
% argument. In the first case the given character ends the inline |
| 15112 |
% listing and EOL within such a listing immediately ends it and |
| 15113 |
% produces an error message. |
| 15114 |
% \begin{macrocode} |
| 15115 |
\def\lst@InlineM#1{% |
| 15116 |
\gdef\lst@inlinechars{% |
| 15117 |
\lst@Def{`#1}{\lst@DeInit\egroup\global\let\lst@inlinechars\@empty}% |
| 15118 |
\lst@Def{13}{\lst@DeInit\egroup \global\let\lst@inlinechars\@empty |
| 15119 |
\PackageError{Listings}{lstinline ended by EOL}\@ehc}}% |
| 15120 |
\lst@inlinechars} |
| 15121 |
% \end{macrocode} |
| 15122 |
% In the other case we get all characters up to |#1|, make these characters |
| 15123 |
% active, execute (typeset) them and end the listing (all via temporary macro). |
| 15124 |
% That's all about it. |
| 15125 |
% \begin{macrocode} |
| 15126 |
\def\lst@InlineJ#1{% |
| 15127 |
\def\lst@temp##1#1{% |
| 15128 |
\let\lst@arg\@empty \lst@InsideConvert{##1}\lst@arg |
| 15129 |
\lst@DeInit\egroup}% |
| 15130 |
\lst@temp} |
| 15131 |
% \end{macrocode} |
| 15132 |
% \end{macro} |
| 15133 |
% \end{macro} |
| 15134 |
% |
| 15135 |
% \begin{macro}{\lst@InlineG} |
| 15136 |
% is experimental. |
| 15137 |
% \begin{macrocode} |
| 15138 |
\def\lst@InlineG{% |
| 15139 |
\lst@Init\relax |
| 15140 |
\lst@IfNextCharActive{\lst@InlineM\}}{% |
| 15141 |
\let\lst@arg\@empty \lst@InlineGJ}} |
| 15142 |
% \end{macrocode} |
| 15143 |
% This is the point for closing the group: |
| 15144 |
% \begin{macrocode} |
| 15145 |
\edef\lst@temp{\the\catcode`\^^@} |
| 15146 |
\catcode`\^^@=2 |
| 15147 |
\def\lst@InlineGJ{\futurelet\@let@token\lst@InlineGJTest} |
| 15148 |
\def\lst@InlineGJTest{% |
| 15149 |
\ifx\@let@token\egroup |
| 15150 |
\iffalse{\fi\romannumeral`^^@ |
| 15151 |
\afterassignment\lst@InlineGJEnd |
| 15152 |
\expandafter\let\expandafter\@let@token |
| 15153 |
\else |
| 15154 |
\ifx\@let@token\@sptoken |
| 15155 |
\let\lst@next\lst@InlineGJReadSp |
| 15156 |
\else |
| 15157 |
\let\lst@next\lst@InlineGJRead |
| 15158 |
\fi |
| 15159 |
\expandafter\lst@next |
| 15160 |
\fi} |
| 15161 |
% \end{macrocode} |
| 15162 |
% As before: restore the previous catcode of |\^^@|: |
| 15163 |
% \begin{macrocode} |
| 15164 |
\catcode`\^^@=\lst@temp |
| 15165 |
\def\lst@InlineGJEnd{\lst@arg\lst@DeInit\egroup} |
| 15166 |
\def\lst@InlineGJRead#1{% |
| 15167 |
\lccode`\~=`#1\lowercase{\lst@lAddTo\lst@arg~}% |
| 15168 |
\lst@InlineGJ} |
| 15169 |
\def\lst@InlineGJReadSp#1{% |
| 15170 |
\lccode`\~=`\ \lowercase{\lst@lAddTo\lst@arg~}% |
| 15171 |
\lst@InlineGJ#1} |
| 15172 |
% \end{macrocode} |
| 15173 |
% \end{macro} |
| 15174 |
% |
| 15175 |
% |
| 15176 |
% \subsubsection{Short inline listing environments} |
| 15177 |
% |
| 15178 |
% The implementation in this section is based on the \packagename{shortvrb} |
| 15179 |
% package, which is part of |doc.dtx| from the Standard \LaTeX\ documentation |
| 15180 |
% package, version 2006/02/02 v2.1d. Portions of it are thus copyright |
| 15181 |
% 1993--2006 by The \LaTeX3 Project and copyright 1989--1999 by Frank |
| 15182 |
% Mittelbach. \lsthelper{Denis~Bitouz\'e}{2020/03/21} |
| 15183 |
% {Typos in error messages} used the Corona crisis to have look at the |
| 15184 |
% error messages and found some typos. |
| 15185 |
% |
| 15186 |
% \begin{macro}{\lstMakeShortInline} |
| 15187 |
% \begin{macro}{\lstMakeShortInline@} |
| 15188 |
% First, we supply an optional argument if it's omitted. |
| 15189 |
% \begin{macrocode} |
| 15190 |
\newcommand\lstMakeShortInline[1][]{% |
| 15191 |
\def\lst@shortinlinedef{\lstinline[#1]}% |
| 15192 |
\lstMakeShortInline@}% |
| 15193 |
\def\lstMakeShortInline@#1{% |
| 15194 |
\expandafter\ifx\csname lst@ShortInlineOldCatcode\string#1\endcsname\relax |
| 15195 |
\lst@shortlstinlineinfo{Made }{#1}% |
| 15196 |
\lst@add@special{#1}% |
| 15197 |
% \end{macrocode} |
| 15198 |
% The character's current catcode is stored in |
| 15199 |
% |\lst@ShortInlineOldCatcode\|\meta{c}. |
| 15200 |
% \begin{macrocode} |
| 15201 |
\expandafter |
| 15202 |
\xdef\csname lst@ShortInlineOldCatcode\string#1\endcsname{% |
| 15203 |
\the\catcode`#1}% |
| 15204 |
% \end{macrocode} |
| 15205 |
% The character is spliced into the definition using the same trick as |
| 15206 |
% used in |\verb| (for instance), having activated |~| in a group. |
| 15207 |
% \begin{macrocode} |
| 15208 |
\begingroup |
| 15209 |
\catcode`\~\active \lccode`\~`#1% |
| 15210 |
\lowercase{% |
| 15211 |
% \end{macrocode} |
| 15212 |
% The character's old meaning is recorded |
| 15213 |
% in |\lst@ShortInlineOldMeaning\|\meta{c} prior to assigning it a new one. |
| 15214 |
% \begin{macrocode} |
| 15215 |
\global\expandafter\let |
| 15216 |
\csname lst@ShortInlineOldMeaning\string#1\endcsname~% |
| 15217 |
\expandafter\gdef\expandafter~\expandafter{% |
| 15218 |
\lst@shortinlinedef#1}}% |
| 15219 |
\endgroup |
| 15220 |
% \end{macrocode} |
| 15221 |
% Finally the character is made active. |
| 15222 |
% \begin{macrocode} |
| 15223 |
\global\catcode`#1\active |
| 15224 |
% \end{macrocode} |
| 15225 |
% If we suspect that \meta{c} is already a short reference, we tell |
| 15226 |
% the user. Now he or she is responsible if anything goes wrong\,\dots |
| 15227 |
% (Change in \packagename{listings}: We give a proper error here.) |
| 15228 |
% \begin{macrocode} |
| 15229 |
\else |
| 15230 |
\PackageError{Listings}% |
| 15231 |
{\string\lstMakeShorterInline\ definitions cannot be nested}% |
| 15232 |
{Use \string\lstDeleteShortInline first.}% |
| 15233 |
{}% |
| 15234 |
\fi} |
| 15235 |
% \end{macrocode} |
| 15236 |
% \end{macro} |
| 15237 |
% \end{macro} |
| 15238 |
% \begin{macro}{\lstDeleteShortInline} |
| 15239 |
% \begin{macrocode} |
| 15240 |
\def\lstDeleteShortInline#1{% |
| 15241 |
\expandafter\ifx% |
| 15242 |
\csname lst@ShortInlineOldCatcode\string#1\endcsname\relax% |
| 15243 |
\PackageError{Listings}% |
| 15244 |
{#1 is not a short reference for \string\lstinline}% |
| 15245 |
{Use \string\lstMakeShortInline first.}% |
| 15246 |
{}% |
| 15247 |
\else |
| 15248 |
\lst@shortlstinlineinfo{Deleted }{#1 as}% |
| 15249 |
\lst@rem@special{#1}% |
| 15250 |
\global\catcode`#1\csname lst@ShortInlineOldCatcode\string#1\endcsname |
| 15251 |
\global \expandafter\let% |
| 15252 |
\csname lst@ShortInlineOldCatcode\string#1\endcsname \relax |
| 15253 |
\ifnum\catcode`#1=\active |
| 15254 |
\begingroup |
| 15255 |
\catcode`\~\active \lccode`\~`#1% |
| 15256 |
\lowercase{% |
| 15257 |
\global\expandafter\let\expandafter~% |
| 15258 |
\csname lst@ShortInlineOldMeaning\string#1\endcsname}% |
| 15259 |
\endgroup |
| 15260 |
\fi |
| 15261 |
\fi} |
| 15262 |
% \end{macrocode} |
| 15263 |
% \end{macro} |
| 15264 |
% |
| 15265 |
% \begin{macro}{\lst@shortlstinlineinfo} |
| 15266 |
% \begin{macrocode} |
| 15267 |
\def\lst@shortlstinlineinfo#1#2{% |
| 15268 |
\PackageInfo{Listings}{% |
| 15269 |
#1\string#2 a short reference for \string\lstinline}} |
| 15270 |
% \end{macrocode} |
| 15271 |
% \end{macro} |
| 15272 |
% |
| 15273 |
% \begin{macro}{\lst@add@special} |
| 15274 |
% This helper macro adds its argument to the |
| 15275 |
% |\dospecials| macro which is conventionally used by verbatim macros |
| 15276 |
% to alter the catcodes of the currently active characters. We need |
| 15277 |
% to add |\do\|\meta{c} to the expansion of |\dospecials| after |
| 15278 |
% removing the character if it was already there to avoid multiple |
| 15279 |
% copies building up should |\lstMakeShortInline| not be balanced by |
| 15280 |
% |\lstDeleteShortInline| (in case anything that uses |\dospecials| |
| 15281 |
% cares about repetitions). |
| 15282 |
% \begin{macrocode} |
| 15283 |
\def\lst@add@special#1{% |
| 15284 |
\lst@rem@special{#1}% |
| 15285 |
\expandafter\gdef\expandafter\dospecials\expandafter |
| 15286 |
{\dospecials \do #1}% |
| 15287 |
% \end{macrocode} |
| 15288 |
% Similarly we have to add |\@makeother\|\meta{c} to |\@sanitize| |
| 15289 |
% (which is used in things like "\index" to re-catcode all special |
| 15290 |
% characters except braces). |
| 15291 |
% \begin{macrocode} |
| 15292 |
\expandafter\gdef\expandafter\@sanitize\expandafter |
| 15293 |
{\@sanitize \@makeother #1}} |
| 15294 |
% \end{macrocode} |
| 15295 |
% \end{macro} |
| 15296 |
% \begin{macro}{\lst@rem@special} |
| 15297 |
% The inverse of |\lst@add@special| is slightly trickier. |\do| is |
| 15298 |
% re-defined to expand to nothing if its argument is the character of |
| 15299 |
% interest, otherwise to expand simply to the argument. We can then |
| 15300 |
% re-define |\dospecials| to be the expansion of itself. The space |
| 15301 |
% after |=`##1| prevents an expansion to |\relax|! |
| 15302 |
% \begin{macrocode} |
| 15303 |
\def\lst@rem@special#1{% |
| 15304 |
\def\do##1{% |
| 15305 |
\ifnum`#1=`##1 \else \noexpand\do\noexpand##1\fi}% |
| 15306 |
\xdef\dospecials{\dospecials}% |
| 15307 |
% \end{macrocode} |
| 15308 |
% Fixing |\@sanitize| is the same except that we need to re-define |
| 15309 |
% |\@makeother| which obviously needs to be done in a group. |
| 15310 |
% \begin{macrocode} |
| 15311 |
\begingroup |
| 15312 |
\def\@makeother##1{% |
| 15313 |
\ifnum`#1=`##1 \else \noexpand\@makeother\noexpand##1\fi}% |
| 15314 |
\xdef\@sanitize{\@sanitize}% |
| 15315 |
\endgroup} |
| 15316 |
% \end{macrocode} |
| 15317 |
% \end{macro} |
| 15318 |
% |
| 15319 |
% |
| 15320 |
% \subsection{The input command}\label{iTheInputCommand} |
| 15321 |
% |
| 15322 |
% \begin{macro}{\lst@MakePath} |
| 15323 |
% \begin{lstkey}{inputpath} |
| 15324 |
% The macro appends a slash to a path if necessary. |
| 15325 |
% \begin{macrocode} |
| 15326 |
\def\lst@MakePath#1{\ifx\@empty#1\@empty\else\lst@MakePath@#1/\@nil/\fi} |
| 15327 |
\def\lst@MakePath@#1/{#1/\lst@MakePath@@} |
| 15328 |
\def\lst@MakePath@@#1/{% |
| 15329 |
\ifx\@nil#1\expandafter\@gobble |
| 15330 |
\else \ifx\@empty#1\else #1/\fi \fi |
| 15331 |
\lst@MakePath@@} |
| 15332 |
% \end{macrocode} |
| 15333 |
% Now we can empty the path or use |\lst@MakePath|. |
| 15334 |
% \begin{macrocode} |
| 15335 |
\lst@Key{inputpath}{}{\edef\lst@inputpath{\lst@MakePath{#1}}} |
| 15336 |
% \end{macrocode} |
| 15337 |
% \end{lstkey} |
| 15338 |
% \end{macro} |
| 15339 |
% |
| 15340 |
% \begin{macro}{\lstinputlisting} |
| 15341 |
% inputs the listing or asks the user for a new file name. |
| 15342 |
% \begin{macrocode} |
| 15343 |
\def\lstinputlisting{% |
| 15344 |
\begingroup \lst@setcatcodes \lst@inputlisting} |
| 15345 |
\newcommand\lst@inputlisting[2][]{% |
| 15346 |
\endgroup |
| 15347 |
% \end{macrocode} |
| 15348 |
% |\lst@set| takes the local options, especially |inputpath=<path>| for |
| 15349 |
% formatting the input file. So |\lstset| must be updated to have the right |
| 15350 |
% value of |\lst@inputpath|. The whole procedure must be grouped to make |
| 15351 |
% the change local. |
| 15352 |
% \begin{macrocode} |
| 15353 |
\bgroup\def\lst@set{#1}% |
| 15354 |
\expandafter\lstset\expandafter{\lst@set}% |
| 15355 |
\IfFileExists{\lst@inputpath#2}% |
| 15356 |
{\lst@InputListing{\lst@inputpath#2}}% |
| 15357 |
{\filename@parse{\lst@inputpath#2}% |
| 15358 |
\edef\reserved@a{\noexpand\lst@MissingFileError |
| 15359 |
{\filename@area\filename@base}% |
| 15360 |
{\ifx\filename@ext\relax tex\else\filename@ext\fi}}% |
| 15361 |
\reserved@a |
| 15362 |
% \end{macrocode} |
| 15363 |
% We must provide a valid value for |\lst@doendpe| in the (error) case that there |
| 15364 |
% exists no file. |
| 15365 |
% \begin{macrocode} |
| 15366 |
\let\lst@doendpe\@empty}% |
| 15367 |
\egroup |
| 15368 |
\lst@doendpe \@newlistfalse \ignorespaces% |
| 15369 |
} |
| 15370 |
% \end{macrocode} |
| 15371 |
% We use |\lst@doendpe| to remove indention at the beginning of the next |
| 15372 |
% line---except there is an empty line after |\lstinputlisting|. Bug was |
| 15373 |
% reported by \lsthelper{David~John~Evans}{1999/06/08}{indention after |
| 15374 |
% listings} and \lsthelper{David~Carlisle}{1999/06/08}{LaTeX `display |
| 15375 |
% environment' code} pointed me to the solution. |
| 15376 |
% \end{macro} |
| 15377 |
% |
| 15378 |
% \begin{macro}{\lst@MissingFileError} |
| 15379 |
% is a derivation of \LaTeX's |\@missingfileerror|. The parenthesis have been |
| 15380 |
% added after \lsthelper{Heiko~Oberdiek}{2003/01/14}{File `Makefile.tex' not |
| 15381 |
% found} reported about a problem discussed on TEX-D-L. |
| 15382 |
% \begin{macrocode} |
| 15383 |
\def\lst@MissingFileError#1#2{% |
| 15384 |
\typeout{^^J! Package Listings Error: File `#1(.#2)' not found.^^J% |
| 15385 |
^^JType X to quit or <RETURN> to proceed,^^J% |
| 15386 |
or enter new name. (Default extension: #2)^^J}% |
| 15387 |
\message{Enter file name: }% |
| 15388 |
{\endlinechar\m@ne \global\read\m@ne to\@gtempa}% |
| 15389 |
% \end{macrocode} |
| 15390 |
% Typing |x| or |X| exits. |
| 15391 |
% \begin{macrocode} |
| 15392 |
\ifx\@gtempa\@empty \else |
| 15393 |
\def\reserved@a{x}\ifx\reserved@a\@gtempa\batchmode\@@end\fi |
| 15394 |
\def\reserved@a{X}\ifx\reserved@a\@gtempa\batchmode\@@end\fi |
| 15395 |
% \end{macrocode} |
| 15396 |
% In all other cases we try the new file name. |
| 15397 |
% \begin{macrocode} |
| 15398 |
\filename@parse\@gtempa |
| 15399 |
\edef\filename@ext{% |
| 15400 |
\ifx\filename@ext\relax#2\else\filename@ext\fi}% |
| 15401 |
\edef\reserved@a{\noexpand\IfFileExists % |
| 15402 |
{\filename@area\filename@base.\filename@ext}% |
| 15403 |
{\noexpand\lst@InputListing % |
| 15404 |
{\filename@area\filename@base.\filename@ext}}% |
| 15405 |
{\noexpand\lst@MissingFileError |
| 15406 |
{\filename@area\filename@base}{\filename@ext}}}% |
| 15407 |
\expandafter\reserved@a % |
| 15408 |
\fi} |
| 15409 |
% \end{macrocode} |
| 15410 |
% \end{macro} |
| 15411 |
% |
| 15412 |
% \begin{macro}{\lst@ifdraft} |
| 15413 |
% makes use of |\lst@ifprint|. \lsthelper{Enrico~Straube}{2002/02/12} |
| 15414 |
% {de.comp.text.tex: listings und draft Modus} requested the final option. |
| 15415 |
% \begin{macrocode} |
| 15416 |
\let\lst@ifdraft\iffalse |
| 15417 |
\DeclareOption{draft}{\let\lst@ifdraft\iftrue} |
| 15418 |
\DeclareOption{final}{\let\lst@ifdraft\iffalse} |
| 15419 |
\lst@AddToHook{PreSet} |
| 15420 |
{\lst@ifdraft |
| 15421 |
\let\lst@ifprint\iffalse |
| 15422 |
\@gobbletwo\fi\fi |
| 15423 |
\fi} |
| 15424 |
% \end{macrocode} |
| 15425 |
% \end{macro} |
| 15426 |
% |
| 15427 |
% \begin{macro}{\lst@InputListing} |
| 15428 |
% The one and only argument is the file name, but we have the `implicit' |
| 15429 |
% argument |\lst@set|. Note that |\lst@Init| takes |\relax| as argument. |
| 15430 |
% \begin{macrocode} |
| 15431 |
\def\lst@InputListing#1{% |
| 15432 |
\begingroup |
| 15433 |
\lsthk@PreSet \gdef\lst@intname{#1}% |
| 15434 |
\expandafter\lstset\expandafter{\lst@set}% |
| 15435 |
\lsthk@DisplayStyle |
| 15436 |
\catcode\active=\active |
| 15437 |
\lst@Init\relax \let\lst@gobble\z@ |
| 15438 |
\lst@SkipToFirst |
| 15439 |
\lst@ifprint \def\lst@next{\input{#1}}% |
| 15440 |
\else \let\lst@next\@empty \fi |
| 15441 |
\lst@next |
| 15442 |
\lst@DeInit |
| 15443 |
\endgroup} |
| 15444 |
% \end{macrocode} |
| 15445 |
% The line |\catcode\active=\active|, which makes the CR-character active, |
| 15446 |
% has been added after a bug report by \lsthelper{Rene~H.~Larsen}{2002/04/15} |
| 15447 |
% {\lstinputlistings and texcl conflict}. |
| 15448 |
% \end{macro} |
| 15449 |
% |
| 15450 |
% \begin{macro}{\lst@SkipToFirst} |
| 15451 |
% The end of line character either processes the listing or is responsible for |
| 15452 |
% dropping lines up to first printing line. |
| 15453 |
% \begin{macrocode} |
| 15454 |
\def\lst@SkipToFirst{% |
| 15455 |
\ifnum \lst@lineno<\lst@firstline |
| 15456 |
% \end{macrocode} |
| 15457 |
% We drop the input and redefine the end of line characters. |
| 15458 |
% \begin{macrocode} |
| 15459 |
\lst@BeginDropInput\lst@Pmode |
| 15460 |
\lst@Let{13}\lst@MSkipToFirst |
| 15461 |
\lst@Let{10}\lst@MSkipToFirst |
| 15462 |
\else |
| 15463 |
\expandafter\lst@BOLGobble |
| 15464 |
\fi} |
| 15465 |
% \end{macrocode} |
| 15466 |
% \end{macro} |
| 15467 |
% |
| 15468 |
% \begin{macro}{\lst@MSkipToFirst} |
| 15469 |
% We just look whether to drop more lines or to leave the mode which restores |
| 15470 |
% the definition of |chr(13)| and |chr(10)|. |
| 15471 |
% \begin{macrocode} |
| 15472 |
\def\lst@MSkipToFirst{% |
| 15473 |
\global\advance\lst@lineno\@ne |
| 15474 |
\ifnum \lst@lineno=\lst@firstline |
| 15475 |
\lst@LeaveMode \global\lst@newlines\z@ |
| 15476 |
\lsthk@InitVarsBOL |
| 15477 |
\lst@DisplayConsecutiveNumbersOrNot |
| 15478 |
\expandafter\lst@BOLGobble |
| 15479 |
\fi} |
| 15480 |
% \end{macrocode} |
| 15481 |
% \end{macro} |
| 15482 |
% |
| 15483 |
% |
| 15484 |
% \subsection{The environment} |
| 15485 |
% |
| 15486 |
% |
| 15487 |
% \subsubsection{Low-level processing} |
| 15488 |
% |
| 15489 |
% \begin{macro}{\lstenv@DroppedWarning} |
| 15490 |
% gives a warning if characters have been dropped. |
| 15491 |
% \begin{macrocode} |
| 15492 |
\def\lstenv@DroppedWarning{% |
| 15493 |
\ifx\lst@dropped\@undefined\else |
| 15494 |
\PackageWarning{Listings}{Text dropped after begin of listing}% |
| 15495 |
\fi} |
| 15496 |
\let\lst@dropped\@undefined % init |
| 15497 |
% \end{macrocode} |
| 15498 |
% \end{macro} |
| 15499 |
% |
| 15500 |
% \begin{macro}{\lstenv@Process} |
| 15501 |
% We execute `|\lstenv@ProcessM|' or |\lstenv@ProcessJ| according to whether we |
| 15502 |
% find an active EOL or a nonactive |^^J|. |
| 15503 |
% \begin{macrocode} |
| 15504 |
\begingroup \lccode`\~=`\^^M\lowercase{% |
| 15505 |
\gdef\lstenv@Process#1{% |
| 15506 |
\ifx~#1% |
| 15507 |
% \end{macrocode} |
| 15508 |
% We make no extra |\lstenv@ProcessM| definition since there is nothing to do |
| 15509 |
% at all if we've found an active EOL. |
| 15510 |
% \begin{macrocode} |
| 15511 |
\lstenv@DroppedWarning \let\lst@next\lst@SkipToFirst |
| 15512 |
\else\ifx^^J#1% |
| 15513 |
\lstenv@DroppedWarning \let\lst@next\lstenv@ProcessJ |
| 15514 |
\else |
| 15515 |
\let\lst@dropped#1\let\lst@next\lstenv@Process |
| 15516 |
\fi \fi |
| 15517 |
\lst@next} |
| 15518 |
}\endgroup |
| 15519 |
% \end{macrocode} |
| 15520 |
% \end{macro} |
| 15521 |
% |
| 15522 |
% \begin{macro}{\lstenv@ProcessJ} |
| 15523 |
% Now comes the horrible scenario: a listing inside an argument. We've |
| 15524 |
% already worked in section \ref{iApplicationsTo} for this. Here we must get |
| 15525 |
% all characters up to `end environment'. We distinguish the cases `command |
| 15526 |
% fashion' and `true environment'. |
| 15527 |
% \begin{macrocode} |
| 15528 |
\def\lstenv@ProcessJ{% |
| 15529 |
\let\lst@arg\@empty |
| 15530 |
\ifx\@currenvir\lstenv@name |
| 15531 |
\expandafter\lstenv@ProcessJEnv |
| 15532 |
\else |
| 15533 |
% \end{macrocode} |
| 15534 |
% The first case is pretty simple: The code is terminated by |
| 15535 |
% |\end|\meta{name of environment}. Thus we expand that control sequence |
| 15536 |
% before defining a temporary macro, which gets the listing and does all |
| 15537 |
% the rest. Back to the definition of |\lstenv@ProcessJ| we call the |
| 15538 |
% temporary macro after expanding |\fi|. |
| 15539 |
% \begin{macrocode} |
| 15540 |
\expandafter\def\expandafter\lst@temp\expandafter##1% |
| 15541 |
\csname end\lstenv@name\endcsname |
| 15542 |
{\lst@InsideConvert{##1}\lstenv@ProcessJ@}% |
| 15543 |
\expandafter\lst@temp |
| 15544 |
\fi} |
| 15545 |
% \end{macrocode} |
| 15546 |
% We must append an active backslash and the `end string' to |\lst@arg|. So all |
| 15547 |
% (in fact most) other processing won't notice that the code has been inside |
| 15548 |
% an argument. But the EOL character is |chr(10)|=|^^J| now and not |chr(13)|. |
| 15549 |
% \begin{macrocode} |
| 15550 |
\begingroup \lccode`\~=`\\\lowercase{% |
| 15551 |
\gdef\lstenv@ProcessJ@{% |
| 15552 |
\lst@lExtend\lst@arg |
| 15553 |
{\expandafter\ \expandafter~\lstenv@endstring}% |
| 15554 |
\catcode10=\active \lst@Let{10}\lst@MProcessListing |
| 15555 |
% \end{macrocode} |
| 15556 |
% We execute |\lst@arg| to typeset the listing. |
| 15557 |
% \begin{macrocode} |
| 15558 |
\lst@SkipToFirst \lst@arg} |
| 15559 |
}\endgroup |
| 15560 |
% \end{macrocode} |
| 15561 |
% \end{macro} |
| 15562 |
% |
| 15563 |
% \begin{macro}{\lstenv@ProcessJEnv} |
| 15564 |
% The `true environment' case is more complicated. We get all characters up to |
| 15565 |
% an |\end| and the following argument. If that equals |\lstenv@name|, we have |
| 15566 |
% found the end of environment and start typesetting. |
| 15567 |
% \begin{macrocode} |
| 15568 |
\def\lstenv@ProcessJEnv#1\end#2{\def\lst@temp{#2}% |
| 15569 |
\ifx\lstenv@name\lst@temp |
| 15570 |
\lst@InsideConvert{#1}% |
| 15571 |
\expandafter\lstenv@ProcessJ@ |
| 15572 |
\else |
| 15573 |
% \end{macrocode} |
| 15574 |
% Otherwise we append the characters including the eaten |\end| and the eaten |
| 15575 |
% argument to current |\lst@arg|. And we look for the end of environment again. |
| 15576 |
% \begin{macrocode} |
| 15577 |
\lst@InsideConvert{#1\\end\{#2\}}% |
| 15578 |
\expandafter\lstenv@ProcessJEnv |
| 15579 |
\fi} |
| 15580 |
% \end{macrocode} |
| 15581 |
% \end{macro} |
| 15582 |
% |
| 15583 |
% \begin{macro}{\lstenv@backslash} |
| 15584 |
% Coming to a backslash we either end the listing or process a backslash and |
| 15585 |
% insert the eaten characters again. |
| 15586 |
% \begin{macrocode} |
| 15587 |
\def\lstenv@backslash{% |
| 15588 |
\lst@IfNextChars\lstenv@endstring |
| 15589 |
{\lstenv@End}% |
| 15590 |
{\expandafter\lsts@backslash \lst@eaten}}% |
| 15591 |
% \end{macrocode} |
| 15592 |
% \end{macro} |
| 15593 |
% |
| 15594 |
% \begin{macro}{\lstenv@End} |
| 15595 |
% This macro has just been used and terminates a listing environment: |
| 15596 |
% We call the `end environment' macro using |\end| or as a command. |
| 15597 |
% \begin{macrocode} |
| 15598 |
\def\lstenv@End{% |
| 15599 |
\ifx\@currenvir\lstenv@name |
| 15600 |
\edef\lst@next{\noexpand\end{\lstenv@name}}% |
| 15601 |
\else |
| 15602 |
\def\lst@next{\csname end\lstenv@name\endcsname}% |
| 15603 |
\fi |
| 15604 |
\lst@next} |
| 15605 |
% \end{macrocode} |
| 15606 |
% \end{macro} |
| 15607 |
% |
| 15608 |
% |
| 15609 |
% \subsubsection{Defining new environments} |
| 15610 |
% |
| 15611 |
% \begin{macro}{\lstnewenvironment} |
| 15612 |
% Now comes the main command. We define undefined environments only. On the |
| 15613 |
% parameter text |#1#2#| (in particular the last sharp) see the paragraph |
| 15614 |
% following example 20.5 on page 204 of `The \TeX book'. |
| 15615 |
% \begin{macrocode} |
| 15616 |
\lst@UserCommand\lstnewenvironment#1#2#{% |
| 15617 |
\@ifundefined{#1}% |
| 15618 |
{\let\lst@arg\@empty |
| 15619 |
\lst@XConvert{#1}\@nil |
| 15620 |
\expandafter\lstnewenvironment@\lst@arg{#1}{#2}}% |
| 15621 |
{\PackageError{Listings}{Environment `#1' already defined}\@eha |
| 15622 |
\@gobbletwo}} |
| 15623 |
\def\@tempa#1#2#3{% |
| 15624 |
\gdef\lstnewenvironment@##1##2##3##4##5{% |
| 15625 |
\begingroup |
| 15626 |
% \end{macrocode} |
| 15627 |
% A lonely `end environment' produces an error. |
| 15628 |
% \begin{macrocode} |
| 15629 |
\global\@namedef{end##2}{\lstenv@Error{##2}}% |
| 15630 |
% \end{macrocode} |
| 15631 |
% The `main' environment macro defines the environment name for later use and |
| 15632 |
% calls a submacro getting all arguments. We open a group and make EOL active. |
| 15633 |
% This ensures |\@ifnextchar[| not to read characters of the listing---it reads |
| 15634 |
% the active EOL instead. |
| 15635 |
% \begin{macrocode} |
| 15636 |
\global\@namedef{##2}{\def\lstenv@name{##2}% |
| 15637 |
\begingroup \lst@setcatcodes \catcode\active=\active |
| 15638 |
\csname##2@\endcsname}% |
| 15639 |
% \end{macrocode} |
| 15640 |
% The submacro is defined via |\new@command|. We misuse |\l@ngrel@x| to make |
| 15641 |
% the definition |\global| and refine \LaTeX's |\@xargdef|. |
| 15642 |
% \begin{macrocode} |
| 15643 |
\let\l@ngrel@x\global |
| 15644 |
% \end{macrocode} |
| 15645 |
% With the \LaTeX{} kernel from November 2025 the above hack---making a command that |
| 15646 |
% was supposed to be either |\long| or |\relax| suddenly applying |\global| doesn't work |
| 15647 |
% anymore, \url{https://tex.stackexchange.com/a/754359} describes why. The |
| 15648 |
% following line remedies this deficiency by replacing it by an equally dubious hack :-) |
| 15649 |
% \begin{macrocode} |
| 15650 |
\let\pr@tectedrel@x\global |
| 15651 |
\let\@xargdef\lstenv@xargdef |
| 15652 |
\expandafter\new@command\csname##2@\endcsname##3% |
| 15653 |
% \end{macrocode} |
| 15654 |
% First we execute |##4|=\meta{begin code}. Then follows the definition of |
| 15655 |
% the terminating string (|end{lstlisting}| or |endlstlisting|, for example): |
| 15656 |
% \begin{macrocode} |
| 15657 |
{\lsthk@PreSet ##4% |
| 15658 |
\ifx\@currenvir\lstenv@name |
| 15659 |
\def\lstenv@endstring{#1#2##1#3}% |
| 15660 |
\else |
| 15661 |
\def\lstenv@endstring{#1##1}% |
| 15662 |
\fi |
| 15663 |
% \end{macrocode} |
| 15664 |
% We redefine (locally) `end environment' since ending is legal now. |
| 15665 |
% Note that the redefinition also works inside a \TeX\ comment line. |
| 15666 |
% \begin{macrocode} |
| 15667 |
\@namedef{end##2}{\lst@DeInit ##5\endgroup |
| 15668 |
\lst@doendpe \@ignoretrue}% |
| 15669 |
% \end{macrocode} |
| 15670 |
% |\lst@doendpe| again removes the indention problem. |
| 15671 |
% |
| 15672 |
% Finally we start the processing. The |\lst@EndProcessListing| assignment |
| 15673 |
% has been moved in front of |\lst@Init| after a bug report by |
| 15674 |
% \lsthelper{Andreas~Deininger}{2002/11/11}{Compiling just stops}. |
| 15675 |
% \begin{macrocode} |
| 15676 |
\lsthk@DisplayStyle |
| 15677 |
\let\lst@EndProcessListing\lstenv@SkipToEnd |
| 15678 |
\lst@Init\lstenv@backslash |
| 15679 |
\lst@ifprint |
| 15680 |
\expandafter\expandafter\expandafter\lstenv@Process |
| 15681 |
\else |
| 15682 |
\expandafter\lstenv@SkipToEnd |
| 15683 |
\fi |
| 15684 |
\lst@insertargs}% |
| 15685 |
\endgroup}% |
| 15686 |
} |
| 15687 |
\let\lst@arg\@empty \lst@XConvert{end}\{\}\@nil |
| 15688 |
\expandafter\@tempa\lst@arg |
| 15689 |
\let\lst@insertargs\@empty |
| 15690 |
% \end{macrocode} |
| 15691 |
% \end{macro} |
| 15692 |
% |
| 15693 |
% \begin{macro}{\lstenv@xargdef} |
| 15694 |
% This is a derivation of \LaTeX's |\@xargdef|. We expand the submacro's name, |
| 15695 |
% use |\gdef| instead of |\def|, and hard code a kind of |\@protected@testopt|. |
| 15696 |
% \begin{macrocode} |
| 15697 |
\def\lstenv@xargdef#1{% |
| 15698 |
\expandafter\lstenv@xargdef@\csname\string#1\endcsname#1} |
| 15699 |
\def\lstenv@xargdef@#1#2[#3][#4]#5{% |
| 15700 |
\@ifdefinable#2{% |
| 15701 |
\gdef#2{% |
| 15702 |
\ifx\protect\@typeset@protect |
| 15703 |
\expandafter\lstenv@testopt |
| 15704 |
\else |
| 15705 |
\@x@protect#2% |
| 15706 |
\fi |
| 15707 |
#1% |
| 15708 |
{#4}}% |
| 15709 |
\@yargdef% |
| 15710 |
#1% |
| 15711 |
\tw@% |
| 15712 |
{#3}% |
| 15713 |
{#5}}% |
| 15714 |
} |
| 15715 |
% \end{macrocode} |
| 15716 |
% \end{macro} |
| 15717 |
% |
| 15718 |
% \begin{macro}{\lstenv@testopt} |
| 15719 |
% The difference between this macro and |\@testopt| is that we temporaryly |
| 15720 |
% reset the catcode of the EOL character |^^M| to read the optional argument. |
| 15721 |
% \begin{macrocode} |
| 15722 |
\long\def\lstenv@testopt#1#2{% |
| 15723 |
\@ifnextchar[{\catcode\active5\relax \lstenv@testopt@#1}% |
| 15724 |
{#1[{#2}]}} |
| 15725 |
\def\lstenv@testopt@#1[#2]{% |
| 15726 |
\catcode\active\active |
| 15727 |
#1[#2]} |
| 15728 |
% \end{macrocode} |
| 15729 |
% \end{macro} |
| 15730 |
% |
| 15731 |
% \begin{macro}{\lstenv@SkipToEnd} |
| 15732 |
% We use the temporary definition |
| 15733 |
% \begin{itemize}\item[] |
| 15734 |
% |\long\def\lst@temp##1\|\meta{content of \textup{\cs{lstenv@endstring}}}|{\lstenv@End}| |
| 15735 |
% \end{itemize} |
| 15736 |
% which gobbles all characters up to the end of environment and finishes it. |
| 15737 |
% \begin{macrocode} |
| 15738 |
\begingroup \lccode`\~=`\\\lowercase{% |
| 15739 |
\gdef\lstenv@SkipToEnd{% |
| 15740 |
\long\expandafter\def\expandafter\lst@temp\expandafter##\expandafter |
| 15741 |
1\expandafter~\lstenv@endstring{\lstenv@End}% |
| 15742 |
\lst@temp} |
| 15743 |
}\endgroup |
| 15744 |
% \end{macrocode} |
| 15745 |
% \end{macro} |
| 15746 |
% |
| 15747 |
% \begin{macro}{\lstenv@Error} |
| 15748 |
% is called by a lonely `end environment'. |
| 15749 |
% \begin{macrocode} |
| 15750 |
\def\lstenv@Error#1{\PackageError{Listings}{Extra \string\end#1}% |
| 15751 |
{I'm ignoring this, since I wasn't doing a \csname#1\endcsname.}} |
| 15752 |
% \end{macrocode} |
| 15753 |
% \end{macro} |
| 15754 |
% |
| 15755 |
% \begin{macro}{\lst@TestEOLChar} |
| 15756 |
% Here we test for the two possible EOL characters. |
| 15757 |
% \begin{macrocode} |
| 15758 |
\begingroup \lccode`\~=`\^^M\lowercase{% |
| 15759 |
\gdef\lst@TestEOLChar#1{% |
| 15760 |
\def\lst@insertargs{#1}% |
| 15761 |
\ifx ~#1\@empty \else |
| 15762 |
\ifx^^J#1\@empty \else |
| 15763 |
\global\let\lst@intname\lst@insertargs |
| 15764 |
\let\lst@insertargs\@empty |
| 15765 |
\fi \fi} |
| 15766 |
}\endgroup |
| 15767 |
% \end{macrocode} |
| 15768 |
% \end{macro} |
| 15769 |
% |
| 15770 |
% \begin{environment}{lstlisting} |
| 15771 |
% The awkward work is done, the definition is quite easy now. We test whether |
| 15772 |
% the user has given the name argument, set the keys, and deal with |
| 15773 |
% continued line numbering. |
| 15774 |
% \begin{macrocode} |
| 15775 |
\lstnewenvironment{lstlisting}[2][]{% |
| 15776 |
\lst@TestEOLChar{#2}% |
| 15777 |
\lstset{#1}% |
| 15778 |
\csname\@lst @SetFirstNumber\endcsname% |
| 15779 |
}{% |
| 15780 |
% \end{macrocode} |
| 15781 |
% There is a problem with vertical space below a listing as pointed out by |
| 15782 |
% \lsthelper{Jean-Yves~Baudais}{2016/03/11}{some |
| 15783 |
% vertical space problem}. A similar problem arises with a listing |
| 15784 |
% beginning at the top of a |\paragraph| or at the beginning of an |
| 15785 |
% |example| environment. Jean-Yves provided a |
| 15786 |
% solution---|\let\if@nobreak\iffalse|---as has been discussed on |
| 15787 |
% |fr.comp.text.tex|. The assumption, that the problem vanishes if there is |
| 15788 |
% a top rule at the beginning of the listing or if |\leavevmode| introduces |
| 15789 |
% the listing, was wrong as |
| 15790 |
% \lsthelper{Karl~Berry}{2018/10/26}{listings 1.7 \rcmdname\leavevmode -> blank line} and |
| 15791 |
% \lsthelper{Sven~Schreiber}{2018/10/23}{Geändertes Verhalten in der neuen listings-Version} reported |
| 15792 |
% independently, so the proposed code goes into the second part of the |
| 15793 |
% environment definition. \lsthelper{Enrico Gregorio}{2019/05/04}{Is it a |
| 15794 |
% listings package bug?} answered on |
| 15795 |
% \url{https://tex.stackexchange.com/questions/489121/is-it-a-listings-package-bug} |
| 15796 |
% that the previous solution |\let\if@nobreak\iffalse| is wrong because it |
| 15797 |
% is a local assignment, but a globally setting is needed. |
| 15798 |
% \begin{macrocode} |
| 15799 |
\@nobreakfalse |
| 15800 |
\csname\@lst @SaveFirstNumber\endcsname% |
| 15801 |
} |
| 15802 |
% \end{macrocode} |
| 15803 |
% \begin{macrocode} |
| 15804 |
%</kernel> |
| 15805 |
% \end{macrocode} |
| 15806 |
% \end{environment} |
| 15807 |
% |
| 15808 |
% |
| 15809 |
% \section{Documentation support} |
| 15810 |
% |
| 15811 |
% \begin{syntax} |
| 15812 |
% \item[0.19] |
| 15813 |
% |\begin{lstsample}|\oarg{point list}\marg{left}\marg{right} |
| 15814 |
% |
| 15815 |
% \leavevmode\hspace*{-\leftmargini}|\end{lstsample}| |
| 15816 |
% |
| 15817 |
% Roughly speaking all material in between this environment is executed |
| 15818 |
% `on the left side' and typeset verbatim on the right. \meta{left} is |
| 15819 |
% executed before the left side is typeset, and similarly \meta{right} |
| 15820 |
% before the right-hand side. |
| 15821 |
% |
| 15822 |
% \meta{point list} is used as argument to the \keyname{point} key. |
| 15823 |
% This is a special key used to highlight the keys in the examples. |
| 15824 |
% |
| 15825 |
% \item[1.0] |
| 15826 |
% |\begin{lstxsample}|\marg{point list} |
| 15827 |
% |
| 15828 |
% \leavevmode\hspace*{-\leftmargini}|\end{lstxsample}| |
| 15829 |
% |
| 15830 |
% The material in between is (a) added to the left side of the next |
| 15831 |
% \texttt{lstsample} environment and (b) typeset verbatim using the |
| 15832 |
% whole line width. |
| 15833 |
% |
| 15834 |
% \item[0.21] |\newdocenvironment|\marg{name}\marg{short name}\marg{begin code}\marg{end code} |
| 15835 |
% |
| 15836 |
% The \meta{name} environment can be used in the same way as `macro'. |
| 15837 |
% The provided(!) definitions |
| 15838 |
% |\Print|\meta{short name}|Name| |
| 15839 |
% and |\SpecialMain|\meta{short name}|Index| |
| 15840 |
% control printing in the margin and indexing as the defaults |
| 15841 |
% |\PrintMacroName| and |\SpecialMainIndex| do. |
| 15842 |
% |
| 15843 |
% This command is used to define the `aspect' and `lstkey' environments. |
| 15844 |
% |
| 15845 |
%\item[0.21] \texttt{macroargs} environment |
| 15846 |
% |
| 15847 |
% This `enumerate' environment uses as labels `|#1| =', `|#2| =', |
| 15848 |
% and so on. |
| 15849 |
% |
| 15850 |
% \item \texttt{TODO} environment |
| 15851 |
% \item \texttt{ALTERNATIVE} environment |
| 15852 |
% \item \texttt{REMOVED} environment |
| 15853 |
% \item \texttt{OLDDEF} environment |
| 15854 |
% |
| 15855 |
% These environments enclose comments on `to do's', alternatives and |
| 15856 |
% removed or old definitions. |
| 15857 |
% |
| 15858 |
% \item[0.21] |\lstscanlanguages|\meta{list macro}\marg{input files}\marg{don't input} |
| 15859 |
% |
| 15860 |
% scans \marg{input files}$\setminus$\marg{don't input} for language |
| 15861 |
% definitions. The available languages are stored in \meta{list macro} |
| 15862 |
% using the form \meta{language}|(|\meta{dialect}|),|. |
| 15863 |
% |
| 15864 |
% \item[0.21] |\lstprintlanguages|\meta{list macro} |
| 15865 |
% |
| 15866 |
% prints the languages in two column format. |
| 15867 |
% \end{syntax} |
| 15868 |
% and a lot of more simple commands. |
| 15869 |
% |
| 15870 |
% |
| 15871 |
% \subsection{Required packages} |
| 15872 |
% |
| 15873 |
% Most of the `required' packages are optional. |
| 15874 |
% \lsthelper{Stephan~Hennig}{2006-09-25}{documentation incompatible with algorithmic} |
| 15875 |
% noted a bug where |\ifalgorithmic| conflicts with an update to |algorithmic.sty|, so |
| 15876 |
% this has been changed to |\ifalgorithmicpkg|. |
| 15877 |
% \begin{macrocode} |
| 15878 |
%<*doc> |
| 15879 |
\let\lstdoc@currversion\fileversion |
| 15880 |
\RequirePackage[writefile]{listings}[2004/09/07] |
| 15881 |
\newif\iffancyvrb \IfFileExists{fancyvrb.sty}{\fancyvrbtrue}{} |
| 15882 |
\newif\ifcolor \IfFileExists{color.sty}{\colortrue}{} |
| 15883 |
\lst@false |
| 15884 |
\newif\ifhyper |
| 15885 |
\@ifundefined{pdfoutput} |
| 15886 |
{} |
| 15887 |
{\ifnum\pdfoutput>\z@ \lst@true \fi} |
| 15888 |
\@ifundefined{VTeXversion} |
| 15889 |
{} |
| 15890 |
{\ifnum\OpMode>\z@ \lst@true \fi} |
| 15891 |
\lst@if \IfFileExists{hyperref.sty}{\hypertrue}{}\fi |
| 15892 |
\newif\ifalgorithmicpkg \IfFileExists{algorithmic.sty}{\algorithmicpkgtrue}{} |
| 15893 |
\newif\iflgrind \IfFileExists{lgrind.sty}{\lgrindtrue}{} |
| 15894 |
\iffancyvrb \RequirePackage{fancyvrb}\fi |
| 15895 |
\ifhyper \RequirePackage[colorlinks]{hyperref}\else |
| 15896 |
\def\href#1{\texttt}\fi |
| 15897 |
\ifcolor \RequirePackage{color}\fi |
| 15898 |
\ifalgorithmicpkg \RequirePackage{algorithmic}\fi |
| 15899 |
\iflgrind \RequirePackage{lgrind}\fi |
| 15900 |
\RequirePackage{nameref} |
| 15901 |
\RequirePackage{xurl} % allow URL breaks |
| 15902 |
\renewcommand\ref{\protect\T@ref} |
| 15903 |
\renewcommand\pageref{\protect\T@pageref} |
| 15904 |
% \end{macrocode} |
| 15905 |
% |
| 15906 |
% |
| 15907 |
% \subsection{Environments for notes} |
| 15908 |
% |
| 15909 |
% \begin{macro}{\lst@BeginRemark} |
| 15910 |
% \begin{macro}{\lst@EndRemark} |
| 15911 |
% We begin with two simple definitions \ldots |
| 15912 |
% \begin{macrocode} |
| 15913 |
\def\lst@BeginRemark#1{% |
| 15914 |
\begin{quote}\topsep0pt\let\small\footnotesize\small#1:} |
| 15915 |
\def\lst@EndRemark{\end{quote}} |
| 15916 |
% \end{macrocode} |
| 15917 |
% \end{macro}\end{macro} |
| 15918 |
% |
| 15919 |
% \begin{environment}{TODO} |
| 15920 |
% \begin{environment}{ALTERNATIVE} |
| 15921 |
% \begin{environment}{REMOVED} |
| 15922 |
% \begin{environment}{OLDDEF} |
| 15923 |
% \ldots\space used to define some environments. |
| 15924 |
% \begin{macrocode} |
| 15925 |
\newenvironment{TODO} |
| 15926 |
{\lst@BeginRemark{To do}}{\lst@EndRemark} |
| 15927 |
\newenvironment{ALTERNATIVE} |
| 15928 |
{\lst@BeginRemark{Alternative}}{\lst@EndRemark} |
| 15929 |
\newenvironment{REMOVED} |
| 15930 |
{\lst@BeginRemark{Removed}}{\lst@EndRemark} |
| 15931 |
\newenvironment{OLDDEF} |
| 15932 |
{\lst@BeginRemark{Old definition}}{\lst@EndRemark} |
| 15933 |
% \end{macrocode} |
| 15934 |
% \end{environment}\end{environment}\end{environment}\end{environment} |
| 15935 |
% |
| 15936 |
% \begin{environment}{advise} |
| 15937 |
% \begin{macro}{\advisespace} |
| 15938 |
% The environment uses |\@listi|. |
| 15939 |
% \begin{macrocode} |
| 15940 |
\def\advise{\par\list\labeladvise |
| 15941 |
{\advance\linewidth\@totalleftmargin |
| 15942 |
\@totalleftmargin\z@ |
| 15943 |
\@listi |
| 15944 |
\let\small\footnotesize \small\sffamily |
| 15945 |
\parsep \z@ \@plus\z@ \@minus\z@ |
| 15946 |
\topsep6\p@ \@plus1\p@\@minus2\p@ |
| 15947 |
\def\makelabel##1{\hss\llap{##1}}}} |
| 15948 |
\let\endadvise\endlist |
| 15949 |
% \end{macrocode} |
| 15950 |
% \begin{macrocode} |
| 15951 |
\def\advisespace{\hbox{}\qquad} |
| 15952 |
\def\labeladvise{$\to$} |
| 15953 |
% \end{macrocode} |
| 15954 |
% \end{macro} |
| 15955 |
% \end{environment} |
| 15956 |
% |
| 15957 |
% \begin{environment}{syntax} |
| 15958 |
% \begin{macro}{\syntaxbreak} |
| 15959 |
% \begin{macro}{\syntaxnewline} |
| 15960 |
% \begin{macro}{\syntaxor} |
| 15961 |
% This environment uses |\list| with a special |\makelabel|, \ldots |
| 15962 |
% \begin{macrocode} |
| 15963 |
\newenvironment{syntax} |
| 15964 |
{\list{}{\itemindent-\leftmargin |
| 15965 |
\def\makelabel##1{\hss\lst@syntaxlabel##1,,,,\relax}}} |
| 15966 |
{\endlist} |
| 15967 |
% \end{macrocode} |
| 15968 |
% \ldots\ which is defined here. The comma separated items are placed as |
| 15969 |
% needed. |
| 15970 |
% \begin{macrocode} |
| 15971 |
\def\lst@syntaxlabel#1,#2,#3,#4\relax{% |
| 15972 |
\llap{\scriptsize\itshape#3}% |
| 15973 |
\def\lst@temp{#2}% |
| 15974 |
\expandafter\lst@syntaxlabel@\meaning\lst@temp\relax |
| 15975 |
\rlap{\hskip-\itemindent\hskip\itemsep\hskip\linewidth |
| 15976 |
\llap{\ttfamily\lst@temp}\hskip\labelwidth |
| 15977 |
\def\lst@temp{#1}% |
| 15978 |
\ifx\lst@temp\lstdoc@currversion#1\fi}} |
| 15979 |
\def\lst@syntaxlabel@#1>#2\relax |
| 15980 |
{\edef\lst@temp{\zap@space#2 \@empty}} |
| 15981 |
% \end{macrocode} |
| 15982 |
% \begin{macrocode} |
| 15983 |
\newcommand*\syntaxnewline{\newline\hbox{}\kern\labelwidth} |
| 15984 |
\newcommand*\syntaxor{\qquad or\qquad} |
| 15985 |
\newcommand*\syntaxbreak |
| 15986 |
{\hfill\kern0pt\discretionary{}{\kern\labelwidth}{}} |
| 15987 |
\let\syntaxfill\hfill |
| 15988 |
% \end{macrocode} |
| 15989 |
% \end{macro} |
| 15990 |
% \end{macro} |
| 15991 |
% \end{macro} |
| 15992 |
% \end{environment} |
| 15993 |
% |
| 15994 |
% \begin{macro}{\alternative} |
| 15995 |
% iterates down the list and inserts vertical rule(s). |
| 15996 |
% \begin{macrocode} |
| 15997 |
\def\alternative#1{\lst@true \alternative@#1,\relax,} |
| 15998 |
\def\alternative@#1,{% |
| 15999 |
\ifx\relax#1\@empty |
| 16000 |
\expandafter\@gobble |
| 16001 |
\else |
| 16002 |
\ifx\@empty#1\@empty\else |
| 16003 |
\lst@if \lst@false \else $\vert$\fi |
| 16004 |
\textup{\texttt{#1}}% |
| 16005 |
\fi |
| 16006 |
\fi |
| 16007 |
\alternative@} |
| 16008 |
% \end{macrocode} |
| 16009 |
% \end{macro} |
| 16010 |
% |
| 16011 |
% |
| 16012 |
% \subsection{Extensions to \packagename{doc}} |
| 16013 |
% |
| 16014 |
% \begin{macro}{\m@cro@} |
| 16015 |
% We need a slight modification of \packagename{doc}'s internal macro. |
| 16016 |
% The former argument |#2| has become |#3|. This change is not marked below. |
| 16017 |
% The second argument is now \meta{short name}. |
| 16018 |
% \begin{macrocode} |
| 16019 |
\long\def\m@cro@#1#2#3{\endgroup \topsep\MacroTopsep \trivlist |
| 16020 |
\edef\saved@macroname{\string#3}% |
| 16021 |
\def\makelabel##1{\llap{##1}}% |
| 16022 |
\if@inlabel |
| 16023 |
\let\@tempa\@empty \count@\macro@cnt |
| 16024 |
\loop \ifnum\count@>\z@ |
| 16025 |
\edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne \repeat |
| 16026 |
\edef\makelabel##1{\llap{\vtop to\baselineskip |
| 16027 |
{\@tempa\hbox{##1}\vss}}}% |
| 16028 |
\advance \macro@cnt \@ne |
| 16029 |
\else \macro@cnt\@ne \fi |
| 16030 |
\edef\@tempa{\noexpand\item[% |
| 16031 |
#1% |
| 16032 |
\noexpand\PrintMacroName |
| 16033 |
\else |
| 16034 |
% \end{macrocode} |
| 16035 |
% The next line has been modified. |
| 16036 |
% \begin{macrocode} |
| 16037 |
\expandafter\noexpand\csname Print#2Name\endcsname % MODIFIED |
| 16038 |
\fi |
| 16039 |
{\string#3}]}% |
| 16040 |
\@tempa |
| 16041 |
\global\advance\c@CodelineNo\@ne |
| 16042 |
#1% |
| 16043 |
\SpecialMainIndex{#3}\nobreak |
| 16044 |
\DoNotIndex{#3}% |
| 16045 |
\else |
| 16046 |
% \end{macrocode} |
| 16047 |
% Ditto. |
| 16048 |
% \begin{macrocode} |
| 16049 |
\csname SpecialMain#2Index\endcsname{#3}\nobreak % MODIFIED |
| 16050 |
\fi |
| 16051 |
\global\advance\c@CodelineNo\m@ne |
| 16052 |
\ignorespaces} |
| 16053 |
% \end{macrocode} |
| 16054 |
% \end{macro} |
| 16055 |
% |
| 16056 |
% \begin{macro}{\macro} |
| 16057 |
% \begin{macro}{\environment} |
| 16058 |
% These two definitions need small adjustments due to the modified |\m@cro@|. |
| 16059 |
% \begin{macrocode} |
| 16060 |
\def\macro{\begingroup |
| 16061 |
\catcode`\\12 |
| 16062 |
\MakePrivateLetters \m@cro@ \iftrue {Macro}}% MODIFIED |
| 16063 |
\def\environment{\begingroup |
| 16064 |
\catcode`\\12 |
| 16065 |
\MakePrivateLetters \m@cro@ \iffalse {Env}}% MODIFIED |
| 16066 |
% \end{macrocode} |
| 16067 |
% \end{macro}\end{macro} |
| 16068 |
% |
| 16069 |
% \begin{macro}{\newdocenvironment} |
| 16070 |
% This command simply makes definitions similar to `environment' and provides |
| 16071 |
% the printing and indexing commands. |
| 16072 |
% \begin{macrocode} |
| 16073 |
\def\newdocenvironment#1#2#3#4{% |
| 16074 |
\@namedef{#1}{#3\begingroup \catcode`\\12\relax |
| 16075 |
\MakePrivateLetters \m@cro@ \iffalse {#2}}% |
| 16076 |
\@namedef{end#1}{#4\endmacro}% |
| 16077 |
\@ifundefined{Print#2Name}{\expandafter |
| 16078 |
\let\csname Print#2Name\endcsname\PrintMacroName}{}% |
| 16079 |
\@ifundefined{SpecialMain#2Index}{\expandafter |
| 16080 |
\let\csname SpecialMain#2Index\endcsname\SpecialMainIndex}{}} |
| 16081 |
% \end{macrocode} |
| 16082 |
% \end{macro} |
| 16083 |
% |
| 16084 |
% \begin{environment}{aspect} |
| 16085 |
% \begin{macro}{\PrintAspectName} |
| 16086 |
% \begin{macro}{\SpecialMainAspectIndex} |
| 16087 |
% The environment and its `print' and `index' commands. |
| 16088 |
% \begin{macrocode} |
| 16089 |
\newdocenvironment{aspect}{Aspect}{}{} |
| 16090 |
\def\PrintAspectName#1{} |
| 16091 |
\def\SpecialMainAspectIndex#1{% |
| 16092 |
\@bsphack |
| 16093 |
\index{aspects:\levelchar\protect\aspectname{#1}}% |
| 16094 |
\@esphack} |
| 16095 |
% \end{macrocode} |
| 16096 |
% \end{macro}\end{macro}\end{environment} |
| 16097 |
% |
| 16098 |
% \begin{environment}{lstkey} |
| 16099 |
% \begin{macro}{\PrintKeyName} |
| 16100 |
% \begin{macro}{\SpecialMainKeyIndex} |
| 16101 |
% One more environment with its `print' and `index' commands. |
| 16102 |
% \begin{macrocode} |
| 16103 |
\newdocenvironment{lstkey}{Key}{}{} |
| 16104 |
\def\PrintKeyName#1{\strut\keyname{#1}\ } |
| 16105 |
\def\SpecialMainKeyIndex#1{% |
| 16106 |
\@bsphack |
| 16107 |
\index{keys\levelchar\protect\keyname{#1}}% |
| 16108 |
\@esphack} |
| 16109 |
% \end{macrocode} |
| 16110 |
% \end{macro}\end{macro}\end{environment} |
| 16111 |
% |
| 16112 |
% \begin{macro}{\labelargcount} |
| 16113 |
% \begin{environment}{macroargs} |
| 16114 |
% We just allocate a counter and use \LaTeX's |\list| to implement this |
| 16115 |
% environment. |
| 16116 |
% \begin{macrocode} |
| 16117 |
\newcounter{argcount} |
| 16118 |
\def\labelargcount{\texttt{\#\arabic{argcount}}\hskip\labelsep$=$} |
| 16119 |
% \end{macrocode} |
| 16120 |
% \begin{macrocode} |
| 16121 |
\def\macroargs{\list\labelargcount |
| 16122 |
{\usecounter{argcount}\leftmargin=2\leftmargin |
| 16123 |
\parsep \z@ \@plus\z@ \@minus\z@ |
| 16124 |
\topsep4\p@ \@plus\p@ \@minus2\p@ |
| 16125 |
\itemsep\z@ \@plus\z@ \@minus\z@ |
| 16126 |
\def\makelabel##1{\hss\llap{##1}}}} |
| 16127 |
\def\endmacroargs{\endlist\@endparenv} |
| 16128 |
% \end{macrocode} |
| 16129 |
% \end{environment}\end{macro} |
| 16130 |
% |
| 16131 |
% |
| 16132 |
% \subsection{The \texttt{lstsample} environment} |
| 16133 |
% |
| 16134 |
% \begin{environment}{lstsample} |
| 16135 |
% We store the verbatim part and write the source code also to file. |
| 16136 |
% \begin{macrocode} |
| 16137 |
\lst@RequireAspects{writefile} |
| 16138 |
% \end{macrocode} |
| 16139 |
% \begin{macrocode} |
| 16140 |
\newbox\lst@samplebox |
| 16141 |
\lstnewenvironment{lstsample}[3][] |
| 16142 |
{\global\let\lst@intname\@empty |
| 16143 |
\gdef\lst@sample{#2}% |
| 16144 |
\setbox\lst@samplebox=\hbox\bgroup |
| 16145 |
\setkeys{lst}{language={},style={},tabsize=4,gobble=5,% |
| 16146 |
basicstyle=\small\ttfamily,basewidth=0.51em,point={#1}} |
| 16147 |
#3% |
| 16148 |
\lst@BeginAlsoWriteFile{\jobname.tmp}} |
| 16149 |
{\lst@EndWriteFile\egroup |
| 16150 |
% \end{macrocode} |
| 16151 |
% Now |\lst@samplebox| contains the verbatim part. |
| 16152 |
% If it's too wide, we use atop and below instead of left and right. |
| 16153 |
% \begin{macrocode} |
| 16154 |
\ifdim \wd\lst@samplebox>.5\linewidth |
| 16155 |
\begin{center}% |
| 16156 |
\hbox to\linewidth{\box\lst@samplebox\hss}% |
| 16157 |
\end{center}% |
| 16158 |
\lst@sampleInput |
| 16159 |
\else |
| 16160 |
\begin{center}% |
| 16161 |
\begin{minipage}{0.45\linewidth}\lst@sampleInput\end{minipage}% |
| 16162 |
\qquad |
| 16163 |
\begin{minipage}{0.45\linewidth}% |
| 16164 |
\hbox to\linewidth{\box\lst@samplebox\hss}% |
| 16165 |
\end{minipage}% |
| 16166 |
\end{center}% |
| 16167 |
\fi} |
| 16168 |
% \end{macrocode} |
| 16169 |
% The new keyword class \keyname{point}. |
| 16170 |
% \begin{macrocode} |
| 16171 |
\lst@InstallKeywords{p}{point}{pointstyle}\relax{keywordstyle}{}ld |
| 16172 |
% \end{macrocode} |
| 16173 |
% \end{environment} |
| 16174 |
% |
| 16175 |
% \begin{environment}{lstxsample} |
| 16176 |
% Omitting |\lst@EndWriteFile| leaves the file open. |
| 16177 |
% \begin{macrocode} |
| 16178 |
\lstnewenvironment{lstxsample}[1][] |
| 16179 |
{\begingroup |
| 16180 |
\setkeys{lst}{belowskip=-\medskipamount,language={},style={},% |
| 16181 |
tabsize=4,gobble=5,basicstyle=\small\ttfamily,% |
| 16182 |
basewidth=0.51em,point={#1}} |
| 16183 |
\lst@BeginAlsoWriteFile{\jobname.tmp}} |
| 16184 |
{\endgroup |
| 16185 |
\endgroup} |
| 16186 |
% \end{macrocode} |
| 16187 |
% \end{environment} |
| 16188 |
% |
| 16189 |
% \begin{macro}{\lst@sampleInput} |
| 16190 |
% inputs the `left-hand' side. |
| 16191 |
% \begin{macrocode} |
| 16192 |
\def\lst@sampleInput{% |
| 16193 |
\MakePercentComment\catcode`\^^M=10\relax |
| 16194 |
\small\lst@sample |
| 16195 |
{\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}% |
| 16196 |
{\lst@ProcessTabulator}}% |
| 16197 |
\leavevmode \input{\jobname.tmp}}\MakePercentIgnore} |
| 16198 |
% \end{macrocode} |
| 16199 |
% \end{macro} |
| 16200 |
% |
| 16201 |
% |
| 16202 |
% \subsection{Miscellaneous} |
| 16203 |
% |
| 16204 |
% \paragraph{Sectioning and cross referencing} |
| 16205 |
% We begin with a redefinition paragraph. |
| 16206 |
% \begin{macrocode} |
| 16207 |
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}% |
| 16208 |
{1.25ex \@plus1ex \@minus.2ex}% |
| 16209 |
{-1em}% |
| 16210 |
{\normalfont\normalsize\bfseries}} |
| 16211 |
% \end{macrocode} |
| 16212 |
% We introduce |\lstref| which prints section number together with its name. |
| 16213 |
% \begin{macrocode} |
| 16214 |
\def\lstref#1{\emph{\ref{#1} \nameref{#1}}} |
| 16215 |
% \end{macrocode} |
| 16216 |
% Moreover we adjust the table of contents. The |\phantomsection| before |
| 16217 |
% adding the contents line provides \packagename{hyperref} with an appropriate |
| 16218 |
% destination for the contents line link, thereby ensuring that the contents |
| 16219 |
% line is at the right level in the PDF bookmark tree. |
| 16220 |
% \begin{macrocode} |
| 16221 |
\def\@part[#1]#2{\ifhyper\phantomsection\fi |
| 16222 |
\addcontentsline{toc}{part}{#1}% |
| 16223 |
{\parindent\z@ \raggedright \interlinepenalty\@M |
| 16224 |
\normalfont \huge \bfseries #2\markboth{}{}\par}% |
| 16225 |
\nobreak\vskip 3ex\@afterheading} |
| 16226 |
\renewcommand*\l@section[2]{% |
| 16227 |
\addpenalty\@secpenalty |
| 16228 |
\addvspace{.25em \@plus\p@}% |
| 16229 |
\setlength\@tempdima{1.5em}% |
| 16230 |
\begingroup |
| 16231 |
\parindent \z@ \rightskip \@pnumwidth |
| 16232 |
\parfillskip -\@pnumwidth |
| 16233 |
\leavevmode |
| 16234 |
\advance\leftskip\@tempdima |
| 16235 |
\hskip -\leftskip |
| 16236 |
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par |
| 16237 |
\endgroup} |
| 16238 |
\renewcommand*\l@subsection{\@dottedtocline{2}{0pt}{2.3em}} |
| 16239 |
\renewcommand*\l@subsubsection{\@dottedtocline{3}{0pt}{3.2em}} |
| 16240 |
% \end{macrocode} |
| 16241 |
% |
| 16242 |
% \paragraph{Indexing} |
| 16243 |
% The `user' commands. There are two different ways to mark up a |
| 16244 |
% key. |\ikeyname| is the commmand for keys which are used \textit{i}nline, |
| 16245 |
% |\rkeyname| defines the \textit{r}eference of a key---displayed green---, |
| 16246 |
% |\rstyle| is defined below. |
| 16247 |
% \begin{macrocode} |
| 16248 |
\newcommand\ikeyname[1]{% |
| 16249 |
\lstkeyindex{#1}{}% |
| 16250 |
\lstaspectindex{#1}{}% |
| 16251 |
\keyname{#1}} |
| 16252 |
\newcommand\rkeyname[1]{% |
| 16253 |
\@bsphack |
| 16254 |
\lstkeyindex{#1}{}% |
| 16255 |
\lstaspectindex{#1}{}% |
| 16256 |
\@esphack{\rstyle\keyname{#1}}} |
| 16257 |
% \end{macrocode} |
| 16258 |
% The same rules apply to |\icmdname| and |\rcmdname|: |
| 16259 |
% \begin{macrocode} |
| 16260 |
\newcommand\icmdname[1]{% |
| 16261 |
\@bsphack |
| 16262 |
\lstaspectindex{#1}{}% |
| 16263 |
\@esphack\texttt{\string#1}} |
| 16264 |
\newcommand\rcmdname[1]{% |
| 16265 |
\@bsphack |
| 16266 |
\lstaspectindex{#1}{}% |
| 16267 |
\@esphack\texttt{\rstyle\string#1}} |
| 16268 |
% \end{macrocode} |
| 16269 |
% One of the two yet unknown `index'-macros is empty, the other looks up |
| 16270 |
% the aspect name for the given argument. |
| 16271 |
% \begin{macrocode} |
| 16272 |
\def\lstaspectindex#1#2{% |
| 16273 |
\global\@namedef{lstkandc@\string#1}{}% |
| 16274 |
\@ifundefined{lstisaspect@\string#1} |
| 16275 |
{\index{unknown\levelchar |
| 16276 |
\protect\texttt{\protect\string\string#1}#2}}% |
| 16277 |
{\index{\@nameuse{lstisaspect@\string#1}\levelchar |
| 16278 |
\protect\texttt{\protect\string\string#1}#2}}% |
| 16279 |
} |
| 16280 |
\def\lstkeyindex#1#2{% |
| 16281 |
% \index{key\levelchar\protect\keyname{#1}#2}% |
| 16282 |
} |
| 16283 |
% \end{macrocode} |
| 16284 |
% The key/command to aspect relation is defined near the top of this file using |
| 16285 |
% the following command. In future the package should read this information |
| 16286 |
% from the aspect files. |
| 16287 |
% \begin{macrocode} |
| 16288 |
\def\lstisaspect[#1]#2{% |
| 16289 |
\global\@namedef{lstaspect@#1}{#2}% |
| 16290 |
\lst@AddTo\lst@allkeysandcmds{,#2}% |
| 16291 |
\@for\lst@temp:=#2\do |
| 16292 |
{\ifx\@empty\lst@temp\else |
| 16293 |
\global\@namedef{lstisaspect@\lst@temp}{#1}% |
| 16294 |
\fi}} |
| 16295 |
\gdef\lst@allkeysandcmds{} |
| 16296 |
% \end{macrocode} |
| 16297 |
% This relation is also good to print all keys and commands of a particular |
| 16298 |
% aspect \ldots |
| 16299 |
% \begin{macrocode} |
| 16300 |
\def\lstprintaspectkeysandcmds#1{% |
| 16301 |
\lst@true |
| 16302 |
\expandafter\@for\expandafter\lst@temp |
| 16303 |
\expandafter:\expandafter=\csname lstaspect@#1\endcsname\do |
| 16304 |
{\lst@if\lst@false\else, \fi \texttt{\lst@temp}}} |
| 16305 |
% \end{macrocode} |
| 16306 |
% \ldots\ or to check the reference. Note that we've defined |
| 16307 |
% |\lstkandc@|\meta{name} in |\lstaspectindex|. |
| 16308 |
% \begin{macrocode} |
| 16309 |
\def\lstcheckreference{% |
| 16310 |
\@for\lst@temp:=\lst@allkeysandcmds\do |
| 16311 |
{\ifx\lst@temp\@empty\else |
| 16312 |
\@ifundefined{lstkandc@\lst@temp} |
| 16313 |
{\typeout{\lst@temp\space not in reference guide?}}{}% |
| 16314 |
\fi}} |
| 16315 |
% \end{macrocode} |
| 16316 |
% |
| 16317 |
% |
| 16318 |
% \paragraph{Unique styles} |
| 16319 |
% \begin{macrocode} |
| 16320 |
\newcommand*\lst{\texttt{lst}} |
| 16321 |
\newcommand*\Cpp{C\texttt{++}} |
| 16322 |
\let\keyname\texttt |
| 16323 |
\let\keyvalue\texttt |
| 16324 |
\let\hookname\texttt |
| 16325 |
\newcommand*\aspectname[1]{{\normalfont\sffamily#1}} |
| 16326 |
% \end{macrocode} |
| 16327 |
% \begin{macrocode} |
| 16328 |
\DeclareRobustCommand\packagename[1]{% |
| 16329 |
{\leavevmode\text@command{#1}% |
| 16330 |
\switchfontfamily\sfdefault\rmdefault |
| 16331 |
\check@icl #1\check@icr |
| 16332 |
\expandafter}}% |
| 16333 |
\renewcommand\packagename[1]{{\normalfont\sffamily#1}} |
| 16334 |
\def\switchfontfamily#1#2{% |
| 16335 |
\begingroup\xdef\@gtempa{#1}\endgroup |
| 16336 |
\ifx\f@family\@gtempa\fontfamily#2% |
| 16337 |
\else\fontfamily#1\fi |
| 16338 |
\selectfont} |
| 16339 |
% \end{macrocode} |
| 16340 |
% The color mainly for keys and commands in the reference |
| 16341 |
% guide---\textit{r} means reference. |
| 16342 |
% \begin{macrocode} |
| 16343 |
\ifcolor |
| 16344 |
\definecolor{darkgreen}{rgb}{0,0.5,0} |
| 16345 |
\def\rstyle{\color{darkgreen}} |
| 16346 |
\else |
| 16347 |
\let\rstyle\empty |
| 16348 |
\fi |
| 16349 |
% \end{macrocode} |
| 16350 |
% |
| 16351 |
% \paragraph{Commands for credits and helpers} |
| 16352 |
% There are two commands for credits and helpers: |
| 16353 |
% \begin{enumerate} |
| 16354 |
% \item |\lstthanks| is used to put a name of a contributor into the |
| 16355 |
% section ``Closing and credit''. It has two arguments: |#1| is the |
| 16356 |
% name, |#2| the email address---the email addres is not shown. |
| 16357 |
% \item |\lsthelper| must be used in the text to show the name of the |
| 16358 |
% helper (argument |#1|), the date of the contribution (argument |#2|) |
| 16359 |
% and a short text about the contribution (argument |#3|). Only the |
| 16360 |
% first argument is printed. |
| 16361 |
% \end{enumerate} |
| 16362 |
% \begin{macrocode} |
| 16363 |
\gdef\lst@emails{} |
| 16364 |
\newcommand*\lstthanks[2] |
| 16365 |
{#1\lst@AddTo\lst@emails{,#1,<#2>}% |
| 16366 |
\ifx\@empty#2\@empty\typeout{Missing email for #1}\fi} |
| 16367 |
\newcommand*\lsthelper[3] |
| 16368 |
{{\let~\ #1}% |
| 16369 |
\lst@IfOneOf#1\relax\lst@emails |
| 16370 |
{}{\typeout{^^JWarning: Unknown helper #1.^^J}}} |
| 16371 |
% \end{macrocode} |
| 16372 |
% |
| 16373 |
% \paragraph{Languages and styles} |
| 16374 |
% \begin{macrocode} |
| 16375 |
\lstdefinelanguage[doc]{Pascal}{% |
| 16376 |
morekeywords={alfa,and,array,begin,boolean,byte,case,char,const,div,% |
| 16377 |
do,downto,else,end,false,file,for,function,get,goto,if,in,% |
| 16378 |
integer,label,maxint,mod,new,not,of,or,pack,packed,page,program,% |
| 16379 |
procedure,put,read,readln,real,record,repeat,reset,rewrite,set,% |
| 16380 |
text,then,to,true,type,unpack,until,var,while,with,write,writeln},% |
| 16381 |
sensitive=false,% |
| 16382 |
morecomment=[s]{(*}{*)},% |
| 16383 |
morecomment=[s]{\{}{\}},% |
| 16384 |
morestring=[d]{'}} |
| 16385 |
% \end{macrocode} |
| 16386 |
% \begin{macrocode} |
| 16387 |
\lstdefinestyle{} |
| 16388 |
{basicstyle={},% |
| 16389 |
keywordstyle=\bfseries,identifierstyle={},% |
| 16390 |
commentstyle=\itshape,stringstyle={},% |
| 16391 |
numberstyle={},stepnumber=1,% |
| 16392 |
pointstyle=\pointstyle} |
| 16393 |
\def\pointstyle{% |
| 16394 |
{\let\lst@um\@empty \xdef\@gtempa{\the\lst@token}}% |
| 16395 |
\expandafter\lstkeyindex\expandafter{\@gtempa}{}% |
| 16396 |
\expandafter\lstaspectindex\expandafter{\@gtempa}{}% |
| 16397 |
\rstyle} |
| 16398 |
\lstset{defaultdialect=[doc]Pascal,language=Pascal,style={}} |
| 16399 |
% \end{macrocode} |
| 16400 |
% |
| 16401 |
% |
| 16402 |
% \subsection{Scanning languages} |
| 16403 |
% |
| 16404 |
% \begin{macro}{\lstscanlanguages} |
| 16405 |
% We modify some internal definitions and input the files. |
| 16406 |
% \begin{macrocode} |
| 16407 |
\def\lstscanlanguages#1#2#3{% |
| 16408 |
\begingroup |
| 16409 |
\def\lst@DefDriver@##1##2##3##4[##5]##6{% |
| 16410 |
\lst@false |
| 16411 |
\lst@lAddTo\lst@scan{##6(##5),}% |
| 16412 |
\begingroup |
| 16413 |
\@ifnextchar[{\lst@XDefDriver{##1}##3}{\lst@DefDriver@@##3}}% |
| 16414 |
\def\lst@XXDefDriver[##1]{}% |
| 16415 |
\lst@InputCatcodes |
| 16416 |
\def\lst@dontinput{#3}% |
| 16417 |
\let\lst@scan\@empty |
| 16418 |
\lst@for{#2}\do{% |
| 16419 |
\lst@IfOneOf##1\relax\lst@dontinput |
| 16420 |
{}% |
| 16421 |
{\InputIfFileExists{##1}{}{}}}% |
| 16422 |
\global\let\@gtempa\lst@scan |
| 16423 |
\endgroup |
| 16424 |
\let#1\@gtempa} |
| 16425 |
% \end{macrocode} |
| 16426 |
% \end{macro} |
| 16427 |
% |
| 16428 |
% \begin{macro}{\lstprintlanguages} |
| 16429 |
% |\do| creates a box of width 0.5|\linewidth| or |\linewidth| depending |
| 16430 |
% on how wide the argument is. This leads to `two column' output. |
| 16431 |
% The other main thing is sorting the list and begin with the output. |
| 16432 |
% \begin{macrocode} |
| 16433 |
\def\lstprintlanguages#1{% |
| 16434 |
\def\do##1{\setbox\@tempboxa\hbox{##1\space\space}% |
| 16435 |
\ifdim\wd\@tempboxa<.5\linewidth \wd\@tempboxa.5\linewidth |
| 16436 |
\else \wd\@tempboxa\linewidth \fi |
| 16437 |
\box\@tempboxa\allowbreak}% |
| 16438 |
\begin{quote} |
| 16439 |
\par\noindent |
| 16440 |
\hyphenpenalty=\@M \rightskip=\z@\@plus\linewidth\relax |
| 16441 |
\lst@BubbleSort#1% |
| 16442 |
\expandafter\lst@NextLanguage#1\relax(\relax),% |
| 16443 |
\end{quote}} |
| 16444 |
% \end{macrocode} |
| 16445 |
% We get and define the current language and \ldots |
| 16446 |
% \begin{macrocode} |
| 16447 |
\def\lst@NextLanguage#1(#2),{% |
| 16448 |
\ifx\relax#1\else |
| 16449 |
\def\lst@language{#1}\def\lst@dialects{(#2),}% |
| 16450 |
\expandafter\lst@NextLanguage@ |
| 16451 |
\fi} |
| 16452 |
% \end{macrocode} |
| 16453 |
% \ldots\space gather all available dialect of this language (note that the |
| 16454 |
% list has been sorted) |
| 16455 |
% \begin{macrocode} |
| 16456 |
\def\lst@NextLanguage@#1(#2),{% |
| 16457 |
\def\lst@temp{#1}% |
| 16458 |
\ifx\lst@temp\lst@language |
| 16459 |
\lst@lAddTo\lst@dialects{(#2),}% |
| 16460 |
\expandafter\lst@NextLanguage@ |
| 16461 |
\else |
| 16462 |
% \end{macrocode} |
| 16463 |
% or begin to print this language with all its dialects. Therefor we sort the |
| 16464 |
% dialects |
| 16465 |
% \begin{macrocode} |
| 16466 |
\do{\lst@language |
| 16467 |
\ifx\lst@dialects\lst@emptydialect\else |
| 16468 |
\expandafter\lst@NormedDef\expandafter\lst@language |
| 16469 |
\expandafter{\lst@language}% |
| 16470 |
\space(% |
| 16471 |
\lst@BubbleSort\lst@dialects |
| 16472 |
\expandafter\lst@PrintDialects\lst@dialects(\relax),% |
| 16473 |
)% |
| 16474 |
\fi}% |
| 16475 |
\def\lst@next{\lst@NextLanguage#1(#2),}% |
| 16476 |
\expandafter\lst@next |
| 16477 |
\fi} |
| 16478 |
\def\lst@emptydialect{(),} |
| 16479 |
% \end{macrocode} |
| 16480 |
% and print the dialect with appropriate commas in between. |
| 16481 |
% \begin{macrocode} |
| 16482 |
\def\lst@PrintDialects(#1),{% |
| 16483 |
\ifx\@empty#1\@empty empty\else |
| 16484 |
\lst@PrintDialect{#1}% |
| 16485 |
\fi |
| 16486 |
\lst@PrintDialects@} |
| 16487 |
\def\lst@PrintDialects@(#1),{% |
| 16488 |
\ifx\relax#1\else |
| 16489 |
, \lst@PrintDialect{#1}% |
| 16490 |
\expandafter\lst@PrintDialects@ |
| 16491 |
\fi} |
| 16492 |
% \end{macrocode} |
| 16493 |
% Here we take care of default dialects. |
| 16494 |
% \begin{macrocode} |
| 16495 |
\def\lst@PrintDialect#1{% |
| 16496 |
\lst@NormedDef\lst@temp{#1}% |
| 16497 |
\expandafter\ifx\csname\@lst dd@\lst@language\endcsname\lst@temp |
| 16498 |
\texttt{\underbar{#1}}% |
| 16499 |
\else |
| 16500 |
\texttt{#1}% |
| 16501 |
\fi} |
| 16502 |
% \end{macrocode} |
| 16503 |
% \end{macro} |
| 16504 |
% |
| 16505 |
% |
| 16506 |
% \subsection{Bubble sort} |
| 16507 |
% |
| 16508 |
% \begin{macro}{\lst@IfLE} |
| 16509 |
% \meta{string 1}|\relax\@empty|\meta{string 2}|\relax\@empty|\marg{then}\meta{else}. |
| 16510 |
% If \meta{string 1} $\leq$ \meta{string 2}, we execute \meta{then} and |
| 16511 |
% \meta{else} otherwise. |
| 16512 |
% Note that this comparision is case insensitive. |
| 16513 |
% \begin{macrocode} |
| 16514 |
\def\lst@IfLE#1#2\@empty#3#4\@empty{% |
| 16515 |
\ifx #1\relax |
| 16516 |
\let\lst@next\@firstoftwo |
| 16517 |
\else \ifx #3\relax |
| 16518 |
\let\lst@next\@secondoftwo |
| 16519 |
\else |
| 16520 |
\lowercase{\ifx#1#3}% |
| 16521 |
\def\lst@next{\lst@IfLE#2\@empty#4\@empty}% |
| 16522 |
\else |
| 16523 |
\lowercase{\ifnum`#1<`#3}\relax |
| 16524 |
\let\lst@next\@firstoftwo |
| 16525 |
\else |
| 16526 |
\let\lst@next\@secondoftwo |
| 16527 |
\fi |
| 16528 |
\fi |
| 16529 |
\fi \fi |
| 16530 |
\lst@next} |
| 16531 |
% \end{macrocode} |
| 16532 |
% \end{macro} |
| 16533 |
% |
| 16534 |
% \begin{macro}{\lst@BubbleSort} |
| 16535 |
% is in fact a derivation of bubble sort. |
| 16536 |
% \begin{macrocode} |
| 16537 |
\def\lst@BubbleSort#1{% |
| 16538 |
\ifx\@empty#1\else |
| 16539 |
\lst@false |
| 16540 |
% \end{macrocode} |
| 16541 |
% We `bubble sort' the first, second, \ldots\ elements and \ldots |
| 16542 |
% \begin{macrocode} |
| 16543 |
\expandafter\lst@BubbleSort@#1\relax,\relax,% |
| 16544 |
% \end{macrocode} |
| 16545 |
% \ldots\space then the second, third, \ldots\ elements until no elemets have |
| 16546 |
% been swapped. |
| 16547 |
% \begin{macrocode} |
| 16548 |
\expandafter\lst@BubbleSort@\expandafter,\lst@sorted |
| 16549 |
\relax,\relax,% |
| 16550 |
\let#1\lst@sorted |
| 16551 |
\lst@if |
| 16552 |
\def\lst@next{\lst@BubbleSort#1}% |
| 16553 |
\expandafter\expandafter\expandafter\lst@next |
| 16554 |
\fi |
| 16555 |
\fi} |
| 16556 |
\def\lst@BubbleSort@#1,#2,{% |
| 16557 |
\ifx\@empty#1\@empty |
| 16558 |
\def\lst@sorted{#2,}% |
| 16559 |
\def\lst@next{\lst@BubbleSort@@}% |
| 16560 |
\else |
| 16561 |
\let\lst@sorted\@empty |
| 16562 |
\def\lst@next{\lst@BubbleSort@@#1,#2,}% |
| 16563 |
\fi |
| 16564 |
\lst@next} |
| 16565 |
% \end{macrocode} |
| 16566 |
% But the bubbles rise only one step per call. Putting the elements at their |
| 16567 |
% top most place would be inefficient (since \TeX\ had to read much more |
| 16568 |
% parameters in this case). |
| 16569 |
% \begin{macrocode} |
| 16570 |
\def\lst@BubbleSort@@#1,#2,{% |
| 16571 |
\ifx\relax#1\else |
| 16572 |
\ifx\relax#2% |
| 16573 |
\lst@lAddTo\lst@sorted{#1,}% |
| 16574 |
\expandafter\expandafter\expandafter\lst@BubbleSort@@@ |
| 16575 |
\else |
| 16576 |
\lst@IfLE #1\relax\@empty #2\relax\@empty |
| 16577 |
{\lst@lAddTo\lst@sorted{#1,#2,}}% |
| 16578 |
{\lst@true \lst@lAddTo\lst@sorted{#2,#1,}}% |
| 16579 |
\expandafter\expandafter\expandafter\lst@BubbleSort@@ |
| 16580 |
\fi |
| 16581 |
\fi} |
| 16582 |
\def\lst@BubbleSort@@@#1\relax,{} |
| 16583 |
% \end{macrocode} |
| 16584 |
% \begin{macrocode} |
| 16585 |
%</doc> |
| 16586 |
% \end{macrocode} |
| 16587 |
% \end{macro} |
| 16588 |
% |
| 16589 |
% |
| 16590 |
% \section{Interfaces to other programs} |
| 16591 |
% |
| 16592 |
% |
| 16593 |
% \subsection{0.21 compatibility} |
| 16594 |
% |
| 16595 |
% \begin{aspect}{0.21} |
| 16596 |
% Some keys have just been renamed. |
| 16597 |
% \begin{macrocode} |
| 16598 |
%<*0.21> |
| 16599 |
\lst@BeginAspect{0.21} |
| 16600 |
% \end{macrocode} |
| 16601 |
% |
| 16602 |
% \begin{macrocode} |
| 16603 |
\lst@Key{labelstyle}{}{\def\lst@numberstyle{#1}} |
| 16604 |
\lst@Key{labelsep}{10pt}{\def\lst@numbersep{#1}} |
| 16605 |
\lst@Key{labelstep}{0}{% |
| 16606 |
\ifnum #1=\z@ \KV@lst@numbers{none}% |
| 16607 |
\else \KV@lst@numbers{left}\fi |
| 16608 |
\def\lst@stepnumber{#1\relax}} |
| 16609 |
\lst@Key{firstlabel}\relax{\def\lst@firstnumber{#1\relax}} |
| 16610 |
\lst@Key{advancelabel}\relax{\def\lst@advancenumber{#1\relax}} |
| 16611 |
\let\c@lstlabel\c@lstnumber |
| 16612 |
\lst@AddToHook{Init}{\def\thelstnumber{\thelstlabel}} |
| 16613 |
\newcommand*\thelstlabel{\@arabic\c@lstlabel} |
| 16614 |
% \end{macrocode} |
| 16615 |
% A |\let| in the second last line has been changed to |\def| after a bug |
| 16616 |
% report by \lsthelper{Venkatesh~Prasad~Ranganath}{2002/08/31}{Undefined |
| 16617 |
% control sequence \thelstnumber with 0.21-option}. |
| 16618 |
% \begin{macrocode} |
| 16619 |
\lst@Key{first}\relax{\def\lst@firstline{#1\relax}} |
| 16620 |
\lst@Key{last}\relax{\def\lst@lastline{#1\relax}} |
| 16621 |
% \end{macrocode} |
| 16622 |
% \begin{macrocode} |
| 16623 |
\lst@Key{framerulewidth}{.4pt}{\def\lst@framerulewidth{#1}} |
| 16624 |
\lst@Key{framerulesep}{2pt}{\def\lst@rulesep{#1}} |
| 16625 |
\lst@Key{frametextsep}{3pt}{\def\lst@frametextsep{#1}} |
| 16626 |
\lst@Key{framerulecolor}{}{\lstKV@OptArg[]{#1}% |
| 16627 |
{\ifx\@empty##2\@empty |
| 16628 |
\let\lst@rulecolor\@empty |
| 16629 |
\else |
| 16630 |
\ifx\@empty##1\@empty |
| 16631 |
\def\lst@rulecolor{\color{##2}}% |
| 16632 |
\else |
| 16633 |
\def\lst@rulecolor{\color[##1]{##2}}% |
| 16634 |
\fi |
| 16635 |
\fi}} |
| 16636 |
\lst@Key{backgroundcolor}{}{\lstKV@OptArg[]{#1}% |
| 16637 |
{\ifx\@empty##2\@empty |
| 16638 |
\let\lst@bkgcolor\@empty |
| 16639 |
\else |
| 16640 |
\ifx\@empty##1\@empty |
| 16641 |
\def\lst@bkgcolor{\color{##2}}% |
| 16642 |
\else |
| 16643 |
\def\lst@bkgcolor{\color[##1]{##2}}% |
| 16644 |
\fi |
| 16645 |
\fi}} |
| 16646 |
\lst@Key{framespread}{\z@}{\def\lst@framespread{#1}} |
| 16647 |
\lst@AddToHook{PreInit} |
| 16648 |
{\@tempdima\lst@framespread\relax \divide\@tempdima\tw@ |
| 16649 |
\edef\lst@framextopmargin{\the\@tempdima}% |
| 16650 |
\let\lst@framexrightmargin\lst@framextopmargin |
| 16651 |
\let\lst@framexbottommargin\lst@framextopmargin |
| 16652 |
\advance\@tempdima\lst@xleftmargin\relax |
| 16653 |
\edef\lst@framexleftmargin{\the\@tempdima}} |
| 16654 |
% \end{macrocode} |
| 16655 |
% \lsthelper{Harald~Harders}{1998/03/30}{inner- and outerspread} had the idea |
| 16656 |
% of two spreads (inner and outer). We either divide the dimension by two or |
| 16657 |
% assign the two dimensions to inner- and outerspread. |
| 16658 |
% \begin{macrocode} |
| 16659 |
\newdimen\lst@innerspread \newdimen\lst@outerspread |
| 16660 |
\lst@Key{spread}{\z@,\z@}{\lstKV@CSTwoArg{#1}% |
| 16661 |
{\lst@innerspread##1\relax |
| 16662 |
\ifx\@empty##2\@empty |
| 16663 |
\divide\lst@innerspread\tw@\relax |
| 16664 |
\lst@outerspread\lst@innerspread |
| 16665 |
\else |
| 16666 |
\lst@outerspread##2\relax |
| 16667 |
\fi}} |
| 16668 |
\lst@AddToHook{BoxUnsafe}{\lst@outerspread\z@ \lst@innerspread\z@} |
| 16669 |
\lst@Key{wholeline}{false}[t]{\lstKV@SetIf{#1}\lst@ifresetmargins} |
| 16670 |
\lst@Key{indent}{\z@}{\def\lst@xleftmargin{#1}} |
| 16671 |
\lst@AddToHook{PreInit} |
| 16672 |
{\lst@innerspread=-\lst@innerspread |
| 16673 |
\lst@outerspread=-\lst@outerspread |
| 16674 |
\ifodd\c@page \advance\lst@innerspread\lst@xleftmargin |
| 16675 |
\else \advance\lst@outerspread\lst@xleftmargin \fi |
| 16676 |
\ifodd\c@page |
| 16677 |
\edef\lst@xleftmargin{\the\lst@innerspread}% |
| 16678 |
\edef\lst@xrightmargin{\the\lst@outerspread}% |
| 16679 |
\else |
| 16680 |
\edef\lst@xleftmargin{\the\lst@outerspread}% |
| 16681 |
\edef\lst@xrightmargin{\the\lst@innerspread}% |
| 16682 |
\fi} |
| 16683 |
% \end{macrocode} |
| 16684 |
% \begin{macrocode} |
| 16685 |
\lst@Key{defaultclass}\relax{\def\lst@classoffset{#1}} |
| 16686 |
\lst@Key{stringtest}\relax{}% dummy |
| 16687 |
\lst@Key{outputpos}\relax{\lst@outputpos#1\relax\relax} |
| 16688 |
% \end{macrocode} |
| 16689 |
% \begin{macrocode} |
| 16690 |
\lst@Key{stringspaces}\relax[t]{\lstKV@SetIf{#1}\lst@ifshowstringspaces} |
| 16691 |
\lst@Key{visiblespaces}\relax[t]{\lstKV@SetIf{#1}\lst@ifshowspaces} |
| 16692 |
\lst@Key{visibletabs}\relax[t]{\lstKV@SetIf{#1}\lst@ifshowtabs} |
| 16693 |
% \end{macrocode} |
| 16694 |
% |
| 16695 |
% \begin{macrocode} |
| 16696 |
\lst@EndAspect |
| 16697 |
%</0.21> |
| 16698 |
% \end{macrocode} |
| 16699 |
% \end{aspect} |
| 16700 |
% |
| 16701 |
% |
| 16702 |
% \subsection{\packagename{fancyvrb}} |
| 16703 |
% |
| 16704 |
% \lsthelper{Denis~Girou}{1998/07/26}{fancyvrb} asked whether |
| 16705 |
% \packagename{fancyvrb} and \packagename{listings} could work together. |
| 16706 |
% |
| 16707 |
% \begin{lstkey}{fancyvrb} |
| 16708 |
% We set the boolean and call a submacro. |
| 16709 |
% \begin{macrocode} |
| 16710 |
%<*kernel> |
| 16711 |
\lst@Key{fancyvrb}\relax[t]{% |
| 16712 |
\lstKV@SetIf{#1}\lst@iffancyvrb |
| 16713 |
\lstFV@fancyvrb} |
| 16714 |
\ifx\lstFV@fancyvrb\@undefined |
| 16715 |
\gdef\lstFV@fancyvrb{\lst@RequireAspects{fancyvrb}\lstFV@fancyvrb} |
| 16716 |
\fi |
| 16717 |
%</kernel> |
| 16718 |
% \end{macrocode} |
| 16719 |
% \end{lstkey} |
| 16720 |
% |
| 16721 |
% \begin{aspect}{fancyvrb} |
| 16722 |
% We end the job if \packagename{fancyvrb} is not present. |
| 16723 |
% \begin{macrocode} |
| 16724 |
%<*misc> |
| 16725 |
\lst@BeginAspect{fancyvrb} |
| 16726 |
% \end{macrocode} |
| 16727 |
% \begin{macrocode} |
| 16728 |
\@ifundefined{FancyVerbFormatLine} |
| 16729 |
{\typeout{^^J% |
| 16730 |
***^^J% |
| 16731 |
*** `listings.sty' needs `fancyvrb.sty' right now.^^J% |
| 16732 |
*** Please ensure its availability and try again.^^J% |
| 16733 |
***^^J}% |
| 16734 |
\batchmode \@@end}{} |
| 16735 |
% \end{macrocode} |
| 16736 |
% |
| 16737 |
% \begin{macro}{\lstFV@fancyvrb} |
| 16738 |
% We assign the correct |\FancyVerbFormatLine| macro. |
| 16739 |
% \begin{macrocode} |
| 16740 |
\gdef\lstFV@fancyvrb{% |
| 16741 |
\lst@iffancyvrb |
| 16742 |
\ifx\FancyVerbFormatLine\lstFV@FancyVerbFormatLine\else |
| 16743 |
\let\lstFV@FVFL\FancyVerbFormatLine |
| 16744 |
\let\FancyVerbFormatLine\lstFV@FancyVerbFormatLine |
| 16745 |
\fi |
| 16746 |
\else |
| 16747 |
\ifx\lstFV@FVFL\@undefined\else |
| 16748 |
\let\FancyVerbFormatLine\lstFV@FVFL |
| 16749 |
\let\lstFV@FVFL\@undefined |
| 16750 |
\fi |
| 16751 |
\fi} |
| 16752 |
% \end{macrocode} |
| 16753 |
% \end{macro} |
| 16754 |
% |
| 16755 |
% \begin{macro}{\lstFV@VerbatimBegin} |
| 16756 |
% We initialize things if necessary. |
| 16757 |
% \begin{macrocode} |
| 16758 |
\gdef\lstFV@VerbatimBegin{% |
| 16759 |
\ifx\FancyVerbFormatLine\lstFV@FancyVerbFormatLine |
| 16760 |
\lsthk@TextStyle \lsthk@BoxUnsafe |
| 16761 |
\lsthk@PreSet |
| 16762 |
\lst@activecharsfalse |
| 16763 |
\let\normalbaselines\relax |
| 16764 |
% \end{macrocode} |
| 16765 |
% \begin{TODO} |
| 16766 |
% Is this |\let| bad? |
| 16767 |
% \end{TODO} |
| 16768 |
% I inserted |\lst@ifresetmargins|\ldots|\fi| after a bug report from |
| 16769 |
% \lsthelper{Peter~Bartke}{1999/11/18}{wrong fancyvrb frame}. The linewidth |
| 16770 |
% is saved and restored since a bug report by \lsthelper{Denis~Girou} |
| 16771 |
% {2003/07/04}{problem in list environments with fancyvrb=true}. |
| 16772 |
% \begin{macrocode} |
| 16773 |
\xdef\lstFV@RestoreData{\noexpand\linewidth\the\linewidth\relax}% |
| 16774 |
\lst@Init\relax |
| 16775 |
\lst@ifresetmargins \advance\linewidth-\@totalleftmargin \fi |
| 16776 |
\lstFV@RestoreData |
| 16777 |
\everypar{}\global\lst@newlines\z@ |
| 16778 |
\lst@mode\lst@nomode \let\lst@entermodes\@empty |
| 16779 |
\lst@InterruptModes |
| 16780 |
% \end{macrocode} |
| 16781 |
% \lsthelper{Rolf~Niepraschk}{1998/11/25}{ligatures problem} reported a bug |
| 16782 |
% concerning ligatures to \lsthelper{Denis~Girou}{1998/11/27}{use |\@noligs|}. |
| 16783 |
% \begin{macrocode} |
| 16784 |
%% D.G. modification begin - Nov. 25, 1998 |
| 16785 |
\let\@noligs\relax |
| 16786 |
%% D.G. modification end |
| 16787 |
\fi} |
| 16788 |
% \end{macrocode} |
| 16789 |
% \end{macro} |
| 16790 |
% |
| 16791 |
% \begin{macro}{\lstFV@VerbatimEnd} |
| 16792 |
% A box and macro must exist after |\lst@DeInit|. |
| 16793 |
% We store them globally. |
| 16794 |
% \begin{macrocode} |
| 16795 |
\gdef\lstFV@VerbatimEnd{% |
| 16796 |
\ifx\FancyVerbFormatLine\lstFV@FancyVerbFormatLine |
| 16797 |
\global\setbox\lstFV@gtempboxa\box\@tempboxa |
| 16798 |
\global\let\@gtempa\FV@ProcessLine |
| 16799 |
\lst@mode\lst@Pmode |
| 16800 |
\lst@DeInit |
| 16801 |
\let\FV@ProcessLine\@gtempa |
| 16802 |
\setbox\@tempboxa\box\lstFV@gtempboxa |
| 16803 |
\par |
| 16804 |
\fi} |
| 16805 |
% \end{macrocode} |
| 16806 |
% The |\par| has been added after a bug report by \lsthelper{Peter~Bartke} |
| 16807 |
% {2002/04/10}{TeX is not in vertical mode when leaving "Verbatim"}. |
| 16808 |
% \begin{macrocode} |
| 16809 |
\newbox\lstFV@gtempboxa |
| 16810 |
% \end{macrocode} |
| 16811 |
% \end{macro} |
| 16812 |
% |
| 16813 |
% \noindent |
| 16814 |
% We insert |\lstFV@VerbatimBegin| and |\lstFV@VerbatimEnd| where necessary. |
| 16815 |
% \begin{macrocode} |
| 16816 |
\lst@AddTo\FV@VerbatimBegin\lstFV@VerbatimBegin |
| 16817 |
\lst@AddToAtTop\FV@VerbatimEnd\lstFV@VerbatimEnd |
| 16818 |
\lst@AddTo\FV@LVerbatimBegin\lstFV@VerbatimBegin |
| 16819 |
\lst@AddToAtTop\FV@LVerbatimEnd\lstFV@VerbatimEnd |
| 16820 |
\lst@AddTo\FV@BVerbatimBegin\lstFV@VerbatimBegin |
| 16821 |
\lst@AddToAtTop\FV@BVerbatimEnd\lstFV@VerbatimEnd |
| 16822 |
% \end{macrocode} |
| 16823 |
% |
| 16824 |
% \begin{macro}{\lstFV@FancyVerbFormatLine} |
| 16825 |
% `@' terminates the argument of |\lst@FVConvert|. |
| 16826 |
% Moreover |\lst@ReenterModes| and |\lst@InterruptModes| encloses some code. |
| 16827 |
% This ensures that we have same group level at the beginning and at the end of |
| 16828 |
% the macro---even if the user begins but doesn't end a comment, which means |
| 16829 |
% one open group. |
| 16830 |
% Furthermore we use |\vtop| and reset |\lst@newlines| to allow line breaking. |
| 16831 |
% \begin{macrocode} |
| 16832 |
\gdef\lstFV@FancyVerbFormatLine#1{% |
| 16833 |
\let\lst@arg\@empty \lst@FVConvert#1\@nil |
| 16834 |
\global\lst@newlines\z@ |
| 16835 |
\vtop{\noindent\lst@parshape |
| 16836 |
\lst@ReenterModes |
| 16837 |
\lst@arg \lst@PrintToken\lst@EOLUpdate\lsthk@InitVarsBOL |
| 16838 |
\lst@InterruptModes}} |
| 16839 |
% \end{macrocode} |
| 16840 |
% The |\lst@parshape| inside |\vtop| is due to a bug report from |
| 16841 |
% \lsthelper{Peter~Bartke}{1999/11/18}{wrong par indention with fancyvrb}. |
| 16842 |
% A |\leavevmode| became |\noindent|. |
| 16843 |
% \end{macro} |
| 16844 |
% |
| 16845 |
% \begin{lstkey}{fvcmdparams} |
| 16846 |
% \begin{lstkey}{morefvcmdparams} |
| 16847 |
% These keys adjust \lst@FVcmdparams, which will be used by the following |
| 16848 |
% conversion macro. The base set of commands and parameter numbers was |
| 16849 |
% provided by \lsthelper{Denis~Girou}{2002/05/31}{init of fvcmdparams}. |
| 16850 |
% \begin{macrocode} |
| 16851 |
\lst@Key{fvcmdparams}% |
| 16852 |
{\overlay\@ne}% |
| 16853 |
{\def\lst@FVcmdparams{,#1}} |
| 16854 |
\lst@Key{morefvcmdparams}\relax{\lst@lAddTo\lst@FVcmdparams{,#1}} |
| 16855 |
% \end{macrocode} |
| 16856 |
% \end{lstkey} |
| 16857 |
% \end{lstkey} |
| 16858 |
% |
| 16859 |
% \begin{macro}{\lst@FVConvert} |
| 16860 |
% We do conversion or \ldots |
| 16861 |
% \begin{macrocode} |
| 16862 |
\gdef\lst@FVConvert{\@tempcnta\z@ \lst@FVConvertO@}% |
| 16863 |
\gdef\lst@FVConvertO@{% |
| 16864 |
\ifcase\@tempcnta |
| 16865 |
\expandafter\futurelet\expandafter\@let@token |
| 16866 |
\expandafter\lst@FVConvert@@ |
| 16867 |
\else |
| 16868 |
% \end{macrocode} |
| 16869 |
% \ldots\ we append arguments without conversion, argument by argument, |
| 16870 |
% |\@tempcnta| times. |
| 16871 |
% \begin{macrocode} |
| 16872 |
\expandafter\lst@FVConvertO@a |
| 16873 |
\fi} |
| 16874 |
\gdef\lst@FVConvertO@a#1{% |
| 16875 |
\lst@lAddTo\lst@arg{{#1}}\advance\@tempcnta\m@ne |
| 16876 |
\lst@FVConvertO@}% |
| 16877 |
% \end{macrocode} |
| 16878 |
% Since |\@ifnextchar\bgroup| might fail, we have to use |\ifcat| here. |
| 16879 |
% Bug reported by \lsthelper{Denis~Girou}{1999/07/26}{fancyvrb=true + `second |
| 16880 |
% commandchar' other than \{ doesn't work}. |
| 16881 |
% However we don't gobble space tokens as |\@ifnextchar| does. |
| 16882 |
% \begin{macrocode} |
| 16883 |
\gdef\lst@FVConvert@@{% |
| 16884 |
\ifcat\noexpand\@let@token\bgroup \expandafter\lst@FVConvertArg |
| 16885 |
\else \expandafter\lst@FVConvert@ \fi} |
| 16886 |
% \end{macrocode} |
| 16887 |
% Coming to such a catcode${}={}$1 character we convert the argument and add |
| 16888 |
% it together with group delimiters to |\lst@arg|. |
| 16889 |
% We also add |\lst@PrintToken|, which prints all collected characters before |
| 16890 |
% we forget them. |
| 16891 |
% Finally we continue the conversion. |
| 16892 |
% \begin{macrocode} |
| 16893 |
\gdef\lst@FVConvertArg#1{% |
| 16894 |
{\let\lst@arg\@empty |
| 16895 |
\lst@FVConvert#1\@nil |
| 16896 |
\global\let\@gtempa\lst@arg}% |
| 16897 |
\lst@lExtend\lst@arg{\expandafter{\@gtempa\lst@PrintToken}}% |
| 16898 |
\lst@FVConvert} |
| 16899 |
% \end{macrocode} |
| 16900 |
% \begin{macrocode} |
| 16901 |
\gdef\lst@FVConvert@#1{% |
| 16902 |
\ifx \@nil#1\else |
| 16903 |
\if\relax\noexpand#1% |
| 16904 |
\lst@lAddTo\lst@arg{\lst@OutputLostSpace\lst@PrintToken#1}% |
| 16905 |
\else |
| 16906 |
\lccode`\~=`#1\lowercase{\lst@lAddTo\lst@arg~}% |
| 16907 |
\fi |
| 16908 |
\expandafter\lst@FVConvert |
| 16909 |
\fi} |
| 16910 |
% \end{macrocode} |
| 16911 |
% Having no |\bgroup|, we look whether we've found the end of the input, and |
| 16912 |
% convert one token ((non)active character or control sequence). |
| 16913 |
% \begin{macrocode} |
| 16914 |
\gdef\lst@FVConvert@#1{% |
| 16915 |
\ifx \@nil#1\else |
| 16916 |
\if\relax\noexpand#1% |
| 16917 |
\lst@lAddTo\lst@arg{\lst@OutputLostSpace\lst@PrintToken#1}% |
| 16918 |
% \end{macrocode} |
| 16919 |
% Here we check for registered commands with arguments and set the value of |
| 16920 |
% |\@tempcnta| as required. |
| 16921 |
% \begin{macrocode} |
| 16922 |
\def\lst@temp##1,#1##2,##3##4\relax{% |
| 16923 |
\ifx##3\@empty \else \@tempcnta##2\relax \fi}% |
| 16924 |
\expandafter\lst@temp\lst@FVcmdparams,#1\z@,\@empty\relax |
| 16925 |
\else |
| 16926 |
\lccode`\~=`#1\lowercase{\lst@lAddTo\lst@arg~}% |
| 16927 |
\fi |
| 16928 |
\expandafter\lst@FVConvertO@ |
| 16929 |
\fi} |
| 16930 |
% \end{macrocode} |
| 16931 |
% \end{macro} |
| 16932 |
% |
| 16933 |
% \begin{macrocode} |
| 16934 |
\lst@EndAspect |
| 16935 |
%</misc> |
| 16936 |
% \end{macrocode} |
| 16937 |
% \end{aspect} |
| 16938 |
% |
| 16939 |
% |
| 16940 |
% \subsection{Omega support} |
| 16941 |
% |
| 16942 |
% \begingroup |
| 16943 |
% $\Omega$ support looks easy---I hope it works at least in some cases. |
| 16944 |
% \begin{macrocode} |
| 16945 |
%<*kernel> |
| 16946 |
% \end{macrocode} |
| 16947 |
% \begin{macrocode} |
| 16948 |
\@ifundefined{ocp}{} |
| 16949 |
{\lst@AddToHook{OutputBox}% |
| 16950 |
{\let\lst@ProcessLetter\@firstofone |
| 16951 |
\let\lst@ProcessDigit\@firstofone |
| 16952 |
\let\lst@ProcessOther\@firstofone}} |
| 16953 |
% \end{macrocode} |
| 16954 |
% \begin{macrocode} |
| 16955 |
%</kernel> |
| 16956 |
% \end{macrocode} |
| 16957 |
% \endgroup |
| 16958 |
% |
| 16959 |
% |
| 16960 |
% \subsection{\packagename{LGrind}} |
| 16961 |
% |
| 16962 |
% \begin{aspect}{lgrind} |
| 16963 |
% \begin{macro}{\lst@LGGetNames} |
| 16964 |
% is used to extract the language names from |\lst@arg| (the |
| 16965 |
% \packagename{LGrind} definition). |
| 16966 |
% \begin{macrocode} |
| 16967 |
%<*misc> |
| 16968 |
\lst@BeginAspect[keywords,comments,strings,language]{lgrind} |
| 16969 |
% \end{macrocode} |
| 16970 |
% \begin{macrocode} |
| 16971 |
\gdef\lst@LGGetNames#1:#2\relax{% |
| 16972 |
\lst@NormedDef\lstlang@{#1}\lst@ReplaceInArg\lstlang@{|,}% |
| 16973 |
\def\lst@arg{:#2}} |
| 16974 |
% \end{macrocode} |
| 16975 |
% \end{macro} |
| 16976 |
% |
| 16977 |
% \begin{macro}{\lst@LGGetValue} |
| 16978 |
% returns in |\lst@LGvalue| the value of capability |#1| given by the list |
| 16979 |
% |\lst@arg|. If |#1| is not found, we have |\lst@if|=|\iffalse|. |
| 16980 |
% Otherwise it is true and the ``cap=value'' pair is removed from the list. |
| 16981 |
% First we test for |#1| and |
| 16982 |
% \begin{macrocode} |
| 16983 |
\gdef\lst@LGGetValue#1{% |
| 16984 |
\lst@false |
| 16985 |
\def\lst@temp##1:#1##2##3\relax{% |
| 16986 |
\ifx\@empty##2\else \lst@LGGetValue@{#1}\fi} |
| 16987 |
\expandafter\lst@temp\lst@arg:#1\@empty\relax} |
| 16988 |
% \end{macrocode} |
| 16989 |
% remove the pair if necessary. |
| 16990 |
% \begin{macrocode} |
| 16991 |
\gdef\lst@LGGetValue@#1{% |
| 16992 |
\lst@true |
| 16993 |
\def\lst@temp##1:#1##2:##3\relax{% |
| 16994 |
\@ifnextchar=\lst@LGGetValue@@{\lst@LGGetValue@@=}##2\relax |
| 16995 |
\def\lst@arg{##1:##3}}% |
| 16996 |
\expandafter\lst@temp\lst@arg\relax} |
| 16997 |
\gdef\lst@LGGetValue@@=#1\relax{\def\lst@LGvalue{#1}} |
| 16998 |
% \end{macrocode} |
| 16999 |
% \end{macro} |
| 17000 |
% |
| 17001 |
% \begin{macro}{\lst@LGGetComment} |
| 17002 |
% stores the comment delimiters (enclosed in braces) in |#2| if comment of type |
| 17003 |
% |#1| is present and not a comment line. Otherwise |#2| is empty. |
| 17004 |
% \begin{macrocode} |
| 17005 |
\gdef\lst@LGGetComment#1#2{% |
| 17006 |
\let#2\@empty |
| 17007 |
\lst@LGGetValue{#1b}% |
| 17008 |
\lst@if |
| 17009 |
\let#2\lst@LGvalue |
| 17010 |
\lst@LGGetValue{#1e}% |
| 17011 |
\ifx\lst@LGvalue\lst@LGEOL |
| 17012 |
\edef\lstlang@{\lstlang@,commentline={#2}}% |
| 17013 |
\let#2\@empty |
| 17014 |
\else |
| 17015 |
\edef#2{{#2}{\lst@LGvalue}}% |
| 17016 |
\fi |
| 17017 |
\fi} |
| 17018 |
% \end{macrocode} |
| 17019 |
% \end{macro} |
| 17020 |
% |
| 17021 |
% \begin{macro}{\lst@LGGetString} |
| 17022 |
% does the same for string delimiters, but it doesn't `return' any value. |
| 17023 |
% \begin{macrocode} |
| 17024 |
\gdef\lst@LGGetString#1#2{% |
| 17025 |
\lst@LGGetValue{#1b}% |
| 17026 |
\lst@if |
| 17027 |
\let#2\lst@LGvalue |
| 17028 |
\lst@LGGetValue{#1e}% |
| 17029 |
\ifx\lst@LGvalue\lst@LGEOL |
| 17030 |
\edef\lstlang@{\lstlang@,morestringizer=[l]{#2}}% |
| 17031 |
\else |
| 17032 |
% \end{macrocode} |
| 17033 |
% we must check for |\e|, i.e.~whether we have to use \texttt doubled or |
| 17034 |
% \texttt backslashed stringizer. |
| 17035 |
% \begin{macrocode} |
| 17036 |
\ifx #2\lst@LGvalue |
| 17037 |
\edef\lstlang@{\lstlang@,morestringizer=[d]{#2}}% |
| 17038 |
\else |
| 17039 |
\edef\lst@temp{\lst@LGe#2}% |
| 17040 |
\ifx \lst@temp\lst@LGvalue |
| 17041 |
\edef\lstlang@{\lstlang@,morestringizer=[b]{#2}}% |
| 17042 |
\else |
| 17043 |
\PackageWarning{Listings}% |
| 17044 |
{String #2...\lst@LGvalue\space not supported}% |
| 17045 |
\fi |
| 17046 |
\fi |
| 17047 |
\fi |
| 17048 |
\fi} |
| 17049 |
% \end{macrocode} |
| 17050 |
% \end{macro} |
| 17051 |
% |
| 17052 |
% \begin{macro}{\lst@LGDefLang} |
| 17053 |
% defines the language given by |\lst@arg|, the definition part, and |
| 17054 |
% |\lst@language@|, the language name. First we remove unwanted stuff from |
| 17055 |
% |\lst@arg|, e.g.~we replace |:\ :| by |:|. |
| 17056 |
% \begin{macrocode} |
| 17057 |
\gdef\lst@LGDefLang{% |
| 17058 |
\lst@LGReplace |
| 17059 |
\let\lstlang@\empty |
| 17060 |
% \end{macrocode} |
| 17061 |
% Get the keywords and values of friends. |
| 17062 |
% \begin{macrocode} |
| 17063 |
\lst@LGGetValue{kw}% |
| 17064 |
\lst@if |
| 17065 |
\lst@ReplaceInArg\lst@LGvalue{{ },}% |
| 17066 |
\edef\lstlang@{\lstlang@,keywords={\lst@LGvalue}}% |
| 17067 |
\fi |
| 17068 |
% \end{macrocode} |
| 17069 |
% \begin{macrocode} |
| 17070 |
\lst@LGGetValue{oc}% |
| 17071 |
\lst@if |
| 17072 |
\edef\lstlang@{\lstlang@,sensitive=f}% |
| 17073 |
\fi |
| 17074 |
% \end{macrocode} |
| 17075 |
% \begin{macrocode} |
| 17076 |
\lst@LGGetValue{id}% |
| 17077 |
\lst@if |
| 17078 |
\edef\lstlang@{\lstlang@,alsoletter=\lst@LGvalue}% |
| 17079 |
\fi |
| 17080 |
% \end{macrocode} |
| 17081 |
% Now we get the comment delimiters and use them as single or double comments |
| 17082 |
% according to whether there are two or four delimiters. |
| 17083 |
% Note that |\lst@LGGetComment| takes care of comment lines. |
| 17084 |
% \begin{macrocode} |
| 17085 |
\lst@LGGetComment a\lst@LGa |
| 17086 |
\lst@LGGetComment c\lst@LGc |
| 17087 |
\ifx\lst@LGa\@empty |
| 17088 |
\ifx\lst@LGc\@empty\else |
| 17089 |
\edef\lstlang@{\lstlang@,singlecomment=\lst@LGc}% |
| 17090 |
\fi |
| 17091 |
\else |
| 17092 |
\ifx\lst@LGc\@empty |
| 17093 |
\edef\lstlang@{\lstlang@,singlecomment=\lst@LGa}% |
| 17094 |
\else |
| 17095 |
\edef\lstlang@{\lstlang@,doublecomment=\lst@LGc\lst@LGa}% |
| 17096 |
\fi |
| 17097 |
\fi |
| 17098 |
% \end{macrocode} |
| 17099 |
% Now we parse the stringizers. |
| 17100 |
% \begin{macrocode} |
| 17101 |
\lst@LGGetString s\lst@LGa |
| 17102 |
\lst@LGGetString l\lst@LGa |
| 17103 |
% \end{macrocode} |
| 17104 |
% We test for the continuation capability and |
| 17105 |
% \begin{macrocode} |
| 17106 |
\lst@LGGetValue{tc}% |
| 17107 |
\lst@if |
| 17108 |
\edef\lstlang@{\lstlang@,lgrindef=\lst@LGvalue}% |
| 17109 |
\fi |
| 17110 |
% \end{macrocode} |
| 17111 |
% define the language. |
| 17112 |
% \begin{macrocode} |
| 17113 |
\expandafter\xdef\csname\@lst LGlang@\lst@language@\endcsname |
| 17114 |
{\noexpand\lstset{\lstlang@}}% |
| 17115 |
% \end{macrocode} |
| 17116 |
% Finally we inform the user of all ignored capabilities. |
| 17117 |
% \begin{macrocode} |
| 17118 |
\lst@ReplaceInArg\lst@arg{{: :}:}\let\lst@LGvalue\@empty |
| 17119 |
\expandafter\lst@LGDroppedCaps\lst@arg\relax\relax |
| 17120 |
\ifx\lst@LGvalue\@empty\else |
| 17121 |
\PackageWarningNoLine{Listings}{Ignored capabilities for |
| 17122 |
\space `\lst@language@' are\MessageBreak\lst@LGvalue}% |
| 17123 |
\fi} |
| 17124 |
% \end{macrocode} |
| 17125 |
% \end{macro} |
| 17126 |
% |
| 17127 |
% \begin{macro}{\lst@LGDroppedCaps} |
| 17128 |
% just drops a previous value and appends the next capabilty name to |
| 17129 |
% |\lst@LGvalue|. |
| 17130 |
% \begin{macrocode} |
| 17131 |
\gdef\lst@LGDroppedCaps#1:#2#3{% |
| 17132 |
\ifx#2\relax |
| 17133 |
\lst@RemoveCommas\lst@LGvalue |
| 17134 |
\else |
| 17135 |
\edef\lst@LGvalue{\lst@LGvalue,#2#3}% |
| 17136 |
\expandafter\lst@LGDroppedCaps |
| 17137 |
\fi} |
| 17138 |
% \end{macrocode} |
| 17139 |
% \end{macro} |
| 17140 |
% |
| 17141 |
% \begin{macro}{\lst@LGReplace} |
| 17142 |
% \begin{macro}{\lst@LGe} |
| 17143 |
% We replace `escaped \verb!:^$|!' by catcode 11 versions, and other strings |
| 17144 |
% by some kind of short versions (which is necessary to get the above |
| 17145 |
% definitions work). |
| 17146 |
% \begin{macrocode} |
| 17147 |
\begingroup |
| 17148 |
\catcode`\/=0 |
| 17149 |
\lccode`\z=`\:\lccode`\y=`\^\lccode`\x=`\$\lccode`\v=`\| |
| 17150 |
\catcode`\\=12\relax |
| 17151 |
/lowercase{% |
| 17152 |
/gdef/lst@LGReplace{/lst@ReplaceInArg/lst@arg |
| 17153 |
{{\:}{z }{\^}{y}{\$}{x}{\|}{v}{ \ }{ }{:\ :}{:}{\ }{ }{\(}({\)})}} |
| 17154 |
/gdef/lst@LGe{\e} |
| 17155 |
} |
| 17156 |
/endgroup |
| 17157 |
% \end{macrocode} |
| 17158 |
% \end{macro}\end{macro} |
| 17159 |
% |
| 17160 |
% \begin{macro}{\lst@LGRead} |
| 17161 |
% reads one language definition and defines the language if the correct one |
| 17162 |
% is found. |
| 17163 |
% \begin{macrocode} |
| 17164 |
\gdef\lst@LGRead#1\par{% |
| 17165 |
\lst@LGGetNames#1:\relax |
| 17166 |
\def\lst@temp{endoflanguagedefinitions}% |
| 17167 |
\ifx\lstlang@\lst@temp |
| 17168 |
\let\lst@next\endinput |
| 17169 |
\else |
| 17170 |
\expandafter\lst@IfOneOf\lst@language@\relax\lstlang@ |
| 17171 |
{\lst@LGDefLang \let\lst@next\endinput}% |
| 17172 |
{\let\lst@next\lst@LGRead}% |
| 17173 |
\fi |
| 17174 |
\lst@next} |
| 17175 |
% \end{macrocode} |
| 17176 |
% \end{macro} |
| 17177 |
% |
| 17178 |
% \begin{lstkey}{lgrindef} |
| 17179 |
% We only have to request the language and |
| 17180 |
% \begin{macrocode} |
| 17181 |
\lst@Key{lgrindef}\relax{% |
| 17182 |
\lst@NormedDef\lst@language@{#1}% |
| 17183 |
\begingroup |
| 17184 |
\@ifundefined{lstLGlang@\lst@language@}% |
| 17185 |
{\everypar{\lst@LGRead}% |
| 17186 |
\catcode`\\=12\catcode`\{=12\catcode`\}=12\catcode`\%=12% |
| 17187 |
\catcode`\#=14\catcode`\$=12\catcode`\^=12\catcode`\_=12\relax |
| 17188 |
\input{\lstlgrindeffile}% |
| 17189 |
}{}% |
| 17190 |
\endgroup |
| 17191 |
% \end{macrocode} |
| 17192 |
% select it or issue an error message. |
| 17193 |
% \begin{macrocode} |
| 17194 |
\@ifundefined{lstLGlang@\lst@language@}% |
| 17195 |
{\PackageError{Listings}% |
| 17196 |
{LGrind language \lst@language@\space undefined}% |
| 17197 |
{The language is not loadable. \@ehc}}% |
| 17198 |
{\lsthk@SetLanguage |
| 17199 |
\csname\@lst LGlang@\lst@language@\endcsname}} |
| 17200 |
% \end{macrocode} |
| 17201 |
% \end{lstkey} |
| 17202 |
% |
| 17203 |
% \begin{macro}{\lstlgrindeffile} |
| 17204 |
% contains just the file name. |
| 17205 |
% \begin{macrocode} |
| 17206 |
\@ifundefined{lstlgrindeffile} |
| 17207 |
{\lst@UserCommand\lstlgrindeffile{lgrindef.}}{} |
| 17208 |
% \end{macrocode} |
| 17209 |
% \end{macro} |
| 17210 |
% |
| 17211 |
% \begin{macrocode} |
| 17212 |
\lst@EndAspect |
| 17213 |
%</misc> |
| 17214 |
% \end{macrocode} |
| 17215 |
% \end{aspect} |
| 17216 |
% |
| 17217 |
% |
| 17218 |
% \subsection{\packagename{hyperref}} |
| 17219 |
% |
| 17220 |
% \begin{aspect}{hyper} |
| 17221 |
% \begin{macrocode} |
| 17222 |
%<*misc> |
| 17223 |
\lst@BeginAspect[keywords]{hyper} |
| 17224 |
% \end{macrocode} |
| 17225 |
% |
| 17226 |
% \begin{lstkey}{hyperanchor} |
| 17227 |
% \begin{lstkey}{hyperlink} |
| 17228 |
% determine the macro to set an anchor and a link, respectively. |
| 17229 |
% \begin{macrocode} |
| 17230 |
\lst@Key{hyperanchor}\hyper@@anchor{\let\lst@hyperanchor#1} |
| 17231 |
\lst@Key{hyperlink}\hyperlink{\let\lst@hyperlink#1} |
| 17232 |
% \end{macrocode} |
| 17233 |
% \end{lstkey}\end{lstkey} |
| 17234 |
% Again, the main thing is a special working procedure. First we extract the |
| 17235 |
% contents of |\lst@token| and get a free macro name for this current character |
| 17236 |
% string (using prefix |lstHR@| and a number as suffix). Then we make this |
| 17237 |
% free macro equivalent to |\@empty|, so it is not used the next time. |
| 17238 |
% \begin{macrocode} |
| 17239 |
\lst@InstallKeywords{h}{hyperref}{}\relax{} |
| 17240 |
{\begingroup |
| 17241 |
\let\lst@UM\@empty \xdef\@gtempa{\the\lst@token}% |
| 17242 |
\endgroup |
| 17243 |
\lst@GetFreeMacro{lstHR@\@gtempa}% |
| 17244 |
\global\expandafter\let\lst@freemacro\@empty |
| 17245 |
% \end{macrocode} |
| 17246 |
% |\@tempcnta| is the suffix of the free macro. We use it here to refer to |
| 17247 |
% the last occurence of the same string. To do this, we redefine the output |
| 17248 |
% macro |\lst@alloverstyle| to set an anchor \ldots |
| 17249 |
% \begin{macrocode} |
| 17250 |
\@tempcntb\@tempcnta \advance\@tempcntb\m@ne |
| 17251 |
\edef\lst@alloverstyle##1{% |
| 17252 |
\let\noexpand\lst@alloverstyle\noexpand\@empty |
| 17253 |
\noexpand\smash{\raise\baselineskip\hbox |
| 17254 |
{\noexpand\lst@hyperanchor{lst.\@gtempa\the\@tempcnta}% |
| 17255 |
{\relax}}}% |
| 17256 |
% \end{macrocode} |
| 17257 |
% \ldots\space and a link to the last occurence (if there is any). |
| 17258 |
% \begin{macrocode} |
| 17259 |
\ifnum\@tempcnta=\z@ ##1\else |
| 17260 |
\noexpand\lst@hyperlink{lst.\@gtempa\the\@tempcntb}{##1}% |
| 17261 |
\fi}% |
| 17262 |
} |
| 17263 |
od |
| 17264 |
% \end{macrocode} |
| 17265 |
% |
| 17266 |
% \begin{macrocode} |
| 17267 |
\lst@EndAspect |
| 17268 |
%</misc> |
| 17269 |
% \end{macrocode} |
| 17270 |
% \end{aspect} |
| 17271 |
% |
| 17272 |
% |
| 17273 |
% \section{Epilogue} |
| 17274 |
% |
| 17275 |
% \begingroup |
| 17276 |
% \begin{macrocode} |
| 17277 |
%<*kernel> |
| 17278 |
% \end{macrocode} |
| 17279 |
% Each option adds the aspect name to |\lst@loadaspects| or removes it from that data macro. |
| 17280 |
% \begin{macrocode} |
| 17281 |
\DeclareOption*{\expandafter\lst@ProcessOption\CurrentOption\relax} |
| 17282 |
\def\lst@ProcessOption#1#2\relax{% |
| 17283 |
\ifx #1!% |
| 17284 |
\lst@DeleteKeysIn\lst@loadaspects{#2}% |
| 17285 |
\else |
| 17286 |
\lst@lAddTo\lst@loadaspects{,#1#2}% |
| 17287 |
\fi} |
| 17288 |
% \end{macrocode} |
| 17289 |
% The following aspects are loaded by default. |
| 17290 |
% \begin{macrocode} |
| 17291 |
\@ifundefined{lst@loadaspects} |
| 17292 |
{\def\lst@loadaspects{strings,comments,escape,style,language,% |
| 17293 |
keywords,labels,lineshape,frames,emph,index}% |
| 17294 |
}{} |
| 17295 |
% \end{macrocode} |
| 17296 |
% We load the patch file, \ldots |
| 17297 |
% \begin{macrocode} |
| 17298 |
\InputIfFileExists{lstpatch.sty}{}{} |
| 17299 |
% \end{macrocode} |
| 17300 |
% \ldots\ process the options, \ldots |
| 17301 |
% \begin{macrocode} |
| 17302 |
\let\lst@ifsavemem\iffalse |
| 17303 |
\DeclareOption{savemem}{\let\lst@ifsavemem\iftrue} |
| 17304 |
\DeclareOption{noaspects}{\let\lst@loadaspects\@empty} |
| 17305 |
\ProcessOptions |
| 17306 |
% \end{macrocode} |
| 17307 |
% \ldots\ and load the aspects. |
| 17308 |
% \begin{macrocode} |
| 17309 |
\lst@RequireAspects\lst@loadaspects |
| 17310 |
\let\lst@loadaspects\@empty |
| 17311 |
% \end{macrocode} |
| 17312 |
% If present we select the empty style and language. |
| 17313 |
% \begin{macrocode} |
| 17314 |
\lst@UseHook{SetStyle}\lst@UseHook{EmptyStyle} |
| 17315 |
\lst@UseHook{SetLanguage}\lst@UseHook{EmptyLanguage} |
| 17316 |
% \end{macrocode} |
| 17317 |
% Finally we load the configuration files. \lsthelper{Ulrike~Fischer}{2020/11/13} |
| 17318 |
% {.cfg-file is read with wrong catcode} pointed out that this must happen |
| 17319 |
% with the correct catcode. At the moment the catcode of |^^M| is 9, which |
| 17320 |
% is wrong. So we reset the catcodes to the correct values before loading |
| 17321 |
% the files: |
| 17322 |
% \begin{macrocode} |
| 17323 |
%<info>\lst@ReportAllocs |
| 17324 |
\lst@RestoreCatcodes% |
| 17325 |
\InputIfFileExists{listings.cfg}{}{} |
| 17326 |
\InputIfFileExists{lstlocal.cfg}{}{} |
| 17327 |
% \end{macrocode} |
| 17328 |
% \begin{macrocode} |
| 17329 |
%</kernel> |
| 17330 |
% \end{macrocode} |
| 17331 |
% \endgroup |
| 17332 |
% |
| 17333 |
% |
| 17334 |
% \section{History} |
| 17335 |
% \begingroup\small |
| 17336 |
% Only major changes are listed here. Introductory version numbers of commands |
| 17337 |
% and keys are in the sources of the guides, which makes this history fairly |
| 17338 |
% short. |
| 17339 |
% \renewcommand\labelitemi{--} |
| 17340 |
% \begin{itemize} |
| 17341 |
% \item[0.1] from 1996/03/09 |
| 17342 |
% \item test version to look whether package is possible or not |
| 17343 |
% \item[0.11] from 1996/08/19 |
| 17344 |
%\iffalse |
| 17345 |
% \item additional blank option (= language) |
| 17346 |
%\fi |
| 17347 |
% \item improved alignment |
| 17348 |
% \item[0.12] from 1997/01/16 |
| 17349 |
% \item nearly `perfect' alignment |
| 17350 |
% \item[0.13] from 1997/02/11 |
| 17351 |
%\iffalse |
| 17352 |
% \item additional languages: Eiffel, Fortran 90, Modula-2, Pascal XSC |
| 17353 |
%\fi |
| 17354 |
% \item load on demand: language specific macros moved to driver files |
| 17355 |
% \item comments are declared now and not implemented for each language again |
| 17356 |
% (this makes the \TeX\ sources easier to read) |
| 17357 |
% \item[0.14] from 1997/02/18 |
| 17358 |
% \item User's guide rewritten, Implementation guide uses macro environment |
| 17359 |
% \item (non) case sensitivity implemented and multiple string types, |
| 17360 |
% i.e.~Modula-2 handles both string types: quotes and double quotes |
| 17361 |
%\iffalse |
| 17362 |
% \item comment declaration is user-accessible |
| 17363 |
% \item package compatible to \verb!german.sty! |
| 17364 |
%\fi |
| 17365 |
% \item[0.15] from 1997/04/18 |
| 17366 |
%\iffalse |
| 17367 |
% \item additional languages: Java, Turbo Pascal |
| 17368 |
%\fi |
| 17369 |
% \item package renamed from \packagename{listing} to \packagename{listings} |
| 17370 |
% since the first already exists |
| 17371 |
% \item[0.16] from 1997/06/01 |
| 17372 |
%\iffalse |
| 17373 |
% \item changed `$<$' to `$>$' in |\lst@SkipToFirst| |
| 17374 |
% \item bug removed: |\lst@Init| must be placed before |\lst@SkipToFirst| |
| 17375 |
%\fi |
| 17376 |
% \item listing environment rewritten |
| 17377 |
% \item[0.17] from 1997/09/29 |
| 17378 |
%\iffalse |
| 17379 |
% \item |\spreadlisting| works correct now (e.g.~page numbers don't move right) |
| 17380 |
%\fi |
| 17381 |
% \item speed up things (quick `if parameter empty', all |\long| except one |
| 17382 |
% removed, faster \verb!\lst@GotoNextTabStop!, etc.) |
| 17383 |
% \item improved alignment of wide other characters (e.g.~$==$) |
| 17384 |
%\iffalse |
| 17385 |
% \item many new languages: Ada, Algol, Cobol, Comal 80, Elan, Fortran 77, |
| 17386 |
% Lisp, Logo, Matlab, Oberon, Perl, PL/I, Simula, SQL, \TeX |
| 17387 |
%\fi |
| 17388 |
% \item[pre-0.18] from 1998/03/24 (unpublished) |
| 17389 |
%\iffalse |
| 17390 |
% \item bug concerning |\labelstyle| (becomes \keyname{numberstyle}) removed |
| 17391 |
% (now oldstylenum example works) |
| 17392 |
%\fi |
| 17393 |
% \item experimental implementation of character classes |
| 17394 |
% \item[0.19] from 1998/11/09 |
| 17395 |
% \item character classes and new \lst-aspects seem to be good |
| 17396 |
% \item user interface uses \packagename{keyval} package |
| 17397 |
% \item \packagename{fancyvrb} support |
| 17398 |
% \item[0.20] from 1999/07/12 |
| 17399 |
% \item new keyword detection mechanism |
| 17400 |
% \item new aspects: \aspectname{writefile}, \aspectname{breaklines}, |
| 17401 |
% captions, \aspectname{html} |
| 17402 |
%\iffalse |
| 17403 |
% \item improved \packagename{fancyvrb} support |
| 17404 |
%\fi |
| 17405 |
% \item all aspects reside in a single file and the language drivers in |
| 17406 |
% currently two files |
| 17407 |
% \item[0.21] 2000/08/23 |
| 17408 |
% \item completely new User's guide |
| 17409 |
% \item experimental format definitions |
| 17410 |
% \item keyword classes replaced by families |
| 17411 |
% \item dynamic modes |
| 17412 |
% \item[1.0$\beta$] 2001/09/21 |
| 17413 |
% \item key names synchronized with \packagename{fancyvrb} |
| 17414 |
% \item \aspectname{frames} aspect extended |
| 17415 |
% \item new output concept (delaying and merging) |
| 17416 |
% \item[1.0] 2002/04/01 |
| 17417 |
% \item update of all documentation sections including Developer's guide |
| 17418 |
% \item delimiters unified |
| 17419 |
% \item[1.1] 2003/06/21 |
| 17420 |
% \item bugfix-release with some new keys |
| 17421 |
% \item[1.2] 2004/02/13 |
| 17422 |
% \item bugfix-release with two new keys and new section \ref{rArbitraryLinerangeMarkers} |
| 17423 |
% \item[1.3] 2004/09/07 |
| 17424 |
% \item another bugfix-release with LPPL-1.3-compliance |
| 17425 |
% \item[1.4] 2007/02/26 |
| 17426 |
% \item many bugfixes, and new maintainership |
| 17427 |
% \item several new and updated language definitions |
| 17428 |
% \item many small documentation improvements |
| 17429 |
% \item new keys, multicharacter string delimiters, short inline listings, and more. |
| 17430 |
% \item[1.5] 2013/06/27 |
| 17431 |
% \item new maintainership |
| 17432 |
% \item[1.6] 2015/05/05 |
| 17433 |
% \item add discussion about using |\lstinline|\oarg{key=value list}\marg{source code} |
| 17434 |
% \item add section ``Bugs and workarounds''. |
| 17435 |
% \item[1.7] 2018/09/02 |
| 17436 |
% \item some new or updated language definitions |
| 17437 |
% \item several error corrections |
| 17438 |
% \item[1.8] from 2019/02/27 on |
| 17439 |
% \item corrected and activated the option |inputpath| |
| 17440 |
% \item some new or updated language definitions |
| 17441 |
% \item several error corrections |
| 17442 |
% \item introduced |\lstlistingnamestyle| |
| 17443 |
% \item[1.9] from 2023/02/27 on |
| 17444 |
% \item hopefully corrected the long outstanding wrong behaviour of |
| 17445 |
% displaying visible spaces |
| 17446 |
% \item generalized the use of |linerange| |
| 17447 |
% \item introduced key |consecutivenumbers| |
| 17448 |
% \item a pagebreak between a (top) caption and source code isn't allowed |
| 17449 |
% anymore |
| 17450 |
% \item the configuration files |listings.cfg| and |lstlocal.cfg| are read |
| 17451 |
% with the correct catcode |
| 17452 |
% \item some documentation and layout enhancements. |
| 17453 |
% \item[1.10] from 2024/02/15 on |
| 17454 |
% \item usage of |tocbasic| if loaded to improve compatibility with |
| 17455 |
% KOMA-Script and also enhance functionality. |
| 17456 |
% \item differentiate between Python 2 and Python 3 |
| 17457 |
% \item add initial support for Scala 3.0 |
| 17458 |
% \item made |\lstinline{...}| work in tabular cells |
| 17459 |
% \item implemented upright double-quotes |
| 17460 |
% \end{itemize} |
| 17461 |
% \endgroup |
| 17462 |
% |
| 17463 |
% |
| 17464 |
% \Finale |
| 17465 |
% |
| 17466 |
% \begin{macrocode} |
| 17467 |
%<*dev/null> |
| 17468 |
% \end{macrocode} |
| 17469 |
%%% Local Variables: |
| 17470 |
%%% ispell-local-dictionary: "english" |
| 17471 |
%%% End: |
| 17472 |
% \begin{macrocode} |
| 17473 |
%<*dev/null> |
| 17474 |
% \end{macrocode} |
| 17475 |
\endinput |