[Tex/LaTex] Cancel maths expression with a down arrow

cancelmath-modestrikeout

The following solution to the question where soome maths text is to be cancelled out makes use of the cancel package. There the macro \cancelto produces an arrow from bottom left to top right. It also gives a macro called \bcancel which gives a strike out from top left to bottom right.

Is it possible to have a macro that combines these two together, something of the form \bcancelto: an arrow from top-left to bottom-right.

Here is a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]

\end{document}

Best Answer

I introduce \bcancelto{label}{term} by modifying one of the packages routines. EDITED to support labels on \bcancelto.

The modification to \canto@vector to produce \cantox@vector amounted to three things:

1) adding a - before #4 in the \vector call;

2) Changing the ^ superscript to a _ subscript before the \raise; and

3) adding a - sign before #2 following the \raise.

Then I had to define \bcancelto to make this macro substitution and call on \cancelto with the substitution in place.

\documentclass{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}
\makeatletter
% #1, #2 offset of label   #6 extra width to clear arrowhead
% #3, #4 vector direction  #7 superscript label style
% #5 vector width          #8 superscript label
\def\cantox@vector#1#2#3#4#5#6#7#8{%
  \dimen@.5\p@
  \setbox\z@\vbox{\boxmaxdepth.5\p@
   \hbox{\kern-1.2\p@\kern#1\dimen@$#7{#8}\m@th$}}%
  \ifx\canto@fil\hidewidth  \wd\z@\z@ \else \kern-#6\unitlength \fi
  \ooalign{%
    \canto@fil$\m@th \CancelColor
    \vcenter{\hbox{\dimen@#6\unitlength \kern\dimen@
      \multiply\dimen@#4\divide\dimen@#3 \vrule\@depth\dimen@\@width\z@
      \vector(#3,-#4){#5}%
    }}_{\raise-#2\dimen@\copy\z@\kern-\scriptspace}$%
    \canto@fil \cr
    \hfil \box\@tempboxa \kern\wd\z@ \hfil \cr}}
\def\bcancelto#1#2{\let\canto@vector\cantox@vector\cancelto{#1}{#2}}
\makeatother
\begin{document}
\noindent
\verb|\cancel{5y}|:
\[ x+\cancel{5y}=0\]
\verb|\bcancel{5y}|:
\[ x+\bcancel{5y}=0\]
\verb|\xcancel{5y}|:
\[ x+\xcancel{5y}=0\]
\verb|\cancelto{\infty}{5y}|:
\[ x+\cancelto{\infty}{5y}=0\]
\noindent NEW! \verb|\bcancelto{\infty}{5y}|:
\[ x+\bcancelto{\infty}{5y}=0\]
\end{document}

enter image description here