# Arrow with superscript in math mode and tikz-cd

I have two scenarios where I use arrows with a super-scripted asterisk: math mode and tikz-cd diagrams. I would like to be able to show such an arrow in both scenarios such that the arrows look the same, i.e., with respect to positioning of the asterisk.

Consider the below MWE. This is how I would like the arrow to look.

MWE

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}

\newcommand*\dirinfsymname{Rightarrow}
\newcommand*\directdatacolourname{PineGreen}
\newcommand*\directdatacolour{\textcolor{\directdatacolourname}}
\newcommand*\dirinfsym{\mathbin{\directdatacolour{\Rightarrow}}}

\newcommand{\pathdirinfsym}[1][]{\mathrel{
\vphantom{\dirinfsym{#1}}
\smash{\dirinfsym{#1}}
\vphantom{\to}^{\textcolor{PineGreen}{*}}}
}

\begin{document}

$a \pathdirinfsym b$

\end{document}


This outputs:

Now, consider this MWE.

MWE

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,tikz-cd}
\usetikzlibrary{shapes,fit}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}

\newcommand*\dirinfsymname{Rightarrow}
\newcommand*\directdatacolourname{PineGreen}
\newcommand*\directdatacolour{\textcolor{\directdatacolourname}}
\newcommand*\dirinfsym{\mathbin{\directdatacolour{\Rightarrow}}}

\begin{document}

\begin{tikzcd}[
column sep=small,
cells={nodes={draw=black, ellipse, anchor=center, minimum height=2em}}
]
a  \arrow[\dirinfsymname, \directdatacolourname, bend left]{rrrrr}{*} & a \arrow[\dirinfsymname, \directdatacolourname]{r}{*}  & a  & |[draw=none]|a\vphantom{1}  & a  & a
\end{tikzcd}

\end{document}


This outputs:

Notice how the two arrows have the asterisk positioned in the middle of the stem. I would like the asterisk positioned in the same position as in the first diagram.

Furthermore, I would like this to work for more than just \Rightarrow. I would like like to be able to do the same for \rightarrow.

tizk-cd has the possibility to use glyphs for arrowheads and arrows.meta allows us to patch arrows together. Here is a more TikZy and shorter code which also has \to-type arrow.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric,arrows.meta}

\newcommand{\mysym}{\vphantom{\to}^{*}}

\begin{document}

\tikzset{
startip/.tip={Glyph[glyph math command=mysym]},
Rightarrow*/.style={PineGreen,double equal sign distance,>={Implies},->.startip},
to*/.style={PineGreen,->.startip}}
\begin{tikzcd}[
column sep=small,
cells={nodes={draw=black, ellipse, anchor=center, minimum height=2em}}
]
a \arrow[r,Rightarrow*]
\arrow[Rightarrow*, bend left]{rrrrr}{m} & a \arrow[Rightarrow*,r] & a
\arrow[to*,r] &
|[draw=none,rectangle,inner sep=1pt]|a\vphantom{1} \arrow[Rightarrow*,r] & a \arrow[Rightarrow*,r] & a
\end{tikzcd}
\end{document}


Note that you do not have to stop here, using this you can patch together any symbols and use them as arrows. (Of course, at a given point you may want to use bending.)

This is the older version which uses your macros.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric,arrows.meta}

\newcommand*\dirinfsymname{Rightarrow}
\newcommand*\directdatacolourname{PineGreen}
\newcommand*\directdatacolour{\textcolor{\directdatacolourname}}
\newcommand*\dirinfsym{\mathbin{\directdatacolour{\Rightarrow}}}

\newcommand{\pathdirinfsym}[1][]{\mathrel{
\vphantom{\dirinfsym{#1}}
\smash{\dirinfsym{#1}}
\vphantom{\to}^{\textcolor{PineGreen}{*}}}
}
\newcommand{\mysym}{\hspace{1em}\vphantom{\to}^{\textcolor{PineGreen}{*}}}
\usetikzlibrary{arrows}

\begin{document}

\tikzset{
fancy/.tip={Glyph[glyph math command=mysym]},
pft/.style={\directdatacolourname,double equal sign
distance,>={Implies},->.fancy}
}
\begin{tikzcd}[
column sep=small,
cells={nodes={draw=black, ellipse, anchor=center, minimum height=2em}}
]
a \arrow[r,pft]
\arrow[pft, bend left]{rrrrr}{m} & a \arrow[pft,r] & a \arrow[pft,r] &
|[draw=none,rectangle,inner sep=1pt]|a\vphantom{1} \arrow[pft,r] & a \arrow[pft,r] & a
\end{tikzcd}

\end{document}


• Thank you! This is excellent. Out of curiosity, the arrow head has lines either side (a continuation of the arrow stem?) - is it possible to remove these? May 26, 2019 at 2:54
• @DavidPoxon Good point! (The fix is also to add a point. ;-)
– user121799
May 26, 2019 at 3:20
• Thank you so much! This is excellent. One question: how might I re-purpose this for a regular \rightarrow? I'm thinking I need to modify pft but I'm at a bit of a loss. May 26, 2019 at 3:36
• @DavidPoxon It is just \tikzset{pfft/.style={\directdatacolourname,->.fancy}} and then a \arrow[pfft,r] in the diagram. You can patch all sorts of things together with this trick.
– user121799
May 26, 2019 at 3:38
• @DavidPoxon I only combine what is written in section ** 16.5 Reference: Arrow Tips** of the pgfmanual v3.1.3 and in section 4.4 of the tikz-cd manual. And if you get stuck somewhere you can ask another question, or if you give me an idea what you want to generalize/change here I will be happy to give it a shot (but I may be hibernating ;-).
– user121799
May 26, 2019 at 4:07