Move a tag
[latex2e.git] / latex2e-20151001 / required / tools / array.dtx
blobd869ca48fbf036465a70a4423a4fe9c78b4b4b96
1 % \iffalse meta-comment
3 % Copyright 1993-2014
5 % The LaTeX3 Project and any individual authors listed elsewhere
6 % in this file.
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
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 %    http://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.
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
22 % \fi
23 %\iffalse   % this is a METACOMMENT !
25 %% Package `array' to use with LaTeX 2e
26 %% Copyright (C) 1989-1998 Frank Mittelbach, all rights reserved.
27 %<+package>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
28 %<+package>\ProvidesPackage{array}
29 %<+package>         [2014/10/28 v2.4c Tabular extension package (FMi)]
31 % \fi
33 % \CheckSum{1115}
34 %% \CharacterTable
35 %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
36 %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
37 %%   Digits        \0\1\2\3\4\5\6\7\8\9
38 %%   Exclamation   \!     Double quote  \"     Hash (number) \#
39 %%   Dollar        \$     Percent       \%     Ampersand     \&
40 %%   Acute accent  \'     Left paren    \(     Right paren   \)
41 %%   Asterisk      \*     Plus          \+     Comma         \,
42 %%   Minus         \-     Point         \.     Solidus       \/
43 %%   Colon         \:     Semicolon     \;     Less than     \<
44 %%   Equals        \=     Greater than  \>     Question mark \?
45 %%   Commercial at \@     Left bracket  \[     Backslash     \\
46 %%   Right bracket \]     Circumflex    \^     Underscore    \_
47 %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
48 %%   Right brace   \}     Tilde         \~}
52 % \changes{v2.4c}{2008/09/09}{(WR) Typo fix in documentation}
54 % \changes{v2.3c}{1995/11/02}{(DPC) minor doc changes}
56 % \changes{v2.3a}{1994/10/16}{Added code for \cs{firsthline} and
57 %                             friends}
59 % \changes{v2.2c}{1994/03/14}{removed check for \cs{@tfor} bug}
61 % \changes{v1.0b}{1987/06/04}{`@classi (faster),
62 %                        `@classvi (new)   A in preamble means
63 %                                         \&\& in `halign.}
65 % \changes{v1.1a}{1987/07/05}{New concept:
66 %                        preamblechar: c,l,r,C,L,R,A,p,t,{\tt !|},@,!!}
67 % \changes{v1.1b}{1987/09/21}{Again p like original \LaTeX{} and z for
68 %                        centered `parbox.}
70 % \changes{v1.2a}{1987/09/27}{Completely new implementation.}
71 % \changes{v1.2b}{1987/10/06}{{\tt !|} does no longer generate space at
72 %                        start or end of the preamble. Otherwise `hline
73 %                        is too long.}
74 % \changes{v1.2b}{1987/10/06}{Enlarged `@arstrutbox by 1pt (Test-Impl)
75 %                         with dimen `@strutheight.}
76 % \changes{v1.2c}{1987/10/22}{New dimen parameter `extrarowheight
77 %                        (default: 0pt).}
78 % \changes{v1.2c}{1987/10/22}{Enlarged `@arstrutbox by `extrarowheight.
79 %                        Thus you may avoid large characters to
80 %                        overprint a `hline.}
81 % \changes{v1.2c}{1987/10/22}{Introduced `m@th in `@array to allow
82 %                         non-zero values of `mathsurround.}
83 % \changes{v1.2d}{1987/11/02}{Completed the documentation.}
84 % \changes{v1.2e}{1987/11/03}{Bug fixed: A at start of preamble resulted
85 %                        in an error since `@mkpream generated
86 %                        `@arstrut \& ... as a preamble.}
87 % \changes{v1.2f}{1987/11/09}{`@testpach documented.}
89 % \changes{v1.3a}{1987/11/11}{Again a new implementation, with a new
90 %                        concept (cf. the documentation).}
91 % \changes{v1.3b}{1988/03/17}{`@decl expands now into `@empty, i.e., it
92 %                        disappears when the preamble is generated,
93 %                        except when the user specifies A\{\} or
94 %                        B\{\}.}
96 % \changes{v1.4a}{1988/03/18}{Test implementation of use of token
97 %                        registers in order to do without `protect.}
98 % \changes{v1.4b}{1988/03/19}{Changed erroneous class numbers:
99 %                        5 -!> 6
100 %                        6 -!> 7
101 %                        7 -!> 5
102 %                        Corresponding changes in the macros.}
103 % \changes{v1.4c}{1988/03/19}{Everything except p,z now works with token
104 %                        registers.}
106 % \changes{v1.9a}{1988/03/20}{Last (so I hope) major change: 1) Options
107 %                        B,A now called !>,<.  These options now point
108 %                        to the column they modify.}
109 % \changes{v1.9a}{1988/03/20}{2) `protect is no longer necessary. But
110 %                           still the macro `@expast needs top be
111 %                          modified. `multicolumn still does not work.}
112 % \changes{v1.9b}{1988/04/29}{inserted missing `fi in `@testpach.
113 %                        Corrected \LaTeX bug in `@tfor.}
114 % \changes{v1.9c}{1988/05/07}{Re-introduced `@endpbox.
115 %                        `multicolumn now works!! Version number still
116 %                        1.9 since the documentation is still not
117 %                        finished.}
118 % \changes{v1.9c}{1988/05/07}{1) `def `the@toks \{`the ...\} remaining
119 %                         only in `@mkpream.  2) Removed `@classiii and
120 %                        replaced by `save@decl.}
121 % \changes{v1.9c}{1988/05/07}{3) `insert@column contains only `@tempcnta
122 %                        and `count@ counters.  4) `@@startpbox and
123 %                        `@@endpbox now totally obsolete.}
124 % \changes{v1.9d}{1988/05/10}{Replaced `number by `the where the `toks
125 %                        registers' contents are used.}
126 % \changes{v1.9e}{1988/05/11}{Re-introduced `@xargarraycr and
127 %                        `@yargarraycr, since `endtemplate seems to
128 %                        be `outer.}
129 % \changes{v1.9f}{1988/05/20}{Small changes finally carried out:
130 %                        1) `par!=`@empty.
131 %                        2) \{..ifnum0!=!`\}...  $\to$ `bgroup and
132 %                           analogously `egroup.}
133 % \changes{v1.9g}{1988/02/24}{Inserted again \{..ifnum0!=!`\}..,
134 %                        c.f. Appendix D of the \protect\TeX{}book.}
135 % \changes{v1.9h}{1988/06/28}{No longer necessary to read in the file
136 %                        twice.}
137 % \changes{v1.9i}{1988/06/28}{Corrected typo in german version.}
138 % \changes{v1.9j}{1988/11/23}{In a `r' column an extra `kern`z@ is
139 %                        needed.}
140 % \changes{v1.9j}{1988/11/23}{Otherwise the `hfil on the left side
141 %                        will be removed by the `unskip in
142 %                        `insert@column if the entry is empty.}
143 % \changes{v1.9k}{1988/06/28}{Corrected typo in german version.}
144 % \changes{v1.9k}{1989/01/16}{`begin{Macro} changed to `begin{macro} in
145 %                        documentation.}
147 % \changes{v2.0a}{1989/05/12}{{\tt\textbackslash @thetoks} changed to
148 %                          {\tt\textbackslash the@toks}.}
149 % \changes{v2.0a}{1989/05/12}{source changed to reflect new doc.sty
150 %                          conventions.}
151 % \changes{v2.0a}{1989/05/12}{t option renamed to p to be compatible to
152 %                        the original.}
153 % \changes{v2.0a}{1989/05/12}{File renamed from arraye.sty to
154 %                        array.sty.}
155 % \changes{v2.0b}{1989/05/17}{Three forgotten end macro added.}
156 % \changes{v2.0b}{1989/05/17}{All lines shortened to 72 or less.}
157 % \changes{v2.2a}{1994/02/03}{Upgrade to \LaTeXe}
159 % \DoNotIndex{\@depth,\@ehc,\@fortmp,\@height,\@ifnextchar,\@ifstar}
160 % \DoNotIndex{\@ifundefined,\@ne,\@nil,\@tempa,\@tempb}
161 % \DoNotIndex{\@tempcnta,\@tempd,\@tempdima,\@whilenum,\@width,\\}
162 % \DoNotIndex{\@tforloop}
163 % \DoNotIndex{\advance}
164 % \DoNotIndex{\baselineskip,\begingroup,\bgroup}
165 % \DoNotIndex{\cr,\crcr,\csname}
166 % \DoNotIndex{\def,\do,\docdate,\dp}
167 % \DoNotIndex{\edef,\egroup,\else,\endcsname,\endinput,\expandafter}
168 % \DoNotIndex{\fi,\filedate,\fileversion}
169 % \DoNotIndex{\gdef}
170 % \DoNotIndex{\hbox,\hfil,\hsize,\hskip,\ht}
171 % \DoNotIndex{\if,\ifcase,\ifdim,\ifnum,\ifx,\ignorespaces}
172 % \DoNotIndex{\kern}
173 % \DoNotIndex{\leavevmode,\let,\lineskip}
174 % \DoNotIndex{\m@ne,\multispan}
175 % \DoNotIndex{\newcount,\newdimen,\noalign}
176 % \DoNotIndex{\or}
177 % \DoNotIndex{\relax}
178 % \DoNotIndex{\setbox,\space,\strutbox}
179 % \DoNotIndex{\tabskip,\thr@@,\the,\toks,\toks@,\tw@,\typeout}
180 % \DoNotIndex{\unhcopy,\unskip}
181 % \DoNotIndex{\vbox,\vcenter,\vline,\vrule,\vtop,\vskip}
182 % \DoNotIndex{\xdef}
183 % \DoNotIndex{\z@}
185 % \GetFileInfo{array.sty}
187 % \title{A new implementation of \LaTeX's \textsf{tabular}
188 %        and \textsf{array} environment\thanks{This file
189 %        has version number \fileversion, last
190 %        revised \filedate.}}
191 % \author{Frank Mittelbach
192 %         \and
193 %         David Carlisle\thanks{David kindly agreed on the inclusion
194 %         of the \texttt{\textbackslash{}newcolumntype} implementation,
195 %         formerly in
196 %         \texttt{newarray.sty} into this package }}
198 % \date{Printed \today}
200 % \MaintainedByLaTeXTeam{tools}
201 % \maketitle
203 % \MakeShortVerb{\=}
205 % \begin{abstract}
206 % This article describes an extended implementation of the \LaTeX\
207 % \textsf{array}-- and \textsf{tabular}--environments. The special
208 % merits of this implementation are further options to format columns
209 % and the fact that fragile \LaTeX--commands don't have to be
210 % =\protect='ed any more within those environments.
212 % The major part of the code for this package dates back to 1988---so
213 % does some of its documentation.
214 % \end{abstract}
218 % \section{Introduction}
220 % This new implementation of the \textsf{array}-- and
221 % \textsf{tabular}--environments is part of a larger project in which
222 % we are trying to improve the \LaTeX\--code in some aspects and to
223 % make \LaTeX\ even easier to handle.
225 % The reader should be familiar with the general structure of the
226 % environments
227 % mentioned above. Further information can be found in
228 % \cite{bk:lamport} and \cite{bk:GMS94}.
229 % The additional options which can be used in the
230 % preamble as well as those which now have a slightly different meaning
231 % are described in table~\ref{tab:opt}.
233 % \DescribeMacro\extrarowheight
234 % Additionally we introduce a new
235 % parameter called =\extrarowheight=. If it takes a positive
236 % length, the value of the parameter is added to the normal height of
237 % every row of the table, while
238 % the depth will remain the same. This is important for tables
239 % with horizontal lines because those lines normally touch the
240 % capital letters.
241 % For example, we used =\setlength{\extrarowheight}{1pt}=
242 % in table~\ref{tab:opt}.
244 % \begin{table}[t]
245 % \begin{center}
246 %    \setlength{\extrarowheight}{1pt}
247 %    \begin{tabular}{|>{\tt}c|m{9cm}|}
248 %       \hline
249 %     \multicolumn{2}{|c|}{Unchanged options}\\
250 %       \hline
251 %       l             &  Left adjusted column. \\
252 %       c             &  Centered adjusted column. \\
253 %       r             &  Right adjusted column. \\
254 %       p\{width\}    &  Equivalent to =\parbox[t]{width}=. \\
255 %       @\{decl.\}    &  Suppresses inter-column space and inserts
256 %                        \texttt{decl.}\ instead. \\
257 %       \hline
258 %     \multicolumn{2}{|c|}{New options}\\
259 %       \hline
260 %       m\{width\}    &  Defines a column of width \texttt{width}.
261 %                        Every entry will be centered in proportion to
262 %                        the rest of the line. It is somewhat like
263 %                        =\parbox{width}=. \\
264 %       \hline
265 %       b\{width\}    &  Coincides with =\parbox[b]{width}=. \\
266 %       \hline
267 %       >\{decl.\}    &  Can be used before an \texttt{l}, \texttt{r},
268 %                        \texttt{c}, \texttt{p}, \texttt{m} or a
269 %                        \texttt{b} option. It inserts \texttt{decl.}\
270 %                        directly in front of the entry of the column.
271 %                        \\
272 %       \hline
273 %       <\{decl.\}    &  Can be used after an \texttt{l}, \texttt{r},
274 %                        \texttt{c}, =p{..}=, =m{..}= or a =b{..}=
275 %                        option.  It inserts \texttt{decl.}\ right
276 %                        after the entry of the column.  \\
277 %       \hline
278 %       |             &  Inserts a vertical line. The distance between
279 %                        two columns will be enlarged by the width of
280 %                        the line
281 %                        in contrast to the original definition of
282 %                        \LaTeX.  \\
283 %       \hline
284 %       !\{decl.\}    &  Can be used anywhere and corresponds with the
285 %                        \texttt{|} option. The difference is that
286 %                        \texttt{decl.} is inserted instead of a
287 %                        vertical line, so this option doesn't
288 %                        suppress the normally inserted space between
289 %                        columns in contrast to =@{...}=.\\
290 %       \hline
291 %    \end{tabular}
292 % \end{center}
293 % \caption{The  preamble options.} \label{tab:opt}
294 % \end{table}
297 % We will discuss a few examples using the new preamble options before
298 % dealing with the implementation.
299 % \begin{itemize}
300 %    \item
301 %       If you want to use a special font (for example =\bfseries=) in a
302 %       flushed left column, this can be done with =>{\bfseries}l=. You
303 %       do not have to begin every entry of the column with  =\bfseries=
304 %       any more.
305 %    \item
306 %       In columns which have been generated with \texttt{p}, \texttt{m}
307 %       or \texttt{b}, the default value of =\parindent= is
308 %       \textsf{0pt}.
309 %       This can be changed with \\
310 %       =>{\setlength{\parindent}{1cm}}p=.
311 %    \item
312 %       The \texttt{>}-- and \texttt{<}--options were originally
313 %       developed for the following application:
314 %       =>{$}c<{$}= generates a column in math
315 %       mode in a \textsf{tabular}--environment. If you use this type
316 %       of a preamble in an \textsf{array}--environment, you get a
317 %       column in LR mode because the additional \$'s cancel the
318 %       existing \$'s.
319 %    \item
320 %       One can also think of more complex applications. A problem
321 %       which has
322 %       been mentioned several times in \TeX{}hax can be solved with
323 %       =>{\centerdots}c=\linebreak[0]=<{\endcenterdots}=.
324 %       To center decimals at their
325 %       decimal points you (only?) have to define the following macros:
326 %       \begin{verbatim}
327 %{\catcode`\.\active\gdef.{\egroup\setbox2\hbox\bgroup}}
328 %\def\centerdots{\catcode`\.\active\setbox0\hbox\bgroup}
329 %\def\endcenterdots{\egroup\ifvoid2 \setbox2\hbox{0}\fi
330 %   \ifdim \wd0>\wd2 \setbox2\hbox to\wd0{\unhbox2\hfill}\else
331 %     \setbox0\hbox to\wd2{\hfill\unhbox0}\fi
332 %   \catcode`\.12 \box0.\box2}
333 %\end{verbatim}
334 %      Warning: The code is bad, it doesn't work with more than one
335 %      dot in a cell and doesn't work when the tabular is used in the
336 %      argument of some other command. A much better version is
337 %      provided in the \texttt{dcolumn.sty} by David Carlisle.
338 %    \item
339 %       Using =c!{\hspace{1cm}}c= you get space between two
340 %       columns which is enlarged by one centimeter, while
341 %       =c@{\hspace{1cm}}c= gives you exactly one centimeter
342 %       space between two columns.
343 % \end{itemize}
345 % \subsection{Defining new column specifiers}
347 % \DeleteShortVerb{\=}
348 % \MakeShortVerb{\"}
349 % \DescribeMacro{\newcolumntype}
350 % Whilst it is handy to be able to type
351 % \begin{quote}
352 %   ">{"\meta{some declarations}"}{c}<{"\meta{some more
353 %   declarations}"}"
354 % \end{quote}
355 % if you have a one-off column in a table, it is rather inconvenient
356 % if you often use columns of this form. The new version allows you
357 % to define a new column specifier, say \texttt{x}, which will expand to
358 % the primitives column specifiers.\footnote{This command was named
359 % \texttt{\textbackslash{}newcolumn} in the \texttt{newarray.sty}.
360 % At the moment \texttt{\textbackslash{}newcolumn} is still supported
361 % (but gives a warning). In later releases it will vanish.} Thus we
362 % may define
363 % \begin{quote}
364 %   "\newcolumntype{x}{>{"\meta{some declarations}"}{c}<{"\meta{some
365 %   more declarations}"}}"\hspace*{-3cm} ^^A no overfull from this line
366 % \end{quote}
367 % One can then use the \texttt{x} column specifier in the preamble
368 % arguments of all \texttt{array} or \texttt{tabular} environments in
369 % which you want columns of this form.
371 % It is common  to need math-mode and LR-mode columns in the same
372 % alignment. If we define:
373 % \begin{quote}
374 %   "\newcolumntype{C}{>{$}c<{$}}" \\
375 %   "\newcolumntype{L}{>{$}l<{$}}" \\
376 %   "\newcolumntype{R}{>{$}r<{$}}"
377 % \end{quote}
378 % Then we can use \texttt{C} to get centred LR-mode in an
379 % \texttt{array}, or centred math-mode in a \texttt{tabular}.
381 % The example given above for `centred decimal points' could be
382 % assigned to a \texttt{d} specifier with the following command.
383 % \begin{quote}
384 % "\newcolumntype{d}{>{\centerdots}c<{\endcenterdots}}"
385 % \end{quote}
387 % The above solution always centres the dot in the
388 % column. This does not look too good if the column consists of large
389 % numbers, but to only a few decimal places. An alternative definition
390 % of a \texttt{d} column is
391 % \begin{quote}
392 %   "\newcolumntype{d}[1]{>{\rightdots{#1}}r<{\endrightdots}}"
393 % \end{quote}
394 % where the appropriate macros in this case are:\footnote{The package
395 % \texttt{dcolumn.sty} contains more robust macros based on these
396 % ideas.}
397 % \begin{verbatim}
398 %   \def\coldot{.}% Or if you prefer, \def\coldot{\cdot}
399 %   {\catcode`\.=\active
400 %     \gdef.{$\egroup\setbox2=\hbox to \dimen0 \bgroup$\coldot}}
401 %   \def\rightdots#1{%
402 %     \setbox0=\hbox{$1$}\dimen0=#1\wd0
403 %     \setbox0=\hbox{$\coldot$}\advance\dimen0 \wd0
404 %     \setbox2=\hbox to \dimen0 {}%
405 %     \setbox0=\hbox\bgroup\mathcode`\.="8000 $}
406 %   \def\endrightdots{$\hfil\egroup\box0\box2}
407 %\end{verbatim}
408 % Note that "\newcolumntype" takes the same optional argument as
409 % "\newcommand" which declares the number of arguments of the column
410 % specifier being defined. Now we can specify "d{2}" in our preamble
411 % for a column of figures to at most two decimal places.
413 % A rather different use of the "\newcolumntype" system takes
414 % advantage of the fact that the replacement text in the
415 % "\newcolumntype" command may refer to more than one column. Suppose
416 % that a document contains a lot of \texttt{tabular} environments that
417 % require the same preamble, but you wish to experiment with different
418 % preambles. Lamport's original definition allowed you to do the
419 % following (although it was probably a mis-use of the system).
420 % \begin{quote}
421 %   "\newcommand{\X}{clr}"\\
422 %   "\begin{tabular}{\X}" \ldots
423 % \end{quote}
424 % \texttt{array.sty} takes great care \textbf{not} to expand the
425 % preamble, and so the above does not work with the new scheme. With
426 % the new version this functionality is returned:
427 % \begin{quote}
428 % "\newcolumntype{X}{clr}"\\
429 % "\begin{tabular}{X}" \ldots
430 % \end{quote}
432 % The replacement text in a "\newcolumntype" command may refer to any of
433 % the primitives of \texttt{array.sty} see table \ref{tab:opt} on page
434 % \pageref{tab:opt}, or to any new letters defined in other
435 % "\newcolumntype" commands.
438 % \DescribeMacro{\showcols}A list of all the currently active
439 % "\newcolumntype" definitions is sent to the terminal and log file if
440 % the "\showcols" command is given.
443 % \subsection{Special variations of \texttt{\textbackslash hline}}
445 % The family of \texttt{tabular} environments allows
446 % vertical positioning with respect to the baseline of
447 % the text in which the environment appears.  By default the
448 % environment appears centered, but this can be changed to
449 % align with the first or last line in the environment by
450 % supplying a \texttt{t} or \texttt{b} value to the
451 % optional position argument. However, this does not work
452 % when the first or last element in the environment is a
453 % "\hline" command---in that case the environment is
454 % aligned at the horizontal rule.
456 % \pagebreak[3]
458 % Here is an example:
459 % \begin{center}
460 % \begin{minipage}[t]{.4\linewidth}
461 % Tables
462 % \begin{tabular}[t]{l}
463 %   with no\\ hline \\ commands \\ used
464 % \end{tabular} versus \\ tables
465 % \begin{tabular}[t]{|l|}
466 %  \hline
467 %   with some \\ hline \\ commands \\
468 %  \hline
469 % \end{tabular} used.
470 % \end{minipage}
471 % \begin{minipage}[t]{.5\linewidth}
472 % \begin{verbatim}
473 % Tables
474 % \begin{tabular}[t]{l}
475 %  with no\\ hline \\ commands \\ used
476 % \end{tabular} versus tables
477 % \begin{tabular}[t]{|l|}
478 %  \hline
479 %   with some \\ hline \\ commands \\
480 %  \hline
481 % \end{tabular} used.
482 % \end{verbatim}
483 % \end{minipage}
484 % \end{center}
486 % \DescribeMacro\firsthline
487 % \DescribeMacro\lasthline
488 % Using "\firsthline" and "\lasthline" will
489 % cure the problem, and the tables will align properly as long
490 % as their first or last line does not contain extremely large
491 % objects.
492 % \begin{center}
493 % \begin{minipage}[t]{.4\linewidth}
494 % Tables
495 % \begin{tabular}[t]{l}
496 %   with no\\ line \\ commands \\ used
497 % \end{tabular} versus \\ tables
498 % \begin{tabular}[t]{|l|}
499 %  \firsthline
500 %   with some \\ line   \\ commands \\
501 %  \lasthline
502 % \end{tabular} used.
503 % \end{minipage}
504 % \begin{minipage}[t]{.5\linewidth}
505 % \begin{verbatim}
506 % Tables
507 % \begin{tabular}[t]{l}
508 %   with no\\ line \\ commands \\ used
509 % \end{tabular} versus tables
510 % \begin{tabular}[t]{|l|}
511 %  \firsthline
512 %   with some \\ line   \\ commands \\
513 %  \lasthline
514 % \end{tabular} used.
515 % \end{verbatim}
516 % \end{minipage}
517 % \end{center}
518 % \DescribeMacro\extratabsurround
519 % The implementation of these two commands contains an extra
520 % dimension, which is called "\extratabsurround", to add some
521 % additional space at the top and the bottom of such an environment.
522 % This is useful if such tables are nested.
524 % \section{Final Comments}
526 % \subsection{Handling of rules}
528 % There are two possible approaches to the handling of horizontal and
529 % vertical rules in tables:
530 % \begin{enumerate}
531 %   \item rules can be placed into the available space without
532 %   enlarging the table, or
533 %   \item rules can be placed between columns or rows thereby enlarging
534 %   the table.
535 % \end{enumerate}
536 % \texttt{array.sty} implements the second possibility while the
537 % default implementation in the \LaTeX{} kernel implements the first
538 % concept. Both concepts have their merits but one has to be aware of
539 % the individual implications.
540 % \begin{itemize}
541 % \item
542 %   With standard \LaTeX{} adding rules to a table will not affect the
543 %   width or height of the table (unless double rules are used), e.g.,
544 %   changing a preamble from \verb=lll= to \verb=l|l|l= does not
545 %   affect the document other than adding rules to the table. In
546 %   contrast, with \texttt{array.sty} a table that just fit the
547 %   \verb=\textwidth= might now produce an overfull box.
548 % \item
549 %   With standard \LaTeX{} modifying the width of rules could result
550 %   in ugly looking tables because without adjusting the
551 %   \verb=\tabcolsep=, etc.\ the space between rule and column could
552 %   get too small (or too large). In fact even overprinting of text is
553 %   possible. In contrast, with  \texttt{array.sty} modifying any such
554 %   length usually works well as the actual visual white space (from
555 %   \verb=\tabcolsep=, etc.) does not depend on the width of the
556 %   rules.
557 % \item
558 %   With standard \LaTeX{} boxed tabulars actually have strange
559 %   corners because the horizontal rules end in the middle of the
560 %   vertical ones. This looks very unpleasant when a large
561 %   \verb=\arrayrulewidth= is chosen. In that case a simple table like
562 %\begin{verbatim}
563 %\setlength{\arrayrulewidth}{5pt}
564 %\begin{tabular}{|l|}
565 %  \hline  A \\  \hline
566 %\end{tabular}
567 %\end{verbatim}
568 %   will produce something like
569 %   \begin{center}
570 %\setlength{\arrayrulewidth}{5pt}
571 %\begin{tabular}{@{}l@{}}
572 %  \hline  \null\hskip-.5\arrayrulewidth\vline
573 %  \hskip\tabcolsep
574 %   A\hskip\tabcolsep
575 %  \vline\hskip-.5\arrayrulewidth\null \\  \hline
576 %\end{tabular}
577 %   \quad
578 %   instead of
579 %   \quad
580 %\begin{tabular}{|l|}
581 %  \hline  A \\  \hline
582 %\end{tabular}
583 %   \end{center}
584 % \end{itemize}
586 % \subsection{Comparisons with older versions of \texttt{array.sty}}
588 % There are some differences in the way version 2.1 treats incorrect
589 % input, even if the source file does not appear to use any of the
590 % extra features of the new version.
591 % \begin{itemize}
592 % \item A preamble of the form "{wx*{0}{abc}yz}" was treated by
593 % versions prior to 2.1 as "{wx}". Version 2.1 treats it as "{wxyz}"
594 % \item An incorrect positional argument such as \texttt{[Q]} was
595 % treated as \texttt{[c]} by \texttt{array.sty}, but is now treated as
596 % \texttt{[t]}.
597 % \item A preamble such as "{cc*{2}}" with an error in
598 % a $*$-form will generate different errors in the new version. In
599 % both cases the error message is not particularly helpful to the
600 % casual user.
601 % \item Repeated \texttt{<} or \texttt{>} constructions
602 % generated an error in earlier versions, but are now allowed in
603 % this package.  ">{"\meta{decs1}"}>{"\meta{decs2}"}" is treated the
604 % same as ">{"\meta{decs2}\meta{decs1}"}".
605 % \item The "\extracolsep"
606 % command does not work with the old versions of \texttt{array.sty},
607 % see the comments in \texttt{array.bug}. With version 2.1
608 % "\extracolsep" may again be used in \texttt{@}-expressions as in
609 % standard \LaTeX, and also in \texttt{!}-expressions (but see the
610 % note below).
611 % \end{itemize}
614 % \subsection{Bugs and Features}
616 % \begin{itemize}
617 % \item Error messages generated when parsing the column specification
618 %   refer to the preamble argument \textbf{after} it has been re-written
619 %   by the "\newcolumntype" system, not to the preamble entered by the
620 %   user.  This seems inevitable with any system based on
621 %   pre-processing and so is classed as a \textbf{feature}.
623 % \item The treatment of multiple \texttt{<} or \texttt{>}
624 %   declarations may seem strange at first. Earlier implementations
625 %   treated ">{"\meta{decs1}"}>{"\meta{decs2}"}" the same as
626 %   ">{"\meta{decs1}\meta{decs2}"}". However this did not give the
627 %   user the opportunity of overriding the settings of a
628 %   "\newcolumntype" defined using these declarations. For example,
629 %   suppose in an \texttt{array} environment we use a \texttt{C}
630 %   column defined as above. The \texttt{C} specifies a centred text
631 %   column, however ">{\bfseries}C", which re-writes to
632 %   ">{\bfseries}>{$}c<{$}" would not specify a bold column as might
633 %   be expected, as the preamble would essentially expand to
634 %   "\hfil$\bfseries$#$ $\hfil" and so the column entry would not be in the
635 %   scope of the "\bfseries"\,! The present version switches the order
636 %   of repeated declarations, and so the above example now produces a
637 %   preamble of the form "\hfil$" "$\bfseries#$" "$\hfil", and the
638 %   dollars cancel each other out without limiting the scope of the
639 %   "\bfseries".
641 % \item The use of "\extracolsep" has been subject to the following
642 %   two restrictions.  There must be at most one "\extracolsep"
643 %   command per "@", or "!" expression and the command must be
644 %   directly entered into the "@" expression, not as part of a macro
645 %   definition. Thus "\newcommand{\ef}{\extracolsep{\fill}}" \ldots
646 %   "@{\ef}" does not work with this package. However you can use
647 %   something like
648 %   "\newcolumntype{e}{@{\extracolsep{\fill}}" instead.
650 % \item As noted by the \LaTeX{} book, for the purpose of
651 %   "\multicolumn" each column with the exception of the first one
652 %   consists of the entry and the \emph{following} inter-column
653 %   material. This means that in a tabular with the preamble
654 %   "|l|l|l|l|" input such as "\multicolumn{2}{|c|}" in
655 %   anything other than the first column is incorrect.
657 %   In the standard array/tabular implementation this error is not so
658 %   noticeable as that version contains negative spacing so that each
659 %   "|" takes up no horizontal space. But since in this package the
660 %   vertical lines take up their natural width one sees two lines if
661 %   two are specified.
663 % \end{itemize}
667 % \changes{v2.2b}{1994/02/04}{Removed interactive prompt}
669 % \StopEventually{
672 % \begin{thebibliography}{1}
673 %    \bibitem{bk:GMS94} \textsc{M.~Goossens}, \textsc{F.~Mittelbach}
674 %       and \textsc{A.~Samarin}.
675 %       \newblock The \LaTeX{} Companion.
676 %       \newblock
677 %       Addison-Wesley, Reading, Massachusetts, 1994.
678 %    \bibitem{bk:knuth}  \textsc{D. E. Knuth}.
679 %       \newblock  The \TeX{}book (Computers \& Typesetting Volume A).
680 %       \newblock
681 %       Addison-Wesley, Reading, Massachusetts, 1986.
682 %    \bibitem{bk:lamport} \textsc{L. Lamport}.
683 %       \newblock
684 %       \LaTeX\ --- A Document Preparation System.
685 %       \newblock
686 %       Addison-Wesley, Reading, Massachusetts, 1986.
687 % \end{thebibliography}
689 % }   ^^A  end of \StopEventually
694 % \section{The documentation driver file}
696 % The first bit of code contains the documentation driver file for
697 % \TeX{}, i.e., the file that will produce the documentation you are
698 % currently reading. It will be extracted from this file by the
699 % \texttt{docstrip} program.
700 %    \begin{macrocode}
701 %<*driver>
702 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
703 \documentclass{ltxdoc}
705 \AtBeginDocument{\DeleteShortVerb{\|}}  % undo the default is not used
707  \usepackage{array}
709  % Allow large table at bottom
710  \renewcommand{\bottomfraction}{0.7}
712 \EnableCrossrefs
713  %\DisableCrossrefs   % Say \DisableCrossrefs if index is ready
715 \RecordChanges                  % Gather update information
717 \CodelineIndex                  % Index code by line number
719  %\OnlyDescription    % comment out for implementation details
720  %\OldMakeindex       % use if your MakeIndex is pre-v2.9
721 \begin{document}
722    \DocInput{array.dtx}
723 \end{document}
724 %</driver>
725 %    \end{macrocode}
728 % \section{The construction of the preamble}
730 % \DeleteShortVerb{\"}
731 % \MakeShortVerb{\=}
733 % It is obvious that those environments will consist mainly of an
734 % =\halign=, because \TeX\ typesets tables using this primitive.
735 % That is why we will now take a look at the algorithm which determines
736 % a preamble for a =\halign= starting with a given user preamble
737 % using the options mentioned above.
740 %    The current version is defined at the top of the file looking
741 %    something like this
742 %    \begin{macrocode}
743 %<*package>
744 %\NeedsTeXFormat{LaTeX2e}[1994/05/13]
745 %\ProvidesPackage{array}[\filedate\space version\fileversion]
746 %    \end{macrocode}
748 % The most interesting macros of this implementation are without doubt
749 % those which are responsible for the construction of the preamble for
750 % the =\halign=. The underlying algorithm was developed by
751 % \textsc{Lamport} (resp.\ \textsc{Knuth}, see texhax V87\#??), and it
752 % has been extended and improved.
754 % The user preamble will be read \textsf{token} by \textsf{token}.  A
755 % \textsf{token} is a single character like \texttt{c} or a block
756 % enclosed in ={...}=. For example the preamble of
757 % =\begin{tabular}=\linebreak[0]={lc||c@{\hspace{1cm}}}= consists of
758 % the \textsf{token} \texttt{l}, \texttt{c}, \texttt{|}, \texttt{|},
759 % \texttt{@} and =\hspace{1cm}=.
761 % The currently used \textsf{token} and the one, used before, are needed
762 % to decide on how the construction of the preamble has to be
763 % continued.
764 % In the example mentioned above the \texttt{l} causes the preamble
765 % to begin with =\hskip\tabcolsep=. Furthermore
766 % =# \hfil= would be appended to define a flush left column.
767 % The next \textsf{token} is a \texttt{c}. Because it was preceded by an
768 % \texttt{l} it generates a new column. This is done with
769 % =\hskip \tabcolsep & \hskip \tabcolsep=. The column which is to
770 % be centered will be appended with =\hfil # \hfil=.
771 % The \textsf{token} \texttt{|} would then add a space of
772 % =\hskip \tabcolsep=
773 % and a vertical line because the last
774 % \textsf{tokens} was a \texttt{c}.
775 % The following \textsf{token} \texttt{|} would only add a space
776 % =\hskip \doublerulesep= because it was preceded by the
777 % \textsf{token} \texttt{|}. We will not discuss our example further but
778 %  rather take a look at the general case of constructing preambles.
780 % The example shows that the desired preamble for the
781 % =\halign= can be constructed as soon as the action of all
782 % combinations
783 % of the preamble \textsf{tokens} are specified. There are 18 such
784 % \textsf{tokens}
785 % so we have $19 \cdot 18 \string= 342$ combinations if we count the
786 % beginning of
787 % the preamble as a special \textsf{token}. Fortunately, there are many
788 % combinations which generate the same spaces, so we can define
789 % \textsf{token} classes. We will identify a
790 % \textsf{token} within a class with a number, so we can insert the
791 % formatting (for example of a column).
792 % Table~\ref{tab:Klassen} lists all \textsf{token} classes and
793 % their corresponding numbers.
794 % \begin{table}[ht]
795 % \begin{center}
796 %    \begin{tabular}[t]{>{\ttfamily}ccc}
797 %       \textsf{token} & =\@chclass= & =\@chnum= \\[2mm]
798 %       c   & 0  & 0 \\
799 %       l   & 0  & 1 \\
800 %       r   & 0  & 2 \\
801 %       p-arg    & 0  & 3 \\
802 %       t-arg    & 0  & 4 \\
803 %       b-arg    & 0  & 5 \\
804 %       |   & 1  & 0 \\
805 %       !-arg    & 1  & 1 \\
806 %       <-arg    & 2  & --- \\
807 %       >-arg    & 3  & ---
808 %    \end{tabular}
809 %    \kern3mm \vrule \kern3mm%
810 %    \begin{tabular}[t]{>{\ttfamily}ccc}
811 %       \textsf{token} & =\@chclass= & =\@chnum= \\[2mm]
812 %       Start    & 4  & --- \\
813 %       @-arg    & 5  & --- \\
814 %       !   & 6  & --- \\
815 %       @   & 7  & --- \\
816 %       <   & 8  & --- \\
817 %       >   & 9  & --- \\
818 %       p   & 10 & 3 \\
819 %       t   & 10 & 4 \\
820 %       b   & 10 & 5
821 %    \end{tabular}
822 % \end{center}
823 % \caption{Classes of preamble \textsf{tokens}}
824 % \label{tab:Klassen}
825 % \end{table}
828 % \begin{macro}{\@chclass}
829 % \begin{macro}{\@chnum}
830 % \begin{macro}{\@lastchclass}
831 %    The class and the number of the current \textsf{token} are saved in
832 %    the
833 %    \textsf{count} registers =\@chclass=
834 %    and =\@chnum=, while the class of the previous
835 %    \textsf{token} is stored in the
836 %    \textsf{count} register =\@lastchclass=.
837 %    All of the mentioned registers are already allocated in
838 %    \texttt{latex.tex},
839 %    which is the reason why the following three lines of code are
840 %    commented out.
841 %    Later throughout the text I will not mention it again explicitly
842 %    whenever I use a =%= sign. These parts are already defined in
843 %    \texttt{latex.tex}.
844 %    \begin{macrocode}
845 % \newcount \@chclass
846 % \newcount \@chnum
847 % \newcount \@lastchclass
848 %    \end{macrocode}
849 % \end{macro}
850 % \end{macro}
851 % \end{macro}
855 % \begin{macro}{\@addtopreamble}
856 %    We will save the already constructed preamble for
857 %    the =\halign=
858 %    in the global macro =\@preamble=. This will then be
859 %     enlarged with
860 %    the command =\@addtopreamble=.
861 %    \begin{macrocode}
862 \def\@addtopreamble#1{\xdef\@preamble{\@preamble #1}}
863 %    \end{macrocode}
864 % \end{macro}
870 % \subsection{The character class of a \textsf{token}}
872 % \begin{macro}{\@testpach}
873 % \changes{v2.0a}{1989/05/12}{p option renamed to m (middle).}
874 % \changes{v2.0a}{1989/05/12}{t option renamed to p to be compatible to
875 %                         the original.}
876 %    With the help of =\@lastchclass= we can now define a macro
877 %    which determines the class and the number of a given preamble
878 %    \textsf{token}
879 %    and assigns them to the registers
880 %    =\@chclass= and =\@chnum=.
881 % \changes{v2.0f}{1992/02/29}{Argument removed since implicitly known}
882 %    \begin{macrocode}
883 \def\@testpach{\@chclass
884 %    \end{macrocode}
885 %    First we deal with the cases in which the \textsf{token}
886 %    (=#1=) is the argument of \texttt{!}, \texttt{@}, \texttt{<} or
887 %    \texttt{>}. We can see this from the value of =\@lastchclass=:
888 %    \begin{macrocode}
889  \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
890   \ifnum \@lastchclass=7 5 \else
891    \ifnum \@lastchclass=8 \tw@ \else
892     \ifnum \@lastchclass=9 \thr@@
893 %    \end{macrocode}
894 %    Otherwise we will assume that the \textsf{token} belongs to the
895 %    class $0$
896 %    and assign the corresponding number to =\@chnum= if our
897 %    assumption is correct.
898 %    \begin{macrocode}
899    \else \z@
900 %    \end{macrocode}
901 %    If the last \textsf{token} was a \texttt{p}, \texttt{m} or a
902 %    \texttt{b}, =\@chnum= already has the right value. This is the
903 %    reason for the somewhat curious choice of the \textsf{token}
904 %    numbers in class $10$.
905 %    \begin{macrocode}
906    \ifnum \@lastchclass = 10 \else
907 %    \end{macrocode}
908 %    Otherwise we will check if =\@nextchar= is either a \texttt{c},
909 %    \texttt{l} or an \texttt{r}.  Some applications change the
910 %    catcodes of certain characters like ``\texttt{@}'' in
911 %    \texttt{amstex.sty}. As a result the tests below would fail since
912 %    they assume non-active character tokens. Therefore we evaluate
913 %    =\@nextchar= once thereby turning the first token of its
914 %    replacement text into a char. At this point here this should have
915 %    been the only char present in =\@nextchar= which put into via a
916 %    =\def=.
917 % \changes{v2.0f}{1992/02/29}{Ensure to test a char which is not active}
918 %    \begin{macrocode}
919    \edef\@nextchar{\expandafter\string\@nextchar}%
920    \@chnum
921    \if \@nextchar c\z@ \else
922     \if \@nextchar l\@ne \else
923      \if \@nextchar r\tw@ \else
924 %    \end{macrocode}
925 %    If it is a different \textsf{token}, we know that the class was
926 %    not $0$. We assign the value $0$ to =\@chnum= because this value
927 %    is needed for the \texttt{|}--\textsf{token}. Now we must check
928 %    the remaining classes.  Note that the value of =\@chnum= is
929 %    insignificant here for most classes.
930 %    \begin{macrocode}
931    \z@ \@chclass
932    \if\@nextchar |\@ne \else
933     \if \@nextchar !6 \else
934      \if \@nextchar @7 \else
935       \if \@nextchar <8 \else
936        \if \@nextchar >9 \else
937 %    \end{macrocode}
938 %    The remaining permitted \textsf{tokens} are \texttt{p},
939 %    \texttt{m} and \texttt{b} (class $10$).
940 %    \begin{macrocode}
941   10
942   \@chnum
943   \if \@nextchar m\thr@@\else
944    \if \@nextchar p4 \else
945     \if \@nextchar b5 \else
946 %    \end{macrocode}
947 %    Now the only remaining possibility is a forbidden \textsf{token},
948 %    so we choose class $0$ and number $0$ and give an error message.
949 %    Then we finish the macro by closing all =\if='s.
950 %    \begin{macrocode}
951    \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi
952    \fi \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi}
953 %    \end{macrocode}
954 % \end{macro}
960 % \subsection{Multiple columns ($*$--form)}
962 % \begin{macro}{\@xexpast}
963 % \begin{macro}{\the@toks}
964 % \begin{macro}{\the@toksz}
965 %    \label{@xexpast} Now we discuss the macro that deletes all forms
966 %    of type =*{=\textit{N\/}=}{=\textit{String\/}=}= from a user
967 %    preamble and replaces them with \textit{N} copies of
968 %    \textit{String}.  Nested $*$--expressions are dealt with
969 %    correctly, that means $*$--expressions are not substituted if
970 %    they are in explicit braces, as in =@{*}=.
972 %    This macro is called via
973 %    =\@xexpast=\meta{preamble}=*0x\@@=.
974 %    The $*$--expression =*0x= is being used to terminate the
975 %    recursion,
976 %    as we shall see later, and =\@@= serves as an argument
977 %    delimiter. =\@xexpast= has four arguments. The first
978 %    one is the part of the
979 %    user preamble before the first $*$--expression while the second
980 %    and third ones are the arguments of the first $*$--expression
981 %    (that is \textit{N} and \textit{String} in the notation mentioned
982 %    above).
983 %    The fourth argument is the rest of the preamble.
984 %    \begin{macrocode}
985 \def\@xexpast#1*#2#3#4\@@{%
986 %    \end{macrocode}
987 %    The number of copies of \textit{String} (=#2=) that are to be
988 %    produced will be saved in a \textsf{count} register.
989 %    \begin{macrocode}
990    \@tempcnta #2
991 %    \end{macrocode}
992 %    We save the part of the preamble which does not
993 %    contain a $*$--form (=#1=)
994 %    in a \PlainTeX\ \textsf{token} register.
995 %    We also save \textit{String} (=#3=) using a \LaTeX\
996 %    \textsf{token} register.
997 %    \begin{macrocode}
998    \toks@={#1}\@temptokena={#3}%
999 %    \end{macrocode}
1000 %    Now we have to use a little trick to produce \textit{N} copies of
1001 %    \textit{String}.
1002 %    We could try =\def\@tempa{#1}= and then
1003 %    \textit{N} times =\edef\@tempa{\@tempa#3}=. This would have the
1004 %    undesired effect that all macros within =#1= and =#3=
1005 %    would be expanded, although, for example, constructions like
1006 %    =@{..}= are not supposed to be changed.
1007 %    That is why we =\let= two control sequences to
1008 %    be equivalent to =\relax=.
1009 %    \begin{macrocode}
1010    \let\the@toksz\relax \let\the@toks\relax
1011 %    \end{macrocode}
1012 %    Then we ensure that =\@tempa= contains
1013 %    ={\the@toksz\the@toks...\the@toks}= (the macro
1014 %    =\the@toks= exactly \textit{N\/} times) as substitution text.
1015 %    \begin{macrocode}
1016    \def\@tempa{\the@toksz}%
1017    \ifnum\@tempcnta >0 \@whilenum\@tempcnta >0\do
1018      {\edef\@tempa{\@tempa\the@toks}\advance \@tempcnta \m@ne}%
1019 %    \end{macrocode}
1020 %    If \textit{N\/} was greater than zero we prepare for another call
1021 %    of =\@xexpast=. Otherwise we assume we have reached the end of
1022 %    the user preamble, because we had appended =*0x\@@= when we first
1023 %    called =\@xexpast=.  In other words: if the user inserts
1024 %    =*{0}{..}= in his preamble, \LaTeX\ ignores the rest of it.
1025 %    \begin{macrocode}
1026        \let \@tempb \@xexpast \else
1027        \let \@tempb \@xexnoop \fi
1028 %    \end{macrocode}
1029 %    Now we will make sure that the part of the user preamble, which
1030 %    was already dealt with, will be saved again in =\@tempa=.
1031 %    \begin{macrocode}
1032    \def\the@toksz{\the\toks@}\def\the@toks{\the\@temptokena}%
1033    \edef\@tempa{\@tempa}%
1034 %    \end{macrocode}
1035 %    We have now evaluated the first $*$--expression, and the user
1036 %    preamble up to this point
1037 %    is saved in =\@tempa=. We will put the contents of
1038 %    =\@tempa= and the rest of the user preamble together and work
1039 %    on the result with =\@tempb=. This macro either corresponds
1040 %    to =\@xexpast=, so that the next
1041 %    $*$--expression is handled, or to the macro =\@xexnoop=,
1042 %    which only ends the recursion by deleting its argument.
1043 %    \begin{macrocode}
1044    \expandafter \@tempb \@tempa #4\@@}
1045 %    \end{macrocode}
1046 % \end{macro}
1047 % \end{macro}
1048 % \end{macro}
1050 % \begin{macro}{\@xexnoop}
1051 %    So the first big problem is solved. Now it is easy to
1052 %    specify =\@xexnoop=.
1053 %    Its argument is delimited by =\@@= and it simply expands to
1054 %    nothing.
1055 %    \begin{macrocode}
1056 %  \def\@xexnoop#1\@@{}
1057 %    \end{macrocode}
1058 % \end{macro}
1063 % \section{The insertion of declarations
1064 %           (\texttt{>}, \texttt{<}, \texttt{!}, \texttt{@})}
1067 % The preamble will be enlarged with the help of =\xdef=, but the
1068 % arguments of \texttt{>}, \texttt{<},~\texttt{!}\ and \texttt{@} are
1069 % not supposed to be expanded during the construction (we want an
1070 % implementation that doesn't need a =\protect=). So we have to find a
1071 % way to inhibit the expansion of those arguments.
1073 % We will solve this problem with \textsf{token} registers. We need
1074 % one register for every \texttt{!}\ and \texttt{@}, while we need two
1075 % for every \texttt{c}, \texttt{l}, \texttt{r}, \texttt{m}, \texttt{p}
1076 % or \texttt{b}. This limits the number of columns of a table because
1077 % there are only 256 \textsf{token} registers. But then, who needs
1078 % tables with more than 100 columns?
1080 % One could also find a solution which only needs two or three
1081 % \textsf{token} registers by proceeding similarly as in the macro
1082 % =\@xexpast= (see page \pageref{@xexpast}). The advantage of our
1083 % approach is the fact that we avoid some of the problems that arise
1084 % with the other method\footnote{Maybe there are also historical
1085 %  reasons.}.
1087 % So how do we proceed? Let us assume that we had =!{foo}= in the
1088 % user preamble and say we saved \texttt{foo} in
1089 % \textsf{token} register $5$. Then we call
1090 % =\@addtopreamble{\the@toks5}= where
1091 % =\the@toks= is defined in a way that it does not expand
1092 % (for example it could be equivalent to =\relax=). Every
1093 % following call
1094 % of =\@addtopreamble= leaves =\the@toks5= unchanged in
1095 % =\@preamble=. If the construction of the preamble is completed
1096 % we change the definition of =\the@toks= to
1097 % =\the\toks= and expand =\@preamble= for the last time.
1098 % During this process all parts of the form
1099 %    =\the@toks=\meta{Number}
1100 % will be substituted by the contents of the respective \textsf{token}
1101 % registers.
1103 % As we can see from this informal discussion the construction of the
1104 % preamble has to take place within a group, so that the
1105 % \textsf{token} registers we use will be freed later on. For that
1106 % reason we keep all assignments to =\@preamble= global; therefore the
1107 % replacement text of this macro will remain the same after we leave
1108 % the group.
1110 % \begin{macro}{\count@}
1111 %    We further need a \textsf{count} register to remember which
1112 %    \textsf{token} register is to be used next. This will be
1113 %    initialized with $-1$ if we want to begin with the \textsf{token}
1114 %    register $0$. We use the \PlainTeX\ scratch register =\count@=
1115 %    because everything takes place locally. All we have to do is
1116 %    insert =\the@toks= =\the= =\count@= into the preamble.
1117 %    =\the@toks= will remain unchanged and =\the\count@= expands into
1118 %    the saved number.
1119 % \end{macro}
1121 % \begin{macro}{\prepnext@tok}
1122 %    The macro =\prepnext@tok= is in charge of preparing the next
1123 %    \textsf{token} register. For that purpose we increase
1124 %    =\count@= by $1$:
1125 %    \begin{macrocode}
1126 \def\prepnext@tok{\advance \count@ \@ne
1127 %    \end{macrocode}
1128 %    Then we locally delete any contents the
1129 %    \textsf{token} register might have.
1130 %    \begin{macrocode}
1131    \toks\count@{}}
1132 %    \end{macrocode}
1133 % \end{macro}
1135 % \begin{macro}{\save@decl}
1136 %    During the construction of the preamble the current
1137 %    \textsf{token} is always saved in the macro =\@nextchar= (see the
1138 %    definition of =\@mkpream= on page \pageref{@mkpream}). The macro
1139 %    =\save@decl= saves it into the next free \textsf{token} register,
1140 %    i.e.\ in =\toks\count@=.
1141 % \changes{v2.0c}{1990/08/14}{\cs{relax} removed and added elsewhere.}
1142 %    \begin{macrocode}
1143 \def\save@decl{\toks\count@ \expandafter{\@nextchar}}
1144 %    \end{macrocode}
1145 %    The reason for the  use of =\relax= is the following
1146 %    hypothetical situation in the preamble:
1147 %    \quad =..\the\toks1\the\toks2..= \quad \TeX\ expands
1148 %    =\the\toks2= first in order to find out if the digit =1=
1149 %    is followed by other digits. E.g.\ a =5= saved in the
1150 %    \textsf{token} register $2$ would lead \TeX\ to insert the contents
1151 %    of \textsf{token} register $15$ instead of $1$ later on.
1153 % The example above referred to an older version of =\save@decl= which
1154 % inserted a =\relex= inside the token register. This is now moved to
1155 % the places where the actual token registers are inserted (look for
1156 % =\the@toks=) because the old version would still make =@=
1157 % expressions to moving arguments since after expanding the second
1158 % register while looking for the end of the number the contents of the
1159 % token register is added so that later on the whole register will be
1160 % expanded.  This serious bug was found after nearly two years
1161 % international use of this package  by Johannes Braams.
1162 % \end{macro}
1166 % How does the situation look like, if we want to add another column
1167 % to the preamble, i.e.\ if we have found a \texttt{c}, \texttt{l},
1168 % \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in the user
1169 % preamble?  In this case we have the problem of the \textsf{token}
1170 % register from =>{..}= and =<{..}= having to be inserted at this
1171 % moment because formatting instructions like =\hfil= have to be set
1172 % around them. On the other hand it is not known yet, if any =<{..}=
1173 % instruction will appear in the user preamble at all.
1175 % We solve this problem by adding two \textsf{token} registers at a
1176 % time.  This explains, why we have freed the \textsf{token} registers
1177 % in =\prepnext@tok=.
1179 % \begin{macro}{\insert@column}
1180 % \begin{macro}{\@sharp}
1181 %    We now define the macro =\insert@column= which will do
1182 %    this work for us.
1183 %    \begin{macrocode}
1184 \def\insert@column{%
1185 %    \end{macrocode}
1186 %    Here, we assume that the \textsf{count} register
1187 %    =\@tempcnta= has saved the value $=\count@= - 1$.
1188 %    \begin{macrocode}
1189    \the@toks \the \@tempcnta
1190 %    \end{macrocode}
1191 %    Next follows the =#= sign which specifies the place
1192 %    where the text of the column shall be inserted. To avoid
1193 %    errors during the expansions in
1194 %    =\@addtopreamble= we hide this sign in the command
1195 %    =\@sharp= which is temporarily occupied with
1196 %    =\relax= during the build-up of the preamble.
1197 %    To remove unwanted spaces before and after the column text, we set
1198 %    an =\ignorespaces=  in front and a =\unskip= afterwards.
1199 % \changes{v2.0e}{1991/02/07}{Added \{\} around \cs{@sharp} for new ftsel}
1200 % \changes{v2.0h}{1992/06/22}{Removed \{\} again in favour of
1201 %                             \cs{d@llarbegin}}
1202 %    \begin{macrocode}
1203    \ignorespaces \@sharp \unskip
1204 %    \end{macrocode}
1205 %    Then the second \textsf{token} register follows whose number should
1206 %    be saved in =\count@=.
1207 %    We make sure that there will be no further expansion after reading
1208 %    the number, by finishing with =\relax=. The case above is not
1209 %    critical since it is ended by =\ignorespaces=.
1210 % \changes{v2.0c}{1990/08/14}{\cs{relax} added to avoid problem
1211 %                           \cs{the}\cs{toks0}\cs{the}\cs{toks1}.}
1212 %    \begin{macrocode}
1213    \the@toks \the \count@ \relax}
1214 %    \end{macrocode}
1215 % \end{macro}
1216 % \end{macro}
1221 % \subsection{The separation of columns}
1223 % \begin{macro}{\@addamp}
1224 %    In the preamble a =&= has to be inserted between any two columns;
1225 %    before the first column there should not be a =&=. As the user
1226 %    preamble may start with a \texttt{|} we have to remember somehow
1227 %    if we have already inserted a =#= (i.e.\ a column). This is done
1228 %    with the boolean variable =\if@firstamp= that we test in
1229 %    =\@addamp=, the macro that inserts the =&=.
1230 %    \begin{macrocode}
1231 %    \newif \@iffirstamp
1232 %    \def\@addamp{\if@firstamp \@firstampfalse
1233 %                 \else \@addtopreamble &\fi}
1234 %    \end{macrocode}
1235 % \end{macro}
1237 % \begin{macro}{\@acol}
1238 % \begin{macro}{\@acolampacol}
1239 % \begin{macro}{\col@sep}
1240 %    We will now define some abbreviations for the extensions,
1241 %    appearing most often in the preamble build-up.
1242 %    Here =\col@sep= is a \textsf{dimen} register which is set
1243 %    equivalent to =\arraycolsep= in an \textsf{array}--environment,
1244 %    otherwise it is set equivalent to =\tabcolsep=.
1245 %    \begin{macrocode}
1246 \newdimen\col@sep
1247 \def\@acol{\@addtopreamble{\hskip\col@sep}}
1248 %    \def\@acolampacol{\@acol\@addamp\@acol}
1249 %    \end{macrocode}
1250 % \end{macro}
1251 % \end{macro}
1252 % \end{macro}
1255 % \subsection{The macro \texttt{\textbackslash @mkpream}}
1257 % \begin{macro}{\@mkpream}
1258 % \begin{macro}{\the@toks}
1259 %    \label{@mkpream}
1260 %    Now we can define the macro which builds up the preamble for the
1261 %    =\halign=.
1262 %    First we initialize =\@preamble=, =\@lastchclass=
1263 %    and the boolean variable =\if@firstamp=.
1264 %    \begin{macrocode}
1265 \def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue
1266 %    \end{macrocode}
1267 %    During the build-up of the preamble we cannot directly use the
1268 %    =#= sign; this would lead to an error message in the next
1269 %    =\@addtopreamble= call.
1270 %    Instead, we use the command =\@sharp= at places where later
1271 %    a =#= will be.
1272 %    This command is at first given the meaning =\relax=;
1273 %    therefore it will not be expanded when the preamble
1274 %    is extended.
1275 %    In the macro =\@array=, shortly before the =\halign=
1276 %    is carried out, =\@sharp= is given its final meaning.
1278 %    In a similar way,
1279 %    we deal with the commands =\@startpbox= and
1280 %    =\@endpbox=, although the reason is different here: these
1281 %    macros expand in many \textsf{tokens} which would delay the
1282 %    build-up of the preamble.
1283 %    \begin{macrocode}
1284    \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax
1285 %    \end{macrocode}
1286 %    Now we remove possible  $*$-forms in the user preamble with the
1287 %    command =\@xexpast=.  As we already know, this command saves
1288 %    its result in the macro =\@tempa=.
1289 %    \begin{macrocode}
1290    \@xexpast #1*0x\@@
1291 %    \end{macrocode}
1292 %    Afterwards we initialize all registers and macros, that we need
1293 %    for the build-up of the preamble.
1294 %    Since we want to start with the \textsf{token} register $0$,
1295 %    =\count@= has to contain the value $-1$.
1296 %    \begin{macrocode}
1297    \count@\m@ne
1298    \let\the@toks\relax
1299 %    \end{macrocode}
1300 %    Then we call up =\prepnext@tok= in order to prepare the
1301 %    \textsf{token} register $0$ for use.
1302 %    \begin{macrocode}
1303    \prepnext@tok
1304 %    \end{macrocode}
1305 %    To evaluate the user preamble (without stars) saved in
1306 %    =\@tempa= we use the \LaTeX--macro =\@tfor=.
1307 %    The strange appearing construction with =\expandafter= is
1308 %    based on the fact that we have to put the replacement text of
1309 %    =\@tempa= and not the macro =\@tempa= to this
1310 %    \LaTeX--macro.
1311 %    \begin{macrocode}
1312    \expandafter \@tfor \expandafter \@nextchar
1313     \expandafter :\expandafter =\@tempa \do
1314 %    \end{macrocode}
1315 %    The body of this loop (the group after the =\do=)
1316 %    is executed for one \textsf{token} at a time, whereas
1317 %    the current \textsf{token} is saved in =\@nextchar=.
1318 %    At first we evaluate the current \textsf{token} with the already
1319 %    defined macro =\@testpach=, i.e.\ we assign to
1320 %    =\@chclass= the character class and to =\@chnum=
1321 %    the character number of this \textsf{token}.
1322 % \changes{v2.0f}{1992/02/29}{\cs{@testpach} now without arg}
1323 %    \begin{macrocode}
1324    {\@testpach
1325 %    \end{macrocode}
1326 %    Then we branch out depending on the value of =\@chclass= into
1327 %    different macros that extend the preamble respectively.
1328 %    \begin{macrocode}
1329    \ifcase \@chclass \@classz \or \@classi \or \@classii
1330      \or \save@decl \or \or \@classv \or \@classvi
1331      \or \@classvii \or \@classviii  \or \@classix
1332      \or \@classx \fi
1333 %    \end{macrocode}
1334 %    Two cases deserve our special attention: Since the current
1335 %    \textsf{token} cannot have the character class $4$ (start) we
1336 %    have skipped this possibility. If the character class is $3$,
1337 %    only the content of =\@nextchar= has to be saved into the current
1338 %    \textsf{token} register; therefore we call up =\save@decl=
1339 %    directly and save a macro name.  After the preamble has been
1340 %    extended we assign the value of =\@chclass= to the counter
1341 %    =\@lastchclass= to assure that this information will be available
1342 %    during the next run of the loop.
1343 %    \begin{macrocode}
1344    \@lastchclass\@chclass}%
1345 %    \end{macrocode}
1346 %    After the loop has been finished space must still be added to
1347 %    the created preamble, depending on the last \textsf{token}.
1348 %    Depending on the value of =\@lastchclass= we perform
1349 %    the necessary operations.
1350 %    \begin{macrocode}
1351    \ifcase\@lastchclass
1352 %    \end{macrocode}
1353 %    If the last class equals $0$ we add a
1354 %    =\hskip \col@sep=.
1355 %    \begin{macrocode}
1356    \@acol \or
1357 %    \end{macrocode}
1358 %    If it equals $1$ we do not add any additional space so that the
1359 %    horizontal lines do not exceed the vertical ones.
1360 %    \begin{macrocode}
1361    \or
1362 %    \end{macrocode}
1363 %    Class $2$ is treated like class $0$ because a =<{...}=  can
1364 %    only directly follow after class $0$.
1365 %    \begin{macrocode}
1366    \@acol \or
1367 %    \end{macrocode}
1368 %    Most of the other possibilities can only appear if the user
1369 %    preamble was defective. Class $3$ is not allowed since after a
1370 %    =>{..}= there must always follow a \texttt{c}, \texttt{l},
1371 %    \texttt{r}, \texttt{p},\texttt{m} or \texttt{b}. We report an
1372 %    error and ignore the declaration given by ={..}=.
1373 %    \begin{macrocode}
1374    \@preamerr \thr@@ \or
1375 %    \end{macrocode}
1376 %    If =\@lastchclass= is $4$ the user preamble has been empty.
1377 %    To continue, we insert a =#= in the preamble.
1378 %    \begin{macrocode}
1379    \@preamerr \tw@ \@addtopreamble\@sharp \or
1380 %    \end{macrocode}
1381 %    Class $5$ is allowed again. In this case
1382 %    (the user preamble ends with =@{..}=) we need not
1383 %    do anything.
1384 %    \begin{macrocode}
1385    \or
1386 %    \end{macrocode}
1387 %    Any other case means that the arguments to =@=, \texttt{!},
1388 %    \texttt{<}, \texttt{>}, \texttt{p}, \texttt{m} or \texttt{b} have
1389 %    been forgotten. So we report an error and ignore the last
1390 %    \textsf{token}.
1391 %    \begin{macrocode}
1392    \else  \@preamerr \@ne \fi
1393 %    \end{macrocode}
1394 %    Now that the build-up of the preamble is almost finished we can
1395 %    insert the \textsf{token} registers and therefore redefine
1396 %    =\the@toks=. The actual insertion, though, is performed
1397 %    later.
1398 %    \begin{macrocode}
1399    \def\the@toks{\the\toks}}
1400 %    \end{macrocode}
1401 % \end{macro}
1402 % \end{macro}
1406 %  \section{The macros \texttt{\textbackslash @classz}
1407 %           to \texttt{\textbackslash @classx}}
1409 % The preamble is extended by the macros =\@classz= to
1410 % =\@classx= which are called by =\@mkpream=
1411 %  depending on =\@lastchclass=
1412 % (i.e. the character class of the last \textsf{token}).
1413 % \begin{macro}{\@classx}
1414 %    First we define =\@classx= because of its important r\^ole.
1415 %    When it is called we find that the current
1416 %    \textsf{token} is \texttt{p}, \texttt{m} or \texttt{b}.
1417 %    That means that a new column has to start.
1418 %    \begin{macrocode}
1419 \def\@classx{%
1420 %    \end{macrocode}
1421 %    Depending on the value of =\@lastchclass= different actions
1422 %    must take place:
1423 %    \begin{macrocode}
1424   \ifcase \@lastchclass
1425 %    \end{macrocode}
1426 %    If the last character class was $0$ we separate the columns by
1427 %    =\hskip\col@sep= followed by =&= and another
1428 %    =\hskip\col@sep=.
1429 %    \begin{macrocode}
1430   \@acolampacol \or
1431 %    \end{macrocode}
1432 %    If the last class was class $1$ --- that means that a vertical
1433 %    line was
1434 %    drawn, --- before this line a =\hskip\col@sep= was inserted.
1435 %    Therefore there has to be only a =&= followed by
1436 %    =\hskip\col@sep=. But this =&= may be inserted only
1437 %    if this is not the first column. This process is controlled
1438 %    by =\if@firstamp= in the macro =\addamp=.
1439 %    \begin{macrocode}
1440   \@addamp \@acol \or
1441 %    \end{macrocode}
1442 %    Class $2$ is treated like class $0$ because =<{...}= can only
1443 %    follow after class $0$.
1444 %    \begin{macrocode}
1445   \@acolampacol \or
1446 %    \end{macrocode}
1447 %    Class $3$ requires no actions because all things necessary have
1448 %    been done by the preamble \textsf{token} \texttt{>}.
1449 %    \begin{macrocode}
1450   \or
1451 %    \end{macrocode}
1452 %    Class $4$ means that we are at the beginning of the preamble.
1453 %    Therefore we start the preamble with =\hskip\col@sep= and
1454 %    then call =\@firstampfalse=. This makes sure that a later
1455 %    =\@addamp= inserts the character
1456 %    =&= into the preamble.
1457 %    \begin{macrocode}
1458   \@acol \@firstampfalse \or
1459 %    \end{macrocode}
1460 %    For class $5$ \textsf{tokens} only the character =&= is inserted
1461 %    as a column separator. Therefore we call =\@addamp=.
1462 %    \begin{macrocode}
1463   \@addamp
1464 %    \end{macrocode}
1465 %    Other cases are impossible. For an example
1466 %    $=\@lastchclass= \string= 6$---as it might appear in a
1467 %    preamble of the form =...!p...=---\texttt{p} would have
1468 %    been taken as an  argument of \texttt{!}\ by =\@testpach=.
1469 %    \begin{macrocode}
1470   \fi}
1471 %    \end{macrocode}
1472 % \end{macro}
1475 % \begin{macro}{\@classz}
1476 %    If the character class of the last \textsf{token} is $0$ we have
1477 %    \texttt{c}, \texttt{l}, \texttt{r} or an argument of \texttt{m},
1478 %    \texttt{b} or\ \texttt{p}. In the first three cases the preamble
1479 %    must be extended the same way as if we had class $10$. The
1480 %    remaining two cases do not require any action because the space
1481 %    needed was generated by the last \textsf{token} (i.e.\
1482 %    \texttt{m}, \texttt{b} or \texttt{p}). Since =\@lastchclass= has
1483 %    the value $10$ at this point nothing happens when =\@classx= is
1484 %    called. So the macro =\@chlassz= may start like this:
1485 %    \begin{macrocode}
1486 \def\@classz{\@classx
1487 %    \end{macrocode}
1488 %    According to the definition of =\insert@column= we must store
1489 %    the number of the \textsf{token} register in which a preceding
1490 %    =>{..}= might have stored its argument into
1491 %    =\@tempcnta=.
1492 %    \begin{macrocode}
1493    \@tempcnta \count@
1494 %    \end{macrocode}
1495 %    To have $=\count@= \string= =\@tmpcnta= + 1$ we prepare
1496 %    the next \textsf{token} register.
1497 %    \begin{macrocode}
1498    \prepnext@tok
1499 %    \end{macrocode}
1500 %    Now the preamble must be extended with the column whose format
1501 %    can be determined by =\@chnum=.
1502 %    \begin{macrocode}
1503    \@addtopreamble{\ifcase \@chnum
1504 %    \end{macrocode}
1505 %    If =\@chnum= has the value $0$ a centered column has to be
1506 %    generated.
1507 %    So we begin with stretchable space.
1508 %    \begin{macrocode}
1509       \hfil
1510 %    \end{macrocode}
1511 %    The command =\d@llarbegin= follows expanding into =\begingroup=
1512 %    (in the \textsf{tabular}--environment) or into =$=.  Doing this
1513 %    (provided an appropriate setting of =\d@llarbegin=) we achieve
1514 %    that the contents of the columns of an \textsf{array}--environment
1515 %    are set in math mode while those of a \textsf{tabular}--environment
1516 %    are set in LR mode.
1517 %    \begin{macrocode}
1518       \d@llarbegin
1519 %    \end{macrocode}
1520 %    Now we insert the contents of the two \textsf{token} registers
1521 %    and the symbol
1522 %    for the column entry (i.e.\ =#= or
1523 %    more precise =\@sharp=) using =\insert@column=.
1524 %    \begin{macrocode}
1525       \insert@column
1526 %    \end{macrocode}
1527 %    We end this case with =\d@llarend= and =\hfil= where =\d@llarend=
1528 %    again is either =$= or =\endgroup=.
1529 %    \begin{macrocode}
1530       \d@llarend \hfil \or
1531 %    \end{macrocode}
1532 %    The templates for \texttt{l} and \texttt{r} (i.e.\ =\@chnum= $1$
1533 %    or $2$) are generated the same way. Since one  =\hfil= is
1534 %    missing the text is moved to the relevant side.
1535 %    The =\kern\z@= is needed in case of an empty column
1536 %    entry. Otherwise
1537 %    the =\unskip= in =\insert@column= removes the
1538 %    =\hfil=. Changed to =\hskip1sp= so that it interacts better with
1539 %    =\@bsphack=.
1540 % \changes{v2.3f}{1996/04/22}
1541 %     {(DPC) Extra \cs{kern} keeps tabcolsep in empty l columns
1542 %             internal/2122}
1543 % \changes{v2.3i}{1996/06/14}
1544 %     {Change both \cs{kern}\cs{z@} to \cs{hskip}1sp for latex/2160}
1545 %    \begin{macrocode}
1546       \hskip1sp\d@llarbegin \insert@column \d@llarend \hfil \or
1547       \hfil\hskip1sp\d@llarbegin \insert@column \d@llarend \or
1548 %    \end{macrocode}
1549 %    The templates for \texttt{p}, \texttt{m} and \texttt{b} mainly
1550 %    consist of a \textsf{box}. In case of \texttt{m} it is generated
1551 %    by =\vcenter=.  This command is allowed only in math
1552 %    mode. Therefore we start with a~=$=.
1553 %    \begin{macrocode}
1554    $\vcenter
1555 %    \end{macrocode}
1556 %    The part of the templates which is the same in all three cases
1557 %    (\texttt{p}, \texttt{m} and \texttt{b})
1558 %    is built by the macros =\@startpbox= and
1559 %    =\@endpbox=. =\@startpbox= has an argument:
1560 %    the width of the column which is stored in the current
1561 %    \textsf{token} (i.e.\ =\@nextchar=).
1562 %    Between these two macros we find the well known
1563 %    =\insert@column=.
1564 %    \begin{macrocode}
1565    \@startpbox{\@nextchar}\insert@column \@endpbox $\or
1566 %    \end{macrocode}
1567 %    The templates for \texttt{p} and \texttt{b} are generated in the
1568 %    same way though we do not need the =$= characters because we use
1569 %    =\vtop= or =\vbox=.
1570 %    \begin{macrocode}
1571    \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or
1572    \vbox \@startpbox{\@nextchar}\insert@column \@endpbox
1573 %    \end{macrocode}
1574 %    Other values for =\@chnum= are impossible. Therefore we
1575 %    end the arguments to =\@addtopreamble= and =\ifcase=.
1576 %    Before we come to the end of =\@classz= we have to
1577 %    prepare the next \textsf{token} register.
1578 %    \begin{macrocode}
1579   \fi}\prepnext@tok}
1580 %    \end{macrocode}
1581 % \end{macro}
1584 % \begin{macro}{\@classix}
1585 %    In case of class $9$ (\texttt{>}--\textsf{token}) we first check
1586 %    if the character class of the last
1587 %    \textsf{token} was $3$. In this case we have a
1588 %    user preamble of the form =..>{...}>{...}..= which
1589 %    is not allowed. We only give an error message and continue.
1590 %    So the declarations defined by the first  =>{...}=
1591 %    are ignored.
1592 %    \begin{macrocode}
1593 \def\@classix{\ifnum \@lastchclass = \thr@@
1594        \@preamerr \thr@@ \fi
1595 %    \end{macrocode}
1596 %    Furthermore, we call up =\@class10= because afterwards always a
1597 %    new column is started by \texttt{c}, \texttt{l}, \texttt{r},
1598 %    \texttt{p}, \texttt{m} or \texttt{b}.
1599 %    \begin{macrocode}
1600        \@classx}
1601 %    \end{macrocode}
1602 % \end{macro}
1606 % \begin{macro}{\@classviii}
1607 %    If the current \textsf{token} is a \texttt{<} the last character
1608 %    class must be $0$. In this case it is not necessary to extend the
1609 %    preamble. Otherwise we output an error message, set =\@chclass=
1610 %    to $6$ and call =\@classvi=.  By doing this we achieve that
1611 %    \texttt{<} is treated like \texttt{!}.
1612 %    \begin{macrocode}
1613 \def\@classviii{\ifnum \@lastchclass >\z@
1614       \@preamerr 4\@chclass 6 \@classvi \fi}
1615 %    \end{macrocode}
1616 % \end{macro}
1618 % \begin{macro}{\@arrayrule}
1619 %    There is only one incompatibility with the original definition:
1620 %    the definition of =\@arrayrule=. In the original a line without
1621 %    width\footnote{So the space between \texttt{cc} and \texttt{c|c}
1622 %    is equal.}  is created by multiple insertions of
1623 % =\hskip .5\arrayrulewidth=.
1624 %    We only insert a vertical line into the
1625 %    preamble.  This is done to prevent problems with \TeX's main
1626 %    memory when generating tables with many vertical lines in them
1627 %    (especially in the case of \textsf{floats}).
1628 %    \begin{macrocode}
1629 \def\@arrayrule{\@addtopreamble \vline}
1630 %    \end{macrocode}
1631 % \end{macro}
1633 % \begin{macro}{\@classvii}
1634 %    As a consequence it follows that in case of class $7$
1635 %    (=@= \textsf{token})  the preamble need not to be extended.
1636 %    In the original definition $=\@lastchclass= \string= 1$
1637 %    is treated by inserting =\hskip .5\arrayrulewidth=.
1638 %    We only check if the last \textsf{token} was of class $3$ which is
1639 %    forbidden.
1640 %    \begin{macrocode}
1641 \def\@classvii{\ifnum \@lastchclass = \thr@@
1642 %    \end{macrocode}
1643 %    If this is true we output an error message and
1644 %    ignore the declarations stored
1645 %    by the last  =>{...}=, because these are overwritten
1646 %    by the argument of \texttt{@}.
1647 %    \begin{macrocode}
1648    \@preamerr \thr@@ \fi}
1649 %    \end{macrocode}
1650 % \end{macro}
1653 % \begin{macro}{\@classvi}
1654 %    If the current \textsf{token} is a regular \texttt{!}\ and the
1655 %    last class was $0$ or $2$ we extend the preamble with
1656 %    =\hskip\col@sep=.  If the last \textsf{token} was of class $1$
1657 %    (for instance \texttt{|}) we extend with =\hskip \doublerulesep=
1658 %    because the construction =!{...}= has to be treated like
1659 %    \texttt{|}.
1660 %    \begin{macrocode}
1661 \def\@classvi{\ifcase \@lastchclass
1662       \@acol \or
1663       \@addtopreamble{\hskip \doublerulesep}\or
1664       \@acol \or
1665 %    \end{macrocode}
1666 %    Now =\@preamerr...= should follow because a
1667 %    user preamble of the form =..>{..}!.= is not allowed.
1668 %    To save memory we call =\@classvii= instead which also
1669 %    does what we want.
1670 %    \begin{macrocode}
1671       \@classvii
1672 %    \end{macrocode}
1673 %    If =\@lastchclass= is $4$ or $5$ nothing has to be done.
1674 %    Class $6$ to $10$ are not possible.
1675 %    So we finish the macro.
1676 %    \begin{macrocode}
1677       \fi}
1678 %    \end{macrocode}
1679 % \end{macro}
1681 % \begin{macro}{\@classii}
1682 % \begin{macro}{\@classiii}
1683 %    In the case of character classes $2$ and $3$ (i.e.\ the argument
1684 %    of \texttt{<} or \texttt{>}) we only have to store the current
1685 %    \textsf{token} (=\@nextchar=) into the corresponding
1686 %    \textsf{token} register since the preparation and
1687 %    insertion of these registers
1688 %    are done by the macro =\@classz=.
1689 %    This is equivalent to calling =\save@decl= in the case of
1690 %    class $3$. To save command identifiers we do this call up
1691 %     in the macro =\@mkpream=.
1693 %    Class $2$ exhibits a more complicated situation: the
1694 %    \textsf{token} registers have already been inserted by
1695 %    =\@classz=. So the value of =\count@= is too high
1696 %    by one. Therefore we decrease =\count@= by $1$.
1697 %    \begin{macrocode}
1698 \def\@classii{\advance \count@ \m@ne
1699 %    \end{macrocode}
1700 %    Next we store the current \textsf{token} into the correct
1701 %    \textsf{token} register by calling =\save@decl= and then
1702 %    increase the value of =\count@= again. At this point we
1703 %    can save memory once more (at the cost of time) if we use the
1704 %     macro =\prepnext@tok=.
1705 %    \begin{macrocode}
1706    \save@decl\prepnext@tok}
1707 %    \end{macrocode}
1708 % \end{macro}
1709 % \end{macro}
1712 % \begin{macro}{\@classv}
1713 %    If the current \textsf{token} is of class $5$ then it is an
1714 %    argument of a \texttt{@} \textsf{token}. It must be stored into a
1715 %    \textsf{token} register.
1716 %    \begin{macrocode}
1717 \def\@classv{\save@decl
1718 %    \end{macrocode}
1719 %    We extend the preamble with a command which inserts this
1720 %    \textsf{token} register into the preamble when its construction
1721 %    is finished. The user expects that this argument is worked out in
1722 %    math mode if it was used in an
1723 %    \textsf{array}--environment. Therefore we surround it with
1724 %    =\d@llar...='s.
1725 % \changes{v2.0c}{1990/08/14}{\cs{relax} added to avoid problem
1726 %                           `the`toks0`the`toks1.}
1727 %    \begin{macrocode}
1728    \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}%
1729 %    \end{macrocode}
1730 %    Finally we must prepare the next \textsf{token} register.
1731 %    \begin{macrocode}
1732    \prepnext@tok}
1733 %    \end{macrocode}
1734 % \end{macro}
1736 % \begin{macro}{\@classi}
1737 %    In the case of class $0$ we were able to generate the necessary
1738 %    space between columns by using the macro =\@classx=.
1739 %    Analogously the macro =\@classvi= can be used for class $1$.
1740 %    \begin{macrocode}
1741 \def\@classi{\@classvi
1742 %    \end{macrocode}
1743 %    Depending on =\@chnum= a vertical line
1744 %    \begin{macrocode}
1745    \ifcase \@chnum \@arrayrule \or
1746 %    \end{macrocode}
1747 %    or (in case of =!{...}=) the current \textsf{token} --- stored
1748 %    in =\@nextchar= --- has to be inserted into the preamble.
1749 %    This corresponds to calling =\@classv=.
1750 %    \begin{macrocode}
1751       \@classv \fi}
1752 %    \end{macrocode}
1753 % \end{macro}
1757 % \begin{macro}{\@startpbox}
1758 %    In =\@classz=  the macro =\@startpbox= is used.
1759 %    The width of the \textsf{parbox} is passed as an argument.
1760 %    =\vcenter=, =\vtop= or =\vbox= are already in the
1761 %    preamble. So we start with the braces for the wanted box.
1762 %    \begin{macrocode}
1763 \def\@startpbox#1{\bgroup
1764 %    \end{macrocode}
1765 %    The argument is the width of the box. This information has to be
1766 %    assigned to =\hsize=.
1767 %    Then we assign default values to several parameters used in a
1768 %    \textsf{parbox}.
1769 % \changes{v2.3k}{1998/05/12}{Use \cs{setlength} to set \cs{hsize},
1770 %      so that the calc package can be applied here (pr/2793)}
1771 %    \begin{macrocode}
1772   \setlength\hsize{#1}\@arrayparboxrestore
1773 %    \end{macrocode}
1774 %    Our main problem is to obtain the same distance between succeeding
1775 %    lines of the \textsf{parbox}.
1776 %    We have to remember that the distance between two \textsf{parboxes}
1777 %    should be defined by =\@arstrut=. That means that it can be
1778 %    greater than the distance in a \textsf{parbox}.
1779 %    Therefore it is not enough to set a =\@arstrut= at the
1780 %    beginning and at the end of the \textsf{parbox}. This would
1781 %    dimension the distance
1782 %    between first and second line and the distance between the two
1783 %    last lines of the \textsf{parbox} wrongly.
1784 %    To prevent this we set an invisible rule of height
1785 %    =\@arstrutbox=
1786 %    at the beginning of the \textsf{parbox}. This has no effect on the
1787 %    depth of the first line. At the end of the \textsf{parbox} we set
1788 %    analogously another invisible rule which only affects the depth
1789 %    of the last line. It is necessary to wait inserting this strut
1790 %    until the paragraph actually starts to allow for things like
1791 %    =\parindent= changes via =>{...}=.
1792 % \changes{v2.1c}{1992/12/14}{Use `everypar to insert strut}
1793 %    \begin{macrocode}
1794    \everypar{%
1795       \vrule \@height \ht\@arstrutbox \@width \z@
1796       \everypar{}}%
1797    }
1798 %    \end{macrocode}
1799 % \end{macro}
1801 % \begin{macro}{\@endpbox}
1802 %    If there are any declarations defined by =>{...}=
1803 %    and =<{...}=
1804 %    they now follow in the macro =\@classz= --- the contents
1805 %    of the column in between.
1806 %    So the macro =\@endpbox= must insert the \textsf{specialstrut}
1807 %    mentioned earlier and then close the group opened by
1808 %    =\@startpbox=.
1809 % \changes{v2.2d}{1994/05/16}{Use \LaTeXe \cs{@finalstrut}}
1810 % \changes{v2.3g}{1996/05/07}{Add \cs{hfil} for tools/2120}
1811 %    \begin{macrocode}
1812 \def\@endpbox{\@finalstrut\@arstrutbox \egroup\hfil}
1813 %    \end{macrocode}
1814 % \end{macro}
1817 % \section{Building and calling \texttt{\textbackslash halign}}
1819 % \begin{macro}{\@array}
1820 %    After we have discussed the macros needed for the evaluation
1821 %    of the user preamble we can define the macro =\@array=
1822 %    which uses these macros to create a =\halign=.
1823 %    It has two arguments. The first one is a position argument
1824 %    which can be \texttt{t}, \texttt{b} or \texttt{c}; the
1825 %    second one describes the wanted preamble,
1826 %    e.g.\ it has the form =|c|c|c|=.
1827 %    \begin{macrocode}
1828 \def\@array[#1]#2{%
1829 %    \end{macrocode}
1830 %    First we define a \textsf{strut} whose size basically corresponds
1831 %     to a normal \textsf{strut} multiplied by the factor
1832 %    =\arraystretch=.
1833 %    This \textsf{strut} is then  inserted into every row and enforces
1834 %     a minimal distance between two rows.
1835 %    Nevertheless, when using horizontal lines, large letters
1836 %    (like accented capital letters) still collide with such lines.
1837 %    Therefore at first we add to the height of a normal \textsf{strut}
1838 %    the value of the parameter =\extrarowheight=.
1839 %    \begin{macrocode}
1840   \@tempdima \ht \strutbox
1841   \advance \@tempdima by\extrarowheight
1842   \setbox \@arstrutbox \hbox{\vrule
1843              \@height \arraystretch \@tempdima
1844              \@depth \arraystretch \dp \strutbox
1845              \@width \z@}%
1846 %    \end{macrocode}
1847 %    Then we open a group, in which the user preamble is evaluated by
1848 %    the macro =\@mkpream=. As we know this must happen locally.
1849 %    This macro creates a preamble for a =\halign= and saves
1850 %    its result globally in the control sequence =\@preamble=.
1851 %    \begin{macrocode}
1852   \begingroup
1853   \@mkpream{#2}%
1854 %    \end{macrocode}
1855 %    We again redefine =\@preamble= so that a call up of =\@preamble=
1856 %    now starts the =\halign=. Thus also the arguments of \texttt{>},
1857 %    \texttt{<}, \texttt{@} and \texttt{!}, saved in the
1858 %    \textsf{token} registers are inserted into the preamble.  The
1859 %    =\tabskip= at the beginning and end of the preamble is set to
1860 %    \textsf{0pt} (in the beginning by the use of =\ialign=). Also the
1861 %    command =\@arstrut= is build in, which inserts the
1862 %    =\@arstrutbox=, defined above. Of course, the opening brace after
1863 %    =\ialign= has to be implicit as it will be closed in =\endarray=
1864 %    or another macro.
1865 % \changes{v2.3m}{1998/12/31}{Added \cs{noexpand} in front of \cs{ialign}
1866 %    to guard against interesting :-) changes to \cs{halign} done to support
1867 %    text glyphs in math}
1869 %    The =\noexpand= in front of =\ialign= does no harm in standard \LaTeX{}
1870 %    and was added since some experimental support for using text glyphs in math
1871 %    redefines =\halign= with the result that is becomes expandable with
1872 %    disastrous results in cases like this.
1873 %    In the kernel definition for this macro the problem does
1874 %    not surface because there =\protect= is set (which is not necessary in this
1875 %    implementation as there is no arbitrary user input that can get expanded) and
1876 %    the experimental code made the redefinition robust. Whether this is the right
1877 %    approach is open to question; consider the =\noexpand= a courtesy to allow an
1878 %    unsupported redefinition of a \TeX{} primitive for the moment (as people rely
1879 %    on that experimental code).
1880 %    \begin{macrocode}
1881   \xdef\@preamble{\noexpand \ialign \@halignto
1882                   \bgroup \@arstrut \@preamble
1883                           \tabskip \z@ \cr}%
1884 %    \end{macrocode}
1885 %    What we have not explained yet is the macro =\@halignto=
1886 %    that was just used. Depending on its replacement text the
1887 %    =\halign= becomes a =\halign= \texttt{to} \meta{dimen}.
1888 %    Now we close the group again. Thus
1889 %    =\@startpbox= and =\@endpbox= as well as all
1890 %    \textsf{token} registers get their former meaning back.
1891 %    \begin{macrocode}
1892   \endgroup
1893 %    \end{macrocode}
1894 %     To support the \texttt{delarray.sty} package  we include a hook
1895 %     into this part of the code which is a no-op in the main package.
1896 % \changes{v2.1a}{1992/07/03}{Hook for delarray added}
1897 %    \begin{macrocode}
1898   \@arrayleft
1899 %    \end{macrocode}
1900 %    Now we decide depending on the position argument in which
1901 %    \textsf{box} the =\halign= is to be put. (=\vcenter= may be used
1902 %    because we are in math mode.)
1903 % \changes{v2.1a}{1992/07/03}{Wrong spec is now equiv to [t]}
1904 %    \begin{macrocode}
1905   \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi
1906 %    \end{macrocode}
1907 %    Now another implicit opening brace appears; then definitions
1908 %    which shall stay local follow. While constructing the
1909 %    =\@preamble= in =\@mkpream= the =#= sign must be
1910 %    hidden in the macro =\@sharp= which is =\let= to
1911 %    =\relax= at that moment (see definition of =\@mkpream=
1912 %    on page~\pageref{@mkpream}).
1913 %    All these now get their actual meaning.
1914 %    \begin{macrocode}
1915   \bgroup
1916   \let \@sharp ##\let \protect \relax
1917 %    \end{macrocode}
1918 %    With the above defined \textsf{struts} we fix down the distance
1919 %    between rows by setting =\lineskip= and =\baselineskip=
1920 %    to \textsf{0pt}. Since there have to be set =$='s
1921 %    around every column in the \textsf{array}--environment
1922 %     the parameter =\mathsurround= should
1923 %    also be set to \textsf{0pt}. This prevents additional space between
1924 %    the rows. The
1925 %    \PlainTeX--macro =\m@th= does this.
1926 %    \begin{macrocode}
1927   \lineskip \z@
1928   \baselineskip \z@
1929   \m@th
1930 %    \end{macrocode}
1931 %    Beside, we have to assign a special meaning (which we still have
1932 %    to specify) to the line separator =\\=. We also have to
1933 %    redefine the command =\par= in such a way that empty lines in
1934 %    =\halign= cannot do any damage. We succeed in doing  so
1935 %    by choosing something that will disappear when expanding.
1936 %    After that we only have to call up =\@preamble= to
1937 %    start the wanted =\halign=.
1938 %    \changes{1994/12/08}{v2.3b}{add \cs{tabularnewline}}
1939 %    \begin{macrocode}
1940   \let\\\@arraycr \let\tabularnewline\\\let\par\@empty \@preamble}
1941 %    \end{macrocode}
1942 % \end{macro}
1944 % \begin{macro}{\arraybackslash}
1945 % \changes{v2.4a}{2003/12/17}{(DPC) Macro added (from tabularx)}
1946 % Restore =\\= for use in array and tabular environment (after
1947 % =\raggedright= etc.).
1948 %    \begin{macrocode}
1949 \def\arraybackslash{\let\\\tabularnewline}
1950 %    \end{macrocode}
1951 % \end{macro}
1953 % \begin{macro}{\extrarowheight}
1954 %    The \textsf{dimen} parameter used above also needs to be
1955 %    allocated.  As a default value we use \textsf{0pt}, to ensure
1956 %    compatibility with standard \LaTeX.
1957 %    \begin{macrocode}
1958 \newdimen \extrarowheight
1959 \extrarowheight=0pt
1960 %    \end{macrocode}
1961 % \end{macro}
1963 % \begin{macro}{\@arstrut}
1964 %    Now the insertion of =\@arstrutbox= through =\@arstut=
1965 %    is easy since we know exactly in which mode \TeX\ is while working
1966 %    on the =\halign= preamble.
1967 %    \begin{macrocode}
1968 \def\@arstrut{\unhcopy\@arstrutbox}
1969 %    \end{macrocode}
1970 % \end{macro}
1973 % \section{The line separator \texttt{\textbackslash\textbackslash}}
1975 % \begin{macro}{\@arraycr}
1976 %    In the macro =\@array= the line separator =\\= is
1977 %    =\let= to the command =\@arraycr=.
1978 %    Its definition starts with a special brace which I have directly
1979 %    copied from the original definition. It is
1980 %    necessary, because the =\futurlet= in =\@ifnextchar=
1981 %    might
1982 %    expand a  following =&= \textsf{token} in a construction like
1983 %    =\\ &=. This would otherwise end the alignment template at a
1984 %    wrong time. On the other hand we have to be careful to avoid
1985 %    producing a real group, i.e.\ ={}=, because the command will also
1986 %    be used for the array environment, i.e.\ in math mode. In that
1987 %    case an extra ={}= would produce an ord atom which could mess up
1988 %    the spacing. For this reason we use a combination that does not
1989 %    really produce a group at all but modifies the master counter so
1990 %    that a =&= will not be considered belonging to the current
1991 %    =\halign= while we are looking for a =*= or =[=.
1992 %    For further information see
1993 %    \cite[Appendix D]{bk:knuth}.
1994 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
1995 %    \begin{macrocode}
1996 \def\@arraycr{\relax\iffalse{\fi\ifnum 0=`}\fi
1997 %    \end{macrocode}
1998 %    Then we test whether the user is using the star form and ignore
1999 %    a possible star (I also disagree with this procedure, because a
2000 %    star does not make any sense here).
2001 %    \begin{macrocode}
2002   \@ifstar \@xarraycr \@xarraycr}
2003 %    \end{macrocode}
2004 % \end{macro}
2006 % \begin{macro}{\@xarraycr}
2007 %    In the command =\@xarraycr= we test if an optional argument
2008 %    exists.
2009 %    \begin{macrocode}
2010 \def\@xarraycr{\@ifnextchar [%
2011 %    \end{macrocode}
2012 %    If it does, we branch out into the macro =\@argarraycr= if
2013 %    not we close the special brace (mentioned above) and end the row
2014 %    of the =\halign= with a =\cr=.
2015 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
2016 %    \begin{macrocode}
2017   \@argarraycr {\ifnum 0=`{}\fi\cr}}
2018 %    \end{macrocode}
2019 % \end{macro}
2022 % \begin{macro}{\@argarraycr}
2023 %    If additional space is requested by the user this case is treated
2024 %    in the macro =\@argarraycr=. First we close the special brace
2025 %    and then we test if the additional space is positive.
2026 % \changes{v2.3c}{1995/04/23}{Avoid adding an ord atom in math}
2027 %    \begin{macrocode}
2028 \def\@argarraycr[#1]{\ifnum0=`{}\fi\ifdim #1>\z@
2029 %    \end{macrocode}
2030 %    If this is the case we create an invisible vertical rule with
2031 %    depth =\dp\@arstutbox=${}+{}$\meta{wanted\ space}.
2032 %    Thus we achieve that all vertical lines specified
2033 %    in the user preamble by a \texttt{|} are now
2034 %    generally drawn.
2035 %    Then the row ends with a =\cr=.
2037 %    If the space is negative we end the row at once with a =\cr=
2038 %    and move back up with a =\vskip=.
2040 %    While testing these macros I found out that the
2041 %    =\endtemplate=
2042 %    created by =\cr= and =&= is something like an
2043 %    =\outer= primitive and therefore it should not appear in
2044 %    incomplete =\if= statements. Thus the following solution was
2045 %    chosen which hides the =\cr= in other macros when \TeX\
2046 %    is skipping conditional text.
2047 % \changes{v2.3c}{1995/04/23}{Use \cs{expandafter}'s in conditional}
2048 %    \begin{macrocode}
2049   \expandafter\@xargarraycr\else
2050   \expandafter\@yargarraycr\fi{#1}}
2051 %    \end{macrocode}
2052 % \end{macro}
2054 % \begin{macro}{\@xargarraycr}
2055 % \begin{macro}{\@yargarraycr}
2056 %    The following macros were already explained above.
2057 %    \begin{macrocode}
2058 \def\@xargarraycr#1{\unskip
2059   \@tempdima #1\advance\@tempdima \dp\@arstrutbox
2060   \vrule \@depth\@tempdima \@width\z@ \cr}
2061 \def\@yargarraycr#1{\cr\noalign{\vskip #1}}
2062 %    \end{macrocode}
2063 % \end{macro}
2064 % \end{macro}
2069 % \section{Spanning several columns}
2071 % \begin{macro}{\multicolumn}
2072 %    If several columns should be held together with a special format
2073 %    the command =\multicolumn= must be used. It has three
2074 %    arguments: the number of columns to be covered; the format for
2075 %    the result column and the actual column entry.
2076 % \changes{v2.3j}{1998/01/29}{Command made \cs{long} to match
2077 %      kernel change for pr/2180}
2078 %    \begin{macrocode}
2079 \long\def\multicolumn#1#2#3{%
2080 %    \end{macrocode}
2081 %    First we combine the given number of columns into a single one;
2082 %    then we start a new block so that the following definition is kept
2083 %    local.
2084 %    \begin{macrocode}
2085    \multispan{#1}\begingroup
2086 %    \end{macrocode}
2087 %    Since a =\multicolumn= should only describe the format of a
2088 %    result column, we redefine =\@addamp= in such a way that one gets
2089 %    an error message if one uses more than one \texttt{c},
2090 %    \texttt{l}, \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in
2091 %    the second argument. One should consider that this definition is
2092 %    local to the build-up of the preamble; an \textsf{array}-- or
2093 %    \textsf{tabular}--environment in the third argument of the
2094 %    =\multicolumn= is therefore worked through correctly as well.
2095 %    \begin{macrocode}
2096    \def\@addamp{\if@firstamp \@firstampfalse \else
2097                 \@preamerr 5\fi}%
2098 %    \end{macrocode}
2099 %    Then we evaluate the second argument with the help of
2100 %    =\@mkpream=.
2101 %    Now we still have to insert the contents of the \textsf{token}
2102 %    register into the =\@preamble=, i.e.\ we have to say
2103 %    =\xdef\@preamble{\@preamble}=. This is achieved shorter by
2104 %    writing:
2105 %    \begin{macrocode}
2106    \@mkpream{#2}\@addtopreamble\@empty
2107 %    \end{macrocode}
2108 %    After the =\@preamble= is created we forget all local
2109 %    definitions and occupations of the \textsf{token} registers.
2110 %    \begin{macrocode}
2111    \endgroup
2112 %    \end{macrocode}
2113 %    In the special situation of  =\multicolumn= =\@preamble=
2114 %    is not needed as preamble for a =\halign= but it is directly
2115 %    inserted into our table. Thus instead of =\sharp=
2116 %    there has to be the column entry (=#3=) wanted by the user.
2117 %    \begin{macrocode}
2118    \def\@sharp{#3}%
2119 %    \end{macrocode}
2120 %    Now we can pass the =\@preamble= to \TeX\ . For safety
2121 %    we start with an =\@arstrut=. This should usually be in the
2122 %    template for the first column however we do not know if this
2123 %    template was overwritten by our =\multicolumn=.
2124 %    We also add a =\null= at the right end to prevent any following
2125 %    =\unskip= (for example from =\\[..]=) to remove the =\tabcolsep=.
2126 % \changes{v2.2e}{1994/06/01}{Added \cs{null}}
2127 %    \begin{macrocode}
2128    \@arstrut \@preamble
2129    \null
2130    \ignorespaces}
2131 %    \end{macrocode}
2132 % \end{macro}
2136 %   \section{The Environment Definitions}
2138 % After these preparations we are able to define the environments. They
2139 % only differ in the initialisations of =\d@llar...=, =\col@sep=
2140 %  and =\@halignto=.
2142 % \begin{macro}{\@halignto}
2143 % \begin{macro}{\d@llarbegin}
2144 % \begin{macro}{\d@llarend}
2145 %    In order to relieve the \textsf{save stack} we assign the
2146 %    replacement texts for =\@halignto= globally. =\d@llar= has to be
2147 %    local since otherwise nested \textsf{tabular} and \textsf{array}
2148 %    environments (via =\multicolumn=) are impossible.
2149 % \changes{v2.0g}{1992/06/18}{`d@llarbegin defined on toplevel.}
2150 %    When the new font selection scheme is in force we have to
2151 %    we surround all =\halign= entries
2152 %    with braces. See remarks in TUGboat 10\#2. Actually we are going
2153 %    to use =\begingroup= and =\endgroup=. However, this is only
2154 %    necessary when we are in text mode. In math the surrounding
2155 %    dollar signs will already serve as the necessary extra grouping
2156 %    level. Therefore we switch the settings of =\d@llarbegin= and
2157 %    =\d@llarend= between groups and dollar signs.
2158 %    \begin{macrocode}
2159 \let\d@llarbegin\begingroup
2160 \let\d@llarend\endgroup
2161 %    \end{macrocode}
2162 % \end{macro}
2163 % \end{macro}
2164 % \end{macro}
2167 % \begin{macro}{\array}
2168 %    Our new definition of =\array= then reads:
2169 % \changes{v2.0d}{1990/08/20}{`d@llar local to preamble.}
2170 %    \begin{macrocode}
2171 \def\array{\col@sep\arraycolsep
2172   \def\d@llarbegin{$}\let\d@llarend\d@llarbegin\gdef\@halignto{}%
2173 %    \end{macrocode}
2174 %    Since there might be an optional argument we call another
2175 %    macro which is also used by the other environments.
2176 %    \begin{macrocode}
2177   \@tabarray}
2178 %    \end{macrocode}
2179 % \end{macro}
2181 % \begin{macro}{\@tabarray}
2182 %    This macro tests for a optional bracket and then calls up
2183 %    =\@array= or =\@array[c]= (as default).
2184 %    \begin{macrocode}
2185 \def\@tabarray{\@ifnextchar[{\@array}{\@array[c]}}
2186 %    \end{macrocode}
2187 % \end{macro}
2190 % \begin{macro}{\tabular}
2191 % \begin{macro}{\tabular*}
2192 %    The environments \textsf{tabular} and \textsf{tabular$*$} differ
2193 %    only in the initialisation of the command =\@halignto=. Therefore
2194 %    we define
2195 %    \begin{macrocode}
2196 \def\tabular{\gdef\@halignto{}\@tabular}
2197 %    \end{macrocode}
2198 %     and analogously for the star form. We evaluate the argument first
2199 %     using =\setlength= so that users of the \texttt{calc} package can
2200 %     write code like\\ =\begin{tabular*}{(\columnwidth-1cm)/2}...=
2201 % \changes{v2.3l}{1998/05/13}{Use \cs{setlength} evaluate arg
2202 %      so that the calc package can be applied here (pr/2793)}
2203 %     \begin{macrocode}
2204 \expandafter\def\csname tabular*\endcsname#1{%
2205        \setlength\dimen@{#1}%
2206        \xdef\@halignto{to\the\dimen@}\@tabular}
2207 %    \end{macrocode}
2208 % \end{macro}
2209 % \end{macro}
2211 % \begin{macro}{\@tabular}
2212 %    The rest of the job is carried out by the =\@tabular= macro:
2213 %    \begin{macrocode}
2214 \def\@tabular{%
2215 %    \end{macrocode}
2216 %    First of all we have to make sure that we start out in
2217 %    \textsf{hmode}.  Otherwise we might find our table dangling by
2218 %    itself on a line.
2219 %    \begin{macrocode}
2220   \leavevmode
2221 %    \end{macrocode}
2222 %    It should be taken into consideration that the macro =\@array=
2223 %    must be called in math mode. Therefore we open a \textsf{box},
2224 %    insert a =$= and then assign the correct values to =\col@sep= and
2225 %    =\d@llar...=.
2226 % \changes{v2.0d}{1990/08/20}{`d@llar local to preamble.}
2227 %    \begin{macrocode}
2228   \hbox \bgroup $\col@sep\tabcolsep \let\d@llarbegin\begingroup
2229                                     \let\d@llarend\endgroup
2230 %    \end{macrocode}
2231 %    Now everything \textsf{tabular} specific is done and we are able to
2232 %    call the =\@tabarray= macro.
2233 %    \begin{macrocode}
2234   \@tabarray}
2235 %    \end{macrocode}
2236 % \end{macro}
2238 % \begin{macro}{\endarray}
2239 %    When the processing of \textsf{array} is finished we have to
2240 %    close the =\halign=
2241 %    and afterwards the surrounding \textsf{box} selected by
2242 %    =\@array=. To save \textsf{token} space we then redefine
2243 %    =\@preamble=
2244 %    because its replacement text isn't longer needed.
2245 %    \begin{macrocode}
2246 \def\endarray{\crcr \egroup \egroup \gdef\@preamble{}}
2247 %    \end{macrocode}
2248 % \end{macro}
2250 % \begin{macro}{\endtabular}
2251 % \begin{macro}{\endtabular*}
2252 %    To end a \textsf{tabular} or \textsf{tabular$*$} environment we
2253 %    call up =\endarray=, close the math mode and then the surrounding
2254 %    =\hbox=.
2255 %    \begin{macrocode}
2256 \def\endtabular{\endarray $\egroup}
2257 \expandafter\let\csname endtabular*\endcsname=\endtabular
2258 %    \end{macrocode}
2259 % \end{macro}
2260 % \end{macro}
2264 %   \section{Last minute definitions}
2267 % If this file is used as a package file we should =\let= all macros
2268 % to =\relax= that were used in the original but are no longer
2269 %  necessary.
2270 %    \begin{macrocode}
2271 \let\@ampacol=\relax        \let\@expast=\relax
2272 \let\@arrayclassiv=\relax   \let\@arrayclassz=\relax
2273 \let\@tabclassiv=\relax     \let\@tabclassz=\relax
2274 \let\@arrayacol=\relax      \let\@tabacol=\relax
2275 \let\@tabularcr=\relax      \let\@@endpbox=\relax
2276 \let\@argtabularcr=\relax   \let\@xtabularcr=\relax
2277 %    \end{macrocode}
2279 % \begin{macro}{\@preamerr}
2280 %    We also have to redefine the error routine =\@preamerr= since
2281 %    new kind of errors are possible.
2282 %    The code for this macro is not perfect yet;
2283 %    it still needs too much memory.
2284 %    \begin{macrocode}
2285 \def\@preamerr#1{\def\@tempd{{..} at wrong position: }%
2286    \PackageError{array}{%
2287    \ifcase #1 Illegal pream-token (\@nextchar): `c' used\or %0
2288     Missing arg: token ignored\or                           %1
2289     Empty preamble: `l' used\or                             %2
2290     >\@tempd token ignored\or                               %3
2291     <\@tempd changed to !{..}\or                            %4
2292     Only one column-spec. allowed.\fi}\@ehc}                %5
2293 %    \end{macrocode}
2294 % \end{macro}
2298 % \section
2299 %   [Defining your own column specifiers]
2300 %   {Defining your own column specifiers\footnotemark}
2302 % \footnotetext{The code and the documentation in this section was
2303 %   written by David. So far only the code from newarray was plugged
2304 %   into array so that some parts of the documentation still claim
2305 %   that this is newarray and even worse, some parts of the code are
2306 %   unnecessarily doubled. This will go away in a future release. For
2307 %   the moment we thought it would be more important to bring both
2308 %   packages together.}
2309 % \changes{v2.1a}{1992/07/03}{Newcolumn stuff added}
2311 % \DeleteShortVerb{\=}
2312 % \MakeShortVerb{\"}
2314 %  \begin{macro}{\newcolumn}
2315 %    In \texttt{newarray.sty} the macro for specifying new columns was
2316 %    named "\newcolumn". When the functionality was added to
2317 %    \texttt{array.sty} the command was renamed "\newcolumntype".
2318 %    Initially both names were supported, but now (In versions of this
2319 %    package distributed for \LaTeXe) the old name is not defined.
2320 % \changes{v2.2a}{1994/02/03}{Now made `newcolumn an error}
2321 % \changes{v2.2a}{1994/02/04}{Removed `newcolumn}
2322 %    \begin{macrocode}
2323 %<*ncols>
2324 %    \end{macrocode}
2325 %  \end{macro}
2327 % \begin{macro}{\newcolumntype}
2328 % \changes{v2.1b}{1992/06/07}{Macro renamed from `newcolumn} As
2329 % described above, the "\newcolumntype" macro gives users the chance
2330 % to define letters, to be used in the same way as the primitive
2331 % column specifiers, `c' `p' etc.
2332 %    \begin{macrocode}
2333 \def\newcolumntype#1{%
2334 %    \end{macrocode}
2335 % "\NC@char" was added in V2.01 so that active characters, like "@" in
2336 % AMS\LaTeX\ may be used. This trick was stolen from \texttt{array.sty}
2337 % 2.0h. Note that we need to use the possibly active token,
2338 % "#1", in several places, as that is the token that actually
2339 % appears in the preamble argument.
2340 %    \begin{macrocode}
2341   \edef\NC@char{\string#1}%
2342 %    \end{macrocode}
2343 % First we check whether there is already a definition for this column.
2344 % Unlike "\newcommand" we give a warning rather than an error if it is
2345 % defined. If it is a new column, add "\NC@do" \meta{column} to
2346 % the list "\NC@list".
2347 %    \begin{macrocode}
2348   \@ifundefined{NC@find@\NC@char}%
2349     {\@tfor\next:=<>clrmbp@!|\do{\if\noexpand\next\NC@char
2350         \PackageWarning{array}%
2351                        {Redefining primitive column \NC@char}\fi}%
2352      \NC@list\expandafter{\the\NC@list\NC@do#1}}%
2353     {\PackageWarning{array}{Column \NC@char\space is already defined}}%
2354 %    \end{macrocode}
2355 % Now we define a macro with an argument delimited by the new column
2356 % specifier, this is used to find occurrences of this specifier in the
2357 % user preamble.
2358 %    \begin{macrocode}
2359   \@namedef{NC@find@\NC@char}##1#1{\NC@{##1}}%
2360 %    \end{macrocode}
2361 % If an optional argument was not given, give a default argument of 0.
2362 %    \begin{macrocode}
2363   \@ifnextchar[{\newcol@{\NC@char}}{\newcol@{\NC@char}[0]}}
2364 %    \end{macrocode}
2365 % \end{macro}
2366 % \begin{macro}{\newcol@}
2367 % We can now define the macro which does the rewriting,
2368 % "\@reargdef" takes the same arguments as "\newcommand", but
2369 % does not check that the command is new. For a column, say `D' with
2370 % one argument, define a command "\NC@rewrite@D" with one
2371 % argument, which recursively calls "\NC@find" on the user preamble
2372 % after replacing the first token or group with the replacement text
2373 % specified in the "\newcolumntype" command. "\NC@find" will find the
2374 % next occurrence of `D' as it will be "\let" equal to
2375 % "\NC@find@D" by "\NC@do".
2376 %    \begin{macrocode}
2377 \def\newcol@#1[#2]#3{\expandafter\@reargdef
2378      \csname NC@rewrite@#1\endcsname[#2]{\NC@find#3}}
2379 %    \end{macrocode}
2380 % \end{macro}
2381 % \begin{macro}{\NC@}
2382 % Having found an occurrence of the new column, save the preamble
2383 % before the column in "\@temptokena", then check to see if we
2384 % are at the end of the preamble. (A dummy occurrence of the column
2385 % specifier will be placed at the end of the preamble by "\NC@do".
2386 %    \begin{macrocode}
2387 \def\NC@#1{%
2388   \@temptokena\expandafter{\the\@temptokena#1}\futurelet\next\NC@ifend}
2389 %    \end{macrocode}
2390 % \end{macro}
2391 % \begin{macro}{\NC@ifend}
2392 % We can tell that we are at the end as "\NC@do" will place a "\relax"
2393 % after the dummy column.
2394 %    \begin{macrocode}
2395 \def\NC@ifend{%
2396 %    \end{macrocode}
2397 % If we are at the end, do nothing. (The whole preamble will now be in
2398 % "\@temptokena".)
2399 %    \begin{macrocode}
2400   \ifx\next\relax
2401 %    \end{macrocode}
2402 % Otherwise set the flag "\if@tempswa", and rewrite the column.
2403 % "\expandafter" introduced 1n V2.01
2404 %    \begin{macrocode}
2405     \else\@tempswatrue\expandafter\NC@rewrite\fi}
2406 %    \end{macrocode}
2407 % \end{macro}
2408 % \begin{macro}{\NC@do}
2409 % If the user has specified `C' and `L' as new columns, the list of
2410 % rewrites (in the token register "\NC@list") will look like
2411 % "\NC@do *" "\NC@do C" "\NC@do L".
2412 % So we need to define "\NC@do" as a one argument macro which
2413 % initialises the rewriting of the specified column. Let us assume that
2414 % `C' is the argument.
2415 %    \begin{macrocode}
2416 \def\NC@do#1{%
2417 %    \end{macrocode}
2418 % First we let "\NC@rewrite" and "\NC@find" be
2419 % "\NC@rewrite@C" and "\NC@find@C" respectively.
2420 %    \begin{macrocode}
2421   \expandafter\let\expandafter\NC@rewrite
2422     \csname NC@rewrite@\string#1\endcsname
2423   \expandafter\let\expandafter\NC@find
2424     \csname NC@find@\string#1\endcsname
2425 %    \end{macrocode}
2426 % Clear the token register "\@temptokena" after putting the present
2427 % contents of the register in front of the token "\NC@find". At the
2428 % end we place the tokens `"C\relax"' which "\NC@ifend" will use
2429 % to detect the end of the user preamble.
2430 %    \begin{macrocode}
2431   \expandafter\@temptokena\expandafter{\expandafter}%
2432         \expandafter\NC@find\the\@temptokena#1\relax}
2433 %    \end{macrocode}
2434 % \end{macro}
2436 % \begin{macro}{\showcols}
2437 % This macro is useful for debugging "\newcolumntype" specifications,
2438 % it is the equivalent of the primitive "\show" command for macro
2439 % definitions.  All we need to do is locally redefine "\NC@do" to take
2440 % its argument (say `C') and then "\show" the (slightly modified)
2441 % definition of "\NC@rewrite@C". Actually as the the list always
2442 % starts off with "\NC@do *" and we do not want to print the
2443 % definition of the $*$-form, define "\NC@do" to throw away the first
2444 % item in the list, and then redefine itself to print the rest of the
2445 % definitions.
2446 %    \begin{macrocode}
2447 \def\showcols{{\def\NC@do##1{\let\NC@do\NC@show}\the\NC@list}}
2448 %    \end{macrocode}
2449 % \end{macro}
2450 % \begin{macro}{\NC@show}
2451 % If the column `C' is defined as above, then
2452 % "\show\NC@rewrite@C" would output\\
2453 % "\long macro: ->\NC@find >{$}c<{$}".
2454 % We want to strip the "long macro: ->" and the "\NC@find". So first we
2455 % use "\meaning" and then apply the macro "\NC@strip" to the tokens so
2456 % produced and then "\typeout" the required string.
2457 %    \begin{macrocode}
2458 \def\NC@show#1{%
2459   \typeout{Column #1\expandafter\expandafter\expandafter\NC@strip
2460   \expandafter\meaning\csname NC@rewrite@#1\endcsname\@@}}
2461 %    \end{macrocode}
2462 % \end{macro}
2463 % \begin{macro}{\NC@strip}
2464 % Delimit the arguments to "\NC@strip" with `\texttt{:}', `\texttt{->}',
2465 % a space, and "\@@" to pull out the required parts of the output from
2466 % "\meaning".
2467 %    \begin{macrocode}
2468 \def\NC@strip#1:#2->#3 #4\@@{#2 -> #4}
2469 %    \end{macrocode}
2470 % \end{macro}
2471 % \begin{macro}{\NC@list}
2472 % Allocate the token register used for the rewrite list.
2473 %    \begin{macrocode}
2474 \newtoks\NC@list
2475 %    \end{macrocode}
2476 % \end{macro}
2478 % \subsection{The $*$--form}
2479 % We view the $*$-form as a slight generalisation of the system
2480 % described in the previous subsection. The idea is to define a $*$
2481 % column by a command of the form:
2482 % \begin{verbatim}
2483 % \newcolumntype{*}[2]{%
2484 %    \count@=#1\ifnum\count@>0
2485 %       \advance\count@ by -1 #2*{\count@}{#2}\fi}
2486 % \end{verbatim}
2487 % \begin{macro}{\NC@rewrite@*}\label{NC@rewrite@*}
2488 % \changes{v2.4b}{2005/08/23}{Fix occasional spurious space (PR/3755)}
2489 % This does not work however as "\newcolumntype" takes great care not
2490 % to expand anything in the preamble, and so the "\if" is never
2491 % expanded. "\newcolumntype" sets up various other parts of the
2492 % rewrite correctly though so we can define:
2493 %    \begin{macrocode}
2494 \newcolumntype{*}[2]{}
2495 %    \end{macrocode}
2496 % Now we must correct the definition of "\NC@rewrite@*". The
2497 % following is probably more efficient than a direct translation of
2498 % the idea sketched above, we do not need to put a $*$ in the preamble
2499 % and call the rewrite recursively, we can just put "#1" copies of
2500 % "#2" into "\@temptokena". (Nested $*$ forms will be expanded
2501 % when the whole rewrite list is expanded again, see "\@mkpream")
2502 %    \begin{macrocode}
2503 \long\@namedef{NC@rewrite@*}#1#2{%
2504 %    \end{macrocode}
2505 % Store the number.
2506 %    \begin{macrocode}
2507   \count@#1\relax
2508 %    \end{macrocode}
2509 % Put "#1" copies of "#2" in the token register.
2510 %    \begin{macrocode}
2511   \loop
2512   \ifnum\count@>\z@
2513   \advance\count@\m@ne
2514   \@temptokena\expandafter{\the\@temptokena#2}%
2515   \repeat
2516 %    \end{macrocode}
2517 % "\NC@do" will ensure that "\NC@find" is "\let" equal
2518 % to "\NC@find@*".
2519 %    \begin{macrocode}
2520   \NC@find}
2521 %    \end{macrocode}
2522 % \end{macro}
2524 % \subsection{Modifications to internal macros of \texttt{array.sty}}
2526 % \begin{macro}{\@xexpast}
2527 % \begin{macro}{\@xexnoop}
2528 %    These macros are used to expand $*$-forms in
2529 %    \texttt{array.sty}. "\let" them to "\relax" to save space.
2530 %    \begin{macrocode}
2531 \let\@xexpast\relax
2532 \let\@xexnoop\relax
2533 %    \end{macrocode}
2534 % \end{macro}
2535 % \end{macro}
2537 % \begin{macro}{\save@decl}
2538 % We do not assume that the token register is free, we add the new
2539 % declarations to the front of the register. This is to allow user
2540 % preambles of the form, ">{foo}>{bar}..". Users are not encouraged to
2541 % enter such expressions directly, but they may result from the
2542 % rewriting of "\newcolumntype"'s.
2543 %    \begin{macrocode}
2544 \def\save@decl{\toks \count@ = \expandafter\expandafter\expandafter
2545                   {\expandafter\@nextchar\the\toks\count@}}
2546 %    \end{macrocode}
2547 % \end{macro}
2548 % \begin{macro}{\@mkpream}
2549 %    The main modification to "\@mkpream" is to replace the call to
2550 %    "\@xexpast" (which expanded $*$-forms) by a loop which expands
2551 %    all "\newcolumntype" specifiers.
2552 %    \begin{macrocode}
2553 \def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue
2554    \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax
2555 %    \end{macrocode}
2556 %    Now we remove possible  $*$-forms and user-defined column
2557 %    specifiers in the user preamble by repeatedly executing the list
2558 %    "\NC@list" until the re-writes have no more effect. The
2559 %    expanded preamble will then be in the token register
2560 %    "\@temptokena". Actually we need to know at this point that
2561 %    this is not "\toks0".
2562 %    \begin{macrocode}
2563    \@temptokena{#1}\@tempswatrue
2564    \@whilesw\if@tempswa\fi{\@tempswafalse\the\NC@list}%
2565 %    \end{macrocode}
2566 %    Afterwards we initialize all registers and macros, that we need
2567 %    for the build-up of the preamble.
2568 %    \begin{macrocode}
2569    \count@\m@ne
2570    \let\the@toks\relax
2571    \prepnext@tok
2572 %    \end{macrocode}
2573 % Having expanded all tokens defined using "\newcolumntype" (including
2574 % "*"), we evaluate the remaining tokens, which are saved in
2575 % "\@temptokena".  We use the \LaTeX--macro "\@tfor" to inspect each
2576 % token in turn.
2577 %    \begin{macrocode}
2578    \expandafter \@tfor \expandafter \@nextchar
2579     \expandafter :\expandafter =\the\@temptokena \do
2580 %    \end{macrocode}
2581 % "\@testpatch" does not take an argument since \texttt{array.sty} 2.0h.
2582 %    \begin{macrocode}
2583    {\@testpach
2584    \ifcase \@chclass \@classz \or \@classi \or \@classii
2585      \or \save@decl \or \or \@classv \or \@classvi
2586      \or \@classvii \or \@classviii
2587 %    \end{macrocode}
2588 %    In \texttt{newarray.sty} class 9 is equivalent to class 10.
2589 %    \begin{macrocode}
2590      \or \@classx
2591      \or \@classx \fi
2592    \@lastchclass\@chclass}%
2593    \ifcase\@lastchclass
2594    \@acol \or
2595    \or
2596    \@acol \or
2597    \@preamerr \thr@@ \or
2598    \@preamerr \tw@ \@addtopreamble\@sharp \or
2599    \or
2600    \else  \@preamerr \@ne \fi
2601    \def\the@toks{\the\toks}}
2602 %    \end{macrocode}
2603 % \end{macro}
2605 % \begin{macro}{\@classix}
2606 %    \texttt{array.sty} does not allow repeated \texttt{>}
2607 %    declarations for the same column. This is allowed in
2608 %    \texttt{newarray.sty} as documented in the introduction. Removing
2609 %    the test for this case makes class 9 equivalent to class 10, and
2610 %    so this macro is redundant. It is "\let" to "\relax" to save
2611 %    space.
2612 %    \begin{macrocode}
2613 \let\@classix\relax
2614 %    \end{macrocode}
2615 % \end{macro}
2617 % \begin{macro}{\@classviii}
2618 %    In \texttt{newarray.sty} explicitly allow class 2, as repeated
2619 %    \texttt{<} expressions are accepted by this package.
2620 %    \begin{macrocode}
2621 \def\@classviii{\ifnum \@lastchclass >\z@\ifnum\@lastchclass=\tw@\else
2622       \@preamerr 4\@chclass 6 \@classvi \fi\fi}
2623 %    \end{macrocode}
2624 % \end{macro}
2626 % \begin{macro}{\@classv}
2627 % Class 5 is \texttt{@}-expressions (and is also called by class 1)
2628 % This macro was incorrect in Version~1. Now we do not expand the
2629 % "@"-expression, but instead explicitly replace an
2630 % "\extracolsep" command by an assignment to "\tabskip" by a
2631 % method similar to the "\newcolumntype" system described above.
2632 % "\d@llarbegin" "\d@llarend" were introduced in V2.01 to match
2633 % \texttt{array.sty} 2.0h.
2634 %    \begin{macrocode}
2635 \def\@classv{\save@decl
2636    \expandafter\NC@ecs\@nextchar\extracolsep{}\extracolsep\@@@
2637    \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}%
2638    \prepnext@tok}
2639 %    \end{macrocode}
2640 % \end{macro}
2642 % \begin{macro}{\NC@ecs}
2643 % Rewrite the first occurrence of "\extracolsep{1in}" to
2644 % "\tabskip1in\relax". As a side effect discard any tokens after a
2645 % second "\extracolsep", there is no point in the user entering two of
2646 % these commands anyway, so this is not really a restriction.
2647 %    \begin{macrocode}
2648 \def\NC@ecs#1\extracolsep#2#3\extracolsep#4\@@@{\def\@tempa{#2}%
2649   \ifx\@tempa\@empty\else\toks\count@={#1\tabskip#2\relax#3}\fi}
2650 %</ncols>
2651 %    \end{macrocode}
2652 % \end{macro}
2655 % \subsection{Support for the \texttt{delarray.sty}}
2657 % The \texttt{delarray.sty} package  extends the array syntax by
2658 % supporting the notation of delimiters. To this end we extend the
2659 % array parsing mechanism to include a hook which can be used by this
2660 % (or another) package to do some additional parsing.
2662 % \begin{macro}{\@tabarray}
2663 %    This macro tests for an optional bracket and then calls up
2664 %    "\@@array" or "\@@array[c]" (as default).
2665 %    \begin{macrocode}
2666 %<*package>
2667 \def\@tabarray{\@ifnextchar[{\@@array}{\@@array[c]}}
2668 %    \end{macrocode}
2669 % \end{macro}
2670 % \begin{macro}{\@@array}
2671 %    This macro tests could then test an optional delimiter before the
2672 %    left brace of the main preamble argument. Here in the main package
2673 %    it simply is let to be "\@array".
2674 %    \begin{macrocode}
2675 \let\@@array\@array
2676 %    \end{macrocode}
2677 % \end{macro}
2679 % \begin{macro}{\endarray}
2680 % \begin{macro}{\@arrayright}
2681 %    We have to declare the hook we put into "\@array" above.
2682 %    A similar hook `"\@arrayright"' will be inserted into the
2683 %    "\endarray" to gain control. Both defaults to empty.
2684 %    \begin{macrocode}
2685 \def\endarray{\crcr \egroup \egroup \@arrayright \gdef\@preamble{}}
2686 \let\@arrayleft\@empty
2687 \let\@arrayright\@empty
2688 %    \end{macrocode}
2689 % \end{macro}
2690 % \end{macro}
2692 % \subsection{Support for \texttt{\textbackslash firsthline} and
2693 %             \texttt{\textbackslash lasthline}}
2695 % The Companion~\cite[p.137]{bk:GMS94} suggests two additional
2696 % commands to control the alignments in case of tabulars with
2697 % horizontal lines. They are now added to this package.
2699 %  \begin{macro}{\extratabsurround}
2700 %    The extra space around a table when "\firsthline" or "\lasthline"
2701 %    are used.
2702 %    \begin{macrocode}
2703 \newlength{\extratabsurround}
2704 \setlength{\extratabsurround}{2pt}
2705 %    \end{macrocode}
2706 %  \end{macro}
2708 % \begin{macro}{\backup@length}
2709 %    This register will be used internally by "\firsthline" and
2710 %    "\lasthline".
2711 %    \begin{macrocode}
2712 \newlength{\backup@length}
2713 %    \end{macrocode}
2714 % \end{macro}
2716 % \begin{macro}{\firsthline}
2717 % \changes{v2.3h}{1996/05/25}{Complete reimplementation}
2718 %    This code can probably be improved but for the moment it should
2719 %    serve.
2721 %    We start by producing a single tabular row without any visible
2722 %    content that will produce the external reference point in case
2723 %    "[t]" is used.
2724 %    \begin{macrocode}
2725 \newcommand{\firsthline}{%
2726   \multicolumn1c{%
2727 %    \end{macrocode}
2728 %    Within this row we calculate "\backup@length" to be the height
2729 %    plus depth of a standard line. In addition we have to add the
2730 %    width of the "\hline", something that was forgotten in the
2731 %    original definition.
2732 %    \begin{macrocode}
2733     \global\backup@length\ht\@arstrutbox
2734     \global\advance\backup@length\dp\@arstrutbox
2735     \global\advance\backup@length\arrayrulewidth
2736 %    \end{macrocode}
2737 %    Finally we do want to make the height of this first line be a bit
2738 %    larger than usual, for this we place the standard array strut
2739 %    into it but raised by "\extratabsurround"
2740 %    \begin{macrocode}
2741      \raise\extratabsurround\copy\@arstrutbox
2742 %    \end{macrocode}
2743 %    Having done all this we end the line and back up by the value of
2744 %    "\backup@length" and then finally place our "\hline". This should
2745 %    place the line exactly at the right place but keep the reference
2746 %    point of the whole tabular at the baseline of the first row.
2747 %    \begin{macrocode}
2748     }\\[-\backup@length]\hline
2750 %    \end{macrocode}
2751 % \end{macro}
2753 % \begin{macro}{\lasthline}
2754 % \changes{v2.3h}{1996/05/25}{Complete reimplementation}
2755 %    For "\lasthline" the situation is even worse and I got it
2756 %    completely wrong initially.
2758 %    The problem in this case is that if the optional argument "[b]"
2759 %    is used we do want the reference point of the tabular be at the
2760 %    baseline of the last row but at the same time do want the the
2761 %    depth of this last line increased by "\extratabsurround" without
2762 %    changing the placement "\hline".
2764 %    We start by placing the rule followed by an invisible row.
2765 %    \begin{macrocode}
2766 \newcommand{\lasthline}{\hline\multicolumn1c{%
2767 %    \end{macrocode}
2768 %    We now calculate "\backup@length" to be the height and depth of
2769 %    two lines plus the width of the rule.
2770 %    \begin{macrocode}
2771     \global\backup@length2\ht\@arstrutbox
2772     \global\advance\backup@length2\dp\@arstrutbox
2773     \global\advance\backup@length\arrayrulewidth
2774 %    \end{macrocode}
2775 %    This will bring us back to the baseline of the second last row:
2776 %    \begin{macrocode}
2777     }\\[-\backup@length]%
2778 %    \end{macrocode}
2779 %    Thus if we now add another invisible row the reference point of
2780 %    that row will be at the baseline of the last row (and will be the
2781 %    reference for the whole tabular). Since this row is invisible we
2782 %    can enlarge its depth by the desired amount.
2783 %    \begin{macrocode}
2784     \multicolumn1c{%
2785        \lower\extratabsurround\copy\@arstrutbox
2786        }%
2788 %    \end{macrocode}
2789 % \end{macro}
2792 % \subsection{Getting the spacing around rules right}
2794 %    Beside a larger functionality \texttt{array.sty} has one
2795 %    important difference to the standard \texttt{tabular} and
2796 %    \texttt{array} environments: horizontal and vertical rules make a
2797 %    table larger or wider, e.g., \verb=\doublerulesep= really denotes
2798 %    the space between two rules and isn't measured from the middle of
2799 %    the rules.
2801 %  \begin{macro}{\@xhline}
2802 %    For vertical rules this is implemented by the definitions above,
2803 %    for horizontal rules we have to take out the backspace.
2804 % \changes{v2.3d}{1995/11/19}{fix space between double rules pr/1945}
2805 %    \begin{macrocode}
2806 \CheckCommand*\@xhline{\ifx\reserved@a\hline
2807                \vskip\doublerulesep
2808                \vskip-\arrayrulewidth
2809              \fi
2810       \ifnum0=`{\fi}}
2811 \renewcommand*\@xhline{\ifx\reserved@a\hline
2812                \vskip\doublerulesep
2813              \fi
2814       \ifnum0=`{\fi}}
2815 %</package>
2816 %    \end{macrocode}
2817 %  \end{macro}
2819 % \PrintIndex
2820 % \PrintChanges
2822 % \Finale
2824 \endinput