8

I'm loving using tikz-cd to draw compiler correctness diagrams, but I can't manage to get quite the same arrows for relations that I'm using in the text. In particular, I'm not sure how to get \Mapsto in a tikz-cd diagram.

I did try combining arrow options to get \Mapsto to work:

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
  M \rar[Rightarrow] \dar[maps to] & N \dar[maps to, Rightarrow] \\
  M' \rar[Rightarrow, maps to] & N'
\end{tikzcd}

\end{document}

But this wound up less than satisfactory (on TeXLive 2013):

Garbled arrows

As you can see, depending on the order I give the arguments, the bar is either missing (there should be one on the N-to-N' arrow) or comically huge. I assume this is a bug? Any known workaround?

2
  • 1
    tikz-cd doesn’t provide a maps to arrow for a doubled line, the arrows | and cm | (which is internally used here) does use the “doubled” line width and not the simple one. Looks like you need either to correct the arrow code for cm |/|` or introduce a new arrow. Sep 26, 2013 at 17:53
  • Well, according to the tikz-cd manual, the arrows with alternate names (one of which is mapsto/maps to) “can be superimposed with other arrows.” If it's not intended that I can mix the maps to and Rightarrow options, I think that's a documentation bug at any rate. In any case, I guess I'm shy about diving into arrow code and hoping there's a simpler way. Also IIUC there's an impedance mismatch between tikz-cd arrows, which combine the specification of the path with that of the arrow tip (I guess this is the source of the maybe-bug?), and tikz arrows (really just tips?). Sep 26, 2013 at 18:04

2 Answers 2

7

I’ve taken a look at the \Mapsto arrow from the stmaryrd package which I have used as the model for the redefinition of the cm | arrow that obeys a double line.

The 3.3 value is approximated so that the vertical line is as wide as the implies arrow (similar to how \Mapsto looks). The original maps to arrow as seen in the example has a rather short bar.

Code

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\expandafter\let\csname pgf@arrow@code@cm |\endcsname\relax
\makeatletter
\pgfarrowsdeclare{cm |}{cm |}{%
  \[email protected]\pgflinewidth
  \ifdim\pgfinnerlinewidth>0pt\relax
    \pgfmathaddtolength\pgfutil@tempdima{-.5*\pgfinnerlinewidth}%
  \fi
  \pgfarrowsleftextend{+-\pgfutil@tempdima}%
  \pgfarrowsrightextend{+\pgfutil@tempdima}%
}{%
  \ifdim\pgfinnerlinewidth=0pt\relax
    \pgfutil@tempdima4\pgflinewidth
  \else
    \pgfutil@tempdima\pgflinewidth
    \advance\pgfutil@tempdima-\pgfinnerlinewidth
    \pgfsetlinewidth{\pgfutil@tempdima/2}%
    \multiply\[email protected]\relax
  \fi
  \pgfsetdash{}{+0pt}%
  \pgfsetroundcap
  \pgfpathmoveto{\pgfqpoint{0pt}{-\pgfutil@tempdima}}%
  \pgfpathlineto{\pgfqpoint{0pt}{\pgfutil@tempdima}}%
  \pgfusepathqstroke
}
\makeatother
\pgfqkeys{/tikz/commutative diagrams}{
  Maps to/.style={
    /tikz/commutative diagrams/Rightarrow,
    /tikz/commutative diagrams/maps to},
  Maps from/.style={
    /tikz/commutative diagrams/Leftarrow,
    /utils/exec=\pgfsetarrowsend{cm |}}
}
\begin{document}
\begin{tikzcd}
  M  \rar[Maps from] \dar[maps to]  & N \dar[Maps to] \\
  M' \rar[Maps to]    & N'
\end{tikzcd}
\end{document}

Output

enter image description here

3
  • Cool, thanks! It's probably a bit much to ask that I be able to understand the code fully :-) but I take it the crux is checking \pgfinnerlinewidth, which will be zero for a single arrow (line) but positive for a double? Sep 26, 2013 at 18:22
  • 1
    @LukeMaurer Oh, me stupid. I have used \ifx where I should have used \ifdim to compare dimens. With the updated code, the single line maps to bar is the same as before (still a little shorter in comparison with the doubled one but well …). Sep 26, 2013 at 19:12
  • This doesn't work as of tikz 3.0.1a, but (see my new answer) there's a much easier solution: tikz-cd 0.9 has Mapsto built in. Mar 22, 2017 at 6:27
6

As of version 0.9c (if not earlier), tikz-cd now provides a Mapsto arrow.

You must log in to answer this question.

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