5

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.

7

I'm not entirely sure if it is wise to do this (perhaps something breaks?), but you certainly can do this by redefining \to using \mathchoice:

\documentclass{article}
\renewcommand\to{\mathchoice{\longrightarrow}{\rightarrow}{\rightarrow}{\rightarrow}}
\begin{document}

  So we have a map $A \to B$ and we have a map
  \[ C \to D.  \]

\end{document}

Here is the output:

enter image description here

I have made it so that \to expands to \longrightarrow in display mode and otherwise to \rightarrow for text, script and scriptscript styles - in fontmath.ltx the \to command is defined as \let\to\rightarrow.

Have a look at The mysteries of \mathpalette for a description of the \mathchoice and \mathpalette commands.

  • 2
    I'd use \rightarrow instead of \realto, no need for the \let. – egreg May 1 at 10:40
  • Although doing the same for \mapsto would require a \let-construction, would it not? – SvanN May 1 at 11:24
  • 1
    @SvanN You could either do something like \let\realmapsto\mapsto and then \renewcommand\mapsto{\mathchoice{\longmapsto}{\realmapsto}{\realmapsto}{\realmapsto}} or instead use \renewcommand\mapsto{\mathchoice{\longmapsto}{\mapstochar\rightarrow}{\mapstochar\rightarrow}{\mapstochar\rightarrow}}. [If you look in fontmath.ltx you will find \def\mapsto{\mapstochar\rightarrow}.] – Andrew May 1 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.