# Scaling symbol when used in subscript

I'm using this symbol (defined by Steven B. Segletes here) to denote a special type of function definition:

\newcommand*\diamondarrow{%
\stackengine{0pt}{\hspace{.83ex}$\rightarrow$}{$\diamond$}{O}{l}{F}{F}{L}}


I have noticed that when used in subscript it does not scale (should it, right?). How can I make it scaling automatically?

\documentclass{article}

\usepackage{stackengine}
\usepackage{scalerel}

\newcommand*\diamondarrow{%
\stackengine{0pt}{\hspace{.83ex}$\rightarrow$}{$\diamond$}{O}{l}{F}{F}{L}}

\begin{document}
$A \diamondarrow B_{C \diamondarrow D_{E \diamondarrow F}}$
\end{document}


I suggest a different definition:

\documentclass{article}

\newcommand{\diamondarrow}{%
\mathrel\diamond
\mathrel{\mathchoice{\mkern-2mu}{\mkern-2mu}{\mkern-2.5mu}{\mkern-3mu}}%
\rightarrow
}

\begin{document}
$A \diamondarrow B_{C \diamondarrow D_{E \diamondarrow F}}$
\end{document}


By setting everything to a \mathrel, TeX will not introduce any additional spacing. With the help of \mathchoice we're able to define different negative kerns for the different math styles. This is font depending, though, so different math fonts might need different amounts.

• It works perfectly! – BlackBrain Nov 7 '18 at 18:17