lstpatch.sty 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. %%
  2. %% This is file `lstpatch.sty', generated manually.
  3. %%
  4. %% Please read the software license in listings.dtx or listings.dvi.
  5. %%
  6. %% (w)(c) 2002 Carsten Heinz
  7. %%
  8. %% This file is distributed under the terms of the LaTeX Project Public
  9. %% License from CTAN archives in directory macros/latex/base/lppl.txt.
  10. %% Either version 1.0 or, at your option, any later version.
  11. %%
  12. %% Send comments and ideas on the package, error reports and additional
  13. %% programming languages to <[email protected]>.
  14. %%
  15. %% This patch file will remove the following bugs from the listings package.
  16. %% Each item contains the bug finder with date of report and first bug fix
  17. %% version, a short description of the problem, and the reason for the bug
  18. %% in parenthesis.
  19. %%
  20. %% 1) Jochen Schneider, 2002/04/03, 1.0a (2002/04/05)
  21. %%
  22. %% undefined control sequence \lst@CommentB with HTML, XML, tcl
  23. %% (I didn't renamed them to \lst@DefDelimB|E)
  24. %%
  25. %% 2) Michael Niedermair, 2002/04/07, 1.0b
  26. %%
  27. %% undefined control sequence \lst@commentmode with XML
  28. %% (mode not defined any more)
  29. %%
  30. %% 3) Carsten Heinz, 2002/04/08, 1.0b
  31. %%
  32. %% bad PODs (investigating bugs 1 and 2)
  33. %% (definition doesn't use 1.0 style)
  34. %%
  35. %% 4) Peter Bartke, 2002/04/10, 1.0b
  36. %%
  37. %% various problems with fancyvrb interface: string ".5" at beginning
  38. %% of first line when using lineskip; ditto "perhaps a missing \item
  39. %% error"; wrong placed characters , and - when using fancyvrb
  40. %% (bad use of \strip@pt; TeX is not in vertical mode when leaving
  41. %% Verbatim; bad `noligs' handling)
  42. %%
  43. %% 5) Rolf Niepraschk, 2002/04/12, 1.0b
  44. %%
  45. %% \RequirePackage is missing keywordstyle when near the top of a page
  46. %% (\lst@lastother not saved away across page breaks)
  47. %%
  48. %% 6) Peter Ruckdeschel, 2002/04/12, 1.0b
  49. %% Timothy Van Zandt analyzed and fixed the bug
  50. %%
  51. %% incompatibility with seminar class
  52. %% (bad assignment of \lst@do@noligs in \lst@SelectCharTable)
  53. %%
  54. %% 7) Rene H. Larsen, 2002/04/12, 1.0b
  55. %%
  56. %% \lstinputlistings and texcl conflict
  57. %% (^^M not active to reenter modes)
  58. %%
  59. %% 8) Carsten Heinz, 2002/04/15, 1.0b (2002/04/15)
  60. %%
  61. %% gobble doesn't always work (investigating problem with VTeX)
  62. %% (\lst@BOLGobble@ must test against \lst@Process{FormFeed|Tabulator}X)
  63. %%
  64. %% 9) Peter Bartke, 2002/04/17, 1.0c
  65. %%
  66. %% TeX capacity exceeded with fancyvrb
  67. %% (\let\lst@entermodes\@empty must stay in \lstFV@VerbatimBegin)
  68. %%
  69. %% 10) Svend Tollak Munkejord, 2002/04/17, 1.0c
  70. %% Heiko Oberdiek analyzed and fixed the bug
  71. %%
  72. %% package incompatible with Lucida .fd files
  73. %% (parentheses have active catcodes when reading the file)
  74. %%
  75. %% 11) Carsten Hamm, 2002/04/19, 1.0c (2002/04/24)
  76. %%
  77. %% wrong frame rules with breaklines and xleftmargin>0pt
  78. %% (missing \kern-\lst@xleftmargin in \lst@discretionary)
  79. %%
  80. %% 12) Michael Niedermair, 2002/05/14, 1.0d
  81. %%
  82. %% backgroundcolor take effect on bottom captions
  83. %% (wrong order of \everypar{} and \lsthk@ExitVars in \lst@DeInit)
  84. %%
  85. %% 13) Georg Rehm, 2002/05/14, 1.0d
  86. %%
  87. %% bad baselineskip with captionpos=b
  88. %% (missing \normalbaselines)
  89. %%
  90. %% 14) Herfried Karl Wagner, 2002/05/11, 1.0d
  91. %%
  92. %% undefined control sequence \lst@entermodes
  93. %% (\output called before first \lst@EnterMode)
  94. %%
  95. %% 15) Peter K\"oller, 2002/05/24, 1.0d
  96. %%
  97. %% XML keywords don't have keywordstyle
  98. %% (missing \ifx... in implementation of contentsstyle)
  99. %%
  100. %% 16) Stephen Reindl, 2002/05/28, 1.0d
  101. %%
  102. %% \inaccessible using Cobol
  103. %% (\lst@Delim@option didn't enclose option in [])
  104. %%
  105. %% 17) Stephen Reindl, 2002/06/04, 1.0d (2002/06/12)
  106. %%
  107. %% frames not deactivated for text style listings
  108. %%
  109. %% 18) Carsten Heinz, 2002/07/27, 1.0e (2002/07/31)
  110. %%
  111. %% broken keywordcomments
  112. %% (\lst@KCpost inside group level 2; bad \lst@BeginComment call)
  113. %%
  114. %% 19) Kris Luyten, 2002/07/30, 1.0f (2002/08/03)
  115. %%
  116. %% Undefined control sequence \lst@thestyle
  117. %% (undefined \lst@directives after _loading_ C)
  118. %%
  119. %% 20) Kris Luyten, 2002/08/03, 1.0g (2002/08/06)
  120. %%
  121. %% Undefined control sequence \lst@thestyle
  122. %% (side effect of 19-bugfix on \lst@ProvideFamily)
  123. %%
  124. %% 21) Venkatesh Prasad Ranganath, 2002/08/31, 1.0h
  125. %%
  126. %% Undefined control sequence \thelstnumber with 0.21-option
  127. %% (\let must be changed to a \def inition)
  128. %%
  129. %% 22) Fermin Reig, 2002/09/04, 1.0h (2002/09/09)
  130. %%
  131. %% Bad top frame inside figure+centering
  132. %% (reset of leftskip, rightskip and parfillskip comes too late)
  133. %%
  134. %% 23) Hermann H\"uttler, 2002/10/05, 1.0i (2002/10/13)
  135. %%
  136. %% C++-string "... \\" does not end with second double quote
  137. %% (missing \let\lst@lastother\@empty in old fix)
  138. %%
  139. %%
  140. %% Moreover the following functionality is added.
  141. %%
  142. %% a) option "final" (Rolf Niepraschk, Enrico Straube)
  143. %%
  144. %% b) keys "fvcmdparams" and "morefvcmdparams" (Denis Girou)
  145. %%
  146. %% c) key "contentstyle" (Peter K\"oller)
  147. %%
  148. %% d) key "numberfirstline" (Georg Rehm)
  149. %%
  150. %%
  151. \ProvidesFile{lstpatch.sty}[2002/10/13 1.0i (Carsten Heinz)]
  152. \lst@CheckVersion{1.0}
  153. {\typeout{^^J%
  154. ***^^J%
  155. *** This is a patch for `listings.sty' version 1.0, but^^J%
  156. *** you're using version \lst@version.^^J%
  157. ***^^J
  158. *** Patch file not loaded.^^J%
  159. ***^^J}%
  160. \endinput
  161. }
  162. %
  163. % 1) Define the missing control sequences. (Not needed any more.)
  164. \def\lstpatch@comments{%
  165. \global\let\lst@CommentB\lst@DefDelimB
  166. \global\let\lst@CommentE\lst@DefDelimE}
  167. %
  168. % 2) Define \lst@commentmode.
  169. \lst@NewMode\lst@commentmode
  170. %
  171. % 3) Introduce \lst@ifxpodcomment as master-clause and define 1.0 style
  172. % contents for SelectCharTable.
  173. \def\lstpatch@pod{%
  174. \lst@Key{podcomment}{false}[t]{\lstKV@SetIf{##1}\lst@ifxpodcomment}%
  175. \lst@AddToHookExe{SetLanguage}{\let\lst@ifxpodcomment\iffalse}%
  176. \lst@AddToHook{SelectCharTable}%
  177. {\lst@ifxpodcomment
  178. \lst@CArgX =\relax\lst@DefDelimB{}{}%
  179. {\ifnum\@tempcnta=\z@
  180. \lst@ifprintpod\else
  181. \def\lst@bnext{\lst@BeginDropOutput\lst@PODmode}%
  182. \expandafter\expandafter\expandafter\@gobblethree
  183. \fi
  184. \else
  185. \expandafter\@gobblethree
  186. \fi}%
  187. \lst@BeginComment\lst@PODmode{{\lst@commentstyle}}% modified
  188. \lst@CArgX =cut\^^M\relax\lst@DefDelimE
  189. {\lst@CalcColumn}%
  190. {\ifnum\@tempcnta=\z@\else
  191. \expandafter\@gobblethree
  192. \fi}%
  193. {}%
  194. \lst@EndComment\lst@PODmode
  195. \fi}%
  196. }
  197. %
  198. % 4) Redefine lineskip like podcomment above and don't use \strip@pt
  199. % together with \divide.
  200. \def\lstpatch@lineshape{%
  201. \lst@Key{lineskip}{\z@}{\def\lst@xlineskip{##1\relax}}
  202. \lst@AddToHook{Init}
  203. {\ifdim\z@=\lst@xlineskip\else
  204. \@tempdima\baselineskip
  205. \advance\@tempdima\lst@xlineskip
  206. \multiply\@tempdima\@cclvi
  207. \divide\@tempdima\baselineskip\relax
  208. \multiply\@tempdima\@cclvi
  209. \edef\baselinestretch{\strip@pt\@tempdima}%
  210. \selectfont
  211. \fi}%
  212. % 11) Add \kern-\lst@xleftmargin.
  213. \gdef\lst@discretionary{%
  214. \discretionary{\let\space\lst@spacekern\lst@prebreak}%
  215. {\llap{\lsthk@EveryLine
  216. \kern\lst@breakcurrindent\kern-\lst@xleftmargin}%
  217. \let\space\lst@spacekern\lst@postbreak}{}}%
  218. }
  219. % Back to 4): Insert \par for vertical mode.
  220. \def\lstpatch@fancyvrb{%
  221. \gdef\lstFV@VerbatimEnd{%
  222. \ifx\FancyVerbFormatLine\lstFV@FancyVerbFormatLine
  223. \global\setbox\lstFV@gtempboxa\box\@tempboxa
  224. \global\let\@gtempa\FV@ProcessLine
  225. \lst@mode\lst@Pmode
  226. \lst@DeInit
  227. \let\FV@ProcessLine\@gtempa
  228. \setbox\@tempboxa\box\lstFV@gtempboxa
  229. \par % modified
  230. \fi}%
  231. % 9) Redefined \lstFV@VerbatimBegin removed.
  232. % b) Refine conversion definitions to either work as usual or to ...
  233. \gdef\lst@FVConvert{\@tempcnta\z@ \lst@FVConvertO@}%
  234. \gdef\lst@FVConvertO@{%
  235. \ifcase\@tempcnta \expandafter
  236. \futurelet\expandafter\@let@token\expandafter\lst@FVConvert@@
  237. \else
  238. % append arguments as they are.
  239. \expandafter\lst@FVConvertO@a
  240. \fi}%
  241. \gdef\lst@FVConvertO@a##1{%
  242. \lst@lAddTo\lst@arg{{##1}}\advance\@tempcnta\m@ne
  243. \lst@FVConvertO@}%
  244. % Here, ...
  245. \gdef\lst@FVConvert@##1{%
  246. \ifx \@nil##1\else
  247. \if\relax\noexpand##1%
  248. \lst@lAddTo\lst@arg{\lst@OutputLostSpace\lst@PrintToken##1}%
  249. % ... actually here, we check for commands with arguments and set the
  250. % value of \@tempcnta as required.
  251. \def\lst@temp####1,##1####2,####3####4\relax{%
  252. \ifx####3\@empty \else \@tempcnta####2\relax \fi}%
  253. \expandafter\lst@temp\lst@FVcmdparams,##1\z@,\@empty\relax
  254. \else
  255. \lccode`\~=`##1\lowercase{\lst@lAddTo\lst@arg~}%
  256. \fi
  257. \expandafter\lst@FVConvertO@
  258. \fi}
  259. % Eventually we define user keys to adjust \lst@FVcmdparams. The base
  260. % set of commands and parameter numbers was provided by Denis Girou.
  261. \lst@Key{fvcmdparams}%
  262. % D.G. suggestion begin - 2002/05/31
  263. {\overlay\@ne}%
  264. % D.G. suggestion end
  265. {\def\lst@FVcmdparams{,##1}}%
  266. \lst@Key{morefvcmdparams}\relax{\lst@lAddTo\lst@FVcmdparams{,##1}}%
  267. }
  268. %
  269. % 5) Extend \lst@SaveToken to save \lst@lastother.
  270. \def\lst@SaveToken{%
  271. \global\let\lst@gthestyle\lst@thestyle
  272. \global\let\lst@glastother\lst@lastother
  273. \xdef\lst@RestoreToken{\noexpand\lst@token{\the\lst@token}%
  274. \noexpand\lst@length\the\lst@length\relax
  275. \noexpand\let\noexpand\lst@thestyle
  276. \noexpand\lst@gthestyle
  277. \noexpand\let\noexpand\lst@lastother
  278. \noexpand\lst@glastother}%
  279. }
  280. %
  281. % 6) Assign \lst@do@noligs to \do.
  282. \def\lst@SelectCharTable{%
  283. \lst@SelectStdCharTable
  284. \lst@ifactivechars
  285. \catcode9\active \catcode12\active \catcode13\active
  286. \@tempcnta=32\relax
  287. \@whilenum\@tempcnta<128\do
  288. {\catcode\@tempcnta\active\advance\@tempcnta\@ne}%
  289. \fi
  290. \lst@ifec \lst@DefEC \fi
  291. \let\do\lst@do@noligs \verbatim@nolig@list % modified
  292. \lsthk@SelectCharTable
  293. \lst@DeveloperSCT
  294. \ifx\lst@Backslash\relax\else
  295. \lst@LetSaveDef{"5C}\lsts@backslash\lst@Backslash
  296. \fi}
  297. % 4)+6) And we need correct versions of \lst@do@noligs[@].
  298. \def\lst@do@noligs#1{%
  299. \begingroup \lccode`\~=`#1\lowercase{\endgroup
  300. \lst@do@noligs@~}}
  301. \def\lst@do@noligs@#1{%
  302. \expandafter\expandafter\expandafter\def
  303. \expandafter\expandafter\expandafter#1%
  304. \expandafter\expandafter\expandafter{\expandafter\lst@NoLig#1}}
  305. %
  306. % 7) Make ^^M active.
  307. \def\lst@InputListing#1{%
  308. \begingroup
  309. \lsthk@PreSet \gdef\lst@intname{#1}%
  310. \expandafter\lstset\expandafter{\lst@set}%
  311. \lsthk@DisplayStyle
  312. \catcode\active=\active % added
  313. \lst@Init\relax \let\lst@gobble\z@
  314. \lst@SkipToFirst
  315. \lst@ifprint \def\lst@next{\input{#1}}%
  316. \else \let\lst@next\@empty \fi
  317. \lst@next
  318. \lst@DeInit
  319. \endgroup}
  320. %
  321. % 8) Replace \lst@Process{FormFeed|Tabulator}.
  322. \def\lst@ProcessFormFeedX{\lst@ProcessFormFeed}
  323. \def\lst@ProcessTabulatorX{\lst@ProcessTabulator}
  324. \def\lst@BOLGobble@#1{%
  325. \let\lst@next#1%
  326. \ifx \lst@next\relax\else
  327. \ifx \lst@next\lst@MProcessListing\else
  328. \ifx \lst@next\lst@ProcessFormFeedX\else
  329. \ifx \lst@next\lstenv@backslash
  330. \let\lst@next\lstenv@BOLGobble@@
  331. \else
  332. \let\lst@next\lst@BOLGobble@@
  333. \ifx #1\lst@ProcessTabulatorX
  334. \advance\@tempcnta-\lst@tabsize\relax
  335. \ifnum\@tempcnta<\z@
  336. \lst@length-\@tempcnta \lst@PreGotoTabStop
  337. \fi
  338. \else
  339. \advance\@tempcnta\m@ne
  340. \fi
  341. \fi \fi \fi \fi
  342. \lst@next}
  343. %
  344. % 10) Add some \@makeother to \lst@nfss@catcodes.
  345. \def\lst@nfss@catcodes{%
  346. \lst@makeletter
  347. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\relax
  348. \@makeother (\@makeother )\@makeother ,\@makeother :\@makeother &%
  349. \@makeother 0\@makeother 1\@makeother 2\@makeother 3\@makeother 4%
  350. \@makeother 5\@makeother 6\@makeother 7\@makeother 8\@makeother 9%
  351. \@makeother =\lsts@nfss@catcodes}
  352. %
  353. % 12) and 13) Deactivate \everypar and use normal baseline parameters.
  354. \lst@AddToHook{DeInit}{\everypar{}\normalbaselines}
  355. %
  356. % 14) Define \lst@entermodes.
  357. \let\lst@entermodes\@empty
  358. %
  359. % 16) Insert [ and ] in replacement text.
  360. \def\lst@Delim@option[#1]{\def\lst@arg{[#1]}\lst@Delim@delim}
  361. %
  362. % 17) Just empty `frame' and top, right, bottom, and left shape.
  363. \lst@AddToHook{TextStyle}
  364. {\let\lst@frame\@empty
  365. \let\lst@frametshape\@empty
  366. \let\lst@framershape\@empty
  367. \let\lst@framebshape\@empty
  368. \let\lst@framelshape\@empty}
  369. %
  370. % 18) Execute \lst@BeginKC and \lst@BeginKCS outside the two groups.
  371. % Modify third argument to \lst@BeginComment to work properly.
  372. \def\lstpatch@keywordcomments{%
  373. \gdef\lst@BeginKC{\aftergroup\aftergroup\aftergroup\lst@BeginKC@}%
  374. \gdef\lst@BeginKC@{%
  375. \lst@ResetToken
  376. \lst@BeginComment\lst@KCmode{{\lst@commentstyle}\lst@modetrue}\@empty}%
  377. \gdef\lst@BeginKCS{\aftergroup\aftergroup\aftergroup\lst@BeginKCS@}%
  378. \gdef\lst@BeginKCS@{%
  379. \lst@ResetToken
  380. \lst@BeginComment\lst@KCSmode{{\lst@commentstyle}\lst@modetrue}\@empty}%
  381. \gdef\lst@EndKC{\lst@SaveToken \lst@LeaveMode \lst@RestoreToken
  382. \let\lst@thestyle\lst@identifierstyle \lsthk@Output}% renew style selection
  383. }
  384. %
  385. % 19) Init \lst@directives.
  386. \def\lstpatch@directives{%
  387. \global\let\lst@directives\@empty}
  388. %
  389. % 20) Use new prefix for a family -- the now initialized \lst@directives
  390. % clashes with the default.
  391. \def\lstpatch@keywords{%
  392. \gdef\lst@ProvideFamily##1{%
  393. \@ifundefined{lstfam@##1\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi}%
  394. {\@namedef{lstfam@##1\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi}{}%
  395. \expandafter\expandafter\expandafter\lst@ProvideFamily@
  396. \csname\@lst @##1@data\endcsname
  397. {\ifnum\@tempcnta=\@ne\else \the\@tempcnta \fi}}%
  398. {}}%
  399. }
  400. % 21) Define \thelstnumber every listing via \def.
  401. \@namedef{lstpatch@021}{%
  402. \lst@AddToHook{Init}{\def\thelstnumber{\thelstlabel}}%
  403. }
  404. % 22) Reset the registers in PreInit hook
  405. \lst@AddToHook{PreInit}
  406. {\rightskip\z@ \leftskip\z@ \parfillskip\z@ plus 1fil}
  407. %
  408. % 23) Add \let\lst@lastother\@empty
  409. \lst@AddToHook{SelectCharTable}{%
  410. \lst@ifbstring
  411. \lst@CArgX \\\\\relax \lst@CDefX{}%
  412. {\lst@ProcessOther\lstum@backslash
  413. \lst@ProcessOther\lstum@backslash
  414. \let\lst@lastother\@empty}%
  415. {}%
  416. \fi}
  417. %
  418. % a) Just declare the option.
  419. \DeclareOption{final}{\let\lst@ifdraft\iffalse}
  420. %
  421. % c) Define contentstyle and use it.
  422. \def\lstpatch@html{%
  423. \lst@Key{contentstyle}{}{\def\lst@contentstyle{##1}}%
  424. \lst@AddToHook{Init}%
  425. {\ifx\lst@DefInside\@empty\else
  426. \let\lst@tagstyle\lst@identifierstyle
  427. \let\lst@identifierstyle\lst@contentstyle
  428. \fi}%
  429. \lst@AddToHook{Output}%
  430. {\ifnum\lst@mode=\lst@insidemode
  431. % 15) Check for keywordstyle.
  432. \ifx\lst@thestyle\lst@gkeywords@sty\else
  433. \lst@ifusekeysinside \let\lst@thestyle\lst@tagstyle
  434. \else \let\lst@thestyle\lst@gkeywords@sty \fi
  435. \fi\fi}%
  436. \lst@AddToHook{OutputOther}%
  437. {\lst@ifmode\else \ifnum\lst@mode=\lst@insidemode\else
  438. \ifx\lst@DefInside\@empty\else
  439. \let\lst@thestyle\lst@contentstyle
  440. \fi
  441. \fi\fi}%
  442. }
  443. %
  444. % d) Define key and adjust \lst@SkipOrPrintLabel.
  445. \def\lstpatch@labels{%
  446. \lst@Key{numberfirstline}{f}[t]{\lstKV@SetIf{##1}\lst@ifnumberfirstline}%
  447. \gdef\lst@numberfirstlinefalse{\let\lst@ifnumberfirstline\iffalse}
  448. \gdef\lst@SkipOrPrintLabel{%
  449. \ifnum\lst@skipnumbers=\z@
  450. \global\advance\lst@skipnumbers-\lst@stepnumber\relax
  451. \lst@PlaceNumber
  452. \lst@numberfirstlinefalse
  453. \else
  454. \lst@ifnumberfirstline
  455. \lst@PlaceNumber
  456. \lst@numberfirstlinefalse
  457. \fi
  458. \fi
  459. \global\advance\lst@skipnumbers\@ne}%
  460. }
  461. %%
  462. \endinput
  463. %%
  464. %% End of file `lstpatch.sty'.