lstpatch.sty 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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) 2000,2001 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. %% Permission is granted to change this file. You are not allowed to
  13. %% distribute any changed version of this file, neither under the same
  14. %% name nor under a different one.
  15. %%
  16. %% Send comments and ideas on the package, error reports and additional
  17. %% programming languages to <[email protected]>.
  18. %%
  19. %%
  20. %% This patch file does *not* include any experimental material I sent to
  21. %% various people. These people will have to copy and paste the definitions.
  22. %%
  23. %% This patch file will remove the following bugs from the listings package.
  24. %% Each item contains the bug finder with date of report and first bug fix
  25. %% version, a short description of the problem, and the reason for the bug
  26. %% in parenthesis.
  27. %%
  28. %% 1) Andreas Deininger, 2000/08/25, 0.21a
  29. %%
  30. %% `breaklines,first>1' leads to ``undefined control sequence'' error
  31. %% (\lst@breakshape undefined in this case)
  32. %%
  33. %% 2) Vespe Savikko, 2000/09/27, 0.21a (2000/11/02)
  34. %%
  35. %% stringstyle used also on previous other characters
  36. %% (missing \lst@PrintToken in \lst@BeginString)
  37. %%
  38. %% 3) Richard Hoefter, 2000/11/03, 0.21b (2000/11/04)
  39. %%
  40. %% no keyword detection in case of language=HTML,language=Java
  41. %% (missing deactivation of `keywordsinside' in hook `SetLanguage')
  42. %%
  43. %% 4) Vespe Savikko, 2000/11/06, 0.21c (2000/11/06)
  44. %%
  45. %% bad output of doc-strings if HTML and Python are loaded
  46. %% (missing group braces around mode argument in \lst@CommentB causes
  47. %% a number `0' appearing in the output)
  48. %%
  49. %% 5) Christian Gudrian, 2000/11/13, 0.21d (2000/11/16)
  50. %%
  51. %% \ref{lst:line} jumps to top of listing and not to the line
  52. %% (\refstepcounter not used on \c@lstlabel)
  53. %%
  54. %% 6) Dr. Jobst Hoffmann, 2000/11/17, 0.21e (2000/11/20)
  55. %%
  56. %% incompatibility with typehtml package
  57. %% (bad lccode of /)
  58. %%
  59. %% 7) Kalle Tuulos, 2001/01/14, 0.21f (2001/01/17)
  60. %%
  61. %% formfeed characters gobbles next output unit
  62. %% (\lst@newlines contains \lst@EOLUpdate, which calls \lst@ResetToken)
  63. %%
  64. %% 8) Adam Prugel-Bennett, 2001/02/19, 0.21g
  65. %%
  66. %% \abovecaptionskip undefined in slides.cls
  67. %%
  68. %% 9) Gabriel Tauro, 2001/04/18, 0.21g
  69. %%
  70. %% unexpected `)' if the character appears before first printed line
  71. %% (\lst@breakProcessOther is active)
  72. %%
  73. %% 10) Jens Schwarzer, 2001/05/29, 0.21g
  74. %%
  75. %% wrong line numbering of lstlisting with first>1
  76. %% (\lst@firstline not taken into accout in this case)
  77. %%
  78. %% 11) Jens Schwarzer, 2001/05/29, 0.21g (2001/06/21)
  79. %%
  80. %% caption and title font are not equal
  81. %% (\lst@maketitle not suitable for koma script)
  82. %%
  83. %% 12) Thorsten Vitt, 2001/06/25, 0.21h
  84. %%
  85. %% fancyhdr + listings crossing pages ==> ~ in header, not space
  86. %% (old problem with \output: explicitly redefine ~)
  87. %%
  88. %% 13) Martin Steffen, 2001/04/07, 0.21h
  89. %%
  90. %% mathescape drops following space
  91. %% (bad \lst@ifwhitespace)
  92. %%
  93. %% 14) Walter E. Brown, 2001/05/22, 0.21h (2001/06/27)
  94. %%
  95. %% pdftex 3.14159-14f warning: destination with the same identifier
  96. %% (bad default of \theHlstlabel)
  97. %%
  98. %% 15) Bradford Chamberlain, 2001/07/07, 0.21i
  99. %%
  100. %% otherkeywords={@,@^} does not work
  101. %% (argument treated as one long keyword)
  102. %%
  103. %% 16) GP Gores, 2001/07/11, 0.21i (2001/07/11)
  104. %%
  105. %% a) inserts \par after each \lstinline
  106. %% (\lst@Init has been modified, but I missed \lst@DeInit)
  107. %%
  108. %% 17) Carsten Heinz, 2001/07/16, 0.21j (2001/07/22)
  109. %%
  110. %% 16) makes first line of lstlisting textstyle
  111. %% (bad modification of \lst@DeInit)
  112. %%
  113. %%
  114. %% Moreover the following functionality is added.
  115. %%
  116. %% a) allow line breaks in \lstinline (experimental)
  117. %%
  118. %% b) everydisplay=<token string>
  119. %%
  120. %% c) nolol=<true|false> is mainly equivalent to the continue key, but
  121. %% it will also drop lol-entries for lstlisting in the next version
  122. %%
  123. %%
  124. \ProvidesFile{lstpatch}[2001/07/22 v0.21j (Carsten Heinz)]
  125. \def\lst@topatch{0.21}
  126. \ifx\lst@version\lst@topatch\else
  127. \typeout{^^J%
  128. ***^^J%
  129. *** Patch file `lstpatch.sty' for version \lst@topatch^^J%
  130. *** is not suitable for `listings.sty' version \lst@version.^^J%
  131. ***^^J
  132. *** Patch file not loaded.^^J%
  133. ***^^J}%
  134. \let\lst@topatch\lst@version
  135. \expandafter\endinput
  136. \fi
  137. %%
  138. %% 1) Just define \lst@breakshape.
  139. \gdef\lst@breakshape{%
  140. \ifodd \c@page -\lst@innerspread \else -\lst@outerspread \fi
  141. \linewidth}
  142. %%
  143. %% 2) Add \lst@PrintToken after \lst@TrackNewLines.
  144. \def\lstpatch@strings{%
  145. \gdef\lst@BeginString##1##2{%
  146. \lst@TrackNewLines \lst@PrintToken
  147. \lst@ifexstrings ##2\lst@PrintToken \fi
  148. \lst@EnterMode{##1}%
  149. {\lst@modetrue \let\lst@currstyle\lst@stringstyle}%
  150. \lst@ifexstrings\else ##2\lst@PrintToken \fi
  151. \lst@ifstringspaces
  152. \lst@keepspacestrue
  153. \let\lst@outputspace\lst@visiblespace
  154. \fi}
  155. }
  156. %%
  157. %% 3) Insert deactivation.
  158. \def\lstpatch@html{%
  159. \lst@AddToHook{SetLanguage}{\let\lst@DefInside\@empty}%
  160. }
  161. %%
  162. %% 4) Insert argument braces around ##5.
  163. \def\lstpatch@comments{%
  164. \gdef\lst@CommentB##1##2##3##4##5##6##7##8##9{%
  165. \lst@CDef##1##2{##3}##4%
  166. {##6}%
  167. {\let\lst@bnext\lst@CArgEmpty
  168. \lst@ifmode ##7\else
  169. ##8%
  170. \def\lst@bnext{\lst@BeginComment{##5}##9}%
  171. \fi
  172. \lst@bnext}%
  173. \@empty}%
  174. }
  175. %%
  176. %% 5) Use `lstlabel' with \refstepcounter.
  177. \def\lstpatch@labels{%
  178. \lst@AddToHook{EveryPar}
  179. {\global\advance\c@lstlabel\m@ne \refstepcounter{lstlabel}}%
  180. %%
  181. %% 14) Define appropriate \theHlstlabel.
  182. \AtBeginDocument{\def\theHlstlabel{\thelstlisting.\thelstlabel}}%
  183. }
  184. %%
  185. %% 6) Restore lccode.
  186. \lccode`\/=`\/
  187. %%
  188. %% 7) Don't add \lst@EOLUpdate to \lst@newlines. Since I don't know the
  189. %% reason for adding it a long time ago :-(, it's probably better to
  190. %% remove \lst@ResetToken (v0.22) from `InitVarsBOL' hook. Well, I'll
  191. %% just wait for other bug reports ...
  192. \def\lst@ProcessFormFeed{%
  193. \lst@PrintToken
  194. \ifx\lst@newlines\@empty
  195. \lst@EOLUpdate \lst@formfeed
  196. \else
  197. % \lst@lAddTo\lst@newlines{\lst@EOLUpdate \lst@formfeed}%
  198. \lst@lAddTo\lst@newlines{\lst@formfeed}%
  199. \fi
  200. \lst@whitespacetrue}
  201. %%
  202. %% 8) Allocate \abovecaptionskip and \belowcaptionskip if necessary.
  203. %% Additionally define \@makecaption (exact copy from report.cls).
  204. \@ifundefined{abovecaptionskip}
  205. {\newskip\abovecaptionskip
  206. \newskip\belowcaptionskip
  207. \long\def\@makecaption#1#2{%
  208. \vskip\abovecaptionskip
  209. \sbox\@tempboxa{#1: #2}%
  210. \ifdim \wd\@tempboxa >\hsize
  211. #1: #2\par
  212. \else
  213. \global \@minipagefalse
  214. \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  215. \fi
  216. \vskip\belowcaptionskip}%
  217. }{}
  218. %%
  219. %% 9) Also deactivate \lst@breakProcessOther.
  220. \def\lst@BeginDropInput#1{%
  221. \lst@EnterMode{#1}%
  222. {\lst@modetrue
  223. \let\lst@ProcessLetter\@gobble
  224. \let\lst@ProcessDigit\@gobble
  225. \let\lst@ProcessOther\@gobble
  226. \let\lst@breakProcessOther\@gobble
  227. \let\lst@ProcessSpace\@empty
  228. \let\lst@ProcessTabulator\@empty
  229. \let\lst@ProcessFormFeed\@empty}}
  230. %%
  231. %% 10) Replace \@tempcnta\@ne by \@tempcnta\lst@firstline.
  232. \def\lstpatch@labels{%
  233. \gdef\lst@SetFirstLabel{%
  234. \ifx\lst@firstlabel\@undefined
  235. \@tempcnta 0\csname lstno@\lst@intname\endcsname\relax
  236. \ifnum\@tempcnta=\z@ \@tempcnta\lst@firstline
  237. \else \lst@continuetrue \fi
  238. \advance\@tempcnta\lst@advancelabel
  239. \edef\lst@firstlabel{\the\@tempcnta\relax}%
  240. \fi}%
  241. }
  242. %%
  243. %% 11) Define \lst@maketitle in terms of \@makecaption. Note
  244. %% thet this need not to work for all packages and classes.
  245. %% The \let command here is especially for koma script.
  246. \def\lst@maketitle#1#2{%
  247. {\let\captionformat\@empty
  248. \@makecaption{}\lst@title}}
  249. %%
  250. %% 12) Redefine ~ in output routine.
  251. \lst@AddToHook{Init}
  252. {\let\lsts@OldOutput\lst@OldOutput
  253. \def\lst@OldOutput{\def~{\nobreakspace{}}%
  254. \lsts@OldOutput}%
  255. }
  256. %%
  257. %% 13) Use \lst@whitespacefalse at end of escape.
  258. \def\lstpatch@escape{%
  259. \lst@Key{escapeend}{}{\def\lst@escapeend{##1\lst@whitespacefalse}}%
  260. }
  261. %%
  262. %% 15) Make `other keywords' active iteratively.
  263. \def\lstpatch@keywords{%
  264. \gdef\lst@AddOtherKey##1,{%
  265. \ifx\relax##1\@empty\else
  266. \ifx\@empty##1\@empty\else
  267. \lst@MakeActive{##1}%
  268. \lst@lExtend\lst@otherkeywords{\expandafter,\lst@temp}%
  269. \fi
  270. \expandafter\lst@AddOtherKey
  271. \fi}%
  272. \lst@Key{otherkeywords}{}%
  273. {\let\lst@otherkeywords\@empty
  274. \lst@AddOtherKey##1,\relax,}
  275. }
  276. %%
  277. %% a) Remove \hbox in front of \bgroup and ...
  278. \renewcommand\lstinline[1][]{%
  279. \leavevmode\bgroup
  280. \def\lst@boxpos{b}\let\lst@ifflexible\iftrue
  281. \lsthk@PreSet\lstset{#1}%
  282. \lsthk@TextStyle \lst@Init\relax
  283. \everypar{}\let\lsthk@Endgroup\@empty
  284. \let\lst@newlines\@empty \let\lst@breakcurrindent\z@
  285. \lstinline@}
  286. %% 17) Add switch to distinguish text and display style listings.
  287. \lst@AddToHook{TextStyle}{\let\lst@iftextstyle\iftrue}
  288. \lst@AddToHook{DisplayStyle}{\let\lst@iftextstyle\iffalse}
  289. \let\lst@iftextstyle\iffalse
  290. % ... back to a):
  291. \def\lst@InputListing#1{%
  292. \begingroup
  293. \lsthk@PreSet \gdef\lst@intname{#1}%
  294. \expandafter\lstset\expandafter{\lst@set}%
  295. \lst@ifprint
  296. \par % inserted to switch to vmode
  297. \lst@Init\relax \let\lst@gobble\z@
  298. \lst@SkipToFirst \input{#1}\lst@DeInit
  299. \else
  300. \begin{center}%
  301. \footnotesize --- Listing of #1 has been skipped. ---
  302. \end{center}%
  303. \fi
  304. \endgroup}
  305. \def\lst@Init#1{%
  306. \begingroup
  307. \ifx\lst@float\relax\else
  308. \edef\@tempa{\noexpand\@float{lstlisting}[\lst@float]}%
  309. \expandafter\@tempa
  310. \fi
  311. \ifhmode\ifinner \lst@boxtrue \fi\fi
  312. \lst@ifbox
  313. \lsthk@BoxUnsafe
  314. \hbox to\z@\bgroup
  315. $\if t\lst@boxpos \vtop
  316. \else \if b\lst@boxpos \vbox
  317. \else \vcenter \fi\fi
  318. \bgroup
  319. \else
  320. %% 17) Don't check for vertical mode, use \lst@iftextstyle.
  321. \lst@iftextstyle\else
  322. \lst@EveryDisplay
  323. \par\penalty-50\relax
  324. \vspace\lst@aboveskip
  325. \fi
  326. \fi
  327. \normalbaselines
  328. \abovecaptionskip\lst@abovecaption\relax
  329. \belowcaptionskip\lst@belowcaption\relax
  330. \lst@MakeCaption t%
  331. \lsthk@PreInit \lsthk@Init
  332. \everypar{\lsthk@EveryLine\lsthk@EveryPar}%
  333. \lsthk@InitVars
  334. \lsthk@InitVarsBOL
  335. \lst@Let{13}\lst@MProcessListing
  336. \let\lst@Backslash#1%
  337. \lst@EnterMode{\lst@Pmode}{\lst@SelectCharTable}}
  338. %%
  339. %% 16) Adjust \lst@DeInit accordingly.
  340. \def\lst@DeInit{%
  341. \lst@PrintToken \lst@EOLUpdate
  342. \lst@RemoveNewLine\@empty
  343. \lst@RemoveNewLine{%
  344. \lst@ifshowlines
  345. \lst@TrackNewLines
  346. \else
  347. \setbox\@tempboxa\vbox{\lst@TrackNewLines}%
  348. \fi}%
  349. %% 17) Don't check for vertical mode, use \lst@iftextstyle.
  350. \lst@iftextstyle\else
  351. \par\removelastskip
  352. \fi
  353. \everypar{}\lsthk@ExitVars \lsthk@DeInit
  354. \lst@MakeCaption b%
  355. \lst@ifbox
  356. \egroup $\hss \egroup
  357. \vrule\@width\lst@maxwidth\@height\z@\@depth\z@
  358. \else
  359. %% check for vertical mode.
  360. \ifvmode
  361. \par\penalty-50\vspace\lst@belowskip
  362. \fi
  363. \fi
  364. \ifx\lst@float\relax\else
  365. \expandafter\end@float
  366. \fi
  367. \endgroup}
  368. %%
  369. %% b) Define key, the material is inserted above.
  370. \lst@Key{everydisplay}{}{\def\lst@EveryDisplay{#1}}
  371. %%
  372. %% c) New key sets value of continue key.
  373. \lst@Key{nolol}{false}[t]{\lstKV@SetIf{#1}\lst@ifnolol}
  374. \lst@AddToHook{PreInit}{\lst@ifcontinue\else \lst@SetIfContinue \fi}
  375. \def\lst@SetIfContinue{\let\lst@ifcontinue\lst@ifnolol}
  376. %%
  377. \endinput
  378. %%
  379. %% End of file `lstpatch.sty'.