From 5c9613c8e5ee20a6d2a318def5ec195d866ef734 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 12 Dec 2018 21:24:10 +0000 Subject: memoir (12dec18) git-svn-id: svn://tug.org/texlive/trunk@49394 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/source/latex/memoir/memoir.dtx | 5398 +++++++++++----------- 1 file changed, 2739 insertions(+), 2659 deletions(-) (limited to 'Master/texmf-dist/source/latex/memoir/memoir.dtx') diff --git a/Master/texmf-dist/source/latex/memoir/memoir.dtx b/Master/texmf-dist/source/latex/memoir/memoir.dtx index 3bf13b2e751..2fd0bb32a55 100644 --- a/Master/texmf-dist/source/latex/memoir/memoir.dtx +++ b/Master/texmf-dist/source/latex/memoir/memoir.dtx @@ -20,7 +20,7 @@ % This work consists of the files listed in the README file. % % \fi -% \CheckSum{31006} +% \CheckSum{31004} % % \changes{v0.1}{2001/05/20}{First public alpha release} % \changes{v0.2}{2001/06/03}{First beta release} @@ -115,7 +115,9 @@ % \changes{v3.7e}{2015/07/08}{Per request from LaTeX Team, etex is not % autoloaded on newer kernels} % \changes{v3.7f}{2016/05/16}{Maintenance, luatex85 and booktabs update} -% +% +% \changes{v3.7h}{2018/12/12}{Maintenance, removing some emulated packages} +% % \def\dtxfile{memoir.dtx} % % \def\fileversion{v0.1} \def\filedate{2001/05/20} @@ -169,7 +171,8 @@ % \def\fileversion{v3.7d} \def\filedate{2015/04/23} % \def\fileversion{v3.7e} \def\filedate{2015/07/08} % \def\fileversion{v3.7f} \def\filedate{2016/05/16} -% \def\fileversion{v3.7g} \def\filedate{2018/04/04} ^^A remember to fix +% \def\fileversion{v3.7g} \def\filedate{2018/04/04} +% \def\fileversion{v3.7h} \def\filedate{2018/12/12} ^^A remember to fix % \title{The LaTeX \Lpack{memoir} class for configurable book % typesetting: Source code\thanks{This % file (\texttt{\dtxfile}) has version number \fileversion, last revised @@ -400,11 +403,11 @@ % Announce the name, option files and version for LaTeX2e files: % \begin{macrocode} %\ProvidesClass{memoir}% -% [2018/04/04 v3.7g configurable book, report, article document class] +% [2018/12/12 v3.7h configurable book, report, article document class] % \end{macrocode} % In the manual it is useful to know the current version. % \begin{macrocode} -%\newcommand\memversion{v3.7g, 2018/04/04} +%\newcommand\memversion{v3.7h, 2018/12/12} %<9pt>\ProvidesFile{mem9.clo}% %<9pt> [2008/01/30 v0.4 memoir class 9pt size option] %<10pt>\ProvidesFile{mem10.clo}% @@ -5986,7 +5989,7 @@ The material used in the footer is too large^^J% (\the\mem@maxfootheight) for the given foot skip (\the\footskip), it is recommended to^^J% - either increase the foot skip or redesign the fotoer^^J% + either increase the foot skip or redesign the footer^^J% (in both cases you will find help in the memoir manual).% } % \end{macrocode} @@ -7192,6 +7195,7 @@ % \end{macro} % % \begin{macro}{\SingleSpacing} +% \begin{macro}{\SingleSpacing*} % \cs{SingleSpacing} starts single spacing. (In package was \cs{singlespacing}). % \changes{v3.6g}{2010/09/19}{Added reset of the float and page note spacings} % \begin{macrocode} @@ -7199,12 +7203,21 @@ \setSpacing{\m@m@singlespace}% \edef\m@m@footnote@spacing{\baselinestretch}% \edef\m@m@float@spacing{\baselinestretch}% - \vskip\baselineskip% correction for coming into single spacing +% \end{macrocode} +% \changes{v3.7h}{2018/09/19}{Added the ifstar and \cs{@noocument}} +% We can have a strange interaction with \Lpack{tikz} if this +% \cs{vskip} is emitted in the preamble. We use a trick (via David +% Carlisle) to check whether we are in the preamble, and only emit the +% vskip if we are not. \cs{@ifstar} added to let the user disable the +% vskip if needed. +% \begin{macrocode} + \@ifstar{}{\ifx\@nodocument\relax\vskip\baselineskip\fi}% correction for coming into single spacing } \SingleSpacing % \end{macrocode} % \end{macro} +% \end{macro} % % % \begin{macro}{\@OnehalfSpacing} @@ -14815,2072 +14828,2087 @@ % \end{macro} % % -% \section{Array and tabular} +% \section{Array and tabularx} % % \subsection{Array}% % -% The description and code are essentially copied from the \Lpack{array} -% package~\cite{ARRAY}. -% -% \begin{macrocode} - -%%%%%%%%%% Array package code %%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%% With acknowledgements to %%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%% Frank Mittelbach & David Carlisle %%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%% Copy corresponds to array.sty 2016/10/06 v2.4d %%%%%%%%% -% \end{macrocode} -% \changes{v3.7g}{2018/03/05}{Updated the embedded copy of the -% \Lpack{array} package to version 2.4d, 2016/10/06} -% \begin{dlf} -% dlf: The \Lpack{array} package has redundant code (caused by a -% quick mashing of and earlier \Lpack{array} version and the -% \Lpack{newaray} package). In thus update (2018/03/05) this -% redundant code is \emph{not} removed as it makes it very hard to -% see where there are class changes to the \Lpack{array} code, and -% when stuff is simply removed. We'll leave it up to the LaTeXteam to -% clean up the \Lpack{array} code at some point. -% -% The following is a carbon copy of the DTX code from -% \verb|array.dtx|, package specific \cs{changes} lines have been -% removed, and we have made any error/warning messages class specific, -% instead of package specific. -% \end{dlf} -% - -% \subsubsection{The construction of the preamble} -% -% It is obvious that those environments will consist mainly of an -% \verb=\halign=, because \TeX\ typesets tables using this primitive. -% That is why we will now take a look at the algorithm which determines -% a preamble for a \verb=\halign= starting with a given user preamble -% using the options mentioned above. -% -% The most interesting macros of this implementation are without doubt -% those which are responsible for the construction of the preamble for -% the \verb=\halign=. The underlying algorithm was developed by -% \textsc{Lamport} (resp.\ \textsc{Knuth}, see texhax V87\#??), and it -% has been extended and improved. -% -% The user preamble will be read \textsf{token} by \textsf{token}. A -% \textsf{token} is a single character like \texttt{c} or a block -% enclosed in \verb={...}=. For example the preamble of -% \verb=\begin{tabular}=\linebreak[0]\verb={lc||c@{\hspace{1cm}}}= consists of -% the \textsf{token} \texttt{l}, \texttt{c}, \texttt{|}, \texttt{|}, -% \texttt{@} and \verb=\hspace{1cm}=. -% -% The currently used \textsf{token} and the one, used before, are needed -% to decide on how the construction of the preamble has to be -% continued. -% In the example mentioned above the \texttt{l} causes the preamble -% to begin with \verb=\hskip\tabcolsep=. Furthermore -% \verb=# \hfil= would be appended to define a flush left column. -% The next \textsf{token} is a \texttt{c}. Because it was preceded by an -% \texttt{l} it generates a new column. This is done with -% \verb=\hskip \tabcolsep & \hskip \tabcolsep=. The column which is to -% be centered will be appended with \verb=\hfil # \hfil=. -% The \textsf{token} \texttt{|} would then add a space of -% \verb=\hskip \tabcolsep= -% and a vertical line because the last -% \textsf{tokens} was a \texttt{c}. -% The following \textsf{token} \texttt{|} would only add a space -% \verb=\hskip \doublerulesep= because it was preceded by the -% \textsf{token} \texttt{|}. We will not discuss our example further but -% rather take a look at the general case of constructing preambles. -% -% The example shows that the desired preamble for the -% \verb=\halign= can be constructed as soon as the action of all -% combinations -% of the preamble \textsf{tokens} are specified. There are 18 such -% \textsf{tokens} -% so we have $19 \cdot 18 = 342$ combinations if we count the -% beginning of -% the preamble as a special \textsf{token}. Fortunately, there are many -% combinations which generate the same spaces, so we can define -% \textsf{token} classes. We will identify a -% \textsf{token} within a class with a number, so we can insert the -% formatting (for example of a column). -% Table~\ref{tab:Klassen} lists all \textsf{token} classes and -% their corresponding numbers. -% \begin{table}[ht] -% \begin{center} -% \begin{tabular}[t]{>{\ttfamily}ccc} -% \textsf{token} & \verb=\@chclass= & \verb=\@chnum= \\[2mm] -% c & 0 & 0 \\ -% l & 0 & 1 \\ -% r & 0 & 2 \\ -% p-arg & 0 & 3 \\ -% t-arg & 0 & 4 \\ -% b-arg & 0 & 5 \\ -% | & 1 & 0 \\ -% !-arg & 1 & 1 \\ -% <-arg & 2 & --- \\ -% >-arg & 3 & --- -% \end{tabular} -% \kern3mm \vrule \kern3mm% -% \begin{tabular}[t]{>{\ttfamily}ccc} -% \textsf{token} & \verb=\@chclass= & \verb=\@chnum= \\[2mm] -% Start & 4 & --- \\ -% @-arg & 5 & --- \\ -% ! & 6 & --- \\ -% @ & 7 & --- \\ -% < & 8 & --- \\ -% > & 9 & --- \\ -% p & 10 & 3 \\ -% t & 10 & 4 \\ -% b & 10 & 5 -% \end{tabular} -% \end{center} -% \caption{Classes of preamble \textsf{tokens}} -% \label{tab:Klassen} -% \end{table} -% -% -% \begin{macro}{\@chclass} -% \begin{macro}{\@chnum} -% \begin{macro}{\@lastchclass} -% The class and the number of the current \textsf{token} are saved in -% the -% \textsf{count} registers \verb=\@chclass= -% and \verb=\@chnum=, while the class of the previous -% \textsf{token} is stored in the -% \textsf{count} register \verb=\@lastchclass=. -% All of the mentioned registers are already allocated in -% \texttt{latex.tex}, -% which is the reason why the following three lines of code are -% commented out. -% Later throughout the text I will not mention it again explicitly -% whenever I use a \verb=%= sign. These parts are already defined in -% \texttt{latex.tex}. -% \begin{macrocode} -% \newcount \@chclass -% \newcount \@chnum -% \newcount \@lastchclass -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% -% -% \begin{macro}{\@addtopreamble} -% We will save the already constructed preamble for -% the \verb=\halign= -% in the global macro \verb=\@preamble=. This will then be -% enlarged with -% the command \verb=\@addtopreamble=. -% \begin{macrocode} -\def\@addtopreamble#1{\xdef\@preamble{\@preamble #1}} -% \end{macrocode} -% \end{macro} -% -% -% -% -% -% \subsubsection{The character class of a \textsf{token}} -% -% \begin{macro}{\@testpach} -% With the help of \verb=\@lastchclass= we can now define a macro -% which determines the class and the number of a given preamble -% \textsf{token} -% and assigns them to the registers -% \verb=\@chclass= and \verb=\@chnum=. -% \begin{macrocode} -\def\@testpach{\@chclass -% \end{macrocode} -% First we deal with the cases in which the \textsf{token} -% (\verb=#1=) is the argument of \texttt{!}, \texttt{@}, \texttt{<} or -% \texttt{>}. We can see this from the value of \verb=\@lastchclass=: -% \begin{macrocode} - \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else - \ifnum \@lastchclass=7 5 \else - \ifnum \@lastchclass=8 \tw@ \else - \ifnum \@lastchclass=9 \thr@@ -% \end{macrocode} -% Otherwise we will assume that the \textsf{token} belongs to the -% class $0$ -% and assign the corresponding number to \verb=\@chnum= if our -% assumption is correct. -% \begin{macrocode} - \else \z@ -% \end{macrocode} -% If the last \textsf{token} was a \texttt{p}, \texttt{m} or a -% \texttt{b}, \verb=\@chnum= already has the right value. This is the -% reason for the somewhat curious choice of the \textsf{token} -% numbers in class $10$. -% \begin{macrocode} - \ifnum \@lastchclass = 10 \else -% \end{macrocode} -% Otherwise we will check if \verb=\@nextchar= is either a \texttt{c}, -% \texttt{l} or an \texttt{r}. Some applications change the -% catcodes of certain characters like ``\texttt{@}'' in -% \texttt{amstex.sty}. As a result the tests below would fail since -% they assume non-active character tokens. Therefore we evaluate -% \verb=\@nextchar= once thereby turning the first token of its -% replacement text into a char. At this point here this should have -% been the only char present in \verb=\@nextchar= which put into via a -% \verb=\def=. -% \begin{macrocode} - \edef\@nextchar{\expandafter\string\@nextchar}% - \@chnum - \if \@nextchar c\z@ \else - \if \@nextchar l\@ne \else - \if \@nextchar r\tw@ \else -% \end{macrocode} -% If it is a different \textsf{token}, we know that the class was -% not $0$. We assign the value $0$ to \verb=\@chnum= because this value -% is needed for the \texttt{|}--\textsf{token}. Now we must check -% the remaining classes. Note that the value of \verb=\@chnum= is -% insignificant here for most classes. -% \begin{macrocode} - \z@ \@chclass - \if\@nextchar |\@ne \else - \if \@nextchar !6 \else - \if \@nextchar @7 \else - \if \@nextchar <8 \else - \if \@nextchar >9 \else -% \end{macrocode} -% The remaining permitted \textsf{tokens} are \texttt{p}, -% \texttt{m} and \texttt{b} (class $10$). -% \begin{macrocode} - 10 - \@chnum - \if \@nextchar m\thr@@\else - \if \@nextchar p4 \else - \if \@nextchar b5 \else -% \end{macrocode} -% Now the only remaining possibility is a forbidden \textsf{token}, -% so we choose class $0$ and number $0$ and give an error message. -% Then we finish the macro by closing all \verb=\if='s. -% \begin{macrocode} - \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi - \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi} -% \end{macrocode} -% \end{macro} -% -% -% -% -% -% \subsubsection{Multiple columns ($*$--form)} -% -% \begin{macro}{\@xexpast} -% \begin{macro}{\the@toks} -% \begin{macro}{\the@toksz} -% \label{@xexpast} Now we discuss the macro that deletes all forms -% of type \verb=*{=\textit{N\/}\verb=}{=\textit{String\/}\verb=}= from a user -% preamble and replaces them with \textit{N} copies of -% \textit{String}. Nested $*$--expressions are dealt with -% correctly, that means $*$--expressions are not substituted if -% they are in explicit braces, as in \verb=@{*}=. -% -% This macro is called via -% \verb=\@xexpast=\meta{preamble}\verb=*0x\@@=. -% The $*$--expression \verb=*0x= is being used to terminate the -% recursion, -% as we shall see later, and \verb=\@@= serves as an argument -% delimiter. \verb=\@xexpast= has four arguments. The first -% one is the part of the -% user preamble before the first $*$--expression while the second -% and third ones are the arguments of the first $*$--expression -% (that is \textit{N} and \textit{String} in the notation mentioned -% above). -% The fourth argument is the rest of the preamble. -% \begin{macrocode} -\def\@xexpast#1*#2#3#4\@@{% -% \end{macrocode} -% The number of copies of \textit{String} (\verb=#2=) that are to be -% produced will be saved in a \textsf{count} register. -% \begin{macrocode} - \@tempcnta #2 -% \end{macrocode} -% We save the part of the preamble which does not -% contain a $*$--form (\verb=#1=) -% in a \PlainTeX\ \textsf{token} register. -% We also save \textit{String} (\verb=#3=) using a \LaTeX\ -% \textsf{token} register. -% \begin{macrocode} - \toks@={#1}\@temptokena={#3}% -% \end{macrocode} -% Now we have to use a little trick to produce \textit{N} copies of -% \textit{String}. -% We could try \verb=\def\@tempa{#1}= and then -% \textit{N} times \verb=\edef\@tempa{\@tempa#3}=. This would have the -% undesired effect that all macros within \verb=#1= and \verb=#3= -% would be expanded, although, for example, constructions like -% \verb=@{..}= are not supposed to be changed. -% That is why we \verb=\let= two control sequences to -% be equivalent to \verb=\relax=. -% \begin{macrocode} - \let\the@toksz\relax \let\the@toks\relax -% \end{macrocode} -% Then we ensure that \verb=\@tempa= contains -% \verb={\the@toksz\the@toks...\the@toks}= (the macro -% \verb=\the@toks= exactly \textit{N\/} times) as substitution text. -% \begin{macrocode} - \def\@tempa{\the@toksz}% - \ifnum\@tempcnta >0 \@whilenum\@tempcnta >0\do - {\edef\@tempa{\@tempa\the@toks}\advance \@tempcnta \m@ne}% -% \end{macrocode} -% If \textit{N\/} was greater than zero we prepare for another call -% of \verb=\@xexpast=. Otherwise we assume we have reached the end of -% the user preamble, because we had appended \verb=*0x\@@= when we first -% called \verb=\@xexpast=. In other words: if the user inserts -% \verb=*{0}{..}= in his preamble, \LaTeX\ ignores the rest of it. -% \begin{macrocode} - \let \@tempb \@xexpast \else - \let \@tempb \@xexnoop \fi -% \end{macrocode} -% Now we will make sure that the part of the user preamble, which -% was already dealt with, will be saved again in \verb=\@tempa=. -% \begin{macrocode} - \def\the@toksz{\the\toks@}\def\the@toks{\the\@temptokena}% - \edef\@tempa{\@tempa}% -% \end{macrocode} -% We have now evaluated the first $*$--expression, and the user -% preamble up to this point -% is saved in \verb=\@tempa=. We will put the contents of -% \verb=\@tempa= and the rest of the user preamble together and work -% on the result with \verb=\@tempb=. This macro either corresponds -% to \verb=\@xexpast=, so that the next -% $*$--expression is handled, or to the macro \verb=\@xexnoop=, -% which only ends the recursion by deleting its argument. -% \begin{macrocode} - \expandafter \@tempb \@tempa #4\@@} -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\@xexnoop} -% So the first big problem is solved. Now it is easy to -% specify \verb=\@xexnoop=. -% Its argument is delimited by \verb=\@@= and it simply expands to -% nothing. +% Here ealier versions of the class had an embedded copy of the +% \Lpack{array} package. Now replaced by requiring the packge instead. % \begin{macrocode} -% \def\@xexnoop#1\@@{} +\RequirePackage{array}[2018/04/30] % \end{macrocode} -% \end{macro} -% -% -% -% -% \subsubsection{The insertion of declarations -% (\texttt{>}, \texttt{<}, \texttt{!}, \texttt{@})} -% -% -% The preamble will be enlarged with the help of \verb=\xdef=, but the -% arguments of \texttt{>}, \texttt{<},~\texttt{!}\ and \texttt{@} are -% not supposed to be expanded during the construction (we want an -% implementation that doesn't need a \verb=\protect=). So we have to find a -% way to inhibit the expansion of those arguments. -% -% We will solve this problem with \textsf{token} registers. We need -% one register for every \texttt{!}\ and \texttt{@}, while we need two -% for every \texttt{c}, \texttt{l}, \texttt{r}, \texttt{m}, \texttt{p} -% or \texttt{b}. This limits the number of columns of a table because -% there are only 256 \textsf{token} registers. But then, who needs -% tables with more than 100 columns? -% -% One could also find a solution which only needs two or three -% \textsf{token} registers by proceeding similarly as in the macro -% \verb=\@xexpast= (see page \pageref{@xexpast}). The advantage of our -% approach is the fact that we avoid some of the problems that arise -% with the other method\footnote{Maybe there are also historical -% reasons.}. -% -% So how do we proceed? Let us assume that we had \verb=!{foo}= in the -% user preamble and say we saved \texttt{foo} in -% \textsf{token} register $5$. Then we call -% \verb=\@addtopreamble{\the@toks5}= where -% \verb=\the@toks= is defined in a way that it does not expand -% (for example it could be equivalent to \verb=\relax=). Every -% following call -% of \verb=\@addtopreamble= leaves \verb=\the@toks5= unchanged in -% \verb=\@preamble=. If the construction of the preamble is completed -% we change the definition of \verb=\the@toks= to -% \verb=\the\toks= and expand \verb=\@preamble= for the last time. -% During this process all parts of the form -% \verb=\the@toks=\meta{Number} -% will be substituted by the contents of the respective \textsf{token} -% registers. -% -% As we can see from this informal discussion the construction of the -% preamble has to take place within a group, so that the -% \textsf{token} registers we use will be freed later on. For that -% reason we keep all assignments to \verb=\@preamble= global; therefore the -% replacement text of this macro will remain the same after we leave -% the group. -% -% \begin{macro}{\count@} -% We further need a \textsf{count} register to remember which -% \textsf{token} register is to be used next. This will be -% initialized with $-1$ if we want to begin with the \textsf{token} -% register $0$. We use the \PlainTeX\ scratch register \verb=\count@= -% because everything takes place locally. All we have to do is -% insert \verb=\the@toks= \verb=\the= \verb=\count@= into the preamble. -% \verb=\the@toks= will remain unchanged and \verb=\the\count@= expands into -% the saved number. -% \end{macro} -% -% \begin{macro}{\prepnext@tok} -% The macro \verb=\prepnext@tok= is in charge of preparing the next -% \textsf{token} register. For that purpose we increase -% \verb=\count@= by $1$: -% \begin{macrocode} -\def\prepnext@tok{\advance \count@ \@ne -% \end{macrocode} -% Then we locally delete any contents the -% \textsf{token} register might have. -% \begin{macrocode} - \toks\count@{}} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\save@decl} -% During the construction of the preamble the current -% \textsf{token} is always saved in the macro \verb=\@nextchar= (see the -% definition of \verb=\@mkpream= on page \pageref{@mkpream}). The macro -% \verb=\save@decl= saves it into the next free \textsf{token} register, -% i.e.\ in \verb=\toks\count@=. -% \begin{macrocode} -\def\save@decl{\toks\count@ \expandafter{\@nextchar}} -% \end{macrocode} -% The reason for the use of \verb=\relax= is the following -% hypothetical situation in the preamble: -% \quad \verb=..\the\toks1\the\toks2..= \quad \TeX\ expands -% \verb=\the\toks2= first in order to find out if the digit \verb=1= -% is followed by other digits. E.g.\ a \verb=5= saved in the -% \textsf{token} register $2$ would lead \TeX\ to insert the contents -% of \textsf{token} register $15$ instead of $1$ later on. -% -% The example above referred to an older version of \verb=\save@decl= which -% inserted a \verb=\relex= inside the token register. This is now moved to -% the places where the actual token registers are inserted (look for -% \verb=\the@toks=) because the old version would still make= @= -% expressions to moving arguments since after expanding the second -% register while looking for the end of the number the contents of the -% token register is added so that later on the whole register will be -% expanded. This serious bug was found after nearly two years -% international use of this package by Johannes Braams. -% \end{macro} -% -% -% -% How does the situation look like, if we want to add another column -% to the preamble, i.e.\ if we have found a \texttt{c}, \texttt{l}, -% \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in the user -% preamble? In this case we have the problem of the \textsf{token} -% register from \verb=>{..}= and \verb=<{..}= having to be inserted at this -% moment because formatting instructions like \verb=\hfil= have to be set -% around them. On the other hand it is not known yet, if any \verb=<{..}= -% instruction will appear in the user preamble at all. -% -% We solve this problem by adding two \textsf{token} registers at a -% time. This explains, why we have freed the \textsf{token} registers -% in \verb=\prepnext@tok=. -% -% \begin{macro}{\insert@column} -% \begin{macro}{\@sharp} -% We now define the macro \verb=\insert@column= which will do -% this work for us. -% \begin{macrocode} -\def\insert@column{% -% \end{macrocode} -% Here, we assume that the \textsf{count} register -% \verb=\@tempcnta= has saved the value $\verb=\count@= - 1$. -% \begin{macrocode} - \the@toks \the \@tempcnta -% \end{macrocode} -% Next follows the \verb=#= sign which specifies the place -% where the text of the column shall be inserted. To avoid -% errors during the expansions in -% \verb=\@addtopreamble= we hide this sign in the command -% \verb=\@sharp= which is temporarily occupied with -% \verb=\relax= during the build-up of the preamble. -% To remove unwanted spaces before and after the column text, we set -% an \verb=\ignorespaces= in front and a \verb=\unskip= afterwards. -% \begin{macrocode} - \ignorespaces \@sharp \unskip -% \end{macrocode} -% Then the second \textsf{token} register follows whose number should -% be saved in \verb=\count@=. -% We make sure that there will be no further expansion after reading -% the number, by finishing with \verb=\relax=. The case above is not -% critical since it is ended by \verb=\ignorespaces=. -% \begin{macrocode} - \the@toks \the \count@ \relax} -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% -% -% \subsubsection{The separation of columns} -% -% \begin{macro}{\@addamp} -% In the preamble a \verb=&= has to be inserted between any two columns; -% before the first column there should not be a \verb=&=. As the user -% preamble may start with a \texttt{|} we have to remember somehow -% if we have already inserted a \verb=#= (i.e.\ a column). This is done -% with the boolean variable \verb=\if@firstamp= that we test in -% \verb=\@addamp=, the macro that inserts the \verb=&=. -% \begin{macrocode} -% \newif \@iffirstamp -% \def\@addamp{\if@firstamp \@firstampfalse -% \else \@addtopreamble &\fi} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@acol} -% \begin{macro}{\@acolampacol} -% \begin{macro}{\col@sep} -% We will now define some abbreviations for the extensions, -% appearing most often in the preamble build-up. -% Here \verb=\col@sep= is a \textsf{dimen} register which is set -% equivalent to \verb=\arraycolsep= in an \textsf{array}--environment, -% otherwise it is set equivalent to \verb=\tabcolsep=. -% \begin{macrocode} -\newdimen\col@sep -\def\@acol{\@addtopreamble{\hskip\col@sep}} -% \def\@acolampacol{\@acol\@addamp\@acol} -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% -% \subsubsection{The macro \texttt{\textbackslash @mkpream}} +% The embeded copy is outcommented for now and will be removed in a +% later version. % -% \begin{macro}{\@mkpream} -% \begin{macro}{\the@toks} -% \label{@mkpream} -% Now we can define the macro which builds up the preamble for the -% \verb=\halign=. -% First we initialize \verb=\@preamble=, \verb=\@lastchclass= -% and the boolean variable \verb=\if@firstamp=. -% \begin{macrocode} -\def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue -% \end{macrocode} -% During the build-up of the preamble we cannot directly use the -% \verb=#= sign; this would lead to an error message in the next -% \verb=\@addtopreamble= call. -% Instead, we use the command \verb=\@sharp= at places where later -% a \verb=#= will be. -% This command is at first given the meaning \verb=\relax=; -% therefore it will not be expanded when the preamble -% is extended. -% In the macro \verb=\@array=, shortly before the \verb=\halign= -% is carried out, \verb=\@sharp= is given its final meaning. +% \changes{v3.7h}{2018/09/06}{Outcommented the embedded copy of +% \Lpack{array} and replaced it with requiring the \Lpack{array} package +% instead.} % -% In a similar way, -% we deal with the commands \verb=\@startpbox= and -% \verb=\@endpbox=, although the reason is different here: these -% macros expand in many \textsf{tokens} which would delay the -% build-up of the preamble. -% \begin{macrocode} - \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax -% \end{macrocode} -% Now we remove possible $*$-forms in the user preamble with the -% command \verb=\@xexpast=. As we already know, this command saves -% its result in the macro \verb=\@tempa=. -% \begin{macrocode} - \@xexpast #1*0x\@@ -% \end{macrocode} -% Afterwards we initialize all registers and macros, that we need -% for the build-up of the preamble. -% Since we want to start with the \textsf{token} register $0$, -% \verb=\count@= has to contain the value $-1$. -% \begin{macrocode} - \count@\m@ne - \let\the@toks\relax -% \end{macrocode} -% Then we call up \verb=\prepnext@tok= in order to prepare the -% \textsf{token} register $0$ for use. -% \begin{macrocode} - \prepnext@tok -% \end{macrocode} -% To evaluate the user preamble (without stars) saved in -% \verb=\@tempa= we use the \LaTeX--macro \verb=\@tfor=. -% The strange appearing construction with \verb=\expandafter= is -% based on the fact that we have to put the replacement text of -% \verb=\@tempa= and not the macro \verb=\@tempa= to this -% \LaTeX--macro. -% \begin{macrocode} - \expandafter \@tfor \expandafter \@nextchar - \expandafter :\expandafter =\@tempa \do -% \end{macrocode} -% The body of this loop (the group after the \verb=\do=) -% is executed for one \textsf{token} at a time, whereas -% the current \textsf{token} is saved in \verb=\@nextchar=. -% At first we evaluate the current \textsf{token} with the already -% defined macro \verb=\@testpach=, i.e.\ we assign to -% \verb=\@chclass= the character class and to \verb=\@chnum= -% the character number of this \textsf{token}. -% \begin{macrocode} - {\@testpach -% \end{macrocode} -% Then we branch out depending on the value of \verb=\@chclass= into -% different macros that extend the preamble respectively. -% \begin{macrocode} - \ifcase \@chclass \@classz \or \@classi \or \@classii - \or \save@decl \or \or \@classv \or \@classvi - \or \@classvii \or \@classviii \or \@classix - \or \@classx \fi -% \end{macrocode} -% Two cases deserve our special attention: Since the current -% \textsf{token} cannot have the character class $4$ (start) we -% have skipped this possibility. If the character class is $3$, -% only the content of \verb=\@nextchar= has to be saved into the current -% \textsf{token} register; therefore we call up \verb=\save@decl= -% directly and save a macro name. After the preamble has been -% extended we assign the value of \verb=\@chclass= to the counter -% \verb=\@lastchclass= to assure that this information will be available -% during the next run of the loop. -% \begin{macrocode} - \@lastchclass\@chclass}% -% \end{macrocode} -% After the loop has been finished space must still be added to -% the created preamble, depending on the last \textsf{token}. -% Depending on the value of \verb=\@lastchclass= we perform -% the necessary operations. -% \begin{macrocode} - \ifcase\@lastchclass -% \end{macrocode} -% If the last class equals $0$ we add a -% \verb=\hskip \col@sep=. -% \begin{macrocode} - \@acol \or -% \end{macrocode} -% If it equals $1$ we do not add any additional space so that the -% horizontal lines do not exceed the vertical ones. -% \begin{macrocode} - \or -% \end{macrocode} -% Class $2$ is treated like class $0$ because a \verb=<{...}= can -% only directly follow after class $0$. -% \begin{macrocode} - \@acol \or -% \end{macrocode} -% Most of the other possibilities can only appear if the user -% preamble was defective. Class $3$ is not allowed since after a -% \verb=>{..}= there must always follow a \texttt{c}, \texttt{l}, -% \texttt{r}, \texttt{p},\texttt{m} or \texttt{b}. We report an -% error and ignore the declaration given by \verb={..}=. +% ^^A % The description and code are essentially copied from the \Lpack{array} +% ^^A package~\cite{ARRAY}. +% ^^A % \begin{macrocode} - \@preamerr \thr@@ \or -% \end{macrocode} -% If \verb=\@lastchclass= is $4$ the user preamble has been empty. -% To continue, we insert a \verb=#= in the preamble. + % + % %%%%%%%%%% Array package code %%%%%%%%%%%%%%%%%%%%% + % %%%%%%%%%% With acknowledgements to %%%%%%%%%%%%%%%%%%%%% + % %%%%%%%%%% Frank Mittelbach & David Carlisle %%%%%%%%%%%%%%%%%%%%% + % + % %%%%%%%%%% Copy corresponds to array.sty 2016/10/06 v2.4d %%%%%%%%% +% \end{macrocode} +% ^^A \changes{v3.7g}{2018/03/05}{Updated the embedded copy of the +% ^^A \Lpack{array} package to version 2.4d, 2016/10/06} +% ^^A \begin{dlf} +% ^^A dlf: The \Lpack{array} package has redundant code (caused by a +% ^^A quick mashing of and earlier \Lpack{array} version and the +% ^^A \Lpack{newaray} package). In thus update (2018/03/05) this +% ^^A redundant code is \emph{not} removed as it makes it very hard to +% ^^A see where there are class changes to the \Lpack{array} code, and +% ^^A when stuff is simply removed. We'll leave it up to the LaTeXteam to +% ^^A clean up the \Lpack{array} code at some point. +% ^^A +% ^^A The following is a carbon copy of the DTX code from +% ^^A \verb|array.dtx|, package specific \cs{changes} lines have been +% ^^A removed, and we have made any error/warning messages class specific, +% ^^A instead of package specific. +% ^^A \end{dlf} +% ^^A +% ^^A +% ^^A \subsubsection{The construction of the preamble} +% ^^A +% ^^A It is obvious that those environments will consist mainly of an +% ^^A \verb=\halign=, because \TeX\ typesets tables using this primitive. +% ^^A That is why we will now take a look at the algorithm which determines +% ^^A a preamble for a \verb=\halign= starting with a given user preamble +% ^^A using the options mentioned above. +% ^^A +% ^^A The most interesting macros of this implementation are without doubt +% ^^A those which are responsible for the construction of the preamble for +% ^^A the \verb=\halign=. The underlying algorithm was developed by +% ^^A \textsc{Lamport} (resp.\ \textsc{Knuth}, see texhax V87\#??), and it +% ^^A has been extended and improved. +% ^^A +% ^^A The user preamble will be read \textsf{token} by \textsf{token}. A +% ^^A \textsf{token} is a single character like \texttt{c} or a block +% ^^A enclosed in \verb={...}=. For example the preamble of +% ^^A \verb=\begin{tabular}=\linebreak[0]\verb={lc||c@{\hspace{1cm}}}= consists of +% ^^A the \textsf{token} \texttt{l}, \texttt{c}, \texttt{|}, \texttt{|}, +% ^^A \texttt{@} and \verb=\hspace{1cm}=. +% ^^A +% ^^A The currently used \textsf{token} and the one, used before, are needed +% ^^A to decide on how the construction of the preamble has to be +% ^^A continued. +% ^^A In the example mentioned above the \texttt{l} causes the preamble +% ^^A to begin with \verb=\hskip\tabcolsep=. Furthermore +% ^^A \verb=# \hfil= would be appended to define a flush left column. +% ^^A The next \textsf{token} is a \texttt{c}. Because it was preceded by an +% ^^A \texttt{l} it generates a new column. This is done with +% ^^A \verb=\hskip \tabcolsep & \hskip \tabcolsep=. The column which is to +% ^^A be centered will be appended with \verb=\hfil # \hfil=. +% ^^A The \textsf{token} \texttt{|} would then add a space of +% ^^A \verb=\hskip \tabcolsep= +% ^^A and a vertical line because the last +% ^^A \textsf{tokens} was a \texttt{c}. +% ^^A The following \textsf{token} \texttt{|} would only add a space +% ^^A \verb=\hskip \doublerulesep= because it was preceded by the +% ^^A \textsf{token} \texttt{|}. We will not discuss our example further but +% ^^A rather take a look at the general case of constructing preambles. +% ^^A +% ^^A The example shows that the desired preamble for the +% ^^A \verb=\halign= can be constructed as soon as the action of all +% ^^A combinations +% ^^A of the preamble \textsf{tokens} are specified. There are 18 such +% ^^A \textsf{tokens} +% ^^A so we have $19 \cdot 18 = 342$ combinations if we count the +% ^^A beginning of +% ^^A the preamble as a special \textsf{token}. Fortunately, there are many +% ^^A combinations which generate the same spaces, so we can define +% ^^A \textsf{token} classes. We will identify a +% ^^A \textsf{token} within a class with a number, so we can insert the +% ^^A formatting (for example of a column). +% ^^A Table~\ref{tab:Klassen} lists all \textsf{token} classes and +% ^^A their corresponding numbers. +% ^^A \begin{table}[ht] +% ^^A \begin{center} +% ^^A \begin{tabular}[t]{>{\ttfamily}ccc} +% ^^A \textsf{token} & \verb=\@chclass= & \verb=\@chnum= \\[2mm] +% ^^A c & 0 & 0 \\ +% ^^A l & 0 & 1 \\ +% ^^A r & 0 & 2 \\ +% ^^A p-arg & 0 & 3 \\ +% ^^A t-arg & 0 & 4 \\ +% ^^A b-arg & 0 & 5 \\ +% ^^A | & 1 & 0 \\ +% ^^A !-arg & 1 & 1 \\ +% ^^A <-arg & 2 & --- \\ +% ^^A >-arg & 3 & --- +% ^^A \end{tabular} +% ^^A \kern3mm \vrule \kern3mm% +% ^^A \begin{tabular}[t]{>{\ttfamily}ccc} +% ^^A \textsf{token} & \verb=\@chclass= & \verb=\@chnum= \\[2mm] +% ^^A Start & 4 & --- \\ +% ^^A @-arg & 5 & --- \\ +% ^^A ! & 6 & --- \\ +% ^^A @ & 7 & --- \\ +% ^^A < & 8 & --- \\ +% ^^A > & 9 & --- \\ +% ^^A p & 10 & 3 \\ +% ^^A t & 10 & 4 \\ +% ^^A b & 10 & 5 +% ^^A \end{tabular} +% ^^A \end{center} +% ^^A \caption{Classes of preamble \textsf{tokens}} +% ^^A \label{tab:Klassen} +% ^^A \end{table} +% ^^A +% ^^A +% ^^A \begin{macro}{\@chclass} +% ^^A \begin{macro}{\@chnum} +% ^^A \begin{macro}{\@lastchclass} +% ^^A The class and the number of the current \textsf{token} are saved in +% ^^A the +% ^^A \textsf{count} registers \verb=\@chclass= +% ^^A and \verb=\@chnum=, while the class of the previous +% ^^A \textsf{token} is stored in the +% ^^A \textsf{count} register \verb=\@lastchclass=. +% ^^A All of the mentioned registers are already allocated in +% ^^A \texttt{latex.tex}, +% ^^A which is the reason why the following three lines of code are +% ^^A commented out. +% ^^A Later throughout the text I will not mention it again explicitly +% ^^A whenever I use a \verb=%= sign. These parts are already defined in +% ^^A \texttt{latex.tex}. +% \begin{macrocode} + % % \newcount \@chclass + % % \newcount \@chnum + % % \newcount \@lastchclass +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \begin{macro}{\@addtopreamble} +% ^^A We will save the already constructed preamble for +% ^^A the \verb=\halign= +% ^^A in the global macro \verb=\@preamble=. This will then be +% ^^A enlarged with +% ^^A the command \verb=\@addtopreamble=. % \begin{macrocode} - \@preamerr \tw@ \@addtopreamble\@sharp \or + % \def\@addtopreamble#1{\xdef\@preamble{\@preamble #1}} % \end{macrocode} -% Class $5$ is allowed again. In this case -% (the user preamble ends with \verb=@{..}=) we need not -% do anything. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{The character class of a \textsf{token}} +% ^^A +% ^^A \begin{macro}{\@testpach} +% ^^A With the help of \verb=\@lastchclass= we can now define a macro +% ^^A which determines the class and the number of a given preamble +% ^^A \textsf{token} +% ^^A and assigns them to the registers +% ^^A \verb=\@chclass= and \verb=\@chnum=. +% \begin{macrocode} + % \def\@testpach{\@chclass +% \end{macrocode} +% ^^A First we deal with the cases in which the \textsf{token} +% ^^A (\verb=#1=) is the argument of \texttt{!}, \texttt{@}, \texttt{<} or +% ^^A \texttt{>}. We can see this from the value of \verb=\@lastchclass=: +% \begin{macrocode} + % \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else + % \ifnum \@lastchclass=7 5 \else + % \ifnum \@lastchclass=8 \tw@ \else + % \ifnum \@lastchclass=9 \thr@@ +% \end{macrocode} +% ^^A Otherwise we will assume that the \textsf{token} belongs to the +% ^^A class $0$ +% ^^A and assign the corresponding number to \verb=\@chnum= if our +% ^^A assumption is correct. +% \begin{macrocode} + % \else \z@ +% \end{macrocode} +% ^^A If the last \textsf{token} was a \texttt{p}, \texttt{m} or a +% ^^A \texttt{b}, \verb=\@chnum= already has the right value. This is the +% ^^A reason for the somewhat curious choice of the \textsf{token} +% ^^A numbers in class $10$. +% \begin{macrocode} + % \ifnum \@lastchclass = 10 \else +% \end{macrocode} +% ^^A Otherwise we will check if \verb=\@nextchar= is either a \texttt{c}, +% ^^A \texttt{l} or an \texttt{r}. Some applications change the +% ^^A catcodes of certain characters like ``\texttt{@}'' in +% ^^A \texttt{amstex.sty}. As a result the tests below would fail since +% ^^A they assume non-active character tokens. Therefore we evaluate +% ^^A \verb=\@nextchar= once thereby turning the first token of its +% ^^A replacement text into a char. At this point here this should have +% ^^A been the only char present in \verb=\@nextchar= which put into via a +% ^^A \verb=\def=. +% \begin{macrocode} + % \edef\@nextchar{\expandafter\string\@nextchar}% + % \@chnum + % \if \@nextchar c\z@ \else + % \if \@nextchar l\@ne \else + % \if \@nextchar r\tw@ \else +% \end{macrocode} +% ^^A If it is a different \textsf{token}, we know that the class was +% ^^A not $0$. We assign the value $0$ to \verb=\@chnum= because this value +% ^^A is needed for the \texttt{|}--\textsf{token}. Now we must check +% ^^A the remaining classes. Note that the value of \verb=\@chnum= is +% ^^A insignificant here for most classes. +% \begin{macrocode} + % \z@ \@chclass + % \if\@nextchar |\@ne \else + % \if \@nextchar !6 \else + % \if \@nextchar @7 \else + % \if \@nextchar <8 \else + % \if \@nextchar >9 \else +% \end{macrocode} +% ^^A The remaining permitted \textsf{tokens} are \texttt{p}, +% ^^A \texttt{m} and \texttt{b} (class $10$). +% \begin{macrocode} + % 10 + % \@chnum + % \if \@nextchar m\thr@@\else + % \if \@nextchar p4 \else + % \if \@nextchar b5 \else +% \end{macrocode} +% ^^A Now the only remaining possibility is a forbidden \textsf{token}, +% ^^A so we choose class $0$ and number $0$ and give an error message. +% ^^A Then we finish the macro by closing all \verb=\if='s. +% \begin{macrocode} + % \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi + % \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi \fi} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{Multiple columns ($*$--form)} +% ^^A +% ^^A \begin{macro}{\@xexpast} +% ^^A \begin{macro}{\the@toks} +% ^^A \begin{macro}{\the@toksz} +% ^^A \label{@xexpast} Now we discuss the macro that deletes all forms +% ^^A of type \verb=*{=\textit{N\/}\verb=}{=\textit{String\/}\verb=}= from a user +% ^^A preamble and replaces them with \textit{N} copies of +% ^^A \textit{String}. Nested $*$--expressions are dealt with +% ^^A correctly, that means $*$--expressions are not substituted if +% ^^A they are in explicit braces, as in \verb=@{*}=. +% ^^A +% ^^A This macro is called via +% ^^A \verb=\@xexpast=\meta{preamble}\verb=*0x\@@=. +% ^^A The $*$--expression \verb=*0x= is being used to terminate the +% ^^A recursion, +% ^^A as we shall see later, and \verb=\@@= serves as an argument +% ^^A delimiter. \verb=\@xexpast= has four arguments. The first +% ^^A one is the part of the +% ^^A user preamble before the first $*$--expression while the second +% ^^A and third ones are the arguments of the first $*$--expression +% ^^A (that is \textit{N} and \textit{String} in the notation mentioned +% ^^A above). +% ^^A The fourth argument is the rest of the preamble. +% \begin{macrocode} + % \def\@xexpast#1*#2#3#4\@@{% +% \end{macrocode} +% ^^A The number of copies of \textit{String} (\verb=#2=) that are to be +% ^^A produced will be saved in a \textsf{count} register. +% \begin{macrocode} + % \@tempcnta #2 +% \end{macrocode} +% ^^A We save the part of the preamble which does not +% ^^A contain a $*$--form (\verb=#1=) +% ^^A in a \PlainTeX\ \textsf{token} register. +% ^^A We also save \textit{String} (\verb=#3=) using a \LaTeX\ +% ^^A \textsf{token} register. +% \begin{macrocode} + % \toks@={#1}\@temptokena={#3}% +% \end{macrocode} +% ^^A Now we have to use a little trick to produce \textit{N} copies of +% ^^A \textit{String}. +% ^^A We could try \verb=\def\@tempa{#1}= and then +% ^^A \textit{N} times \verb=\edef\@tempa{\@tempa#3}=. This would have the +% ^^A undesired effect that all macros within \verb=#1= and \verb=#3= +% ^^A would be expanded, although, for example, constructions like +% ^^A \verb=@{..}= are not supposed to be changed. +% ^^A That is why we \verb=\let= two control sequences to +% ^^A be equivalent to \verb=\relax=. +% \begin{macrocode} + % \let\the@toksz\relax \let\the@toks\relax +% \end{macrocode} +% ^^A Then we ensure that \verb=\@tempa= contains +% ^^A \verb={\the@toksz\the@toks...\the@toks}= (the macro +% ^^A \verb=\the@toks= exactly \textit{N\/} times) as substitution text. +% \begin{macrocode} + % \def\@tempa{\the@toksz}% + % \ifnum\@tempcnta >0 \@whilenum\@tempcnta >0\do + % {\edef\@tempa{\@tempa\the@toks}\advance \@tempcnta \m@ne}% +% \end{macrocode} +% ^^A If \textit{N\/} was greater than zero we prepare for another call +% ^^A of \verb=\@xexpast=. Otherwise we assume we have reached the end of +% ^^A the user preamble, because we had appended \verb=*0x\@@= when we first +% ^^A called \verb=\@xexpast=. In other words: if the user inserts +% ^^A \verb=*{0}{..}= in his preamble, \LaTeX\ ignores the rest of it. +% \begin{macrocode} + % \let \@tempb \@xexpast \else + % \let \@tempb \@xexnoop \fi +% \end{macrocode} +% ^^A Now we will make sure that the part of the user preamble, which +% ^^A was already dealt with, will be saved again in \verb=\@tempa=. +% \begin{macrocode} + % \def\the@toksz{\the\toks@}\def\the@toks{\the\@temptokena}% + % \edef\@tempa{\@tempa}% +% \end{macrocode} +% ^^A We have now evaluated the first $*$--expression, and the user +% ^^A preamble up to this point +% ^^A is saved in \verb=\@tempa=. We will put the contents of +% ^^A \verb=\@tempa= and the rest of the user preamble together and work +% ^^A on the result with \verb=\@tempb=. This macro either corresponds +% ^^A to \verb=\@xexpast=, so that the next +% ^^A $*$--expression is handled, or to the macro \verb=\@xexnoop=, +% ^^A which only ends the recursion by deleting its argument. +% \begin{macrocode} + % \expandafter \@tempb \@tempa #4\@@} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@xexnoop} +% ^^A So the first big problem is solved. Now it is easy to +% ^^A specify \verb=\@xexnoop=. +% ^^A Its argument is delimited by \verb=\@@= and it simply expands to +% ^^A nothing. % \begin{macrocode} - \or + % % \def\@xexnoop#1\@@{} % \end{macrocode} -% Any other case means that the arguments to \verb=@=, \texttt{!}, -% \texttt{<}, \texttt{>}, \texttt{p}, \texttt{m} or \texttt{b} have -% been forgotten. So we report an error and ignore the last -% \textsf{token}. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{The insertion of declarations +% ^^A (\texttt{>}, \texttt{<}, \texttt{!}, \texttt{@})} +% ^^A +% ^^A +% ^^A The preamble will be enlarged with the help of \verb=\xdef=, but the +% ^^A arguments of \texttt{>}, \texttt{<},~\texttt{!}\ and \texttt{@} are +% ^^A not supposed to be expanded during the construction (we want an +% ^^A implementation that doesn't need a \verb=\protect=). So we have to find a +% ^^A way to inhibit the expansion of those arguments. +% ^^A +% ^^A We will solve this problem with \textsf{token} registers. We need +% ^^A one register for every \texttt{!}\ and \texttt{@}, while we need two +% ^^A for every \texttt{c}, \texttt{l}, \texttt{r}, \texttt{m}, \texttt{p} +% ^^A or \texttt{b}. This limits the number of columns of a table because +% ^^A there are only 256 \textsf{token} registers. But then, who needs +% ^^A tables with more than 100 columns? +% ^^A +% ^^A One could also find a solution which only needs two or three +% ^^A \textsf{token} registers by proceeding similarly as in the macro +% ^^A \verb=\@xexpast= (see page \pageref{@xexpast}). The advantage of our +% ^^A approach is the fact that we avoid some of the problems that arise +% ^^A with the other method\footnote{Maybe there are also historical +% ^^A reasons.}. +% ^^A +% ^^A So how do we proceed? Let us assume that we had \verb=!{foo}= in the +% ^^A user preamble and say we saved \texttt{foo} in +% ^^A \textsf{token} register $5$. Then we call +% ^^A \verb=\@addtopreamble{\the@toks5}= where +% ^^A \verb=\the@toks= is defined in a way that it does not expand +% ^^A (for example it could be equivalent to \verb=\relax=). Every +% ^^A following call +% ^^A of \verb=\@addtopreamble= leaves \verb=\the@toks5= unchanged in +% ^^A \verb=\@preamble=. If the construction of the preamble is completed +% ^^A we change the definition of \verb=\the@toks= to +% ^^A \verb=\the\toks= and expand \verb=\@preamble= for the last time. +% ^^A During this process all parts of the form +% ^^A \verb=\the@toks=\meta{Number} +% ^^A will be substituted by the contents of the respective \textsf{token} +% ^^A registers. +% ^^A +% ^^A As we can see from this informal discussion the construction of the +% ^^A preamble has to take place within a group, so that the +% ^^A \textsf{token} registers we use will be freed later on. For that +% ^^A reason we keep all assignments to \verb=\@preamble= global; therefore the +% ^^A replacement text of this macro will remain the same after we leave +% ^^A the group. +% ^^A +% ^^A \begin{macro}{\count@} +% ^^A We further need a \textsf{count} register to remember which +% ^^A \textsf{token} register is to be used next. This will be +% ^^A initialized with $-1$ if we want to begin with the \textsf{token} +% ^^A register $0$. We use the \PlainTeX\ scratch register \verb=\count@= +% ^^A because everything takes place locally. All we have to do is +% ^^A insert \verb=\the@toks= \verb=\the= \verb=\count@= into the preamble. +% ^^A \verb=\the@toks= will remain unchanged and \verb=\the\count@= expands into +% ^^A the saved number. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\prepnext@tok} +% ^^A The macro \verb=\prepnext@tok= is in charge of preparing the next +% ^^A \textsf{token} register. For that purpose we increase +% ^^A \verb=\count@= by $1$: % \begin{macrocode} - \else \@preamerr \@ne \fi + % \def\prepnext@tok{\advance \count@ \@ne % \end{macrocode} -% Now that the build-up of the preamble is almost finished we can -% insert the \textsf{token} registers and therefore redefine -% \verb=\the@toks=. The actual insertion, though, is performed -% later. +% ^^A Then we locally delete any contents the +% ^^A \textsf{token} register might have. % \begin{macrocode} - \def\the@toks{\the\toks}} + % \toks\count@{}} % \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% -% \subsubsection{The macros \texttt{\textbackslash @classz} -% to \texttt{\textbackslash @classx}} -% -% The preamble is extended by the macros \verb=\@classz= to -% \verb=\@classx= which are called by \verb=\@mkpream= -% depending on \verb=\@lastchclass= -% (i.e. the character class of the last \textsf{token}). -% \begin{macro}{\@classx} -% First we define =\@classx= because of its important r\^ole. -% When it is called we find that the current -% \textsf{token} is \texttt{p}, \texttt{m} or \texttt{b}. -% That means that a new column has to start. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\save@decl} +% ^^A During the construction of the preamble the current +% ^^A \textsf{token} is always saved in the macro \verb=\@nextchar= (see the +% ^^A definition of \verb=\@mkpream= on page \pageref{@mkpream}). The macro +% ^^A \verb=\save@decl= saves it into the next free \textsf{token} register, +% ^^A i.e.\ in \verb=\toks\count@=. +% \begin{macrocode} + % \def\save@decl{\toks\count@ \expandafter{\@nextchar}} +% \end{macrocode} +% ^^A The reason for the use of \verb=\relax= is the following +% ^^A hypothetical situation in the preamble: +% ^^A \quad \verb=..\the\toks1\the\toks2..= \quad \TeX\ expands +% ^^A \verb=\the\toks2= first in order to find out if the digit \verb=1= +% ^^A is followed by other digits. E.g.\ a \verb=5= saved in the +% ^^A \textsf{token} register $2$ would lead \TeX\ to insert the contents +% ^^A of \textsf{token} register $15$ instead of $1$ later on. +% ^^A +% ^^A The example above referred to an older version of \verb=\save@decl= which +% ^^A inserted a \verb=\relex= inside the token register. This is now moved to +% ^^A the places where the actual token registers are inserted (look for +% ^^A \verb=\the@toks=) because the old version would still make= @= +% ^^A expressions to moving arguments since after expanding the second +% ^^A register while looking for the end of the number the contents of the +% ^^A token register is added so that later on the whole register will be +% ^^A expanded. This serious bug was found after nearly two years +% ^^A international use of this package by Johannes Braams. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A How does the situation look like, if we want to add another column +% ^^A to the preamble, i.e.\ if we have found a \texttt{c}, \texttt{l}, +% ^^A \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in the user +% ^^A preamble? In this case we have the problem of the \textsf{token} +% ^^A register from \verb=>{..}= and \verb=<{..}= having to be inserted at this +% ^^A moment because formatting instructions like \verb=\hfil= have to be set +% ^^A around them. On the other hand it is not known yet, if any \verb=<{..}= +% ^^A instruction will appear in the user preamble at all. +% ^^A +% ^^A We solve this problem by adding two \textsf{token} registers at a +% ^^A time. This explains, why we have freed the \textsf{token} registers +% ^^A in \verb=\prepnext@tok=. +% ^^A +% ^^A \begin{macro}{\insert@column} +% ^^A \begin{macro}{\@sharp} +% ^^A We now define the macro \verb=\insert@column= which will do +% ^^A this work for us. % \begin{macrocode} -\def\@classx{% + % \def\insert@column{% % \end{macrocode} -% Depending on the value of \verb=\@lastchclass= different actions -% must take place: +% ^^A Here, we assume that the \textsf{count} register +% ^^A \verb=\@tempcnta= has saved the value $\verb=\count@= - 1$. % \begin{macrocode} - \ifcase \@lastchclass + % \the@toks \the \@tempcnta % \end{macrocode} -% If the last character class was $0$ we separate the columns by -% \verb=\hskip\col@sep= followed by \verb=&= and another -% \verb=\hskip\col@sep=. +% ^^A Next follows the \verb=#= sign which specifies the place +% ^^A where the text of the column shall be inserted. To avoid +% ^^A errors during the expansions in +% ^^A \verb=\@addtopreamble= we hide this sign in the command +% ^^A \verb=\@sharp= which is temporarily occupied with +% ^^A \verb=\relax= during the build-up of the preamble. +% ^^A To remove unwanted spaces before and after the column text, we set +% ^^A an \verb=\ignorespaces= in front and a \verb=\unskip= afterwards. % \begin{macrocode} - \@acolampacol \or + % \ignorespaces \@sharp \unskip % \end{macrocode} -% If the last class was class $1$ --- that means that a vertical -% line was -% drawn, --- before this line a \verb=\hskip\col@sep= was inserted. -% Therefore there has to be only a \verb=&= followed by -% \verb=\hskip\col@sep=. But this \verb=&= may be inserted only -% if this is not the first column. This process is controlled -% by \verb=\if@firstamp= in the macro \verb=\addamp=. +% ^^A Then the second \textsf{token} register follows whose number should +% ^^A be saved in \verb=\count@=. +% ^^A We make sure that there will be no further expansion after reading +% ^^A the number, by finishing with \verb=\relax=. The case above is not +% ^^A critical since it is ended by \verb=\ignorespaces=. % \begin{macrocode} - \@addamp \@acol \or + % \the@toks \the \count@ \relax} % \end{macrocode} -% Class $2$ is treated like class $0$ because \verb=<{...}= can only -% follow after class $0$. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{The separation of columns} +% ^^A +% ^^A \begin{macro}{\@addamp} +% ^^A In the preamble a \verb=&= has to be inserted between any two columns; +% ^^A before the first column there should not be a \verb=&=. As the user +% ^^A preamble may start with a \texttt{|} we have to remember somehow +% ^^A if we have already inserted a \verb=#= (i.e.\ a column). This is done +% ^^A with the boolean variable \verb=\if@firstamp= that we test in +% ^^A \verb=\@addamp=, the macro that inserts the \verb=&=. +% \begin{macrocode} + % % \newif \@iffirstamp + % % \def\@addamp{\if@firstamp \@firstampfalse + % % \else \@addtopreamble &\fi} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@acol} +% ^^A \begin{macro}{\@acolampacol} +% ^^A \begin{macro}{\col@sep} +% ^^A We will now define some abbreviations for the extensions, +% ^^A appearing most often in the preamble build-up. +% ^^A Here \verb=\col@sep= is a \textsf{dimen} register which is set +% ^^A equivalent to \verb=\arraycolsep= in an \textsf{array}--environment, +% ^^A otherwise it is set equivalent to \verb=\tabcolsep=. +% \begin{macrocode} + % \newdimen\col@sep + % \def\@acol{\@addtopreamble{\hskip\col@sep}} + % % \def\@acolampacol{\@acol\@addamp\@acol} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \subsubsection{The macro \texttt{\textbackslash @mkpream}} +% ^^A +% ^^A \begin{macro}{\@mkpream} +% ^^A \begin{macro}{\the@toks} +% ^^A \label{@mkpream} +% ^^A Now we can define the macro which builds up the preamble for the +% ^^A \verb=\halign=. +% ^^A First we initialize \verb=\@preamble=, \verb=\@lastchclass= +% ^^A and the boolean variable \verb=\if@firstamp=. +% \begin{macrocode} + % \def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue +% \end{macrocode} +% ^^A During the build-up of the preamble we cannot directly use the +% ^^A \verb=#= sign; this would lead to an error message in the next +% ^^A \verb=\@addtopreamble= call. +% ^^A Instead, we use the command \verb=\@sharp= at places where later +% ^^A a \verb=#= will be. +% ^^A This command is at first given the meaning \verb=\relax=; +% ^^A therefore it will not be expanded when the preamble +% ^^A is extended. +% ^^A In the macro \verb=\@array=, shortly before the \verb=\halign= +% ^^A is carried out, \verb=\@sharp= is given its final meaning. +% ^^A +% ^^A In a similar way, +% ^^A we deal with the commands \verb=\@startpbox= and +% ^^A \verb=\@endpbox=, although the reason is different here: these +% ^^A macros expand in many \textsf{tokens} which would delay the +% ^^A build-up of the preamble. % \begin{macrocode} - \@acolampacol \or + % \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax % \end{macrocode} -% Class $3$ requires no actions because all things necessary have -% been done by the preamble \textsf{token} \texttt{>}. +% ^^A Now we remove possible $*$-forms in the user preamble with the +% ^^A command \verb=\@xexpast=. As we already know, this command saves +% ^^A its result in the macro \verb=\@tempa=. % \begin{macrocode} - \or + % \@xexpast #1*0x\@@ % \end{macrocode} -% Class $4$ means that we are at the beginning of the preamble. -% Therefore we start the preamble with \verb=\hskip\col@sep= and -% then call \verb=\@firstampfalse=. This makes sure that a later -% \verb=\@addamp= inserts the character -% \verb=&= into the preamble. +% ^^A Afterwards we initialize all registers and macros, that we need +% ^^A for the build-up of the preamble. +% ^^A Since we want to start with the \textsf{token} register $0$, +% ^^A \verb=\count@= has to contain the value $-1$. % \begin{macrocode} - \@acol \@firstampfalse \or + % \count@\m@ne + % \let\the@toks\relax % \end{macrocode} -% For class $5$ \textsf{tokens} only the character \verb=&= is inserted -% as a column separator. Therefore we call \verb=\@addamp=. +% ^^A Then we call up \verb=\prepnext@tok= in order to prepare the +% ^^A \textsf{token} register $0$ for use. % \begin{macrocode} - \@addamp + % \prepnext@tok % \end{macrocode} -% Other cases are impossible. For an example -% $\verb=\@lastchclass= = 6$---as it might appear in a -% preamble of the form \verb=...!p...=---\texttt{p} would have -% been taken as an argument of \texttt{!}\ by \verb=\@testpach=. +% ^^A To evaluate the user preamble (without stars) saved in +% ^^A \verb=\@tempa= we use the \LaTeX--macro \verb=\@tfor=. +% ^^A The strange appearing construction with \verb=\expandafter= is +% ^^A based on the fact that we have to put the replacement text of +% ^^A \verb=\@tempa= and not the macro \verb=\@tempa= to this +% ^^A \LaTeX--macro. % \begin{macrocode} - \fi} + % \expandafter \@tfor \expandafter \@nextchar + % \expandafter :\expandafter =\@tempa \do % \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@classz} -% If the character class of the last \textsf{token} is $0$ we have -% \texttt{c}, \texttt{l}, \texttt{r} or an argument of \texttt{m}, -% \texttt{b} or\ \texttt{p}. In the first three cases the preamble -% must be extended the same way as if we had class $10$. The -% remaining two cases do not require any action because the space -% needed was generated by the last \textsf{token} (i.e.\ -% \texttt{m}, \texttt{b} or \texttt{p}). Since \verb=\@lastchclass= has -% the value $10$ at this point nothing happens when \verb=\@classx= is -% called. So the macro \verb=\@chlassz= may start like this: +% ^^A The body of this loop (the group after the \verb=\do=) +% ^^A is executed for one \textsf{token} at a time, whereas +% ^^A the current \textsf{token} is saved in \verb=\@nextchar=. +% ^^A At first we evaluate the current \textsf{token} with the already +% ^^A defined macro \verb=\@testpach=, i.e.\ we assign to +% ^^A \verb=\@chclass= the character class and to \verb=\@chnum= +% ^^A the character number of this \textsf{token}. % \begin{macrocode} -\def\@classz{\@classx + % {\@testpach % \end{macrocode} -% According to the definition of \verb=\insert@column= we must store -% the number of the \textsf{token} register in which a preceding -% \verb=>{..}= might have stored its argument into -% \verb=\@tempcnta=. +% ^^A Then we branch out depending on the value of \verb=\@chclass= into +% ^^A different macros that extend the preamble respectively. % \begin{macrocode} - \@tempcnta \count@ + % \ifcase \@chclass \@classz \or \@classi \or \@classii + % \or \save@decl \or \or \@classv \or \@classvi + % \or \@classvii \or \@classviii \or \@classix + % \or \@classx \fi % \end{macrocode} -% To have $\verb=\count@= = \verb=\@tmpcnta= + 1$ we prepare -% the next \textsf{token} register. +% ^^A Two cases deserve our special attention: Since the current +% ^^A \textsf{token} cannot have the character class $4$ (start) we +% ^^A have skipped this possibility. If the character class is $3$, +% ^^A only the content of \verb=\@nextchar= has to be saved into the current +% ^^A \textsf{token} register; therefore we call up \verb=\save@decl= +% ^^A directly and save a macro name. After the preamble has been +% ^^A extended we assign the value of \verb=\@chclass= to the counter +% ^^A \verb=\@lastchclass= to assure that this information will be available +% ^^A during the next run of the loop. % \begin{macrocode} - \prepnext@tok + % \@lastchclass\@chclass}% % \end{macrocode} -% Now the preamble must be extended with the column whose format -% can be determined by \verb=\@chnum=. +% ^^A After the loop has been finished space must still be added to +% ^^A the created preamble, depending on the last \textsf{token}. +% ^^A Depending on the value of \verb=\@lastchclass= we perform +% ^^A the necessary operations. % \begin{macrocode} - \@addtopreamble{\ifcase \@chnum + % \ifcase\@lastchclass % \end{macrocode} -% If \verb=\@chnum= has the value $0$ a centered column has to be -% generated. -% So we begin with stretchable space. +% ^^A If the last class equals $0$ we add a +% ^^A \verb=\hskip \col@sep=. % \begin{macrocode} - \hfil + % \@acol \or % \end{macrocode} -% The command \verb=\d@llarbegin= follows expanding into \verb=\begingroup= -% (in the \textsf{tabular}--environment) or into \verb=$=. Doing this -% (provided an appropriate setting of \verb=\d@llarbegin=) we achieve -% that the contents of the columns of an \textsf{array}--environment -% are set in math mode while those of a \textsf{tabular}--environment -% are set in LR mode. +% ^^A If it equals $1$ we do not add any additional space so that the +% ^^A horizontal lines do not exceed the vertical ones. % \begin{macrocode} - \d@llarbegin + % \or % \end{macrocode} -% Now we insert the contents of the two \textsf{token} registers -% and the symbol -% for the column entry (i.e.\ \verb=#= or -% more precise \verb=\@sharp=) using \verb=\insert@column=. +% ^^A Class $2$ is treated like class $0$ because a \verb=<{...}= can +% ^^A only directly follow after class $0$. % \begin{macrocode} - \insert@column + % \@acol \or % \end{macrocode} -% We end this case with \verb=\d@llarend= and \verb=\hfil= where \verb=\d@llarend= -% again is either \verb=$= or \verb=\endgroup=. +% ^^A Most of the other possibilities can only appear if the user +% ^^A preamble was defective. Class $3$ is not allowed since after a +% ^^A \verb=>{..}= there must always follow a \texttt{c}, \texttt{l}, +% ^^A \texttt{r}, \texttt{p},\texttt{m} or \texttt{b}. We report an +% ^^A error and ignore the declaration given by \verb={..}=. % \begin{macrocode} - \d@llarend \hfil \or + % \@preamerr \thr@@ \or % \end{macrocode} -% The templates for \texttt{l} and \texttt{r} (i.e.\ \verb=\@chnum= $1$ -% or $2$) are generated the same way. Since one \verb=\hfil= is -% missing the text is moved to the relevant side. -% The \verb=\kern\z@= is needed in case of an empty column -% entry. Otherwise -% the \verb=\unskip= in \verb=\insert@column= removes the -% \verb=\hfil=. Changed to \verb=\hskip1sp= so that it interacts better with -% \verb=\@bsphack=. +% ^^A If \verb=\@lastchclass= is $4$ the user preamble has been empty. +% ^^A To continue, we insert a \verb=#= in the preamble. % \begin{macrocode} - \hskip1sp\d@llarbegin \insert@column \d@llarend \hfil \or - \hfil\hskip1sp\d@llarbegin \insert@column \d@llarend \or + % \@preamerr \tw@ \@addtopreamble\@sharp \or % \end{macrocode} -% The templates for \texttt{p}, \texttt{m} and \texttt{b} mainly -% consist of a \textsf{box}. In case of \texttt{m} it is generated -% by \verb=\vcenter=. This command is allowed only in math -% mode. Therefore we start with a~\verb=$=. +% ^^A Class $5$ is allowed again. In this case +% ^^A (the user preamble ends with \verb=@{..}=) we need not +% ^^A do anything. % \begin{macrocode} - $\vcenter%$ emacs + % \or % \end{macrocode} -% The part of the templates which is the same in all three cases -% (\texttt{p}, \texttt{m} and \texttt{b}) -% is built by the macros \verb=\@startpbox= and -% \verb=\@endpbox=. \verb=\@startpbox= has an argument: -% the width of the column which is stored in the current -% \textsf{token} (i.e.\ \verb=\@nextchar=). -% Between these two macros we find the well known -% \verb=\insert@column=. +% ^^A Any other case means that the arguments to \verb=@=, \texttt{!}, +% ^^A \texttt{<}, \texttt{>}, \texttt{p}, \texttt{m} or \texttt{b} have +% ^^A been forgotten. So we report an error and ignore the last +% ^^A \textsf{token}. % \begin{macrocode} - \@startpbox{\@nextchar}\insert@column \@endpbox $\or%$ emacs + % \else \@preamerr \@ne \fi % \end{macrocode} -% The templates for \texttt{p} and \texttt{b} are generated in the -% same way though we do not need the \verb=$= characters because we use -% \verb=\vtop= or \verb=\vbox=. +% ^^A Now that the build-up of the preamble is almost finished we can +% ^^A insert the \textsf{token} registers and therefore redefine +% ^^A \verb=\the@toks=. The actual insertion, though, is performed +% ^^A later. % \begin{macrocode} - \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or - \vbox \@startpbox{\@nextchar}\insert@column \@endpbox + % \def\the@toks{\the\toks}} % \end{macrocode} -% Other values for \verb=\@chnum= are impossible. Therefore we -% end the arguments to \verb=\@addtopreamble= and \verb=\ifcase=. -% Before we come to the end of \verb=\@classz= we have to -% prepare the next \textsf{token} register. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{The macros \texttt{\textbackslash @classz} +% ^^A to \texttt{\textbackslash @classx}} +% ^^A +% ^^A The preamble is extended by the macros \verb=\@classz= to +% ^^A \verb=\@classx= which are called by \verb=\@mkpream= +% ^^A depending on \verb=\@lastchclass= +% ^^A (i.e. the character class of the last \textsf{token}). +% ^^A \begin{macro}{\@classx} +% ^^A First we define =\@classx= because of its important r\^ole. +% ^^A When it is called we find that the current +% ^^A \textsf{token} is \texttt{p}, \texttt{m} or \texttt{b}. +% ^^A That means that a new column has to start. % \begin{macrocode} - \fi}\prepnext@tok} + % \def\@classx{% % \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@classix} -% In case of class $9$ (\texttt{>}--\textsf{token}) we first check -% if the character class of the last -% \textsf{token} was $3$. In this case we have a -% user preamble of the form \verb=..>{...}>{...}..= which -% is not allowed. We only give an error message and continue. -% So the declarations defined by the first \verb=>{...}= -% are ignored. +% ^^A Depending on the value of \verb=\@lastchclass= different actions +% ^^A must take place: % \begin{macrocode} -\def\@classix{\ifnum \@lastchclass = \thr@@ - \@preamerr \thr@@ \fi + % \ifcase \@lastchclass % \end{macrocode} -% Furthermore, we call up \verb=\@class10= because afterwards always a -% new column is started by \texttt{c}, \texttt{l}, \texttt{r}, -% \texttt{p}, \texttt{m} or \texttt{b}. +% ^^A If the last character class was $0$ we separate the columns by +% ^^A \verb=\hskip\col@sep= followed by \verb=&= and another +% ^^A \verb=\hskip\col@sep=. % \begin{macrocode} - \@classx} + % \@acolampacol \or % \end{macrocode} -% \end{macro} -% -% -% -% \begin{macro}{\@classviii} -% If the current \textsf{token} is a \texttt{<} the last character -% class must be $0$. In this case it is not necessary to extend the -% preamble. Otherwise we output an error message, set \verb=\@chclass= -% to $6$ and call \verb=\@classvi=. By doing this we achieve that -% \texttt{<} is treated like \texttt{!}. +% ^^A If the last class was class $1$ --- that means that a vertical +% ^^A line was +% ^^A drawn, --- before this line a \verb=\hskip\col@sep= was inserted. +% ^^A Therefore there has to be only a \verb=&= followed by +% ^^A \verb=\hskip\col@sep=. But this \verb=&= may be inserted only +% ^^A if this is not the first column. This process is controlled +% ^^A by \verb=\if@firstamp= in the macro \verb=\addamp=. % \begin{macrocode} -\def\@classviii{\ifnum \@lastchclass >\z@ - \@preamerr 4\@chclass 6 \@classvi \fi} + % \@addamp \@acol \or % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@arrayrule} -% There is only one incompatibility with the original definition: -% the definition of \verb=\@arrayrule=. In the original a line without -% width\footnote{So the space between \texttt{cc} and \texttt{c|c} -% is equal.} is created by multiple insertions of -% \verb=\hskip .5\arrayrulewidth=. -% We only insert a vertical line into the -% preamble. This is done to prevent problems with \TeX's main -% memory when generating tables with many vertical lines in them -% (especially in the case of \textsf{floats}). +% ^^A Class $2$ is treated like class $0$ because \verb=<{...}= can only +% ^^A follow after class $0$. % \begin{macrocode} -\def\@arrayrule{\@addtopreamble \vline} + % \@acolampacol \or % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classvii} -% As a consequence it follows that in case of class $7$ -% (\verb=@= \textsf{token}) the preamble need not to be extended. -% In the original definition $\verb=\@lastchclass= = 1$ -% is treated by inserting \verb=\hskip .5\arrayrulewidth=. -% We only check if the last \textsf{token} was of class $3$ which is -% forbidden. +% ^^A Class $3$ requires no actions because all things necessary have +% ^^A been done by the preamble \textsf{token} \texttt{>}. % \begin{macrocode} -\def\@classvii{\ifnum \@lastchclass = \thr@@ + % \or % \end{macrocode} -% If this is true we output an error message and -% ignore the declarations stored -% by the last \verb=>{...}=, because these are overwritten -% by the argument of \texttt{@}. +% ^^A Class $4$ means that we are at the beginning of the preamble. +% ^^A Therefore we start the preamble with \verb=\hskip\col@sep= and +% ^^A then call \verb=\@firstampfalse=. This makes sure that a later +% ^^A \verb=\@addamp= inserts the character +% ^^A \verb=&= into the preamble. % \begin{macrocode} - \@preamerr \thr@@ \fi} + % \@acol \@firstampfalse \or % \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@classvi} -% If the current \textsf{token} is a regular \texttt{!}\ and the -% last class was $0$ or $2$ we extend the preamble with -% \verb=\hskip\col@sep=. If the last \textsf{token} was of class $1$ -% (for instance \texttt{|}) we extend with \verb=\hskip \doublerulesep= -% because the construction \verb=!{...}= has to be treated like -% \texttt{|}. +% ^^A For class $5$ \textsf{tokens} only the character \verb=&= is inserted +% ^^A as a column separator. Therefore we call \verb=\@addamp=. % \begin{macrocode} -\def\@classvi{\ifcase \@lastchclass - \@acol \or - \@addtopreamble{\hskip \doublerulesep}\or - \@acol \or + % \@addamp % \end{macrocode} -% Now \verb=\@preamerr...= should follow because a -% user preamble of the form \verb=..>{..}!.= is not allowed. -% To save memory we call \verb=\@classvii= instead which also -% does what we want. +% ^^A Other cases are impossible. For an example +% ^^A $\verb=\@lastchclass= = 6$---as it might appear in a +% ^^A preamble of the form \verb=...!p...=---\texttt{p} would have +% ^^A been taken as an argument of \texttt{!}\ by \verb=\@testpach=. % \begin{macrocode} - \@classvii + % \fi} % \end{macrocode} -% If \verb=\@lastchclass= is $4$ or $5$ nothing has to be done. -% Class $6$ to $10$ are not possible. -% So we finish the macro. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\@classz} +% ^^A If the character class of the last \textsf{token} is $0$ we have +% ^^A \texttt{c}, \texttt{l}, \texttt{r} or an argument of \texttt{m}, +% ^^A \texttt{b} or\ \texttt{p}. In the first three cases the preamble +% ^^A must be extended the same way as if we had class $10$. The +% ^^A remaining two cases do not require any action because the space +% ^^A needed was generated by the last \textsf{token} (i.e.\ +% ^^A \texttt{m}, \texttt{b} or \texttt{p}). Since \verb=\@lastchclass= has +% ^^A the value $10$ at this point nothing happens when \verb=\@classx= is +% ^^A called. So the macro \verb=\@chlassz= may start like this: % \begin{macrocode} - \fi} + % \def\@classz{\@classx % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classii} -% \begin{macro}{\@classiii} -% In the case of character classes $2$ and $3$ (i.e.\ the argument -% of \texttt{<} or \texttt{>}) we only have to store the current -% \textsf{token} (\verb=\@nextchar=) into the corresponding -% \textsf{token} register since the preparation and -% insertion of these registers -% are done by the macro \verb=\@classz=. -% This is equivalent to calling \verb=\save@decl= in the case of -% class $3$. To save command identifiers we do this call up -% in the macro \verb=\@mkpream=. -% -% Class $2$ exhibits a more complicated situation: the -% \textsf{token} registers have already been inserted by -% \verb=\@classz=. So the value of \verb=\count@= is too high -% by one. Therefore we decrease \verb=\count@= by $1$. +% ^^A According to the definition of \verb=\insert@column= we must store +% ^^A the number of the \textsf{token} register in which a preceding +% ^^A \verb=>{..}= might have stored its argument into +% ^^A \verb=\@tempcnta=. % \begin{macrocode} -\def\@classii{\advance \count@ \m@ne + % \@tempcnta \count@ % \end{macrocode} -% Next we store the current \textsf{token} into the correct -% \textsf{token} register by calling \verb=\save@decl= and then -% increase the value of \verb=\count@= again. At this point we -% can save memory once more (at the cost of time) if we use the -% macro \verb=\prepnext@tok=. +% ^^A To have $\verb=\count@= = \verb=\@tmpcnta= + 1$ we prepare +% ^^A the next \textsf{token} register. % \begin{macrocode} - \save@decl\prepnext@tok} + % \prepnext@tok % \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% \begin{macro}{\@classv} -% If the current \textsf{token} is of class $5$ then it is an -% argument of a \texttt{@} \textsf{token}. It must be stored into a -% \textsf{token} register. +% ^^A Now the preamble must be extended with the column whose format +% ^^A can be determined by \verb=\@chnum=. % \begin{macrocode} -\def\@classv{\save@decl + % \@addtopreamble{\ifcase \@chnum % \end{macrocode} -% We extend the preamble with a command which inserts this -% \textsf{token} register into the preamble when its construction -% is finished. The user expects that this argument is worked out in -% math mode if it was used in an -% \textsf{array}--environment. Therefore we surround it with -% \verb=\d@llar...='s. +% ^^A If \verb=\@chnum= has the value $0$ a centered column has to be +% ^^A generated. +% ^^A So we begin with stretchable space. % \begin{macrocode} - \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}% + % \hfil % \end{macrocode} -% Finally we must prepare the next \textsf{token} register. +% ^^A The command \verb=\d@llarbegin= follows expanding into \verb=\begingroup= +% ^^A (in the \textsf{tabular}--environment) or into \verb=$=. Doing this +% ^^A (provided an appropriate setting of \verb=\d@llarbegin=) we achieve +% ^^A that the contents of the columns of an \textsf{array}--environment +% ^^A are set in math mode while those of a \textsf{tabular}--environment +% ^^A are set in LR mode. % \begin{macrocode} - \prepnext@tok} + % \d@llarbegin % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classi} -% In the case of class $0$ we were able to generate the necessary -% space between columns by using the macro \verb=\@classx=. -% Analogously the macro \verb=\@classvi= can be used for class $1$. +% ^^A Now we insert the contents of the two \textsf{token} registers +% ^^A and the symbol +% ^^A for the column entry (i.e.\ \verb=#= or +% ^^A more precise \verb=\@sharp=) using \verb=\insert@column=. % \begin{macrocode} -\def\@classi{\@classvi + % \insert@column % \end{macrocode} -% Depending on \verb=\@chnum= a vertical line +% ^^A We end this case with \verb=\d@llarend= and \verb=\hfil= where \verb=\d@llarend= +% ^^A again is either \verb=$= or \verb=\endgroup=. % \begin{macrocode} - \ifcase \@chnum \@arrayrule \or + % \d@llarend \hfil \or % \end{macrocode} -% or (in case of \verb=!{...}=) the current \textsf{token} --- stored -% in \verb=\@nextchar= --- has to be inserted into the preamble. -% This corresponds to calling \verb=\@classv=. +% ^^A The templates for \texttt{l} and \texttt{r} (i.e.\ \verb=\@chnum= $1$ +% ^^A or $2$) are generated the same way. Since one \verb=\hfil= is +% ^^A missing the text is moved to the relevant side. +% ^^A The \verb=\kern\z@= is needed in case of an empty column +% ^^A entry. Otherwise +% ^^A the \verb=\unskip= in \verb=\insert@column= removes the +% ^^A \verb=\hfil=. Changed to \verb=\hskip1sp= so that it interacts better with +% ^^A \verb=\@bsphack=. % \begin{macrocode} - \@classv \fi} + % \hskip1sp\d@llarbegin \insert@column \d@llarend \hfil \or + % \hfil\hskip1sp\d@llarbegin \insert@column \d@llarend \or % \end{macrocode} -% \end{macro} -% -% -% -% \begin{macro}{\@startpbox} -% In \verb=\@classz= the macro \verb=\@startpbox= is used. -% The width of the \textsf{parbox} is passed as an argument. -% \verb=\vcenter=, \verb=\vtop= or \verb=\vbox= are already in the -% preamble. So we start with the braces for the wanted box. +% ^^A The templates for \texttt{p}, \texttt{m} and \texttt{b} mainly +% ^^A consist of a \textsf{box}. In case of \texttt{m} it is generated +% ^^A by \verb=\vcenter=. This command is allowed only in math +% ^^A mode. Therefore we start with a~\verb=$=. % \begin{macrocode} -\def\@startpbox#1{\bgroup + % $\vcenter%$ emacs % \end{macrocode} -% The argument is the width of the box. This information has to be -% assigned to \verb=\hsize=. -% Then we assign default values to several parameters used in a -% \textsf{parbox}. +% ^^A The part of the templates which is the same in all three cases +% ^^A (\texttt{p}, \texttt{m} and \texttt{b}) +% ^^A is built by the macros \verb=\@startpbox= and +% ^^A \verb=\@endpbox=. \verb=\@startpbox= has an argument: +% ^^A the width of the column which is stored in the current +% ^^A \textsf{token} (i.e.\ \verb=\@nextchar=). +% ^^A Between these two macros we find the well known +% ^^A \verb=\insert@column=. % \begin{macrocode} - \setlength\hsize{#1}\@arrayparboxrestore + % \@startpbox{\@nextchar}\insert@column \@endpbox $\or%$ emacs % \end{macrocode} -% Our main problem is to obtain the same distance between succeeding -% lines of the \textsf{parbox}. -% We have to remember that the distance between two \textsf{parboxes} -% should be defined by \verb=\@arstrut=. That means that it can be -% greater than the distance in a \textsf{parbox}. -% Therefore it is not enough to set a \verb=\@arstrut= at the -% beginning and at the end of the \textsf{parbox}. This would -% dimension the distance -% between first and second line and the distance between the two -% last lines of the \textsf{parbox} wrongly. -% To prevent this we set an invisible rule of height -% \verb=\@arstrutbox= -% at the beginning of the \textsf{parbox}. This has no effect on the -% depth of the first line. At the end of the \textsf{parbox} we set -% analogously another invisible rule which only affects the depth -% of the last line. It is necessary to wait inserting this strut -% until the paragraph actually starts to allow for things like -% \verb=\parindent= changes via \verb=>{...}=. +% ^^A The templates for \texttt{p} and \texttt{b} are generated in the +% ^^A same way though we do not need the \verb=$= characters because we use +% ^^A \verb=\vtop= or \verb=\vbox=. % \begin{macrocode} - \everypar{% - \vrule \@height \ht\@arstrutbox \@width \z@ - \everypar{}}% - } + % \vtop \@startpbox{\@nextchar}\insert@column \@endpbox \or + % \vbox \@startpbox{\@nextchar}\insert@column \@endpbox % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@endpbox} -% If there are any declarations defined by \verb=>{...}= -% and \verb=<{...}= -% they now follow in the macro \verb=\@classz= --- the contents -% of the column in between. -% So the macro \verb=\@endpbox= must insert the \textsf{specialstrut} -% mentioned earlier and then close the group opened by -% \verb=\@startpbox=. +% ^^A Other values for \verb=\@chnum= are impossible. Therefore we +% ^^A end the arguments to \verb=\@addtopreamble= and \verb=\ifcase=. +% ^^A Before we come to the end of \verb=\@classz= we have to +% ^^A prepare the next \textsf{token} register. % \begin{macrocode} -\def\@endpbox{\@finalstrut\@arstrutbox \egroup\hfil} + % \fi}\prepnext@tok} % \end{macrocode} -% \end{macro} -% -% -% \subsubsection{Building and calling \texttt{\textbackslash halign}} -% -% \begin{macro}{\@array} -% After we have discussed the macros needed for the evaluation -% of the user preamble we can define the macro \verb=\@array= -% which uses these macros to create a \verb=\halign=. -% It has two arguments. The first one is a position argument -% which can be \texttt{t}, \texttt{b} or \texttt{c}; the -% second one describes the wanted preamble, -% e.g.\ it has the form \verb=|c|c|c|=. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\@classix} +% ^^A In case of class $9$ (\texttt{>}--\textsf{token}) we first check +% ^^A if the character class of the last +% ^^A \textsf{token} was $3$. In this case we have a +% ^^A user preamble of the form \verb=..>{...}>{...}..= which +% ^^A is not allowed. We only give an error message and continue. +% ^^A So the declarations defined by the first \verb=>{...}= +% ^^A are ignored. % \begin{macrocode} -\def\@array[#1]#2{% + % \def\@classix{\ifnum \@lastchclass = \thr@@ + % \@preamerr \thr@@ \fi % \end{macrocode} -% First we define a \textsf{strut} whose size basically corresponds -% to a normal \textsf{strut} multiplied by the factor -% \verb=\arraystretch=. -% This \textsf{strut} is then inserted into every row and enforces -% a minimal distance between two rows. -% Nevertheless, when using horizontal lines, large letters -% (like accented capital letters) still collide with such lines. -% Therefore at first we add to the height of a normal \textsf{strut} -% the value of the parameter \verb=\extrarowheight=. +% ^^A Furthermore, we call up \verb=\@class10= because afterwards always a +% ^^A new column is started by \texttt{c}, \texttt{l}, \texttt{r}, +% ^^A \texttt{p}, \texttt{m} or \texttt{b}. % \begin{macrocode} - \@tempdima \ht \strutbox - \advance \@tempdima by\extrarowheight - \setbox \@arstrutbox \hbox{\vrule - \@height \arraystretch \@tempdima - \@depth \arraystretch \dp \strutbox - \@width \z@}% + % \@classx} % \end{macrocode} -% Then we open a group, in which the user preamble is evaluated by -% the macro \verb=\@mkpream=. As we know this must happen locally. -% This macro creates a preamble for a \verb=\halign= and saves -% its result globally in the control sequence \verb=\@preamble=. -% \begin{macrocode} - \begingroup - \@mkpream{#2}% -% \end{macrocode} -% We again redefine \verb=\@preamble= so that a call up of \verb=\@preamble= -% now starts the \verb=\halign=. Thus also the arguments of \texttt{>}, -% \texttt{<}, \texttt{@} and \texttt{!}, saved in the -% \textsf{token} registers are inserted into the preamble. The -% \verb=\tabskip= at the beginning and end of the preamble is set to -% \textsf{0pt} (in the beginning by the use of \verb=\ialign=). Also the -% command \verb=\@arstrut= is build in, which inserts the -% \verb=\@arstrutbox=, defined above. Of course, the opening brace after -% \verb=\ialign= has to be implicit as it will be closed in \verb=\endarray= -% or another macro. -% -% The \verb=\noexpand= in front of \verb=\ialign= does no harm in standard \LaTeX{} -% and was added since some experimental support for using text glyphs in math -% redefines \verb=\halign= with the result that is becomes expandable with -% disastrous results in cases like this. -% In the kernel definition for this macro the problem does -% not surface because there \verb=\protect= is set (which is not necessary in this -% implementation as there is no arbitrary user input that can get expanded) and -% the experimental code made the redefinition robust. Whether this is the right -% approach is open to question; consider the \verb=\noexpand= a courtesy to allow an -% unsupported redefinition of a \TeX{} primitive for the moment (as people rely -% on that experimental code). -% \begin{macrocode} - \xdef\@preamble{\noexpand \ialign \@halignto - \bgroup \@arstrut \@preamble - \tabskip \z@ \cr}% -% \end{macrocode} -% What we have not explained yet is the macro \verb=\@halignto= -% that was just used. Depending on its replacement text the -% \verb=\halign= becomes a \verb=\halign= \texttt{to} \meta{dimen}. -% Now we close the group again. Thus -% \verb=\@startpbox= and \verb=\@endpbox= as well as all -% \textsf{token} registers get their former meaning back. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \begin{macro}{\@classviii} +% ^^A If the current \textsf{token} is a \texttt{<} the last character +% ^^A class must be $0$. In this case it is not necessary to extend the +% ^^A preamble. Otherwise we output an error message, set \verb=\@chclass= +% ^^A to $6$ and call \verb=\@classvi=. By doing this we achieve that +% ^^A \texttt{<} is treated like \texttt{!}. % \begin{macrocode} - \endgroup + % \def\@classviii{\ifnum \@lastchclass >\z@ + % \@preamerr 4\@chclass 6 \@classvi \fi} % \end{macrocode} -% To support the \texttt{delarray.sty} package we include a hook -% into this part of the code which is a no-op in the main package. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@arrayrule} +% ^^A There is only one incompatibility with the original definition: +% ^^A the definition of \verb=\@arrayrule=. In the original a line without +% ^^A width\footnote{So the space between \texttt{cc} and \texttt{c|c} +% ^^A is equal.} is created by multiple insertions of +% ^^A \verb=\hskip .5\arrayrulewidth=. +% ^^A We only insert a vertical line into the +% ^^A preamble. This is done to prevent problems with \TeX's main +% ^^A memory when generating tables with many vertical lines in them +% ^^A (especially in the case of \textsf{floats}). +% \begin{macrocode} + % \def\@arrayrule{\@addtopreamble \vline} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classvii} +% ^^A As a consequence it follows that in case of class $7$ +% ^^A (\verb=@= \textsf{token}) the preamble need not to be extended. +% ^^A In the original definition $\verb=\@lastchclass= = 1$ +% ^^A is treated by inserting \verb=\hskip .5\arrayrulewidth=. +% ^^A We only check if the last \textsf{token} was of class $3$ which is +% ^^A forbidden. % \begin{macrocode} - \@arrayleft + % \def\@classvii{\ifnum \@lastchclass = \thr@@ % \end{macrocode} -% Now we decide depending on the position argument in which -% \textsf{box} the \verb=\halign= is to be put. (\verb=\vcenter= may be used -% because we are in math mode.) +% ^^A If this is true we output an error message and +% ^^A ignore the declarations stored +% ^^A by the last \verb=>{...}=, because these are overwritten +% ^^A by the argument of \texttt{@}. % \begin{macrocode} - \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi + % \@preamerr \thr@@ \fi} % \end{macrocode} -% Now another implicit opening brace appears; then definitions -% which shall stay local follow. While constructing the -% \verb=\@preamble= in \verb=\@mkpream= the \verb=#= sign must be -% hidden in the macro \verb=\@sharp= which is \verb=\let= to -% \verb=\relax= at that moment (see definition of \verb=\@mkpream= -% on page~\pageref{@mkpream}). -% All these now get their actual meaning. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\@classvi} +% ^^A If the current \textsf{token} is a regular \texttt{!}\ and the +% ^^A last class was $0$ or $2$ we extend the preamble with +% ^^A \verb=\hskip\col@sep=. If the last \textsf{token} was of class $1$ +% ^^A (for instance \texttt{|}) we extend with \verb=\hskip \doublerulesep= +% ^^A because the construction \verb=!{...}= has to be treated like +% ^^A \texttt{|}. % \begin{macrocode} - \bgroup - \let \@sharp ##\let \protect \relax + % \def\@classvi{\ifcase \@lastchclass + % \@acol \or + % \@addtopreamble{\hskip \doublerulesep}\or + % \@acol \or % \end{macrocode} -% With the above defined \textsf{struts} we fix down the distance -% between rows by setting \verb=\lineskip= and \verb=\baselineskip= -% to \textsf{0pt}. Since there have to be set \verb=$='s -% around every column in the \textsf{array}--environment -% the parameter \verb=\mathsurround= should -% also be set to \textsf{0pt}. This prevents additional space between -% the rows. The -% \PlainTeX--macro \verb=\m@th= does this. +% ^^A Now \verb=\@preamerr...= should follow because a +% ^^A user preamble of the form \verb=..>{..}!.= is not allowed. +% ^^A To save memory we call \verb=\@classvii= instead which also +% ^^A does what we want. % \begin{macrocode} - \lineskip \z@ - \baselineskip \z@ - \m@th + % \@classvii % \end{macrocode} -% Beside, we have to assign a special meaning (which we still have -% to specify) to the line separator \verb=\\=. We also have to -% redefine the command \verb=\par= in such a way that empty lines in -% \verb=\halign= cannot do any damage. We succeed in doing so -% by choosing something that will disappear when expanding. -% After that we only have to call up \verb=\@preamble= to -% start the wanted \verb=\halign=. +% ^^A If \verb=\@lastchclass= is $4$ or $5$ nothing has to be done. +% ^^A Class $6$ to $10$ are not possible. +% ^^A So we finish the macro. % \begin{macrocode} - \let\\\@arraycr \let\tabularnewline\\\let\par\@empty \@preamble} + % \fi} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\arraybackslash} -% Restore \verb=\\= for use in array and tabular environment (after -% \verb=\raggedright= etc.). +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classii} +% ^^A \begin{macro}{\@classiii} +% ^^A In the case of character classes $2$ and $3$ (i.e.\ the argument +% ^^A of \texttt{<} or \texttt{>}) we only have to store the current +% ^^A \textsf{token} (\verb=\@nextchar=) into the corresponding +% ^^A \textsf{token} register since the preparation and +% ^^A insertion of these registers +% ^^A are done by the macro \verb=\@classz=. +% ^^A This is equivalent to calling \verb=\save@decl= in the case of +% ^^A class $3$. To save command identifiers we do this call up +% ^^A in the macro \verb=\@mkpream=. +% ^^A +% ^^A Class $2$ exhibits a more complicated situation: the +% ^^A \textsf{token} registers have already been inserted by +% ^^A \verb=\@classz=. So the value of \verb=\count@= is too high +% ^^A by one. Therefore we decrease \verb=\count@= by $1$. % \begin{macrocode} -\def\arraybackslash{\let\\\tabularnewline} + % \def\@classii{\advance \count@ \m@ne % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\extrarowheight} -% The \textsf{dimen} parameter used above also needs to be -% allocated. As a default value we use \textsf{0pt}, to ensure -% compatibility with standard \LaTeX. +% ^^A Next we store the current \textsf{token} into the correct +% ^^A \textsf{token} register by calling \verb=\save@decl= and then +% ^^A increase the value of \verb=\count@= again. At this point we +% ^^A can save memory once more (at the cost of time) if we use the +% ^^A macro \verb=\prepnext@tok=. % \begin{macrocode} -\newdimen \extrarowheight -\extrarowheight=0pt + % \save@decl\prepnext@tok} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@arstrut} -% Now the insertion of \verb=\@arstrutbox= through \verb=\@arstut= -% is easy since we know exactly in which mode \TeX\ is while working -% on the \verb=\halign= preamble. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\@classv} +% ^^A If the current \textsf{token} is of class $5$ then it is an +% ^^A argument of a \texttt{@} \textsf{token}. It must be stored into a +% ^^A \textsf{token} register. % \begin{macrocode} -\def\@arstrut{\unhcopy\@arstrutbox} + % \def\@classv{\save@decl % \end{macrocode} -% \end{macro} -% -% -% \subsubsection{The line separator \texttt{\textbackslash\textbackslash}} -% -% \begin{macro}{\@arraycr} -% In the macro \verb=\@array= the line separator \verb=\\= is -% \verb=\let= to the command \verb=\@arraycr=. -% Its definition starts with a special brace which I have directly -% copied from the original definition. It is -% necessary, because the \verb=\futurlet= in \verb=\@ifnextchar= -% might -% expand a following \verb=&= \textsf{token} in a construction like -% \verb=\\ &=. This would otherwise end the alignment template at a -% wrong time. On the other hand we have to be careful to avoid -% producing a real group, i.e.\ \verb={}=, because the command will also -% be used for the array environment, i.e.\ in math mode. In that -% case an extra \verb={}= would produce an ord atom which could mess up -% the spacing. For this reason we use a combination that does not -% really produce a group at all but modifies the master counter so -% that a \verb=&= will not be considered belonging to the current -% \verb=\halign= while we are looking for a \verb=*= or \verb=[=. -% For further information see -% \cite[Appendix D]{bk:knuth}. +% ^^A We extend the preamble with a command which inserts this +% ^^A \textsf{token} register into the preamble when its construction +% ^^A is finished. The user expects that this argument is worked out in +% ^^A math mode if it was used in an +% ^^A \textsf{array}--environment. Therefore we surround it with +% ^^A \verb=\d@llar...='s. % \begin{macrocode} -\def\@arraycr{\relax\iffalse{\fi\ifnum 0=`}\fi + % \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}% % \end{macrocode} -% Then we test whether the user is using the star form and ignore -% a possible star (I also disagree with this procedure, because a -% star does not make any sense here). +% ^^A Finally we must prepare the next \textsf{token} register. % \begin{macrocode} - \@ifstar \@xarraycr \@xarraycr} + % \prepnext@tok} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@xarraycr} -% In the command \verb=\@xarraycr= we test if an optional argument -% exists. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classi} +% ^^A In the case of class $0$ we were able to generate the necessary +% ^^A space between columns by using the macro \verb=\@classx=. +% ^^A Analogously the macro \verb=\@classvi= can be used for class $1$. % \begin{macrocode} -\def\@xarraycr{\@ifnextchar [% + % \def\@classi{\@classvi % \end{macrocode} -% If it does, we branch out into the macro \verb=\@argarraycr= if -% not we close the special brace (mentioned above) and end the row -% of the \verb=\halign= with a \verb=\cr=. +% ^^A Depending on \verb=\@chnum= a vertical line % \begin{macrocode} - \@argarraycr {\ifnum 0=`{}\fi\cr}} + % \ifcase \@chnum \@arrayrule \or % \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\@argarraycr} -% If additional space is requested by the user this case is treated -% in the macro \verb=\@argarraycr=. First we close the special brace -% and then we test if the additional space is positive. +% ^^A or (in case of \verb=!{...}=) the current \textsf{token} --- stored +% ^^A in \verb=\@nextchar= --- has to be inserted into the preamble. +% ^^A This corresponds to calling \verb=\@classv=. % \begin{macrocode} -\def\@argarraycr[#1]{\ifnum0=`{}\fi\ifdim #1>\z@ + % \@classv \fi} % \end{macrocode} -% If this is the case we create an invisible vertical rule with -% depth \verb=\dp\@arstutbox=${}+{}$\meta{wanted\ space}. -% Thus we achieve that all vertical lines specified -% in the user preamble by a \texttt{|} are now -% generally drawn. -% Then the row ends with a \verb=\cr=. -% -% If the space is negative we end the row at once with a \verb=\cr= -% and move back up with a \verb=\vskip=. -% -% While testing these macros I found out that the -% \verb=\endtemplate= -% created by \verb=\cr= and \verb=&= is something like an -% \verb=\outer= primitive and therefore it should not appear in -% incomplete \verb=\if= statements. Thus the following solution was -% chosen which hides the \verb=\cr= in other macros when \TeX\ -% is skipping conditional text. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \begin{macro}{\@startpbox} +% ^^A In \verb=\@classz= the macro \verb=\@startpbox= is used. +% ^^A The width of the \textsf{parbox} is passed as an argument. +% ^^A \verb=\vcenter=, \verb=\vtop= or \verb=\vbox= are already in the +% ^^A preamble. So we start with the braces for the wanted box. +% \begin{macrocode} + % \def\@startpbox#1{\bgroup +% \end{macrocode} +% ^^A The argument is the width of the box. This information has to be +% ^^A assigned to \verb=\hsize=. +% ^^A Then we assign default values to several parameters used in a +% ^^A \textsf{parbox}. +% \begin{macrocode} + % \setlength\hsize{#1}\@arrayparboxrestore +% \end{macrocode} +% ^^A Our main problem is to obtain the same distance between succeeding +% ^^A lines of the \textsf{parbox}. +% ^^A We have to remember that the distance between two \textsf{parboxes} +% ^^A should be defined by \verb=\@arstrut=. That means that it can be +% ^^A greater than the distance in a \textsf{parbox}. +% ^^A Therefore it is not enough to set a \verb=\@arstrut= at the +% ^^A beginning and at the end of the \textsf{parbox}. This would +% ^^A dimension the distance +% ^^A between first and second line and the distance between the two +% ^^A last lines of the \textsf{parbox} wrongly. +% ^^A To prevent this we set an invisible rule of height +% ^^A \verb=\@arstrutbox= +% ^^A at the beginning of the \textsf{parbox}. This has no effect on the +% ^^A depth of the first line. At the end of the \textsf{parbox} we set +% ^^A analogously another invisible rule which only affects the depth +% ^^A of the last line. It is necessary to wait inserting this strut +% ^^A until the paragraph actually starts to allow for things like +% ^^A \verb=\parindent= changes via \verb=>{...}=. +% \begin{macrocode} + % \everypar{% + % \vrule \@height \ht\@arstrutbox \@width \z@ + % \everypar{}}% + % } +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@endpbox} +% ^^A If there are any declarations defined by \verb=>{...}= +% ^^A and \verb=<{...}= +% ^^A they now follow in the macro \verb=\@classz= --- the contents +% ^^A of the column in between. +% ^^A So the macro \verb=\@endpbox= must insert the \textsf{specialstrut} +% ^^A mentioned earlier and then close the group opened by +% ^^A \verb=\@startpbox=. +% \begin{macrocode} + % \def\@endpbox{\@finalstrut\@arstrutbox \egroup\hfil} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \subsubsection{Building and calling \texttt{\textbackslash halign}} +% ^^A +% ^^A \begin{macro}{\@array} +% ^^A After we have discussed the macros needed for the evaluation +% ^^A of the user preamble we can define the macro \verb=\@array= +% ^^A which uses these macros to create a \verb=\halign=. +% ^^A It has two arguments. The first one is a position argument +% ^^A which can be \texttt{t}, \texttt{b} or \texttt{c}; the +% ^^A second one describes the wanted preamble, +% ^^A e.g.\ it has the form \verb=|c|c|c|=. +% \begin{macrocode} + % \def\@array[#1]#2{% +% \end{macrocode} +% ^^A First we define a \textsf{strut} whose size basically corresponds +% ^^A to a normal \textsf{strut} multiplied by the factor +% ^^A \verb=\arraystretch=. +% ^^A This \textsf{strut} is then inserted into every row and enforces +% ^^A a minimal distance between two rows. +% ^^A Nevertheless, when using horizontal lines, large letters +% ^^A (like accented capital letters) still collide with such lines. +% ^^A Therefore at first we add to the height of a normal \textsf{strut} +% ^^A the value of the parameter \verb=\extrarowheight=. +% \begin{macrocode} + % \@tempdima \ht \strutbox + % \advance \@tempdima by\extrarowheight + % \setbox \@arstrutbox \hbox{\vrule + % \@height \arraystretch \@tempdima + % \@depth \arraystretch \dp \strutbox + % \@width \z@}% +% \end{macrocode} +% ^^A Then we open a group, in which the user preamble is evaluated by +% ^^A the macro \verb=\@mkpream=. As we know this must happen locally. +% ^^A This macro creates a preamble for a \verb=\halign= and saves +% ^^A its result globally in the control sequence \verb=\@preamble=. +% \begin{macrocode} + % \begingroup + % \@mkpream{#2}% +% \end{macrocode} +% ^^A We again redefine \verb=\@preamble= so that a call up of \verb=\@preamble= +% ^^A now starts the \verb=\halign=. Thus also the arguments of \texttt{>}, +% ^^A \texttt{<}, \texttt{@} and \texttt{!}, saved in the +% ^^A \textsf{token} registers are inserted into the preamble. The +% ^^A \verb=\tabskip= at the beginning and end of the preamble is set to +% ^^A \textsf{0pt} (in the beginning by the use of \verb=\ialign=). Also the +% ^^A command \verb=\@arstrut= is build in, which inserts the +% ^^A \verb=\@arstrutbox=, defined above. Of course, the opening brace after +% ^^A \verb=\ialign= has to be implicit as it will be closed in \verb=\endarray= +% ^^A or another macro. +% ^^A +% ^^A The \verb=\noexpand= in front of \verb=\ialign= does no harm in standard \LaTeX{} +% ^^A and was added since some experimental support for using text glyphs in math +% ^^A redefines \verb=\halign= with the result that is becomes expandable with +% ^^A disastrous results in cases like this. +% ^^A In the kernel definition for this macro the problem does +% ^^A not surface because there \verb=\protect= is set (which is not necessary in this +% ^^A implementation as there is no arbitrary user input that can get expanded) and +% ^^A the experimental code made the redefinition robust. Whether this is the right +% ^^A approach is open to question; consider the \verb=\noexpand= a courtesy to allow an +% ^^A unsupported redefinition of a \TeX{} primitive for the moment (as people rely +% ^^A on that experimental code). +% \begin{macrocode} + % \xdef\@preamble{\noexpand \ialign \@halignto + % \bgroup \@arstrut \@preamble + % \tabskip \z@ \cr}% +% \end{macrocode} +% ^^A What we have not explained yet is the macro \verb=\@halignto= +% ^^A that was just used. Depending on its replacement text the +% ^^A \verb=\halign= becomes a \verb=\halign= \texttt{to} \meta{dimen}. +% ^^A Now we close the group again. Thus +% ^^A \verb=\@startpbox= and \verb=\@endpbox= as well as all +% ^^A \textsf{token} registers get their former meaning back. +% \begin{macrocode} + % \endgroup +% \end{macrocode} +% ^^A To support the \texttt{delarray.sty} package we include a hook +% ^^A into this part of the code which is a no-op in the main package. +% \begin{macrocode} + % \@arrayleft +% \end{macrocode} +% ^^A Now we decide depending on the position argument in which +% ^^A \textsf{box} the \verb=\halign= is to be put. (\verb=\vcenter= may be used +% ^^A because we are in math mode.) +% \begin{macrocode} + % \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi +% \end{macrocode} +% ^^A Now another implicit opening brace appears; then definitions +% ^^A which shall stay local follow. While constructing the +% ^^A \verb=\@preamble= in \verb=\@mkpream= the \verb=#= sign must be +% ^^A hidden in the macro \verb=\@sharp= which is \verb=\let= to +% ^^A \verb=\relax= at that moment (see definition of \verb=\@mkpream= +% ^^A on page~\pageref{@mkpream}). +% ^^A All these now get their actual meaning. +% \begin{macrocode} + % \bgroup + % \let \@sharp ##\let \protect \relax +% \end{macrocode} +% ^^A With the above defined \textsf{struts} we fix down the distance +% ^^A between rows by setting \verb=\lineskip= and \verb=\baselineskip= +% ^^A to \textsf{0pt}. Since there have to be set \verb=$='s +% ^^A around every column in the \textsf{array}--environment +% ^^A the parameter \verb=\mathsurround= should +% ^^A also be set to \textsf{0pt}. This prevents additional space between +% ^^A the rows. The +% ^^A \PlainTeX--macro \verb=\m@th= does this. +% \begin{macrocode} + % \lineskip \z@ + % \baselineskip \z@ + % \m@th +% \end{macrocode} +% ^^A Beside, we have to assign a special meaning (which we still have +% ^^A to specify) to the line separator \verb=\\=. We also have to +% ^^A redefine the command \verb=\par= in such a way that empty lines in +% ^^A \verb=\halign= cannot do any damage. We succeed in doing so +% ^^A by choosing something that will disappear when expanding. +% ^^A After that we only have to call up \verb=\@preamble= to +% ^^A start the wanted \verb=\halign=. +% \begin{macrocode} + % \let\\\@arraycr \let\tabularnewline\\\let\par\@empty \@preamble} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\arraybackslash} +% ^^A Restore \verb=\\= for use in array and tabular environment (after +% ^^A \verb=\raggedright= etc.). % \begin{macrocode} - \expandafter\@xargarraycr\else - \expandafter\@yargarraycr\fi{#1}} + % \def\arraybackslash{\let\\\tabularnewline} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@xargarraycr} -% \begin{macro}{\@yargarraycr} -% The following macros were already explained above. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\extrarowheight} +% ^^A The \textsf{dimen} parameter used above also needs to be +% ^^A allocated. As a default value we use \textsf{0pt}, to ensure +% ^^A compatibility with standard \LaTeX. % \begin{macrocode} -\def\@xargarraycr#1{\unskip - \@tempdima #1\advance\@tempdima \dp\@arstrutbox - \vrule \@depth\@tempdima \@width\z@ \cr} -\def\@yargarraycr#1{\cr\noalign{\vskip #1}} + % \newdimen \extrarowheight + % \extrarowheight=0pt % \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% -% -% \subsubsection{Spanning several columns} -% -% \begin{macro}{\multicolumn} -% If several columns should be held together with a special format -% the command \verb=\multicolumn= must be used. It has three -% arguments: the number of columns to be covered; the format for -% the result column and the actual column entry. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@arstrut} +% ^^A Now the insertion of \verb=\@arstrutbox= through \verb=\@arstut= +% ^^A is easy since we know exactly in which mode \TeX\ is while working +% ^^A on the \verb=\halign= preamble. % \begin{macrocode} -\long\def\multicolumn#1#2#3{% + % \def\@arstrut{\unhcopy\@arstrutbox} % \end{macrocode} -% First we combine the given number of columns into a single one; -% then we start a new block so that the following definition is kept -% local. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \subsubsection{The line separator \texttt{\textbackslash\textbackslash}} +% ^^A +% ^^A \begin{macro}{\@arraycr} +% ^^A In the macro \verb=\@array= the line separator \verb=\\= is +% ^^A \verb=\let= to the command \verb=\@arraycr=. +% ^^A Its definition starts with a special brace which I have directly +% ^^A copied from the original definition. It is +% ^^A necessary, because the \verb=\futurlet= in \verb=\@ifnextchar= +% ^^A might +% ^^A expand a following \verb=&= \textsf{token} in a construction like +% ^^A \verb=\\ &=. This would otherwise end the alignment template at a +% ^^A wrong time. On the other hand we have to be careful to avoid +% ^^A producing a real group, i.e.\ \verb={}=, because the command will also +% ^^A be used for the array environment, i.e.\ in math mode. In that +% ^^A case an extra \verb={}= would produce an ord atom which could mess up +% ^^A the spacing. For this reason we use a combination that does not +% ^^A really produce a group at all but modifies the master counter so +% ^^A that a \verb=&= will not be considered belonging to the current +% ^^A \verb=\halign= while we are looking for a \verb=*= or \verb=[=. +% ^^A For further information see +% ^^A \cite[Appendix D]{bk:knuth}. +% \begin{macrocode} + % \def\@arraycr{\relax\iffalse{\fi\ifnum 0=`}\fi +% \end{macrocode} +% ^^A Then we test whether the user is using the star form and ignore +% ^^A a possible star (I also disagree with this procedure, because a +% ^^A star does not make any sense here). +% \begin{macrocode} + % \@ifstar \@xarraycr \@xarraycr} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@xarraycr} +% ^^A In the command \verb=\@xarraycr= we test if an optional argument +% ^^A exists. % \begin{macrocode} - \multispan{#1}\begingroup + % \def\@xarraycr{\@ifnextchar [% % \end{macrocode} -% Since a \verb=\multicolumn= should only describe the format of a -% result column, we redefine \verb=\@addamp= in such a way that one gets -% an error message if one uses more than one \texttt{c}, -% \texttt{l}, \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in -% the second argument. One should consider that this definition is -% local to the build-up of the preamble; an \textsf{array}-- or -% \textsf{tabular}--environment in the third argument of the -% \verb=\multicolumn= is therefore worked through correctly as well. +% ^^A If it does, we branch out into the macro \verb=\@argarraycr= if +% ^^A not we close the special brace (mentioned above) and end the row +% ^^A of the \verb=\halign= with a \verb=\cr=. % \begin{macrocode} - \def\@addamp{\if@firstamp \@firstampfalse \else - \@preamerr 5\fi}% + % \@argarraycr {\ifnum 0=`{}\fi\cr}} % \end{macrocode} -% Then we evaluate the second argument with the help of -% \verb=\@mkpream=. -% Now we still have to insert the contents of the \textsf{token} -% register into the \verb=\@preamble=, i.e.\ we have to say -% \verb=\xdef\@preamble{\@preamble}=. This is achieved shorter by -% writing: +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\@argarraycr} +% ^^A If additional space is requested by the user this case is treated +% ^^A in the macro \verb=\@argarraycr=. First we close the special brace +% ^^A and then we test if the additional space is positive. +% \begin{macrocode} + % \def\@argarraycr[#1]{\ifnum0=`{}\fi\ifdim #1>\z@ +% \end{macrocode} +% ^^A If this is the case we create an invisible vertical rule with +% ^^A depth \verb=\dp\@arstutbox=${}+{}$\meta{wanted\ space}. +% ^^A Thus we achieve that all vertical lines specified +% ^^A in the user preamble by a \texttt{|} are now +% ^^A generally drawn. +% ^^A Then the row ends with a \verb=\cr=. +% ^^A +% ^^A If the space is negative we end the row at once with a \verb=\cr= +% ^^A and move back up with a \verb=\vskip=. +% ^^A +% ^^A While testing these macros I found out that the +% ^^A \verb=\endtemplate= +% ^^A created by \verb=\cr= and \verb=&= is something like an +% ^^A \verb=\outer= primitive and therefore it should not appear in +% ^^A incomplete \verb=\if= statements. Thus the following solution was +% ^^A chosen which hides the \verb=\cr= in other macros when \TeX\ +% ^^A is skipping conditional text. +% \begin{macrocode} + % \expandafter\@xargarraycr\else + % \expandafter\@yargarraycr\fi{#1}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@xargarraycr} +% ^^A \begin{macro}{\@yargarraycr} +% ^^A The following macros were already explained above. % \begin{macrocode} - \@mkpream{#2}\@addtopreamble\@empty + % \def\@xargarraycr#1{\unskip + % \@tempdima #1\advance\@tempdima \dp\@arstrutbox + % \vrule \@depth\@tempdima \@width\z@ \cr} + % \def\@yargarraycr#1{\cr\noalign{\vskip #1}} % \end{macrocode} -% After the \verb=\@preamble= is created we forget all local -% definitions and occupations of the \textsf{token} registers. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{Spanning several columns} +% ^^A +% ^^A \begin{macro}{\multicolumn} +% ^^A If several columns should be held together with a special format +% ^^A the command \verb=\multicolumn= must be used. It has three +% ^^A arguments: the number of columns to be covered; the format for +% ^^A the result column and the actual column entry. +% \begin{macrocode} + % \long\def\multicolumn#1#2#3{% +% \end{macrocode} +% ^^A First we combine the given number of columns into a single one; +% ^^A then we start a new block so that the following definition is kept +% ^^A local. +% \begin{macrocode} + % \multispan{#1}\begingroup +% \end{macrocode} +% ^^A Since a \verb=\multicolumn= should only describe the format of a +% ^^A result column, we redefine \verb=\@addamp= in such a way that one gets +% ^^A an error message if one uses more than one \texttt{c}, +% ^^A \texttt{l}, \texttt{r}, \texttt{p}, \texttt{m} or \texttt{b} in +% ^^A the second argument. One should consider that this definition is +% ^^A local to the build-up of the preamble; an \textsf{array}-- or +% ^^A \textsf{tabular}--environment in the third argument of the +% ^^A \verb=\multicolumn= is therefore worked through correctly as well. +% \begin{macrocode} + % \def\@addamp{\if@firstamp \@firstampfalse \else + % \@preamerr 5\fi}% +% \end{macrocode} +% ^^A Then we evaluate the second argument with the help of +% ^^A \verb=\@mkpream=. +% ^^A Now we still have to insert the contents of the \textsf{token} +% ^^A register into the \verb=\@preamble=, i.e.\ we have to say +% ^^A \verb=\xdef\@preamble{\@preamble}=. This is achieved shorter by +% ^^A writing: +% \begin{macrocode} + % \@mkpream{#2}\@addtopreamble\@empty +% \end{macrocode} +% ^^A After the \verb=\@preamble= is created we forget all local +% ^^A definitions and occupations of the \textsf{token} registers. % \begin{macrocode} - \endgroup -% \end{macrocode} -% In the special situation of \verb=\multicolumn= \verb=\@preamble= -% is not needed as preamble for a \verb=\halign= but it is directly -% inserted into our table. Thus instead of \verb=\sharp= -% there has to be the column entry (\verb=#3=) wanted by the user. -% \begin{macrocode} - \def\@sharp{#3}% -% \end{macrocode} -% Now we can pass the \verb=\@preamble= to \TeX\ . For safety -% we start with an \verb=\@arstrut=. This should usually be in the -% template for the first column however we do not know if this -% template was overwritten by our \verb=\multicolumn=. -% We also add a \verb=\null= at the right end to prevent any following -% \verb=\unskip= (for example from \verb=\\[..]=) to remove the \verb=\tabcolsep=. -% \begin{macrocode} - \@arstrut \@preamble - \null - \ignorespaces} -% \end{macrocode} -% \end{macro} -% -% -% -% \subsubsection{The Environment Definitions} -% -% After these preparations we are able to define the environments. They -% only differ in the initialisations of \verb=\d@llar...=, \verb=\col@sep= -% and \verb=\@halignto=. -% -% \begin{macro}{\@halignto} -% \begin{macro}{\d@llarbegin} -% \begin{macro}{\d@llarend} -% \verb=\d@llar= has to be -% locally asigned since otherwise nested \textsf{tabular} and \textsf{array} -% environments (via \verb=\multicolumn=) are impossible. -% For 25 years or so \verb=\@halignto= was set globally (to save space on the -% save stack, but that was a mistake: if there is a tabular in the -% output routine (e.g., in the running header) then that tabular is -% able overwrite the \verb=\@halignto= -% setting of a tabular in the main text resulting in a very weird error. -% When the new font selection scheme is in force we have to -% we surround all \verb=\halign= entries -% with braces. See remarks in TUGboat 10\#2. Actually we are going -% to use \verb=\begingroup= and \verb=\endgroup=. However, this is only -% necessary when we are in text mode. In math the surrounding -% dollar signs will already serve as the necessary extra grouping -% level. Therefore we switch the settings of \verb=\d@llarbegin= and -% \verb=\d@llarend= between groups and dollar signs. -% \begin{macrocode} -\let\d@llarbegin\begingroup -\let\d@llarend\endgroup -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% -% \begin{macro}{\array} -% Our new definition of \verb=\array= then reads: -% \begin{macrocode} -\def\array{\col@sep\arraycolsep - \def\d@llarbegin{$}\let\d@llarend\d@llarbegin\def\@halignto{}%$ emacs -% \end{macrocode} -% Since there might be an optional argument we call another -% macro which is also used by the other environments. -% \begin{macrocode} - \@tabarray} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@tabarray} -% This macro tests for a optional bracket and then calls up -% \verb=\@array= or \verb=\@array[c]= (as default). -% \begin{macrocode} -\def\@tabarray{\@ifnextchar[{\@array}{\@array[c]}} -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\tabular} -% \begin{macro}{\tabular*} -% The environments \textsf{tabular} and \textsf{tabular$*$} differ -% only in the initialisation of the command \verb=\@halignto=. Therefore -% we define -% \begin{macrocode} -\def\tabular{\def\@halignto{}\@tabular} -% \end{macrocode} -% and analogously for the star form. We evaluate the argument first -% using =\setlength= so that users of the \texttt{calc} package can -% write code like\\ \verb=\begin{tabular*}{(\columnwidth-1cm)/2}...= -% \begin{macrocode} -\expandafter\def\csname tabular*\endcsname#1{% - \setlength\dimen@{#1}% - \edef\@halignto{to\the\dimen@}\@tabular} -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\@tabular} -% The rest of the job is carried out by the \verb=\@tabular= macro: -% \begin{macrocode} -\def\@tabular{% -% \end{macrocode} -% First of all we have to make sure that we start out in -% \textsf{hmode}. Otherwise we might find our table dangling by -% itself on a line. -% \begin{macrocode} - \leavevmode -% \end{macrocode} -% It should be taken into consideration that the macro \verb=\@array= -% must be called in math mode. Therefore we open a \textsf{box}, -% insert a \verb=$= and then assign the correct values to \verb=\col@sep= and -% \verb=\d@llar...=. -% \begin{macrocode} - \hbox \bgroup $\col@sep\tabcolsep \let\d@llarbegin\begingroup% $ emacs - \let\d@llarend\endgroup -% \end{macrocode} -% Now everything \textsf{tabular} specific is done and we are able to -% call the \verb=\@tabarray= macro. -% \begin{macrocode} - \@tabarray} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\endarray} -% When the processing of \textsf{array} is finished we have to -% close the \verb=\halign= -% and afterwards the surrounding \textsf{box} selected by -% \verb=\@array=. To save \textsf{token} space we then redefine -% \verb=\@preamble= -% because its replacement text isn't longer needed. -% \begin{macrocode} -\def\endarray{\crcr \egroup \egroup \gdef\@preamble{}} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\endtabular} -% \begin{macro}{\endtabular*} -% To end a \textsf{tabular} or \textsf{tabular$*$} environment we -% call up \verb=\endarray=, close the math mode and then the surrounding -% \verb=\hbox=. -% \begin{macrocode} -\def\endtabular{\endarray $\egroup}%$ emacs -\expandafter\let\csname endtabular*\endcsname=\endtabular -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% -% -% \subsubsection{Last minute definitions} -% -% -% If this file is used as a package file we should \verb=\let= all macros -% to \verb=\relax= that were used in the original but are no longer -% necessary. -% \begin{macrocode} -\let\@ampacol=\relax \let\@expast=\relax -\let\@arrayclassiv=\relax \let\@arrayclassz=\relax -\let\@tabclassiv=\relax \let\@tabclassz=\relax -\let\@arrayacol=\relax \let\@tabacol=\relax -\let\@tabularcr=\relax \let\@@endpbox=\relax -\let\@argtabularcr=\relax \let\@xtabularcr=\relax -% \end{macrocode} -% -% \begin{macro}{\@preamerr} -% We also have to redefine the error routine \verb=\@preamerr= since -% new kind of errors are possible. -% The code for this macro is not perfect yet; -% it still needs too much memory. -% \begin{macrocode} -\def\@preamerr#1{\def\@tempd{{..} at wrong position: }% - %\PackageError{array}{% - \ClassError{memoir}{% changed in menoir - \ifcase #1 Illegal pream-token (\@nextchar): `c' used\or %0 - Missing arg: token ignored\or %1 - Empty preamble: `l' used\or %2 - >\@tempd token ignored\or %3 - <\@tempd changed to !{..}\or %4 - Only one column-spec. allowed.\fi}\@ehc} %5 -% \end{macrocode} -% \end{macro} -% -% -% -% \subsubsection -% [Defining your own column specifiers] -% {Defining your own column specifiers\footnotemark} -% -% \footnotetext{The code and the documentation in this section was -% written by David. So far only the code from newarray was plugged -% into array so that some parts of the documentation still claim -% that this is newarray and even worse, some parts of the code are -% unnecessarily doubled. This will go away in a future release. For -% the moment we thought it would be more important to bring both -% packages together.} -% -% \begin{macro}{\newcolumn} -% In \texttt{newarray.sty} the macro for specifying new columns was -% named \verb"\newcolumn". When the functionality was added to -% \texttt{array.sty} the command was renamed \verb"\newcolumntype". -% Initially both names were supported, but now (In versions of this -% package distributed for \LaTeXe) the old name is not defined. -% \end{macro} -% -% \begin{macro}{\newcolumntype} -% As -% described above, the \verb"\newcolumntype" macro gives users the chance -% to define letters, to be used in the same way as the primitive -% column specifiers, `c' `p' etc. -% \begin{macrocode} -\def\newcolumntype#1{% -% \end{macrocode} -% \verb"\NC@char" was added in V2.01 so that active characters, like "@" in -% AMS\LaTeX\ may be used. This trick was stolen from \texttt{array.sty} -% 2.0h. Note that we need to use the possibly active token, -% \verb"#1", in several places, as that is the token that actually -% appears in the preamble argument. -% \begin{macrocode} - \edef\NC@char{\string#1}% -% \end{macrocode} -% First we check whether there is already a definition for this column. -% Unlike \verb"\newcommand" we give a warning rather than an error if it is -% defined. If it is a new column, add \verb"\NC@do" \meta{column} to -% the list \verb"\NC@list". -% \begin{macrocode} - \@ifundefined{NC@find@\NC@char}% - {\@tfor\next:=<>clrmbp@!|\do{\if\noexpand\next\NC@char - %\PackageWarning{array}% - \@memwarn{Redefining primitive column \NC@char}\fi}% memoir change - \NC@list\expandafter{\the\NC@list\NC@do#1}}% - {%\PackageWarning{array} - \@memwarn{Column \NC@char\space is already defined}}% memoir change -% \end{macrocode} -% Now we define a macro with an argument delimited by the new column -% specifier, this is used to find occurrences of this specifier in the -% user preamble. -% \begin{macrocode} - \@namedef{NC@find@\NC@char}##1#1{\NC@{##1}}% -% \end{macrocode} -% If an optional argument was not given, give a default argument of 0. -% \begin{macrocode} - \@ifnextchar[{\newcol@{\NC@char}}{\newcol@{\NC@char}[0]}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\newcol@} -% We can now define the macro which does the rewriting, -% \verb"\@reargdef" takes the same arguments as \verb"\newcommand", but -% does not check that the command is new. For a column, say `D' with -% one argument, define a command \verb"\NC@rewrite@D" with one -% argument, which recursively calls \verb"\NC@find" on the user preamble -% after replacing the first token or group with the replacement text -% specified in the \verb"\newcolumntype" command. \verb"\NC@find" will find the -% next occurrence of `D' as it will be \verb"\let" equal to -% \verb"\NC@find@D" by \verb"\NC@do". -% \begin{macrocode} -\def\newcol@#1[#2]#3{\expandafter\@reargdef - \csname NC@rewrite@#1\endcsname[#2]{\NC@find#3}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@} -% Having found an occurrence of the new column, save the preamble -% before the column in \verb"\@temptokena", then check to see if we -% are at the end of the preamble. (A dummy occurrence of the column -% specifier will be placed at the end of the preamble by \verb"\NC@do". -% \begin{macrocode} -\def\NC@#1{% - \@temptokena\expandafter{\the\@temptokena#1}\futurelet\next\NC@ifend} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@ifend} -% We can tell that we are at the end as \verb"\NC@do" will place a \verb"\relax" -% after the dummy column. -% \begin{macrocode} -\def\NC@ifend{% -% \end{macrocode} -% If we are at the end, do nothing. (The whole preamble will now be in -% \verb"\@temptokena".) -% \begin{macrocode} - \ifx\next\relax + % \endgroup % \end{macrocode} -% Otherwise set the flag \verb"\if@tempswa", and rewrite the column. -% \verb"\expandafter" introduced 1n V2.01 +% ^^A In the special situation of \verb=\multicolumn= \verb=\@preamble= +% ^^A is not needed as preamble for a \verb=\halign= but it is directly +% ^^A inserted into our table. Thus instead of \verb=\sharp= +% ^^A there has to be the column entry (\verb=#3=) wanted by the user. % \begin{macrocode} - \else\@tempswatrue\expandafter\NC@rewrite\fi} + % \def\@sharp{#3}% % \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@do} -% If the user has specified `C' and `L' as new columns, the list of -% rewrites (in the token register \verb"\NC@list") will look like -% \verb"\NC@do *" \verb"\NC@do C" \verb"\NC@do L". -% So we need to define \verb"\NC@do" as a one argument macro which -% initialises the rewriting of the specified column. Let us assume that -% `C' is the argument. -% \begin{macrocode} -\def\NC@do#1{% -% \end{macrocode} -% First we let \verb"\NC@rewrite" and \verb"\NC@find" be -% \verb"\NC@rewrite@C" and \verb"\NC@find@C" respectively. -% \begin{macrocode} - \expandafter\let\expandafter\NC@rewrite - \csname NC@rewrite@\string#1\endcsname - \expandafter\let\expandafter\NC@find - \csname NC@find@\string#1\endcsname -% \end{macrocode} -% Clear the token register \verb"\@temptokena" after putting the present -% contents of the register in front of the token \verb"\NC@find". At the -% end we place the tokens `\verb"C\relax"' which \verb"\NC@ifend" will use -% to detect the end of the user preamble. -% \begin{macrocode} - \expandafter\@temptokena\expandafter{\expandafter}% - \expandafter\NC@find\the\@temptokena#1\relax} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\showcols} -% This macro is useful for debugging \verb"\newcolumntype" specifications, -% it is the equivalent of the primitive \verb"\show" command for macro -% definitions. All we need to do is locally redefine \verb"\NC@do" to take -% its argument (say `C') and then \verb"\show" the (slightly modified) -% definition of \verb"\NC@rewrite@C". Actually as the the list always -% starts off with \verb"\NC@do *" and we do not want to print the -% definition of the $*$-form, define \verb"\NC@do" to throw away the first -% item in the list, and then redefine itself to print the rest of the -% definitions. -% \begin{macrocode} -\def\showcols{{\def\NC@do##1{\let\NC@do\NC@show}\the\NC@list}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@show} -% If the column `C' is defined as above, then -% \verb"\show\NC@rewrite@C" would output\\ -% \verb"\long macro: ->\NC@find >{$}c<{$}". -% We want to strip the \verb"long macro: ->" and the \verb"\NC@find". So first we -% use \verb"\meaning" and then apply the macro \verb"\NC@strip" to the tokens so -% produced and then \verb"\typeout" the required string. -% \begin{macrocode} -\def\NC@show#1{% - \typeout{Column #1\expandafter\expandafter\expandafter\NC@strip - \expandafter\meaning\csname NC@rewrite@#1\endcsname\@@}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@strip} -% Delimit the arguments to \verb"\NC@strip" with `\texttt{:}', `\texttt{->}', -% a space, and \verb"\@@" to pull out the required parts of the output from -% \verb"\meaning". -% \begin{macrocode} -\def\NC@strip#1:#2->#3 #4\@@{#2 -> #4} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\NC@list} -% Allocate the token register used for the rewrite list. +% ^^A Now we can pass the \verb=\@preamble= to \TeX\ . For safety +% ^^A we start with an \verb=\@arstrut=. This should usually be in the +% ^^A template for the first column however we do not know if this +% ^^A template was overwritten by our \verb=\multicolumn=. +% ^^A We also add a \verb=\null= at the right end to prevent any following +% ^^A \verb=\unskip= (for example from \verb=\\[..]=) to remove the \verb=\tabcolsep=. % \begin{macrocode} -\newtoks\NC@list + % \@arstrut \@preamble + % \null + % \ignorespaces} % \end{macrocode} -% \end{macro} -% -% \subsubsection{The $*$--form} -% We view the $*$-form as a slight generalisation of the system -% described in the previous subsection. The idea is to define a $*$ -% column by a command of the form: -% \begin{verbatim} -% \newcolumntype{*}[2]{% -% \count@=#1\ifnum\count@>0 -% \advance\count@ by -1 #2*{\count@}{#2}\fi} -% \end{verbatim} -% \begin{macro}{\NC@rewrite@*}\label{NC@rewrite@*} -% This does not work however as \verb"\newcolumntype" takes great care not -% to expand anything in the preamble, and so the \verb"\if" is never -% expanded. \verb"\newcolumntype" sets up various other parts of the -% rewrite correctly though so we can define: -% \begin{macrocode} -\newcolumntype{*}[2]{} -% \end{macrocode} -% Now we must correct the definition of \verb"\NC@rewrite@*". The -% following is probably more efficient than a direct translation of -% the idea sketched above, we do not need to put a $*$ in the preamble -% and call the rewrite recursively, we can just put \verb"#1" copies of -% \verb"#2" into \verb"\@temptokena". (Nested $*$ forms will be expanded -% when the whole rewrite list is expanded again, see \verb"\@mkpream") -% \begin{macrocode} -\long\@namedef{NC@rewrite@*}#1#2{% -% \end{macrocode} -% Store the number. -% \begin{macrocode} - \count@#1\relax -% \end{macrocode} -% Put \verb"#1" copies of \verb"#2" in the token register. -% \begin{macrocode} - \loop - \ifnum\count@>\z@ - \advance\count@\m@ne - \@temptokena\expandafter{\the\@temptokena#2}% - \repeat -% \end{macrocode} -% \verb"\NC@do" will ensure that \verb"\NC@find" is \verb"\let" equal -% to \verb"\NC@find@*". +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{The Environment Definitions} +% ^^A +% ^^A After these preparations we are able to define the environments. They +% ^^A only differ in the initialisations of \verb=\d@llar...=, \verb=\col@sep= +% ^^A and \verb=\@halignto=. +% ^^A +% ^^A \begin{macro}{\@halignto} +% ^^A \begin{macro}{\d@llarbegin} +% ^^A \begin{macro}{\d@llarend} +% ^^A \verb=\d@llar= has to be +% ^^A locally asigned since otherwise nested \textsf{tabular} and \textsf{array} +% ^^A environments (via \verb=\multicolumn=) are impossible. +% ^^A For 25 years or so \verb=\@halignto= was set globally (to save space on the +% ^^A save stack, but that was a mistake: if there is a tabular in the +% ^^A output routine (e.g., in the running header) then that tabular is +% ^^A able overwrite the \verb=\@halignto= +% ^^A setting of a tabular in the main text resulting in a very weird error. +% ^^A When the new font selection scheme is in force we have to +% ^^A we surround all \verb=\halign= entries +% ^^A with braces. See remarks in TUGboat 10\#2. Actually we are going +% ^^A to use \verb=\begingroup= and \verb=\endgroup=. However, this is only +% ^^A necessary when we are in text mode. In math the surrounding +% ^^A dollar signs will already serve as the necessary extra grouping +% ^^A level. Therefore we switch the settings of \verb=\d@llarbegin= and +% ^^A \verb=\d@llarend= between groups and dollar signs. +% \begin{macrocode} + % \let\d@llarbegin\begingroup + % \let\d@llarend\endgroup +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\array} +% ^^A Our new definition of \verb=\array= then reads: % \begin{macrocode} - \NC@find} + % \def\array{\col@sep\arraycolsep + % \def\d@llarbegin{$}\let\d@llarend\d@llarbegin\def\@halignto{}%$ emacs % \end{macrocode} -% \end{macro} -% -% \subsubsection{Modifications to internal macros of \texttt{array.sty}} -% -% \begin{macro}{\@xexpast} -% \begin{macro}{\@xexnoop} -% These macros are used to expand $*$-forms in -% \texttt{array.sty}. \verb"\let" them to \verb"\relax" to save space. +% ^^A Since there might be an optional argument we call another +% ^^A macro which is also used by the other environments. % \begin{macrocode} -\let\@xexpast\relax -\let\@xexnoop\relax + % \@tabarray} % \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\save@decl} -% We do not assume that the token register is free, we add the new -% declarations to the front of the register. This is to allow user -% preambles of the form, \verb">{foo}>{bar}..". Users are not encouraged to -% enter such expressions directly, but they may result from the -% rewriting of \verb"\newcolumntype"'s. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@tabarray} +% ^^A This macro tests for a optional bracket and then calls up +% ^^A \verb=\@array= or \verb=\@array[c]= (as default). % \begin{macrocode} -\def\save@decl{\toks \count@ = \expandafter\expandafter\expandafter - {\expandafter\@nextchar\the\toks\count@}} + % \def\@tabarray{\@ifnextchar[{\@array}{\@array[c]}} % \end{macrocode} -% \end{macro} -% \begin{macro}{\@mkpream} -% The main modification to \verb"\@mkpream" is to replace the call to -% \verb"\@xexpast" (which expanded $*$-forms) by a loop which expands -% all \verb"\newcolumntype" specifiers. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\tabular} +% ^^A \begin{macro}{\tabular*} +% ^^A The environments \textsf{tabular} and \textsf{tabular$*$} differ +% ^^A only in the initialisation of the command \verb=\@halignto=. Therefore +% ^^A we define +% \begin{macrocode} + % \def\tabular{\def\@halignto{}\@tabular} +% \end{macrocode} +% ^^A and analogously for the star form. We evaluate the argument first +% ^^A using =\setlength= so that users of the \texttt{calc} package can +% ^^A write code like\\ \verb=\begin{tabular*}{(\columnwidth-1cm)/2}...= +% ^^A \begin{macrocode} + % \expandafter\def\csname tabular*\endcsname#1{% + % \setlength\dimen@{#1}% + % \edef\@halignto{to\the\dimen@}\@tabular} +% ^^A \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@tabular} +% ^^A The rest of the job is carried out by the \verb=\@tabular= macro: % \begin{macrocode} -\def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue - \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax + % \def\@tabular{% % \end{macrocode} -% Now we remove possible $*$-forms and user-defined column -% specifiers in the user preamble by repeatedly executing the list -% \verb"\NC@list" until the re-writes have no more effect. The -% expanded preamble will then be in the token register -% \verb"\@temptokena". Actually we need to know at this point that -% this is not \verb"\toks0". +% ^^A First of all we have to make sure that we start out in +% ^^A \textsf{hmode}. Otherwise we might find our table dangling by +% ^^A itself on a line. % \begin{macrocode} - \@temptokena{#1}\@tempswatrue - \@whilesw\if@tempswa\fi{\@tempswafalse\the\NC@list}% + % \leavevmode % \end{macrocode} -% Afterwards we initialize all registers and macros, that we need -% for the build-up of the preamble. +% ^^A It should be taken into consideration that the macro \verb=\@array= +% ^^A must be called in math mode. Therefore we open a \textsf{box}, +% ^^A insert a \verb=$= and then assign the correct values to \verb=\col@sep= and +% ^^A \verb=\d@llar...=. % \begin{macrocode} - \count@\m@ne - \let\the@toks\relax - \prepnext@tok + % \hbox \bgroup $\col@sep\tabcolsep \let\d@llarbegin\begingroup% $ emacs + % \let\d@llarend\endgroup % \end{macrocode} -% Having expanded all tokens defined using \verb"\newcolumntype" (including -% \verb"*"), we evaluate the remaining tokens, which are saved in -% \verb"\@temptokena". We use the \LaTeX--macro \verb"\@tfor" to inspect each -% token in turn. +% ^^A Now everything \textsf{tabular} specific is done and we are able to +% ^^A call the \verb=\@tabarray= macro. % \begin{macrocode} - \expandafter \@tfor \expandafter \@nextchar - \expandafter :\expandafter =\the\@temptokena \do + % \@tabarray} % \end{macrocode} -% \verb"\@testpatch" does not take an argument since \texttt{array.sty} 2.0h. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\endarray} +% ^^A When the processing of \textsf{array} is finished we have to +% ^^A close the \verb=\halign= +% ^^A and afterwards the surrounding \textsf{box} selected by +% ^^A \verb=\@array=. To save \textsf{token} space we then redefine +% ^^A \verb=\@preamble= +% ^^A because its replacement text isn't longer needed. % \begin{macrocode} - {\@testpach - \ifcase \@chclass \@classz \or \@classi \or \@classii - \or \save@decl \or \or \@classv \or \@classvi - \or \@classvii \or \@classviii + % \def\endarray{\crcr \egroup \egroup \gdef\@preamble{}} % \end{macrocode} -% In \texttt{newarray.sty} class 9 is equivalent to class 10. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\endtabular} +% ^^A \begin{macro}{\endtabular*} +% ^^A To end a \textsf{tabular} or \textsf{tabular$*$} environment we +% ^^A call up \verb=\endarray=, close the math mode and then the surrounding +% ^^A \verb=\hbox=. % \begin{macrocode} - \or \@classx - \or \@classx \fi - \@lastchclass\@chclass}% - \ifcase\@lastchclass - \@acol \or - \or - \@acol \or - \@preamerr \thr@@ \or - \@preamerr \tw@ \@addtopreamble\@sharp \or - \or - \else \@preamerr \@ne \fi - \def\the@toks{\the\toks}} + % \def\endtabular{\endarray $\egroup}%$ emacs + % \expandafter\let\csname endtabular*\endcsname=\endtabular % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classix} -% \texttt{array.sty} does not allow repeated \texttt{>} -% declarations for the same column. This is allowed in -% \texttt{newarray.sty} as documented in the introduction. Removing -% the test for this case makes class 9 equivalent to class 10, and -% so this macro is redundant. It is \verb"\let" to \verb"\relax" to save -% space. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection{Last minute definitions} +% ^^A +% ^^A +% ^^A If this file is used as a package file we should \verb=\let= all macros +% ^^A to \verb=\relax= that were used in the original but are no longer +% ^^A necessary. % \begin{macrocode} -\let\@classix\relax + % \let\@ampacol=\relax \let\@expast=\relax + % \let\@arrayclassiv=\relax \let\@arrayclassz=\relax + % \let\@tabclassiv=\relax \let\@tabclassz=\relax + % \let\@arrayacol=\relax \let\@tabacol=\relax + % \let\@tabularcr=\relax \let\@@endpbox=\relax + % \let\@argtabularcr=\relax \let\@xtabularcr=\relax % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classviii} -% In \texttt{newarray.sty} explicitly allow class 2, as repeated -% \texttt{<} expressions are accepted by this package. +% ^^A +% ^^A \begin{macro}{\@preamerr} +% ^^A We also have to redefine the error routine \verb=\@preamerr= since +% ^^A new kind of errors are possible. +% ^^A The code for this macro is not perfect yet; +% ^^A it still needs too much memory. +% \begin{macrocode} + % \def\@preamerr#1{\def\@tempd{{..} at wrong position: }% + % %\PackageError{array}{% + % \ClassError{memoir}{% changed in menoir + % \ifcase #1 Illegal pream-token (\@nextchar): `c' used\or %0 + % Missing arg: token ignored\or %1 + % Empty preamble: `l' used\or %2 + % >\@tempd token ignored\or %3 + % <\@tempd changed to !{..}\or %4 + % Only one column-spec. allowed.\fi}\@ehc} %5 +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A +% ^^A \subsubsection +% ^^A [Defining your own column specifiers] +% ^^A {Defining your own column specifiers\footnotemark} +% ^^A +% ^^A \footnotetext{The code and the documentation in this section was +% ^^A written by David. So far only the code from newarray was plugged +% ^^A into array so that some parts of the documentation still claim +% ^^A that this is newarray and even worse, some parts of the code are +% ^^A unnecessarily doubled. This will go away in a future release. For +% ^^A the moment we thought it would be more important to bring both +% ^^A packages together.} +% ^^A +% ^^A \begin{macro}{\newcolumn} +% ^^A In \texttt{newarray.sty} the macro for specifying new columns was +% ^^A named \verb"\newcolumn". When the functionality was added to +% ^^A \texttt{array.sty} the command was renamed \verb"\newcolumntype". +% ^^A Initially both names were supported, but now (In versions of this +% ^^A package distributed for \LaTeXe) the old name is not defined. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\newcolumntype} +% ^^A As +% ^^A described above, the \verb"\newcolumntype" macro gives users the chance +% ^^A to define letters, to be used in the same way as the primitive +% ^^A column specifiers, `c' `p' etc. +% \begin{macrocode} + % \def\newcolumntype#1{% +% \end{macrocode} +% ^^A \verb"\NC@char" was added in V2.01 so that active characters, like "@" in +% ^^A AMS\LaTeX\ may be used. This trick was stolen from \texttt{array.sty} +% ^^A 2.0h. Note that we need to use the possibly active token, +% ^^A \verb"#1", in several places, as that is the token that actually +% ^^A appears in the preamble argument. +% \begin{macrocode} + % \edef\NC@char{\string#1}% +% \end{macrocode} +% ^^A First we check whether there is already a definition for this column. +% ^^A Unlike \verb"\newcommand" we give a warning rather than an error if it is +% ^^A defined. If it is a new column, add \verb"\NC@do" \meta{column} to +% ^^A the list \verb"\NC@list". +% \begin{macrocode} + % \@ifundefined{NC@find@\NC@char}% + % {\@tfor\next:=<>clrmbp@!|\do{\if\noexpand\next\NC@char + % %\PackageWarning{array}% + % \@memwarn{Redefining primitive column \NC@char}\fi}% memoir change + % \NC@list\expandafter{\the\NC@list\NC@do#1}}% + % {%\PackageWarning{array} + % \@memwarn{Column \NC@char\space is already defined}}% memoir change +% \end{macrocode} +% ^^A Now we define a macro with an argument delimited by the new column +% ^^A specifier, this is used to find occurrences of this specifier in the +% ^^A user preamble. +% \begin{macrocode} + % \@namedef{NC@find@\NC@char}##1#1{\NC@{##1}}% +% \end{macrocode} +% ^^A If an optional argument was not given, give a default argument of 0. +% \begin{macrocode} + % \@ifnextchar[{\newcol@{\NC@char}}{\newcol@{\NC@char}[0]}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\newcol@} +% ^^A We can now define the macro which does the rewriting, +% ^^A \verb"\@reargdef" takes the same arguments as \verb"\newcommand", but +% ^^A does not check that the command is new. For a column, say `D' with +% ^^A one argument, define a command \verb"\NC@rewrite@D" with one +% ^^A argument, which recursively calls \verb"\NC@find" on the user preamble +% ^^A after replacing the first token or group with the replacement text +% ^^A specified in the \verb"\newcolumntype" command. \verb"\NC@find" will find the +% ^^A next occurrence of `D' as it will be \verb"\let" equal to +% ^^A \verb"\NC@find@D" by \verb"\NC@do". +% \begin{macrocode} + % \def\newcol@#1[#2]#3{\expandafter\@reargdef + % \csname NC@rewrite@#1\endcsname[#2]{\NC@find#3}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@} +% ^^A Having found an occurrence of the new column, save the preamble +% ^^A before the column in \verb"\@temptokena", then check to see if we +% ^^A are at the end of the preamble. (A dummy occurrence of the column +% ^^A specifier will be placed at the end of the preamble by \verb"\NC@do". +% \begin{macrocode} + % \def\NC@#1{% + % \@temptokena\expandafter{\the\@temptokena#1}\futurelet\next\NC@ifend} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@ifend} +% ^^A We can tell that we are at the end as \verb"\NC@do" will place a \verb"\relax" +% ^^A after the dummy column. +% \begin{macrocode} + % \def\NC@ifend{% +% \end{macrocode} +% ^^A If we are at the end, do nothing. (The whole preamble will now be in +% ^^A \verb"\@temptokena".) +% \begin{macrocode} + % \ifx\next\relax +% \end{macrocode} +% ^^A Otherwise set the flag \verb"\if@tempswa", and rewrite the column. +% ^^A \verb"\expandafter" introduced 1n V2.01 +% \begin{macrocode} + % \else\@tempswatrue\expandafter\NC@rewrite\fi} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@do} +% ^^A If the user has specified `C' and `L' as new columns, the list of +% ^^A rewrites (in the token register \verb"\NC@list") will look like +% ^^A \verb"\NC@do *" \verb"\NC@do C" \verb"\NC@do L". +% ^^A So we need to define \verb"\NC@do" as a one argument macro which +% ^^A initialises the rewriting of the specified column. Let us assume that +% ^^A `C' is the argument. +% \begin{macrocode} + % \def\NC@do#1{% +% \end{macrocode} +% ^^A First we let \verb"\NC@rewrite" and \verb"\NC@find" be +% ^^A \verb"\NC@rewrite@C" and \verb"\NC@find@C" respectively. +% \begin{macrocode} + % \expandafter\let\expandafter\NC@rewrite + % \csname NC@rewrite@\string#1\endcsname + % \expandafter\let\expandafter\NC@find + % \csname NC@find@\string#1\endcsname +% \end{macrocode} +% ^^A Clear the token register \verb"\@temptokena" after putting the present +% ^^A contents of the register in front of the token \verb"\NC@find". At the +% ^^A end we place the tokens `\verb"C\relax"' which \verb"\NC@ifend" will use +% ^^A to detect the end of the user preamble. % \begin{macrocode} -\def\@classviii{\ifnum \@lastchclass >\z@\ifnum\@lastchclass=\tw@\else - \@preamerr 4\@chclass 6 \@classvi \fi\fi} + % \expandafter\@temptokena\expandafter{\expandafter}% + % \expandafter\NC@find\the\@temptokena#1\relax} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\@classv} -% Class 5 is \texttt{@}-expressions (and is also called by class 1) -% This macro was incorrect in Version~1. Now we do not expand the -% \verb"@"-expression, but instead explicitly replace an -% \verb"\extracolsep" command by an assignment to \verb"\tabskip" by a -% method similar to the \verb"\newcolumntype" system described above. -% \verb"\d@llarbegin" \verb"\d@llarend" were introduced in V2.01 to match -% \texttt{array.sty} 2.0h. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\showcols} +% ^^A This macro is useful for debugging \verb"\newcolumntype" specifications, +% ^^A it is the equivalent of the primitive \verb"\show" command for macro +% ^^A definitions. All we need to do is locally redefine \verb"\NC@do" to take +% ^^A its argument (say `C') and then \verb"\show" the (slightly modified) +% ^^A definition of \verb"\NC@rewrite@C". Actually as the the list always +% ^^A starts off with \verb"\NC@do *" and we do not want to print the +% ^^A definition of the $*$-form, define \verb"\NC@do" to throw away the first +% ^^A item in the list, and then redefine itself to print the rest of the +% ^^A definitions. +% \begin{macrocode} + % \def\showcols{{\def\NC@do##1{\let\NC@do\NC@show}\the\NC@list}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@show} +% ^^A If the column `C' is defined as above, then +% ^^A \verb"\show\NC@rewrite@C" would output\\ +% ^^A \verb"\long macro: ->\NC@find >{$}c<{$}". +% ^^A We want to strip the \verb"long macro: ->" and the \verb"\NC@find". So first we +% ^^A use \verb"\meaning" and then apply the macro \verb"\NC@strip" to the tokens so +% ^^A produced and then \verb"\typeout" the required string. +% \begin{macrocode} + % \def\NC@show#1{% + % \typeout{Column #1\expandafter\expandafter\expandafter\NC@strip + % \expandafter\meaning\csname NC@rewrite@#1\endcsname\@@}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@strip} +% ^^A Delimit the arguments to \verb"\NC@strip" with `\texttt{:}', `\texttt{->}', +% ^^A a space, and \verb"\@@" to pull out the required parts of the output from +% ^^A \verb"\meaning". +% \begin{macrocode} + % \def\NC@strip#1:#2->#3 #4\@@{#2 -> #4} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\NC@list} +% ^^A Allocate the token register used for the rewrite list. +% \begin{macrocode} + % \newtoks\NC@list +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \subsubsection{The $*$--form} +% ^^A We view the $*$-form as a slight generalisation of the system +% ^^A described in the previous subsection. The idea is to define a $*$ +% ^^A column by a command of the form: +% ^^A \begin{verbatim} +% ^^A \newcolumntype{*}[2]{% +% ^^A \count@=#1\ifnum\count@>0 +% ^^A \advance\count@ by -1 #2*{\count@}{#2}\fi} +% ^^A \end{verbatim} +% ^^A \begin{macro}{\NC@rewrite@*}\label{NC@rewrite@*} +% ^^A This does not work however as \verb"\newcolumntype" takes great care not +% ^^A to expand anything in the preamble, and so the \verb"\if" is never +% ^^A expanded. \verb"\newcolumntype" sets up various other parts of the +% ^^A rewrite correctly though so we can define: +% \begin{macrocode} + % \newcolumntype{*}[2]{} +% \end{macrocode} +% ^^A Now we must correct the definition of \verb"\NC@rewrite@*". The +% ^^A following is probably more efficient than a direct translation of +% ^^A the idea sketched above, we do not need to put a $*$ in the preamble +% ^^A and call the rewrite recursively, we can just put \verb"#1" copies of +% ^^A \verb"#2" into \verb"\@temptokena". (Nested $*$ forms will be expanded +% ^^A when the whole rewrite list is expanded again, see \verb"\@mkpream") +% \begin{macrocode} + % \long\@namedef{NC@rewrite@*}#1#2{% +% \end{macrocode} +% ^^A Store the number. +% \begin{macrocode} + % \count@#1\relax +% \end{macrocode} +% ^^A Put \verb"#1" copies of \verb"#2" in the token register. +% \begin{macrocode} + % \loop + % \ifnum\count@>\z@ + % \advance\count@\m@ne + % \@temptokena\expandafter{\the\@temptokena#2}% + % \repeat +% \end{macrocode} +% ^^A \verb"\NC@do" will ensure that \verb"\NC@find" is \verb"\let" equal +% ^^A to \verb"\NC@find@*". +% \begin{macrocode} + % \NC@find} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \subsubsection{Modifications to internal macros of \texttt{array.sty}} +% ^^A +% ^^A \begin{macro}{\@xexpast} +% ^^A \begin{macro}{\@xexnoop} +% ^^A These macros are used to expand $*$-forms in +% ^^A \texttt{array.sty}. \verb"\let" them to \verb"\relax" to save space. % \begin{macrocode} -\def\@classv{\save@decl - \expandafter\NC@ecs\@nextchar\extracolsep{}\extracolsep\@@@ - \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}% - \prepnext@tok} + % \let\@xexpast\relax + % \let\@xexnoop\relax % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\NC@ecs} -% Rewrite the first occurrence of \verb"\extracolsep{1in}" to -% \verb"\tabskip1in\relax". As a side effect discard any tokens after a -% second \verb"\extracolsep", there is no point in the user entering two of -% these commands anyway, so this is not really a restriction. +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\save@decl} +% ^^A We do not assume that the token register is free, we add the new +% ^^A declarations to the front of the register. This is to allow user +% ^^A preambles of the form, \verb">{foo}>{bar}..". Users are not encouraged to +% ^^A enter such expressions directly, but they may result from the +% ^^A rewriting of \verb"\newcolumntype"'s. +% \begin{macrocode} + % \def\save@decl{\toks \count@ = \expandafter\expandafter\expandafter + % {\expandafter\@nextchar\the\toks\count@}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \begin{macro}{\@mkpream} +% ^^A The main modification to \verb"\@mkpream" is to replace the call to +% ^^A \verb"\@xexpast" (which expanded $*$-forms) by a loop which expands +% ^^A all \verb"\newcolumntype" specifiers. +% \begin{macrocode} + % \def\@mkpream#1{\gdef\@preamble{}\@lastchclass 4 \@firstamptrue + % \let\@sharp\relax \let\@startpbox\relax \let\@endpbox\relax +% \end{macrocode} +% ^^A Now we remove possible $*$-forms and user-defined column +% ^^A specifiers in the user preamble by repeatedly executing the list +% ^^A \verb"\NC@list" until the re-writes have no more effect. The +% ^^A expanded preamble will then be in the token register +% ^^A \verb"\@temptokena". Actually we need to know at this point that +% ^^A this is not \verb"\toks0". +% \begin{macrocode} + % \@temptokena{#1}\@tempswatrue + % \@whilesw\if@tempswa\fi{\@tempswafalse\the\NC@list}% +% \end{macrocode} +% ^^A Afterwards we initialize all registers and macros, that we need +% ^^A for the build-up of the preamble. +% \begin{macrocode} + % \count@\m@ne + % \let\the@toks\relax + % \prepnext@tok +% \end{macrocode} +% ^^A Having expanded all tokens defined using \verb"\newcolumntype" (including +% ^^A \verb"*"), we evaluate the remaining tokens, which are saved in +% ^^A \verb"\@temptokena". We use the \LaTeX--macro \verb"\@tfor" to inspect each +% ^^A token in turn. +% \begin{macrocode} + % \expandafter \@tfor \expandafter \@nextchar + % \expandafter :\expandafter =\the\@temptokena \do +% \end{macrocode} +% ^^A \verb"\@testpatch" does not take an argument since \texttt{array.sty} 2.0h. +% \begin{macrocode} + % {\@testpach + % \ifcase \@chclass \@classz \or \@classi \or \@classii + % \or \save@decl \or \or \@classv \or \@classvi + % \or \@classvii \or \@classviii +% \end{macrocode} +% ^^A In \texttt{newarray.sty} class 9 is equivalent to class 10. +% \begin{macrocode} + % \or \@classx + % \or \@classx \fi + % \@lastchclass\@chclass}% + % \ifcase\@lastchclass + % \@acol \or + % \or + % \@acol \or + % \@preamerr \thr@@ \or + % \@preamerr \tw@ \@addtopreamble\@sharp \or + % \or + % \else \@preamerr \@ne \fi + % \def\the@toks{\the\toks}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classix} +% ^^A \texttt{array.sty} does not allow repeated \texttt{>} +% ^^A declarations for the same column. This is allowed in +% ^^A \texttt{newarray.sty} as documented in the introduction. Removing +% ^^A the test for this case makes class 9 equivalent to class 10, and +% ^^A so this macro is redundant. It is \verb"\let" to \verb"\relax" to save +% ^^A space. % \begin{macrocode} -\def\NC@ecs#1\extracolsep#2#3\extracolsep#4\@@@{\def\@tempa{#2}% - \ifx\@tempa\@empty\else\toks\count@={#1\tabskip#2\relax#3}\fi} + % \let\@classix\relax % \end{macrocode} -% \end{macro} -% -% -% \subsubsection{Support for the \texttt{delarray.sty}} -% -% The \texttt{delarray.sty} package extends the array syntax by -% supporting the notation of delimiters. To this end we extend the -% array parsing mechanism to include a hook which can be used by this -% (or another) package to do some additional parsing. -% -% \begin{macro}{\@tabarray} -% This macro tests for an optional bracket and then calls up -% \verb"\@@array" or \verb"\@@array[c]" (as default). +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classviii} +% ^^A In \texttt{newarray.sty} explicitly allow class 2, as repeated +% ^^A \texttt{<} expressions are accepted by this package. % \begin{macrocode} -\def\@tabarray{\@ifnextchar[{\@@array}{\@@array[c]}} + % \def\@classviii{\ifnum \@lastchclass >\z@\ifnum\@lastchclass=\tw@\else + % \@preamerr 4\@chclass 6 \@classvi \fi\fi} % \end{macrocode} -% \end{macro} -% \begin{macro}{\@@array} -% This macro tests could then test an optional delimiter before the -% left brace of the main preamble argument. Here in the main package -% it simply is let to be \verb"\@array". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\@classv} +% ^^A Class 5 is \texttt{@}-expressions (and is also called by class 1) +% ^^A This macro was incorrect in Version~1. Now we do not expand the +% ^^A \verb"@"-expression, but instead explicitly replace an +% ^^A \verb"\extracolsep" command by an assignment to \verb"\tabskip" by a +% ^^A method similar to the \verb"\newcolumntype" system described above. +% ^^A \verb"\d@llarbegin" \verb"\d@llarend" were introduced in V2.01 to match +% ^^A \texttt{array.sty} 2.0h. +% \begin{macrocode} + % \def\@classv{\save@decl + % \expandafter\NC@ecs\@nextchar\extracolsep{}\extracolsep\@@@ + % \@addtopreamble{\d@llarbegin\the@toks\the\count@\relax\d@llarend}% + % \prepnext@tok} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\NC@ecs} +% ^^A Rewrite the first occurrence of \verb"\extracolsep{1in}" to +% ^^A \verb"\tabskip1in\relax". As a side effect discard any tokens after a +% ^^A second \verb"\extracolsep", there is no point in the user entering two of +% ^^A these commands anyway, so this is not really a restriction. % \begin{macrocode} -\let\@@array\@array + % \def\NC@ecs#1\extracolsep#2#3\extracolsep#4\@@@{\def\@tempa{#2}% + % \ifx\@tempa\@empty\else\toks\count@={#1\tabskip#2\relax#3}\fi} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\endarray} -% \begin{macro}{\@arrayright} -% We have to declare the hook we put into \verb"\@array" above. -% A similar hook `\verb"\@arrayright"' will be inserted into the -% \verb"\endarray" to gain control. Both defaults to empty. +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \subsubsection{Support for the \texttt{delarray.sty}} +% ^^A +% ^^A The \texttt{delarray.sty} package extends the array syntax by +% ^^A supporting the notation of delimiters. To this end we extend the +% ^^A array parsing mechanism to include a hook which can be used by this +% ^^A (or another) package to do some additional parsing. +% ^^A +% ^^A \begin{macro}{\@tabarray} +% ^^A This macro tests for an optional bracket and then calls up +% ^^A \verb"\@@array" or \verb"\@@array[c]" (as default). % \begin{macrocode} -\def\endarray{\crcr \egroup \egroup \@arrayright \gdef\@preamble{}} -\let\@arrayleft\@empty -\let\@arrayright\@empty + % \def\@tabarray{\@ifnextchar[{\@@array}{\@@array[c]}} % \end{macrocode} -% \end{macro} -% \end{macro} -% -% \subsubsection{Support for \texttt{\textbackslash firsthline} and -% \texttt{\textbackslash lasthline}} -% -% The Companion~\cite[p.137]{GOOSSENS94} suggests two additional -% commands to control the alignments in case of tabulars with -% horizontal lines. They are now added to this package. -% -% \begin{macro}{\extratabsurround} -% The extra space around a table when \verb"\firsthline" or \verb"\lasthline" -% are used. +% ^^A \end{macro} +% ^^A \begin{macro}{\@@array} +% ^^A This macro tests could then test an optional delimiter before the +% ^^A left brace of the main preamble argument. Here in the main package +% ^^A it simply is let to be \verb"\@array". % \begin{macrocode} -\newlength{\extratabsurround} -\setlength{\extratabsurround}{2pt} + % \let\@@array\@array % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\backup@length} -% This register will be used internally by \verb"\firsthline" and -% \verb"\lasthline". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\endarray} +% ^^A \begin{macro}{\@arrayright} +% ^^A We have to declare the hook we put into \verb"\@array" above. +% ^^A A similar hook `\verb"\@arrayright"' will be inserted into the +% ^^A \verb"\endarray" to gain control. Both defaults to empty. +% \begin{macrocode} + % \def\endarray{\crcr \egroup \egroup \@arrayright \gdef\@preamble{}} + % \let\@arrayleft\@empty + % \let\@arrayright\@empty +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A \subsubsection{Support for \texttt{\textbackslash firsthline} and +% ^^A \texttt{\textbackslash lasthline}} +% ^^A +% ^^A The Companion~\cite[p.137]{GOOSSENS94} suggests two additional +% ^^A commands to control the alignments in case of tabulars with +% ^^A horizontal lines. They are now added to this package. +% ^^A +% ^^A \begin{macro}{\extratabsurround} +% ^^A The extra space around a table when \verb"\firsthline" or \verb"\lasthline" +% ^^A are used. % \begin{macrocode} -\newlength{\backup@length} + % \newlength{\extratabsurround} + % \setlength{\extratabsurround}{2pt} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\firsthline} -% This code can probably be improved but for the moment it should -% serve. -% -% We start by producing a single tabular row without any visible -% content that will produce the external reference point in case -% \verb"[t]" is used. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\backup@length} +% ^^A This register will be used internally by \verb"\firsthline" and +% ^^A \verb"\lasthline". % \begin{macrocode} -\newcommand{\firsthline}{%}} emacs - \multicolumn1c{% + % \newlength{\backup@length} % \end{macrocode} -% Within this row we calculate \verb"\backup@length" to be the height -% plus depth of a standard line. In addition we have to add the -% width of the \verb"\hline", something that was forgotten in the -% original definition. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\firsthline} +% ^^A This code can probably be improved but for the moment it should +% ^^A serve. +% ^^A +% ^^A We start by producing a single tabular row without any visible +% ^^A content that will produce the external reference point in case +% ^^A \verb"[t]" is used. % \begin{macrocode} - \global\backup@length\ht\@arstrutbox - \global\advance\backup@length\dp\@arstrutbox - \global\advance\backup@length\arrayrulewidth + % \newcommand{\firsthline}{%}} emacs + % \multicolumn1c{% % \end{macrocode} -% Finally we do want to make the height of this first line be a bit -% larger than usual, for this we place the standard array strut -% into it but raised by \verb"\extratabsurround" +% ^^A Within this row we calculate \verb"\backup@length" to be the height +% ^^A plus depth of a standard line. In addition we have to add the +% ^^A width of the \verb"\hline", something that was forgotten in the +% ^^A original definition. % \begin{macrocode} - \raise\extratabsurround\copy\@arstrutbox + % \global\backup@length\ht\@arstrutbox + % \global\advance\backup@length\dp\@arstrutbox + % \global\advance\backup@length\arrayrulewidth % \end{macrocode} -% Having done all this we end the line and back up by the value of -% \verb"\backup@length" and then finally place our \verb"\hline". This should -% place the line exactly at the right place but keep the reference -% point of the whole tabular at the baseline of the first row. +% ^^A Finally we do want to make the height of this first line be a bit +% ^^A larger than usual, for this we place the standard array strut +% ^^A into it but raised by \verb"\extratabsurround" % \begin{macrocode} - }\\[-\backup@length]\hline -} + % \raise\extratabsurround\copy\@arstrutbox % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\lasthline} -% For \verb"\lasthline" the situation is even worse and I got it -% completely wrong initially. -% -% The problem in this case is that if the optional argument \verb"[b]" -% is used we do want the reference point of the tabular be at the -% baseline of the last row but at the same time do want the the -% depth of this last line increased by \verb"\extratabsurround" without -% changing the placement \verb"\hline". -% -% We start by placing the rule followed by an invisible row. +% ^^A Having done all this we end the line and back up by the value of +% ^^A \verb"\backup@length" and then finally place our \verb"\hline". This should +% ^^A place the line exactly at the right place but keep the reference +% ^^A point of the whole tabular at the baseline of the first row. % \begin{macrocode} -\newcommand{\lasthline}{\hline\multicolumn1c{%}} emacs + % }\\[-\backup@length]\hline + % } % \end{macrocode} -% We now calculate \verb"\backup@length" to be the height and depth of -% two lines plus the width of the rule. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\lasthline} +% ^^A For \verb"\lasthline" the situation is even worse and I got it +% ^^A completely wrong initially. +% ^^A +% ^^A The problem in this case is that if the optional argument \verb"[b]" +% ^^A is used we do want the reference point of the tabular be at the +% ^^A baseline of the last row but at the same time do want the the +% ^^A depth of this last line increased by \verb"\extratabsurround" without +% ^^A changing the placement \verb"\hline". +% ^^A +% ^^A We start by placing the rule followed by an invisible row. % \begin{macrocode} - \global\backup@length2\ht\@arstrutbox - \global\advance\backup@length2\dp\@arstrutbox - \global\advance\backup@length\arrayrulewidth + % \newcommand{\lasthline}{\hline\multicolumn1c{%}} emacs % \end{macrocode} -% This will bring us back to the baseline of the second last row: +% ^^A We now calculate \verb"\backup@length" to be the height and depth of +% ^^A two lines plus the width of the rule. % \begin{macrocode} - }\\[-\backup@length]% + % \global\backup@length2\ht\@arstrutbox + % \global\advance\backup@length2\dp\@arstrutbox + % \global\advance\backup@length\arrayrulewidth % \end{macrocode} -% Thus if we now add another invisible row the reference point of -% that row will be at the baseline of the last row (and will be the -% reference for the whole tabular). Since this row is invisible we -% can enlarge its depth by the desired amount. +% ^^A This will bring us back to the baseline of the second last row: % \begin{macrocode} - \multicolumn1c{% - \lower\extratabsurround\copy\@arstrutbox - }% -} + % }\\[-\backup@length]% % \end{macrocode} -% \end{macro} -% -% -% \subsubsection{Getting the spacing around rules right} -% -% Beside a larger functionality \texttt{array.sty} has one -% important difference to the standard \texttt{tabular} and -% \texttt{array} environments: horizontal and vertical rules make a -% table larger or wider, e.g., \verb=\doublerulesep= really denotes -% the space between two rules and isn't measured from the middle of -% the rules. -% -% \begin{macro}{\@xhline} -% For vertical rules this is implemented by the definitions above, -% for horizontal rules we have to take out the backspace. +% ^^A Thus if we now add another invisible row the reference point of +% ^^A that row will be at the baseline of the last row (and will be the +% ^^A reference for the whole tabular). Since this row is invisible we +% ^^A can enlarge its depth by the desired amount. % \begin{macrocode} -\CheckCommand*\@xhline{\ifx\reserved@a\hline - \vskip\doublerulesep - \vskip-\arrayrulewidth - \fi - \ifnum0=`{\fi}} -\renewcommand*\@xhline{\ifx\reserved@a\hline - \vskip\doublerulesep - \fi - \ifnum0=`{\fi}} + % \multicolumn1c{% + % \lower\extratabsurround\copy\@arstrutbox + % }% + % } % \end{macrocode} -% \end{macro} -% -% +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \subsubsection{Getting the spacing around rules right} +% ^^A +% ^^A Beside a larger functionality \texttt{array.sty} has one +% ^^A important difference to the standard \texttt{tabular} and +% ^^A \texttt{array} environments: horizontal and vertical rules make a +% ^^A table larger or wider, e.g., \verb=\doublerulesep= really denotes +% ^^A the space between two rules and isn't measured from the middle of +% ^^A the rules. +% ^^A +% ^^A \begin{macro}{\@xhline} +% ^^A For vertical rules this is implemented by the definitions above, +% ^^A for horizontal rules we have to take out the backspace. +% \begin{macrocode} + % \CheckCommand*\@xhline{\ifx\reserved@a\hline + % \vskip\doublerulesep + % \vskip-\arrayrulewidth + % \fi + % \ifnum0=`{\fi}} + % \renewcommand*\@xhline{\ifx\reserved@a\hline + % \vskip\doublerulesep + % \fi + % \ifnum0=`{\fi}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A % \begin{macrocode} -%%%%%%%%%% end array.sty 2016/10/06 v2.4d %%%%%%%%% - + % %%%%%%%%%% end array.sty 2016/10/06 v2.4d %%%%%%%%% + % % \end{macrocode} +% ^^A +% ^^A % -% +% \subsubsection{Class additions to Array} +% % \begin{macro}{\m@mold@addamp} % \begin{macro}{\m@m@addamp} % \begin{macro}{\@addamp} @@ -16925,958 +16953,1000 @@ % \subsection{D column specifiers} \label{sec:dcolumns} % -% The description and code are essentially copied from the -% \Lpack{dcolumn} package~\cite{DCOLUMN}. % +% Here ealier versions of the class had an embedded copy of the +% \Lpack{cdolumn} package. Now replaced by requiring the packge instead. % \begin{macrocode} -%%%%%%%%%% Dcolumn package code %%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% - +\RequirePackage{dcolumn}[2014/10/28] % \end{macrocode} +% The embeded copy is outcommented for now and will be removed in a +% later version. % +% \changes{v3.7h}{2018/09/06}{Outcommented the embedded copy of +% \Lpack{dcolumn} and replaced it with requiring the \Lpack{dcolumn} package +% instead.} % -% The \Lpack{dcolumn} package~\cite{DCOLUMN} defines \texttt{D} -% to be a column specifier -% with three arguments.\\ -% \verb?D?\marg{sep.tex}\marg{sep.dvi}\marg{decimal places} -% for columns which are to be aligned on a `decimal point'. -% -% -% The basic ideas behind these macros have been explained earlier. -% However they use three -% tricks which may be useful in other contexts. -% \begin{itemize} -% \item The separator is surrounded in extra \verb?{ }?, so that it is set -% with \cs{mathord} spacing, otherwise, for instance a `,' would have -% extra space after it. -% \item The separator is not given its special definition by making it -% active, as this would not work for an entry such as \verb?& .5 &?, as the -% first token of an alignment entry is read \emph{before} the preamble -% part, incase it is an \cs{omit}, in which case the preamble is to be -% omitted. Instead we switch the mathcode to (hex) 8000, which makes the -% token act as if it were active. -% \item Although \verb?\mathcode`.="8000? makes \texttt{.} act as if it -% were active, it is still not allowed in constructions such as -% \verb?\def.{}?, even in math-mode, so we have to construct an active -% version of the separator, this is done by making it the uppercase of -% \verb?~?, and then using the construct\\ -% \verb?\uppercase{\def~}?\marg{definition}.\\ -% Note that the \meta{definition} is not uppercased, so the definition -% can refer to the standard, non-active use of the separator. -% \end{itemize} -% -% \begin{macro}{\DC@} -% Set up uppercase tables as required, and then grab the first part of -% the numerical argument into \cs{count@}. +% ^^A The description and code are essentially copied from the +% ^^A \Lpack{dcolumn} package~\cite{DCOLUMN}. +% ^^A % \begin{macrocode} -\def\DC@#1#2#3{% - \uccode`\~=`#1\relax - \m@th - \afterassignment\DC@x\count@#3\relax{#1}{#2}} + % %%%%%%%%%% Dcolumn package code %%%%%%%%%%%%%%%%%%%%% + % %%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% + % % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\DC@x} -% If \cs{count@} is negative, centre on the decimal point. If it is -% positive either \verb?#1? will be empty in which case bad out decimal -% part to the number of digits specified by \cs{count@} or -% it is none empty in which case \cs{count@} contains the -% number of digits to the left of the point, and \verb?#1? contains a junk -% token (probably \verb?.?) followed by the number of digits to the right -% of the point. In either of these latter cases, \cs{DC@right} is used. +% ^^A +% ^^A +% ^^A The \Lpack{dcolumn} package~\cite{DCOLUMN} defines \texttt{D} +% ^^A to be a column specifier +% ^^A with three arguments.\\ +% ^^A \verb?D?\marg{sep.tex}\marg{sep.dvi}\marg{decimal places} +% ^^A for columns which are to be aligned on a `decimal point'. +% ^^A +% ^^A +% ^^A The basic ideas behind these macros have been explained earlier. +% ^^A However they use three +% ^^A tricks which may be useful in other contexts. +% ^^A \begin{itemize} +% ^^A \item The separator is surrounded in extra \verb?{ }?, so that it is set +% ^^A with \cs{mathord} spacing, otherwise, for instance a `,' would have +% ^^A extra space after it. +% ^^A \item The separator is not given its special definition by making it +% ^^A active, as this would not work for an entry such as \verb?& .5 &?, as the +% ^^A first token of an alignment entry is read \emph{before} the preamble +% ^^A part, incase it is an \cs{omit}, in which case the preamble is to be +% ^^A omitted. Instead we switch the mathcode to (hex) 8000, which makes the +% ^^A token act as if it were active. +% ^^A \item Although \verb?\mathcode`.="8000? makes \texttt{.} act as if it +% ^^A were active, it is still not allowed in constructions such as +% ^^A \verb?\def.{}?, even in math-mode, so we have to construct an active +% ^^A version of the separator, this is done by making it the uppercase of +% ^^A \verb?~?, and then using the construct\\ +% ^^A \verb?\uppercase{\def~}?\marg{definition}.\\ +% ^^A Note that the \meta{definition} is not uppercased, so the definition +% ^^A can refer to the standard, non-active use of the separator. +% ^^A \end{itemize} +% ^^A +% ^^A \begin{macro}{\DC@} +% ^^A Set up uppercase tables as required, and then grab the first part of +% ^^A the numerical argument into \cs{count@}. % \begin{macrocode} -\def\DC@x#1\relax#2#3{% - \ifnum\z@>\count@ - \expandafter\DC@centre - \else - \expandafter\DC@right - \fi - {#2}{#3}{#1}} + % \def\DC@#1#2#3{% + % \uccode`\~=`#1\relax + % \m@th + % \afterassignment\DC@x\count@#3\relax{#1}{#2}} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\DC@centre} -% If centering on the decimal point, just need to box up the two halves. -% \begin{macrocode} -\def\DC@centre#1#2#3{% - \let\DC@end\DC@endcentre - \uppercase{\def~}{$\egroup\setbox\tw@=\hbox\bgroup${#2}}%$ - \setbox\tw@=\hbox{${\phantom{{#2}}}$}% - \setbox\z@=\hbox\bgroup$\mathcode`#1="8000 }%$ +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\DC@x} +% ^^A If \cs{count@} is negative, centre on the decimal point. If it is +% ^^A positive either \verb?#1? will be empty in which case bad out decimal +% ^^A part to the number of digits specified by \cs{count@} or +% ^^A it is none empty in which case \cs{count@} contains the +% ^^A number of digits to the left of the point, and \verb?#1? contains a junk +% ^^A token (probably \verb?.?) followed by the number of digits to the right +% ^^A of the point. In either of these latter cases, \cs{DC@right} is used. +% \begin{macrocode} + % \def\DC@x#1\relax#2#3{% + % \ifnum\z@>\count@ + % \expandafter\DC@centre + % \else + % \expandafter\DC@right + % \fi + % {#2}{#3}{#1}} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\DC@endcentre} -% and then pad out the smaller of the two boxes so there is the same -% amount of stuff either side of the point. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\DC@centre} +% ^^A If centering on the decimal point, just need to box up the two halves. % \begin{macrocode} -\def\DC@endcentre{$\egroup%$ - \ifdim \wd\z@>\wd\tw@ - \setbox\tw@=\hbox to\wd\z@{\unhbox\tw@\hfill}% - \else - \setbox\z@=\hbox to\wd\tw@{\hfill\unhbox\z@}\fi - \box\z@\box\tw@} + % \def\DC@centre#1#2#3{% + % \let\DC@end\DC@endcentre + % \uppercase{\def~}{$\egroup\setbox\tw@=\hbox\bgroup${#2}}%$ + % \setbox\tw@=\hbox{${\phantom{{#2}}}$}% + % \setbox\z@=\hbox\bgroup$\mathcode`#1="8000 }%$ % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\DC@right} -% This deals with both the cases where a specified number of decimal -% places is given. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\DC@endcentre} +% ^^A and then pad out the smaller of the two boxes so there is the same +% ^^A amount of stuff either side of the point. +% \begin{macrocode} + % \def\DC@endcentre{$\egroup%$ + % \ifdim \wd\z@>\wd\tw@ + % \setbox\tw@=\hbox to\wd\z@{\unhbox\tw@\hfill}% + % \else + % \setbox\z@=\hbox to\wd\tw@{\hfill\unhbox\z@}\fi + % \box\z@\box\tw@} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\DC@right} +% ^^A This deals with both the cases where a specified number of decimal +% ^^A places is given. % \begin{macrocode} -\def\DC@right#1#2#3{% - \ifx\relax#3\relax + % \def\DC@right#1#2#3{% + % \ifx\relax#3\relax % \end{macrocode} -% If \verb?#3? is empty, add \cs{hfill} to right align the column, and -% Just set \cs{DC@rl} to begin a group, so nothing fancy is done with -% the whole number part. +% ^^A If \verb?#3? is empty, add \cs{hfill} to right align the column, and +% ^^A Just set \cs{DC@rl} to begin a group, so nothing fancy is done with +% ^^A the whole number part. % \begin{macrocode} - \hfill - \let\DC@rl\bgroup - \else + % \hfill + % \let\DC@rl\bgroup + % \else % \end{macrocode} -% Otherwise set \cs{DC@rl} so that the whole number part is put in a -% box \cs{count@} times as wide as a digit. -% In order to share code with the other branch, then move \verb?#3? (the -% number of decimal places) into \cs{count@} throwing away the `.' from -% the user syntax. +% ^^A Otherwise set \cs{DC@rl} so that the whole number part is put in a +% ^^A box \cs{count@} times as wide as a digit. +% ^^A In order to share code with the other branch, then move \verb?#3? (the +% ^^A number of decimal places) into \cs{count@} throwing away the `.' from +% ^^A the user syntax. % \begin{macrocode} - \edef\DC@rl{to\the\count@\dimen@ii\bgroup\hss\hfill}% - \count@\@gobble#3\relax - \fi + % \edef\DC@rl{to\the\count@\dimen@ii\bgroup\hss\hfill}% + % \count@\@gobble#3\relax + % \fi % \end{macrocode} -% +% ^^A % \begin{macrocode} - \let\DC@end\DC@endright + % \let\DC@end\DC@endright % \end{macrocode} -% Box 2 contains the decimal part, set to \cs{dimen@} which is -% calculated below to be \cs{count@} times the width of a digit, plus -% the width of the `decimal point'. +% ^^A Box 2 contains the decimal part, set to \cs{dimen@} which is +% ^^A calculated below to be \cs{count@} times the width of a digit, plus +% ^^A the width of the `decimal point'. % \begin{macrocode} - \uppercase{\def~}{$\egroup\setbox\tw@\hbox to\dimen@\bgroup${#2}}% - \setbox\z@\hbox{$1$}\dimen@ii\wd\z@ - \dimen@\count@\dimen@ii - \setbox\z@\hbox{${#2}$}\advance\dimen@\wd\z@ - \setbox\tw@\hbox to\dimen@{}% + % \uppercase{\def~}{$\egroup\setbox\tw@\hbox to\dimen@\bgroup${#2}}% + % \setbox\z@\hbox{$1$}\dimen@ii\wd\z@ + % \dimen@\count@\dimen@ii + % \setbox\z@\hbox{${#2}$}\advance\dimen@\wd\z@ + % \setbox\tw@\hbox to\dimen@{}% % \end{macrocode} -% Box 0 contains the whole number part, either just at its natural -% size for right aligned columns, or set to (the old value of) -% \cs{count@} times the width of a digit. \cs{DC@rl} defined above -% determines the two cases. +% ^^A Box 0 contains the whole number part, either just at its natural +% ^^A size for right aligned columns, or set to (the old value of) +% ^^A \cs{count@} times the width of a digit. \cs{DC@rl} defined above +% ^^A determines the two cases. % \begin{macrocode} - \setbox\z@\hbox\DC@rl$\mathcode`#1="8000 }%$ + % \setbox\z@\hbox\DC@rl$\mathcode`#1="8000 }%$ % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\DC@endright} -% Just finish off the second box, and then put out both boxes. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\DC@endright} +% ^^A Just finish off the second box, and then put out both boxes. % \begin{macrocode} -\def\DC@endright{$\hfil\egroup\box\z@\box\tw@}%$ + % \def\DC@endright{$\hfil\egroup\box\z@\box\tw@}%$ % \end{macrocode} -% \end{macro} -% -% \begin{macro}{D} -% The user interface, define the {\tt D} column to take three arguments. -% For special purposes, you may need to directly access \cs{DC@} rather -% than the \verb?D? column, eg to get a bold version you could use -%\begin{verbatim} -% \newcolumntype{E}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}} -%\end{verbatim} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{D} +% ^^A The user interface, define the {\tt D} column to take three arguments. +% ^^A For special purposes, you may need to directly access \cs{DC@} rather +% ^^A than the \verb?D? column, eg to get a bold version you could use +% ^^A\begin{verbatim} +% ^^A \newcolumntype{E}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}} +% ^^A\end{verbatim} +% \begin{macrocode} + % \newcolumntype{D}[3]{>{\DC@{#1}{#2}{#3}}c<{\DC@end}} + % +% \end{macrocode} +% ^^A \end{macro} +% ^^A % \begin{macrocode} -\newcolumntype{D}[3]{>{\DC@{#1}{#2}{#3}}c<{\DC@end}} - + % %%%%%%%%%% end Dcolumn package code %%%%%%%%%%%%%%%%%%%%% + % % \end{macrocode} -% \end{macro} +% ^^A % -% \begin{macrocode} -%%%%%%%%%% end Dcolumn package code %%%%%%%%%%%%%%%%%%%%% - -% \end{macrocode} % % \subsection{Support for delimeters} % -% The description and code are essentially from the -% \Lpack{delarray} package~\cite{DELARRAY}, v1.01 1994/03/14. -% +% Here ealier versions of the class had an embedded copy of the +% \Lpack{dearray} package. Now replaced by requiring the packge instead. % \begin{macrocode} -%%%%%%%%%% Delarray package code %%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% - +\RequirePackage{delarray}[2014/10/28] % \end{macrocode} +% The embeded copy is outcommented for now and will be removed in a +% later version. % -% -% The array syntax is extended by -% supporting the notation of delimiters. To this end we extend the -% array parsing mechanism to include a hook which can be used by this -% (or another) package to do some additional parsing. -% -% -% \begin{macro}{\@@array} -% This macro tests for an optional delimiter before the left brace -% of the main preamble argument. If there is no delimiter, -% \cs{@arrayleft} and \cs{@arrayright} are made a no-ops, and -% \cs{@array} is called with the positional argument. Otherwise -% call \cs{@del@array}. +% \changes{v3.7h}{2018/09/06}{Outcommented the embedded copy of +% \Lpack{delarray} and replaced it with requiring the \Lpack{delarray} package +% instead.} +% ^^A +% ^^A The description and code are essentially from the +% ^^A \Lpack{delarray} package~\cite{DELARRAY}, v1.01 1994/03/14. +% ^^A % \begin{macrocode} -\def\@@array[#1]{\@ifnextchar\bgroup - {\let\@arrayleft\relax\let\@arrayright\relax\@array[#1]}% - {\@del@array[#1]}} + % %%%%%%%%%% Delarray package code %%%%%%%%%%%%%%%%%%%%% + % %%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% + % % \end{macrocode} -% \end{macro} -% \begin{macro}{\@del@array} -% We now know that we have an {\tt array} (or {\tt tabular}) with -% delimiters. +% ^^A +% ^^A +% ^^A The array syntax is extended by +% ^^A supporting the notation of delimiters. To this end we extend the +% ^^A array parsing mechanism to include a hook which can be used by this +% ^^A (or another) package to do some additional parsing. +% ^^A +% ^^A +% ^^A \begin{macro}{\@@array} +% ^^A This macro tests for an optional delimiter before the left brace +% ^^A of the main preamble argument. If there is no delimiter, +% ^^A \cs{@arrayleft} and \cs{@arrayright} are made a no-ops, and +% ^^A \cs{@array} is called with the positional argument. Otherwise +% ^^A call \cs{@del@array}. % \begin{macrocode} -\def\@del@array[#1]#2#3#4{% + % \def\@@array[#1]{\@ifnextchar\bgroup + % {\let\@arrayleft\relax\let\@arrayright\relax\@array[#1]}% + % {\@del@array[#1]}} % \end{macrocode} -% The following line is completely redundant but it does catch errors -% involving delimiters before the processing of the alignment begins. -% A common error is likely to be omiting the `.' in a -% \cs{cases}-type construction. This causes the first token of the -% alignment to be gobbled, possibly causing lots of spurious errors -% before the cause of the error, the missing delimiter, is discovered as -% \cs{@arrayright} puts the alignment and the delimiters together. +% ^^A \end{macro} +% ^^A \begin{macro}{\@del@array} +% ^^A We now know that we have an {\tt array} (or {\tt tabular}) with +% ^^A delimiters. % \begin{macrocode} - \setbox\z@\hbox{$\left#2\right#4$}% + % \def\@del@array[#1]#2#3#4{% % \end{macrocode} -% In the case of a `c' argument we do not need to rebox the alignment, -% so we can define \cs{@arrayleft} and \cs{@arrayright} just to -% insert the delimiters. +% ^^A The following line is completely redundant but it does catch errors +% ^^A involving delimiters before the processing of the alignment begins. +% ^^A A common error is likely to be omiting the `.' in a +% ^^A \cs{cases}-type construction. This causes the first token of the +% ^^A alignment to be gobbled, possibly causing lots of spurious errors +% ^^A before the cause of the error, the missing delimiter, is discovered as +% ^^A \cs{@arrayright} puts the alignment and the delimiters together. % \begin{macrocode} - \if#1c\def\@arrayleft{\left#2}\def\@arrayright{\right#4}% + % \setbox\z@\hbox{$\left#2\right#4$}% % \end{macrocode} -% Otherwise we (should) have a {\tt[t]} or {\tt[b]} argument, so first we -% store the alignment, without delimiters in box0. +% ^^A In the case of a `c' argument we do not need to rebox the alignment, +% ^^A so we can define \cs{@arrayleft} and \cs{@arrayright} just to +% ^^A insert the delimiters. % \begin{macrocode} - \else\def\@arrayleft{\setbox\z@}% + % \if#1c\def\@arrayleft{\left#2}\def\@arrayright{\right#4}% % \end{macrocode} -% Then after the alignment is finished: +% ^^A Otherwise we (should) have a {\tt[t]} or {\tt[b]} argument, so first we +% ^^A store the alignment, without delimiters in box0. % \begin{macrocode} - \def\@arrayright{% + % \else\def\@arrayleft{\setbox\z@}% % \end{macrocode} -% Calculate the amount the box needs to be lowered (this will be -% negative in the case of \verb?[b]?). A little bit of arithmetic cf.\ -% \theTeXbook, Appendix G, rule 8. We calculate the amount this -% way, rather than just taking the difference between the depth of box0 -% and the depth of the box defined below, as the depth of that box may -% be affected by the delimiters if \cs{delimitershortfall} or -% \cs{delimiterfactor} have non-standard values. +% ^^A Then after the alignment is finished: % \begin{macrocode} - \dimen@=\dp\z@ - \advance\dimen@-\ht\z@ - \divide \dimen@ by \tw@ - \advance\dimen@ by\fontdimen22 \textfont\tw@ + % \def\@arrayright{% % \end{macrocode} -% Now lower the alignment and the delimiters into place. +% ^^A Calculate the amount the box needs to be lowered (this will be +% ^^A negative in the case of \verb?[b]?). A little bit of arithmetic cf.\ +% ^^A \theTeXbook, Appendix G, rule 8. We calculate the amount this +% ^^A way, rather than just taking the difference between the depth of box0 +% ^^A and the depth of the box defined below, as the depth of that box may +% ^^A be affected by the delimiters if \cs{delimitershortfall} or +% ^^A \cs{delimiterfactor} have non-standard values. % \begin{macrocode} - \lower\dimen@\hbox{$\left#2\vcenter{\unvbox\z@}\right#4$}}% + % \dimen@=\dp\z@ + % \advance\dimen@-\ht\z@ + % \divide \dimen@ by \tw@ + % \advance\dimen@ by\fontdimen22 \textfont\tw@ % \end{macrocode} -% End the \verb?\if#1c? +% ^^A Now lower the alignment and the delimiters into place. % \begin{macrocode} - \fi + % \lower\dimen@\hbox{$\left#2\vcenter{\unvbox\z@}\right#4$}}% % \end{macrocode} -% Now that we have defined \cs{@arrayleft} and \cs{@arrayright}, call -% \cs{@array}. +% ^^A End the \verb?\if#1c? % \begin{macrocode} - \@array[#1]{#3}} -% \end{macrocode} -% \end{macro} -% -% -% \begin{macrocode} -%%%%%%%%%% end Delarray package code %%%%%%%%%%%%%%%%%%%%% - + % \fi % \end{macrocode} -% -% \subsection{The tabularx environment} -% -% The code and description are essentially from David Carlisle's -% \Lpack{tabularx} package~\cite{TABULARX}, v2.07 1999/01/07. -% +% ^^A Now that we have defined \cs{@arrayleft} and \cs{@arrayright}, call +% ^^A \cs{@array}. % \begin{macrocode} -%%%%%%%%%% Tabularx package code %%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% - -%%% This is a carbon copy of the tabularx dtx sources for v2.11, -%%% 2016/02/03 with two changes: error messages mention the class -%%% instead of tabularx. - -%%%%%%%%%% Tabularx package code v2.11 2016/02/03 %%%%%%%%%%%%%%%%%%%%% - + % \@array[#1]{#3}} % \end{macrocode} -% -% -% -% The \Lpack{tabularx} package~\cite{TABULARX} implements a version of the \texttt{tabular} -% environment in which the widths of certain columns are calculated so -% that the table is is a specified width. The columns that may stretch are -% marked by an \texttt{X} in the preamble argument. -% -% What follows is a carbon copy of the contents of \texttt{tabularx.dtx} with small changes: (1) We make errors/warnings -% mention the class instead of \texttt{tabularx}, (2) we strip \texttt{tabularx} related \cs{changes} macros, (3) we -% remove loading the \Lpack{array} package, as we already come with a copy. -% -% First some registers etc.\ that we need. +% ^^A \end{macro} +% ^^A +% ^^A % \begin{macrocode} -\newdimen\TX@col@width -\newdimen\TX@old@table -\newdimen\TX@old@col -\newdimen\TX@target -\newdimen\TX@delta -\newcount\TX@cols -\newif\ifTX@ + % %%%%%%%%%% end Delarray package code %%%%%%%%%%%%%%%%%%%%% + % % \end{macrocode} +% ^^A % -% Now a trick to get the body of an environment into a token register, without doing any expansion. This does not do any -% real checking of nested environments, so if you should need to nest one {\ttfamily tabularx} inside another, the inner -% one must be surrounded by \verb+{ }+. % -% \begin{macro}{\tabularx} -% Prior to (\texttt{tabularx}) v1.06, this macro took two arguments, which were saved in -% separate registers before the table body was saved by \verb+\TX@get@body+. -% Unfortunately this disables the \verb|[t]| optional argument. Now just save -% the width specification separately, then clear the token register -% \verb|\toks@|. -% Finally call \verb|\TX@get@body| to begin saving the body of the table. -% The \verb|{\ifnum0=`}\fi| was added at (tabularx) v1.03, to allow \Lenv{tabularx} to appear -% inside a \verb|\halign|.^^A -% \setbox0=\hbox{\footnotesize"\iffalse{\fi\ifnum0=`}\fi"}^^A -% \setbox2=\hbox{\footnotesize"\ifnum0=`{}\fi"}^^A -% \footnote{This adds an extra level of grouping, -% which is not really needed. Instead, I could use \box0\ here, and -% \box2\ below, however the code here would then have to be moved after -% the first line, because of the footnote to page 386 of the \TeX{}Book, -% and I do not think I should be writing code that is so obscure as to -% be documented in a footnote in an appendix called ``Dirty Tricks''!} +% \subsection{The tabularx environment} % -% This mechanism of grabbing an environment body does have the -% disadvantage (shared with the AMS alignment environments) that you -% can not make extension environments by code such as -%\begin{verbatim} -%\newenvironment{foo}{\begin{tabularx}{XX}}{\end{tabularx}} -%\end{verbatim} -% as the code is looking for a literal string \verb"\end{tabularx}" to stop -% scanning. Since version (tabularx) 2.02, one may avoid this problem by using -% \verb|\tabularx| and \verb|\endtabularx| directly in the definition: -%\begin{verbatim} -%\newenvironment{foo}{\tabularx{XX}}{\endtabularx} -%\end{verbatim} -% The scanner now looks for the end of the current environment (\verb|foo| in -% this example.) There are some restrictions on this usage, the -% principal one being that \verb|\endtabularx| must not be inside any \verb"{ }" pairs -% ao that the code before \verb"\endtabularx" may be extracted and added to the table body -% (prior to version (tabularx) 2.09 \verb"\endtabularx" had to be -% the \emph{first} token of the `end code' of the environment). +% Here ealier versions of the class had an embedded copy of the +% \Lpack{tabularx} package. Now replaced by requiring the packge instead. % \begin{macrocode} -\def\tabularx#1{% +\RequirePackage{tabularx}[2016/02/03] % \end{macrocode} -% Allow \verb"\tabularx" \verb"\endtabularx" (but not \verb"\begin{tabularx}" -% \verb"\end{tabularx}") to be used in \verb"\newenvironment" definitions. -% \begin{macrocode} -\edef\TX@{\@currenvir}% - {\ifnum0=`}\fi -% \end{macrocode} -% \verb"\relax" added at v1.05 so that non-expandable length tokens, like -% \verb"\textwidth" do not generate an extra space, and an overfull box. -% \verb"\relax" removed again at v4.09 in favour of \verb"\setlength" so if you -% use the calc package you can use a width of \verb"(\textwidth-12pt)/2". -% \begin{macrocode} - \setlength\TX@target{#1}% - \TX@typeout{Target width: #1 = \the\TX@target.}% - \toks@{}\TX@get@body} -% \end{macrocode} -% \end{macro} +% The embeded copy is outcommented for now and will be removed in a +% later version. % +% \changes{v3.7h}{2018/09/06}{Outcommented the embedded copy of +% \Lpack{tabularx} and replaced it with requiring the \Lpack{tabularx} package +% instead.} -% \begin{macro}{\endtabularx} -% This does not do very much\ldots -% \begin{macrocode} -\let\endtabularx\relax -% \end{macrocode} -% \end{macro} % -% \begin{macro}{\TX@get@body} -% Place all tokens as far as the first \verb"\end" into a token register. -% Then call \verb"\TX@find@end" to see if we are at \verb"\end{tabularx}". -% \begin{macrocode} -\long\def\TX@get@body#1\end - {\toks@\expandafter{\the\toks@#1}\TX@find@end} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@find@end} -% If we are at \verb"\end{tabularx}", call \verb"\TX@endtabularx", otherwise -% add \verb"\end{...}" to the register, and call \verb"\TX@get@body" again. +% ^^A The code and description are essentially from David Carlisle's +% ^^A \Lpack{tabularx} package~\cite{TABULARX}, v2.07 1999/01/07. +% ^^A % \begin{macrocode} -\def\TX@find@end#1{% - \def\@tempa{#1}% - \ifx\@tempa\TX@\expandafter\TX@endtabularx - \else\toks@\expandafter - {\the\toks@\end{#1}}\expandafter\TX@get@body\fi} + % %%%%%%%%%% Tabularx package code %%%%%%%%%%%%%%%%%%%%% + % %%%%%%%%%% With acknowledgements to David Carlisle %%%%%%%%%%%%%%%%%%%%% + % + % %%% This is a carbon copy of the tabularx dtx sources for v2.11, + % %%% 2016/02/03 with two changes: error messages mention the class + % %%% instead of tabularx. + % + % %%%%%%%%%% Tabularx package code v2.11 2016/02/03 %%%%%%%%%%%%%%%%%%%%% + % % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@find@endtabularxa} -% split up the end code, and extract the part that lives in the table body. +% ^^A +% ^^A +% ^^A +% ^^A The \Lpack{tabularx} package~\cite{TABULARX} implements a version of the \texttt{tabular} +% ^^A environment in which the widths of certain columns are calculated so +% ^^A that the table is is a specified width. The columns that may stretch are +% ^^A marked by an \texttt{X} in the preamble argument. +% ^^A +% ^^A What follows is a carbon copy of the contents of \texttt{tabularx.dtx} with small changes: (1) We make errors/warnings +% ^^A mention the class instead of \texttt{tabularx}, (2) we strip \texttt{tabularx} related \cs{changes} macros, (3) we +% ^^A remove loading the \Lpack{array} package, as we already come with a copy. +% ^^A +% ^^A First some registers etc.\ that we need. % \begin{macrocode} -\long\def\TX@find@endtabularxa - #1\endtabularx#2\endtabularx#3\TX@find@endtabularxa{% - \ifx\TX@#2\relax\else - \toks@\expandafter{\the\toks@#1}% - \fi} + % \newdimen\TX@col@width + % \newdimen\TX@old@table + % \newdimen\TX@old@col + % \newdimen\TX@target + % \newdimen\TX@delta + % \newcount\TX@cols + % \newif\ifTX@ % \end{macrocode} -% \end{macro} -% \begin{macro}{\TX@find@endtabularxb} -% split up the end code, and extract the part that lives outside the table body. +% ^^A +% ^^A Now a trick to get the body of an environment into a token register, without doing any expansion. This does not do any +% ^^A real checking of nested environments, so if you should need to nest one {\ttfamily tabularx} inside another, the inner +% ^^A one must be surrounded by \verb+{ }+. +% ^^A +% ^^A \begin{macro}{\tabularx} +% ^^A Prior to (\texttt{tabularx}) v1.06, this macro took two arguments, which were saved in +% ^^A separate registers before the table body was saved by \verb+\TX@get@body+. +% ^^A Unfortunately this disables the \verb|[t]| optional argument. Now just save +% ^^A the width specification separately, then clear the token register +% ^^A \verb|\toks@|. +% ^^A Finally call \verb|\TX@get@body| to begin saving the body of the table. +% ^^A The \verb|{\ifnum0=`}\fi| was added at (tabularx) v1.03, to allow \Lenv{tabularx} to appear +% ^^A inside a \verb|\halign|.^^A +% ^^A \setbox0=\hbox{\footnotesize"\iffalse{\fi\ifnum0=`}\fi"}^^A +% ^^A \setbox2=\hbox{\footnotesize"\ifnum0=`{}\fi"}^^A +% ^^A \footnote{This adds an extra level of grouping, +% ^^A which is not really needed. Instead, I could use \box0\ here, and +% ^^A \box2\ below, however the code here would then have to be moved after +% ^^A the first line, because of the footnote to page 386 of the \TeX{}Book, +% ^^A and I do not think I should be writing code that is so obscure as to +% ^^A be documented in a footnote in an appendix called ``Dirty Tricks''!} +% ^^A +% ^^A This mechanism of grabbing an environment body does have the +% ^^A disadvantage (shared with the AMS alignment environments) that you +% ^^A can not make extension environments by code such as +% ^^A\begin{verbatim} +% ^^A\newenvironment{foo}{\begin{tabularx}{XX}}{\end{tabularx}} +% ^^A\end{verbatim} +% ^^A as the code is looking for a literal string \verb"\end{tabularx}" to stop +% ^^A scanning. Since version (tabularx) 2.02, one may avoid this problem by using +% ^^A \verb|\tabularx| and \verb|\endtabularx| directly in the definition: +% ^^A\begin{verbatim} +% ^^A\newenvironment{foo}{\tabularx{XX}}{\endtabularx} +% ^^A\end{verbatim} +% ^^A The scanner now looks for the end of the current environment (\verb|foo| in +% ^^A this example.) There are some restrictions on this usage, the +% ^^A principal one being that \verb|\endtabularx| must not be inside any \verb"{ }" pairs +% ^^A ao that the code before \verb"\endtabularx" may be extracted and added to the table body +% ^^A (prior to version (tabularx) 2.09 \verb"\endtabularx" had to be +% ^^A the \emph{first} token of the `end code' of the environment). +% \begin{macrocode} + % \def\tabularx#1{% +% \end{macrocode} +% ^^A Allow \verb"\tabularx" \verb"\endtabularx" (but not \verb"\begin{tabularx}" +% ^^A \verb"\end{tabularx}") to be used in \verb"\newenvironment" definitions. +% \begin{macrocode} + % \edef\TX@{\@currenvir}% + % {\ifnum0=`}\fi +% \end{macrocode} +% ^^A \verb"\relax" added at v1.05 so that non-expandable length tokens, like +% ^^A \verb"\textwidth" do not generate an extra space, and an overfull box. +% ^^A \verb"\relax" removed again at v4.09 in favour of \verb"\setlength" so if you +% ^^A use the calc package you can use a width of \verb"(\textwidth-12pt)/2". +% \begin{macrocode} + % \setlength\TX@target{#1}% + % \TX@typeout{Target width: #1 = \the\TX@target.}% + % \toks@{}\TX@get@body} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\endtabularx} +% ^^A This does not do very much\ldots % \begin{macrocode} -\long\def\TX@find@endtabularxb - #1\endtabularx#2\endtabularx#3\TX@find@endtabularxb{% - \ifx\TX@#2% - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi - {#1}{#2}} + % \let\endtabularx\relax % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@find@endtabularxbb} -% Helper to avoid needing 15 consecutive \verb"\expandafter" +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@get@body} +% ^^A Place all tokens as far as the first \verb"\end" into a token register. +% ^^A Then call \verb"\TX@find@end" to see if we are at \verb"\end{tabularx}". % \begin{macrocode} -\def\TX@find@endtabularxbb{% - \expandafter\expandafter\expandafter - \TX@find@endtabularxb -} + % \long\def\TX@get@body#1\end + % {\toks@\expandafter{\the\toks@#1}\TX@find@end} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@} -% The string {\ttfamily tabularx} as a macro for testing with \verb"\ifx". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@find@end} +% ^^A If we are at \verb"\end{tabularx}", call \verb"\TX@endtabularx", otherwise +% ^^A add \verb"\end{...}" to the register, and call \verb"\TX@get@body" again. % \begin{macrocode} -\def\TX@{tabularx} + % \def\TX@find@end#1{% + % \def\@tempa{#1}% + % \ifx\@tempa\TX@\expandafter\TX@endtabularx + % \else\toks@\expandafter + % {\the\toks@\end{#1}}\expandafter\TX@get@body\fi} % \end{macrocode} -% \end{macro} -% -% Now that all the parts of the table specification are stored in -% registers, we can begin the work of setting the table. -% -% The algorithm for finding the correct column widths is as follows. -% Firstly set the table with each {\ttfamily X} column the width of the -% final table. Assuming that there is at least one {\ttfamily X} column, -% this will produce a table that is too wide. Divide the excess width by -% the number of {\ttfamily X} columns, and reduce the column width by -% this amount. Reset the table. If the table is not now the correct -% width, a \verb"\multicolumn" entry must be `hiding' one of the {\ttfamily -% X} columns, and so there is one less {\ttfamily X} column affecting -% the width of the table. So we reduce by 1 the number of X columns and -% repeat the process. -% -% \begin{macro}{\TX@endtabularx} -% Although I have tried to make {\ttfamily tabularx} look like an -% environment, it is in fact a command, all the work is done by this -% macro. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@find@endtabularxa} +% ^^A split up the end code, and extract the part that lives in the table body. % \begin{macrocode} -\def\TX@endtabularx{% - \expandafter\expandafter\expandafter - \TX@find@endtabularxa\csname end\TX@\endcsname - \endtabularx\TX@\endtabularx\TX@find@endtabularxa + % \long\def\TX@find@endtabularxa + % #1\endtabularx#2\endtabularx#3\TX@find@endtabularxa{% + % \ifx\TX@#2\relax\else + % \toks@\expandafter{\the\toks@#1}% + % \fi} % \end{macrocode} -% Define the {\ttfamily X} column, with an internal version of the -% \verb"\newcolumntype" command. The \verb"\expandafter" commands enable -% \verb"\NC@newcol" to get the {\em expansion} of\\ -% \verb"\tabularxcolumn{\TX@col@width}" as its -% argument. This will be the definition of an {\ttfamily X} column, as -% discussed in section 4. +% ^^A \end{macro} +% ^^A \begin{macro}{\TX@find@endtabularxb} +% ^^A split up the end code, and extract the part that lives outside the table body. % \begin{macrocode} - \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}% + % \long\def\TX@find@endtabularxb + % #1\endtabularx#2\endtabularx#3\TX@find@endtabularxb{% + % \ifx\TX@#2% + % \expandafter\@firstoftwo + % \else + % \expandafter\@secondoftwo + % \fi + % {#1}{#2}} % \end{macrocode} -% Initialise the column width, and the number of {\ttfamily X} columns. -% The number of {\ttfamily X} columns is set to one, which means that -% the initial count will be one too high, but this value is decremented -% before it is used in the main loop. -% -% Since v1.02, switch the definition of \verb"\verb". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@find@endtabularxbb} +% ^^A Helper to avoid needing 15 consecutive \verb"\expandafter" % \begin{macrocode} - \let\verb\TX@verb + % \def\TX@find@endtabularxbb{% + % \expandafter\expandafter\expandafter + % \TX@find@endtabularxb + % } % \end{macrocode} -% Since v1.05, save the values of all \LaTeX\ counters, the list -% \verb"\cl@@ckpt" contains the names of all the \LaTeX\ counters that have -% been defined so far. We expand \verb"\setcounter" at this point, as it -% results in fewer tokens being stored in \verb"\TX@ckpt", but the actual -% resetting of the counters occurs when \verb"\TX@ckpt" is expanded after -% each trial run. -% Actually since v1.07, use something equivalent to the expansion of the -% original definition of \verb"\setcounter", so that \verb"tabularx" works in -% conjunction with \verb"calc.sty". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@} +% ^^A The string {\ttfamily tabularx} as a macro for testing with \verb"\ifx". % \begin{macrocode} - \def\@elt##1{\global\value{##1}\the\value{##1}\relax}% - \edef\TX@ckpt{\cl@@ckpt}% - \let\@elt\relax - \TX@old@table\maxdimen - \TX@col@width\TX@target - \global\TX@cols\@ne + % \def\TX@{tabularx} % \end{macrocode} -% Typeout some headings (unless this is disabled). -% \begin{macrocode} - \TX@typeout@ - {\@spaces Table Width\@spaces Column Width\@spaces X Columns}% +% ^^A \end{macro} +% ^^A +% ^^A Now that all the parts of the table specification are stored in +% ^^A registers, we can begin the work of setting the table. +% ^^A +% ^^A The algorithm for finding the correct column widths is as follows. +% ^^A Firstly set the table with each {\ttfamily X} column the width of the +% ^^A final table. Assuming that there is at least one {\ttfamily X} column, +% ^^A this will produce a table that is too wide. Divide the excess width by +% ^^A the number of {\ttfamily X} columns, and reduce the column width by +% ^^A this amount. Reset the table. If the table is not now the correct +% ^^A width, a \verb"\multicolumn" entry must be `hiding' one of the {\ttfamily +% ^^A X} columns, and so there is one less {\ttfamily X} column affecting +% ^^A the width of the table. So we reduce by 1 the number of X columns and +% ^^A repeat the process. +% ^^A +% ^^A \begin{macro}{\TX@endtabularx} +% ^^A Although I have tried to make {\ttfamily tabularx} look like an +% ^^A environment, it is in fact a command, all the work is done by this +% ^^A macro. +% \begin{macrocode} + % \def\TX@endtabularx{% + % \expandafter\expandafter\expandafter + % \TX@find@endtabularxa\csname end\TX@\endcsname + % \endtabularx\TX@\endtabularx\TX@find@endtabularxa +% \end{macrocode} +% ^^A Define the {\ttfamily X} column, with an internal version of the +% ^^A \verb"\newcolumntype" command. The \verb"\expandafter" commands enable +% ^^A \verb"\NC@newcol" to get the {\em expansion} of\\ +% ^^A \verb"\tabularxcolumn{\TX@col@width}" as its +% ^^A argument. This will be the definition of an {\ttfamily X} column, as +% ^^A discussed in section 4. +% \begin{macrocode} + % \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}% +% \end{macrocode} +% ^^A Initialise the column width, and the number of {\ttfamily X} columns. +% ^^A The number of {\ttfamily X} columns is set to one, which means that +% ^^A the initial count will be one too high, but this value is decremented +% ^^A before it is used in the main loop. +% ^^A +% ^^A Since v1.02, switch the definition of \verb"\verb". +% \begin{macrocode} + % \let\verb\TX@verb +% \end{macrocode} +% ^^A Since v1.05, save the values of all \LaTeX\ counters, the list +% ^^A \verb"\cl@@ckpt" contains the names of all the \LaTeX\ counters that have +% ^^A been defined so far. We expand \verb"\setcounter" at this point, as it +% ^^A results in fewer tokens being stored in \verb"\TX@ckpt", but the actual +% ^^A resetting of the counters occurs when \verb"\TX@ckpt" is expanded after +% ^^A each trial run. +% ^^A Actually since v1.07, use something equivalent to the expansion of the +% ^^A original definition of \verb"\setcounter", so that \verb"tabularx" works in +% ^^A conjunction with \verb"calc.sty". +% \begin{macrocode} + % \def\@elt##1{\global\value{##1}\the\value{##1}\relax}% + % \edef\TX@ckpt{\cl@@ckpt}% + % \let\@elt\relax + % \TX@old@table\maxdimen + % \TX@col@width\TX@target + % \global\TX@cols\@ne +% \end{macrocode} +% ^^A Typeout some headings (unless this is disabled). +% \begin{macrocode} + % \TX@typeout@ + % {\@spaces Table Width\@spaces Column Width\@spaces X Columns}% % \end{macrocode}% -% First attempt. Modify the {\ttfamily X} definition to count {\ttfamily -% X} columns. -% \begin{macrocode} - \TX@trial{\def\NC@rewrite@X{% - \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}% -% \end{macrocode} -% Repeatedly decrease column width until table is the correct width, -% or stops shrinking, or the columns become two narrow. -% If there are no multicolumn entries, this will only take one attempt. +% ^^A First attempt. Modify the {\ttfamily X} definition to count {\ttfamily +% ^^A X} columns. % \begin{macrocode} - \loop - \TX@arith - \ifTX@ - \TX@trial{}% - \repeat -% \end{macrocode} -% One last time, with warnings back on (see appendix D) -% use {\ttfamily tabular*} to put it in a box of the right size, in case -% the algorithm failed to find the correct size. -% -% Since v1.04, locally make \verb"\footnotetext" save its argument in a token -% register. -% Since v1.06, \verb"\toks@" contains the preamble specification, -% and possible optional argument, as well as the table body. -% \begin{macrocode} - {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext - \csname tabular*\expandafter\endcsname\expandafter\TX@target - \the\toks@ - \csname endtabular*\endcsname}% -% \end{macrocode} -% Now the alignment is finished, and the \verb"}" has restored the original -% meaning of \verb"\@footnotetext" expand the register \verb"\TX@ftn" which will -% execute a series of\\ -% \verb"\footnotetext["\meta{num}\verb"]{"\meta{note}\verb"}"\\ -% commands. We need to be careful about clearing the register as we may -% be inside a nested {\ttfamily tabularx}. -% \begin{macrocode} - \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn -% \end{macrocode} -% Now finish off the {\ttfamily tabularx} environment. Note that we need -% \verb"\end{tabularx}" here as the \verb"\end{tabularx}" in the user's -% file is never expanded. Now use \verb"\TX@" rather than \verb"tabularx". -% -% We also need to finish off the group started by \verb"{\ifnum0=`}\fi" in -% the macro \verb"\tabularx". -% \begin{macrocode} - \ifnum0=`{\fi}% - \expandafter\expandafter\expandafter - \TX@find@endtabularxbb - \expandafter\end\expandafter{\TX@}% - \endtabularx\TX@\endtabularx\TX@find@endtabularxb -} + % \TX@trial{\def\NC@rewrite@X{% + % \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}% % \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\TX@arith} -% Calculate the column width for the next try, setting the flag -% \verb"\ifTX@" to false if the loop should be aborted. +% ^^A Repeatedly decrease column width until table is the correct width, +% ^^A or stops shrinking, or the columns become two narrow. +% ^^A If there are no multicolumn entries, this will only take one attempt. % \begin{macrocode} -\def\TX@arith{% - \TX@false - \@tempdimb\maxdimen - \divide\@tempdimb\TX@cols - \ifdim\TX@col@width>\@tempdimb - \TX@typeout@{Don't exceed \maxdimen}% - \wd\@tempboxa\maxdimen - \fi - \ifdim\TX@old@table=\wd\@tempboxa + % \loop + % \TX@arith + % \ifTX@ + % \TX@trial{}% + % \repeat % \end{macrocode} -% If we have reduced the column width, but the table width has not -% changed, we stop the loop, and output the table (which will cause an -% over-full alignment) with the previous value of \verb"\TX@col@width". +% ^^A One last time, with warnings back on (see appendix D) +% ^^A use {\ttfamily tabular*} to put it in a box of the right size, in case +% ^^A the algorithm failed to find the correct size. +% ^^A +% ^^A Since v1.04, locally make \verb"\footnotetext" save its argument in a token +% ^^A register. +% ^^A Since v1.06, \verb"\toks@" contains the preamble specification, +% ^^A and possible optional argument, as well as the table body. +% \begin{macrocode} + % {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext + % \csname tabular*\expandafter\endcsname\expandafter\TX@target + % \the\toks@ + % \csname endtabular*\endcsname}% +% \end{macrocode} +% ^^A Now the alignment is finished, and the \verb"}" has restored the original +% ^^A meaning of \verb"\@footnotetext" expand the register \verb"\TX@ftn" which will +% ^^A execute a series of\\ +% ^^A \verb"\footnotetext["\meta{num}\verb"]{"\meta{note}\verb"}"\\ +% ^^A commands. We need to be careful about clearing the register as we may +% ^^A be inside a nested {\ttfamily tabularx}. +% \begin{macrocode} + % \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn +% \end{macrocode} +% ^^A Now finish off the {\ttfamily tabularx} environment. Note that we need +% ^^A \verb"\end{tabularx}" here as the \verb"\end{tabularx}" in the user's +% ^^A file is never expanded. Now use \verb"\TX@" rather than \verb"tabularx". +% ^^A +% ^^A We also need to finish off the group started by \verb"{\ifnum0=`}\fi" in +% ^^A the macro \verb"\tabularx". % \begin{macrocode} - \TX@col@width\TX@old@col - \TX@typeout@{Reached minimum width, backing up.}% - \else + % \ifnum0=`{\fi}% + % \expandafter\expandafter\expandafter + % \TX@find@endtabularxbb + % \expandafter\end\expandafter{\TX@}% + % \endtabularx\TX@\endtabularx\TX@find@endtabularxb + % } % \end{macrocode} -% Otherwise calculate the amount by which the current table is too wide. -% \begin{macrocode} - \dimen@\wd\@tempboxa - \advance\dimen@ -\TX@target - \ifdim\dimen@<\TX@delta +% ^^A \end{macro} +% ^^A +% ^^A +% ^^A \begin{macro}{\TX@arith} +% ^^A Calculate the column width for the next try, setting the flag +% ^^A \verb"\ifTX@" to false if the loop should be aborted. +% \begin{macrocode} + % \def\TX@arith{% + % \TX@false + % \@tempdimb\maxdimen + % \divide\@tempdimb\TX@cols + % \ifdim\TX@col@width>\@tempdimb + % \TX@typeout@{Don't exceed \maxdimen}% + % \wd\@tempboxa\maxdimen + % \fi + % \ifdim\TX@old@table=\wd\@tempboxa % \end{macrocode} -% If this amount is less than \verb"\TX@delta", stop. (\verb"\TX@delta" -% should be non-zero otherwise we may miss the target due to rounding -% error.) +% ^^A If we have reduced the column width, but the table width has not +% ^^A changed, we stop the loop, and output the table (which will cause an +% ^^A over-full alignment) with the previous value of \verb"\TX@col@width". % \begin{macrocode} - \TX@typeout@{Reached target.}% - \else + % \TX@col@width\TX@old@col + % \TX@typeout@{Reached minimum width, backing up.}% + % \else % \end{macrocode} -% Reduce the number of effective {\ttfamily X} columns by one. (Checking -% that we do not get 0, as this would produce an error later.) Then -% divide excess width by the number of effective columns, and calculate -% the new column width. Temporarily store this value (times $-1$) in -% \verb"\dimen@". +% ^^A Otherwise calculate the amount by which the current table is too wide. % \begin{macrocode} - \ifnum\TX@cols>\@ne - \advance\TX@cols\m@ne - \fi - \divide\dimen@\TX@cols - \advance\dimen@ -\TX@col@width - \ifdim \dimen@ >\z@ -% \end{macrocode} -% If the new width would be too narrow, abort the loop. At the moment -% too narrow, means less than 0\,pt! -% -% Prior to v2.03, if the loop was aborted here, the X columns were left -% with the width of the previous run, but this may make the table far -% too wide as initial guesses are always too big. Now force to -% \verb"\TX@error@width" which defaults to be 1em. If you want to -% get the old behaviour stick\\ -% \verb"\renewcommand\TX@error@width{\TX@col@width}"\\ -% in a package file loaded after \textsf{tabularx}. -% \begin{macrocode} - %\PackageWarning{tabularx}% - \@memwarn{X Columns too narrow (table too wide)\MessageBreak}% <-- change here - \TX@col@width\TX@error@width\relax - \else + % \dimen@\wd\@tempboxa + % \advance\dimen@ -\TX@target + % \ifdim\dimen@<\TX@delta % \end{macrocode} -% Otherwise save the old settings, and set the new column width. Set the -% flag to true so that the table will be set, and the loop will be -% executed again. +% ^^A If this amount is less than \verb"\TX@delta", stop. (\verb"\TX@delta" +% ^^A should be non-zero otherwise we may miss the target due to rounding +% ^^A error.) % \begin{macrocode} - \TX@old@col\TX@col@width - \TX@old@table\wd\@tempboxa - \TX@col@width-\dimen@ - \TX@true - \fi - \fi - \fi} + % \TX@typeout@{Reached target.}% + % \else % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@error@width} -% If the calculated width is negative, use this instead. +% ^^A Reduce the number of effective {\ttfamily X} columns by one. (Checking +% ^^A that we do not get 0, as this would produce an error later.) Then +% ^^A divide excess width by the number of effective columns, and calculate +% ^^A the new column width. Temporarily store this value (times $-1$) in +% ^^A \verb"\dimen@". % \begin{macrocode} -\def\TX@error@width{1em} + % \ifnum\TX@cols>\@ne + % \advance\TX@cols\m@ne + % \fi + % \divide\dimen@\TX@cols + % \advance\dimen@ -\TX@col@width + % \ifdim \dimen@ >\z@ % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@delta} -% Accept a table that is within \verb"\hfuzz" of the correct width. -% \begin{macrocode} -\TX@delta\hfuzz +% ^^A If the new width would be too narrow, abort the loop. At the moment +% ^^A too narrow, means less than 0\,pt! +% ^^A +% ^^A Prior to v2.03, if the loop was aborted here, the X columns were left +% ^^A with the width of the previous run, but this may make the table far +% ^^A too wide as initial guesses are always too big. Now force to +% ^^A \verb"\TX@error@width" which defaults to be 1em. If you want to +% ^^A get the old behaviour stick\\ +% ^^A \verb"\renewcommand\TX@error@width{\TX@col@width}"\\ +% ^^A in a package file loaded after \textsf{tabularx}. +% \begin{macrocode} + % %\PackageWarning{tabularx}% + % \@memwarn{X Columns too narrow (table too wide)\MessageBreak}% <-- change here + % \TX@col@width\TX@error@width\relax + % \else +% \end{macrocode} +% ^^A Otherwise save the old settings, and set the new column width. Set the +% ^^A flag to true so that the table will be set, and the loop will be +% ^^A executed again. +% \begin{macrocode} + % \TX@old@col\TX@col@width + % \TX@old@table\wd\@tempboxa + % \TX@col@width-\dimen@ + % \TX@true + % \fi + % \fi + % \fi} % \end{macrocode} -% \end{macro} -% -% Initialise the {\ttfamily X} column. The definition can be empty here, -% as it is set for each {\ttfamily tabularx} environment. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@error@width} +% ^^A If the calculated width is negative, use this instead. % \begin{macrocode} -\newcolumntype{X}{} + % \def\TX@error@width{1em} % \end{macrocode} -% -% \begin{macro}{\tabularxcolumn} -% The default definition of {\ttfamily X} is \verb"p{#1}". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@delta} +% ^^A Accept a table that is within \verb"\hfuzz" of the correct width. % \begin{macrocode} -\def\tabularxcolumn#1{p{#1}} + % \TX@delta\hfuzz % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@newcol} -% A little macro just used to cut down the number of \verb"\expandafter" -% commands needed. +% ^^A \end{macro} +% ^^A +% ^^A Initialise the {\ttfamily X} column. The definition can be empty here, +% ^^A as it is set for each {\ttfamily tabularx} environment. % \begin{macrocode} -\def\TX@newcol{\newcol@{X}[0]} + % \newcolumntype{X}{} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@trial} -% Make a test run. +% ^^A +% ^^A \begin{macro}{\tabularxcolumn} +% ^^A The default definition of {\ttfamily X} is \verb"p{#1}". % \begin{macrocode} -\def\TX@trial#1{% - \setbox\@tempboxa\hbox{% + % \def\tabularxcolumn#1{p{#1}} % \end{macrocode} -% Any extra commands. This is used on the first run to count the number -% of {\ttfamily X} columns. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@newcol} +% ^^A A little macro just used to cut down the number of \verb"\expandafter" +% ^^A commands needed. % \begin{macrocode} - #1\relax + % \def\TX@newcol{\newcol@{X}[0]} % \end{macrocode} -% Since v1.04, make \verb"\footnotetext" gobble its arguments. Also locally -% clear \verb"\TX@vwarn" so that the warning is generated by the {\ttfamily -% final} run, and does not appear in the middle of the table if -% \verb"\tracingtabularx". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@trial} +% ^^A Make a test run. % \begin{macrocode} - \let\@footnotetext\TX@trial@ftn - \let\TX@vwarn\@empty + % \def\TX@trial#1{% + % \setbox\@tempboxa\hbox{% % \end{macrocode} -% Do not nest {\ttfamily tabularx} environments during trial runs. This -% would waste time, and the global setting of \verb"\TX@cols" would break the -% algorithm. +% ^^A Any extra commands. This is used on the first run to count the number +% ^^A of {\ttfamily X} columns. % \begin{macrocode} - \expandafter\let\expandafter\tabularx\csname tabular*\endcsname - \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname + % #1\relax % \end{macrocode} -% Added at v1.05: disable \verb"\write"s during a trial run. This trick is -% from the \TeX{}Book.\footnote{Actually the \TeX{}Book trick does -% not work correctly, so changed for v2.05.} +% ^^A Since v1.04, make \verb"\footnotetext" gobble its arguments. Also locally +% ^^A clear \verb"\TX@vwarn" so that the warning is generated by the {\ttfamily +% ^^A final} run, and does not appear in the middle of the table if +% ^^A \verb"\tracingtabularx". % \begin{macrocode} - \def\write{\begingroup - \def\let{\afterassignment\endgroup\toks@}% - \afterassignment\let\count@}% + % \let\@footnotetext\TX@trial@ftn + % \let\TX@vwarn\@empty % \end{macrocode} -% Turn off warnings (see appendix D). Also prevent them being turned -% back on by setting the parameter names to be registers. +% ^^A Do not nest {\ttfamily tabularx} environments during trial runs. This +% ^^A would waste time, and the global setting of \verb"\TX@cols" would break the +% ^^A algorithm. % \begin{macrocode} - \hbadness\@M - \hfuzz\maxdimen - \let\hbadness\@tempcnta - \let\hfuzz\@tempdima + % \expandafter\let\expandafter\tabularx\csname tabular*\endcsname + % \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname % \end{macrocode} -% Make the table, and finish the hbox. -% Since v1.06, \verb"\toks@" contains the preamble specification, -% and possible optional argument, as well as the table body. +% ^^A Added at v1.05: disable \verb"\write"s during a trial run. This trick is +% ^^A from the \TeX{}Book.\footnote{Actually the \TeX{}Book trick does +% ^^A not work correctly, so changed for v2.05.} % \begin{macrocode} - \expandafter\tabular\the\toks@ - \endtabular}% + % \def\write{\begingroup + % \def\let{\afterassignment\endgroup\toks@}% + % \afterassignment\let\count@}% % \end{macrocode} -% Since v1.05 reset all \LaTeX\ counters, by executing \verb"\TX@ckpt". +% ^^A Turn off warnings (see appendix D). Also prevent them being turned +% ^^A back on by setting the parameter names to be registers. % \begin{macrocode} - \TX@ckpt + % \hbadness\@M + % \hfuzz\maxdimen + % \let\hbadness\@tempcnta + % \let\hfuzz\@tempdima % \end{macrocode} -% Print some statistics. -% Added \verb"\TX@align" in v1.05, to line up the columns. +% ^^A Make the table, and finish the hbox. +% ^^A Since v1.06, \verb"\toks@" contains the preamble specification, +% ^^A and possible optional argument, as well as the table body. % \begin{macrocode} - \TX@typeout@{\@spaces - \expandafter\TX@align - \the\wd\@tempboxa\space\space\space\space\space\@@ - \expandafter\TX@align - \the\TX@col@width\space\space\space\space\space\@@ - \@spaces\the\TX@cols}} + % \expandafter\tabular\the\toks@ + % \endtabular}% % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@align} -% Macro added at v1.05, to improve the printing of the tracing info. +% ^^A Since v1.05 reset all \LaTeX\ counters, by executing \verb"\TX@ckpt". % \begin{macrocode} -\def\TX@align#1.#2#3#4#5#6#7#8#9\@@{% - \ifnum#1<10 \space\fi - \ifnum#1<100 \space\fi - \ifnum#1<\@m\space\fi - \ifnum#1<\@M\space\fi - #1.#2#3#4#5#6#7#8\space\space} + % \TX@ckpt % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\arraybackslash} -% \verb"\\" hack. +% ^^A Print some statistics. +% ^^A Added \verb"\TX@align" in v1.05, to line up the columns. % \begin{macrocode} -\ifx\arraybackslash\@undefined -\def\arraybackslash{\let\\\tabularnewline} -\fi + % \TX@typeout@{\@spaces + % \expandafter\TX@align + % \the\wd\@tempboxa\space\space\space\space\space\@@ + % \expandafter\TX@align + % \the\TX@col@width\space\space\space\space\space\@@ + % \@spaces\the\TX@cols}} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\tracingtabularx} -% Print statistics on column and table widths. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@align} +% ^^A Macro added at v1.05, to improve the printing of the tracing info. % \begin{macrocode} -\def\tracingtabularx{% - %\def\TX@typeout{\PackageWarningNoLine{tabularx}}% - \def\TX@typeout{\ClassWarningNoLine{memoir}}% <--- changed - \def\TX@typeout@##1{\typeout{(tabularx) ##1}}} + % \def\TX@align#1.#2#3#4#5#6#7#8#9\@@{% + % \ifnum#1<10 \space\fi + % \ifnum#1<100 \space\fi + % \ifnum#1<\@m\space\fi + % \ifnum#1<\@M\space\fi + % #1.#2#3#4#5#6#7#8\space\space} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@typeout} -% The default is to be to be quiet +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\arraybackslash} +% ^^A \verb"\\" hack. % \begin{macrocode} -\let\TX@typeout\@gobble -\let\TX@typeout@\@gobble + % \ifx\arraybackslash\@undefined + % \def\arraybackslash{\let\\\tabularnewline} + % \fi % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@ftn} -% A token register for saving footnote texts. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\tracingtabularx} +% ^^A Print statistics on column and table widths. % \begin{macrocode} -\newtoks\TX@ftn + % \def\tracingtabularx{% + % %\def\TX@typeout{\PackageWarningNoLine{tabularx}}% + % \def\TX@typeout{\ClassWarningNoLine{memoir}}% <--- changed + % \def\TX@typeout@##1{\typeout{(tabularx) ##1}}} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@ftntext} -% \begin{macro}{\TX@xftntext} -% Inside the alignment just save up the footnote text in a token -% register. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@typeout} +% ^^A The default is to be to be quiet % \begin{macrocode} -\long\def\TX@ftntext#1{% - \edef\@tempa{\the\TX@ftn\noexpand\footnotetext - [\the\csname c@\@mpfn\endcsname]}% - \global\TX@ftn\expandafter{\@tempa{#1}}}% -\long\def\TX@xftntext[#1]#2{% - \global\TX@ftn\expandafter{\the\TX@ftn\footnotetext[#1]{#2}}} + % \let\TX@typeout\@gobble + % \let\TX@typeout@\@gobble % \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\TX@trial@ftn} -% On trial runs, gobble footnote texts. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@ftn} +% ^^A A token register for saving footnote texts. % \begin{macrocode} -\long\def\TX@trial@ftn#1{} + % \newtoks\TX@ftn % \end{macrocode} -% \end{macro} -% -% This last section was added at Version 1.02. Previous versions -% documented the fact that \verb"\verb" did not work inside {\ttfamily -% tabularx}, but that did not stop people using it! This usually put -% \LaTeX\ into an irrecoverable error position, with error messages that -% did not mention the cause of the error. The `poor man's \verb"\verb"' (and -% \verb"\verb*") defined here is based on page 382 of the \TeX{}Book. As -% explained there, doing verbatim this way means that spaces are not -% treated correctly, and so \verb"\verb*" may well be useless, however I -% consider this section of code to be error-recovery, rather than a real -% implementation of verbatim. -% -% The mechanism is quite general, and any macro which wants to allow a -% form of \verb"\verb" to be used within its argument may -% \verb"\let\verb=\TX@verb". (Making sure to restore the real definition -% later!) -% -% \verb"\verb" and \verb"\verb*" are subject to the following restrictions: -% \begin{enumerate} -% \item Spaces in the argument are not read verbatim, but may be skipped -% according to \TeX's usual rules. -% \item Spaces will be added to the output after control words, even if -% they were not present in the input. -% \item Unless the argument is a single space, any trailing space, -% whether in the original argument, or added as in (2), -% will be omitted. -% \item The argument must not end with \verb"\", so \verb"\verb|\|" is not -% allowed, however, because of (3), \verb"\verb|\ |" produces -% \verb"\". -% \item The argument must be balanced with respect to \verb"{" and \verb"}". So -% \verb"\verb|{|" is not allowed. -% \item A comment character like \verb"%" will not appear verbatim. It will -% act as usual, commenting out the rest of the input line! -% \item The combinations \verb"?`" and \verb"!`" will appear as -% {\ttfamily?`} and {\ttfamily!`} if the {\ttfamily cmtt} font is -% being used. -% \end{enumerate} -% -% \begin{macro}{\TX@verb} -% The internal definition of \verb"\verb". Spaces will be replaced by \verb"~", so -% for the star-form, \verb"\let" \verb"~" be \verb*| |, which we obtain as -% \verb"\uppercase{*}". Use \verb"{\ifnum0=`}\fi" rather than \verb"\bgroup" to allow -% \verb"&" to appear in the argument. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@ftntext} +% ^^A \begin{macro}{\TX@xftntext} +% ^^A Inside the alignment just save up the footnote text in a token +% ^^A register. +% \begin{macrocode} + % \long\def\TX@ftntext#1{% + % \edef\@tempa{\the\TX@ftn\noexpand\footnotetext + % [\the\csname c@\@mpfn\endcsname]}% + % \global\TX@ftn\expandafter{\@tempa{#1}}}% + % \long\def\TX@xftntext[#1]#2{% + % \global\TX@ftn\expandafter{\the\TX@ftn\footnotetext[#1]{#2}}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@trial@ftn} +% ^^A On trial runs, gobble footnote texts. % \begin{macrocode} -{\uccode`\*=`\ % -\uppercase{\gdef\TX@verb{% - \leavevmode\null\TX@vwarn - {\ifnum0=`}\fi\ttfamily\let\\\ignorespaces - \@ifstar{\let~*\TX@vb}{\TX@vb}}}} + % \long\def\TX@trial@ftn#1{} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@vb} -% Get the `almost verbatim' text using \verb"\meaning". The `\verb"!"' is added to -% the front of the user supplied text, to ensure that the whole argument -% does not consist of a single \verb"{ }" group. \TeX\ would strip the outer -% braces from such a group. The `\verb"!"' will be removed later. -% -% Originally I followed Knuth, and had \verb"\def\@tempa{##1}", however this -% did not allow \verb"#" to appear in the argument. So in v1.04, I changed -% this to to use a token register, and \verb"\edef". This allows \verb"#" appear, -% but makes each one appear twice!, so later we loop through, replacing -% \verb"##" by \verb"#". +% ^^A \end{macro} +% ^^A +% ^^A This last section was added at Version 1.02. Previous versions +% ^^A documented the fact that \verb"\verb" did not work inside {\ttfamily +% ^^A tabularx}, but that did not stop people using it! This usually put +% ^^A \LaTeX\ into an irrecoverable error position, with error messages that +% ^^A did not mention the cause of the error. The `poor man's \verb"\verb"' (and +% ^^A \verb"\verb*") defined here is based on page 382 of the \TeX{}Book. As +% ^^A explained there, doing verbatim this way means that spaces are not +% ^^A treated correctly, and so \verb"\verb*" may well be useless, however I +% ^^A consider this section of code to be error-recovery, rather than a real +% ^^A implementation of verbatim. +% ^^A +% ^^A The mechanism is quite general, and any macro which wants to allow a +% ^^A form of \verb"\verb" to be used within its argument may +% ^^A \verb"\let\verb=\TX@verb". (Making sure to restore the real definition +% ^^A later!) +% ^^A +% ^^A \verb"\verb" and \verb"\verb*" are subject to the following restrictions: +% ^^A \begin{enumerate} +% ^^A \item Spaces in the argument are not read verbatim, but may be skipped +% ^^A according to \TeX's usual rules. +% ^^A \item Spaces will be added to the output after control words, even if +% ^^A they were not present in the input. +% ^^A \item Unless the argument is a single space, any trailing space, +% ^^A whether in the original argument, or added as in (2), +% ^^A will be omitted. +% ^^A \item The argument must not end with \verb"\", so \verb"\verb|\|" is not +% ^^A allowed, however, because of (3), \verb"\verb|\ |" produces +% ^^A \verb"\". +% ^^A \item The argument must be balanced with respect to \verb"{" and \verb"}". So +% ^^A \verb"\verb|{|" is not allowed. +% ^^A \item A comment character like \verb"%" will not appear verbatim. It will +% ^^A act as usual, commenting out the rest of the input line! +% ^^A \item The combinations \verb"?`" and \verb"!`" will appear as +% ^^A {\ttfamily?`} and {\ttfamily!`} if the {\ttfamily cmtt} font is +% ^^A being used. +% ^^A \end{enumerate} +% ^^A +% ^^A \begin{macro}{\TX@verb} +% ^^A The internal definition of \verb"\verb". Spaces will be replaced by \verb"~", so +% ^^A for the star-form, \verb"\let" \verb"~" be \verb*| |, which we obtain as +% ^^A \verb"\uppercase{*}". Use \verb"{\ifnum0=`}\fi" rather than \verb"\bgroup" to allow +% ^^A \verb"&" to appear in the argument. +% \begin{macrocode} + % {\uccode`\*=`\ % + % \uppercase{\gdef\TX@verb{% + % \leavevmode\null\TX@vwarn + % {\ifnum0=`}\fi\ttfamily\let\\\ignorespaces + % \@ifstar{\let~*\TX@vb}{\TX@vb}}}} +% \end{macrocode} +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@vb} +% ^^A Get the `almost verbatim' text using \verb"\meaning". The `\verb"!"' is added to +% ^^A the front of the user supplied text, to ensure that the whole argument +% ^^A does not consist of a single \verb"{ }" group. \TeX\ would strip the outer +% ^^A braces from such a group. The `\verb"!"' will be removed later. +% ^^A +% ^^A Originally I followed Knuth, and had \verb"\def\@tempa{##1}", however this +% ^^A did not allow \verb"#" to appear in the argument. So in v1.04, I changed +% ^^A this to to use a token register, and \verb"\edef". This allows \verb"#" appear, +% ^^A but makes each one appear twice!, so later we loop through, replacing +% ^^A \verb"##" by \verb"#". % \begin{macrocode} -\def\TX@vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}% - \expandafter\TX@v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!} + % \def\TX@vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}% + % \expandafter\TX@v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@v} -% Strip the initial segment of the \verb"\meaning", including the `\verb"!"' -% added earlier. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@v} +% ^^A Strip the initial segment of the \verb"\meaning", including the `\verb"!"' +% ^^A added earlier. % \begin{macrocode} -\def\TX@v#1!{\afterassignment\TX@vfirst\let\@tempa= } + % \def\TX@v#1!{\afterassignment\TX@vfirst\let\@tempa= } % \end{macrocode} -% \end{macro} -% -% As explained above we are going to replace \verb"##" pairs by \verb"#". To do -% this we need non-special \verb"#" tokens. Make \verb"*" into a parameter -% token so that we can define macros with arguments. The normal meanings -% will be restored by the \verb"\endgroup" later. +% ^^A \end{macro} +% ^^A +% ^^A As explained above we are going to replace \verb"##" pairs by \verb"#". To do +% ^^A this we need non-special \verb"#" tokens. Make \verb"*" into a parameter +% ^^A token so that we can define macros with arguments. The normal meanings +% ^^A will be restored by the \verb"\endgroup" later. % \begin{macrocode} -\begingroup -\catcode`\*=\catcode`\# -\catcode`\#=12 + % \begingroup + % \catcode`\*=\catcode`\# + % \catcode`\#=12 % \end{macrocode} -% -% \begin{macro}{\TX@vfirst} -% As a special case, prevent the first character from being dropped. -% This makes \verb"\verb*| |" produce \verb*| |. Then call \verb"\TX@v@". -% This is slightly tricky since v1.04, as I have to ensure that an -% actual \verb"#" rather than a command \verb"\let" to \verb"#" is passed on if the -% first character is \verb"#". -% \begin{macrocode} -\gdef\TX@vfirst{% - \if\@tempa#% - \def\@tempb{\TX@v@#}% - \else - \let\@tempb\TX@v@ - \if\@tempa\space~\else\@tempa\fi - \fi - \@tempb} +% ^^A +% ^^A \begin{macro}{\TX@vfirst} +% ^^A As a special case, prevent the first character from being dropped. +% ^^A This makes \verb"\verb*| |" produce \verb*| |. Then call \verb"\TX@v@". +% ^^A This is slightly tricky since v1.04, as I have to ensure that an +% ^^A actual \verb"#" rather than a command \verb"\let" to \verb"#" is passed on if the +% ^^A first character is \verb"#". +% \begin{macrocode} + % \gdef\TX@vfirst{% + % \if\@tempa#% + % \def\@tempb{\TX@v@#}% + % \else + % \let\@tempb\TX@v@ + % \if\@tempa\space~\else\@tempa\fi + % \fi + % \@tempb} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@v@} -% Loop through the \verb"\meaning", replacing all spaces by \verb"~". If the last -% character is a space it is dropped, so that \verb"\verb*|\LaTeX|" produces -% \verb"\LaTeX" not \verb*|\LaTeX |. The rewritten tokens are then further -% processed to replace \verb"##" pairs. +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@v@} +% ^^A Loop through the \verb"\meaning", replacing all spaces by \verb"~". If the last +% ^^A character is a space it is dropped, so that \verb"\verb*|\LaTeX|" produces +% ^^A \verb"\LaTeX" not \verb*|\LaTeX |. The rewritten tokens are then further +% ^^A processed to replace \verb"##" pairs. % \begin{macrocode} -\gdef\TX@v@*1 *2{% - \TX@v@hash*1##\relax\if*2\\\else~\expandafter\TX@v@\fi*2} + % \gdef\TX@v@*1 *2{% + % \TX@v@hash*1##\relax\if*2\\\else~\expandafter\TX@v@\fi*2} % \end{macrocode} -% \end{macro} -% -% \begin{macro}{\TX@v@hash} -% The inner loop, replacing \verb"##" by \verb"#". +% ^^A \end{macro} +% ^^A +% ^^A \begin{macro}{\TX@v@hash} +% ^^A The inner loop, replacing \verb"##" by \verb"#". % \begin{macrocode} -\gdef\TX@v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX@v@hash\fi*2} + % \gdef\TX@v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX@v@hash\fi*2} % \end{macrocode} -% \end{macro} -% -% As promised, we now restore the normal meanings of \verb"#" and \verb"*". +% ^^A \end{macro} +% ^^A +% ^^A As promised, we now restore the normal meanings of \verb"#" and \verb"*". % \begin{macrocode} -\endgroup + % \endgroup % \end{macrocode} -% -% \begin{macro}{\TX@vwarn} -% Warn the user the first time this \verb"\verb" is used. +% ^^A +% ^^A \begin{macro}{\TX@vwarn} +% ^^A Warn the user the first time this \verb"\verb" is used. % \begin{macrocode} -\def\TX@vwarn{% - \@warning{\noexpand\verb may be unreliable inside tabularx}% - \global\let\TX@vwarn\@empty} + % \def\TX@vwarn{% + % \@warning{\noexpand\verb may be unreliable inside tabularx}% + % \global\let\TX@vwarn\@empty} % \end{macrocode} -% \end{macro} +% ^^A \end{macro} % \begin{macrocode} - -%%%%%%%%%% end Tabularx package code v2.11 %%%%%%%%%%%%%%%%%%%%% - - - - + % + % %%%%%%%%%% end Tabularx package code v2.11 %%%%%%%%%%%%%%%%%%%%% + % + % + % + % % \end{macrocode} -% -% At this point we had better stop anyone trying to load the several -% tabular-related packages (as effectively they are already loaded). +% ^^A +% ^^A At this point we had better stop anyone trying to load the several +% ^^A tabular-related packages (as effectively they are already loaded). % \begin{macrocode} -%%\@memfakeusepackage{array} -%%\@memfakeusepackage{dcolumn} -%%\@memfakeusepackage{delarray} -%%\@memfakeusepackage{tabularx} - + % %%\@memfakeusepackage{array} + % %%\@memfakeusepackage{dcolumn} + % %%\@memfakeusepackage{delarray} + % %%\@memfakeusepackage{tabularx} + % % \end{macrocode} -% -% +% ^^A +% ^^A % % \subsection{Fear's rules} % @@ -36060,20 +36130,28 @@ % v2.4b (2005) and c (2008) are some copyright years.} % \changes{v3.7g}{2018/03/05}{Embedded the latest version of the % \Lpack{array} package} +% \changes{v3.7h}{2018/09/06}{\Lpack{array} no longer embedded, +% required instead} % \begin{macrocode} -\EmulatedPackage{array}[2016/10/06] + % \EmulatedPackage{array}[2016/10/06] \EmulatedPackage{booktabs}[2016/05/16] \EmulatedPackage{ccaption}[2008/07/23] \EmulatedPackage{changepage}[2008/07/23] \EmulatedPackage{chngcntr}[2008/07/23] \EmulatedPackage{chngpage}[2008/07/23] \EmulatedPackage{crop} -\EmulatedPackage{dcolumn}[2008/07/23] +% \end{macrocode} +% \changes{v3.7h}{2018/09/06}{\Lpack{dcolumn} is no longer embedded, +% emulation removed. We require it instead} +% \begin{macrocode} + % \EmulatedPackage{dcolumn}[2008/07/23] % \end{macrocode} % \changes{v3.7g}{2018/03/06}{Adjusted the date for \Lpack{delarray}, % the code is the same} +% \changes{v3.7h}{2018/09/06}{\Lpack{delarray} is no longer embedded, +% emulation removed. We require it instead} % \begin{macrocode} -\EmulatedPackage{delarray}[2014/10/28] + % \EmulatedPackage{delarray}[2014/10/28] \EmulatedPackage{enumerate}[2008/07/23] \EmulatedPackage{epigraph}[2008/07/23] %%%%%\EmulatedPackage{framed}[2008/07/23] @@ -36100,8 +36178,10 @@ \EmulatedPackage{showidx}[2008/07/23] % \end{macrocode} % \changes{v3.7g}{2018/03/02}{Updated the embedded version of \Lpack{tabularx} to v2.11 2016/02/03} +% \changes{v3.7h}{2018/09/08}{\Lpack{tabularx} is no longer emulated, +% but a required package} % \begin{macrocode} -\EmulatedPackage{tabularx}[2016/02/03] + % \EmulatedPackage{tabularx}[2016/02/03] \EmulatedPackage{titleref}[2008/07/23] \EmulatedPackage{titling}[2008/07/23] \EmulatedPackage{tocbibind}[2008/07/23] -- cgit v1.2.3