Makefile: Include some custom LaTeX setup.
[mdwtools] / mdwmath.dtx
CommitLineData
86f6a31e 1% \begin{meta-comment} <general public licence>
2%%
3%% mdwmath package -- various nicer mathematical things
8bc5bdd2 4%% Copyright (c) 2003, 2020 Mark Wooding
86f6a31e 5%%
3d509049 6%% This file is part of the `mdwtools' LaTeX package collection.
86f6a31e 7%%
3d509049
MW
8%% `mdwtools' is free software: you can redistribute it and/or modify it
9%% under the terms of the GNU General Public License as published by the
10%% Free Software Foundation; either version 2 of the License, or (at your
11%% option) any later version.
12%%
13%% `mdwtools' is distributed in the hope that it will be useful, but
14%% WITHOUT ANY WARRANTY; without even the implied warranty of
15%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16%% General Public License for more details.
86f6a31e 17%%
18%% You should have received a copy of the GNU General Public License
3d509049
MW
19%% along with `mdwtools'. If not, write to the Free Software Foundation,
20%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
86f6a31e 21%%
22% \end{meta-comment}
23%
24% \begin{meta-comment} <Package preamble>
25%<+package>\NeedsTeXFormat{LaTeX2e}
26%<+package>\ProvidesPackage{mdwmath}
af8af7eb 27%<+package> [2020/09/06 1.14.0 Nice mathematical things]
86f6a31e 28% \end{meta-comment}
29%
3d974523 30% \CheckSum{980}
86f6a31e 31%% \CharacterTable
32%% {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
33%% 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
34%% Digits \0\1\2\3\4\5\6\7\8\9
35%% Exclamation \! Double quote \" Hash (number) \#
36%% Dollar \$ Percent \% Ampersand \&
37%% Acute accent \' Left paren \( Right paren \)
38%% Asterisk \* Plus \+ Comma \,
39%% Minus \- Point \. Solidus \/
40%% Colon \: Semicolon \; Less than \<
41%% Equals \= Greater than \> Question mark \?
42%% Commercial at \@ Left bracket \[ Backslash \\
43%% Right bracket \] Circumflex \^ Underscore \_
44%% Grave accent \` Left brace \{ Vertical bar \|
45%% Right brace \} Tilde \~}
46%%
47%
48% \begin{meta-comment}
49%
50%<*driver>
51\input{mdwtools}
52\let\opmod\pmod
53\usepackage{amssymb}
54\describespackage{mdwmath}
86f6a31e 55\mdwdoc
56%</driver>
57%
58% \end{meta-comment}
59%
60% \section{User guide}
61%
62% \subsection{Square root typesetting}
63%
64% \DescribeMacro{\sqrt}
65% The package supplies a star variant of the |\sqrt| command which omits the
66% vinculum over the operand (the line over the top). While this is most
67% useful in simple cases like $\sqrt*{2}$ it works for any size of operand.
68% The package also re-implements the standard square root command so that it
69% positions the root number rather better.
70%
71% \begin{figure}
72% \begin{demo}[w]{Examples of the new square root command}
73%\[ \sqrt*{2} \quad \mbox{rather than} \quad \sqrt{2} \]
74%\[ \sqrt*[3]{2} \quad \mbox{ rather than } \quad \sqrt[3]{2} \]
75%\[ \sqrt{x^3 + \sqrt*[y]{\alpha}} - \sqrt*[n+1]{a} \]
76%\[ x = \sqrt*[3]{\frac{3y}{7}} \]
77%\[ q = \frac{2\sqrt*{2}}{5}+\sqrt[\frac{n+1}{2}]{2x^2+3xy-y^2} \]
78% \end{demo}
79% \end{figure}
80%
81% [Note that omission of the vinculum was originally a cost-cutting exercise
82% because the radical symbol can just fit in next to its operand and
83% everything ends up being laid out along a line. However, I find that the
84% square root without vinculum is less cluttered, so I tend to use it when
85% it doesn't cause ambiguity.]
86%
87% \subsection{Modular arithmetic}
88%
89% In standard maths mode, there's too much space before the parentheses in
90% the output of the |\pmod| command. Suppose that $x \equiv y^2 \opmod n$:
91% then the spacing looks awful. Go on, admit it.
92%
93% It looks OK in a display. For example, if
94% \[ c \equiv m^e \opmod n \]
95% then it's fine. The package redefines the |\pmod| command to do something
96% more sensible. So now $c^d \equiv m^{ed} \equiv m \pmod n$ and all looks
97% fine.
98%
99% \subsection{Some maths symbols you already have}
100%
101% \DescribeMacro\bitor
102% \DescribeMacro\bitand
103% \DescribeMacro\dblor
104% \DescribeMacro\dbland
105% Having just tried to do some simple things, I've found that there are maths
106% symbols missing. Here they are, in all their glory:
107% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
eafdddad
MW
108% $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\
109% $\bitand$ & "\bitand" & $\dblor$ & "\dblor" &
86f6a31e 110% \end{tabular} \end{center}
111%
112% \DescribeMacro\xor
113% \DescribeMacro\cat
114% I also set up the |\xor| command to typeset `$\xor$', which is commonly
115% used to represent the bitsize exclusive-or operation among cryptographers.
116% The command |\cat| typesets `$\cat$', which is a common operator indicating
117% concatenation of strings.
118%
119% \DescribeMacro\lsl
120% \DescribeMacro\lsr
121% \DescribeMacro\rol
122% \DescribeMacro\ror
123% The commands |\lsl| and |\lsr| typeset binary operators `$\lsl$' and
124% `$\lsr$' respectively, and |\rol| and |\ror| typeset `$\rol$' and `$\ror$'.
125% Note that these are spaced as binary operators, rather than relations.
126%
127% \DescribeMacro\compose
128% \DescribeMacro\implies
129% \DescribeMacro\vect
130% The |\compose| command typesets `$\compose$', which is usually used to
131% denote function composition. The |\implies| command is made to typeset
132% `$\implies$'. And \syntax{"\\vect{"<x>"}"} typesets `$\vect{x}$'.
133%
134% \DescribeMacro\statclose
135% \DescribeMacro\compind
136% The |\statclose| command typesets `$\statclose$', which indicates
137% `statistical closeness' of probability distributions; |\compind| typesets
138% `$\compind$', which indicates computational indistinguishability.
139%
4a655c6f 140% \subsection{Fractions}
141%
142% \DescribeMacro\fracdef
143% We provide a general fraction system, a little tiny bit like
144% \package{amsmath}'s |\genfrac|. Say
145% \syntax{"\\fracdef{"<name>"}{"<frac-params>"}"} to define a new
146% |\frac|-like operator. The \<frac-params> are a comma-separated list of
147% parameters:
148% \begin{description}
149% \item[\lit*{line}] Include a horizontal line between the top and bottom
150% (like |\frac|).
151% \item[\lit*{line=}\<length>] Include a horizontal line with width
152% \<length>.
153% \item[\lit*{noline}] Don't include a line (like |\binom|).
154% \item[\lit*{leftdelim=}\<delim>] Use \<delim> as the left-hand delimiter.
155% \item[\lit*{rightdelim=}\<delim>] Use \<delim> as the right-hand delimiter.
156% \item[\lit*{nodelims}] Don't include delimiters.
157% \item[\lit*{style=}\<style>] Typeset the fraction in \<style>, which is one
158% of |display|, |text|, |script| or |scriptscript|.
159% \item[\lit*{style}] Use the prevailing style for the fraction.
160% \item[\lit*{innerstyle=}\<style>] Typeset the \emph{components} of the
161% fraction in \<style>.
162% \item[\lit*{innerstyle}] Typeset the fraction components according to the
163% prevailing style.
164% \end{description}
165% The commands created by |\fracdef| have the following syntax:
166% \syntax{<name>"["<frac-params>"]{"<top>"}{"<bottom>"}"}. Thus, you can use
167% the optional argument to `tweak' the fraction if necessary. This isn't
168% such a good idea to do often.
169%
170% \DescribeMacro\frac
171% \DescribeMacro\binom
86f6a31e 172% \DescribeMacro\jacobi
4a655c6f 173% The macros |\frac|, |\binom| and |\jacobi| are defined using |\fracdef|.
174% They typset $\frac{x}{y}$, $\binom{n}{k}$ and $\jacobi{x}{n}$ respectively.
175% (The last may be of use to number theorists talking about Jacobi or
176% Lagrange symbols.)
177%
178% By way of example, these commands were defined using
179%\begin{verbatim}
180%\fracdef\frac{nodelims, line}
181%\fracdef\binom{leftdelim = (, rightdelim = ), noline}
182%\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
183%\end{verbatim}
86f6a31e 184%
185% \subsection{Rant about derivatives}
186%
187% \DescribeMacro\d
188% There is a difference between UK and US typesetting of derivatives.
189% Americans typeset
190% \[ \frac{dy}{dx} \]
191% while the British want
192% \[ \frac{\d y}{\d x}. \]
4a655c6f 193% The command |\d| command is fixed to typeset a `$\d$'. (In text mode,
194% |\d{x}| still typesets `\d{x}'.)
86f6a31e 195%
196% \subsection{New operator names}
197%
198% \DescribeMacro\keys
199% \DescribeMacro\dom
200% \DescribeMacro\ran
201% \DescribeMacro\supp
202% \DescribeMacro\lcm
4a655c6f 203% \DescribeMacro\ord
204% \DescribeMacro\poly
205% \DescribeMacro\negl
86f6a31e 206% A few esoteric new operator names are supplied.
207% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
eafdddad
MW
208% $\keys$ & "\keys" & $\dom$ & "\dom" & $\ran$ & "\ran" \\
209% $\supp$ & "\supp" & $\lcm$ & "\lcm" & $\ord$ & "\ord" \\
210% $\poly$ & "\poly" & $\negl$ & "\negl"
86f6a31e 211% \end{tabular} \end{center}
212% I think |\lcm| ought to be self-explanatory. The |\dom| and |\ran|
213% operators pick out the domain and range of a function, respectively; thus,
214% if $F\colon X \to Y$ is a function, then $\dom F = X$ and $\ran F = Y$.
215% The \emph{support} of a probability distribution $\mathcal{D}$ is the set
216% of objects with nonzero probability; i.e., $\supp{D} = \{\, x \in
4a655c6f 217% \dom\mathcal{D} \mid \mathcal{D}(x) > 0 \,\}$. If $g \in G$ is a group
218% element then $\ord g$ is the \emph{order} of $g$; i.e., the smallest
219% positive integer $i$ where $g^i$ is the identity element, or $0$ if there
220% is no such $i$. $\poly(n)$ is some polynomial function of $n$. A function
221% $\nu(\cdot)$ is \emph{negligible} if, for every polynomial function
222% $p(\cdot)$, there is an integer $N$ such that $\nu(n) < 1/p(n)$ for all $n
223% > N$; $\negl(n)$ is some negligible function of $n$.
86f6a31e 224%
4a576d39
MW
225% \DescribeMacro\defop
226% New operators can be defined using |\defop|:
227% \begin{quote} \syntax{"\\defop"["*"]"{"<command>"}{"<text>"}"} \end{quote}
228% defines \<command> to be an operator which typesets \<text>. By default,
229% limits will be placed above and below the operator in display style; with
230% |*|, limits are always written as super- and subscripts.
231%
86f6a31e 232% \subsection{Standard set names}
233%
234% \DescribeMacro\Z
235% \DescribeMacro\Q
236% \DescribeMacro\R
237% \DescribeMacro\C
238% \DescribeMacro\N
239% \DescribeMacro\F
240% \DescribeMacro\powerset
4a655c6f 241% \DescribeMacro\gf
86f6a31e 242% If you have a |\mathbb| command defined, the following magic is revealed:
243% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
244% $\Z$ & "\Z" & $\Q$ & "\Q" & $\R$ & "\R" \\
245% $\N$ & "\N" & $\F$ & "\F" & $\C$ & "\C"
246% \end{tabular} \end{center}
247% which are handy for various standard sets of things. Also the |\powerset|
4a655c6f 248% command typesets `$\powerset$', and \syntax{"\\gf{"<q>"}"}, which by default
249% typesets $\gf{\syntax{<q>}}$ but you might choose to have it set
250% $\mathrm{GF}(\syntax{<q>})$ intead.
251%
252% \subsection{Biggles}
253%
254% \DescribeMacro\bbigg
255% \DescribeMacro\bbiggl
256% \DescribeMacro\bbiggr
257% \DescribeMacro\bbiggm
258% The |\bbigg| commands generalizes the Plain \TeX\ |\bigg| family of
259% macros. |\bbigg| produces an `ordinary' symbol; |\bbiggl| and |\bbiggr|
260% produce left and right delimiters; and |\bbiggm| produces a relation. They
261% produce symbols whose size is related to the prevailing text size -- so
262% they adjust correctly in chapter headings, for example.
263%
264% The syntax is straightforward:
265% \syntax{"\\"<bigop>"["$a$"]{"$n$"}{"<delim>"}"}. Describing it is a bit
266% trickier. The size is based on the current |\strut| height. If |\strut|
267% has a height of $h$ and a depth of $d$, then the delimiter produced has a
268% height of $n \times (h + d + a)$.
269%
270% The old |\big| commands have been redefined in terms of |\bbigg|.
86f6a31e 271%
3d974523
MW
272% \subsection{Defining bracketty notations}
273%
274% \DescribeMacro\defbrk
275% Many mathematical notations involve wrapping brackets of various kinds
276% around expressions. \LaTeX\ doesn't provide much help in defining commands
277% for these notations, which is a shame because it's a good idea to keep the
278% markup semantic rather than visual. I hereby present the |\defbrk|
279% command:
280% \begin{quote}
281% \syntax{"\\defbrk{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
282% "["<rinner>"]{"<rbrk>"}["<router>"]"}
283% \end{quote}
284% The syntax looks intimidating, but it's quite easy really. The \<command>
285% should be a command name, with a leading |\|. The \<lbrk> and \<rbrk>
286% arguments, which are the only other mandatory arguments, are the brackets;
287% they should be something that can appear after |\left| and |\right|. The
288% optional arguments are just extra stuff, commonly spacing, which can appear
289% around the brackets.
290%
291% The main command |\|\<foo> is invoked as
292% \syntax{"\\"<foo>"["<left>"]["<right>"]{"<filling>"}"}. Slightly
293% unusually, the optional \<left> and \<right> arguments must be either both
294% missing or both provided. They're the sizes to be applied to the brackets,
295% so they can be something like |\biggl| and |\biggr|, or |\left| and
296% |\right|; they default to empty, so you get the ordinary text-sized
297% brackets if you don't do anything special. The \<filling> is just the
298% stuff to go in-between the brackets.
299%
300% You also get a number of extra commands:
301% \begin{itemize}
302% \item |\auto|\<foo> uses automatically-resizing brackets, as if you'd asked
303% for |\left| and |\right|;
304% \item |\big|\<foo>, |\Big|\<foo>, |\bigg|\<foo>, and |\Bigg|\<foo> use the
305% corresponding standard sizes of brackets; and
306% \item \syntax{"\\bbigg"<foo>"["$a$"]{"$n$"}"} uses the `bbigg' machinery
307% described above for custom bracket sizes.
308% \end{itemize}
309%
310% \begin{figure}
311% \begin{demo}{Custom bracket notation}
312%\defbrk\set{\{}{\}}
313%\defbrk\floor{\lfloor}{\rfloor}
314%
315%Let $S = \set{1, 2, 3}$.
316%
317%Let
318%\[ \mu = \biggfloor{\frac{B^{2n}}{m}}
319% \mpunct. \]
320%Show that $\bigfloor{\floor{a/b}/c} =
321%\floor{a/b c}$.
322% \end{demo}
323% \end{figure}
324%
325% But wait! There's more! Some notation comes in two pieces with a
326% separator in the middle. For these, there's an even more complicated |*|
327% version of |\defbrk|:
328% \begin{quote}
329% \syntax{"\\defbrk*{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
330% "["<mbefore>"]{"<mid>"}["<mafter>"]"^^A
331% "["<rinner>"]{"<rbrk>"}["<router>"]"}
332% \end{quote}
333% This defines \<command> as before, but now it takes two arguments, to be
334% surrounded by the \<lbrk> and \<rbrk> brackets and separated by \<mid>.
335%
336% \begin{figure}
337% \begin{demo}{More custom bracket notation}
338%\defbrk*\setcomp{\{}[\,]\vert[][\,]{\}}
339%
340%Consider the coset $x + H =
341%\setcomp{x + h}{h \in H}$.
342% \end{demo}
343% \end{figure}
344%
86f6a31e 345% \subsection{The `QED' symbol}
346%
347% \DescribeMacro\qed
348% \DescribeMacro\qedrule
349% For use in proofs of theorems, we provide a `QED' symbol which behaves well
350% under bizarre line-splitting conditions. To use it, just say |\qed|. The
351% little `\qedrule' symbol is available on its own, by saying |\qedrule|.
352% This also sets |\qedsymbol| if it's not set already.
353% \qed
354%
3ba7380e
MW
355% \subsection{Punctuation in displays}
356%
357% It's conventional to follow displayed equations with the necessary
358% punctuation for them to fit into the surrounding prose. This isn't
359% universal: Ian Stewart says in the preface to the third edition of his
360% \emph{Galois Theory}:\footnote{^^A
361% Chapman \& Hall/CRC Mathematics, 2004; ISBN 1-58488-393-6.} ^^A
362% \begin{quote}
363% Along the way I made once change that may raise a few eyebrows. I have
364% spent much of my career telling students that written mathematics should
365% have punctuation as well as symbols. If a symbol or a formula would be
366% followed by a comma if it were replaced by a word or phrase, then it
367% should be followed by a comma; however strange the formula then looks.
368%
369% I still think that punctuation is essential for formulas in the main body
370% of the text. If the formula is $t^2 + 1$, say, then it should have its
371% terminating comma. But I have come to the conclusion that eliminating
372% visual junk from the printed page is more important than punctuatory
373% pedantry, so that when the same formula is \emph{displayed}, for example
374% \[ t^2 + 1 \]
375% then it looks silly if the comma is included, like this,
376% \[ t^2 + 1 \mpunct{,} \]
377% and everything is much cleaner and less ambiguous without punctuation.
378%
379% Purists will hate this, though many of them would not have noticed had I
380% not pointed it out here. Until recently, I would have agreed. But I
381% think it is time we accepted that the act of displaying a formula equips
382% it with \emph{implicit} (invisible) punctuation. This is the 21st
383% century, and typography has moved on.
384% \end{quote}%
385%
386% \DescribeMacro\mpunct
387% I tended to agree with Prof.\ Stewart, even before I read his preface; but
388% now I'm not so sure, and it's clear that we're in the minority. Therefore,
389% the command |\mpunct| sets its argument as text, a little distance from
390% the preceding mathematics.
391%
86f6a31e 392% \implementation
393%
394% \section{Implementation}
395%
396% This isn't really complicated (honest) although it is a lot hairier than I
397% think it ought to be.
398%
399% \begin{macrocode}
400%<*package>
4a655c6f 401\RequirePackage{amssymb}
402\RequirePackage{mdwkey}
86f6a31e 403% \end{macrocode}
404%
405% \subsection{Square roots}
406%
407% \subsubsection{Where is the square root sign?}
408%
409% \LaTeX\ hides the square root sign away somewhere without telling anyone
410% where it is. I extract it forcibly by peeking inside the |\sqrtsign| macro
411% and scrutinising the contents. Here we go: prepare for yukkiness.
412%
413% \begin{macrocode}
414\newcount\sq@sqrt \begingroup \catcode`\|0 \catcode`\\12
415|def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax}
416|expandafter|sq@readrad|meaning|sqrtsign|relax |endgroup
417\def\sq@delim{\delimiter\sq@sqrt\relax}
418% \end{macrocode}
419%
420% \subsubsection{Drawing fake square root signs}
421%
422% \TeX\ absolutely insists on drawing square root signs with a vinculum over
423% the top. In order to get the same effect, we have to attempt to emulate
424% \TeX's behaviour.
425%
426% \begin{macro}{\sqrtdel}
427%
428% This does the main job of typesetting a vinculum-free radical.\footnote{^^A
429% Note for chemists: this is nothing to do with short-lived things which
430% don't have their normal numbers of electrons. And it won't reduce the
431% appearance of wrinkles either.}
432% It's more or less a duplicate of what \TeX\ does internally, so it might be
433% a good plan to have a copy of Appendix~G open while you examine this.
434%
435% We start off by using |\mathpalette| to help decide how big things should
436% be.
437%
438% \begin{macrocode}
439\def\sqrtdel{\mathpalette\sqrtdel@i}
440% \end{macrocode}
441%
442% Read the contents of the radical into a box, so we can measure it.
443%
444% \begin{macrocode}
445\def\sqrtdel@i#1#2{%
446 \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
447% \end{macrocode}
448%
449% Now try and sort out the values needed in this calculation. We'll assume
450% that $\xi_8$ is 0.6\,pt, the way it usually is. Next try to work out the
451% value of $\varphi$.
452%
453% \begin{macrocode}
454 \ifx#1\displaystyle%
455 \@tempdima1ex%
456 \else%
457 \@tempdima.6\p@%
458 \fi%
459% \end{macrocode}
460%
461% That was easy. Now for $\psi$.
462%
463% \begin{macrocode}
464 \@tempdimb.6\p@%
465 \advance\@tempdimb.25\@tempdima%
466% \end{macrocode}
467%
468% Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as
469% requested. Box~2 will do well for this purpose.
470%
471% \begin{macrocode}
472 \dimen@.6\p@%
473 \advance\dimen@\@tempdimb%
474 \advance\dimen@\ht\z@%
475 \advance\dimen@\dp\z@%
476 \setbox\tw@\hbox{%
477 $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
478 }%
479% \end{macrocode}
480%
481% Now we need to do some more calculating (don't you hate it?). As far as
482% Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the
e8e9e5d8 483% top.
86f6a31e 484%
485% \begin{macrocode}
486 \@tempdima\ht\tw@%
487 \advance\@tempdima\dp\tw@%
488 \advance\@tempdima-\ht\z@%
489 \advance\@tempdima-\dp\z@%
490 \ifdim\@tempdima>\@tempdimb%
491 \advance\@tempdima\@tempdimb%
492 \@tempdimb.5\@tempdima%
493 \fi%
494% \end{macrocode}
495%
496% Work out how high to raise the radical symbol. Remember that Appendix~G
497% thinks that the box has a very small height, although this is untrue here.
498%
499% \begin{macrocode}
500 \@tempdima\ht\z@%
501 \advance\@tempdima\@tempdimb%
502 \advance\@tempdima-\ht\tw@%
503% \end{macrocode}
504%
505% Build the output (finally). The brace group is there to turn the output
506% into a mathord, one of the few times that this is actually desirable.
507%
508% \begin{macrocode}
509 {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
510}
511% \end{macrocode}
512%
513% \end{macro}
514%
515% \subsubsection{The new square root command}
516%
517% This is where we reimplement all the square root stuff. Most of this stuff
518% comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\
519% and \LaTeXe, and some is original. I've tried to make the spacing vaguely
520% automatic, so although it's not configurable like \AmSTeX's version, the
521% output should look nice more of the time. Maybe.
522%
523% \begin{macro}{\sqrt}
524%
525% \LaTeX\ says this must be robust, so we make it robust. The first thing to
526% do is to see if there's a star and pass the appropriate squareroot-drawing
527% command on to the rest of the code.
528%
529% \begin{macrocode}
530\DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
531% \end{macrocode}
532%
533% Now we can sort out an optional argument to be displayed on the root.
534%
535% \begin{macrocode}
536\def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
537% \end{macrocode}
538%
539% Stages~2 and~3 below are essentially equivalents of \PlainTeX's
540% |\root|\dots|\of| and |\r@@t|. Here we also find the first wrinkle: the
541% |\rootbox| used to store the number is spaced out on the left if necessary.
542% There's a backspace after the end so that the root can slip underneath, and
543% everything works out nicely. Unfortunately size is fixed here, although
544% doesn't actually seem to matter.
545%
546% \begin{macrocode}
547\def\sqrt@ii#1[#2]{%
548 \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
549 \ifdim\wd\rootbox<6\p@%
550 \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
551 \fi%
552 \mathpalette{\sqrt@iii{#1}}%
553}
554% \end{macrocode}
555%
556% Now we can actually build everything. Note that the root is raised by its
557% depth -- this prevents a common problem with letters with descenders.
558%
559% \begin{macrocode}
560\def\sqrt@iii#1#2#3{%
561 \setbox\z@\hbox{$\m@th#2#1{#3}$}%
562 \dimen@\ht\z@%
563 \advance\dimen@-\dp\z@%
564 \dimen@.6\dimen@%
565 \advance\dimen@\dp\rootbox%
566 \mkern-3mu%
567 \raise\dimen@\copy\rootbox%
568 \mkern-10mu%
569 \box\z@%
570}
571% \end{macrocode}
572%
573% Finally handle a non-numbered root. We read the rooted text in as an
574% argument, to stop problems when people omit the braces. (\AmSTeX\ does
575% this too.)
576%
577% \begin{macrocode}
578\def\sqrt@iv#1#2{#1{#2}}
579% \end{macrocode}
580%
581% \end{macro}
582%
583% \begin{macro}{\root}
584%
585% We also re-implement \PlainTeX's |\root| command, just in case someone uses
586% it, and supply a star-variant. This is all very trivial.
587%
588% \begin{macrocode}
589\def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
590\def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
591% \end{macrocode}
592%
593% \end{macro}
594%
595% \subsection{Modular programming}
596%
597% \begin{macro}{\pmod}
598%
599% Do some hacking if not |\ifouter|.
600%
601% \begin{macrocode}
602\def\pmod#1{%
603 \ifinner\;\else\allowbreak\mkern18mu\fi%
604 ({\operator@font mod}\,\,#1)%
605}
606% \end{macrocode}
607%
608% \end{macro}
609%
610% \subsection{Some magic new maths characters}
611%
612% \begin{macro}{\bitor}
613% \begin{macro}{\bitand}
614% \begin{macro}{\dblor}
615% \begin{macro}{\dbland}
616% \begin{macro}{\xor}
617% \begin{macro}{\lor}
618% \begin{macro}{\ror}
619% \begin{macro}{\lsl}
620% \begin{macro}{\lsr}
621%
622% The new boolean operators.
623%
624% \begin{macrocode}
625\DeclareMathSymbol{&}{\mathbin}{operators}{`\&}
626\DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&}
627\def\bitor{\mathbin\mid}
628\def\dblor{\mathbin{\mid\mid}}
629\def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}}
630\let\xor\oplus
631\def\lsl{\mathbin{<\!\!<}}
632\def\lsr{\mathbin{>\!\!>}}
633\def\rol{\mathbin{<\!\!<\!\!<}}
634\def\ror{\mathbin{>\!\!>\!\!>}}
635\AtBeginDocument{\ifx\lll\@@undefined\else
636 \def\lsl{\mathbin{\ll}}
637 \def\lsr{\mathbin{\gg}}
638 \def\rol{\mathbin{\lll}}
639 \def\ror{\mathbin{\ggg}}
640\fi}
641% \end{macrocode}
642%
643% \end{macro}
644% \end{macro}
645% \end{macro}
646% \end{macro}
647% \end{macro}
648% \end{macro}
649% \end{macro}
650% \end{macro}
651% \end{macro}
652%
653% \begin{macro}{\cat}
654% \begin{macro}{\compose}
655% \begin{macro}{\implies}
656% \begin{macro}{\vect}
657% \begin{macro}{\d}
658% \begin{macro}{\jacobi}
659%
660% A mixed bag of stuff.
661%
662% \begin{macrocode}
663\def\cat{\mathbin{\|}}
664\let\compose\circ
665\def\implies{\Rightarrow}
666\def\vect#1{\mathord{\mathbf{#1}}}
4a655c6f 667\def\d{%
668 \ifmmode\mathord{\operator@font d}%
669 \else\expandafter\a\expandafter d\fi%
670}
86f6a31e 671\def\jacobi#1#2{{{#1}\overwithdelims()#2}}
672% \end{macrocode}
673%
674% \end{macro}
675% \end{macro}
676% \end{macro}
677% \end{macro}
678% \end{macro}
679% \end{macro}
680%
681% \begin{macro}{\statclose}
682% \begin{macro}{\compind}
683%
684% Fancy new relations for probability distributions.
685%
686% \begin{macrocode}
687\def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
688\def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
689% \end{macrocode}
690%
691% \end{macro}
692% \end{macro}
693%
4a576d39
MW
694% \begin{macro}{\defop}
695% Defining new operator names.
696% \begin{macrocode}
697\def\defop{\@ifstar{\defop@\nolimits}{\defop@\limits}}
698\def\defop@#1#2#3{\def#2{\mathop{\operator@font #3}#1}}
699% \end{macrocode}
700% \end{macro}
701%
86f6a31e 702% \begin{macro}{\keys}
703% \begin{macro}{\dom}
704% \begin{macro}{\ran}
705% \begin{macro}{\supp}
706% \begin{macro}{\lcm}
4a655c6f 707% \begin{macro}{\poly}
708% \begin{macro}{\negl}
709% \begin{macro}{\ord}
86f6a31e 710%
711% And the new operator names.
712%
713% \begin{macrocode}
4a576d39
MW
714\defop*\keys{keys}
715\defop*\dom{dom}
716\defop*\ran{ran}
717\defop*\supp{supp}
718\defop*\lcm{lcm}
719\defop*\poly{poly}
720\defop*\negl{negl}
721\defop*\ord{ord}
86f6a31e 722% \end{macrocode}
723%
724% \end{macro}
725% \end{macro}
726% \end{macro}
727% \end{macro}
728% \end{macro}
4a655c6f 729% \end{macro}
730% \end{macro}
731% \end{macro}
732%
733% \subsection{Fractions}
734%
735% \begin{macro}{\@frac@parse}
736%
737% \syntax{"\\@frac@parse{"<stuff>"}{"<frac-params>"}"} -- run \<stuff>
738% passing it three arguments: an infix fraction-making command, the `outer'
739% style, and the `inner' style.
740%
741% This is rather tricky. We clear a load of parameters, parse the parameter
742% list, and then build a token list containing the right stuff. Without the
743% token list fiddling, we end up expanding things at the wrong times -- for
744% example, |\{| expands to something terribly unpleasant in a document
745% preamble.
746%
747% All of the nastiness is contained in a group.
748%
749% \begin{macrocode}
750\def\@frac@parse#1#2{%
751 \begingroup%
752 \let\@wd\@empty\def\@ldel{.}\def\@rdel{.}%
753 \def\@op{over}\let\@dim\@empty\@tempswafalse%
754 \let\@is\@empty\let\@os\@empty%
755 \mkparse{mdwmath:frac}{#2}%
756 \toks\tw@{\endgroup#1}%
757 \toks@\expandafter{\csname @@\@op\@wd\endcsname}%
758 \if@tempswa%
759 \toks@\expandafter{\the\expandafter\toks@\@ldel}%
760 \toks@\expandafter{\the\expandafter\toks@\@rdel}%
761 \fi%
762 \expandafter\toks@\expandafter{\the\expandafter\toks@\@dim}%
763 \toks@\expandafter{\the\toks\expandafter\tw@\expandafter{\the\toks@}}
764 \toks@\expandafter{\the\expandafter\toks@\expandafter{\@os}}
765 \toks@\expandafter{\the\expandafter\toks@\expandafter{\@is}}
766 \the\toks@%
767}
768% \end{macrocode}
769%
770% The keyword definitions are relatively straightforward now. The error
771% handling for \textsf{style} and \textsf{innerstyle} could do with
772% improvement.
773%
774% \begin{macrocode}
775\def\@frac@del#1#2{\def\@wd{withdelims}\@tempswatrue\def#1{#2}}
776\mkdef{mdwmath:frac}{leftdelim}{\@frac@del\@ldel{#1}}
777\mkdef{mdwmath:frac}{rightdelim}{\@frac@del\@rdel{#1}}
778\mkdef{mdwmath:frac}{nodelims}*{\let\@wd\@empty\@tempswafalse}
779\mkdef{mdwmath:frac}{line}{%
780 \def\@op{above}\setlength\dimen@{#1}\edef\@dim{\the\dimen@\space}%
781}
782\mkdef{mdwmath:frac}{line}*{\def\@op{over}\let\@dim\@empty}
783\mkdef{mdwmath:frac}{noline}*{\def\@op{atop}\let\@dim\@empty}
784\def\@frac@style#1#2{%
785 \ifx\q@delim#2\q@delim\let#1\@empty%
786 \else%
787 \expandafter\ifx\csname #2style\endcsname\relax%
788 \PackageError{mdwmath}{Bad maths style `#2'}\@ehc%
789 \else%
790 \edef#1{\csname#2style\endcsname}%
791 \fi%
792 \fi%
793}
794\mkdef{mdwmath:frac}{style}[]{\@frac@style\@os{#1}}
795\mkdef{mdwmath:frac}{innerstyle}[]{\@frac@style\@is{#1}}
796% \end{macrocode}
797%
798% \end{macro}
799%
800% \begin{macro}{\fracdef}
801%
802% Here's where the rest of the pain is. We do a preliminary parse of the
803% parameters and `compile' the result into the output macro. If there's no
804% optional argument, then we don't need to do any really tedious formatting
805% at the point of use.
806%
807% \begin{macrocode}
808\def\fracdef#1#2{\@frac@parse{\fracdef@i{#1}{#2}}{#2}}
809\def\fracdef@i#1#2#3#4#5{\def#1{\@frac@do{#2}{#3}{#4}{#5}}}
810\def\@frac@do#1#2#3#4{%
811 \@ifnextchar[{\@frac@complex{#1}}{\@frac@simple{#2}{#3}{#4}}%
812}
813\def\@frac@complex#1[#2]{\@frac@parse\@frac@simple{#1,#2}}
814\def\@frac@simple#1#2#3#4#5{{#2{{#3#4}#1{#3#5}}}}
815% \end{macrocode}
816%
817% \end{macro}
818%
819% \begin{macro}{\frac@fix}
820% \begin{macro}{\@@over}
821% \begin{macro}{\@@atop}
822% \begin{macro}{\@@above}
823% \begin{macro}{\@@overwithdelims}
824% \begin{macro}{\@@atopwithdelims}
825% \begin{macro}{\@@abovewithdelims}
826%
827% Finally, we need to fix up |\@@over| and friends. Maybe \package{amsmath}
828% has hidden the commands away somewhere unhelpful. If not, we make the
829% requisite copies.
830%
831% \begin{macrocode}
832\def\q@delim{\q@delim}
833\def\frac@fix#1{\expandafter\frac@fix@i\string#1\q@delim}
834\def\frac@fix@i#1#2\q@delim{\frac@fix@ii{#2}\frac@fix@ii{#2withdelims}}
835\def\frac@fix@ii#1{%
836 \expandafter\ifx\csname @@#1\endcsname\relax%
837 \expandafter\let\csname @@#1\expandafter\endcsname\csname#1\endcsname%
838 \fi%
839}
840\frac@fix\over \frac@fix\atop \frac@fix\above
841% \end{macrocode}
842%
843% \end{macro}
844% \end{macro}
845% \end{macro}
846% \end{macro}
847% \end{macro}
848% \end{macro}
849% \end{macro}
850%
851% \begin{macro}{\frac}
852% \begin{macro}{\binom}
853% \begin{macro}{\jacobi}
854%
855% And finally, we define the fraction-making commands.
856%
857% \begin{macrocode}
858\fracdef\frac{nodelims, line}
859\fracdef\binom{leftdelim = (, rightdelim = ), noline}
860\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
861% \end{macrocode}
862%
863% \end{macro}
864% \end{macro}
865% \end{macro}
86f6a31e 866%
867% \subsection{Blackboard bold stuff}
868%
869% \begin{macro}{\Z}
870% \begin{macro}{\Q}
871% \begin{macro}{\R}
872% \begin{macro}{\C}
873% \begin{macro}{\N}
874% \begin{macro}{\F}
875% \begin{macro}{\powerset}
4a655c6f 876% \begin{macro}{\gf}
86f6a31e 877%
878% First of all, the signs.
879%
880% \begin{macrocode}
881\def\Z{\mathbb{Z}}
882\def\Q{\mathbb{Q}}
883\def\R{\mathbb{R}}
884\def\C{\mathbb{C}}
885\def\N{\mathbb{N}}
886\def\F{\mathbb{F}}
887\def\powerset{\mathbb{P}}
4a655c6f 888\def\gf#1{\F_{#1}}
889%\def\gf#1{\mathrm{GF}({#1})}
86f6a31e 890% \end{macrocode}
891%
892% \end{macro}
893% \end{macro}
894% \end{macro}
895% \end{macro}
896% \end{macro}
897% \end{macro}
898% \end{macro}
4a655c6f 899% \end{macro}
86f6a31e 900%
901% And now, define |\mathbb| if it's not there already.
902%
903% \begin{macrocode}
904\AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
905% \end{macrocode}
906%
907% \subsection{Biggles}
908%
909% Now for some user-controlled delimiter sizing. The standard bigness of
910% plain \TeX's delimiters are all right, but it's a little limiting.
911%
912% The biggness of delimiters is based on the size of the current |\strut|,
913% which \LaTeX\ keeps up to date all the time. This will make the various
914% delimiters grow in proportion when the text gets bigger. Actually, I'm
915% not sure that this is exactly right -- maybe it should be nonlinear,
916%
917% \begin{macro}{\bbigg}
918% \begin{macro}{\bbiggl}
919% \begin{macro}{\bbiggr}
920% \begin{macro}{\bbiggm}
921%
922% This is where the bigness is done. This is more similar to the plain \TeX\
923% big delimiter stuff than to the \package{amsmath} stuff, although there's
924% not really a lot of difference.
925%
926% The two arguments are a multiplier for the delimiter size, and a small
927% increment applied \emph{before} the multiplication (which is optional).
928%
929% This is actually a front for a low-level interface which can be called
930% directly for efficiency.
931%
932% \begin{macrocode}
933\def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
934\def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
935% \end{macrocode}
936%
937% \end{macro}
938% \end{macro}
939% \end{macro}
940% \end{macro}
941%
942% \begin{macro}{\@bbigg}
943%
944% This is an optional argument parser providing a front end for the main
945% macro |\bbigg@|.
946%
947% \begin{macrocode}
a1af3c0e
MW
948\def\@bbigg#1{\@testopt{\@bbigg@i{#1}}\z@}
949\def\@bbigg@i#1[#2]{#1{\bbigg@{#2}}}
86f6a31e 950% \end{macrocode}
951%
952% \end{macro}
953%
954% \begin{macro}{\bbigg@}
955%
956% This is it, at last. The arguments are as described above: an addition
957% to be made to the strut height, and a multiplier. Oh, and the delimiter,
958% of course.
959%
960% This is a bit messy. The smallest `big' delimiter, |\big|, is the same
961% height as the current strut box. Other delimiters are~$1\frac12$, $2$
962% and~$2\frac12$ times this height. I'll set the height of the delimiter by
963% putting in a |\vcenter| of the appropriate size.
964%
965% Given an extra height~$x$, a multiplication factor~$f$ and a strut
966% height~$h$ and depth~$d$, I'll create a vcenter with total height
967% $f(h+d+x)$. Easy, isn't it?
968%
969% \begin{macrocode}
970\def\bbigg@#1#2#3{%
971 {\hbox{$%
972 \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
973 \advance\dimen@#1%
974 \dimen@#2\dimen@%
975 \left#3\vcenter to\dimen@{}\right.\n@space%
976 $}}%
977}
978% \end{macrocode}
979%
980% \end{macro}
981%
982% \begin{macro}{\big}
983% \begin{macro}{\Big}
984% \begin{macro}{\bigg}
985% \begin{macro}{\Bigg}
986%
987% Now for the easy macros.
988%
989% \begin{macrocode}
990\def\big{\bbigg@\z@\@ne}
991\def\Big{\bbigg@\z@{1.5}}
992\def\bigg{\bbigg@\z@\tw@}
993\def\Bigg{\bbigg@\z@{2.5}}
994% \end{macrocode}
995%
996% \end{macro}
997% \end{macro}
998% \end{macro}
999% \end{macro}
1000%
3d974523
MW
1001% \subsection{Bracketty notation}
1002%
1003% This is mostly an exercise in keeping track of data structures. Which is a
1004% problem, because \TeX\ isn't really very good at data structures. Our main
1005% trick is Church-encoded tuples; i.e., we represent a collection of things
1006% as a higher-order function which applies a given projection to the tuple.
1007%
1008% \begin{macro}{\brk@delim}
1009% \begin{macro}{\brk@plain}
1010% \begin{macro}{\brk@size}
1011% A delimiter keeps track of a before-string, a plain-text delimiter, a sized
1012% delimiter, and an after-string. Rather than just projecting components, we
1013% we want to typeset the things, so we provide two macros for doing this: one
1014% typesets the plain version (possibly with a prefix), and the other applies
1015% a size to the sized delimiter.
1016% \begin{macrocode}
1017\def\brk@delim#1#2#3#4#5{#5{#1}{#2}{#3}{#4}}
1018\def\brk@plain#1#2#3#4#5{#2#1#3#5}
1019\def\brk@size#1#2#3#4#5{#2#1#4#5}
1020% \end{macrocode}
1021% \end{macro}
1022% \end{macro}
1023% \end{macro}
1024%
1025% \begin{macro}{\brk@bbigg}
1026% Before we get really stuck in, here's a quick macro to collect a |\bbigg|
1027% argument and pass it to its continuation.
1028% \begin{macrocode}
1029\def\brk@bbigg#1{\@testopt{\brk@bbigg@{#1}}\z@}
1030\def\brk@bbigg@#1[#2]#3{#1{#2}}
1031% \end{macrocode}
1032% \end{macro}
1033%
1034% \begin{macro}{\brk@lefttwo}
1035% \begin{macro}{\brk@righttwo}
1036% We now begin the two-delimiter machinery proper. The macro |\defbrk| will
1037% package up the delimiters in a macro. The following two projections pick
1038% out the left and right delimiters and apply them to their argument.
1039% \begin{macrocode}
1040\def\brk@lefttwo#1#2#3{#2{#1}}
1041\def\brk@righttwo#1#2#3{#3{#1}}
1042% \end{macrocode}
1043% \end{macro}
1044% \end{macro}
1045%
1046% \begin{macro}{\brk@plaintwo}
1047% \begin{macro}{\brk@sizetwo}
1048% The next stage is to typeset a full delimited expression, which is what we
1049% do here.
1050% \begin{macrocode}
1051\def\brk@plaintwo#1#2%
1052 {#1{\brk@lefttwo{\brk@plain{}}}#2#1{\brk@righttwo{\brk@plain{}}}}
1053\def\brk@sizetwo#1#2#3#4%
1054 {#3{\brk@lefttwo{\brk@size{#1}}}#4#3{\brk@righttwo{\brk@size{#2}}}}
1055% \end{macrocode}
1056% \end{macro}
1057% \end{macro}
1058%
1059% \begin{macro}{\brk@maintwo}
1060% \begin{macro}{\brk@bigtwo}
1061% \begin{macro}{\brk@Bigtwo}
1062% \begin{macro}{\brk@biggtwo}
1063% \begin{macro}{\brk@Biggtwo}
1064% \begin{macro}{\brk@bbiggtwo}
1065% \begin{macro}{\brk@auto}
1066% And finally, the top-level handlers for two-delimiter bracket-notation
1067% macros.
1068% \begin{macrocode}
1069\def\brk@maintwo#1{\@ifnextchar[{\brk@maintwo@size#1}{\brk@plaintwo#1}}
1070\def\brk@maintwo@size#1[#2][#3]{\brk@sizetwo{#2}{#3}#1}
1071\def\brk@bigtwo{\brk@sizetwo\bigl\bigr}
1072\def\brk@Bigtwo{\brk@sizetwo\Bigl\Bigr}
1073\def\brk@biggtwo{\brk@sizetwo\biggl\biggr}
1074\def\brk@Biggtwo{\brk@sizetwo\Biggl\Biggr}
1075\def\brk@bbiggtwo#1{\brk@bbigg{\brk@bbiggtwo@#1}}
1076\def\brk@bbiggtwo@#1#2{\brk@sizetwo{\bbiggl#1{#2}}{\bbiggr#1{#2}}}
1077\def\brk@auto{\brk@sizetwo\left\right}
1078% \end{macrocode}
1079% \end{macro}
1080% \end{macro}
1081% \end{macro}
1082% \end{macro}
1083% \end{macro}
1084% \end{macro}
1085% \end{macro}
1086%
1087% \begin{macro}{\brk@leftthree}
1088% \begin{macro}{\brk@midthree}
1089% \begin{macro}{\brk@rightthree}
1090% \begin{macro}{\brk@plainthree}
1091% \begin{macro}{\brk@sizethree}
1092% Next, the three-delimiter projections.
1093% \begin{macrocode}
1094\def\brk@leftthree#1#2#3#4{#2{#1}}
1095\def\brk@midthree#1#2#3#4{#3{#1}}
1096\def\brk@rightthree#1#2#3#4{#4{#1}}
1097\def\brk@plainthree#1#2#3{%
1098 #1{\brk@leftthree{\brk@plain{}}}#2%
1099 #1{\brk@midthree{\brk@plain\mathrel}}#3%
1100 #1{\brk@rightthree{\brk@plain{}}}%
1101}
1102\def\brk@sizethree#1#2#3#4#5#6{%
1103 #4{\brk@leftthree{\brk@size{#1}}}#5%
1104 #4{\brk@midthree{\brk@size{#2}}}#6%
1105 #4{\brk@rightthree{\brk@size{#3}}}%
1106}
1107% \end{macrocode}
1108% \end{macro}
1109% \end{macro}
1110% \end{macro}
1111% \end{macro}
1112% \end{macro}
1113%
1114% \begin{macro}{\brk@mainthree}
1115% \begin{macro}{\brk@bigthree}
1116% \begin{macro}{\brk@Bigthree}
1117% \begin{macro}{\brk@biggthree}
1118% \begin{macro}{\brk@Biggthree}
1119% \begin{macro}{\brk@bbiggthree}
1120% And finally, the top-level handlers for three-delimiter bracket-notation
1121% macros.
1122% \begin{macrocode}
1123\def\brk@mainthree#1{\@ifnextchar[{\brk@mainthree@size#1}{\brk@plainthree#1}}
1124\def\brk@mainthree@size#1[#2][#3][#4]{\brk@sizethree{#2}{#3}{#4}#1}
1125\def\brk@bigthree{\brk@sizethree\bigl\bigm\bigr}
1126\def\brk@Bigthree{\brk@sizethree\Bigl\Bigm\Bigr}
1127\def\brk@biggthree{\brk@sizethree\biggl\biggm\biggr}
1128\def\brk@Biggthree{\brk@sizethree\Biggl\Biggm\Biggr}
1129\def\brk@bbiggthree#1{\brk@bbigg{\brk@bbiggtree@#1}}
1130\def\brk@bbiggthree@#1#2%
1131 {\brk@sizethree{\bbiggl#1{#2}}{\bbiggm#1{#2}}{\bbiggr#1{#2}}}
1132% \end{macrocode}
1133% \end{macro}
1134% \end{macro}
1135% \end{macro}
1136% \end{macro}
1137% \end{macro}
1138% \end{macro}
1139%
1140% \begin{macro}{\@csname}
1141% A brief change of pace: \syntax{"\\@csname{"<cont>"}{"<command>"}"} calls
1142% \<cont> with the name of the control sequence \<command>, suitable for
1143% inlcuding as part of |\csname|\ldots|\endcsname|. I use |\string|, and
1144% then there's a dance to remove the backslash from the beginning and the
1145% space from the end.
1146% \begin{macrocode}
1147\def\@csname#1#2{\expandafter\@csname@\string#2 \relax#1}
1148\begingroup \lccode`\|=`\\
1149 \lowercase{\endgroup \def\@csname@|#1 \relax#2{#2{#1}}}
1150% \end{macrocode}
1151% \end{macro}
1152%
1153% \begin{macro}{\defbrk}
1154% There's nothing to do now but to define |\defbrk| itself. This is mostly a
1155% tedious exercise in collecting the arguments.
1156% \begin{macrocode}
1157\def\defbrk@delim#1{\@testopt{\defbrk@delim@i{#1}}{}}
1158\def\defbrk@delim@i#1[#2]#3{%
1159 \def\@tempa{#3}%
1160 \ifx\@tempa\@empty \expandafter\@firstoftwo
1161 \else \expandafter\@secondoftwo \fi
1162 {\@testopt{\defbrk@delim@ii{#1}{#2}{}{.}}{}}%
1163 {\@testopt{\defbrk@delim@ii{#1}{#2}{#3}{#3}}{}}%
1164}
1165\def\defbrk@delim@ii#1#2#3#4[#5]{#1{\brk@delim{#2}{#3}{#4}{#5}}}
1166\def\defbrk{\@ifstar\defbrk@three\defbrk@two}
1167\def\defbrk@two#1{\defbrk@delim{\defbrk@two@i{#1}}}
1168\def\defbrk@two@i#1#2{\defbrk@delim{\defbrk@two@ii{#1}{#2}}}
1169\def\defbrk@two@ii{\@csname\defbrk@two@iii}
1170\def\defbrk@two@iii#1#2#3{%
1171 \@namedef{(#1)}##1{##1{#2}{#3}}%
1172 \expandafter\defbrk@two@iv\csname(#1)\endcsname{#1}%
1173}
1174\def\defbrk@two@iv#1#2{%
1175 \@namedef{#2}{\brk@maintwo#1}%
1176 \@namedef{big#2}{\brk@bigtwo#1}%
1177 \@namedef{Big#2}{\brk@Bigtwo#1}%
1178 \@namedef{bigg#2}{\brk@biggtwo#1}%
1179 \@namedef{Bigg#2}{\brk@Biggtwo#1}%
1180 \@namedef{bbigg#2}{\brk@bbiggtwo#1}%
1181 \@namedef{auto#2}{\brk@auto#1}%
1182}
1183\def\defbrk@three#1{\defbrk@delim{\defbrk@three@i{#1}}}
1184\def\defbrk@three@i#1#2{\defbrk@delim{\defbrk@three@ii{#1}{#2}}}
1185\def\defbrk@three@ii#1#2#3{\defbrk@delim{\defbrk@three@iii{#1}{#2}{#3}}}
1186\def\defbrk@three@iii{\@csname\defbrk@three@iv}
1187\def\defbrk@three@iv#1#2#3#4{%
1188 \@namedef{(#1)}##1{##1{#2}{#3}{#4}}%
1189 \expandafter\defbrk@three@v\csname(#1)\endcsname{#1}%
1190}
1191\def\defbrk@three@v#1#2{%
1192 \@namedef{#2}{\brk@mainthree#1}%
1193 \@namedef{big#2}{\brk@bigthree#1}%
1194 \@namedef{Big#2}{\brk@Bigthree#1}%
1195 \@namedef{bigg#2}{\brk@biggthree#1}%
1196 \@namedef{Bigg#2}{\brk@Biggthree#1}%
1197 \@namedef{bbigg#2}{\brk@bbiggthree#1}%
1198}
1199% \end{macrocode}
1200% \end{macro}
1201%
86f6a31e 1202% \subsection{The `QED' symbol}
1203%
1204% \begin{macro}{\qed}
1205% \begin{macro}{\qedrule}
1206% \begin{macro}{\qedsymbol}
1207%
1208% This is fairly simple. Just be careful will the glue and penalties. The
1209% size of the little box is based on the current font size.
1210%
1211% The horizontal list constructed by the macro is like this:
1212%
1213% \begin{itemize}
1214% \item A |\quad| of space. This might get eaten if there's a break here or
1215% before. That's OK, though.
1216% \item An empty box, to break a run of discardable items.
1217% \item A |\penalty 10000| to ensure that the spacing glue isn't discarded.
1218% \item |\hfill| glue to push the little rule to the end of the line.
1219% \item A little square rule `\qedrule', with some small kerns around it.
1220% \item A glue item to counter the effect of glue added at the paragraph
e8e9e5d8 1221% boundary.
86f6a31e 1222% \end{itemize}
1223%
4a655c6f 1224% The vertical mode case is simpler, but less universal. It copes with
1225% relatively simple cases only.
1226%
86f6a31e 1227% A |\qed| commend ends the paragraph.
1228%
1229% \begin{macrocode}
4a655c6f 1230\def\qed{%
1231 \ifvmode%
1232 \unskip%
1233 \setbox\z@\hb@xt@\linewidth{\hfil\strut\qedsymbol}%
1234 \prevdepth-\@m\p@%
1235 \ifdim\prevdepth>\dp\strutbox%
1236 \dimen@\prevdepth\advance\dimen@-\dp\strutbox%
1237 \kern-\dimen@%
1238 \fi%
1239 \penalty\@M\vskip-\baselineskip\box\z@%
1240 \else%
1241 \unskip%
1242 \penalty\@M\hfill%
1243 \hbox{}\penalty200\quad%
1244 \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
1245 \fi%
86f6a31e 1246}
1247\def\qedrule{{%
1248 \dimen@\ht\strutbox%
4a655c6f 1249 \advance\dimen@\dp\strutbox%
86f6a31e 1250 \dimen@ii1ex%
1251 \advance\dimen@-\dimen@ii%
1252 \divide\dimen@\tw@%
1253 \advance\dimen@-\dp\strutbox%
1254 \advance\dimen@\dimen@ii%
1255 \advance\dimen@ii-\dimen@%
1256 \kern\p@%
1257 \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
1258 \kern\p@%
1259}}
1260\providecommand\qedsymbol{\qedrule}
1261% \end{macrocode}
1262%
1263% \end{macro}
1264% \end{macro}
1265% \end{macro}
1266%
3ba7380e
MW
1267% \subsection{Punctuation in displays}
1268%
1269% \begin{macro}{\mpunct}
1270%
1271% This is actually a little more subtle than you'd expect. If the
1272% \package{amstext} package is loaded, or something else has defined the
1273% |\text| command, then we should use that; otherwise, just drop a box in and
1274% hope for the best.
1275%
1276% \begin{macrocode}
1277\def\mpunct#1{%
1278 \,%
1279 \ifx\text\@@undefined\hbox%
1280 \else\expandafter\text\fi%
1281 {#1}%
1282}
1283% \end{macrocode}
1284%
1285%\end{macro}
1286%
86f6a31e 1287% That's all there is. Byebye.
1288%
1289% \begin{macrocode}
1290%</package>
1291% \end{macrocode}
1292%
1293% \hfill Mark Wooding, \today
1294%
1295% \Finale
1296\endinput