[dev-context] Some math improvements
Aditya Mahajan
adityam at umich.edu
Tue May 22 02:37:38 CEST 2007
Hi Hans and Taco,
I am attaching the math enhancements that I have been promising for
about for some days^H^H^H^Hweeks now. Here are the changes.
1. Improved \llap, \rlap, \clap that work in both math and text mode
(Taco's code)
2. A \cramped macro to go into cramped mode (based on Knuth's code)
3. \crampedllap \crampedrlap, \crampedclap for the equivalents to
\llap etc which typesets its contents in cramped mode (well, I kinda
figured that out on my own :)
4. An improved substack macro, with improved spacing. (Based on
amsmath's substack macro). Taco, does it make sense to surround
substack with a group, which will save some typing
\sum_startsubstack whatever \stopsubstack or are there any side
effects? In the code, I do not have the extra group.
5. Definitions for iint, iiint, iiiint (for those who can't count i's
like me, you can use \repeatintegral{1}, \repeatintegral{2}, etc.
Maybe, we should have the more readable \doubleintegral,
\tripeintegral, \quadintegral also). This is based on amsmath code,
and tries to use correct spacing for \iint\limits_{....}. BTW, does
anyone wish that the limits with \int were configurable rather than
defaulting to \nolimits? amsmath provides this feature, but I have
personally never seen it being used. It is not too difficult to
implement.
6. A definition for splitfrac, which is useful for multi-line
fractions. Based on Michael Downes' code.
.... I also had something for \intertext, but realized that
\intertext does not honor indentations. I will look into that first,
before posting the code.
Now, I need to do collect everthing for theorems. Hopefully, core-des
has not changed since I started working on it...
Aditya
-------------- next part --------------
%AM: This should go to supp-box.tex.
%D \macros
%D {llap, rlap, tlap, blap, clap}
%D
%D Some well known friends, but we implement them our own
%D way. We want the macros to work in both math and text mode.
\def\dorlap{\begingroup\dowithnextbox{\normalhbox to \zeropoint
{\flushnextbox\normalhss}\endgroup}\normalhbox}
\def\dollap{\begingroup\dowithnextbox{\normalhbox to \zeropoint
{\normalhss\flushnextbox}\endgroup}\normalhbox}
\def\doclap{\begingroup\dowithnextbox{\normalhbox to \zeropoint
{\normalhss\flushnextbox\normalhss}\endgroup}\normalhbox}
\def\domathclap{\mathpalette\dodomathclap}
\def\dodomathclap#1#2{\doclap{$\m at th#1#2$}}
\def\domathllap{\mathpalette\dodomathllap}
\def\dodomathllap#1#2{\dollap{$\m at th#1#2$}}
\def\domathrlap{\mathpalette\dodomathrlap}
\def\dodomathrlap#1#2{\dorlap{$\m at th#1#2$}}
\unexpanded\def\rlap{\mathortext\domathrlap\dorlap}
\unexpanded\def\llap{\mathortext\domathllap\dollap}
\unexpanded\def\clap{\mathortext\domathclap\doclap}
%AM: I do not know where this belongs. Perhaps supp-mat.tex
%D \macros {cramed}
%D
%D \TEX provides no primitive to force in cramped math mode.
%D Here is a macro that does so. It is based on a solution by
%D Don Knuth
%D \userul{http://www.ctan.org/tex-archive/digests/tex-implementors/042}.
%D The explanation is by Morten H?gholm's mathtools package.
\def\cramped
{\mathpalette\docramped}
\def\docramped#1#2%
%D Force a cramped style by issuing a non||existing radical
{\setbox\scratchbox=\hbox{\nulldelimiterspace=\zeropoint%
$\m at th#1\radical\zerocount{#2}$}
%D Make sure the height is correct
\ifx#1\displaystyle
\scratchdimen=\fontdimen8\textfont3
\advance\scratchdimen .25\fontdimen5\textfont2
\else
\scratchdimen=1.25\fontdimen8
\ifx#1\textstyle\textfont
\else
\ifx#1\scriptstyle\scriptfont\else\scriptscriptfont\fi
\fi
3
\fi
\advance\scratchdimen-\ht\scratchbox
\ht\scratchbox=-\scratchdimen
\box\scratchbox}
%AM: Not sure about these either. Either supp-box or supp-mat
%AM: core-mat.
%D \macros
%D {cramedllap, crampedrlap, crampedclap}
%D In many cases, one wants to use the \tex{clap} macro in
%D math mode while using subscripts. Normally, subscripts are
%D in cramped mode, and these macros allow you to go to
%D cramped mode. For example
%D \startbuffer
%D \startformula
%D \sum_{a^2 < b^2 < c^2} \quad
%D \sum_{\clap{a^2 < b^2 < c^2}} \quad
%D \sum_{\crampedclap{a^2 < b^2 < c^2}}
%D \stopformula
%D \stopbuffer
%D \typebuffer{\switchtobodyfont[24pt]\getbuffer}
%D Notice that \type{\clap{\cramped ... }} would also work,
%D but it requires \TEX\ to typeset it arguments 16 times.
\def\docrampedllap#1#2{{}\dollap{\docramped #1{#2}}}
\def\docrampedrlap#1#2{{}\dorlap{\docramped #1{#2}}}
\def\docrampedclap#1#2{{}\doclap{\docramped #1{#2}}}
\def\crampedllap{\mathpalette\docrampedllap}
\def\crampedrlap{\mathpalette\docrampedrlap}
\def\crampedclap{\mathpalette\docrampedclap}
%AM: This needs to replace the core-mat macros.
%D \macros
%D {substack}
%D
%D Preliminary code:
%D
%D \startbuffer
%D \startformula
%D \sum_{%
%D \startsubstack
%D i = 1 \NR
%D i \neq n \NR
%D i \neq m
%D \stopsubstack
%D }a_i
%D \stopformula
%D \stopbuffer
%D \getbuffer which was typed as \typebuffer
%D Notice that these macros give the correct spacing for
%D subscripts. Compare for example
%D \startbuffer
%D \startformula
%D \sum_{\startsubstack a \NR b \NR \stopsubstack}
%D \text{ and }
%D \sum_{\scriptstyle a \atop \scriptstyle}
%D \stopformula
%D \typebuffer which gives \getbuffer
\def\startsubstack
{%\bgroup% Is this ok?
\vcenter\bgroup
\baselineskip\fontdimen10 \scriptfont\plustwo
\advance\baselineskip\fontdimen12 \scriptfont\plustwo
\lineskip\plusthree\fontdimen8 \scriptfont\plusthree
\lineskiplimit\lineskip
\let\stopmathmode\relax
\def\NC{\domatrixNC}%
\def\MC{\domatrixNC\startmathmode}%
\global\let\domatrixNC\dodomatrixNC
\def\NR
{\stopmathmode
\global\let\domatrixNC\dodomatrixNC
\crcr}%
\mathsurround\zeropoint
\everycr\emptytoks
\halign\bgroup\hfil$\scriptstyle##$\hfil\crcr}
\def\stopsubstack
{\crcr
\egroup
\egroup
%\egroup% Is this ok?
}
%AM: These need to go into math-tex. Perhaps I should also
%AM: port dotsint?
\def\dointkern {\mkern-6mu\mathchoice{\mkern-3mu}{}{}{}}
\definemathcommand [iint] {\repeatintegral{1}}
\definemathcommand [iiint] {\repeatintegral{2}}
\definemathcommand [iiiint] {\repeatintegral{3}}
\def\repeatintegral#1%
{\scratchtoks\emptytoks
\let\dointlimits\nolimits
\dorecurse{#1}{\appendtoks \intop \dointkern \to \scratchtoks}
\appendtoks \intop \dointlimits \to \scratchtoks
\edef\dodorepeatintegral{\the\scratchtoks}
\futurelet\next\dorepeatintegral}
%D If the \type{\limits} option is used after \type{\iint}, use
%D \type{\mathop} and fudge the left hand space a bit to make the
%D subscript visually centered.
\def\dorepeatintegral
{\ifx\limits\next \dointlimitcorrection
\else \ifx \displaylimits\next \dointlimitcorrection
\fi\fi
\dodorepeatintegral}
\def\dointlimitcorrection
{\mkern-7mu\mathchoice{\mkern-2mu}{}{}{}%
\mathop\bgroup
\mkern7mu\mathchoice{\mkern2mu}{}{}{}%
\let\dointlimits\egroup}
%AM: This needs to go to m-newmat.tex
%D \macros {splitfrac, splitdfrac}
%D Occasionally one needs to typeset multi||line fractions.
%D These commands use \tex{genfrac} to create such fractions.
%D \startbuffer
%D \startformula
%D a=\frac{
%D \splitfrac{xy + xy + xy + xy + xy}
%D {+ xy + xy + xy + xy}
%D }
%D {z}
%D =\frac{
%D \splitdfrac{xy + xy + xy + xy + xy}
%D {+ xy + xy + xy + xy}
%D }
%D {z}
%D \stopformula
%D \stopbuffer
%D \typebuffer \getbuffer
%D
%D These macros are based on Michael J.~Downes posting on
%D comp.text.tex on 2001/12/06
\def\splitfrac#1#2%
{\genfrac{}{}{0pt}{1}%
{\textstyle#1\quad\hfill}%
{\textstyle\hfill\quad\mathstrut#2}}
\def\splitdfrac#1#2%
{\genfrac{}{}{0pt}{0}%
{#1\quad\hfill}
{\hfill\quad\mathstrut #2}}
More information about the dev-context
mailing list