3 % $Id: mdwmath.dtx,v 1.1 2002/02/03 20:49:03 mdw Exp $
5 % Various nicer mathematical things
7 % (c) 1996 Mark Wooding
9 %----- Revision history -----------------------------------------------------
11 % $Log: mdwmath.dtx,v $
12 % Revision 1.1 2002/02/03 20:49:03 mdw
13 % Checkin for new build system.
15 % Revision 1.1 1996/11/19 20:53:21 mdw
21 % \begin{meta-comment} <general public licence>
23 %% mdwmath package -- various nicer mathematical things
24 %% Copyright (c) 1996 Mark Wooding
26 %% This program is free software; you can redistribute it and/or modify
27 %% it under the terms of the GNU General Public License as published by
28 %% the Free Software Foundation; either version 2 of the License, or
29 %% (at your option) any later version.
31 %% This program is distributed in the hope that it will be useful,
32 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
33 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 %% GNU General Public License for more details.
36 %% You should have received a copy of the GNU General Public License
37 %% along with this program; if not, write to the Free Software
38 %% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 % \begin{meta-comment} <Package preamble>
43 %<+package>\NeedsTeXFormat{LaTeX2e}
44 %<+package>\ProvidesPackage{mdwmath}
45 %<+package> [2000/07/02 1.2 Nice mathematical things]
46 %<+oldeqnarray>\NeedsTeXFormat{LaTeX2e}
47 %<+oldeqnarray>\ProvidesPackage{eqnarray}
48 %<+oldeqnarray> [1996/04/11 1.1 Old enhanced eqnarray]
53 %% {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
54 %% 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
55 %% Digits \0\1\2\3\4\5\6\7\8\9
56 %% Exclamation \! Double quote \" Hash (number) \#
57 %% Dollar \$ Percent \% Ampersand \&
58 %% Acute accent \' Left paren \( Right paren \)
59 %% Asterisk \* Plus \+ Comma \,
60 %% Minus \- Point \. Solidus \/
61 %% Colon \: Semicolon \; Less than \<
62 %% Equals \= Greater than \> Question mark \?
63 %% Commercial at \@ Left bracket \[ Backslash \\
64 %% Right bracket \] Circumflex \^ Underscore \_
65 %% Grave accent \` Left brace \{ Vertical bar \|
66 %% Right brace \} Tilde \~}
69 % \begin{meta-comment}
75 \describespackage{mdwmath}
76 % \describespackage{eqnarray}
77 \ignoreenv{old-eqnarray}
78 % \unignoreenv{old-eqnarray}
84 % \section{User guide}
86 % \subsection{Square root typesetting}
88 % \DescribeMacro{\sqrt}
89 % The package supplies a star variant of the |\sqrt| command which omits the
90 % vinculum over the operand (the line over the top). While this is most
91 % useful in simple cases like $\sqrt*{2}$ it works for any size of operand.
92 % The package also re-implements the standard square root command so that it
93 % positions the root number rather better.
96 % \begin{demo}[w]{Examples of the new square root command}
97 %\[ \sqrt*{2} \quad \mbox{rather than} \quad \sqrt{2} \]
98 %\[ \sqrt*[3]{2} \quad \mbox{ rather than } \quad \sqrt[3]{2} \]
99 %\[ \sqrt{x^3 + \sqrt*[y]{\alpha}} - \sqrt*[n+1]{a} \]
100 %\[ x = \sqrt*[3]{\frac{3y}{7}} \]
101 %\[ q = \frac{2\sqrt*{2}}{5}+\sqrt[\frac{n+1}{2}]{2x^2+3xy-y^2} \]
105 % [Note that omission of the vinculum was originally a cost-cutting exercise
106 % because the radical symbol can just fit in next to its operand and
107 % everything ends up being laid out along a line. However, I find that the
108 % square root without vinculum is less cluttered, so I tend to use it when
109 % it doesn't cause ambiguity.]
111 % \subsection{Modular arithmetic}
113 % In standard maths mode, there's too much space before the parentheses in
114 % the output of the |\pmod| command. Suppose that $x \equiv y^2 \opmod n$:
115 % then the spacing looks awful. Go on, admit it.
117 % It looks OK in a display. For example, if
118 % \[ c \equiv m^e \opmod n \]
119 % then it's fine. The package redefines the |\pmod| command to do something
120 % more sensible. So now $c^d \equiv m^{ed} \equiv m \pmod n$ and all looks
123 % \subsection{Some maths symbols you already have}
125 % \DescribeMacro\bitor
126 % \DescribeMacro\bitand
127 % \DescribeMacro\dblor
128 % \DescribeMacro\dbland
129 % Having just tried to do some simple things, I've found that there are maths
130 % symbols missing. Here they are, in all their glory:
131 % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
132 % $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\
133 % $\bitand$ & "\bitand" & $\dblor$ & "\dblor" &
134 % \end{tabular} \end{center}
138 % I also set up the |\xor| command to typeset `$\xor$', which is commonly
139 % used to represent the bitsize exclusive-or operation among cryptographers.
140 % The command |\cat| typesets `$\cat$', which is a common operator indicating
141 % concatenation of strings.
147 % The commands |\lsl| and |\lsr| typeset binary operators `$\lsl$' and
148 % `$\lsr$' respectively, and |\rol| and |\ror| typeset `$\rol$' and `$\ror$'.
149 % Note that these are spaced as binary operators, rather than relations.
151 % \DescribeMacro\compose
152 % \DescribeMacro\implies
153 % \DescribeMacro\vect
154 % The |\compose| command typesets `$\compose$', which is usually used to
155 % denote function composition. The |\implies| command is made to typeset
156 % `$\implies$'. And \syntax{"\\vect{"<x>"}"} typesets `$\vect{x}$'.
158 % \DescribeMacro\statclose
159 % \DescribeMacro\compind
160 % The |\statclose| command typesets `$\statclose$', which indicates
161 % `statistical closeness' of probability distributions; |\compind| typesets
162 % `$\compind$', which indicates computational indistinguishability.
164 % \DescribeMacro\jacobi
165 % The |\jacobi{x}{n}| command typesets `$\jacobi{x}{n}$', which may be of use
166 % to number theorists talking about Jacobi or Lagrange symbols.
168 % \subsection{Rant about derivatives}
171 % There is a difference between UK and US typesetting of derivatives.
173 % \[ \frac{dy}{dx} \]
174 % while the British want
175 % \[ \frac{\d y}{\d x}. \]
176 % The command |\d| command is fixed to typeset a `$\d$'. If you want the
177 % accent, try |\a{d}{x}|, which typesets `\a{d}{x}'.
179 % \subsection{New operator names}
181 % \DescribeMacro\keys
184 % \DescribeMacro\supp
186 % A few esoteric new operator names are supplied.
187 % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
188 % $\keys$ & "\keys" & $\dom$ & "\dom" & $\ran$ & "\ran" \\
189 % $\supp$ & "\supp" & $\lcm$ & "\lcm"
190 % \end{tabular} \end{center}
191 % I think |\lcm| ought to be self-explanatory. The |\dom| and |\ran|
192 % operators pick out the domain and range of a function, respectively; thus,
193 % if $F\colon X \to Y$ is a function, then $\dom F = X$ and $\ran F = Y$.
194 % The \emph{support} of a probability distribution $\mathcal{D}$ is the set
195 % of objects with nonzero probability; i.e., $\supp{D} = \{\, x \in
196 % \dom\mathcal{D} \mid \mathcal{D}(x) > 0 \,\}$.
198 % \subsection{Standard set names}
206 % \DescribeMacro\powerset
207 % If you have a |\mathbb| command defined, the following magic is revealed:
208 % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
209 % $\Z$ & "\Z" & $\Q$ & "\Q" & $\R$ & "\R" \\
210 % $\N$ & "\N" & $\F$ & "\F" & $\C$ & "\C"
211 % \end{tabular} \end{center}
212 % which are handy for various standard sets of things. Also the |\powerset|
213 % command typesets `$\powerset$'.
215 % \subsection{The `QED' symbol}
218 % \DescribeMacro\qedrule
219 % For use in proofs of theorems, we provide a `QED' symbol which behaves well
220 % under bizarre line-splitting conditions. To use it, just say |\qed|. The
221 % little `\qedrule' symbol is available on its own, by saying |\qedrule|.
222 % This also sets |\qedsymbol| if it's not set already.
226 % There used to be an eqnarray here, but that's migrated its way into the
227 % \package{mdwtab} package. Maybe the original version, without dependency
228 % on \package{mdwtab} ought to be releasable separately. I'll keep it around
231 % The following is the documentation for the original version. There's an
232 % updated edition in \package{mdwtab}.
235 % \begin{old-eqnarray}
237 % \subsection{A new \env{eqnarray} environment}
239 % \LaTeX's built-in \env{eqnarray} is horrible -- it puts far too much space
240 % between the items in the array. This environment is rather nearer to the
241 % \env{amsmath} \env{align} environments, although rather less capable.
244 % \DescribeEnv{eqnarray}
246 % \setbox0\hbox{"\\begin{eqnarray}["<preamble>"]" \dots "\\end{eqnarray}"}
247 % \leavevmode \hskip-\parindent \fbox{\box0}
251 % The new version of \env{eqnarray} tries to do everything which you really
252 % want it to. The \synt{preamble} string allows you to define the column
253 % types in a vaguely similar way to the wonderful \env{tabular} environment.
254 % The types provided (and it's easy-ish to add more) are:
257 % \begin{description} \def\makelabel{\hskip\labelsep\normalfont\ttfamily}
258 % \item [r] Right aligned equation
259 % \item [c] Centre-aligned equation
260 % \item [l] Left aligned equation
261 % \item [\textrm{\texttt{Tr}, \texttt{Tc} and \texttt{Tl}}] Right, centre and
262 % left aligned text (not maths)
263 % \item [L] Left aligned zero-width equation
264 % \item [x] Centred entire equation
265 % \item [:] Big gap separating sets of equations
266 % \item [q] Quad space
267 % \item [>\ch\{\synt{text}\ch\}] Insert text before column
268 % \item [<\ch\{\synt{text}\ch\}] Insert text after column
271 % Some others are also defined: don't use them because they do complicated
272 % things which are hard to explain and they aren't much use anyway.
274 % The default preamble, if you don't supply one of your own, is \lit{rcl}.
275 % Most of the time, \lit{rl} is sufficient, although compatibility is more
278 % By default, there is no space between columns, which makes formul\ae\ in an
279 % \env{eqnarray} environment look just like formul\ae\ typeset on their own,
280 % except that things get aligned in columns. This is where the default
281 % \env{eqnarray} falls down: it leaves |\arraycolsep| space between each
282 % column making the thing look horrible.
284 % An example would be good here, I think. This one's from exercise 22.9 of
285 % the \textit{\TeX book}.
287 % \begin{demo}[w]{Simultaneous equations}
288 %\begin{eqnarray}[rcrcrcrl]
289 % 10w & + & 3x & + & 3y & + & 18z & = 1 \\
290 % 6w & - & 17x & & & - & 5z & = 2
294 % Choosing a more up-to-date example, here's one demonstrating the \lit{:}
295 % column specifier from the \textit{\LaTeX\ Companion}.
297 % \begin{demo}[w]{Lots of equations}
298 %\begin{eqnarray}[rl:rl:l]
299 % V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, &
300 % U_i = u_i, \qquad \mbox{for $i \ne j$} \label{eq:A} \\
301 % V_j &= v_j, & X_j &= x_j &
302 % U_j u_j + \sum_{i \ne j} q_i u_i.
306 % We can make things more interesting by adding a plain text column. Here we
309 % \begin{demo}[w]{Plain text column}
310 %\begin{eqnarray}[rlqqTl]
311 % x &= y & by (\ref{eq:A}) \\
312 % x' &= y' & by definition \\
313 % x + x' &= y + y' & by Axiom~1
317 % The new features also mean that you don't need to mess about with
318 % |\lefteqn| any more. This is handled by the \lit{L} column type:
320 % \begin{demo}{Splitting example}
321 %\begin{eqnarray*}[Ll]
328 % Finally, just to prove that the spacing's right at last, here's another one
329 % from the \textit{Companion}.
331 % \begin{demo}{Spacing demonstration}
335 %\begin{eqnarray}[rl]
336 % x^2 + y^2 &= z^2 \\
341 % Well, that was easy enough. Now on to numbering. As you've noticed, the
342 % equations above are numbered. You can use the \env{eqnarray$*$}
343 % environment to turn off the numbering in the whole environment, or say
344 % |\nonumber| on a line to suppress numbering of that one in particular.
345 % More excitingly, you can say \syntax{"\\nonumber["<text>"]"} to choose
346 % what text to display.
348 % A note for cheats: you can use the sparkly new \env{eqnarray} for simple
349 % equations simply by specifying \lit{x} as the column description. Who
350 % needs \AmSTeX? |;-)|
356 % \section{Implementation}
358 % This isn't really complicated (honest) although it is a lot hairier than I
359 % think it ought to be.
365 % \subsection{Square roots}
367 % \subsubsection{Where is the square root sign?}
369 % \LaTeX\ hides the square root sign away somewhere without telling anyone
370 % where it is. I extract it forcibly by peeking inside the |\sqrtsign| macro
371 % and scrutinising the contents. Here we go: prepare for yukkiness.
374 \newcount\sq@sqrt \begingroup \catcode`\|0 \catcode`\\12
375 |def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax}
376 |expandafter|sq@readrad|meaning|sqrtsign|relax |endgroup
377 \def\sq@delim{\delimiter\sq@sqrt\relax}
380 % \subsubsection{Drawing fake square root signs}
382 % \TeX\ absolutely insists on drawing square root signs with a vinculum over
383 % the top. In order to get the same effect, we have to attempt to emulate
386 % \begin{macro}{\sqrtdel}
388 % This does the main job of typesetting a vinculum-free radical.\footnote{^^A
389 % Note for chemists: this is nothing to do with short-lived things which
390 % don't have their normal numbers of electrons. And it won't reduce the
391 % appearance of wrinkles either.}
392 % It's more or less a duplicate of what \TeX\ does internally, so it might be
393 % a good plan to have a copy of Appendix~G open while you examine this.
395 % We start off by using |\mathpalette| to help decide how big things should
399 \def\sqrtdel{\mathpalette\sqrtdel@i}
402 % Read the contents of the radical into a box, so we can measure it.
406 \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
409 % Now try and sort out the values needed in this calculation. We'll assume
410 % that $\xi_8$ is 0.6\,pt, the way it usually is. Next try to work out the
411 % value of $\varphi$.
421 % That was easy. Now for $\psi$.
425 \advance\@tempdimb.25\@tempdima%
428 % Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as
429 % requested. Box~2 will do well for this purpose.
433 \advance\dimen@\@tempdimb%
434 \advance\dimen@\ht\z@%
435 \advance\dimen@\dp\z@%
437 $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
441 % Now we need to do some more calculating (don't you hate it?). As far as
442 % Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the
447 \advance\@tempdima\dp\tw@%
448 \advance\@tempdima-\ht\z@%
449 \advance\@tempdima-\dp\z@%
450 \ifdim\@tempdima>\@tempdimb%
451 \advance\@tempdima\@tempdimb%
452 \@tempdimb.5\@tempdima%
456 % Work out how high to raise the radical symbol. Remember that Appendix~G
457 % thinks that the box has a very small height, although this is untrue here.
461 \advance\@tempdima\@tempdimb%
462 \advance\@tempdima-\ht\tw@%
465 % Build the output (finally). The brace group is there to turn the output
466 % into a mathord, one of the few times that this is actually desirable.
469 {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
475 % \subsubsection{The new square root command}
477 % This is where we reimplement all the square root stuff. Most of this stuff
478 % comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\
479 % and \LaTeXe, and some is original. I've tried to make the spacing vaguely
480 % automatic, so although it's not configurable like \AmSTeX's version, the
481 % output should look nice more of the time. Maybe.
483 % \begin{macro}{\sqrt}
485 % \LaTeX\ says this must be robust, so we make it robust. The first thing to
486 % do is to see if there's a star and pass the appropriate squareroot-drawing
487 % command on to the rest of the code.
490 \DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
493 % Now we can sort out an optional argument to be displayed on the root.
496 \def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
499 % Stages~2 and~3 below are essentially equivalents of \PlainTeX's
500 % |\root|\dots|\of| and |\r@@t|. Here we also find the first wrinkle: the
501 % |\rootbox| used to store the number is spaced out on the left if necessary.
502 % There's a backspace after the end so that the root can slip underneath, and
503 % everything works out nicely. Unfortunately size is fixed here, although
504 % doesn't actually seem to matter.
508 \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
509 \ifdim\wd\rootbox<6\p@%
510 \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
512 \mathpalette{\sqrt@iii{#1}}%
516 % Now we can actually build everything. Note that the root is raised by its
517 % depth -- this prevents a common problem with letters with descenders.
520 \def\sqrt@iii#1#2#3{%
521 \setbox\z@\hbox{$\m@th#2#1{#3}$}%
523 \advance\dimen@-\dp\z@%
525 \advance\dimen@\dp\rootbox%
527 \raise\dimen@\copy\rootbox%
533 % Finally handle a non-numbered root. We read the rooted text in as an
534 % argument, to stop problems when people omit the braces. (\AmSTeX\ does
538 \def\sqrt@iv#1#2{#1{#2}}
543 % \begin{macro}{\root}
545 % We also re-implement \PlainTeX's |\root| command, just in case someone uses
546 % it, and supply a star-variant. This is all very trivial.
549 \def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
550 \def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
555 % \subsection{Modular programming}
557 % \begin{macro}{\pmod}
559 % Do some hacking if not |\ifouter|.
563 \ifinner\;\else\allowbreak\mkern18mu\fi%
564 ({\operator@font mod}\,\,#1)%
570 % \subsection{Some magic new maths characters}
572 % \begin{macro}{\bitor}
573 % \begin{macro}{\bitand}
574 % \begin{macro}{\dblor}
575 % \begin{macro}{\dbland}
576 % \begin{macro}{\xor}
577 % \begin{macro}{\lor}
578 % \begin{macro}{\ror}
579 % \begin{macro}{\lsl}
580 % \begin{macro}{\lsr}
582 % The new boolean operators.
585 \DeclareMathSymbol{&}{\mathbin}{operators}{`\&}
586 \DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&}
587 \def\bitor{\mathbin\mid}
588 \def\dblor{\mathbin{\mid\mid}}
589 \def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}}
591 \def\lsl{\mathbin{<\!\!<}}
592 \def\lsr{\mathbin{>\!\!>}}
593 \def\rol{\mathbin{<\!\!<\!\!<}}
594 \def\ror{\mathbin{>\!\!>\!\!>}}
595 \AtBeginDocument{\ifx\lll\@@undefined\else
596 \def\lsl{\mathbin{\ll}}
597 \def\lsr{\mathbin{\gg}}
598 \def\rol{\mathbin{\lll}}
599 \def\ror{\mathbin{\ggg}}
613 % \begin{macro}{\cat}
614 % \begin{macro}{\compose}
615 % \begin{macro}{\implies}
616 % \begin{macro}{\vect}
618 % \begin{macro}{\jacobi}
620 % A mixed bag of stuff.
623 \def\cat{\mathbin{\|}}
625 \def\implies{\Rightarrow}
626 \def\vect#1{\mathord{\mathbf{#1}}}
627 \def\d{\mathord{\operator@font d}}
628 \def\jacobi#1#2{{{#1}\overwithdelims()#2}}
638 % \begin{macro}{\statclose}
639 % \begin{macro}{\compind}
641 % Fancy new relations for probability distributions.
644 \def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
645 \def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
651 % \begin{macro}{\keys}
652 % \begin{macro}{\dom}
653 % \begin{macro}{\ran}
654 % \begin{macro}{\supp}
655 % \begin{macro}{\lcm}
657 % And the new operator names.
660 \def\keys{\mathop{\operator@font keys}\nolimits}
661 \def\dom{\mathop{\operator@font dom}\nolimits}
662 \def\ran{\mathop{\operator@font ran}\nolimits}
663 \def\supp{\mathop{\operator@font supp}\nolimits}
664 \def\lcm{\mathop{\operator@font lcm}\nolimits}
673 % \subsection{Blackboard bold stuff}
681 % \begin{macro}{\powerset}
683 % First of all, the signs.
692 \def\powerset{\mathbb{P}}
703 % And now, define |\mathbb| if it's not there already.
706 \AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
709 % \subsection{Biggles}
711 % Now for some user-controlled delimiter sizing. The standard bigness of
712 % plain \TeX's delimiters are all right, but it's a little limiting.
714 % The biggness of delimiters is based on the size of the current |\strut|,
715 % which \LaTeX\ keeps up to date all the time. This will make the various
716 % delimiters grow in proportion when the text gets bigger. Actually, I'm
717 % not sure that this is exactly right -- maybe it should be nonlinear,
719 % \begin{macro}{\bbigg}
720 % \begin{macro}{\bbiggl}
721 % \begin{macro}{\bbiggr}
722 % \begin{macro}{\bbiggm}
724 % This is where the bigness is done. This is more similar to the plain \TeX\
725 % big delimiter stuff than to the \package{amsmath} stuff, although there's
726 % not really a lot of difference.
728 % The two arguments are a multiplier for the delimiter size, and a small
729 % increment applied \emph{before} the multiplication (which is optional).
731 % This is actually a front for a low-level interface which can be called
732 % directly for efficiency.
735 \def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
736 \def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
744 % \begin{macro}{\@bbigg}
746 % This is an optional argument parser providing a front end for the main
750 \def\@bbigg#1{\@ifnextchar[{\@bigg@i{#1}}{\@bigg@i{#1}[\z@]}}
751 \def\@bigg@i#1[#2]#3#4{#1{\bbigg@{#2}{#3}{#4}}}
756 % \begin{macro}{\bbigg@}
758 % This is it, at last. The arguments are as described above: an addition
759 % to be made to the strut height, and a multiplier. Oh, and the delimiter,
762 % This is a bit messy. The smallest `big' delimiter, |\big|, is the same
763 % height as the current strut box. Other delimiters are~$1\frac12$, $2$
764 % and~$2\frac12$ times this height. I'll set the height of the delimiter by
765 % putting in a |\vcenter| of the appropriate size.
767 % Given an extra height~$x$, a multiplication factor~$f$ and a strut
768 % height~$h$ and depth~$d$, I'll create a vcenter with total height
769 % $f(h+d+x)$. Easy, isn't it?
774 \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
777 \left#3\vcenter to\dimen@{}\right.\n@space%
784 % \begin{macro}{\big}
785 % \begin{macro}{\Big}
786 % \begin{macro}{\bigg}
787 % \begin{macro}{\Bigg}
789 % Now for the easy macros.
792 \def\big{\bbigg@\z@\@ne}
793 \def\Big{\bbigg@\z@{1.5}}
794 \def\bigg{\bbigg@\z@\tw@}
795 \def\Bigg{\bbigg@\z@{2.5}}
803 % \subsection{The `QED' symbol}
805 % \begin{macro}{\qed}
806 % \begin{macro}{\qedrule}
807 % \begin{macro}{\qedsymbol}
809 % This is fairly simple. Just be careful will the glue and penalties. The
810 % size of the little box is based on the current font size.
812 % The horizontal list constructed by the macro is like this:
815 % \item A |\quad| of space. This might get eaten if there's a break here or
816 % before. That's OK, though.
817 % \item An empty box, to break a run of discardable items.
818 % \item A |\penalty 10000| to ensure that the spacing glue isn't discarded.
819 % \item |\hfill| glue to push the little rule to the end of the line.
820 % \item A little square rule `\qedrule', with some small kerns around it.
821 % \item A glue item to counter the effect of glue added at the paragraph
825 % A |\qed| commend ends the paragraph.
828 \providecommand\qed{%
832 \hbox{}\penalty\z@\quad%
833 \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
837 \advance\dimen@\dp\strutbox
839 \advance\dimen@-\dimen@ii%
841 \advance\dimen@-\dp\strutbox%
842 \advance\dimen@\dimen@ii%
843 \advance\dimen@ii-\dimen@%
845 \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
848 \providecommand\qedsymbol{\qedrule}
856 % The following is the original definition of the enhanced eqnarray
857 % environment. It's not supported, although if you can figure out how to
858 % extract it, it's all yours.
861 % \begin{old-eqnarray}
863 % \subsection{The sparkly new \env{eqnarray}}
865 % Start off by writing a different package.
872 % \subsubsection{Options handling}
874 % We need to be able to cope with \textsf{fleqn} and \textsf{leqno} options.
875 % This will adjust our magic modified \env{eqnarray} environment
881 \DeclareOption{fleqn}{\@fleqntrue}
882 \DeclareOption{leqno}{\@leqnotrue}
886 % This is all really different to the \LaTeX\ version. I've looked at the
887 % various \env{tabular} implementations, the original \env{eqnarray} and the
888 % \textit{\TeX book} to see how best to do this, and then went my own way.
889 % If it doesn't work it's all my fault.
891 % \subsubsection{Some useful registers}
893 % The old \LaTeX\ version puts the equation numbers in by keeping a count of
894 % where it is in the alignment. Since I don't know how may columns there are
895 % going to be, I'll just use a switch in the preamble to tell me to stop
902 % Now define some useful length parameters. First allocate them:
906 \newskip\eqacloseskip
911 % Now assign some default values. Users can play with these if they really
912 % want although I can't see the point myself.
916 \AtBeginDocument{\eqaopenskip\leftmargini}
918 \eqaopenskip\@centering
920 \eqacloseskip\@centering
921 \eqacolskip\@centering
925 % We allow the user to play with the style if this is really wanted. I dunno
926 % why, really. Maybe someone wants very small alignments.
929 \let\eqa@style\displaystyle
932 % \subsubsection{The main environments}
934 % We define the toplevel commands here. They just add in default arguments
935 % and then call |\@eqnarray| with a preamble string. The only difference is
936 % the last column they add in -- \env{eqnarray$*$} throws away the last
937 % column by sticking it in box~0. (I used to |\@gobble| it but that caused
938 % the |\cr| to be lost.)
941 \def\eqnarray{\@ifnextchar[\eqnarray@i{\eqnarray@i[rcl]}}
942 \def\eqnarray@i[#1]{%
943 \@eqnarray{#1!{\hb@xt@\z@{\hss##}\tabskip\z@}}
945 \@namedef{eqnarray*}{\@ifnextchar[\eqnarray@s@i{\eqnarray@s@i[rcl]}}
946 \def\eqnarray@s@i[#1]{%
947 \@eqnarray{#1!{\nonumber\setbox\z@\hbox{##}\tabskip\z@}}%
951 % \subsubsection{Set up the initial display}
953 % \begin{macro}{\@eqnarray}
955 % The |\@eqnarray| command does most of the initial work. It sets up some
956 % flags and things, builds the |\halign| preamble, and returns.
962 % Start playing with the counter here. The original does some icky internal
963 % playing, which isn't necessary. The |\if@eqnsw| switch is |true| if the
964 % user hasn't supplied an equation number. The |\if@eqalast| switch is
965 % |true| in the final equation-number column.
968 \refstepcounter{equation}%
974 % Set things up for the |\halign| which is coming up.
978 \tabskip\eqaopenskip%
984 % We'll build the real |\halign| and preamble in a token register. All we
985 % need to do is stuff the header in the token register, clear a switch
986 % (that'll be explained later), parse the preamble and then expand the
987 % tokens we collected. Easy, no?
990 \toks@{\halign to\displaywidth\bgroup}%
999 % \subsubsection{Parsing the preamble}
1001 % All this actually involves is reading the next character and building a
1002 % command from it. That can pull off an argument if it needs it. Just make
1003 % sure we don't fall off the end and we'll be OK.
1006 \def\eqa@preamble#1{%
1007 \ifx\end#1\else\csname eqa@char@#1\expandafter\endcsname\fi%
1011 % Adding stuff to the preamble tokens is a simple matter of using
1012 % |\expandafter| in the correct way.\footnote{^^A
1013 % I have no idea why \LaTeX\ uses \cmd\edef\ for building its preamble. It
1014 % seems utterly insane to me -- the amount of bodgery that \env{tabular}
1015 % has to go through to make everything expand at the appropriate times is
1016 % scary. Maybe Messrs~Lamport and Mittelbach just forgot about token
1017 % registers when they were writing the code. Maybe I ought to rewrite the
1018 % thing properly some time. Sigh.
1020 % As a sort of postscript to the above, I \emph{have} rewritten the
1021 % \env{tabular} environment, and made a damned fine job of it, in my
1022 % oh-so-humble opinion. All this \env{eqnarray} stuff has been remoulded
1023 % in terms of the generic column-defining things in \package{mdwtab}.
1024 % You're reading the documentation of the old version, which isn't
1025 % supported any more, so any bugs here are your own problem.}
1028 \def\eqa@addraw#1{\expandafter\toks@\expandafter{\the\toks@#1}}
1031 % Now for some cleverness again. In order to put all the right bits of
1032 % |\tabskip| glue in the right places we must \emph{not} terminate each
1033 % column until we know what the next one is. We set |\if@tempswa| to be
1034 % |true| if there's a column waiting to be closed (so it's initially
1035 % |false|). The following macro adds a column correctly, assuming we're in
1036 % a formula. Other column types make their own arrangements.
1041 \eqa@addraw{\tabskip\eqainskip}%
1049 % Now to defining column types. Let's define a macro which allows us to
1050 % define column types:
1053 \def\eqa@def#1{\expandafter\def\csname eqa@char@#1\endcsname}
1056 % Now we can define the column types. Each column type must loop back to
1057 % |\eqa@preamble| once it's finished, to read the rest of the preamble
1058 % string. Note the positioning of ord atoms in the stuff below. This will
1059 % space out relations and binops correctly when they occur at the edges of
1060 % columns, and won't affect ord atoms at the edges, because ords pack
1063 % First the easy onces. Just stick |\hfil| in the right places and
1064 % everything will be all right.
1067 \eqa@def r{\eqa@add{\hfil$\eqa@style##{}$}\eqa@preamble}
1068 \eqa@def c{\eqa@add{\hfil$\eqa@style{}##{}$\hfil}\eqa@preamble}
1069 \eqa@def l{\eqa@add{$\eqa@style{}##$\hfil}\eqa@preamble}
1070 \eqa@def x{\eqa@add{\hfil$\eqa@style##$\hfil}\eqa@preamble}
1073 % Now for the textual ones. This is also fairly easy.
1078 \if#1l\else\eqa@addraw{\hfil}\fi%
1080 \if#1r\else\eqa@addraw{\hfil}\fi%
1085 % Sort of split types of equations. I mustn't use |\rlap| here, or
1086 % everything goes wrong -- |\\| doesn't get noticed by \TeX\ in the same way
1090 \eqa@def L{\eqa@add{\hb@xt@\z@{$\eqa@style##$\hss}\qquad}\eqa@preamble}
1093 % The \lit{:} column type is fairly simple. We set |\tabskip| up to make
1094 % lots of space and close the current column, because there must be one.^^A
1095 % \footnote{This is an assumption.}
1099 \eqa@addraw{\tabskip\eqacolskip&}\@tempswafalse\eqa@preamble%
1101 \eqa@def q{\eqa@add{\quad}\@tempswafalse\eqa@preamble}
1104 % The other column types just insert given text in an appropriate way.
1107 \eqa@def >#1{\eqa@add{#1}\@tempswafalse\eqa@preamble}
1108 \eqa@def <#1{\eqa@addraw{#1}\eqa@preamble}
1111 % Finally, the magical \lit{!} column type, which sets the equation number.
1112 % We set up the |\tabskip| glue properly, tab on, and set the flag which
1113 % marks the final column.
1117 \eqa@addraw{\tabskip\eqacloseskip&\@eqalasttrue#1}\eqa@preamble%
1121 % \subsubsection{Newline codes}
1123 % Newline sequences (|\\|) get turned into calls of |\@eqncr|. The job is
1124 % fairly simple, really. However, to avoid reading `|&|' characters
1125 % prematurely, we set up a magic brace (from the \package{array} package --
1126 % this avoids creating ord atoms and other nastyness).
1130 \iffalse{\fi\ifnum0=`}\fi%
1131 \@ifstar{\eqacr@i{\@M}}{\eqacr@i{\interdisplaylinepenalty}}%
1133 \def\eqacr@i#1{\@ifnextchar[{\eqacr@ii{#1}}{\eqacr@ii{#1}[\z@]}}
1134 \def\eqacr@ii#1[#2]{%
1137 \noalign{\penalty#1\vskip#2\relax}%
1141 % \subsubsection{Setting equation numbers}
1143 % Before we start, we need to generalise the flush-left number handling bits.
1144 % The macro |\eqa@eqpos| will put its argument in the right place.
1149 \hb@xt@.01\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}%
1152 \def\eqa@eqpos#1{\normalfont\normalcolor#1}
1156 % First we need to move into the right column. Then we just set the equation
1157 % number appropriately. There is some subtlety here, ish. The |\relax| is
1158 % important, to delay expansion of the |\if|\dots\ until the new column has
1159 % been started. The two helper macros are important too, to hide `|&|'s and
1160 % `|\cr|'s from \TeX's scanner until the right time.
1165 \if@eqalast\expandafter\eqa@eqnum@i\else\expandafter\eqa@eqnum@ii\fi%
1169 \eqa@eqpos{(\theequation)}\stepcounter{equation}%
1171 \eqa@eqpos\eqa@number%
1176 \def\eqa@eqnum@ii{&\eqa@eqnum}
1179 % \subsubsection{Numbering control}
1181 % This is trivial. We set the |\if@eqnsw| flag to be |false| and store the
1186 \newcommand\nonumber[1][]{\global\@eqnswfalse\global\def\eqa@number{#1}}
1189 % \subsubsection{Closing the environments off}
1191 % This is really easy. Set the final equation number, close the |\halign|,
1192 % tidy up the equation counter (it's been stepped once too many times) and
1193 % close the display.
1199 \global\advance\c@equation\m@ne%
1201 \global\@ignoretrue%
1203 \expandafter\let\csname endeqnarray*\endcsname\endeqnarray
1206 % Now start up the other package again.
1213 % \end{old-eqnarray}
1215 % That's all there is. Byebye.
1221 % \hfill Mark Wooding, \today