Debian Codegraph @

texmf-dist/tex/plain/zztex/zztabbing.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Tabbing Facilities
4 %
5 % Synopsis: This module contains the definition of the block that is
6 % used to format text with tab stops.
7 %
8 % Authors: Paul C. Anagnostopoulos
9 % Created: 27 May 2016
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Tabbing Block
17 % ------- -----
18
19
20 \defineblock{\tabbing}{\endtabbing}{\false}{}
21 \resetinvcontext{\tabbing}
22
23 %~block tabbing Type
24 % \abovepenalty = integer % Penalty above text.
25 % \aboveskip = glue % Space b/b above text.
26 % \setflag \autocallout = boolean % Automatically number lines?
27 % \def \beginformat {...} % Beginning of text formatter.
28 % \belowpenalty = integer % Penalty below text.
29 % \belowskip = glue % Space b/b below text.
30 % \bodyfont = {font} % Body font.
31 % \def \calloutformat ##1{...} % Callout formatter.
32 % \calloutnumber = integer % Number of first callout.
33 % \def \callouttext {...} % Callout text or \arg.
34 % \defaulttabwidth = dimen % Default repeating tab width.
35 % \def \endformat {...} % End of text formatter.
36 % \leftindent = glue % Left indentation.
37 % \rightindent = glue % Right indentation.
38 % \tabbinggapskip = glue % Standard tabbing gap.
39 % \textcolor = {...} % Color of text.
40 % \width = dimen % Line width.
41 %~end
42
43 \defineskip{\tabbinggapskip}{0pt}
44
45 \def \tabbing #1{% {type}
46 \blockcantbein{\tabbing}{\tabbing}%
47 \beginblockscope{tabbing}%
48 \global\increment \tabbingdepth
49 \abovepenalty = \breakgood %~default hard
50 \setflag \autocallout = \false %~default soft
51 \def \beginformat {}% %~default soft
52 \belowpenalty = \breakgood %~default hard
53 \calloutnumber = 1 %~default with
54 \def \callouttext {\number\calloutnumber}% %~default soft
55 \defaulttabwidth = \mindimen %~default soft
56 \def \endformat {}% %~default soft
57 \tabbinggapskip = \enclosingbaselineskip %~default soft
58 \textcolor = {}% %~default soft
59 \parindent = 0pt
60 \parrag = 0pt
61 \parskip = 0pt
62 \processdesign{\tabbing}{#1}%
63 \global\increment \tabbingnumber
64 \tabbingformat
65 \def \zarg {\arg}%
66 \if \tokeqlp{\callouttext}{\zarg}%
67 \defineatsigncommand @##{\ztbngatcallout}%
68 \else
69 \defineatsigncommand @##{\ztbngatcallout{\callouttext}}%
70 \fi
71 \if \emptytoksp{\textcolor}% % Must have a group around \ztbnginit.
72 \bgroup
73 \else
74 \color{\the\textcolor}%
75 \fi
76 \ztbnginit
77 \ztbngstartline}
78
79 \def \endtabbing {%
80 \ztbngfinal
81 \if \emptytoksp{\textcolor}%
82 \egroup % \tabbing group
83 \else
84 \endcolor
85 \fi
86 \futurelet\nexttoken \zendtabbing}
87
88 \def \zendtabbing {%
89 \endtabbingformat
90 \global\decrement \tabbingdepth
91 \endblockscope{tabbing}%
92 \parnext}
93
94 \def \tabbingformat {%
95 \endgraf
96 \the\bodyfont
97 \bbskipabove{\abovepenalty}{\aboveskip}%
98 \alterindentation{\leftindent}{\rightindent}%
99 \settextwidth{\width}%
100 \beginformat}
101
102 \def \endtabbingformat {%
103 \endformat
104 \bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}}
105
106 %~ Use this command in between lines in a |\tabbing| block to
107 %~ perform a vertical adjustment between those two lines. For example,
108 %~
109 %~ \adjusttabbing{\fullpagebreak}
110
111 \long\def \adjusttabbing #1{% {commands}
112 \ztbngadjust{#1}}
113
114 % Initialize and Finalize
115 % ---------- --- --------
116
117
118 \definecount{\ztbngstopcount}{0}
119 \definecount{\ztbngstopindex}{0}
120
121 \definebox{\ztbngline}
122 \definebox{\ztbngfragment}
123
124
125 \def \ztbnginit {%
126 \let \par = \ztbngshouldntbepar
127 \def \nl {\ztbngfinishline{\false}}%
128 \defineatsigncommand @.{\ztbngatsetstop}%
129 \defineatsigncommand @>{\ztbngattab}%
130 \defineatsigncommand @C{\ztbngatclear}%
131 \defineatsigncommand @D{\ztbngatdiscard}%
132 \ztbngsetdefaultstops{\defaulttabwidth}}
133
134 \def \ztbngsetdefaultstops #1{% {width}
135 \global\ztbngstopcount = 0
136 \def \ztbngstop {0pt}%
137 \if \dimgtrp{#1}{0pt}%
138 \tdimena = 0pt
139 \loop
140 \global\increment \ztbngstopcount
141 \advance \tdimena by #1\relax
142 \withname\edef {\ztbngstop\romannumeral\ztbngstopcount}{\the\tdimena}%
143 \if \dimlssp{\tdimena}{\hsize}%
144 \repeat
145 \fi}
146
147 \def \ztbngfinal {%
148 \ztbngfinishline{\true}}
149
150 % Build Lines
151 % ----- -----
152
153
154 \def \ztbngstartline {%
155 \ztbngstopindex = 0
156 \setbox\ztbngline = \hbox{}%
157 \global\setflag \ztbngdiscardp = \false
158 \settaginfo{\number\calloutnumber}{???title???}%
159 \ztbngstartfragment}
160
161 \def \ztbngstartfragment {%
162 \setbox \ztbngfragment = \hbox\bgroup
163 \ignorespaces}
164
165 \def \ztbngfinishfragment {%
166 \egroup % \ztbngfragment box
167 \setbox\ztbngline = \hbox{%
168 \unhbox\ztbngline
169 \tdimena = \name{\ztbngstop\romannumeral\ztbngstopindex}%
170 \hskip \tdimena
171 \tdimenb = \hsize
172 \advance \tdimenb by -\tdimena
173 \hbox to \tdimenb{\copy\ztbngfragment \hfil}%
174 \hskip -\tdimenb
175 \hskip -\tdimena}}
176
177 \def \ztbngfinishline #1{% {end-of-block?}
178 \ztbngfinishfragment
179 \if \notp{\ztbngdiscardp}%
180 \if \orp{\posp{\ztbngstopindex}}{\dimposp{\wd\ztbngfragment}}%
181 \noindent
182 \if \autocallout
183 \llap{\calloutformat{\the\calloutnumber}}%
184 \increment \calloutnumber
185 \fi
186 \box\ztbngline
187 \endgraf
188 \else\if \notp{#1}%
189 \vspace{\tabbinggapskip}%
190 \fi\fi
191 \fi
192 \if #1\let \znext = \relax \else \let \znext = \ztbngstartline \fi
193 \znext}
194
195 % At-sign Commands
196 % ------- --------
197
198
199 % @#{callout}text...
200
201 \def \ztbngatcallout #1{% {callout}
202 \ztbngfinishfragment
203 \if \andp{\zerop{\ztbngstopindex}}{\dimzerop{\wd\ztbngfragment}}
204 \setbox\ztbngfragment = \hbox\bgroup
205 \llap{\calloutformat{#1}}%
206 \ztbngfinishfragment
207 \else
208 \error{badtabcallout}{Callout command (\noexpand@##) must appear
209 at the beginning of the line}%
210 \fi
211 \increment \calloutnumber
212 \ztbngstartfragment}
213
214 % [email protected] text...
215
216 \def \ztbngatsetstop {%
217 \ztbngfinishfragment
218 \tdimena = \name{\ztbngstop\romannumeral\ztbngstopindex}%
219 \advance \tdimena by \wd\ztbngfragment
220 \increment \ztbngstopindex
221 \if \gtrp{\ztbngstopindex}{\ztbngstopcount}%
222 \withname\edef {\ztbngstop\romannumeral\ztbngstopindex}{\the\tdimena}%
223 \increment \ztbngstopcount
224 \else
225 \error{badtabstop}{There is already a tab stop}%
226 \fi
227 \ztbngstartfragment}
228
229 % text@>more text...
230
231 \def \ztbngattab {%
232 \ztbngfinishfragment
233 \if \lssp{\ztbngstopindex}{\ztbngstopcount}%
234 \increment \ztbngstopindex
235 \else
236 \warning{toomanytabs}{Too many tabs on line; extra tabs ignored}%
237 \fi
238 \ztbngstartfragment}
239
240 % @Ctext...\nl
241
242 \def \ztbngatclear {%
243 \if \zerop{\ztbngstopindex}%
244 \global\ztbngstopcount = 0\relax
245 \else
246 \error{badtabclear}{Tabs must be cleared at the beginning of the line}%
247 \fi}
248
249 % text@D\nl
250
251 \def \ztbngatdiscard {%
252 \global\setflag \ztbngdiscardp = \true \relax}
253
254 % Adjustment
255 % ----------
256
257
258 \long\def \ztbngadjust #1{% {commands}
259 \ztbngfinishfragment
260 \if \andp{\zerop{\ztbngstopindex}}{\dimzerop{\wd\ztbngfragment}}
261 #1%
262 \else
263 \error{badtabadjust}{The \noexpand\adjusttabbing command must appear
264 in between lines}%
265 \fi
266 \ztbngstartfragment}