mdwmath.dtx: Use `\@testopt', which I've just noticed.
[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%
a1af3c0e 30% \CheckSum{727}
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%
272% \subsection{The `QED' symbol}
273%
274% \DescribeMacro\qed
275% \DescribeMacro\qedrule
276% For use in proofs of theorems, we provide a `QED' symbol which behaves well
277% under bizarre line-splitting conditions. To use it, just say |\qed|. The
278% little `\qedrule' symbol is available on its own, by saying |\qedrule|.
279% This also sets |\qedsymbol| if it's not set already.
280% \qed
281%
3ba7380e
MW
282% \subsection{Punctuation in displays}
283%
284% It's conventional to follow displayed equations with the necessary
285% punctuation for them to fit into the surrounding prose. This isn't
286% universal: Ian Stewart says in the preface to the third edition of his
287% \emph{Galois Theory}:\footnote{^^A
288% Chapman \& Hall/CRC Mathematics, 2004; ISBN 1-58488-393-6.} ^^A
289% \begin{quote}
290% Along the way I made once change that may raise a few eyebrows. I have
291% spent much of my career telling students that written mathematics should
292% have punctuation as well as symbols. If a symbol or a formula would be
293% followed by a comma if it were replaced by a word or phrase, then it
294% should be followed by a comma; however strange the formula then looks.
295%
296% I still think that punctuation is essential for formulas in the main body
297% of the text. If the formula is $t^2 + 1$, say, then it should have its
298% terminating comma. But I have come to the conclusion that eliminating
299% visual junk from the printed page is more important than punctuatory
300% pedantry, so that when the same formula is \emph{displayed}, for example
301% \[ t^2 + 1 \]
302% then it looks silly if the comma is included, like this,
303% \[ t^2 + 1 \mpunct{,} \]
304% and everything is much cleaner and less ambiguous without punctuation.
305%
306% Purists will hate this, though many of them would not have noticed had I
307% not pointed it out here. Until recently, I would have agreed. But I
308% think it is time we accepted that the act of displaying a formula equips
309% it with \emph{implicit} (invisible) punctuation. This is the 21st
310% century, and typography has moved on.
311% \end{quote}%
312%
313% \DescribeMacro\mpunct
314% I tended to agree with Prof.\ Stewart, even before I read his preface; but
315% now I'm not so sure, and it's clear that we're in the minority. Therefore,
316% the command |\mpunct| sets its argument as text, a little distance from
317% the preceding mathematics.
318%
86f6a31e 319% \implementation
320%
321% \section{Implementation}
322%
323% This isn't really complicated (honest) although it is a lot hairier than I
324% think it ought to be.
325%
326% \begin{macrocode}
327%<*package>
4a655c6f 328\RequirePackage{amssymb}
329\RequirePackage{mdwkey}
86f6a31e 330% \end{macrocode}
331%
332% \subsection{Square roots}
333%
334% \subsubsection{Where is the square root sign?}
335%
336% \LaTeX\ hides the square root sign away somewhere without telling anyone
337% where it is. I extract it forcibly by peeking inside the |\sqrtsign| macro
338% and scrutinising the contents. Here we go: prepare for yukkiness.
339%
340% \begin{macrocode}
341\newcount\sq@sqrt \begingroup \catcode`\|0 \catcode`\\12
342|def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax}
343|expandafter|sq@readrad|meaning|sqrtsign|relax |endgroup
344\def\sq@delim{\delimiter\sq@sqrt\relax}
345% \end{macrocode}
346%
347% \subsubsection{Drawing fake square root signs}
348%
349% \TeX\ absolutely insists on drawing square root signs with a vinculum over
350% the top. In order to get the same effect, we have to attempt to emulate
351% \TeX's behaviour.
352%
353% \begin{macro}{\sqrtdel}
354%
355% This does the main job of typesetting a vinculum-free radical.\footnote{^^A
356% Note for chemists: this is nothing to do with short-lived things which
357% don't have their normal numbers of electrons. And it won't reduce the
358% appearance of wrinkles either.}
359% It's more or less a duplicate of what \TeX\ does internally, so it might be
360% a good plan to have a copy of Appendix~G open while you examine this.
361%
362% We start off by using |\mathpalette| to help decide how big things should
363% be.
364%
365% \begin{macrocode}
366\def\sqrtdel{\mathpalette\sqrtdel@i}
367% \end{macrocode}
368%
369% Read the contents of the radical into a box, so we can measure it.
370%
371% \begin{macrocode}
372\def\sqrtdel@i#1#2{%
373 \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
374% \end{macrocode}
375%
376% Now try and sort out the values needed in this calculation. We'll assume
377% that $\xi_8$ is 0.6\,pt, the way it usually is. Next try to work out the
378% value of $\varphi$.
379%
380% \begin{macrocode}
381 \ifx#1\displaystyle%
382 \@tempdima1ex%
383 \else%
384 \@tempdima.6\p@%
385 \fi%
386% \end{macrocode}
387%
388% That was easy. Now for $\psi$.
389%
390% \begin{macrocode}
391 \@tempdimb.6\p@%
392 \advance\@tempdimb.25\@tempdima%
393% \end{macrocode}
394%
395% Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as
396% requested. Box~2 will do well for this purpose.
397%
398% \begin{macrocode}
399 \dimen@.6\p@%
400 \advance\dimen@\@tempdimb%
401 \advance\dimen@\ht\z@%
402 \advance\dimen@\dp\z@%
403 \setbox\tw@\hbox{%
404 $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
405 }%
406% \end{macrocode}
407%
408% Now we need to do some more calculating (don't you hate it?). As far as
409% Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the
e8e9e5d8 410% top.
86f6a31e 411%
412% \begin{macrocode}
413 \@tempdima\ht\tw@%
414 \advance\@tempdima\dp\tw@%
415 \advance\@tempdima-\ht\z@%
416 \advance\@tempdima-\dp\z@%
417 \ifdim\@tempdima>\@tempdimb%
418 \advance\@tempdima\@tempdimb%
419 \@tempdimb.5\@tempdima%
420 \fi%
421% \end{macrocode}
422%
423% Work out how high to raise the radical symbol. Remember that Appendix~G
424% thinks that the box has a very small height, although this is untrue here.
425%
426% \begin{macrocode}
427 \@tempdima\ht\z@%
428 \advance\@tempdima\@tempdimb%
429 \advance\@tempdima-\ht\tw@%
430% \end{macrocode}
431%
432% Build the output (finally). The brace group is there to turn the output
433% into a mathord, one of the few times that this is actually desirable.
434%
435% \begin{macrocode}
436 {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
437}
438% \end{macrocode}
439%
440% \end{macro}
441%
442% \subsubsection{The new square root command}
443%
444% This is where we reimplement all the square root stuff. Most of this stuff
445% comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\
446% and \LaTeXe, and some is original. I've tried to make the spacing vaguely
447% automatic, so although it's not configurable like \AmSTeX's version, the
448% output should look nice more of the time. Maybe.
449%
450% \begin{macro}{\sqrt}
451%
452% \LaTeX\ says this must be robust, so we make it robust. The first thing to
453% do is to see if there's a star and pass the appropriate squareroot-drawing
454% command on to the rest of the code.
455%
456% \begin{macrocode}
457\DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
458% \end{macrocode}
459%
460% Now we can sort out an optional argument to be displayed on the root.
461%
462% \begin{macrocode}
463\def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
464% \end{macrocode}
465%
466% Stages~2 and~3 below are essentially equivalents of \PlainTeX's
467% |\root|\dots|\of| and |\r@@t|. Here we also find the first wrinkle: the
468% |\rootbox| used to store the number is spaced out on the left if necessary.
469% There's a backspace after the end so that the root can slip underneath, and
470% everything works out nicely. Unfortunately size is fixed here, although
471% doesn't actually seem to matter.
472%
473% \begin{macrocode}
474\def\sqrt@ii#1[#2]{%
475 \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
476 \ifdim\wd\rootbox<6\p@%
477 \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
478 \fi%
479 \mathpalette{\sqrt@iii{#1}}%
480}
481% \end{macrocode}
482%
483% Now we can actually build everything. Note that the root is raised by its
484% depth -- this prevents a common problem with letters with descenders.
485%
486% \begin{macrocode}
487\def\sqrt@iii#1#2#3{%
488 \setbox\z@\hbox{$\m@th#2#1{#3}$}%
489 \dimen@\ht\z@%
490 \advance\dimen@-\dp\z@%
491 \dimen@.6\dimen@%
492 \advance\dimen@\dp\rootbox%
493 \mkern-3mu%
494 \raise\dimen@\copy\rootbox%
495 \mkern-10mu%
496 \box\z@%
497}
498% \end{macrocode}
499%
500% Finally handle a non-numbered root. We read the rooted text in as an
501% argument, to stop problems when people omit the braces. (\AmSTeX\ does
502% this too.)
503%
504% \begin{macrocode}
505\def\sqrt@iv#1#2{#1{#2}}
506% \end{macrocode}
507%
508% \end{macro}
509%
510% \begin{macro}{\root}
511%
512% We also re-implement \PlainTeX's |\root| command, just in case someone uses
513% it, and supply a star-variant. This is all very trivial.
514%
515% \begin{macrocode}
516\def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
517\def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
518% \end{macrocode}
519%
520% \end{macro}
521%
522% \subsection{Modular programming}
523%
524% \begin{macro}{\pmod}
525%
526% Do some hacking if not |\ifouter|.
527%
528% \begin{macrocode}
529\def\pmod#1{%
530 \ifinner\;\else\allowbreak\mkern18mu\fi%
531 ({\operator@font mod}\,\,#1)%
532}
533% \end{macrocode}
534%
535% \end{macro}
536%
537% \subsection{Some magic new maths characters}
538%
539% \begin{macro}{\bitor}
540% \begin{macro}{\bitand}
541% \begin{macro}{\dblor}
542% \begin{macro}{\dbland}
543% \begin{macro}{\xor}
544% \begin{macro}{\lor}
545% \begin{macro}{\ror}
546% \begin{macro}{\lsl}
547% \begin{macro}{\lsr}
548%
549% The new boolean operators.
550%
551% \begin{macrocode}
552\DeclareMathSymbol{&}{\mathbin}{operators}{`\&}
553\DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&}
554\def\bitor{\mathbin\mid}
555\def\dblor{\mathbin{\mid\mid}}
556\def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}}
557\let\xor\oplus
558\def\lsl{\mathbin{<\!\!<}}
559\def\lsr{\mathbin{>\!\!>}}
560\def\rol{\mathbin{<\!\!<\!\!<}}
561\def\ror{\mathbin{>\!\!>\!\!>}}
562\AtBeginDocument{\ifx\lll\@@undefined\else
563 \def\lsl{\mathbin{\ll}}
564 \def\lsr{\mathbin{\gg}}
565 \def\rol{\mathbin{\lll}}
566 \def\ror{\mathbin{\ggg}}
567\fi}
568% \end{macrocode}
569%
570% \end{macro}
571% \end{macro}
572% \end{macro}
573% \end{macro}
574% \end{macro}
575% \end{macro}
576% \end{macro}
577% \end{macro}
578% \end{macro}
579%
580% \begin{macro}{\cat}
581% \begin{macro}{\compose}
582% \begin{macro}{\implies}
583% \begin{macro}{\vect}
584% \begin{macro}{\d}
585% \begin{macro}{\jacobi}
586%
587% A mixed bag of stuff.
588%
589% \begin{macrocode}
590\def\cat{\mathbin{\|}}
591\let\compose\circ
592\def\implies{\Rightarrow}
593\def\vect#1{\mathord{\mathbf{#1}}}
4a655c6f 594\def\d{%
595 \ifmmode\mathord{\operator@font d}%
596 \else\expandafter\a\expandafter d\fi%
597}
86f6a31e 598\def\jacobi#1#2{{{#1}\overwithdelims()#2}}
599% \end{macrocode}
600%
601% \end{macro}
602% \end{macro}
603% \end{macro}
604% \end{macro}
605% \end{macro}
606% \end{macro}
607%
608% \begin{macro}{\statclose}
609% \begin{macro}{\compind}
610%
611% Fancy new relations for probability distributions.
612%
613% \begin{macrocode}
614\def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
615\def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
616% \end{macrocode}
617%
618% \end{macro}
619% \end{macro}
620%
4a576d39
MW
621% \begin{macro}{\defop}
622% Defining new operator names.
623% \begin{macrocode}
624\def\defop{\@ifstar{\defop@\nolimits}{\defop@\limits}}
625\def\defop@#1#2#3{\def#2{\mathop{\operator@font #3}#1}}
626% \end{macrocode}
627% \end{macro}
628%
86f6a31e 629% \begin{macro}{\keys}
630% \begin{macro}{\dom}
631% \begin{macro}{\ran}
632% \begin{macro}{\supp}
633% \begin{macro}{\lcm}
4a655c6f 634% \begin{macro}{\poly}
635% \begin{macro}{\negl}
636% \begin{macro}{\ord}
86f6a31e 637%
638% And the new operator names.
639%
640% \begin{macrocode}
4a576d39
MW
641\defop*\keys{keys}
642\defop*\dom{dom}
643\defop*\ran{ran}
644\defop*\supp{supp}
645\defop*\lcm{lcm}
646\defop*\poly{poly}
647\defop*\negl{negl}
648\defop*\ord{ord}
86f6a31e 649% \end{macrocode}
650%
651% \end{macro}
652% \end{macro}
653% \end{macro}
654% \end{macro}
655% \end{macro}
4a655c6f 656% \end{macro}
657% \end{macro}
658% \end{macro}
659%
660% \subsection{Fractions}
661%
662% \begin{macro}{\@frac@parse}
663%
664% \syntax{"\\@frac@parse{"<stuff>"}{"<frac-params>"}"} -- run \<stuff>
665% passing it three arguments: an infix fraction-making command, the `outer'
666% style, and the `inner' style.
667%
668% This is rather tricky. We clear a load of parameters, parse the parameter
669% list, and then build a token list containing the right stuff. Without the
670% token list fiddling, we end up expanding things at the wrong times -- for
671% example, |\{| expands to something terribly unpleasant in a document
672% preamble.
673%
674% All of the nastiness is contained in a group.
675%
676% \begin{macrocode}
677\def\@frac@parse#1#2{%
678 \begingroup%
679 \let\@wd\@empty\def\@ldel{.}\def\@rdel{.}%
680 \def\@op{over}\let\@dim\@empty\@tempswafalse%
681 \let\@is\@empty\let\@os\@empty%
682 \mkparse{mdwmath:frac}{#2}%
683 \toks\tw@{\endgroup#1}%
684 \toks@\expandafter{\csname @@\@op\@wd\endcsname}%
685 \if@tempswa%
686 \toks@\expandafter{\the\expandafter\toks@\@ldel}%
687 \toks@\expandafter{\the\expandafter\toks@\@rdel}%
688 \fi%
689 \expandafter\toks@\expandafter{\the\expandafter\toks@\@dim}%
690 \toks@\expandafter{\the\toks\expandafter\tw@\expandafter{\the\toks@}}
691 \toks@\expandafter{\the\expandafter\toks@\expandafter{\@os}}
692 \toks@\expandafter{\the\expandafter\toks@\expandafter{\@is}}
693 \the\toks@%
694}
695% \end{macrocode}
696%
697% The keyword definitions are relatively straightforward now. The error
698% handling for \textsf{style} and \textsf{innerstyle} could do with
699% improvement.
700%
701% \begin{macrocode}
702\def\@frac@del#1#2{\def\@wd{withdelims}\@tempswatrue\def#1{#2}}
703\mkdef{mdwmath:frac}{leftdelim}{\@frac@del\@ldel{#1}}
704\mkdef{mdwmath:frac}{rightdelim}{\@frac@del\@rdel{#1}}
705\mkdef{mdwmath:frac}{nodelims}*{\let\@wd\@empty\@tempswafalse}
706\mkdef{mdwmath:frac}{line}{%
707 \def\@op{above}\setlength\dimen@{#1}\edef\@dim{\the\dimen@\space}%
708}
709\mkdef{mdwmath:frac}{line}*{\def\@op{over}\let\@dim\@empty}
710\mkdef{mdwmath:frac}{noline}*{\def\@op{atop}\let\@dim\@empty}
711\def\@frac@style#1#2{%
712 \ifx\q@delim#2\q@delim\let#1\@empty%
713 \else%
714 \expandafter\ifx\csname #2style\endcsname\relax%
715 \PackageError{mdwmath}{Bad maths style `#2'}\@ehc%
716 \else%
717 \edef#1{\csname#2style\endcsname}%
718 \fi%
719 \fi%
720}
721\mkdef{mdwmath:frac}{style}[]{\@frac@style\@os{#1}}
722\mkdef{mdwmath:frac}{innerstyle}[]{\@frac@style\@is{#1}}
723% \end{macrocode}
724%
725% \end{macro}
726%
727% \begin{macro}{\fracdef}
728%
729% Here's where the rest of the pain is. We do a preliminary parse of the
730% parameters and `compile' the result into the output macro. If there's no
731% optional argument, then we don't need to do any really tedious formatting
732% at the point of use.
733%
734% \begin{macrocode}
735\def\fracdef#1#2{\@frac@parse{\fracdef@i{#1}{#2}}{#2}}
736\def\fracdef@i#1#2#3#4#5{\def#1{\@frac@do{#2}{#3}{#4}{#5}}}
737\def\@frac@do#1#2#3#4{%
738 \@ifnextchar[{\@frac@complex{#1}}{\@frac@simple{#2}{#3}{#4}}%
739}
740\def\@frac@complex#1[#2]{\@frac@parse\@frac@simple{#1,#2}}
741\def\@frac@simple#1#2#3#4#5{{#2{{#3#4}#1{#3#5}}}}
742% \end{macrocode}
743%
744% \end{macro}
745%
746% \begin{macro}{\frac@fix}
747% \begin{macro}{\@@over}
748% \begin{macro}{\@@atop}
749% \begin{macro}{\@@above}
750% \begin{macro}{\@@overwithdelims}
751% \begin{macro}{\@@atopwithdelims}
752% \begin{macro}{\@@abovewithdelims}
753%
754% Finally, we need to fix up |\@@over| and friends. Maybe \package{amsmath}
755% has hidden the commands away somewhere unhelpful. If not, we make the
756% requisite copies.
757%
758% \begin{macrocode}
759\def\q@delim{\q@delim}
760\def\frac@fix#1{\expandafter\frac@fix@i\string#1\q@delim}
761\def\frac@fix@i#1#2\q@delim{\frac@fix@ii{#2}\frac@fix@ii{#2withdelims}}
762\def\frac@fix@ii#1{%
763 \expandafter\ifx\csname @@#1\endcsname\relax%
764 \expandafter\let\csname @@#1\expandafter\endcsname\csname#1\endcsname%
765 \fi%
766}
767\frac@fix\over \frac@fix\atop \frac@fix\above
768% \end{macrocode}
769%
770% \end{macro}
771% \end{macro}
772% \end{macro}
773% \end{macro}
774% \end{macro}
775% \end{macro}
776% \end{macro}
777%
778% \begin{macro}{\frac}
779% \begin{macro}{\binom}
780% \begin{macro}{\jacobi}
781%
782% And finally, we define the fraction-making commands.
783%
784% \begin{macrocode}
785\fracdef\frac{nodelims, line}
786\fracdef\binom{leftdelim = (, rightdelim = ), noline}
787\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
788% \end{macrocode}
789%
790% \end{macro}
791% \end{macro}
792% \end{macro}
86f6a31e 793%
794% \subsection{Blackboard bold stuff}
795%
796% \begin{macro}{\Z}
797% \begin{macro}{\Q}
798% \begin{macro}{\R}
799% \begin{macro}{\C}
800% \begin{macro}{\N}
801% \begin{macro}{\F}
802% \begin{macro}{\powerset}
4a655c6f 803% \begin{macro}{\gf}
86f6a31e 804%
805% First of all, the signs.
806%
807% \begin{macrocode}
808\def\Z{\mathbb{Z}}
809\def\Q{\mathbb{Q}}
810\def\R{\mathbb{R}}
811\def\C{\mathbb{C}}
812\def\N{\mathbb{N}}
813\def\F{\mathbb{F}}
814\def\powerset{\mathbb{P}}
4a655c6f 815\def\gf#1{\F_{#1}}
816%\def\gf#1{\mathrm{GF}({#1})}
86f6a31e 817% \end{macrocode}
818%
819% \end{macro}
820% \end{macro}
821% \end{macro}
822% \end{macro}
823% \end{macro}
824% \end{macro}
825% \end{macro}
4a655c6f 826% \end{macro}
86f6a31e 827%
828% And now, define |\mathbb| if it's not there already.
829%
830% \begin{macrocode}
831\AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
832% \end{macrocode}
833%
834% \subsection{Biggles}
835%
836% Now for some user-controlled delimiter sizing. The standard bigness of
837% plain \TeX's delimiters are all right, but it's a little limiting.
838%
839% The biggness of delimiters is based on the size of the current |\strut|,
840% which \LaTeX\ keeps up to date all the time. This will make the various
841% delimiters grow in proportion when the text gets bigger. Actually, I'm
842% not sure that this is exactly right -- maybe it should be nonlinear,
843%
844% \begin{macro}{\bbigg}
845% \begin{macro}{\bbiggl}
846% \begin{macro}{\bbiggr}
847% \begin{macro}{\bbiggm}
848%
849% This is where the bigness is done. This is more similar to the plain \TeX\
850% big delimiter stuff than to the \package{amsmath} stuff, although there's
851% not really a lot of difference.
852%
853% The two arguments are a multiplier for the delimiter size, and a small
854% increment applied \emph{before} the multiplication (which is optional).
855%
856% This is actually a front for a low-level interface which can be called
857% directly for efficiency.
858%
859% \begin{macrocode}
860\def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
861\def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
862% \end{macrocode}
863%
864% \end{macro}
865% \end{macro}
866% \end{macro}
867% \end{macro}
868%
869% \begin{macro}{\@bbigg}
870%
871% This is an optional argument parser providing a front end for the main
872% macro |\bbigg@|.
873%
874% \begin{macrocode}
a1af3c0e
MW
875\def\@bbigg#1{\@testopt{\@bbigg@i{#1}}\z@}
876\def\@bbigg@i#1[#2]{#1{\bbigg@{#2}}}
86f6a31e 877% \end{macrocode}
878%
879% \end{macro}
880%
881% \begin{macro}{\bbigg@}
882%
883% This is it, at last. The arguments are as described above: an addition
884% to be made to the strut height, and a multiplier. Oh, and the delimiter,
885% of course.
886%
887% This is a bit messy. The smallest `big' delimiter, |\big|, is the same
888% height as the current strut box. Other delimiters are~$1\frac12$, $2$
889% and~$2\frac12$ times this height. I'll set the height of the delimiter by
890% putting in a |\vcenter| of the appropriate size.
891%
892% Given an extra height~$x$, a multiplication factor~$f$ and a strut
893% height~$h$ and depth~$d$, I'll create a vcenter with total height
894% $f(h+d+x)$. Easy, isn't it?
895%
896% \begin{macrocode}
897\def\bbigg@#1#2#3{%
898 {\hbox{$%
899 \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
900 \advance\dimen@#1%
901 \dimen@#2\dimen@%
902 \left#3\vcenter to\dimen@{}\right.\n@space%
903 $}}%
904}
905% \end{macrocode}
906%
907% \end{macro}
908%
909% \begin{macro}{\big}
910% \begin{macro}{\Big}
911% \begin{macro}{\bigg}
912% \begin{macro}{\Bigg}
913%
914% Now for the easy macros.
915%
916% \begin{macrocode}
917\def\big{\bbigg@\z@\@ne}
918\def\Big{\bbigg@\z@{1.5}}
919\def\bigg{\bbigg@\z@\tw@}
920\def\Bigg{\bbigg@\z@{2.5}}
921% \end{macrocode}
922%
923% \end{macro}
924% \end{macro}
925% \end{macro}
926% \end{macro}
927%
928% \subsection{The `QED' symbol}
929%
930% \begin{macro}{\qed}
931% \begin{macro}{\qedrule}
932% \begin{macro}{\qedsymbol}
933%
934% This is fairly simple. Just be careful will the glue and penalties. The
935% size of the little box is based on the current font size.
936%
937% The horizontal list constructed by the macro is like this:
938%
939% \begin{itemize}
940% \item A |\quad| of space. This might get eaten if there's a break here or
941% before. That's OK, though.
942% \item An empty box, to break a run of discardable items.
943% \item A |\penalty 10000| to ensure that the spacing glue isn't discarded.
944% \item |\hfill| glue to push the little rule to the end of the line.
945% \item A little square rule `\qedrule', with some small kerns around it.
946% \item A glue item to counter the effect of glue added at the paragraph
e8e9e5d8 947% boundary.
86f6a31e 948% \end{itemize}
949%
4a655c6f 950% The vertical mode case is simpler, but less universal. It copes with
951% relatively simple cases only.
952%
86f6a31e 953% A |\qed| commend ends the paragraph.
954%
955% \begin{macrocode}
4a655c6f 956\def\qed{%
957 \ifvmode%
958 \unskip%
959 \setbox\z@\hb@xt@\linewidth{\hfil\strut\qedsymbol}%
960 \prevdepth-\@m\p@%
961 \ifdim\prevdepth>\dp\strutbox%
962 \dimen@\prevdepth\advance\dimen@-\dp\strutbox%
963 \kern-\dimen@%
964 \fi%
965 \penalty\@M\vskip-\baselineskip\box\z@%
966 \else%
967 \unskip%
968 \penalty\@M\hfill%
969 \hbox{}\penalty200\quad%
970 \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
971 \fi%
86f6a31e 972}
973\def\qedrule{{%
974 \dimen@\ht\strutbox%
4a655c6f 975 \advance\dimen@\dp\strutbox%
86f6a31e 976 \dimen@ii1ex%
977 \advance\dimen@-\dimen@ii%
978 \divide\dimen@\tw@%
979 \advance\dimen@-\dp\strutbox%
980 \advance\dimen@\dimen@ii%
981 \advance\dimen@ii-\dimen@%
982 \kern\p@%
983 \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
984 \kern\p@%
985}}
986\providecommand\qedsymbol{\qedrule}
987% \end{macrocode}
988%
989% \end{macro}
990% \end{macro}
991% \end{macro}
992%
3ba7380e
MW
993% \subsection{Punctuation in displays}
994%
995% \begin{macro}{\mpunct}
996%
997% This is actually a little more subtle than you'd expect. If the
998% \package{amstext} package is loaded, or something else has defined the
999% |\text| command, then we should use that; otherwise, just drop a box in and
1000% hope for the best.
1001%
1002% \begin{macrocode}
1003\def\mpunct#1{%
1004 \,%
1005 \ifx\text\@@undefined\hbox%
1006 \else\expandafter\text\fi%
1007 {#1}%
1008}
1009% \end{macrocode}
1010%
1011%\end{macro}
1012%
86f6a31e 1013% That's all there is. Byebye.
1014%
1015% \begin{macrocode}
1016%</package>
1017% \end{macrocode}
1018%
1019% \hfill Mark Wooding, \today
1020%
1021% \Finale
1022\endinput