4

In a previous question Gonzalo Medina and Peter Grill gave a solution to replace the \to arrow by an arrow generated by TikZ.

For some people using TikZ in commutative diagrams, it would be perhaps desirable to uniformize the tips of some common arrows (\to, \leftarrow, \mapsto,\rightsquigarrow,etc.)

One can extend Peter Grill's solution in the question above (Gonzalo Medina's solution provides an arrow that resizes, but since arrows other than \to are less commonly used in super- or subindices, here the simplest solution is used) to obtain a\leftarrow as in the code show bellow. The problem is with the \mapsto arrow, for I cannot produce it: its vertical part is too large, as shown in the picture bellow.

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}

% Tikz part
%********************************************************************
\usepackage{tikz}
\usetikzlibrary{mindmap,trees}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}
\makeatletter
\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\makeatother
%
\tikzset{>=stealth',every on chain/.append style={join},
         every join/.style={->}}
\tikzstyle{labeled}=[execute at begin node=$\scriptstyle,
   execute at end node=$]
\usepackage{tikz-cd}
\usetikzlibrary{arrows}
\tikzset{
commutative diagrams/.cd,
arrow style=math font,
diagrams={>=stealth}} 
%*******************************************************
%redefining the arrows
%*******************************************************
\newcommand{\MyOt}[1][]{\mathbin{\tikz \draw [#1, stealth-] (0,0) (0,0.5ex) -- (1.0em,0.5ex);}}
\newcommand{\MyTo}[1][]{\mathbin{\tikz \draw [-stealth, #1] (0,0) (0,0.5ex) -- (1.0em,0.5ex);}}
\newcommand{\MyMapsto}[1][]{\mathbin{\tikz \draw [|-stealth, #1] (0,0) (0,0.5ex) -- (1.0em,0.5ex);}}

\let\OldTo\to
\let\OldOt\leftarrow
\let\OldMapsto\mapsto
\renewcommand{\to}{\MyTo}%
\renewcommand{\leftarrow}{\MyOt}
\renewcommand{\mapsto}{\MyMapsto}
\newcommand{\where}{\quad\mbox{where}\quad}
%************************************************** 

\begin{document}    

\begin{align*}
f: A\to B & \quad \rightsquigarrow \quad f^*:A^*\leftarrow B^*\where  f^*:\phi \mapsto \phi\circ f\qquad&\mbox{(with TikZ)} \\
f: A\OldTo B &\quad \rightsquigarrow \quad f^*:A^*\OldOt B^* \!\!\where f^*:\phi \OldMapsto \phi\circ f\qquad &\mbox{(ordinary)}\\
\end{align*}

\end{document}

The result is: enter image description here

7
  • The arrows should be declared by \mathrel, not \mathbin
    – egreg
    Commented Oct 22, 2012 at 21:16
  • I just substituted \mathbin by \mathrel: same result.
    – c.p.
    Commented Oct 22, 2012 at 21:23
  • 3
    Well, \mathrel or \mathbin influence the spacing around the arrows, not the arrows themselves. By the way, if I had to express a preference, I'd point to the second row.
    – egreg
    Commented Oct 22, 2012 at 21:24
  • 1
    Though, I'm a loyal TikZ foot soldier, I think such a replacement is only justified if the arrows are unquestionably prettier than the usual ones since it will bring a large overhead (unless you protocol or use the basic layer drawing commands etc.)
    – percusse
    Commented Oct 22, 2012 at 23:08
  • 1
    To fix the height of the mapsto, you could draw the vertical line yourself: \newcommand{\MyMapsto}[1][]{\mathbin{\tikz \draw [-stealth, cap=round, #1] (0,0) (0,0.97ex) -- (0,0.035ex) (0,0.50ex) -- (1.0em,0.50ex);}}. Might still need some more tweaking of the vertical line though. I am not sure what you want to change regarding the \rightsquigarrow. Commented Oct 23, 2012 at 1:03

1 Answer 1

1

Does this help? I put together a composite \mapsto, by adding a vertical rule to a stealth arrow (outside of tikz) EDIT: Now it works in \scriptstyle

\documentclass{article}
% See http://tex.stackexchange.com/questions/14386/importing-a-
%            single-symbol-from-a-different-font
% Setup the matha font (from mathabx.sty)
\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * matha
      <10.95> matha10 <12> <14.4> <17.28> <20.74> <24.88> matha12
      }{}
\DeclareSymbolFont{matha}{U}{matha}{m}{n}

% Define a subset character from that font (from mathabx.dcl)
% to completely replace the \subset character, you can replace
% \varsubset with \subset

\DeclareMathSymbol{\varleftarrow}{3}{matha}{"D0}
\DeclareMathSymbol{\varrightarrow}{3}{matha}{"D1}

\usepackage{scalerel}

\def\Newmapsto{%
  \mbox{$\displaystyle\rule{.3ex}{0ex}\rule[.2ex]{.075ex}{.8ex}\rule{-.8ex}{0ex}%
  \varrightarrow$}}%
\def\newmapsto{%
\scalerel*{\Newmapsto}{\scaleobj{1.2}{\mapsto}}%
}
\begin{document}
\[
A \mapsto B \qquad A \newmapsto B \scriptstyle \qquad 
A \mapsto B \qquad A \newmapsto B
\]
\end{document}

enter image description here


Thanks to varsop for the very effective and simpler alternative using \joinrel:

\documentclass{article}
% See http://tex.stackexchange.com/questions/14386/importing-a-
%            single-symbol-from-a-different-font
% Setup the matha font (from mathabx.sty)
\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * matha
      <10.95> matha10 <12> <14.4> <17.28> <20.74> <24.88> matha12
      }{}
\DeclareSymbolFont{matha}{U}{matha}{m}{n}

\DeclareMathSymbol{\varleftarrow}{3}{matha}{"D0}
\DeclareMathSymbol{\varrightarrow}{3}{matha}{"D1}
\DeclareMathSymbol{\mapstochar} {3}{matha}{"DE} 
\def\newmapsto{\mapstochar\joinrel\kern1.7pt\varrightarrow}

\begin{document}
\[
A \mapsto B \qquad A \newmapsto B \scriptstyle \qquad 
A \mapsto B \qquad A \newmapsto B
\]
\[
\scriptscriptstyle A \mapsto B \qquad A \newmapsto B
\]
\end{document}

enter image description here

2
  • 1
    One can also achieve the same result without building a new vertical rule. Just perform the same steps as in the answer until \DeclareMathSymbol{\varrightarrow}{3}{matha}{"D1} and then add \DeclareMathSymbol{\mapstochar} {3}{matha}{"DE} and moreover \def\newmapsto{\mapstochar\joinrel\varrightarrow}. \joinrel does the trick!
    – varsop
    Commented Apr 11, 2018 at 10:12
  • @varsop That is a very clever approach with which I was not familiar. However, I note that, without some other adjustment, the placement of the vertical bar is not at the far end of the arrow, as it should be. However, \def\newmapsto{\mapstochar\joinrel\kern1.5pt\varrightarrow} seems to work. Commented Apr 11, 2018 at 10:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .