# [dev-context] [NTG-context] llap, rlap, clap equivalent for math

Mon Apr 23 19:08:07 CEST 2007

On Thu, 19 Apr 2007, Hans Hagen wrote:
> before i add this, we need to be sure that llap/rlap are not used in
> math constructs which expect it to behave like an hbox

Continuing on the same thread, I found that the above definitions for
(c|l|r)lap is not always adequate for math mode. The main problem is
that tex does not provide a cramped primitive. The problem has been
discussed with a solution proposed by Knuth
http://www.ctan.org/tex-archive/digests/tex-implementors/042 and
implemented for LaTeX in the mathtools package. Attached is my attempt
to port it to ConTeXt. Please look at the \cramped and \crampedclap
macros carefully before deciding to include them in the core. I have
just copied most of the code from Knuth's definition and do not really
understand what is happening here.

-------------- next part --------------
\unprotect

% Taco's definition of \tex{rlap}, etc.

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

%D There is a problem with using these in the math mode. The problem is
%D not with the macros, but with \TEX. \TEX provides no primitive to
%D force in cramped math mode. Here is a macro that does so. It is based
%D on a solution by 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
\else
\scratchdimen=1.25\fontdimen8
\ifx#1\textstyle\textfont
\else
\ifx#1\scriptstyle\scriptfont\else\scriptscriptfont\fi
\fi
3
\fi
\ht\scratchbox=-\scratchdimen
\box\scratchbox}

%D Now we provide commands for cramped styles

\def\crampedclap
{\mathpalette\docrampedclap}

\def\docrampedclap#1#2%
{{}\doclap{\docramped #1{#2}}}

\def\crampedllap
{\mathpalette\docrampedllap}

\def\docrampedllap#1#2%
{{}\dollap{\docramped #1{#2}}}

\def\crampedrlap
{\mathpalette\docrampedrlap}

\def\docrampedrlap#1#2%
{{}\dorlap{\docramped #1{#2}}}
\protect

\starttext

Look at the output of
\startbuffer
\startformula
\sum_{\clap{a^2 < b^2 < c^2}} \quad
\sum_{a^2 < b^2 < c^2}
\stopformula
\stopbuffer
\typebuffer{\switchtobodyfont[24pt]\getbuffer}

The formula on the left is not set in cramped style. The above
\tex{cramped} macro typesets in cramped style. So, we can use
\startbuffer
\startformula
\sum_{\clap{\cramped a^2 < b^2 < c^2}} \quad
\sum_{a^2 < b^2 < c^2}
\stopformula
\stopbuffer
\typebuffer{\switchtobodyfont[24pt]\getbuffer}

But \type{\clap{\cramped ... }} typesets its arguments 16 times (which
is true for any command recursively using \tex{mathpalette}. So, we
provide a \tex{cramped...} version of \tex{clap} etc.

\startbuffer
\startformula
\sum_{\crampedclap{a^2 < b^2 < c^2}} \quad
\sum_{a^2 < b^2 < c^2}
\stopformula
\stopbuffer
\typebuffer{\switchtobodyfont[24pt]\getbuffer}

\stoptext