Debian Codegraph @

texmf-dist/source/latex-dev/tools/array.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2026
4 %
5 % The LaTeX Project and any individual authors listed elsewhere
6 % in this file.
7 %
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
10 %
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % https://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
18 %
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
21 %
22 % \fi
23 %\iffalse % this is a METACOMMENT !
24 %
25 %% Package `array' to use with LaTeX 2e
26 %% Copyright (C) 1989-1998 Frank Mittelbach, all rights reserved.
27 %
28 %<+package>
29 % For anything before 2016-10-06 we load the 2016 version and hope for the best:
30 %<+package>\DeclareRelease{}{1994-06-01}{array-2016-10-06.sty}
31 %
32 %<+package>\DeclareRelease{}{2016-10-06}{array-2016-10-06.sty}
33 %<+package>\DeclareRelease{v2.4}{2020-02-10}{array-2020-02-10.sty}
34 %<+package>\DeclareRelease{v2.5}{2023-11-01}{array-2023-11-01.sty}
35 %<+package>\DeclareRelease{v2.6}{2024-06-01}{array-2024-06-01.sty}
36 %<+package>\DeclareCurrentRelease{}{2026-06-01}
37 %<+package>
38 % \end{macrocode}
39 % Current version needs a new kernel.
40 % \begin{macrocode}
41 %<+package>\NeedsTeXFormat{LaTeX2e}[2026/06/01]
42 %<+package>\ProvidesPackage{array}
43 %<+package> [2026/02/24 v2.7b Tabular extension package (FMi)]
44 %
45 % \fi
46 %
47 %%
48 %
49 % \providecommand\hook[1]{\texttt{#1}}
50 %
51 % \changes{v2.4g}{2018/04/07}{Renamed internal \cs{mcell@box} to
52 % \cs{ar@mcellbox} and \cs{align@mcell} to \cs{ar@align@mcell}
53 % to avoid conflict with makecell package}
54 %
55 % \changes{v2.4c}{2008/09/09}{(WR) Typo fix in documentation}
56 %
57 % \changes{v2.3c}{1995/11/02}{(DPC) minor doc changes}
58 %
59 % \changes{v2.3a}{1994/10/16}{Added code for \cs{firsthline} and
60 % friends}
61 %
62 % \changes{v2.2c}{1994/03/14}{removed check for \cs{@tfor} bug}
63 %
64 % \changes{v1.0b}{1987/06/04}{`@classi (faster),
65 % `@classvi (new) A in preamble means
66 % \&\& in `halign.}
67 %
68 % \changes{v1.1a}{1987/07/05}{New concept:
69 % preamblechar: c,l,r,C,L,R,A,p,t,{\tt !|},@,!!}
70 % \changes{v1.1b}{1987/09/21}{Again p like original \LaTeX{} and z for
71 % centered `parbox.}
72 %
73 % \changes{v1.2a}{1987/09/27}{Completely new implementation.}
74 % \changes{v1.2b}{1987/10/06}{{\tt !|} does no longer generate space at
75 % start or end of the preamble. Otherwise `hline
76 % is too long.}
77 % \changes{v1.2b}{1987/10/06}{Enlarged `@arstrutbox by 1pt (Test-Impl)
78 % with dimen `@strutheight.}
79 % \changes{v1.2c}{1987/10/22}{New dimen parameter `extrarowheight
80 % (default: 0pt).}
81 % \changes{v1.2c}{1987/10/22}{Enlarged `@arstrutbox by `extrarowheight.
82 % Thus you may avoid large characters to
83 % overprint a `hline.}
84 % \changes{v1.2c}{1987/10/22}{Introduced `m@th in `@array to allow
85 % non-zero values of `mathsurround.}
86 % \changes{v1.2d}{1987/11/02}{Completed the documentation.}
87 % \changes{v1.2e}{1987/11/03}{Bug fixed: A at start of preamble resulted
88 % in an error since `@mkpream generated
89 % `@arstrut \& ... as a preamble.}
90 % \changes{v1.2f}{1987/11/09}{`@testpach documented.}
91 %
92 % \changes{v1.3a}{1987/11/11}{Again a new implementation, with a new
93 % concept (cf. the documentation).}
94 % \changes{v1.3b}{1988/03/17}{`@decl expands now into `@empty, i.e., it
95 % disappears when the preamble is generated,
96 % except when the user specifies A\{\} or
97 % B\{\}.}
98 %
99 % \changes{v1.4a}{1988/03/18}{Test implementation of use of token
100 % registers in order to do without `protect.}
101 % \changes{v1.4b}{1988/03/19}{Changed erroneous class numbers:
102 % 5 -!> 6
103 % 6 -!> 7
104 % 7 -!> 5
105 % Corresponding changes in the macros.}
106 % \changes{v1.4c}{1988/03/19}{Everything except p,z now works with token
107 % registers.}
108 %
109 % \changes{v1.9a}{1988/03/20}{Last (so I hope) major change: 1) Options
110 % B,A now called !>,<. These options now point
111 % to the column they modify.}
112 % \changes{v1.9a}{1988/03/20}{2) `protect is no longer necessary. But
113 % still the macro `@expast needs top be
114 % modified. `multicolumn still does not work.}
115 % \changes{v1.9b}{1988/04/29}{inserted missing `fi in `@testpach.
116 % Corrected \LaTeX bug in `@tfor.}
117 % \changes{v1.9c}{1988/05/07}{Re-introduced `@endpbox.
118 % `multicolumn now works!! Version number still
119 % 1.9 since the documentation is still not
120 % finished.}
121 % \changes{v1.9c}{1988/05/07}{1) `def `the@toks \{`the ...\} remaining
122 % only in `@mkpream. 2) Removed `@classiii and
123 % replaced by `save@decl.}
124 % \changes{v1.9c}{1988/05/07}{3) `insert@column contains only `@tempcnta
125 % and `count@ counters. 4) `@@startpbox and
126 % `@@endpbox now totally obsolete.}
127 % \changes{v1.9d}{1988/05/10}{Replaced `number by `the where the `toks
128 % registers' contents are used.}
129 % \changes{v1.9e}{1988/05/11}{Re-introduced `@xargarraycr and
130 % `@yargarraycr, since `endtemplate seems to
131 % be `outer.}
132 % \changes{v1.9f}{1988/05/20}{Small changes finally carried out:
133 % 1) `par!=`@empty.
134 % 2) \{..ifnum0!=!`\}... $\to$ `bgroup and
135 % analogously `egroup.}
136 % \changes{v1.9g}{1988/02/24}{Inserted again \{..ifnum0!=!`\}..,
137 % c.f. Appendix D of the \protect\TeX{}book.}
138 % \changes{v1.9h}{1988/06/28}{No longer necessary to read in the file
139 % twice.}
140 % \changes{v1.9i}{1988/06/28}{Corrected typo in german version.}
141 % \changes{v1.9j}{1988/11/23}{In a `r' column an extra `kern`z@ is
142 % needed.}
143 % \changes{v1.9j}{1988/11/23}{Otherwise the `hfil on the left side
144 % will be removed by the `unskip in
145 % `insert@column if the entry is empty.}
146 % \changes{v1.9k}{1988/06/28}{Corrected typo in german version.}
147 % \changes{v1.9k}{1989/01/16}{`begin{Macro} changed to `begin{macro} in
148 % documentation.}
149 %
150 % \changes{v2.0a}{1989/05/12}{\cs{@thetoks} changed to \cs{the@toks}.}
151 % \changes{v2.0a}{1989/05/12}{source changed to reflect new doc.sty
152 % conventions.}
153 % \changes{v2.0a}{1989/05/12}{t option renamed to p to be compatible to
154 % the original.}
155 % \changes{v2.0a}{1989/05/12}{File renamed from arraye.sty to
156 % array.sty.}
157 % \changes{v2.0b}{1989/05/17}{Three forgotten end macro added.}
158 % \changes{v2.0b}{1989/05/17}{All lines shortened to 72 or less.}
159 % \changes{v2.2a}{1994/02/03}{Upgrade to \LaTeXe}
160 %
161 % \DoNotIndex{\@depth,\@ehc,\@fortmp,\@height,\@ifnextchar,\@ifstar}
162 % \DoNotIndex{\@ifundefined,\@ne,\@nil,\@tempa,\@tempb}
163 % \DoNotIndex{\@tempcnta,\@tempd,\@tempdima,\@whilenum,\@width,\\}
164 % \DoNotIndex{\@tforloop}
165 % \DoNotIndex{\advance}
166 % \DoNotIndex{\baselineskip,\begingroup,\bgroup}
167 % \DoNotIndex{\cr,\crcr,\csname}
168 % \DoNotIndex{\def,\do,\docdate,\dp}
169 % \DoNotIndex{\edef,\egroup,\else,\endcsname,\endinput,\expandafter}
170 % \DoNotIndex{\fi,\filedate,\fileversion}
171 % \DoNotIndex{\gdef}
172 % \DoNotIndex{\hbox,\hfil,\hsize,\hskip,\ht}
173 % \DoNotIndex{\if,\ifcase,\ifdim,\ifnum,\ifx,\ignorespaces}
174 % \DoNotIndex{\kern}
175 % \DoNotIndex{\leavevmode,\let,\lineskip}
176 % \DoNotIndex{\m@ne,\multispan}
177 % \DoNotIndex{\newcount,\newdimen,\noalign}
178 % \DoNotIndex{\or}
179 % \DoNotIndex{\relax}
180 % \DoNotIndex{\setbox,\space,\strutbox}
181 % \DoNotIndex{\tabskip,\thr@@,\the,\toks,\toks@,\tw@,\typeout}
182 % \DoNotIndex{\unhcopy,\unskip}
183 % \DoNotIndex{\vbox,\vcenter,\vline,\vrule,\vtop,\vskip}
184 % \DoNotIndex{\xdef}
185 % \DoNotIndex{\z@}
186 %
187 %
188 % \providecommand\env[1]{\texttt{#1}}
189 %
190 %
191 % \GetFileInfo{array.sty}
192 %
193 % \title{A new implementation of \LaTeX's \textsf{tabular}
194 % and \textsf{array} environment\thanks{This file
195 % has version number \fileversion, last
196 % revised \filedate.}}
197 % \author{Frank Mittelbach
198 % \and
199 % David Carlisle\thanks{David kindly agreed on the inclusion
200 % of the \texttt{\textbackslash{}newcolumntype} implementation,
201 % formerly in
202 % \texttt{newarray.sty} into this package.}}
203 %
204 % \date{Printed \today}
205 %
206 % \MaintainedByLaTeXTeam{tools}
207 % \maketitle
208 %
209 %
210 %
211 % \MakeShortVerb{\=}
212 %
213 % \begin{abstract}
214 % This article describes an extended implementation of the \LaTeX\
215 % \textsf{array}-- and \textsf{tabular}--environments. The special
216 % merits of this implementation are further options to format columns
217 % and the fact that fragile \LaTeX--commands don't have to be
218 % =\protect='ed any more within those environments.
219 %
220 % The major part of the code for this package dates back to 1988---so
221 % does some of its documentation.
222 % \end{abstract}
223 %
224 %
225 %
226 % \section{Introduction}
227 %
228 % This new implementation of the \textsf{array}-- and
229 % \textsf{tabular}--environments is part of a larger project in which
230 % we are trying to improve the \LaTeX\--code in some aspects and to
231 % make \LaTeX\ even easier to handle.
232 %
233 % The reader should be familiar with the general structure of the
234 % environments
235 % mentioned above. Further information can be found in
236 % \cite{bk:lamport} and \cite{bk:GMS94}.
237 % The additional options which can be used in the
238 % preamble as well as those which now have a slightly different meaning
239 % are described in table~\ref{tab:opt}.
240 %
241 % \DescribeMacro\extrarowheight
242 % Additionally we introduce a new
243 % parameter called =\extrarowheight=. If it takes a positive
244 % length, the value of the parameter is added to the normal height of
245 % every row of the table, while
246 % the depth will remain the same. This is important for tables
247 % with horizontal lines because those lines normally touch the
248 % capital letters.
249 % For example, we used =\setlength{\extrarowheight}{1pt}=
250 % in table~\ref{tab:opt}.
251 %
252 % \begin{table}[!t]
253 % \begin{center}
254 % \setlength{\extrarowheight}{1pt}
255 % \begin{tabular}{|>{\ttfamily}c|m{9cm}|}
256 % \hline
257 % \multicolumn{2}{|c|}{Unchanged options}\\
258 % \hline
259 % l & Left adjusted column. \\
260 % c & Centered adjusted column. \\
261 % r & Right adjusted column. \\
262 % p\{width\} & Equivalent to =\parbox[t]{width}=. \\
263 % @\{decl.\} & Suppresses inter-column space and inserts
264 % \texttt{decl.}\ instead. \\
265 % \hline
266 % \multicolumn{2}{|c|}{New options}\\
267 % \hline
268 % m\{width\} & Defines a column of width \texttt{width}.
269 % Every entry will be centered in proportion to
270 % the rest of the line. It is somewhat like
271 % =\parbox{width}=. \\
272 % \hline
273 % b\{width\} & Coincides with =\parbox[b]{width}=. \\
274 % \hline
275 % >\{decl.\} & Can be used before an \texttt{l}, \texttt{r},
276 % \texttt{c}, \texttt{p}, \texttt{m} or a
277 % \texttt{b} option. It inserts \texttt{decl.}\
278 % directly in front of the entry of the column.
279 % \\
280 % \hline
281 % <\{decl.\} & Can be used after an \texttt{l}, \texttt{r},
282 % \texttt{c}, =p{..}=, =m{..}= or a =b{..}=
283 % option. It inserts \texttt{decl.}\ right
284 % after the entry of the column. \\
285 % \hline
286 % | & Inserts a vertical line. The distance between
287 % two columns will be enlarged by the width of
288 % the line
289 % in contrast to the original definition of
290 % \LaTeX. \\
291 % \hline
292 % !\{decl.\} & Can be used anywhere and corresponds with the
293 % \texttt{|} option. The difference is that
294 % \texttt{decl.} is inserted instead of a
295 % vertical line, so this option doesn't
296 % suppress the normally inserted space between
297 % columns in contrast to =@{...}=.\\
298 % \hline\hline
299 % w\{align\}\{width\} & Sets the cell content in a box of the
300 % specified \texttt{width} aligned according to
301 % the \texttt{align} parameter which could be
302 % either \texttt{l}, \texttt{c} or
303 % \texttt{r}. Works essentially like
304 % =\makebox[=width=][=align=]{=cell=}= so
305 % silently overprints if the cell content is
306 % wider than the specified width. If that is
307 % not desired use \texttt{W} instead.\\
308 % \hline
309 % W\{align\}\{width\} & Like \texttt{w} but spits out an overfull
310 % box warning (and an overfullrule marker in
311 % draft mode) when the cell content is too wide
312 % to fit. This also means that the alignment is
313 % different if there is too much material,
314 % because it then always protrudes to the right!\\
315 % \hline
316 % \end{tabular}
317 % \end{center}
318 % \caption{The preamble options.} \label{tab:opt}
319 % \end{table}
320 %
321 %
322 % We will discuss a few examples using the new preamble options before
323 % dealing with the implementation.
324 % \begin{itemize}
325 % \item
326 % If you want to use a special font (for example =\bfseries=) in a
327 % flushed left column, this can be done with =>{\bfseries}l=. You
328 % do not have to begin every entry of the column with =\bfseries=
329 % any more.
330 % \item
331 % In columns which have been generated with \texttt{p}, \texttt{m}
332 % or \texttt{b}, the default value of =\parindent= is
333 % \textsf{0pt}.
334 % This can be changed with \\
335 % =>{\setlength{\parindent}{1cm}}p=.
336 % \item
337 % The \texttt{>}-- and \texttt{<}--options were originally
338 % developed for the following application:
339 % =>{$}c<{$}= generates a column in math
340 % mode in a \textsf{tabular}--environment. If you use this type
341 % of a preamble in an \textsf{array}--environment, you get a
342 % column in LR mode because the additional \$'s cancel the
343 % existing \$'s.
344 %
345 % Note that the arguments should only contain declarations, see the
346 % section below.
347 % \item
348 % Using =c!{\hspace{1cm}}c= you get space between two
349 % columns which is enlarged by one centimeter, while
350 % =c@{\hspace{1cm}}c= gives you exactly one centimeter
351 % space between two columns.
352 %
353 % \item
354 % A declaration like =w{l}{3cm}= (or even shorter =wl{3cm}=)
355 % works like an =l= column except that the width will always be
356 % =3cm= regardless of the cell content. Same with =w{c}= or
357 % =w{r}=. This means that it is easy to set up tables in which all
358 % columns have predefined widths.
359 % \end{itemize}
360 %
361 %
362 %
363 % \subsection{A note on the allowed content of \texttt{>\{...\}} and
364 % \texttt{<\{...\}}}
365 %
366 % These specifiers are meant to hold declarations, such as
367 % \verb=>{\itshape}=. They cannot end in commands that take arguments
368 % without providing these arguments as part of the \verb={...}=. It
369 % would be a mistaken assumption that they pick up all or parts of the
370 % alignment entry data if their argument is not provided. E.g.,
371 % \verb=>{\textbf}= would not make the whole column bold nor would it
372 % make the first character bold (technically it would try to
373 % bolden \cs{ignorespaces}). Thus, it would not fail with an error,
374 % but effectively the output would be wrong and not as expected.
375 %
376 % It is also not possible to use an environment that grabs its body,
377 % that is defining
378 % \verb=\NewDocumentEnvironment{foo}{b}{\textit{#1}}{}= and then
379 % trying \verb=>{\begin{foo}= \texttt{c} \verb=<{\end{foo}=. This
380 % will fail with a low-level error message.
381
382 %
383 % \subsection{The behavior of the \cs{\textbackslash} command}
384 %
385 % In the basic \texttt{tabular} implementation of \LaTeX{} the \cs{\textbackslash}
386 % command ending the rows of the \texttt{tabular} or \texttt{array} has
387 % a somewhat inconsistent behavior if its optional argument is used. The
388 % result then depends on the type of rightmost column and as remarked in
389 % Leslie Lamport's \LaTeX{} manual~\cite{bk:lamport} may not always produce the
390 % expected extra space.
391 %
392 %
393 % Without the \textsf{array} package the extra space requested by the
394 % optional argument of \cs{\textbackslash} is measured from the last baseline of
395 % the rightmost column (indicated by ``x'' in the following
396 % example). As a result, swapping the column will give different
397 % results:
398 % \begin{verbatim}
399 % \begin{tabular}[t]{lp{1cm}}
400 % 1 & 1\newline x \\[20pt] 2 & 2 \end{tabular}
401 % \begin{tabular}[t]{p{1cm}l}
402 % 1\newline 1 & x \\[20pt] 2 & 2 \end{tabular}
403 % \end{verbatim}
404 % \pagebreak
405 % If you run this without the \textsf{array} package you will get the
406 % following result:
407 % \begin{center}
408 % \begin{tabular}[t]{lp{1cm}}
409 % 1 & 1\newline x \\[32pt] 2 & 2 \end{tabular}
410 % \begin{tabular}[t]{p{1cm}l}
411 % 1\newline 1 & x \\[20pt] 2 & 2 \end{tabular}
412 % \end{center}
413 % In contrast, when the \textsf{array} package is loaded, the requested
414 % space in the optional argument is always measured from the baseline of
415 % the whole row and not from the last baseline of the rightmost column, thus
416 % swapping columns doesn't change the spacing and we same table height
417 % with an effective 8pt of extra space (as the second line already takes
418 % up 12pt of the requested 20pt):
419 % \begin{center}
420 % \begin{tabular}[t]{lp{1cm}}
421 % 1 & 1\newline x \\[20pt] 2 & 2 \end{tabular}
422 % \begin{tabular}[t]{p{1cm}l}
423 % 1\newline 1 & x \\[20pt] 2 & 2 \end{tabular}
424 % \end{center}
425 %
426 % This correction of behavior only makes a difference if the rightmost column
427 % is a \texttt{p}-column. Thus if you add the \textsf{array}
428 % package to an existing document, you should verify the spacing in all
429 % tables that have this kind of structure.
430 %
431 %
432 % \subsection{Defining new column specifiers}
433 %
434 % \DeleteShortVerb{\=}
435 % \MakeShortVerb{\"}
436 % \DescribeMacro{\newcolumntype}
437 % Whilst it is handy to be able to type
438 % \begin{quote}
439 % ">{"\meta{some declarations}"}{c}<{"\meta{some more
440 % declarations}"}"
441 % \end{quote}
442 % if you have a one-off column in a table, it is rather inconvenient
443 % if you often use columns of this form. The new version allows you
444 % to define a new column specifier, say \texttt{x}, which will expand to
445 % the primitives column specifiers.\footnote{This command was named
446 % \texttt{\textbackslash{}newcolumn} in the \texttt{newarray.sty}.
447 % At the moment \texttt{\textbackslash{}newcolumn} is still supported
448 % (but gives a warning). In later releases it will vanish.} Thus we
449 % may define
450 % \begin{quote}
451 % "\newcolumntype{x}{>{"\meta{some declarations}"}{c}<{"\meta{some
452 % more declarations}"}}"\hspace*{-3cm} ^^A no overfull from this line
453 % \end{quote}
454 % One can then use the \texttt{x} column specifier in the preamble
455 % arguments of all \texttt{array} or \texttt{tabular} environments in
456 % which you want columns of this form.
457 %
458 % It is common to need math-mode and LR-mode columns in the same
459 % alignment. If we define:
460 % \begin{quote}
461 % "\newcolumntype{C}{>{$}c<{$}}" \\
462 % "\newcolumntype{L}{>{$}l<{$}}" \\
463 % "\newcolumntype{R}{>{$}r<{$}}"
464 % \end{quote}
465 % Then we can use \texttt{C} to get centered LR-mode in an
466 % \texttt{array}, or centered math-mode in a \texttt{tabular}.
467 %
468 % The example given above for `center decimal points' could be
469 % assigned to a \texttt{d} specifier with the following command.
470 % \begin{quote}
471 % "\newcolumntype{d}{>{\centerdots}c<{\endcenterdots}}"
472 % \end{quote}
473 %
474 % The above solution always centers the dot in the
475 % column. This does not look too good if the column consists of large
476 % numbers, but to only a few decimal places. An alternative definition
477 % of a \texttt{d} column is
478 % \begin{quote}
479 % "\newcolumntype{d}[1]{>{\rightdots{#1}}r<{\endrightdots}}"
480 % \end{quote}
481 % where the appropriate macros in this case are:\footnote{The package
482 % \texttt{dcolumn.sty} contains more robust macros based on these
483 % ideas.}
484 % \begin{verbatim}
485 % \def\coldot{.}% Or if you prefer, \def\coldot{\cdot}
486 % {\catcode`\.=\active
487 % \gdef.{$\egroup\setbox2=\hbox to \dimen0 \bgroup$\coldot}}
488 % \def\rightdots#1{%
489 % \setbox0=\hbox{$1$}\dimen0=#1\wd0
490 % \setbox0=\hbox{$\coldot$}\advance\dimen0 \wd0
491 % \setbox2=\hbox to \dimen0 {}%
492 % \setbox0=\hbox\bgroup\mathcode`\.="8000 $}
493 % \def\endrightdots{$\hfil\egroup\box0\box2}
494 %\end{verbatim}
495 % Note that "\newcolumntype" takes the same optional argument as
496 % "\newcommand" which declares the number of arguments of the column
497 % specifier being defined. Now we can specify "d{2}" in our preamble
498 % for a column of figures to at most two decimal places.
499 %
500 % A rather different use of the "\newcolumntype" system takes
501 % advantage of the fact that the replacement text in the
502 % "\newcolumntype" command may refer to more than one column. Suppose
503 % that a document contains a lot of \texttt{tabular} environments that
504 % require the same preamble, but you wish to experiment with different
505 % preambles. Lamport's original definition allowed you to do the
506 % following (although it was probably a mis-use of the system).
507 % \begin{quote}
508 % "\newcommand{\X}{clr}"\\
509 % "\begin{tabular}{\X}" \ldots
510 % \end{quote}
511 % \texttt{array.sty} takes great care \textbf{not} to expand the
512 % preamble, and so the above does not work with the new scheme. With
513 % the new version this functionality is returned:
514 % \begin{quote}
515 % "\newcolumntype{X}{clr}"\\
516 % "\begin{tabular}{X}" \ldots
517 % \end{quote}
518 %
519 % The replacement text in a "\newcolumntype" command may refer to any of
520 % the primitives of \texttt{array.sty} see table \ref{tab:opt} on page
521 % \pageref{tab:opt}, or to any new letters defined in other
522 % "\newcolumntype" commands.
523 %
524 %
525 % \DescribeMacro{\showcols}A list of all the currently active
526 % "\newcolumntype" definitions is sent to the terminal and log file if
527 % the "\showcols" command is given.
528 %
529 %
530 % \subsection{Special variations of \texttt{\textbackslash hline}}
531 %
532 % The family of \texttt{tabular} environments allows
533 % vertical positioning with respect to the baseline of
534 % the text in which the environment appears. By default the
535 % environment appears centered, but this can be changed to
536 % align with the first or last line in the environment by
537 % supplying a \texttt{t} or \texttt{b} value to the
538 % optional position argument. However, this does not work
539 % when the first or last element in the environment is a
540 % "\hline" command---in that case the environment is
541 % aligned at the horizontal rule.
542 %
543 % \pagebreak[3]
544 %
545 % Here is an example:
546 % \begin{center}
547 % \begin{minipage}[t]{.4\linewidth}
548 % Tables
549 % \begin{tabular}[t]{l}
550 % with no\\ hline \\ commands \\ used
551 % \end{tabular} versus \\ tables
552 % \begin{tabular}[t]{|l|}
553 % \hline
554 % with some \\ hline \\ commands \\
555 % \hline
556 % \end{tabular} used.
557 % \end{minipage}
558 % \begin{minipage}[t]{.5\linewidth}
559 % \begin{verbatim}
560 % Tables
561 % \begin{tabular}[t]{l}
562 % with no\\ hline \\ commands \\ used
563 % \end{tabular} versus tables
564 % \begin{tabular}[t]{|l|}
565 % \hline
566 % with some \\ hline \\ commands \\
567 % \hline
568 % \end{tabular} used.
569 % \end{verbatim}
570 % \end{minipage}
571 % \end{center}
572 %
573 % \DescribeMacro\firsthline
574 % \DescribeMacro\lasthline
575 % Using "\firsthline" and "\lasthline" will
576 % cure the problem, and the tables will align properly as long
577 % as their first or last line does not contain extremely large
578 % objects.
579 % \begin{center}
580 % \begin{minipage}[t]{.4\linewidth}
581 % Tables
582 % \begin{tabular}[t]{l}
583 % with no\\ line \\ commands \\ used
584 % \end{tabular} versus \\ tables
585 % \begin{tabular}[t]{|l|}
586 % \firsthline
587 % with some \\ line \\ commands \\
588 % \lasthline
589 % \end{tabular} used.
590 % \end{minipage}
591 % \begin{minipage}[t]{.5\linewidth}
592 % \begin{verbatim}
593 % Tables
594 % \begin{tabular}[t]{l}
595 % with no\\ line \\ commands \\ used
596 % \end{tabular} versus tables
597 % \begin{tabular}[t]{|l|}
598 % \firsthline
599 % with some \\ line \\ commands \\
600 % \lasthline
601 % \end{tabular} used.
602 % \end{verbatim}
603 % \end{minipage}
604 % \end{center}
605 % \DescribeMacro\extratabsurround
606 % The implementation of these two commands contains an extra
607 % dimension, which is called "\extratabsurround", to add some
608 % additional space at the top and the bottom of such an environment.
609 % This is useful if such tables are nested.
610 %
611 % \section{Final Comments}
612 %
613 % \subsection{Handling of rules}
614 %
615 % There are two possible approaches to the handling of horizontal and
616 % vertical rules in tables:
617 % \begin{enumerate}
618 % \item rules can be placed into the available space without
619 % enlarging the table, or
620 % \item rules can be placed between columns or rows thereby enlarging
621 % the table.
622 % \end{enumerate}
623 % For vertical rules \texttt{array.sty} implements the second
624 % possibility while the default implementation in the \LaTeX{} kernel
625 % implements the first concept.
626 % Both concepts have their merits but
627 % one has to be aware of the individual implications.
628 % \begin{itemize}
629 % \item
630 % With standard \LaTeX{} adding vertical rules to a table will
631 % not affect the
632 % width of the table (unless double rules are used), e.g.,
633 % changing a preamble from \verb=lll= to \verb=l|l|l= does not
634 % affect the document other than adding rules to the table. In
635 % contrast, with \texttt{array.sty} a table that just fit the
636 % \verb=\textwidth= might now produce an overfull box.
637 % \item
638 % With standard \LaTeX{} modifying the width of rules could result
639 % in ugly looking tables because without adjusting the
640 % \verb=\tabcolsep=, etc.\ the space between rule and column could
641 % get too small (or too large). In fact even overprinting of text is
642 % possible. In contrast, with \texttt{array.sty} modifying any such
643 % length usually works well as the actual visual white space (from
644 % \verb=\tabcolsep=, etc.) does not depend on the width of the
645 % rules.
646 % \item
647 % With standard \LaTeX{} boxed tabulars actually have strange
648 % corners because the horizontal rules end in the middle of the
649 % vertical ones. This looks very unpleasant when a large
650 % \verb=\arrayrulewidth= is chosen. In that case a simple table like
651 %\begin{verbatim}
652 %\setlength{\arrayrulewidth}{5pt}
653 %\begin{tabular}{|l|}
654 % \hline A \\ \hline
655 %\end{tabular}
656 %\end{verbatim}
657 % will produce something like
658 % \begin{center}
659 %\setlength{\arrayrulewidth}{5pt}
660 %\begin{tabular}{@{}l@{}}
661 % \hline \null\hskip-.5\arrayrulewidth\vline
662 % \hskip\tabcolsep
663 % A\hskip\tabcolsep
664 % \vline\hskip-.5\arrayrulewidth\null \\ \hline
665 %\end{tabular}
666 % \quad
667 % instead of
668 % \quad
669 %\begin{tabular}{|l|}
670 % \hline A \\ \hline
671 %\end{tabular}
672 % \end{center}
673 % \end{itemize}
674 %
675 % Horizontal rules produced with \cs{hline} add to the table height in
676 % both implementations but they differ in handling double \cs{hline}s.
677 % In contrast a \cs{cline} does not change the table
678 % height.\footnote{All a bit inconsistent, but nothing that can be
679 % changed after being 30+ years in existence.}
680 %
681 % \subsection{Comparisons with older versions of \texttt{array.sty}}
682 %
683 % There are some differences in the way version 2.1 treats incorrect
684 % input, even if the source file does not appear to use any of the
685 % extra features of the new version.
686 % \begin{itemize}
687 % \item A preamble of the form "{wx*{0}{abc}yz}" was treated by
688 % versions prior to 2.1 as "{wx}". Version 2.1 treats it as "{wxyz}"
689 % \item An incorrect positional argument such as \texttt{[Q]} was
690 % treated as \texttt{[c]} by \texttt{array.sty}, but is now treated as
691 % \texttt{[t]}.
692 % \item A preamble such as "{cc*{2}}" with an error in
693 % a $*$-form will generate different errors in the new version. In
694 % both cases the error message is not particularly helpful to the
695 % casual user.
696 % \item Repeated \texttt{<} or \texttt{>} constructions
697 % generated an error in earlier versions, but are now allowed in
698 % this package. ">{"\meta{decs1}"}>{"\meta{decs2}"}" is treated the
699 % same as ">{"\meta{decs2}\meta{decs1}"}".
700 % \item The "\extracolsep"
701 % command does not work with the old versions of \texttt{array.sty},
702 % see the comments in \texttt{array.bug}. With version 2.1
703 % "\extracolsep" may again be used in \texttt{@}-expressions as in
704 % standard \LaTeX, and also in \texttt{!}-expressions (but see the
705 % note below).
706 % \end{itemize}
707 %
708 % Prior to version 2.4f the space added by the optional argument to "\\"
709 % was added inside an m-cell if the last column was of type
710 % \texttt{m}. As a result that cell was vertically centered with that
711 % space inside, resulting in a strange offset. Since 2.4f, this space
712 % is now added after centering the cell.
713 %
714 % A similar problem happened when "\extrarowheight" was used. For that
715 % reason m-cells now manually position the cell content which
716 % allows to ignore this extra space request during the vertical alignment.
717 %
718 %
719 % \subsection{Bugs and Features}
720 %
721 % \begin{itemize}
722 % \item Error messages generated when parsing the column specification
723 % refer to the preamble argument \textbf{after} it has been re-written
724 % by the "\newcolumntype" system, not to the preamble entered by the
725 % user. This seems inevitable with any system based on
726 % pre-processing and so is classed as a \textbf{feature}.
727 %
728 % \item The treatment of multiple \texttt{<} or \texttt{>}
729 % declarations may seem strange at first. Earlier implementations
730 % treated ">{"\meta{decs1}"}>{"\meta{decs2}"}" the same as
731 % ">{"\meta{decs1}\meta{decs2}"}". However this did not give the
732 % user the opportunity of overriding the settings of a
733 % "\newcolumntype" defined using these declarations. For example,
734 % suppose in an \texttt{array} environment we use a \texttt{C}
735 % column defined as above. The \texttt{C} specifies a centered text
736 % column, however ">{\bfseries}C", which re-writes to
737 % ">{\bfseries}>{$}c<{$}" would not specify a bold column as might
738 % be expected, as the preamble would essentially expand to
739 % "\hfil$\bfseries$#$ $\hfil" and so the column entry would not be in the
740 % scope of the "\bfseries"\,! The present version switches the order
741 % of repeated declarations, and so the above example now produces a
742 % preamble of the form "\hfil$" "$\bfseries#$" "$\hfil", and the
743 % dollars cancel each other out without limiting the scope of the
744 % "\bfseries".
745 %
746 % \item The use of "\extracolsep" has been subject to the following
747 % two restrictions. There must be at most one "\extracolsep"
748 % command per "@", or "!" expression and the command must be
749 % directly entered into the "@" expression, not as part of a macro
750 % definition. Thus "\newcommand{\ef}{\extracolsep{\fill}}" \ldots
751 % "@{\ef}" does not work with this package. However you can use
752 % something like
753 % "\newcolumntype{e}{@{\extracolsep{\fill}}" instead.
754 %
755 % \item As noted by the \LaTeX{} book, for the purpose of
756 % "\multicolumn" each column with the exception of the first one
757 % consists of the entry and the \emph{following} inter-column
758 % material. This means that in a tabular with the preamble
759 % "|l|l|l|l|" input such as "\multicolumn{2}{|c|}" in
760 % anything other than the first column is incorrect.
761
762 % In the standard array/tabular implementation this error is not so
763 % noticeable as that version contains negative spacing so that each
764 % "|" takes up no horizontal space. But since in this package the
765 % vertical lines take up their natural width one sees two lines if
766 % two are specified.
767 %
768 % \end{itemize}
769 %
770 %
771 % \section{Support for tagged PDF}
772 %
773 % With version 2.6a the package is made tagging aware, which means that
774 % it will automatically produce tagged tables (necessary, for example, for
775 % accessibility) if tagging is requested via \cs{DocumentMetadata}.
776 %
777 % More granular control, e.g., explicitly deciding which cells are
778 % header cells, etc., is currently under development, but syntax for
779 % this will not appear in this package. Instead it will become
780 % available across all tabular-generating packages and then
781 % automatically apply here as well.
782 %
783 % Enabling \LaTeX{} to automatically produce tagged PDF is a long-term
784 % project and this is a tiny step in this puzzle. For more information
785 % on the project and already available functionality, see
786 % \url{https://latex-project.org/publications/indexbytopic/pdf} and
787 % \url{https://github.com/latex3/tagging-project}.
788 %
789 %
790 % \section{Package hooks}
791 %
792 % To support extensions made by other packages a few hooks
793 % have been added. There are
794 % \begin{description}
795 %
796 % \item[\hook{tbl/init}]
797 %
798 % This hook is executed at the start of the \env{tabular} after the
799 % preamble has been evaluated. It accepts two arguments, the number
800 % of columns and the full user preamble and can be used to make
801 % special initializations.
802 %
803 % \item[\hook{tbl/row/init}]
804 %
805 % This hook is invoked just before a row is about to start or could
806 % start, i.e., just before the first row and then after each row
807 % including the last. At this point tagging for the row has not been
808 % added and the hook can therefore only contain declarations (which
809 % have to to be global as everything is executed within a
810 % \cs{noalign}) and it can contain special commands such as
811 % \cs{hline}, \cs{cline}, or \cs{rowcolor}, that are allowed after
812 % \verb=\\=.
813 %
814 % \item[\hook{tbl/row/begin}]
815 %
816 % This hook is executed after the tagging for the row is done but
817 % before the tagging for the cell is added, so again it is not
818 % intended for adding any typeset material. It accepts the current
819 % row number as its argument.
820 %
821 % This hook is probably of limited use, because it is in fact local
822 % to the first cell due to technical restrictions. Local
823 % declarations therefore do not apply to the whole row but just to
824 % its first cell.
825 %
826 % So perhaps this hook and the corresponding \texttt{/end} hook
827 % are removed again before the final release in June.
828 %
829 % \item[\hook{tbl/row/end}]
830 %
831 % This hook is executed when \verb=\\= or the end of the tabular is
832 % seen, after the tagging for the cell is done but before the
833 % row-end tag is added, so again it is not
834 % intended for adding any typeset material. It accepts the current
835 % row number as its argument.
836 %
837 % It is implemented as a reversed hook.
838 %
839 % \item[\hook{tbl/cell/init}]
840 %
841 % This hook is executed at the start of each cell (before tagging for
842 % the cell is set up), it should therefore not generate any textual
843 % material. It accepts the current row and column numbers and the
844 % current cell type (\texttt{c}, \texttt{l}, \ldots) as its
845 % arguments.
846 %
847 % Cell type in the context of hooks means only the built-in specifiers and
848 % not those that are added using \cs{newcolumntype}. When the
849 % preamble for the tabular is constructed the \cs{newcolumntype}
850 % specfiers are expanded until only base ones remain. The
851 % \pkg{array} package defines two specifiers with
852 % \cs{newcolumntype}: \texttt{w} and \texttt{W}. By the hooks both
853 % are seen as \texttt{c} type cells, because technically that's
854 % what they are.
855 %
856 % \item[\hook{tbl/cell/begin}]
857 %
858 % This hook is executed after the start-tag for the cell is added
859 % but before any code from \verb=>{...}= is looked at and can, with
860 % some care, contain material that is typeset as part of the cell.
861 % It accepts the current row and column numbers and the current
862 % cell type as its arguments.
863 %
864 % \item[\hook{tbl/cell/end}]
865 %
866 % This hook is executed at the end of the cell before the end-tag for
867 % the cell is added and thus can theoretically contain material
868 % that is typeset as part of the cell. It accepts the current
869 % row and column numbers and the
870 % current cell type as its arguments.
871 %
872 % It is implemented as a reversed hook.
873 %
874 % \end{description}
875 %
876 %
877 %
878 %
879 %
880 %
881 % \changes{v2.2b}{1994/02/04}{Removed interactive prompt}
882 %
883 % \MaybeStop{
884 % \begin{thebibliography}{1}
885 % \bibitem{bk:GMS94} \textsc{M.~Goossens}, \textsc{F.~Mittelbach}
886 % and \textsc{A.~Samarin}.
887 % \newblock The \LaTeX{} Companion.
888 % \newblock
889 % Addison-Wesley, Reading, Massachusetts, 1994.
890 % \bibitem{bk:knuth} \textsc{D. E. Knuth}.
891 % \newblock The \TeX{}book (Computers \& Typesetting Volume A).
892 % \newblock
893 % Addison-Wesley, Reading, Massachusetts, 1986.
894 % \bibitem{bk:lamport} \textsc{L. Lamport}.
895 % \newblock
896 % \LaTeX\ --- A Document Preparation System.
897 % \newblock
898 % Addison-Wesley, Reading, Massachusetts, 1986.
899 % \end{thebibliography}
900 % } ^^A end of \MaybeStop
901 %
902 %
903 %
904 %
905 % \section{The documentation driver file}
906 %
907 % The first bit of code contains the documentation driver file for
908 % \TeX{}, i.e., the file that will produce the documentation you are
909 % currently reading. It will be extracted from this file by the
910 % \texttt{docstrip} program.
911 % \begin{macrocode}
912 %<*driver>
913 \NeedsTeXFormat{LaTeX2e}[2024/06/01]
914 % \end{macrocode}
915 %
916 % We switched from \cls{ltxdoc} to \cls{l3doc} to get support for
917 % code written in the L3 programming layer. The first is that we
918 % are currently missing \cs{MaintainedByLaTeXTeam}, so we have to
919 % provide that for now.
920 % \begin{macrocode}
921 \documentclass{l3doc}
922
923 % currently missing in l3doc
924 \makeatletter
925 \def\MaintainedBy#1{\gdef\@maintainedby{#1}}
926 \let\@maintainedby\@empty
927 \def\MaintainedByLaTeXTeam#1{%
928 {\gdef\@maintainedby{%
929 This file is maintained by the \LaTeX{} Project team.\\%
930 Bug reports can be opened (category \texttt{#1}) at\\%
931 \url{https://latex-project.org/bugs.html}.}}}
932 \def\@maketitle{%
933 \newpage
934 \null
935 \vskip 2em%
936 \begin{center}%
937 \let \footnote \thanks
938 {\LARGE \@title \par}%
939 \vskip 1.5em%
940 {\large
941 \lineskip .5em%
942 \begin{tabular}[t]{c}%
943 \@author
944 \end{tabular}\par}%
945 \vskip 1em%
946 {\large \@date}%
947 \ifx\@maintainedby\@empty
948 \else
949 \vskip 1em%
950 \fbox{\fbox{\begin{tabular}{@{}l@{}}\@maintainedby\end{tabular}}}%
951 \fi
952 \end{center}%
953 \par
954 \vskip 1.5em}
955 \makeatother
956
957 % undo the default is not used:
958
959 \IfFormatAtLeastTF {2020/10/01}
960 {\AtBeginDocument[ltxdoc]{\DeleteShortVerb{\|}} }
961 {\AtBeginDocument{\DeleteShortVerb{\|}} }
962
963 \usepackage{array}
964
965 % Allow large table at bottom
966 \renewcommand{\bottomfraction}{0.7}
967
968 \EnableCrossrefs
969 %\DisableCrossrefs % Say \DisableCrossrefs if index is ready
970
971 \RecordChanges % Gather update information
972
973 \CodelineIndex % Index code by line number
974
975 %\OnlyDescription % comment out for implementation details
976 %\OldMakeindex % use if your MakeIndex is pre-v2.9
977
978 \begin{document}
979 \DocInput{array.dtx}
980 \end{document}
981 %</driver>
982 % \end{macrocode}
983 %
984 %
985 % \section{A note on the updates done December 2023}
986 %
987 % We introduced support for tagged PDF and at the same time we added
988 % code to determine row and column numbers for each cell in
989 % preparation for supporting formatting or type specifications for individual
990 % cells (or group of cells) from the outside, e.g., \enquote{rows 1,
991 % 2, and 10 are header rows} (syntax to be decided).
992 %
993 % This new code is already written with L3 programming layer conventions
994 % while most of the legacy code is still as it was before. This make the code
995 % currently somewhat clattered, unfortunately. Eventually this will all move to L3
996 % programming layer but this will take time.
997 %
998 %
999 % \begin{macrocode}
1000 %<@@=tbl>
1001 \ExplSyntaxOn
1002 % \end{macrocode}
1003 %
1004 %
1005 %
1006 %
1007 %
1008 % \section{The construction of the preamble}
1009 %
1010 % \DeleteShortVerb{\"}
1011 % \MakeShortVerb{\=}
1012 %
1013 % It is obvious that those environments will consist mainly of an
1014 % =\halign=, because \TeX\ typesets tables using this primitive.
1015 % That is why we will now take a look at the algorithm which determines
1016 % a preamble for a =\halign= starting with a given user preamble
1017 % using the options mentioned above.
1018 %
1019 %
1020 % The current version is defined at the top of the file looking
1021 % something like this
1022 % \begin{macrocode}
1023 %<*package>
1024 %\NeedsTeXFormat{LaTeX2e}[1994/05/13]
1025 %\ProvidesPackage{array}[\filedate\space version\fileversion]
1026 % \end{macrocode}
1027 %
1028 % The most interesting macros of this implementation are without doubt
1029 % those which are responsible for the construction of the preamble for
1030 % the =\halign=. The underlying algorithm was developed by
1031 % \textsc{Lamport} (resp.\ \textsc{Knuth}, see texhax V87\#??), and it
1032 % has been extended and improved.
1033 %
1034 % The user preamble will be read \textsf{token} by \textsf{token}. A
1035 % \textsf{token} is a single character like \texttt{c} or a block
1036 % enclosed in ={...}=. For example the preamble of
1037 % =\begin{tabular}=\linebreak[0]={lc||c@{\hspace{1cm}}}= consists of
1038 % the \textsf{token} \texttt{l}, \texttt{c}, \texttt{|}, \texttt{|},
1039 % \texttt{@} and =\hspace{1cm}=.
1040 %
1041 % The currently used \textsf{token} and the one, used before, are needed
1042 % to decide on how the construction of the preamble has to be
1043 % continued.
1044 % In the example mentioned above the \texttt{l} causes the preamble
1045 % to begin with =\hskip\tabcolsep=. Furthermore
1046 % =# \hfil= would be appended to define a flush left column.
1047 % The next \textsf{token} is a \texttt{c}. Because it was preceded by an
1048 % \texttt{l} it generates a new column. This is done with
1049 % =\hskip \tabcolsep & \hskip \tabcolsep=. The column which is to
1050 % be centered will be appended with =\hfil # \hfil=.
1051 % The \textsf{token} \texttt{|} would then add a space of
1052 % =\hskip \tabcolsep=
1053 % and a vertical line because the last
1054 % \textsf{tokens} was a \texttt{c}.
1055 % The following \textsf{token} \texttt{|} would only add a space
1056 % =\hskip \doublerulesep= because it was preceded by the
1057 % \textsf{token} \texttt{|}. We will not discuss our example further but
1058 % rather take a look at the general case of constructing preambles.
1059 %
1060 % The example shows that the desired preamble for the
1061 % =\halign= can be constructed as soon as the action of all
1062 % combinations
1063 % of the preamble \textsf{tokens} are specified. There are 18 such
1064 % \textsf{tokens}
1065 % so we have $19 \cdot 18 \string= 342$ combinations if we count the
1066 % beginning of
1067 % the preamble as a special \textsf{token}. Fortunately, there are many
1068 % combinations which generate the same spaces, so we can define
1069 % \textsf{token} classes. We will identify a
1070 % \textsf{token} within a class with a number, so we can insert the
1071 % formatting (for example of a column).
1072 % Table~\ref{tab:Klassen} lists all \textsf{token} classes and
1073 % their corresponding numbers.
1074 % \begin{table}[ht]
1075 % \begin{center}
1076 % \begin{tabular}[t]{>{\ttfamily}ccc}
1077 % \textsf{token} & =\@chclass= & =\@chnum= \\[2mm]
1078 % c & 0 & 0 \\
1079 % l & 0 & 1 \\
1080 % r & 0 & 2 \\
1081 % m-arg & 0 & 3 \\
1082 % p-arg & 0 & 4 \\
1083 % b-arg & 0 & 5 \\
1084 % | & 1 & 0 \\
1085 % !-arg & 1 & 1 \\
1086 % <-arg & 2 & --- \\
1087 % >-arg & 3 & ---
1088 % \end{tabular}
1089 % \kern3mm \vrule \kern3mm%
1090 % \begin{tabular}[t]{>{\ttfamily}ccc}
1091 % \textsf{token} & =\@chclass= & =\@chnum= \\[2mm]
1092 % Start & 4 & --- \\
1093 % @-arg & 5 & --- \\
1094 % ! & 6 & --- \\
1095 % @ & 7 & --- \\
1096 % < & 8 & --- \\
1097 % > & 9 & --- \\
1098 % m & 10 & 3 \\
1099 % p & 10 & 4 \\
1100 % b & 10 & 5
1101 % \end{tabular}
1102 % \end{center}
1103 % \caption{Classes of preamble \textsf{tokens}}
1104 % \label{tab:Klassen}
1105 % \end{table}
1106 %
1107 %
1108 % \begin{macro}[int]{\@chclass}
1109 % \begin{macro}[int]{\@chnum}
1110 % \begin{macro}[int]{\@lastchclass}
1111 % The class and the number of the current \textsf{token} are saved in
1112 % the
1113 % \textsf{count} registers =\@chclass=
1114 % and =\@chnum=, while the class of the previous
1115 % \textsf{token} is stored in the
1116 % \textsf{count} register =\@lastchclass=.
1117 % All of the mentioned registers are already allocated in
1118 % the \LaTeX{} format,
1119 % which is the reason why the following three lines of code are
1120 % commented out.
1121 % Later throughout the text I will not mention it again explicitly
1122 % whenever I use a =%= sign. These parts are already defined in
1123 % the \LaTeX{} format.
1124 % \begin{macrocode}
1125 % \newcount \@chclass
1126 % \newcount \@chnum
1127 % \newcount \@lastchclass
1128 % \end{macrocode}
1129 % \end{macro}
1130 % \end{macro}
1131 % \end{macro}
1132 %
1133 %
1134 %
1135 % \begin{macro}[int]{\@addtopreamble}
1136 % We will save the already constructed preamble for
1137 % the =\halign=
1138 % in the global macro =\@preamble=. This will then be
1139 % enlarged with
1140 % the command =\@addtopreamble=.
1141 % \begin{macrocode}
1142 \def\@addtopreamble#1{\xdef\@preamble{\@preamble #1}}
1143 % \end{macrocode}
1144 % \end{macro}
1145 %
1146 %
1147 %
1148 %
1149 %
1150 % \subsection{The character class of a \textsf{token}}
1151 %
1152 % \begin{macro}[int]{\@testpach}
1153 % \changes{v2.0a}{1989/05/12}{p option renamed to m (middle).}
1154 % \changes{v2.0a}{1989/05/12}{t option renamed to p to be compatible to
1155 % the original.}
1156 % With the help of =\@lastchclass= we can now define a macro
1157 % which determines the class and the number of a given preamble
1158 % \textsf{token}
1159 % and assigns them to the registers
1160 % =\@chclass= and =\@chnum=.
1161 % \changes{v2.0f}{1992/02/29}{Argument removed since implicitly known}
1162 % \begin{macrocode}
1163 \ExplSyntaxOff
1164 \def\@testpach{\@chclass
1165 % \end{macrocode}
1166 % First we deal with the cases in which the \textsf{token}
1167 % (=#1=) is the argument of \texttt{!}, \texttt{@}, \texttt{<} or
1168 % \texttt{>}. We can see this from the value of =\@lastchclass=:
1169 % \begin{macrocode}
1170 \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
1171 \ifnum \@lastchclass=7 5 \else
1172 \ifnum \@lastchclass=8 \tw@ \else
1173 \ifnum \@lastchclass=9 \thr@@@@
1174 % \end{macrocode}
1175 % Otherwise we will assume that the \textsf{token} belongs to the
1176 % class $0$
1177 % and assign the corresponding number to =\@chnum= if our
1178 % assumption is correct.
1179 % \begin{macrocode}
1180 \else \z@
1181 % \end{macrocode}
1182 % If the last \textsf{token} was a \texttt{p}, \texttt{m} or a
1183 % \texttt{b}, =\@chnum= already has the right value. This is the
1184 % reason for the somewhat curious choice of the \textsf{token}
1185 % numbers in class $10$.
1186 % \begin{macrocode}
1187 \ifnum \@lastchclass = 10 \else
1188 % \end{macrocode}
1189 % Otherwise we will check if =\@nextchar= is either a \texttt{c},
1190 % \texttt{l} or an \texttt{r}. Some applications change the
1191 % catcodes of certain characters like ``\texttt{@}'' in
1192 % \texttt{amstex.sty}. As a result the tests below would fail since
1193 % they assume non-active character tokens. Therefore we evaluate
1194 % =\@nextchar= once thereby turning the first token of its
1195 % replacement text into a char. At this point here this should have
1196 % been the only char present in =\@nextchar= which put into via a
1197 % =\def=.
1198 % \changes{v2.0f}{1992/02/29}{Ensure to test a char which is not active}
1199 % \begin{macrocode}
1200 \edef\@nextchar{\expandafter\string\@nextchar}%
1201 \@chnum
1202 \if \@nextchar c\z@ \else
1203 \if \@nextchar l\@ne \else
1204 \if \@nextchar r\tw@ \else
1205 % \end{macrocode}
1206 % If it is a different \textsf{token}, we know that the class was
1207 % not $0$. We assign the value $0$ to =\@chnum= because this value
1208 % is needed for the \texttt{|}--\textsf{token}. Now we must check
1209 % the remaining classes. Note that the value of =\@chnum= is
1210 % insignificant here for most classes.
1211 % \begin{macrocode}
1212 \z@ \@chclass
1213 \if\@nextchar |\@ne \else
1214 \if \@nextchar !6 \else
1215 \if \@nextchar @7 \else
1216 \if \@nextchar <8 \else
1217 \if \@nextchar >9 \else
1218 % \end{macrocode}
1219 % The remaining permitted \textsf{tokens} are \texttt{p},
1220 % \texttt{m} and \texttt{b} (class $10$).
1221 % \begin{macrocode}
1222 10
1223 \@chnum
1224 \if \@nextchar m\thr@@@@ \else
1225 \if \@nextchar p4 \else
1226 \if \@nextchar b5 \else
1227 % \end{macrocode}
1228 % Now the only remaining possibility is a forbidden \textsf{token},
1229 % so we choose class $0$ and number $0$ and give an error message.
1230 % Then we finish the macro by closing all =\if='s.
1231 % \begin{macrocode}
1232 \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi
1233 \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi}
1234 \ExplSyntaxOn
1235 % \end{macrocode}
1236 % \end{macro}
1237 %
1238 %
1239 %
1240 %
1241 %
1242 % \subsection{Multiple columns (\texorpdfstring{$*$}{*}--form)}
1243 %
1244 % \begin{macro}[int]{\@xexpast}
1245 % \begin{macro}[int]{\the@toks}
1246 % \begin{macro}[int]{\the@toksz}
1247 % \label{@xexpast} Now we discuss the macro that deletes all forms
1248 % of type =*{=\textit{N\/}=}{=\textit{String\/}=}= from a user
1249 % preamble and replaces them with \textit{N} copies of
1250 % \textit{String}. Nested $*$--expressions are dealt with
1251 % correctly, that means $*$--expressions are not substituted if
1252 % they are in explicit braces, as in =@{*}=.
1253 %
1254 % This macro is called via
1255 % =\@xexpast=\meta{preamble}=*0x\@@@@=.
1256 % The $*$--expression =*0x= is being used to terminate the
1257 % recursion,
1258 % as we shall see later, and =\@@@@= serves as an argument
1259 % delimiter. =\@xexpast= has four arguments. The first
1260 % one is the part of the
1261 % user preamble before the first $*$--expression while the second
1262 % and third ones are the arguments of the first $*$--expression
1263 % (that is \textit{N} and \textit{String} in the notation mentioned
1264 % above).
1265 % The fourth argument is the rest of the preamble.
1266 % \begin{macrocode}
1267 \def\@xexpast#1*#2#3#4\@@@@{%
1268 % \end{macrocode}
1269 % The number of copies of \textit{String} (=#2=) that are to be
1270 % produced will be saved in a \textsf{count} register.
1271 % \begin{macrocode}
1272 \@tempcnta #2
1273 % \end{macrocode}
1274 % We save the part of the preamble which does not
1275 % contain a $*$--form (=#1=)
1276 % in a \PlainTeX\ \textsf{token} register.
1277 % We also save \textit{String} (=#3=) using a \LaTeX\
1278 % \textsf{token} register.
1279 % \begin{macrocode}
1280 \toks@={#1}\@temptokena={#3}%
1281 % \end{macrocode}
1282 % Now we have to use a little trick to produce \textit{N} copies of
1283 % \textit{String}.
1284 % We could try =\def\@tempa{#1}= and then
1285 % \textit{N} times =\edef\@tempa{\@tempa#3}=. This would have the
1286 % undesired effect that all macros within =#1= and =#3=
1287 % would be expanded, although, for example, constructions like
1288 % =@{..}= are not supposed to be changed.
1289 % That is why we =\let= two control sequences to
1290 % be equivalent to =\relax=.
1291 % \begin{macrocode}
1292 \let\the@toksz\relax \let\the@toks\relax
1293 % \end{macrocode}
1294 % Then we ensure that =\@tempa= contains
1295 % ={\the@toksz\the@toks...\the@toks}= (the macro
1296 % =\the@toks= exactly \textit{N\/} times) as substitution text.
1297 % \begin{macrocode}
1298 \def\@tempa{\the@toksz}%
1299 \ifnum\@tempcnta >0 \@whilenum\@tempcnta >0\do
1300 {\edef\@tempa{\@tempa\the@toks}\advance \@tempcnta \m@ne}%
1301 % \end{macrocode}
1302 % If \textit{N\/} was greater than zero we prepare for another call
1303 % of =\@xexpast=. Otherwise we assume we have reached the end of
1304 % the user preamble, because we had appended =*0x\@@@@= when we first
1305 % called =\@xexpast=. In other words: if the user inserts
1306 % =*{0}{..}= in his preamble, \LaTeX\ ignores the rest of it.
1307 % \begin{macrocode}
1308 \let \@tempb \@xexpast \else
1309 \let \@tempb \@xexnoop \fi
1310 % \end{macrocode}
1311 % Now we will make sure that the part of the user preamble, which
1312 % was already dealt with, will be saved again in =\@tempa=.
1313 % \begin{macrocode}
1314 \def\the@toksz{\the\toks@}\def\the@toks{\the\@temptokena}%
1315 \edef\@tempa{\@tempa}%
1316 % \end{macrocode}
1317 % We have now evaluated the first $*$--expression, and the user
1318 % preamble up to this point
1319 % is saved in =\@tempa=. We will put the contents of
1320 % =\@tempa= and the rest of the user preamble together and work
1321 % on the result with =\@tempb=. This macro either corresponds
1322 % to =\@xexpast=, so that the next
1323 % $*$--expression is handled, or to the macro =\@xexnoop=,
1324 % which only ends the recursion by deleting its argument.
1325 % \begin{macrocode}
1326 \expandafter \@tempb \@tempa #4\@@@@}
1327 % \end{macrocode}
1328 % \end{macro}
1329 % \end{macro}
1330 % \end{macro}
1331 %
1332 % \begin{macro}[int]{\@xexnoop}
1333 % So the first big problem is solved. Now it is easy to
1334 % specify =\@xexnoop=.
1335 % Its argument is delimited by =\@@@@= and it simply expands to
1336 % nothing.
1337 % \begin{macrocode}
1338 % \def\@xexnoop#1\@@@@{}
1339 % \end{macrocode}
1340 % \end{macro}
1341 %
1342 %
1343 %
1344 %
1345 % \section{The insertion of declarations
1346 % (\texttt{>}, \texttt{<}, \texttt{!}, \texttt{@})}
1347 %
1348 %
1349 % The preamble will be enlarged with the help of =\xdef=, but the
1350 % arguments of \texttt{>}, \texttt{<},~\texttt{!}\ and \texttt{@} are
1351 % not supposed to be expanded during the construction (we want an
1352 % implementation that doesn't need a =\protect=). So we have to find a
1353 % way to inhibit the expansion of those arguments.
1354 %
1355 % We will solve this problem with \textsf{token} registers. We need
1356 % one register for every \texttt{!}\ and \texttt{@}, while we need two
1357 % for every \texttt{c}, \texttt{l}, \texttt{r}, \texttt{m}, \texttt{p}
1358 % or \texttt{b}. This limits the number of columns of a table because
1359 % there are only 256 \textsf{token} registers. But then, who needs
1360 % tables with more than 100 columns?
1361 %
1362 % One could also find a solution which only needs two or three
1363 % \textsf{token} registers by proceeding similarly as in the macro
1364 % =\@xexpast= (see page \pageref{@xexpast}). The advantage of our
1365 % approach is the fact that we avoid some of the problems that arise
1366 % with the other method\footnote{Maybe there are also historical
1367 % reasons.}.
1368 %
1369 % So how do we proceed? Let us assume that we had =!{foo}= in the
1370 % user preamble and say we saved \texttt{foo} in
1371 % \textsf{token} register $5$. Then we call
1372 % =\@addtopreamble{\the@toks5}= where
1373 % =\the@toks= is defined in a way that it does not expand
1374 % (for example it could be equivalent to =\relax=). Every
1375 % following call
1376 % of =\@addtopreamble= leaves =\the@toks5= unchanged in
1377 % =\@preamble=. If the construction of the preamble is completed
1378 % we change the definition of =\the@toks= to
1379 % =\the\toks= and expand =\@preamble= for the last time.
1380 % During this process all parts of the form
1381 % =\the@toks=\meta{Number}
1382 % will be substituted by the contents of the respective \textsf{token}
1383 % registers.
1384 %
1385 % As we can see from this informal discussion the construction of the
1386 % preamble has to take place within a group, so that the
1387 % \textsf{token} registers we use will be freed later on. For that
1388 % reason we keep all assignments to =\@preamble= global; therefore the
1389 % replacement text of this macro will remain the same after we leave
1390 % the group.
1391 %
1392 % \begin{macro}[int]{\count@}
1393 % We further need a \textsf{count} register to remember which
1394 % \textsf{token} register is to be used next. This will be
1395 % initialized with $-1$ if we want to begin with the \textsf{token}
1396 % register $0$. We use the \PlainTeX\ scratch register =\count@=
1397 % because everything takes place locally. All we have to do is
1398 % insert =\the@toks= =\the= =\count@= into the preamble.
1399 % =\the@toks= will remain unchanged and =\the\count@= expands into
1400 % the saved number.
1401 % \end{macro}
1402 %
1403 % \begin{macro}[int]{\prepnext@tok}
1404 % The macro =\prepnext@tok= is in charge of preparing the next
1405 % \textsf{token} register. For that purpose we increase
1406 % =\count@= by $1$:
1407 % \begin{macrocode}
1408 \def\prepnext@tok{\advance \count@ \@ne
1409 % \end{macrocode}
1410 % Then we locally delete any contents the
1411 % \textsf{token} register might have.
1412 % \begin{macrocode}
1413 \toks\count@{}}
1414 % \end{macrocode}
1415 % \end{macro}
1416 %
1417 % \begin{macro}[int]{\save@decl}
1418 % During the construction of the preamble the current
1419 % \textsf{token} is always saved in the macro =\@nextchar= (see the
1420 % definition of =\@mkpream= on page \pageref{@mkpream}). The macro
1421 % =\save@decl= saves it into the next free \textsf{token} register,
1422 % i.e.\ in =\toks\count@=.
1423 % \changes{v2.0c}{1990/08/14}{\cs{relax} removed and added elsewhere.}
1424 % \begin{macrocode}
1425 \def\save@decl{\toks\count@ \expandafter{\@nextchar}}
1426 % \end{macrocode}
1427 % The reason for the use of =\relax= is the following
1428 % hypothetical situation in the preamble:
1429 % \quad =..\the\toks1\the\toks2..= \quad \TeX\ expands
1430 % =\the\toks2= first in order to find out if the digit =1=
1431 % is followed by other digits. E.g.\ a =5= saved in the
1432 % \textsf{token} register $2$ would lead \TeX\ to insert the contents
1433 % of \textsf{token} register $15$ instead of $1$ later on.
1434 %
1435 % The example above referred to an older version of =\save@decl= which
1436 % inserted a =\relax= inside the token register. This is now moved to
1437 % the places where the actual token registers are inserted (look for
1438 % =\the@toks=) because the old version would still make =@=
1439 % expressions to moving arguments since after expanding the second
1440 % register while looking for the end of the number the contents of the
1441 % token register is added so that later on the whole register will be
1442 % expanded. This serious bug was found after nearly two years
1443 % international use of this package by Johannes Braams.
1444 % \end{macro}
1445 %
1446 %
1447 %
1448 % How does the situation look like, if we want to add another column
1449 % to the preamble, i.e.\ if we have found a \texttt{c}, \texttt{l},
1450 % \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in the user
1451 % preamble? In this case we have the problem of the \textsf{token}
1452 % register from =>{..}= and =<{..}= having to be inserted at this
1453 % moment because formatting instructions like =\hfil= have to be set
1454 % around them. On the other hand it is not known yet, if any =<{..}=
1455 % instruction will appear in the user preamble at all.
1456 %
1457 % We solve this problem by adding two \textsf{token} registers at a
1458 % time. This explains, why we have freed the \textsf{token} registers
1459 % in =\prepnext@tok=.
1460 %
1461 % \begin{macro}[int]{\insert@column}
1462 % \begin{macro}[int]{\@sharp}
1463 % \begin{macro}[int]{\textonly@unskip}
1464 % \begin{macro}[int]{\@protected@firstofone}
1465 % We now define the macro =\insert@column= which will do
1466 % this work for us.
1467 % \begin{macrocode}
1468 \def\insert@column{%
1469 % \end{macrocode}
1470 % We start with a hook that packages can use to add code at the
1471 % start of the cell. It accepts 3 arguments: the current row and
1472 % column number and the cell type, so that the hook code can do
1473 % conditional processing based on the values. The
1474 % \cs{insert@column} command is x-expanded during the preamble
1475 % construction and \cs{hook_use:nnw} is fully expandable, so we
1476 % have to prevent that expansion inside the \cs{xdef} of the
1477 % \cs{@premable} construction. \cs{@@_hook_use_protected:nVVn} does
1478 % just that for us.
1479 % \changes{v2.6m}{2026-01-15}{Add support hook}
1480 % \begin{macrocode}
1481 \@@_hook_use_protected:nVVn {tbl/cell/init}
1482 \g_@@_row_int
1483 \g_@@_col_int
1484 { \ar@cell@type }
1485 % \end{macrocode}
1486 %
1487 % For tagging we insert as special socket, that adds the necessary
1488 % PDF tag at the beginning of the cell if tagging is enabled.
1489 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
1490 % \begin{macrocode}
1491 \UseTaggingSocket{tbl/cell/begin}%
1492 \@@_hook_use_protected:nVVn {tbl/cell/begin}
1493 \g_@@_row_int
1494 \g_@@_col_int
1495 { \ar@cell@type }
1496 % \end{macrocode}
1497 % Next we have to insert the toks register holding the content of
1498 % \verb=>{...}=. Here, we assume that the \textsf{count} register
1499 % =\@tempcnta= has saved the value $=\count@= - 1$.
1500 %
1501 % To keep \TeX{} happy if there is a look ahead in the tabular
1502 % preamble, i.e., starting in \verb=>{...}=, which uses the
1503 % Appendix~D trick (for example, anything with a trailing optional
1504 % argument defined by \pkg{ltcmd}), we wrap everything here in a
1505 % protected version of \cs{@firstofone}. \TeX{} otherwise can get
1506 % confused about the value of the master counter, and we get some
1507 % strange errors. We suspected that there was an underlying issue
1508 % is the \TeX{} engine, but it turned out to be rather hard to get
1509 % to the bottom of it, because the master counter is not accessible
1510 % through \TeX{}'s tracing tools. Thus, all we could do was
1511 % producing various example documents, observing results, as well
1512 % as staring at a printout of the \TeX{} program. As an example,
1513 % without this approach, something like
1514 % \begin{verbatim}
1515 % \NewDocumentCommand\foo{o}{x}
1516 % \begin{tabular}{>{\foo}l}
1517 % Foo
1518 % \end{tabular}
1519 % \end{verbatim}
1520 % failed. That can be fixed by adding a \cs{relax} after the
1521 % \cs{@tempcnta}, but that then leads to issues if you are
1522 % collecting whole cells (tagging code or \pkg{collcell}), where
1523 % you can no longer alter the meaning of \cs{cr} as the master
1524 % counter goes wrong due to an obscure bug (or perhaps, say, an
1525 % undocumented feature of \TeX{}). Eventually, we were able to pin
1526 % down the root cause and really understand why
1527 % \cs{@protected@firstofone} solves the problem, even though it
1528 % looks like a nonsense addition to the code that does nothing
1529 % useful.\footnote{So it is a \TeX{} engine bug that was in there
1530 % from day one, or if you like, it is a hidden feature that is not
1531 % explained; neither in the \TeX{}book nor in the program code. We
1532 % don't really expect this to change in \TeX{} after such a long
1533 % time, other than perhaps documenting it as a feature, so this is
1534 % a proper solution to the problem and not just a workaround.}
1535 %
1536 % The problem is that \TeX{} tries to conserve stack space, and
1537 % when the last token of an existing token list is a macro, then
1538 % this token list is \emph{first} removed from memory (reducing the
1539 % stack) \emph{before} the macro replacement text (as a new
1540 % token list) is given to the parser adding a new stack level. This
1541 % is done using the routine \texttt{end\_token\_list} in the \TeX{}
1542 % program and ending the u-part of an \cs{halign} column with this
1543 % routine immediately sets the \emph{master counter} used by alignments to
1544 % zero (see chapter~22 and Appendix~D of the \TeX{}book). This
1545 % means that technically the expansion of the last token in the u-part (if it
1546 % is a macro) is not executed in the context of the u-part, but in
1547 % the context of the alignment entry in the document. That normally
1548 % doesn't make any difference whatsoever --- unless you play
1549 % around (as we sometimes have to) with tricks like those from
1550 % Appendix~D.
1551 %
1552 % To illustrate the issue we show a bit of strange low-level plain
1553 % \TeX{} code.\footnote{If all of this looks mighty strange to you,
1554 % don't worry. You will be unlikely to need to know about it. It is
1555 % just there so that programmers at some point in the future do not
1556 % have to wonder too much why there is this odd
1557 % \cs{@protected@firstofone} that apparently does nothing
1558 % useful. It took us several nights of head scratching to come up
1559 % with these minimal examples and then some more time to understand
1560 % what the heck is going on inside \TeX{}---thanks to Bruno for the
1561 % right ideas on the latter.} Below are two very special grouping
1562 % commands that are like \cs{bgroup} and \cs{egroup} but also
1563 % affect the alignment master counter when expanded (see
1564 % \TeX{}book p.385). If one of them is used as the
1565 % last macro in the u-part of a column, then you get strange errors
1566 % that you shouldn't get.
1567 % \begin{verbatim}
1568 % \def\bbgroup{{\ifnum0=`}\fi}
1569 % \def\eegroup{\ifnum0=`{\fi}}
1570 %
1571 % % Fails with an error message, but there should be none:
1572 % \halign{%
1573 % \message{u-part^^J}%
1574 % \bbgroup % <-- in the u-part
1575 % \eegroup % <-- in the u-part
1576 % #%
1577 % \message{v-part^^J}%
1578 % \hfill\cr
1579 % \message{body^^J}x
1580 % \cr
1581 % }
1582 %
1583 % % Fails but should work, the v-part is never reached:
1584 % \halign{%
1585 % \message{u-part^^J}%
1586 % \bbgroup % <-- in the u-part
1587 % #%
1588 % \message{v-part^^JJ}%
1589 % \eegroup % <-- in the v-part
1590 % \hfill\cr
1591 % \message{body^^J}x
1592 % \cr
1593 % }
1594 % \end{verbatim}
1595 %
1596 % So the trick we use now is making \cs{@protected@firstofone} the
1597 % last macro in the u-part, i.e., before the \cs{@sharp}. That way
1598 % its argument is always fully expanded as part of the alignment
1599 % entry and not as part of the u-part and this way we know exactly
1600 % what the master counter value is at this point, regardless of the content of
1601 % \verb=>{...}=.
1602 %
1603 % \changes{v2.6f}{2024/09/13}{Stop parsing for optional argument (gh/1468)}
1604 % \changes{v2.6g}{2024/10/12}{Further work to support optional args in preamble (gh/1468)}
1605 % \begin{macrocode}
1606 \@protected@firstofone { \the@toks \the \@tempcnta \ignorespaces }
1607 % \end{macrocode}
1608 % Next follows the =#= sign which specifies the place
1609 % where the text of the column shall be inserted. To avoid
1610 % errors during the expansions in
1611 % =\@addtopreamble= we hide this sign in the command
1612 % =\@sharp= which is temporarily occupied with
1613 % =\relax= during the build-up of the preamble.
1614 % To remove unwanted spaces before and after the column in text mode,
1615 % we set an =\ignorespaces= in front (see above) and a =\unskip=
1616 % afterwards; in math mode, the latter is suppressed while the
1617 % \cs{ignorespaces} makes no difference.
1618 % \changes{v2.0e}{1991/02/07}{Added \{\} around \cs{@sharp} for new ftsel}
1619 % \changes{v2.0h}{1992/06/22}{Removed \{\} again in favor of
1620 % \cs{d@llarbegin}}
1621 % \changes{v2.6b}{2024/04/08}{Do not \cs{unskip} if in math mode (gh/1323)}
1622 % \begin{macrocode}
1623 \@sharp \textonly@unskip
1624 % \end{macrocode}
1625 % Then the second \textsf{token} register follows whose number should
1626 % be saved in =\count@=.
1627 % We make sure that there will be no further expansion after reading
1628 % the number, by finishing with =\relax=. The case above is not
1629 % critical since it is ended by =\ignorespaces=.
1630 % \changes{v2.0c}{1990/08/14}{\cs{relax} added to avoid problem
1631 % \cs{the}\cs{toks0}\cs{the}\cs{toks1}.}
1632 % \begin{macrocode}
1633 \the@toks \the \count@ \relax
1634 % \end{macrocode}
1635 % The corresponding hook at the end of the cell.
1636 % \changes{v2.6m}{2026-01-15}{Add support hook}
1637 % \begin{macrocode}
1638 \@@_hook_use_protected:nVVn {tbl/cell/end}%
1639 \g_@@_row_int
1640 \g_@@_col_int
1641 {\ar@cell@type}%
1642 % \end{macrocode}
1643 %
1644 % And another socket for tagging that adds the necessary closing tag
1645 % if enabled.
1646 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
1647 % \begin{macrocode}
1648 \UseTaggingSocket{tbl/cell/end}%
1649 }
1650 % \end{macrocode}
1651 %
1652 %
1653 % Do the unskip only if we are in hmode:
1654 % \changes{v2.6b}{2024/04/08}{Do not \cs{unskip} if in math mode (gh/1323)}
1655 % \begin{macrocode}
1656 \protected\def\textonly@unskip{\ifhmode\unskip\fi}
1657 % \end{macrocode}
1658 % \changes{v2.6g}{2024/10/12}{Further work to support optional args in preamble (gh/1468)}
1659 % We need an engine-protected function that is just \cs{@firstofone}:
1660 % \begin{macrocode}
1661 \protected\long\def\@protected@firstofone#1{#1}
1662 % \end{macrocode}
1663 % \end{macro}
1664 % \end{macro}
1665 % \end{macro}
1666 % \end{macro}
1667 %
1668 %
1669 %
1670 % \begin{macro}{\@@_hook_use_protected:n,
1671 % \@@_hook_use_protected:nn,\@@_hook_use_protected:nnnn,
1672 % \@@_hook_use_protected:nV,\@@_hook_use_protected:nVVn}
1673 %
1674 % Unexpandable versions of \cs{hook_use:n} and
1675 % \cs{hook_use:nnw} for use within the preamble
1676 % construction that is done with \cs{xdef}.
1677 %
1678 % For now we define them as internal commands because they are
1679 % really only needed because of the strange way \cs{@preamble} is
1680 % constructed which is really a historical artifact.
1681 % \begin{macrocode}
1682 \cs_new_protected:Npn \@@_hook_use_protected:n #1 {
1683 \hook_use:n {#1}
1684 }
1685 \cs_new_protected:Npn \@@_hook_use_protected:nn #1#2 {
1686 \hook_use:nnw {#1}{1}{#2}
1687 }
1688 \cs_new_protected:Npn \@@_hook_use_protected:nnnn #1#2#3#4 {
1689 \hook_use:nnw {#1}{3}{#2}{#3}{#4}
1690 }
1691 \cs_generate_variant:Nn \@@_hook_use_protected:nn { nV }
1692 \cs_generate_variant:Nn \@@_hook_use_protected:nnnn { nVVn }
1693 % \end{macrocode}
1694 % \end{macro}
1695 %
1696 %
1697 % \begin{macro}[int]{\insert@pcolumn}
1698 % Handling pcolumn-cells needs slightly different handling when
1699 % doing tagging. Rather than changing the plugs in
1700 % \cs{insert@column} back and forth, we simply use a different
1701 % version of \cs{insert@column} that has its own sockets.
1702 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
1703 % \begin{macrocode}
1704 \def\insert@pcolumn{%
1705 % \end{macrocode}
1706 % We start with the initalization hook for cells; again this one needs protection from
1707 % premature expansion.
1708 % \changes{v2.6m}{2026-01-15}{Add support hook}
1709 % \begin{macrocode}
1710 \@@_hook_use_protected:nVVn {tbl/cell/init}%
1711 \g_@@_row_int
1712 \g_@@_col_int
1713 {\ar@cell@type}%
1714 % \end{macrocode}
1715 % Then set up the tagging.
1716 % \begin{macrocode}
1717 \UseTaggingSocket{tbl/pcell/begin}%
1718 % \end{macrocode}
1719 % If special code is wanted only for a specific type or for certain
1720 % rows, columns or even for a specific cell then the arguments can
1721 % be used to define conditional processing.
1722 % \begin{macrocode}
1723 \@@_hook_use_protected:nVVn {tbl/cell/begin}%
1724 \g_@@_row_int
1725 \g_@@_col_int
1726 {\ar@cell@type}%
1727 % \end{macrocode}
1728 % \changes{v2.6f}{2024/09/13}{Stop parsing for optional argument (gh/1468)}
1729 % \begin{macrocode}
1730 \the@toks \the \@tempcnta \relax
1731 \ignorespaces \@sharp \unskip
1732 \the@toks \the \count@ \relax
1733 % \end{macrocode}
1734 % And the corresponding closing hook and socket.
1735 % \changes{v2.6m}{2026-01-15}{Add support hook}
1736 % \begin{macrocode}
1737 \@@_hook_use_protected:nVVn {tbl/cell/end}%
1738 \g_@@_row_int
1739 \g_@@_col_int
1740 {\ar@cell@type}%
1741 \UseTaggingSocket{tbl/pcell/end}%
1742 }
1743 % \end{macrocode}
1744 % \end{macro}
1745 %
1746 %
1747 %
1748 % \subsection{The separation of columns}
1749 %
1750 % \begin{macro}[int]{\@addamp}
1751 % In the preamble a =&= has to be inserted between any two columns;
1752 % before the first column there should not be a =&=. As the user
1753 % preamble may start with a \texttt{|} we have to remember somehow
1754 % if we have already inserted a =#= (i.e.\ a column). This is done
1755 % with the boolean variable =\if@firstamp= that we test in
1756 % =\@addamp=, the macro that inserts the =&=.
1757 % \begin{macrocode}
1758 % \newif \@iffirstamp
1759 \def\@addamp {
1760 \if@firstamp
1761 \@firstampfalse
1762 \else
1763 % \end{macrocode}
1764 % If we are after the first column we have to insert a \verb=&= and
1765 % also update the cell data.
1766 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
1767 % \begin{macrocode}
1768 \edef\@preamble{\@preamble &
1769 \noexpand\tbl_update_cell_data: }
1770 \fi
1771 }
1772 % \end{macrocode}
1773 % \end{macro}
1774 %
1775 %
1776 %
1777 % \begin{macro}[int]{\@acol}
1778 % \begin{macro}[int]{\@acolampacol}
1779 % \begin{macro}[int]{\col@sep}
1780 % We will now define some abbreviations for the extensions,
1781 % appearing most often in the preamble build-up.
1782 % Here =\col@sep= is a \textsf{dimen} register which is set
1783 % equivalent to =\arraycolsep= in an \textsf{array}--environment,
1784 % otherwise it is set equivalent to =\tabcolsep=.
1785 % \begin{macrocode}
1786 \newdimen\col@sep
1787 \def\@acol{\@addtopreamble{\hskip\col@sep}}
1788 % \def\@acolampacol{\@acol\@addamp\@acol}
1789 % \end{macrocode}
1790 % \end{macro}
1791 % \end{macro}
1792 % \end{macro}
1793 %
1794 %
1795 % \subsection{The macro \texttt{\textbackslash @mkpream}}
1796 %
1797 % \begin{macro}[int]{\@mkpream}
1798 % \emph{The code below has been replaced long time ago by an
1799 % extended version further down but the code and its documentation
1800 % was left here for reference. It is now commented out to avoid
1801 % confusion.}
1802 % \begin{macro}[int]{\the@toks}
1803 % \label{@mkpream}
1804 % Now we can define the macro which builds up the preamble for the
1805 % =\halign=.
1806 % First we initialize =\@preamble=, =\@lastchclass=
1807 % and the boolean variable =\if@firstamp=.
1808 % \begin{macrocode}
1809 %\def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue
1810 % \end{macrocode}
1811 % During the build-up of the preamble we cannot directly use the
1812 % =#= sign; this would lead to an error message in the next
1813 % =\@addtopreamble= call.
1814 % Instead, we use the command =\@sharp= at places where later
1815 % a =#= will be.
1816 % This command is at first given the meaning =\relax=;
1817 % therefore it will not be expanded when the preamble
1818 % is extended.
1819 % In the macro =\@array=, shortly before the =\halign=
1820 % is carried out, =\@sharp= is given its final meaning.
1821 %
1822 % In a similar way,
1823 % we deal with the commands =\@startpbox= and
1824 % =\@endpbox=, although the reason is different here: these
1825 % macros expand in many \textsf{tokens} which would delay the
1826 % build-up of the preamble.
1827 % \begin{macrocode}
1828 % \let\@sharp\relax\let\@startpbox\relax\let\@endpbox\relax
1829 % \end{macrocode}
1830 % Two more are needed to deal with the code that handles struts
1831 % for extra space after a row from =\\[<space>]=
1832 % (=\do@row@strut=) and code that manages m-cells depending on
1833 % their heights (=\ar@align@mcell=).
1834 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
1835 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
1836 % \begin{macrocode}
1837 % \let\do@row@strut\relax
1838 % \let\ar@align@mcell\relax
1839 % \end{macrocode}
1840 % Now we remove possible $*$-forms in the user preamble with the
1841 % command =\@xexpast=. As we already know, this command saves
1842 % its result in the macro =\@tempa=.
1843 % \begin{macrocode}
1844 % \@xexpast #1*0x\@@@@
1845 % \end{macrocode}
1846 % Afterwards we initialize all registers and macros, that we need
1847 % for the build-up of the preamble.
1848 % Since we want to start with the \textsf{token} register $0$,
1849 % =\count@= has to contain the value $-1$.
1850 % \begin{macrocode}
1851 % \count@\m@ne
1852 % \let\the@toks\relax
1853 % \end{macrocode}
1854 % Then we call up =\prepnext@tok= in order to prepare the
1855 % \textsf{token} register $0$ for use.
1856 % \begin{macrocode}
1857 % \prepnext@tok
1858 % \end{macrocode}
1859 % To evaluate the user preamble (without stars) saved in
1860 % =\@tempa= we use the \LaTeX--macro =\@tfor=.
1861 % The strange appearing construction with =\expandafter= is
1862 % based on the fact that we have to put the replacement text of
1863 % =\@tempa= and not the macro =\@tempa= to this
1864 % \LaTeX--macro.
1865 % \begin{macrocode}
1866 % \expandafter \@tfor \expandafter \@nextchar
1867 % \expandafter :\expandafter =\@tempa \do
1868 % \end{macrocode}
1869 % The body of this loop (the group after the =\do=)
1870 % is executed for one \textsf{token} at a time, whereas
1871 % the current \textsf{token} is saved in =\@nextchar=.
1872 % At first we evaluate the current \textsf{token} with the already
1873 % defined macro =\@testpach=, i.e.\ we assign to
1874 % =\@chclass= the character class and to =\@chnum=
1875 % the character number of this \textsf{token}.
1876 % \changes{v2.0f}{1992/02/29}{\cs{@testpach} now without arg}
1877 % \begin{macrocode}
1878 % {\@testpach
1879 % \end{macrocode}
1880 % Then we branch out depending on the value of =\@chclass= into
1881 % different macros that extend the preamble respectively.
1882 % \begin{macrocode}
1883 % \ifcase \@chclass \@classz \or \@classi \or \@classii
1884 % \or \save@decl \or \or \@classv \or \@classvi
1885 % \or \@classvii \or \@classviii \or \@classix
1886 % \or \@classx \fi
1887 % \end{macrocode}
1888 % Two cases deserve our special attention: Since the current
1889 % \textsf{token} cannot have the character class $4$ (start) we
1890 % have skipped this possibility. If the character class is $3$,
1891 % only the content of =\@nextchar= has to be saved into the current
1892 % \textsf{token} register; therefore we call up =\save@decl=
1893 % directly and save a macro name. After the preamble has been
1894 % extended we assign the value of =\@chclass= to the counter
1895 % =\@lastchclass= to assure that this information will be available
1896 % during the next run of the loop.
1897 % \begin{macrocode}
1898 % \@lastchclass\@chclass}%
1899 % \end{macrocode}
1900 % After the loop has been finished space must still be added to
1901 % the created preamble, depending on the last \textsf{token}.
1902 % Depending on the value of =\@lastchclass= we perform
1903 % the necessary operations.
1904 % \begin{macrocode}
1905 % \ifcase\@lastchclass
1906 % \end{macrocode}
1907 % If the last class equals $0$ we add a
1908 % =\hskip \col@sep=.
1909 % \begin{macrocode}
1910 % \@acol \or
1911 % \end{macrocode}
1912 % If it equals $1$ we do not add any additional space so that the
1913 % horizontal lines do not exceed the vertical ones.
1914 % \begin{macrocode}
1915 % \or
1916 % \end{macrocode}
1917 % Class $2$ is treated like class $0$ because a =<{...}= can
1918 % only directly follow after class $0$.
1919 % \begin{macrocode}
1920 % \@acol \or
1921 % \end{macrocode}
1922 % Most of the other possibilities can only appear if the user
1923 % preamble was defective. Class $3$ is not allowed since after a
1924 % =>{..}= there must always follow a \texttt{c}, \texttt{l},
1925 % \texttt{r}, \texttt{p},\texttt{m} or \texttt{b}. We report an
1926 % error and ignore the declaration given by ={..}=.
1927 % \begin{macrocode}
1928 % \@preamerr \thr@@@@ \or
1929 % \end{macrocode}
1930 % If =\@lastchclass= is $4$ the user preamble has been empty.
1931 % To continue, we insert a =#= in the preamble.
1932 % \begin{macrocode}
1933 % \@preamerr \tw@ \@addtopreamble\@sharp \or
1934 % \end{macrocode}
1935 % Class $5$ is allowed again. In this case
1936 % (the user preamble ends with =@{..}=) we need not
1937 % do anything.
1938 % \begin{macrocode}
1939 % \or
1940 % \end{macrocode}
1941 % Any other case means that the arguments to =@=, \texttt{!},
1942 % \texttt{<}, \texttt{>}, \texttt{p}, \texttt{m} or \texttt{b} have
1943 % been forgotten. So we report an error and ignore the last
1944 % \textsf{token}.
1945 % \begin{macrocode}
1946 % \else \@preamerr \@ne \fi
1947 % \end{macrocode}
1948 % Now that the build-up of the preamble is almost finished we can
1949 % insert the \textsf{token} registers and therefore redefine
1950 % =\the@toks=. The actual insertion, though, is performed
1951 % later.
1952 % \begin{macrocode}
1953 % \def\the@toks{\the\toks}}
1954 % \end{macrocode}
1955 % \end{macro}
1956 % \end{macro}
1957 %
1958 %
1959 %
1960 % \section{The macros \texttt{\textbackslash @classz}
1961 % to \texttt{\textbackslash @classx}}
1962 %
1963 % The preamble is extended by the macros =\@classz= to
1964 % =\@classx= which are called by =\@mkpream=
1965 % depending on =\@lastchclass=
1966 % (i.e. the character class of the last \textsf{token}).
1967 % \begin{macro}[int]{\@classx}
1968 % First we define =\@classx= because of its important r\^ole.
1969 % When it is called we find that the current
1970 % \textsf{token} is \texttt{p}, \texttt{m} or \texttt{b}.
1971 % That means that a new column has to start.
1972 % \begin{macrocode}
1973 \def\@classx{%
1974 % \end{macrocode}
1975 % Depending on the value of =\@lastchclass= different actions
1976 % must take place:
1977 % \begin{macrocode}
1978 \ifcase \@lastchclass
1979 % \end{macrocode}
1980 % If the last character class was $0$ we separate the columns by
1981 % =\hskip\col@sep= followed by =&= and another
1982 % =\hskip\col@sep=.
1983 % \begin{macrocode}
1984 \@acolampacol \or
1985 % \end{macrocode}
1986 % If the last class was class $1$ --- that means that a vertical
1987 % line was
1988 % drawn, --- before this line a =\hskip\col@sep= was inserted.
1989 % Therefore there has to be only a =&= followed by
1990 % =\hskip\col@sep=. But this =&= may be inserted only
1991 % if this is not the first column. This process is controlled
1992 % by =\if@firstamp= in the macro =\addamp=.
1993 % \begin{macrocode}
1994 \@addamp \@acol \or
1995 % \end{macrocode}
1996 % Class $2$ is treated like class $0$ because =<{...}= can only
1997 % follow after class $0$.
1998 % \begin{macrocode}
1999 \@acolampacol \or
2000 % \end{macrocode}
2001 % Class $3$ requires no actions because all things necessary have
2002 % been done by the preamble \textsf{token} \texttt{>}.
2003 % \begin{macrocode}
2004 \or
2005 % \end{macrocode}
2006 % Class $4$ means that we are at the beginning of the preamble.
2007 % Therefore we start the preamble with =\hskip\col@sep= and
2008 % then call =\@firstampfalse=. This makes sure that a later
2009 % =\@addamp= inserts the character
2010 % =&= into the preamble.
2011 % \begin{macrocode}
2012 \@acol \@firstampfalse \or
2013 % \end{macrocode}
2014 % For class $5$ \textsf{tokens} only the character =&= is inserted
2015 % as a column separator. Therefore we call =\@addamp=.
2016 % \begin{macrocode}
2017 \@addamp
2018 % \end{macrocode}
2019 % Other cases are impossible. For an example
2020 % $=\@lastchclass= \string= 6$---as it might appear in a
2021 % preamble of the form =...!p...=---\texttt{p} would have
2022 % been taken as an argument of \texttt{!}\ by =\@testpach=.
2023 % \begin{macrocode}
2024 \fi}
2025 % \end{macrocode}
2026 % \end{macro}
2027 %
2028 % \changes{v2.6h}{2024/12/02}{Add tagging sockets for luamml support}
2029 % Until the sockets are in the release we test for existence
2030 % and declare them.
2031 % \begin{macrocode}
2032 \str_if_exist:cF { l__socket_tagsupport/math/luamml/array/save_plug_str }
2033 {
2034 \NewSocket{tagsupport/math/luamml/array/save}{0}
2035 \NewSocket{tagsupport/math/luamml/array/finalize}{0}
2036 \NewSocket{tagsupport/math/luamml/array/initcol}{0}
2037 \NewSocket{tagsupport/math/luamml/array/finalizecol}{1}
2038 \AssignSocketPlug{tagsupport/math/luamml/array/finalizecol}{noop}
2039 }
2040 % \end{macrocode}
2041 % \begin{macro}[int]{\@classz}
2042 % If the character class of the last \textsf{token} is $0$ we have
2043 % \texttt{c}, \texttt{l}, \texttt{r} or an argument of \texttt{m},
2044 % \texttt{b} or\ \texttt{p}. In the first three cases the preamble
2045 % must be extended the same way as if we had class $10$. The
2046 % remaining two cases do not require any action because the space
2047 % needed was generated by the last \textsf{token} (i.e.\
2048 % \texttt{m}, \texttt{b} or \texttt{p}). Since =\@lastchclass= has
2049 % the value $10$ at this point nothing happens when =\@classx= is
2050 % called. So the macro =\@chlassz= may start like this:
2051 % \begin{macrocode}
2052 \def\@classz{\@classx
2053 % \end{macrocode}
2054 % According to the definition of =\insert@column= we must store
2055 % the number of the \textsf{token} register in which a preceding
2056 % =>{..}= might have stored its argument into
2057 % =\@tempcnta=.
2058 % \begin{macrocode}
2059 \@tempcnta \count@
2060 % \end{macrocode}
2061 % To have $=\count@= \string= =\@tmpcnta= + 1$ we prepare
2062 % the next \textsf{token} register.
2063 % \begin{macrocode}
2064 \prepnext@tok
2065 % \end{macrocode}
2066 % Now the preamble must be extended with the column whose format
2067 % can be determined by =\@chnum=.
2068 % \begin{macrocode}
2069 \@addtopreamble{\ifcase \@chnum
2070 % \end{macrocode}
2071 % If =\@chnum= has the value $0$ a centered column has to be
2072 % generated.
2073 % So we begin with stretchable space.
2074 % \begin{macrocode}
2075 \hfil
2076 % \end{macrocode}
2077 % We also add a space of 1sp just in case the first thing in the
2078 % cell is a command doing an =\unskip=.
2079 % \changes{v2.4k}{2018/12/30}{Add extra \cs{hskip} to guard against an
2080 % \cs{unskip} at the start of a c-column cell (gh/102)}
2081 % \begin{macrocode}
2082 \hskip1sp%
2083 % \end{macrocode}
2084 % The command =\d@llarbegin= follows expanding into =\begingroup=
2085 % (in the \textsf{tabular}--environment) or into =$=. Doing this
2086 % (provided an appropriate setting of =\d@llarbegin=) we achieve
2087 % that the contents of the columns of an \textsf{array}--environment
2088 % are set in math mode while those of a \textsf{tabular}--environment
2089 % are set in LR mode.
2090 % \begin{macrocode}
2091 \d@llarbegin
2092 % \end{macrocode}
2093 % Now we insert the contents of the two \textsf{token} registers
2094 % and the symbol
2095 % for the column entry (i.e.\ =#= or
2096 % more precise =\@sharp=) using =\insert@column=.
2097 % \begin{macrocode}
2098 \insert@column
2099 % \end{macrocode}
2100 % We end this case with =\d@llarend= and =\hfil= where =\d@llarend=
2101 % again is either =$= or =\endgroup=.
2102 % The strut to enforce a regular row height is placed between the two.
2103 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
2104 % \begin{macrocode}
2105 \d@llarend
2106 \do@row@strut \hfil \or
2107 % \end{macrocode}
2108 % The templates for \texttt{l} and \texttt{r} (i.e.\ =\@chnum= $1$
2109 % or $2$) are generated the same way. Since one =\hfil= is
2110 % missing the text is moved to the relevant side.
2111 % The =\kern\z@= is needed in case of an empty column
2112 % entry. Otherwise
2113 % the =\unskip= in =\insert@column= removes the
2114 % =\hfil=. Changed to =\hskip1sp= so that it interacts better with
2115 % =\@bsphack=.
2116 % \changes{v2.3f}{1996/04/22}
2117 % {(DPC) Extra \cs{kern} keeps tabcolsep in empty l columns
2118 % internal/2122}
2119 % \changes{v2.3i}{1996/06/14}
2120 % {Change both \cs{kern}\cs{z@} to \cs{hskip}1sp for latex/2160}
2121 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
2122 % \begin{macrocode}
2123 \hskip1sp\d@llarbegin\insert@column\d@llarend
2124 \do@row@strut \hfil \or
2125 \hfil\hskip1sp\d@llarbegin\insert@column\d@llarend
2126 \do@row@strut \or
2127 % \end{macrocode}
2128 % The templates for \texttt{p}, \texttt{m} and \texttt{b} mainly
2129 % consist of a \textsf{box}. In case of \texttt{m} it is generated
2130 % by =\vcenter=. This command is allowed only in math
2131 % mode. Therefore we start with a~=$=.
2132 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
2133 % \begin{macrocode}
2134 \setbox\ar@mcellbox\vbox
2135 % \end{macrocode}
2136 % The part of the templates which is the same in all three cases
2137 % (\texttt{p}, \texttt{m} and \texttt{b}) is built by the macros
2138 % =\@startpbox= and =\@endpbox=. =\@startpbox= has an argument: the
2139 % width of the column which is stored in the current \textsf{token}
2140 % (i.e.\ =\@nextchar=). Between these two macros we find the well
2141 % known =\insert@column= or rather the variant for tagging:
2142 % \cs{insert@pcolumn}. The strut is placed after the box.
2143 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
2144 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
2145 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2146 % \begin{macrocode}
2147 \@startpbox{\@nextchar}\insert@pcolumn \@endpbox
2148 \ar@align@mcell
2149 \do@row@strut \or
2150 % \end{macrocode}
2151 % The templates for \texttt{p} and \texttt{b} are generated in the
2152 % same way though we do not need the =$= characters because we use
2153 % =\vtop= or =\vbox=.
2154 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
2155 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2156 % \begin{macrocode}
2157 \vtop \@startpbox{\@nextchar}\insert@pcolumn \@endpbox\do@row@strut \or
2158 \vbox \@startpbox{\@nextchar}\insert@pcolumn \@endpbox\do@row@strut
2159 % \end{macrocode}
2160 % Other values for =\@chnum= are impossible. Therefore we
2161 % end the arguments to =\@addtopreamble= and =\ifcase=.
2162 % Before we come to the end of =\@classz= we have to
2163 % prepare the next \textsf{token} register.
2164 % \begin{macrocode}
2165 \fi}\prepnext@tok}
2166 % \end{macrocode}
2167 % \end{macro}
2168 %
2169
2170 %
2171 % \begin{macro}[int]{\ar@mcellbox}
2172 % When dealing with m-cells we need a box to measure the cell
2173 % height.
2174 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
2175 % \begin{macrocode}
2176 \newbox\ar@mcellbox
2177 % \end{macrocode}
2178 % \end{macro}
2179 %
2180 %
2181 % \begin{macro}[int]{\ar@align@mcell}
2182 % M-cells are supposed to be vertically centered within the table
2183 % row. In the original implementation that was done using
2184 % =\vcenter= but the issue with that approach is that it centers
2185 % the material based on the math-axis. In most situations that
2186 % comes out quit right, but if, for example, an m-cell has only a
2187 % single line worth of material inside it will be positioned
2188 % differently to a =l=, =c= or =r= cell or to a =p= or =b= cell
2189 % with the same content.
2190 %
2191 % For that reason the new implementation does the centering
2192 % manually: First we check the height of the cell and if that is
2193 % less or equal to =\ht\strutbox= we assume that this is a
2194 % single line cell. In that case we don't do any vertical maneuver
2195 % and simply output the box, i.e., make it behave like a single
2196 % line p-cell.
2197 %
2198 % We use the height of \cs{strutbox} not \cs{@arstrutbox} in the comparison,
2199 % because \cs{box}\cs{ar@mcellbox} does not have any strut
2200 % incorporated and if \cs{arraystretch} is made very
2201 % small the test would otherwise incorrectly assume a multi-line cell.
2202 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
2203 % \changes{v2.5g}{2022/09/04}{Test against \cs{strutbox} height (gh/766)}
2204 % \begin{macrocode}
2205 \def\ar@align@mcell{%
2206 \ifdim \ht\ar@mcellbox > \ht\strutbox
2207 % \end{macrocode}
2208 % Otherwise we realign vertically by lowering the box. The question
2209 % is how much do we need to move down? If there is any
2210 % =\arraystretch= in place then the first line will have some
2211 % unusual height and we don't want to consider that when finding
2212 % the middle point. So we subtract from the cell height the height
2213 % of that strut. But of course we want to include the normal height
2214 % of the first line (which would be something like =\ht\strutbox=)
2215 % so we need to add that. On the other hand, when centering around
2216 % the mid-point of the cell, we also need to account for the depth
2217 % of the last line (which is nominally something like
2218 % =\dp\strutbox=). Both together equals =\baselineskip= so that is
2219 % what we add and then lower the cell by half of the resulting value.
2220 % \begin{macrocode}
2221 \begingroup
2222 \dimen@\ht\ar@mcellbox
2223 \advance\dimen@-\ht\@arstrutbox
2224 \advance\dimen@\baselineskip
2225 \lower.5\dimen@\box\ar@mcellbox
2226 \endgroup
2227 \else % assume one line and align at baseline
2228 \box\ar@mcellbox
2229 \fi}
2230 % \end{macrocode}
2231 % \end{macro}
2232 %
2233
2234 %
2235 % \begin{macro}[int]{\@classix}
2236 % \emph{The code below has been replaced long time ago by an
2237 % extended version further down but the code and its documentation
2238 % was left here for reference. It is now commented out to avoid
2239 % confusion.}
2240 %
2241 % In case of class $9$ (\texttt{>}--\textsf{token}) we first check
2242 % if the character class of the last
2243 % \textsf{token} was $3$. In this case we have a
2244 % user preamble of the form =..>{...}>{...}..= which
2245 % is not allowed. We only give an error message and continue.
2246 % So the declarations defined by the first =>{...}=
2247 % are ignored.
2248 % \begin{macrocode}
2249 %\def\@classix{\ifnum \@lastchclass = \thr@@@@
2250 % \@preamerr \thr@@@@ \fi
2251 % \end{macrocode}
2252 % Furthermore, we call up =\@class10= because afterwards always a
2253 % new column is started by \texttt{c}, \texttt{l}, \texttt{r},
2254 % \texttt{p}, \texttt{m} or \texttt{b}.
2255 % \begin{macrocode}
2256 % \@classx}
2257 % \end{macrocode}
2258 % \end{macro}
2259 %
2260 %
2261 %
2262 % \begin{macro}[int]{\@classviii}
2263 % \emph{The code below has been replaced long time ago by an
2264 % extended version further down but the code and its documentation
2265 % was left here for reference. It is now commented out to avoid
2266 % confusion.}
2267 %
2268 % If the current \textsf{token} is a \texttt{<} the last character
2269 % class must be $0$. In this case it is not necessary to extend the
2270 % preamble. Otherwise we output an error message, set =\@chclass=
2271 % to $6$ and call =\@classvi=. By doing this we achieve that
2272 % \texttt{<} is treated like \texttt{!}.
2273 % \begin{macrocode}
2274 %\def\@classviii{\ifnum \@lastchclass >\z@
2275 % \@preamerr 4\@chclass 6 \@classvi \fi}
2276 % \end{macrocode}
2277 % \end{macro}
2278 %
2279 % \begin{macro}[int]{\@arrayrule}
2280 % There is only one incompatibility with the original definition:
2281 % the definition of =\@arrayrule=. In the original a line without
2282 % width\footnote{So the space between \texttt{cc} and \texttt{c|c}
2283 % is equal.} is created by multiple insertions of
2284 % =\hskip .5\arrayrulewidth=.
2285 % We only insert a vertical line into the
2286 % preamble. This is done to prevent problems with \TeX's main
2287 % memory when generating tables with many vertical lines in them
2288 % (especially in the case of \textsf{floats}).
2289 % \begin{macrocode}
2290 \def\@arrayrule{\@addtopreamble \vline}
2291 % \end{macrocode}
2292 % \end{macro}
2293 %
2294 % \begin{macro}[int]{\@classvii}
2295 % As a consequence it follows that in case of class $7$
2296 % (=@= \textsf{token}) the preamble need not to be extended.
2297 % In the original definition $=\@lastchclass= \string= 1$
2298 % is treated by inserting =\hskip .5\arrayrulewidth=.
2299 % We only check if the last \textsf{token} was of class $3$ which is
2300 % forbidden.
2301 % \begin{macrocode}
2302 \def\@classvii{\ifnum \@lastchclass = \thr@@@@
2303 % \end{macrocode}
2304 % If this is true we output an error message and
2305 % ignore the declarations stored
2306 % by the last =>{...}=, because these are overwritten
2307 % by the argument of \texttt{@}.
2308 % \begin{macrocode}
2309 \@preamerr \thr@@@@ \fi}
2310 % \end{macrocode}
2311 % \end{macro}
2312 %
2313 %
2314 % \begin{macro}[int]{\@classvi}
2315 % If the current \textsf{token} is a regular \texttt{!}\ and the
2316 % last class was $0$ or $2$ we extend the preamble with
2317 % =\hskip\col@sep=. If the last \textsf{token} was of class $1$
2318 % (for instance \texttt{|}) we extend with =\hskip \doublerulesep=
2319 % because the construction =!{...}= has to be treated like
2320 % \texttt{|}.
2321 % \begin{macrocode}
2322 \def\@classvi{\ifcase \@lastchclass
2323 \@acol \or
2324 \@addtopreamble{\hskip \doublerulesep}\or
2325 \@acol \or
2326 % \end{macrocode}
2327 % Now =\@preamerr...= should follow because a
2328 % user preamble of the form =..>{..}!.= is not allowed.
2329 % To save memory we call =\@classvii= instead which also
2330 % does what we want.
2331 % \begin{macrocode}
2332 \@classvii
2333 % \end{macrocode}
2334 % If =\@lastchclass= is $4$ or $5$ nothing has to be done.
2335 % Class $6$ to $10$ are not possible.
2336 % So we finish the macro.
2337 % \begin{macrocode}
2338 \fi}
2339 % \end{macrocode}
2340 % \end{macro}
2341 %
2342 % \begin{macro}[int]{\@classii}
2343 % \begin{macro}[int]{\@classiii}
2344 % In the case of character classes $2$ and $3$ (i.e.\ the argument
2345 % of \texttt{<} or \texttt{>}) we only have to store the current
2346 % \textsf{token} (=\@nextchar=) into the corresponding
2347 % \textsf{token} register since the preparation and
2348 % insertion of these registers
2349 % are done by the macro =\@classz=.
2350 % This is equivalent to calling =\save@decl= in the case of
2351 % class $3$. To save command identifiers we do this call up
2352 % in the macro =\@mkpream=.
2353 %
2354 % Class $2$ exhibits a more complicated situation: the
2355 % \textsf{token} registers have already been inserted by
2356 % =\@classz=. So the value of =\count@= is too high
2357 % by one. Therefore we decrease =\count@= by $1$.
2358 % \begin{macrocode}
2359 \def\@classii{\advance \count@ \m@ne
2360 % \end{macrocode}
2361 % Next we store the current \textsf{token} into the correct
2362 % \textsf{token} register by calling =\save@decl= and then
2363 % increase the value of =\count@= again. At this point we
2364 % can save memory once more (at the cost of time) if we use the
2365 % macro =\prepnext@tok=.
2366 % \begin{macrocode}
2367 \save@decl\prepnext@tok}
2368 % \end{macrocode}
2369 % \end{macro}
2370 % \end{macro}
2371 %
2372 %
2373 % \begin{macro}[int]{\@classv}
2374 % \emph{The code below has been replaced long time ago by an
2375 % extended version further down but the code and its documentation
2376 % was left here for reference. It is now commented out to avoid
2377 % confusion.}
2378 %
2379 % If the current \textsf{token} is of class $5$ then it is an
2380 % argument of a \texttt{@} \textsf{token}. It must be stored into a
2381 % \textsf{token} register.
2382 % \begin{macrocode}
2383 %\def\@classv{\save@decl
2384 % \end{macrocode}
2385 % We extend the preamble with a command which inserts this
2386 % \textsf{token} register into the preamble when its construction
2387 % is finished. The user expects that this argument is worked out in
2388 % math mode if it was used in an
2389 % \textsf{array}--environment. Therefore we surround it with
2390 % =\d@llar...='s.
2391 % \changes{v2.0c}{1990/08/14}{\cs{relax} added to avoid problem
2392 % `the`toks0`the`toks1.}
2393 % \begin{macrocode}
2394 % \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}%
2395 % \end{macrocode}
2396 % Finally we must prepare the next \textsf{token} register.
2397 % \begin{macrocode}
2398 % \prepnext@tok}
2399 % \end{macrocode}
2400 % \end{macro}
2401 %
2402 % \begin{macro}[int]{\@classi}
2403 % In the case of class $0$ we were able to generate the necessary
2404 % space between columns by using the macro =\@classx=.
2405 % Analogously the macro =\@classvi= can be used for class $1$.
2406 % \begin{macrocode}
2407 \def\@classi{\@classvi
2408 % \end{macrocode}
2409 % Depending on =\@chnum= a vertical line
2410 % \begin{macrocode}
2411 \ifcase \@chnum \@arrayrule \or
2412 % \end{macrocode}
2413 % or (in case of =!{...}=) the current \textsf{token} --- stored
2414 % in =\@nextchar= --- has to be inserted into the preamble.
2415 % This corresponds to calling =\@classv=.
2416 % \begin{macrocode}
2417 \@classv \fi}
2418 % \end{macrocode}
2419 % \end{macro}
2420 %
2421 %
2422 %
2423 % \begin{macro}[int]{\@startpbox,\@startpbox@action}
2424 % In =\@classz= the macro =\@startpbox= is used.
2425 % The width of the \textsf{parbox} is passed as an argument.
2426 % =\vcenter=, =\vtop= or =\vbox= are already in the
2427 % preamble. So we start with the braces for the wanted box.
2428 % \changes{v2.4i}{2018/09/13}{Add group to prevent color leak (gh/72)}
2429 % \begin{macrocode}
2430 \def\@startpbox#1{\bgroup
2431 \color@begingroup
2432 % \end{macrocode}
2433 % The argument is the width of the box. This information has to be
2434 % assigned to =\hsize=.
2435 % Then we assign default values to several parameters used in a
2436 % \textsf{parbox}.
2437 % \changes{v2.3k}{1998/05/12}{Use \cs{setlength} to set \cs{hsize},
2438 % so that the calc package can be applied here (pr/2793)}
2439 % \begin{macrocode}
2440 \setlength\hsize{#1}\@arrayparboxrestore
2441 % \end{macrocode}
2442 % Our main problem is to obtain the same distance between succeeding
2443 % lines of the \textsf{parbox}.
2444 % We have to remember that the distance between two \textsf{parboxes}
2445 % should be defined by =\@arstrut=. That means that it can be
2446 % greater than the distance in a \textsf{parbox}.
2447 % Therefore it is not enough to set a =\@arstrut= at the
2448 % beginning and at the end of the \textsf{parbox}. This would
2449 % dimension the distance
2450 % between first and second line and the distance between the two
2451 % last lines of the \textsf{parbox} wrongly.
2452 % To prevent this we set an invisible rule of height
2453 % =\@arstrutbox=
2454 % at the beginning of the \textsf{parbox}. This has no effect on the
2455 % depth of the first line. At the end of the \textsf{parbox} we set
2456 % analogously another invisible rule which only affects the depth
2457 % of the last line. It is necessary to wait inserting this strut
2458 % until the paragraph actually starts to allow for things like
2459 % =\parindent= changes via =>{...}=.
2460 % \changes{v2.1c}{1992/12/14}{Use `everypar to insert strut}
2461 % \begin{macrocode}
2462 \everypar{%
2463 \vrule \@height \ht\@arstrutbox \@width \z@
2464 \everypar{}}%
2465 }
2466 % \end{macrocode}
2467 %
2468 % \changes{v2.6h}{2024/12/17}{New \cs{@startpbox@action} to do the real work
2469 % after the preamble is built (gh/1585)}
2470 % Starting with 2.6h, \cs{@startpbox} is used only during the
2471 % built-up of the preamble and then changed to \cs{@startpbox@action}
2472 % which does the real work. For an explanation of this code see
2473 % the documentation in \cs{@mkpream}. We keep the \cs{@startpbox}
2474 % definition on top-level in case there are tabular packages that
2475 % built the preamble differently and expect that it contains
2476 % \cs{@startpbox} (\pkg{longtable} at the moment).
2477 % \begin{macrocode}
2478 \let\@startpbox@action\@startpbox
2479 % \end{macrocode}
2480 % \end{macro}
2481 %
2482 % \begin{macro}[int]{\@endpbox}
2483 % If there are any declarations defined by =>{...}=
2484 % and =<{...}=
2485 % they now follow in the macro =\@classz= --- the contents
2486 % of the column in between.
2487 % So the macro =\@endpbox= must insert the \textsf{specialstrut}
2488 % mentioned earlier and then close the group opened by
2489 % =\@startpbox=.
2490 % \changes{v2.2d}{1994/05/16}{Use \LaTeXe \cs{@finalstrut}}
2491 % \changes{v2.3g}{1996/05/07}{Add \cs{hfil} for tools/2120}
2492 % \changes{v2.4i}{2018/09/13}{Add group to prevent color leak (gh/72)}
2493 % \changes{v2.5d}{2021/02/10}{Explicitly run \cs{par} at the end of pboxes}
2494 % \begin{macrocode}
2495 \def\@endpbox{\@finalstrut\@arstrutbox \par \color@endgroup \egroup\hfil}
2496 % \end{macrocode}
2497 % \end{macro}
2498 %
2499 % \begin{macro}[int]{\@finalstrut}
2500 % We also have to adjust \cs{@finalstrut} so that it doesn't back
2501 % up by a \cs{baselineskip} when the the current vlist is completely empty.
2502 % This should go eventually to \file{ltboxes} but not in a PL.
2503 % \changes{v2.6i}{2025/05/19}{Ensure \cs{arraystretch} is taken into
2504 % account inside a tabular (gh/1730)}
2505 % \changes{v2.6j}{2025/06/08}{Fix gh/1730 correctly (gh/1765)}
2506 % \begin{macrocode}
2507 \def\@finalstrut#1{%
2508 \unskip
2509 \ifhmode \nobreak
2510 \else
2511 \ifnum\lastnodetype>\m@ne
2512 \vskip-\baselineskip
2513 \fi
2514 \fi
2515 \vrule\@width\z@\@height\z@\@depth\dp#1}
2516 % \end{macrocode}
2517 % \end{macro}
2518 %
2519 %
2520 % \section{Building and calling \texttt{\textbackslash halign}}
2521 %
2522 % \begin{macro}[int]{\@array}
2523 % After we have discussed the macros needed for the evaluation
2524 % of the user preamble we can define the macro =\@array=
2525 % which uses these macros to create a =\halign=.
2526 % It has two arguments. The first one is a position argument
2527 % which can be \texttt{t}, \texttt{b} or \texttt{c}; the
2528 % second one describes the wanted preamble,
2529 % e.g.\ it has the form =|c|c|c|=.
2530 % \begin{macrocode}
2531 \def\@array[#1]#2{
2532 % \end{macrocode}
2533 % First we define a \textsf{strut} whose size basically corresponds
2534 % to a normal \textsf{strut} multiplied by the factor
2535 % =\arraystretch=.
2536 % This \textsf{strut} is then inserted into every row and enforces
2537 % a minimal distance between two rows.
2538 % Nevertheless, when using horizontal lines, large letters
2539 % (like accented capital letters) still collide with such lines.
2540 % Therefore at first we add to the height of a normal \textsf{strut}
2541 % the value of the parameter =\extrarowheight=.
2542 % \begin{macrocode}
2543 \@tempdima \ht \strutbox
2544 \advance \@tempdima by\extrarowheight
2545 \setbox \@arstrutbox \hbox{\vrule
2546 \@height \arraystretch \@tempdima
2547 \@depth \arraystretch \dp \strutbox
2548 \@width \z@}%
2549 % \end{macrocode}
2550 % Before starting a table we have to initialize the variables
2551 % holding row and column information for cells. We also have
2552 % locally store the information related to the current cell (if we
2553 % are already inside a table) so that we can restore it once the
2554 % inner table is finished.
2555 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
2556 % The total number of table columns of the current table is
2557 % determined in \cs{tbl_count_table_cols:} but this is called in
2558 % a group, so local settings do not survive. Thus, to save away the
2559 % outer value of \cs{g_@@_table_cols_tl} we do that also
2560 % \cs{tbl_init_cell_data_for_table:}.
2561 % \changes{v2.6k}{2025/07/18}{Set cs{tbl_init_cell_data_for_table} here}
2562 % \begin{macrocode}
2563 \tbl_init_cell_data_for_table:
2564 % \end{macrocode}
2565 % Then we open a group, in which the user preamble is evaluated by
2566 % the macro =\@mkpream=. As we know this must happen locally.
2567 % This macro creates a preamble for a =\halign= and saves
2568 % its result globally in the control sequence =\@preamble=.
2569 % \begin{macrocode}
2570 \begingroup
2571 \@mkpream{#2}%
2572 % \end{macrocode}
2573 % Figure out how many columns this table has:
2574 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
2575 % \begin{macrocode}
2576 \tbl_count_table_cols:
2577 % \end{macrocode}
2578 % We again redefine =\@preamble= so that a call up of =\@preamble=
2579 % now starts the =\halign=. Thus also the arguments of \texttt{>},
2580 % \texttt{<}, \texttt{@} and \texttt{!}, saved in the
2581 % \textsf{token} registers are inserted into the preamble. The
2582 % =\tabskip= at the beginning and end of the preamble is set to
2583 % \textsf{0pt} (in the beginning by the use of =\ialign=). Also the
2584 % command =\@arstrut= is build in, which inserts the
2585 % =\@arstrutbox=, defined above. Of course, the opening brace after
2586 % =\ialign= has to be implicit as it will be closed in =\endarray=
2587 % or another macro.
2588 % \changes{v2.3m}{1998/12/31}{Added \cs{noexpand} in front of \cs{ialign}
2589 % to guard against interesting :-) changes to \cs{halign} done to support
2590 % text glyphs in math}
2591 %
2592 % The =\noexpand= in front of =\ialign= does no harm in standard \LaTeX{}
2593 % and was added since some experimental support for using text glyphs in math
2594 % redefines =\halign= with the result that is becomes expandable with
2595 % disastrous results in cases like this.
2596 % In the kernel definition for this macro the problem does
2597 % not surface because there =\protect= is set (which is not necessary in this
2598 % implementation as there is no arbitrary user input that can get expanded) and
2599 % the experimental code made the redefinition robust. Whether this is the right
2600 % approach is open to question; consider the =\noexpand= a courtesy to allow an
2601 % unsupported redefinition of a \TeX{} primitive for the moment (as people rely
2602 % on that experimental code).
2603 % \begin{macrocode}
2604 \xdef\@preamble{
2605 % \end{macrocode}
2606 % \cs{ialign} in the original definition is replaced by
2607 % \cs{ar@ialign} defined below. This does what \cs{ialign} does but
2608 % additionally handles the tagging structure for the whole table if necessary.
2609 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2610 % \begin{macrocode}
2611 \noexpand \ar@ialign
2612 \@halignto
2613 \bgroup \@arstrut
2614 % \end{macrocode}
2615 % What we have not explained yet is the macro =\@halignto=
2616 % that was just used. Depending on its replacement text the
2617 % =\halign= becomes a =\halign= \texttt{to} \meta{dimen}.
2618 %
2619 % Next, a tagging support socket is inserted adding the start row tag.
2620 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2621 % \begin{macrocode}
2622 \UseTaggingSocket{tbl/row/begin}
2623 % \end{macrocode}
2624 %
2625 % \begin{macrocode}
2626 \@@_hook_use_protected:nV {tbl/row/begin} \g_@@_row_int
2627 % \end{macrocode}
2628 % At the start of the preamble for the first column we call
2629 % \cs{tbl_init_cell_data_for_row:} to initialize the cell index data. In
2630 % later columns this data is updated via \cs{tbl_update_cell_data:}.
2631 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
2632 % \begin{macrocode}
2633 \tbl_init_cell_data_for_row:
2634 % \end{macrocode}
2635 %
2636 % \begin{macrocode}
2637 \@preamble
2638 \tabskip \z@ \cr}
2639 % \end{macrocode}
2640 % Now we close the group again. Thus
2641 % =\@startpbox= and =\@endpbox= as well as all
2642 % \textsf{token} registers get their former meaning back.
2643 % \begin{macrocode}
2644 \endgroup
2645 % \end{macrocode}
2646 % Then we run the hook \hook{tbl/init} that can be used by other
2647 % packages to add additional initializations. We pass it the number
2648 % of columns detected and the user preamble for inspection in the
2649 % hook code.
2650 % \changes{v2.6m}{2026-01-15}{Add support hook}
2651 % \begin{macrocode}
2652 \exp_args:Nnno \hook_use:nnw {tbl/init} {2}
2653 \g_@@_table_cols_tl {#2}
2654 % \end{macrocode}
2655 % To support the \texttt{delarray.sty} package we include a hook
2656 % into this part of the code which is a no-op in the main package.
2657 % \changes{v2.1a}{1992/07/03}{Hook for delarray added}
2658 % \begin{macrocode}
2659 \@arrayleft
2660 % \end{macrocode}
2661 % Now we decide depending on the position argument in which
2662 % \textsf{box} the =\halign= is to be put. (=\vcenter= may be used
2663 % because we are in math mode.)
2664 % \changes{v2.1a}{1992/07/03}{Wrong spec is now equiv to [t]}
2665 % \changes{v2.7b}{2026/02/24}{Use text mode vertical centering}
2666 % \begin{macrocode}
2667 \if #1t\vtop \else \if#1b\vbox \else \vcenter@text \fi \fi
2668 % \end{macrocode}
2669 % Now another implicit opening brace appears; then definitions
2670 % which shall stay local follow. While constructing the
2671 % =\@preamble= in =\@mkpream= the =#= sign must be
2672 % hidden in the macro =\@sharp= which is =\let= to
2673 % =\relax= at that moment (see definition of =\@mkpream=
2674 % on page~\pageref{@mkpream}).
2675 % All these now get their actual meaning.
2676 % \begin{macrocode}
2677 \bgroup
2678 \let \@sharp ##\let \protect \relax
2679 % \end{macrocode}
2680 % With the above defined \textsf{struts} we fix down the distance
2681 % between rows by setting =\lineskip= and =\baselineskip=
2682 % to \textsf{0pt}. Since there have to be set =$='s
2683 % around every column in the \textsf{array}--environment
2684 % the parameter =\mathsurround= should
2685 % also be set to \textsf{0pt}. This prevents additional space between
2686 % the rows.
2687 % \begin{macrocode}
2688 \lineskip \z@
2689 \baselineskip \z@
2690 % \end{macrocode}
2691 % Don't use \cs{m@th} here as that signals to the math tagging
2692 % code that this is fake math that should not be tagged.
2693 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2694 % \begin{macrocode}
2695 \mathsurround \z@
2696 % \end{macrocode}
2697 % Beside, we have to assign a special meaning (which we still have
2698 % to specify) to the line separator =\\=. We also have to
2699 % redefine the command =\par= in such a way that empty lines in
2700 % =\halign= cannot do any damage. We succeed in doing so
2701 % by choosing something that will disappear when expanding.
2702 % After that we only have to call up =\@preamble= to
2703 % start the wanted =\halign=.
2704 % \changes{v2.3b}{1994/12/08}{add \cs{tabularnewline}}
2705 % \changes{v2.6m}{2025/09/24}{Check \cs{currentgrouptype} in \cs{par} (gh1864)}
2706 % \changes{v2.6n}{2025/09/25}{double @ for l3doc conventions (gh1864)}
2707 % \begin{macrocode}
2708 \let\\\@arraycr \let\tabularnewline\\%
2709 \def\par{\ifnum\currentgrouptype=6~ \else\@@@@par\fi}%
2710 % \end{macrocode}
2711 % Another socket for tagging. TODO: what about \cs{arrayleft} above?
2712 % \begin{macrocode}
2713 \UseTaggingSocket{tbl/init}
2714 % \end{macrocode}
2715 %
2716 % \begin{macrocode}
2717 %\show \@preamble
2718 \@preamble
2719 }
2720 % \end{macrocode}
2721 % \end{macro}
2722 %
2723 %
2724 %
2725 %
2726 %
2727 % \begin{macro}[int]{\ar@ialign}
2728 % A new command that replaces \cs{ialign} used previously. \cs{everycr} is
2729 % also applied to the \cs{cr} ending the preamble so we have to
2730 % program around that.
2731 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2732 % \begin{macrocode}
2733 \def\ar@ialign{%
2734 % \end{macrocode}
2735 %
2736 % \begin{macrocode}
2737 \everycr{%
2738 \noalign{%
2739 % \end{macrocode}
2740 % If this \cs{cr} was at the end of a real row (e.g., not at the
2741 % end of the table preamble) we run the end-row hook row and also
2742 % have add the socket that adds the end-row tag.
2743 % \changes{v2.6m}{2026-01-15}{Add support hook}
2744 % \begin{macrocode}
2745 \tbl_if_row_was_started:T {
2746 % \end{macrocode}
2747 %
2748 % \begin{macrocode}
2749 \@@_hook_use_protected:nV {tbl/row/end} \g_@@_row_int
2750 \UseTaggingSocket{tbl/row/end}
2751 }
2752 % \end{macrocode}
2753 % Then we prepare for the next row.
2754 % \begin{macrocode}
2755 \tbl_update_cell_data_for_next_row:
2756 % \end{macrocode}
2757 % We are now ready to start the next row and or to process any
2758 % material between rows, such as \cs{hline}. This is the right
2759 % place to initialize anything extra for the upcoming row, i.e.,
2760 % the place for the \texttt{tbl/row/init}.
2761 %
2762 % For a number of reasons we have to do this inside a \cs{noalign}
2763 % so declarations put into this hook have to be global to take any
2764 % effect.
2765 %
2766 % But we also want to be able to call \cs{hline} or \cs{rowcolor}
2767 % and similar commands from this hook. Such commands come with
2768 % their own \cs{noalign} and it is not allowed to nest them. We
2769 % therefore temporarily change \cs{noalign} into a no-op.
2770 %
2771 % At this point, \LaTeX{} does not know if there is any real row
2772 % following or if the next thing is \verb=\end{tabular}=. This can
2773 % only be figured out in a two pass system, where the last row
2774 % number of each tabular is recorded and passed to the next run via
2775 % the \texttt{.aux} file. If hook code needs this information it has
2776 % implement this as part of the hook code. Should it turn out that
2777 % is needed more often we may provided it in the end directly.
2778 %
2779 % \changes{v2.6m}{2026-01-15}{Add support hook}
2780 % \begin{macrocode}
2781 \cs_set_eq:NN \noalign \prg_do_nothing:
2782 \@@_hook_use_protected:nV {tbl/row/init} \g_@@_row_int
2783 }%
2784 }%
2785 \tabskip\z@skip\halign}
2786 % \end{macrocode}
2787 % \end{macro}
2788 %
2789 %
2790 %
2791 %
2792 % \begin{macro}[no-user-doc]{\arraybackslash}
2793 % \changes{v2.4a}{2003/12/17}{(DPC) Macro added (from tabularx)}
2794 % Restore =\\= for use in array and tabular environment (after
2795 % =\raggedright= etc.).
2796 % \begin{macrocode}
2797 \def\arraybackslash{\let\\\tabularnewline}
2798 % \end{macrocode}
2799 % \end{macro}
2800 %
2801 % \begin{macro}[no-user-doc]{\extrarowheight}
2802 % The \textsf{dimen} parameter used above also needs to be
2803 % allocated. As a default value we use \textsf{0pt}, to ensure
2804 % compatibility with standard \LaTeX.
2805 % \begin{macrocode}
2806 \newdimen \extrarowheight
2807 \extrarowheight=0pt
2808 % \end{macrocode}
2809 % \end{macro}
2810 %
2811 % \begin{macro}[int]{\@arstrut}
2812 % Now the insertion of =\@arstrutbox= through =\@arstut=
2813 % is easy since we know exactly in which mode \TeX\ is while working
2814 % on the =\halign= preamble.
2815 % \begin{macrocode}
2816 \def\@arstrut{\unhcopy\@arstrutbox}
2817 % \end{macrocode}
2818 % \end{macro}
2819 %
2820 %
2821 % \section{The line separator \texttt{\textbackslash\textbackslash}}
2822 %
2823 % \begin{macro}[int]{\@arraycr}
2824 % In the macro =\@array= the line separator =\\= is
2825 % =\let= to the command =\@arraycr=.
2826 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
2827 % \changes{v2.5e}{2021/04/20}{Use \cs{protected} for \cs{\textbackslash} variant (gh/548)}
2828 % \begin{macrocode}
2829 \protected\def\@arraycr {
2830 % \end{macrocode}
2831 % Add code that figures out if the current table row is incomplete
2832 % (not enough \verb=&=s). It can then do extra actions, such as
2833 % inserting missing cell tags.
2834 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
2835 % \begin{macrocode}
2836 \tbl_count_missing_cells:n {@arraycr}
2837 % \end{macrocode}
2838 % TODO: maybe this is also the right place to add a socket that
2839 % could be used to actually enter missing cells instead of just
2840 % adding tagging structures for them later. This would be optional
2841 % but in many cases it would be the right thing to do (for example
2842 % if tables contain vertical lines or similar visual structures
2843 % that require fully specified rows.
2844 %
2845 %
2846 % We then start a special brace which I have directly
2847 % copied from the original definition. It is
2848 % necessary, because the =\futurelet= in =\@ifnextchar=
2849 % might
2850 % expand a following =&= \textsf{token} in a construction like
2851 % =\\ &=. This would otherwise end the alignment template at a
2852 % wrong time. On the other hand we have to be careful to avoid
2853 % producing a real group, i.e.\ ={}=, because the command will also
2854 % be used for the array environment, i.e.\ in math mode. In that
2855 % case an extra ={}= would produce an ord atom which could mess up
2856 % the spacing. For this reason we use a combination that does not
2857 % really produce a group at all but modifies the master counter so
2858 % that a =&= will not be considered belonging to the current
2859 % =\halign= while we are looking for a =*= or =[=.
2860 % For further information see
2861 % \cite[Appendix~D]{bk:knuth}.
2862 % \begin{macrocode}
2863 \iffalse{\fi\ifnum 0=`}\fi
2864 % \end{macrocode}
2865 % Then we test whether the user is using the star form and ignore
2866 % a possible star (I also disagree with this procedure, because a
2867 % star does not make any sense here).
2868 % \begin{macrocode}
2869 \@ifstar \@xarraycr \@xarraycr}
2870 % \end{macrocode}
2871 % \end{macro}
2872
2873
2874
2875
2876
2877 %
2878 % \begin{macro}[int]{\@xarraycr}
2879 % In the command =\@xarraycr= we test if an optional argument
2880 % exists.
2881 % \begin{macrocode}
2882 \def\@xarraycr{\@ifnextchar [%
2883 % \end{macrocode}
2884 % If it does, we branch out into the macro =\@argarraycr= if
2885 % not we close the special brace (mentioned above) and end the row
2886 % of the =\halign= with a =\cr=.
2887 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
2888 % \begin{macrocode}
2889 \@argarraycr {\ifnum 0=`{}\fi\cr}}
2890 % \end{macrocode}
2891 % \end{macro}
2892 %
2893 %
2894 % \begin{macro}[int]{\@argarraycr}
2895 % If additional space is requested by the user this case is treated
2896 % in the macro =\@argarraycr=. First we close the special brace
2897 % and then we test if the additional space is positive.
2898 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
2899 % \begin{macrocode}
2900 \def\@argarraycr[#1]{\ifnum0=`{}\fi\ifdim #1>\z@
2901 % \end{macrocode}
2902 % If this is the case we create an invisible vertical rule with
2903 % depth =\dp\@arstutbox=${}+{}$\meta{wanted\ space}.
2904 % Thus we achieve that all vertical lines specified
2905 % in the user preamble by a \texttt{|} are now
2906 % generally drawn.
2907 % Then the row ends with a =\cr=.
2908 %
2909 % If the space is negative we end the row at once with a =\cr=
2910 % and move back up with a =\vskip=.
2911 %
2912 % While testing these macros I found out that the
2913 % =\endtemplate=
2914 % created by =\cr= and =&= is something like an
2915 % =\outer= primitive and therefore it should not appear in
2916 % incomplete =\if= statements. Thus the following solution was
2917 % chosen which hides the =\cr= in other macros when \TeX\
2918 % is skipping conditional text.
2919 % \changes{v2.3c}{1995/04/23}{Use \cs{expandafter}'s in conditional}
2920 % \begin{macrocode}
2921 \expandafter\@xargarraycr\else
2922 \expandafter\@yargarraycr\fi{#1}}
2923 % \end{macrocode}
2924 % \end{macro}
2925 %
2926 % \begin{macro}[int]{\@xargarraycr}
2927 % \begin{macro}[int]{\@yargarraycr}
2928 % The following macros were already explained above.
2929 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
2930 % \begin{macrocode}
2931 \def\@xargarraycr#1{\unskip\gdef\do@row@strut
2932 {\@tempdima #1\advance\@tempdima \dp\@arstrutbox
2933 \vrule \@depth\@tempdima \@width\z@\global\let\do@row@strut\relax}%
2934 % \end{macrocode}
2935 % If the last column is a =\multicolumn= cell then we need to
2936 % insert the row strut now as it isn't inside the template (as that
2937 % got =\omit=ted).
2938 % \changes{v2.4h}{2018/04/30}{Fixing issue 42}
2939 % \begin{macrocode}
2940 \ifnum\@multicnt >\z@ \do@row@strut \fi
2941 \cr}
2942 \let\do@row@strut\relax
2943 % \end{macrocode}
2944 %
2945 % \cs{@yargarraycr} is the same as in the \LaTeX{} kernel
2946 % (depending on the date of the kernel with one of the two
2947 % definitions below). We therefore do not define it again.
2948 % \changes{v2.5b}{2020/04/22}{Don't define \cs{@yargarraycr} unnecessarily}
2949 % \begin{macrocode}
2950 %\def\@yargarraycr#1{\cr\noalign{\@vspace@calcify{#1}}} % 2020-10-01
2951 %\def\@yargarraycr#1{\cr\noalign{\vskip #1}}
2952 % \end{macrocode}
2953 % \end{macro}
2954 % \end{macro}
2955 %
2956 %
2957 %
2958 %
2959 % \section{Spanning several columns}
2960 %
2961 % \begin{macro}[no-user-doc]{\multicolumn}
2962 % If several columns should be held together with a special format
2963 % the command =\multicolumn= must be used. It has three
2964 % arguments: the number of columns to be covered; the format for
2965 % the result column and the actual column entry.
2966 % \changes{v2.3j}{1998/01/29}{Command made \cs{long} to match
2967 % kernel change for pr/2180}
2968 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
2969 % \begin{macrocode}
2970 \long\def\multicolumn#1#2#3{%
2971 % \end{macrocode}
2972 % First we combine the given number of columns into a single one;
2973 % then we start a new block so that the following definition is kept
2974 % local.
2975 % \begin{macrocode}
2976 \multispan{#1}\begingroup
2977 % \end{macrocode}
2978 % For tagging support we have to solve two problems:
2979 % \cs{multicolumn} must handle the row begin if it is used there,
2980 % and it must save the numbers of cells it spans so that we can add
2981 % a suitable ColSpan attribute. We do this in the next macro
2982 % (which in turn calls the \texttt{tbl/row/begin} socket, if
2983 % necessary).
2984 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
2985 % \begin{macrocode}
2986 \tbl_update_multicolumn_cell_data:n {#1}
2987 % \end{macrocode}
2988 % Since a =\multicolumn= should only describe the format of a
2989 % result column, we redefine =\@addamp= in such a way that one gets
2990 % an error message if one uses more than one \texttt{c},
2991 % \texttt{l}, \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in
2992 % the second argument. One should consider that this definition is
2993 % local to the build-up of the preamble; an \textsf{array}-- or
2994 % \textsf{tabular}--environment in the third argument of the
2995 % =\multicolumn= is therefore worked through correctly as well.
2996 % \begin{macrocode}
2997 \def\@addamp{\if@firstamp \@firstampfalse \else
2998 \@preamerr 5\fi}%
2999 % \end{macrocode}
3000 % Then we evaluate the second argument with the help of
3001 % =\@mkpream=.
3002 % Now we still have to insert the contents of the \textsf{token}
3003 % register into the =\@preamble=, i.e.\ we have to say
3004 % =\xdef\@preamble{\@preamble}=. This is achieved shorter by
3005 % writing:
3006 % \begin{macrocode}
3007 \@mkpream{#2}\@addtopreamble\@empty
3008 % \end{macrocode}
3009 % After the =\@preamble= is created we forget all local
3010 % definitions and occupations of the \textsf{token} registers.
3011 % \begin{macrocode}
3012 \endgroup
3013 % \end{macrocode}
3014 % Now we update the colspan attribute. This needs setting after
3015 % the group as it is hidden inside the plug in \cs{insert@column}.
3016 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
3017 % \begin{macrocode}
3018 \UseTaggingSocket{tbl/colspan}{#1}%
3019 % \end{macrocode}
3020 % In the special situation of =\multicolumn= =\@preamble=
3021 % is not needed as preamble for a =\halign= but it is directly
3022 % inserted into our table. Thus instead of =\sharp=
3023 % there has to be the column entry (=#3=) wanted by the user.
3024 % \begin{macrocode}
3025 \def\@sharp{#3}%
3026 % \end{macrocode}
3027 % Now we can pass the =\@preamble= to \TeX\ . For safety
3028 % we start with an =\@arstrut=. This should usually be in the
3029 % template for the first column however we do not know if this
3030 % template was overwritten by our =\multicolumn=.
3031 % We also add a =\null= at the right end to prevent any following
3032 % =\unskip= (for example from =\\[..]=) to remove the =\tabcolsep=.
3033 % \changes{v2.2e}{1994/06/01}{Added \cs{null}}
3034 % \begin{macrocode}
3035 \@arstrut \@preamble
3036 \null
3037 \ignorespaces}
3038 % \end{macrocode}
3039 % \end{macro}
3040 %
3041 %
3042 %
3043 % \section{The Environment Definitions}
3044 %
3045 % After these preparations we are able to define the environments. They
3046 % only differ in the initializations of =\d@llar...=, =\col@sep=
3047 % and =\@halignto=.
3048 %
3049 % \begin{macro}[int]{\@halignto}
3050 % \begin{macro}[no-user-doc]{\d@llarbegin}
3051 % \begin{macro}[no-user-doc]{\d@llarend}
3052 % =\d@llar= has to be
3053 % locally assigned since otherwise nested \textsf{tabular} and \textsf{array}
3054 % environments (via =\multicolumn=) are impossible.
3055 % For 25 years or so =\@halignto= was set globally (to save space on the
3056 % save stack, but that was a mistake: if there is a tabular in the
3057 % output routine (e.g., in the running header) then that tabular is
3058 % able overwrite the =\@halignto=
3059 % setting of a tabular in the main text resulting in a very weird error.
3060 % \changes{v2.4d}{2016/10/06}{\cs{@halignto} set locally (pr/4488)}
3061 % \changes{v2.0g}{1992/06/18}{`d@llarbegin defined on top-level.}
3062 % When the new font selection scheme is in force we have to
3063 % we surround all =\halign= entries
3064 % with braces. See remarks in TUGboat 10\#2. Actually we are going
3065 % to use =\begingroup= and =\endgroup=. However, this is only
3066 % necessary when we are in text mode. In math the surrounding
3067 % dollar signs will already serve as the necessary extra grouping
3068 % level. Therefore we switch the settings of =\d@llarbegin= and
3069 % =\d@llarend= between groups and dollar signs.
3070 % \begin{macrocode}
3071 \let\d@llarbegin\begingroup
3072 \let\d@llarend\endgroup
3073 % \end{macrocode}
3074 % \end{macro}
3075 % \end{macro}
3076 % \end{macro}
3077 %
3078 %
3079 % \begin{macro}[no-user-doc]{\array}
3080 % Our new definition of =\array= then reads:
3081 % \changes{v2.0d}{1990/08/20}{`d@llar local to preamble.}
3082 % \changes{v2.4d}{2016/10/06}{\cs{@halignto} set locally (pr/4488)}
3083 % In math mode we additionally add also the tagging sockets for luamml.
3084 % \changes{v2.6h}{2024/12/02}{Add tagging sockets for luamml support}.
3085 % \changes{v2.7b}{2026/02/24}{Move \cs{m@th} from \cs{@tabarray}}
3086 % The =math/luamml/array/finalizecol= takes as argument a number (0, 1, 2)
3087 % that should represent the alignment (c,l,r).
3088 % TODO: instead of =\the\@chnum= a proper tl should be used.
3089 % TODO: the w and W columntypes must be redefined - currently they
3090 % insert stray mtext columns.
3091 % \begin{macrocode}
3092 \def\array{\col@sep\arraycolsep
3093 \def\d@llarbegin{$\tag_socket_use:n { math/luamml/array/initcol }}
3094 \def\d@llarend
3095 {
3096 \tag_socket_use:nn { math/luamml/save/nn }{{}{mtd}}
3097 $
3098 \tag_socket_use:nn { math/luamml/array/finalizecol}{\the\@chnum}
3099 }
3100 \def\@halignto{}%
3101 % \end{macrocode}
3102 % Since there might be an optional argument we call another
3103 % macro which is also used by the other environments.
3104 % \begin{macrocode}
3105 \m@th\@tabarray}
3106 % \end{macrocode}
3107 % \end{macro}
3108 %
3109 % \begin{macro}[int]{\@tabarray}
3110 % \emph{The code below has been replaced long time ago by an
3111 % extended version further down but the code and its documentation
3112 % was left here for reference. It is now commented out to avoid
3113 % confusion.}
3114 %
3115 % This macro tests for a optional bracket and then calls up
3116 % =\@array= or =\@array[c]= (as default).
3117 % \begin{macrocode}
3118 %\def\@tabarray{\@ifnextchar[{\@array}{\@array[c]}}
3119 % \end{macrocode}
3120 % \end{macro}
3121 %
3122 %
3123 % \begin{macro}[no-user-doc]{\tabular}
3124 % \begin{macro}[no-user-doc]{\tabular*}
3125 % The environments \textsf{tabular} and \textsf{tabular$*$} differ
3126 % only in the initialization of the command =\@halignto=. Therefore
3127 % we define
3128 % \changes{v2.4d}{2016/10/06}{\cs{@halignto} set locally (pr/4488)}
3129 % \begin{macrocode}
3130 \def\tabular{\def\@halignto{}\@tabular}
3131 % \end{macrocode}
3132 % and analogously for the star form. We evaluate the argument first
3133 % using =\setlength= so that users of the \texttt{calc} package can
3134 % write code like\\ =\begin{tabular*}{(\columnwidth-1cm)/2}...=
3135 % \changes{v2.3l}{1998/05/13}{Use \cs{setlength} evaluate arg
3136 % so that the calc package can be applied here (pr/2793)}
3137 % \changes{v2.4d}{2016/10/06}{\cs{@halignto} set locally (pr/4488)}
3138 % \begin{macrocode}
3139 \expandafter\def\csname tabular*\endcsname#1{%
3140 \setlength\dimen@{#1}%
3141 \edef\@halignto{to\the\dimen@}\@tabular}
3142 % \end{macrocode}
3143 % \end{macro}
3144 % \end{macro}
3145 %
3146 % \begin{macro}[int]{\@tabular}
3147 % The rest of the job is carried out by the =\@tabular= macro:
3148 % \begin{macrocode}
3149 \providecommand\@kernel@tabular@init{}
3150 \def\@tabular{%
3151 % \end{macrocode}
3152 % First of all we have to make sure that we start out in
3153 % \textsf{hmode}. Otherwise we might find our table dangling by
3154 % itself on a line.
3155 % \begin{macrocode}
3156 \leavevmode
3157 % \end{macrocode}
3158 % Now that we know we are in hmode we can add the start tag for the
3159 % whole table.
3160 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
3161 % \begin{macrocode}
3162 \UseTaggingSocket{tbl/hmode/begin}%
3163 % \end{macrocode}
3164 % It should be taken into consideration that the macro =\@array=
3165 % must be called in math mode. Therefore we open a \textsf{box},
3166 % then assign the correct values to =\col@sep= and
3167 % =\d@llar...=.
3168 % \changes{v2.0d}{1990/08/20}{`d@llar local to preamble.}
3169 % \changes{v2.6h}{2025/02/18}{Surround dollar with \cs{MathCollectTrue}/\cs{MathCollectFalse}}%
3170 % \changes{v2.6l}{2025/09/09}{Use \cs{UseMathForPositioningText} instead (tagging/973+983)}%
3171 % \changes{v2.7b}{2026/02/24}{Remove math mode switch}
3172 % \begin{macrocode}
3173 \hbox \bgroup
3174 \col@sep\tabcolsep
3175 \let\d@llarbegin\begingroup
3176 \let\d@llarend\endgroup
3177 % \end{macrocode}
3178 % \changes{v2.6h}{2025/02/18}{Add internal kernel hook to switch math collection method}%
3179 % \begin{macrocode}
3180 \@kernel@tabular@init
3181 % \end{macrocode}
3182 % Now everything \textsf{tabular} specific is done and we are able to
3183 % call the =\@tabarray= macro.
3184 % \begin{macrocode}
3185 \@tabarray}
3186 % \end{macrocode}
3187 % \end{macro}
3188 %
3189 % \begin{macro}[no-user-doc]{\endarray}
3190 %
3191 % When the processing of \textsf{array} is finished we have to
3192 % close the =\halign=
3193 % and afterwards the surrounding \textsf{box} selected by
3194 % =\@array=. To save \textsf{token} space we then redefine
3195 % =\@preamble=
3196 % because its replacement text isn't longer needed.
3197 %
3198 % To handle cell indexes, we do not use \cs{crcr} but a variant
3199 % that also handles missing cells as necessary.
3200 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
3201 % \changes{v2.6h}{2024/12/02}{Add tagging sockets for luamml support}%
3202 % \begin{macrocode}
3203 \def\endarray {
3204 \tbl_crcr:n{endarray}
3205 \tag_socket_use_expandable:n { math/luamml/array/save }
3206 \egroup
3207 \tag_socket_use:n { tbl/finalize }
3208 % \end{macrocode}
3209 %
3210 % If tables are nested into another then it is necessary to
3211 % restore information about the cell the inner table started
3212 % in. Otherwise, the cell index data structures reflect the
3213 % status in the outer table as they
3214 % are globally manipulated. We restore in all cases even if we are
3215 % not in a nesting situation as that makes the code simpler (and
3216 % probably faster).
3217 %
3218 % \cs{endtabular} and \cs{endtabular*} inherit from \cs{endarray}
3219 % so we only need to change that. \texttt{tabularx} uses a similar method.
3220 % \changes{v2.6a}{2023/12/11}{Managing cell indexes}
3221 % \begin{macrocode}
3222 \tbl_restore_outer_cell_data:
3223 % \end{macrocode}
3224 %
3225 % \begin{macrocode}
3226 \egroup
3227 \tag_socket_use:n { math/luamml/array/finalize }
3228 \@arrayright \gdef\@preamble{}%
3229 }
3230 % \end{macrocode}
3231 % \end{macro}
3232 %
3233 %
3234 %
3235 %
3236 % \begin{macro}[no-user-doc]{\endtabular}
3237 % \begin{macro}[no-user-doc]{\endtabular*}
3238 % To end a \textsf{tabular} or \textsf{tabular$*$} environment we
3239 % call up =\endarray=, then the surrounding
3240 % =\hbox=.
3241 % \changes{v2.5f}{2021/07/12}{Cancel any outside \cs{mathsurround} (gh/614)}
3242 % \changes{v2.7b}{2026/02/24}{Remove math mode switch}
3243 % \begin{macrocode}
3244 \def\endtabular{\endarray\egroup
3245 % \end{macrocode}
3246 %
3247 % \changes{v2.6a}{2023/12/11}{Support for tagged PDF}
3248 % \begin{macrocode}
3249 \UseTaggingSocket{tbl/hmode/end}%
3250 }
3251 \expandafter\let\csname endtabular*\endcsname=\endtabular
3252 % \end{macrocode}
3253 % \end{macro}
3254 % \end{macro}
3255 %
3256 %
3257 %
3258 % \section{Last minute definitions}
3259 %
3260 %
3261 % If this file is used as a package file we should =\let= all macros
3262 % to =\relax= that were used in the original but are no longer
3263 % necessary.
3264 % \begin{macrocode}
3265 \let\@ampacol=\relax \let\@expast=\relax
3266 \let\@arrayclassiv=\relax \let\@arrayclassz=\relax
3267 \let\@tabclassiv=\relax \let\@tabclassz=\relax
3268 \let\@arrayacol=\relax \let\@tabacol=\relax
3269 \let\@tabularcr=\relax \let\@@@@endpbox=\relax
3270 \let\@argtabularcr=\relax \let\@xtabularcr=\relax
3271 % \end{macrocode}
3272 %
3273 % \begin{macro}[int]{\@preamerr}
3274 % \changes{v2.6d}{2024/06/14}{Keep message sources out of L3 code (gh/1378)}
3275 % We also have to redefine the error routine =\@preamerr= since
3276 % new kind of errors are possible.
3277 % The code for this macro is not perfect yet;
3278 % it still needs too much memory.
3279 % \begin{macrocode}
3280 \ExplSyntaxOff
3281 \def\@preamerr#1{\def\@tempd{{..} at wrong position: }%
3282 \PackageError{array}{%
3283 \ifcase #1 Illegal pream-token (\@nextchar): `c' used\or %0
3284 Missing arg: token ignored\or %1
3285 Empty preamble: `l' used\or %2
3286 >\@tempd token ignored\or %3
3287 <\@tempd changed to !{..}\or %4
3288 Only one column-spec. allowed.\fi}\@ehc} %5
3289 % \end{macrocode}
3290 % \end{macro}
3291 %
3292 %
3293 %
3294 % \section
3295 % [Defining your own column specifiers]
3296 % {Defining your own column specifiers\footnotemark}
3297 %
3298 % \footnotetext{The code and the documentation in this section was
3299 % written by David. So far only the code from newarray was plugged
3300 % into array so that some parts of the documentation still claim
3301 % that this is newarray and even worse, some parts of the code are
3302 % unnecessarily doubled. This will go away in a future release. For
3303 % the moment we thought it would be more important to bring both
3304 % packages together.}
3305 % \changes{v2.1a}{1992/07/03}{Newcolumn stuff added}
3306 %
3307 % \DeleteShortVerb{\=}
3308 % \MakeShortVerb{\"}
3309 %
3310 % \begin{macro}[no-user-doc]{\newcolumn}
3311 % In \texttt{newarray.sty} the macro for specifying new columns was
3312 % named "\newcolumn". When the functionality was added to
3313 % \texttt{array.sty} the command was renamed "\newcolumntype".
3314 % Initially both names were supported, but now (In versions of this
3315 % package distributed for \LaTeXe) the old name is not defined.
3316 % \changes{v2.2a}{1994/02/03}{Now made `newcolumn an error}
3317 % \changes{v2.2a}{1994/02/04}{Removed `newcolumn}
3318 % \begin{macrocode}
3319 %<*ncols>
3320 % \end{macrocode}
3321 % \end{macro}
3322 %
3323 % \begin{macro}[no-user-doc]{\newcolumntype}
3324 % \changes{v2.1b}{1992/06/07}{Macro renamed from `newcolumn} As
3325 % described above, the "\newcolumntype" macro gives users the chance
3326 % to define letters, to be used in the same way as the primitive
3327 % column specifiers, `c' `p' etc.
3328 % \begin{macrocode}
3329 \def\newcolumntype#1{%
3330 % \end{macrocode}
3331 % "\NC@char" was added in V2.01 so that active characters, like "@" in
3332 % AMS\LaTeX\ may be used. This trick was stolen from \texttt{array.sty}
3333 % 2.0h. Note that we need to use the possibly active token,
3334 % "#1", in several places, as that is the token that actually
3335 % appears in the preamble argument.
3336 % \begin{macrocode}
3337 \edef\NC@char{\string#1}%
3338 % \end{macrocode}
3339 % First we check whether there is already a definition for this column.
3340 % Unlike "\newcommand" we give a warning rather than an error if it is
3341 % defined. If it is a new column, add "\NC@do" \meta{column} to
3342 % the list "\NC@list".
3343 % \begin{macrocode}
3344 \@ifundefined{NC@find@\NC@char}%
3345 {\@tfor\next:=<>clrmbp@!|\do
3346 {%
3347 % \end{macrocode}
3348 % We use \cs{noexpand} on the tokens from the list in case one or
3349 % the other (typically \texttt{@}, \texttt{!} or \texttt{|}) has
3350 % been made active.
3351 % \changes{v2.4l}{2019/08/31}{Add a necessary \cs{expandafter} (github/148)}
3352 % \begin{macrocode}
3353 \if\expandafter\noexpand\next\NC@char
3354 \PackageWarning{array}%
3355 {Redefining primitive column \NC@char}\fi}%
3356 \NC@list\expandafter{\the\NC@list\NC@do#1}}%
3357 {\PackageWarning{array}{Column \NC@char\space is already defined}}%
3358 % \end{macrocode}
3359 % Now we define a macro with an argument delimited by the new column
3360 % specifier, this is used to find occurrences of this specifier in the
3361 % user preamble.
3362 % \begin{macrocode}
3363 \@namedef{NC@find@\NC@char}##1#1{\NC@{##1}}%
3364 % \end{macrocode}
3365 % If an optional argument was not given, give a default argument of 0.
3366 % \begin{macrocode}
3367 \@ifnextchar[{\newcol@{\NC@char}}{\newcol@{\NC@char}[0]}}
3368 \ExplSyntaxOn
3369 % \end{macrocode}
3370 % \end{macro}
3371 % \begin{macro}[int]{\newcol@}
3372 % We can now define the macro which does the rewriting,
3373 % "\@reargdef" takes the same arguments as "\newcommand", but
3374 % does not check that the command is new. For a column, say `D' with
3375 % one argument, define a command "\NC@rewrite@D" with one
3376 % argument, which recursively calls "\NC@find" on the user preamble
3377 % after replacing the first token or group with the replacement text
3378 % specified in the "\newcolumntype" command. "\NC@find" will find the
3379 % next occurrence of `D' as it will be "\let" equal to
3380 % "\NC@find@D" by "\NC@do".
3381 % \begin{macrocode}
3382 \def\newcol@#1[#2]#3{\expandafter\@reargdef
3383 \csname NC@rewrite@#1\endcsname[#2]{\NC@find#3}}
3384 % \end{macrocode}
3385 % \end{macro}
3386 % \begin{macro}[int]{\NC@}
3387 % Having found an occurrence of the new column, save the preamble
3388 % before the column in "\@temptokena", then check to see if we
3389 % are at the end of the preamble. (A dummy occurrence of the column
3390 % specifier will be placed at the end of the preamble by "\NC@do".
3391 % \begin{macrocode}
3392 \def\NC@#1{%
3393 \@temptokena\expandafter{\the\@temptokena#1}\futurelet\next\NC@ifend}
3394 % \end{macrocode}
3395 % \end{macro}
3396 % \begin{macro}[int]{\NC@ifend}
3397 % We can tell that we are at the end as "\NC@do" will place a "\relax"
3398 % after the dummy column.
3399 % \begin{macrocode}
3400 \def\NC@ifend{%
3401 % \end{macrocode}
3402 % If we are at the end, do nothing. (The whole preamble will now be in
3403 % "\@temptokena".)
3404 % \begin{macrocode}
3405 \ifx\next\relax
3406 % \end{macrocode}
3407 % Otherwise set the flag "\if@tempswa", and rewrite the column.
3408 % "\expandafter" introduced 1n V2.01
3409 % \begin{macrocode}
3410 \else\@tempswatrue\expandafter\NC@rewrite\fi}
3411 % \end{macrocode}
3412 % \end{macro}
3413 % \begin{macro}[int]{\NC@do}
3414 % If the user has specified `C' and `L' as new columns, the list of
3415 % rewrites (in the token register "\NC@list") will look like
3416 % "\NC@do *" "\NC@do C" "\NC@do L".
3417 % So we need to define "\NC@do" as a one argument macro which
3418 % initializes the rewriting of the specified column. Let us assume that
3419 % `C' is the argument.
3420 % \begin{macrocode}
3421 \def\NC@do#1{%
3422 % \end{macrocode}
3423 % First we let "\NC@rewrite" and "\NC@find" be
3424 % "\NC@rewrite@C" and "\NC@find@C" respectively.
3425 % \begin{macrocode}
3426 \expandafter\let\expandafter\NC@rewrite
3427 \csname NC@rewrite@\string#1\endcsname
3428 \expandafter\let\expandafter\NC@find
3429 \csname NC@find@\string#1\endcsname
3430 % \end{macrocode}
3431 % Clear the token register "\@temptokena" after putting the present
3432 % contents of the register in front of the token "\NC@find". At the
3433 % end we place the tokens `"C\relax"' which "\NC@ifend" will use
3434 % to detect the end of the user preamble.
3435 % \begin{macrocode}
3436 \expandafter\@temptokena\expandafter{\expandafter}%
3437 \expandafter\NC@find\the\@temptokena#1\relax}
3438 % \end{macrocode}
3439 % \end{macro}
3440 %
3441 % \begin{macro}[no-user-doc]{\showcols}
3442 % This macro is useful for debugging "\newcolumntype" specifications,
3443 % it is the equivalent of the primitive "\show" command for macro
3444 % definitions. All we need to do is locally redefine "\NC@do" to take
3445 % its argument (say `C') and then "\show" the (slightly modified)
3446 % definition of "\NC@rewrite@C". Actually as the list always
3447 % starts off with "\NC@do *" and we do not want to print the
3448 % definition of the $*$-form, define "\NC@do" to throw away the first
3449 % item in the list, and then redefine itself to print the rest of the
3450 % definitions.
3451 % \begin{macrocode}
3452 \def\showcols{{\def\NC@do##1{\let\NC@do\NC@show}\the\NC@list}}
3453 % \end{macrocode}
3454 % \end{macro}
3455 % \begin{macro}[int]{\NC@show}
3456 % If the column `C' is defined as above, then
3457 % "\show\NC@rewrite@C" would output\\
3458 % "\long macro: ->\NC@find >{$}c<{$}".
3459 % We want to strip the "long macro: ->" and the "\NC@find". So first we
3460 % use "\meaning" and then apply the macro "\NC@strip" to the tokens so
3461 % produced and then "\typeout" the required string.
3462 % \begin{macrocode}
3463 \def\NC@show#1{%
3464 \typeout{Column~ #1\expandafter\expandafter\expandafter\NC@strip
3465 \expandafter\meaning\csname NC@rewrite@#1\endcsname\@@@@}}
3466 % \end{macrocode}
3467 % \end{macro}
3468 % \begin{macro}[int]{\NC@strip}
3469 % Delimit the arguments to "\NC@strip" with `\texttt{:}', `\texttt{->}',
3470 % a space, and "\@@@@" to pull out the required parts of the output from
3471 % "\meaning".
3472 % \begin{macrocode}
3473 \ExplSyntaxOff
3474 \def\NC@strip#1:#2->#3 #4\@@@@{#2 -> #4}
3475 \ExplSyntaxOn
3476 % \end{macrocode}
3477 % \end{macro}
3478 % \begin{macro}[int]{\NC@list}
3479 % Allocate the token register used for the rewrite list.
3480 % \begin{macrocode}
3481 \newtoks\NC@list
3482 % \end{macrocode}
3483 % \end{macro}
3484 %
3485 % \subsection{The \texorpdfstring{$*$}{*}--form}
3486 % We view the $*$-form as a slight generalization of the system
3487 % described in the previous subsection. The idea is to define a $*$
3488 % column by a command of the form:
3489 % \begin{verbatim}
3490 % \newcolumntype{*}[2]{%
3491 % \count@=#1\ifnum\count@>0
3492 % \advance\count@ by -1 #2*{\count@}{#2}\fi}
3493 % \end{verbatim}
3494 % \begin{macro}[int]{\NC@rewrite@*}\label{NC@rewrite@*}
3495 % \changes{v2.4b}{2005/08/23}{Fix occasional spurious space (PR/3755)}
3496 % This does not work however as "\newcolumntype" takes great care not
3497 % to expand anything in the preamble, and so the "\if" is never
3498 % expanded. "\newcolumntype" sets up various other parts of the
3499 % rewrite correctly though so we can define:
3500 % \begin{macrocode}
3501 \newcolumntype{*}[2]{}
3502 % \end{macrocode}
3503 % Now we must correct the definition of "\NC@rewrite@*". The
3504 % following is probably more efficient than a direct translation of
3505 % the idea sketched above, we do not need to put a $*$ in the preamble
3506 % and call the rewrite recursively, we can just put "#1" copies of
3507 % "#2" into "\@temptokena". (Nested $*$ forms will be expanded
3508 % when the whole rewrite list is expanded again, see "\@mkpream")
3509 % \begin{macrocode}
3510 \long\@namedef{NC@rewrite@*}#1#2{%
3511 % \end{macrocode}
3512 % Store the number.
3513 % \begin{macrocode}
3514 \count@#1\relax
3515 % \end{macrocode}
3516 % Put "#1" copies of "#2" in the token register.
3517 % \begin{macrocode}
3518 \loop
3519 \ifnum\count@>\z@
3520 \advance\count@\m@ne
3521 \@temptokena\expandafter{\the\@temptokena#2}%
3522 \repeat
3523 % \end{macrocode}
3524 % "\NC@do" will ensure that "\NC@find" is "\let" equal
3525 % to "\NC@find@*".
3526 % \begin{macrocode}
3527 \NC@find}
3528 % \end{macrocode}
3529 % \end{macro}
3530 %
3531 % \subsection{Modifications to internal macros of \texttt{array.sty}}
3532 %
3533 % \begin{macro}[int]{\@xexpast}
3534 % \begin{macro}[int]{\@xexnoop}
3535 % These macros are used to expand $*$-forms in
3536 % \texttt{array.sty}. "\let" them to "\relax" to save space.
3537 % \begin{macrocode}
3538 \let\@xexpast\relax
3539 \let\@xexnoop\relax
3540 % \end{macrocode}
3541 % \end{macro}
3542 % \end{macro}
3543 %
3544 % \begin{macro}[int]{\save@decl}
3545 % We do not assume that the token register is free, we add the new
3546 % declarations to the front of the register. This is to allow user
3547 % preambles of the form, ">{foo}>{bar}..". Users are not encouraged to
3548 % enter such expressions directly, but they may result from the
3549 % rewriting of "\newcolumntype"'s.
3550 % \begin{macrocode}
3551 \def\save@decl{\toks \count@ = \expandafter\expandafter\expandafter
3552 {\expandafter\@nextchar\the\toks\count@}}
3553 % \end{macrocode}
3554 % \end{macro}
3555 %
3556 % \begin{macro}[int]{\@mkpream}
3557 % The main modification to "\@mkpream" is to replace the call to
3558 % "\@xexpast" (which expanded $*$-forms) by a loop which expands
3559 % all "\newcolumntype" specifiers.
3560 % \changes{v2.4e}{2016/10/07}{Fixing SX68732}
3561 % \changes{v2.4f}{2017/11/04}{Managing m-cells without \cs{vcenter}}
3562 % \begin{macrocode}
3563 \ExplSyntaxOff % really oldstyle using \@tfor :=
3564 \def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue
3565 \let\@sharp\relax
3566 % \end{macrocode}
3567 %
3568 % The "\@startpbox" (which is called for "p", "m" or "b" columns)
3569 % receives a user supplied argument: the width of the
3570 % paragraph-column. Normally that is something harmless like a length or a
3571 % simple length expression, but with the calc package involved it
3572 % could break under an "\edef" operation, which is how the preamble
3573 % is constructed. We now make use of "\unexpanded" here to prevent that. The
3574 % "\expandafter" gymnastics are necessary to expand the "#1" exactly
3575 % once (since it will get "\@nextchar" as its value and need its
3576 % content). However, once added to the preamble, no further
3577 % expansion should happen if the preamble is extended. Therefore we
3578 % change from \cs{@startpbox} to \cs{@startpbox@action}. The latter
3579 % then has a trivial definition and expands (including its
3580 % argument) to itself while the preamble is being built. Outside of this
3581 % preamble build up \cs{@startpbox@action} does the actual work.
3582 %
3583 % \changes{v2.4j}{2018/11/13}{Do not expand argument of
3584 % \cs{@startpbox} while building the tabular preamble (sx/459285)}
3585 % \changes{v2.6h}{2024/12/17}{Expand argument of \cs{@startpbox}
3586 % exactly once while the preamble is being built, and use
3587 % \cs{@startpbox@action} later to do the real work (gh/1585)}
3588 % \begin{macrocode}
3589 \def\@startpbox##1{\unexpanded\expandafter{\expandafter
3590 \@startpbox@action\expandafter{##1}}}%
3591 \def\@startpbox@action##1{\unexpanded{\@startpbox@action{##1}}}%
3592 \let\@endpbox\relax
3593 \let\do@row@strut\relax
3594 \let\ar@align@mcell\relax
3595 % \end{macrocode}
3596 % Now we remove possible $*$-forms and user-defined column
3597 % specifiers in the user preamble by repeatedly executing the list
3598 % "\NC@list" until the re-writes have no more effect. The
3599 % expanded preamble will then be in the token register
3600 % "\@temptokena". Actually we need to know at this point that
3601 % this is not "\toks0".
3602 % \begin{macrocode}
3603 \@temptokena{#1}\@tempswatrue
3604 \@whilesw\if@tempswa\fi{\@tempswafalse\the\NC@list}%
3605 % \end{macrocode}
3606 % Afterwards we initialize all registers and macros, that we need
3607 % for the build-up of the preamble.
3608 % \begin{macrocode}
3609 \count@\m@ne
3610 \let\the@toks\relax
3611 \prepnext@tok
3612 % \end{macrocode}
3613 % Having expanded all tokens defined using "\newcolumntype" (including
3614 % "*"), we evaluate the remaining tokens, which are saved in
3615 % "\@temptokena". We use the \LaTeX--macro "\@tfor" to inspect each
3616 % token in turn.
3617 % \begin{macrocode}
3618 \expandafter \@tfor \expandafter \@nextchar
3619 \expandafter :\expandafter =\the\@temptokena \do
3620 % \end{macrocode}
3621 % "\@testpatch" does not take an argument since \texttt{array.sty} 2.0h.
3622 % \begin{macrocode}
3623 {\@testpach
3624 % \end{macrocode}
3625 % We provide the current cell type in \cs{ar@cell@type} to pass it
3626 % to the hooks.
3627 % \begin{macrocode}
3628 \edef\ar@cell@type{%
3629 \ifcase\@chnum c\or l\or r\or m\or p\or b\else ?\fi}%
3630 % \end{macrocode}
3631 %
3632 % \begin{macrocode}
3633 \ifcase \@chclass \@classz \or \@classi \or \@classii
3634 \or \save@decl \or \or \@classv \or \@classvi
3635 \or \@classvii \or \@classviii
3636 % \end{macrocode}
3637 % In \texttt{newarray.sty} class 9 is equivalent to class 10.
3638 % \begin{macrocode}
3639 \or \@classx
3640 \or \@classx \fi
3641 \@lastchclass\@chclass}%
3642 \ifcase\@lastchclass
3643 \@acol \or
3644 \or
3645 \@acol \or
3646 \@preamerr \thr@@@@ \or
3647 \@preamerr \tw@ \@addtopreamble\@sharp \or
3648 \or
3649 \else \@preamerr \@ne \fi
3650 \def\the@toks{\the\toks}}
3651 % \end{macrocode}
3652 % \end{macro}
3653 %
3654 %
3655 % \begin{macro}{\ar@cell@type}
3656 % We need a top-level definition for the current cell type, just in
3657 % case some package overwrites \cs{@mkpream} and the runtime
3658 % definition gets lost this way. We make it \texttt{?} which isn't
3659 % a real cell type.
3660 % \begin{macrocode}
3661 \def\ar@cell@type{?}
3662 % \end{macrocode}
3663 % \end{macro}
3664 %
3665 %
3666 %
3667 % \begin{macrocode}
3668 \ExplSyntaxOn
3669 % \end{macrocode}
3670 %
3671 % \begin{macro}[int]{\@classix}
3672 % \texttt{array.sty} does not allow repeated \texttt{>}
3673 % declarations for the same column. This is allowed in
3674 % \texttt{newarray.sty} as documented in the introduction. Removing
3675 % the test for this case makes class 9 equivalent to class 10, and
3676 % so this macro is redundant. It is "\let" to "\relax" to save
3677 % space.
3678 % \begin{macrocode}
3679 \let\@classix\relax
3680 % \end{macrocode}
3681 % \end{macro}
3682 %
3683 % \begin{macro}[int]{\@classviii}
3684 % In \texttt{newarray.sty} explicitly allow class 2, as repeated
3685 % \texttt{<} expressions are accepted by this package.
3686 % \begin{macrocode}
3687 \def\@classviii{\ifnum \@lastchclass >\z@\ifnum\@lastchclass=\tw@\else
3688 \@preamerr 4\@chclass 6 \@classvi \fi\fi}
3689 % \end{macrocode}
3690 % \end{macro}
3691 %
3692 % \begin{macro}[int]{\@classv}
3693 % Class 5 is \texttt{@}-expressions (and is also called by class 1)
3694 % This macro was incorrect in Version~1. Now we do not expand the
3695 % "@"-expression, but instead explicitly replace an
3696 % "\extracolsep" command by an assignment to "\tabskip" by a
3697 % method similar to the "\newcolumntype" system described above.
3698 % "\d@llarbegin" "\d@llarend" were introduced in V2.01 to match
3699 % \texttt{array.sty} 2.0h.
3700 % \begin{macrocode}
3701 \def\@classv{\save@decl
3702 \expandafter\NC@ecs\@nextchar\extracolsep{}\extracolsep\@@@@@@
3703 \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}%
3704 \prepnext@tok}
3705 % \end{macrocode}
3706 % \end{macro}
3707 %
3708 % \begin{macro}[int]{\NC@ecs}
3709 % Rewrite the first occurrence of "\extracolsep{1in}" to
3710 % "\tabskip1in\relax". As a side effect discard any tokens after a
3711 % second "\extracolsep", there is no point in the user entering two of
3712 % these commands anyway, so this is not really a restriction.
3713 % \begin{macrocode}
3714 \def\NC@ecs#1\extracolsep#2#3\extracolsep#4\@@@@@@{\def\@tempa{#2}%
3715 \ifx\@tempa\@empty\else\toks\count@={#1\tabskip#2\relax#3}\fi}
3716 %</ncols>
3717 % \end{macrocode}
3718 % \end{macro}
3719 %
3720 %
3721 % \subsection{Support for the \texttt{delarray.sty}}
3722 %
3723 % The \texttt{delarray.sty} package extends the array syntax by
3724 % supporting the notation of delimiters. To this end we extend the
3725 % array parsing mechanism to include a hook which can be used by this
3726 % (or another) package to do some additional parsing.
3727 %
3728 % \begin{macro}[int]{\@tabarray}
3729 % This macro tests for an optional bracket and then calls up
3730 % "\@@@@array" or "\@@@@array[c]" (as default).
3731 % \begin{macrocode}
3732 %<*package>
3733 \def\@tabarray{\@ifnextchar[{\@@@@array}{\@@@@array[c]}}
3734 % \end{macrocode}
3735 % \end{macro}
3736 % \begin{macro}[int]{\@@@@array}
3737 % This macro tests could then test an optional delimiter before the
3738 % left brace of the main preamble argument. Here in the main package
3739 % it simply is let to be "\@array".
3740 % \begin{macrocode}
3741 \let\@@@@array\@array
3742 % \end{macrocode}
3743 % \end{macro}
3744 %
3745 % \begin{macro}[int]{\@arrrayleft}
3746 % \begin{macro}[int]{\@arrayright}
3747 % We have to declare the hook we put into "\@array" above.
3748 % A similar hook \cs{@arrayright} will be inserted into the
3749 % "\endarray" to gain control. Both defaults to empty.
3750 % \begin{macrocode}
3751 \let\@arrayleft\@empty
3752 \let\@arrayright\@empty
3753 % \end{macrocode}
3754 % \end{macro}
3755 % \end{macro}
3756 %
3757 % \subsection{Support for \texttt{\textbackslash firsthline} and
3758 % \texttt{\textbackslash lasthline}}
3759 %
3760 % The Companion~\cite[p.137]{bk:GMS94} suggests two additional
3761 % commands to control the alignments in case of tabulars with
3762 % horizontal lines. They are now added to this package.
3763 %
3764 % \begin{macro}[no-user-doc]{\extratabsurround}
3765 % The extra space around a table when "\firsthline" or "\lasthline"
3766 % are used.
3767 % \begin{macrocode}
3768 \newlength{\extratabsurround}
3769 \setlength{\extratabsurround}{2pt}
3770 % \end{macrocode}
3771 % \end{macro}
3772 %
3773 % \begin{macro}[int]{\backup@length}
3774 % This register will be used internally by "\firsthline" and
3775 % "\lasthline".
3776 % \begin{macrocode}
3777 \newlength{\backup@length}
3778 % \end{macrocode}
3779 % \end{macro}
3780 %
3781 % \begin{macro}[no-user-doc]{\firsthline}
3782 % \changes{v2.3h}{1996/05/25}{Complete reimplementation}
3783 % This code can probably be improved but for the moment it should
3784 % serve.
3785 %
3786 % We start by producing a single tabular row without any visible
3787 % content that will produce the external reference point in case
3788 % "[t]" is used. We need to suppress the \cs{tabcolsep} in the
3789 % \cs{multicolumn} in case there wasn't any in the real column.
3790 %
3791 % \changes{v2.5c}{2020/07/20}{Suppress all column space (gh/322)}
3792 % \begin{macrocode}
3793 \newcommand{\firsthline}{%
3794 \multicolumn1{@{}c@{}}{%
3795 % \end{macrocode}
3796 % Within this row we calculate "\backup@length" to be the height
3797 % plus depth of a standard line. In addition we have to add the
3798 % width of the "\hline", something that was forgotten in the
3799 % original definition.
3800 % \begin{macrocode}
3801 \global\backup@length\ht\@arstrutbox
3802 \global\advance\backup@length\dp\@arstrutbox
3803 \global\advance\backup@length\arrayrulewidth
3804 % \end{macrocode}
3805 % Finally we do want to make the height of this first line be a bit
3806 % larger than usual, for this we place the standard array strut
3807 % into it but raised by "\extratabsurround"
3808 % \begin{macrocode}
3809 \raise\extratabsurround\copy\@arstrutbox
3810 % \end{macrocode}
3811 % And we should also cancel the guard otherwise we end up with two.
3812 % \begin{macrocode}
3813 \kern-1sp%
3814 % \end{macrocode}
3815 % Having done all this we end the line and back up by the value of
3816 % "\backup@length" and then finally place our "\hline". This should
3817 % place the line exactly at the right place but keep the reference
3818 % point of the whole tabular at the baseline of the first row.
3819 % \begin{macrocode}
3820 }\\[-\backup@length]\hline
3821 }
3822 % \end{macrocode}
3823 % \end{macro}
3824 %
3825 % \begin{macro}[no-user-doc]{\lasthline}
3826 % \changes{v2.3h}{1996/05/25}{Complete reimplementation}
3827 % For "\lasthline" the situation is even worse and I got it
3828 % completely wrong initially.
3829 %
3830 % The problem in this case is that if the optional argument "[b]"
3831 % is used we do want the reference point of the tabular be at the
3832 % baseline of the last row but at the same time do want the
3833 % depth of this last line increased by "\extratabsurround" without
3834 % changing the placement "\hline".
3835 %
3836 % We start by placing the rule followed by an invisible row. We
3837 % need to suppress the \cs{tabcolsep} in the multicol in case there
3838 % wasn't any in the real column.
3839 % \changes{v2.5c}{2020/07/20}{Suppress all column space (gh/322)}
3840 % \begin{macrocode}
3841 \newcommand{\lasthline}{\hline\multicolumn1{@{}c@{}}{%
3842 % \end{macrocode}
3843 % We now calculate "\backup@length" to be the height and depth of
3844 % two lines plus the width of the rule.
3845 % \begin{macrocode}
3846 \global\backup@length2\ht\@arstrutbox
3847 \global\advance\backup@length2\dp\@arstrutbox
3848 \global\advance\backup@length\arrayrulewidth
3849 % \end{macrocode}
3850 % This will bring us back to the baseline of the second last row:
3851 % \begin{macrocode}
3852 }\\[-\backup@length]%
3853 % \end{macrocode}
3854 % Thus if we now add another invisible row the reference point of
3855 % that row will be at the baseline of the last row (and will be the
3856 % reference for the whole tabular). Since this row is invisible we
3857 % can enlarge its depth by the desired amount.
3858 % \begin{macrocode}
3859 \multicolumn1{@{}c@{}}{%
3860 \lower\extratabsurround\copy\@arstrutbox
3861 \kern-1sp%
3862 }%
3863 }
3864 % \end{macrocode}
3865 % \end{macro}
3866 %
3867 %
3868 % \subsection{Getting the spacing around rules right}
3869 %
3870 % Beside a larger functionality \texttt{array.sty} has one
3871 % important difference to the standard \texttt{tabular} and
3872 % \texttt{array} environments: horizontal and vertical rules make a
3873 % table larger or wider, e.g., \verb=\doublerulesep= really denotes
3874 % the space between two rules and isn't measured from the middle of
3875 % the rules.
3876 %
3877 % \begin{macro}[int]{\@xhline}
3878 % For vertical rules this is implemented by the definitions above,
3879 % for horizontal rules we have to take out the backspace.
3880 % \changes{v2.3d}{1995/11/19}{fix space between double rules pr/1945}
3881 % \begin{macrocode}
3882 \CheckCommand*\@xhline{\ifx\reserved@a\hline
3883 \vskip\doublerulesep
3884 \vskip-\arrayrulewidth
3885 \fi
3886 \ifnum0=`{\fi}}
3887 \renewcommand*\@xhline{\ifx\reserved@a\hline
3888 \vskip\doublerulesep
3889 \fi
3890 \ifnum0=`{\fi}}
3891 %</package>
3892 % \end{macrocode}
3893 % \end{macro}
3894
3895 % \subsection{Implementing column types \texttt{w} and \texttt{W}}
3896 %
3897 % In TugBoat 38/2 an extension was presented that implemented two
3898 % additional column types \texttt{w} and \texttt{W}. These have now
3899 % been added to the package itself.
3900 %
3901 %
3902 % \begin{macro}[int]{\ar@cellbox}
3903 % For \texttt{w} and \texttt{W} column types we need a box to
3904 % temporarily hold the cell content.
3905 % \changes{v2.4f}{2017/11/07}{Macro added}
3906 % \begin{macrocode}
3907 \newsavebox\ar@cellbox
3908 % \end{macrocode}
3909 % \end{macro}
3910 %
3911 %
3912 % \begin{macro}[no-user-doc]{\newcolumntype w}
3913 % The \texttt{w} column type has two arguments: the first holds the
3914 % alignment which is either "l", "c", or "r" and the second is the
3915 % nominal width of the column.
3916 % \changes{v2.4f}{2017/11/07}{Column type added}
3917 % \changes{v2.5a}{2020/04/06}{Use \cs{d@llarbegin} and \cs{d@llarend} so
3918 % that cell is typeset in math mode inside \texttt{array} (gh/297)}
3919 % \begin{macrocode}
3920 \newcolumntype{w}[2]{%
3921 % \end{macrocode}
3922 % Before the cell content we start an "lrbox"-environment to
3923 % collect the cell material into the previously allocated box
3924 % "\ar@cellbox". We add \cs{d@llarbegin} (and later \cs{d@llarend})
3925 % so that the content is typeset in math mode if we are in an
3926 % \texttt{array} environment.
3927 % \begin{macrocode}
3928 >{\begin{lrbox}\ar@cellbox\d@llarbegin}%
3929 % \end{macrocode}
3930 % Then comes a specifier for the cell content. We use "c", but
3931 % that doesn't matter as in the end we will always put a box of a
3932 % specific width ("#2") into the cells of that column, so "l" or
3933 % "r" would give the same result. There is only a difference if
3934 % there are also very wide "\multicolumn" rows overwriting the
3935 % setting in which case "c" seems to be slightly better.
3936 % \begin{macrocode}
3937 c%
3938 % \end{macrocode}
3939 % At the end of the cell we end the "lrbox" environment so that all
3940 % of the cell content is now in box "\ar@cellbox". As a final step we
3941 % put that box into a "\makebox" using the optional arguments of
3942 % that command to achieve the correct width and the desired
3943 % alignment within that width. We unbox the collected material so
3944 % that any stretchable glue inside can interact with the alignment.
3945 % \changes{v2.4m}{2020/02/10}{Unbox collected material so that
3946 % stretchable glue inside can act (gh/270)}
3947 % \begin{macrocode}
3948 <{\d@llarend \end{lrbox}%
3949 \makebox[#2][#1]{\unhbox\ar@cellbox}}}
3950 % \end{macrocode}
3951 % \end{macro}
3952
3953 %
3954 %
3955 % \begin{macro}[no-user-doc]{\newcolumntype W}
3956 % The \texttt{W} is similar but in this case we want a warning if
3957 % the cell content is too wide.
3958 % \changes{v2.4f}{2017/11/07}{Column type added}
3959 % \changes{v2.5a}{2020/04/06}{Use \cs{d@llarbegin} and \cs{d@llarend} so
3960 % that cell is typeset in math mode inside \texttt{array} (gh/297)}
3961 % \begin{macrocode}
3962 \newcolumntype{W}[2]
3963 {>{\begin{lrbox}\ar@cellbox\d@llarbegin}%
3964 c%
3965 <{\d@llarend\end{lrbox}%
3966 \let\hss\hfil
3967 \makebox[#2][#1]{\unhbox\ar@cellbox}}}
3968 % \end{macrocode}
3969 % This is a bit sneaky, as it temporarily disables "\hss", but
3970 % given that we know what goes into that box it should be
3971 % sufficient.
3972 % \end{macro}
3973 %
3974 %
3975 % \subsection{Handling \cs{cline}}
3976 %
3977 % In the past \pkg{array} did not have to concern itself with
3978 % \cs{cline} but simply used the definition already provided in the
3979 % kernel. However, for tagged PDF output this definition is
3980 % insufficient, because it causes incorrect row counting and the rules
3981 % it generates would need to be marked as artifacts.
3982 % We therefore update it here.
3983 %
3984 %
3985 % \begin{macro}[int]{\@cline}
3986 % Tagging support for \cs{cline}
3987 % \changes{v2.6e}{2024/07/13}{Support for tagging \cs{cline} (tagging/134)}
3988 % \begin{macrocode}
3989 \ExplSyntaxOn
3990 \def\@cline#1-#2\@nil{
3991 \omit
3992 \@multicnt#1
3993 \advance\@multispan\m@ne
3994 \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
3995 \@multicnt#2
3996 \advance\@multicnt-#1
3997 \advance\@multispan\@ne
3998 % \end{macrocode}
3999 % The rule needs artifact tagging in tagged PDF.
4000 % \begin{macrocode}
4001 \UseTaggingSocket{tbl/leaders/begin}
4002 \leaders\hrule\@height\arrayrulewidth\hfill
4003 \UseTaggingSocket{tbl/leaders/end}
4004 % \end{macrocode}
4005 % To the row counting the above appears like an extra row, so we
4006 % have to correct the count.
4007 % \begin{macrocode}
4008 \tbl_gdecr_row_count:
4009 \cr
4010 \noalign{\vskip-\arrayrulewidth}
4011 }
4012 \ExplSyntaxOff
4013 % \end{macrocode}
4014 % \end{macro}
4015 %
4016 %
4017 % \begin{macrocode}
4018 \ExplSyntaxOff
4019 % \end{macrocode}
4020 %
4021 %
4022 % \PrintIndex
4023 % \PrintChanges
4024 %
4025 % \Finale
4026 %
4027 \endinput