1 % The UCW Macro Collection: Verbatim environment
2 % Written by Martin Mares <mj@ucw.cz> in 2010 and placed into public domain
3 % -------------------------------------------------------------------------
5 % We'll use internal macros of plain TeX
8 % New \frenchspacing, which doesn't leave unwanted spaces in text.
9 \def\frenchsp@cing{\sfcode`\.\@m \sfcode`\?\@m \sfcode`\!\@m%
10 \sfcode`\:\@m \sfcode`\;\@m \sfcode`\,\@m}
12 % Typesetting of one verbatim word: |word| (enable by \inlineverbon)
14 % Set if spaces should be rendered as "bath-tub" glyphs
18 \def\make@ther#1{\catcode`#1=12\relax}
19 \def\setverb@tim{\tt\frenchsp@cing\catcode`\`=13\catcode`\'=13\n@ligs%
20 \let\do=\make@ther\dospecials\obeyspaces\showsp@ces}
24 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
27 \global\chardef\sp@ce=32
28 \gdef\showsp@ces{\ifshowspaces\let =\sp@ce\fi}
31 {\catcode124=\active % Make | active
32 \gdef\ttst@rt{\begingroup\setverb@tim\let|=\endgroup}
33 \gdef\inlineverbon{\catcode124=\active\let|=\ttst@rt}
34 \gdef\inlineverboff{\catcode124=12}
37 % Typesetting of verbatim blocks:
38 % - the block is enclosed in balanced {}'s
39 % - leading and trailing empty lines are ignored
40 % - all other empty lines are converted to \verbemptylineskip's
41 % - tabs are interpreted (one tab stop per \verbtabsize columns)
42 % - \showspacestrue works here, too, but it does not apply to tabs
44 \newskip\verbstartskip % vskip before \verbatim
45 \newskip\verbendskip % vskip after \verbatim
46 \newskip\verbinterlineskip % between adjacent non-empty lines
47 \newskip\verbemptylineskip % instead of every empty line
48 \newskip\verbleftskip % left and right margin
49 \newskip\verbrightskip
51 \verbstartskip=3pt plus 1pt minus 0.3pt
52 \verbendskip=\verbstartskip
53 \verbinterlineskip=0pt
54 \verbemptylineskip=5pt plus 2pt
56 \verbrightskip=0pt plus 1fil
58 % Can be re-defined to customize the verbatim environment
61 % Size of a single tab
69 % When a complete line is assembled in \box0, \verbship is called to add it
70 % to the main vertical list. You can override it to get e.g. line numbering.
78 \vskip\verbinterlineskip
81 \line{\hskip\verbleftskip \box0 \hskip\verbrightskip}
84 \advance\v@rbspace by \verbemptylineskip
89 \def\v@rbend{\par\egroup\endgroup\vskip\verbendskip}
90 \def\v@rbl{\ifnum\verbcnt>0\{\fi\global\advance\verbcnt by 1\relax}
91 \def\v@rbr{\ifnum\verbcnt>1\}\else\v@rbend\fi\global\advance\verbcnt by -1\relax}
104 \def\startb@x{\setbox0=\hbox\bgroup}
105 \def\endb@x{\egroup\verbship\startb@x}
107 {\catcode`\^^I=\active
108 \gdef\setupt@bs{\catcode`\^^I=\active
109 \setbox0=\hbox{\ }\t@bwidth=\wd0\multiply\t@bwidth by \verbtabsize
110 \def^^I{\egroup\t@b=\wd0\divide\t@b by \t@bwidth%
111 \multiply\t@b by \t@bwidth%
112 \advance\t@b by \t@bwidth\advance\t@b by -\wd0\startb@x\box0\hbox to \t@b{}}%
116 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
117 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
118 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs\setupt@bs\startb@x%
121 % Input file verbatim
123 \def\verbinput#1{\begingroup\v@rbparams\verblocaldefs\setupt@bs\startb@x\input #1 \egroup\endgroup}
125 % Let's hide all internal macros