| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl \table {Macros for tables <2024-11-21>} % preloaded in format |
| 4 |
|
| 5 |
\_doc ----------------------------- |
| 6 |
The result of the \`\table``{<declaration>}{<data>}` macro is inserted into |
| 7 |
\`\_tablebox`. You can change default value if you want by |
| 8 |
`\let\_tablebox=\vtop` or `\let\_tablebox=\relax`. |
| 9 |
\_cod ----------------------------- |
| 10 |
|
| 11 |
\_let\_tablebox=\_vbox |
| 12 |
|
| 13 |
\_doc ----------------------------- |
| 14 |
We save the `to<size>` or `pxto<size>` to `#1` and \`\_tableW` sets the |
| 15 |
`to<size>` to the \`\_tablew` macro. |
| 16 |
If `pxto<size>` is used then `\_tablew` is empty and `\_tmpdim` includes |
| 17 |
given <size>. The `\_ifpxto` returns true in this case. |
| 18 |
|
| 19 |
The `\table` continues by reading `{<declaration>}` in the \^`\_tableA` macro. |
| 20 |
Catcodes (for example the `|` character) have to be normal when reading |
| 21 |
`\table` parameters. This is the reason why we use `\catcodetable` here. |
| 22 |
\_cod ----------------------------- |
| 23 |
|
| 24 |
\_newifi \_ifpxto |
| 25 |
\_def\_table#1#{\_tablebox\_bgroup \_tableW#1\_empty\_fin |
| 26 |
\_bgroup \_catcodetable\_optexcatcodes \_tableA} |
| 27 |
\_def\_tableW#1#2\_fin{\_pxtofalse |
| 28 |
\_ifx#1\_empty \_def\_tablew{}\_else |
| 29 |
\_ifx#1p \_def\_tablew{}\_tableWx#2\_fin \_else \_def\_tablew{#1#2}\_fi\_fi} |
| 30 |
\_def\_tableWx xto#1\_fin{\_tmpdim=#1\_relax \_pxtotrue} |
| 31 |
\_public \table ; |
| 32 |
|
| 33 |
\_doc ----------------------------- |
| 34 |
The \^`\tablinespace` is implemented by enlarging given \^`\tabstrut` |
| 35 |
by desired dimension (height and depth too) and by setting |
| 36 |
`\_lineskip=-2\_tablinespace`. Normal table rows (where no `\hrule` is |
| 37 |
between them) have normal baseline distance.\nl |
| 38 |
The \`\_tableA``{<declaration>}` macro scans the `<declaration>` by |
| 39 |
`\_scantabdata#1\_relax` and continues by processing `{<data>}` by \^`\_tableB`. |
| 40 |
\_cod ----------------------------- |
| 41 |
|
| 42 |
\_def\_tableA#1{\_egroup |
| 43 |
\_the\_thistable \_global\_thistable={}% |
| 44 |
\_ea\_ifx\_ea^\_the\_tabstrut^\_setbox\_tstrutbox=\_null |
| 45 |
\_else \_setbox\_tstrutbox=\_hbox{\_the\_tabstrut}% |
| 46 |
\_setbox\_tstrutbox=\_hbox{\_vrule width\_zo |
| 47 |
height\_dimexpr\_ht\_tstrutbox+\_tablinespace |
| 48 |
depth\_dimexpr\_dp\_tstrutbox+\_tablinespace}% |
| 49 |
\_offinterlineskip |
| 50 |
\_lineskip=-2\_tablinespace |
| 51 |
\_fi |
| 52 |
\_colnum=0 \_let\_addtabitem=\_addtabitemx |
| 53 |
\_def\_tmpa{}\_tabdata={\_colnum1\_relax}\_scantabdata#1\_relax |
| 54 |
\_the\_everytable \_tableB |
| 55 |
} |
| 56 |
|
| 57 |
\_doc ----------------------------- |
| 58 |
The \`\_tableB` saves `<data>` to `\_tmpb`. The `#1` parameter is |
| 59 |
re-scanned in order to set potential `#` characters inside it as others. |
| 60 |
This is needed because of `\gdef\_tmpb` and next \^`\replstring`s. |
| 61 |
They prefix each macro \^`\crl` (etc.) by `\_crcr`. See \^`\_tabreplstrings`. |
| 62 |
The whole `\_tableB` macro is hidden in `{...}` in order to |
| 63 |
there may be `\table` in `\table` and we want to manipulate with |
| 64 |
`&` and `\cr` as with normal tokens in the `\_tabreplstrings`, not as |
| 65 |
the item delimiters of an outer `\table`. |
| 66 |
|
| 67 |
The `\tabskip` value is saved for places between columns |
| 68 |
into the \`\_tabskipmid` macro. Then it runs |
| 69 |
\begtt \catcode`\<=13 |
| 70 |
\tabskip=\tabskipl \halign{<converted declaration>\tabskip=\tabskipr \cr <data>\crcr} |
| 71 |
\endtt |
| 72 |
This sets the desired boundary values of `\tabskip`. The |
| 73 |
\"between-columns" values are set as `\tabskip=`\^`\_tabskipmid` in the |
| 74 |
`<converted declaration>` immediately after each column declarator. |
| 75 |
|
| 76 |
If `pxto` keyword was used, then we set the virtual unit \^`\tsize` to |
| 77 |
`-\hsize` first. Then the first attempt of the table is created in box 0. |
| 78 |
All columns where `p{..\tsize}` is used, are created as empty in this first |
| 79 |
pass. So, the `\wd0` is the width of all other columns. |
| 80 |
The \^`\_tsizesum` includes the sum of \^`\tsize`'s in `\hsize` units |
| 81 |
after first pass. The desired table width is stored in the `\_tmpdim`, so |
| 82 |
`\_tmpdim-\_wd0` is the rest which have to be filled by \^`\tsize`s. |
| 83 |
Then the \^`\tsize` is re-calculated and the real table is |
| 84 |
printed by `\halign` in the second pass. |
| 85 |
|
| 86 |
If no `pxto` keyword was used, then we print the table using `\halign` |
| 87 |
directly. The \^`\_tablew` macro is nonempty if the `to` keyword was used. |
| 88 |
|
| 89 |
The <data> are re-tokenized by `\_scantextokens` in order to be more |
| 90 |
robust to catcode changing inside the <data>. But inline verbatim cannot |
| 91 |
work in special cases here like \code{`\{`} for example. |
| 92 |
\_cod ----------------------------- |
| 93 |
|
| 94 |
\_long\_def\_tableB #1{% |
| 95 |
{{\_catcode`\#=12 % see OpTeX trick 0117: |
| 96 |
\_directlua{tex.sprint(-1,"\_luaescapestring{\_unexpanded{\_gdef\_tmpb{#1}}}")}}% |
| 97 |
\_tablereplstrings \_edef\_tabskipmid{\_the\_tabskip}\_tabskip=\_tabskipl |
| 98 |
\_ifpxto |
| 99 |
\_edef\_tsizes{\_global\_tsizesum=\_the\_tsizesum \_gdef\_noexpand\_tsizelast{\_tsizelast}}% |
| 100 |
\_tsizesum=\_zo \_def\_tsizelast{0}% |
| 101 |
\_tsize=-\_hsize \_setbox0=\_vbox{\_tablepxpreset \_halign \_tableC}% |
| 102 |
\_advance\_tmpdim by-\_wd0 |
| 103 |
\_ifdim \_tmpdim >\_zo \_else \_tsizesum=\_zo \_fi |
| 104 |
\_ifdim \_tsizesum >\_zo \_tsize =\_expr{\_number\_hsize/\_number\_tsizesum}\_tmpdim |
| 105 |
\_else \_tsize=\_zo \_fi |
| 106 |
\_tsizes % restoring values if there is a \table pxto inside a \table pxto. |
| 107 |
\_setbox0=\_null \_halign \_tableC |
| 108 |
\_else |
| 109 |
\_halign\_tablew \_tableC |
| 110 |
\_fi |
| 111 |
\_glet\_tmpb\_undefined |
| 112 |
}\_egroup % \_tablebox\_bgroup is in the \_table macro |
| 113 |
} |
| 114 |
\_def\_tableC{\_ea{\_the\_tabdata\_tabskip=\_tabskipr\_cr \_scantextokens\_ea{\_tmpb\_crcr}}} |
| 115 |
|
| 116 |
\_doc ----------------------------- |
| 117 |
\`\_tabreplstrings` replaces each `\crl` etc. to `\crcr\crl`. |
| 118 |
The reason is: we want to use macros that scan its parameter |
| 119 |
to a delimiter written in the right part of the table item declaration. |
| 120 |
The `\crcr` cannot be hidden in another macro in this case. |
| 121 |
\_cod ----------------------------- |
| 122 |
|
| 123 |
\_def\_tablereplstrings{% |
| 124 |
\_replstring\_tmpb{\crl}{\_crcr\crl}\_replstring\_tmpb{\crll}{\_crcr\crll}% |
| 125 |
\_replstring\_tmpb{\crli}{\_crcr\crli}\_replstring\_tmpb{\crlli}{\_crcr\crlli}% |
| 126 |
\_replstring\_tmpb{\crlp}{\_crcr\crlp}% |
| 127 |
} |
| 128 |
|
| 129 |
\_def\_tablepxpreset{} % can be used to de-activate references to .ref file |
| 130 |
\_newbox\_tstrutbox % strut used in table rows |
| 131 |
\_newtoks\_tabdata % the \halign declaration line |
| 132 |
|
| 133 |
\_doc ----------------------------- |
| 134 |
The \`\_scantabdata` macro converts `\table`'s `<declaration>` to |
| 135 |
`\halign` `<converted declaration>`. |
| 136 |
The result is stored into \`\_tabdata` tokens list. |
| 137 |
For example, the |
| 138 |
following result is generated when `<declaration>=|cr||cl|`. |
| 139 |
\begtt |
| 140 |
tabdata: \_vrule\_the\_tabiteml{\_hfil#\_unsskip\_hfil}\_the\_tabitemr\_tabstrutA |
| 141 |
&\_the\_tabiteml{\_hfil#\_unsskip}\_the\_tabitemr |
| 142 |
\_vrule\_kern\_vvkern\_vrule\_tabstrutA |
| 143 |
&\_the\_tabiteml{\_hfil#\_unsskip\_hfil}\_the\_tabitemr\_tabstrutA |
| 144 |
&\_the\_tabiteml{\_relax#\_unsskip\_hfil}\_the\_tabitemr\_vrule\_tabstrutA |
| 145 |
ddlinedata: &\_dditem &\_dditem\_vvitem &\_dditem &\_dditem |
| 146 |
\endtt |
| 147 |
The second result in the \`\_ddlinedata` macro is a template of one row of the table |
| 148 |
used by \^`\crli` macro. |
| 149 |
\_cod ----------------------------- |
| 150 |
|
| 151 |
\_def\_scantabdata#1{\_let\_next=\_scantabdata |
| 152 |
\_ifx\_relax#1\_let\_next=\_relax |
| 153 |
\_else\_ifx|#1\_addtabvrule |
| 154 |
\_else\_ifx(#1\_def\_next{\_scantabdataE}% |
| 155 |
\_else\_ifx:#1\_def\_next{\_scantabdataF}% |
| 156 |
\_else\_isinlist{123456789}#1\_iftrue \_def\_next{\_scantabdataC#1}% |
| 157 |
\_else \_ea\_ifx\_csname _tabdeclare#1\_endcsname \_relax |
| 158 |
\_ea\_ifx\_csname _paramtabdeclare#1\_endcsname \_relax |
| 159 |
\_opwarning{tab-declarator "#1" unknown, ignored}% |
| 160 |
\_else |
| 161 |
\_def\_next{\_ea\_scantabdataB\_csname _paramtabdeclare#1\_endcsname}\_fi |
| 162 |
\_else \_def\_next{\_ea\_scantabdataA\_csname _tabdeclare#1\_endcsname}% |
| 163 |
\_fi\_fi\_fi\_fi\_fi\_fi \_next |
| 164 |
} |
| 165 |
\_def\_scantabdataA#1{\_addtabitem |
| 166 |
\_ea\_addtabdata\_ea{#1\_tabstrutA \_tabskip\_tabskipmid\_relax}\_scantabdata} |
| 167 |
\_def\_scantabdataB#1#2{\_addtabitem |
| 168 |
\_ea\_addtabdata\_ea{#1{#2}\_tabstrutA \_tabskip\_tabskipmid\_relax}\_scantabdata} |
| 169 |
\_def\_scantabdataC {\_def\_tmpb{}\_afterassignment\_scantabdataD \_tmpnum=} |
| 170 |
\_def\_scantabdataD#1{\_loop \_ifnum\_tmpnum>0 \_advance\_tmpnum by-1 \_addto\_tmpb{#1}\_repeat |
| 171 |
\_ea\_scantabdata\_tmpb} |
| 172 |
\_def\_scantabdataE#1){\_addtabdata{#1}\_scantabdata} |
| 173 |
\_def\_scantabdataF {\_addtabitem\_def\_addtabitem{\_let\_addtabitem=\_addtabitemx}\_scantabdata} |
| 174 |
|
| 175 |
\_doc ----------------------------- |
| 176 |
The \`\_addtabitemx` adds the boundary code (used between columns) |
| 177 |
to the <converted declaration>. This code is |
| 178 |
`\egroup &\bgroup \colnum=<value>\relax`. You can get the current number of |
| 179 |
column from the \`\colnum` register, but you cannot write |
| 180 |
`\the\colnum` as the first object in a <data> item because `\halign` |
| 181 |
first expands the front of the item and the left part of the declaration |
| 182 |
is processed after this. Use `\relax\the\colnum` instead. Or you can |
| 183 |
write: |
| 184 |
\begtt |
| 185 |
\def\showcolnum{\ea\def\ea\totcolnum\ea{\the\colnum}\the\colnum/\totcolnum} |
| 186 |
\table{ccc}{\showcolnum & \showcolnum & \showcolnum} |
| 187 |
\endtt |
| 188 |
This example prints 1/3 \ 2/3 \ 3/3, because the value of the `\colnum` is |
| 189 |
equal to the total number of columns before left part of the column declaration |
| 190 |
is processed. |
| 191 |
\_cod ----------------------------- |
| 192 |
|
| 193 |
\_newcount\_colnum % number of current column in the table |
| 194 |
\_public \colnum ; |
| 195 |
|
| 196 |
\_def\_addtabitemx{\_ifnum\_colnum>0 |
| 197 |
\_addtabdata{&}\_addto\_ddlinedata{&\_dditem}\_fi |
| 198 |
\_advance\_colnum by1 \_let\_tmpa=\_relax |
| 199 |
\_ifnum\_colnum>1 \_etoksapp\_tabdata{\_colnum\_the\_colnum\_relax}\_fi} |
| 200 |
\_def\_addtabdata{\_toksapp\_tabdata} |
| 201 |
|
| 202 |
\_doc ----------------------------- |
| 203 |
This code converts `||` or `|` from `\table` <declaration> to the <converted declaration>. |
| 204 |
\_cod ----------------------------- |
| 205 |
|
| 206 |
\_def\_addtabvrule{% |
| 207 |
\_ifx\_tmpa\_vrule \_addtabdata{\_kern\_vvkern}% |
| 208 |
\_ifnum\_colnum=0 \_addto\_vvleft{\_vvitem}\_else\_addto\_ddlinedata{\_vvitem}\_fi |
| 209 |
\_else \_ifnum\_colnum=0 \_addto\_vvleft{\_vvitemA}\_else\_addto\_ddlinedata{\_vvitemA}\_fi\_fi |
| 210 |
\_let\_tmpa=\_vrule \_addtabdata{\_vrule}% |
| 211 |
} |
| 212 |
\_def\_tabstrutA{\_copy\_tstrutbox} |
| 213 |
\_def\_vvleft{} |
| 214 |
\_def\_ddlinedata{} |
| 215 |
|
| 216 |
\_doc ----------------------------- |
| 217 |
The default \"declaration letters" `c`, `l`, `r` and `p` are declared |
| 218 |
by setting \`\_tabdeclarec`, \`\_tabdeclarel`, \`\_tabdeclarer` and |
| 219 |
\^`\_paramtabdeclarep` macros. In general, define |
| 220 |
`\def\_tabdeclare<letter>{...}` for a non-parametric |
| 221 |
letter and `\def\_paramtabdeclare<letter>{...}` for a letter with a parameter. |
| 222 |
The double hash `##` must be in the definition, it is replaced by a real table item data. |
| 223 |
You can declare more such \"declaration letters" if you want. |
| 224 |
|
| 225 |
Note, that the `##` with fills are in group. The reason can be explained |
| 226 |
by following example: |
| 227 |
\begtt |
| 228 |
\table{|c|c|}{\crl \Red A & B \crl} |
| 229 |
\endtt |
| 230 |
We don't want vertical line after red A to be in red. |
| 231 |
\_cod ----------------------------- |
| 232 |
|
| 233 |
\_def\_tabdeclarec{\_the\_tabiteml \_hfil{##}\_unsskip \_hfil \_the\_tabitemr} |
| 234 |
\_def\_tabdeclarel{\_the\_tabiteml {##}\_unsskip \_hfil\_the\_tabitemr} |
| 235 |
\_def\_tabdeclarer{\_the\_tabiteml \_hfil{##}\_unsskip \_the\_tabitemr} |
| 236 |
|
| 237 |
\_doc ----------------------------- |
| 238 |
The \`\_paramtabdeclarep``{<data>}` is invoked when `p{<data>}` |
| 239 |
declarator is used. First, it saves the `\hsize` value |
| 240 |
and then it runs \`\_tablepar`. |
| 241 |
The \^`\_tablepar` macro behaves like \`\_tableparbox` (which is `\vtop`) in normal cases. |
| 242 |
But there is a special case: if the first pass of `pxto` table is |
| 243 |
processed then `\hsize` is negative. We print nothing in this case, i.e.\ |
| 244 |
\^`\_tableparbox` is \^`\ignoreit` and we advance the \`\_tsizesum`. |
| 245 |
The auxiliary macro \`\_tsizelast` is used to do advancing |
| 246 |
only in the first row of the table. |
| 247 |
\^`\_tsizesum` and \^`\_tsizelast` are initialized in the \^`\_tableB` macro. |
| 248 |
\_cod ----------------------------- |
| 249 |
|
| 250 |
\_def\_paramtabdeclarep#1{\_hsize=#1\_relax |
| 251 |
\_the\_tabiteml \_tablepar{\_tableparB ##\_tableparC}\_the\_tabitemr |
| 252 |
} |
| 253 |
\_def\_tablepar{% |
| 254 |
\_ifdim\_hsize<0pt |
| 255 |
\_ifnum\_tsizelast<\_colnum \_global\_advance\_tsizesum by-\_hsize |
| 256 |
\_xdef\_tsizelast{\_the\_colnum}\_fi |
| 257 |
\_let\_tableparbox=\_ignoreit |
| 258 |
\_fi |
| 259 |
\_tableparA \_tableparbox |
| 260 |
} |
| 261 |
\_let \_tableparbox=\_vtop |
| 262 |
\_let \_tableparA=\_empty |
| 263 |
\_newdimen \_tsizesum |
| 264 |
\_def \_tsizelast{0} |
| 265 |
|
| 266 |
\_doc ----------------------------- |
| 267 |
The \`\_tableparB` initializes the paragraphs inside the table item and |
| 268 |
\`\_tableparC` closes them. They are used in the \^`\_paramtabdeclarep` macro. |
| 269 |
The first paragraph is no indented. |
| 270 |
\_cod ----------------------------- |
| 271 |
|
| 272 |
\_def\_tableparB{% |
| 273 |
\_baselineskip=\_normalbaselineskip \_lineskiplimit=\_zo \_noindent |
| 274 |
\_unless\_ifx\_tabstrutA\_empty \_raise\_ht\_tstrutbox\_null \_fi |
| 275 |
\_hskip\_zo \_relax |
| 276 |
} |
| 277 |
\_def\_tableparC{% |
| 278 |
\_unsskip |
| 279 |
\_unless\_ifx\_tabstrutA\_empty |
| 280 |
\_ifvmode\_vskip\_dp\_tstrutbox \_else\_lower\_dp\_tstrutbox\_null\_fi |
| 281 |
\_fi |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
\_doc ----------------------------- |
| 286 |
Users put optional spaces around the table item typically, i.e.\ they write |
| 287 |
`& text &` instead `&text&`. The left space is ignored by the internal \TeX/ algorithm but |
| 288 |
the right space must be removed by macros. This is a reason why we recommend to |
| 289 |
use \`\_unsskip` after each `##` in your definition of \"declaration letters". |
| 290 |
This macro isn't only the primitive `\unskip` because we allow usage of plain \TeX/ |
| 291 |
`\hideskip` macro: `&\hideskip text\hideskip&`. |
| 292 |
\_cod ----------------------------- |
| 293 |
|
| 294 |
\_def\_unsskip{\_ifmmode\_else\_ifdim\_lastskip>\_zo \_unskip\_fi\_fi} |
| 295 |
|
| 296 |
\_doc ----------------------------- |
| 297 |
The \`\fL`, \`\fR`, \`\fC` and \`\fX` macros only do special parameters settings |
| 298 |
for paragraph building algorithm. |
| 299 |
\_cod |
| 300 |
|
| 301 |
\_let\_fL=\_raggedright |
| 302 |
\_def\_fR{\_leftskip=0pt plus 1fill \_relax} |
| 303 |
\_def\_fC{\_leftskip=0pt plus1fill \_rightskip=0pt plus 1fill \_relax} |
| 304 |
\_def\_fX{\_leftskip=0pt plus1fil \_rightskip=0pt plus-1fil \_parfillskip=0pt plus2fil \_relax} |
| 305 |
\_public \fL \fR \fC \fX ; |
| 306 |
|
| 307 |
\_doc ----------------------------- |
| 308 |
The \`\fS` macro is more tricky. The \^`\_tableparbox` isn't printed |
| 309 |
immediately, but `\setbox2=` is prefixed by the macro \`\_tableparA`, |
| 310 |
which is empty by default (used in \^`\_tablepar`). The \`\_tableparD` |
| 311 |
is processed after the box is set: it checks if there is only one line |
| 312 |
and prints `\hbox to\hsize{\hfil<this line>\hfil}` in this case. In other |
| 313 |
cases, the box2 is printed. |
| 314 |
\_cod ----------------------------- |
| 315 |
|
| 316 |
\_def\_fS{\_relax |
| 317 |
\_ifdim\_hsize<0pt \_else \_def\_tableparA{\_setbox2=}\_fi |
| 318 |
\_addto\_tableparC{\_aftergroup\_tableparD}% |
| 319 |
} |
| 320 |
\_def\_tableparD{\_setbox0=\_vbox{\_unvcopy2 \_unskip \_global\_setbox1=\_lastbox}% |
| 321 |
\_ifdim\_ht0>0pt \_box2 \_setbox0=\_box1 |
| 322 |
\_else \_hbox to\_hsize{\_hfil \_unhbox1\_unskip\_unskip\_hfil}\_setbox0=\_box2 \_fi |
| 323 |
} |
| 324 |
\_public \fS ; |
| 325 |
|
| 326 |
\_doc ----------------------------- |
| 327 |
The family of `\_cr*` macros |
| 328 |
\`\crl`, \`\crll`, \`\crli`, \`\crlli`, \`\crlp` and |
| 329 |
\`\tskip` `<dimen>` is implemented here. |
| 330 |
The \`\_zerotabrule` is used to suppress the negative `\lineskip` |
| 331 |
declared by \^`\tablinespace`. |
| 332 |
\_cod ----------------------------- |
| 333 |
|
| 334 |
\_def\_crl{\_crcr\_noalign{\_hrule}} |
| 335 |
\_def\_crll{\_crcr\_noalign{\_hrule\_kern\_hhkern\_hrule}} |
| 336 |
\_def\_zerotabrule {\_noalign{\_hrule height\_zo width\_zo depth\_zo}} |
| 337 |
|
| 338 |
\_def\_crli{\_crcr \_zerotabrule \_omit |
| 339 |
\_gdef\_dditem{\_omit\_tablinefil}\_gdef\_vvitem{\_kern\_vvkern\_vrule}\_gdef\_vvitemA{\_vrule}% |
| 340 |
\_vvleft\_tablinefil\_ddlinedata\_crcr \_zerotabrule} |
| 341 |
\_def\_crlli{\_crli\_noalign{\_kern\_hhkern}\_crli} |
| 342 |
\_def\_tablinefil{\_leaders\_hrule\_hfil} |
| 343 |
|
| 344 |
\_def\_crlp#1{\_crcr \_zerotabrule \_noalign{\_kern-\_drulewidth}% |
| 345 |
\_omit \_xdef\_crlplist{#1}\_xdef\_crlplist{,\_ea}\_ea\_crlpA\_crlplist,\_fin,% |
| 346 |
\_global\_tmpnum=0 \_gdef\_dditem{\_omit\_crlpD}% |
| 347 |
\_gdef\_vvitem{\_kern\_vvkern\_kern\_drulewidth}\_gdef\_vvitemA{\_kern\_drulewidth}% |
| 348 |
\_vvleft\_crlpD\_ddlinedata \_global\_tmpnum=0 \_crcr \_zerotabrule} |
| 349 |
\_def\_crlpA#1,{\_ifx\_fin#1\_else \_crlpB#1-\_fin,\_ea\_crlpA\_fi} |
| 350 |
\_def\_crlpB#1#2-#3,{\_ifx\_fin#3\_xdef\_crlplist{\_crlplist#1#2,}\_else\_crlpC#1#2-#3,\_fi} |
| 351 |
\_def\_crlpC#1-#2-#3,{\_tmpnum=#1\_relax |
| 352 |
\_loop \_xdef\_crlplist{\_crlplist\_the\_tmpnum,}\_ifnum\_tmpnum<#2\_advance\_tmpnum by1 \_repeat} |
| 353 |
\_def\_crlpD{\_incr\_tmpnum \_edef\_tmpa{\_noexpand\_isinlist\_noexpand\_crlplist{,\_the\_tmpnum,}}% |
| 354 |
\_tmpa\_iftrue \_kern-\_drulewidth \_tablinefil \_kern-\_drulewidth\_else\_hfil \_fi} |
| 355 |
|
| 356 |
\_def\_tskip{\_afterassignment\_tskipA \_tmpdim} |
| 357 |
\_def\_tskipA{\_gdef\_dditem{}\_gdef\_vvitem{}\_gdef\_vvitemA{}\_gdef\_tabstrutA{}% |
| 358 |
\_vbox to\_tmpdim{}\_ddlinedata \_crcr |
| 359 |
\_zerotabrule \_noalign{\_gdef\_tabstrutA{\_copy\_tstrutbox}}} |
| 360 |
|
| 361 |
\_public \crl \crll \crli \crlli \crlp \tskip ; |
| 362 |
|
| 363 |
\_doc ----------------------------- |
| 364 |
The \`\mspan``{<number>}[<declaration>]{<text>}` macro generates similar `\omit\span\omit\span` |
| 365 |
sequence as plain \TeX/ macro `\multispan`. Moreover, it uses \^`\_scantabdata` to |
| 366 |
convert `<declaration>` from `\table` syntax to `\halign` syntax. |
| 367 |
\_cod ----------------------------- |
| 368 |
|
| 369 |
\_def\_mspan{\_omit \_afterassignment\_mspanA \_mscount=} |
| 370 |
\_def\_mspanA[#1]#2{\_loop \_ifnum\_mscount>1 \_cs{_span}\_omit \_advance\_mscount-1 \_repeat |
| 371 |
\_count1=\_colnum \_colnum=0 \_def\_tmpa{}\_tabdata={}\_scantabdata#1\_relax |
| 372 |
\_colnum=\_count1 \_setbox0=\_vbox{\_halign\_ea{\_the\_tabdata\_cr#2\_cr}% |
| 373 |
\_global\_setbox8=\_lastbox}% |
| 374 |
\_setbox0=\_hbox{\_unhbox8 \_unskip \_global\_setbox8=\_lastbox}% |
| 375 |
\_unhbox8 \_ignorespaces} |
| 376 |
\_public \mspan ; |
| 377 |
|
| 378 |
\_doc ----------------------------- |
| 379 |
The \`\vspan``<number>{<text>}` implementation is here. |
| 380 |
We need to lower the box by |
| 381 |
\begtt \catcode`\<=13 |
| 382 |
(<number>-1)*(\ht+\dp of \tabstrut) / 2. |
| 383 |
\endtt |
| 384 |
The `#1` parameter must be a one-digit number. If you want to set more digits |
| 385 |
then use braces. |
| 386 |
\_cod ----------------------------- |
| 387 |
|
| 388 |
\_def\_vspan#1#2#{\_vspanA{#1#2}} |
| 389 |
\_def\_vspanA#1#2{\_vtop to\_zo{\_hbox{\_lower \_dimexpr |
| 390 |
#1\_dimexpr(\_ht\_tstrutbox+\_dp\_tstrutbox)/2\_relax |
| 391 |
-\_dimexpr(\_ht\_tstrutbox+\_dp\_tstrutbox)/2\_relax \_hbox{#2}}\_vss}} |
| 392 |
\_public \vspan ; |
| 393 |
|
| 394 |
\_doc ----------------------------- |
| 395 |
The parameters of primitive `\vrule` and `\hrule` keeps the rule \"last wins". |
| 396 |
If we re-define `\hrule` to `\_orihrule height1pt` then each usage |
| 397 |
of redefined `\hrule` uses `1pt` height if this parameter isn't |
| 398 |
overwritten by another following `height` parameter. This principle is used for |
| 399 |
settings another default rule thickness than 0.4\,pt by the macro |
| 400 |
\`\rulewidth`. |
| 401 |
\_cod ----------------------------- |
| 402 |
|
| 403 |
\_newdimen\_drulewidth \_drulewidth=0.4pt |
| 404 |
\_let\_orihrule=\_hrule \_let\_orivrule=\_vrule |
| 405 |
\_def\_rulewidth{\_afterassignment\_rulewidthA \_drulewidth} |
| 406 |
\_def\_rulewidthA{\_edef\_hrule{\_orihrule height\_drulewidth}% |
| 407 |
\_edef\_vrule{\_orivrule width\_drulewidth}% |
| 408 |
\_let\_rulewidth=\_drulewidth |
| 409 |
\_public \vrule \hrule \rulewidth;} |
| 410 |
\_public \rulewidth ; |
| 411 |
|
| 412 |
\_doc ----------------------------- |
| 413 |
The \`\frame``{<text>}` uses \"\code{\\vbox} in \code{\\vtop}" trick in order to keep the |
| 414 |
baseline of the internal text at the same level as outer baseline. |
| 415 |
User can write `\frame{abcxyz}` in normal paragraph line, for example |
| 416 |
and gets the expected result: \frame{abcxyz}. |
| 417 |
The internal margins are set by `\vvkern` and `\hhkern` parameters. |
| 418 |
\_cod ----------------------------- |
| 419 |
|
| 420 |
\_long\_def\_frame#1{% |
| 421 |
\_hbox{\_vrule\_vtop{\_vbox{\_hrule\_kern\_vvkern |
| 422 |
\_hbox{\_kern\_hhkern{#1}\_kern\_hhkern}% |
| 423 |
}\_kern\_vvkern\_hrule}\_vrule}} |
| 424 |
\_public \frame ; |
| 425 |
|
| 426 |
\_doc ----------------------------- |
| 427 |
\`\eqbox` and \`\eqboxsize` are implemented here. The widths of |
| 428 |
all `\eqbox`es are saved to the `.ref` file in the format |
| 429 |
\`\_Xeqbox``{<label>}{<size>}`. The `.ref` file is read again and maximum |
| 430 |
box width for each <label> is saved to `\_eqb:<label>`. |
| 431 |
\_cod ----------------------------- |
| 432 |
|
| 433 |
\_def\_Xeqbox#1#2{% |
| 434 |
\_ifcsname _eqb:#1\_endcsname |
| 435 |
\_ifdim #2>\_cs{_eqb:#1}\_relax \_sdef{_eqb:#1}{#2}\_fi |
| 436 |
\_else \_sdef{_eqb:#1}{#2}\_fi |
| 437 |
} |
| 438 |
\_def\_eqbox #1[#2]#3{\_setbox0=\_hbox{{#3}}% |
| 439 |
\_openref \_immediate\_wref \_Xeqbox{{#2}{\_the\_wd0}}% |
| 440 |
\_ifcsname _eqb:#2\_endcsname |
| 441 |
\_hbox to\_cs{_eqb:#2}{\_ifx r#1\_hfill\_fi\_hss\_unhbox0\_hss\_ifx l#1\_hfill\_fi}% |
| 442 |
\_else \_box0 \_fi |
| 443 |
} |
| 444 |
\_def\_eqboxsize [#1]#2{\_trycs{_eqb:#1}{#2}} |
| 445 |
|
| 446 |
\public \eqbox \eqboxsize ; |
| 447 |
|
| 448 |
\_endcode % ------------------------------------- |
| 449 |
|
| 450 |
\secc[table.bound] The boundary declarator \code{:} |
| 451 |
|
| 452 |
The `<declaration>` part of `\table{<declaration>}{<data>}` includes |
| 453 |
column declarators (letters) and other material: the `|` or `(<cmd>)`. |
| 454 |
If the boundary declarator `:` is not used then |
| 455 |
the boundaries of columns are just before each column declarator |
| 456 |
with exception of the first one. |
| 457 |
For example, the declaration `{|c||c(xx)(yy)c}` |
| 458 |
should be written more exactly using the boundary declarator `:` |
| 459 |
by `{|c||:c(xx)(yy):c}`. But you can set these boundaries to |
| 460 |
other places using the boundary declarator~`:` explicitly, |
| 461 |
for example `{|c:||c(xx):(yy)c}`. The boundary declarator `:` |
| 462 |
can be used only once between each pair of column declarators. |
| 463 |
|
| 464 |
Each table item has its group. The `(<cmd>)` are parts of the given |
| 465 |
table item (depending on the boundary declarator position). |
| 466 |
If you want to apply a special setting for a given column, you can do this by |
| 467 |
`(<setting>)` followed by column declarator. But if the column is not |
| 468 |
first, you must use `:(<setting>)`. Example. We have three centered columns, |
| 469 |
the second one have to be in bold font and the third one have to be in red: |
| 470 |
`\table{c:(\bf)c:(\Red)c}{<data>}` |
| 471 |
|
| 472 |
\secc Usage of the \code{\\tabskip} primitive |
| 473 |
|
| 474 |
The value of `\tabskip` primitive is used between all columns of the table. |
| 475 |
It is glue-type, so it can be stretchable or shrinkable, see next |
| 476 |
section~\ref[table.w]. |
| 477 |
|
| 478 |
By default, `\tabskip` is 0\,pt. It means that only \^`\tabiteml`, |
| 479 |
\^`\tabitemr` and `(<cmds>)` can generate visual spaces between columns. But they |
| 480 |
are not real spaces between columns because they are in fact the part of |
| 481 |
the total column width. |
| 482 |
|
| 483 |
The `\tabskip` value declared before the \^`\table` macro (or in |
| 484 |
\^`\everytable` or in \^`\thistable`) is used between all columns in the table. |
| 485 |
This value is equal to all spaces between columns. But you can set each such space |
| 486 |
individually if you use `(\tabskip=<value>)` in the <declaration> immediately |
| 487 |
before boundary character. The boundary character represents the column pair for |
| 488 |
which the `\tabskip` has individual value. For example |
| 489 |
`c(\tabskip=5pt):r` gives `\tabskip` value between `c` and `r` columns. |
| 490 |
You need not use boundary character explicitly, so `c(\tabskip=5pt)r` gives |
| 491 |
the same result. |
| 492 |
|
| 493 |
Space before the first column is given by the \^`\tabskipl` |
| 494 |
and space after the last column is equal to \^`\tabskipr`. |
| 495 |
Default values are 0\,pt. |
| 496 |
|
| 497 |
Use nonzero `\tabskip` only in special applications. If `\tabskip` is |
| 498 |
nonzero then horizontal lines generated by \^`\crli`, \^`\crlli` and \^`\crlp` |
| 499 |
have another behavior than you probably expected: they are interrupted in |
| 500 |
each `\tabskip` space. |
| 501 |
|
| 502 |
\secc[table.w] Tables to given width |
| 503 |
|
| 504 |
There are two possibilities how to create tables to given width: |
| 505 |
|
| 506 |
\begitems |
| 507 |
* `\table to<size>{<declaration>}{<data>}` uses stretchability or |
| 508 |
shrinkability of all spaces between columns generated by `\tabskip` value and |
| 509 |
eventually by \^`\tabskipl`, \^`\tabskipr` values. See example below. |
| 510 |
* `\table pxto<size>{<declaration>}{<data>}` expands the columns declared |
| 511 |
by `p{<size>}`, if the `<size>` is given by a virtual \^`\tsize` unit. |
| 512 |
See the example below. |
| 513 |
\enditems |
| 514 |
|
| 515 |
Example of `\table to<size>`: |
| 516 |
|
| 517 |
\begtt \catcode`\<=13 |
| 518 |
\thistable{\tabskip=0pt plus1fil minus1fil} |
| 519 |
\table to\hsize {lr}{<data>} |
| 520 |
\endtt |
| 521 |
% |
| 522 |
This table has its width `\hsize`. The first column starts at the left boundary of |
| 523 |
this table and it is justified left (to the boundary). The second column ends at |
| 524 |
the right boundary of the table and it is justified right (to the boundary). |
| 525 |
The space between them is stretchable and shrinkable to reach |
| 526 |
the given width `\hsize`. |
| 527 |
|
| 528 |
\medskip |
| 529 |
Example of `\table pxto<size>` (means \"{\bf p}aragraphs e{\bf x}panded {\bf to}"): |
| 530 |
|
| 531 |
\begtt |
| 532 |
\table pxto\hsize {|c|p{\tsize}|}{\crl |
| 533 |
aaa & Ddkas jd dsjds ds cgha sfgs dd fddzf dfhz xxz |
| 534 |
dras ffg hksd kds d sdjds h sd jd dsjds ds cgha |
| 535 |
sfgs dd fddzf dfhz xxz. \crl |
| 536 |
bb ddd ggg & Dsjds ds cgha sfgs dd fddzf dfhz xxz |
| 537 |
ddkas jd dsjds ds cgha sfgs dd fddzf. \crl } |
| 538 |
\endtt |
| 539 |
|
| 540 |
\noindent\table pxto\hsize {|c|p{\tsize}|}{\crl |
| 541 |
aaa & Ddkas jd dsjds ds cgha sfgs dd fddzf dfhz xxz |
| 542 |
dras ffg hksd kds d sdjds h sd jd dsjds ds cgha |
| 543 |
sfgs dd fddzf dfhz xxz. \crl |
| 544 |
bb ddd ggg & Dsjds ds cgha sfgs dd fddzf dfhz xxz |
| 545 |
ddkas jd dsjds ds cgha sfgs dd fddzf. \crl } |
| 546 |
\medskip |
| 547 |
|
| 548 |
The first `c` column is variable width (it gets the width of the most wide item) |
| 549 |
and the resting space to given `\hsize` is filled by the `p` column. |
| 550 |
|
| 551 |
You can declare more than one `p{<coefficient>\tsize}` columns in the table |
| 552 |
when `pxto` keyword is used. |
| 553 |
|
| 554 |
\begtt \catcode`\<=13 |
| 555 |
\table pxto13cm {r p{3.5\tsize} p{2\tsize} p{\tsize} l}{<data>} |
| 556 |
\endtt |
| 557 |
% |
| 558 |
This gives the ratio of widths of individual paragraphs in the table |
| 559 |
3.5\,:\,2\,:\,1. |
| 560 |
|
| 561 |
\secc `\eqbox`: boxes with equal width across the whole document |
| 562 |
|
| 563 |
The \^`\eqbox` `[<label>]{<text>}` behaves like `\hbox{<text>}` in the first |
| 564 |
run of \TeX. But the widths of all boxes with the same label are saved to |
| 565 |
`.ref` file and the maximum box width for each label is calculated at the |
| 566 |
beginning of the next \TeX/ run. Then \^`\eqbox`~`[<label>]{<text>}` behaves |
| 567 |
like `\hbox to <dim:label> {\hss <text>\hss}`, where <dim:label> is |
| 568 |
the maximum width of all boxes |
| 569 |
labeled by the same `[<label>]`. The documentation of the \LaTeX/ package |
| 570 |
`eqparbox` includes more information and tips. |
| 571 |
|
| 572 |
The \^`\eqboxsize` `[<label>]{<dimen>}` expands to <dim:label> if this value is known, |
| 573 |
else it expands to the given <dimen>. |
| 574 |
|
| 575 |
The optional parameter `r` or `l` can be written before `[<label>]` (for example |
| 576 |
`\eqbox r[label]{text}`) if you want to put the text to the right or to the |
| 577 |
left side of the box width. |
| 578 |
|
| 579 |
Try the following example and watch what happens after first \TeX/ run and |
| 580 |
after the second one. |
| 581 |
|
| 582 |
\begtt |
| 583 |
\def\leftitem#1{\par |
| 584 |
\noindent \hangindent=\eqboxsize[items]{2em}\hangafter=1 |
| 585 |
\eqbox r[items]{#1 }\ignorespaces} |
| 586 |
|
| 587 |
\leftitem {\bf first} \lorem[1] |
| 588 |
\leftitem {\bf second one} \lorem[2] |
| 589 |
\leftitem {\bf final} \lorem[3] |
| 590 |
\endtt |
| 591 |
|
| 592 |
|
| 593 |
\_endinput |
| 594 |
|
| 595 |
2024-11-21 \_tableB improved (rescan its parameter by \directlua) |
| 596 |
2023-06-27 \frame: argument in group |
| 597 |
2023-05-19 \_tableparB,C: no strut when \tskip is processed (bug fixed). |
| 598 |
2022-12-26 \tabdeclare: use {##} in order to allow a\over b in table items |
| 599 |
2022-05-03 \_let\_tablereplstring\_relax removed and {...} encloses whole \_tableB body |
| 600 |
2022-05-02 \_tablereplstrings put in group: bug fix \table in \halign |
| 601 |
2022-02-25 {}->\(begin|end)group in \_tabdeclare(l|r|c), bug when \tabitem(l|r)={$} fixed. |
| 602 |
2021-08-04 \_patamtabdeclarep reimplemented. |
| 603 |
2021-07-16 grouping based on colors via attributes. |
| 604 |
2021-06-03 \scantextokens added to \_partabitem, bug fixed. |
| 605 |
2021-06-03 \fS corrected, re-implemented. |
| 606 |
2021-06-02 \table in \table allowed, bug fixed. |
| 607 |
2021-06-01 pxto: sum of \tsize's allowed different than 1 |
| 608 |
2021-04-12 p declarator: \hskip0pt added to allow first word hyphenated |
| 609 |
2021-03-09 \_tablepxpreset introduced |
| 610 |
2021-02-15 \_expandafter -> \_ea |
| 611 |
2021-01-27 \_tableB: \long\def added, \vspan syntax improved |
| 612 |
2020-05-26 \eqbox implemented |
| 613 |
2020-05-20 \colnum implemented. |
| 614 |
\vspan implemented. |
| 615 |
2020-05-19 \fL, \fR ets defined. |
| 616 |
\table to, \table pxto implemented. |
| 617 |
2020-05-10 \bgroup &\egroup added to tabdata (in order to \aftergroup from colors) |
| 618 |
boundary declarator : introduced |
| 619 |
\_unsskip: \ifmmode added. |
| 620 |
2020-04-10 second group for items in order to \localcolors |