1 % The UCW Macro Collection: Verbatim environments
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 text with a given delimiter:
38 % - usage: \verb%verbatim text%
39 % - the delimiter is the first character after \verb
40 % - remember that writing (for example) \verbz with meaning \verb
41 % with the delimiter 'z' is possible only if \catcode`z is not 11
43 \def\verb{\relax\def\sv@rb##1{\uccode`~=`##1%
44 \uppercase{\catcode`~13\global\let~\endgroup}}%
45 \begingroup\setverb@tim\sv@rb}
47 % Typesetting of verbatim blocks:
48 % - the block is enclosed in balanced {}'s
49 % - leading and trailing empty lines are ignored
50 % - all other empty lines are converted to \verbemptylineskip's
51 % - tabs are interpreted (one tab stop per \verbtabsize columns)
52 % - \showspacestrue works here, too, but it does not apply to tabs
54 \newskip\verbstartskip % vskip before \verbatim
55 \newskip\verbendskip % vskip after \verbatim
56 \newskip\verbinterlineskip % between adjacent non-empty lines
57 \newskip\verbemptylineskip % instead of every empty line
58 \newskip\verbleftskip % left and right margin
59 \newskip\verbrightskip
61 \verbstartskip=3pt plus 1pt minus 0.3pt
62 \verbendskip=\verbstartskip
63 \verbinterlineskip=0pt
64 \verbemptylineskip=5pt plus 2pt
66 \verbrightskip=0pt plus 1fil
68 % Can be re-defined to customize the verbatim environment
71 % Size of a single tab
79 % When a complete line is assembled in \box0, \verbship is called to add it
80 % to the main vertical list. You can override it to get e.g. line numbering.
88 \vskip\verbinterlineskip
91 \line{\hskip\verbleftskip \box0 \hskip\verbrightskip}
94 \advance\v@rbspace by \verbemptylineskip
99 \def\v@rbend{\par\egroup\endgroup\vskip\verbendskip}
100 \def\v@rbl{\ifnum\verbcnt>0\{\fi\global\advance\verbcnt by 1\relax}
101 \def\v@rbr{\ifnum\verbcnt>1\}\else\v@rbend\fi\global\advance\verbcnt by -1\relax}
114 \def\startb@x{\setbox0=\hbox\bgroup}
115 \def\endb@x{\egroup\verbship\startb@x}
117 {\catcode`\^^I=\active
118 \gdef\setupt@bs{\catcode`\^^I=\active
119 \setbox0=\hbox{\ }\t@bwidth=\wd0\multiply\t@bwidth by \verbtabsize
120 \def^^I{\egroup\t@b=\wd0\divide\t@b by \t@bwidth%
121 \multiply\t@b by \t@bwidth%
122 \advance\t@b by \t@bwidth\advance\t@b by -\wd0\startb@x\box0\hbox to \t@b{}}%
126 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
127 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
128 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs\setupt@bs\startb@x%
131 % Input file verbatim
133 \def\verbinput#1{\begingroup\v@rbparams\verblocaldefs\setupt@bs\startb@x\input #1 \egroup\endgroup}
135 % Let's hide all internal macros