% \begin{meta-comment} <general public licence>
%%
%% mdwmath package -- various nicer mathematical things
%% Copyright (c) 2003, 2020 Mark Wooding
%%
%% This file is part of the `mdwtools' LaTeX package collection.
%%
%% `mdwtools' is free software: you can redistribute it and/or modify it
%% under the terms of the GNU General Public License as published by the
%% Free Software Foundation; either version 2 of the License, or (at your
%% option) any later version.
%%
%% `mdwtools' is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%% General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with `mdwtools'.  If not, write to the Free Software Foundation,
%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
%%
% \end{meta-comment}
%
% \begin{meta-comment} <Package preamble>
%<+package>\NeedsTeXFormat{LaTeX2e}
%<+package>\ProvidesPackage{mdwmath}
%<+package>                [2020/09/06 1.14.0 Nice mathematical things]
% \end{meta-comment}
%
% \CheckSum{980}
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%
% \begin{meta-comment}
%
%<*driver>
\input{mdwtools}
\let\opmod\pmod
\usepackage{amssymb}
\describespackage{mdwmath}
\mdwdoc
%</driver>
%
% \end{meta-comment}
%
% \section{User guide}
%
% \subsection{Square root typesetting}
%
% \DescribeMacro{\sqrt}
% The package supplies a star variant of the |\sqrt| command which omits the
% vinculum over the operand (the line over the top).  While this is most
% useful in simple cases like $\sqrt*{2}$ it works for any size of operand.
% The package also re-implements the standard square root command so that it
% positions the root number rather better.
%
% \begin{figure}
% \begin{demo}[w]{Examples of the new square root command}
%\[ \sqrt*{2} \quad \mbox{rather than} \quad \sqrt{2} \]
%\[ \sqrt*[3]{2} \quad \mbox{ rather than } \quad \sqrt[3]{2} \]
%\[ \sqrt{x^3 + \sqrt*[y]{\alpha}} - \sqrt*[n+1]{a} \]
%\[ x = \sqrt*[3]{\frac{3y}{7}} \]
%\[ q = \frac{2\sqrt*{2}}{5}+\sqrt[\frac{n+1}{2}]{2x^2+3xy-y^2} \]
% \end{demo}
% \end{figure}
%
% [Note that omission of the vinculum was originally a cost-cutting exercise
% because the radical symbol can just fit in next to its operand and
% everything ends up being laid out along a line.  However, I find that the
% square root without vinculum is less cluttered, so I tend to use it when
% it doesn't cause ambiguity.]
%
% \subsection{Modular arithmetic}
%
% In standard maths mode, there's too much space before the parentheses in
% the output of the |\pmod| command.  Suppose that $x \equiv y^2 \opmod n$:
% then the spacing looks awful.  Go on, admit it.
%
% It looks OK in a display.  For example, if
% \[ c \equiv m^e \opmod n \]
% then it's fine.  The package redefines the |\pmod| command to do something
% more sensible.  So now $c^d \equiv m^{ed} \equiv m \pmod n$ and all looks
% fine.
%
% \subsection{Some maths symbols you already have}
%
% \DescribeMacro\bitor
% \DescribeMacro\bitand
% \DescribeMacro\dblor
% \DescribeMacro\dbland
% Having just tried to do some simple things, I've found that there are maths
% symbols missing.  Here they are, in all their glory:
% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
% $\&$ & "\&"           & $\bitor$ & "\bitor"   & $\dbland$ & "\dbland" \\
% $\bitand$ & "\bitand" & $\dblor$ & "\dblor"   &
% \end{tabular} \end{center}
%
% \DescribeMacro\xor
% \DescribeMacro\cat
% I also set up the |\xor| command to typeset `$\xor$', which is commonly
% used to represent the bitsize exclusive-or operation among cryptographers.
% The command |\cat| typesets `$\cat$', which is a common operator indicating
% concatenation of strings.
%
% \DescribeMacro\lsl
% \DescribeMacro\lsr
% \DescribeMacro\rol
% \DescribeMacro\ror
% The commands |\lsl| and |\lsr| typeset binary operators `$\lsl$' and
% `$\lsr$' respectively, and |\rol| and |\ror| typeset `$\rol$' and `$\ror$'.
% Note that these are spaced as binary operators, rather than relations.
%
% \DescribeMacro\compose
% \DescribeMacro\implies
% \DescribeMacro\vect
% The |\compose| command typesets `$\compose$', which is usually used to
% denote function composition.  The |\implies| command is made to typeset
% `$\implies$'.  And \syntax{"\\vect{"<x>"}"} typesets `$\vect{x}$'.
%
% \DescribeMacro\statclose
% \DescribeMacro\compind
% The |\statclose| command typesets `$\statclose$', which indicates
% `statistical closeness' of probability distributions; |\compind| typesets
% `$\compind$', which indicates computational indistinguishability.
%
% \subsection{Fractions}
%
% \DescribeMacro\fracdef
% We provide a general fraction system, a little tiny bit like
% \package{amsmath}'s |\genfrac|.  Say
% \syntax{"\\fracdef{"<name>"}{"<frac-params>"}"} to define a new
% |\frac|-like operator.  The \<frac-params> are a comma-separated list of
% parameters:
% \begin{description}
% \item[\lit*{line}] Include a horizontal line between the top and bottom
%   (like |\frac|).
% \item[\lit*{line=}\<length>] Include a horizontal line with width
%   \<length>.
% \item[\lit*{noline}] Don't include a line (like |\binom|).
% \item[\lit*{leftdelim=}\<delim>] Use \<delim> as the left-hand delimiter.
% \item[\lit*{rightdelim=}\<delim>] Use \<delim> as the right-hand delimiter.
% \item[\lit*{nodelims}] Don't include delimiters.
% \item[\lit*{style=}\<style>] Typeset the fraction in \<style>, which is one
%   of |display|, |text|, |script| or |scriptscript|.
% \item[\lit*{style}] Use the prevailing style for the fraction.
% \item[\lit*{innerstyle=}\<style>] Typeset the \emph{components} of the
%   fraction in \<style>.
% \item[\lit*{innerstyle}] Typeset the fraction components according to the
%   prevailing style.
% \end{description}
% The commands created by |\fracdef| have the following syntax:
% \syntax{<name>"["<frac-params>"]{"<top>"}{"<bottom>"}"}.  Thus, you can use
% the optional argument to `tweak' the fraction if necessary.  This isn't
% such a good idea to do often.
%
% \DescribeMacro\frac
% \DescribeMacro\binom
% \DescribeMacro\jacobi
% The macros |\frac|, |\binom| and |\jacobi| are defined using |\fracdef|.
% They typset $\frac{x}{y}$, $\binom{n}{k}$ and $\jacobi{x}{n}$ respectively.
% (The last may be of use to number theorists talking about Jacobi or
% Lagrange symbols.)
%
% By way of example, these commands were defined using
%\begin{verbatim}
%\fracdef\frac{nodelims, line}
%\fracdef\binom{leftdelim = (, rightdelim = ), noline}
%\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
%\end{verbatim}
%
% \subsection{Rant about derivatives}
%
% \DescribeMacro\d
% There is a difference between UK and US typesetting of derivatives.
% Americans typeset
% \[ \frac{dy}{dx} \]
% while the British want
% \[ \frac{\d y}{\d x}. \]
% The command |\d| command is fixed to typeset a `$\d$'.  (In text mode,
% |\d{x}| still typesets `\d{x}'.)
%
% \subsection{New operator names}
%
% \DescribeMacro\keys
% \DescribeMacro\dom
% \DescribeMacro\ran
% \DescribeMacro\supp
% \DescribeMacro\lcm
% \DescribeMacro\ord
% \DescribeMacro\poly
% \DescribeMacro\negl
% A few esoteric new operator names are supplied.
% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
% $\keys$ & "\keys"     & $\dom$ & "\dom"       & $\ran$ & "\ran" \\
% $\supp$ & "\supp"     & $\lcm$ & "\lcm"       & $\ord$ & "\ord" \\
% $\poly$ & "\poly"     & $\negl$ & "\negl"
% \end{tabular} \end{center}
% I think |\lcm| ought to be self-explanatory.  The |\dom| and |\ran|
% operators pick out the domain and range of a function, respectively; thus,
% if $F\colon X \to Y$ is a function, then $\dom F = X$ and $\ran F = Y$.
% The \emph{support} of a probability distribution $\mathcal{D}$ is the set
% of objects with nonzero probability; i.e., $\supp{D} = \{\, x \in
% \dom\mathcal{D} \mid \mathcal{D}(x) > 0 \,\}$.  If $g \in G$ is a group
% element then $\ord g$ is the \emph{order} of $g$; i.e., the smallest
% positive integer $i$ where $g^i$ is the identity element, or $0$ if there
% is no such $i$.  $\poly(n)$ is some polynomial function of $n$.  A function
% $\nu(\cdot)$ is \emph{negligible} if, for every polynomial function
% $p(\cdot)$, there is an integer $N$ such that $\nu(n) < 1/p(n)$ for all $n
% > N$; $\negl(n)$ is some negligible function of $n$.
%
% \DescribeMacro\defop
% New operators can be defined using |\defop|:
% \begin{quote} \syntax{"\\defop"["*"]"{"<command>"}{"<text>"}"} \end{quote}
% defines \<command> to be an operator which typesets \<text>.  By default,
% limits will be placed above and below the operator in display style; with
% |*|, limits are always written as super- and subscripts.
%
% \subsection{Standard set names}
%
% \DescribeMacro\Z
% \DescribeMacro\Q
% \DescribeMacro\R
% \DescribeMacro\C
% \DescribeMacro\N
% \DescribeMacro\F
% \DescribeMacro\powerset
% \DescribeMacro\gf
% If you have a |\mathbb| command defined, the following magic is revealed:
% \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
% $\Z$ & "\Z" & $\Q$ & "\Q" & $\R$ & "\R" \\
% $\N$ & "\N" & $\F$ & "\F" & $\C$ & "\C"
% \end{tabular} \end{center}
% which are handy for various standard sets of things.  Also the |\powerset|
% command typesets `$\powerset$', and \syntax{"\\gf{"<q>"}"}, which by default
% typesets $\gf{\syntax{<q>}}$ but you might choose to have it set
% $\mathrm{GF}(\syntax{<q>})$ intead.
%
% \subsection{Biggles}
%
% \DescribeMacro\bbigg
% \DescribeMacro\bbiggl
% \DescribeMacro\bbiggr
% \DescribeMacro\bbiggm
% The |\bbigg| commands generalizes the Plain \TeX\ |\bigg| family of
% macros.  |\bbigg| produces an `ordinary' symbol; |\bbiggl| and |\bbiggr|
% produce left and right delimiters; and |\bbiggm| produces a relation.  They
% produce symbols whose size is related to the prevailing text size -- so
% they adjust correctly in chapter headings, for example.
%
% The syntax is straightforward:
% \syntax{"\\"<bigop>"["$a$"]{"$n$"}{"<delim>"}"}.  Describing it is a bit
% trickier.  The size is based on the current |\strut| height.  If |\strut|
% has a height of $h$ and a depth of $d$, then the delimiter produced has a
% height of $n \times (h + d + a)$.
%
% The old |\big| commands have been redefined in terms of |\bbigg|.
%
% \subsection{Defining bracketty notations}
%
% \DescribeMacro\defbrk
% Many mathematical notations involve wrapping brackets of various kinds
% around expressions.  \LaTeX\ doesn't provide much help in defining commands
% for these notations, which is a shame because it's a good idea to keep the
% markup semantic rather than visual.  I hereby present the |\defbrk|
% command:
% \begin{quote}
% \syntax{"\\defbrk{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
%                              "["<rinner>"]{"<rbrk>"}["<router>"]"}
% \end{quote}
% The syntax looks intimidating, but it's quite easy really.  The \<command>
% should be a command name, with a leading |\|.  The \<lbrk> and \<rbrk>
% arguments, which are the only other mandatory arguments, are the brackets;
% they should be something that can appear after |\left| and |\right|.  The
% optional arguments are just extra stuff, commonly spacing, which can appear
% around the brackets.
%
% The main command |\|\<foo> is invoked as
% \syntax{"\\"<foo>"["<left>"]["<right>"]{"<filling>"}"}.  Slightly
% unusually, the optional \<left> and \<right> arguments must be either both
% missing or both provided.  They're the sizes to be applied to the brackets,
% so they can be something like |\biggl| and |\biggr|, or |\left| and
% |\right|; they default to empty, so you get the ordinary text-sized
% brackets if you don't do anything special.  The \<filling> is just the
% stuff to go in-between the brackets.
%
% You also get a number of extra commands:
% \begin{itemize}
% \item |\auto|\<foo> uses automatically-resizing brackets, as if you'd asked
%   for |\left| and |\right|;
% \item |\big|\<foo>, |\Big|\<foo>, |\bigg|\<foo>, and |\Bigg|\<foo> use the
%   corresponding standard sizes of brackets; and
% \item \syntax{"\\bbigg"<foo>"["$a$"]{"$n$"}"} uses the `bbigg' machinery
%   described above for custom bracket sizes.
% \end{itemize}
%
% \begin{figure}
% \begin{demo}{Custom bracket notation}
%\defbrk\set{\{}{\}}
%\defbrk\floor{\lfloor}{\rfloor}
%
%Let $S = \set{1, 2, 3}$.
%
%Let
%\[ \mu = \biggfloor{\frac{B^{2n}}{m}}
%   \mpunct. \]
%Show that $\bigfloor{\floor{a/b}/c} =
%\floor{a/b c}$.
% \end{demo}
% \end{figure}
%
% But wait!  There's more!  Some notation comes in two pieces with a
% separator in the middle.  For these, there's an even more complicated |*|
% version of |\defbrk|:
% \begin{quote}
% \syntax{"\\defbrk*{"<command>"}["<louter>"]{"<lbrk>"}["<linner>"]"^^A
%                               "["<mbefore>"]{"<mid>"}["<mafter>"]"^^A
%                               "["<rinner>"]{"<rbrk>"}["<router>"]"}
% \end{quote}
% This defines \<command> as before, but now it takes two arguments, to be
% surrounded by the \<lbrk> and \<rbrk> brackets and separated by \<mid>.
%
% \begin{figure}
% \begin{demo}{More custom bracket notation}
%\defbrk*\setcomp{\{}[\,]\vert[][\,]{\}}
%
%Consider the coset $x + H =
%\setcomp{x + h}{h \in H}$.
% \end{demo}
% \end{figure}
%
% \subsection{The `QED' symbol}
%
% \DescribeMacro\qed
% \DescribeMacro\qedrule
% For use in proofs of theorems, we provide a `QED' symbol which behaves well
% under bizarre line-splitting conditions.  To use it, just say |\qed|.  The
% little `\qedrule' symbol is available on its own, by saying |\qedrule|.
% This also sets |\qedsymbol| if it's not set already.
% \qed
%
% \subsection{Punctuation in displays}
%
% It's conventional to follow displayed equations with the necessary
% punctuation for them to fit into the surrounding prose.  This isn't
% universal: Ian Stewart says in the preface to the third edition of his
% \emph{Galois Theory}:\footnote{^^A
%   Chapman \& Hall/CRC Mathematics, 2004; ISBN 1-58488-393-6.} ^^A
% \begin{quote}
%   Along the way I made once change that may raise a few eyebrows.  I have
%   spent much of my career telling students that written mathematics should
%   have punctuation as well as symbols.  If a symbol or a formula would be
%   followed by a comma if it were replaced by a word or phrase, then it
%   should be followed by a comma; however strange the formula then looks.
%
%   I still think that punctuation is essential for formulas in the main body
%   of the text.  If the formula is $t^2 + 1$, say, then it should have its
%   terminating comma.  But I have come to the conclusion that eliminating
%   visual junk from the printed page is more important than punctuatory
%   pedantry, so that when the same formula is \emph{displayed}, for example
%   \[ t^2 + 1 \]
%   then it looks silly if the comma is included, like this,
%   \[ t^2 + 1 \mpunct{,} \]
%   and everything is much cleaner and less ambiguous without punctuation.
%
%   Purists will hate this, though many of them would not have noticed had I
%   not pointed it out here.  Until recently, I would have agreed.  But I
%   think it is time we accepted that the act of displaying a formula equips
%   it with \emph{implicit} (invisible) punctuation.  This is the 21st
%   century, and typography has moved on.
% \end{quote}%
%
% \DescribeMacro\mpunct
% I tended to agree with Prof.\ Stewart, even before I read his preface; but
% now I'm not so sure, and it's clear that we're in the minority.  Therefore,
% the command |\mpunct| sets its argument as text, a little distance from
% the preceding mathematics.
%
% \implementation
%
% \section{Implementation}
%
% This isn't really complicated (honest) although it is a lot hairier than I
% think it ought to be.
%
%    \begin{macrocode}
%<*package>
\RequirePackage{amssymb}
\RequirePackage{mdwkey}
%    \end{macrocode}
%
% \subsection{Square roots}
%
% \subsubsection{Where is the square root sign?}
%
% \LaTeX\ hides the square root sign away somewhere without telling anyone
% where it is.  I extract it forcibly by peeking inside the |\sqrtsign| macro
% and scrutinising the contents.  Here we go: prepare for yukkiness.
%
%    \begin{macrocode}
\newcount\sq@sqrt \begingroup \catcode`\|0 \catcode`\\12
|def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax}
|expandafter|sq@readrad|meaning|sqrtsign|relax |endgroup
\def\sq@delim{\delimiter\sq@sqrt\relax}
%    \end{macrocode}
%
% \subsubsection{Drawing fake square root signs}
%
% \TeX\ absolutely insists on drawing square root signs with a vinculum over
% the top.  In order to get the same effect, we have to attempt to emulate
% \TeX's behaviour.
%
% \begin{macro}{\sqrtdel}
%
% This does the main job of typesetting a vinculum-free radical.\footnote{^^A
%   Note for chemists: this is nothing to do with short-lived things which
%   don't have their normal numbers of electrons.  And it won't reduce the
%   appearance of wrinkles either.}
% It's more or less a duplicate of what \TeX\ does internally, so it might be
% a good plan to have a copy of Appendix~G open while you examine this.
%
% We start off by using |\mathpalette| to help decide how big things should
% be.
%
%    \begin{macrocode}
\def\sqrtdel{\mathpalette\sqrtdel@i}
%    \end{macrocode}
%
% Read the contents of the radical into a box, so we can measure it.
%
%    \begin{macrocode}
\def\sqrtdel@i#1#2{%
  \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
