summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/tabl-ntb.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/tabl-ntb.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/tabl-ntb.mkiv188
1 files changed, 98 insertions, 90 deletions
diff --git a/Master/texmf-dist/tex/context/base/tabl-ntb.mkiv b/Master/texmf-dist/tex/context/base/tabl-ntb.mkiv
index b24eaa85d3c..96b1aabed82 100644
--- a/Master/texmf-dist/tex/context/base/tabl-ntb.mkiv
+++ b/Master/texmf-dist/tex/context/base/tabl-ntb.mkiv
@@ -14,6 +14,7 @@
%D This is an unfinished, preliminary module. At least two
%D runs are needed to get the table fixed. Ugly code.
+% todo: TABLE TBL -> ntb
% todo: special parsetb for argless variant
% todo: protect \tbl...
% todo: tblnx also count
@@ -21,6 +22,22 @@
% todo: fast if
% todo: avoid halign (just do it manual) and thereby globals
+% \unexpanded\def\startrow {\bTR}
+% \unexpanded\def\stoprow {\eTR}
+% \unexpanded\def\startcell#1\stopcell{\bTD#1\eTD}
+% \let\stopcell \relax
+% \let\startcelltable \bTABLE
+% \let\stopcelltable \eTABLE
+
+% \starttext
+% \startcelltable
+% \startrow \startcell a \stopcell \stoprow
+% \startrow \startcell a \stopcell \stoprow
+% \startrow \startcell a \stopcell \stoprow
+% \startrow \startcell a \stopcell \stoprow
+% \stopcelltable
+% \stoptext
+
% optie=rek beschrijven
\writestatus{loading}{ConTeXt Table Macros / Natural Tables}
@@ -99,8 +116,11 @@
%D
%D \typebuffer \getbuffer
+\let\dotagTABLEalign\relax
+
\def\bTBLCELL % why not \doinhibitblank
{\inhibitblank
+ \dotagTABLEalign
\doconvertfont\tbltblstyle\empty
\everypar{\tbltblleft\delayedbegstrut}}
@@ -273,7 +293,7 @@
\processcommalist[#1]\dodosetupTABLE}
\def\nopTABLEparameters[#1][#2]%
- {\letvalue{\@@tblprefix#1}\empty}
+ {\letvalueempty{\@@tblprefix#1}} % can be made faster
\def\setTABLEparameters[#1][#2]%
{\pushTBLparameters
@@ -466,17 +486,17 @@
\newcount\currentcol
\newcount\tblspn
-\def\parseTR[#1][#2]% [#2] is dummy that kills spaces / no #3 argument
+\def\settblref#1#2{\expandafter\xdef\csname\@@tblprefix\number#1:\number#2:x\endcsname}
+\def\gettblref#1#2{\ifcsname\@@tblprefix\number#1:\number#2:x\endcsname\csname\@@tblprefix\number#1:\number#2:x\endcsname\fi}
+
+\def\parseTR[#1]%
{\currentcol\zerocount
\advance\maximumrow\plusone
\iffirstargument
\setvalue{\@@tblprefix\c!y++\number\maximumrow}{\getparameters[\@@tbl\@@tbl][#1]}% maybe also in mkii
\fi}
-\def\settblref#1#2{\expandafter\xdef\csname\@@tblprefix\number#1:\number#2:x\endcsname}
-\def\gettblref#1#2{\ifcsname\@@tblprefix\number#1:\number#2:x\endcsname\csname\@@tblprefix\number#1:\number#2:x\endcsname\fi}
-
-\long\def\parseTD[#1][#2]#3\eTD % [#2] is dummy that kills spaces
+\long\def\parseTD[#1]#2\eTD
{\def\tblny{\tblnr}%
\def\tblnx{\tblnc}%
\let\tblnc\plusone
@@ -493,7 +513,7 @@
\else\ifnum\@@tblnindeed=\currentcol\else
\scratchcounter\numexpr\@@tblnindeed-\currentcol+\minusone-\tblspn\relax
\ifnum\scratchcounter>\zerocount
- \normalexpanded{\noexpand\parseTD[\c!nx=\the\scratchcounter,\c!n=,\c!m=,*sq=\v!no][]}\eTD
+ \normalexpanded{\noexpand\parseTD[\c!nx=\the\scratchcounter,\c!n=,\c!m=,*sq=\v!no]}\eTD
\fi
% can also be made faster
\getparameters[\@@tbl][\c!ny=\tblnr,\c!nx=\tblnc,nc=1,nr=1,#1,\c!n=,\c!m=]%
@@ -502,7 +522,7 @@
\ifx\@@tblmindeed\empty \else
\ifnum\@@tblmindeed=\currentcol \else
\scratchcounter\numexpr\@@tblmindeed-\currentcol+\minusone-\tblspn\relax
- \dorecurse\scratchcounter{\normalexpanded{\noexpand\parseTD[\c!n=,\c!m=][]}\eTD}%
+ \dorecurse\scratchcounter{\normalexpanded{\noexpand\parseTD[\c!n=,\c!m=]}\eTD}%
% can be sped up
\getparameters[\@@tbl][\c!ny=\tblnr,\c!nx=\tblnc,nc=1,nr=1,#1,\c!n=,\c!m=]% kind of double, see prev
\fi
@@ -527,10 +547,11 @@
\lettbltag\maximumrow\currentcol\tblcell
\settblcol\maximumrow\currentcol{\number\tblnx}%
\settblrow\maximumrow\currentcol{\number\tblny}%
+ % the action key will change!
\settblref\maximumrow\currentcol{\ifcsname\@@tbl\c!action\endcsname\csname\@@tbl\c!action\endcsname\fi}%
% save text
\edef\celltag{{\number\maximumrow}{\number\currentcol}}%
- \@EA\settbltxt\@EA\maximumrow\@EA\currentcol\@EA{\@EA\handleTBLcell\celltag[#1]{#3}}}
+ \@EA\settbltxt\@EA\maximumrow\@EA\currentcol\@EA{\@EA\handleTBLcell\celltag[#1]{#2}}}
\def\presetTBLcell
{\row\maximumrow
@@ -588,8 +609,6 @@
\long\def\parseTH[#1]#2\eTH
{\parseTD[#1,\c!color=\tbltblheadcolor,\c!style=\tbltblheadstyle,\c!aligncharacter=\v!no]#2\eTD}
-
-%D new
\long\def\parseTN[#1]#2\eTN
{\parseTD[#1]\digits#2\relax\eTD}
@@ -664,14 +683,14 @@
\let\pushTBL\relax
\let\popTBL \relax
-\chardef\tblpass=0
+\newconstant\tblpass
\def\presetallTABLEparameters% each odd|even level / can be sped up but only once per table
{\executeifdefined{\@@rawtblprefix\v!start\v!each}\relax
\executeifdefined{\@@rawtblprefix\v!start\v!oddeven\TBLlevel}\relax
\executeifdefined{\@@rawtblprefix\v!start\number\TBLlevel}\relax}
-\def\bTABLE
+\unexpanded\def\bTABLE
{\dosingleempty\dobTABLE}
\def\dobTABLE[#1]%
@@ -700,7 +719,7 @@
[\tbltblheader]
[\v!repeat=>\multipleTBLheadstrue]%
\presetallTABLEparameters
- \ExpandFirstAfter\processallactionsinset
+ \processallactionsinset
[\tbltbloption]
[\v!stretch=>\autoTBLspreadtrue]%
\linewidth\tbltblrulethickness % needs to be frozen
@@ -714,19 +733,19 @@
\let\bTH\dobTH
\let\bTN\dobTN}
-\unexpanded\def\dobTR{\dodoubleempty\parseTR}
-\unexpanded\def\dobTD{\dodoubleempty\parseTD}
-\unexpanded\def\dobTH{\dodoubleempty\parseTH}
-\unexpanded\def\dobTN{\dodoubleempty\parseTN}
+\unexpanded\def\dobTR{\dosingleempty\parseTR}
+\unexpanded\def\dobTD{\dosingleempty\parseTD}
+\unexpanded\def\dobTH{\dosingleempty\parseTH}
+\unexpanded\def\dobTN{\dosingleempty\parseTN}
% permits \expanded{\bTD ... \eTD}
-\unexpanded\def\eTR{\ignorespaces} % handy in case we use a macro to generate rows
-\unexpanded\def\eTD{\ignorespaces}
-\unexpanded\def\eTH{\ignorespaces}
-\unexpanded\def\eTN{\ignorespaces}
+\let\bTR\relax \unexpanded\def\eTR{\ignorespaces} % handy in case we use a macro to generate rows
+\let\bTD\relax \unexpanded\def\eTD{\ignorespaces}
+\let\bTH\relax \unexpanded\def\eTH{\ignorespaces}
+\let\bTN\relax \unexpanded\def\eTN{\ignorespaces}
-\def\eTABLE % beware, we need to get rid of spurious spaces when in hmode
+\unexpanded\def\eTABLE % beware, we need to get rid of spurious spaces when in hmode
{% tricky and dirty order -)
\doifsometokselse\TBLhead % slow, better a flag
{\the\TBLhead
@@ -833,7 +852,7 @@
\def\eTBL{\tbltoks\@EA\@EA\@EA{\@EA\the\@EA\tbltoks\@EA\begintblrow\the\tblrowtoks\endtblrow}}%
\def\prelocateTBLerror
- {\writestatus\m!systems{fatal error: use \string\prelocateTBLrows\space to increase table memory (now: \number\prelocatedTBLrows)}}
+ {\writestatus\m!system{fatal error: use \string\prelocateTBLrows\space to increase table memory (now: \number\prelocatedTBLrows)}}
\def\prelocateTBLrows#1% we start at zero so we have one to much, better play safe anyway
{\dostepwiserecurse\prelocatedTBLrows{#1}\plusone{\expandafter\newtoks\csname tbl:\recurselevel\endcsname}%
@@ -885,8 +904,12 @@
\crcr
\noalign
{\nointerlineskip
- \ifnum\gettblnob\tblrow=\zerocount
- \allowbreak
+ \ifnum\tblrow>\noftblheadlines
+ \ifnum\gettblnob\tblrow=\zerocount
+ \allowbreak
+ \fi
+ \else
+ \allowbreak % else no proper head split off
\fi
\bgroup % protect local vars
\@@tblsplitafter
@@ -900,18 +923,38 @@
\fi
\egroup}}
+% \def\begintbl
+% {\global\tblspn\zerocount
+% \global\tblcol\zerocount
+% \global\tblrow\zerocount
+% \global\advance\tblrow\minusone
+% \tabskip\zeropoint
+% \halign\bgroup
+% \registerparoptions % new
+% \ignorespaces##\unskip&&\ignorespaces##\unskip\cr}
+
+% \def\endtbl
+% {\egroup}
+
+\let\dotagTABLEcell\relax
+
\def\begintbl
{\global\tblspn\zerocount
\global\tblcol\zerocount
\global\tblrow\zerocount
\global\advance\tblrow\minusone
\tabskip\zeropoint
+ \dostarttagged\t!table\empty
+ \dostarttagged\t!tablerow\empty
+ \appendtoks\dostoptagged\dostarttagged\t!tablerow\empty\to\everycr
\halign\bgroup
- \registerparoptions % new
- \ignorespaces##\unskip&&\ignorespaces##\unskip\cr}
+ \registerparoptions
+ % watch out: tagging the cell happens at the outer level (faster)
+ \ignorespaces##\unskip&&\dostarttagged\t!tablecell\empty\ignorespaces##\unskip\dostoptagged\cr} % one too many
\def\endtbl
- {\egroup}
+ {\dostoptagged\egroup
+ \dostoptagged}
\setvalue{\tblnone TBL}#1#2%
{\spanTBL{#1}{#2}}
@@ -936,10 +979,16 @@
{\global\tblspn\zerocount
\global\tblrow\zerocount
\global\tblcol\zerocount
- \chardef\tblpass\zerocount
+ \tblpass\zerocount
\tbltoks\emptytoks}
-\def\flushtbltoks{\begintbl\the\tbltoks\endtbl}
+\newtoks\everyTABLEpass
+
+\def\flushtbltoks
+ {\the\everyTABLEpass
+ \begintbl
+ \the\tbltoks
+ \endtbl}
\def\domakeTBLone#1 #2 %
{\gettbltxt{#1}{#2}}%
@@ -960,11 +1009,16 @@
\settblhei{#1}{\the\ht\scratchbox}%
\fi}%
+\let\dotagnoftablecolumns\relax
+\let\dotagnoftablerows \relax
+
\def\domakeTBLthree#1 #2 %
{% height
\!!counta \gettblcol{#1}{#2}\relax
\!!countb \gettblrow{#1}{#2}\relax
\!!heighta\gettblht {#1}{#2}\relax
+\dotagnoftablecolumns
+\dotagnoftablerows
\scratchdimen\zeropoint
\ifnum\!!counta=\maximumcol\relax
% case: nc=maxcolumns
@@ -1003,11 +1057,10 @@
\else
\normalexpanded{\noexpand\directgotobox{\box\scratchbox}[\!!stringa]}% to be checked
\fi
- \box\scratchbox}
+ \dotagTABLEcell} % right spot
\def\inTBLcell#1#2% hm, do we need #1 #2 ? we use tblcol anyway
- {\ExpandBothAfter\doifinsetelse\localwidth{\v!fit,\v!broad} % user set
- {}
+ {\doifnotinset\localwidth{\v!fit,\v!broad}% user set
{\scratchdimen\gettblaut\tblcol\relax
\ifdim\localwidth>\scratchdimen
\settblaut\tblcol{\the\dimexpr\localwidth\relax}%
@@ -1032,11 +1085,11 @@
\lettbldis\recurselevel\zeropoint}%
\dorecurse\maximumrow
{\lettblhei\recurselevel\maxdimen}%
- \chardef\tblpass\plusone
+ \tblpass\plusone
\let\makeTBL\domakeTBLone
\let\handleTBLcell\dohandleTBLcellA
- \setbox0\vbox{\trialtypesettingtrue \flushtbltoks}%
-% \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
+ \setbox0\vbox{\settrialtypesetting \flushtbltoks}%
+% \setbox\scratchbox\vbox{\settrialtypesetting \flushtbltoks}%
\lettbldis\maximumcol\zeropoint
\ifautoTBLspread
% experimental, stretch non fixed cells to \hsize
@@ -1044,13 +1097,13 @@
\checktblwidthstwo % real run
\stretchtblwidths
\let\handleTBLcell\dohandleTBLcellB
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
+ \setbox\scratchbox\vbox{\settrialtypesetting \flushtbltoks}%
\else\ifdim\wd0>\hsize
\ifautoTBLhsize
\checktblwidthsone % trial run
\checktblwidthstwo % real run
\let\handleTBLcell\dohandleTBLcellB
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
+ \setbox\scratchbox\vbox{\settrialtypesetting \flushtbltoks}%
\fi
\else\ifautoTBLrowspan\ifnum\maximumrowspan>1 % max ?
% added jan 2002 because nx=* did no longer work
@@ -1061,16 +1114,16 @@
\hsize\savedhsize
%
\let\handleTBLcell\dohandleTBLcellC
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
+ \setbox\scratchbox\vbox{\settrialtypesetting \flushtbltoks}%
\fi\fi\fi\fi
\let\handleTBLcell\dohandleTBLcellD
- \chardef\tblpass\plustwo
+ \tblpass\plustwo
\let\makeTBL\domakeTBLtwo
- \setbox\scratchbox\vbox{\trialtypesettingtrue \flushtbltoks}%
+ \setbox\scratchbox\vbox{\settrialtypesetting \flushtbltoks}%
\checktblheightsone
\checktblheightstwo
\let\handleTBLcell\dohandleTBLcellE
- \chardef\tblpass\plusthree
+ \tblpass\plusthree
\let\makeTBL\domakeTBLthree
\ifnum\TBLlevel>\plusone
\@EA\notsplittblbox
@@ -1348,7 +1401,7 @@
\fi
\fi
\fi
- \setbox2\null
+ \setbox2\emptyhbox
\wd2\wd\scratchbox \ht2\ht\scratchbox \dp2\dp\scratchbox
\box2
\egroup}
@@ -1360,7 +1413,7 @@
[\@@tbl\@@tbl]
[#4,#1,\c!frame=\v!off,\c!background=]
{\bTBLCELL#5\eTBLCELL}}%
- \setbox2\null
+ \setbox2\emptyhbox
\wd2\wd\scratchbox \ht2\ht\scratchbox \dp2\dp\scratchbox
\ifautoTBLrowspan
\scratchcounter\numexpr\tblrow+\plusone\relax
@@ -1546,51 +1599,6 @@
\fi
\fi}
-%D Spacing:
-%
-% \starttabulate
-% \NC text \NC text \NC \NR
-% \TB[small]
-% \NC text \NC text \NC \NR
-% \TB[4*big]
-% \NC text \NC text \NC \NR
-% \stoptabulate
-%
-% \starttable[|||]
-% \VL text \VL text \VL \AR
-% \TB[small]
-% \VL text \VL text \VL \AR
-% \TB[4*big]
-% \VL text \VL text \VL \AR
-% \stoptable
-
-\def\complexTableTB[#1]{\TABLEnoalign{\blank[#1]}}
-\def\simpleTableTB {\TABLEnoalign{\blank}}
-
-\def\TabulateTB
- {\complexorsimpleTable{TB}}
-
-\def\doTableinterline% #1
- {\ifnum\currentTABLEcolumn>\maxTABLEcolumn
- \chuckTABLEautorow
- \else\ifnum\currentTABLEcolumn=\zerocount
- \TABLEnoalign
- {\globalletempty\checkTABLEautorow
- \globalletempty\chuckTABLEautorow}%
- \else
- \setTABLEerror\TABLEmissingcolumn
- \handleTABLEerror
- \fi\fi
- \complexorsimpleTable} % {#1}
-
-\def\TableHL{\doTableinterline{HL}}
-\def\TableTB{\doTableinterline{TB}}
-
-\appendtoks\let\TB\TableTB \to\everytable
-\appendtoks\let\TB\TabulateTB\to\everytabulate % strange place
-
-\appendtoks \chardef\recodeverbatimmode\plustwo \to \everytable
-
% new (for Olivier Turlier)
%
% \defineTABLEsetup [xx] [foregroundcolor=red]