[Tex/LaTex] Remove space between characters

kerningmath-modespacing

How can I remove the space between this

\newcommand{\deref}{\ensuremath{\rightarrowtriangle}\xspace}

$b\deref\mathbf{r}_S$

such that the arrow is as closest to the two surounding characters as possible?

enter image description here

Best Answer

Put one extra pair of braces around the arrow.

\documentclass{article}
\usepackage{stmaryrd,xspace}
\newcommand{\deref}{\ensuremath{{\rightarrowtriangle}}\xspace}


\begin{document}
  $b\deref\mathbf{r}_S$
\end{document}

enter image description here

BTW, what is the intention of using ensuremath and \xspace here? It is better not to use them.