Debian Codegraph @

texmf-dist/doc/latex/tabstackengine/tabstackengine.tex

raw
1 \documentclass{article}
2 \usepackage[T1]{fontenc}
3 \usepackage{lmodern}
4 \usepackage[TABcline]{tabstackengine}
5 \usepackage{verbatimbox}
6 \usepackage{xcolor}
7 \parindent 0in\parskip 1em \newlength\dotscale
8
9
10 % FOR CLOSE-BOXING ARGUMENTS \fboxsep=0pt\fboxrule=.6pt
11 \def\rl{\rule[-.3pt]{2ex}{.6pt}} \def\tst{\textsf{tabstackengine}}
12 \def\ste{\textsf{stackengine}} \def\loi{\textsf{listofitems}}
13 \def\bs{\texttt{\char'134}} \let\vb\verb
14 \reversemarginpar \marginparwidth 1.6in
15 \newcommand\margtt[1]{\marginpar{\hfill\ttfamily#1}}
16 \newcommand\margcmd[1]{\marginpar{\hfill\ttfamily\char'134#1}}
17 \newcommand\cmd[1]{\texttt{\char'134#1}}
18
19 \catcode`>=\active %
20 \catcode`<=\active %
21 \catcode`!=\active %
22 \def\vbspecial#1>{\textit{\rmfamily#1}}
23 \def\vbdelim{\catcode`<=\active \catcode`>=\active \catcode`!=\active \def<{\vbspecial}\def>{}\def!{\stringrms}}
24 \catcode`!=12 %
25 \catcode`>=12 %
26 \catcode`<=12 %
27 \def\endvbdelim{\catcode`>=12 \catcode`<=12 }
28
29 \def\stringrms#1{%
30 \ifx1#1\relax\textrm{(provided by \ste)}\fi%
31 \ifx2#1\relax\textrm{(only with \texttt{TABcline} package option)}\fi%
32 }
33 \begin{document}
34
35 \begin{center} \LARGE The {\tst} Package\\ \rule{0em}{.7em}\small
36 Front-end to the {\ste} package, allowing tabbed stacking\\ \rule{0em}{2.7em}\large
37 Steven B. Segletes\\ [email protected]\\
38 \rule{0em}{1.7em}\today\\ \tabstackengineversionnumber \end{center}
39
40 \tableofcontents
41
42 \section{Introduction}
43
44 The {\tst} package provides a front end to the {\ste} package that
45 allows for the use of tabbing characters within the stacking arguments.
46 \textbf{Familiarity with the syntax of the {\ste} package is assumed.}
47 When invoked, {\tst} loads the {\ste} package and initializes it in
48 such a way that the end-of-line (EOL)
49 character in certain stacking arguments will be taken, by default,
50 as \vb|\\|, rather
51 than a space (which is the default EOL separator in \ste).
52 The EOL separator can be changed using \ste{}'s \cmd{setstackEOL} macro.
53
54 With \tst, command variations are introduced to allow several variants
55 of tabbing within the macro arguments. The default tabbing character is
56 the ampersand (\vb|&|); however, the tabbing character can be reset to
57 other tokens using the \vb|\setstackTAB| macro.
58
59 \begin{sloppypar}
60 In most cases (where it makes sense), a {\ste} macro name may be
61 prepended with the word \texttt{tabbed}, \texttt{align}, or
62 \texttt{tabular} to create a new {\tst} macro that allows for tabbed
63 arguments.
64 \end{sloppypar}
65
66 \section{Modes and Styles of \tst}
67
68 \begin{sloppypar}
69 Like the \ste{} package which provides the modes \vb|\stackText| and
70 \vb|\stackMath|, the \tst{} package provides the modes
71 \vb|\TABstackText| and \vb|\TABstackMath|.\margcmd{TABstackText}%
72 \margcmd{TABstackMath}
73 However, the \tst{} package honors the underlying mode of \ste, and
74 so if either \vb|\stackMath| or \vb|\TABstackMath| are set, all
75 TABstacking arguments will be processed in math mode.%
76 \footnote{The one exception here is if \ste{} macros are embedded (nested)
77 inside \tst{} macro arguments. In this case, the embedded \ste{} macro will
78 only respond to the \ste{} mode, and not the \tst{} mode.}
79 So what are the differences?\vspace{-\parskip}
80 \begin{itemize}
81 \item \vb|\TABstackMath| and \vb|\TABstackText| are local settings, whereas
82 \vb|\stackMath| and \vb|\stackText| are global settings.
83 \item As of version 2.00,
84 \tst{} provides the means to add additional styles to a stack,
85 associated with \vb|\TABstackMath| and \vb|\TABstackText|.
86 In particular,
87 the macros \vb|\TABstackMathstyle| and \vb|\TABstackTextstyle|%
88 \margcmd{TABstackMathstyle}\margcmd{TABstackTextstyle}
89 can be used to add custom styles to stacks. For example,
90 \vb|\TABstackMathstyle{\displaystyle}| will cause all stacked items
91 processed in TABstack-math mode to be set in display style. Likewise
92 \vb|\TABstackTextstyle{\scriptsize}| will cause all stacked items
93 processed in TABstack-text mode to be set in script size.
94 Styles (for both math and text modes) can be cleared with the command
95 \vb|\clearTABstyle|\margcmd{clearTABstyle}.
96 \end{itemize}
97 \end{sloppypar}
98
99
100 \section{Tabbing Variations within \tst}
101
102 The {\tst} package syntax allows three types of tabbing variation
103 denoted by the words \texttt{tabbed}, \texttt{align}, and
104 \texttt{tabular} in the macro name itself. In the case of
105 \texttt{tabbed} macros, the tabbed columns all share the same alignment,
106 as dictated by the \vb|\stackalignment| setting or perhaps provided as
107 an optional argument in some macro forms.
108
109 In the case of \texttt{align} macros, the alignment in columns is
110 alternately specified as right, then left, \textit{etc.}, in the manner
111 of the \texttt{align} environment of the \textsf{amsmath} package.
112
113 Finally, in the case of \texttt{tabular} macros, an extra argument is
114 passed to the macro that specifies the left-center-right alignment for
115 each individual column, in the manner of \vb|{lccr}|.
116
117 \section{Column Spacing within \tst}
118
119 Intercolumn space can be introduced to {\tst} output in one of two ways.
120 \margcmd{fixTABwidth}First, there is a macro setting to force all columns
121 to be the same width (namely, the width of the widest entry in the stack),
122 using the syntax
123 \vb|\fixTABwidth{T| \textit{or} \vb|F}|.
124 The default is \texttt{F}.
125 When set true, additional column space will be introduced to all but the widest
126 column of a stack, so as to make all columns of a width equal to that
127 of the widest column.
128
129 Secondly,\margcmd{setstacktabbedgap}
130 each of the tabbing variations has the means to introduce a
131 fixed amount of space between columns. By default, the \texttt{tabbed}
132 stacking macros add no space (\texttt{0pt}) between adjacent columns,
133 but this value can be reset with the macro
134 \vb|\setstacktabbedgap{|\textit{length}\vb|}|.
135
136 In\margcmd{setstackaligngap}
137 the case of the \texttt{align} stacking macros, there is never any
138 gap introduced after the right-aligned (odd-numbered) columns.
139 However, the default gap introduced after the left-aligned (even-numbered)
140 columns is, by default, \texttt{1em} (the same gap as \cmd{quad}).
141 It can be reset with the macro \vb|\setstackaligngap{|\textit{length}\vb|}|.
142
143 For\margcmd{setstacktabulargap}
144 the \texttt{tabular} stacks, the default intercolumn gap is the
145 value of \cmd{tabcolsep}. The default value may be reset with the macro
146 \vb|\setstacktabulargap{|\textit{length}\vb|}|.
147
148 Note that these \cmd{setstack...gap} macros are for setting horizontal
149 gaps between columns of a stack. They should not be confused with
150 the \cmd{setstackgap} macro of {\ste} that sets the vertical gap
151 for long and short stacks.
152
153 \section{Horizontal Rules}\label{s:hr}
154
155 As of version 2.10, \tst{} provides the facility to lay down horizontal rules
156 that fill up the TABstack cell width.
157 There are two ways that this may be accomplished.
158 First, the macro \vb|\TABrule[<|\textit{vertical shift}\vb|>]|%
159 \margcmd{TABrule}
160 may be specified as the entry in a cell, in order to place a horizontal
161 rule, of thickness \vb|\fboxrule| across the width of the cell.%
162 \footnote{The width of the \cmd{TABrule} will actually be the width of
163 the widest data in that column. This has implications when the
164 \cmd{fixTABwidth} switch is set true, in that some columns will
165 be typeset wider than their widest data.}
166 The optional argument specifies the vertical shift of the rule.
167 The default vertical shift, initially 0pt, may also be specified in the
168 length \cmd{TABruleshift}.\margcmd{TABruleshift}
169
170 So, for example,
171
172 \vb|\tabbedstackon{a&bb&CCC&dddd}{&\TABrule&&\TABrule}|
173
174 will yield this result:
175 \tabbedstackon{a&bb&CCC&dddd}{&\TABrule&&\TABrule}.
176 Note that the vertical spacing around the \vb|\TABrule| will conform
177 to the stackengine rules set by \vb|\setstackgap|, for both ``short'' and
178 ``long'' stacks.
179 In essence, the \vb|\TABrule|s literally constitute their own row in the stack.
180
181 A \vb|\TABrule| may also constitute a cell that contains actual [non-rule]
182 data elsewhere on the row.
183 So, for example,
184
185 \vb|\tabbedLongstack{aa&\TABrule\\\TABrule&bbb}|
186
187 produces the result \tabbedLongstack{aa&\TABrule\\\TABrule&bbb}.
188
189 If a row of the TABstack is to be composed solely of rules, then these rules
190 can also be achieved in a second way.
191
192 \subsection{The \texttt{TABcline} Package Option}\label{s:rtx}
193
194 There is also introduced in version 2.10, a package option \vb|TABcline|,
195 invoked in the standard way via \vb|\usepackage[TABcline]{tabstackengine}|.
196 This option reduces the efficiency of the package slightly, but provides
197 two macros that can enhance convenience.
198 The two macros that are activated with this package option are \vb|\TABcline{}|%
199 \margcmd{TABcline}
200 and \vb|\relaxTABsyntax|.
201 The macro
202
203 \vb|\TABcline{<|\textit{col1}\vb|>,<|\textit{col2}\vb|>,<|%
204 \textit{col3--col4}\vb|>,...}|
205
206 provides a shorthand notation for creating a row of \vb|\TABrule|s.
207 For example, in a five-column TABstack, the shorthand
208
209 \vb|\TABcline{1,3-4}|
210
211 is equivalent to (assuming column separator as \vb|&|, spaces
212 inserted for clarity)
213
214 \vb|\TABrule & & \TABrule & \TABrule &|
215
216 Furthermore, if the \vb|\TABcline| occurs prior to the last row of the
217 TABstack, an end-of-line (EOL) token (\textit{e.g.}, \vb|\\|) is also
218 suffixed to the replacement.
219 Thus,
220
221 \vb|\tabbedShortstack{\TABcline{2-3}\TABcline{1,3-4}a&bb&CCC&dddd}|
222
223 produces \tabbedShortstack{\TABcline{2-3}\TABcline{1,3-4}a&bb&CCC&dddd}.
224
225 When the \texttt{TABcline} package option is selected,
226 the \vb|\relaxTABsyntax|%
227 \margcmd{relaxTABsyntax}
228 switch may also be invoked to address an issue of
229 bad syntax.
230 Some users have a tendency to tack a trailing stack-EOL to the end of
231 an input argument, in the manner of \vb|\tabbedLongstack{a&bb\\cc&d\\}|.
232 This rightfully provokes a \loi{} invalid-index error in \tst{}, because
233 the syntax implies the creation of a third row of a 2-column TABstack,
234 for which no column separators have been specified.
235
236 However, some may find the error message difficult to understand, especially
237 because similar syntax is benign in the \texttt{tabular} environment and
238 non-fatal in the \texttt{align} family of environments.
239 If the switch \vb|\relaxTABsyntax| is in force, the compilation will instead
240 succeed, with the trailing row of the TABstack left blank, in the manner
241 of {\relaxTABsyntax\tabbedLongstack{a&bb\\cc&d\\}}.
242 Such syntax is still considered bad form, but by compiling without error,
243 the visual result may make the source of the problem more obvious to the
244 user.
245
246 \clearpage
247 \section{Command Summary}
248
249 Below are the new TABstack making commands introduced by \tst.
250 In the syntax shown below, when there are multiple commands delimited by
251 braces, any one of the commands within the brace may be selected.
252
253 \vbdelim
254 \ttfamily\footnotesize
255 \(\left.\Centerstack[r]{%
256 \textcolor{red}{\cmd tabbed}\\\\
257 \textcolor{teal}{\cmd align}\\\\
258 \textcolor{blue}{\cmd tabular}
259 }\right\}%
260 \left\{
261 \Centerstack[c]{Shortstack\\Shortunderstack\\Longstack\\
262 Longunderstack\\Centerstack\\Vectorstack}
263 \right\}%
264 \left\{\Centerstack[c]{
265 \textcolor{red}{[<alignment>]}\\\\
266 \\\\
267 \textcolor{blue}{\{<column alignments>\}}
268 }\right\}\)\{<tabbed EOL-separated string>\}
269
270 \(\displaystyle\$\left\{\Centerstack[r]{\cmd\\ \cmd paren\\\cmd brace\\\cmd bracket\\\cmd vert}\right\}\)%
271 \textcolor{red}{Matrix}stack[<alignment>]\{%
272 <tabbed EOL-separated string>\}\$
273
274 \(\left.\Centerstack[r]{
275 \textcolor{red}{\cmd tabbed}\\\\
276 \textcolor{teal}{\cmd align}\\\\
277 \textcolor{blue}{\cmd tabular}}\right\}%
278 \left\{
279 \Centerstack[c]{stackon\\stackunder\\stackanchor}
280 \right\}%
281 \mathtt{[<stack gap>]}\left\{\Centerstack[l]{
282 \\\\
283 \\\\
284 \textcolor{blue}{\{col.\ alignments\}}
285 }\right\}\)\{<tabbed anchor>\}\{\rlap{<tabbed~argument>\}}
286
287 \cmd setstack\(\left\{\Centerstack{
288 \textcolor{red}{tabbed}\\\\
289 \textcolor{teal}{align}\\\\
290 \textcolor{blue}{tabular}
291 }\right\}\)gap\{<length>\}
292 \hspace{3em}\textrm{Initial Defaults:}\(\left\{\Centerstack{
293 \textcolor{red}{0pt}\\\\
294 \textcolor{teal}{1em}\\\\
295 \textcolor{blue}{\cmd tabcolsep}
296 }\right\}\)
297
298 \rmfamily\normalsize
299
300 The ``\textit{tabbed EOL separated string}'' can contain not only regular
301 \LaTeX{} content, but
302 it may also contain \cmd{TABrule}s and/or \cmd{TABcline}s as discussed
303 in section~\ref{s:hr}.
304 The macro\margcmd{ensureTABstackMath}\vspace{-8pt}
305 \begin{verbnobox}[\footnotesize\vbdelim]
306 \ensureTABstackMath{<commands involving TABstacks>}
307 \end{verbnobox}
308 \vspace{-8pt}
309 will force any \tst{} stacks within its argument to be
310 processed in math mode, even
311 if the prevailing mode is otherwise \vb|\TABstackText|.
312 The package also provides a set of declarations that can be used to define the
313 manner in which subsequent TABstacks will be processed:\vspace{-8pt}
314 \begin{verbnobox}[\footnotesize\vbdelim]
315 \fixTABwidth{T <or> F}
316 \TABstackMath
317 \TABstackText
318 \TABstackMathstyle{<directive>}
319 \TABstackTextstyle{<directive>}
320 \clearTABstyle
321 \setstackEOL{<end-of-line character>} !1
322 \setstackTAB{<tabbing character>}
323 \TABunaryLeft (\TABbinaryRight)
324 \TABunaryRight (\TABbinaryLeft)
325 \TABbinary
326 \relaxTABsyntax !2
327 \end{verbnobox}
328 The following macros can be used for parsing tabbed data outside of a
329 TABstack and also provide various stack metrics for the most recently
330 parsed \tst{} data.
331 \vspace{-6pt}
332 \begin{verbnobox}[\footnotesize\vbdelim]
333 \readTABstack{<tabbed EOL-separated string>}
334 \TABcellRaw[<row>,<column>]
335 \TABcell{<row>}{<column>}
336 \TABcellBox[<alignment>]{<row>}{<column>}
337 \getTABcelltoks[<row>,<column>] \the\TABcelltoks
338 \TABcells{<row> or blank}
339 \TABstrut{<row>}
340 \TABwd{<column>}
341 \TABht{<row>}
342 \TABdp{<row>}
343 \end{verbnobox}
344 \vspace{-12pt}
345
346 \subsection{Command Examples}
347
348 Below we give examples of the various types of commands made available through
349 the \tst{} package.
350
351 \subsection*{Tabbed End-of-Line (EOL)-delimited Stacks}
352
353 Here, the optional argument \vb|[l]| defines the alignment of \textit{all} the
354 columns as ``left.'' The default alignment is \vb|[c]|.
355
356 \vb|\TABstackTextstyle{\scshape}|\\
357 \vb|\tabbedShortunderstack[l]{This& Is &The\\Time & Of&Man's\\ |\\
358 \vb| Great&Dis&content}|
359
360 {\small\TABstackTextstyle{\scshape}%
361 \tabbedShortunderstack[l]{This& Is &The\\Time & Of&Man's\\
362 Great&Dis&content}}
363
364 Note that spaces around the arguments are absorbed and discarded. Furthermore, the
365 text style has been set to \vb|\scshape|.
366
367 \subsection*{Align End-of-Line (EOL)-delimited Stacks}
368
369 In an \texttt{align}-stack, the column alignments will always be \vb|rlrl...|
370 The gap following the left-aligned columns is set by \vb|\setstackaligngap|.
371
372 \vb|$\ensurestackMath{Z:\left\{\alignCenterstack{%|\\
373 \vb| y=&mx+b,&0=&Ax+By+C \\ y_1=&W_1,&y_2=&W_2}\right.}$|
374
375 {\small$\ensurestackMath{Z:\left\{\alignCenterstack{%
376 y=&mx+b,&0=&Ax+By+C \\ y_1=&W_1,&y_2=&W_2}\right.}$}
377
378 \subsection*{Tabular End-of-Line (EOL)-delimited Stacks}
379
380 In a \texttt{tabular}-stack, the alignment of each column is specified in a separate
381 leading argument.
382
383 \vb|\stackText\tabularLongstack{rllc}{%|\\
384 \vb| 9)& $y_1=mx+b$ &linear&*\\10)& $y_2=e^x$ &exponential&[23]}|
385
386 {\small\stackText\tabularLongstack{rllc}{9)& $y_1=mx+b$ &linear&*\\10)& $y_2=e^x$ &exponential&[23]}}
387
388 \subsection*{Matrix Stacks}
389
390 The \texttt{Matrix}-stacks are tabbed variants of \ste's \texttt{Vector}-stacks.
391
392 \vb|\setstacktabbedgap{1.5ex}|\\
393 \vb|$I = \bracketMatrixstack{1&0&0\\0&1&0\\0&0&1}$|
394
395 {\small\setstacktabbedgap{1.5ex} $I = \bracketMatrixstack{1&0&0\\0&1&0\\0&0&1}$}
396
397 \subsection*{Tabbed Stack}
398
399 This variant of a \texttt{tabbed}-stack stacks exactly two items.
400 The optional argument is a stacking gap,
401 as in the syntax of the \ste{} package.
402
403 \vb|\setstacktabbedgap{1ex}|\\
404 \vb|\tabbedstackon[4pt]{Jack&drove&the car&home.}{SN&V&DO&IO}|
405
406 {\small\stackText\setstacktabbedgap{1ex}\tabbedstackon[4pt]{Jack&drove&the car&home.}{SN&V&DO&IO}}
407
408 \subsection*{Align Stack}
409
410 This is for stacking two items with \texttt{rlrl...} alignment pattern.
411
412 \vb|\TABstackMath\setstackaligngap{3em}|\\
413 \vb|\alignstackunder[8pt]{y=&mx+b,&0=&Ax+By+C}{y_1=&W_1,&y_2=&W_2}|
414
415 {\small\TABstackMath\setstackaligngap{3em}
416 \alignstackunder[8pt]{y=&mx+b,&0=&Ax+By+C}{y_1=&W_1,&y_2=&W_2}}
417
418 \subsection*{Tabular Stack}
419
420 This is for stacking items with specifiable alignment pattern.
421
422 \vb|\TABbinary\TABstackMath\setstackgap{S}{0pt}\fboxrule=1pt\relax|\\
423 \vb|\tabularShortstack{lcr}{1 + 2(4-3) &=& 6 - 6/2\\|\\
424 \vb| \TABcline{1-3}\kern6em & \triangle & \kern6em}|
425
426
427 {\small\TABbinary\TABstackMath\setstackgap{S}{0pt}\fboxrule=1pt\relax
428 \tabularShortstack{lcr}{1 + 2(4-3) &=& 6 - 6/2\\
429 \TABcline{1-3}\kern6em & \triangle & \kern6em}}
430
431 Note the use of \vb|\TABbinary|, which applies a group to the beginning and
432 end of each cell, in the event a binary treatment of leading/trailing
433 operators is desired.
434 So, in this case, a cell containing \vb|=| will be set as \vb|{}={}|.
435 In the absence of that declaration, the cell containing
436 the equal sign would have to have been explicitly defined as \vb|={}|
437 (in accordance with the \vb|\TABunaryLeft| default setting of the package).
438 Negative vertical stacking gap, while not used here, is a perfectly
439 acceptable syntax and can be used to achieve overlap, if desired.
440
441 \subsection*{Fixed Tab Width (equal width columns, based on largest)}
442
443 With the \vb|\fixTABwidth| mode set\margcmd{fixTABwidth}, the stack
444 will have fixed-width columns, based on the overall widest entry.
445 Compare with versus without fixed width for the following TABstack.
446
447 \vb|\setstacktabbedgap{1ex}\fixTABwidth{T}%|\\
448 \vb|$\left(\tabbedCenterstack[r]{1&34&544\\4324329&0&8\\89&123&1}\right)$|\\
449 \vb|versus \fixTABwidth{F}%|\\
450 \vb|$\left(\tabbedCenterstack[r]{1&34&544\\4324329&0&8\\89&123&1}\right)$|
451
452 {\small\setstacktabbedgap{1ex}\fixTABwidth{T}
453 $\left(\tabbedCenterstack[r]{1&34&544\\4324329&0&8\\89&123&1}\right)$
454 versus \fixTABwidth{F}%
455 $\left(\tabbedCenterstack[r]{1&34&544\\4324329&0&8\\89&123&1}\right)$}
456
457 \subsection*{Setting the Stack Tabbing Character}
458
459 \begin{sloppypar}
460 By default, for the parsing of columns within a given row, this package employs
461 the \vb|&| character to delimit the columns.
462 This value can be changed via \vb|\setstackTAB{|<tabbing character>\vb|}|,%
463 \margcmd{setstackTAB}
464 where the argument is the newly desired tabbing token.
465 It can be any of various tokens\footnote{%
466 Since \tst{} uses the \loi{} package for parsing rows and columns,
467 see the \loi{} package documentation for limitations on the tokens that
468 can be used as a valid parsing separator.}
469 , including a space token, if one wishes to
470 parse a space-separated list of columns.
471 \end{sloppypar}
472
473 \subsection*{TABstacks Inside the \texttt{tabular} or \texttt{align}
474 Environments}
475
476 When invoking a TABstack inside another tabbed environment, such as
477 \vb|tabular|, \vb|align|, or other similar environments, one
478 \textbf{no longer}\footnote{%
479 As of version 2.10, the problem of properly scoping TABstack argument
480 was resolved with the use of ``brace hacks'' described on p.\,385 of the
481 \TeX book, and suggested to the author by Prof. Enrico Gregorio.
482 }
483 needs to group the TABstacks in their own braces \vb|{}|:
484 \begin{verbnobox}[\footnotesize\vbdelim]
485 \ensureTABstackMath{%
486 \begin{tabular}{c|c}
487 Left Eqn. & Right Eqn.\\
488 \hline
489 \tabularCenterstack{lr}{a_1 & 12\\c & 1234} & \
490 \tabularCenterstack{rl}{a_1 & 12\\c & 1234}\\
491 \hline
492 \end{tabular}
493 }
494 \end{verbnobox}
495 {%
496 \ensureTABstackMath{%
497 \begin{tabular}{c|c}
498 Left Eqn. & Right Eqn.\\
499 \hline
500 \tabularCenterstack{lr}{a_1 & 12\\c & 1234} &
501 \tabularCenterstack{rl}{a_1 & 12\\c & 1234}\\
502 \hline
503 \end{tabular}
504 }
505
506 \subsection*{Math Relations/Operators at Cell Left/Right Extrema}
507
508 There are two things to keep in mind regarding TABstacked content.
509 First, a TABstack cell has no precise understanding up what content precedes
510 it in the cell to the immediate left, nor what content follows it in the
511 cell to the immediate right.
512 It does, however know the overall height/depth of the content across the whole
513 row and creates a vertical ``strut'' of that height and depth, which must,
514 in some way, be applied to every cell in the row.
515
516 This vertical strut can be applied to the cell immediately prior to or
517 immediately following the cell content, as we shall see.
518 However, such an action will have an effect on math operators and relations
519 found at the leading or trailing ends of the cell content.
520
521 Math operators and relations can be categorized as unary or binary; some
522 may be both, depending on their usage context, such as the minus sign.
523 When used as $a-b$, the relation is binary, because it connects $a$ and $b$
524 in a mathematical operation.
525 Note how space appears both before and after the minus sign.
526 Alternatively, when used as $-\pi$, the minus sign operates only upon what
527 follows, in this case $\pi$, to produce a negative.
528 Note how no space is introduced between the minus sign and $\pi$.
529 This is the minus used as a unary operator.
530
531 Because a TABstack cell has no intimate knowledge of the adjacent cell content,
532 it is up to the user to employ his tabbing separators in a way that produces
533 the desired result.
534 By default, \tst{} will place the strut after the cell content.
535 This means that any trailing math operator in a cell will present itself in its
536 binary form (regardless of what comes in the cell to the right), because the
537 strut will appear as trailing data against which the operator can
538 be set.
539 Similarly, any leading math operator will present itself as unary (regardless of
540 what content appears in the cell to the left).
541
542 \stackMath
543 Thus, under the default setting \vb|\tabbedLongstack{y =&-mx +& b}| will
544 present as {\tabbedLongstack{y =&-mx +& b}}, by default, with the trailing
545 equal and plus signs as binary, and the leading minus sign as unary.
546 The package can reverse the default with the following declarative modes:
547 \vb|\TABunaryRight|\margcmd{TABunaryRight} (identical to
548 \vb|\TABbinaryLeft|)\margcmd{TABbinaryLeft}; alternately,
549 one may use \vb|\TABbinary|\margcmd{TABbinary}, which will
550 present both leading \textit{and} trailing
551 operators in their binary form.
552 The default can be restored with \vb|\TABunaryLeft| (identical to
553 \vb|\TABbinaryRight|).\margcmd{TABunaryLeft}\margcmd{TABbinaryRight}
554
555 Without changing any of the package strut modes, an operator, such as minus,
556 can always be forced into its unary mode by enclosing it in braces: \vb|{-}|.
557 Likewise, it can be forced into its binary mode by placing empty braces on
558 both sides of it: \vb|{}-{}|.
559
560 \subsection*{The Parsing Macros \texttt{\textbackslash readTABstack}, <etc.>}
561
562 As of version 2.00 of the \tst{} package, the parsing functions of the package
563 were delegated to the very powerful \loi{} package.
564 As such {\bfseries the \vb|\readTABrow| macro is no longer supported}.
565 For typical parsing functionality, therefore, please consult the
566 documentation to the \loi{} package and its \vb|\readlist| macro.
567 I commend it to your inspection and use for a variety of parsing tasks.
568
569 However, there may still be a need to access the various stacking related data
570 in either a recently composed TABstack, or even one that is yet to be typeset.
571 When a TABstack is constructed by the \tst{} package, a call is made to the routine
572 \vb|\readTABstack|\margcmd{readTABstack}, in order to parse the data.
573 This macro may be independently called by the user to read TABstack data
574 without producing a constructed TABstack, by passing it the same tabbed,
575 EOL-separated data that would otherwise be used to construct a stack.%
576 \footnote{Alternately, TABstacking data can be read without generating a
577 TABstack by using the \texttt{\cmd renewcommand\cmd quietstack\{T\}}
578 setting of \ste{} to suppress the stack output, without suppressing its
579 construction.}
580 If the routine is not called independently by the user, data from the most
581 recent TABstacking operation is still available for interrogation.
582
583 Take the example
584
585 \vb|\TABstackMath\TABstackMathstyle{\displaystyle}\setstackgap{S}{5pt}%|\\
586 \vb|\alignShortstack{\frac{A}{Q}x=&B\\ C= &\frac{Dx}{2}\\E=&F}|
587
588 which presents as
589
590 \TABunaryLeft
591 \TABstackMath\TABstackMathstyle{\displaystyle}\setstackgap{S}{5pt}%
592 \alignShortstack{\frac{A}{Q}x=&B\\ C= &\frac{Dx}{2}\\E=&F}
593
594 Let us say we were interested in information about the cell in the 1st
595 column of the 2nd row.
596 I can obtain its dimensions as the column-1 width \vb|\TABwd{1}|%
597 \margcmd{TABwd}, as well as the row-2 height and depth
598 \vb|\TABht{2}|\margcmd{TABht} and \vb|\TABdp{2}|\margcmd{TABdp}.
599 Note that these macros provide dimensions of the TABstack \textit{cell}, which
600 in this case is larger than the mere ``\TABcell{2}{1}'' content.
601 Those dimensions are as follows, followed by a \vb|\rule| depicting the total
602 size of the cell:
603
604 Width: \TABwd{1},\hfill Height/Depth: \TABht{2}/\TABdp{2},\hfill Rule:
605 \rule[-\TABdp{2}]{\TABwd{1}}{\dimexpr\TABdp{2}+\TABht{2}\relax}
606
607 One can also obtain information about what is in the cell.
608 Here, use the macro \vb|\TABcellRaw[2,1]|\margcmd{TABcellRaw}, which will
609 expand to the tokens employed in the stack definition (shown here in an
610 \vb|\fbox| to show that the leading/trailing spaces have been discarded):
611
612 \fboxsep=1pt
613 \fbox{\TABcellRaw[2,1]}
614
615 If one would like to see the cell data presented in the prevailing
616 (\textsf{tab})\ste{} mode and style%
617 \footnote{Note that both \cmd{TABcell} and, as described later,
618 \cmd{TABcellBox} present in the \textit{prevailing} TABstack mode and
619 style.
620 While a recent use of \cmd{ensureTABstackMath} will be remembered,
621 intervening declarations of \cmd{TABstackMath}, \cmd{TABstackText} and
622 their associated styles will change the \textit{prevailing} mode
623 and style in which subsequent \cmd{TABcell} and \cmd{TABcellBox}
624 are processed.}%
625 , the macro
626 \vb|\TABcell{2}{1}|\margcmd{TABcell} may be used (again shown in
627 an \vb|\fbox|):
628
629 \fbox{\TABcell{2}{1}}
630
631 Note, however, that the \vb|\TABcell| still does not account for three things:
632 \vspace{-\parskip}\begin{itemize}
633 \item it is not strutted to reflect the height of the full row content;
634 \item it does not reflect the full column width (nor the alignment within
635 the column); and
636 \item it does not provide any of the empty group treatments that would
637 otherwise make leading/trailing math operators perform in a binary fashion.
638 \end{itemize}\vspace{-\parskip}
639 A strut of the given row height may be obtained with \vb|\TABstrut{2}|%
640 \margcmd{TABstrut}:
641
642 \fboxsep=0pt
643 \fbox{\TABstrut{2}} $\quad\leftarrow$the strut is boxed here to show
644 its vertical extent
645
646 However, to obtain the fully rendered cell, \textit{as it appears within the
647 actual TABstack}, one needs \vb|\TABcellBox{2}{1}|\margcmd{TABcellBox},
648 shown (in an \vb|\fbox|) as
649
650 \fbox{\TABcellBox{2}{1}}\quad% ACCOUNTS FOR \TABunaryLeft, etc.
651
652 Since the \vb|\readTABstack| macro, itself, neither knows nor determines the
653 eventual cell alignment of a future stack, the actual \texttt{lcr}
654 alignment of a \vb|\TABcellBox| will only be known when applied to
655 a previously constructed stack.
656 Therefore, if \vb|\TABcellBox| is called following an independent
657 invocation of \vb|\readTABstack|, center alignment
658 of the cell content will be provided, by default, which can be overridden
659 with the optional argument to \vb|\TABcellBox|.
660
661 Note that the height/depth of the \vb|\TABcellBox| reflects the height and
662 depth of the row content of the TABstack.
663 For short stacks, the specified gap between rows is \textit{in addition}
664 to these strutted boxes.
665 For long stacks, the inter-row spacing is independent of the box height and
666 depth.
667 However, even for long stacks, the height of the top row and the depth of
668 the bottom row of a stack still affect the overall dimensions of the stack.
669
670 \begin{sloppypar}
671 If one wishes to recover the \textit{actual tokens} that were employed in a
672 given TABstack cell (rather that just something that will \textit{expand}
673 to those tokens), that can be accomplished in one of two ways.
674 The macro \vb|\TABcellRaw[,]| can be expanded twice in the manner of
675 \end{sloppypar}
676
677 \vb|\detokenize\expandafter\expandafter\expandafter{\TABcellRaw[2,2]}|
678
679 \detokenize\expandafter\expandafter\expandafter{\TABcellRaw[2,2]}
680
681 Alternately, the macro \vb|\getTABcelltoks[,]|\margcmd{getTABcelltoks} will
682 produce a token list named \vb|\TABcelltoks|\margcmd{the\cmd TABcelltoks} that
683 contains the cell's tokens:
684
685 \vb|\getTABcelltoks[2,2]\detokenize\expandafter{\the\TABcelltoks}|
686
687 \getTABcelltoks[2,2]\detokenize\expandafter{\the\TABcelltoks}
688 \TABstackText
689
690 In summary then, \tst{} cell content can be accessed in a number of ways:\\
691 \renewcommand\arraystretch{1.2}
692 \begin{tabular}{@{}l@{~--~}p{3.3in}@{}}
693 \vb|\TABcellRaw[,]| & expands into the tokens of the cell\\
694 \vb|\TABcell{}{}| & presents the cell content in the prevailing mode (text
695 or math) and style set by \ste{} and \tst{}\\
696 \vb|\TABcellBox{}{}| & presents the cell content, in the prevailing mode
697 and style, strutted to the proper row height/depth, set in a box of the
698 proper cell width, flanked by the appropriate \vb|{}| groups defined by
699 \tst's unary and/or binary declarations,
700 and (when knowable) set in the proper \texttt{lcr} alignment\\
701 \vb|\getTABcelltoks[,]| & creates a token list register \vb|\TABcelltoks|
702 that contains the actual tokens employed in the cell, accessible by
703 way of \vb|\the\TABcelltoks|
704 \end{tabular}
705
706 \section*{TABstack Array Dimensions}
707
708 Consider the example
709
710 \vb|\setstacktabbedgap{.5em}|\\
711 \vb|\tabbedLongstack{a & b & c & d\\ e & f & g & h\\ i & j & k & l}|
712
713 which produces
714
715 \setstacktabbedgap{.5em}
716 \tabbedLongstack{a & b & c & d\\ e & f & g & h & H\\ i & j & k & l}
717
718 The macros \vb|\TABwd|, \vb|\TABht|, and \vb|\TABdp| were presented as the
719 means to get the physical dimensions of various rows and columns of a TABstack.
720 But what if the information sought is the number of rows and columns?
721
722 The macro \vb|\TABcells{}|\margcmd{TABcells} performs the function.
723 When passed a blank argument, it returns the number of rows of the most
724 recently constructed TABstack (or \vb|\readTABstack|).
725
726 $\textrm{Rows} = \vb|\TABcells{}| = \TABcells{}$
727
728 On the other hand, pass it a row number for its arguments and it will tell you
729 how many columns below to that row
730
731 $\textrm{Columns} = \vb|\TABcells{1}| = \TABcells{1}$
732
733 Note that \tst{} uses the number of columns provided in row 1 to determine the
734 dimensions of the subsequent TABstack.
735 If the 2nd or 3rd rows of the above stack were [accidentally] defined with 5
736 columns of data, the 5th column of data would be ignored during the TABstack
737 construction, since the 1st row only has 4 columns.
738 However, in that case, \vb|\TABcells{2}| would still, in fact, yield
739 \TABcells{2}.
740
741 \section{Absent Features/Tricky Syntax}
742
743 \textbf{1. Nothing Equivalent to} \vb`|`
744
745 This is not a bug, but rather a notation of a missing feature. Currently
746 vertical lines may \textbf{not} be added to a tabular stack
747 with the use of \vb`|` elements in the column specifier.
748
749 \textbf{2. Trailing Row Separator/Empty Items Are Not Ignored (by Default)}
750
751 The \loi{} package used to parse TABstack input, does not, by default,
752 ignore empty items.
753 This can cause parsing errors, if not understood properly.
754 Take, for example, the well formed TABstack invocation,
755
756 \vb|\tabularLongstack{rc}{11&12\\21&22\\31&32}|.
757
758 Adding a trailing \vb|\\| row separator to the input, as in:
759
760 \vb|\tabularLongstack{rc}{11&12\\21&22\\31&32\\}|,
761
762 however, breaks the parsing because 2 columns of data are expected
763 following the final \vb|\\| (even though such syntax is benign
764 in, for example, the \texttt{tabular} environment).
765 This syntax can be immediately made acceptable by
766 invoking the \loi{} declaration \cmd{ignoreemptyitems}, in which case
767 the final [empty] row is discarded.
768 However, that approach can introduce a new set of problems, because
769 it will then ignore actual blank input that was intended, as in the
770 case of this example, in which table cell (2,2) is intentionally
771 left blank:
772
773 \vb|\tabularLongstack{rc}{11&12\\21&\\31&32\\}|.
774
775 To make this latter case work, when empty items are ignored, an
776 empty group would need be explicitly inserted:
777
778 \vb|\tabularLongstack{rc}{11&12\\21&{}\\31&32\\}|.
779
780 As of V2.1, the case of the trailing row separator can also be addressed
781 in a 2nd way, if the \texttt{TABcline} package option has been
782 declared.
783 In that case, the switch \cmd{relaxTABsyntax} will automatically
784 add the necessary column separators to \tst{} macro input, in
785 order to avoid compilation error for the case of a trailing row
786 separator.
787 See section~\ref{s:rtx} for more details.
788
789 These problems arising from syntax can be wholly avoided,
790 without the need to resort to
791 \cmd{ignoreemptyitems} or \cmd{relaxTABsyntax}, if care is used in the
792 construction of the TABstack input.
793
794 \endvbdelim
795 \section*{Acknowledgments}
796
797 I would like to thank Christian Tellechea for his development of the
798 \loi{} package (which was directly inspired by my deficient
799 \textsf{getargs} package).
800 The macros provided by Christian were directly implemented for version 2.00
801 of the \tst{} package.
802
803 I would also thank the user ``Werner'' at \textsf{tex.stackexchange.com} for
804 helping me to understand some of the details of the \textsf{etoolbox} package:
805
806 \vb|http://tex.stackexchange.com/questions/140372/|\\
807 \vb|loop-multi-contingency-using-etoolbox|
808
809 Professor Enrico Gregorio is a constant source of knowledge and assistance
810 for which I am very grateful.
811
812 \section{Code Listing}
813
814 \verbfilenobox[\footnotesize]{tabstackengine.sty}
815 \end{document}
816
817
818