summaryrefslogtreecommitdiff
path: root/macros/optex/base/table.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/optex/base/table.opm')
-rw-r--r--macros/optex/base/table.opm94
1 files changed, 71 insertions, 23 deletions
diff --git a/macros/optex/base/table.opm b/macros/optex/base/table.opm
index f32bf311ab..b29aabbf4a 100644
--- a/macros/optex/base/table.opm
+++ b/macros/optex/base/table.opm
@@ -1,6 +1,6 @@
%% This is part of the OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \table {Basic macros for OpTeX <2021-04-12>} % preloaded in format
+\_codedecl \table {Basic macros for OpTeX <2021-06-03>} % preloaded in format
\_doc -----------------------------
The result of the \`\table``{<declaration>}{<data>}` macro is inserted into
@@ -58,10 +58,9 @@
\_doc -----------------------------
The \`\_tableB` saves `<data>` to `\_tmpb`
- and does four \^`\replstring`s to prefix each macro \^`\crl` (etc.)
- by `\_crcr`. The reason is: we want to use macros that scan its parameter
- to the delimiter written in the right part of the table item declaration.
- See \^`\fS` for example. The `\crcr` cannot be hidden in another macro in this case.
+ and does \^`\replstring`s to prefix each macro \^`\crl` (etc.)
+ by `\_crcr`. See \^`\_tabreplstrings`. It cannot be used in a `\table` in
+ another `\table`, so \^`\_tabreplstrings` is set to `\relax` locally.
The `\tabskip` value is saved for places between columns
into the \`\_tabskipmid` macro. Then it runs
@@ -73,8 +72,13 @@
`<converted declaration>` immediately after each column declarator.
If `pxto` keyword was used, then we set the virtual unit \^`\tsize` to
- `\hsize` first. Then the first attempt of the table is created in box 0.
- Then the \^`\tsize` is re-calculated using `\wd0` and the real table is
+ `-\hsize` first. Then the first attempt of the table is created in box 0.
+ All collums where `p{..\tsize}` is used, are created as empty in this first
+ pass. So, the `\wd0` is the width of all other columns.
+ The \^`\_tsizesum` includes the sum of \^`\tsize`'s in `\hsize` units
+ after firts pass. The desired table width is stored in the `\_tmpdim`, so
+ `\_tmpdim-\_wd0` is the rest which have to be filled by \^`\tsize`s.
+ Then the \^`\tsize` is re-calculated and the real table is
printed by `\halign` in the second pass.
If no `pxto` keyword was used, then we print the table using `\halign`
@@ -96,13 +100,17 @@
\_cod -----------------------------
\_long\_def\_tableB #1{\_egroup \_def\_tmpb{#1}%
- \_replstring\_tmpb{\crl}{\_crcr\crl}\_replstring\_tmpb{\crll}{\_crcr\crll}%
- \_replstring\_tmpb{\crli}{\_crcr\crli}\_replstring\_tmpb{\crlli}{\_crcr\crlli}%
- \_replstring\_tmpb{\crlp}{\_crcr\crlp}%
+ \_tablereplstrings \_let\_tablereplstrings=\_relax
\_edef\_tabskipmid{\_the\_tabskip}\_tabskip=\_tabskipl
\_ifpxto
- \_tsize=\_hsize \_setbox0 = \_vbox{\_tablepxpreset \_halign \_tableC}%
- \_tsize=\_dimexpr\_hsize-(\_wd0-\_tmpdim)\_relax
+ \_edef\_tsizes{\_global\_tsizesum=\_the\_tsizesum \_gdef\_noexpand\_tsizelast{\_tsizelast}}%
+ \_tsizesum=\_zo \_def\_tsizelast{0}%
+ \_tsize=-\_hsize \_setbox0=\_vbox{\_tablepxpreset \_halign \_tableC}%
+ \_advance\_tmpdim by-\_wd0
+ \_ifdim \_tmpdim >\_zo \_else \_tsizesum=\_zo \_fi
+ \_ifdim \_tsizesum >\_zo \_tsize =\_expr{\_number\_hsize/\_number\_tsizesum}\_tmpdim
+ \_else \_tsize=\_zo \_fi
+ \_tsizes % retoring values if there is a \table pxto inside a \table pxto.
\_setbox0=\_null \_halign \_tableC
\_else
\_halign\_tablew \_tableC
@@ -111,6 +119,19 @@
\_def\_tableC{\_ea{\_ea\_bgroup\_the\_tabdata\_egroup\_tabskip=\_tabskipr\_cr
\_scantextokens\_ea{\_tmpb\_crcr}}}
+ \_doc -----------------------------
+ \`\_tabreplstrings` replaces each `\crl` etc. to `\crcr\crl`.
+ The reason is: we want to use macros that scan its parameter
+ to a delimiter written in the right part of the table item declaration.
+ The `\crcr` cannot be hidden in another macro in this case.
+ \_cod -----------------------------
+
+\_def\_tablereplstrings{%
+ \_replstring\_tmpb{\crl}{\_crcr\crl}\_replstring\_tmpb{\crll}{\_crcr\crll}%
+ \_replstring\_tmpb{\crli}{\_crcr\crli}\_replstring\_tmpb{\crlli}{\_crcr\crlli}%
+ \_replstring\_tmpb{\crlp}{\_crcr\crlp}%
+}
+
\_def\_tablepxpreset{} % can be used to de-activate references to .ref file
\_newbox\_tstrutbox % strut used in table rows
\_newtoks\_tabdata % the \halign declaration line
@@ -211,10 +232,34 @@
\_def\_tabdeclarec{\_the\_tabiteml\_hfil##\_unsskip\_hfil\_the\_tabitemr}
\_def\_tabdeclarel{\_the\_tabiteml\_relax##\_unsskip\_hfil\_the\_tabitemr}
\_def\_tabdeclarer{\_the\_tabiteml\_hfil##\_unsskip\_the\_tabitemr}
-\_def\_paramtabdeclarep#1{\_the\_tabiteml
- \_vtop{\_hsize=#1\_relax \_baselineskip=\_normalbaselineskip
- \_lineskiplimit=\_zo \_noindent \_hskip\_zo \_relax ##\_unsskip
- \_ifvmode\_vskip\_dp\_tstrutbox \_else\_lower\_dp\_tstrutbox\_hbox{}\_fi}\_the\_tabitemr}
+\_def\_paramtabdeclarep#1{\_the\_tabiteml\_vtop{\_hsize=#1\_relax \_partabitem{##}}\_the\_tabitemr}
+
+ \_doc -----------------------------
+ \`\_partabitem``{<data>}` prints the table item in a paragraph format.
+ This macro solves two things. Fist, the setting of parameters for the
+ paragraph formatting. The `\hsize` and parameters from macros
+ \^`\fC`, \^`\fR` etc. are set already.\nl
+ Second thing: if the `\hsize` is negative then first pass of `pxto` table is processed.
+ We print nothing in such case but we advance the \`\_tsizesum`.
+ The auxiliary macro \`\_tsizelast` is used to do advancing
+ only in the first row of the table.
+ \^`\_tsizesum` and \^`\_tsizelast` are initialized in the \^`\_tableB` macro.\nl
+ \`\_partabitemA``{<data>}` only copies <data>, but it is redefined by \^`\fS`.
+ \_cod -----------------------------
+
+\_newdimen \_tsizesum
+\_def \_tsizelast{0}
+\_long\_def\_partabitem#1{%
+ \_ifdim\_hsize<0pt
+ \_ifnum\_tsizelast<\_colnum \_global\_advance\_tsizesum by-\_hsize
+ \_xdef\_tsizelast{\_the\_colnum}\_fi
+ \_else
+ \_baselineskip=\_normalbaselineskip
+ \_lineskiplimit=\_zo \_noindent \_hskip\_zo \_relax \_partabitemA{#1}\_unsskip
+ \_ifvmode\_vskip\_dp\_tstrutbox \_else\_lower\_dp\_tstrutbox\_hbox{}\_fi
+ \_fi
+}
+\_let\_partabitemA=\_useit
\_doc -----------------------------
Users put optional spaces around the table item typically, i.e.\ they write
@@ -238,9 +283,9 @@
\_def\_fR{\_leftskip=0pt plus 1fill \_relax}
\_def\_fC{\_leftskip=0pt plus1fill \_rightskip=0pt plus 1fill \_relax}
\_def\_fX{\_leftskip=0pt plus1fil \_rightskip=0pt plus-1fil \_parfillskip=0pt plus2fil \_relax}
-\_long\_def\_fS #1\_unsskip{\_noindent \_setbox0 =\_vbox{\_noindent #1\_endgraf \_ea}%
- \_ifnum\_prevgraf=1 \_hfil \_fi #1\_unsskip
-}
+\_def\_fS{\_long\_def\_partabitemA##1{%
+ \_setbox0=\_vbox{\_noindent ##1\_endgraf \_ea}\_ifnum\_prevgraf=1 \_hfil \_fi ##1%
+}}
\_public \fL \fR \fC \fX \fS ;
\_doc -----------------------------
@@ -469,14 +514,14 @@ The first `c` column is variable width (it gets the width of the most wide item)
and the resting space to given `\hsize` is filled by the `p` column.
You can declare more than one `p{<coefficient>\tsize}` columns in the table
-when `pxto` keyword is used. The total sum of <coefficinets> must be exactly one.
-For example,
+when `pxto` keyword is used.
\begtt \catcode`\<=13
-\table pxto13cm {r p{.3\tsize} p{.5\tsize} p{.2\tsize} l}{<data>}
+\table pxto13cm {r p{3.5\tsize} p{2\tsize} p{\tsize} l}{<data>}
\endtt
%
-This gives the ratio of widths of individual paragraphs in the table.
+This gives the ratio of widths of individual paragraphs in the table
+3.5\,:\,2\,:\,1.
\secc `\eqbox`: boxes with equal width across the whole document
@@ -512,6 +557,9 @@ after the second one.
\_endinput
+2021-06-03 \fS corrected, re-implemented.
+2021-06-02 \table in \table allowed, bug fixed.
+2021-06-01 pxto: sum of \tsize's allowed different than 1
2021-04-12 p declarator: \hskip0pt added to allow first word hyphenated
2021-03-09 \_tablepxpreset introduced
2021-02-15 \_expandafter -> \_ea