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.opm125
1 files changed, 77 insertions, 48 deletions
diff --git a/macros/optex/base/table.opm b/macros/optex/base/table.opm
index b29aabbf4a..d10e916bbe 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-06-03>} % preloaded in format
+\_codedecl \table {Basic macros for OpTeX <2021-08-04>} % preloaded in format
\_doc -----------------------------
The result of the \`\table``{<declaration>}{<data>}` macro is inserted into
@@ -84,16 +84,6 @@
If no `pxto` keyword was used, then we print the table using `\halign`
directly. The \^`\_tablew` macro is nonempty if the `to` keyword was used.
- Because the color selector with `\aftergroup` can be used inside the
- table item, we must create the second real group for each table item.
- This is reason why we start `<converted declaration>` by `\bgroup` and we
- end it by `\egroup` in the \`\_tableC` macro. Each `&` character
- is stored as `\egroup&\bgroup` in `<converted declaration>`. The
- `\halign\_tablew\_tableC` really does:
- \begtt \catcode`\<=13
- \halign\_tablew{\bgroup<converted declaration>\egroup\tabskip=\tabskipr \cr<data>\crcr}
- \endtt
- \relax
The <data> are re-tokenized by `\_scantextokens` in order to be more
robust to catcode changing inside the <data>. But inline verbatim cannot
work in special cases here like \code{`\{`} for example.
@@ -116,8 +106,7 @@
\_halign\_tablew \_tableC
\_fi \_egroup
}
-\_def\_tableC{\_ea{\_ea\_bgroup\_the\_tabdata\_egroup\_tabskip=\_tabskipr\_cr
- \_scantextokens\_ea{\_tmpb\_crcr}}}
+\_def\_tableC{\_ea{\_the\_tabdata\_tabskip=\_tabskipr\_cr \_scantextokens\_ea{\_tmpb\_crcr}}}
\_doc -----------------------------
\`\_tabreplstrings` replaces each `\crl` etc. to `\crcr\crl`.
@@ -143,11 +132,11 @@
For example, the
following result is generated when `<declaration>=|cr||cl|`.
\begtt
- tabdata: \_vrule\_the\_tabiteml\_hfil#\_unsskip\_hfil\_the\_tabitemr\_tabstrutA
- &\_the\_tabiteml\_hfil#\_unsskip\_the\_tabitemr
+ tabdata: \_vrule\_the\_tabiteml{\_hfil#\_unsskip\_hfil}\_the\_tabitemr\_tabstrutA
+ &\_the\_tabiteml{\_hfil#\_unsskip}\_the\_tabitemr
\_vrule\_kern\_vvkern\_vrule\_tabstrutA
- &\_the\_tabiteml\_hfil#\_unsskip\_hfil\_the\_tabitemr\_tabstrutA
- &\_the\_tabiteml#\_unsskip\_hfil\_the\_tabitemr\_vrule\_tabstrutA
+ &\_the\_tabiteml{\_hfil#\_unsskip\_hfil}\_the\_tabitemr\_tabstrutA
+ &\_the\_tabiteml{\_relax#\_unsskip\_hfil}\_the\_tabitemr\_vrule\_tabstrutA
ddlinedata: &\_dditem &\_dditem\_vvitem &\_dditem &\_dditem
\endtt
The second result in the \`\_ddlinedata` macro is a template of one row of the table
@@ -200,7 +189,7 @@
\_public \colnum ;
\_def\_addtabitemx{\_ifnum\_colnum>0
- \_addtabdata{\_egroup &\_bgroup}\_addto\_ddlinedata{&\_dditem}\_fi
+ \_addtabdata{&}\_addto\_ddlinedata{&\_dditem}\_fi
\_advance\_colnum by1 \_let\_tmpa=\_relax
\_ifnum\_colnum>1 \_ea\_addtabdata\_ea{\_ea\_colnum\_the\_colnum\_relax}\_fi}
\_def\_addtabdata#1{\_tabdata\_ea{\_the\_tabdata#1}}
@@ -222,44 +211,67 @@
\_doc -----------------------------
The default \"declaration letters" `c`, `l`, `r` and `p` are declared
by setting \`\_tabdeclarec`, \`\_tabdeclarel`, \`\_tabdeclarer` and
- \`\_paramtabdeclarep` macros. In general, define
+ \^`\_paramtabdeclarep` macros. In general, define
`\def\_tabdeclare<letter>{...}` for a non-parametric
letter and `\def\_paramtabdeclare<letter>{...}` for a letter with a parameter.
The double hash `##` must be in the definition, it is replaced by a real table item data.
You can declare more such \"declaration letters" if you want.
+
+ Note, that the `##` with fills are in group. The reason can be explained
+ by following example:
+ \begtt
+ \table{|c|c|}{\crl \Red A & B \crl}
+ \endtt
+ We don't want vertical line after red A to be in red.
\_cod -----------------------------
-\_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 \_partabitem{##}}\_the\_tabitemr}
+\_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}
\_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 \`\_paramtabdeclarep``{<data>}` is invoked when `p{<data>}`
+ declarator is used. First, it saves the `\hsize` value
+ and then it runs \`\_tablepar`.
+ The \^`\_tablepar` macro behaves like \`\_tableparbox` (which is `\vtop`) in normal cases.
+ But there is a special case: if the first pass of `pxto` table is
+ processed then `\hsize` is negative. We print nothing in this case, i.e.\
+ \^`\_tableparbox` is \^`\ignoreit` and 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`.
+ \^`\_tsizesum` and \^`\_tsizelast` are initialized in the \^`\_tableB` macro.
\_cod -----------------------------
-\_newdimen \_tsizesum
-\_def \_tsizelast{0}
-\_long\_def\_partabitem#1{%
+\_def\_paramtabdeclarep#1{\_hsize=#1\_relax
+ \_the\_tabiteml \_tablepar{\_tableparB ##\_tableparC}\_the\_tabitemr
+}
+\_def\_tablepar{%
\_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
+ \_let\_tableparbox=\_ignoreit
\_fi
+ \_tableparA \_tableparbox
+}
+\_let \_tableparbox=\_vtop
+\_let \_tableparA=\_empty
+\_newdimen \_tsizesum
+\_def \_tsizelast{0}
+
+ \_doc -----------------------------
+ The \`\_tableparB` initializes the paragraphs inside the table item and
+ \`\_tableparC` closes them. They are used in the \^`\_paramtabdeclarep` macro.
+ The first paragraph is no indented.
+ \_cod -----------------------------
+
+\_def\_tableparB{%
+ \_baselineskip=\_normalbaselineskip \_lineskiplimit=\_zo \_noindent
+ \_raise\_ht\_tstrutbox\_null \_hskip\_zo \_relax
+}
+\_def\_tableparC{%
+ \_unsskip
+ \_ifvmode\_vskip\_dp\_tstrutbox \_else\_lower\_dp\_tstrutbox\_null\_fi
}
-\_let\_partabitemA=\_useit
\_doc -----------------------------
Users put optional spaces around the table item typically, i.e.\ they write
@@ -274,19 +286,33 @@
\_doc -----------------------------
The \`\fL`, \`\fR`, \`\fC` and \`\fX` macros only do special parameters settings
- for paragraph building algorithm. The \`\fS` prints the paragraph into
- box 0 first, measures the number of lines by the `\prevgraf` primitive
- and use (or don't use) `\hfil` (for centering) before the first line.
- \_cod -----------------------------
+ for paragraph building algorithm.
+ \_cod
\_let\_fL=\_raggedright
\_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}
-\_def\_fS{\_long\_def\_partabitemA##1{%
- \_setbox0=\_vbox{\_noindent ##1\_endgraf \_ea}\_ifnum\_prevgraf=1 \_hfil \_fi ##1%
-}}
-\_public \fL \fR \fC \fX \fS ;
+\_public \fL \fR \fC \fX ;
+
+ \_doc -----------------------------
+ The \`\fS` macro is more tricky. The \^`\_tableparbox` isn't printed
+ immediatelly, but `\setbox2=` is prefixed by the macro \`\_tableparA`,
+ which is empty by default (used in \^`\_tablepar`). The \`\_tableparD`
+ is processed after the box is set: it checks if there is only one line
+ and prints `\hbox to\hsize{\hfil<this line>\hfil}` in this case. In other
+ cases, the box2 is printed.
+ \_cod -----------------------------
+
+\_def\_fS{\_relax
+ \_ifdim\_hsize<0pt \_else \_def\_tableparA{\_setbox2=}\_fi
+ \_addto\_tableparC{\_aftergroup\_tableparD}%
+}
+\_def\_tableparD{\_setbox0=\_vbox{\_unvcopy2 \_unskip \_global\_setbox1=\_lastbox}%
+ \_ifdim\_ht0>0pt \_box2 \_setbox0=\_box1
+ \_else \_hbox to\_hsize{\_hfil \_unhbox1\_unskip\_unskip\_hfil}\_setbox0=\_box2 \_fi
+}
+\_public \fS ;
\_doc -----------------------------
The family of `\_cr*` macros
@@ -334,7 +360,7 @@
\_def\_mspan{\_omit \_afterassignment\_mspanA \_mscount=}
\_def\_mspanA[#1]#2{\_loop \_ifnum\_mscount>1 \_cs{_span}\_omit \_advance\_mscount-1 \_repeat
\_count1=\_colnum \_colnum=0 \_def\_tmpa{}\_tabdata={}\_scantabdata#1\_relax
- \_colnum=\_count1 \_setbox0=\_vbox{\_halign\_ea{\_ea\_bgroup\_the\_tabdata\_egroup\_cr#2\_cr}%
+ \_colnum=\_count1 \_setbox0=\_vbox{\_halign\_ea{\_the\_tabdata\_cr#2\_cr}%
\_global\_setbox8=\_lastbox}%
\_setbox0=\_hbox{\_unhbox8 \_unskip \_global\_setbox8=\_lastbox}%
\_unhbox8 \_ignorespaces}
@@ -557,6 +583,9 @@ after the second one.
\_endinput
+2021-08-04 \_patamtabdeclarep reimplemented.
+2021-07-16 grouping based on colors via attributes.
+2021-06-03 \scantextokens added to \_partabitem, bug fixed.
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