+% \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}