# Arrow through text in Math mode

So I know the cancel package lets you put a diagonal arrow through text in Math mode, but how could I achieve the same result but with a horizontal arrow?

• The result doesn't seem pretty: the arrow tip will confuse with the text underneath. – egreg Nov 24 '15 at 21:59
• @egreg I'm imaging an image that, if I try to approximate it with ASCII, would look like: x -f-u-n-c-t-i-o-n-> y. Of course I don't always want the text that is overlapping with arrow to be 'function' but this gives a sense of what I want it to look like. But the arrow-head should stick out some distance to the right of the text so that there isn't that confusion. – Addem Nov 24 '15 at 23:13

Maybe something like this, using \xrightarrow:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\arrowcancel}[1]{%
\mathrel{%
\sbox0{$\mspace{3mu}{#1}\mspace{6mu}$}%
{\vphantom{#1}
\ooalign{%
$\xrightarrow{\hspace{\wd0}}$\cr
\hidewidth\box0 \hidewidth\cr
}%
}%
}%
}

\begin{document}

$x\arrowcancel{abc}y$

\end{document}


• I'm playing around with it and can't figure out how I might automatically make the arrow head extend just a little farther to the right. I know I can do it if I use the command \arrowcancel{abc\,\,} but is there a way to automate this effect? – Addem Nov 24 '15 at 23:31
• @Addem Change \mspace{6mu} into \mspace{9mu} or so. – egreg Nov 24 '15 at 23:38