Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 345
1
%%
2
%% This is file `lstpatch.sty', generated manually.
3
%%
4
%% (w)(c) 2004 Carsten Heinz
5
%%
6
%% This file may be distributed under the terms of the LaTeX Project Public
7
%% License from CTAN archives in directory macros/latex/base/lppl.txt.
8
%% Either version 1.0 or, at your option, any later version.
9
%%
10
%% Send comments and ideas on the package, error reports and additional
11
%% programming languages to <[email protected]>.
12
%%
13
%% This patch file will remove the following bugs from the listings package.
14
%% Each item contains the bug finder with date of report and first bug fix
15
%% version, a short description of the problem, and the reason for the bug
16
%% in parenthesis.
17
%%
18
%% 1) Frank Atanassow, 2004/10/07, 1.3b
19
%%
20
%% space after mathescape is not preserved
21
%% (\lst@newlines>0)
22
%%
23
%% 2) Benjamin Lings, 2004/10/15, 1.3b (2004/10/17)
24
%%
25
%% \usepackage{xy,listings} yields:
26
%% "Forbidden control sequence found while scanning use of \lst@lExtend"
27
%% (xy-pic correctly resets catcode of ^^L (to active), which is \outer)
28
%%
29
%%
30
%% The following features are added to the base package.
31
%%
32
%% 1.3a (2004/09/07)
33
%%
34
%% a) H I G H L Y E X P E R I M E N T A L
35
%%
36
%% Use the options
37
%% rangeprefix=<prefix for begin and end of range>
38
%% rangesuffix=<suffix for begin and end of range>
39
%%
40
%% rangebeginprefix=<prefix for begin of range>
41
%% rangebeginsuffix=<suffix for begin of range>
42
%%
43
%% rangeendprefix=<prefix for end of range>
44
%% rangeendsuffix=<suffix for end of range>
45
%%
46
%% includerangemarker=true|false
47
%% together with
48
%% firstline=<begin marker>
49
%% lastline=<end marker>
50
%% or
51
%% linerange={<begin marker 1>-<end marker 1>,
52
%% <begin marker 2>-<end marker 2>, ...}
53
%% The according markers in the source code are
54
%% <prefix><marker><suffix>
55
%% for begin respectively end of range. Moreover, one can use
56
%% includerangemarker=true|false
57
%% to show or hide the range markers in the output.
58
%%
59
%% 1.3b (2004/10/17)
60
%%
61
%% b) multicols=<number> (requires loaded multicol package)
62
%%
63
%%
64
\lst@CheckVersion{1.3}
65
{\typeout{^^J%
66
***^^J%
67
*** This is a patch for listings 1.3, but you're using^^J%
68
*** version \lst@version.^^J%
69
***^^J
70
*** Patch file not loaded.^^J%
71
***^^J}%
72
\endinput
73
}
74
\def\fileversion{1.3b}
75
\def\filedate{2004/10/17}
76
\ProvidesFile{lstpatch.sty}[\filedate\space\fileversion\space (Carsten Heinz)]
77
%
78
% 0) Insert % after #1.
79
\def\@@xbitor #1{\@tempcntb \count#1%
80
\ifnum \@tempcnta =\z@
81
\else
82
\divide\@tempcntb\@tempcnta
83
\ifodd\@tempcntb \@testtrue\fi
84
\fi}
85
%
86
% 1) Reset \lst@newlines at end of escape.
87
\def\lstpatch@escape{%
88
\gdef\lst@Escape##1##2##3##4{%
89
\lst@CArgX ##1\relax\lst@CDefX
90
{}%
91
{\lst@ifdropinput\else
92
\lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken
93
\lst@InterruptModes
94
\lst@EnterMode{\lst@TeXmode}{\lst@modetrue}%
95
\ifx\^^M##2%
96
\lst@CArg ##2\relax\lst@ActiveCDefX
97
{}%
98
{\lst@escapeend ##4\lst@LeaveAllModes\lst@ReenterModes}%
99
{\lst@MProcessListing}%
100
\else
101
\lst@CArg ##2\relax\lst@ActiveCDefX
102
{}%
103
{\lst@escapeend ##4\lst@LeaveAllModes\lst@ReenterModes
104
\lst@newlines\z@ \lst@whitespacefalse}%
105
{}%
106
\fi
107
##3\lst@escapebegin
108
\fi}%
109
{}}%
110
}
111
%
112
% 2) Deactivate \outer definition of ^^L temporarily (inside and outside
113
% of \lst@ScanChars) and restore \catcode at end of package.
114
\begingroup \catcode12=\active\let^^L\@empty
115
\gdef\lst@ScanChars{%
116
\let\lsts@ssL^^L%
117
\def^^L{\par}%
118
\lst@GetChars\lst@RestoreOrigCatcodes\@ne {128}%
119
\let^^L\lsts@ssL
120
\lst@GetChars\lst@RestoreOrigExtendedCatcodes{128}{256}}
121
\endgroup
122
\lst@lAddTo\lst@RestoreCatcodes{\catcode12\active}
123
%
124
% a) Let's start with the options:
125
\lst@Key{rangeprefix}\relax{\def\lst@rangebeginprefix{#1}%
126
\def\lst@rangeendprefix{#1}}
127
\lst@Key{rangesuffix}\relax{\def\lst@rangebeginsuffix{#1}%
128
\def\lst@rangeendsuffix{#1}}
129
\lst@Key{rangebeginprefix}{}{\def\lst@rangebeginprefix{#1}}
130
\lst@Key{rangebeginsuffix}{}{\def\lst@rangebeginsuffix{#1}}
131
\lst@Key{rangeendprefix}{}{\def\lst@rangeendprefix{#1}}
132
\lst@Key{rangeendsuffix}{}{\def\lst@rangeendsuffix{#1}}
133
\lst@Key{includerangemarker}{true}[t]{\lstKV@SetIf{#1}\lst@ifincluderangemarker}
134
%
135
% The key is a redefinition of \lst@GLI@ checking for numbers.
136
\def\lst@GLI@#1-#2-#3\@nil{%
137
\lst@IfNumber{#1}%
138
{\ifx\@empty#1\@empty
139
\let\lst@firstline\@ne
140
\else
141
\def\lst@firstline{#1\relax}%
142
\fi
143
\ifx\@empty#3\@empty
144
\def\lst@lastline{9999999\relax}%
145
\else
146
\ifx\@empty#2\@empty
147
\let\lst@lastline\lst@firstline
148
\else
149
\def\lst@lastline{#2\relax}%
150
\fi
151
\fi}%
152
%
153
% If we've found a general marker, we set firstline and lastline to 9999999.
154
% This prevents (almost) anything to be printed for now.
155
{\def\lst@firstline{9999999\relax}%
156
\let\lst@lastline\lst@firstline
157
%
158
% We add the prefixes and suffixes to the markers.
159
\let\lst@rangebegin\lst@rangebeginprefix
160
\lst@AddTo\lst@rangebegin{#1}\lst@Extend\lst@rangebegin\lst@rangebeginsuffix
161
\ifx\@empty#3\@empty
162
\let\lst@rangeend\lst@rangeendprefix
163
\lst@AddTo\lst@rangeend{#1}\lst@Extend\lst@rangeend\lst@rangeendsuffix
164
\else
165
\ifx\@empty#2\@empty
166
\let\lst@rangeend\@empty
167
\else
168
\let\lst@rangeend\lst@rangeendprefix
169
\lst@AddTo\lst@rangeend{#2}\lst@Extend\lst@rangeend\lst@rangeendsuffix
170
\fi
171
\fi
172
% The following definition will be executed in the SelectCharTable hook
173
% and here right now if we are already processing a listing.
174
\global\def\lst@DefRange{\expandafter\lst@CArgX\lst@rangebegin\relax\lst@DefRangeB}%
175
\ifnum\lst@mode=\lst@Pmode \expandafter\lst@DefRange \fi}}
176
% \lst@DefRange is not inserted via a hook anymore. Instead it is now called
177
% directly from \lst@SelectCharTable. This was necessary to get rid of an
178
% interference with the escape-to-LaTeX-feature. The bug was reported by
179
% \lsthelper{Michael~Bachmann}{2004/07/21}{Keine label-Referenzierung
180
% m\"oglich...}. Another chance is due to the same bug: \lst@DefRange is
181
% redefined globally when the begin of code is found, see below. The bug was
182
% reported by \lsthelper{Tobias~Rapp}{2004/04/06}{undetected end of range if
183
% listing crosses page break} \lsthelper{Markus~Luisser}{2004/08/13}{Bug mit
184
% 'linerangemarker' in umgebrochenen listings}
185
%\lst@AddToHook{SelectCharTable}{\lst@DefRange}
186
\lst@AddToHookExe{DeInit}{\global\let\lst@DefRange\@empty}
187
%
188
% Actually defining the marker (via \lst@GLI@, \lst@DefRange, \lst@CArgX as
189
% seen above) is similar to \lst@DefDelimB---except that we unfold the first
190
% parameter and use different <execute>, <pre>, and <post> statements.
191
\def\lst@DefRangeB#1#2{\lst@DefRangeB@#1#2}
192
\def\lst@DefRangeB@#1#2#3#4{%
193
\lst@CDef{#1{#2}{#3}}#4{}%
194
{\lst@ifincluderangemarker
195
\lst@LeaveMode
196
\let#1#4%
197
\lst@DefRangeEnd
198
\lst@InitLstNumber
199
\else
200
\@tempcnta\lst@lineno \advance\@tempcnta\@ne
201
\edef\lst@firstline{\the\@tempcnta\relax}%
202
\gdef\lst@OnceAtEOL{\let#1#4\lst@DefRangeEnd}%
203
\lst@InitLstNumber
204
\fi
205
\global\let\lst@DefRange\lst@DefRangeEnd
206
\lst@CArgEmpty}%
207
\@empty}
208
%
209
% Modify labels and define |\lst@InitLstNumber| used above.
210
% \lsthelper{Omair-Inam~Abdul-Matin}{2004/05/10}{experimental linerange
211
% feature does not work with firstnumber}
212
\def\lstpatch@labels{%
213
\gdef\lst@SetFirstNumber{%
214
\ifx\lst@firstnumber\@undefined
215
\@tempcnta 0\csname\@lst no@\lst@intname\endcsname\relax
216
\ifnum\@tempcnta=\z@ \else
217
\lst@nololtrue
218
\advance\@tempcnta\lst@advancenumber
219
\edef\lst@firstnumber{\the\@tempcnta\relax}%
220
\fi
221
\fi}%
222
}
223
\lst@AddToAtTop\lsthk@PreInit
224
{\ifx\lst@firstnumber\@undefined
225
\def\lst@firstnumber{\lst@lineno}%
226
\fi}
227
\def\lst@InitLstNumber{%
228
\global\c@lstnumber\lst@firstnumber
229
\global\advance\c@lstnumber\lst@advancenumber
230
\global\advance\c@lstnumber-\lst@advancelstnum
231
\ifx \lst@firstnumber\c@lstnumber
232
\global\advance\c@lstnumber-\lst@advancelstnum
233
\fi}
234
%
235
% The end-marker is defined if and only if it's not empty. The definition is
236
% similar to \lst@DefDelimE---with the above exceptions and except that we
237
% define the re-entry point \lst@DefRangeE@@ as it is defined in the new
238
% version of \lst@MProcessListing above.
239
\def\lst@DefRangeEnd{%
240
\ifx\lst@rangeend\@empty\else
241
\expandafter\lst@CArgX\lst@rangeend\relax\lst@DefRangeE
242
\fi}
243
\def\lst@DefRangeE#1#2{\lst@DefRangeE@#1#2}
244
\def\lst@DefRangeE@#1#2#3#4{%
245
\lst@CDef{#1#2{#3}}#4{}%
246
{\let#1#4%
247
\edef\lst@lastline{\the\lst@lineno\relax}%
248
\lst@DefRangeE@@}%
249
\@empty}
250
\def\lst@DefRangeE@@#1\@empty{%
251
\lst@ifincluderangemarker
252
#1\lst@XPrintToken
253
\fi
254
\lst@LeaveModeToPmode
255
\lst@BeginDropInput{\lst@Pmode}}
256
%
257
\def\lst@LeaveModeToPmode{%
258
\ifnum\lst@mode=\lst@Pmode
259
\expandafter\lsthk@EndGroup
260
\else
261
\expandafter\egroup\expandafter\lst@LeaveModeToPmode
262
\fi}
263
%
264
% Eventually we shouldn't forget to install \lst@OnceAtEOL, which must
265
% also be called in \lst@MSkipToFirst.
266
\lst@AddToHook{EOL}{\lst@OnceAtEOL\global\let\lst@OnceAtEOL\@empty}
267
\gdef\lst@OnceAtEOL{}% Init
268
\def\lst@MSkipToFirst{%
269
\global\advance\lst@lineno\@ne
270
\ifnum \lst@lineno=\lst@firstline
271
\def\lst@next{\lst@LeaveMode \global\lst@newlines\z@
272
\lst@OnceAtEOL \global\let\lst@OnceAtEOL\@empty
273
\lst@InitLstNumber % Added to work with modified \lsthk@PreInit.
274
\lsthk@InitVarsBOL
275
\lst@BOLGobble}%
276
\expandafter\lst@next
277
\fi}
278
\def\lst@SkipToFirst{%
279
\ifnum \lst@lineno<\lst@firstline
280
\def\lst@next{\lst@BeginDropInput\lst@Pmode
281
\lst@Let{13}\lst@MSkipToFirst
282
\lst@Let{10}\lst@MSkipToFirst}%
283
\expandafter\lst@next
284
\else
285
\expandafter\lst@BOLGobble
286
\fi}
287
%
288
% Finally the service macro \lst@IfNumber:
289
\def\lst@IfNumber#1{%
290
\ifx\@empty#1\@empty
291
\let\lst@next\@firstoftwo
292
\else
293
\lst@IfNumber@#1\@nil
294
\fi
295
\lst@next}
296
\def\lst@IfNumber@#1#2\@nil{%
297
\let\lst@next\@secondoftwo
298
\ifnum`#1>47\relax \ifnum`#1>57\relax\else
299
\let\lst@next\@firstoftwo
300
\fi\fi}
301
%
302
% b) The following is known to fail with some keys.
303
\lst@Key{multicols}{}{\@tempcnta=0#1\relax\def\lst@multicols{#1}}
304
\def\lst@Init#1{%
305
\begingroup
306
\ifx\lst@float\relax\else
307
\edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\lst@float]}%
308
\expandafter\@tempa
309
\fi
310
% chmod begin
311
\ifx\lst@multicols\@empty\else
312
\edef\lst@next{\noexpand\multicols{\lst@multicols}}
313
\expandafter\lst@next
314
\fi
315
% chmod end
316
\ifhmode\ifinner \lst@boxtrue \fi\fi
317
\lst@ifbox
318
\lsthk@BoxUnsafe
319
\hbox to\z@\bgroup
320
$\if t\lst@boxpos \vtop
321
\else \if b\lst@boxpos \vbox
322
\else \vcenter \fi\fi
323
\bgroup \par\noindent
324
\else
325
\lst@ifdisplaystyle
326
\lst@EveryDisplay
327
\par\penalty-50\relax
328
\vspace\lst@aboveskip
329
\fi
330
\fi
331
\normalbaselines
332
\abovecaptionskip\lst@abovecaption\relax
333
\belowcaptionskip\lst@belowcaption\relax
334
\lst@MakeCaption t%
335
\lsthk@PreInit \lsthk@Init
336
\lst@ifdisplaystyle
337
\global\let\lst@ltxlabel\@empty
338
\if@inlabel
339
\lst@ifresetmargins
340
\leavevmode
341
\else
342
\xdef\lst@ltxlabel{\the\everypar}%
343
\lst@AddTo\lst@ltxlabel{%
344
\global\let\lst@ltxlabel\@empty
345
\everypar{\lsthk@EveryLine\lsthk@EveryPar}}%
346
\fi
347
\fi
348
\everypar\expandafter{\lst@ltxlabel
349
\lsthk@EveryLine\lsthk@EveryPar}%
350
\else
351
\everypar{}\let\lst@NewLine\@empty
352
\fi
353
\lsthk@InitVars \lsthk@InitVarsBOL
354
\lst@Let{13}\lst@MProcessListing
355
\let\lst@Backslash#1%
356
\lst@EnterMode{\lst@Pmode}{\lst@SelectCharTable}%
357
\lst@InitFinalize}
358
\def\lst@DeInit{%
359
\lst@XPrintToken \lst@EOLUpdate
360
\global\advance\lst@newlines\m@ne
361
\lst@ifshowlines
362
\lst@DoNewLines
363
\else
364
\setbox\@tempboxa\vbox{\lst@DoNewLines}%
365
\fi
366
\lst@ifdisplaystyle \par\removelastskip \fi
367
\lsthk@ExitVars\everypar{}\lsthk@DeInit\normalbaselines\normalcolor
368
\lst@MakeCaption b%
369
\lst@ifbox
370
\egroup $\hss \egroup
371
\vrule\@width\lst@maxwidth\@height\z@\@depth\z@
372
\else
373
\lst@ifdisplaystyle
374
\par\penalty-50\vspace\lst@belowskip
375
\fi
376
\fi
377
% chmod begin
378
\ifx\lst@multicols\@empty\else
379
\def\lst@next{\global\let\@checkend\@gobble
380
\endmulticols
381
\global\let\@checkend\lst@@checkend}
382
\expandafter\lst@next
383
\fi
384
% chmod end
385
\ifx\lst@float\relax\else
386
\expandafter\lst@endfloat
387
\fi
388
\endgroup}
389
\let\lst@@checkend\@checkend
390
%%
391
\endinput
392
%%
393
%% End of file `lstpatch.sty'.
394