[Tex/LaTex] Matching arrowheads in TikZ with math mode arrowheads

arrowstikz-pgf

TikZ is great at drawing diagrams but there is one feature which I find quite annoying and that's the fact that the default arrowhead provided by TikZ does not necessarily respect the math mode in whichever font you are using. I know that
the TikZ library arrows lets you chose between several different types of arrowheads but none of which offers the same arrowhead as the one drawn in math mode.

When drawing a diagram in TikZ I want the arrowheads to match arrowheads drawn by commands like \to or \xrightarrow{foo}.

Does anyone know how to fix this?


As suggested by Andrew Stacey in the comments below, I should really provide you with an example of what I am talking about.

Using the following code:

An arrow tip produced by TikZ:  
\begin{tikzpicture}
\node (A) at (0,0){$A$};
\node (B) at (1,0){$B$.};

\path (A) edge[->] node[midway,above]{$f$} (B);
\end{tikzpicture}

An arrow tip produced by \texttt{amsmath}: $A \xrightarrow{f} B$.  

I get the following output:

enter image description here

I want these two arrowheads to be identical.

Best Answer

I have prepared a comprehensive set of arrow tips matching the Computer Modern arrows, and posted it on CTAN (along with some discussion on this issue and some more stuff that might be useful for mathematical diagrams).

My arrow tips are not as precise as Christian's, but they are about as good as one can get using a few line strokes (as opposed to filling a region), and in practice I find the result good enough.

Here is a comparison (Computer Modern above, tikz-drawn arrow below).

\documentclass{article} 
\usepackage{tikz,tikz-cd,graphicx} 
\begin{document} 
\noindent\hspace{2mm} \scalebox{20}{$\hookrightarrow$} 
\vspace{2cm} 
\tikz \draw[line width=8pt,cm right hook-cm to] (0,0) to (7,0); 
\end{document}

enter image description here