%    \end{macrocode}
%
% Now try and sort out the values needed in this calculation.  We'll assume
% that $\xi_8$ is 0.6\,pt, the way it usually is.  Next try to work out the
% value of $\varphi$.
%
%    \begin{macrocode}
  \ifx#1\displaystyle%
    \@tempdima1ex%
  \else%
    \@tempdima.6\p@%
  \fi%
%    \end{macrocode}
%
% That was easy.  Now for $\psi$.
%
%    \begin{macrocode}
  \@tempdimb.6\p@%
  \advance\@tempdimb.25\@tempdima%
%    \end{macrocode}
%
% Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as
% requested.  Box~2 will do well for this purpose.
%
%    \begin{macrocode}
  \dimen@.6\p@%
  \advance\dimen@\@tempdimb%
  \advance\dimen@\ht\z@%
  \advance\dimen@\dp\z@%
  \setbox\tw@\hbox{%
    $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
  }%
%    \end{macrocode}
%
% Now we need to do some more calculating (don't you hate it?).  As far as
% Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the
% top.
%
%    \begin{macrocode}
  \@tempdima\ht\tw@%
  \advance\@tempdima\dp\tw@%
  \advance\@tempdima-\ht\z@%
  \advance\@tempdima-\dp\z@%
  \ifdim\@tempdima>\@tempdimb%
    \advance\@tempdima\@tempdimb%
    \@tempdimb.5\@tempdima%
  \fi%
%    \end{macrocode}
%
% Work out how high to raise the radical symbol.  Remember that Appendix~G
% thinks that the box has a very small height, although this is untrue here.
%
%    \begin{macrocode}
  \@tempdima\ht\z@%
  \advance\@tempdima\@tempdimb%
  \advance\@tempdima-\ht\tw@%
%    \end{macrocode}
%
% Build the output (finally).  The brace group is there to turn the output
% into a mathord, one of the few times that this is actually desirable.
%
%    \begin{macrocode}
  {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
}
%    \end{macrocode}
%
% \end{macro}
%
% \subsubsection{The new square root command}
%
% This is where we reimplement all the square root stuff.  Most of this stuff
% comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\
% and \LaTeXe, and some is original.  I've tried to make the spacing vaguely
% automatic, so although it's not configurable like \AmSTeX's version, the
% output should look nice more of the time.  Maybe.
%
% \begin{macro}{\sqrt}
%
% \LaTeX\ says this must be robust, so we make it robust.  The first thing to
% do is to see if there's a star and pass the appropriate squareroot-drawing
% command on to the rest of the code.
%
%    \begin{macrocode}
\DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
%    \end{macrocode}
%
% Now we can sort out an optional argument to be displayed on the root.
%
%    \begin{macrocode}
\def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
%    \end{macrocode}
%
% Stages~2 and~3 below are essentially equivalents of \PlainTeX's
% |\root|\dots|\of| and |\r@@t|.  Here we also find the first wrinkle: the
% |\rootbox| used to store the number is spaced out on the left if necessary.
% There's a backspace after the end so that the root can slip underneath, and
% everything works out nicely.  Unfortunately size is fixed here, although
% doesn't actually seem to matter.
%
%    \begin{macrocode}
\def\sqrt@ii#1[#2]{%
  \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
  \ifdim\wd\rootbox<6\p@%
    \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
  \fi%
  \mathpalette{\sqrt@iii{#1}}%
}
%    \end{macrocode}
%
% Now we can actually build everything.  Note that the root is raised by its
% depth -- this prevents a common problem with letters with descenders.
%
%    \begin{macrocode}
\def\sqrt@iii#1#2#3{%
  \setbox\z@\hbox{$\m@th#2#1{#3}$}%
  \dimen@\ht\z@%
  \advance\dimen@-\dp\z@%
  \dimen@.6\dimen@%
  \advance\dimen@\dp\rootbox%
  \mkern-3mu%
  \raise\dimen@\copy\rootbox%
  \mkern-10mu%
  \box\z@%
}
%    \end{macrocode}
%
% Finally handle a non-numbered root.  We read the rooted text in as an
% argument, to stop problems when people omit the braces.  (\AmSTeX\ does
% this too.)
%
%    \begin{macrocode}
\def\sqrt@iv#1#2{#1{#2}}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\root}
%
% We also re-implement \PlainTeX's |\root| command, just in case someone uses
% it, and supply a star-variant.  This is all very trivial.
%
%    \begin{macrocode}
\def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
\def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
%    \end{macrocode}
%
% \end{macro}
%
% \subsection{Modular programming}
%
% \begin{macro}{\pmod}
%
% Do some hacking if not |\ifouter|.
%
%    \begin{macrocode}
\def\pmod#1{%
  \ifinner\;\else\allowbreak\mkern18mu\fi%
  ({\operator@font mod}\,\,#1)%
}
%    \end{macrocode}
%
% \end{macro}
%
% \subsection{Some magic new maths characters}
%
% \begin{macro}{\bitor}
% \begin{macro}{\bitand}
% \begin{macro}{\dblor}
% \begin{macro}{\dbland}
% \begin{macro}{\xor}
% \begin{macro}{\lor}
% \begin{macro}{\ror}
% \begin{macro}{\lsl}
% \begin{macro}{\lsr}
%
% The new boolean operators.
%
%    \begin{macrocode}
\DeclareMathSymbol{&}{\mathbin}{operators}{`\&}
\DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&}
\def\bitor{\mathbin\mid}
\def\dblor{\mathbin{\mid\mid}}
\def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}}
\let\xor\oplus
\def\lsl{\mathbin{<\!\!<}}
\def\lsr{\mathbin{>\!\!>}}
\def\rol{\mathbin{<\!\!<\!\!<}}
\def\ror{\mathbin{>\!\!>\!\!>}}
\AtBeginDocument{\ifx\lll\@@undefined\else
  \def\lsl{\mathbin{\ll}}
  \def\lsr{\mathbin{\gg}}
  \def\rol{\mathbin{\lll}}
  \def\ror{\mathbin{\ggg}}
\fi}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cat}
% \begin{macro}{\compose}
% \begin{macro}{\implies}
% \begin{macro}{\vect}
% \begin{macro}{\d}
% \begin{macro}{\jacobi}
%
% A mixed bag of stuff.
%
%    \begin{macrocode}
\def\cat{\mathbin{\|}}
\let\compose\circ
\def\implies{\Rightarrow}
\def\vect#1{\mathord{\mathbf{#1}}}
\def\d{%
  \ifmmode\mathord{\operator@font d}%
  \else\expandafter\a\expandafter d\fi%
}
\def\jacobi#1#2{{{#1}\overwithdelims()#2}}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\statclose}
% \begin{macro}{\compind}
%
% Fancy new relations for probability distributions.
%
%    \begin{macrocode}
\def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}}
\def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
%
% \begin{macro}{\defop}
% Defining new operator names.
%    \begin{macrocode}
\def\defop{\@ifstar{\defop@\nolimits}{\defop@\limits}}
\def\defop@#1#2#3{\def#2{\mathop{\operator@font #3}#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\keys}
% \begin{macro}{\dom}
% \begin{macro}{\ran}
% \begin{macro}{\supp}
% \begin{macro}{\lcm}
% \begin{macro}{\poly}
% \begin{macro}{\negl}
% \begin{macro}{\ord}
%
% And the new operator names.
%
%    \begin{macrocode}
\defop*\keys{keys}
\defop*\dom{dom}
\defop*\ran{ran}
\defop*\supp{supp}
\defop*\lcm{lcm}
\defop*\poly{poly}
\defop*\negl{negl}
\defop*\ord{ord}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Fractions}
%
% \begin{macro}{\@frac@parse}
%
% \syntax{"\\@frac@parse{"<stuff>"}{"<frac-params>"}"} -- run \<stuff>
% passing it three arguments: an infix fraction-making command, the `outer'
% style, and the `inner' style.
%
% This is rather tricky.  We clear a load of parameters, parse the parameter
% list, and then build a token list containing the right stuff.  Without the
% token list fiddling, we end up expanding things at the wrong times -- for
% example, |\{| expands to something terribly unpleasant in a document
% preamble.
%
% All of the nastiness is contained in a group.
%
%    \begin{macrocode}
\def\@frac@parse#1#2{%
  \begingroup%
  \let\@wd\@empty\def\@ldel{.}\def\@rdel{.}%
  \def\@op{over}\let\@dim\@empty\@tempswafalse%
  \let\@is\@empty\let\@os\@empty%
  \mkparse{mdwmath:frac}{#2}%
  \toks\tw@{\endgroup#1}%
  \toks@\expandafter{\csname @@\@op\@wd\endcsname}%
  \if@tempswa%
    \toks@\expandafter{\the\expandafter\toks@\@ldel}%
    \toks@\expandafter{\the\expandafter\toks@\@rdel}%
  \fi%
  \expandafter\toks@\expandafter{\the\expandafter\toks@\@dim}%
  \toks@\expandafter{\the\toks\expandafter\tw@\expandafter{\the\toks@}}
  \toks@\expandafter{\the\expandafter\toks@\expandafter{\@os}}
  \toks@\expandafter{\the\expandafter\toks@\expandafter{\@is}}
  \the\toks@%
}
%    \end{macrocode}
%
% The keyword definitions are relatively straightforward now.  The error
% handling for \textsf{style} and \textsf{innerstyle} could do with
% improvement.
%
%    \begin{macrocode}
\def\@frac@del#1#2{\def\@wd{withdelims}\@tempswatrue\def#1{#2}}
\mkdef{mdwmath:frac}{leftdelim}{\@frac@del\@ldel{#1}}
\mkdef{mdwmath:frac}{rightdelim}{\@frac@del\@rdel{#1}}
\mkdef{mdwmath:frac}{nodelims}*{\let\@wd\@empty\@tempswafalse}
\mkdef{mdwmath:frac}{line}{%
  \def\@op{above}\setlength\dimen@{#1}\edef\@dim{\the\dimen@\space}%
}
\mkdef{mdwmath:frac}{line}*{\def\@op{over}\let\@dim\@empty}
\mkdef{mdwmath:frac}{noline}*{\def\@op{atop}\let\@dim\@empty}
\def\@frac@style#1#2{%
  \ifx\q@delim#2\q@delim\let#1\@empty%
  \else%
    \expandafter\ifx\csname #2style\endcsname\relax%
      \PackageError{mdwmath}{Bad maths style `#2'}\@ehc%
    \else%
      \edef#1{\csname#2style\endcsname}%
    \fi%
  \fi%
}
\mkdef{mdwmath:frac}{style}[]{\@frac@style\@os{#1}}
\mkdef{mdwmath:frac}{innerstyle}[]{\@frac@style\@is{#1}}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\fracdef}
%
% Here's where the rest of the pain is.  We do a preliminary parse of the
% parameters and `compile' the result into the output macro.  If there's no
% optional argument, then we don't need to do any really tedious formatting
% at the point of use.
%
%    \begin{macrocode}
\def\fracdef#1#2{\@frac@parse{\fracdef@i{#1}{#2}}{#2}}
\def\fracdef@i#1#2#3#4#5{\def#1{\@frac@do{#2}{#3}{#4}{#5}}}
\def\@frac@do#1#2#3#4{%
  \@ifnextchar[{\@frac@complex{#1}}{\@frac@simple{#2}{#3}{#4}}%
}
\def\@frac@complex#1[#2]{\@frac@parse\@frac@simple{#1,#2}}
\def\@frac@simple#1#2#3#4#5{{#2{{#3#4}#1{#3#5}}}}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\frac@fix}
% \begin{macro}{\@@over}
% \begin{macro}{\@@atop}
% \begin{macro}{\@@above}
% \begin{macro}{\@@overwithdelims}
% \begin{macro}{\@@atopwithdelims}
% \begin{macro}{\@@abovewithdelims}
%
% Finally, we need to fix up |\@@over| and friends.  Maybe \package{amsmath}
% has hidden the commands away somewhere unhelpful.  If not, we make the
% requisite copies.
%
%    \begin{macrocode}
\def\q@delim{\q@delim}
\def\frac@fix#1{\expandafter\frac@fix@i\string#1\q@delim}
\def\frac@fix@i#1#2\q@delim{\frac@fix@ii{#2}\frac@fix@ii{#2withdelims}}
\def\frac@fix@ii#1{%
  \expandafter\ifx\csname @@#1\endcsname\relax%
    \expandafter\let\csname @@#1\expandafter\endcsname\csname#1\endcsname%
  \fi%
}
\frac@fix\over \frac@fix\atop \frac@fix\above
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\frac}
% \begin{macro}{\binom}
% \begin{macro}{\jacobi}
%
% And finally, we define the fraction-making commands.
%
%    \begin{macrocode}
\fracdef\frac{nodelims, line}
\fracdef\binom{leftdelim = (, rightdelim = ), noline}
\fracdef\jacobi{leftdelim = (, rightdelim = ), line}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Blackboard bold stuff}
%
% \begin{macro}{\Z}
% \begin{macro}{\Q}
% \begin{macro}{\R}
% \begin{macro}{\C}
% \begin{macro}{\N}
% \begin{macro}{\F}
% \begin{macro}{\powerset}
% \begin{macro}{\gf}
%
% First of all, the signs.
%
%    \begin{macrocode}
\def\Z{\mathbb{Z}}
\def\Q{\mathbb{Q}}
\def\R{\mathbb{R}}
\def\C{\mathbb{C}}
\def\N{\mathbb{N}}
\def\F{\mathbb{F}}
\def\powerset{\mathbb{P}}
\def\gf#1{\F_{#1}}
%\def\gf#1{\mathrm{GF}({#1})}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% And now, define |\mathbb| if it's not there already.
%
%    \begin{macrocode}
\AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi}
%    \end{macrocode}
%
% \subsection{Biggles}
%
% Now for some user-controlled delimiter sizing.  The standard bigness of
% plain \TeX's delimiters are all right, but it's a little limiting.
%
% The biggness of delimiters is based on the size of the current |\strut|,
% which \LaTeX\ keeps up to date all the time.  This will make the various
% delimiters grow in proportion when the text gets bigger.  Actually, I'm
% not sure that this is exactly right -- maybe it should be nonlinear,
%
% \begin{macro}{\bbigg}
% \begin{macro}{\bbiggl}
% \begin{macro}{\bbiggr}
% \begin{macro}{\bbiggm}
%
% This is where the bigness is done.  This is more similar to the plain \TeX\
% big delimiter stuff than to the \package{amsmath} stuff, although there's
% not really a lot of difference.
%
% The two arguments are a multiplier for the delimiter size, and a small
% increment applied \emph{before} the multiplication (which is optional).
%
% This is actually a front for a low-level interface which can be called
% directly for efficiency.
%
%    \begin{macrocode}
\def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen}
\def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@bbigg}
%
% This is an optional argument parser providing a front end for the main
% macro |\bbigg@|.
%
%    \begin{macrocode}
\def\@bbigg#1{\@testopt{\@bbigg@i{#1}}\z@}
\def\@bbigg@i#1[#2]{#1{\bbigg@{#2}}}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\bbigg@}
%
% This is it, at last.  The arguments are as described above: an addition
% to be made to the strut height, and a multiplier.  Oh, and the delimiter,
% of course.
%
% This is a bit messy.  The smallest `big' delimiter, |\big|, is the same
% height as the current strut box.  Other delimiters are~$1\frac12$, $2$
% and~$2\frac12$ times this height.  I'll set the height of the delimiter by
% putting in a |\vcenter| of the appropriate size.
%
% Given an extra height~$x$, a multiplication factor~$f$ and a strut
% height~$h$ and depth~$d$, I'll create a vcenter with total height
% $f(h+d+x)$.  Easy, isn't it?
%
%    \begin{macrocode}
\def\bbigg@#1#2#3{%
  {\hbox{$%
    \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
    \advance\dimen@#1%
    \dimen@#2\dimen@%
    \left#3\vcenter to\dimen@{}\right.\n@space%
  $}}%
}
%    \end{macrocode}
%
% \end{macro}
%
% \begin{macro}{\big}
% \begin{macro}{\Big}
% \begin{macro}{\bigg}
% \begin{macro}{\Bigg}
%
% Now for the easy macros.
%
%    \begin{macrocode}
\def\big{\bbigg@\z@\@ne}
\def\Big{\bbigg@\z@{1.5}}
\def\bigg{\bbigg@\z@\tw@}
\def\Bigg{\bbigg@\z@{2.5}}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Bracketty notation}
%
% This is mostly an exercise in keeping track of data structures.  Which is a
% problem, because \TeX\ isn't really very good at data structures.  Our main
% trick is Church-encoded tuples; i.e., we represent a collection of things
% as a higher-order function which applies a given projection to the tuple.
%
% \begin{macro}{\brk@delim}
% \begin{macro}{\brk@plain}
% \begin{macro}{\brk@size}
% A delimiter keeps track of a before-string, a plain-text delimiter, a sized
% delimiter, and an after-string.  Rather than just projecting components, we
% we want to typeset the things, so we provide two macros for doing this: one
% typesets the plain version (possibly with a prefix), and the other applies
% a size to the sized delimiter.
%    \begin{macrocode}
\def\brk@delim#1#2#3#4#5{#5{#1}{#2}{#3}{#4}}
\def\brk@plain#1#2#3#4#5{#2#1#3#5}
\def\brk@size#1#2#3#4#5{#2#1#4#5}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\brk@bbigg}
% Before we get really stuck in, here's a quick macro to collect a |\bbigg|
% argument and pass it to its continuation.
%    \begin{macrocode}
\def\brk@bbigg#1{\@testopt{\brk@bbigg@{#1}}\z@}
\def\brk@bbigg@#1[#2]#3{#1{#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\brk@lefttwo}
% \begin{macro}{\brk@righttwo}
% We now begin the two-delimiter machinery proper.  The macro |\defbrk| will
% package up the delimiters in a macro.  The following two projections pick
% out the left and right delimiters and apply them to their argument.
%    \begin{macrocode}
\def\brk@lefttwo#1#2#3{#2{#1}}
\def\brk@righttwo#1#2#3{#3{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\brk@plaintwo}
% \begin{macro}{\brk@sizetwo}
% The next stage is to typeset a full delimited expression, which is what we
% do here.
%    \begin{macrocode}
\def\brk@plaintwo#1#2%
  {#1{\brk@lefttwo{\brk@plain{}}}#2#1{\brk@righttwo{\brk@plain{}}}}
\def\brk@sizetwo#1#2#3#4%
  {#3{\brk@lefttwo{\brk@size{#1}}}#4#3{\brk@righttwo{\brk@size{#2}}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\brk@maintwo}
% \begin{macro}{\brk@bigtwo}
% \begin{macro}{\brk@Bigtwo}
% \begin{macro}{\brk@biggtwo}
% \begin{macro}{\brk@Biggtwo}
% \begin{macro}{\brk@bbiggtwo}
% \begin{macro}{\brk@auto}
% And finally, the top-level handlers for two-delimiter bracket-notation
% macros.
%    \begin{macrocode}
\def\brk@maintwo#1{\@ifnextchar[{\brk@maintwo@size#1}{\brk@plaintwo#1}}
\def\brk@maintwo@size#1[#2][#3]{\brk@sizetwo{#2}{#3}#1}
\def\brk@bigtwo{\brk@sizetwo\bigl\bigr}
\def\brk@Bigtwo{\brk@sizetwo\Bigl\Bigr}
\def\brk@biggtwo{\brk@sizetwo\biggl\biggr}
\def\brk@Biggtwo{\brk@sizetwo\Biggl\Biggr}
\def\brk@bbiggtwo#1{\brk@bbigg{\brk@bbiggtwo@#1}}
\def\brk@bbiggtwo@#1#2{\brk@sizetwo{\bbiggl#1{#2}}{\bbiggr#1{#2}}}
\def\brk@auto{\brk@sizetwo\left\right}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\brk@leftthree}
% \begin{macro}{\brk@midthree}
% \begin{macro}{\brk@rightthree}
% \begin{macro}{\brk@plainthree}
% \begin{macro}{\brk@sizethree}
% Next, the three-delimiter projections.
%    \begin{macrocode}
\def\brk@leftthree#1#2#3#4{#2{#1}}
\def\brk@midthree#1#2#3#4{#3{#1}}
\def\brk@rightthree#1#2#3#4{#4{#1}}
\def\brk@plainthree#1#2#3{%
  #1{\brk@leftthree{\brk@plain{}}}#2%
  #1{\brk@midthree{\brk@plain\mathrel}}#3%
  #1{\brk@rightthree{\brk@plain{}}}%
}
\def\brk@sizethree#1#2#3#4#5#6{%
  #4{\brk@leftthree{\brk@size{#1}}}#5%
  #4{\brk@midthree{\brk@size{#2}}}#6%
  #4{\brk@rightthree{\brk@size{#3}}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\brk@mainthree}
% \begin{macro}{\brk@bigthree}
% \begin{macro}{\brk@Bigthree}
% \begin{macro}{\brk@biggthree}
% \begin{macro}{\brk@Biggthree}
% \begin{macro}{\brk@bbiggthree}
% And finally, the top-level handlers for three-delimiter bracket-notation
% macros.
%    \begin{macrocode}
\def\brk@mainthree#1{\@ifnextchar[{\brk@mainthree@size#1}{\brk@plainthree#1}}
\def\brk@mainthree@size#1[#2][#3][#4]{\brk@sizethree{#2}{#3}{#4}#1}
\def\brk@bigthree{\brk@sizethree\bigl\bigm\bigr}
\def\brk@Bigthree{\brk@sizethree\Bigl\Bigm\Bigr}
\def\brk@biggthree{\brk@sizethree\biggl\biggm\biggr}
\def\brk@Biggthree{\brk@sizethree\Biggl\Biggm\Biggr}
\def\brk@bbiggthree#1{\brk@bbigg{\brk@bbiggtree@#1}}
\def\brk@bbiggthree@#1#2%
  {\brk@sizethree{\bbiggl#1{#2}}{\bbiggm#1{#2}}{\bbiggr#1{#2}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@csname}
% A brief change of pace: \syntax{"\\@csname{"<cont>"}{"<command>"}"} calls
% \<cont> with the name of the control sequence \<command>, suitable for
% inlcuding as part of |\csname|\ldots|\endcsname|.  I use |\string|, and
% then there's a dance to remove the backslash from the beginning and the
% space from the end.
%    \begin{macrocode}
\def\@csname#1#2{\expandafter\@csname@\string#2 \relax#1}
\begingroup \lccode`\|=`\\
  \lowercase{\endgroup \def\@csname@|#1 \relax#2{#2{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\defbrk}
% There's nothing to do now but to define |\defbrk| itself.  This is mostly a
% tedious exercise in collecting the arguments.
%    \begin{macrocode}
\def\defbrk@delim#1{\@testopt{\defbrk@delim@i{#1}}{}}
\def\defbrk@delim@i#1[#2]#3{%
  \def\@tempa{#3}%
  \ifx\@tempa\@empty \expandafter\@firstoftwo
  \else \expandafter\@secondoftwo \fi
    {\@testopt{\defbrk@delim@ii{#1}{#2}{}{.}}{}}%
    {\@testopt{\defbrk@delim@ii{#1}{#2}{#3}{#3}}{}}%
}
\def\defbrk@delim@ii#1#2#3#4[#5]{#1{\brk@delim{#2}{#3}{#4}{#5}}}
\def\defbrk{\@ifstar\defbrk@three\defbrk@two}
\def\defbrk@two#1{\defbrk@delim{\defbrk@two@i{#1}}}
\def\defbrk@two@i#1#2{\defbrk@delim{\defbrk@two@ii{#1}{#2}}}
\def\defbrk@two@ii{\@csname\defbrk@two@iii}
\def\defbrk@two@iii#1#2#3{%
  \@namedef{(#1)}##1{##1{#2}{#3}}%
  \expandafter\defbrk@two@iv\csname(#1)\endcsname{#1}%
}
\def\defbrk@two@iv#1#2{%
  \@namedef{#2}{\brk@maintwo#1}%
  \@namedef{big#2}{\brk@bigtwo#1}%
  \@namedef{Big#2}{\brk@Bigtwo#1}%
  \@namedef{bigg#2}{\brk@biggtwo#1}%
  \@namedef{Bigg#2}{\brk@Biggtwo#1}%
  \@namedef{bbigg#2}{\brk@bbiggtwo#1}%
  \@namedef{auto#2}{\brk@auto#1}%
}
\def\defbrk@three#1{\defbrk@delim{\defbrk@three@i{#1}}}
\def\defbrk@three@i#1#2{\defbrk@delim{\defbrk@three@ii{#1}{#2}}}
\def\defbrk@three@ii#1#2#3{\defbrk@delim{\defbrk@three@iii{#1}{#2}{#3}}}
\def\defbrk@three@iii{\@csname\defbrk@three@iv}
\def\defbrk@three@iv#1#2#3#4{%
  \@namedef{(#1)}##1{##1{#2}{#3}{#4}}%
  \expandafter\defbrk@three@v\csname(#1)\endcsname{#1}%
}
\def\defbrk@three@v#1#2{%
  \@namedef{#2}{\brk@mainthree#1}%
  \@namedef{big#2}{\brk@bigthree#1}%
  \@namedef{Big#2}{\brk@Bigthree#1}%
  \@namedef{bigg#2}{\brk@biggthree#1}%
  \@namedef{Bigg#2}{\brk@Biggthree#1}%
  \@namedef{bbigg#2}{\brk@bbiggthree#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The `QED' symbol}
%
% \begin{macro}{\qed}
% \begin{macro}{\qedrule}
% \begin{macro}{\qedsymbol}
%
% This is fairly simple.  Just be careful will the glue and penalties.  The
% size of the little box is based on the current font size.
%
% The horizontal list constructed by the macro is like this:
%
% \begin{itemize}
% \item A |\quad| of space.  This might get eaten if there's a break here or
%   before.  That's OK, though.
% \item An empty box, to break a run of discardable items.
% \item A |\penalty 10000| to ensure that the spacing glue isn't discarded.
% \item |\hfill| glue to push the little rule to the end of the line.
% \item A little square rule `\qedrule', with some small kerns around it.
% \item A glue item to counter the effect of glue added at the paragraph
%   boundary.
% \end{itemize}
%
% The vertical mode case is simpler, but less universal.  It copes with
% relatively simple cases only.
%
% A |\qed| commend ends the paragraph.
%
%    \begin{macrocode}
\def\qed{%
  \ifvmode%
    \unskip%
    \setbox\z@\hb@xt@\linewidth{\hfil\strut\qedsymbol}%
    \prevdepth-\@m\p@%
    \ifdim\prevdepth>\dp\strutbox%
      \dimen@\prevdepth\advance\dimen@-\dp\strutbox%
      \kern-\dimen@%
    \fi%
    \penalty\@M\vskip-\baselineskip\box\z@%
  \else%
    \unskip%
    \penalty\@M\hfill%
    \hbox{}\penalty200\quad%
    \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
  \fi%
}
\def\qedrule{{%
  \dimen@\ht\strutbox%
  \advance\dimen@\dp\strutbox%
  \dimen@ii1ex%
  \advance\dimen@-\dimen@ii%
  \divide\dimen@\tw@%
  \advance\dimen@-\dp\strutbox%
  \advance\dimen@\dimen@ii%
  \advance\dimen@ii-\dimen@%
  \kern\p@%
  \vrule\@width1ex\@height\dimen@\@depth\dimen@ii%
  \kern\p@%
}}
\providecommand\qedsymbol{\qedrule}
%    \end{macrocode}
%
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Punctuation in displays}
%
% \begin{macro}{\mpunct}
%
% This is actually a little more subtle than you'd expect.  If the
% \package{amstext} package is loaded, or something else has defined the
% |\text| command, then we should use that; otherwise, just drop a box in and
% hope for the best.
%
%    \begin{macrocode}
\def\mpunct#1{%
  \,%
  \ifx\text\@@undefined\hbox%
  \else\expandafter\text\fi%
    {#1}%
}
%    \end{macrocode}
%
%\end{macro}
%
% That's all there is.  Byebye.
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \hfill Mark Wooding, \today
%
% \Finale
\endinput
