I want to write a macro for a math map f:A\to B when it is in inline math mode and f:A\longrightarrow B for displayed math. But I don't know how to check that it is in inline mode or displayed style.
Here is my try:
\documentclass{article}
\newcommand{\map}[3]{#1\mathpunct{:}#2\longrightarrow #3}
\begin{document}
$\map{f}{A}{B}$
[\map{f}{A}{B}]
\end{document}
I have tried the following but it produces Undefined control sequence. $\map
\makeatletter
\newcommand[3]{\map}{
#1\mathpunct{:}#2
\if@display
\longrightarrow #3
\else
\rightarrow #3
\fi}
\makeatother
\mathchoice. https://tex.stackexchange.com/questions/148740/what-is-mathchoice – Alan Xiang May 30 '21 at 16:23