]> mj.ucw.cz Git - ucwmac.git/blob - ucw-verb.tex
Introduced \footfont
[ucwmac.git] / ucw-verb.tex
1 % The UCW Macro Collection: Verbatim environment
2 % Written by Martin Mares <mj@ucw.cz> in 2010 and placed into public domain
3 % -------------------------------------------------------------------------
4
5 % We'll use internal macros of plain TeX
6 \catcode`@=11
7
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}
11
12 % Typesetting of one verbatim word: |word| (enable by \inlineverbon)
13
14 % Set if spaces should be rendered as "bath-tub" glyphs
15 \newif\ifshowspaces
16 \showspacesfalse
17
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}
21
22 {\catcode`'=13
23 \catcode``=13
24 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
25
26 {\obeyspaces
27 \global\chardef\sp@ce=32
28 \gdef\showsp@ces{\ifshowspaces\let =\sp@ce\fi}
29 \global\let =\ }
30
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}
35 }
36
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
43
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
50
51 \verbstartskip=3pt plus 1pt minus 0.3pt
52 \verbendskip=\verbstartskip
53 \verbinterlineskip=0pt
54 \verbemptylineskip=5pt plus 2pt
55 \verbleftskip=0in
56 \verbrightskip=0pt plus 1fil
57
58 % Can be re-defined to customize the verbatim environment
59 \def\verblocaldefs{}
60
61 % Size of a single tab
62 \newcount\verbtabsize
63 \verbtabsize=8
64
65 \newdimen\v@rbspace
66 \newdimen\t@b
67 \newdimen\t@bwidth
68
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.
71 \def\verbship{%
72         \ifdim\wd0>0pt
73                 \ifdim\v@rbspace>0pt
74                         \penalty-100
75                         \vskip\v@rbspace
76                 \else
77                         \ifdim\v@rbspace=0pt
78                                 \vskip\verbinterlineskip
79                         \fi
80                 \fi
81                 \line{\hskip\verbleftskip \box0 \hskip\verbrightskip}
82                 \v@rbspace=0pt
83         \else
84                 \advance\v@rbspace by \verbemptylineskip
85         \fi
86 }
87
88 \newcount\verbcnt
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}
92
93 \def\v@rbparams{%
94         \setverb@tim
95         \raggedbottom
96         \verbcnt=0
97         \v@rbspace=-1000pt
98         \catcode124=12
99         \vskip\verbstartskip
100         \let\par=\endb@x
101         \obeylines
102 }
103
104 \def\startb@x{\setbox0=\hbox\bgroup}
105 \def\endb@x{\egroup\verbship\startb@x}
106
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{}}%
113 }}
114
115 {
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%
119 ]]
120
121 % Input file verbatim
122
123 \def\verbinput#1{\begingroup\v@rbparams\verblocaldefs\setupt@bs\startb@x\input #1 \egroup\endgroup}
124
125 % Let's hide all internal macros
126 \catcode`@=12