Debian Codegraph @

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

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX New Tabular Facilities
4 %
5 % Synopsis: This module contains all the facilities for producing
6 % tabular material. This is the second major version.
7 %
8 % Author: Paul C. Anagnostopoulos
9 % Created: 30 April 2001
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Tabular Block
17 % ------- -----
18
19
20 \let \tabularcomptext = \relax
21 \let \tabulardepth = \relax
22 \let \tabularnumber = \relax
23
24
25 \defineblock{\tabular}{\endtabular}{\false}{}
26
27 %~obsolete-block tabular Type
28 % \abovepenalty = integer
29 % \aboveskip = glue
30 % \belowpenalty = integer
31 % \belowskip = glue
32 % \bodyfont = {...}
33 % \columngutter = glue
34 % \colheadaboveskip = glue
35 % \colheadbelowskip = glue
36 % \colheadfont = {...}
37 % \cutinheadfont = {...}
38 % \setflag \hastoprule = \false
39 % \interrowskip = glue
40 % \leftindent = glue
41 % \parhang = dimen
42 % \parrag = dimen
43 % \rightindent = glue
44 % \rulecolwidth = dimen
45 % \sectionheadaboveskip = glue
46 % \sectionheadbelowskip = glue
47 % \sideheadfont = {...}
48 % \spannerheadfont = {...}
49 % \spannerruleaboveskip = dimen
50 % \spannerrulebelowskip = dimen
51 % \spannerrulecolor = {color}
52 % \spannerruleheight = dimen
53 % \style = {...}
54 % \tabbottomruleaboveskip = dimen
55 % \tabheadrulebelowskip = dimen
56 % \def \tabnoteformat ##1{...}
57 % \tabrulecolor = {color}
58 % \tabruleheight = dimen
59 % \width = dimen
60 %~end
61
62 \defineskip{\colheadaboveskip}{0pt}
63 %%%\defineskip{\colheadbelowskip}{0pt}
64 %%%\definetoks{\colheadfont}
65 \definetoks{\cutinheadfont}
66 %%%\definedimen{\rulecolwidth}{0pt}
67 \defineskip{\sectionheadaboveskip}{0pt}
68 \defineskip{\sectionheadbelowskip}{0pt}
69 %%%\definetoks{\sideheadfont}
70 %%%\definetoks{\spannerheadfont}
71 %%%\defineskip{\spannerruleaboveskip}{0pt}
72 %%%\defineskip{\spannerrulebelowskip}{0pt}
73 %%%\definetoks{\spannerrulecolor}
74 %%%\definedimen{\spannerruleheight}{0pt}
75 %%%\definedimen{\tabbottomruleaboveskip}{0pt}
76 %%%\definedimen{\tabheadrulebelowskip}{0pt}
77 %%%\definetoks{\tabrulecolor}
78 %%%\definedimen{\tabruleheight}{0pt}
79
80
81 %%%\definecount{\tabcolcount}{0} % Number of columns in table.
82
83 \definetoks{\ztabspacetoks} % Special row for vertical spacing.
84 %%%\definebox{\zrowstrut} % Strut for table rows.
85 %%%\definebox{\zparcelltopstrut} % Strut for first line of par cell.
86 %%%\definebox{\zparcellbotstrut} % Strut for last line of par cell.
87
88
89 \def \tabular #1#2{% {type}{template}
90 \endgraf
91 \beginblockscope{tabular}%
92 \global\increment \tabulardepth
93 \abovepenalty = \breakgood %~default hard
94 \belowpenalty = \breakbetter %~default hard
95 \setflag \hastoprule = \false %~default soft
96 \parhang = 0pt %~default soft
97 \spannerrulecolor = {black}% %~default soft
98 \style = {top/head/bottom rules}% %~default soft
99 \tabrulecolor = {black}% %~default soft
100 \processdesign{\tabular}{#1}%
101 \global\increment \tabularnumber
102 \iffalse{\fi % Analyze the template with
103 \tabcolcount = 0 % master counter > 0 to hide
104 \ztabspacetoks = {}% % \set and &.
105 \zchecktabcols #2&\zmark
106 \let \set = \span
107 \iffalse}\fi
108 \tabularformat
109 \offinterlineskip
110 \everycr = {}%
111 \defineatsigncommand @A{\adjustcolrule}%
112 \defineatsigncommand @C{\nointerrowskip}%
113 \defineatsigncommand @N{\nocolrule}%
114 \defineatsigncommand @S{\skipabovespannerrule}%
115 \defineatsigncommand @T{\skipbelowspannerrule}%
116 \tabskip = \leftskip
117 \halign \if \dimneqlp{\width}{\naturalwidth}to \width \fi \bgroup
118 #2\tabskip = \rightskip\cr}
119
120 \def \endtabular {%
121 \egroup % \halign
122 \if \posp{\prevdepth}% % Does the last line have a strut?
123 \kern -.5\interrowskip % To eliminate row strut depth.
124 \prevdepth = \dp\strutbox
125 \else
126 \prevdepth = \tabruleheight
127 \fi
128 \futurelet\nexttoken \zendtabular}
129
130 \def \zendtabular {%
131 \endtabularformat
132 \global\decrement \tabulardepth
133 \endblockscope{tabular}%
134 \parnext}
135
136 \def \tabularformat {%
137 \the\bodyfont
138 \calculate \tdimena = {\interrowskip,/,2,+,\ht\strutbox}%
139 \calculate \tdimenb = {\interrowskip,/,2,+,\dp\strutbox}%
140 \setbox \zrowstrut = \hbox{\vrule width 0pt
141 height \tdimena depth \tdimenb}%
142 \setbox \zparcelltopstrut = \hbox{\vrule width 0pt
143 height \tdimena depth 0pt}%
144 \setbox \zparcellbotstrut = \hbox{\vrule width 0pt
145 height 0pt depth \tdimenb}%
146 \bbskipabove{\abovepenalty}{\aboveskip}%
147 \fakepar % This fakes an empty paragraph
148 \hbox{}% % so the \bbskipabove works.
149 \nobreak
150 \vskip \if \hastoprule -\tabruleheight \else -\ht\zrowstrut \fi
151 \alterindentation{\leftindent}{\rightindent}}
152
153 \def \endtabularformat{%
154 \bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}}
155
156 \def \zchecktabcols #1#2#3&#4\zmark{%
157 \if \notp{\tokeqlp{#1}{\set}}%
158 \error{misset}{A tabular column template must begin with \string\set}%
159 \fi
160 \if \posp{\tabcolcount}%
161 \ztabspacetoks = \expandafter{\the\ztabspacetoks &}%
162 \fi
163 \if \notp{\tokeqlp{#2}{\rulecol}}%
164 \ztabspacetoks = \expandafter{\the\ztabspacetoks \omit \ztabspacestrut}%
165 \fi
166 \increment \tabcolcount
167 \if \notp{\emptyargp{#4}}\zchecktabcols #4\zmark \fi}
168
169 % Template Facilities
170 % -------- ----------
171
172
173 % The following macros are used to construct the tabular template.
174 % They are all used with the \set macro.
175
176 \def \centercol {%
177 \hfil ##\rowstrut \hfil \tabskip=\columngutter}
178
179 \def \centernumbercol #1{% {template}
180 \hfil \znumcell{#1}{##}\rowstrut \hfil \tabskip=\columngutter}
181
182 \let \gutter = \tabskip
183
184 \def \customcol #1{% {template}
185 #1\rowstrut \tabskip=\columngutter}
186
187 \def \customrulecol #1#2{% {color}{width}
188 \color{#1}%
189 \vrule width #2 ##%
190 \endcolor \tabskip=\columngutter}
191
192 \def \emptycol #1{% {width}
193 ##\rowstrut \hspace{#1}\tabskip=\columngutter}
194
195 \def \leftcol {%
196 ##\rowstrut \hfil \tabskip=\columngutter}
197
198 \def \leftnumbercol #1{% {template}
199 \znumcell{#1}{##}\rowstrut \hfil \tabskip=\columngutter}
200
201 \def \parcol #1{% {width}
202 \vtop{\zpushvcontext
203 \zinitparcell{#1}{\parhang}%
204 \unhcopy \zparcelltopstrut ##%
205 \if \hmodep \unhcopy \zparcellbotstrut \par \fi
206 \zpopvcontext}%
207 \tabskip=\columngutter}
208
209 \def \rightcol {%
210 \hfil ##\rowstrut \tabskip=\columngutter}
211
212 \def \rightnumbercol #1{% {template}
213 \hfil \znumcell{#1}{##}\rowstrut \tabskip=\columngutter}
214
215 \def \rulecol {%
216 \color{\the\tabrulecolor}%
217 \vrule width \rulecolwidth ##%
218 \endcolor \tabskip=\columngutter}
219
220 % Cell Facilities
221 % ---- ----------
222
223
224 % The following macros help with tabular entries (cells).
225
226 \def \0{\phantom{0}}
227
228 \def \centercell #1{% {text}
229 \omit
230 \hfil #1\rowstrut \hfil}
231
232 \def \centerhead #1{% {heading}
233 \centercell{\the\colheadfont #1}}
234
235 \def \centernumbercell #1#2{% {template}{text}
236 \omit
237 \hfil \znumcell{#1}{#2}\rowstrut \hfil}
238
239 \def \cutinhead #1{% {heading}
240 \skipabovetabsection
241 \multispan{\tabcolcount}%
242 \leftcell{\the\cutinheadfont #1}\cr
243 \skipbelowtabsection}
244
245 \zremovePlaindef \hideskip
246 \defineskip{\hideskip}{-1000pt plus 1fill}
247
248 \def \hidewidth {\hskip \hideskip}
249
250 \def \leftcell #1{% {text}
251 \omit
252 #1\rowstrut \hfil}
253
254 \def \lefthead #1{% {heading}
255 \leftcell{\the\colheadfont #1}}
256
257 \def \leftnumbercell #1#2{% {template}{text}
258 \omit
259 \znumcell{#1}{#2}\rowstrut \hfil}
260
261 \def \multispan #1{% {columns}
262 \omit
263 \tcounta = #1%
264 \loop \ifnum \tcounta > 1 \zspan \repeat
265 \let \omit = \relax % In case the next thing is a \leftcell or whatever.
266 \ignorespaces}
267
268 \def \zspan {\span\omit \decrement \tcounta}
269
270 \def \parcell #1#2{% {width}{text}
271 \omit
272 \vtop{\zpushvcontext
273 \zinitparcell{#1}{\parhang}%
274 \unhcopy \zparcelltopstrut #2%
275 \if \hmodep \unhcopy \zparcellbotstrut \par \fi
276 \zpopvcontext}}
277
278 \def \rightcell #1{% {text}
279 \omit
280 \hfil #1\rowstrut}
281
282 \def \righthead #1{% {heading}
283 \rightcell{\the\colheadfont #1}}
284
285 \def \rightnumbercell #1#2{% {template}{text}
286 \omit
287 \hfil \znumcell{#1}{#2}\rowstrut}
288
289 \def \rowstrut {%
290 \unhcopy \zrowstrut}
291
292 \def \sidehead #1{% {heading}
293 \leftcell{\the\sideheadfont #1}}
294
295 \def \spannerhead #1#2{% {columns}{heading}
296 \multispan{#1}%
297 \centercell{\the\spannerheadfont #2}}
298
299 \def \tabnote #1{% {note-mark}
300 {\tabnoteformat{#1}}}
301
302 \def \znumcell #1#2{% {template}{text}
303 \if \emptyargp{#2}%
304 \relax
305 \else
306 \znumcella{#1}{#2}%
307 \fi}
308
309 \def \znumcella #1#2{% {template}{text}
310 {\ztoksa = {}\ztoksb = {}%
311 \setflag \znumpt = \false
312 \znumcellb #1\zmark
313 \setbox\zboxa = \hbox{\the\ztoksa}%
314 \tdimena = \wd\zboxa
315 \setbox\zboxa = \hbox{\the\ztoksb}%
316 \tdimenb = \wd\zboxa
317 \setflag \ztempt = \znumpt
318 \ztoksa = {}\ztoksb = {}%
319 \setflag \znumpt = \false
320 \znumcellb #2\zmark
321 \if \ztempt % Template had a decimal point.
322 \if \znumpt
323 \hbox to \tdimena{\hss \the\ztoksa}%
324 \the\decimalpoint
325 \hbox to \tdimenb{\the\ztoksb \hss}%
326 \else
327 \setbox\zboxa = \hbox{\the\decimalpoint}%
328 \hbox to \tdimena{\hss \the\ztoksa}%
329 \kern \wd\zboxa \kern \tdimenb
330 \fi
331 \else % Template had no decimal point.
332 \if \znumpt
333 \error{celldecpt}{Tabular template did not specify a decimal point}%
334 \else
335 \hbox to \tdimena{\hss \the\ztoksa}%
336 \fi
337 \fi}}
338
339 \def \znumcellb #1#2\zmark{% t1 trest \zmark
340 \if \codeeqlp{\noexpand#1}{\the\decimalpoint}%
341 \setflag \znumpt = \true
342 \else
343 \if \znumpt
344 \ztoksb = \expandafter{\the\ztoksb #1}%
345 \else
346 \ztoksa = \expandafter{\the\ztoksa #1}%
347 \fi
348 \fi
349 \if \emptyargp{#2}%
350 \let \znext = \relax
351 \else
352 \def \znext {\znumcellb #2\zmark}%
353 \fi
354 \znext}
355
356 % Rule Facilities
357 % ---- ----------
358
359
360 \def \adjustcolrule #1,#2,#3;{% width,height,depth;
361 \if \notp{\emptyargp{#1}}width #1pt\fi
362 \if \notp{\emptyargp{#2}}height #2pt\fi
363 \if \notp{\emptyargp{#3}}depth #3pt\fi\relax}
364
365 \def \custompartialtabrule #1#2#3{% {color}{thickness}{columns}
366 \multispan{#3}%
367 \color{#1}%
368 \ruleleaders{\hrule height #2 depth 0pt}%
369 \endcolor}
370
371 \def \customspannerrule #1#2#3{% {color}{thickness}{columns}
372 \multispan{#3}%
373 \rowstrut
374 \color{#1}%
375 \ruleleaders{\hrule height #2 depth 0pt}%
376 \endcolor}
377
378 \def \customtabrule #1#2{% {color}{thickness}
379 \multispan{\tabcolcount}%
380 \color{#1}%
381 \ruleleaders{\hrule height #2 depth 0pt}%
382 \endcolor\cr}
383
384 \def \nocolrule {%
385 width 0pt }
386
387 \def \partialtabrule #1{% {columns}
388 \custompartialtabrule{\the\tabrulecolor}{\tabruleheight}{#1}}
389
390 \def \spannerrule #1{% {columns}
391 \customspannerrule{\the\spannerrulecolor}{\spannerruleheight}{#1}}
392
393 \def \tabbottomrule {%
394 \tabbbskipaboverule{\tabbottomruleaboveskip}%
395 \tabrule}
396
397 \def \tabheadrule {%
398 \tabbbskipaboverule{\colheadbelowskip}%
399 \tabrule
400 \tabbbskipbelowrule{\tabheadrulebelowskip}}
401
402 \def \tabrule {%
403 \customtabrule{\the\tabrulecolor}{\tabruleheight}}
404
405 \def \tabtoprule {%
406 \tabrule
407 \tabbbskipbelowrule{\colheadaboveskip}}
408
409 % Spacing Facilities
410 % ------- ----------
411
412
413 \definedimen{\zskipamount}{0pt}
414
415
416 \def \nointerrowskip {%
417 \tabvspace{-\interrowskip}}
418
419 \def \skipabovecolhead {%
420 \tabbbskip{\colheadaboveskip}}
421
422 \def \skipbelowcolhead {%
423 \tabbbskip{\colheadbelowskip}}
424
425 \def \skipabovespannerrule {%
426 \tabbbskip{\spannerruleaboveskip}}
427
428 \def \skipbelowspannerrule {%
429 \tabbbskip{\spannerrulebelowskip}}
430
431 \def \skipabovetabsection {%
432 \tabbbskip{\sectionheadaboveskip}}
433
434 \def \skipbelowtabsection {%
435 \tabbbskip{\sectionheadbelowskip}}
436
437 \def \tabbbskip #1{%
438 \noalign{%
439 \calculate \zskipamount = {#1,-,\dp\zrowstrut,-,\ht\zrowstrut}%
440 \ztabvspace{\zskipamount}}%
441 \the\ztabspacetoks\cr}
442
443 \def \tabbbskipaboverule #1{%
444 \noalign{%
445 \calculate \zskipamount = {#1,-,\dp\zrowstrut,-,\tabruleheight}%
446 \ztabvspace{\zskipamount}}%
447 \the\ztabspacetoks\cr}
448
449 \def \tabbbskipbelowrule #1{%
450 \noalign{%
451 \calculate \zskipamount = {#1,-,\ht\zrowstrut,-,\tabruleheight}%
452 \ztabvspace{\zskipamount}}%
453 \the\ztabspacetoks\cr}
454
455 \def \tabvspace #1{%
456 \noalign{\ztabvspace{#1}}%
457 \the\ztabspacetoks\cr}
458
459 \def \ztabvspace #1{%
460 \if \dimnegp{#1}%
461 \vskip #1\relax
462 \global\zskipamount = 0pt
463 \else
464 \global\zskipamount = #1%
465 \fi}
466
467 \def \ztabspacestrut {%
468 \vrule width 0pt height 0pt depth \zskipamount\relax}
469
470 % Inter-Row Facilities
471 % --------- ----------
472
473
474 \def \adjusttab #1{%
475 \if \notp{\vmodep}%
476 \error{badrowcmd}{The \string\adjusttab command cannot be used
477 in a table row}%
478 \fi
479 \noalign{#1}}
480
481
482 % Utilities
483 % ---------
484
485
486 \let \completerow = \cr
487
488 \def \ialign {\everycr = {}\tabskip = 0pt \halign}
489
490 \def \oalign #1{% {row...}
491 \ensurepar
492 \vtop{\baselineskip = 0pt
493 \lineskip = .25ex
494 \ialign{##\cr #1\crcr}}}
495
496 \def \ooalign {%
497 \lineskiplimit = -\maxdimen
498 \oalign}
499
500 \def \ozalign {%
501 \lineskiplimit = 0pt\relax
502 \oalign}
503
504 \def \zinitparcell #1#2{% {width}{hang}
505 \baselineskip = \normalbaselineskip
506 \lineskiplimit = 0pt \lineskip = 0pt
507 \setindentation{0pt}{0pt}%
508 \settextwidth{#1}%
509 \setparrag{\parrag}%
510 \leftskip = #2
511 \parindent = -#2
512 \parfillskip = \normalparfillskip}