# Equivalent of cancelto in ConTeXt

Is there any equivalent of \cancelto in ConTeXt? I want to cancel math expression with an arrow as in "goes to zero".

The code given below is probably not working in all cases, and there might be better ways to do this, but it could serve you as a start. It uses a framed formula (without frame!) with a MetaPost background. It is not as flexible as the \cancelto, since the 0 is hardcoded.

% Define the MetaPost background
\startuseMPgraphic{cancel}
drawarrow origin--(OverlayWidth,OverlayHeight);
label.top("$0$",(OverlayWidth,OverlayHeight));
setbounds currentpicture to unitsquare xyscaled(OverlayWidth,OverlayHeight);
\stopuseMPgraphic

% Define the overlay
\defineoverlay[cancel][\useMPgraphic{cancel}]

% Define a new mathframed cancel
\definemathframed[cancel][mframed][
frame=off,
offset=overlay,
background=cancel,
]

% Example
\startTEXpage[width=4in,offset=3bp]
\startformula
\int_0^{+\infty}e^{-x}\cos x\,dx
=
\cancel{\Bigl[e^{-x}\sin x\Bigr]_0^{+\infty}}
+\int_0^{+\infty}e^{-x}\sin x\,dx.
\stopformula
\stopTEXpage

PS I suggest that one does not use these kind of arrows in formulas striking out terms, but instead make it clear from the text (and formulas) what is canceled and why.

• My most sincere compliments. I not know absolutely ConTeXt. – Sebastiano Jul 23 '19 at 21:26
• You could use \setMPtext and \MPstring to make the $0$ configurable. I've added another answer for that, however, feel free to incorporate my answer into yours, then I will delete it again. – Henri Menke Aug 6 '19 at 22:13
• Nice! I suggest that we keep it as is. Your answer add sufficient value to stand by its own. – mickep Aug 7 '19 at 2:59

Just some more bells and whistles for Mikael's answer.

% Define the MetaPost background
\startuseMPgraphic{cancel}
drawarrow origin--(OverlayWidth,OverlayHeight);
label.top(\MPstring{cancelto},(OverlayWidth,OverlayHeight));
setbounds currentpicture to unitsquare xyscaled(OverlayWidth,OverlayHeight);
\stopuseMPgraphic

% Define the overlay
\defineoverlay[cancel][\useMPgraphic{cancel}]

% Define a new mathframed cancel
\definemathframed
[cancel]
[mframed]
[frame=off,
offset=overlay,
background=cancel,
to={},
extras={\setMPtext{cancelto}{$\framedparameter{to}$}}]

% Example
\startTEXpage[width=4in,offset=3bp]

\startformula
\int_0^{+\infty}e^{-x}\cos x\,dx
=
\cancel[to=0]{\Bigl[e^{-x}\sin x\Bigr]_0^{+\infty}}
+\int_0^{+\infty}e^{-x}\sin x\,dx.
\stopformula
\stopTEXpage