Insert correct checksums.
[mdwtools] / mdwmath.dtx
CommitLineData
86f6a31e 1% \begin{meta-comment}
2%
3% $Id: mdwmath.dtx,v 1.1 2002/02/03 20:49:03 mdw Exp $
4%
5% Various nicer mathematical things
6%
7% (c) 1996 Mark Wooding
8%
9%----- Revision history -----------------------------------------------------
10%
11% $Log: mdwmath.dtx,v $
12% Revision 1.1 2002/02/03 20:49:03 mdw
13% Checkin for new build system.
14%
15% Revision 1.1 1996/11/19 20:53:21 mdw
16% Initial revision
17%
18%
19% \end{meta-comment}
20%
21% \begin{meta-comment} <general public licence>
22%%
23%% mdwmath package -- various nicer mathematical things
24%% Copyright (c) 1996 Mark Wooding
25%%
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.
30%%
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.
35%%
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.
39%%
40% \end{meta-comment}
41%
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]
49% \end{meta-comment}
50%
51% \CheckSum{465}
52%% \CharacterTable
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 \~}
67%%
68%
69% \begin{meta-comment}
70%
71%<*driver>
72\input{mdwtools}
73\let\opmod\pmod
74\usepackage{amssymb}
75\describespackage{mdwmath}
76% \describespackage{eqnarray}
77\ignoreenv{old-eqnarray}
78% \unignoreenv{old-eqnarray}
79\mdwdoc
80%</driver>
81%
82% \end{meta-comment}
83%
84% \section{User guide}
85%
86% \subsection{Square root typesetting}
87%
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.
94%
95% \begin{figure}
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} \]
102% \end{demo}
103% \end{figure}
104%
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.]
110%
111% \subsection{Modular arithmetic}
112%
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.
116%
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
121% fine.
122%
123% \subsection{Some maths symbols you already have}
124%
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}
135%
136% \DescribeMacro\xor
137% \DescribeMacro\cat
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.
142%
143% \DescribeMacro\lsl
144% \DescribeMacro\lsr
145% \DescribeMacro\rol
146% \DescribeMacro\ror
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.
150%
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}$'.
157%
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.
163%
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.
167%
168% \subsection{Rant about derivatives}
169%
170% \DescribeMacro\d
171% There is a difference between UK and US typesetting of derivatives.
172% Americans typeset
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}'.
178%
179% \subsection{New operator names}
180%
181% \DescribeMacro\keys
182% \DescribeMacro\dom
183% \DescribeMacro\ran
184% \DescribeMacro\supp
185% \DescribeMacro\lcm
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 \,\}$.
197%
198% \subsection{Standard set names}
199%
200% \DescribeMacro\Z
201% \DescribeMacro\Q
202% \DescribeMacro\R
203% \DescribeMacro\C
204% \DescribeMacro\N
205% \DescribeMacro\F
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$'.
214%
215% \subsection{The `QED' symbol}
216%
217% \DescribeMacro\qed
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.
223% \qed
224%
225% \begin{ignore}
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
229% just in case.
230%
231% The following is the documentation for the original version. There's an
232% updated edition in \package{mdwtab}.
233% \end{ignore}
234%
235% \begin{old-eqnarray}
236%
237% \subsection{A new \env{eqnarray} environment}
238%
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.
242%
243% \bigskip
244% \DescribeEnv{eqnarray}
245% {\synshorts
246% \setbox0\hbox{"\\begin{eqnarray}["<preamble>"]" \dots "\\end{eqnarray}"}
247% \leavevmode \hskip-\parindent \fbox{\box0}
248% }
249% \smallskip
250%
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:
255%
256% \def\ch{\char`}
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
269% \end{description}
270%
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.
273%
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
276% important to me.
277%
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.
283%
284% An example would be good here, I think. This one's from exercise 22.9 of
285% the \textit{\TeX book}.
286%
287% \begin{demo}[w]{Simultaneous equations}
288%\begin{eqnarray}[rcrcrcrl]
289% 10w & + & 3x & + & 3y & + & 18z & = 1 \\
290% 6w & - & 17x & & & - & 5z & = 2
291%\end{eqnarray}
292% \end{demo}
293%
294% Choosing a more up-to-date example, here's one demonstrating the \lit{:}
295% column specifier from the \textit{\LaTeX\ Companion}.
296%
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.
303%\end{eqnarray}
304% \end{demo}
305%
306% We can make things more interesting by adding a plain text column. Here we
307% go:
308%
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
314%\end{eqnarray}
315% \end{demo}
316%
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:
319%
320% \begin{demo}{Splitting example}
321%\begin{eqnarray*}[Ll]
322% w+x+y+z = \\
323% & a+b+c+d+e+ \\
324% & f+g+h+i+j
325%\end{eqnarray*}
326% \end{demo}
327%
328% Finally, just to prove that the spacing's right at last, here's another one
329% from the \textit{Companion}.
330%
331% \begin{demo}{Spacing demonstration}
332%\begin{equation}
333% x^2 + y^2 = z^2
334%\end{equation}
335%\begin{eqnarray}[rl]
336% x^2 + y^2 &= z^2 \\
337% y^2 &< z^2
338%\end{eqnarray}
339% \end{demo}
340%
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.
347%
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? |;-)|
351%
352% \end{old-eqnarray}
353%
354% \implementation
355%
356% \section{Implementation}
357%
358% This isn't really complicated (honest) although it is a lot hairier than I
359% think it ought to be.
360%
361% \begin{macrocode}
362%<*package>
363% \end{macrocode}
364%
365% \subsection{Square roots}
366%
367% \subsubsection{Where is the square root sign?}
368%
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.
372%
373% \begin{macrocode}
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}
378% \end{macrocode}
379%
380% \subsubsection{Drawing fake square root signs}
381%
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
384% \TeX's behaviour.
385%
386% \begin{macro}{\sqrtdel}
387%
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.
394%
395% We start off by using |\mathpalette| to help decide how big things should
396% be.
397%
398% \begin{macrocode}
399\def\sqrtdel{\mathpalette\sqrtdel@i}
400% \end{macrocode}
401%
402% Read the contents of the radical into a box, so we can measure it.
403%
404% \begin{macrocode}
405\def\sqrtdel@i#1#2{%
406 \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
407% \end{macrocode}
408%
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$.
412%
413% \begin{macrocode}
414 \ifx#1\displaystyle%
415 \@tempdima1ex%
416 \else%
417 \@tempdima.6\p@%
418 \fi%
419% \end{macrocode}
420%
421% That was easy. Now for $\psi$.
422%
423% \begin{macrocode}
424 \@tempdimb.6\p@%
425 \advance\@tempdimb.25\@tempdima%
426% \end{macrocode}
427%
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.
430%
431% \begin{macrocode}
432 \dimen@.6\p@%
433 \advance\dimen@\@tempdimb%
434 \advance\dimen@\ht\z@%
435 \advance\dimen@\dp\z@%
436 \setbox\tw@\hbox{%
437 $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
438 }%
439% \end{macrocode}
440%
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
443% top.
444%
445% \begin{macrocode}
446 \@tempdima\ht\tw@%
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%
453 \fi%
454% \end{macrocode}
455%
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.
458%
459% \begin{macrocode}
460 \@tempdima\ht\z@%
461 \advance\@tempdima\@tempdimb%
462 \advance\@tempdima-\ht\tw@%
463% \end{macrocode}
464%
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.
467%
468% \begin{macrocode}
469 {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
470}
471% \end{macrocode}
472%
473% \end{macro}
474%
475% \subsubsection{The new square root command}
476%
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.
482%
483% \begin{macro}{\sqrt}
484%
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.
488%
489% \begin{macrocode}
490\DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
491% \end{macrocode}
492%
493% Now we can sort out an optional argument to be displayed on the root.
494%
495% \begin{macrocode}
496\def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
497% \end{macrocode}
498%
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.
505%
506% \begin{macrocode}
507\def\sqrt@ii#1[#2]{%
508 \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
509 \ifdim\wd\rootbox<6\p@%
510 \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
511 \fi%
512 \mathpalette{\sqrt@iii{#1}}%
513}
514% \end{macrocode}
515%
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.
518%
519% \begin{macrocode}
520\def\sqrt@iii#1#2#3{%
521 \setbox\z@\hbox{$\m@th#2#1{#3}$}%
522 \dimen@\ht\z@%
523 \advance\dimen@-\dp\z@%
524 \dimen@.6\dimen@%
525 \advance\dimen@\dp\rootbox%
526 \mkern-3mu%
527 \raise\dimen@\copy\rootbox%
528 \mkern-10mu%
529 \box\z@%
530}
531% \end{macrocode}
532%
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
535% this too.)
536%
537% \begin{macrocode}
538\def\sqrt@iv#1#2{#1{#2}}
539% \end{macrocode}
540%
541% \end{macro}
542%
543% \begin{macro}{\root}
544%
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.
547%
548% \begin{macrocode}
549\def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
550\def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
551% \end{macrocode}
552%
553% \end{macro}
554%
555% \subsection{Modular programming}
556%
557% \begin{macro}{\pmod}
558%
559% Do some hacking if not |\ifouter|.
560%
561% \begin{macrocode}
562\def\pmod#1{%
563 \ifinner\;\else\allowbreak\mkern18mu\fi%
564 ({\operator@font mod}\,\,#1)%
565}
566% \end{macrocode}
567%
568% \end{macro}
569%
570% \subsection{Some magic new maths characters}
571%
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}
581%
582% The new boolean operators.
583%
584% \begin{macrocode}
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}}
590\let\xor\oplus
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}}
600\fi}
601% \end{macrocode}
602%
603% \end{macro}
604% \end{macro}
605% \end{macro}
606% \end{macro}
607% \end{macro}
608% \end{macro}
609% \end{macro}
610% \end{macro}
611% \end{macro}
612%
613% \begin{macro}{\cat}
614% \begin{macro}{\compose}
615% \begin{macro}{\implies}
616% \begin{macro}{\vect}
617% \begin{macro}{\d}
618% \begin{macro}{\jacobi}
619%
620% A mixed bag of stuff.
621%
622% \begin{macrocode}
623\def\cat{\mathbin{\|}}
624\let\compose\circ
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}}
629% \end{macrocode}
630%
631% \end{macro}
632% \end{macro}
633% \end{macro}
634% \end{macro}
635% \end{macro}
636% \end{macro}
637%
638% \begin{macro}{\statclose}
639% \begin{macro}{\compind}
640%
641% Fancy new relations for probability distributions.
642%
643% \begin{macrocode}
644\def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
645\def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
646% \end{macrocode}
647%
648% \end{macro}
649% \end{macro}
650%
651% \begin{macro}{\keys}
652% \begin{macro}{\dom}
653% \begin{macro}{\ran}
654% \begin{macro}{\supp}
655% \begin{macro}{\lcm}
656%
657% And the new operator names.
658%
659% \begin{macrocode}
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}
665% \end{macrocode}
666%
667% \end{macro}
668% \end{macro}
669% \end{macro}
670% \end{macro}
671% \end{macro}
672%
673% \subsection{Blackboard bold stuff}
674%
675% \begin{macro}{\Z}
676% \begin{macro}{\Q}
677% \begin{macro}{\R}
678% \begin{macro}{\C}
679% \begin{macro}{\N}
680% \begin{macro}{\F}
681% \begin{macro}{\powerset}
682%
683% First of all, the signs.
684%
685% \begin{macrocode}
686\def\Z{\mathbb{Z}}
687\def\Q{\mathbb{Q}}
688\def\R{\mathbb{R}}
689\def\C{\mathbb{C}}
690\def\N{\mathbb{N}}
691\def\F{\mathbb{F}}
692\def\powerset{\mathbb{P}}
693% \end{macrocode}
694%
695% \end{macro}
696% \end{macro}
697% \end{macro}
698% \end{macro}
699% \end{macro}
700% \end{macro}
701% \end{macro}
702%
703% And now, define |\mathbb| if it's not there already.
704%
705% \begin{macrocode}
706\AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
707% \end{macrocode}
708%
709% \subsection{Biggles}
710%
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.
713%
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,
718%
719% \begin{macro}{\bbigg}
720% \begin{macro}{\bbiggl}
721% \begin{macro}{\bbiggr}
722% \begin{macro}{\bbiggm}
723%
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.
727%
728% The two arguments are a multiplier for the delimiter size, and a small
729% increment applied \emph{before} the multiplication (which is optional).
730%
731% This is actually a front for a low-level interface which can be called
732% directly for efficiency.
733%
734% \begin{macrocode}
735\def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
736\def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
737% \end{macrocode}
738%
739% \end{macro}
740% \end{macro}
741% \end{macro}
742% \end{macro}
743%
744% \begin{macro}{\@bbigg}
745%
746% This is an optional argument parser providing a front end for the main
747% macro |\bbigg@|.
748%
749% \begin{macrocode}
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}}}
752% \end{macrocode}
753%
754% \end{macro}
755%
756% \begin{macro}{\bbigg@}
757%
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,
760% of course.
761%
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.
766%
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?
770%
771% \begin{macrocode}
772\def\bbigg@#1#2#3{%
773 {\hbox{$%
774 \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
775 \advance\dimen@#1%
776 \dimen@#2\dimen@%
777 \left#3\vcenter to\dimen@{}\right.\n@space%
778 $}}%
779}
780% \end{macrocode}
781%
782% \end{macro}
783%
784% \begin{macro}{\big}
785% \begin{macro}{\Big}
786% \begin{macro}{\bigg}
787% \begin{macro}{\Bigg}
788%
789% Now for the easy macros.
790%
791% \begin{macrocode}
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}}
796% \end{macrocode}
797%
798% \end{macro}
799% \end{macro}
800% \end{macro}
801% \end{macro}
802%
803% \subsection{The `QED' symbol}
804%
805% \begin{macro}{\qed}
806% \begin{macro}{\qedrule}
807% \begin{macro}{\qedsymbol}
808%
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.
811%
812% The horizontal list constructed by the macro is like this:
813%
814% \begin{itemize}
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
822% boundary.
823% \end{itemize}
824%
825% A |\qed| commend ends the paragraph.
826%
827% \begin{macrocode}
828\providecommand\qed{%
829 \leavevmode%
830 \unskip%
831 \penalty\@M\hfill%
832 \hbox{}\penalty\z@\quad%
833 \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
834}
835\def\qedrule{{%
836 \dimen@\ht\strutbox%
837 \advance\dimen@\dp\strutbox
838 \dimen@ii1ex%
839 \advance\dimen@-\dimen@ii%
840 \divide\dimen@\tw@%
841 \advance\dimen@-\dp\strutbox%
842 \advance\dimen@\dimen@ii%
843 \advance\dimen@ii-\dimen@%
844 \kern\p@%
845 \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
846 \kern\p@%
847}}
848\providecommand\qedsymbol{\qedrule}
849% \end{macrocode}
850%
851% \end{macro}
852% \end{macro}
853% \end{macro}
854%
855% \begin{ignore}
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.
859% \end{ignore}
860%
861% \begin{old-eqnarray}
862%
863% \subsection{The sparkly new \env{eqnarray}}
864%
865% Start off by writing a different package.
866%
867% \begin{macrocode}
868%</package>
869%<*oldeqnarray>
870% \end{macrocode}
871%
872% \subsubsection{Options handling}
873%
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
876% appropriately.
877%
878% \begin{macrocode}
879\newif\if@fleqn
880\newif\if@leqno
881\DeclareOption{fleqn}{\@fleqntrue}
882\DeclareOption{leqno}{\@leqnotrue}
883\ProcessOptions
884% \end{macrocode}
885%
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.
890%
891% \subsubsection{Some useful registers}
892%
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
896% tabbing.
897%
898% \begin{macrocode}
899\newif\if@eqalast
900% \end{macrocode}
901%
902% Now define some useful length parameters. First allocate them:
903%
904% \begin{macrocode}
905\newskip\eqaopenskip
906\newskip\eqacloseskip
907\newskip\eqacolskip
908\newskip\eqainskip
909% \end{macrocode}
910%
911% Now assign some default values. Users can play with these if they really
912% want although I can't see the point myself.
913%
914% \begin{macrocode}
915\if@fleqn
916 \AtBeginDocument{\eqaopenskip\leftmargini}
917\else
918 \eqaopenskip\@centering
919\fi
920\eqacloseskip\@centering
921\eqacolskip\@centering
922\eqainskip\z@
923% \end{macrocode}
924%
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.
927%
928% \begin{macrocode}
929\let\eqa@style\displaystyle
930% \end{macrocode}
931%
932% \subsubsection{The main environments}
933%
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.)
939%
940% \begin{macrocode}
941\def\eqnarray{\@ifnextchar[\eqnarray@i{\eqnarray@i[rcl]}}
942\def\eqnarray@i[#1]{%
943 \@eqnarray{#1!{\hb@xt@\z@{\hss##}\tabskip\z@}}
944}
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@}}%
948}
949% \end{macrocode}
950%
951% \subsubsection{Set up the initial display}
952%
953% \begin{macro}{\@eqnarray}
954%
955% The |\@eqnarray| command does most of the initial work. It sets up some
956% flags and things, builds the |\halign| preamble, and returns.
957%
958% \begin{macrocode}
959\def\@eqnarray#1{%
960% \end{macrocode}
961%
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.
966%
967% \begin{macrocode}
968 \refstepcounter{equation}%
969 \@eqalastfalse%
970 \global\@eqnswtrue%
971 \m@th%
972% \end{macrocode}
973%
974% Set things up for the |\halign| which is coming up.
975%
976% \begin{macrocode}
977 \openup\jot%
978 \tabskip\eqaopenskip%
979 \let\\\@eqncr%
980 \everycr{}%
981 $$%
982% \end{macrocode}
983%
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?
988%
989% \begin{macrocode}
990 \toks@{\halign to\displaywidth\bgroup}%
991 \@tempswafalse%
992 \eqa@preamble#1\end%
993 \the\toks@\cr%
994}
995% \end{macrocode}
996%
997% \end{macro}
998%
999% \subsubsection{Parsing the preamble}
1000%
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.
1004%
1005% \begin{macrocode}
1006\def\eqa@preamble#1{%
1007 \ifx\end#1\else\csname eqa@char@#1\expandafter\endcsname\fi%
1008}
1009% \end{macrocode}
1010%
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.
1019%
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.}
1026%
1027% \begin{macrocode}
1028\def\eqa@addraw#1{\expandafter\toks@\expandafter{\the\toks@#1}}
1029% \end{macrocode}
1030%
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.
1037%
1038% \begin{macrocode}
1039\def\eqa@add#1{%
1040 \if@tempswa%
1041 \eqa@addraw{\tabskip\eqainskip&#1}%
1042 \else%
1043 \eqa@addraw{#1}%
1044 \fi%
1045 \@tempswatrue%
1046}
1047% \end{macrocode}
1048%
1049% Now to defining column types. Let's define a macro which allows us to
1050% define column types:
1051%
1052% \begin{macrocode}
1053\def\eqa@def#1{\expandafter\def\csname eqa@char@#1\endcsname}
1054% \end{macrocode}
1055%
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
1061% closely.
1062%
1063% First the easy onces. Just stick |\hfil| in the right places and
1064% everything will be all right.
1065%
1066% \begin{macrocode}
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}
1071% \end{macrocode}
1072%
1073% Now for the textual ones. This is also fairly easy.
1074%
1075% \begin{macrocode}
1076\eqa@def T#1{%
1077 \eqa@add{}%
1078 \if#1l\else\eqa@addraw{\hfil}\fi%
1079 \eqa@addraw{##}%
1080 \if#1r\else\eqa@addraw{\hfil}\fi%
1081 \eqa@preamble%
1082}
1083% \end{macrocode}
1084%
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
1087% as |\cr| does.
1088%
1089% \begin{macrocode}
1090\eqa@def L{\eqa@add{\hb@xt@\z@{$\eqa@style##$\hss}\qquad}\eqa@preamble}
1091% \end{macrocode}
1092%
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.}
1096%
1097% \begin{macrocode}
1098\eqa@def :{%
1099 \eqa@addraw{\tabskip\eqacolskip&}\@tempswafalse\eqa@preamble%
1100}
1101\eqa@def q{\eqa@add{\quad}\@tempswafalse\eqa@preamble}
1102% \end{macrocode}
1103%
1104% The other column types just insert given text in an appropriate way.
1105%
1106% \begin{macrocode}
1107\eqa@def >#1{\eqa@add{#1}\@tempswafalse\eqa@preamble}
1108\eqa@def <#1{\eqa@addraw{#1}\eqa@preamble}
1109% \end{macrocode}
1110%
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.
1114%
1115% \begin{macrocode}
1116\eqa@def !#1{%
1117 \eqa@addraw{\tabskip\eqacloseskip&\@eqalasttrue#1}\eqa@preamble%
1118}
1119% \end{macrocode}
1120%
1121% \subsubsection{Newline codes}
1122%
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).
1127%
1128% \begin{macrocode}
1129\def\@eqncr{%
1130 \iffalse{\fi\ifnum0=`}\fi%
1131 \@ifstar{\eqacr@i{\@M}}{\eqacr@i{\interdisplaylinepenalty}}%
1132}
1133\def\eqacr@i#1{\@ifnextchar[{\eqacr@ii{#1}}{\eqacr@ii{#1}[\z@]}}
1134\def\eqacr@ii#1[#2]{%
1135 \ifnum0=`{}\fi%
1136 \eqa@eqnum%
1137 \noalign{\penalty#1\vskip#2\relax}%
1138}
1139% \end{macrocode}
1140%
1141% \subsubsection{Setting equation numbers}
1142%
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.
1145%
1146% \begin{macrocode}
1147\if@leqno
1148 \def\eqa@eqpos#1{%
1149 \hb@xt@.01\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}%
1150 }
1151\else
1152 \def\eqa@eqpos#1{\normalfont\normalcolor#1}
1153\fi
1154% \end{macrocode}
1155%
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.
1161%
1162% \begin{macrocode}
1163\def\eqa@eqnum{%
1164 \relax%
1165 \if@eqalast\expandafter\eqa@eqnum@i\else\expandafter\eqa@eqnum@ii\fi%
1166}
1167\def\eqa@eqnum@i{%
1168 \if@eqnsw%
1169 \eqa@eqpos{(\theequation)}\stepcounter{equation}%
1170 \else%
1171 \eqa@eqpos\eqa@number%
1172 \fi%
1173 \global\@eqnswtrue%
1174 \cr%
1175}
1176\def\eqa@eqnum@ii{&\eqa@eqnum}
1177% \end{macrocode}
1178%
1179% \subsubsection{Numbering control}
1180%
1181% This is trivial. We set the |\if@eqnsw| flag to be |false| and store the
1182% text in a macro.
1183%
1184% \begin{macrocode}
1185\let\nonumber\relax
1186\newcommand\nonumber[1][]{\global\@eqnswfalse\global\def\eqa@number{#1}}
1187% \end{macrocode}
1188%
1189% \subsubsection{Closing the environments off}
1190%
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.
1194%
1195% \begin{macrocode}
1196\def\endeqnarray{%
1197 \eqa@eqnum%
1198 \egroup%
1199 \global\advance\c@equation\m@ne%
1200 $$%
1201 \global\@ignoretrue%
1202}
1203\expandafter\let\csname endeqnarray*\endcsname\endeqnarray
1204% \end{macrocode}
1205%
1206% Now start up the other package again.
1207%
1208% \begin{macrocode}
1209%</oldeqnarray>
1210%<*package>
1211% \end{macrocode}
1212%
1213% \end{old-eqnarray}
1214%
1215% That's all there is. Byebye.
1216%
1217% \begin{macrocode}
1218%</package>
1219% \end{macrocode}
1220%
1221% \hfill Mark Wooding, \today
1222%
1223% \Finale
1224\endinput