| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Tabular Facilities |
| 4 |
% |
| 5 |
% Synopsis: This module contains all the facilities for producing |
| 6 |
% tabular material. |
| 7 |
% |
| 8 |
% Author: Paul C. Anagnostopoulos |
| 9 |
% Created: 1990 |
| 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 |
% \setflag \allowbreaks = boolean |
| 31 |
% \belowpenalty = integer |
| 32 |
% \belowskip = glue |
| 33 |
% \bodyfont = {...} |
| 34 |
% \colheadaboveskip = glue |
| 35 |
% \colheadbelowskip = glue |
| 36 |
% \colheadfont = {...} |
| 37 |
% \colsubheadfont = {...} |
| 38 |
% \columngutter = glue |
| 39 |
% \cutinheadaboveskip = glue |
| 40 |
% \cutinheadbelowskip = glue |
| 41 |
% \cutinheadfont = {...} |
| 42 |
% \interrowskip = glue |
| 43 |
% \leftindent = glue |
| 44 |
% \parhang = dimen |
| 45 |
% \parrag = dimen |
| 46 |
% \rightindent = glue |
| 47 |
% \rulecolwidth = dimen |
| 48 |
% \spannerheadfont = {...} |
| 49 |
% \spannerruleaboveskip = dimen |
| 50 |
% \spannerrulebelowskip = dimen |
| 51 |
% \spannerruleheight = dimen |
| 52 |
% \def \tabnoteformat ##1{...} |
| 53 |
% \tabrulecolor = {color}% |
| 54 |
% \tabruleheight = dimen |
| 55 |
% \width = dimen |
| 56 |
%~end |
| 57 |
|
| 58 |
\defineskip{\colheadaboveskip}{0pt} |
| 59 |
\let \headaboveskip = \colheadaboveskip |
| 60 |
\let \headbelowskip = \colheadbelowskip |
| 61 |
\definetoks{\colsubheadfont} |
| 62 |
\defineskip{\cutinheadaboveskip}{0pt} |
| 63 |
\defineskip{\cutinheadbelowskip}{0pt} |
| 64 |
\definetoks{\cutinheadfont} |
| 65 |
|
| 66 |
|
| 67 |
\definecount{\tabularcolcount}{0} % Number of columns in table. |
| 68 |
\definebox{\rowstrutbox} % Strut for table rows. |
| 69 |
|
| 70 |
|
| 71 |
\def \tabular #1#2{% {type}{template} |
| 72 |
\endgraf |
| 73 |
\beginblockscope{tabular}% |
| 74 |
\global\increment \tabulardepth |
| 75 |
\abovepenalty = \breakgood %~default hard |
| 76 |
\belowpenalty = \breakbetter %~default hard |
| 77 |
\tabrulecolor = {black}% %~default soft |
| 78 |
\processdesign{\tabular}{#1}% |
| 79 |
\global\increment \tabularnumber |
| 80 |
\iffalse{\fi % Must be done with master |
| 81 |
\tabularcolcount = 0 % counter > 0, to hide inner |
| 82 |
\ztabcols #2&\zmark % \set and &. |
| 83 |
\let \set = \span |
| 84 |
\iffalse}\fi |
| 85 |
\tabularformat |
| 86 |
\fakepar |
| 87 |
\nointerlineskip % We assume this below. |
| 88 |
\if \notp{\allowbreaks}\vtop \fi \bgroup |
| 89 |
\offinterlineskip |
| 90 |
\everycr = {}% |
| 91 |
\tabskip = \leftskip |
| 92 |
\halign \if \dimneqlp{\width}{\naturalwidth}to \width \fi \bgroup |
| 93 |
#2\tabskip = \rightskip \cr} |
| 94 |
|
| 95 |
\def \endtabular {% |
| 96 |
\crcr |
| 97 |
\egroup % \halign |
| 98 |
\if \posp{\prevdepth}\kern -\interrowskip \fi % If last line has strut. |
| 99 |
\egroup % \vtop |
| 100 |
\prevdepth = \dp\strutbox % So row strut depth won't shine thru. |
| 101 |
\futurelet\nexttoken \zendtabular} |
| 102 |
|
| 103 |
\def \zendtabular {% |
| 104 |
\endtabularformat |
| 105 |
\global\decrement \tabulardepth |
| 106 |
\endblockscope{tabular}% |
| 107 |
\parnext} |
| 108 |
|
| 109 |
\def \tabularformat {% |
| 110 |
\endgraf |
| 111 |
\the\bodyfont |
| 112 |
\tdimena = \dp\strutbox |
| 113 |
\advance \tdimena by \interrowskip |
| 114 |
\setbox \rowstrutbox = \hbox{\vrule height \ht\strutbox depth \tdimena |
| 115 |
width 0pt}% |
| 116 |
\advance \aboveskip by \baselineskip % Compensate for absence |
| 117 |
\advance \aboveskip by -\prevdepth % of interlineskip above |
| 118 |
\advance \aboveskip by -\ht\rowstrutbox % first row of tabular. |
| 119 |
\bbskipabove{\abovepenalty}{\aboveskip}% |
| 120 |
\alterindentation{\leftindent}{\rightindent}} |
| 121 |
|
| 122 |
\def \endtabularformat{% |
| 123 |
\bbskipbelowblockpar{\nexttoken}{\belowpenalty}{\belowskip}} |
| 124 |
|
| 125 |
\def \ztabcols #1\zmark{% |
| 126 |
\increment \tabularcolcount |
| 127 |
\if \notp{\emptyargp{#2}}\ztabcols #2\zmark \fi} |
| 128 |
|
| 129 |
% Template Facilities |
| 130 |
% -------- ---------- |
| 131 |
|
| 132 |
|
| 133 |
% The following macros are used to construct the tabular template. |
| 134 |
% They are all used with the \set macro. |
| 135 |
|
| 136 |
\def \centercol {% |
| 137 |
\hfil ##\rowstrut \hfil \tabskip=\columngutter} |
| 138 |
|
| 139 |
\def \centernumbercol #1{% {template} |
| 140 |
\hfil \znumcell{#1}{##}\rowstrut \hfil \tabskip=\columngutter} |
| 141 |
|
| 142 |
\let \colgutter = \tabskip |
| 143 |
|
| 144 |
\def \customcol #1#2{% {left}{right} |
| 145 |
#1\relax##\rowstrut #2\relax \tabskip=\columngutter} |
| 146 |
|
| 147 |
\def \customrulecol #1{% {width} |
| 148 |
\color{\the\tabrulecolor}% |
| 149 |
\vrule width #1 ##% |
| 150 |
\endcolor \tabskip=\columngutter} |
| 151 |
|
| 152 |
\def \emptycol #1{% {width} |
| 153 |
##\rowstrut \hspace{#1}\tabskip=\columngutter} |
| 154 |
|
| 155 |
\def \leftcol {% |
| 156 |
##\rowstrut \hfil \tabskip=\columngutter} |
| 157 |
|
| 158 |
\def \leftnumbercol #1{% {template} |
| 159 |
\znumcell{#1}{##}\rowstrut \hfil \tabskip=\columngutter} |
| 160 |
|
| 161 |
\def \parcol #1{% {width} |
| 162 |
\vtop{\zpushvcontext |
| 163 |
\zinitparcell{#1}{\parhang}% |
| 164 |
\strut ##% |
| 165 |
\if \hmodep \rowstrut \par \fi |
| 166 |
\zpopvcontext}% |
| 167 |
\tabskip=\columngutter} |
| 168 |
|
| 169 |
\def \rightcol {% |
| 170 |
\hfil ##\rowstrut \tabskip=\columngutter} |
| 171 |
|
| 172 |
\def \rightnumbercol #1{% {template} |
| 173 |
\hfil \znumcell{#1}{##}\rowstrut \tabskip=\columngutter} |
| 174 |
|
| 175 |
\def \rulecol {% |
| 176 |
\color{\the\tabrulecolor}% |
| 177 |
\vrule width \rulecolwidth ##% |
| 178 |
\endcolor \tabskip=\columngutter} |
| 179 |
|
| 180 |
% Cell Facilities |
| 181 |
% ---- ---------- |
| 182 |
|
| 183 |
|
| 184 |
% The following macros help with tabular entries (cells). |
| 185 |
|
| 186 |
\def \0{\phantom{0}} |
| 187 |
|
| 188 |
\def \centercell #1{% {text} |
| 189 |
\omit |
| 190 |
\hfil #1\rowstrut \hfil} |
| 191 |
|
| 192 |
\def \centerhead #1{% {heading} |
| 193 |
\centercell{\the\colheadfont #1}} |
| 194 |
|
| 195 |
\def \centernumbercell #1#2{% {template}{text} |
| 196 |
\omit |
| 197 |
\hfil \znumcell{#1}{#2}\rowstrut \hfil} |
| 198 |
|
| 199 |
\def \centersubhead #1{% {heading} |
| 200 |
\centercell{\the\colsubheadfont #1}} |
| 201 |
|
| 202 |
\def \customspannerrule #1#2{% {columns}{height} |
| 203 |
\multispan{#1}% |
| 204 |
\rowstrut |
| 205 |
\ruleleaders{\hrule height #2 depth 0pt}} |
| 206 |
|
| 207 |
\def \customspannerruleabut #1#2{% {columns}{height} |
| 208 |
\multispan{#1}% |
| 209 |
\ruleleaders{\hrule height #2 depth 0pt}} |
| 210 |
|
| 211 |
\def \cutinhead #1{% {heading} |
| 212 |
\multispan{\tabularcolcount}% |
| 213 |
\leftcell{\the\cutinheadfont #1}} |
| 214 |
|
| 215 |
\def \cutinpar #1#2{% {width}{text} |
| 216 |
\multispan{\tabularcolcount}% |
| 217 |
\parhang = 0pt \parcell{#1}{#2}} |
| 218 |
|
| 219 |
\zremovePlaindef \hideskip |
| 220 |
\defineskip{\hideskip}{-1000pt plus 1fill} |
| 221 |
|
| 222 |
\def \hidewidth {\hskip \hideskip} |
| 223 |
|
| 224 |
\def \leftcell #1{% {text} |
| 225 |
\omit |
| 226 |
#1\rowstrut \hfil} |
| 227 |
|
| 228 |
\def \lefthead #1{% {heading} |
| 229 |
\leftcell{\the\colheadfont #1}} |
| 230 |
|
| 231 |
\def \leftnumbercell #1#2{% {template}{text} |
| 232 |
\omit |
| 233 |
\znumcell{#1}{#2}\rowstrut \hfil} |
| 234 |
|
| 235 |
\def \leftsubhead #1{% {heading} |
| 236 |
\leftcell{\the\colsubheadfont #1}} |
| 237 |
|
| 238 |
\def \multispan #1{% {columns} |
| 239 |
\omit |
| 240 |
\tcounta =#1\relax |
| 241 |
\loop \ifnum \tcounta > 1 \zspan \repeat |
| 242 |
\let \omit = \relax % In case the next thing is a \leftcell or whatever. |
| 243 |
\ignorespaces} |
| 244 |
|
| 245 |
\def \zspan{\span\omit \decrement \tcounta} |
| 246 |
|
| 247 |
\def \nocolrule {% |
| 248 |
width 0pt } |
| 249 |
|
| 250 |
\def \parcell #1#2{% {width}{text} |
| 251 |
\omit |
| 252 |
\vtop{\zpushvcontext |
| 253 |
\zinitparcell{#1}{\parhang}% |
| 254 |
\strut #2% |
| 255 |
\if \hmodep \rowstrut \par \fi |
| 256 |
\zpopvcontext}} |
| 257 |
|
| 258 |
\def \rightcell #1{% {text} |
| 259 |
\omit |
| 260 |
\hfil #1\rowstrut} |
| 261 |
|
| 262 |
\def \righthead #1{% {heading} |
| 263 |
\rightcell{\the\colheadfont #1}} |
| 264 |
|
| 265 |
\def \rightnumbercell #1#2{% {template}{text} |
| 266 |
\omit |
| 267 |
\hfil \znumcell{#1}{#2}\rowstrut} |
| 268 |
|
| 269 |
\def \rightsubhead #1{% {heading} |
| 270 |
\rightcell{\the\colsubheadfont #1}} |
| 271 |
|
| 272 |
\def \rowstrut {\unhcopy \rowstrutbox} |
| 273 |
|
| 274 |
\def \spannerhead #1#2{% {columns}{heading} |
| 275 |
\multispan{#1}% |
| 276 |
\centercell{\the\spannerheadfont #2}} |
| 277 |
|
| 278 |
\def \spannerrule #1{% {columns} |
| 279 |
\multispan{#1}% |
| 280 |
\rowstrut |
| 281 |
\ruleleaders{\hrule height \spannerruleheight depth 0pt}} |
| 282 |
|
| 283 |
\def \spannerruleabut #1{% {columns} |
| 284 |
\multispan{#1}% |
| 285 |
\ruleleaders{\hrule height \spannerruleheight depth 0pt}} |
| 286 |
|
| 287 |
\def \spannerruleabutbelow #1{% {columns} |
| 288 |
\multispan{#1}% |
| 289 |
\vrule height \ht\rowstrutbox depth 0pt width 0pt\relax |
| 290 |
\ruleleaders{\hrule height \spannerruleheight depth 0pt}} |
| 291 |
|
| 292 |
\def \tabnote #1{% {note-mark} |
| 293 |
{\tabnoteformat{#1}}} |
| 294 |
|
| 295 |
\def \znumcell #1#2{% {template}{text} |
| 296 |
\if \emptyargp{#2}% |
| 297 |
\relax |
| 298 |
\else |
| 299 |
\znumcella{#1}{#2}% |
| 300 |
\fi} |
| 301 |
|
| 302 |
\def \znumcella #1#2{% {template}{text} |
| 303 |
{\ztoksa = {}\ztoksb = {}% |
| 304 |
\setflag \znumpt = \false |
| 305 |
\znumcellb #1\zmark |
| 306 |
\setbox\zboxa = \hbox{\the\ztoksa}% |
| 307 |
\tdimena = \wd\zboxa |
| 308 |
\setbox\zboxa = \hbox{\the\ztoksb}% |
| 309 |
\tdimenb = \wd\zboxa |
| 310 |
\setflag \ztempt = \znumpt |
| 311 |
\ztoksa = {}\ztoksb = {}% |
| 312 |
\setflag \znumpt = \false |
| 313 |
\znumcellb #2\zmark |
| 314 |
\if \ztempt % Template had a decimal point. |
| 315 |
\if \znumpt |
| 316 |
\hbox to \tdimena{\hss \the\ztoksa}% |
| 317 |
\the\decimalpoint |
| 318 |
\hbox to \tdimenb{\the\ztoksb \hss}% |
| 319 |
\else |
| 320 |
\setbox\zboxa = \hbox{\the\decimalpoint}% |
| 321 |
\hbox to \tdimena{\hss \the\ztoksa}% |
| 322 |
\kern \wd\zboxa \kern \tdimenb |
| 323 |
\fi |
| 324 |
\else % Template had no decimal point. |
| 325 |
\if \znumpt |
| 326 |
\error{celldecpt}{Tabular template did not specify a decimal point}% |
| 327 |
\else |
| 328 |
\hbox to \tdimena{\hss \the\ztoksa}% |
| 329 |
\fi |
| 330 |
\fi}} |
| 331 |
|
| 332 |
\def \znumcellb #1#2\zmark{% t1 trest \zmark |
| 333 |
\if \codeeqlp{\noexpand#1}{\the\decimalpoint}% |
| 334 |
\setflag \znumpt = \true |
| 335 |
\else |
| 336 |
\if \znumpt |
| 337 |
\ztoksb = \expandafter{\the\ztoksb #1}% |
| 338 |
\else |
| 339 |
\ztoksa = \expandafter{\the\ztoksa #1}% |
| 340 |
\fi |
| 341 |
\fi |
| 342 |
\if \emptyargp{#2}% |
| 343 |
\let \znext = \relax |
| 344 |
\else |
| 345 |
\def \znext {\znumcellb #2\zmark}% |
| 346 |
\fi |
| 347 |
\znext} |
| 348 |
|
| 349 |
% Inter-Row Facilities |
| 350 |
% --------- ---------- |
| 351 |
|
| 352 |
|
| 353 |
% The following macros perform various actions in between rows. |
| 354 |
|
| 355 |
\def \adjusttab #1{% |
| 356 |
\if \notp{\vmodep}% |
| 357 |
\error{badrowcmd}{The \string\adjusttab command cannot be used in a table row}% |
| 358 |
\fi |
| 359 |
\noalign{#1}} |
| 360 |
|
| 361 |
\def \customtabrule #1{% {height} |
| 362 |
\multispan{\tabularcolcount}% |
| 363 |
\rowstrut |
| 364 |
\color{\the\tabrulecolor}% |
| 365 |
\ruleleaders{\hrule height #1 depth 0pt}% |
| 366 |
\endcolor |
| 367 |
\cr} |
| 368 |
|
| 369 |
\def \customtabruleabut #1{% |
| 370 |
\multispan{\tabularcolcount}% |
| 371 |
\color{\the\tabrulecolor}% |
| 372 |
\ruleleaders{\hrule height #1 depth 0pt}% |
| 373 |
\endcolor |
| 374 |
\cr} |
| 375 |
|
| 376 |
\def \customtabruleabutbelow #1{% |
| 377 |
\multispan{\tabularcolcount}% |
| 378 |
\vrule height \ht\rowstrutbox depth 0pt width 0pt\relax |
| 379 |
\color{\the\tabrulecolor}% |
| 380 |
\ruleleaders{\hrule height #1 depth 0pt}% |
| 381 |
\endcolor |
| 382 |
\cr} |
| 383 |
|
| 384 |
\def \nointerrowskip {\tabvspace{-\interrowskip}} |
| 385 |
|
| 386 |
\def \skipabovecolhead {% |
| 387 |
\tabbbskip{\colheadaboveskip}} |
| 388 |
|
| 389 |
\def \skipbelowcolhead {% |
| 390 |
\tabbbskip{\colheadbelowskip}} |
| 391 |
|
| 392 |
\def \skipabovespannerrule {% |
| 393 |
\tabbbskip{\spannerruleaboveskip}} |
| 394 |
|
| 395 |
\def \skipbelowspannerrule {% |
| 396 |
\tabbbskip{\spannerrulebelowskip}} |
| 397 |
|
| 398 |
\def \skipabovecutinhead {% |
| 399 |
\tabbbskip{\cutinheadaboveskip}} |
| 400 |
|
| 401 |
\def \skipbelowcutinhead {% |
| 402 |
\tabbbskip{\cutinheadbelowskip}} |
| 403 |
|
| 404 |
\def \tabbbskip #1{% {glue} |
| 405 |
\adjusttab{\zskipa = #1\relax |
| 406 |
\advance \zskipa by -\ht\rowstrutbox |
| 407 |
\advance \zskipa by -\dp\rowstrutbox |
| 408 |
\vskip \zskipa}} |
| 409 |
|
| 410 |
\def \tabrule {% |
| 411 |
\multispan{\tabularcolcount}% |
| 412 |
\rowstrut |
| 413 |
\color{\the\tabrulecolor}% |
| 414 |
\ruleleaders{\hrule height \tabruleheight depth 0pt}% |
| 415 |
\endcolor |
| 416 |
\cr} |
| 417 |
|
| 418 |
\def \tabruleabut {% |
| 419 |
\multispan{\tabularcolcount}% |
| 420 |
\color{\the\tabrulecolor}% |
| 421 |
\ruleleaders{\hrule height \tabruleheight depth 0pt}% |
| 422 |
\endcolor |
| 423 |
\cr} |
| 424 |
|
| 425 |
\def \tabruleabutbelow {% |
| 426 |
\multispan{\tabularcolcount}% |
| 427 |
\vrule height \ht\rowstrutbox depth 0pt width 0pt\relax |
| 428 |
\color{\the\tabrulecolor}% |
| 429 |
\ruleleaders{\hrule height \tabruleheight depth 0pt}% |
| 430 |
\endcolor |
| 431 |
\cr} |
| 432 |
|
| 433 |
\def \tabvspace #1{\adjusttab{\vskip #1}}% {glue} |
| 434 |
|
| 435 |
% Alignment Utilities |
| 436 |
% --------- --------- |
| 437 |
|
| 438 |
|
| 439 |
\let \completerow = \cr |
| 440 |
|
| 441 |
\def \ialign {\everycr = {}\tabskip = 0pt \halign} |
| 442 |
|
| 443 |
\def \oalign #1{% {row...} |
| 444 |
\ensurepar |
| 445 |
\vtop{\baselineskip = 0pt |
| 446 |
\lineskip = .25ex |
| 447 |
\ialign{##\cr #1\crcr}}} |
| 448 |
|
| 449 |
\def \ooalign {% |
| 450 |
\lineskiplimit = -\maxdimen |
| 451 |
\oalign} |
| 452 |
|
| 453 |
\def \ozalign {% |
| 454 |
\lineskiplimit = 0pt\relax |
| 455 |
\oalign} |
| 456 |
|
| 457 |
\def \zinitparcell #1#2{% {width}{hang} |
| 458 |
\baselineskip = \normalbaselineskip |
| 459 |
\lineskiplimit = 0pt \lineskip = 0pt |
| 460 |
\setindentation{0pt}{0pt}% |
| 461 |
\settextwidth{#1}% |
| 462 |
\setparrag{\parrag}% |
| 463 |
\leftskip = #2 |
| 464 |
\parindent = -#2 |
| 465 |
\parfillskip = \normalparfillskip} |