| 1 |
% \begin{meta-comment} |
| 2 |
% |
| 3 |
% $Id: mdwtab.dtx,v 1.8 1996/12/09 23:20:42 mdw Exp $ |
| 4 |
% |
| 5 |
% Another rewrite of the tabular environment, and maths alignments |
| 6 |
% |
| 7 |
% (c) 1996 Mark Wooding |
| 8 |
% |
| 9 |
%----- Revision history ----------------------------------------------------- |
| 10 |
% |
| 11 |
% $Log: mdwtab.dtx,v $ |
| 12 |
% Revision 1.8 1996/12/09 23:20:42 mdw |
| 13 |
% (\tab@setstrut): Fixed so that it uses \dimen\tw@ for the strut depth, |
| 14 |
% as advertised. |
| 15 |
% |
| 16 |
% Revision 1.7 1996/11/29 21:59:16 mdw |
| 17 |
% Fixed a little formatting mistake in a syntax diagram, and switched over |
| 18 |
% to the new syntax diagram commands on the grounds that they're slightly |
| 19 |
% less messy. Maybe. |
| 20 |
% |
| 21 |
% Revision 1.6 1996/11/19 20:54:33 mdw |
| 22 |
% Entered into RCS |
| 23 |
% |
| 24 |
% |
| 25 |
% \end{meta-comment} |
| 26 |
% |
| 27 |
% \begin{meta-comment} <general public licence> |
| 28 |
%% |
| 29 |
%% mdwtab package -- another rewrite of the tabular environment, etc. |
| 30 |
%% Copyright (c) 1996 Mark Wooding |
| 31 |
%% |
| 32 |
%% This program is free software; you can redistribute it and/or modify |
| 33 |
%% it under the terms of the GNU General Public License as published by |
| 34 |
%% the Free Software Foundation; either version 2 of the License, or |
| 35 |
%% (at your option) any later version. |
| 36 |
%% |
| 37 |
%% This program is distributed in the hope that it will be useful, |
| 38 |
%% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 39 |
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 40 |
%% GNU General Public License for more details. |
| 41 |
%% |
| 42 |
%% You should have received a copy of the GNU General Public License |
| 43 |
%% along with this program; if not, write to the Free Software |
| 44 |
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 45 |
%% |
| 46 |
% \end{meta-comment} |
| 47 |
% |
| 48 |
% \begin{meta-comment} <Package preambles> |
| 49 |
%<+mdwtab>\NeedsTeXFormat{LaTeX2e} |
| 50 |
%<+mdwtab>\ProvidesPackage{mdwtab} |
| 51 |
%<+mdwtab> [1998/04/28 1.9 Table typesetting with style] |
| 52 |
%<+mathenv>\NeedsTeXFormat{LaTeX2e} |
| 53 |
%<+mathenv>\ProvidesPackage{mathenv} |
| 54 |
%<+mathenv> [1998/04/28 1.9 Various maths environments] |
| 55 |
% \end{meta-comment} |
| 56 |
% |
| 57 |
% \CheckSum{2758} |
| 58 |
%% \CharacterTable |
| 59 |
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 60 |
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 61 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 62 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 63 |
%% Dollar \$ Percent \% Ampersand \& |
| 64 |
%% Acute accent \' Left paren \( Right paren \) |
| 65 |
%% Asterisk \* Plus \+ Comma \, |
| 66 |
%% Minus \- Point \. Solidus \/ |
| 67 |
%% Colon \: Semicolon \; Less than \< |
| 68 |
%% Equals \= Greater than \> Question mark \? |
| 69 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 70 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 71 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 72 |
%% Right brace \} Tilde \~} |
| 73 |
%% |
| 74 |
% |
| 75 |
% \begin{meta-comment} |
| 76 |
% |
| 77 |
%<*driver> |
| 78 |
\input{mdwtools} |
| 79 |
\describespackage{mdwtab} |
| 80 |
\describespackage{mathenv} |
| 81 |
\addcontents{lot}{\listoftables} |
| 82 |
\mdwdoc |
| 83 |
%</driver> |
| 84 |
% |
| 85 |
% \end{meta-comment} |
| 86 |
% |
| 87 |
%^^A------------------------------------------------------------------------- |
| 88 |
% \renewcommand{\tabstyle}{\small} |
| 89 |
% |
| 90 |
% \section{User guide} |
| 91 |
% |
| 92 |
% |
| 93 |
% The \package{mdwtab} package contains a reimplementation of the standard |
| 94 |
% \LaTeX\ \env{tabular} and \env{array} environments. This is not just an |
| 95 |
% upgraded version: it's a complete rewrite. It has several advantages over |
| 96 |
% the official \package{array} package (not raw \LaTeX's, which is even less |
| 97 |
% nice), and it's more-or-less compatible. Most of these are rather |
| 98 |
% technical, I'll admit. |
| 99 |
% |
| 100 |
% \begin{itemize} |
| 101 |
% |
| 102 |
% \item The newcolumn system is properly and perfectly integrated into the |
| 103 |
% system. There are now \emph{no} `primitive' column types -- all the |
| 104 |
% standard types are created as user-defined columns. |
| 105 |
% |
| 106 |
% \item You can define entirely different table-like environments using the |
| 107 |
% equipment here. It's still hard work, although less so than before. |
| 108 |
% I'll do an example of this some time. |
| 109 |
% |
| 110 |
% \item Construction of the preamble is generally much tidier. I've used |
| 111 |
% token registers rather than |\edef|, and it's all done very nicely. |
| 112 |
% |
| 113 |
% \item Fine spacing before and after rules (described by DEK as `a mark of |
| 114 |
% quality') is now utterly trivial, since the preamble-generator will |
| 115 |
% store the appropriate information. |
| 116 |
% |
| 117 |
% \item You can use \env{array} in LR and paragraph modes without having |
| 118 |
% to surround it with `|$|' signs. |
| 119 |
% |
| 120 |
% \item Usually you don't want tables in the middle of paragraphs. For these |
| 121 |
% cases, I've provided a simpler way to position the table |
| 122 |
% horizontally. |
| 123 |
% |
| 124 |
% \item Footnotes work properly inside \env{tabular} environments (hoorah!). |
| 125 |
% You can `catch' footnotes using the \env{minipage} environment if |
| 126 |
% you like. (It uses an internal version of the \package{footnote} |
| 127 |
% package to handle footnotes, which doesn't provide extra goodies like |
| 128 |
% the \env{footnote} environment; you'll need to load the full package |
| 129 |
% explicitly to get them.) |
| 130 |
% |
| 131 |
% \item Standard \LaTeX\ tabular environments have a problem with lining up |
| 132 |
% ruled tables. The |\firsthline| command given in the \textit{\LaTeX\ |
| 133 |
% Companion} helps a bit, but it's not really good enough, and besides, |
| 134 |
% it doesn't \emph{actually} line the text up right after all. The |
| 135 |
% \package{mdwtab} package does the job properly to begin with, so you |
| 136 |
% don't need to worry. |
| 137 |
% |
| 138 |
% \end{itemize} |
| 139 |
% |
| 140 |
% I've tested the following packages with \package{mdwtab}, and they all |
| 141 |
% work. Some of the contortions required to make them work weren't pleasant, |
| 142 |
% but you don't need to know about them. By a strange coincidence, all the |
| 143 |
% packages were written by David Carlisle. Anyway, here's the list: |
| 144 |
% \begin{itemize} |
| 145 |
% \item The quite nice \package{dcolumn} package. |
| 146 |
% \item The more useful \package{delarray} package. |
| 147 |
% \item The rather spiffy \package{hhline} package. |
| 148 |
% \item The truly wonderful \package{tabularx} package. |
| 149 |
% \item The utterly magnificent \package{longtable} package. |
| 150 |
% \end{itemize} |
| 151 |
% |
| 152 |
% Note that I've looked at \package{supertabular} as well: it won't work, so |
| 153 |
% use \package{longtable} instead, 'cos it's much better. |
| 154 |
% |
| 155 |
% |
| 156 |
% \subsection{The downside} |
| 157 |
% |
| 158 |
% There's no such thing as a free lunch. The \package{mdwtab} environment |
| 159 |
% is not 100\% compatible with the \env{tabular} environment found in |
| 160 |
% \LaTeXe\ or the \package{array} package. |
| 161 |
% |
| 162 |
% The differences between \package{mdwtab} and \LaTeXe's \env{tabular} |
| 163 |
% environment are as follows: |
| 164 |
% |
| 165 |
% \begin{itemize} \synshorts \let\`=\lq |
| 166 |
% |
| 167 |
% \item The vertical spacing in \env{array} environments is different to |
| 168 |
% that in \env{tabular} environments. This produces more attractive |
| 169 |
% results in most mathematical uses of \env{array}s, in the author's |
| 170 |
% opinion. The spacing can be modified by playing with length |
| 171 |
% parameters. |
| 172 |
% |
| 173 |
% \item The presence of horizontal and vertical rules will alter the spacing |
| 174 |
% of the table (so a pair of columns separated by a `|' is wider than |
| 175 |
% a pair with no separation by "\\arrayrulewidth". This does mean that |
| 176 |
% horizontal and vertical rules match up properly -- the usual \LaTeX\ |
| 177 |
% environment makes the horizontal rules stop just short of the edge |
| 178 |
% of the table, making an ugly mess (check out the \textit{\LaTeX\ |
| 179 |
% book} if you don't believe me -- page~62 provides a good example). |
| 180 |
% The \package{array} package handles rules in the same way as |
| 181 |
% \package{mdwtab}. |
| 182 |
% |
| 183 |
% \setbox0=\hbox{\footnotesize`\\def\\xcs{\\tabskip=\\fill}'} |
| 184 |
% \setbox2=\hbox{\footnotesize`...@{\\span\\xcs}...'} |
| 185 |
% \item In common with the \package{array} package, there are some |
| 186 |
% restrictions on the use of the "\\extracolsep" command in preambles: |
| 187 |
% you may use at most one "\\extracolsep" command in each `@' or `!' |
| 188 |
% expression. Also, you can't say |
| 189 |
% \begin{listing} |
| 190 |
%\newcommand{\xcs}{\extracolsep{\fill}} |
| 191 |
% \end{listing} |
| 192 |
% and then expect something like `...@{\\xcs}...' to actually work -- |
| 193 |
% the "\\extracolsep" mustn't be hidden inside any other |
| 194 |
% commands. Because things like `@' expressions aren't expanded at |
| 195 |
% the time, "\\extracolsep" has to be searched and processed |
| 196 |
% \`by hand'.\footnote{^^A |
| 197 |
% All \cs{extracolsep} does is modify the \cs{tabskip} glue, so |
| 198 |
% if you were an evil \TeX\ hacker like me, you could just say |
| 199 |
% \unhbox0\ and put \unhbox2\ in your preamble. That'd work nicely. |
| 200 |
% It also works with the \package{array} package.} |
| 201 |
% |
| 202 |
% \item Control sequences (commands) in a table's preamble aren't expanded |
| 203 |
% before the preamble is read. In fact, commands in the preamble are |
| 204 |
% considered to be column types, and their names are entirely |
| 205 |
% independent of normal \LaTeX\ commands. No column types of this |
| 206 |
% nature have yet been defined\footnote{^^A |
| 207 |
% There used to be an internal \cs{@magic} type used by |
| 208 |
% \env{eqnarray}, but you're not supposed to know about that. |
| 209 |
% Besides, it's not there any more.} |
| 210 |
% but the possibility's always there. Use the "\\newcolumntype" or |
| 211 |
% "\\coldef" commands to define new column types. |
| 212 |
% |
| 213 |
% \item The preamble parsing works in a completely different way. There is |
| 214 |
% a certain amount of compatibility provided, although it's heavily |
| 215 |
% geared towards keeping \package{longtable} happy and probably won't |
| 216 |
% work with other packages. |
| 217 |
% |
| 218 |
% \item Obscure constructs which were allowed by the old preamble parser but |
| 219 |
% violate the syntax shown in the next section (e.g., `|@{}|' to |
| 220 |
% suppress the "\\doublerulesep" space between two vertical rules, |
| 221 |
% described in \textit{The \LaTeX\ Companion} as \`a misuse of the |
| 222 |
% `@{...}' qualifier') are now properly outlawed. You will be given |
| 223 |
% an error message if you attempt to use such a construction. |
| 224 |
% |
| 225 |
% \item The `*' forms (which repeat column types) are now expanded at a |
| 226 |
% different time. Previously, preambles like `c@*{4}{{:}@}{--}c' |
| 227 |
% were considered valid (the example would expand to |
| 228 |
% `c@{:}@{:}@{:}@{:}@{--}c'), because `*'s were expanded before the |
| 229 |
% preamble was actually parsed. In the new system, `*' is treated |
| 230 |
% just like any other preamble character (it just has a rather odd |
| 231 |
% action), and preambles like this will result in an error (and |
| 232 |
% probably a rather confusing one). |
| 233 |
% |
| 234 |
% \end{itemize} |
| 235 |
% |
| 236 |
% There are also several incompatibilities between \package{mdwtab} and |
| 237 |
% \package{array}: |
| 238 |
% |
| 239 |
% \begin{itemize} \synshorts \let\`=\lq |
| 240 |
% |
| 241 |
% \item Because of the way "\\newcolumntype" works in the \package{array} |
| 242 |
% package, a horrid construction like |
| 243 |
% \begin{listing} |
| 244 |
%\newcolumntype{x}{{:}} |
| 245 |
%\begin{tabular}{|c!xc|} |
| 246 |
% \end{listing} |
| 247 |
% is considered to be valid, and is interpreted as `|c!{:}c|'. My |
| 248 |
% reading of pages~54 and~55 of the \textit{\LaTeX\ book} tells me |
| 249 |
% that this sort of thing is forbidden in normal \LaTeX\ commands. |
| 250 |
% The \package{mdwtab} preamble parser now treats column type letters |
| 251 |
% much more like commands with the result that the hacking above won't |
| 252 |
% work any more. The construction above would actually be interpreted |
| 253 |
% as `|c!{x}c|' (i.e., the `x' column type wouldn't be expanded to |
| 254 |
% `{:}' because the parser noticed that it was the argument to the |
| 255 |
% `!' modifier\footnote{^^A |
| 256 |
% This is a direct result of the way \TeX\ treats undelimited |
| 257 |
% arguments. See chapters~5 and~20 of \textit{The \TeX book} for |
| 258 |
% more information about how grouping affects argument reading.}). |
| 259 |
% |
| 260 |
% \item Most of the points above, particularly those relating to the |
| 261 |
% handling of the preamble, also apply to the \package{array} package. |
| 262 |
% it's not such an advance over the \LaTeXe\ version as everyone said |
| 263 |
% it was. |
| 264 |
% |
| 265 |
% \end{itemize} |
| 266 |
% |
| 267 |
% |
| 268 |
% \subsection{Syntax} |
| 269 |
% |
| 270 |
% \DescribeEnv{tabular} |
| 271 |
% \DescribeEnv{tabular*} |
| 272 |
% \DescribeEnv{array} |
| 273 |
% So that everyone knows where I stand, here's a complete syntax for my |
| 274 |
% version of the \env{tabular} environment, and friends |
| 275 |
% |
| 276 |
% \begin{grammar} |
| 277 |
% |
| 278 |
% <tabular-env> ::= \[[ |
| 279 |
% "\\begin" |
| 280 |
% \begin{stack} |
| 281 |
% "{tabular}" \\ "{tabular*}" "{" <length> "}" \\ |
| 282 |
% "{array}" \\ "{smarray}" |
| 283 |
% \end{stack} |
| 284 |
% \[ "[" <position-arg> "]" \] |
| 285 |
% "{" <preamble> "}" <text> |
| 286 |
% "\\end" |
| 287 |
% \( "{tabular}" \\ "{tabular*}" \\ "{array}" \\ "{smarray}" \) |
| 288 |
% \]] |
| 289 |
% |
| 290 |
% <position-arg> ::= (see below) |
| 291 |
% |
| 292 |
% <preamble> ::= \[[ |
| 293 |
% <first-column> |
| 294 |
% \[ \< <column> \> \] |
| 295 |
% \]] |
| 296 |
% |
| 297 |
% <first-column> ::= \[[ \[ <rule> \] <column> \]] |
| 298 |
% |
| 299 |
% <column> ::= \[[ |
| 300 |
% \[ <spacing> \] \[ \< <user-pre-text> \> \] <column-type> |
| 301 |
% \[ \< <user-post-text> \> \] \[ <spacing> \] \[ <rule> \] |
| 302 |
% \]] |
| 303 |
% |
| 304 |
% <spacing> ::= \[[ "@" "{" <text> "}" \]] |
| 305 |
% |
| 306 |
% <user-pre-text> ::= \[[ ">" "{" <text> "}" \]] |
| 307 |
% |
| 308 |
% <column-type> ::= \[[ |
| 309 |
% \begin{stack} |
| 310 |
% \[ "T" \\ "M" \] \( "l" \\ "c" \\ "r" \) \\ |
| 311 |
% \( "p" \\ "m" \\ "b" \) "{" <length> "}" \\ |
| 312 |
% "#" "{" <raw-pre-text> "}" "{" <raw-post-text> "}" |
| 313 |
% \end{stack} |
| 314 |
% \]] |
| 315 |
% |
| 316 |
% <user-post-text> ::= \[[ "<" "{" <text> "}" \]] |
| 317 |
% |
| 318 |
% <rule> ::= \[[ \( "|" \\ "!" "{" <text> "}" \) \]] |
| 319 |
% |
| 320 |
% \end{grammar} |
| 321 |
% |
| 322 |
% If you examine the above very carefully, you'll notice a slight deviation |
| 323 |
% from the original -- an |@|-expression \emph{following} a rule is |
| 324 |
% considered to be part of the \emph{next} column, not the current one. This |
| 325 |
% is, I think, an almost insignificant change, and essential for some of the |
| 326 |
% new features. You'll also notice the new |#| column type form, which |
| 327 |
% allows you to define new real column types instead of just modifying |
| 328 |
% existing ones. It's not intended for direct use in preambles -- it's |
| 329 |
% there mainly for the benefit of people who know what they're doing and |
| 330 |
% insist on using |\newcolumntype| anyway. |
| 331 |
%% |
| 332 |
% The actual column types are shown in table~\ref{tbl:columns}. |
| 333 |
% |
| 334 |
% \begin{table} |
| 335 |
% \begin{tabular}[C]{| >{\synshorts} c | m{3in} |} \hlx{hv[1]} |
| 336 |
% |
| 337 |
% \multicolumn{2}{|c|}{\bf Column types} \\ \hlx{v[1]hv} |
| 338 |
% \bf Name & \bf Meaning \\ \hlx{vhv.} |
| 339 |
% "l" & Left aligned text (\env{tabular}) or |
| 340 |
% equation (\env{array}). \\ \hlx{.} |
| 341 |
% "c" & Centred text (\env{tabular}) or |
| 342 |
% equation (\env{array}). \\ \hlx{.} |
| 343 |
% "r" & Right aligned text (\env{tabular}) or |
| 344 |
% equation (\env{array}). \\ \hlx{vhv.} |
| 345 |
% "Ml", "Mc" and "Mr" & Left, centre and right aligned |
| 346 |
% equations.* \\ \hlx{.} |
| 347 |
% "Tl", "Tc" and "Tr" & Left, centre and right aligned |
| 348 |
% text.* \\ \hlx{vhv.} |
| 349 |
% "p{"<width>"}" & Top aligned paragraph with the given |
| 350 |
% width. \\ \hlx{.} |
| 351 |
% "m{"<width>"}" & Vertically centred paragraph with |
| 352 |
% the given width. \\ \hlx{.} |
| 353 |
% "b{"<width>"}" & Bottom aligned paragraph with the |
| 354 |
% given width. \\ \hlx{vhv.} |
| 355 |
% "#{"<pre>"}{"<post>"}" & User defined column type: |
| 356 |
% \<pre> is inserted before the |
| 357 |
% cell entry, \<post> is inserted |
| 358 |
% afterwards.* \\ \hlx{vhhv[1]} |
| 359 |
% |
| 360 |
% \multicolumn{2}{|c|}{\bf Other modifier characters} \\ \hlx{v[1]hv} |
| 361 |
% \bf Name & \bf Meaning \\ \hlx{vhv.} |
| 362 |
% "|" & Inserts a vertical rule between |
| 363 |
% columns. \\ \hlx{.} |
| 364 |
% "!{"<text>"}" & Inserts \<text> between columns, |
| 365 |
% treating it as a vertical rule. \\ \hlx{vhv.} |
| 366 |
% "@{"<text>"}" & Inserts \<text> instead of the |
| 367 |
% usual intercolumn space. \\ \hlx{vhv.} |
| 368 |
% ">{"<text>"}" & Inserts \<text> just before the |
| 369 |
% actual column entry. \\ \hlx{.} |
| 370 |
% "<{"<text>"}" & Inserts \<text> just after the |
| 371 |
% actual column entry. \\ \hlx{vhv.} |
| 372 |
% "*{"<count>"}{"<chars>"}" & Inserts \<count> |
| 373 |
% copies of the \<chars> into the |
| 374 |
% preamble. \\ \hlx{vhs} |
| 375 |
% |
| 376 |
% \multicolumn{2}{@{}l}{* This column type is a new feature} |
| 377 |
% \end{tabular} |
| 378 |
% |
| 379 |
% \caption{\package{array} and \package{tabular} column types and modifiers} |
| 380 |
% \label{tbl:columns} |
| 381 |
% \end{table} |
| 382 |
% |
| 383 |
% Now that's sorted everything out, there shouldn't be any arguments at all |
| 384 |
% about what a column means. |
| 385 |
% |
| 386 |
% The lowercase \<position-arg>s \lit{t}, \lit{c} and \lit{b} do exactly |
| 387 |
% what they did before: control the vertical positioning of the table. The |
| 388 |
% uppercase ones control the \emph{horizontal} positioning -- this is how you |
| 389 |
% create \emph{unboxed} tables. You can only create unboxed tables in |
| 390 |
% paragraph mode. |
| 391 |
% |
| 392 |
% Note that unboxed tables still can't be broken across pages. Use |
| 393 |
% the \package{longtable} package for this, because it already does an |
| 394 |
% excellent job. |
| 395 |
% |
| 396 |
% \DescribeMacro{\tabpause} |
| 397 |
% One thing you can to with unboxed tables, however, is to `interrupt' them, |
| 398 |
% do some normal typesetting, and then continue. This is achieved by the |
| 399 |
% |\tabpause| command: its argument is written out in paragraph mode, and |
| 400 |
% the table is continued after the argument finishes. |
| 401 |
% Note that it isn't a real argument as far as commands like |\verb| are |
| 402 |
% concerned -- they'll work inside |\tabpause| without any problems. |
| 403 |
% |
| 404 |
% \DescribeMacro{\vline} |
| 405 |
% The |\vline| command draws a vertical rule the height of the current table |
| 406 |
% cell (unless the current cell is being typeset in paragraph mode -- it |
| 407 |
% only works in the simple LR-mode table cells, or in \lit{@} or \lit{!} |
| 408 |
% modifiers). It's now been given an optional argument which gives the |
| 409 |
% width of the rule to draw: |
| 410 |
% |
| 411 |
% { \let\tabstyle=\relax |
| 412 |
% \begin{demo}{An example of \cmd\vline} |
| 413 |
%\large |
| 414 |
%\begin{tabular} |
| 415 |
% {| c !{\vline[2pt]} c | c |} |
| 416 |
% \hlx{hv} |
| 417 |
% \bf A & \it B & \sf C \\ |
| 418 |
% \hlx{vhv} |
| 419 |
% \bf D & \it E & \sf F \\ |
| 420 |
% \hlx{vh} |
| 421 |
%\end{tabular} |
| 422 |
% \end{demo} |
| 423 |
% } |
| 424 |
% |
| 425 |
% \DescribeMacro{smarray} |
| 426 |
% You've probably noticed that there's an unfamiliar environment mentioned |
| 427 |
% in the syntax shown above. The \env{smarray} environment produces a |
| 428 |
% `small' array, with script size cells rather than the normal full text |
| 429 |
% size cells. I've seen examples of this sort of construction\footnote{^^A |
| 430 |
% There's a nasty use of \env{smallmatrix} in the |testmath.tex| file which |
| 431 |
% comes with the \package{amslatex} distribution. It's actually there to |
| 432 |
% simulate a `smallcases' environment, which the \package{mathenv} package |
| 433 |
% includes, based around \env{smarray}.} |
| 434 |
% being implemented by totally unsuitable commands. Someone may find it |
| 435 |
% handy. |
| 436 |
% |
| 437 |
% |
| 438 |
% \subsection{An updated \cs{cline} command} |
| 439 |
% |
| 440 |
% \DescribeMacro{\cline} |
| 441 |
% The standard \LaTeX\ |\cline| command has been updated. As well as just |
| 442 |
% passing a range of columns to draw lines through, you can now pass a comma |
| 443 |
% separated list of column numbers and ranges: |
| 444 |
% |
| 445 |
% \begin{grammar} |
| 446 |
% <cline-cmd> ::= \[[ |
| 447 |
% "\\cline" "{" \< <number> \[ "-" <number> \] \\ "," \> "}" |
| 448 |
% \]] |
| 449 |
% \end{grammar} |
| 450 |
% |
| 451 |
% The positioning of the horizontal lines has also been improved a bit, so |
| 452 |
% that they meet up with the vertical lines properly. Displays like the one |
| 453 |
% in the example below don't look good unless this has been done properly. |
| 454 |
% |
| 455 |
% {\let\tabstyle\relax |
| 456 |
% \begin{demo}[w]{A \cs{cline} example} |
| 457 |
%\newcommand{\mc}{\multicolumn{1}} |
| 458 |
%\begin{tabular}[C]{|c|c|c|c|} \cline{2,4} |
| 459 |
% \mc{c|}{one} & two & three & four \\ \hline |
| 460 |
% five & six & seven & \mc{c}{eight} \\ \cline{1,3} |
| 461 |
%\end{tabular} |
| 462 |
% \end{demo} |
| 463 |
% } |
| 464 |
% |
| 465 |
% \subsection{Spacing control} |
| 466 |
% |
| 467 |
% One of the most irritating things about \LaTeX's tables is that there isn't |
| 468 |
% enough space around horizontal rules. Donald Knuth, in \textit{The |
| 469 |
% \TeX book}, describes addition of some extra vertical space here as `a mark |
| 470 |
% of quality', and since \TeX\ was designed to produce `beautiful documents' |
| 471 |
% it seems a shame that \LaTeX\ doesn't allow this to be done nicely. Well, |
| 472 |
% it does now. |
| 473 |
% |
| 474 |
% \DescribeMacro{\vgap} |
| 475 |
% The extra vertical space is added using a command |\vgap|, with the |
| 476 |
% following syntax: |
| 477 |
% |
| 478 |
% \begin{grammar} |
| 479 |
% |
| 480 |
% <vgap-cmd> ::= \[[ |
| 481 |
% "\\vgap" \[ "[" <which-cols> "]" \] "{" <length> "}" |
| 482 |
% \]] |
| 483 |
% |
| 484 |
% <which-cols> ::= \[[ \< <number> \[ "-" <number> \] \\ "," \> \]] |
| 485 |
% |
| 486 |
% \end{grammar} |
| 487 |
% |
| 488 |
% This command must appear either immediately after the beginning of the |
| 489 |
% table or immediately after the |\\| which ends a row. (Actually, there are |
| 490 |
% other commands which also have this requirement -- you can specify a |
| 491 |
% collection of them wherever you're allowed to give any one.) It adds some |
| 492 |
% vertical space (the amount is given by the \<length>) to the table, |
| 493 |
% making sure that the vertical rules of the table are extended correctly. |
| 494 |
% |
| 495 |
% The |\vgap| command relies on information stored while your table preamble |
| 496 |
% is being examined. However, it's possible that you might not want some |
| 497 |
% of the rules drawn (e.g., if you've used |\multicolumn|). The optional |
| 498 |
% \<which-cols> argument allows you to specify which rules are \emph{not} |
| 499 |
% to be drawn. You can specify either single column numbers or ranges. The |
| 500 |
% rule at the very left hand side is given the number~0; the rules at the |
| 501 |
% end of column~$n$ are numbered~$n$. It's easy really. |
| 502 |
% |
| 503 |
% \DescribeMacro{\hlx} |
| 504 |
% Using |\vgap| is all very well, but it's a bit cumbersome, and takes up a |
| 505 |
% lot of typing, especially when combined with |\hline| commands. The |\hlx| |
| 506 |
% command tries to tidy things. |
| 507 |
% |
| 508 |
% The syntax is simple: |
| 509 |
% \begin{grammar} |
| 510 |
% |
| 511 |
% <hlx-cmd> ::= \[[ |
| 512 |
% "\\hlx" "{" |
| 513 |
% \begin{rep} |
| 514 |
% \begin{stack} |
| 515 |
% "h" \\ |
| 516 |
% \tok{"v["<which-cols>"]["<length>"]"} \\ |
| 517 |
% \tok{"s["<length>"]"} \\ |
| 518 |
% \tok{"c{"<which-cols>"}"} \\ |
| 519 |
% "b" \\ |
| 520 |
% \tok{"/["<number>"]"} \\ |
| 521 |
% "." |
| 522 |
% \end{stack} |
| 523 |
% \end{rep} |
| 524 |
% "}" |
| 525 |
% \]] |
| 526 |
% |
| 527 |
% \end{grammar} |
| 528 |
% The argument works a bit like a table preamble, really. Each letter is a |
| 529 |
% command. The following are supported: |
| 530 |
% |
| 531 |
% \begin{description} |
| 532 |
% |
| 533 |
% \item [\lit*{h}] Works just like |\hline|. If you put two adjacent to each |
| 534 |
% other, a gap will be put between them. |
| 535 |
% |
| 536 |
% \item [\lit*{v[}\<which-cols>\lit*{][}\<length>\lit*{]}] Works |
| 537 |
% like \syntax{"\\vgap["<which-cols>"]{"<length>"}"}. If the |
| 538 |
% \<length> is omitted, the value of |\doublerulesep| is used. |
| 539 |
% This usually looks right. |
| 540 |
% |
| 541 |
% \item [\lit*{s[}\<length>\lit*{]}] Leaves a vertical gap with the |
| 542 |
% given size. If you omit the \<length> then |\doublerulesep| is |
| 543 |
% used. This is usually right. |
| 544 |
% |
| 545 |
% \item [\lit*{c\char`\{}\<which-cols>\lit*{\char`\}}] Works just like |
| 546 |
% |\cline|. |
| 547 |
% |
| 548 |
% \item [\lit*{b}] Inserts a backspace the width of a rule. This is useful |
| 549 |
% when doing \package{longtable}s. |
| 550 |
% |
| 551 |
% \item [\lit*{/[}\<number>\lit*{]}] Allows a page break in a table. Don't |
| 552 |
% use this except in a \env{longtable} environment. The \<number> |
| 553 |
% works exactly the same as it does in the |\pagebreak| command, |
| 554 |
% except that the default is 0, which just permits a break without |
| 555 |
% forcing it. |
| 556 |
% |
| 557 |
% \item [\lit*{.}] (That's a dot) Starts the next row of the table. No |
| 558 |
% more characters may follow the dot, and no |\hline|, |\hlx|, |\vgap| |
| 559 |
% or |\multicolumn| commands may be used after it. You don't have to |
| 560 |
% include it, and most of the time it's totally useless. It can be |
| 561 |
% handy for some macros, though. I used it in (and in fact added it |
| 562 |
% especially for) the table of column types. |
| 563 |
% |
| 564 |
% \end{description} |
| 565 |
% |
| 566 |
% An example of the use of |\hlx| is given, so you can see what's going on. |
| 567 |
% |
| 568 |
% \begin{figure} |
| 569 |
% \let\tabstyle\relax |
| 570 |
% \begin{demo}[w]{Beautiful table example} |
| 571 |
%\newcommand{\zerowidth}[1]{\hbox to 0pt{\hss#1\hss}} |
| 572 |
%\setlength{\tabcolsep}{1.5em} |
| 573 |
%\begin{tabular}[C]{| r | c | r |} \hlx{hv[1,2]} |
| 574 |
% \multicolumn{3}{|c|}{\bf AT\&T Common Stock} \\ \hlx{v[1,2]hv} |
| 575 |
% \multicolumn{1}{|c|}{\zerowidth{\bf Year}} & |
| 576 |
% \multicolumn{1}{c|}{\zerowidth{\bf Price}} & |
| 577 |
% \multicolumn{1}{c|}{\zerowidth{\bf Dividend}} \\ \hlx{vhv} |
| 578 |
% 1971 & 41--54 & \$2.60 \\ |
| 579 |
% 2 & 41--54 & 2.70 \\ |
| 580 |
% 3 & 46--55 & 2.87 \\ |
| 581 |
% 4 & 40--53 & 3.24 \\ |
| 582 |
% 5 & 45--52 & 3.40 \\ |
| 583 |
% 6 & 51--59 & .95\rlap{*} \\ \hlx{vhs} |
| 584 |
% \multicolumn{3}{@{}l}{* (first quarter only)} |
| 585 |
%\end{tabular} |
| 586 |
% \end{demo} |
| 587 |
% \end{figure} |
| 588 |
% |
| 589 |
% |
| 590 |
% \subsection{Creating beautiful long tables} |
| 591 |
% |
| 592 |
% You can use the |\vgap| and |\hlx| commands with David Carlisle's |
| 593 |
% stunning \package{longtable} package. However, there are some things you |
| 594 |
% should be away of to ensure that your tables always come out looking |
| 595 |
% lovely. |
| 596 |
% |
| 597 |
% The \package{longtable} package will break a table at an |\hline| command, |
| 598 |
% leaving a rule at the bottom of the page and another at the top of the |
| 599 |
% next page. This means that a constructions like |\hlx{vhv}| will be |
| 600 |
% broken into something like |\hlx{vh}| at the bottom of the page and |
| 601 |
% |\hlx{hv}| at the top of the next. You need to design the table headers |
| 602 |
% and footers with this in mind. |
| 603 |
% |
| 604 |
% However, there appears to be a slight problem:\footnote |
| 605 |
% {You might very well call it a bug. I couldn't possibly comment.} |
| 606 |
% if the footer starts with an |\hline|, and a page is broken at an |\hline|, |
| 607 |
% then you get an extra thick rule at the bottom of the page. This is a bit |
| 608 |
% of a problem, because if the rule isn't there in the footer and you get |
| 609 |
% a break between two rows \emph{without} a rule between them, then the page |
| 610 |
% looks very odd. |
| 611 |
% |
| 612 |
% If you want to do ruled longtables, I'd recommend that you proceed as |
| 613 |
% follows: |
| 614 |
% \begin{itemize} |
| 615 |
% \item End header sections with an |\hlx{vh}|. |
| 616 |
% \item Begin footer sections with an |\hlx{bh}|. |
| 617 |
% \item Begin the main table with |\hlx{v}|. |
| 618 |
% \item Insert |\hlx{vhv}| commands in the main table body as usual. |
| 619 |
% \end{itemize} |
| 620 |
% If \package{longtable} gets modified appropriately, the use of the \lit{b} |
| 621 |
% command won't be necessary. |
| 622 |
% |
| 623 |
% Here's an example of the sort of thing you'd type. |
| 624 |
% |
| 625 |
% \begin{listinglist} \listingsize |
| 626 |
% \verb"\begin{longtable}[c]{|c|l|} \hlx{hv}" \\ |
| 627 |
% \verb"\bf Heading & \bf Also heading \\ \hlx{vh}" \\ |
| 628 |
% \verb"\endhead" \\ |
| 629 |
% \verb"\hlx{bh}" \\ |
| 630 |
% \verb"\endfoot" \\ |
| 631 |
% \verb"\hlx{v}" \\ |
| 632 |
% \verb"First main & table line \\ \hlx{vhv}" \\ |
| 633 |
% \verb"Lots of text & like this \\ \hlx{vhv}" \\ |
| 634 |
% \null\quad\vdots \\ |
| 635 |
% \verb"Lots of text & like this \\ \hlx{vhv}" \\ |
| 636 |
% \verb"Last main & table line \\ \hlx{vh}" \\ |
| 637 |
% \verb"\end{longtable}" |
| 638 |
% \end{listinglist} |
| 639 |
% |
| 640 |
% |
| 641 |
% \subsection{Rules and vertical positioning} |
| 642 |
% |
| 643 |
% In the \LaTeXe\ and \package{array.sty} versions of \env{tabular}, you run |
| 644 |
% into problems if you try to use ruled tables together with the \lit{[t]} or |
| 645 |
% \lit{[b]} position specifiers -- the top or bottom rule ends up being |
| 646 |
% nicely lined up with the text baseline, giving you an effect which is |
| 647 |
% nothing like the one you expected. The \textit{\LaTeX\ Companion} gives |
| 648 |
% two commands |\firsthline| and |\lasthline| which are supposed to help with |
| 649 |
% this problem. (These commands have since migrated into the \package{array} |
| 650 |
% package.) Unfortunately, |\firsthline| doesn't do its job properly -- |
| 651 |
% it gets the text position wrong by exactly the width of the table rules. |
| 652 |
% |
| 653 |
% The \package{mdwtab} package makes all of this automatic. It gets the |
| 654 |
% baseline positions exactly right, whether or not you use rules. Earlier |
| 655 |
% versions of this package required that you play with a length parameter |
| 656 |
% called |\rulefudge|; this is no longer necessary (or even possible -- the |
| 657 |
% length parameter no longer exists). The package now correctly compensates |
| 658 |
% for all sorts of rules and |\vgap|s at the top and bottom of a table and |
| 659 |
% it gets the positioning right all by itself. You've never had it so good. |
| 660 |
% |
| 661 |
% |
| 662 |
% \subsection{User serviceable parts} |
| 663 |
% |
| 664 |
% There are a lot of parameters which you can modify in order to make arrays |
| 665 |
% and tables look nicer. They are all listed in table~\ref{tbl:config}. |
| 666 |
% |
| 667 |
% \begin{table} |
| 668 |
% \begin{tabular}[C]{| l | m{3in} |} \hlx{hv} |
| 669 |
% \bf Parameter & \bf Meaning \\ \hlx{vhv} |
| 670 |
% |\tabstyle| & A command executed at the beginning of |
| 671 |
% a \env{tabular} or \env{tabular$*$} |
| 672 |
% environment. By default does nothing. |
| 673 |
% Change using |\renewcommand|. \\ \hlx{vhv} |
| 674 |
% |\extrarowheight| & A length added to the height of every |
| 675 |
% row, used to stop table rules |
| 676 |
% overprinting ascenders. Default 0\,pt. |
| 677 |
% Usage is deprecated now: use |\hlx| |
| 678 |
% instead. \\ \hlx{vhv} |
| 679 |
% |\tabextrasep| & Extra space added between rows in a |
| 680 |
% \env{tabular} or \env{tabular$*$} |
| 681 |
% environment (added \emph{before} any |
| 682 |
% following |\hline|). Default 0\,pt. \\ |
| 683 |
% |\arrayextrasep| & Analogous to |\tabextrasep|, but for |
| 684 |
% \env{array} environments. Default |
| 685 |
% 1\,jot (3\,pt). \\ |
| 686 |
% |\smarrayextrasep| & Analogous to |\tabextrasep|, but for |
| 687 |
% \env{smarray} environments. Default |
| 688 |
% 1\,pt. \\ \hlx{vhv} |
| 689 |
% |\tabcolsep| & Space added by default on each side of |
| 690 |
% a table cell (unless suppressed by an |
| 691 |
% \lit{@}-expression) in \env{tabular} |
| 692 |
% environments. Default is defined by |
| 693 |
% your document class. \\ |
| 694 |
% |\arraycolsep| & Analogous to |\tabcolsep|, but for |
| 695 |
% \env{array} environments. Default is |
| 696 |
% defined by your document class. \\ |
| 697 |
% |\smarraycolsep| & Analogous to |\tabcolsep|, but for |
| 698 |
% \env{smarray} environments. Default |
| 699 |
% is 3\,pt. \\ \hlx{vhv} |
| 700 |
% |\arrayrulewidth| & The width of horizontal and vertical |
| 701 |
% rules in tables. \\ |
| 702 |
% |\doublerulesep| & Space added between two adjacent |
| 703 |
% vertical or horizontal rules. Also |
| 704 |
% used by |\hlx{v}|. \\ \hlx{vhv} |
| 705 |
% |\arraystretch| & Command containing a factor to |
| 706 |
% multiply the default row height. |
| 707 |
% Default is defined by your document |
| 708 |
% class (usually 1). \\ \hlx{vh} |
| 709 |
% \end{tabular} |
| 710 |
% |
| 711 |
% \caption{Parameters for configuring table environments} |
| 712 |
% \label{tbl:config} |
| 713 |
% |
| 714 |
% \end{table} |
| 715 |
% |
| 716 |
% |
| 717 |
% \subsection{Defining column types} |
| 718 |
% |
| 719 |
% \DescribeMacro{\newcolumntype} |
| 720 |
% The easy way to define new column types is using |\newcolumntype|. It |
| 721 |
% works in more or less the same way as |\newcommand|: |
| 722 |
% |
| 723 |
% \begin{grammar} |
| 724 |
% |
| 725 |
% <new-col-type-cmd> ::= \[[ |
| 726 |
% "\\newcolumntype" |
| 727 |
% "{" <column-name> "}" |
| 728 |
% \[ "[" <num-args> "]" \] |
| 729 |
% \[ "[" <default-arg> "]" \] |
| 730 |
% "{" <first-column> \[ \< <column> \> \] "}" |
| 731 |
% \]] |
| 732 |
% |
| 733 |
% \end{grammar} |
| 734 |
% |
| 735 |
% (The \env{array.sty} implementation doesn't accept the \<default-arg> |
| 736 |
% argument. I've no idea why not, 'cos it was very easy to implement.) |
| 737 |
% |
| 738 |
% \DescribeMacro{\colset} |
| 739 |
% This implementation allows you to define lots of different sets of columns. |
| 740 |
% You can change the current set using the |\colset| declaration: |
| 741 |
% \begin{grammar} |
| 742 |
% <colset-cmd> ::= \[[ "\\colset" "{" <set-name> "}" \]] |
| 743 |
% \end{grammar} |
| 744 |
% This leaves a problem, though: at any particular moment, the current |
| 745 |
% column set could be anything, since other macros and packages can change |
| 746 |
% it. |
| 747 |
% |
| 748 |
% \DescribeMacro{\colpush} |
| 749 |
% \DescribeMacro{\colpop} |
| 750 |
% What actually happens is that a stack of column sets is maintained. The |
| 751 |
% |\colset| command just replaces the item at the top of the stack. The |
| 752 |
% command |\colpush| pushes its argument onto the top of the stack, making |
| 753 |
% it the new current set. The corresponding |\colpop| macro (which doesn't |
| 754 |
% take any arguments) removes the top item from the stack, reinstating the |
| 755 |
% previous current column set. |
| 756 |
% |
| 757 |
% \begin{grammar} |
| 758 |
% <colpush-cmd> ::= \[[ "\\colpush" "{" <set-name> "}" \]] |
| 759 |
% <colpop-cmd> ::= \[[ "\\colpop" \]] |
| 760 |
% \end{grammar} |
| 761 |
% |
| 762 |
% The macros which manipulate the column set stack work \emph{locally}. |
| 763 |
% The contents of the stack are saved when you open a new group. |
| 764 |
% |
| 765 |
% To make sure everyone behaves themselves properly, these are the rules for |
| 766 |
% using the column set stack: |
| 767 |
% |
| 768 |
% \begin{itemize} |
| 769 |
% |
| 770 |
% \item Packages defining column types must ensure that they preserve the |
| 771 |
% current column set. Either they must push their own column type |
| 772 |
% and pop it off when they're finished defining columns, or they must |
| 773 |
% avoid changing the stack at all, and use the optional arguments to |
| 774 |
% |\coldef| and |\collet|. |
| 775 |
% |
| 776 |
% \item Packages must not assume that any particular column set is current |
| 777 |
% unless they have made sure of it themselves. |
| 778 |
% |
| 779 |
% \item Packages must ensure that they pop exactly as much as they push. |
| 780 |
% There isn't much policing of this (perhaps there should be more), |
| 781 |
% so authors are encouraged to behave responsibly. |
| 782 |
% |
| 783 |
% \item Packages must change the current column set (using |\colset|) when |
| 784 |
% they start up their table environment. This will be restored when |
| 785 |
% the environment closes. |
| 786 |
% |
| 787 |
% \end{itemize} |
| 788 |
% |
| 789 |
% \DescribeMacro{\coldef} |
| 790 |
% |\newcolumntype| is probably enough for most purposes. However, Real |
| 791 |
% \TeX nicians, and people writing new table-generating environments, require |
| 792 |
% something lower-level. |
| 793 |
% |
| 794 |
% \begin{grammar} |
| 795 |
% <coldef-cmd> ::= \[[ |
| 796 |
% "\\coldef" |
| 797 |
% \[ "[" <set-name> "]" \] |
| 798 |
% <col-name> <arg-template> "{" <replacement-text> "}" |
| 799 |
% \]] |
| 800 |
% \end{grammar} |
| 801 |
% |
| 802 |
% Note that this defines a column type in the current colset. It works |
| 803 |
% almost exactly the same way as \TeX's primitive |\def|. There is a |
| 804 |
% potential gotcha here: a |\tab@mkpream| token is inserted at the end of |
| 805 |
% your replacement text. If you need to read an optional argument or |
| 806 |
% something, you'll need to gobble this token before you carry on. The |
| 807 |
% |\@firstoftwo| macro could be handy here: |
| 808 |
% \begin{listing} |
| 809 |
%\coldef x{\@firstoftwo{\@ifnextchar[\@xcolumn@i\@xcolumn@ii}}} |
| 810 |
% \end{listing} |
| 811 |
% This isn't a terribly pretty state of affairs, and I ought to do something |
| 812 |
% about it. I've not seen any use for an optional argument yet, though. |
| 813 |
% Note that if you do gobble the |\tab@mkpream|, it's your responsibility to |
| 814 |
% insert another one at the very end of your macro's expansion (so that |
| 815 |
% further preamble characters can be read). |
| 816 |
% |
| 817 |
% The replacement text is inserted directly. It's normal to insert preamble |
| 818 |
% elements here. There are several to choose from: |
| 819 |
% |
| 820 |
% \begin{description} |
| 821 |
% |
| 822 |
% \item [Column items] provide the main `meat' of a column. You insert a |
| 823 |
% column element by saying |
| 824 |
% \syntax{"\\tabcoltype{"<pre-text>"}{"<post-text>"}"}. |
| 825 |
% The user's text gets inserted between these two. (So do user pre- |
| 826 |
% and post-texts. Bear this in mind.) |
| 827 |
% |
| 828 |
% \item [User pre-text items] work like the \lit{>} preamble command. You |
| 829 |
% use the \syntax{"\\tabuserpretype{"<text>"}"} command to insert it. |
| 830 |
% User pre-texts are written in \emph{reverse} order between the |
| 831 |
% pre-text of the column item and the text from the table cell. |
| 832 |
% |
| 833 |
% \item [User post-text items] work like the \lit{<} preamble command. You |
| 834 |
% use the \syntax{"\\tabuserposttype{"<text>"}"} command to insert it. |
| 835 |
% Like user pre-texts, user post-texts are written in reverse order, |
| 836 |
% between the table cell text and the column item post-text. |
| 837 |
% |
| 838 |
% \item [Space items] work like the \lit{@} preamble command. They're |
| 839 |
% inserted with the \syntax{"\\tabspctype{"<text>"}"} command. |
| 840 |
% |
| 841 |
% \item [Rule items] work like the `\verb"|"' and \lit{!} commands. You |
| 842 |
% insert them with the \syntax{"\\tabruletype{"<text>"}"} command. |
| 843 |
% Note that the text is inserted by |\vgap| too, so it should contain |
| 844 |
% things which adjust their vertical size nicely. If you really need |
| 845 |
% to, you can test |\iftab@vgap| to see if you're in a |\vgap|. |
| 846 |
% |
| 847 |
% \end{description} |
| 848 |
% |
| 849 |
% \DescribeMacro{\collet} |
| 850 |
% As well as defining columns, you can copy definitions (rather like |\let| |
| 851 |
% allows you to copy macros). The syntax is like this: |
| 852 |
% |
| 853 |
% \begin{grammar} |
| 854 |
% |
| 855 |
% <collet-cmd> ::= \[[ |
| 856 |
% \[ "[" <set-name> "]" \] <col-name> \[ "=" \] \[ "[" <set-name> "]" \] |
| 857 |
% <col-name> |
| 858 |
% \]] |
| 859 |
% |
| 860 |
% \end{grammar} |
| 861 |
% |
| 862 |
% (In other words, you can copy defintions from other column sets.) |
| 863 |
% |
| 864 |
% |
| 865 |
% \subsection{Defining new table-generating environments} |
| 866 |
% |
| 867 |
% Quite a few routines are provided specifically to help you to define new |
| 868 |
% environments which do alignment in a nice way. |
| 869 |
% |
| 870 |
% \subsubsection{Reading preambles} |
| 871 |
% |
| 872 |
% The main tricky bit in doing table-like environments is parsing preambles. |
| 873 |
% No longer. |
| 874 |
% |
| 875 |
% \DescribeMacro{\tab@readpreamble} |
| 876 |
% \DescribeMacro{\tab@doreadpream} |
| 877 |
% The main parser routine is called |\tab@doreadpream|. Given a user |
| 878 |
% preamble string as an argument, it will build an |\halign| preamble to |
| 879 |
% return to you. However, the preamble produced won't be complete. This is |
| 880 |
% because you can actually make multiple calls to |\tab@doreadpream| with |
| 881 |
% bits of user preambles. The |\newcolumntype| system uses this mechanism, |
| 882 |
% as does the \lit{*} (repeating) modifier. When there really is no more |
| 883 |
% preamble to read, you need to \emph{commit} the heldover tokens to the |
| 884 |
% output. The |\tab@readpreamble| routine will do this for you -- given a |
| 885 |
% user preamble, it builds a complete output from it. |
| 886 |
% |
| 887 |
% A token register |\tab@preamble| is used to store the generated preamble. |
| 888 |
% Before starting, you must iniitialise this token list to whatever you want. |
| 889 |
% There's another token register, |\tab@shortline|, which is used to store |
| 890 |
% tokens used by |\vgap|. For each column in the table, the list contains |
| 891 |
% an |\omit| (to override the standard preamble) and an |\hfil| space taking |
| 892 |
% up most of the column. Finally, for each rule item in the user preamble, |
| 893 |
% the shortline list contains an entry of the form: |
| 894 |
% \begin{quote} \synshorts |
| 895 |
% "\\tab@ckr{"<column-number>"}{"<rule-text>"}" |
| 896 |
% \end{quote} |
| 897 |
% This is used to decide whether to print the rule or an empty thing of the |
| 898 |
% same width. You probably ought to know that the very first column does |
| 899 |
% \emph{not} have a leading |\omit| -- this is supplied by |\vgap| so that |
| 900 |
% it can then look for optional arguments. |
| 901 |
% |
| 902 |
% \DescribeMacro{\tab@initread} |
| 903 |
% As well as initialising |\tab@preamble| and emptying |\tab@shortline|, |
| 904 |
% there are several other operations required to initialise a preamble read. |
| 905 |
% These are all performed by the |\tab@initread| macro, although you may want |
| 906 |
% to change some of the values for your specific application. For reference, |
| 907 |
% the actions performed are: |
| 908 |
% \begin{itemize} |
| 909 |
% \item initialising the parser state by setting $|\tab@state| = |
| 910 |
% |\tab@startstate|$; |
| 911 |
% \item clearing the token lists |\tab@preamble| and |\tab@shortlist|; |
| 912 |
% \item initialising the macros |\tab@tabtext|, |\tab@midtext|, and |
| 913 |
% |\tab@multicol| to their default values of `|&|', |
| 914 |
% `|\ignorespaces#\unskip|' and the empty token list respectively.^^A |
| 915 |
% \footnote{^^A |
| 916 |
% These are macros rather than token lists to avoid hogging all |
| 917 |
% the token list registers. Actually, the package only allocates |
| 918 |
% two, although it does use almost all of the temporary registers as |
| 919 |
% well. Also, there's a lie: \cs{unskip} is too hamfisted to remove |
| 920 |
% trailing spaces properly; I really use a macro called |
| 921 |
% \cs{@maybe@unskip}} |
| 922 |
% \item clearing the internal token list registers |\tab@pretext|, |
| 923 |
% |tab@userpretext| and |\tab@posttext|; |
| 924 |
% \item clearing the column counter |\tab@columns| to zero; |
| 925 |
% \item clearing the action performed when a new column is started (by making |
| 926 |
% the |\tab@looped| macro equal to |\relax|; this is used to make |
| 927 |
% |\multicolumn| macro raise an error if you try to do more than one |
| 928 |
% column); and |
| 929 |
% \item setting up some other switches used by the parser (|\iftab@rule|, |
| 930 |
% |\iftab@initrule| and |\iftab@firstcol|, all of which are set to be |
| 931 |
% |true|). |
| 932 |
% \end{itemize} |
| 933 |
% |
| 934 |
% The macro |\tab@multicol| is used by the |\multicolumn| command to insert |
| 935 |
% any necessary items (e.g., struts) before the actual column text. If you |
| 936 |
% set this to something non-empty, you should probably consider adding a |
| 937 |
% call to the macro to the beginning of |\tab@preamble|. |
| 938 |
% |
| 939 |
% When parsing is finally done, the count register |\tab@columns| contains |
| 940 |
% the number of columns in the alignment. Don't corrupt this value, because |
| 941 |
% it's used for handling |\hline| commands. |
| 942 |
% |
| 943 |
% \subsubsection{Starting new lines} |
| 944 |
% |
| 945 |
% The other messy bit required by table environments is the newline command |
| 946 |
% |\\|. There are nasty complications involved with starting new lines, some |
| 947 |
% of which can be handled by this package, and some on which I can only give |
| 948 |
% advice. |
| 949 |
% |
| 950 |
% \DescribeMacro{\tab@cr} |
| 951 |
% The optional arguments and star-forms etc. can be read fairly painlessly |
| 952 |
% using the |\tab@cr| command: |
| 953 |
% |
| 954 |
% \begin{grammar} |
| 955 |
% <tabcr-cmd> ::= \[[ |
| 956 |
% "\\tab@cr" <command> "{" <non-star-text> "}" "{" <star-text> "}" |
| 957 |
% \]] |
| 958 |
% \end{grammar} |
| 959 |
% |
| 960 |
% This will call your \<command> with two arguments. The first is the |
| 961 |
% contents of the optional argument, or `|\z@|' if there wasn't one. The |
| 962 |
% second is either \<star-text> or \<non-star-text> depending on |
| 963 |
% whether the user wrote the $*$-form or not. |
| 964 |
% |
| 965 |
% Somewhere in your \<command>, you'll have to use the |\cr| primitive to |
| 966 |
% end the table row. After you've done this, you \emph{must} ensure that you |
| 967 |
% don't do anything that gets past \TeX's mouth without protecting it -- |
| 968 |
% otherwise |\hline| and co.\ won't work. I usually wrap things up in a |
| 969 |
% |\noalign| to protect them, although there are other methods. Maybe. |
| 970 |
% |
| 971 |
% You might like to have a look at the \env{eqnarray} implementation provided |
| 972 |
% to see how all this gets put into practice. |
| 973 |
% |
| 974 |
% |
| 975 |
% \subsection{The \env{mathenv} package alignment environments} |
| 976 |
% |
| 977 |
% The \env{mathenv} package provides several environments for aligning |
| 978 |
% equations in various ways. They're mainly provided as a demonstration of |
| 979 |
% the table handling macros in \package{mdwtab}, so don't expect great |
| 980 |
% things. If you want truly beautiful mathematics, use |
| 981 |
% \package{amsmath}.\footnote{^^A |
| 982 |
% Particularly since nice commands like \cmd\over\ are being reactivated |
| 983 |
% in a later release of \package{amsmath}.} |
| 984 |
% However, the various environments do nest in an approximately useful way. |
| 985 |
% I also think that the \env{matrix} and \env{script} environments provided |
| 986 |
% here give better results than their \package{amsmath} equivalents, and |
| 987 |
% they are certainly more versatile. |
| 988 |
% |
| 989 |
% \subsubsection{The new \env{eqnarray} environment} |
| 990 |
% |
| 991 |
% \DescribeEnv{eqnarray} |
| 992 |
% \DescribeEnv{eqnarray*} |
| 993 |
% As an example of the new column defining features, and because the original |
| 994 |
% isn't terribly good, I've included a rewritten version of the |
| 995 |
% \env{eqnarray} environment. The new implementation closes the gap between |
| 996 |
% \env{eqnarray} and \AmSTeX\ alignment features. It's in a separate, |
| 997 |
% package called \package{mathenv}, to avoid wasting your memory. |
| 998 |
% |
| 999 |
% \begin{grammar} |
| 1000 |
% |
| 1001 |
% <eqnarray-env> ::= \[[ |
| 1002 |
% <begin-eqnarray> \< <row> \\ "\\\\" \> <end-eqnarray> |
| 1003 |
% \]] |
| 1004 |
% |
| 1005 |
% <begin-eqnarray> ::= \[[ |
| 1006 |
% "\\begin" \( "{eqnarray}" \\ "{eqnarray*}" \) |
| 1007 |
% \[ "[" \< <eqa-column> \> "]" \] |
| 1008 |
% \]] |
| 1009 |
% |
| 1010 |
% <eqa-column> ::= \[[ |
| 1011 |
% \[ "q" \\ ":" \] |
| 1012 |
% \[ \< ">" "{" <pre-text> "}" \> \] |
| 1013 |
% \begin{stack} |
| 1014 |
% \[ "T" \] \( "r" \\ "c" \\ "l" \) \\ |
| 1015 |
% "L" \\ |
| 1016 |
% "x" |
| 1017 |
% \end{stack} |
| 1018 |
% \[ \< "<" "{" <post-text> "}" \> \] |
| 1019 |
% \]] |
| 1020 |
% |
| 1021 |
% <end-eqnarray> ::= \[[ |
| 1022 |
% "\\end" \begin{stack} "{eqnarray}" \\ "{eqnarray*}" \end{stack} |
| 1023 |
% \]] |
| 1024 |
% |
| 1025 |
% \end{grammar} |
| 1026 |
% |
| 1027 |
% Descriptions of the various column types are given in |
| 1028 |
% table~\ref{tbl:eqnarray}. |
| 1029 |
% |
| 1030 |
% \begin{table} |
| 1031 |
% \begin{tabular}[C]{| >{\synshorts} c | m{3in} |} \hlx{hv[1]} |
| 1032 |
% |
| 1033 |
% \multicolumn{2}{|c|}{\bf Column types} \\ \hlx{v[1]hv} |
| 1034 |
% \bf Name & \bf Meaning \\ \hlx{vhv.} |
| 1035 |
% "l" & Left aligned piece of equation. \\ \hlx{.} |
| 1036 |
% "c" & Centred piece of equation. \\ \hlx{.} |
| 1037 |
% "x" & Centred or flush-left whole equation |
| 1038 |
% (depending on \textsf{fleqn} option). \\ \hlx{.} |
| 1039 |
% "r" & Right aligned piece of equation. \\ \hlx{vhv.} |
| 1040 |
% "L" & Left aligned piece of equation whose |
| 1041 |
% width is considered to be 2\,em. \\ \hlx{vhv.} |
| 1042 |
% "Tl", "Tc" and "Tr" & Left, centre and right aligned |
| 1043 |
% text. \\ \hlx{vhhv[1]} |
| 1044 |
% |
| 1045 |
% \multicolumn{2}{|c|}{\bf Other modifier characters} \\ \hlx{v[1]hv} |
| 1046 |
% \bf Name & \bf Meaning \\ \hlx{vhv.} |
| 1047 |
% ":" & Leaves a big gap between equations. |
| 1048 |
% By default, the `chunks' separated by |
| 1049 |
% \lit{:}s are equally spaced on the |
| 1050 |
% line. \\ \hlx{.} |
| 1051 |
% "q" & Inserts 1\,em of space \\ \hlx{vhv.} |
| 1052 |
% ">{"<text>"}" & Inserts \<text> just before the |
| 1053 |
% actual column entry. \\ \hlx{.} |
| 1054 |
% "<{"<text>"}" & Inserts \<text> just after the |
| 1055 |
% actual column entry. \\ \hlx{vhv.} |
| 1056 |
% "*{"<count>"}{"<chars>"}" & Inserts \<count> |
| 1057 |
% copies of the \<chars> into the |
| 1058 |
% preamble. \\ \hlx{vh} |
| 1059 |
% \end{tabular} |
| 1060 |
% |
| 1061 |
% \caption{\package{eqnarray} column types and modifiers} |
| 1062 |
% \label{tbl:eqnarray} |
| 1063 |
% \end{table} |
| 1064 |
% |
| 1065 |
% The default preamble, if you don't supply one of your own, is \lit{rcl}. |
| 1066 |
% Most of the time, \lit{rl} is sufficient, although compatibility is more |
| 1067 |
% important to me. |
| 1068 |
% |
| 1069 |
% By default, there is no space between columns, which makes formul\ae\ in an |
| 1070 |
% \env{eqnarray} environment look just like formul\ae\ typeset on their own, |
| 1071 |
% except that things get aligned in columns. This is where the default |
| 1072 |
% \env{eqnarray} falls down: it leaves |\arraycolsep| space between each |
| 1073 |
% column making the thing look horrible. |
| 1074 |
% |
| 1075 |
% An example would be good here, I think. This one's from exercise 22.9 of |
| 1076 |
% the \textit{\TeX book}. |
| 1077 |
% |
| 1078 |
% \begin{demo}[w]{Simultaneous equations} |
| 1079 |
%\begin{eqnarray}[*3{rc}rl] |
| 1080 |
% 10w & + & 3x & + & 3y & + & 18z & = 1 \\ |
| 1081 |
% 6w & - & 17x & & & - & 5z & = 2 |
| 1082 |
%\end{eqnarray} |
| 1083 |
% \end{demo} |
| 1084 |
% |
| 1085 |
% Choosing a more up-to-date example, here's some examples from the |
| 1086 |
% \textit{\LaTeX\ Companion}. |
| 1087 |
% |
| 1088 |
% \begin{demo}[w]{Lots of equations} |
| 1089 |
%\begin{eqnarray}[rl:rl:lq] |
| 1090 |
% V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, & |
| 1091 |
% U_i = u_i, \qquad \mbox{for $i \ne j$} \\ |
| 1092 |
% V_j &= v_j, & X_j &= x_j & |
| 1093 |
% U_j u_j + \sum_{i \ne j} q_i u_i. \label{eq:A} |
| 1094 |
%\end{eqnarray} |
| 1095 |
% \end{demo} |
| 1096 |
% |
| 1097 |
% \begin{figure} |
| 1098 |
% \begin{demo}[w]{Plain text column and \cs{tabpause}} |
| 1099 |
%\begin{eqnarray}[rlqqTl] |
| 1100 |
% x &= y & by (\ref{eq:A}) \\ |
| 1101 |
% x' &= y' & by definition \\ |
| 1102 |
%\tabpause{and} |
| 1103 |
% x + x' &= y + y' & by Axiom~1 |
| 1104 |
%\end{eqnarray} |
| 1105 |
% \end{demo} |
| 1106 |
% \end{figure} |
| 1107 |
% |
| 1108 |
% The new features also mean that you don't need to mess about with |
| 1109 |
% |\lefteqn| any more. This is handled by the \lit{L} column type: |
| 1110 |
% |
| 1111 |
% \begin{demo}{Splitting example} |
| 1112 |
%\begin{eqnarray*}[Ll] |
| 1113 |
% w+x+y+z = \\ |
| 1114 |
% & a+b+c+d+e+ \\ |
| 1115 |
% & f+g+h+i+j |
| 1116 |
%\end{eqnarray*} |
| 1117 |
% \end{demo} |
| 1118 |
% |
| 1119 |
% Finally, just to prove that the spacing's right at last, here's another one |
| 1120 |
% from the \textit{Companion}. |
| 1121 |
% |
| 1122 |
% \begin{demo}{Spacing demonstration} |
| 1123 |
%\begin{equation} |
| 1124 |
% x^2 + y^2 = z^2 |
| 1125 |
%\end{equation} |
| 1126 |
%\begin{eqnarray}[rl] |
| 1127 |
% x^2 + y^2 &= z^2 \\ |
| 1128 |
% y^2 &< z^2 |
| 1129 |
%\end{eqnarray} |
| 1130 |
% \end{demo} |
| 1131 |
% |
| 1132 |
% Well, that was easy enough. Now on to numbering. As you've noticed, the |
| 1133 |
% equations above are numbered. You can use the \env{eqnarray$*$} |
| 1134 |
% environment to turn off the numbering in the whole environment, or say |
| 1135 |
% |\nonumber| on a line to suppress numbering of that one in particular. |
| 1136 |
% |
| 1137 |
% \DescribeMacro{\eqnumber} |
| 1138 |
% More excitingly, you can say |\eqnumber| to enable numbering for a |
| 1139 |
% particular equation, or \syntax{"\\eqnumber["<text>"]"} to choose what to |
| 1140 |
% show instead of the line number. This works for both starred and unstarred |
| 1141 |
% versions of the environment. Now |\nonumber| becomes merely a synonym for |
| 1142 |
% `|\eqnumber[]|'. |
| 1143 |
% |
| 1144 |
% A note for cheats: you can use the sparkly new \env{eqnarray} for simple |
| 1145 |
% equations by specifying \lit{x} as the column description. Who needs |
| 1146 |
% \AmSTeX?\ |;-)| |
| 1147 |
% |
| 1148 |
% \DescribeEnv{eqlines} |
| 1149 |
% \DescribeEnv{eqlines*} |
| 1150 |
% In fact, there's a separate environment \env{eqlines}, which is equivalent |
| 1151 |
% to \env{eqnarray} with a single \lit{x} column; the result is that you can |
| 1152 |
% insert a collection of displayed equations separated by |\\| commands. If |
| 1153 |
% you don't like numbering, use \env{eqlines$*$} insead. |
| 1154 |
% |
| 1155 |
% \subsubsection{The \env{eqnalign} environment} |
| 1156 |
% |
| 1157 |
% \DescribeEnv{eqnalign} |
| 1158 |
% There's a new environment, \env{eqnalign}, which does almost the same |
| 1159 |
% thing as \env{eqnarray} but not quite. It doesn't do equation numbers, |
| 1160 |
% and it wraps its contents up in a box. The result of this is that: |
| 1161 |
% |
| 1162 |
% \begin{itemize} |
| 1163 |
% |
| 1164 |
% \item You can use \env{eqnalign} for just a part of a formula. |
| 1165 |
% The \env{eqnarray} environment must take up the whole display. |
| 1166 |
% |
| 1167 |
% \item You can use \env{eqnalign} within \env{eqnarray} for extra fine |
| 1168 |
% alignment of subsidiary bits. |
| 1169 |
% |
| 1170 |
% \item You can break off from doing an \env{eqnarray} using the |\tabpause| |
| 1171 |
% command. You can't use |\tabpause| inside |
| 1172 |
% \env{eqnalign}.\footnote{^^A |
| 1173 |
% Well, technically speaking there's nothing to stop you. However, |
| 1174 |
% the results won't be pretty.} |
| 1175 |
% |
| 1176 |
% \end{itemize} |
| 1177 |
% |
| 1178 |
% The \env{eqnalign} environment works like this: |
| 1179 |
% |
| 1180 |
% \begin{grammar} |
| 1181 |
% |
| 1182 |
% <eqnalign-env> ::= \[[ |
| 1183 |
% <begin-eqnalign> <contents> <end-eqnalign> |
| 1184 |
% \]] |
| 1185 |
% |
| 1186 |
% <begin-eqnalign> ::= \[[ |
| 1187 |
% "\\begin" "{eqnalign}" |
| 1188 |
% \[ "[" \< <eqa-column> \> "]" \] |
| 1189 |
% \[ "[" \( "t" \\ "c" \\ "b" \) "]" \] |
| 1190 |
% \]] |
| 1191 |
% |
| 1192 |
% <end-eqnalign> ::= \[[ "\\end" "{eqnalign}" \]] |
| 1193 |
% |
| 1194 |
% \end{grammar} |
| 1195 |
% |
| 1196 |
% As the syntax suggests, the preamble for the \env{eqnalign} environment |
| 1197 |
% works exactly the same way as for \env{eqnarray}. Example time: another |
| 1198 |
% one from the \textit{\TeX book}. |
| 1199 |
% |
| 1200 |
% \begin{figure} |
| 1201 |
% \begin{demo}[w]{Example of \env{eqnalign}} |
| 1202 |
%\[ |
| 1203 |
% \left\{ \begin{eqnalign}[rl] |
| 1204 |
% \alpha &= f(z) \\ \beta &= f(z^2) \\ |
| 1205 |
% \gamma &= f(z^3) |
| 1206 |
% \end{eqnalign} \right\} |
| 1207 |
% \qquad |
| 1208 |
% \left\{ \begin{eqnalign}[rl] |
| 1209 |
% x &= \alpha^2 - \beta \\ y &= 2\gamma |
| 1210 |
% \end{eqnalign} \right\}. |
| 1211 |
%\] |
| 1212 |
% \end{demo} |
| 1213 |
% \end{figure} |
| 1214 |
% |
| 1215 |
% \DescribeMacro{\multicolumn} |
| 1216 |
% The |\multicolumn| command works correctly in both the \env{eqnarray} and |
| 1217 |
% \env{eqnalign} environments, although you should bear in mind that you |
| 1218 |
% should give \env{eqnarray} column types, not \env{array} ones. |
| 1219 |
% |
| 1220 |
% \subsubsection{A note on spacing in alignment environments} |
| 1221 |
% |
| 1222 |
% Most of the time, equations in \env{eqnarray} and \env{eqnalign} |
| 1223 |
% environments will be beautiful. However, there are some things you should |
| 1224 |
% bear in mind when you produce beautiful equations. |
| 1225 |
% |
| 1226 |
% The main problem with spacing is making sure that binary relations and |
| 1227 |
% binary operators have the correct amount of space on each side of them. |
| 1228 |
% The alignment environments insert `hidden' objects at the ends of table |
| 1229 |
% cells to assist with the spacing: \lit{l} column types have a hidden object |
| 1230 |
% on the left, \lit{r} types have a hidden object on the right, and \lit{c} |
| 1231 |
% types have a hidden object on \emph{both} ends. These hidden objects add |
| 1232 |
% the correct space when there's a binary operator or relation next to them. |
| 1233 |
% If some other sort of object is lurking there, no space is added. So far, |
| 1234 |
% so good. |
| 1235 |
% |
| 1236 |
% The only problem comes when you have something like this: |
| 1237 |
% |
| 1238 |
% \begin{demo}{How not to do an \env{eqnarray}} |
| 1239 |
%\begin{eqnarray*}[rcl] |
| 1240 |
% x + y & = & 12 \\ |
| 1241 |
% 2x - 5y & = & -6 |
| 1242 |
%\end{eqnarray*} |
| 1243 |
% \end{demo} |
| 1244 |
% |
| 1245 |
% The `$-$' sign in the second equation has been treated as a binary operator |
| 1246 |
% when really it should be a unary prefix operator, but \TeX\ isn't clever |
| 1247 |
% enough to know the difference. (Can you see the difference in the spacing |
| 1248 |
% between $-6$~and~${}-6$?) There are two possible solutions to the |
| 1249 |
% problem. You could wrap the `|-6|' up in a group (`|{-6}|'), or just the |
| 1250 |
% $-$ sign (`|{-}6|'). A better plan, though, is to get rid of the middle |
| 1251 |
% column altogether: |
| 1252 |
% |
| 1253 |
% \begin{demo}{How to do an \env{eqnarray}} |
| 1254 |
%\begin{eqnarray*}[rl] |
| 1255 |
% x + y & = 12 \\ |
| 1256 |
% 2x - 5y & = -6 |
| 1257 |
%\end{eqnarray*} |
| 1258 |
% \end{demo} |
| 1259 |
% |
| 1260 |
% Since the things in the middle column were the same width, it's not |
| 1261 |
% actually doing any good. Also, now that \TeX\ can see that the thing on |
| 1262 |
% the left of the `$-$' sign is a relation (the `$=$' sign), it will space |
| 1263 |
% the formula correctly. |
| 1264 |
% |
| 1265 |
% In this case, it might be even better to add some extra columns, and line |
| 1266 |
% up the $x$ and $y$ terms in the left hand side: |
| 1267 |
% |
| 1268 |
% \begin{demo}{Extra beautiful \env{eqnarray}} |
| 1269 |
%\begin{eqnarray*}[rrl] |
| 1270 |
% x + & y & = 12 \\ |
| 1271 |
% 2x - & 5y & = -6 |
| 1272 |
%\end{eqnarray*} |
| 1273 |
% \end{demo} |
| 1274 |
% |
| 1275 |
% ^^A Some hacking now to display box sizes. |
| 1276 |
% |
| 1277 |
% { |
| 1278 |
% \catcode`p=12 \catcode`t=12 |
| 1279 |
% \gdef\magni#1pt{#1} |
| 1280 |
% } |
| 1281 |
% |
| 1282 |
% \newcommand{\widthof}[1]{^^A |
| 1283 |
% \settowidth{\dimen0 }{#1}^^A |
| 1284 |
% \expandafter\magni\the\dimen0\,pt^^A |
| 1285 |
% } |
| 1286 |
% |
| 1287 |
% ^^A The text below makes an assumption which looks correct to me (I asked |
| 1288 |
% ^^A TeX, and it agreed with me), although in case anything changes, I want |
| 1289 |
% ^^A to be informed. |
| 1290 |
% |
| 1291 |
% \sbox0{$+$} \sbox2{$-$} \ifdim\wd0=\wd2\else% |
| 1292 |
% \errmessage{Assertion failed: `+' and `-' are different widths!} |
| 1293 |
% \fi |
| 1294 |
% |
| 1295 |
% There's no need to put the `$+$' and `$-$' operators in their own column |
| 1296 |
% here, because they're both \widthof{$+$} wide, even though they don't |
| 1297 |
% look it. |
| 1298 |
% |
| 1299 |
% \subsubsection{Configuring the alignment environments} |
| 1300 |
% |
| 1301 |
% There are a collection of parameters you can use to make the equation |
| 1302 |
% alignment environments (\env{eqnarray} and \env{eqnalign}) look the way |
| 1303 |
% you like them. These are all shown in table~\ref{tbl:eqnparms}. |
| 1304 |
% |
| 1305 |
% \begin{table} |
| 1306 |
% \begin{tabular}[C]{| l | p{3in} |} \hlx{hv} |
| 1307 |
% \bf Parameter & \bf Use \\ \hlx{vhv} |
| 1308 |
% |\eqaopenskip| & Length put on the left of an |
| 1309 |
% \env{eqnarray} environment. By |
| 1310 |
% default, this is |\@centering| (to |
| 1311 |
% centre the alignment) or |\mathindent| |
| 1312 |
% (to left align) depending on whether |
| 1313 |
% you're using the \textsf{fleqn} |
| 1314 |
% document class option. \\ |
| 1315 |
% |\eqacloseskip| & Length put on the right of an |
| 1316 |
% \env{eqnarray} environment. By |
| 1317 |
% default, this is |\@centering|, to |
| 1318 |
% align the environment correctly. \\ \hlx{vhv} |
| 1319 |
% |\eqacolskip| & Space added by the \lit{:} column |
| 1320 |
% modifier. This should be a rubber |
| 1321 |
% length, although it only stretches in |
| 1322 |
% \env{eqnarray}, not in \env{eqnalign}. |
| 1323 |
% The default value is 1\smallf1/2\,em |
| 1324 |
% with 1000\,pt of stretch. \\ |
| 1325 |
% |\eqainskip| & Space added at each side of a normal |
| 1326 |
% column. By default this is 0\,pt. \\ \hlx{vhv} |
| 1327 |
% |\eqastyle| & The maths style used in the alignment. |
| 1328 |
% By default, this is |\textstyle|, |
| 1329 |
% and you probably won't want to change |
| 1330 |
% it. \\ \hlx{vh} |
| 1331 |
% \end{tabular} |
| 1332 |
% |
| 1333 |
% \caption{Parameters for the \env{eqnarray} and \env{eqnalign} environments} |
| 1334 |
% \label{tbl:eqnparms} |
| 1335 |
% \end{table} |
| 1336 |
% |
| 1337 |
% |
| 1338 |
% \subsection{Other multiline equations} |
| 1339 |
% |
| 1340 |
% Sometimes there's no sensible alignment point for splitting equations. The |
| 1341 |
% normal thing to do under these circumstances is to put the first line way |
| 1342 |
% over to the left of the page, and the last line over to the right. (If |
| 1343 |
% there are more lines, I imagine we put them in the middle.) |
| 1344 |
% |
| 1345 |
% \DescribeEnv{spliteqn} |
| 1346 |
% \DescribeEnv{spliteqn*} |
| 1347 |
% The \env{spliteqn} environment allows you to do such splitting of |
| 1348 |
% equations. Rather than tediously describe it, I'll just give an example, |
| 1349 |
% because it's really easy. The $*$-version works the same, except it |
| 1350 |
% doesn't put an equation number in. |
| 1351 |
% |
| 1352 |
% \begin{figure} |
| 1353 |
% \begin{demo}[w]{A split equation} |
| 1354 |
%\begin{spliteqn} |
| 1355 |
% \sum_{1\le j\le n} |
| 1356 |
% \frac {1} { (x_j - x_1) \ldots (x_j - x_{j-1}) |
| 1357 |
% (x - x_j) (x_j - x_{j+1}) \ldots (x_j - x_n) } |
| 1358 |
% \\ |
| 1359 |
% = \frac {1} { (x - x_1) \ldots (x - x_n) }. |
| 1360 |
%\end{spliteqn} |
| 1361 |
% \end{demo} |
| 1362 |
% \end{figure} |
| 1363 |
% |
| 1364 |
% \DescribeEnv{subsplit} |
| 1365 |
% If you have a very badly behaved equation, you might want to split a part |
| 1366 |
% of it (say, a bit of a fraction), particularly if you're doing things in |
| 1367 |
% narrow columns. |
| 1368 |
% |
| 1369 |
% \begin{figure} |
| 1370 |
% \begin{demo}[w]{A \env{subsplit} environment} |
| 1371 |
%\begin{equation} |
| 1372 |
% \frac{ |
| 1373 |
% \begin{subsplit} |
| 1374 |
% q^{\frac{1}{2} n(n+1)}(ea; q^2)_\infty (eq/a; q^2)_\infty \\ |
| 1375 |
% (caq/e; q^2)_\infty (cq^2/ae; q^2)_\infty |
| 1376 |
% \end{subsplit} |
| 1377 |
% }{ |
| 1378 |
% (e; q)_\infty (cq/e; q)_\infty |
| 1379 |
% } |
| 1380 |
%\end{equation} |
| 1381 |
% \end{demo} |
| 1382 |
% \end{figure} |
| 1383 |
% |
| 1384 |
% \subsection{Matrices} |
| 1385 |
% |
| 1386 |
% Also included in the \package{mathenv} package is a collection of things |
| 1387 |
% for typesetting matrices. The standard \env{array} doesn't (in my opinion) |
| 1388 |
% provide the right sort of spacing for matrices. \PlainTeX\ provides some |
| 1389 |
% quite nice matrix handling macros, but they don't work in the appropriate |
| 1390 |
% \LaTeX\ way. |
| 1391 |
% |
| 1392 |
% \textbf{Warning:} These definitions will make old versions of |
| 1393 |
% \package{plain.sty} unhappy; newer versions correctly restore the |
| 1394 |
% Plain~\TeX\ macros |\matrix| and |\pmatrix|. |
| 1395 |
% |
| 1396 |
% \DescribeEnv{matrix} |
| 1397 |
% The simple way to do matrices is with the \env{matrix} environment. |
| 1398 |
% |
| 1399 |
% \begin{grammar} |
| 1400 |
% |
| 1401 |
% <matrix-env> ::= \[[ <begin-matrix> <contents> <end-matrix> \]] |
| 1402 |
% |
| 1403 |
% <begin-matrix> ::= \[[ "\\begin{matrix}" \[ "[" <matrix-cols> "]" \] \]] |
| 1404 |
% |
| 1405 |
% <matrix-cols> ::= \[[ |
| 1406 |
% \< \[ "[" \] \[ "T" \] \( "l" \\ "c" \\ "r" \) \> |
| 1407 |
% \]] |
| 1408 |
% |
| 1409 |
% <end-matrix> ::= \[[ "\\end{stack}" \]] |
| 1410 |
% |
| 1411 |
% \end{grammar} |
| 1412 |
% |
| 1413 |
% The \lit{l}, \lit{c} and \lit{r} columns are fairly obvious -- they align |
| 1414 |
% their contents in the appropriate way. The \lit{[} character is more |
| 1415 |
% complicated. It means `repeat the remaining column types forever', so a |
| 1416 |
% preamble of \lit{cc[lr} means `two centred columns, then alternating left- |
| 1417 |
% and right-aligned columns for as often as needed'. The default preamble, |
| 1418 |
% if you don't specify one, is \lit{[c} -- `any number of centred columns'. |
| 1419 |
% |
| 1420 |
% \DescribeMacro{\multicolumn} |
| 1421 |
% The |\multicolumn| command works correctly in matrices, although you should |
| 1422 |
% bear in mind that you should give \env{matrix} column types, not |
| 1423 |
% \env{array} ones. |
| 1424 |
% |
| 1425 |
% \DescribeEnv{pmatrix} |
| 1426 |
% The standard \env{matrix} environment doesn't put any delimiters around the |
| 1427 |
% matrix. You can use the standard |\left| and |\right| commands, although |
| 1428 |
% this is a bit nasty. The \env{pmatrix} environment will put parentheses |
| 1429 |
% around the matrix it creates; it's otherwise exactly the same as |
| 1430 |
% \env{matrix}. |
| 1431 |
% |
| 1432 |
% \DescribeEnv{dmatrix} |
| 1433 |
% A \env{dmatrix} environment is also provided. It takes two extra |
| 1434 |
% arguments: the left and right delimiter characters (without |\left| or |
| 1435 |
% |\right|). |
| 1436 |
% |
| 1437 |
% \begin{figure} |
| 1438 |
% \begin{demo}[w]{Various \env{matrix} environments} |
| 1439 |
%\[ \begin{matrix} 1 & 0 \\ 0 & -1 \end{matrix} \quad |
| 1440 |
% \begin{pmatrix} |
| 1441 |
% \cos\theta & \sin\theta \\ |
| 1442 |
% -\sin\theta & \cos\theta |
| 1443 |
% \end{pmatrix} \quad |
| 1444 |
% \begin{dmatrix}[] 0 & -i \\ i & 0 \end{dmatrix} |
| 1445 |
%\] |
| 1446 |
% \end{demo} |
| 1447 |
% \end{figure} |
| 1448 |
% |
| 1449 |
% \DescribeEnv{smatrix} |
| 1450 |
% Normal matrices always come out the same size; they don't change size |
| 1451 |
% according to the surrounding context (unfortunately). However, it can be |
| 1452 |
% occasionally useful to put matrices in running text, so you can talk about |
| 1453 |
% $A$ being $\bigl( \begin{smatrix} a & b \\ b & c \end{smatrix} \bigr)$ |
| 1454 |
% being its own transpose (i.e., $A = A^T$). This is accomplished using the |
| 1455 |
% \env{smatrix} (the `s' stands for `small' -- I thought that `smallmatrix' |
| 1456 |
% was too big to type inline). As well as inline text, the \env{smatrix} |
| 1457 |
% can be useful in displays, if the matrix is deep in a subformula. I can't |
| 1458 |
% think of any examples offhand, though. |
| 1459 |
% |
| 1460 |
% \DescribeEnv{spmatrix} |
| 1461 |
% \DescribeEnv{sdmatrix} |
| 1462 |
% The \env{smatrix} environment doesn't supply any delimiters, like |
| 1463 |
% \env{matrix}. There are \env{spmatrix} and \env{sdmatrix} environments |
| 1464 |
% which do, though. Note that delimiters have a tendency to get too big and |
| 1465 |
% mess up the line spacing -- I had to use explicitly |\big| delimiters |
| 1466 |
% in the above example. |
| 1467 |
% |
| 1468 |
% \DescribeEnv{pmatrix*} |
| 1469 |
% \DescribeEnv{spmatrix*} |
| 1470 |
% \DescribeEnv{sdmatrix*} |
| 1471 |
% All the small matrix environments have starred versions, which are more |
| 1472 |
% suitable for use in displays, since they have more space between the rows. |
| 1473 |
% They're intended for typesetting really big matrices in displays. |
| 1474 |
% |
| 1475 |
% \DescribeMacro{\ddots} |
| 1476 |
% \DescribeMacro{\vdots} |
| 1477 |
% The standard |\vdots| and |\ddots| commands don't produce anything at all |
| 1478 |
% nice in small matrices, so this package redefines them so that they scale |
| 1479 |
% properly to smaller sizes. |
| 1480 |
% |
| 1481 |
% \DescribeEnv{genmatrix} |
| 1482 |
% Actually, all these environments are special cases of one: \env{genmatrix}. |
| 1483 |
% This takes oodles of arguments: |
| 1484 |
% \begin{quote} \synshorts |
| 1485 |
% "\\begin{genmatrix}{"<matrix-style>"}{"<outer-style>"}" \\ |
| 1486 |
% \null \qquad "{"<spacing>"}{"<left-delim>"}{"<right-delim>"}" \\ |
| 1487 |
% \null \quad\vdots \\ |
| 1488 |
% "\\end{genmatrix}" |
| 1489 |
% \end{quote} |
| 1490 |
% The two `style' arguments should be things like |\textstyle| or |
| 1491 |
% |\scriptstyle|; the first, \<matrix-style>, is the style to use for the |
| 1492 |
% matrix elements, and the second, \<outer-style>, is the style to assume |
| 1493 |
% for the surrounding text (this affects the spacing within the matrix; it |
| 1494 |
% should usually be the same as \<matrix-style>). The \<spacing> is inserted |
| 1495 |
% between the matrix and the delimiters, on each side of the matrix. It's |
| 1496 |
% usually `|\,|' in full-size matrices, and blank for small ones. The |
| 1497 |
% delimiters are inserted around the matrices, and sized appropriately. |
| 1498 |
% |
| 1499 |
% \DescribeEnv{newmatrix} |
| 1500 |
% You can create your own matrix environments if you like, using the |
| 1501 |
% |\newmatrix| command. It takes two arguments, although they're a bit |
| 1502 |
% odd. The first is the name of the environment, and the second contains |
| 1503 |
% the arguments to pass to \env{genmatrix}. For example, the \env{pmatrix} |
| 1504 |
% environment was defined by saying |
| 1505 |
% |
| 1506 |
% \begin{listing} |
| 1507 |
%\newmatrix{pmatrix}{{\textstyle}{\textstyle}{\,}{(}{)}} |
| 1508 |
% \end{listing} |
| 1509 |
% |
| 1510 |
% If you don't pass all three arguments, then you end up requiring the |
| 1511 |
% user to specify the remaining ones. This is how \env{dmatrix} works. |
| 1512 |
% |
| 1513 |
% \DescribeEnv{script} |
| 1514 |
% Finally, although it's not really a matrix, stacked super- and subscripts |
| 1515 |
% follow much the same sorts of spacing rules. The \env{script} environment |
| 1516 |
% allows you to do this sort of thing very easily. It essentially provides |
| 1517 |
% a `matrix' with the right sort of spacing. The default preamble string is |
| 1518 |
% \lit{c}, giving you centred scripts, although you can say |
| 1519 |
% |\begin{script}[l]| for left-aligned scripts, which is better if the |
| 1520 |
% script is being placed to the right of its operator. If you're really |
| 1521 |
% odd, you can have more than one column. |
| 1522 |
% |
| 1523 |
% \begin{demo}{Example of \env{script}} |
| 1524 |
%\[ \mathop{{\sum}'}_{x \in A} |
| 1525 |
% f(x) |
| 1526 |
% \stackrel{\mathrm{def}}{=} |
| 1527 |
% \sum_{\begin{script} |
| 1528 |
% x \in A \\ x \ne 0 |
| 1529 |
% \end{script}} f(x) |
| 1530 |
%\] |
| 1531 |
% \end{demo} |
| 1532 |
% |
| 1533 |
% |
| 1534 |
% \subsection{Other \package{mathenv} environments} |
| 1535 |
% |
| 1536 |
% The \package{mathenv} package contains some other environments which may |
| 1537 |
% be useful, based on the enhanced \env{tabular} and \env{array} |
| 1538 |
% environments. |
| 1539 |
% |
| 1540 |
% \DescribeEnv{cases} |
| 1541 |
% The \env{cases} environment lets you say things like the following: |
| 1542 |
% |
| 1543 |
% \begin{demo}[w]{Example of \env{cases}} |
| 1544 |
%\[ P_{r-j} = \begin{cases} |
| 1545 |
% 0 & if $r-j$ is odd \\ |
| 1546 |
% r!\,(-1)^{(r-j)/2} & if $r-j$ is even |
| 1547 |
% \end{cases} |
| 1548 |
%\] |
| 1549 |
% \end{demo} |
| 1550 |
% |
| 1551 |
% The spacing required for this is a bit messy, so providing an environment |
| 1552 |
% for it is quite handy. |
| 1553 |
% |
| 1554 |
% \DescribeEnv{smcases} |
| 1555 |
% The \env{smcases} environment works the same way as \env{cases}, but with |
| 1556 |
% scriptsize lettering. |
| 1557 |
% |
| 1558 |
% \implementation |
| 1559 |
% |
| 1560 |
% |
| 1561 |
%^^A------------------------------------------------------------------------- |
| 1562 |
% \section{Implementation of table handling} |
| 1563 |
% |
| 1564 |
% |
| 1565 |
% Here we go. It starts horrid and gets worse. However, it does stay nicer |
| 1566 |
% than the original, IMHO. |
| 1567 |
% |
| 1568 |
% \begin{macrocode} |
| 1569 |
%<*mdwtab> |
| 1570 |
% \end{macrocode} |
| 1571 |
% |
| 1572 |
% |
| 1573 |
% \subsection{Registers, switches and things} |
| 1574 |
% |
| 1575 |
% We need lots of these. It's great fun. |
| 1576 |
% |
| 1577 |
% The two count registers are simple enough: |
| 1578 |
% |
| 1579 |
% \begin{description} |
| 1580 |
% \item [\cs{tab@state}] contains the current parser state. Since we |
| 1581 |
% probably won't be parsing preambles recursively, this is a global |
| 1582 |
% variable. |
| 1583 |
% \item [\cs{tab@columns}] contains the number of the current column. |
| 1584 |
% \item [\cs{tab@hlstate}] contains the state required for hline management. |
| 1585 |
% \end{description} |
| 1586 |
% |
| 1587 |
% \begin{macrocode} |
| 1588 |
\newcount\tab@state |
| 1589 |
\newcount\tab@columns |
| 1590 |
% \end{macrocode} |
| 1591 |
% |
| 1592 |
% We need \emph{lots} of token registers. Fortunately, most of them are only |
| 1593 |
% used during parsing. We'll use \PlainTeX's scratch tokens for this. Note |
| 1594 |
% that |\toks\tw@| isn't used here. It, and |\toks@|, are free for use by |
| 1595 |
% column commands. |
| 1596 |
% |
| 1597 |
% \begin{macrocode} |
| 1598 |
\newtoks\tab@preamble |
| 1599 |
\newtoks\tab@shortline |
| 1600 |
\toksdef\tab@pretext 4 |
| 1601 |
\toksdef\tab@posttext 6 |
| 1602 |
\toksdef\tab@userpretext 8 |
| 1603 |
% \end{macrocode} |
| 1604 |
% |
| 1605 |
% The dimens are fairly straightforward. The inclusion of |\col@sep| is a |
| 1606 |
% sacrifice to compatibility -- judicious use of |\let| in \package{array} |
| 1607 |
% would have saved a register. |
| 1608 |
% |
| 1609 |
% \begin{macrocode} |
| 1610 |
\newdimen\extrarowheight |
| 1611 |
\newdimen\tabextrasep |
| 1612 |
\newdimen\arrayextrasep |
| 1613 |
\newdimen\smarraycolsep |
| 1614 |
\newdimen\smarrayextrasep |
| 1615 |
\newdimen\tab@width |
| 1616 |
\newdimen\col@sep |
| 1617 |
\newdimen\tab@endheight |
| 1618 |
% \end{macrocode} |
| 1619 |
% |
| 1620 |
% Some skip registers too. Phew. |
| 1621 |
% |
| 1622 |
% \begin{macrocode} |
| 1623 |
\newskip\tab@leftskip |
| 1624 |
\newskip\tab@rightskip |
| 1625 |
% \end{macrocode} |
| 1626 |
% |
| 1627 |
% And some switches. The first three are for the parser. |
| 1628 |
% |
| 1629 |
% \begin{macrocode} |
| 1630 |
\newif\iftab@firstcol |
| 1631 |
\newif\iftab@initrule |
| 1632 |
\newif\iftab@rule |
| 1633 |
\newif\iftab@vgap |
| 1634 |
% \end{macrocode} |
| 1635 |
% |
| 1636 |
% Now assign some default values to new dimen parameters. These definitions |
| 1637 |
% are essentially the equivalent of an |\openup 1\jot| in \env{array}, but |
| 1638 |
% not in \env{tabular}. This looks nice, I think. |
| 1639 |
% |
| 1640 |
% \begin{macrocode} |
| 1641 |
\tabextrasep\z@ |
| 1642 |
\arrayextrasep\jot |
| 1643 |
\smarraycolsep\thr@@\p@ |
| 1644 |
\smarrayextrasep\z@ |
| 1645 |
% \end{macrocode} |
| 1646 |
% |
| 1647 |
% Set some things up for alien table environments. |
| 1648 |
% |
| 1649 |
% \begin{macrocode} |
| 1650 |
\let\tab@extrasep\tabextrasep |
| 1651 |
\let\tab@penalty\relax |
| 1652 |
% \end{macrocode} |
| 1653 |
% |
| 1654 |
% |
| 1655 |
% \subsection{Some little details} |
| 1656 |
% |
| 1657 |
% \begin{macro}{\@maybe@unskip} |
| 1658 |
% |
| 1659 |
% This macro solves a little problem. In an alignment (and in other places) |
| 1660 |
% it's desirable to suppress trailing space. The usual method, to say |
| 1661 |
% |\unskip|, is a little hamfisted, because it removes perfectly reasonable |
| 1662 |
% aligning spaces like |\hfil|s. While as a package writer I can deal with |
| 1663 |
% this sort of thing by saying |\kern\z@| in appropriate places, it can |
| 1664 |
% annoy users who are trying to use |\hfill| to override alignment in funny |
| 1665 |
% places. |
| 1666 |
% |
| 1667 |
% My current solution seems to be acceptable. I'll remove the natural width |
| 1668 |
% of the last glue item, so that it can still stretch and shrink if |
| 1669 |
% necessary. The implementation makes use of the fact that multiplying |
| 1670 |
% a \<skip> by a \<number> kills off the stretch. (Bug fix: don't do this |
| 1671 |
% when we're in vertical mode.) |
| 1672 |
% |
| 1673 |
% \begin{macrocode} |
| 1674 |
\def\@maybe@unskip{\ifhmode\hskip\m@ne\lastskip\relax\fi} |
| 1675 |
% \end{macrocode} |
| 1676 |
% |
| 1677 |
% \end{macro} |
| 1678 |
% |
| 1679 |
% \begin{macro}{\q@delim} |
| 1680 |
% |
| 1681 |
% Finally, for the sake of niceness, here's a delimiter token I can use |
| 1682 |
% for various things. It's a `quark', for what it's worth (i.e., it expands |
| 1683 |
% to itself) although I'm not really sure why this is a good thing. As far |
| 1684 |
% as I'm concerned, it's important that it has a unique meaning (i.e., that |
| 1685 |
% it won't be |\ifx|-equal to other things, or something undefined) and that |
| 1686 |
% it won't be used where I don't expect it to be used. \TeX\ will loop |
| 1687 |
% horridly if it tries to expand this, so I don't think that quarks are |
| 1688 |
% wonderfully clever thing to use. (Maybe it should really expand to |
| 1689 |
% something like `\syntax{<quark>"."}', which will rapdly fill \TeX's memory |
| 1690 |
% if it gets accidentally expanded. Still, I'll leave it as it is until |
| 1691 |
% such time as I understand the idea more.) |
| 1692 |
% |
| 1693 |
% \begin{macrocode} |
| 1694 |
\def\q@delim{\q@delim} |
| 1695 |
% \end{macrocode} |
| 1696 |
% |
| 1697 |
% \end{macro} |
| 1698 |
% |
| 1699 |
% |
| 1700 |
% \subsection{Parser states} |
| 1701 |
% |
| 1702 |
% Now we start on the parser. It's really simple, deep down. We progress |
| 1703 |
% from state to state, extracing tokens from the preamble and building |
| 1704 |
% command names from them. Each command calls one of the element-building |
| 1705 |
% routines, which works out which state it should be in. We go through each |
| 1706 |
% of the states in between (see later) doing default things for the ones we |
| 1707 |
% missed out. |
| 1708 |
% |
| 1709 |
% Anyway, here's some symbolic names for the states. It makes my life |
| 1710 |
% easier. |
| 1711 |
% |
| 1712 |
% \begin{macrocode} |
| 1713 |
\chardef\tab@startstate 0 |
| 1714 |
\chardef\tab@loopstate 1 |
| 1715 |
\chardef\tab@rulestate 1 |
| 1716 |
\chardef\tab@prespcstate 2 |
| 1717 |
\chardef\tab@prestate 3 |
| 1718 |
\chardef\tab@colstate 4 |
| 1719 |
\chardef\tab@poststate 5 |
| 1720 |
\chardef\tab@postspcstate 6 |
| 1721 |
\chardef\tab@limitstate 7 |
| 1722 |
% \end{macrocode} |
| 1723 |
% |
| 1724 |
% |
| 1725 |
% \subsection{Adding things to token lists} |
| 1726 |
% |
| 1727 |
% Define some macros for adding stuff to the beginning and end of token |
| 1728 |
% lists. This is really easy, actually. Here we go. |
| 1729 |
% |
| 1730 |
% \begin{macrocode} |
| 1731 |
\def\tab@append#1#2{#1\expandafter{\the#1#2}} |
| 1732 |
\def\tab@prepend#1#2{% |
| 1733 |
\toks@{#2}#1\expandafter{\the\expandafter\toks@\the#1}% |
| 1734 |
} |
| 1735 |
% \end{macrocode}% |
| 1736 |
% |
| 1737 |
% |
| 1738 |
% \subsection{Committing a column to the preamble} |
| 1739 |
% |
| 1740 |
% Each time we pass the `rule' state, we `commit' the tokens we've gathered |
| 1741 |
% so far to the main preamble token list. This is how we do it. Note the |
| 1742 |
% icky use of |\expandafter|. |
| 1743 |
% |
| 1744 |
% \begin{macrocode} |
| 1745 |
\def\tab@commit{% |
| 1746 |
% \end{macrocode} |
| 1747 |
% |
| 1748 |
% If this isn't the first column, then we need to put in a column separator. |
| 1749 |
% |
| 1750 |
% \begin{macrocode} |
| 1751 |
\iftab@firstcol\else% |
| 1752 |
\expandafter\tab@append\expandafter\tab@preamble% |
| 1753 |
\expandafter{\tab@tabtext}% |
| 1754 |
\fi% |
| 1755 |
% \end{macrocode} |
| 1756 |
% |
| 1757 |
% Now we spill the token registers into the main list in a funny order (which |
| 1758 |
% is why we're doing it in this strange way in the first place. |
| 1759 |
% |
| 1760 |
% \begin{macrocode} |
| 1761 |
\toks@\expandafter{\tab@midtext}% |
| 1762 |
\tab@preamble\expandafter{% |
| 1763 |
\the\expandafter\tab@preamble% |
| 1764 |
\the\expandafter\tab@pretext% |
| 1765 |
\the\expandafter\tab@userpretext% |
| 1766 |
\the\expandafter\toks@% |
| 1767 |
\the\tab@posttext% |
| 1768 |
}% |
| 1769 |
% \end{macrocode} |
| 1770 |
% |
| 1771 |
% Now reset token lists and things for the next go round. |
| 1772 |
% |
| 1773 |
% \begin{macrocode} |
| 1774 |
\tab@firstcolfalse% |
| 1775 |
\tab@pretext{}% |
| 1776 |
\tab@userpretext{}% |
| 1777 |
\tab@posttext{}% |
| 1778 |
} |
| 1779 |
% \end{macrocode} |
| 1780 |
% |
| 1781 |
% |
| 1782 |
% \subsection{Playing with parser states} |
| 1783 |
% |
| 1784 |
% \begin{macro}{\tab@setstate} |
| 1785 |
% |
| 1786 |
% This is how we set new states. The algorithm is fairly simple, really. |
| 1787 |
% |
| 1788 |
% ^^A Let's see how good my TeX really is... ;-) |
| 1789 |
% ^^A Actually, it doesn't seem to have worked out too badly. Maybe I should |
| 1790 |
% ^^A write a package to do this automatically. It's rather tricky, though. |
| 1791 |
% |
| 1792 |
% \def\qq{\mbox{\quad}} |
| 1793 |
% \sbox{0}{\itshape\textunderscore}\def\_{\usebox{0}} |
| 1794 |
% |
| 1795 |
% \begin{quote} |
| 1796 |
% {\bf while} $\it tab\_state \ne s$ {\bf do} \\ |
| 1797 |
% \qq $\mathit{tab\_state = tab\_state}+1$; \\ |
| 1798 |
% \qq {\bf if} $\it tab\_state = tab\_limitState$ {\bf then} |
| 1799 |
% $\it tab\_state=tab\_loopState$; \\ |
| 1800 |
% \qq {\bf if} $\it tab\_state = tab\_preSpcState$ {\bf then} \\ |
| 1801 |
% \qq \qq {\bf if} $\it tab\_initRule$ {\bf then} \\ |
| 1802 |
% \qq \qq \qq $\it tab\_initRule = {\bf false}$; \\ |
| 1803 |
% \qq \qq {\bf else} \\ |
| 1804 |
% \qq \qq \qq {\bf if} $\it tab\_inMultiCol$ {\bf then moan}; \\ |
| 1805 |
% \qq \qq \qq $\it commit$; \\ |
| 1806 |
% \qq \qq \qq $\it append(tab\_shortLine,\hbox{`|&\omit|')}$; \\ |
| 1807 |
% \qq \qq {\bf end\,if}; \\ |
| 1808 |
% \qq {\bf end\,if}; \\ |
| 1809 |
% \qq {\bf if} $\it tab\_state \ne s$ {\bf then} |
| 1810 |
% $\it do\_default(tab\_state)$; \\ |
| 1811 |
% {\bf end\,while}; |
| 1812 |
% \end{quote} |
| 1813 |
% |
| 1814 |
% First we decide if there's anything to do. If so, we call another macro to |
| 1815 |
% do it for us. |
| 1816 |
% |
| 1817 |
% \begin{macrocode} |
| 1818 |
\def\tab@setstate#1{% |
| 1819 |
\ifnum#1=\tab@state\else% |
| 1820 |
\def\@tempa{\tab@setstate@i{#1}}% |
| 1821 |
\@tempa% |
| 1822 |
\fi% |
| 1823 |
} |
| 1824 |
% \end{macrocode} |
| 1825 |
% |
| 1826 |
% This is where the fun is. First we bump the state by one, and loop back |
| 1827 |
% if we fall off the end. |
| 1828 |
% |
| 1829 |
% \begin{macrocode} |
| 1830 |
\def\tab@setstate@i#1{% |
| 1831 |
\global\advance\tab@state\@ne% |
| 1832 |
\ifnum\tab@state>\tab@limitstate% |
| 1833 |
\global\tab@state\tab@loopstate% |
| 1834 |
\fi% |
| 1835 |
% \end{macrocode} |
| 1836 |
% |
| 1837 |
% Now, if we've just passed the ruleoff state, we commit the current text |
| 1838 |
% \emph{unless} this was the strange initial rule at the very beginning. We |
| 1839 |
% provide a little hook here so that |\multicolumn| can moan if you try and |
| 1840 |
% give more than one column there. We also add another tab/omit pair to the |
| 1841 |
% list we use for |\vgap|. |
| 1842 |
% |
| 1843 |
% \begin{macrocode} |
| 1844 |
\ifnum\tab@state=\tab@prespcstate% |
| 1845 |
\iftab@initrule% |
| 1846 |
\tab@initrulefalse% |
| 1847 |
\else% |
| 1848 |
\tab@looped% |
| 1849 |
\tab@commit% |
| 1850 |
\tab@append\tab@shortline{&\omit}% |
| 1851 |
\fi% |
| 1852 |
\fi% |
| 1853 |
% \end{macrocode} |
| 1854 |
% |
| 1855 |
% Now we decide whether to go round again. If not, we do the default thing |
| 1856 |
% for this state. This is mainly here so that we can put the |\tabcolsep| or |
| 1857 |
% whatever in if the user didn't give an \lit{@} expression. |
| 1858 |
% |
| 1859 |
% \begin{macrocode} |
| 1860 |
\ifnum#1=\tab@state% |
| 1861 |
\let\@tempa\relax% |
| 1862 |
\else% |
| 1863 |
\csname tab@default@\number\tab@state\endcsname% |
| 1864 |
\fi% |
| 1865 |
\@tempa% |
| 1866 |
} |
| 1867 |
% \end{macrocode} |
| 1868 |
% |
| 1869 |
% \end{macro} |
| 1870 |
% |
| 1871 |
% Now we set up the default actions for the various states. |
| 1872 |
% |
| 1873 |
% In state~2 (pre-space) we add in the default gap if either we didn't have |
| 1874 |
% an \lit{@} expression in the post-space state or there was an explicit |
| 1875 |
% intervening rule. |
| 1876 |
% |
| 1877 |
% \begin{macrocode} |
| 1878 |
\@namedef{tab@default@2}{% |
| 1879 |
\iftab@rule% |
| 1880 |
\tab@append\tab@pretext{\hskip\col@sep}% |
| 1881 |
\fi% |
| 1882 |
} |
| 1883 |
% \end{macrocode} |
| 1884 |
% |
| 1885 |
% If the user omits the column type, we insert an `l'-type column and moan |
| 1886 |
% a lot. |
| 1887 |
% |
| 1888 |
% \begin{macrocode} |
| 1889 |
\@namedef{tab@default@4}{% |
| 1890 |
\tab@err@misscol% |
| 1891 |
\tab@append\tab@pretext{\tab@bgroup\relax}% |
| 1892 |
\tab@append\tab@posttext{\relax\tab@egroup\hfil}% |
| 1893 |
\tab@append\tab@shortline{\hfil}% |
| 1894 |
\advance\tab@columns\@ne% |
| 1895 |
} |
| 1896 |
% \end{macrocode} |
| 1897 |
% |
| 1898 |
% Finally we deal with the post-space state. We set a marker so that we |
| 1899 |
% put in the default space in the pre-space state later too. |
| 1900 |
% |
| 1901 |
% \begin{macrocode} |
| 1902 |
\@namedef{tab@default@6}{% |
| 1903 |
\tab@append\tab@posttext{\hskip\col@sep}% |
| 1904 |
\tab@ruletrue% |
| 1905 |
} |
| 1906 |
% \end{macrocode} |
| 1907 |
% |
| 1908 |
% |
| 1909 |
% \subsection{Declaring token types} |
| 1910 |
% |
| 1911 |
% \begin{macro}{\tab@extracol} |
| 1912 |
% |
| 1913 |
% Before we start, we need to handle |\extracolsep|. This is a right pain, |
| 1914 |
% because the original version of \env{tabular} worked on total expansion, |
| 1915 |
% which is a Bad Thing. On the other hand, turning |\extracolsep| into a |
| 1916 |
% |\tabskip| is also a major pain. |
| 1917 |
% |
| 1918 |
% \begin{macrocode} |
| 1919 |
\def\tab@extracol#1#2{\tab@extracol@i#1#2\extracolsep{}\extracolsep\end} |
| 1920 |
\def\tab@extracol@i#1#2\extracolsep#3#4\extracolsep#5\end{% |
| 1921 |
\ifx @#3@% |
| 1922 |
\def\@tempa{#1{#2}}% |
| 1923 |
\else% |
| 1924 |
\def\@tempa{#1{#2\tabskip#3\relax#4}}% |
| 1925 |
\fi% |
| 1926 |
\@tempa% |
| 1927 |
} |
| 1928 |
% \end{macrocode} |
| 1929 |
% |
| 1930 |
% \end{macro} |
| 1931 |
% |
| 1932 |
% This is where we do the work for inserting preamble elements. |
| 1933 |
% |
| 1934 |
% \begin{macro}{\tabruletype} |
| 1935 |
% |
| 1936 |
% Inserting rules is interesting, because we have to decide where to put |
| 1937 |
% them. If this is the funny initial rule, it goes in the pre-text list, |
| 1938 |
% otherwise it goes in the post-text list. We work out what to do first |
| 1939 |
% thing: |
| 1940 |
% |
| 1941 |
% \begin{macrocode} |
| 1942 |
\def\tabruletype#1{\tab@extracol\tabruletype@i{#1}}% |
| 1943 |
\def\tabruletype@i#1{% |
| 1944 |
\iftab@initrule% |
| 1945 |
\let\tab@tok\tab@pretext% |
| 1946 |
\else% |
| 1947 |
\let\tab@tok\tab@posttext% |
| 1948 |
\fi% |
| 1949 |
% \end{macrocode} |
| 1950 |
% |
| 1951 |
% Now if we're already in the rule state, we must have just done a rule. |
| 1952 |
% This means we must put in the |\doublerulesep| space, both here and in the |
| 1953 |
% shortline list. Otherwise we just stick the rule in. |
| 1954 |
% |
| 1955 |
% This is complicated, because |\vgap| needs to be able to remove some bits |
| 1956 |
% of rule. We pass each one to a macro |\tab@ckr|, together with the column |
| 1957 |
% number, which is carefully bumped at the right times, and this macro will |
| 1958 |
% vet the rules and output the appropriate ones. There's lots of extreme |
| 1959 |
% |\expandafter| nastiness as a result. Amazingly, this actually works. |
| 1960 |
% |
| 1961 |
% \begin{macrocode} |
| 1962 |
\ifnum\tab@state=\tab@rulestate% |
| 1963 |
\tab@append\tab@tok{\hskip\doublerulesep\begingroup#1\endgroup}% |
| 1964 |
\expandafter\tab@append\expandafter\tab@shortline\expandafter{% |
| 1965 |
\expandafter\hskip\expandafter\doublerulesep% |
| 1966 |
\expandafter\tab@ckr\expandafter{\the\tab@columns}% |
| 1967 |
{\begingroup#1\endgroup}% |
| 1968 |
}% |
| 1969 |
\else% |
| 1970 |
\tab@setstate\tab@rulestate% |
| 1971 |
\tab@append\tab@tok{\begingroup#1\endgroup}% |
| 1972 |
\expandafter\tab@append\expandafter\tab@shortline\expandafter{% |
| 1973 |
\expandafter\tab@ckr\expandafter{\the\tab@columns}% |
| 1974 |
{\begingroup#1\endgroup}% |
| 1975 |
}% |
| 1976 |
\fi% |
| 1977 |
% \end{macrocode} |
| 1978 |
% |
| 1979 |
% Finally, we say there was a rule here, so that default space gets put in |
| 1980 |
% after this. Otherwise we lose lots of generality. |
| 1981 |
% |
| 1982 |
% \begin{macrocode} |
| 1983 |
\tab@ruletrue% |
| 1984 |
} |
| 1985 |
% \end{macrocode} |
| 1986 |
% |
| 1987 |
% \end{macro} |
| 1988 |
% |
| 1989 |
% \begin{macro}{\tabspctype} |
| 1990 |
% |
| 1991 |
% We need to work out which space-state we should be in. Then we just put |
| 1992 |
% the text in. Easy, really. |
| 1993 |
% |
| 1994 |
% \begin{macrocode} |
| 1995 |
\def\tabspctype#1{\tab@extracol\tabspctype@i{#1}}% |
| 1996 |
\def\tabspctype@i#1{% |
| 1997 |
\tab@rulefalse% |
| 1998 |
\ifnum\tab@state>\tab@prespcstate% |
| 1999 |
\tab@setstate\tab@postspcstate% |
| 2000 |
\let\tab@tok\tab@posttext% |
| 2001 |
\else% |
| 2002 |
\tab@setstate\tab@prespcstate% |
| 2003 |
\let\tab@tok\tab@pretext% |
| 2004 |
\fi% |
| 2005 |
\tab@append\tab@tok{\begingroup#1\endgroup}% |
| 2006 |
} |
| 2007 |
% \end{macrocode} |
| 2008 |
% |
| 2009 |
% \end{macro} |
| 2010 |
% |
| 2011 |
% \begin{macro}{\tabcoltype} |
| 2012 |
% |
| 2013 |
% If we're already in the column state, we bump the state and loop round |
| 2014 |
% again, to get all the appropriate default behaviour. We bump the column |
| 2015 |
% counter, and add the bits of text we were given to appropriate token lists. |
| 2016 |
% We also add the |\hfil| glue to the shortline list, to space out the rules |
| 2017 |
% properly. |
| 2018 |
% |
| 2019 |
% \begin{macrocode} |
| 2020 |
\def\tabcoltype#1#2{% |
| 2021 |
\ifnum\tab@state=\tab@colstate% |
| 2022 |
\global\advance\tab@state\@ne% |
| 2023 |
\fi% |
| 2024 |
\advance\tab@columns\@ne% |
| 2025 |
\tab@setstate\tab@colstate% |
| 2026 |
\tab@append\tab@pretext{#1}% |
| 2027 |
\tab@append\tab@posttext{#2}% |
| 2028 |
\tab@append\tab@shortline{\hfil}% |
| 2029 |
} |
| 2030 |
% \end{macrocode} |
| 2031 |
% |
| 2032 |
% \end{macro} |
| 2033 |
% |
| 2034 |
% \begin{macro}{\tabuserpretype} |
| 2035 |
% \begin{macro}{\tabuserposttype} |
| 2036 |
% |
| 2037 |
% These are both utterly trivial. |
| 2038 |
% |
| 2039 |
% \begin{macrocode} |
| 2040 |
\def\tabuserpretype#1{% |
| 2041 |
\tab@setstate\tab@prestate% |
| 2042 |
\tab@prepend\tab@userpretext{#1}% |
| 2043 |
} |
| 2044 |
% \end{macrocode} |
| 2045 |
% |
| 2046 |
% \begin{macrocode} |
| 2047 |
\def\tabuserposttype#1{% |
| 2048 |
\tab@setstate\tab@poststate% |
| 2049 |
\tab@prepend\tab@posttext{#1}% |
| 2050 |
} |
| 2051 |
% \end{macrocode} |
| 2052 |
% |
| 2053 |
% \end{macro} |
| 2054 |
% \end{macro} |
| 2055 |
% |
| 2056 |
% |
| 2057 |
% \subsection{The colset stack} |
| 2058 |
% |
| 2059 |
% Let's start with something fairly easy. We'll keep a stack of column sets |
| 2060 |
% so that users don't get confused by package authors changing the current |
| 2061 |
% column set. This is fairly easy, really. |
| 2062 |
% |
| 2063 |
% \begin{macro}{\tab@push} |
| 2064 |
% \begin{macro}{\tab@pop} |
| 2065 |
% \begin{macro}{\tab@head} |
| 2066 |
% |
| 2067 |
% These are the stack management routines. The only important thing to note |
| 2068 |
% is that |\tab@head| must take place \emph{only} in \TeX's mouth, so we can |
| 2069 |
% use it in |\csname|\dots|\endcsname| constructions. |
| 2070 |
% |
| 2071 |
% \begin{macrocode} |
| 2072 |
\def\tab@push#1#2{% |
| 2073 |
\toks@{{#2}}% |
| 2074 |
\expandafter\def\expandafter#1\expandafter{\the\expandafter\toks@#1}% |
| 2075 |
} |
| 2076 |
\def\tab@pop#1{\expandafter\def\expandafter#1\expandafter{\@gobble#1}} |
| 2077 |
\def\tab@head#1{\expandafter\tab@head@i#1\relax} |
| 2078 |
\def\tab@head@i#1#2\relax{#1} |
| 2079 |
% \end{macrocode} |
| 2080 |
% |
| 2081 |
% \end{macro} |
| 2082 |
% \end{macro} |
| 2083 |
% \end{macro} |
| 2084 |
% |
| 2085 |
% \begin{macro}{\colset} |
| 2086 |
% \begin{macro}{\colpush} |
| 2087 |
% \begin{macro}{\colpop} |
| 2088 |
% |
| 2089 |
% Now we can define the user macros. |
| 2090 |
% |
| 2091 |
% \begin{macrocode} |
| 2092 |
\def\tab@colstack{{tabular}} |
| 2093 |
\def\colset{\colpop\colpush} |
| 2094 |
\def\colpush{\tab@push\tab@colstack} |
| 2095 |
\def\colpop{\tab@pop\tab@colstack} |
| 2096 |
% \end{macrocode} |
| 2097 |
% |
| 2098 |
% \end{macro} |
| 2099 |
% \end{macro} |
| 2100 |
% \end{macro} |
| 2101 |
% |
| 2102 |
% \begin{macro}{\tab@colset} |
| 2103 |
% |
| 2104 |
% Now we define a shortcut for reading the top item off the stack. |
| 2105 |
% |
| 2106 |
% \begin{macrocode} |
| 2107 |
\def\tab@colset{\tab@head\tab@colstack} |
| 2108 |
% \end{macrocode} |
| 2109 |
% |
| 2110 |
% \end{macro} |
| 2111 |
% |
| 2112 |
% |
| 2113 |
% \subsection{The main parser routine} |
| 2114 |
% |
| 2115 |
% \begin{macro}{\tab@initread} |
| 2116 |
% |
| 2117 |
% This macro sets up lots of variables to their normal states prior to |
| 2118 |
% parsing a preamble. Some things may need changing, but not many. |
| 2119 |
% |
| 2120 |
% \begin{macrocode} |
| 2121 |
\def\tab@initread{% |
| 2122 |
% \end{macrocode} |
| 2123 |
% |
| 2124 |
% First, reset the parser state to the start state. |
| 2125 |
% |
| 2126 |
% \begin{macrocode} |
| 2127 |
\global\tab@state\tab@startstate% |
| 2128 |
% \end{macrocode} |
| 2129 |
% |
| 2130 |
% We clear the token lists to sensible values, mostly. The midtext macro |
| 2131 |
% contains what to put in the very middle of each template -- |\multicolumn| |
| 2132 |
% will insert its argument here. |
| 2133 |
% |
| 2134 |
% \begin{macrocode} |
| 2135 |
\tab@preamble{}% |
| 2136 |
\tab@shortline{}% |
| 2137 |
\def\tab@tabtext{&}% |
| 2138 |
\def\tab@midtext{\ignorespaces####\@maybe@unskip}% |
| 2139 |
\tab@pretext{}% |
| 2140 |
\tab@userpretext{}% |
| 2141 |
\tab@posttext{}% |
| 2142 |
\let\tab@multicol\@empty% |
| 2143 |
\def\tab@startpause{\penalty\postdisplaypenalty\medskip}% |
| 2144 |
\def\tab@endpause{\penalty\predisplaypenalty\medskip}% |
| 2145 |
% \end{macrocode} |
| 2146 |
% |
| 2147 |
% Finally, reset the column counter, don't raise errors when we loop, and set |
| 2148 |
% some parser flags to their appropriate values. |
| 2149 |
% |
| 2150 |
% \begin{macrocode} |
| 2151 |
\tab@columns\z@% |
| 2152 |
\let\tab@looped\relax% |
| 2153 |
\tab@ruletrue% |
| 2154 |
\tab@initruletrue% |
| 2155 |
\tab@firstcoltrue% |
| 2156 |
} |
| 2157 |
% \end{macrocode} |
| 2158 |
% |
| 2159 |
% \end{macro} |
| 2160 |
% |
| 2161 |
% \begin{macro}{\tab@readpreamble} |
| 2162 |
% |
| 2163 |
% This is the main macro for preamble handling. Actually, all it does is |
| 2164 |
% gobble its argument's leading brace and call another macro, but it does it |
| 2165 |
% with style. |
| 2166 |
% |
| 2167 |
% \begin{macrocode} |
| 2168 |
\def\tab@readpreamble#1{% |
| 2169 |
\tab@doreadpream{#1}% |
| 2170 |
\iftab@initrule\global\tab@state\tab@prespcstate\fi% |
| 2171 |
\tab@setstate\tab@rulestate% |
| 2172 |
\tab@commit% |
| 2173 |
} |
| 2174 |
% \end{macrocode} |
| 2175 |
% |
| 2176 |
% \end{macro} |
| 2177 |
% |
| 2178 |
% \begin{macro}{\tab@doreadpream} |
| 2179 |
% |
| 2180 |
% The preamble is in an argument. Previous versions used a nasty trick using |
| 2181 |
% |\let| and |\afterassignment|. Now we use an explicit end token, to allow |
| 2182 |
% dodgy column type handlers to scoop up the remaining preamble tokens |
| 2183 |
% and process them. Not that anyone would want to do that, oh no (see |
| 2184 |
% the \lit{[} type in the \env{eqnarray} environment |;-)|). |
| 2185 |
% |
| 2186 |
% \begin{macrocode} |
| 2187 |
\def\tab@doreadpream#1{\tab@mkpreamble#1\q@delim} |
| 2188 |
% \end{macrocode} |
| 2189 |
% |
| 2190 |
% \end{macro} |
| 2191 |
% |
| 2192 |
% \begin{macro}{\tab@mkpreamble} |
| 2193 |
% |
| 2194 |
% This is the main parser routine. It takes each token in turn, scrutinises |
| 2195 |
% it carefully, and does the appropriate thing with it. |
| 2196 |
% |
| 2197 |
% The preamble was given as an argument to |\tab@doreadpream|, and that has |
| 2198 |
% helpfully stripped off the initial |{| character. We need to pick off the |
| 2199 |
% next token (whatever it is) so we can examine it. We'll use |\futurelet| |
| 2200 |
% so we can detect groups and things in funny places. |
| 2201 |
% |
| 2202 |
% \begin{macrocode} |
| 2203 |
\def\tab@mkpreamble{\futurelet\@let@token\tab@mkpreamble@i} |
| 2204 |
% \end{macrocode} |
| 2205 |
% |
| 2206 |
% If we find a space token, we'll go off and do something a bit special, |
| 2207 |
% since spaces are sort of hard to handle. Otherwise we'll do it in the old |
| 2208 |
% fashioned way. |
| 2209 |
% |
| 2210 |
% \begin{macrocode} |
| 2211 |
\def\tab@mkpreamble@i{% |
| 2212 |
\ifx\@let@token\@sptoken% |
| 2213 |
\expandafter\tab@mkpreamble@spc% |
| 2214 |
\else% |
| 2215 |
\expandafter\tab@mkpreamble@ii% |
| 2216 |
\fi% |
| 2217 |
} |
| 2218 |
% \end{macrocode} |
| 2219 |
% |
| 2220 |
% If we find a |\@@endpreamble| token, that's it and we're finished. We just |
| 2221 |
% gobble it and return. Otherwise, if it's an open group character, we'll |
| 2222 |
% complain because someone's probably tried to put an argument in the wrong |
| 2223 |
% place. Finally, if none of the other things apply, we'll deal with the |
| 2224 |
% character below. |
| 2225 |
% |
| 2226 |
% \begin{macrocode} |
| 2227 |
\def\tab@mkpreamble@ii{% |
| 2228 |
\ifx\@let@token\q@delim% |
| 2229 |
\def\@tempa{\let\@let@token}% |
| 2230 |
\else% |
| 2231 |
\ifcat\bgroup\noexpand\@let@token% |
| 2232 |
\tab@err@oddgroup% |
| 2233 |
\def\@tempa##1{\tab@mkpreamble}% |
| 2234 |
\else% |
| 2235 |
\let\@tempa\tab@mkpreamble@iii% |
| 2236 |
\fi% |
| 2237 |
\fi% |
| 2238 |
\@tempa% |
| 2239 |
} |
| 2240 |
% \end{macrocode} |
| 2241 |
% |
| 2242 |
% Handle a character. This involves checking to see if it's actually |
| 2243 |
% defined, and then doing it. Doing things this way means we won't get |
| 2244 |
% stranded in mid-preamble unless a package author has blown it. |
| 2245 |
% |
| 2246 |
% \begin{macrocode} |
| 2247 |
\def\tab@mkpreamble@iii#1{% |
| 2248 |
\@ifundefined{\tab@colset!col.\string#1}{% |
| 2249 |
\tab@err@undef{#1}\tab@mkpreamble% |
| 2250 |
}{% |
| 2251 |
\@nameuse{\tab@colset!col.\string#1}% |
| 2252 |
}% |
| 2253 |
} |
| 2254 |
% \end{macrocode} |
| 2255 |
% |
| 2256 |
% If we get given a space character, we'll look up the command name as |
| 2257 |
% before. If no-one's defined the column type we'll just skip it silently, |
| 2258 |
% which lets users do pretty formatting if they like. |
| 2259 |
% |
| 2260 |
% \begin{macrocode} |
| 2261 |
\@namedef{tab@mkpreamble@spc} {% |
| 2262 |
\@ifundefined{\tab@colset!col. }{% |
| 2263 |
\tab@mkpreamble% |
| 2264 |
}{% |
| 2265 |
\@nameuse{\tab@colset!col. }% |
| 2266 |
}% |
| 2267 |
} |
| 2268 |
% \end{macrocode} |
| 2269 |
% |
| 2270 |
% \end{macro} |
| 2271 |
% |
| 2272 |
% \begin{macro}{\coldef} |
| 2273 |
% |
| 2274 |
% Here's how to define column types the nice way. Some dexterity is required |
| 2275 |
% to make everything work right, but it's simple really. |
| 2276 |
% |
| 2277 |
% \begin{macrocode} |
| 2278 |
\def\coldef{\@ifnextchar[\coldef@i{\coldef@i[\tab@colset]}} |
| 2279 |
\def\coldef@i[#1]#2#3#{\coldef@ii[#1]{#2}{#3}} |
| 2280 |
\def\coldef@ii[#1]#2#3#4{% |
| 2281 |
\expandafter\def\csname#1!col.\string#2\endcsname#3{% |
| 2282 |
#4\tab@mkpreamble% |
| 2283 |
}% |
| 2284 |
} |
| 2285 |
% \end{macrocode} |
| 2286 |
% |
| 2287 |
% \end{macro} |
| 2288 |
% |
| 2289 |
% \begin{macro}{\collet} |
| 2290 |
% |
| 2291 |
% We'd like to let people copy column types from other places. This is how |
| 2292 |
% to do it. |
| 2293 |
% |
| 2294 |
% \begin{macrocode} |
| 2295 |
\def\collet{\@ifnextchar[\collet@i{\collet@i[\tab@colset]}} |
| 2296 |
\def\collet@i[#1]#2{% |
| 2297 |
\@ifnextchar=% |
| 2298 |
{\collet@ii[#1]{#2}}% |
| 2299 |
{\collet@ii[#1]{#2}=}% |
| 2300 |
} |
| 2301 |
\def\collet@ii[#1]#2={% |
| 2302 |
\@ifnextchar[% |
| 2303 |
{\collet@iii[#1]{#2}}% |
| 2304 |
{\collet@iii[#1]{#2}[\tab@colset]}% |
| 2305 |
} |
| 2306 |
\def\collet@iii[#1]#2[#3]#4{% |
| 2307 |
\expandafter\let\csname#1!col.\string#2\expandafter\endcsname% |
| 2308 |
\csname#3!col.\string#4\endcsname% |
| 2309 |
} |
| 2310 |
% \end{macrocode} |
| 2311 |
% |
| 2312 |
% \end{macro} |
| 2313 |
% |
| 2314 |
% \begin{macro}{\newcolumntype} |
| 2315 |
% |
| 2316 |
% We just bundle the text off to |\newcommand| and expect it to cope. It |
| 2317 |
% ought to. The column type code inserts the user's tokens directly, rather |
| 2318 |
% than calling |\tab@doreadpream| recursively. The magic control sequence |
| 2319 |
% is the one looked up by the parser. |
| 2320 |
% |
| 2321 |
% There's some additional magic here for compatiblity with the obscure way |
| 2322 |
% that \package{array} works. |
| 2323 |
% |
| 2324 |
% \begin{macrocode} |
| 2325 |
\def\newcolumntype#1{\@ifnextchar[{\nct@i{#1}}{\nct@i#1[0]}} |
| 2326 |
\def\nct@i#1[#2]{\@ifnextchar[{\nct@ii{#1}[#2]}{\nct@iii{#1}{[#2]}}} |
| 2327 |
\def\nct@ii#1[#2][#3]{\nct@iii{#1}{[#2][#3]}} |
| 2328 |
\def\nct@iii#1#2#3{% |
| 2329 |
\expandafter\let\csname\tab@colset!col.\string#1\endcsname\relax% |
| 2330 |
\expandafter\newcommand\csname\tab@colset!col.\string#1\endcsname#2{% |
| 2331 |
\tab@deepmagic{#1}% |
| 2332 |
\tab@mkpreamble% |
| 2333 |
#3% |
| 2334 |
}% |
| 2335 |
} |
| 2336 |
% \end{macrocode} |
| 2337 |
% |
| 2338 |
% Now for some hacking for compatibility with \package{tabularx}. |
| 2339 |
% |
| 2340 |
% \begin{macrocode} |
| 2341 |
\def\newcol@#1[#2]{\nct@iii{#1}{[#2]}} |
| 2342 |
% \end{macrocode} |
| 2343 |
% |
| 2344 |
% And now some more. This is seriously deep magic. Hence the name. |
| 2345 |
% |
| 2346 |
% \begin{macrocode} |
| 2347 |
\def\tab@deepmagic#1{% |
| 2348 |
\csname NC@rewrite@\string#1\endcsname\NC@find\tab@@magic@@% |
| 2349 |
} |
| 2350 |
\def\NC@find#1\tab@@magic@@{} |
| 2351 |
% \end{macrocode} |
| 2352 |
% |
| 2353 |
% \end{macro} |
| 2354 |
% |
| 2355 |
% |
| 2356 |
% \subsection{Standard column types} |
| 2357 |
% |
| 2358 |
% First, make sure we're setting up the right columns. This also sets the |
| 2359 |
% default for the user. Other packages must not use the |\colset| command |
| 2360 |
% for defining columns -- they should use the stack operations defined above. |
| 2361 |
% |
| 2362 |
% \begin{macrocode} |
| 2363 |
\colset{tabular} |
| 2364 |
% \end{macrocode} |
| 2365 |
% |
| 2366 |
% Now do the simple alignment types. These are fairly simple. The |
| 2367 |
% mysterious kern in the \lit{l} type is to stop the |\col@sep| glue from |
| 2368 |
% vanishing due to the |\unskip| inserted by the standard |\tab@midtext| if |
| 2369 |
% the column contains no text. (Thanks for spotting this bug go to that |
| 2370 |
% nice Mr~Carlisle.) |
| 2371 |
% |
| 2372 |
% \begin{macrocode} |
| 2373 |
\coldef l{\tabcoltype{\kern\z@\tab@bgroup}{\tab@egroup\hfil}} |
| 2374 |
\coldef c{\tabcoltype{\hfil\tab@bgroup}{\tab@egroup\hfil}} |
| 2375 |
\coldef r{\tabcoltype{\hfil\tab@bgroup}{\tab@egroup}} |
| 2376 |
% \end{macrocode} |
| 2377 |
% |
| 2378 |
% Some extensions now. These are explicitly teextual or mathematical |
| 2379 |
% columns. Can be useful if you're providing column types for other people. |
| 2380 |
% I've inserted a kern here for exactly the same reason as for the \lit{l} |
| 2381 |
% column type above. |
| 2382 |
% |
| 2383 |
% \begin{macrocode} |
| 2384 |
\coldef T#1{\tab@aligncol{#1}{\tab@btext}{\tab@etext}} |
| 2385 |
\coldef M#1{\tab@aligncol{#1}{\tab@bmaths}{\tab@emaths}} |
| 2386 |
\def\tab@aligncol#1#2#3{% |
| 2387 |
\if#1l\tabcoltype{\kern\z@#2}{#3\hfil}\fi% |
| 2388 |
\if#1c\tabcoltype{\hfil#2}{#3\hfil}\fi% |
| 2389 |
\if#1r\tabcoltype{\hfil#2}{#3}\fi% |
| 2390 |
} |
| 2391 |
% \end{macrocode} |
| 2392 |
% |
| 2393 |
% Now for the default rules. |
| 2394 |
% |
| 2395 |
% \begin{macrocode} |
| 2396 |
\coldef |{\tabruletype{\vrule\@width\arrayrulewidth}} |
| 2397 |
\coldef !#1{\tabruletype{#1}} |
| 2398 |
% \end{macrocode} |
| 2399 |
% |
| 2400 |
% Deal with \lit{@} expressions. |
| 2401 |
% |
| 2402 |
% \begin{macrocode} |
| 2403 |
\coldef @#1{\tabspctype{#1}} |
| 2404 |
% \end{macrocode} |
| 2405 |
% |
| 2406 |
% And the paragraph types. I've added things to handle footnotes here. |
| 2407 |
% |
| 2408 |
% \begin{macrocode} |
| 2409 |
\coldef p#1{\tabcoltype% |
| 2410 |
{\savenotes\vtop\tab@bpar{#1}}% |
| 2411 |
{\tab@epar\spewnotes\hfil}} |
| 2412 |
\coldef m#1{\tabcoltype% |
| 2413 |
{\savenotes$\vcenter\tab@bpar{#1}}% |
| 2414 |
{\tab@epar$\spewnotes\hfil}} |
| 2415 |
\coldef b#1{\tabcoltype% |
| 2416 |
{\savenotes\vbox\tab@bpar{#1}}% |
| 2417 |
{\tab@epar\spewnotes\hfil}} |
| 2418 |
% \end{macrocode} |
| 2419 |
% |
| 2420 |
% Phew. Only a few more left now. The user text ones. |
| 2421 |
% |
| 2422 |
% \begin{macrocode} |
| 2423 |
\coldef >#1{\tabuserpretype{#1}} |
| 2424 |
\coldef <#1{\tabuserposttype{#1}} |
| 2425 |
% \end{macrocode} |
| 2426 |
% |
| 2427 |
% The strange column type. |
| 2428 |
% |
| 2429 |
% \begin{macrocode} |
| 2430 |
\coldef ##1#2{\tabcoltype{#1}{#2}} |
| 2431 |
% \end{macrocode} |
| 2432 |
% |
| 2433 |
% And \lit{*}, which repeats a preamble spec. This is really easy, and not |
| 2434 |
% at all like the original one. |
| 2435 |
% |
| 2436 |
% \begin{macrocode} |
| 2437 |
\coldef *#1#2{% |
| 2438 |
\count@#1% |
| 2439 |
\loop\ifnum\count@>0\relax% |
| 2440 |
\tab@doreadpream{#2}% |
| 2441 |
\advance\count@\m@ne% |
| 2442 |
\repeat% |
| 2443 |
} |
| 2444 |
% \end{macrocode} |
| 2445 |
% |
| 2446 |
% |
| 2447 |
% \subsection{Paragraph handling} |
| 2448 |
% |
| 2449 |
% First of all, starting new paragraphs: the vbox token is already there, and |
| 2450 |
% we have the width as an argument. |
| 2451 |
% |
| 2452 |
% \begin{macro}{\tab@bpar} |
| 2453 |
% |
| 2454 |
% There are some gymnastics to do here to support lists which form the |
| 2455 |
% complete text of the parbox. One of the odd things I'll do here is to |
| 2456 |
% not insert a strut on the first line: instead, I'll put the text into a |
| 2457 |
% box register so that I can inspect it later. So that I have access to |
| 2458 |
% the height of the first line, I'll use a |\vtop| -- I can get at the |
| 2459 |
% final depth by using |\prevdepth|, so this seems to be the most general |
| 2460 |
% solution. |
| 2461 |
% |
| 2462 |
% \begin{macrocode} |
| 2463 |
\def\tab@bpar#1{% |
| 2464 |
\bgroup% |
| 2465 |
\hsize#1\relax% |
| 2466 |
\@arrayparboxrestore% |
| 2467 |
\setbox\z@\vtop\bgroup |
| 2468 |
\global\@minipagetrue% |
| 2469 |
\everypar{% |
| 2470 |
\global\@minipagefalse% |
| 2471 |
\everypar{}% |
| 2472 |
}% |
| 2473 |
} |
| 2474 |
% \end{macrocode} |
| 2475 |
% |
| 2476 |
% \end{macro} |
| 2477 |
% |
| 2478 |
% \begin{macro}{\tab@epar} |
| 2479 |
% |
| 2480 |
% To end the paragraph, close the box. That sounds easy, doesn't it? |
| 2481 |
% I need to space out the top and bottom of the box so that it looks as if |
| 2482 |
% struts have been applied. |
| 2483 |
% |
| 2484 |
% \begin{macrocode} |
| 2485 |
\def\tab@epar{% |
| 2486 |
% \end{macrocode} |
| 2487 |
% |
| 2488 |
% Anyway, I should end the current paragraph if I'm still in horizontal |
| 2489 |
% mode. A simple |\par| will do this nicely. I'll also remove any trailing |
| 2490 |
% vertical glue (which may be left there by a list environment), because |
| 2491 |
% things will look very strange otherwise. |
| 2492 |
% |
| 2493 |
% \begin{macrocode} |
| 2494 |
\ifhmode\@maybe@unskip\par\fi% |
| 2495 |
\unskip% |
| 2496 |
% \end{macrocode} |
| 2497 |
% |
| 2498 |
% Now I'll look at the depth of the last box: if it's less deep than my |
| 2499 |
% special strut, I'll cunningly backpedal by a bit, and add a box with the |
| 2500 |
% appropriate depth. Since this will lie on the previous baseline, it won't |
| 2501 |
% alter the effective height of the box. There's a snag here. |\prevdepth| |
| 2502 |
% may be wrong for example if the last thing inserted was a rule, or the |
| 2503 |
% box is just empty. Check for this specially. (Thanks to Rowland for |
| 2504 |
% spotting this.) |
| 2505 |
% |
| 2506 |
% \begin{macrocode} |
| 2507 |
\ifdim\prevdepth>-\@m\p@\ifdim\prevdepth<\dp\@arstrutbox% |
| 2508 |
\kern-\prevdepth% |
| 2509 |
\nointerlineskip% |
| 2510 |
\vtop to\dp\@arstrutbox{}% |
| 2511 |
\fi\fi% |
| 2512 |
% \end{macrocode} |
| 2513 |
% |
| 2514 |
% I've finished the bottom of the box now: I'll close it, and start work on |
| 2515 |
% the top again. |
| 2516 |
% |
| 2517 |
% \begin{macrocode} |
| 2518 |
\egroup% |
| 2519 |
% \end{macrocode} |
| 2520 |
% |
| 2521 |
% For top-alignment to work, the first item in the box must be another box. |
| 2522 |
% (This is why I couldn't just set |\prevdepth| at the beginning.) If the |
| 2523 |
% box isn't high enough, I'll add a box of the right height and then kern |
| 2524 |
% backwards so that the `real' first box ends up in the right place. |
| 2525 |
% |
| 2526 |
% \begin{macrocode} |
| 2527 |
\ifdim\ht\z@<\ht\@arstrutbox% |
| 2528 |
\vbox to\ht\@arstrutbox{}% |
| 2529 |
\kern-\ht\z@% |
| 2530 |
\fi% |
| 2531 |
\unvbox\z@% |
| 2532 |
\egroup% |
| 2533 |
} |
| 2534 |
% \end{macrocode} |
| 2535 |
% |
| 2536 |
% \end{macro} |
| 2537 |
% |
| 2538 |
% |
| 2539 |
% \subsection{Gentle persuasion} |
| 2540 |
% |
| 2541 |
% To persuade \package{longtable} to work, we emulate some features of |
| 2542 |
% the \package{array} way of doing things. It's a shame, but we have to do |
| 2543 |
% it, because \package{longtable} came first. |
| 2544 |
% |
| 2545 |
% Note the horribleness with the grouping here. In order to get everything |
| 2546 |
% expanded at the right time, |\@preamble| just replaces itself with the (not |
| 2547 |
% expanded!) preamble string, using |\the|. This means that the preamble |
| 2548 |
% string must be visible in the group just above us. Now, |
| 2549 |
% \package{longtable} (and \package{array} for that matter) does |
| 2550 |
% |\@mkpreamble| immediately after opening a new group. So all we need to do |
| 2551 |
% is close that group, do our stuff, and reopen the group again. (Evil |
| 2552 |
% laughter\dots) |
| 2553 |
% |
| 2554 |
% \begin{macrocode} |
| 2555 |
\def\@mkpream#1{% |
| 2556 |
\endgroup% |
| 2557 |
\colset{tabular}% |
| 2558 |
\tab@initread% |
| 2559 |
\def\tab@multicol{\@arstrut}% |
| 2560 |
\tab@preamble{\tab@multicol}% |
| 2561 |
\def\tab@midtext{\ignorespaces\@sharp\@sharp\@maybe@unskip}% |
| 2562 |
\tab@readpreamble{#1}% |
| 2563 |
\gdef\@preamble{\the\tab@preamble}% |
| 2564 |
\let\tab@bgroup\begingroup% |
| 2565 |
\let\tab@egroup\endgroup% |
| 2566 |
\begingroup% |
| 2567 |
} |
| 2568 |
% \end{macrocode} |
| 2569 |
% |
| 2570 |
% |
| 2571 |
% \subsection{Debugging} |
| 2572 |
% |
| 2573 |
% This macro just parses a preamble and displays it on the terminal. It |
| 2574 |
% means I can see whether the thing's working. |
| 2575 |
% |
| 2576 |
% \begin{macrocode} |
| 2577 |
\def\showpream#1{% |
| 2578 |
\tab@initread% |
| 2579 |
\tab@readpreamble{#1}% |
| 2580 |
\showthe\tab@preamble% |
| 2581 |
\showthe\tab@shortline% |
| 2582 |
} |
| 2583 |
% \end{macrocode} |
| 2584 |
% |
| 2585 |
% A quick macro for showing column types. |
| 2586 |
% |
| 2587 |
% \begin{macrocode} |
| 2588 |
\def\showcol#1{% |
| 2589 |
\expandafter\show\csname\tab@colset!col.\string#1\endcsname% |
| 2590 |
} |
| 2591 |
% \end{macrocode} |
| 2592 |
% |
| 2593 |
% |
| 2594 |
% \subsection{The \env{tabular} and \env{array} environments} |
| 2595 |
% |
| 2596 |
% This is where we define the actual environments which users play with. |
| 2597 |
% |
| 2598 |
% \subsubsection{The environment routines} |
| 2599 |
% |
| 2600 |
% The real work is done in the |\@array| macro later. We just set up lots |
| 2601 |
% (and I mean \emph{lots}) of parameters first, and then call |\@array|. |
| 2602 |
% |
| 2603 |
% \begin{macro}{\tab@array} |
| 2604 |
% |
| 2605 |
% The |\tab@array| macro does most of the common array things. |
| 2606 |
% |
| 2607 |
% \begin{macrocode} |
| 2608 |
\def\tab@array{% |
| 2609 |
\tab@width\z@% |
| 2610 |
\let\tab@bgroup\tab@bmaths% |
| 2611 |
\let\tab@egroup\tab@emaths% |
| 2612 |
\@tabarray% |
| 2613 |
} |
| 2614 |
% \end{macrocode} |
| 2615 |
% |
| 2616 |
% \end{macro} |
| 2617 |
% |
| 2618 |
% \begin{macro}{\tab@btext} |
| 2619 |
% \begin{macro}{\tab@bmaths} |
| 2620 |
% \begin{macro}{\tab@etext} |
| 2621 |
% \begin{macro}{\tab@emaths} |
| 2622 |
% |
| 2623 |
% These macros contain appropriate things to use when typesetting |
| 2624 |
% text or maths macros. They're all trivial. They're here only for |
| 2625 |
% later modification by funny things like the \env{smarray} environment. |
| 2626 |
% |
| 2627 |
% \begin{macrocode} |
| 2628 |
\def\tab@btext{\begingroup} |
| 2629 |
\def\tab@bmaths{$} |
| 2630 |
\def\tab@etext{\endgroup} |
| 2631 |
\def\tab@emaths{\m@th$} |
| 2632 |
% \end{macrocode} |
| 2633 |
% |
| 2634 |
% \end{macro} |
| 2635 |
% \end{macro} |
| 2636 |
% \end{macro} |
| 2637 |
% \end{macro} |
| 2638 |
% |
| 2639 |
% \begin{environment}{array} |
| 2640 |
% |
| 2641 |
% Now for the \env{array} environment. The `|$|' signs act as a group, so we |
| 2642 |
% don't need to do extra grouping this time. Closing the environment is |
| 2643 |
% easy. |
| 2644 |
% |
| 2645 |
% \begin{macrocode} |
| 2646 |
\def\array{% |
| 2647 |
\col@sep\arraycolsep% |
| 2648 |
\let\tab@extrasep\arrayextrasep% |
| 2649 |
\tab@normalstrut% |
| 2650 |
\tab@array% |
| 2651 |
} |
| 2652 |
\def\endarray{% |
| 2653 |
\crcr% |
| 2654 |
\egroup% |
| 2655 |
\tab@right% |
| 2656 |
\tab@restorehlstate% |
| 2657 |
} |
| 2658 |
% \end{macrocode} |
| 2659 |
% |
| 2660 |
% \end{environment} |
| 2661 |
% |
| 2662 |
% \begin{environment}{smarray} |
| 2663 |
% |
| 2664 |
% Now for something a little different. The \env{smarray} environment |
| 2665 |
% gives you an array with lots of small text. |
| 2666 |
% |
| 2667 |
% \begin{macrocode} |
| 2668 |
\def\smarray{% |
| 2669 |
\extrarowheight\z@% |
| 2670 |
\col@sep\smarraycolsep% |
| 2671 |
\let\tab@extrasep\smarrayextrasep% |
| 2672 |
\def\tab@bmaths{$\scriptstyle}% |
| 2673 |
\def\tab@btext{\begingroup\scriptsize}% |
| 2674 |
\setbox\z@\hbox{\scriptsize\strut}% |
| 2675 |
\dimen@\ht\z@\dimen\tw@\dp\z@\tab@setstrut% |
| 2676 |
\tab@array% |
| 2677 |
} |
| 2678 |
\let\endsmarray\endarray |
| 2679 |
% \end{macrocode} |
| 2680 |
% |
| 2681 |
% \end{environment} |
| 2682 |
% |
| 2683 |
% \begin{macro}{\tabstyle} |
| 2684 |
% |
| 2685 |
% This is a little hook that document designers can use to modify the |
| 2686 |
% appearance of tables throughout a document. For example, I've set it to |
| 2687 |
% make the text size |\small| in all tables in this document. Macro writers |
| 2688 |
% shouldn't try to use it as a hook for their own evilness, though. I've |
| 2689 |
% used |\providecommand| to avoid nobbling an existing definition. |
| 2690 |
% |
| 2691 |
% \begin{macrocode} |
| 2692 |
\providecommand\tabstyle{} |
| 2693 |
% \end{macrocode} |
| 2694 |
% |
| 2695 |
% \end{macro} |
| 2696 |
% |
| 2697 |
% \begin{macro}{\@tabular} |
| 2698 |
% |
| 2699 |
% The two \env{tabular} environments share lots of common code, so we |
| 2700 |
% separate that out. (This needs to be done better.) All we really do here |
| 2701 |
% is set up the |\tab@bgroup| and |\tab@egroup| to localise things properly, |
| 2702 |
% and then go. |
| 2703 |
% |
| 2704 |
% \begin{macrocode} |
| 2705 |
\def\@tabular#1{% |
| 2706 |
\tabstyle% |
| 2707 |
\tab@width#1% |
| 2708 |
\let\tab@bgroup\tab@btext% |
| 2709 |
\let\tab@egroup\tab@etext% |
| 2710 |
\col@sep\tabcolsep% |
| 2711 |
\let\tab@extrasep\tabextrasep% |
| 2712 |
\tab@normalstrut% |
| 2713 |
\@tabarray% |
| 2714 |
} |
| 2715 |
% \end{macrocode} |
| 2716 |
% |
| 2717 |
% \end{macro} |
| 2718 |
% |
| 2719 |
% \begin{environment}{tabular} |
| 2720 |
% \begin{environment}{tabular*} |
| 2721 |
% |
| 2722 |
% These environments just call a macro which does all the common stuff. |
| 2723 |
% |
| 2724 |
% \begin{macrocode} |
| 2725 |
\def\tabular{\@tabular\z@} |
| 2726 |
\expandafter\let\csname tabular*\endcsname\@tabular |
| 2727 |
\let\endtabular\endarray |
| 2728 |
\expandafter\let\csname endtabular*\endcsname\endarray |
| 2729 |
% \end{macrocode} |
| 2730 |
% |
| 2731 |
% \end{environment} |
| 2732 |
% \end{environment} |
| 2733 |
% |
| 2734 |
% \subsubsection{Setting the strut height} |
| 2735 |
% |
| 2736 |
% \begin{macro}{\tab@setstrut} |
| 2737 |
% |
| 2738 |
% We use a magical strut, called |\@arstrut|, which keeps the table from |
| 2739 |
% collapsing around our heads. This is where we set it up. |
| 2740 |
% |
| 2741 |
% It bases the array strut size on the given values of |\dimen@| and |
| 2742 |
% |\dimen\tw@|, amended by various appropriate fiddle values added in by |
| 2743 |
% various people. |
| 2744 |
% |
| 2745 |
% \begin{macrocode} |
| 2746 |
\def\tab@setstrut{% |
| 2747 |
\setbox\@arstrutbox\hbox{% |
| 2748 |
\vrule% |
| 2749 |
\@height\arraystretch\dimen@% |
| 2750 |
\@depth\arraystretch\dimen\tw@% |
| 2751 |
\@width\z@% |
| 2752 |
}% |
| 2753 |
} |
| 2754 |
% \end{macrocode} |
| 2755 |
% |
| 2756 |
% \end{macro} |
| 2757 |
% |
| 2758 |
% \begin{macro}{\tab@normalstrut} |
| 2759 |
% |
| 2760 |
% This sets the strut the normal way, from the size of |\strutbox|. |
| 2761 |
% |
| 2762 |
% \begin{macrocode} |
| 2763 |
\def\tab@normalstrut{% |
| 2764 |
\dimen@\ht\strutbox\advance\dimen@\extrarowheight% |
| 2765 |
\dimen\tw@\dp\strutbox% |
| 2766 |
\tab@setstrut% |
| 2767 |
} |
| 2768 |
% \end{macrocode} |
| 2769 |
% |
| 2770 |
% \end{macro} |
| 2771 |
% |
| 2772 |
% \subsubsection{Setting up the alignment} |
| 2773 |
% |
| 2774 |
% The following bits are mainly for other packages to hook themselves onto. |
| 2775 |
% |
| 2776 |
% \begin{macrocode} |
| 2777 |
\let\@arrayleft\relax% |
| 2778 |
\let\@arrayright\relax% |
| 2779 |
% \end{macrocode} |
| 2780 |
% |
| 2781 |
% \begin{macrocode} |
| 2782 |
\def\@tabarray{% |
| 2783 |
\let\@arrayleft\relax% |
| 2784 |
\let\@arrayright\relax% |
| 2785 |
\@ifnextchar[\@array{\@array[c]}% |
| 2786 |
} |
| 2787 |
% \end{macrocode} |
| 2788 |
% |
| 2789 |
% \begin{macro}{\@array} |
| 2790 |
% |
| 2791 |
% The |\@array| macro does most of the real work for the environments. The |
| 2792 |
% first job is to set up the row strut, which keeps the table rows at the |
| 2793 |
% right height. We just take the normal strut box, and extend its height by |
| 2794 |
% the |\extrarowheight| length parameter. |
| 2795 |
% |
| 2796 |
% \begin{macrocode} |
| 2797 |
\def\@array[#1]#2{% |
| 2798 |
% \end{macrocode} |
| 2799 |
% |
| 2800 |
% Sort out the hline state variable. We'll store the old value in a |
| 2801 |
% control sequence to avoid wasting any more count registers. |
| 2802 |
% |
| 2803 |
% \begin{macrocode} |
| 2804 |
\edef\tab@restorehlstate{% |
| 2805 |
\global\tab@endheight\the\tab@endheight% |
| 2806 |
\gdef\noexpand\tab@hlstate{\tab@hlstate}% |
| 2807 |
}% |
| 2808 |
\def\tab@hlstate{n}% |
| 2809 |
% \end{macrocode} |
| 2810 |
% |
| 2811 |
% Now we read the preamble. All the clever things we've already done are |
| 2812 |
% terribly useful here. |
| 2813 |
% |
| 2814 |
% The |\tab@setcr| sets up |\\| to be a newline even if users have changed it |
| 2815 |
% using something like |\raggedright|. |
| 2816 |
% |
| 2817 |
% \begin{macrocode} |
| 2818 |
\colset{tabular}% |
| 2819 |
\tab@initread% |
| 2820 |
\def\tab@midtext{\tab@setcr\ignorespaces####\@maybe@unskip}% |
| 2821 |
\def\tab@multicol{\@arstrut\tab@startrow}% |
| 2822 |
\tab@preamble{\tab@multicol\tabskip\z@skip}% |
| 2823 |
\tab@readpreamble{#2}% |
| 2824 |
% \end{macrocode} |
| 2825 |
% |
| 2826 |
% Set up the default tabskip glue. This is easy: there isn't any. |
| 2827 |
% |
| 2828 |
% \begin{macrocode} |
| 2829 |
\tab@leftskip\z@skip% |
| 2830 |
\tab@rightskip\z@skip% |
| 2831 |
% \end{macrocode} |
| 2832 |
% |
| 2833 |
% Now set up the positioning of the table. This is put into a separate macro |
| 2834 |
% because it's rather complicated. |
| 2835 |
% |
| 2836 |
% \begin{macrocode} |
| 2837 |
\tab@setposn{#1}% |
| 2838 |
% \end{macrocode} |
| 2839 |
% |
| 2840 |
% Now work out how to start the alignment. |
| 2841 |
% |
| 2842 |
% \begin{macrocode} |
| 2843 |
\ifdim\tab@width=\z@% |
| 2844 |
\def\tab@halign{}% |
| 2845 |
\else% |
| 2846 |
\def\tab@halign{to\tab@width}% |
| 2847 |
\fi% |
| 2848 |
% \end{macrocode} |
| 2849 |
% |
| 2850 |
% Finally, do all the normal things we need to do before an alignment. Note |
| 2851 |
% that we define |\tabularnewline| first, then set |\\| from that (using |
| 2852 |
% |\tab@setcr|). Since |\\| is reset in the |\tab@midtext| of every table |
| 2853 |
% cell, it becomes secondary to |\tabularnewline|. Doing things this way |
| 2854 |
% avoids the problems with declarations like |\raggedright| which redefine |
| 2855 |
% |\\| in their own (usually rather strange) way, so you don't need to mess |
| 2856 |
% about with things like the |\PreserveBackslash| command given in the |
| 2857 |
% \textit{\LaTeX\ Companion}. |
| 2858 |
% |
| 2859 |
% \begin{macrocode} |
| 2860 |
\lineskip\z@\baselineskip\z@% |
| 2861 |
\m@th% |
| 2862 |
\def\tabularnewline{\tab@arraycr\tab@penalty}% |
| 2863 |
\tab@setcr% |
| 2864 |
\let\par\@empty% |
| 2865 |
\everycr{}\tabskip\tab@leftskip% |
| 2866 |
\tab@left\halign\tab@halign\expandafter\bgroup% |
| 2867 |
\the\tab@preamble\tabskip\tab@rightskip\cr% |
| 2868 |
} |
| 2869 |
% \end{macrocode} |
| 2870 |
% |
| 2871 |
% \end{macro} |
| 2872 |
% |
| 2873 |
% You've no doubt noticed the |\tab@left| and |\tab@right| macros above. |
| 2874 |
% These are set up here and elsewhere to allow other things to gain control |
| 2875 |
% at various points of the table (they include and take the place of the |
| 2876 |
% |\@arrayleft| and |\@arrayright| hooks in \package{array}, put in for |
| 2877 |
% \package{delarray}'s use. |
| 2878 |
% |
| 2879 |
% \subsubsection{Positioning the table} |
| 2880 |
% |
| 2881 |
% \begin{macro}{\tab@setposn} |
| 2882 |
% |
| 2883 |
% This macro sets everything up for the table's positioning. It's rather |
| 2884 |
% long, but not all that complicated. Honest. |
| 2885 |
% |
| 2886 |
% First, we set up some defaults (for centring). If anything goes wrong, we |
| 2887 |
% just do the centring things. |
| 2888 |
% |
| 2889 |
% \begin{macrocode} |
| 2890 |
\def\tab@setposn#1{% |
| 2891 |
\def\tab@left{% |
| 2892 |
\savenotes% |
| 2893 |
\leavevmode\hbox\bgroup$\@arrayleft\vcenter\bgroup% |
| 2894 |
}% |
| 2895 |
\def\tab@right{% |
| 2896 |
\egroup% |
| 2897 |
\m@th\@arrayright$\egroup% |
| 2898 |
\spewnotes% |
| 2899 |
}% |
| 2900 |
\global\tab@endheight\z@% |
| 2901 |
% \end{macrocode} |
| 2902 |
% |
| 2903 |
% For the standard positioning things, we just do appropriate boxing things. |
| 2904 |
% Note that the dollar signs are important, since \package{delarray} might |
| 2905 |
% want to put its delimiters in here. |
| 2906 |
% |
| 2907 |
% The |\if@tempswa| switch it used to decide if we're doing an unboxed |
| 2908 |
% tabular. We'll set it if we find an unbox-type position code, and then |
| 2909 |
% check that everything's OK for this. |
| 2910 |
% |
| 2911 |
% \begin{macrocode} |
| 2912 |
\@tempswafalse% |
| 2913 |
\let\tab@penalty\relax% |
| 2914 |
\if#1t% |
| 2915 |
\def\tab@left{% |
| 2916 |
\savenotes% |
| 2917 |
\leavevmode\setbox\z@\hbox\bgroup$\@arrayleft\vtop\bgroup% |
| 2918 |
}% |
| 2919 |
\def\tab@right{% |
| 2920 |
\egroup% |
| 2921 |
\m@th\@arrayright$\egroup% |
| 2922 |
\tab@raisebase% |
| 2923 |
\spewnotes% |
| 2924 |
}% |
| 2925 |
\gdef\tab@hlstate{t}% |
| 2926 |
\global\tab@endheight\ht\@arstrutbox% |
| 2927 |
\else\if#1b% |
| 2928 |
\def\tab@left{% |
| 2929 |
\savenotes% |
| 2930 |
\leavevmode\setbox\z@\hbox\bgroup$\@arrayleft\vbox\bgroup% |
| 2931 |
}% |
| 2932 |
\def\tab@right{% |
| 2933 |
\egroup% |
| 2934 |
\m@th\@arrayright$\egroup% |
| 2935 |
\tab@lowerbase% |
| 2936 |
\spewnotes% |
| 2937 |
}% |
| 2938 |
\gdef\tab@hlstate{b}% |
| 2939 |
\else% |
| 2940 |
\if#1L\@tempswatrue\fi% |
| 2941 |
\if#1C\@tempswatrue\fi% |
| 2942 |
\if#1R\@tempswatrue\fi% |
| 2943 |
\fi\fi% |
| 2944 |
% \end{macrocode} |
| 2945 |
% |
| 2946 |
% Now for some tests to make sure we're allowed to do the unboxing. We text |
| 2947 |
% for |\@arrayleft| being defined, because people trying to hook us won't |
| 2948 |
% understand unboxed tabulars. |
| 2949 |
% |
| 2950 |
% \begin{macrocode} |
| 2951 |
\if@tempswa\ifhmode% |
| 2952 |
\ifinner\tab@err@unbrh\@tempswafalse\else\par\fi% |
| 2953 |
\fi\fi% |
| 2954 |
\if@tempswa\ifmmode\tab@err@unbmm\@tempswafalse\fi\fi% |
| 2955 |
\if@tempswa\ifx\@arrayleft\relax\else% |
| 2956 |
\tab@err@unbext\@tempswafalse% |
| 2957 |
\fi\fi% |
| 2958 |
% \end{macrocode} |
| 2959 |
% |
| 2960 |
% Finally, if we're still doing an unboxed alignment, we need to sort out the |
| 2961 |
% spacing. We know that no-one's tried to hook on to the environment, so we |
| 2962 |
% clear |\tab@left| and |\tab@right|. |
| 2963 |
% |
| 2964 |
% \begin{macrocode} |
| 2965 |
\if@tempswa% |
| 2966 |
\def\tab@left{\vskip\parskip\medskip}% |
| 2967 |
\def\tab@right{\par\@endpetrue\global\@ignoretrue}% |
| 2968 |
% \end{macrocode} |
| 2969 |
% |
| 2970 |
% Now we need to sort out the alignment. The only way we can do this is by |
| 2971 |
% playing with tabskip glue. There are two possiblities: |
| 2972 |
% |
| 2973 |
% \begin{itemize} |
| 2974 |
% |
| 2975 |
% \item If this is a straight \env{tabular} or an \env{array}, we just use |
| 2976 |
% infinite glue. This is reasonable, I think. |
| 2977 |
% |
| 2978 |
% \item If we have a width for the table, we calculate the fixed values of |
| 2979 |
% glue on either side. This is fairly easy, and forces the table to |
| 2980 |
% the required width. |
| 2981 |
% |
| 2982 |
% \end{itemize} |
| 2983 |
% |
| 2984 |
% First, set up the left and right glues to represent the prevailing |
| 2985 |
% margins set up by \env{list} environments. I think this is the right |
| 2986 |
% thing to do. |
| 2987 |
% |
| 2988 |
% \begin{macrocode} |
| 2989 |
\tab@leftskip\@totalleftmargin% |
| 2990 |
\tab@rightskip\hsize% |
| 2991 |
\advance\tab@rightskip-\linewidth% |
| 2992 |
\advance\tab@rightskip-\@totalleftmargin% |
| 2993 |
% \end{macrocode} |
| 2994 |
% |
| 2995 |
% First of all, deal with the simple case. I'm using 10000\,fill glue here, |
| 2996 |
% in an attempt to suppress |\extracolsep| glue from making the table the |
| 2997 |
% wrong width. It can always use filll glue if it really needs to, though. |
| 2998 |
% |
| 2999 |
% \begin{macrocode} |
| 3000 |
\ifdim\tab@width=\z@% |
| 3001 |
\if#1L\else\advance\tab@leftskip\z@\@plus10000fill\fi% |
| 3002 |
\if#1R\else\advance\tab@rightskip\z@\@plus10000fill\fi% |
| 3003 |
% \end{macrocode} |
| 3004 |
% |
| 3005 |
% Now for the fun bit. This isn't too hard really. The extra space I must |
| 3006 |
% add around the table adds up to $|\linewidth| - |\tab@width|$. I just |
| 3007 |
% need to add this onto the appropriate sides of the table. |
| 3008 |
% |
| 3009 |
% \begin{macrocode} |
| 3010 |
\else% |
| 3011 |
\dimen@\linewidth% |
| 3012 |
\advance\dimen@-\tab@width% |
| 3013 |
\if#1L\advance\tab@rightskip\dimen@\fi% |
| 3014 |
\if#1R\advance\tab@leftskip\dimen@\fi% |
| 3015 |
\if#1C% |
| 3016 |
\advance\[email protected]\dimen@% |
| 3017 |
\advance\[email protected]\dimen@% |
| 3018 |
\fi% |
| 3019 |
\fi% |
| 3020 |
% \end{macrocode} |
| 3021 |
% |
| 3022 |
% Don't allow page breaks. David Carlisle's wonderful \env{longtable} |
| 3023 |
% package does page breaks far better than I could possibly do here, and |
| 3024 |
% we're compatible with it (wahey!). |
| 3025 |
% |
| 3026 |
% \begin{macrocode} |
| 3027 |
\def\tab@penalty{\penalty\@M}% |
| 3028 |
% \end{macrocode} |
| 3029 |
% |
| 3030 |
% Finally, set the new width of the table, and leave. |
| 3031 |
% |
| 3032 |
% \begin{macrocode} |
| 3033 |
\tab@width\hsize% |
| 3034 |
\fi% |
| 3035 |
} |
| 3036 |
% \end{macrocode} |
| 3037 |
% |
| 3038 |
% \end{macro} |
| 3039 |
% |
| 3040 |
% \subsubsection{Handling tops and bottoms} |
| 3041 |
% |
| 3042 |
% This is how the tops and bottoms of tables are made to line up with the |
| 3043 |
% text on the same line, in the presence of arbitrary rules and space. The |
| 3044 |
% old method, based on the way the \package{array} package worked, wasn't |
| 3045 |
% terribly good. This new version copes much better with almost anything |
| 3046 |
% that gets thrown at it. |
| 3047 |
% |
| 3048 |
% I'll keep a state in a macro (|\tab@hlstate|), which tells me what I'm |
| 3049 |
% meant to be doing. The possible values are \lit{n}, which means I don't |
| 3050 |
% have to do anything, \lit{t}, which means that I'm meant to be handling |
| 3051 |
% top-aligned tables, and \lit{b}, which means that I'm meant to be lining |
| 3052 |
% up the bottom. There are several other `substates' which have various |
| 3053 |
% magic meanings. |
| 3054 |
% |
| 3055 |
% \begin{macrocode} |
| 3056 |
\def\tab@hlstate{n} |
| 3057 |
% \end{macrocode} |
| 3058 |
% |
| 3059 |
% When all's said and done, I extract the box containing the table, and |
| 3060 |
% play with the height and depth to try and make it correct. |
| 3061 |
% |
| 3062 |
% \begin{macro}{\tab@addruleheight} |
| 3063 |
% |
| 3064 |
% This macro is called by `inter-row' things to add their height to our |
| 3065 |
% dimen register. |
| 3066 |
% |
| 3067 |
% Only do this if the state indicates that it's sensible. |
| 3068 |
% |
| 3069 |
% \begin{macrocode} |
| 3070 |
\def\tab@addruleheight#1{% |
| 3071 |
\if\tab@hlstate n\else% |
| 3072 |
\global\advance\tab@endheight#1\relax% |
| 3073 |
\fi% |
| 3074 |
} |
| 3075 |
% \end{macrocode} |
| 3076 |
% |
| 3077 |
% \end{macro} |
| 3078 |
% |
| 3079 |
% \begin{macro}{\tab@startrow} |
| 3080 |
% |
| 3081 |
% This is called at the start of a row, from within the array preamble. |
| 3082 |
% Currently, this assumes that the rows aren't bigger than their struts: |
| 3083 |
% this is reasonable, although slightly limiting, and it could be done better |
| 3084 |
% if I was willing to rip the alignment apart and put it back together |
| 3085 |
% again. |
| 3086 |
% |
| 3087 |
% \begin{macrocode} |
| 3088 |
\def\tab@startrow{% |
| 3089 |
\if\tab@hlstate t% |
| 3090 |
\gdef\tab@hlstate{n}% |
| 3091 |
\else\if\tab@hlstate b% |
| 3092 |
\global\tab@endheight\dp\@arstrutbox% |
| 3093 |
\fi\fi% |
| 3094 |
} |
| 3095 |
% \end{macrocode} |
| 3096 |
% |
| 3097 |
% \end{macro} |
| 3098 |
% |
| 3099 |
% \begin{macro}{\tab@raisebase} |
| 3100 |
% |
| 3101 |
% This macro is called at the end of it all, to set the height and depth |
| 3102 |
% of the box correctly. It sets the height to |\tab@endheight|, and the |
| 3103 |
% depth to everything else. The box is in |\box|~0 currently. |
| 3104 |
% |
| 3105 |
% \begin{macrocode} |
| 3106 |
\def\tab@raisebase{% |
| 3107 |
\global\advance\tab@endheight-\ht\z@% |
| 3108 |
\raise\tab@endheight\box\z@% |
| 3109 |
} |
| 3110 |
% \end{macrocode} |
| 3111 |
% |
| 3112 |
% \end{macro} |
| 3113 |
% |
| 3114 |
% \begin{macro}{\tab@lowerbase} |
| 3115 |
% |
| 3116 |
% And, for symmetry's sake, here's how to set the bottom properly instead. |
| 3117 |
% |
| 3118 |
% \begin{macrocode} |
| 3119 |
\def\tab@lowerbase{% |
| 3120 |
\global\advance\tab@endheight-\dp\z@% |
| 3121 |
\lower\tab@endheight\box\z@% |
| 3122 |
} |
| 3123 |
% \end{macrocode} |
| 3124 |
% |
| 3125 |
% \end{macro} |
| 3126 |
% |
| 3127 |
% |
| 3128 |
% \subsection{Breaking tables into bits} |
| 3129 |
% |
| 3130 |
% Unboxed tables have a wonderful advantage over boxed ones: you can stop |
| 3131 |
% halfway through and do something else for a bit. Here's how: |
| 3132 |
% |
| 3133 |
% \begin{macro}{\tabpause} |
| 3134 |
% |
| 3135 |
% I'd like to avoid forbidding catcode changes here. I'll use |\doafter| |
| 3136 |
% now I've got it, to ensure that colour handling and things occur |
| 3137 |
% \emph{inside} the |\noalign| (otherwise they'll mess up the alignment |
| 3138 |
% very seriously). |
| 3139 |
% |
| 3140 |
% We have to be careful here to ensure that everything works correctly within |
| 3141 |
% lists. (The \package{amsmath} package had this problem in its |
| 3142 |
% |\intertext| macro, so I'm not alone here.) |
| 3143 |
% |
| 3144 |
% \begin{macrocode} |
| 3145 |
\def\tabpause#{% |
| 3146 |
\noalign{\ifnum0=`}\fi% |
| 3147 |
\@parboxrestore% |
| 3148 |
\tab@startpause% |
| 3149 |
\vskip-\parskip% |
| 3150 |
\parshape\@ne\@totalleftmargin\linewidth% |
| 3151 |
\noindent% |
| 3152 |
\doafter\tabpause@i% |
| 3153 |
} |
| 3154 |
\def\tabpause@i{% |
| 3155 |
\nobreak% |
| 3156 |
\tab@endpause% |
| 3157 |
\ifnum0=`{\fi}% |
| 3158 |
} |
| 3159 |
% \end{macrocode} |
| 3160 |
% |
| 3161 |
% \end{macro} |
| 3162 |
% |
| 3163 |
% |
| 3164 |
% \subsection{The wonderful world of \cmd\multicolumn} |
| 3165 |
% |
| 3166 |
% \begin{macro}{\multicolumn} |
| 3167 |
% |
| 3168 |
% This is actually fantasitcally easy. Watch and learn. Make sure you |
| 3169 |
% notice the |\long|s here: remember that some table cells can contain |
| 3170 |
% paragraphs, so it seems sensible to allow |\par| into the argument. |
| 3171 |
% (As far as I know, most other |\multicolumn| commands don't do this, |
| 3172 |
% which seems a little silly. Then again, I forgot to do it the first |
| 3173 |
% time around.) |
| 3174 |
% |
| 3175 |
% \begin{macrocode} |
| 3176 |
\long\def\multicolumn#1#2#3{% |
| 3177 |
\multispan{#1}% |
| 3178 |
\begingroup% |
| 3179 |
\tab@multicol% |
| 3180 |
\tab@initread% |
| 3181 |
\tab@preamble{}% |
| 3182 |
\long\def\tab@midtext{#3}% |
| 3183 |
\let\tab@looped\tab@err@multi% |
| 3184 |
\tab@readpreamble{#2}% |
| 3185 |
\the\tab@preamble% |
| 3186 |
\endgroup% |
| 3187 |
\ignorespaces% |
| 3188 |
} |
| 3189 |
% \end{macrocode} |
| 3190 |
% |
| 3191 |
% \end{macro} |
| 3192 |
% |
| 3193 |
% |
| 3194 |
% \subsection{Interlude: range lists} |
| 3195 |
% |
| 3196 |
% For processing arguments to |\vgap| and |\cline|, we need to be able to |
| 3197 |
% do things with lists of column ranges. To save space, and to make my |
| 3198 |
% fingers do less typing, here's some routines which do range handling. |
| 3199 |
% |
| 3200 |
% \begin{macro}{\ranges} |
| 3201 |
% |
| 3202 |
% Given a macro name and a comma separated list of ranges and simple numbers, |
| 3203 |
% this macro will call the macro giving it each range in the list in turn. |
| 3204 |
% Single numbers~$n$ will be turned into ranges $n$--$n$. |
| 3205 |
% |
| 3206 |
% The first job is to read the macro to do (which may already have some |
| 3207 |
% arguments attached to it). We'll also start a group to make sure that |
| 3208 |
% our changes to temp registers don't affect anyone else. |
| 3209 |
% |
| 3210 |
% There's a space before the delimiting |\q@delim| to stop numbers being |
| 3211 |
% parsed to far and expanding our quark (which will stop \TeX\ dead in its |
| 3212 |
% tracks). Since we use |\@ifnextchar| to look ahead, spaces in range lists |
| 3213 |
% are perfectly all right. |
| 3214 |
% |
| 3215 |
% \begin{macrocode} |
| 3216 |
\def\ranges#1#2{% |
| 3217 |
\gdef\ranges@temp{#1}% |
| 3218 |
\begingroup% |
| 3219 |
\ranges@i#2 \q@delim% |
| 3220 |
} |
| 3221 |
% \end{macrocode} |
| 3222 |
% |
| 3223 |
% |
| 3224 |
% We're at the beginning of the list. We expect either the closing marker |
| 3225 |
% (if this is an empty list) or a number, which we can scoop up into a |
| 3226 |
% scratch register. |
| 3227 |
% |
| 3228 |
% \begin{macrocode} |
| 3229 |
\def\ranges@i{% |
| 3230 |
\@ifnextchar\q@delim\ranges@done{\afterassignment\ranges@ii\count@}% |
| 3231 |
} |
| 3232 |
% \end{macrocode} |
| 3233 |
% |
| 3234 |
% We've read the first number in the range. If there's another number, we'll |
| 3235 |
% expect a `|-|' sign to be next. If there is no `|-|', call the user's code |
| 3236 |
% with the number duplicated and then do the rest of the list. |
| 3237 |
% |
| 3238 |
% \begin{macrocode} |
| 3239 |
\def\ranges@ii{% |
| 3240 |
\@ifnextchar-\ranges@iii{\ranges@do\count@\count@\ranges@v}% |
| 3241 |
} |
| 3242 |
% \end{macrocode} |
| 3243 |
% |
| 3244 |
% Now we strip the `|-|' off and read the other number into a temporary |
| 3245 |
% register. |
| 3246 |
% |
| 3247 |
% \begin{macrocode} |
| 3248 |
\def\ranges@iii-{\afterassignment\ranges@iv\@tempcnta} |
| 3249 |
% \end{macrocode} |
| 3250 |
% |
| 3251 |
% We have both ends of the range now, so call the user's code, passing it |
| 3252 |
% both ends of the range. |
| 3253 |
% |
| 3254 |
% \begin{macrocode} |
| 3255 |
\def\ranges@iv{\ranges@do\count@\@tempcnta\ranges@v} |
| 3256 |
% \end{macrocode} |
| 3257 |
% |
| 3258 |
% We've finished doing an item now. If we have a `|,|' next, then start |
| 3259 |
% over with the next item. Otherwise, if we're at the end of the list, |
| 3260 |
% we can end happily. Finally, if we're totally confused, raise an |
| 3261 |
% error. |
| 3262 |
% |
| 3263 |
% \begin{macrocode} |
| 3264 |
\def\ranges@v{% |
| 3265 |
\@ifnextchar,% |
| 3266 |
\ranges@vi% |
| 3267 |
{% |
| 3268 |
\@ifnextchar\q@delim% |
| 3269 |
\ranges@done% |
| 3270 |
{\tab@err@range\ranges@vi,}% |
| 3271 |
}% |
| 3272 |
} |
| 3273 |
% \end{macrocode} |
| 3274 |
% |
| 3275 |
% We had a comma, so gobble it, read the next number, and go round again. |
| 3276 |
% |
| 3277 |
% \begin{macrocode} |
| 3278 |
\def\ranges@vi,{\afterassignment\ranges@ii\count@} |
| 3279 |
% \end{macrocode} |
| 3280 |
% |
| 3281 |
% Here's how we call the user's code, now. We close the group, so that the |
| 3282 |
% user's code doesn't have to do global things to remember its results, and |
| 3283 |
% we expand the two range ends from their count registers. We also ensure |
| 3284 |
% that the range is the right way round. |
| 3285 |
% |
| 3286 |
% \begin{macrocode} |
| 3287 |
\def\ranges@do#1#2{% |
| 3288 |
\ifnum#1>#2\else% |
| 3289 |
\expandafter\endgroup% |
| 3290 |
\expandafter\ranges@temp% |
| 3291 |
\expandafter{% |
| 3292 |
\the\expandafter#1% |
| 3293 |
\expandafter}% |
| 3294 |
\expandafter{% |
| 3295 |
\the#2% |
| 3296 |
}% |
| 3297 |
\begingroup% |
| 3298 |
\fi% |
| 3299 |
} |
| 3300 |
% \end{macrocode} |
| 3301 |
% |
| 3302 |
% And finishing the scan is really easy. We close the group after gobbling |
| 3303 |
% the close token. |
| 3304 |
% |
| 3305 |
% \begin{macrocode} |
| 3306 |
\def\ranges@done\q@delim{\endgroup} |
| 3307 |
% \end{macrocode} |
| 3308 |
% |
| 3309 |
% \end{macro} |
| 3310 |
% |
| 3311 |
% \begin{macro}{\ifinrange} |
| 3312 |
% |
| 3313 |
% Something a little more useful, now. |\ifinrange| takes four arguments: |
| 3314 |
% a number, a range list (as above), and two token lists which I'll call |
| 3315 |
% \emph{then} and \emph{else}. If the number is in the list, I'll do |
| 3316 |
% \emph{then}, otherwise I'll do \emph{else}. |
| 3317 |
% |
| 3318 |
% \begin{macrocode} |
| 3319 |
\def\ifinrange#1#2{% |
| 3320 |
\@tempswafalse% |
| 3321 |
\count@#1% |
| 3322 |
\ranges\ifinrange@i{#2}% |
| 3323 |
\if@tempswa% |
| 3324 |
\expandafter\@firstoftwo% |
| 3325 |
\else% |
| 3326 |
\expandafter\@secondoftwo% |
| 3327 |
\fi% |
| 3328 |
} |
| 3329 |
\def\ifinrange@i#1#2{% |
| 3330 |
\ifnum\count@<#1 \else\ifnum\count@>#2 \else\@tempswatrue\fi\fi% |
| 3331 |
} |
| 3332 |
% \end{macrocode} |
| 3333 |
% |
| 3334 |
% \end{macro} |
| 3335 |
% |
| 3336 |
% |
| 3337 |
% \subsection{Horizontal rules OK} |
| 3338 |
% |
| 3339 |
% This is where all the gubbins for |\vgap| and friends is kept, lest it |
| 3340 |
% contaminate fairly clean bits of code found elsewhere. |
| 3341 |
% |
| 3342 |
% \subsubsection{Drawing horizontal rules} |
| 3343 |
% |
| 3344 |
% \begin{macro}{\hline} |
| 3345 |
% |
| 3346 |
% Note the funny use of |\noalign| to allow \TeX\ stomach ops like |
| 3347 |
% |\futurelet| without starting a new table row. This lets us see if there's |
| 3348 |
% another |\hline| coming up, so we can see if we need to insert extra |
| 3349 |
% vertical space. |
| 3350 |
% |
| 3351 |
% \begin{macrocode} |
| 3352 |
\def\hline{% |
| 3353 |
\tab@dohline% |
| 3354 |
\noalign{\ifnum0=`}\fi% |
| 3355 |
\tab@penalty% |
| 3356 |
\futurelet\@let@token\hline@i% |
| 3357 |
} |
| 3358 |
% \end{macrocode} |
| 3359 |
% |
| 3360 |
% We check here for another |\hline| command, and insert glue if there is. |
| 3361 |
% This looks terrible, though, and |\hlx{hvh}| is much nicer. Still\dots |
| 3362 |
% |
| 3363 |
% \begin{macrocode} |
| 3364 |
\def\hline@i{% |
| 3365 |
\ifx\@let@token\hline% |
| 3366 |
\vskip\doublerulesep% |
| 3367 |
\tab@addruleheight\doublerulesep% |
| 3368 |
\fi% |
| 3369 |
\ifnum0=`{\fi}% |
| 3370 |
} |
| 3371 |
% \end{macrocode} |
| 3372 |
% |
| 3373 |
% \end{macro} |
| 3374 |
% |
| 3375 |
% \begin{macro}{\tab@dohline} |
| 3376 |
% |
| 3377 |
% This is where hlines actually get drawn. |
| 3378 |
% Drawing lines is more awkward than it used to be, particularly in unboxed |
| 3379 |
% tables. It used to be a case simply of saying |\noalign{\hrule}|. |
| 3380 |
% However, since unboxed tables are actually much wider than they look, this |
| 3381 |
% would make the rules stretch right across the page and look generally |
| 3382 |
% horrible. |
| 3383 |
% |
| 3384 |
% The solution is simple: we basically do a dirty big |\cline|. |
| 3385 |
% |
| 3386 |
% \begin{macrocode} |
| 3387 |
\def\tab@dohline{% |
| 3388 |
\multispan{\tab@columns}% |
| 3389 |
\leaders\hrule\@height\arrayrulewidth\hfil% |
| 3390 |
\tab@addruleheight\arrayrulewidth% |
| 3391 |
\cr% |
| 3392 |
} |
| 3393 |
% \end{macrocode} |
| 3394 |
% |
| 3395 |
% \end{macro} |
| 3396 |
% |
| 3397 |
% \subsubsection{Vertical rules} |
| 3398 |
% |
| 3399 |
% I couldn't fit these in anywhere else, so they'll have to go here. I'll |
| 3400 |
% provide a new optional argument which specifies the width of the rule; this |
| 3401 |
% gets rid of the problem described in the \emph{Companion}, where to get |
| 3402 |
% an unusually wide vertical rule, you have to play with things like |
| 3403 |
% \syntax{"\\vrule width" <dimen>} which really isn't too nice. |
| 3404 |
% |
| 3405 |
% \begin{macro}{\vline} |
| 3406 |
% |
| 3407 |
% The new |\vline| has an optional argument which gives the width of the |
| 3408 |
% rule. The |\relax| stops \TeX\ trying to parse a \<rule-specification> for |
| 3409 |
% too long, in case someone says something like `|\vline depthcharges|' or |
| 3410 |
% something equally unlikely. |
| 3411 |
% |
| 3412 |
% \begin{macrocode} |
| 3413 |
\renewcommand\vline[1][\arrayrulewidth]{\vrule\@width#1\relax} |
| 3414 |
% \end{macrocode} |
| 3415 |
% |
| 3416 |
% \end{macro} |
| 3417 |
% |
| 3418 |
% \subsubsection{Drawing bits of lines} |
| 3419 |
% |
| 3420 |
% Just for a bit of fun, here's an extended version of |\cline| which takes |
| 3421 |
% a list of columns to draw lines under, rather than just a single range. |
| 3422 |
% |
| 3423 |
% \begin{macro}{\cline} |
| 3424 |
% |
| 3425 |
% Not a single line of code written yet, and we already have a dilemma on |
| 3426 |
% our hands. Multiple consecutive |\cline| commands are meant to draw |
| 3427 |
% on the same vertical bit of table. But horizontal lines are meant to have |
| 3428 |
% thickness now. Oh, well [sigh], we'll skip back on it after all. |
| 3429 |
% |
| 3430 |
% Now the problem remains how best to do the job. The way I see it, there |
| 3431 |
% are three possibilities: |
| 3432 |
% |
| 3433 |
% \begin{itemize} |
| 3434 |
% |
| 3435 |
% \item We can start a table row, and then for each column of the table |
| 3436 |
% (as recorded in |\tab@columns|) we look to see if that column is |
| 3437 |
% listed in the range list and if so draw the rule. This requires |
| 3438 |
% lots of scanning of the range list. |
| 3439 |
% |
| 3440 |
% \item We can take each range in the list, and draw rules appropriately, |
| 3441 |
% just like the old |\cline| used to do, and starting a new table row |
| 3442 |
% for each. |
| 3443 |
% |
| 3444 |
% \item We can start a table row, and then for each range remember where we |
| 3445 |
% stopped drawing the last row, move to the start of the new one, and |
| 3446 |
% draw it. If we start moving backwards, we close the current row |
| 3447 |
% and open a new one. |
| 3448 |
% |
| 3449 |
% \end{itemize} |
| 3450 |
% |
| 3451 |
% The last option looks the most efficient, and the most difficult. This |
| 3452 |
% is therefore what I shall do |;-)|. |
| 3453 |
% |
| 3454 |
% The first thing to do is to add in a little negative space, and start a |
| 3455 |
% table row (omitting the first item). Then scan the range list, and finally |
| 3456 |
% close the table row and add some negative space again. |
| 3457 |
% |
| 3458 |
% We need a global count register to keep track of where we are. Mixing |
| 3459 |
% local and global assignments causes all sorts of tragedy, so I shall hijack |
| 3460 |
% |\tab@state|. |
| 3461 |
% |
| 3462 |
% \begin{macrocode} |
| 3463 |
\def\cline#1{% |
| 3464 |
\noalign{\kern-.5\arrayrulewidth\tab@penalty}% |
| 3465 |
\omit% |
| 3466 |
\global\tab@state\@ne% |
| 3467 |
\ranges\cline@i{#1}% |
| 3468 |
\cr% |
| 3469 |
\noalign{\kern-.5\arrayrulewidth\tab@penalty}% |
| 3470 |
} |
| 3471 |
% \end{macrocode} |
| 3472 |
% |
| 3473 |
% Now for the tricky bit. When we're given a range, we look to see if the |
| 3474 |
% first number is less than |\tab@state|. If so, we quickly close the |
| 3475 |
% current row, kern backwards and start again with an |\omit| and reset |
| 3476 |
% |\tab@state| to 1, and try again. |
| 3477 |
% |
| 3478 |
% \begin{macrocode} |
| 3479 |
\def\cline@i#1#2{% |
| 3480 |
\ifnum#1<\tab@state\relax% |
| 3481 |
\tab@@cr% |
| 3482 |
\noalign{\kern-\arrayrulewidth\tab@penalty}% |
| 3483 |
\omit% |
| 3484 |
\global\tab@state\@ne% |
| 3485 |
\fi% |
| 3486 |
% \end{macrocode} |
| 3487 |
% |
| 3488 |
% We are now either at or in front of the column position required. If |
| 3489 |
% we're too far back, we must |\hfil&\omit| our way over to the correct% |
| 3490 |
% column. |
| 3491 |
% |
| 3492 |
% \begin{macrocode} |
| 3493 |
\@whilenum\tab@state<#1\do{% |
| 3494 |
\hfil\tab@@tab@omit% |
| 3495 |
\global\advance\tab@state\@ne% |
| 3496 |
}% |
| 3497 |
% \end{macrocode} |
| 3498 |
% |
| 3499 |
% We've found the start correctly. We must deal with a tiny problem now: |
| 3500 |
% if this is not the first table cell, the left hand vertical rule is in the |
| 3501 |
% column to the left, so our horizontal rule won't match up properly. So |
| 3502 |
% we skip back by a bit to compensate. If there isn't actually a vertical |
| 3503 |
% rule to line up with, no-one will notice, because the rules are so thin. |
| 3504 |
% This adds a little touch of quality to the whole thing, which is after all |
| 3505 |
% the point of this whole exercise. |
| 3506 |
% |
| 3507 |
% \begin{macrocode} |
| 3508 |
\ifnum\tab@state>\@ne% |
| 3509 |
\kern-\arrayrulewidth% |
| 3510 |
\fi% |
| 3511 |
% \end{macrocode} |
| 3512 |
% |
| 3513 |
% Now we must stretch this table cell to the correct width. |
| 3514 |
% |
| 3515 |
% \begin{macrocode} |
| 3516 |
\@whilenum\tab@state<#2\do{% |
| 3517 |
\tab@@span@omit% |
| 3518 |
\global\advance\tab@state\@ne% |
| 3519 |
}% |
| 3520 |
% \end{macrocode} |
| 3521 |
% |
| 3522 |
% We're ready. Draw the rule. Note that this is |\hfill| glue, just in case |
| 3523 |
% we start putting in |\hfil| glue when we step onto the next cell. |
| 3524 |
% |
| 3525 |
% \begin{macrocode} |
| 3526 |
\leaders\hrule\@height\arrayrulewidth\hfill% |
| 3527 |
} |
| 3528 |
% \end{macrocode} |
| 3529 |
% |
| 3530 |
% Some alignment primitives are hidden inside macros so they don't get seen |
| 3531 |
% at the wrong time. This is what they look like: |
| 3532 |
% |
| 3533 |
% \begin{macrocode} |
| 3534 |
\def\tab@@cr{\cr} |
| 3535 |
\def\tab@@tab@omit{&\omit} |
| 3536 |
\def\tab@@span@omit{\span\omit} |
| 3537 |
% \end{macrocode} |
| 3538 |
% |
| 3539 |
% \end{macro} |
| 3540 |
% |
| 3541 |
% \subsubsection{Drawing short table rows} |
| 3542 |
% |
| 3543 |
% Before I start on a description of more code, I think I'll briefly discuss |
| 3544 |
% my reasons for leaving the |\vgap| command in its current state. There's a |
| 3545 |
% reasonable case for introducing an interface between |\vgap| and |
| 3546 |
% |\multicolumn|, to avoid all the tedious messing about with column |
| 3547 |
% ranges. There are good reasons why I'm not going to do this: |
| 3548 |
% |
| 3549 |
% \begin{itemize} |
| 3550 |
% |
| 3551 |
% \item It's very difficult to do: it requires either postprocessing of |
| 3552 |
% the table or delaying processing of each row until I know exactly |
| 3553 |
% what's in it; a |\multicolumn| in a row should be able to affect |
| 3554 |
% a |\vgap| before the row, which gets very nasty. This package is |
| 3555 |
% probably far too large already, and adding more complexity and |
| 3556 |
% running the risk of exhausting \TeX's frustratingly finite capacity |
| 3557 |
% for the sake of relieving the user of a fairly trivial job doesn't |
| 3558 |
% seem worthwhile. |
| 3559 |
% |
| 3560 |
% \item Perhaps more importantly, there are perfectly valid occasions when |
| 3561 |
% it's useful to have the current vgap behaviour. For example, the |
| 3562 |
% \texttt{MIX} word layout diagrams found in \emph{The Art of |
| 3563 |
% Computer Programming} use the little `stub lines' to show where |
| 3564 |
% data items cross byte boundaries: |
| 3565 |
% |
| 3566 |
% ^^A This actually looks terrifyingly similar to the original. |
| 3567 |
% ^^A The leading @{} is there to stop the table looking off-centre, |
| 3568 |
% ^^A because there's no left hand rule telling you where the table |
| 3569 |
% ^^A starts, like there is on the right, just the \tabcolsep glue. |
| 3570 |
% |
| 3571 |
% \begingroup |
| 3572 |
% \newcommand{\wide}[2]{\multicolumn{#1}{c|}{\ttfamily #2}} |
| 3573 |
% \begin{tabular}[C]{@{} r @{\qquad} | Mc | *{5}{c|}} \hlx{c{2-7} v} |
| 3574 |
% empty & - & 1 & 0 & 0 & 0 & 0 \\ \hlx{v c{2-7} v} |
| 3575 |
% occupied & + & \wide{2}{LINK} & \wide{3}{KEY} \\ \hlx{v c{2-7}} |
| 3576 |
% \end{tabular} |
| 3577 |
% \endgroup |
| 3578 |
% |
| 3579 |
% \end{itemize} |
| 3580 |
% |
| 3581 |
% That's my excuses out of the way; now I'll press on with the actual |
| 3582 |
% programming. |
| 3583 |
% |
| 3584 |
% \begin{macro}{\tab@checkrule} |
| 3585 |
% |
| 3586 |
% We have a range list in |\tab@xcols| and a number as an argument. If we |
| 3587 |
% find the number in the list, wejust space out the following group, |
| 3588 |
% otherwise we let it be. |
| 3589 |
% |
| 3590 |
% \begin{macrocode} |
| 3591 |
\def\tab@checkrule#1{% |
| 3592 |
\count@#1\relax% |
| 3593 |
\expandafter\ifinrange% |
| 3594 |
\expandafter\count@% |
| 3595 |
\expandafter{\tab@xcols}% |
| 3596 |
{\tab@checkrule@i}% |
| 3597 |
{}% |
| 3598 |
} |
| 3599 |
\def\tab@checkrule@i#1{\setbox\z@\hbox{#1}\hb@xt@\wd\z@{}} |
| 3600 |
% \end{macrocode} |
| 3601 |
% |
| 3602 |
% \end{macro} |
| 3603 |
% |
| 3604 |
% \begin{macro}{\vgap} |
| 3605 |
% |
| 3606 |
% We must tread carefully here. A single misplaced stomach operation can |
| 3607 |
% cause error messages. We therefore start with an |\omit| so we can search |
| 3608 |
% for optional arguments. |
| 3609 |
% |
| 3610 |
% So that |\hlx| can get control after |\vgap| has finished, we provide a |
| 3611 |
% hook called |\vgap@after| which is expanded after |\vgap| has finished. |
| 3612 |
% Here we make it work like |\@empty|, which expands to nothing. (Note that |
| 3613 |
% |\relax| will start a new table row, so we can't use that.) There are |
| 3614 |
% some penalty items here to stick the |\vgap| row to the text row and |
| 3615 |
% |\hline| that are adjacent to it. The \package{longtable} package will |
| 3616 |
% split an |\hline| in half, so this is the correct thing to do. |
| 3617 |
% |
| 3618 |
% \begin{macrocode} |
| 3619 |
\def\vgap{% |
| 3620 |
\noalign{\nobreak}% |
| 3621 |
\omit% |
| 3622 |
\global\let\vgap@after\@empty% |
| 3623 |
\iffalse{\fi\ifnum0=`}\fi% |
| 3624 |
\@ifnextchar[\vgap@i\vgap@simple% |
| 3625 |
} |
| 3626 |
% \end{macrocode} |
| 3627 |
% |
| 3628 |
% We set up two different sorts of |\vgap| -- a simple one which allows all |
| 3629 |
% rules to be passed through, and a specific one which carefully vets each |
| 3630 |
% one (and is therefore slower). We decide which to so based on the presence |
| 3631 |
% of an optional argument. |
| 3632 |
% |
| 3633 |
% The optional argument handler just passes its argument to an interface |
| 3634 |
% routine which is used by |\hlx|. |
| 3635 |
% |
| 3636 |
% \begin{macrocode} |
| 3637 |
\def\vgap@i[#1]{\vgap@spec{#1}} |
| 3638 |
% \end{macrocode} |
| 3639 |
% |
| 3640 |
% Now we handle specified columns. Since we're in an omitted table cell, we |
| 3641 |
% must set things up globally. Assign the column spec to a macro, and set up |
| 3642 |
% vetting by the routine above. Then just go and do the job. |
| 3643 |
% |
| 3644 |
% \begin{macrocode} |
| 3645 |
\def\vgap@spec#1#2{% |
| 3646 |
\gdef\tab@xcols{#1}% |
| 3647 |
\global\let\tab@ckr\tab@checkrule% |
| 3648 |
\vgap@do{#2}% |
| 3649 |
} |
| 3650 |
% \end{macrocode} |
| 3651 |
% |
| 3652 |
% Handle all columns. Just gobble the column number for each rule, and let |
| 3653 |
% the drawing pass unharmed. Easy. |
| 3654 |
% |
| 3655 |
% \begin{macrocode} |
| 3656 |
\def\vgap@simple#1{% |
| 3657 |
\global\let\tab@ckr\@gobble% |
| 3658 |
\vgap@do{#1}% |
| 3659 |
} |
| 3660 |
% \end{macrocode} |
| 3661 |
% |
| 3662 |
% This is where stuff actually gets done. We set the |\vgap| flag on while |
| 3663 |
% we do the short row. Then just expand the token list we built while |
| 3664 |
% scanning the preamble. |
| 3665 |
% |
| 3666 |
% Note that the flag is cleared at the end of the last column, to allow other |
| 3667 |
% funny things like |\noalign| and |\omit| before a new row is started. |
| 3668 |
% |
| 3669 |
% \begin{macrocode} |
| 3670 |
\def\vgap@do#1{% |
| 3671 |
\ifnum0=`{}\fi% |
| 3672 |
\global\tab@vgaptrue% |
| 3673 |
\the\tab@shortline% |
| 3674 |
\vrule\@height#1\@width\z@% |
| 3675 |
\global\tab@vgapfalse |
| 3676 |
\tab@addruleheight{#1}% |
| 3677 |
\cr% |
| 3678 |
\noalign{\nobreak}% |
| 3679 |
\vgap@after% |
| 3680 |
} |
| 3681 |
% \end{macrocode} |
| 3682 |
% |
| 3683 |
% \end{macro} |
| 3684 |
% |
| 3685 |
% \subsubsection{Prettifying syntax} |
| 3686 |
% |
| 3687 |
% \begin{macro}{\hlx} |
| 3688 |
% |
| 3689 |
% This is like a poor cousin to the preamble parser. The whole loop is |
| 3690 |
% carefully written to take place \emph{only} in \TeX's mouth, so the |
| 3691 |
% alignment handling bits half way down the gullet don't see any of this. |
| 3692 |
% |
| 3693 |
% First, pass the string to another routine. |
| 3694 |
% |
| 3695 |
% \begin{macrocode} |
| 3696 |
\def\hlx#1{\hlx@loop#1\q@delim} |
| 3697 |
% \end{macrocode} |
| 3698 |
% |
| 3699 |
% Now peel off a token, and dispatch using |\csname|. We handle |
| 3700 |
% undefinedness of the command in a fairly messy way, although it probably |
| 3701 |
% works. Maybe. |
| 3702 |
% |
| 3703 |
% \begin{macrocode} |
| 3704 |
\def\hlx@loop#1{% |
| 3705 |
\ifx#1\q@delim\else% |
| 3706 |
\@ifundefined{hlx@cmd@\string#1}{% |
| 3707 |
\expandafter\hlx@loop% |
| 3708 |
}{% |
| 3709 |
\csname hlx@cmd@\string#1\expandafter\endcsname% |
| 3710 |
}% |
| 3711 |
\fi% |
| 3712 |
} |
| 3713 |
% \end{macrocode} |
| 3714 |
% |
| 3715 |
% \end{macro} |
| 3716 |
% |
| 3717 |
% \begin{macro}{\hlxdef} |
| 3718 |
% |
| 3719 |
% New |\hlx| commands can be defined using |\hlxdef|. This is a simple |
| 3720 |
% abbreviation. |
| 3721 |
% |
| 3722 |
% \begin{macrocode} |
| 3723 |
\def\hlxdef#1{\@namedef{hlx@cmd@#1}} |
| 3724 |
% \end{macrocode} |
| 3725 |
% |
| 3726 |
% \end{macro} |
| 3727 |
% |
| 3728 |
% \begin{macro}{\hlx h} |
| 3729 |
% |
| 3730 |
% Handle an \lit{h} character. Just do an |\hline| and return to the loop. |
| 3731 |
% We look ahead to see if there's another \lit{h} coming up, and if so |
| 3732 |
% insert two |\hline| commands. This strange (and inefficient) behaviour |
| 3733 |
% keeps packages which redefine |\hline| happy. |
| 3734 |
% |
| 3735 |
% \begin{macrocode} |
| 3736 |
\hlxdef h#1{% |
| 3737 |
\noalign{% |
| 3738 |
\ifx#1h% |
| 3739 |
\def\@tempa{\hline\hline\hlx@loop}% |
| 3740 |
\else% |
| 3741 |
\def\@tempa{\hline\hlx@loop#1}% |
| 3742 |
\fi% |
| 3743 |
\expandafter |
| 3744 |
}% |
| 3745 |
\@tempa% |
| 3746 |
} |
| 3747 |
% \end{macrocode} |
| 3748 |
% |
| 3749 |
% \end{macro} |
| 3750 |
% |
| 3751 |
% \begin{macro}{\hlx b} |
| 3752 |
% |
| 3753 |
% The \lit{b} character does a nifty backspace, for \package{longtable}'s |
| 3754 |
% benefit. |
| 3755 |
% |
| 3756 |
% \begin{macrocode} |
| 3757 |
\hlxdef b{\noalign{\kern-\arrayrulewidth}\hlx@loop} |
| 3758 |
% \end{macrocode} |
| 3759 |
% |
| 3760 |
% \end{macro} |
| 3761 |
% |
| 3762 |
% \begin{macro}{\hlx /} |
| 3763 |
% |
| 3764 |
% The `"/"' character allows a page break at the current position. |
| 3765 |
% |
| 3766 |
% \begin{macrocode} |
| 3767 |
\hlxdef /{% |
| 3768 |
\noalign{\ifnum0=`}\fi% |
| 3769 |
\@ifnextchar[\hlx@cmd@break@i{\hlx@cmd@break@i[0]}% |
| 3770 |
} |
| 3771 |
\def\hlx@cmd@break@i[#1]{\ifnum0=`{\fi}\pagebreak[0]\hlx@loop} |
| 3772 |
% \end{macrocode} |
| 3773 |
% |
| 3774 |
% \end{macro} |
| 3775 |
% |
| 3776 |
% \begin{macro}{\hlx v} |
| 3777 |
% |
| 3778 |
% Handle a \lit{v} character. This is rather like the |\vgap| code above, |
| 3779 |
% although there are syntactic differences. |
| 3780 |
% |
| 3781 |
% \begin{macrocode} |
| 3782 |
\hlxdef v{% |
| 3783 |
\noalign{\nobreak}% |
| 3784 |
\omit% |
| 3785 |
\iffalse{\fi\ifnum0=`}\fi% |
| 3786 |
\global\let\vgap@after\hlx@loop% |
| 3787 |
\@ifnextchar[\hlx@vgap@i{\hlx@vgap@ii\vgap@simple}% |
| 3788 |
} |
| 3789 |
\def\hlx@vgap@i[#1]{% |
| 3790 |
\ifx!#1!% |
| 3791 |
\def\@tempa{\hlx@vgap@ii\vgap@simple}% |
| 3792 |
\else% |
| 3793 |
\def\@tempa{\hlx@vgap@ii{\vgap@spec{#1}}}% |
| 3794 |
\fi% |
| 3795 |
\@tempa% |
| 3796 |
} |
| 3797 |
\def\hlx@vgap@ii#1{% |
| 3798 |
\@ifnextchar[{\hlx@vgap@iii{#1}}{\hlx@vgap@iii{#1}[\doublerulesep]}% |
| 3799 |
} |
| 3800 |
\def\hlx@vgap@iii#1[#2]{#1{#2}} |
| 3801 |
% \end{macrocode} |
| 3802 |
% |
| 3803 |
% \end{macro} |
| 3804 |
% |
| 3805 |
% \begin{macro}{\hlx s} |
| 3806 |
% |
| 3807 |
% Allow the user to leave a small gap using the \lit{s} command. |
| 3808 |
% |
| 3809 |
% \begin{macrocode} |
| 3810 |
\hlxdef s{% |
| 3811 |
\noalign{\ifnum0=`}\fi% |
| 3812 |
\nobreak% |
| 3813 |
\@ifnextchar[\hlx@space@i{\hlx@space@i[\doublerulesep]}% |
| 3814 |
} |
| 3815 |
\def\hlx@space@i[#1]{% |
| 3816 |
\vskip#1% |
| 3817 |
\tab@addruleheight{#1}% |
| 3818 |
\ifnum0=`{\fi}% |
| 3819 |
\hlx@loop% |
| 3820 |
} |
| 3821 |
% \end{macrocode} |
| 3822 |
% |
| 3823 |
% \end{macro} |
| 3824 |
% |
| 3825 |
% \begin{macro}{\hlx c} |
| 3826 |
% |
| 3827 |
% We might as well allow a \lit{c} command to do a |\cline|. |
| 3828 |
% |
| 3829 |
% \begin{macrocode} |
| 3830 |
\hlxdef c#1{\cline{#1}\hlx@loop} |
| 3831 |
% \end{macrocode} |
| 3832 |
% |
| 3833 |
% \end{macro} |
| 3834 |
% |
| 3835 |
% \begin{macro}{\hlx .} |
| 3836 |
% |
| 3837 |
% The \lit{.} character forces a start of the new column. There's a little |
| 3838 |
% problem here. Since the \lit{.} character starts the next column, we need |
| 3839 |
% to gobble any spaces following the |\hlx| command before the cell contents |
| 3840 |
% actually starts. Unfortunately, |\ignorespaces| will start the column for |
| 3841 |
% us, so we can't put it in always. We'll handle it here, then. We'll take |
| 3842 |
% the rest of the `preamble' string, and warn if it's not empty. Then we'll |
| 3843 |
% |\ignorespaces| -- this will start the column for us, so we don't need to |
| 3844 |
% |\relax| any more. |
| 3845 |
% |
| 3846 |
% \begin{macrocode} |
| 3847 |
\hlxdef .#1\q@delim{% |
| 3848 |
\ifx @#1@\else% |
| 3849 |
\PackageWarning{mdwtab}{% |
| 3850 |
Ignoring \protect\hlx\space command characters following a |
| 3851 |
`.'\MessageBreak command% |
| 3852 |
}% |
| 3853 |
\fi% |
| 3854 |
\ignorespaces% |
| 3855 |
} |
| 3856 |
% \end{macrocode} |
| 3857 |
% |
| 3858 |
% \end{macro} |
| 3859 |
% |
| 3860 |
% |
| 3861 |
% \subsection{Starting new table rows} |
| 3862 |
% |
| 3863 |
% We take a break from careful mouthery at last, and start playing with |
| 3864 |
% newlines. The standard one allows pagebreaks in unboxed tables, which |
| 3865 |
% isn't really too desirable. |
| 3866 |
% |
| 3867 |
% Anyway, we'll try to make this macro rather more reusable than the standard |
| 3868 |
% one. Here goes. |
| 3869 |
% |
| 3870 |
% \begin{macro}{\@arraycr} |
| 3871 |
% |
| 3872 |
% We pass lots of information to a main parser macro, and expect it to cope. |
| 3873 |
% |
| 3874 |
% \begin{macrocode} |
| 3875 |
\def\@arraycr{\tab@arraycr{}} |
| 3876 |
\def\tab@arraycr#1{\tab@cr{\tab@tabcr{#1}}{}{}} |
| 3877 |
% \end{macrocode} |
| 3878 |
% |
| 3879 |
% Now to actually do the work. |\tab@cr| passes us the skip size, and the |
| 3880 |
% appropriate one of the two arguments given above (both of which are empty) |
| 3881 |
% depending on the presence of the $*$. |
| 3882 |
% |
| 3883 |
% \begin{macrocode} |
| 3884 |
\def\tab@tabcr#1#2{% |
| 3885 |
% \end{macrocode} |
| 3886 |
% |
| 3887 |
% If the total height I need to add between rows (from the optional argument |
| 3888 |
% and the `extrasep' parameter) is greater than zero, I'll handle this by |
| 3889 |
% extending the strut slightly. I'm not actually sure whether this is the |
| 3890 |
% right thing to do, to be honest, although it's easier than trying to |
| 3891 |
% to an automatic |\vgap|, because I need to know which columns to skip. |
| 3892 |
% If the space is less than zero, I'll just insert the vertical space with |
| 3893 |
% in a |\noalign|. |
| 3894 |
% |
| 3895 |
% First, to calculate how much space needs adding. |
| 3896 |
% |
| 3897 |
% \begin{macrocode} |
| 3898 |
\dimen@#2% |
| 3899 |
\advance\dimen@\tab@extrasep% |
| 3900 |
% \end{macrocode} |
| 3901 |
% |
| 3902 |
% If the height is greater than zero, I need to play with the strut. I must |
| 3903 |
% bear in mind that the current table cell (which I'm still in, remember) |
| 3904 |
% may be in vertical mode, and I may or may not be in a paragraph. |
| 3905 |
% |
| 3906 |
% If I am in vertical mode, I'll backpedal to the previous box and put the |
| 3907 |
% strut in an hbox superimposed on the previous baseline. Otherwise, I can |
| 3908 |
% just put the strut at the end of the text. (This works in either LR |
| 3909 |
% or paragraph mode as long as I'm not between paragraphs.) Again, Rowland's |
| 3910 |
% empty cell bug strikes. (See |\tab@epar| for details.) |
| 3911 |
% |
| 3912 |
% \begin{macrocode} |
| 3913 |
\ifdim\dimen@>\z@% |
| 3914 |
\ifvmode% |
| 3915 |
\unskip\ifdim\prevdepth>-\@m\p@\kern-\prevdepth\fi% |
| 3916 |
\nointerlineskip\expandafter\hbox% |
| 3917 |
\else% |
| 3918 |
\@maybe@unskip\expandafter\@firstofone% |
| 3919 |
\fi% |
| 3920 |
{\advance\dimen@\dp\@arstrutbox\vrule\@depth\dimen@\@width\z@}% |
| 3921 |
\fi% |
| 3922 |
% \end{macrocode} |
| 3923 |
% |
| 3924 |
% This table cell works as a group (which is annoying here). I'll copy the |
| 3925 |
% interrow gap into a global register so that I can use it in the |\noalign|. |
| 3926 |
% |
| 3927 |
% \begin{macrocode} |
| 3928 |
\global\dimen\@ne\dimen@% |
| 3929 |
\cr% |
| 3930 |
\noalign{% |
| 3931 |
#1% |
| 3932 |
\ifdim\dimen\@ne<\z@\vskip\dimen\@ne\relax\fi% |
| 3933 |
}% |
| 3934 |
\@gobble% |
| 3935 |
} |
| 3936 |
% \end{macrocode} |
| 3937 |
% |
| 3938 |
% \end{macro} |
| 3939 |
% |
| 3940 |
% \begin{macro}{\tab@setcr} |
| 3941 |
% |
| 3942 |
% To set the |\\| command correctly in each table cell, we make it a part of |
| 3943 |
% the preamble (in |\tab@midtext|) to call this routine. It's easy -- just |
| 3944 |
% saves the preamble from being huge. |
| 3945 |
% |
| 3946 |
% \begin{macrocode} |
| 3947 |
\def\tab@setcr{\let\\\tabularnewline} |
| 3948 |
% \end{macrocode} |
| 3949 |
% |
| 3950 |
% \end{macro} |
| 3951 |
% |
| 3952 |
% \begin{macro}{\tab@cr} |
| 3953 |
% |
| 3954 |
% Now we do the parsing work. This is fun. Note the revenge of the funny |
| 3955 |
% braces here. Nothing to worry about, honest. The tricky bit is to keep |
| 3956 |
% track of which arguments are which. (Thanks to David Carlisle for pointing |
| 3957 |
% out that I'd missed out the |\relax| here.) |
| 3958 |
% |
| 3959 |
% \begin{macrocode} |
| 3960 |
\def\tab@cr#1#2#3{% |
| 3961 |
\relax% |
| 3962 |
\iffalse{\fi\ifnum0=`}\fi% |
| 3963 |
\@ifstar{\tab@cr@i{#1}{#3}}{\tab@cr@i{#1}{#2}}% |
| 3964 |
} |
| 3965 |
\def\tab@cr@i#1#2{% |
| 3966 |
\@ifnextchar[{\tab@cr@ii{#1}{#2}}{\tab@cr@ii{#1}{#2}[\z@]}% |
| 3967 |
} |
| 3968 |
\def\tab@cr@ii#1#2[#3]{% |
| 3969 |
\ifnum0=`{}\fi% |
| 3970 |
#1{#3}{#2}% |
| 3971 |
} |
| 3972 |
% \end{macrocode} |
| 3973 |
% |
| 3974 |
% \end{macro} |
| 3975 |
% |
| 3976 |
% |
| 3977 |
% \subsection{Gratuitous grotesquery} |
| 3978 |
% |
| 3979 |
% So far we've had an easy-ish ride (or should that be \emph{queasy}?). Now |
| 3980 |
% for something unexplainably evil. We convince \LaTeX\ that it's loaded the |
| 3981 |
% \package{array} package, so that packages which need it think they've got |
| 3982 |
% it. |
| 3983 |
% |
| 3984 |
% The bogus date is the same as the date for the \package{array} package I've |
| 3985 |
% got here -- this will raise a warning if Frank updates his package which |
| 3986 |
% should filter back to me telling me that there's something I need to |
| 3987 |
% know about. |
| 3988 |
% |
| 3989 |
% The messing with |\xdef| and the funny parsing ought to insert the current |
| 3990 |
% \package{mdwtab} version and date into the fake \package{array} version |
| 3991 |
% string, giving a visible clue to the user that this isn't the real |
| 3992 |
% \package{array} package. |
| 3993 |
% |
| 3994 |
% \begin{macrocode} |
| 3995 |
\begingroup |
| 3996 |
\catcode`.=11 |
| 3997 |
\def\@tempa#1 #2 #3\@@{#1 #2} |
| 3998 |
\xdef\[email protected] |
| 3999 |
{1995/11/19 [mdwtab.sty \expandafter\@tempa\[email protected]\@@]} |
| 4000 |
\endgroup |
| 4001 |
% \end{macrocode} |
| 4002 |
% |
| 4003 |
% |
| 4004 |
% \subsection{Error messages} |
| 4005 |
% |
| 4006 |
% I've put all the error messages together, where I can find them, translate |
| 4007 |
% them or whatever. |
| 4008 |
% |
| 4009 |
% First, some token-space saving (which also saves my fingers): |
| 4010 |
% |
| 4011 |
% \begin{macrocode} |
| 4012 |
\def\tab@error{\PackageError{mdwtab}} |
| 4013 |
% \end{macrocode} |
| 4014 |
% |
| 4015 |
% Now do the error messages. |
| 4016 |
% |
| 4017 |
% \begin{macrocode} |
| 4018 |
\def\tab@err@misscol{% |
| 4019 |
\tab@error{Missing column type}{% |
| 4020 |
I'm lost. I was expecting something describing^^J% |
| 4021 |
the type of the current column, but you seem to^^J% |
| 4022 |
have missed it out. I've inserted a type `l'^^J% |
| 4023 |
column here in the hope that this makes sense.% |
| 4024 |
}% |
| 4025 |
} |
| 4026 |
% \end{macrocode} |
| 4027 |
% |
| 4028 |
% \begin{macrocode} |
| 4029 |
\def\tab@err@oddgroup{% |
| 4030 |
\tab@error{Misplaced group in table preamble}{% |
| 4031 |
I've found an open brace character in your preamble^^J% |
| 4032 |
when I was expecting a specifier character. I'm^^J% |
| 4033 |
going to gobble the whole group and carry on as if^^J% |
| 4034 |
I'd never seen it.% |
| 4035 |
}% |
| 4036 |
} |
| 4037 |
% \end{macrocode} |
| 4038 |
% |
| 4039 |
% \begin{macrocode} |
| 4040 |
\def\tab@err@undef#1{% |
| 4041 |
\tab@error{Unknown `\tab@colset' preamble character `\string#1'}{% |
| 4042 |
I don't understand what you meant by typing this^^J% |
| 4043 |
character. Anyway, I'll ignore it this time around.^^J% |
| 4044 |
Just don't you do it again.% |
| 4045 |
}% |
| 4046 |
} |
| 4047 |
% \end{macrocode} |
| 4048 |
% |
| 4049 |
% \begin{macrocode} |
| 4050 |
\def\tab@err@unbrh{% |
| 4051 |
\tab@error{Can't use unboxed tabular in LR mode}{% |
| 4052 |
You've asked for a tabular or array environment with^^J% |
| 4053 |
`L', `C' or `R' as the position specifier, but you're^^J% |
| 4054 |
in LR (restricted horizontal) mode, so it won't work.^^J% |
| 4055 |
I'll assume you really meant `c' and soldier on.% |
| 4056 |
}% |
| 4057 |
} |
| 4058 |
% \end{macrocode} |
| 4059 |
% |
| 4060 |
% \begin{macrocode} |
| 4061 |
\def\tab@err@unbmm{% |
| 4062 |
\tab@error{Can't use unboxed tabular in maths mode}{% |
| 4063 |
You've asked for a tabular or array environment with^^J% |
| 4064 |
`L', `C' or `R' as the position specifier, but you're^^J% |
| 4065 |
in maths mode, so it won't work. I'll pretend that^^J% |
| 4066 |
you really typed `c', and that this is all a bad dream.% |
| 4067 |
}% |
| 4068 |
} |
| 4069 |
% \end{macrocode} |
| 4070 |
% |
| 4071 |
% \begin{macrocode} |
| 4072 |
\def\tab@err@unbext{% |
| 4073 |
\tab@error{Can't extend unboxed tabulars}{% |
| 4074 |
You're trying to use kludgy extensions (e.g.,^^J% |
| 4075 |
`delarray') on an array or tabular with `L', `C'^^J% |
| 4076 |
or `R' as the position specifier. I'll assume you^^J% |
| 4077 |
subconsciously wanted a `c' type all along.% |
| 4078 |
}% |
| 4079 |
} |
| 4080 |
% \end{macrocode} |
| 4081 |
% |
| 4082 |
% \begin{macrocode} |
| 4083 |
\def\tab@err@multi{% |
| 4084 |
\tab@error{More than one column in a \protect\multicolumn}{% |
| 4085 |
You've put more than one column into a \string\multicolumn^^J% |
| 4086 |
descriptor. It won't work. I have no idea what^^J% |
| 4087 |
will happen, although it won't be pleasant. Hold^^J% |
| 4088 |
on tight now...% |
| 4089 |
}% |
| 4090 |
} |
| 4091 |
% \end{macrocode} |
| 4092 |
% |
| 4093 |
% \begin{macrocode} |
| 4094 |
\def\tab@err@range{% |
| 4095 |
\tab@error{Expected `,' or `<end>' in range list}{% |
| 4096 |
I was expecting either the end of the range list,^^J% |
| 4097 |
or a comma, followed by another range. I've^^J% |
| 4098 |
inserted a comma to try and get me back on track.^^J% |
| 4099 |
Good luck.% |
| 4100 |
}% |
| 4101 |
} |
| 4102 |
% \end{macrocode} |
| 4103 |
% |
| 4104 |
% That's it. No more. Move along please. |
| 4105 |
% |
| 4106 |
% \begin{macrocode} |
| 4107 |
%</mdwtab> |
| 4108 |
% \end{macrocode} |
| 4109 |
% |
| 4110 |
% |
| 4111 |
%^^A------------------------------------------------------------------------- |
| 4112 |
% \section{Implementation of \package{mathenv}} |
| 4113 |
% |
| 4114 |
% |
| 4115 |
% This is in a separate package, mainly to avoid wasting people's memory. |
| 4116 |
% |
| 4117 |
% \begin{macrocode} |
| 4118 |
%<*mathenv> |
| 4119 |
% \end{macrocode} |
| 4120 |
% |
| 4121 |
% |
| 4122 |
% \subsection{Options handling} |
| 4123 |
% |
| 4124 |
% We need to be able to cope with \textsf{fleqn} and \textsf{leqno} options. |
| 4125 |
% This will adjust our magic modified \env{eqnarray} environment |
| 4126 |
% appropriately. |
| 4127 |
% |
| 4128 |
% \begin{macrocode} |
| 4129 |
\newif\if@fleqn |
| 4130 |
\newif\if@leqno |
| 4131 |
\DeclareOption{fleqn}{\@fleqntrue} |
| 4132 |
\DeclareOption{leqno}{\@leqnotrue} |
| 4133 |
\ProcessOptions |
| 4134 |
% \end{macrocode} |
| 4135 |
% |
| 4136 |
% We use the \package{mdwtab} package for all its nice table handling things. |
| 4137 |
% (Oh, and to inflict it on users who want to do nice equations and don't |
| 4138 |
% care about our tables.) |
| 4139 |
% |
| 4140 |
% \begin{macrocode} |
| 4141 |
\RequirePackage{mdwtab} |
| 4142 |
% \end{macrocode} |
| 4143 |
% |
| 4144 |
% |
| 4145 |
% \subsection{Some useful registers} |
| 4146 |
% |
| 4147 |
% The old \LaTeX\ version puts the equation numbers in by keeping a count of |
| 4148 |
% where it is in the alignment. Since I don't know how may columns there are |
| 4149 |
% going to be, I'll just use a switch in the preamble to tell me to stop |
| 4150 |
% tabbing. |
| 4151 |
% |
| 4152 |
% \begin{macrocode} |
| 4153 |
\newif\if@eqalast |
| 4154 |
% \end{macrocode} |
| 4155 |
% |
| 4156 |
% Now define some useful length parameters. First allocate them: |
| 4157 |
% |
| 4158 |
% \begin{macrocode} |
| 4159 |
\newskip\eqaopenskip |
| 4160 |
\newskip\eqacloseskip |
| 4161 |
\newskip\eqacolskip |
| 4162 |
\newskip\eqainskip |
| 4163 |
\newskip\splitleft |
| 4164 |
\newskip\splitright |
| 4165 |
% \end{macrocode} |
| 4166 |
% |
| 4167 |
% Now assign some default values. Users can play with these if they really |
| 4168 |
% want although I can't see the point myself. |
| 4169 |
% |
| 4170 |
% \begin{macrocode} |
| 4171 |
\AtBeginDocument{% |
| 4172 |
\eqacloseskip\@centering% |
| 4173 |
\eqacolskip1.5em\@plus\@m\p@ |
| 4174 |
\eqainskip\z@% |
| 4175 |
\if@fleqn% |
| 4176 |
\eqaopenskip\mathindent% |
| 4177 |
\splitleft\mathindent\relax% |
| 4178 |
\splitright\mathindent\@minus\mathindent\relax% |
| 4179 |
\else% |
| 4180 |
\eqaopenskip\@centering% |
| 4181 |
\splitleft2.5em\@minus2.5em% |
| 4182 |
\splitright\splitleft% |
| 4183 |
\fi% |
| 4184 |
\relax% |
| 4185 |
} |
| 4186 |
% \end{macrocode} |
| 4187 |
% |
| 4188 |
% |
| 4189 |
% \subsection{A little display handling} |
| 4190 |
% |
| 4191 |
% I'm probably going a little far here, and invading territory already |
| 4192 |
% claimed by the \package{amsmath} stuff (and done a good deal better than |
| 4193 |
% I can be bothered to do), but just for completeness, this is how we handle |
| 4194 |
% attempts to put displays inside other displays without screwing up the |
| 4195 |
% spacing. |
| 4196 |
% |
| 4197 |
% \begin{macro}{\dsp@startouter} |
| 4198 |
% |
| 4199 |
% This is how we start an outermost display. It's fairly easy really. We |
| 4200 |
% make |\dsp@start| start an inner display, and make |\dsp@end| close the |
| 4201 |
% outer display. |
| 4202 |
% |
| 4203 |
% \begin{macrocode} |
| 4204 |
\def\dsp@startouter{% |
| 4205 |
\let\dsp@end\dsp@endouter% |
| 4206 |
$$% |
| 4207 |
} |
| 4208 |
% \end{macrocode} |
| 4209 |
% |
| 4210 |
% \end{macro} |
| 4211 |
% |
| 4212 |
% \begin{macro}{\dsp@endouter} |
| 4213 |
% |
| 4214 |
% Ending the outer display is utterly trivial. |
| 4215 |
% |
| 4216 |
% \begin{macrocode} |
| 4217 |
\def\dsp@endouter{$$} |
| 4218 |
% \end{macrocode} |
| 4219 |
% |
| 4220 |
% \end{macro} |
| 4221 |
% |
| 4222 |
% \begin{macro}{\dsp@startinner} |
| 4223 |
% |
| 4224 |
% Starting inner displays is done in a vbox (actually I choose |\vbox| or |
| 4225 |
% |\vtop| depending on the setting of \textsf{leqno} to put the equation |
| 4226 |
% number the right way round). |
| 4227 |
% |
| 4228 |
% \begin{macrocode} |
| 4229 |
\def\dsp@startinner{% |
| 4230 |
\let\dsp@end\dsp@endinner% |
| 4231 |
\if@fleqn\kern-\mathindent\fi% |
| 4232 |
\if@leqno\vtop\else\vtop\fi\bgroup% |
| 4233 |
} |
| 4234 |
% \end{macrocode} |
| 4235 |
% |
| 4236 |
% \end{macro} |
| 4237 |
% |
| 4238 |
% \begin{macro}{\dsp@endinner} |
| 4239 |
% |
| 4240 |
% Ending an inner display is also really easy. |
| 4241 |
% |
| 4242 |
% \begin{macrocode} |
| 4243 |
\def\dsp@endinner{\egroup} |
| 4244 |
% \end{macrocode} |
| 4245 |
% |
| 4246 |
% \end{macro} |
| 4247 |
% |
| 4248 |
% \begin{macro}{\dsp@start} |
| 4249 |
% |
| 4250 |
% This is what other bits of code uses to start displays. It's one of the |
| 4251 |
% start macros up above, and outer by default. |
| 4252 |
% |
| 4253 |
% \begin{macrocode} |
| 4254 |
\def\dsp@start{% |
| 4255 |
\ifmmode% |
| 4256 |
\ifinner\mth@err@mdsp\fi% |
| 4257 |
\expandafter\dsp@startinner% |
| 4258 |
\else% |
| 4259 |
\ifhmode\ifinner\mth@err@hdsp\fi\fi% |
| 4260 |
\expandafter\dsp@startouter% |
| 4261 |
\fi% |
| 4262 |
} |
| 4263 |
% \end{macrocode} |
| 4264 |
% |
| 4265 |
% \end{macro} |
| 4266 |
% |
| 4267 |
% \begin{macro}{\dsp@tabpause} |
| 4268 |
% |
| 4269 |
% This sets up the correct pre- and postambles for the |\tabpause| macro in |
| 4270 |
% maths displays. This is fairly simple stuff. |
| 4271 |
% |
| 4272 |
% \begin{macrocode} |
| 4273 |
\def\dsp@tabpause{% |
| 4274 |
\def\tab@startpause% |
| 4275 |
{\penalty\postdisplaypenalty\vskip\belowdisplayskip}% |
| 4276 |
\def\tab@endpause% |
| 4277 |
{\penalty\predisplaypenalty\vskip\abovedisplayskip}% |
| 4278 |
} |
| 4279 |
% \end{macrocode} |
| 4280 |
% |
| 4281 |
% \end{macro} |
| 4282 |
% |
| 4283 |
% |
| 4284 |
% \subsection{The \env{eqnarray} environment} |
| 4285 |
% |
| 4286 |
% We allow the user to play with the style if this is really wanted. I dunno |
| 4287 |
% why, really. Maybe someone wants very small alignments. |
| 4288 |
% |
| 4289 |
% \begin{macrocode} |
| 4290 |
\let\eqastyle\displaystyle |
| 4291 |
% \end{macrocode} |
| 4292 |
% |
| 4293 |
% \subsubsection{The main environments} |
| 4294 |
% |
| 4295 |
% \begin{environment}{eqnarray} |
| 4296 |
% \begin{environment}{eqnarray*} |
| 4297 |
% |
| 4298 |
% We define the toplevel commands here. They just add in default arguments |
| 4299 |
% and then call |\@eqnarray| with a preamble string. We handle equation |
| 4300 |
% numbers by setting up a default (|\eqa@defnumber|) which is put into |
| 4301 |
% the final column. At the beginning of each row, we globally |\let| |
| 4302 |
% |\eqa@number| equal to |\eqa@defnumber|. The |\eqnumber| macro just |
| 4303 |
% changes |\eqa@number| as required. Since |\eqa@number| is changed globally |
| 4304 |
% we must save it in this environment. |
| 4305 |
% |
| 4306 |
% First, we must sort out the optional arguments and things. This is really |
| 4307 |
% easy. The only difference between the starred and non-starred environments |
| 4308 |
% is the default definition of |\eqa@defnumber|. |
| 4309 |
% |
| 4310 |
% \begin{macrocode} |
| 4311 |
\def\eqnarray{% |
| 4312 |
\eqnarray@i\eqa@eqcount% |
| 4313 |
} |
| 4314 |
\@namedef{eqnarray*}{\eqnarray@i{}} |
| 4315 |
\def\eqnarray@i#1{\@ifnextchar[{\eqnarray@ii{#1}}{\eqnarray@ii{#1}[rcl]}} |
| 4316 |
% \end{macrocode} |
| 4317 |
% |
| 4318 |
% Right. Now for the real work. The first argument is the default numbering |
| 4319 |
% tokens; the second is the preamble string. |
| 4320 |
% |
| 4321 |
% \begin{macrocode} |
| 4322 |
\def\eqnarray@ii#1[#2]{% |
| 4323 |
% \end{macrocode} |
| 4324 |
% |
| 4325 |
% Set up the equation counter and labels correctly. |
| 4326 |
% |
| 4327 |
% \medskip\par\noindent|\begin{rant}|\par |
| 4328 |
% The hacking with |\@currentlabel| is here because (in the author's opinion) |
| 4329 |
% \LaTeX's |\refstepcounter| macro is broken. It's currently defined as |
| 4330 |
% \begin{listing} |
| 4331 |
%\def\refstepcounter#1{% |
| 4332 |
% \stepcounter{#1}% |
| 4333 |
% \protected@edef\@currentlabel% |
| 4334 |
% {\csname p@#1\endcsname\csname the#1\endcsname}% |
| 4335 |
%} |
| 4336 |
% \end{listing} |
| 4337 |
% which means that the current label gets `frozen' as soon as you do the |
| 4338 |
% counter step. By redefining the macro as |
| 4339 |
% \begin{listing} |
| 4340 |
%\def\refstepcounter#1{% |
| 4341 |
% \stepcounter{#1}% |
| 4342 |
% \edef\@currentlabel{% |
| 4343 |
% \expandafter\noexpand\csname p@#1\endcsname% |
| 4344 |
% \expandafter\noexpand\csname the#1\endcsname% |
| 4345 |
% }% |
| 4346 |
%} |
| 4347 |
% \end{listing} |
| 4348 |
% these sorts of problems would be avoided, without any loss of functionality |
| 4349 |
% or compatibility that I can see. |
| 4350 |
% \par\noindent|\end{rant}|\par |
| 4351 |
% |
| 4352 |
% \begin{macrocode} |
| 4353 |
\stepcounter{equation}% |
| 4354 |
\def\@currentlabel{\p@equation\theequation}% |
| 4355 |
% \end{macrocode} |
| 4356 |
% |
| 4357 |
% The next step is to set up the numbering. I must save the old numbering |
| 4358 |
% so I can restore it later (once in the alignment, I must assign these |
| 4359 |
% things globally). |
| 4360 |
% |
| 4361 |
% \begin{macrocode} |
| 4362 |
\let\eqa@oldnumber\eqa@number% |
| 4363 |
\def\eqa@defnumber{#1}% |
| 4364 |
\global\let\eqa@number\eqa@defnumber% |
| 4365 |
% \end{macrocode} |
| 4366 |
% |
| 4367 |
% The |\if@eqalastfalse| switch is false everywhere except when we're in the |
| 4368 |
% final column. |
| 4369 |
% |
| 4370 |
% \begin{macrocode} |
| 4371 |
\@eqalastfalse% |
| 4372 |
% \end{macrocode} |
| 4373 |
% |
| 4374 |
% Remove the |\mathsurround| kerning, since it will look very odd inside |
| 4375 |
% the display. We have our own spacing parameters for configuring these |
| 4376 |
% things, so |\mathsurround| is unnecessary. |
| 4377 |
% |
| 4378 |
% \begin{macrocode} |
| 4379 |
\m@th% |
| 4380 |
% \end{macrocode} |
| 4381 |
% |
| 4382 |
% Time to parse the preamble string now. I must choose the correct column |
| 4383 |
% set, initialise the preamble parser and set up the various macros. The% |
| 4384 |
% extra `|@{\tabskip\eqacloseskip}|' item sets up the tabskip glue to centre |
| 4385 |
% the alignment properly. |
| 4386 |
% |
| 4387 |
% \begin{macrocode} |
| 4388 |
\colset{eqnarray}% |
| 4389 |
\tab@initread% |
| 4390 |
\def\tab@tabtext{&\tabskip\z@skip}% |
| 4391 |
\tab@preamble{\tabskip\z@skip}% |
| 4392 |
\tab@readpreamble{#2@{\tabskip\eqacloseskip}}% |
| 4393 |
\dsp@tabpause% |
| 4394 |
% \end{macrocode} |
| 4395 |
% |
| 4396 |
% Now for some final setting up. The column separation is set from the |
| 4397 |
% user's parameter, the |\everycr| tokens are cleared, and I set up the |
| 4398 |
% newline command appropriately. |
| 4399 |
% |
| 4400 |
% \begin{macrocode} |
| 4401 |
\[email protected]\eqainskip% |
| 4402 |
\everycr{}% |
| 4403 |
\let\\\@eqncr% |
| 4404 |
% \end{macrocode} |
| 4405 |
% |
| 4406 |
% Now start a maths display and do the alignment. Set up the left hand |
| 4407 |
% tabskip glue to centre the alignment, and do the actual alignment. |
| 4408 |
% The preamble used is mainly that generated from the user's string, although |
| 4409 |
% the stuff at the end is how we set up the equation number -- it repeats |
| 4410 |
% appropriately so we can always find it. |
| 4411 |
% |
| 4412 |
% \begin{macrocode} |
| 4413 |
\dsp@start% |
| 4414 |
\tabskip\eqaopenskip% |
| 4415 |
\halign to\displaywidth\expandafter\bgroup% |
| 4416 |
\the\tab@preamble% |
| 4417 |
&&\eqa@lastcol\hb@xt@\z@{\hss##}\tabskip\z@\cr% |
| 4418 |
} |
| 4419 |
% \end{macrocode} |
| 4420 |
% |
| 4421 |
% Now for the end of the environment. This is really easy. Set the final |
| 4422 |
% equation number, close the |\halign|, tidy up the equation counter (it's |
| 4423 |
% been stepped once too many times) and close the display. |
| 4424 |
% |
| 4425 |
% \begin{macrocode} |
| 4426 |
\def\endeqnarray{% |
| 4427 |
\eqa@eqnum% |
| 4428 |
\egroup% |
| 4429 |
\dsp@end% |
| 4430 |
\global\let\eqa@number\eqa@oldnumber% |
| 4431 |
\global\@ignoretrue% |
| 4432 |
\global\advance\c@equation\m@ne% |
| 4433 |
} |
| 4434 |
\expandafter\let\csname endeqnarray*\endcsname\endeqnarray |
| 4435 |
% \end{macrocode} |
| 4436 |
% |
| 4437 |
% \end{environment} |
| 4438 |
% \end{environment} |
| 4439 |
% |
| 4440 |
% Now we can define the column types. |
| 4441 |
% |
| 4442 |
% \begin{macrocode} |
| 4443 |
\colpush{eqnarray} |
| 4444 |
% \end{macrocode} |
| 4445 |
% |
| 4446 |
% Note the positioning of ord atoms in the stuff below. This will space out |
| 4447 |
% relations and binops correctly when they occur at the edges of columns, and |
| 4448 |
% won't affect ord atoms at the edges, because ords pack closely. |
| 4449 |
% |
| 4450 |
% First the easy onces. Just stick |\hfil| in the right places and |
| 4451 |
% everything will be all right. |
| 4452 |
% |
| 4453 |
% \begin{macrocode} |
| 4454 |
\coldef r{\tabcoltype{\hfil$\eqastyle}{{}$}} |
| 4455 |
\coldef c{\tabcoltype{\hfil$\eqastyle{}}{{}$\hfil}} |
| 4456 |
\coldef l{\tabcoltype{$\eqastyle{}}{$\hfil}} |
| 4457 |
\coldef x{\tabcoltype{\if@fleqn\else\hfil\fi$\eqastyle}{$\hfil}} |
| 4458 |
% \end{macrocode} |
| 4459 |
% |
| 4460 |
% Now for the textual ones. This is also fairly easy. |
| 4461 |
% |
| 4462 |
% \begin{macrocode} |
| 4463 |
\collet T [tabular]T |
| 4464 |
% \end{macrocode} |
| 4465 |
% |
| 4466 |
% Sort of split types of equations. I mustn't use |\rlap| here, or |
| 4467 |
% everything goes wrong -- |\\| doesn't get noticed by \TeX\ in the same way |
| 4468 |
% as |\cr| does. |
| 4469 |
% |
| 4470 |
% \begin{macrocode} |
| 4471 |
\coldef L{\tabcoltype{\hb@xt@2em\bgroup$\eqastyle}{$\hss\egroup}} |
| 4472 |
% \end{macrocode} |
| 4473 |
% |
| 4474 |
% The \lit{:} column type is fairly simple. |
| 4475 |
% |
| 4476 |
% \begin{macrocode} |
| 4477 |
\coldef :{\tabspctype{\tabskip\eqacolskip}} |
| 4478 |
\coldef q{\tabspctype{\quad}} |
| 4479 |
% \end{macrocode} |
| 4480 |
% |
| 4481 |
% The other column types just insert given text in an appropriate way. |
| 4482 |
% |
| 4483 |
% \begin{macrocode} |
| 4484 |
\collet > [tabular]> |
| 4485 |
\collet < [tabular]< |
| 4486 |
\collet * [tabular]* |
| 4487 |
\collet @ [tabular]@ |
| 4488 |
% \end{macrocode} |
| 4489 |
% |
| 4490 |
% Finally, the magical `|\magic|' column type, which sets the equation |
| 4491 |
% number. We set up the |\tabskip| glue properly, tab on, and set the flag |
| 4492 |
% which marks the final column. The |\eqa@lastcol| command is there to |
| 4493 |
% raise an error if the user tabs over to this column. I'll temporarily |
| 4494 |
% redefine it to |\@eqalasttrue| when I enter this column legitimately. |
| 4495 |
% The extra magical bits here will make the final column repeat, so that we |
| 4496 |
% can find it if necessary. Well is this column type named. |
| 4497 |
% |
| 4498 |
% That's it. We can return to normal now. |
| 4499 |
% |
| 4500 |
% \begin{macrocode} |
| 4501 |
\colpop |
| 4502 |
% \end{macrocode} |
| 4503 |
% |
| 4504 |
% \subsubsection{Newline codes} |
| 4505 |
% |
| 4506 |
% Newline sequences (|\\|) get turned into calls of |\@eqncr|. The job is |
| 4507 |
% fairly simple, really. |
| 4508 |
% |
| 4509 |
% \begin{macrocode} |
| 4510 |
\def\@eqncr{\tab@cr\eqacr@i\interdisplaylinepenalty\@M}% |
| 4511 |
\def\eqacr@i#1#2{% |
| 4512 |
\eqa@eqnum% |
| 4513 |
\noalign{\penalty#2\vskip\jot\vskip#1}% |
| 4514 |
} |
| 4515 |
% \end{macrocode} |
| 4516 |
% |
| 4517 |
% \subsubsection{Setting equation numbers} |
| 4518 |
% |
| 4519 |
% \begin{macro}{\eqa@eqpos} |
| 4520 |
% |
| 4521 |
% Before we start, we need to generalise the flush-left number handling bits. |
| 4522 |
% The macro |\eqa@eqpos| will put its argument in the right place. |
| 4523 |
% |
| 4524 |
% \begin{macrocode} |
| 4525 |
\if@leqno |
| 4526 |
\def\eqa@eqpos#1{% |
| 4527 |
\hb@[email protected]\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}% |
| 4528 |
} |
| 4529 |
\else |
| 4530 |
\def\eqa@eqpos#1{\normalfont\normalcolor#1} |
| 4531 |
\fi |
| 4532 |
% \end{macrocode} |
| 4533 |
% |
| 4534 |
% \end{macro} |
| 4535 |
% |
| 4536 |
% \begin{macro}{\eqa@eqnum} |
| 4537 |
% |
| 4538 |
% Here we typeset an equation number in roughly the right place. First I'll |
| 4539 |
% redefine |\eqa@lastcol| so that it tells me I'm in the right place, and |
| 4540 |
% start a loop to find that place. |
| 4541 |
% |
| 4542 |
% \begin{macrocode} |
| 4543 |
\def\eqa@eqnum{% |
| 4544 |
\global\let\eqa@lastcol\@eqalasttrue% |
| 4545 |
\eqa@eqnum@i% |
| 4546 |
} |
| 4547 |
% \end{macrocode} |
| 4548 |
% |
| 4549 |
% Now for the loop. The |\relax| here is absolutely vital -- it starts the |
| 4550 |
% table column, inserting useful tokens like `|\eqa@lastcol|' which tell |
| 4551 |
% me where I am in the alignment. Then, if I've reached the end, I can |
| 4552 |
% typeset the equation number; otherwise I go off into another macro and |
| 4553 |
% step on to the next column. |
| 4554 |
% |
| 4555 |
% \begin{macrocode} |
| 4556 |
\def\eqa@eqnum@i{% |
| 4557 |
\relax% |
| 4558 |
\if@eqalast% |
| 4559 |
\expandafter\eqa@eqnum@ii% |
| 4560 |
\else% |
| 4561 |
\expandafter\eqa@eqnum@iii% |
| 4562 |
\fi% |
| 4563 |
} |
| 4564 |
\def\eqa@eqnum@ii{% |
| 4565 |
\eqa@eqpos\eqa@number% |
| 4566 |
\global\let\eqa@number\eqa@defnumber% |
| 4567 |
\global\let\eqa@lastcol\eqa@@lastcol% |
| 4568 |
\cr% |
| 4569 |
} |
| 4570 |
\def\eqa@eqnum@iii{&\eqa@eqnum@i} |
| 4571 |
% \end{macrocode} |
| 4572 |
% |
| 4573 |
% \end{macro} |
| 4574 |
% |
| 4575 |
% \begin{macro}{\eqa@lastcol} |
| 4576 |
% |
| 4577 |
% This is used as a marker for the final column in an \env{eqnarray} |
| 4578 |
% environment. By default it informs the user that they've been very |
| 4579 |
% silly and swallows the contents of the column. I'll redefine it to |
| 4580 |
% something more useful at appropriate times, and then turn it back again. |
| 4581 |
% |
| 4582 |
% \begin{macrocode} |
| 4583 |
\def\eqa@@lastcol{\mth@err@number\setbox\z@} |
| 4584 |
\let\eqa@lastcol\eqa@@lastcol |
| 4585 |
% \end{macrocode} |
| 4586 |
% |
| 4587 |
% \end{macro} |
| 4588 |
% |
| 4589 |
% \subsubsection{Numbering control} |
| 4590 |
% |
| 4591 |
% \begin{macro}{\eqnumber} |
| 4592 |
% |
| 4593 |
% The |\eqnumber| command sets the equation number on the current equation. |
| 4594 |
% This is really easy, actually. |
| 4595 |
% |
| 4596 |
% \begin{macrocode} |
| 4597 |
\newcommand\eqnumber[1][\eqa@eqcount]{\gdef\eqa@number{#1}} |
| 4598 |
% \end{macrocode} |
| 4599 |
% |
| 4600 |
% \end{macro} |
| 4601 |
% |
| 4602 |
% \begin{macro}{\eqa@eqcount} |
| 4603 |
% |
| 4604 |
% This is how a standard equation number is set, stepping the counter and |
| 4605 |
% all. It's really easy and obvious. |
| 4606 |
% |
| 4607 |
% \begin{macrocode} |
| 4608 |
\def\eqa@eqcount{(\theequation)\global\advance\c@equation\@ne} |
| 4609 |
% \end{macrocode} |
| 4610 |
% |
| 4611 |
% \end{macro} |
| 4612 |
% |
| 4613 |
% \begin{macro}{\nonumber} |
| 4614 |
% |
| 4615 |
% The \LaTeX\ |\nonumber| command could be defined by saying |
| 4616 |
% \begin{listing} |
| 4617 |
%\renewcommand{\nonumber}{\eqnumber[]} |
| 4618 |
% \end{listing} |
| 4619 |
% but I'll be slightly more efficient and redefine |\eqa@number| directly. |
| 4620 |
% |
| 4621 |
% \begin{macrocode} |
| 4622 |
\def\nonumber{\global\let\eqa@number\@empty} |
| 4623 |
% \end{macrocode} |
| 4624 |
% |
| 4625 |
% \end{macro} |
| 4626 |
% |
| 4627 |
% \subsubsection{The \env{eqnalign} environment} |
| 4628 |
% |
| 4629 |
% As a sort of companion to \env{eqnarray}, here's an environment which does |
| 4630 |
% similar things inside a box, rather than taking up the whole display width. |
| 4631 |
% It uses the same column types that we've already created, so there should |
| 4632 |
% be no problems. |
| 4633 |
% |
| 4634 |
% \begin{environment}{eqnalign} |
| 4635 |
% |
| 4636 |
% First, sort out some simple things like optional arguments. |
| 4637 |
% |
| 4638 |
% \begin{macrocode} |
| 4639 |
\def\eqnalign{\@ifnextchar[\eqnalign@i{\eqnalign@i[rcl]}} |
| 4640 |
\def\eqnalign@i[#1]{% |
| 4641 |
\@ifnextchar[{\eqnalign@ii{#1}}{\eqnalign@ii{#1}[c]}% |
| 4642 |
} |
| 4643 |
% \end{macrocode} |
| 4644 |
% |
| 4645 |
% Now we actually do the environment. This is fairly easy, actually. |
| 4646 |
% |
| 4647 |
% \begin{macrocode} |
| 4648 |
\def\eqnalign@ii#1[#2]{% |
| 4649 |
\let\\\eqn@cr% |
| 4650 |
\colset{eqnarray}% |
| 4651 |
\tab@initread% |
| 4652 |
\def\tab@tabtext{&\tabskip\z@skip}% |
| 4653 |
\tabskip\z@skip% |
| 4654 |
\[email protected]\eqainskip% |
| 4655 |
\tab@readpreamble{#1}% |
| 4656 |
\everycr{}% |
| 4657 |
\if#2t\vtop\else% |
| 4658 |
\if#2b\vbox\else% |
| 4659 |
\vcenter% |
| 4660 |
\fi% |
| 4661 |
\fi% |
| 4662 |
\bgroup% |
| 4663 |
\halign\expandafter\bgroup\the\tab@preamble\cr% |
| 4664 |
} |
| 4665 |
% \end{macrocode} |
| 4666 |
% |
| 4667 |
% Finishing the environment is even simpler. |
| 4668 |
% |
| 4669 |
% \begin{macrocode} |
| 4670 |
\def\endeqnalign{% |
| 4671 |
\crcr% |
| 4672 |
\egroup% |
| 4673 |
\egroup% |
| 4674 |
} |
| 4675 |
% \end{macrocode} |
| 4676 |
% |
| 4677 |
% \end{environment} |
| 4678 |
% |
| 4679 |
% \begin{macro}{\eqn@cr} |
| 4680 |
% |
| 4681 |
% Newlines are really easy here. |
| 4682 |
% |
| 4683 |
% \begin{macrocode} |
| 4684 |
\def\eqn@cr{\tab@cr\eqn@cr@i{}{}} |
| 4685 |
\def\eqn@cr@i#1{\cr\noalign{\vskip\jot\vskip#1}\@gobble} |
| 4686 |
% \end{macrocode} |
| 4687 |
% |
| 4688 |
% \end{macro} |
| 4689 |
% |
| 4690 |
% |
| 4691 |
% \subsection{Simple multiline equations} |
| 4692 |
% |
| 4693 |
% As a sort of example and abbreviation, here's a multiline display |
| 4694 |
% environment which just centres everything. |
| 4695 |
% |
| 4696 |
% \begin{environment}{eqlines} |
| 4697 |
% |
| 4698 |
% We just get |\eqnarray| to do everything for us. This is really easy. |
| 4699 |
% |
| 4700 |
% \begin{macrocode} |
| 4701 |
\def\eqlines{\eqnarray[x]} |
| 4702 |
\let\endeqlines\endeqnarray |
| 4703 |
% \end{macrocode} |
| 4704 |
% |
| 4705 |
% \end{environment} |
| 4706 |
% |
| 4707 |
% \begin{environment}{eqlines*} |
| 4708 |
% |
| 4709 |
% There's a $*$ version which omits numbers. This is easy too. Lots of |
| 4710 |
% hacking with expansion here to try and reduce the number of tokens being |
| 4711 |
% used. Is it worth it? |
| 4712 |
% |
| 4713 |
% \begin{macrocode} |
| 4714 |
\expandafter\edef\csname eqlines*\endcsname{% |
| 4715 |
\expandafter\noexpand\csname eqnarray*\endcsname[x]% |
| 4716 |
} |
| 4717 |
\expandafter\let\csname endeqlines*\expandafter\endcsname |
| 4718 |
\csname endeqnarray*\endcsname |
| 4719 |
% \end{macrocode} |
| 4720 |
% |
| 4721 |
% \end{environment} |
| 4722 |
% |
| 4723 |
% |
| 4724 |
% \subsection{Split equations} |
| 4725 |
% |
| 4726 |
% Based on an idea from \textit{The \TeX book}, we provide some simple |
| 4727 |
% environments for doing split equations. These's plenty of scope for |
| 4728 |
% improvement here, though. |
| 4729 |
% |
| 4730 |
% \begin{environment}{spliteqn} |
| 4731 |
% \begin{environment}{spliteqn*} |
| 4732 |
% |
| 4733 |
% The only difference between these two is that the $*$-version doesn't put |
| 4734 |
% in an equation number by default (although this behaviour can be |
| 4735 |
% changed by |\eqnumber|). |
| 4736 |
% |
| 4737 |
% The fun here mainly concerns putting in the equation number at the right |
| 4738 |
% place -- for |leqno| users, we need to put the number on the first line; |
| 4739 |
% otherwise we put it on the last line. |
| 4740 |
% |
| 4741 |
% The way we handle this is to have two macros, |\\| (which clearly does |
| 4742 |
% all the user line breaks) and |\seq@lastcr| which is used at the end of |
| 4743 |
% the environment to wrap everything up. The |\seq@eqnocr| macro puts an |
| 4744 |
% equation number on the current line and then does a normal |\\|. It also |
| 4745 |
% resets |\\| and |\seq@lastcr| so that they don't try to put another |
| 4746 |
% equation number in. This must be done globally, although anyone who tries |
| 4747 |
% to nest maths displays will get what they deserve. |
| 4748 |
% |
| 4749 |
% For the non-$*$ environment, then, we need to step the equation counter, |
| 4750 |
% and set |\\| to |\seq@cr| or |\seq@eqnocr| as appropriate for the setting |
| 4751 |
% of the |leqno| flag -- |\seq@lastcr| always gets set to put an equation |
| 4752 |
% number in (because it will be reset if the number actually gets done |
| 4753 |
% earlier -- this catches stupid users trying to put a single row into |
| 4754 |
% a split environment). |
| 4755 |
% |
| 4756 |
% \begin{macrocode} |
| 4757 |
\def\spliteqn{% |
| 4758 |
\let\eqa@oldnumber\eqa@number% |
| 4759 |
\global\let\eqa@number\eqa@eqcount% |
| 4760 |
\spliteqn@i% |
| 4761 |
} |
| 4762 |
% \end{macrocode} |
| 4763 |
% |
| 4764 |
% For the $*$ variant, we don't need to bother with equation numbering, so |
| 4765 |
% this is really easy. |
| 4766 |
% |
| 4767 |
% \begin{macrocode} |
| 4768 |
\@namedef{spliteqn*}{% |
| 4769 |
\let\eqa@oldnumber\eqa@number% |
| 4770 |
\gdef\eqa@number{}% |
| 4771 |
\spliteqn@i% |
| 4772 |
} |
| 4773 |
% \end{macrocode} |
| 4774 |
% |
| 4775 |
% Ending the environments is easy. Most of the stuff here will be described |
| 4776 |
% later. |
| 4777 |
% |
| 4778 |
% \begin{macrocode} |
| 4779 |
\def\endspliteqn{% |
| 4780 |
\hfilneg\seq@lastcr% |
| 4781 |
\egroup% |
| 4782 |
\dsp@end% |
| 4783 |
\global\let\eqa@number\eqa@oldnumber% |
| 4784 |
\global\advance\c@equation\m@ne% |
| 4785 |
} |
| 4786 |
\expandafter\let\csname endspliteqn*\endcsname\endspliteqn |
| 4787 |
% \end{macrocode} |
| 4788 |
% |
| 4789 |
% \end{environment} |
| 4790 |
% \end{environment} |
| 4791 |
% |
| 4792 |
% \begin{macro}{\spliteqn@i} |
| 4793 |
% |
| 4794 |
% Here we handle the full display splits. Start a maths display, and make |
| 4795 |
% each row of the alignment take up the full display width. |
| 4796 |
% |
| 4797 |
% The macro |\seq@dosplit| does most of the real work for us -- setting up |
| 4798 |
% the alignment and so forth. The template column is interesting. There |
| 4799 |
% are two items glue on both sides of the actual text: |
| 4800 |
% |
| 4801 |
% \begin{itemize} |
| 4802 |
% |
| 4803 |
% \item Some glue which can shrink. This keeps the display from the edges |
| 4804 |
% of the page unless we get a really wide item. |
| 4805 |
% |
| 4806 |
% \item An |\hfil| to do the alignment. By default, this centres the |
| 4807 |
% equations. On the first line, however, we put a leading |\hfilneg| |
| 4808 |
% which cancels the first |\hfil|, making the first row left aligned. |
| 4809 |
% Similarly, at the end, we put an |\hfilneg| after the last equation |
| 4810 |
% to right align the last line. |
| 4811 |
% |
| 4812 |
% \end{itemize} |
| 4813 |
% |
| 4814 |
% We pass this information on as an argument. It's easy really. |
| 4815 |
% |
| 4816 |
% \begin{macrocode} |
| 4817 |
\def\spliteqn@i{% |
| 4818 |
% \end{macrocode} |
| 4819 |
% |
| 4820 |
% First, set up equation numbering properly. See my rant about |
| 4821 |
% |\refstepcounter| above. |
| 4822 |
% |
| 4823 |
% \begin{macrocode} |
| 4824 |
\stepcounter{equation}% |
| 4825 |
\def\@currentlabel{\p@equation\theequation}% |
| 4826 |
% \end{macrocode} |
| 4827 |
% |
| 4828 |
% Right; now to sort out the numbering and newline handling. If the number's |
| 4829 |
% meant to be on the first line (for \textsf{leqno} users), then it gets |
| 4830 |
% typeset on the first like; otherwise we just do a normal newline on |
| 4831 |
% all lines except the first. Once |\seq@eqnocr| has done its stuff, it |
| 4832 |
% redefines all the newline handling not to insert another number. |
| 4833 |
% |
| 4834 |
% \begin{macrocode} |
| 4835 |
\if@leqno% |
| 4836 |
\global\let\seq@docr\seq@eqnocr% |
| 4837 |
\else% |
| 4838 |
\global\let\seq@docr\seq@cr% |
| 4839 |
\fi% |
| 4840 |
\global\let\seq@lastcr\seq@eqnocr% |
| 4841 |
% \end{macrocode} |
| 4842 |
% |
| 4843 |
% For my next trick, I'll do some display handling -- start a (possibly |
| 4844 |
% nested) maths display, set up the |\tabpause| macro appropriately, and |
| 4845 |
% set the newline command to do the right thing. |
| 4846 |
% |
| 4847 |
% \begin{macrocode} |
| 4848 |
\dsp@start% |
| 4849 |
\dsp@tabpause% |
| 4850 |
\def\\{\seq@docr}% |
| 4851 |
% \end{macrocode} |
| 4852 |
% |
| 4853 |
% Finally, call another macro to do the remaining bits of setting up. |
| 4854 |
% |
| 4855 |
% \begin{macrocode} |
| 4856 |
\seq@dosplit% |
| 4857 |
{\hb@xt@\displaywidth{% |
| 4858 |
\hskip\splitleft\hfil$\displaystyle##$% |
| 4859 |
\hfil\hskip\splitright}}% |
| 4860 |
{\hfilneg}% |
| 4861 |
} |
| 4862 |
% \end{macrocode} |
| 4863 |
% |
| 4864 |
% \end{macro} |
| 4865 |
% |
| 4866 |
% \begin{environment}{subsplit} |
| 4867 |
% |
| 4868 |
% For doing splits in the middle of equations, we provide a similar |
| 4869 |
% environment. Here, we make |\\| just start a new line. We also use |
| 4870 |
% a |\vcenter| rather than a full maths display. The glue items are also |
| 4871 |
% a bit different: we use plain double-quads on each side of the item, and |
| 4872 |
% we need to remove them by hand at the extremeties of the environment. |
| 4873 |
% |
| 4874 |
% \begin{macrocode} |
| 4875 |
\def\subsplit{% |
| 4876 |
\let\\\seq@cr% |
| 4877 |
\vcenter\bgroup% |
| 4878 |
\seq@dosplit{\hfil\qquad$##$\qquad\hfil}{\hfilneg\hskip-2em}% |
| 4879 |
} |
| 4880 |
% \end{macrocode} |
| 4881 |
% |
| 4882 |
% Ending the environment is fairly easy. We remove the final glue item, |
| 4883 |
% and close the alignment and the vbox. |
| 4884 |
% |
| 4885 |
% \begin{macrocode} |
| 4886 |
\def\endsubsplit{% |
| 4887 |
\hfilneg\hskip-2em\cr% |
| 4888 |
\egroup\egroup% |
| 4889 |
} |
| 4890 |
% \end{macrocode} |
| 4891 |
% |
| 4892 |
% \end{environment} |
| 4893 |
% |
| 4894 |
% \begin{macro}{\seq@dosplit} |
| 4895 |
% |
| 4896 |
% Here we do most of the real work. Actually, since the preamble is passed |
| 4897 |
% in as an argument, most of the work is already done. The only thing to |
| 4898 |
% really note is the template for subsequent columns. To stop users putting |
| 4899 |
% in extra columns (which is where we put the equation number) we raise an |
| 4900 |
% error and discard the input in a scratch box register. This template is |
| 4901 |
% repeated infinitely so as to allow us to put the equation number in nicely. |
| 4902 |
% However, the final negative glue item won't work properly, so the equation |
| 4903 |
% will look awful. |
| 4904 |
% |
| 4905 |
% \begin{macrocode} |
| 4906 |
\def\seq@dosplit#1#2{% |
| 4907 |
\halign\bgroup% |
| 4908 |
#1&&\mth@err@number\setbox\z@\hbox{##}\cr% |
| 4909 |
#2\relax% |
| 4910 |
} |
| 4911 |
% \end{macrocode} |
| 4912 |
% |
| 4913 |
% \end{macro} |
| 4914 |
% |
| 4915 |
% \begin{macro}{\seq@eqnocr} |
| 4916 |
% |
| 4917 |
% Here's how we set equation numbers. Since the column provided raises |
| 4918 |
% errors as soon as a token finds its way into it, we start with a |&\omit|. |
| 4919 |
% Then we just put the equation number in a zero-width box. Finally, we |
| 4920 |
% reset the newline commands to avoid putting in more than one equation |
| 4921 |
% number, and do normal newline things. |
| 4922 |
% |
| 4923 |
% \begin{macrocode} |
| 4924 |
\def\seq@eqnocr{% |
| 4925 |
&\omit% |
| 4926 |
\hb@xt@\z@{\hss\eqa@eqpos\eqa@number}% |
| 4927 |
\global\let\seq@docr\seq@cr% |
| 4928 |
\global\let\seq@lastcr\seq@cr% |
| 4929 |
\seq@cr% |
| 4930 |
} |
| 4931 |
% \end{macrocode} |
| 4932 |
% |
| 4933 |
% \end{macro} |
| 4934 |
% |
| 4935 |
% \begin{macro}{\seq@cr} |
| 4936 |
% |
| 4937 |
% Newlines are very easy. We add a |\jot| of extra space, since this is |
| 4938 |
% a nice thing to do. |
| 4939 |
% |
| 4940 |
% \begin{macrocode} |
| 4941 |
\def\seq@cr{\tab@cr\seq@cr@i\interdisplaylinepenalty\@M} |
| 4942 |
\def\seq@cr@i#1#2{\cr\noalign{\penalty#2\vskip\jot\vskip#1}} |
| 4943 |
% \end{macrocode} |
| 4944 |
% |
| 4945 |
% \end{macro} |
| 4946 |
% |
| 4947 |
% |
| 4948 |
% \subsection{Matrix handling} |
| 4949 |
% |
| 4950 |
% There's been a complete and total overhaul of the spacing calculations |
| 4951 |
% for matrices here. The vertical spacing now bears an uncanny similarity |
| 4952 |
% to the rules \TeX\ uses to space out |\atop|-like fractions, the difference |
| 4953 |
% being that you can have more than one column in a matrix. This has the |
| 4954 |
% interesting side-effect that we get an \package{amsmath}-style |
| 4955 |
% sub/superscript environment almost free of charge with the matrix handling |
| 4956 |
% (it just ends up being a script-size single-column matrix). |
| 4957 |
% |
| 4958 |
% What is rather gratifying is that our \env{matrix} environment looks |
| 4959 |
% rather nicer than \package{amsmath}'s (which is based directly on |
| 4960 |
% \env{array}, giving it nasty restrictions on the numbers of columns and |
| 4961 |
% so on); in particular, the version here gives the `correct' result for |
| 4962 |
% Knuth's exercise~18.42 (which states categorically that a |\smallskip| |
| 4963 |
% should be placed between the rows of the big matrix). |
| 4964 |
% |
| 4965 |
% The reason the interrow space doesn't come out in the AMS version is |
| 4966 |
% that \env{array} inserts extra vertical space by extending the depth of |
| 4967 |
% the final row using a strut: the big matrix already extends deeper than |
| 4968 |
% this, so the strut doesn't make any difference. If the space was added |
| 4969 |
% by |\hlx{s[\smallskipamount]}| instead of the |\\| command, things would |
| 4970 |
% be different. |
| 4971 |
% |
| 4972 |
% \begin{figure} |
| 4973 |
% |
| 4974 |
% ^^A This is essentially what amsmath (version 1.2b) does. The real |
| 4975 |
% ^^A implementation requires a counter MaxMatrixCols, and has fewer braces: |
| 4976 |
% ^^A that's all the difference. Oh, and I turn off \arrayextrasep here, |
| 4977 |
% ^^A since amsmath doesn't expect it to be there (accurate emulation, see?) |
| 4978 |
% ^^A and I've used \hspace instead of \hskip since everything else is |
| 4979 |
% ^^A `proper' LaTeX stuff. |
| 4980 |
% |
| 4981 |
% \newenvironment{ams-pmatrix}{^^A |
| 4982 |
% \setlength{\arrayextrasep}{0pt}^^A |
| 4983 |
% \left(^^A |
| 4984 |
% \hspace{-\arraycolsep}^^A |
| 4985 |
% \begin{array}{*{10}{c}}^^A |
| 4986 |
% }{^^A |
| 4987 |
% \end{array}^^A |
| 4988 |
% \hspace{-\arraycolsep}^^A |
| 4989 |
% \right)^^A |
| 4990 |
% } |
| 4991 |
% |
| 4992 |
% \begin{demo}{Exercise 18.42 from \emph{The \TeX book}} |
| 4993 |
%\newcommand{\domatrix}[1]{ |
| 4994 |
% \def\mat##1 |
| 4995 |
% {\begin{#1}##1\end{#1}} |
| 4996 |
% \[ \begin{#1} |
| 4997 |
% \mat{a & b \\ c & d} & |
| 4998 |
% \mat{e & f \\ g & h} |
| 4999 |
% \\[\smallskipamount] |
| 5000 |
% 0 & |
| 5001 |
% \mat{i & j \\ k & l} |
| 5002 |
% \end{#1} |
| 5003 |
% \] |
| 5004 |
%} |
| 5005 |
%\domatrix{pmatrix} |
| 5006 |
%\domatrix{ams-pmatrix} |
| 5007 |
% \end{demo} |
| 5008 |
% |
| 5009 |
% \end{figure} |
| 5010 |
% |
| 5011 |
% \begin{environment}{genmatrix} |
| 5012 |
% |
| 5013 |
% The first job is to store my maths style and font away, because I'll be |
| 5014 |
% needing it lots later. |
| 5015 |
% |
| 5016 |
% \begin{macrocode} |
| 5017 |
\def\genmatrix#1#2#3#4#5{% |
| 5018 |
\let\mat@style#1% |
| 5019 |
\ifx#2\scriptstyle% |
| 5020 |
\let\mat@font\scriptfont% |
| 5021 |
\else\ifx#2\scriptscriptstyle% |
| 5022 |
\let\mat@font\scriptscriptfont% |
| 5023 |
\else% |
| 5024 |
\let\mat@font\textfont% |
| 5025 |
\fi\fi% |
| 5026 |
% \end{macrocode} |
| 5027 |
% |
| 5028 |
% Now to cope with inserted text. This is easy. |
| 5029 |
% |
| 5030 |
% \begin{macrocode} |
| 5031 |
\ifx\mat@style\scriptstyle% |
| 5032 |
\let\mat@textsize\scriptsize% |
| 5033 |
\else\ifx\mat@style\scriptscriptstyle% |
| 5034 |
\let\mat@textsize\scriptscriptsize% |
| 5035 |
\else% |
| 5036 |
\let\mat@textsize\relax% |
| 5037 |
\fi\fi% |
| 5038 |
% \end{macrocode} |
| 5039 |
% |
| 5040 |
% Now for some fun. I'll remember how to start and end the matrix in a |
| 5041 |
% couple of macros |\mat@left| and |\mat@right|. I haven't yet worked out |
| 5042 |
% exactly what needs to be in |\mat@right| yet, though, so I'll build that |
| 5043 |
% up in a scratch token list while I'm making my mind up. |
| 5044 |
% |
| 5045 |
% Initially, I want to open a group (to trap the style changes), set the |
| 5046 |
% maths style (to get the right spacing), insert the left delimiter, insert |
| 5047 |
% some spacing around the matrix, and start a centred box. The ending just |
| 5048 |
% closes all the groups and delimiters I opened. |
| 5049 |
% |
| 5050 |
% \begin{macrocode} |
| 5051 |
\def\mat@left{\bgroup\mat@style\left#4#3\vcenter\bgroup}% |
| 5052 |
\toks@{\egroup#3\right#5\egroup}% |
| 5053 |
% \end{macrocode} |
| 5054 |
% |
| 5055 |
% Now comes a slightly trickier bit. If the maths style is script or |
| 5056 |
% scriptscript, then I need to raise the box by a little bit to make it look |
| 5057 |
% really good. The right amount is somewhere around \smallf 3/4\,pt, I |
| 5058 |
% think, so that's what I'll use. |
| 5059 |
% |
| 5060 |
% \begin{macrocode} |
| 5061 |
\@tempswatrue% |
| 5062 |
\ifx\mat@style\displaystyle\else\ifx\mat@style\textstyle\else% |
| 5063 |
\@tempswafalse% |
| 5064 |
\setbox\z@\hbox\bgroup$% |
| 5065 |
\toks@\expandafter{\the\toks@$\m@th\egroup\raise.75\p@\box\z@}% |
| 5066 |
\fi\fi% |
| 5067 |
% \end{macrocode} |
| 5068 |
% |
| 5069 |
% If I'm not in maths mode right now, then I should enter maths mode, and |
| 5070 |
% remember to leave it later. |
| 5071 |
% |
| 5072 |
% \begin{macrocode} |
| 5073 |
\if@tempswa\ifmmode\else% |
| 5074 |
$\m@th% |
| 5075 |
\toks@\expandafter{\the\toks@$}% |
| 5076 |
\fi\fi% |
| 5077 |
% \end{macrocode} |
| 5078 |
% |
| 5079 |
% Now I've sorted out how to end the environment properly, so I can set up |
| 5080 |
% the macro, using |\edef|. |
| 5081 |
% |
| 5082 |
% \begin{macrocode} |
| 5083 |
\edef\mat@right{\the\toks@}% |
| 5084 |
% \end{macrocode} |
| 5085 |
% |
| 5086 |
% Now see if there's an optional argument. If not, create lots of centred |
| 5087 |
% columns. |
| 5088 |
% |
| 5089 |
% \begin{macrocode} |
| 5090 |
\@ifnextchar[\genmatrix@i{\genmatrix@i[[c]}% |
| 5091 |
} |
| 5092 |
% \end{macrocode} |
| 5093 |
% |
| 5094 |
% Now to sort out everything else. |
| 5095 |
% |
| 5096 |
% \begin{macrocode} |
| 5097 |
\def\genmatrix@i[#1]{% |
| 5098 |
% \end{macrocode} |
| 5099 |
% |
| 5100 |
% Some initial setting up: choose the correct column set, and set up some |
| 5101 |
% variables for reading the preamble. |
| 5102 |
% |
| 5103 |
% \begin{macrocode} |
| 5104 |
\colset{matrix}% |
| 5105 |
\tab@initread% |
| 5106 |
% \end{macrocode} |
| 5107 |
% |
| 5108 |
% Now comes some of the tricky stuff. The space between columns should be |
| 5109 |
% 12\,mu (by trial and error). We put the space in a box so we can measure |
| 5110 |
% it in the correct mathstyle. |
| 5111 |
% |
| 5112 |
% \begin{macrocode} |
| 5113 |
\setbox\z@\hbox{$\mat@style\mskip12mu$}% |
| 5114 |
\edef\tab@tabtext{&\kern\the\wd\z@}% |
| 5115 |
\tab@readpreamble{#1}% |
| 5116 |
% \end{macrocode} |
| 5117 |
% |
| 5118 |
% Now we need to decide how to space out the rows. The code here is based |
| 5119 |
% on the information in appendix~G of \emph{The \TeX book}: I think it'd be |
| 5120 |
% nice if my matrices were spaced out in the same way as normal fractions |
| 5121 |
% (particularly |\choose|y things). The standard |\baselineskip| and |
| 5122 |
% |\lineskip| parameters come in really handy here. |
| 5123 |
% |
| 5124 |
% The parameters vary according to the size of the text, so I need to see |
| 5125 |
% if we have scriptsize or less, or not. The tricky |\if| sorts this out. |
| 5126 |
% |
| 5127 |
% \begin{macrocode} |
| 5128 |
\if1\ifx\mat@style\scriptstyle1\else% |
| 5129 |
\ifx\mat@style\scriptscriptstyle1\else0\fi\fi% |
| 5130 |
\baselineskip\fontdimen10\mat@font\tw@% |
| 5131 |
\advance\baselineskip\fontdimen12\mat@font\tw@% |
| 5132 |
\lineskip\thr@@\fontdimen8\mat@font\thr@@% |
| 5133 |
\else% |
| 5134 |
\baselineskip\fontdimen8\mat@font\tw@% |
| 5135 |
\advance\baselineskip\fontdimen11\mat@font\tw@% |
| 5136 |
\lineskip7\fontdimen8\mat@font\thr@@% |
| 5137 |
\fi% |
| 5138 |
\lineskiplimit\lineskip% |
| 5139 |
% \end{macrocode} |
| 5140 |
% |
| 5141 |
% Now actually set up for the alignment. Assign |\\| to the correct value. |
| 5142 |
% Set up the |\tabskip|. Do the appropriate |\mat@left| thing set up above. |
| 5143 |
% And then start the alignment. |
| 5144 |
% |
| 5145 |
% \begin{macrocode} |
| 5146 |
\let\\\mat@cr% |
| 5147 |
\tabskip\z@skip% |
| 5148 |
\col@sep\z@% |
| 5149 |
\mat@left% |
| 5150 |
\halign\expandafter\bgroup\the\tab@preamble\tabskip\z@skip\cr% |
| 5151 |
% \end{macrocode} |
| 5152 |
% |
| 5153 |
% Now for a little hack to make the spacing consistent between matrices of |
| 5154 |
% the same height. This comes directly from \PlainTeX. This appears to |
| 5155 |
% make the spacing \emph{exactly} the same as the \TeX\ primites, oddly |
| 5156 |
% enough. |
| 5157 |
% |
| 5158 |
% \begin{macrocode} |
| 5159 |
\ifx\mat@font\textfont% |
| 5160 |
\omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}% |
| 5161 |
\fi% |
| 5162 |
} |
| 5163 |
% \end{macrocode} |
| 5164 |
% |
| 5165 |
% Finishing the environment is really easy. We do the spacing hack again |
| 5166 |
% at the bottom, close the alignment and then tidy whatever we started in |
| 5167 |
% |\mat@left|. |
| 5168 |
% |
| 5169 |
% \begin{macrocode} |
| 5170 |
\def\endgenmatrix{% |
| 5171 |
\crcr% |
| 5172 |
\ifx\mat@font\textfont% |
| 5173 |
\omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}% |
| 5174 |
\fi% |
| 5175 |
\egroup% |
| 5176 |
\mat@right% |
| 5177 |
} |
| 5178 |
% \end{macrocode} |
| 5179 |
% |
| 5180 |
% \end{environment} |
| 5181 |
% |
| 5182 |
% \begin{macro}{\mat@cr} |
| 5183 |
% |
| 5184 |
% Newlines are really easy. The $*$-form means nothing here, so we ignore |
| 5185 |
% it. |
| 5186 |
% |
| 5187 |
% \begin{macrocode} |
| 5188 |
\def\mat@cr{\tab@cr\mat@cr@i{}{}} |
| 5189 |
\def\mat@cr@i#1{\cr\noalign{\vskip#1}\@gobble} |
| 5190 |
% \end{macrocode} |
| 5191 |
% |
| 5192 |
% \end{macro} |
| 5193 |
% |
| 5194 |
% \begin{macro}{\newmatrix} |
| 5195 |
% |
| 5196 |
% This is how we define new matrix environments. It's simple fun with |
| 5197 |
% |\csname| and |\expandafter|. |
| 5198 |
% |
| 5199 |
% \begin{macrocode} |
| 5200 |
\def\newmatrix#1#2{% |
| 5201 |
\@namedef{#1}{\genmatrix#2}% |
| 5202 |
\expandafter\let\csname end#1\endcsname\endgenmatrix% |
| 5203 |
} |
| 5204 |
% \end{macrocode} |
| 5205 |
% |
| 5206 |
% \end{macro} |
| 5207 |
% |
| 5208 |
% \begin{environment}{matrix} |
| 5209 |
% \begin{environment}{pmatrix} |
| 5210 |
% \begin{environment}{dmatrix} |
| 5211 |
% \begin{environment}{smatrix} |
| 5212 |
% \begin{environment}{spmatrix} |
| 5213 |
% \begin{environment}{sdmatrix} |
| 5214 |
% \begin{environment}{smatrix*} |
| 5215 |
% \begin{environment}{spmatrix*} |
| 5216 |
% \begin{environment}{sdmatrix*} |
| 5217 |
% |
| 5218 |
% Now we define all the other environments we promised. This is easy. |
| 5219 |
% |
| 5220 |
% \begin{macrocode} |
| 5221 |
\newmatrix{matrix}{{\textstyle}{\textstyle}{\,}{.}{.}} |
| 5222 |
\newmatrix{pmatrix}{{\textstyle}{\textstyle}{\,}{(}{)}} |
| 5223 |
\newmatrix{dmatrix}{{\textstyle}{\textstyle}{\,}} |
| 5224 |
\newmatrix{smatrix}{{\scriptstyle}{\scriptstyle}{}{.}{.}} |
| 5225 |
\newmatrix{spmatrix}{{\scriptstyle}{\scriptstyle}{}{(}{)}} |
| 5226 |
\newmatrix{sdmatrix}{{\scriptstyle}{\scriptstyle}{}} |
| 5227 |
\newmatrix{smatrix*}{{\scriptstyle}{\textstyle}{}{.}{.}} |
| 5228 |
\newmatrix{spmatrix*}{{\scriptstyle}{\textstyle}{}{(}{)}} |
| 5229 |
\newmatrix{sdmatrix*}{{\scriptstyle}{\textstyle}{}} |
| 5230 |
% \end{macrocode} |
| 5231 |
% |
| 5232 |
% \end{environment} |
| 5233 |
% \end{environment} |
| 5234 |
% \end{environment} |
| 5235 |
% \end{environment} |
| 5236 |
% \end{environment} |
| 5237 |
% \end{environment} |
| 5238 |
% \end{environment} |
| 5239 |
% \end{environment} |
| 5240 |
% \end{environment} |
| 5241 |
% |
| 5242 |
% \begin{environment}{script} |
| 5243 |
% |
| 5244 |
% Now for superscripts and subscripts. This is fairly easy, because I |
| 5245 |
% took so much care over the matrix handling. |
| 5246 |
% |
| 5247 |
% \begin{macrocode} |
| 5248 |
\def\script{% |
| 5249 |
\let\mat@style\scriptstyle% |
| 5250 |
\def\mat@left{\vcenter\bgroup}% |
| 5251 |
\def\mat@right{\egroup}% |
| 5252 |
\let\mat@font\scriptfont% |
| 5253 |
\let\mat@textsize\scriptsize% |
| 5254 |
\@ifnextchar[\genmatrix@i{\genmatrix@i[c]}% |
| 5255 |
} |
| 5256 |
\let\endscript\endgenmatrix |
| 5257 |
% \end{macrocode} |
| 5258 |
% |
| 5259 |
% \end{environment} |
| 5260 |
% |
| 5261 |
% Now define the column types. |
| 5262 |
% |
| 5263 |
% \begin{macrocode} |
| 5264 |
\colpush{matrix} |
| 5265 |
\coldef l{\tabcoltype{\kern\z@$\mat@style}{\m@th$\hfil}} |
| 5266 |
\coldef c{\tabcoltype{\hfil$\mat@style}{\m@th$\hfil}} |
| 5267 |
\coldef r{\tabcoltype{\hfil$\mat@style}{\m@th$}} |
| 5268 |
\coldef T#1{\tab@aligncol{#1}{\begingroup\mat@textsize}{\endgroup}} |
| 5269 |
% \end{macrocode} |
| 5270 |
% |
| 5271 |
% The repeating type is more awkward. Things will go wrong if this is |
| 5272 |
% given before the first column, so we must do a whole repeat by hand. We |
| 5273 |
% can tell if we haven't contributed a column yet, since |\tab@column| will |
| 5274 |
% be zero. Otherwise, we fiddle the parser state to start a new column, and |
| 5275 |
% insert the |&| character to make \TeX\ repeat the preamble. |
| 5276 |
% |
| 5277 |
% \begin{macrocode} |
| 5278 |
\coldef {[}{% |
| 5279 |
\@firstoftwo{% |
| 5280 |
\ifnum\tab@columns=\z@% |
| 5281 |
\def\@tempa##1\q@delim{% |
| 5282 |
\tab@mkpreamble##1[##1\q@delim% |
| 5283 |
}% |
| 5284 |
\expandafter\@tempa% |
| 5285 |
\else% |
| 5286 |
\tab@setstate\tab@prestate% |
| 5287 |
\tab@append\tab@preamble{&}% |
| 5288 |
\expandafter\tab@mkpreamble% |
| 5289 |
\fi% |
| 5290 |
}% |
| 5291 |
} |
| 5292 |
% \end{macrocode} |
| 5293 |
% |
| 5294 |
% We're done defining columns now. |
| 5295 |
% |
| 5296 |
% \begin{macrocode} |
| 5297 |
\colpop |
| 5298 |
% \end{macrocode} |
| 5299 |
% |
| 5300 |
% |
| 5301 |
% \subsection{Dots\dots} |
| 5302 |
% |
| 5303 |
% Nothing whatsoever to do with alignments, although vertical and diagonal |
| 5304 |
% dots in small matrices look really silly. The following hacky definitions |
| 5305 |
% work rather better. |
| 5306 |
% |
| 5307 |
% \begin{macro}{\mdw@dots} |
| 5308 |
% |
| 5309 |
% First of all, here's some definitions common to both of the dots macros. |
| 5310 |
% The macro takes as an argument the actual code to draw the dots, passing |
| 5311 |
% it the scaled size of a point in the scratch register |\dimen@|; the |
| 5312 |
% register |\box 0| is set to contain a dot of the appropriate size. |
| 5313 |
% |
| 5314 |
% \begin{macrocode} |
| 5315 |
\def\mdw@dots#1{\ensuremath{\mathpalette\mdw@dots@i{#1}}} |
| 5316 |
\def\mdw@dots@i#1#2{% |
| 5317 |
\setbox\z@\hbox{$#1\mskip1.8mu$}% |
| 5318 |
\dimen@\wd\z@% |
| 5319 |
\setbox\z@\hbox{$#1.$}% |
| 5320 |
#2% |
| 5321 |
} |
| 5322 |
% \end{macrocode} |
| 5323 |
% |
| 5324 |
% \end{macro} |
| 5325 |
% |
| 5326 |
% \begin{macro}{\vdots} |
| 5327 |
% |
| 5328 |
% I'll start with the easy one. This is a simple translation of the original |
| 5329 |
% implementation. |
| 5330 |
% |
| 5331 |
% \begin{macrocode} |
| 5332 |
\def\vdots{% |
| 5333 |
\mdw@dots{\vbox{% |
| 5334 |
\baselineskip4\dimen@% |
| 5335 |
\lineskiplimit\z@% |
| 5336 |
\kern6\dimen@% |
| 5337 |
\copy\z@\copy\z@\box\z@% |
| 5338 |
}}% |
| 5339 |
} |
| 5340 |
% \end{macrocode} |
| 5341 |
% |
| 5342 |
% \end{macro} |
| 5343 |
% |
| 5344 |
% \begin{macro}{\ddots} |
| 5345 |
% |
| 5346 |
% And I'll end with the other easy one\dots |
| 5347 |
% |
| 5348 |
% \begin{macrocode} |
| 5349 |
\def\ddots{% |
| 5350 |
\mdw@dots{\mathinner{% |
| 5351 |
\mkern1mu% |
| 5352 |
\raise7\dimen@\vbox{\kern7\dimen@\copy\z@}% |
| 5353 |
\mkern2mu% |
| 5354 |
\raise4\dimen@\copy\z@% |
| 5355 |
\mkern2mu% |
| 5356 |
\raise\dimen@\box\z@% |
| 5357 |
\mkern1mu% |
| 5358 |
}}% |
| 5359 |
} |
| 5360 |
% \end{macrocode} |
| 5361 |
% |
| 5362 |
% \end{macro} |
| 5363 |
% |
| 5364 |
% |
| 5365 |
% \subsection{Lucky dip} |
| 5366 |
% |
| 5367 |
% Time to round off with some trivial environments, just to show how easy |
| 5368 |
% this stuff is. |
| 5369 |
% |
| 5370 |
% \begin{environment}{cases} |
| 5371 |
% \begin{environment}{smcases} |
| 5372 |
% |
| 5373 |
% These are totally and utterly trivial. |
| 5374 |
% |
| 5375 |
% \begin{macrocode} |
| 5376 |
\def\cases{\left\{\,\array{@{}lTl@{}}} |
| 5377 |
\def\endcases{\endarray\,\right.} |
| 5378 |
\def\smcases{\left\{\smarray{@{}lTl@{}}} |
| 5379 |
\def\endsmcases{\endsmarray\,\right.} |
| 5380 |
% \end{macrocode} |
| 5381 |
% |
| 5382 |
% \end{environment} |
| 5383 |
% \end{environment} |
| 5384 |
% |
| 5385 |
% \subsection{Error messages} |
| 5386 |
% |
| 5387 |
% Some token saving: |
| 5388 |
% |
| 5389 |
% \begin{macrocode} |
| 5390 |
\def\mth@error{\PackageError{mathenv}} |
| 5391 |
% \end{macrocode} |
| 5392 |
% |
| 5393 |
% Now for the error messages. |
| 5394 |
% |
| 5395 |
% \begin{macrocode} |
| 5396 |
\def\mth@err@number{% |
| 5397 |
\mth@error{Too many `&' characters found}{% |
| 5398 |
You've put too many `&' characters in an alignment^^J% |
| 5399 |
environment (like `eqnarray' or `spliteqn') and wandered^^J% |
| 5400 |
into trouble. I've gobbled the contents of that column^^J% |
| 5401 |
and hopefully I can recover fairly easily.% |
| 5402 |
}% |
| 5403 |
} |
| 5404 |
% \end{macrocode} |
| 5405 |
% |
| 5406 |
% \begin{macrocode} |
| 5407 |
\def\mth@err@mdsp{% |
| 5408 |
\mth@error{Can't do displays in nondisplay maths mode}{% |
| 5409 |
You're trying to start a display environment, but you're^^J% |
| 5410 |
in nondisplay maths mode. The display will appear but^^J% |
| 5411 |
don't blame me when it looks horrible.% |
| 5412 |
}% |
| 5413 |
} |
| 5414 |
% \end{macrocode} |
| 5415 |
% |
| 5416 |
% \begin{macrocode} |
| 5417 |
\def\mth@err@hdsp{% |
| 5418 |
\mth@error{Can't do displays in LR mode}{% |
| 5419 |
You're trying to start a display environment, but you're^^J% |
| 5420 |
in LR (restricted horizontal) mode. Everything will go^^J% |
| 5421 |
totally wrong, so your best bet is to type `X', fix the^^J% |
| 5422 |
mistake and start again.% |
| 5423 |
}% |
| 5424 |
} |
| 5425 |
% \end{macrocode} |
| 5426 |
% |
| 5427 |
% \vskip\parskip\vbox{ ^^A The best way I could find of keeping this lot |
| 5428 |
% ^^A together, I'm afraid. |
| 5429 |
% That's all there is. Byebye. |
| 5430 |
% |
| 5431 |
% \begin{macrocode} |
| 5432 |
%</mathenv> |
| 5433 |
% \end{macrocode} |
| 5434 |
% \nopagebreak |
| 5435 |
% |
| 5436 |
% \hfill Mark Wooding, \today |
| 5437 |
% } |
| 5438 |
% |
| 5439 |
% \Finale |
| 5440 |
% |
| 5441 |
\endinput |