I'd like to have the command \to produce the arrow from \longrightarrow, but only when in a display mode, making use of the available space.
More precisely, the output of
So we have a map $A \to B$.
should be left unchanged, but
So we have a map
\[
A \to B.
\]
should produce the same as
So we have a map
\[
A \longrightarrow B.
\]
If possible, I'd like the same to happen to \mapsto getting replaced by \longmapsto when in display mode.

\rightarrowinstead of\realto, no need for the\let. – egreg May 01 '19 at 10:40\mapstowould require a\let-construction, would it not? – SvanN May 01 '19 at 11:24\let\realmapsto\mapstoand then\renewcommand\mapsto{\mathchoice{\longmapsto}{\realmapsto}{\realmapsto}{\realmapsto}}or instead use\renewcommand\mapsto{\mathchoice{\longmapsto}{\mapstochar\rightarrow}{\mapstochar\rightarrow}{\mapstochar\rightarrow}}. [If you look infontmath.ltxyou will find\def\mapsto{\mapstochar\rightarrow}.] – May 01 '19 at 12:26