% \begin{meta-comment}
%
-% $Id: mdwmath.dtx,v 1.1 2002/02/03 20:49:03 mdw Exp $
+% $Id: mdwmath.dtx,v 1.2 2003/09/05 16:14:36 mdw Exp $
%
% Various nicer mathematical things
%
-% (c) 1996 Mark Wooding
-%
-%----- Revision history -----------------------------------------------------
-%
-% $Log: mdwmath.dtx,v $
-% Revision 1.1 2002/02/03 20:49:03 mdw
-% Checkin for new build system.
-%
-% Revision 1.1 1996/11/19 20:53:21 mdw
-% Initial revision
-%
+% (c) 2003 Mark Wooding
%
% \end{meta-comment}
%
% \begin{meta-comment} <general public licence>
%%
%% mdwmath package -- various nicer mathematical things
-%% Copyright (c) 1996 Mark Wooding
+%% Copyright (c) 2003 Mark Wooding
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
% \begin{meta-comment} <Package preamble>
%<+package>\NeedsTeXFormat{LaTeX2e}
%<+package>\ProvidesPackage{mdwmath}
-%<+package> [2000/07/02 1.2 Nice mathematical things]
+%<+package> [2003/08/25 1.3 Nice mathematical things]
%<+oldeqnarray>\NeedsTeXFormat{LaTeX2e}
%<+oldeqnarray>\ProvidesPackage{eqnarray}
%<+oldeqnarray> [1996/04/11 1.1 Old enhanced eqnarray]
% \end{meta-comment}
%
-% \CheckSum{465}
+% \CheckSum{740}
%% \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
\let\opmod\pmod
\usepackage{amssymb}
\describespackage{mdwmath}
-% \describespackage{eqnarray}
+%\describespackage{eqnarray}
\ignoreenv{old-eqnarray}
-% \unignoreenv{old-eqnarray}
+%\unignoreenv{old-eqnarray}
\mdwdoc
%</driver>
%
% 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" &
+% $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\
+% $\bitand$ & "\bitand" & $\dblor$ & "\dblor" &
% \end{tabular} \end{center}
%
% \DescribeMacro\xor
% `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 |\jacobi{x}{n}| command typesets `$\jacobi{x}{n}$', which may be of use
-% to number theorists talking about Jacobi or Lagrange symbols.
+% 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}
%
% \[ \frac{dy}{dx} \]
% while the British want
% \[ \frac{\d y}{\d x}. \]
-% The command |\d| command is fixed to typeset a `$\d$'. If you want the
-% accent, try |\a{d}{x}|, which typesets `\a{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\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"
+% $\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 \,\}$.
+% \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$.
%
% \subsection{Standard set names}
%
% \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$'.
+% 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{The `QED' symbol}
%
% 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.
+%
% \begin{ignore}
% There used to be an eqnarray here, but that's migrated its way into the
% \package{mdwtab} package. Maybe the original version, without dependency
% The types provided (and it's easy-ish to add more) are:
%
% \def\ch{\char`}
-% \begin{description} \def\makelabel{\hskip\labelsep\normalfont\ttfamily}
+% \begin{description} \setdescriptionlabel{\normalfont\ttfamily#1}
% \item [r] Right aligned equation
% \item [c] Centre-aligned equation
% \item [l] Left aligned equation
%
% \begin{demo}[w]{Lots of equations}
%\begin{eqnarray}[rl:rl:l]
-% V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, &
+% V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, &
% U_i = u_i, \qquad \mbox{for $i \ne j$} \label{eq:A} \\
% V_j &= v_j, & X_j &= x_j &
% U_j u_j + \sum_{i \ne j} q_i u_i.
% \begin{demo}{Splitting example}
%\begin{eqnarray*}[Ll]
% w+x+y+z = \\
-% & a+b+c+d+e+ \\
+% & a+b+c+d+e+{} \\
% & f+g+h+i+j
%\end{eqnarray*}
% \end{demo}
%
% \begin{macrocode}
%<*package>
+\RequirePackage{amssymb}
+\RequirePackage{mdwkey}
% \end{macrocode}
%
% \subsection{Square roots}
%
% 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.
+% top.
%
% \begin{macrocode}
\@tempdima\ht\tw@%
\let\compose\circ
\def\implies{\Rightarrow}
\def\vect#1{\mathord{\mathbf{#1}}}
-\def\d{\mathord{\operator@font d}}
+\def\d{%
+ \ifmmode\mathord{\operator@font d}%
+ \else\expandafter\a\expandafter d\fi%
+}
\def\jacobi#1#2{{{#1}\overwithdelims()#2}}
% \end{macrocode}
%
% \begin{macro}{\ran}
% \begin{macro}{\supp}
% \begin{macro}{\lcm}
+% \begin{macro}{\poly}
+% \begin{macro}{\negl}
+% \begin{macro}{\ord}
%
% And the new operator names.
%
\def\ran{\mathop{\operator@font ran}\nolimits}
\def\supp{\mathop{\operator@font supp}\nolimits}
\def\lcm{\mathop{\operator@font lcm}\nolimits}
+\def\poly{\mathop{\operator@font poly}\nolimits}
+\def\negl{\mathop{\operator@font negl}\nolimits}
+\def\ord{\mathop{\operator@font ord}\nolimits}
+% \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}{\N}
% \begin{macro}{\F}
% \begin{macro}{\powerset}
+% \begin{macro}{\gf}
%
% First of all, the signs.
%
\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}
%
% And now, define |\mathbb| if it's not there already.
%
% \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.
+% 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}
-\providecommand\qed{%
- \leavevmode%
- \unskip%
- \penalty\@M\hfill%
- \hbox{}\penalty\z@\quad%
- \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par%
+\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
+ \advance\dimen@\dp\strutbox%
\dimen@ii1ex%
\advance\dimen@-\dimen@ii%
\divide\dimen@\tw@%
% \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}
+%
% \begin{ignore}
% The following is the original definition of the enhanced eqnarray
% environment. It's not supported, although if you can figure out how to