summaryrefslogtreecommitdiff
path: root/macros/latex/required/tools/delarray.dtx
blob: cc503707b0dc74923fca8829d366ab536f653f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
% \iffalse meta-comment
%
% Copyright (C) 1993-2021
%
% The LaTeX Project and any individual authors listed elsewhere
% in this file.
%
% This file is part of the Standard LaTeX `Tools Bundle'.
% -------------------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%    https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% The list of all files belonging to the LaTeX `Tools Bundle' is
% given in the file `manifest.txt'.
%
% \fi
% \iffalse
%% File: delarray.dtx Copyright (C) 1991-1994 David Carlisle
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{delarray}
%<package>         [2014/10/28 v1.01 array delimiter package (DPC)]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{delarray}
\GetFileInfo{delarray.sty}
\begin{document}
\title{The \textsf{delarray} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
\author{David Carlisle}
\date{\filedate}
 \MaintainedByLaTeXTeam{tools}
 \maketitle
 \DocInput{delarray.dtx}
\end{document}
%</driver>
% \fi
%
%
% \changes{v1.00}{1992/07/06}
%    {Initial version after merging of newarray.sty to array.sty}
%
% \changes{v1.01}{1994/03/14}
%    {Update to LaTeX2e}
%
%
% \section{Examples}
%
%
% The addition to {\tt array.sty} added in {\tt delarray.sty} is
% a system of implicit |\left| |\right| pairs. If you want an array
% surrounded by parentheses, you can enter:\\
% |\begin{array}({cc})| \ldots
% \[  \begin{array}({cc})a&b\\c&d\end{array}   \]
%
% Similarly if an environment equivalent to \PlainTeX's |\cases| could
% be defined by:\\
% |\begin{array}\{{lL}.| \ldots
%
% \newcolumntype{L}{>{$}l<{$}}
% \[  f(x)=\begin{array}\{{lL}.
%           0        &if $x=0$\\
%           \sin(x)/x&otherwise
%           \end{array}  \]
% Here |L| is supposed to denote a column of left aligned L-R text. It
% may be defined via: |\newcolumntype{L}{>{$}l<{$}}|, as discussed in
% {\tt array.sty}.
% Note that as the delimiters must always be used in pairs, the  `|.|'
% must be used to denote a  `null delimiter'.
%
% This feature is especially useful if the |[t]| or |[b]|
% arguments are also used. In these cases the result is not equivalent
% to surrounding the environment by |\left|\ldots|\right|, as
% can be seen from the following example:
% \[
% \begin{array}[t]({c}) 1\\2\\3 \end{array}
% \begin{array}[c]({c}) 1\\2\\3 \end{array}
% \begin{array}[b]({c}) 1\\2\\3 \end{array}
% \quad\mbox{not}\quad
% \left(\begin{array}[t]{c} 1\\2\\3 \end{array}\right)
% \left(\begin{array}[c]{c} 1\\2\\3 \end{array}\right)
% \left(\begin{array}[b]{c} 1\\2\\3 \end{array}\right)
% \]
% \begin{verbatim}
% \begin{array}[t]({c}) 1\\2\\3 \end{array}
% \begin{array}[c]({c}) 1\\2\\3 \end{array}
% \begin{array}[b]({c}) 1\\2\\3 \end{array}
% \quad\mbox{not}\quad
% \left(\begin{array}[t]{c} 1\\2\\3 \end{array}\right)
% \left(\begin{array}[c]{c} 1\\2\\3 \end{array}\right)
% \left(\begin{array}[b]{c} 1\\2\\3 \end{array}\right)
% \end{verbatim}
%
%
% \StopEventually{}
%
% \section{The Macros}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{array}[1994/02/03]
%    \end{macrocode}
%
% \begin{macro}{\@tabarray}
%    This macro tests for an optional bracket and then calls up
%    |\@@array| or |\@@array[c]| (as default).
%    \begin{macrocode}
\def\@tabarray{\@ifnextchar[{\@@array}{\@@array[c]}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@array}
%    This macro tests for an optional delimiter before the left brace
%    of the main preamble argument. If there is no delimiter,
%    |\@arrayleft| and |\@arrayright| are made a no-ops, and
%    |\@array| is called with the positional argument. Otherwise
%    call |\@del@array|.
%    \begin{macrocode}
\def\@@array[#1]{\@ifnextchar\bgroup
  {\let\@arrayleft\relax\let\@arrayright\relax\@array[#1]}%
  {\@del@array[#1]}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@del@array}
%    We now know that we have an {\tt array} (or {\tt tabular}) with
%    delimiters.
%    \begin{macrocode}
\def\@del@array[#1]#2#3#4{%
%    \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 omitting the `.' in a
% |\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
% |\@arrayright| puts the alignment and the delimiters together.
%    \begin{macrocode}
  \setbox\z@\hbox{$\left#2\right#4$}%
%    \end{macrocode}
% In the case of a `c' argument we do not need to rebox the alignment,
% so we can define |\@arrayleft| and |\@arrayright| just to
% insert the delimiters.
%    \begin{macrocode}
  \if#1c\def\@arrayleft{\left#2}\def\@arrayright{\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.
%    \begin{macrocode}
  \else\def\@arrayleft{\setbox\z@}%
%    \end{macrocode}
% Then after the alignment is finished:
%    \begin{macrocode}
  \def\@arrayright{%
%    \end{macrocode}
% Calculate the amount the box needs to be lowered (this will be
% negative in the case of |[b]|). A little bit of arithmetic cf.\
% the \TeX{}Book, 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 |\delimitershortfall| or
% |\delimiterfactor| have non-standard values.
%    \begin{macrocode}
     \dimen@=\dp\z@
     \advance\dimen@-\ht\z@
     \divide \dimen@ by \tw@
     \advance\dimen@ by\fontdimen22 \textfont\tw@
%    \end{macrocode}
% Now lower the alignment and the delimiters into place.
%    \begin{macrocode}
     \lower\dimen@\hbox{$\left#2\vcenter{\unvbox\z@}\right#4$}}%
%    \end{macrocode}
% End the |\if#1c|
%    \begin{macrocode}
  \fi
%    \end{macrocode}
% Now that we have defined |\@arrayleft| and |\@arrayright|, call
% |\@array|.
%    \begin{macrocode}
  \@array[#1]{#3}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
%
% \subsection{newarray.sty}
% All the features of the old {\tt newarray} style option have been
% merged into the {\tt array} or {\tt delarray} options.
% \changes{v1.00}{1992/07/06}
%    {Stop generating a `shell' newarray.sty}
%
%
% \Finale
\endinput