tabl-pln.mkiv /size: 3533 b    last modification: 2020-07-01 14:35
1%D The following bunch of macros come from plain \TEX\ by
2%D Don Knuth and deal with basic alignment. We just include
3%D them here so that they can be used if needed. Normally,
4%D \CONTEXT\ users will fall back on one of the three table
5%D environments.
6%D
7%D The hidden names are somewhat adapted and we use other
8%D local variables.
9
10\writestatus{loading}{ConTeXt Table Macros / Plain Tabular}
11
12%D This code might become a module.
13
14\unprotect
15
16\newconditional \c_tabl_plain_cr
17\newconditional \c_tabl_plain_use_tab
18\newbox         \b_tabl_plain_tabs
19\newbox         \b_tabl_plain_tabs_yet
20\newbox         \b_tabl_plain_tabs_done
21\newdimen       \d_tabl_plain_tab
22
23\let\m_tabl_plain_next\relax
24
25\def\cleartabs % visible
26  {\global\setbox\b_tabl_plain_tabs_yet\emptyhbox
27   \setbox\b_tabl_plain_tabs\emptyhbox}
28
29\def\settabs % visible
30  {\setbox\b_tabl_plain_tabs\emptyhbox
31   \futurelet\m_tabl_plain_next\tabl_plain_set_tabs}
32
33\def\tabalign % visible
34  {\settrue\c_tabl_plain_use_tab
35   \tabl_plain_make_tab_box}
36
37\ifdefined\+ \else
38    \let\+\tabalign % no outer here (can be overloaded)
39\fi
40
41\def\tabl_plain_set_tabs
42  {\ifx\m_tabl_plain_next\+%
43     \let\tabl_plain_nxt\tabl_plain_align
44   \else\ifx\m_tabl_plain_next\tabalign % added hh
45     \let\tabl_plain_nxt\tabl_plain_align
46   \else
47     \let\tabl_plain_nxt\tabl_plain_set_cols
48   \fi\fi
49   \let\m_tabl_plain_next\relax
50   \tabl_plain_nxt}
51
52\def\tabl_plain_align
53  {\afterassignment\tabl_plain_set_tab
54   \let\tabl_plain_nxt}
55
56\def\tabl_plain_set_tab
57  {\let\tabl_plain_nxt\relax
58   \setfalse\c_tabl_plain_use_tab
59   \tabl_plain_make_tab_box}
60
61\def\tabl_plain_set_cols#1\columns
62  {\scratchcounter#1\relax
63   \d_tabl_plain_tab\hsize
64   \loop
65     \ifnum\scratchcounter>\zerocount
66       \tabl_plain_other
67   \repeat}
68
69\def\tabl_plain_other
70  {\scratchdimen\d_tabl_plain_tab
71   \divide\scratchdimen\scratchcounter
72   \setbox\b_tabl_plain_tabs\hbox
73     {\hbox to\scratchdimen{}%
74      \unhbox\b_tabl_plain_tabs}%
75   \advance\d_tabl_plain_tab-\scratchdimen
76   \advance\scratchcounter\minusone}
77
78\def\tabl_plain_make_tab_box
79  {\begingroup
80   \let\+\tabalign % added hh
81   \global\setbox\b_tabl_plain_tabs_yet\copy\b_tabl_plain_tabs
82   \global\setbox\b_tabl_plain_tabs_done\emptyhbox
83   \let\cr\tabl_plain_cr
84   \setbox\scratchbox\vbox\bgroup
85     \setfalse\c_tabl_plain_cr
86     \ialign\bgroup
87       \aligntab
88       \tabl_plain_begin_tab_box
89       \alignmark\alignmark
90       \tabl_plain_end_tab_box
91       \crcr}
92
93\def\tabl_plain_cr
94  {\settrue\c_tabl_plain_cr
95   \crcr
96   \egroup
97   \egroup
98   \ifconditional\c_tabl_plain_use_tab
99     \unvbox\scratchbox
100     \lastbox % okay?
101   \fi
102   \endgroup
103   \setbox\b_tabl_plain_tabs\hbox
104     {\unhbox\b_tabl_plain_tabs_yet
105      \unhbox\b_tabl_plain_tabs_done}}
106
107\def\tabl_plain_begin_tab_box
108  {\setbox\scratchbox\hbox\bgroup}
109
110\def\tabl_plain_end_tab_box
111  {\ifconditional\c_tabl_plain_cr
112     \egroup % now \box\scratchbox holds the column
113   \else
114     \hss
115     \egroup
116     \global\setbox\b_tabl_plain_tabs_yet\hbox
117       {\unhbox\b_tabl_plain_tabs_yet
118        \global\setbox\globalscratchbox\lastbox}% now \box\globalscratchbox holds its size
119     \ifvoid\globalscratchbox
120       \global\setbox\globalscratchbox\hbox to \wd\scratchbox
121         {}%
122     \else
123       \setbox\scratchbox\hbox to \wd\globalscratchbox
124         {\unhbox\scratchbox}%
125     \fi
126     \global\setbox\b_tabl_plain_tabs_done\hbox
127       {\box\globalscratchbox
128        \unhbox\b_tabl_plain_tabs_done}%
129   \fi
130   \box\scratchbox}
131
132\protect \endinput
133