The following macro produces an arrow with a name between two objects. It has three parameters.
\newcommand{\rname}[3]{
\begin{tikzcd}[ampersand replacement=\&]
{#1} \arrow[r, "{#2}"] \& {#3}
\end{tikzcd}
}
However, I would like to have only one parameter, the name of the arrow:
\newcommand{\rname}[1]{
\begin{tikzcd}[ampersand replacement=\&]
\arrow[r, "{#1}"] \&
\end{tikzcd}
}
But this does not work with tikz. How can I fix it? Here is a compilable example:
\documentclass{article}
\usepackage{tikz-cd}
\newcommand{\rname}[3]{
\begin{tikzcd}[ampersand replacement=\&]
{#1} \arrow[r, "{#2}"] \& {#3}
\end{tikzcd}
}
\begin{document}
$\rname{A}{f}{B}$
%$A\rname{f}B$ I would like it to function like this.
\end{document}