summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv245
1 files changed, 122 insertions, 123 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv b/Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv
index ca3d78800ac..8ff02330a9a 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv
+++ b/Master/texmf-dist/tex/context/base/mkiv/tabl-ntb.mkiv
@@ -11,13 +11,12 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-%D This module has a more modern variant in xtables but as we follow a bit
-%D different approach with settings there, this mechanism will stay. In fact
-%D each of them has its advantages. This module could be sped up a bit and made
-%D more efficient by delegating some housekeeping to \LUA\ but it's not worth
-%D the effort. The code could me made more readable but again, there is no
-%D real purpose in it. If needed I can squeeze out a few more percentages
-%D runtime.
+%D This module has a more modern variant in xtables but as we follow a bit different
+%D approach with settings there, this mechanism will stay. In fact each of them has
+%D its advantages. This module could be sped up a bit and made more efficient by
+%D delegating some housekeeping to \LUA\ but it's not worth the effort. The code
+%D could me made more readable but again, there is no real purpose in it. If needed
+%D I can squeeze out a few more percentages runtime.
% columndistance 'optimized' ... needs checking
%
@@ -27,8 +26,8 @@
% sometimes this helps (with nc going wild): \setupTABLE[maxwidth=100cm]
%
-% bug: width 3cm is not honored and column becomes too wide
-% as given width is added to distributed width
+% bug: width 3cm is not honored and column becomes too wide as given width is added
+% to distributed width
%
% \bTABLE
% \bTR
@@ -61,16 +60,14 @@
% \stopcelltable
% \stoptext
-%D As always, this is the n\high{th} version. Much time went in
-%D trying to speed up the many cell calculations, some
-%D optimizations were rejected in order not to complicate this
-%D module too much (and in order to prevail extensibility). In the
+%D As always, this is the n\high{th} version. Much time went in trying to speed up
+%D the many cell calculations, some optimizations were rejected in order not to
+%D complicate this module too much (and in order to prevail extensibility). In the
%D meantime we've sacrified some speed for readability.
\unprotect
-%D The next alternative also takes care of preceding and following
-%D white space.
+%D The next alternative also takes care of preceding and following white space.
%D
%D \startbuffer
%D \bTABLE[left={(},right={)},top=\startnarrower,bottom=\stopnarrower]
@@ -203,25 +200,35 @@
\newbox\b_tabl_ntb_final
-%D We have already prepared the previous macros for nesting,
-%D so we only have to pop in the right ones:
+%D For tagging and export:
+
+\newconstant \c_tabl_ntb_head
+\newconstant \c_tabl_ntb_body
+\newconstant \c_tabl_ntb_foot
+\newconditional \c_tabl_ntb_okay
+
+%D We have already prepared the previous macros for nesting, so we only have to pop
+%D in the right ones:
\newcount\c_tabl_level
+\installglobalmacrostack\m_tabl_ntb_saved_row
+\installglobalmacrostack\m_tabl_ntb_saved_col
+
\unexpanded\def\tabl_ntb_table_push
{\ifnum\m_tabl_tbl_level>\plusone
\tabl_ntb_parameters_reset
% we need a proper count push/pop
- \xdef\m_tabl_ntb_saved_row{\the\c_tabl_ntb_row}\globalpushmacro\m_tabl_ntb_saved_row
- \xdef\m_tabl_ntb_saved_col{\the\c_tabl_ntb_col}\globalpushmacro\m_tabl_ntb_saved_col
+ \xdef\m_tabl_ntb_saved_row{\the\c_tabl_ntb_row}\push_macro_m_tabl_ntb_saved_row
+ \xdef\m_tabl_ntb_saved_col{\the\c_tabl_ntb_col}\push_macro_m_tabl_ntb_saved_col
\else
\global\intabletrue
\fi}
\unexpanded\def\tabl_ntb_table_pop
{\ifnum\m_tabl_tbl_level>\plusone
- \globalpopmacro\m_tabl_ntb_saved_row\global\c_tabl_ntb_row\m_tabl_ntb_saved_row
- \globalpopmacro\m_tabl_ntb_saved_col\global\c_tabl_ntb_col\m_tabl_ntb_saved_col
+ \pop_macro_m_tabl_ntb_saved_row\global\c_tabl_ntb_row\m_tabl_ntb_saved_row
+ \pop_macro_m_tabl_ntb_saved_col\global\c_tabl_ntb_col\m_tabl_ntb_saved_col
\else
\global\intablefalse
\fi}
@@ -858,8 +865,8 @@
\def\tabl_ntb_tn[#1]#2\eTN
{\tabl_ntb_td[#1]\digits#2\relax\eTD}
-%D Vit Zyka needed the option to create a distance between columns, so I
-%D added support for individual column distances.
+%D Vit Zyka needed the option to create a distance between columns, so I added
+%D support for individual column distances.
%D
%D \startbuffer
%D % \setupTABLE[c][each][distance=2em]
@@ -881,9 +888,8 @@
%D
%D \typebuffer \startlinecorrection \getbuffer \stoplinecorrection
%D
-%D and he provided patches for the global left and right margin distances
-%D as well as the columndistance (although i changed the names -). Here
-%D is his testcase:
+%D and he provided patches for the global left and right margin distances as well as
+%D the columndistance (although i changed the names -). Here is his testcase:
%D
%D \startbuffer
%D \framed[offset=overlay]\bgroup
@@ -992,6 +998,8 @@
\let\nofTABLErows \!!zerocount
\let\nofTABLEcolumns \!!zerocount
+% there is no gain in a \doifelsenextoptionalcs variant
+
\unexpanded\def\dobTR{\dosingleempty\tabl_ntb_tr} % also used in tabl-nte
\unexpanded\def\dobTD{\dosingleempty\tabl_ntb_td} % also used in tabl-nte
\unexpanded\def\dobTH{\dosingleempty\tabl_ntb_th} % also used in tabl-nte
@@ -1006,19 +1014,30 @@
\unexpanded\def\eTABLE % beware, we need to get rid of spurious spaces when in hmode
{% tricky and dirty order -)
+ \setfalse\c_tabl_ntb_okay
+ % head
\doifelsesometoks\t_tabl_ntb_head % slow, better a flag
- {\the\t_tabl_ntb_head
+ {\c_tabl_ntb_head\numexpr\c_tabl_ntb_maximum_row+\plusone\relax
+ \the\t_tabl_ntb_head
\c_tabl_ntb_n_of_head_lines\c_tabl_ntb_maximum_row\relax
\doifelsesometoks\t_tabl_ntb_next
{\the\t_tabl_ntb_next
\c_tabl_ntb_n_of_next_lines\numexpr\c_tabl_ntb_maximum_row-\c_tabl_ntb_n_of_head_lines\relax}%
{\c_tabl_ntb_n_of_next_lines\zerocount}% was 1
\c_tabl_ntb_n_of_hdnx_lines\c_tabl_ntb_maximum_row}
- {\c_tabl_ntb_n_of_head_lines\zerocount % was 1
+ {\c_tabl_ntb_head\zerocount
+ \c_tabl_ntb_n_of_head_lines\zerocount % was 1
\c_tabl_ntb_n_of_next_lines\zerocount
\c_tabl_ntb_n_of_hdnx_lines\zerocount}%
+ % body
+ \c_tabl_ntb_body\numexpr\c_tabl_ntb_maximum_row+\plusone\relax
\the\t_tabl_ntb_body
- \the\t_tabl_ntb_foot
+ % foot
+ \doifelsesometoks\t_tabl_ntb_foot
+ {\c_tabl_ntb_foot\numexpr\c_tabl_ntb_maximum_row+\plusone\relax
+ \the\t_tabl_ntb_foot}%
+ {\c_tabl_ntb_foot\zerocount}%
+ % done
\removeunwantedspaces % only if hmode
% finish cells
\tabl_ntb_loop_one
@@ -1228,25 +1247,76 @@
\def\tabl_ntb_prelocate_okay
{\expandafter\let\expandafter\t_tabl_ntb_row\csname\??naturaltabletok\the\c_tabl_ntb_row\endcsname\t_tabl_ntb_row\emptytoks}
-% We use aligments to handle the empty (skipped) columns, so
-% that we don't have to (re|)|calculate these.
+%D We use aligments to handle the empty (skipped) columns, so that we don't have to
+%D (re|)|calculate these.
\let\m_tabl_ntb_saved_row\!!zerocount
\let\m_tabl_ntb_saved_col\!!zerocount
+\def\tabl_ntb_start_tagged
+ {\scratchcounter\numexpr\c_tabl_ntb_row+\plusone\relax
+ \ifnum\scratchcounter=\c_tabl_ntb_head
+ \ifconditional\c_tabl_ntb_okay
+ \dostoptagged
+ \else
+ \settrue\c_tabl_ntb_okay
+ \fi
+ \dostarttagged\t!tablehead\empty
+ \else\ifnum\scratchcounter=\c_tabl_ntb_body
+ \ifconditional\c_tabl_ntb_okay
+ \dostoptagged
+ \else
+ \settrue\c_tabl_ntb_okay
+ \fi
+ \dostarttagged\t!tablebody\empty
+ \else\ifnum\scratchcounter=\c_tabl_ntb_foot
+ \ifconditional\c_tabl_ntb_okay
+ \dostoptagged
+ \else
+ \settrue\c_tabl_ntb_okay
+ \fi
+ \dostarttagged\t!tablefoot\empty
+ \fi\fi\fi
+ \dostarttagged\t!tablerow\empty}
+
+\def\tabl_ntb_stop_tagged
+ {\dostoptagged
+ \ifconditional\c_tabl_ntb_okay
+ \scratchcounter\numexpr\c_tabl_ntb_row+\plustwo\relax
+ \ifnum\scratchcounter=\c_tabl_ntb_body
+ \dostoptagged
+ \setfalse\c_tabl_ntb_okay
+ \else\ifnum\scratchcounter=\c_tabl_ntb_foot
+ \dostoptagged
+ \setfalse\c_tabl_ntb_okay
+ \else\ifnum\scratchcounter>\c_tabl_ntb_maximum_row
+ \dostoptagged
+ \setfalse\c_tabl_ntb_okay
+ \fi\fi\fi
+ \fi}
+
\unexpanded\def\tabl_ntb_row_align_start
{\global\advance\c_tabl_ntb_row\plusone
\global\c_tabl_ntb_col\plusone
\global\c_tabl_ntb_spn\zerocount
\tabl_ntb_row_align_start_inject
- \dostarttagged\t!tablerow\empty
- \hbox\bgroup
- \kern\dimexpr\d_tabl_ntb_leftmargindistance\relax}
+ \ifconditional\c_strc_tags_enabled
+ \tabl_ntb_start_tagged
+ \fi
+ % we are in sync but just to be sure:
+ \synchronizedisplaydirection
+ \synchronizeinlinedirection
+ \hbox
+ \usedirectionparameterreverse\naturaltablelocalparameter
+ \bgroup
+ \kern\dimexpr\d_tabl_ntb_leftmargindistance\relax}
\unexpanded\def\tabl_ntb_row_align_stop
{\kern\dimexpr\d_tabl_ntb_rightmargindistance-\d_tabl_ntb_columndistance\relax
\egroup
- \dostoptagged
+ \ifconditional\c_strc_tags_enabled
+ \tabl_ntb_stop_tagged
+ \fi
\tabl_ntb_row_align_stop_inject}
\unexpanded\def\tabl_ntb_before_page
@@ -1723,12 +1793,14 @@
\tabl_ntb_set_aut\recurselevel{\the\scratchdimen}%
\fi
\else
- \ifdim\scratchdimen=\zeropoint % auto set width
+ \ifzeropt\scratchdimen % auto set width
\tabl_ntb_set_wid\recurselevel{\the\!!dimena}%
\fi
\fi}%
\ifconditional\c_tabl_ntb_trace_widths\tabl_ntb_show_widths E#1\fi}
+% todo: use scratchcounters, not !! ones
+
\def\tabl_ntb_check_heights_one_indeed
{\!!countb\tabl_ntb_get_row\c_tabl_ntb_current_row_three\c_tabl_ntb_current_col_three\relax
% check row span
@@ -1810,19 +1882,6 @@
{\writestatus\m!TABLE{\space\space\recurselevel: \the\dimexpr\tabl_ntb_get_wid\recurselevel}}%
\endgroup}
-% \def\tabl_ntb_char_align
-% {\doifelse{\naturaltablelocalparameter\c!aligncharacter}\v!yes
-% \tabl_ntb_char_align_indeed\gobbletwoarguments}
-
-% \def\tabl_ntb_char_align_indeed#1#2#3% row column data
-% {\edef\alignmentclass{#2}%
-% \edef\alignmentcharacter{\naturaltablelocalparameter\c!alignmentcharacter}%
-% \ifcase\c_tabl_tbl_pass\or
-% \setfirstpasscharacteralign\checkalignment{#3}% {\strut#2\unskip}%
-% \fi % force hsize, so always a second
-% \setsecondpasscharacteralign \checkalignment{#3}% {\strut#2\unskip}%
-% \ignorespaces}
-
\def\tabl_ntb_char_align % called often
{\edef\p_characteralign{\naturaltablelocalparameter\c!aligncharacter}%
\ifx\p_characteralign\v!yes
@@ -1852,25 +1911,12 @@
\unexpanded\def\tabl_ntb_cell_process_x#1#2[#3]#4%
{}
-% problem: when span doesn't break we can have a span that is the sum of
-% cells but still to small .. chicken egg problem ... for that we should
-% also have a smallest width run
+% problem: when span doesn't break we can have a span that is the sum of cells but
+% still to small .. chicken egg problem ... for that we should also have a smallest
+% width run
%
% nilling the background makes a run upto 25% faster
-% \def\tabl_ntb_cell_process_a_check_span_one
-% {\ifautosqueezeTBLspan
-% \edef\p_width{\naturaltablelocalparameter\c!width}%
-% \csname\??naturaltablesqueeze\ifcsname\??naturaltablesqueeze\p_width\endcsname\p_width\fi\endcsname
-% \else
-% \donetrue
-% \fi
-% \ifdone % brr, 0
-% \ifnum\scratchcounter>\plusone
-% \tabl_ntb_set_spn\c_tabl_ntb_col
-% \fi
-% \fi}
-
\def\tabl_ntb_cell_process_a_check_span_one
{\ifautosqueezeTBLspan
\edef\p_width{\naturaltablelocalparameter\c!width}%
@@ -1884,47 +1930,6 @@
\fi
\fi}
-% \def\tabl_ntb_cell_process_a_check_span_two_yes
-% {\iftightTBLcolspan
-% \donefalse
-% \else
-% \ifnum\scratchcounter>\plusone
-% \begingroup
-% \edef\p_width{\naturaltablelocalparameter\c!width}%
-% \csname\??naturaltablesqueeze\ifcsname\??naturaltablesqueeze\p_width\endcsname\p_width\fi\endcsname
-% \ifdone
-% \endgroup
-% \edef\p_option{\naturaltablelocalparameter\c!option}%
-% \ifx\p_option\v!tight\donefalse\else\donetrue\fi
-% \else
-% % a dimension
-% \endgroup
-% \donefalse
-% \fi
-% \else
-% \edef\p_option{\naturaltablelocalparameter\c!option}%
-% \ifx\p_option\v!tight\donefalse\else\donetrue\fi
-% \fi
-% \fi
-% \ifdone
-% \ifdim\tabl_ntb_get_wid\c_tabl_ntb_col<\wd\scratchbox
-% \tabl_ntb_set_wid\c_tabl_ntb_col{\the\wd\scratchbox}%
-% \fi
-% \fi}
-
-% \def\tabl_ntb_cell_process_a_check_span_two_nop
-% {\ifnum\scratchcounter>\plusone
-% \edef\p_width{\naturaltablelocalparameter\c!width}%
-% \csname\??naturaltablesqueeze\ifcsname\??naturaltablesqueeze\p_width\endcsname\p_width\fi\endcsname
-% \else
-% \donetrue
-% \fi
-% \ifdone
-% \ifdim\tabl_ntb_get_wid\c_tabl_ntb_col<\wd\scratchbox
-% \tabl_ntb_set_wid\c_tabl_ntb_col{\the\wd\scratchbox}%
-% \fi
-% \fi}
-
\let\tabl_ntb_cell_process_a_check_span_two_yes\relax
\def\tabl_ntb_cell_process_a_check_span_two_nop
@@ -1948,9 +1953,9 @@
\anch_backgrounds_text_level_start
\inheritednaturaltablelocalframed{\tabl_ntb_cell_start\tabl_ntb_char_align{#1}{#2}#4\tabl_ntb_cell_stop\tabl_ntb_cell_finalize}%
\anch_backgrounds_text_level_stop
-\ifcase\c_anch_backgrounds_text_count\else
- \tabl_ntb_let_bck{#1}{#2}\c_anch_backgrounds_text_state
-\fi
+ \ifcase\c_anch_backgrounds_text_count\else
+ \tabl_ntb_let_bck{#1}{#2}\c_anch_backgrounds_text_state
+ \fi
}%
\scratchdimen\tabl_ntb_get_wid\c_tabl_ntb_col\relax
\ifdim\wd\scratchbox>\scratchdimen
@@ -1972,7 +1977,7 @@
\ifdim\wd\scratchbox<.75\hsize % fuzzy guess
\ifdim\ht\scratchbox>2\openlineheight % honor width since this
\scratchdimen\tabl_ntb_get_aut\c_tabl_ntb_col\relax % can be a figure or so
- \ifdim\scratchdimen=\zeropoint
+ \ifzeropt\scratchdimen
% side effect: when width is set to 0pt,
% we can force a span that fits the sum of spans widths
\tabl_ntb_set_aut\c_tabl_ntb_col{\the\scratchdimen}%
@@ -2050,16 +2055,16 @@
[\naturaltablelocalparameter\c!color] % as well as permits local colors to take precedence
{\letnaturaltablelocalparameter\c!color\empty
\setnaturaltablelocalparameter\c!width{\d_tabl_ntb_width}%
- \ifdim\d_tabl_ntb_height=\zeropoint\relax % case: nc=maxcolumns
+ \ifzeropt\d_tabl_ntb_height % case: nc=maxcolumns
\else
\setnaturaltablelocalparameter\c!height{\d_tabl_ntb_height}%
\fi
-\ifcase\c_anch_backgrounds_text_count\else
- \edef\p_region{\naturaltablelocalparameter\c!region}%
- \ifx\p_region\empty\ifnum\tabl_ntb_get_bck{#1}{#2}>\zerocount
- \letnaturaltablelocalparameter\c!region\v!yes
- \fi\fi
-\fi
+ \ifcase\c_anch_backgrounds_text_count\else
+ \edef\p_region{\naturaltablelocalparameter\c!region}%
+ \ifx\p_region\empty\ifnum\tabl_ntb_get_bck{#1}{#2}>\zerocount
+ \letnaturaltablelocalparameter\c!region\v!yes
+ \fi\fi
+ \fi
\inheritednaturaltablelocalframed{\tabl_ntb_cell_start\tabl_ntb_char_align{#1}{#2}#4\tabl_ntb_cell_stop}}%
\hskip\tabl_ntb_get_dis{#2}}
@@ -2193,12 +2198,6 @@
\let\eTDs\relax
\let\eTRs\relax
-% \unexpanded\def\bTDs[#1]#2\eTDs
-% {\normalexpanded{\bTD[\ifcsname\??naturaltablesetup#1\endcsname\csname\??naturaltablesetup#1\endcsname\fi]}#2\eTD}
-%
-% \unexpanded\def\bTRs[#1]#2\eTRs
-% {\normalexpanded{\bTR[\ifcsname\??naturaltablesetup#1\endcsname\csname\??naturaltablesetup#1\endcsname\fi]}#2\eTR}
-
\unexpanded\def\bTDs[#1]#2\eTDs
{\normalexpanded{\bTD[\begincsname\??naturaltablesetup#1\endcsname]}#2\eTD}