1 % \begin{meta-comment} <general public licence>
3 %% mdwmath package -- various nicer mathematical things
4 %% Copyright (c) 2003, 2020 Mark Wooding
6 %% This file is part of the `mdwtools' LaTeX package collection.
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.
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.
18 %% You should have received a copy of the GNU General Public License
19 %% along with `mdwtools'. If not, write to the Free Software Foundation,
20 %% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 % \begin{meta-comment} <Package preamble>
25 %<+package>\NeedsTeXFormat{LaTeX2e}
26 %<+package>\ProvidesPackage{mdwmath}
27 %<+package> [2020/09/06 1.14.0 Nice mathematical things]
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 \~}
48 % \begin{meta-comment}
54 \describespackage{mdwmath}
60 % \section{User guide}
62 % \subsection{Square root typesetting}
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.
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} \]
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.]
87 % \subsection{Modular arithmetic}
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.
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
99 % \subsection{Some maths symbols you already have}
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}
108 % $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\
109 % $\bitand$ & "\bitand" & $\dblor$ & "\dblor" &
110 % \end{tabular} \end{center}
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.
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.
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}$'.
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.
140 % \subsection{Fractions}
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
148 % \begin{description}
149 % \item[\lit*{line}] Include a horizontal line between the top and bottom
151 % \item[\lit*{line=}\<length>] Include a horizontal line with width
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
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.
170 % \DescribeMacro\frac
171 % \DescribeMacro\binom
172 % \DescribeMacro\jacobi
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
178 % By way of example, these commands were defined using
180 %\fracdef\frac{nodelims, line}
181 %\fracdef\binom{leftdelim = (, rightdelim = ), noline}
182 %\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
185 % \subsection{Rant about derivatives}
188 % There is a difference between UK and US typesetting of derivatives.
190 % \[ \frac{dy}{dx} \]
191 % while the British want
192 % \[ \frac{\d y}{\d x}. \]
193 % The command |\d| command is fixed to typeset a `$\d$'. (In text mode,
194 % |\d{x}| still typesets `\d{x}'.)
196 % \subsection{New operator names}
198 % \DescribeMacro\keys
201 % \DescribeMacro\supp
204 % \DescribeMacro\poly
205 % \DescribeMacro\negl
206 % A few esoteric new operator names are supplied.
207 % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
208 % $\keys$ & "\keys" & $\dom$ & "\dom" & $\ran$ & "\ran" \\
209 % $\supp$ & "\supp" & $\lcm$ & "\lcm" & $\ord$ & "\ord" \\
210 % $\poly$ & "\poly" & $\negl$ & "\negl"
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
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$.
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.
232 % \subsection{Standard set names}
240 % \DescribeMacro\powerset
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|
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.
252 % \subsection{Biggles}
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.
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)$.
270 % The old |\big| commands have been redefined in terms of |\bbigg|.
272 % \subsection{Defining bracketty notations}
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|
281 % \syntax{"\\defbrk{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
282 % "["<rinner>"]{"<rbrk>"}["<router>"]"}
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.
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.
300 % You also get a number of extra commands:
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.
311 % \begin{demo}{Custom bracket notation}
313 %\defbrk\floor{\lfloor}{\rfloor}
315 %Let $S = \set{1, 2, 3}$.
318 %\[ \mu = \biggfloor{\frac{B^{2n}}{m}}
320 %Show that $\bigfloor{\floor{a/b}/c} =
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|:
329 % \syntax{"\\defbrk*{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
330 % "["<mbefore>"]{"<mid>"}["<mafter>"]"^^A
331 % "["<rinner>"]{"<rbrk>"}["<router>"]"}
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>.
337 % \begin{demo}{More custom bracket notation}
338 %\defbrk*\setcomp{\{}[\,]\vert[][\,]{\}}
340 %Consider the coset $x + H =
341 %\setcomp{x + h}{h \in H}$.
345 % \subsection{The `QED' symbol}
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.
355 % \subsection{Punctuation in displays}
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
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.
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
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.
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.
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.
394 % \section{Implementation}
396 % This isn't really complicated (honest) although it is a lot hairier than I
397 % think it ought to be.
401 \RequirePackage{amssymb}
402 \RequirePackage{mdwkey}
405 % \subsection{Square roots}
407 % \subsubsection{Where is the square root sign?}
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.
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}
420 % \subsubsection{Drawing fake square root signs}
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
426 % \begin{macro}{\sqrtdel}
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.
435 % We start off by using |\mathpalette| to help decide how big things should
439 \def\sqrtdel{\mathpalette\sqrtdel@i}
442 % Read the contents of the radical into a box, so we can measure it.
446 \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
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$.
461 % That was easy. Now for $\psi$.
465 \advance\@tempdimb.25\@tempdima%
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.
473 \advance\dimen@\@tempdimb%
474 \advance\dimen@\ht\z@%
475 \advance\dimen@\dp\z@%
477 $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
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
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%
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.
501 \advance\@tempdima\@tempdimb%
502 \advance\@tempdima-\ht\tw@%
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.
509 {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
515 % \subsubsection{The new square root command}
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.
523 % \begin{macro}{\sqrt}
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.
530 \DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
533 % Now we can sort out an optional argument to be displayed on the root.
536 \def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
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.
548 \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
549 \ifdim\wd\rootbox<6\p@%
550 \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
552 \mathpalette{\sqrt@iii{#1}}%
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.
560 \def\sqrt@iii#1#2#3{%
561 \setbox\z@\hbox{$\m@th#2#1{#3}$}%
563 \advance\dimen@-\dp\z@%
565 \advance\dimen@\dp\rootbox%
567 \raise\dimen@\copy\rootbox%
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
578 \def\sqrt@iv#1#2{#1{#2}}
583 % \begin{macro}{\root}
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.
589 \def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
590 \def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
595 % \subsection{Modular programming}
597 % \begin{macro}{\pmod}
599 % Do some hacking if not |\ifouter|.
603 \ifinner\;\else\allowbreak\mkern18mu\fi%
604 ({\operator@font mod}\,\,#1)%
610 % \subsection{Some magic new maths characters}
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}
622 % The new boolean operators.
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}}
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}}
653 % \begin{macro}{\cat}
654 % \begin{macro}{\compose}
655 % \begin{macro}{\implies}
656 % \begin{macro}{\vect}
658 % \begin{macro}{\jacobi}
660 % A mixed bag of stuff.
663 \def\cat{\mathbin{\|}}
665 \def\implies{\Rightarrow}
666 \def\vect#1{\mathord{\mathbf{#1}}}
668 \ifmmode\mathord{\operator@font d}%
669 \else\expandafter\a\expandafter d\fi%
671 \def\jacobi#1#2{{{#1}\overwithdelims()#2}}
681 % \begin{macro}{\statclose}
682 % \begin{macro}{\compind}
684 % Fancy new relations for probability distributions.
687 \def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
688 \def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
694 % \begin{macro}{\defop}
695 % Defining new operator names.
697 \def\defop{\@ifstar{\defop@\nolimits}{\defop@\limits}}
698 \def\defop@#1#2#3{\def#2{\mathop{\operator@font #3}#1}}
702 % \begin{macro}{\keys}
703 % \begin{macro}{\dom}
704 % \begin{macro}{\ran}
705 % \begin{macro}{\supp}
706 % \begin{macro}{\lcm}
707 % \begin{macro}{\poly}
708 % \begin{macro}{\negl}
709 % \begin{macro}{\ord}
711 % And the new operator names.
733 % \subsection{Fractions}
735 % \begin{macro}{\@frac@parse}
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.
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
747 % All of the nastiness is contained in a group.
750 \def\@frac@parse#1#2{%
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}%
759 \toks@\expandafter{\the\expandafter\toks@\@ldel}%
760 \toks@\expandafter{\the\expandafter\toks@\@rdel}%
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}}
770 % The keyword definitions are relatively straightforward now. The error
771 % handling for \textsf{style} and \textsf{innerstyle} could do with
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}%
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%
787 \expandafter\ifx\csname #2style\endcsname\relax%
788 \PackageError{mdwmath}{Bad maths style `#2'}\@ehc%
790 \edef#1{\csname#2style\endcsname}%
794 \mkdef{mdwmath:frac}{style}[]{\@frac@style\@os{#1}}
795 \mkdef{mdwmath:frac}{innerstyle}[]{\@frac@style\@is{#1}}
800 % \begin{macro}{\fracdef}
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.
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}}%
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}}}}
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}
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
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}}
836 \expandafter\ifx\csname @@#1\endcsname\relax%
837 \expandafter\let\csname @@#1\expandafter\endcsname\csname#1\endcsname%
840 \frac@fix\over \frac@fix\atop \frac@fix\above
851 % \begin{macro}{\frac}
852 % \begin{macro}{\binom}
853 % \begin{macro}{\jacobi}
855 % And finally, we define the fraction-making commands.
858 \fracdef\frac{nodelims, line}
859 \fracdef\binom{leftdelim = (, rightdelim = ), noline}
860 \fracdef\jacobi{leftdelim = (, rightdelim = ), line}
867 % \subsection{Blackboard bold stuff}
875 % \begin{macro}{\powerset}
878 % First of all, the signs.
887 \def\powerset{\mathbb{P}}
889 %\def\gf#1{\mathrm{GF}({#1})}
901 % And now, define |\mathbb| if it's not there already.
904 \AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
907 % \subsection{Biggles}
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.
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,
917 % \begin{macro}{\bbigg}
918 % \begin{macro}{\bbiggl}
919 % \begin{macro}{\bbiggr}
920 % \begin{macro}{\bbiggm}
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.
926 % The two arguments are a multiplier for the delimiter size, and a small
927 % increment applied \emph{before} the multiplication (which is optional).
929 % This is actually a front for a low-level interface which can be called
930 % directly for efficiency.
933 \def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
934 \def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
942 % \begin{macro}{\@bbigg}
944 % This is an optional argument parser providing a front end for the main
948 \def\@bbigg#1{\@testopt{\@bbigg@i{#1}}\z@}
949 \def\@bbigg@i#1[#2]{#1{\bbigg@{#2}}}
954 % \begin{macro}{\bbigg@}
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,
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.
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?
972 \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
975 \left#3\vcenter to\dimen@{}\right.\n@space%
982 % \begin{macro}{\big}
983 % \begin{macro}{\Big}
984 % \begin{macro}{\bigg}
985 % \begin{macro}{\Bigg}
987 % Now for the easy macros.
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}}
1001 % \subsection{Bracketty notation}
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.
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.
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}
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.
1029 \def\brk@bbigg#1{\@testopt{\brk@bbigg@{#1}}\z@}
1030 \def\brk@bbigg@#1[#2]#3{#1{#2}}
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.
1040 \def\brk@lefttwo#1#2#3{#2{#1}}
1041 \def\brk@righttwo#1#2#3{#3{#1}}
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
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}}}}
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
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}
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.
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{}}}%
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}}}%
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
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}}}
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.
1147 \def\@csname#1#2{\expandafter\@csname@\string#2 \relax#1}
1148 \begingroup \lccode`\|=`\\
1149 \lowercase{\endgroup \def\@csname@|#1 \relax#2{#2{#1}}}
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.
1157 \def\defbrk@delim#1{\@testopt{\defbrk@delim@i{#1}}{}}
1158 \def\defbrk@delim@i#1[#2]#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}}{}}%
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}%
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}%
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}%
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}%
1202 % \subsection{The `QED' symbol}
1204 % \begin{macro}{\qed}
1205 % \begin{macro}{\qedrule}
1206 % \begin{macro}{\qedsymbol}
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.
1211 % The horizontal list constructed by the macro is like this:
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
1224 % The vertical mode case is simpler, but less universal. It copes with
1225 % relatively simple cases only.
1227 % A |\qed| commend ends the paragraph.
1233 \setbox\z@\hb@xt@\linewidth{\hfil\strut\qedsymbol}%
1235 \ifdim\prevdepth>\dp\strutbox%
1236 \dimen@\prevdepth\advance\dimen@-\dp\strutbox%
1239 \penalty\@M\vskip-\baselineskip\box\z@%
1243 \hbox{}\penalty200\quad%
1244 \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
1248 \dimen@\ht\strutbox%
1249 \advance\dimen@\dp\strutbox%
1251 \advance\dimen@-\dimen@ii%
1253 \advance\dimen@-\dp\strutbox%
1254 \advance\dimen@\dimen@ii%
1255 \advance\dimen@ii-\dimen@%
1257 \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
1260 \providecommand\qedsymbol{\qedrule}
1267 % \subsection{Punctuation in displays}
1269 % \begin{macro}{\mpunct}
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.
1279 \ifx\text\@@undefined\hbox%
1280 \else\expandafter\text\fi%
1287 % That's all there is. Byebye.
1293 % \hfill Mark Wooding, \today