\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@th#1#2$}}

\def\domathllap{\mathpalette\dodomathllap}
\def\dodomathllap#1#2{\dollap{$\m@th#1#2$}}

\def\domathrlap{\mathpalette\dodomathrlap}
\def\dodomathrlap#1#2{\dorlap{$\m@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@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}

%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
