# \to arrow with tikz or tikzcd

I want to replace the usual \to short arrow by an (approximately) equally short arrow with a nicer tip. Although completely newbie, I'm fond of tikz-methods and I write all my commutative diagrams with tikzcd. But using this tool inside the text renders a longer arrow. So far, I've just found the very unelegant solution

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{arrows}
\tikzset{
commutative diagrams/.cd,
arrow style=tikz,
diagrams={>=stealth}}
\begin{document}
$\alpha: A$ \begin{tikzcd}[column sep=small]\arrow{r}\!\!\!\!\!\! &     \!\!\!\!\!\!\end{tikzcd} $B$
\end{document}


This renders:

This won't allow me to redefine the command \to. I'm sure there is a better way to implement this.

Using \mathchoice you can define a symbol that will adapt to the surrounding style in math mode; below there's an example of such a definition and a comparison between the newly defined \myto and the standard \to commands (perhaps some more fine tuning can be done);:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\newlength\mytoraise
\newlength\mytolength

\def\mytoi{\mathrel{\raisebox{\mytoraise}{%
\begin{tikzpicture}
\draw[-stealth] (0,0ex) -- (\mytolength,0ex);
\end{tikzpicture}}}}
\def\myto{\mathchoice
{\setlength\mytoraise{0.55ex}\setlength\mytolength{9pt}\mkern1mu\mytoi\mkern1mu}
{\setlength\mytoraise{0.55ex}\setlength\mytolength{8pt}\mkern1mu\mytoi\mkern1mu}
{\setlength\mytoraise{0.4ex}\setlength\mytolength{7pt}\mkern2mu\mytoi\mkern2mu}
{\setlength\mytoraise{0.25ex}\setlength\mytolength{5.5pt}\mkern1mu\mytoi\mkern1mu}
}

\begin{document}

${\displaystyle A\myto B}\quad A\myto B\quad \lim_{A\myto B}\quad A_{\lim_{A\myto B}}$

${\displaystyle A\to B}\quad A\to B\quad \lim_{A\to B}\quad A_{\lim_{A\to B}}$

\end{document}


An a variation allowing an optional argument to specify attributes (I also added a vertical scale factor so the arrow tip looks proportional in the styles \scriptstyle and \scriptscriptstyle):

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows}

\newlength\mytoraise
\newlength\mytolength
\newcommand\yscale{1}

\newcommand\mytoi[1][]{\mathrel{\raisebox{\mytoraise}{\scalebox{1}[\yscale]{%
\begin{tikzpicture}
\draw[-stealth,#1] (0,0ex) -- (\mytolength,0ex);
\end{tikzpicture}}}}}
\newcommand\myto[1][]{\mathchoice
{\setlength\mytoraise{0.55ex}\setlength\mytolength{9pt}\mkern1mu\mytoi[#1]\mkern1mu}
{\setlength\mytoraise{0.55ex}\setlength\mytolength{8pt}\mkern1mu\mytoi[#1]\mkern1mu}
{\setlength\mytoraise{0.4ex}\setlength\mytolength{7pt}%
\renewcommand\yscale{.8}\mkern2mu\mytoi[#1]\mkern2mu}
{\setlength\mytoraise{0.25ex}\setlength\mytolength{5.5pt}%
\renewcommand\yscale{.7}\mkern1mu\mytoi[#1]\mkern1mu}
}

\begin{document}

${\displaystyle A\to B}\quad A\to B\quad \lim_{A\to B}\quad A_{\lim_{A\to B}}$

${\displaystyle A\myto B}\quad A\myto B\quad \lim_{A\myto B}\quad A_{\lim_{A\myto B}}$

${\displaystyle A\myto[red] B}\quad A\myto[blue] B\quad \lim_{A\myto[orange] B}\quad A_{\lim_{A\myto[olive] B}}$

\end{document}


• Nice solution. Cannot I mark both solutions as the solution? I mean, this is more complete but the other was written first. Which fairness criterion shall apply here? – c.p. Oct 10 '12 at 0:55
• @JorgeCampos It's up to you; there has been some discussion about this on meta; see this question, for example. – Gonzalo Medina Oct 10 '12 at 0:59

## Update:

In the comments on drawing a Dashed down arrow, egreg provided an ingenious trick to simplify the resizing issue, by using \text{}:

## Further Enhancements:

• There seems to be slight spacing discrepancy at the beginning of the arrow, which is more evident in the last example. I do not know what is causing that.

## Code

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\MyTo}[1][]{\mathrel{\text{\tikz \draw [-stealth, #1] (0,0) (0,0.5ex) -- (0.9em,0.5ex);}}}

\let\OldTo\to
\renewcommand{\to}{\MyTo}%

\begin{document}
$\alpha: A \MyTo[red] B \MyTo[blue,-latex] C \MyTo[blue,->] D$

$\beta: A \to B$

$\gamma: A \OldTo B$ \quad original \verb|\to|

Testing math sizes:

$\alpha: A \OldTo B \quad M_{B \OldTo C} \quad L_{M_{\OldTo D}}$ \quad original \verb|\to|

$\alpha: A \MyTo[blue] B \quad M_{B \MyTo[blue] C} \quad L_{M_{\MyTo[blue] D}}$ \quad original \verb|\MyTo|
\end{document}


## Earlier Solution (does not resize):

You should probably just use your own command instead of replacing to, but if you do wish to redefine to you can use \renewcommand:

## Notes:

• I added an optional first parameter to \MyTo which allows you to pass in drawing options.

## Further Enhancements:

• As the width parameters such as 1.0em do not adjust based on the math style, one should use \mathchoice to adjust this (See Gonzalo Medina's answer).

## Code:

\documentclass{article}
\usepackage{tikz}

\newcommand{\MyTo}[1][]{\mathrel{\tikz \draw [-stealth, #1] (0,0) (0,0.5ex) -- (0.9em,0.5ex);}}

\let\OldTo\to
\renewcommand{\to}{\MyTo}%

\begin{document}
$\alpha: A \MyTo[red] B \MyTo[blue,-latex] C \MyTo[blue,->] D$

$\beta: A \to B$

$\gamma: A \OldTo B$ \quad original \verb|\to|
\end{document}