[Tex/LaTex] How to draw the “snake” arrow for the connecting homomorphism in the snake lemma

diagramstikz-pgfxy-pic

How does one draw the "snake" arrow for the connecting homomorphism when using the snake lemma?

I'd also be interested in drawing similar arrows act as "carriage returns" when considering a long exact sequence of cohomology.

I'm sorry if this is a little vague. I'm hoping that someone who's already done this might be willing to share a template. I'd prefer things in xy-pic, but would also be interested to see other ways it can be done.

Best Answer

I'm glad you said:

but would also be interested to see other ways it can be done.

because I don't use xy-pic anymore (fantastic though it was when in the pre-TikZ days). Here's my best shot with TikZ.

Here's the result:

snake lemma

The code follows. A couple of comments on my choices. None of the libraries loaded is strictly necessary, but I felt that the matrix and calc libraries made for cleaner code and I don't like the standard arrows so the arrows library makes it look better. I labelled the matrix entries explicitly, which isn't strictly necessary, again because I felt it made the code easier to read. I shifted the horizontal of the snake arrow upwards to avoid the labels on the downward arrows. The key effect, of rounded corners, is the (wait for it) rounded corners option to the final path. The amsmath package is purely to get the \DeclareMathOperator command for \coker (\ker is already defined in latex). Again, this could easily be done another way.

(Added in edit) As pointed out in the comments, in the original code the arrow from the lower 0 to the A' was slightly slanted. This was because the prime adds a little height to the node containing the A' meaning that the natural targets for the arrow (east of 0 and west of A') aren't in a straight line. There are numerous ways to fix this, the one I chose was to align the nodes in the matrix according to their centres instead of their baselines.

Since this answer has proved so popular, I got a little more perfectionistic about it! I decided that the grey horizontal arrows (kernels and cokernels) were a little high for my taste. So I chose the 'mid' targets. Putting these in with the 'edge' command resulted in bizarre extra arrow heads (try it) so I had to put each one in as a separate \draw command. I also changed the spacing of the grid so that the spaces were measured from the centres of the nodes rather than their edges.

Idle thoughts on this version: I ought to be able to put the mid east/west targets in the edge commands. I also wondered if there was some neat way to say "make sure all the arrows are strictly horizontal" rather than using the explicit targets. I wondered about using the "coordinates at intersections" syntax but would need to play with it a little and I'm not sure it would be shorter.

Edit: 2012-09-10 I've just learnt about the asymmetrical rectangle of the tikz-cd package and it answers my idle thoughts above so I thought - as this is in many ways my "show case" answer - I'd update this to take advantage of it.

\documentclass{article}
\thispagestyle{empty}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{%
  matrix,%
  calc,%
  arrows%
}

\DeclareMathOperator{\coker}{coker}

\begin{document}
\begin{tikzpicture}[>=triangle 60]
\matrix[matrix of math nodes,column sep={60pt,between origins},row
sep={60pt,between origins},nodes={asymmetrical rectangle}] (s)
{
&|[name=ka]| \ker f &|[name=kb]| \ker g &|[name=kc]| \ker h \\
%
&|[name=A]| A' &|[name=B]| B' &|[name=C]| C' &|[name=01]| 0 \\
%
|[name=02]| 0 &|[name=A']| A &|[name=B']| B &|[name=C']| C \\
%
&|[name=ca]| \coker f &|[name=cb]| \coker g &|[name=cc]| \coker h \\
};
\draw[->] (ka) edge (A)
          (kb) edge (B)
          (kc) edge (C)
          (A) edge (B)
          (B) edge node[auto] {\(p\)} (C)
          (C) edge (01)
          (A) edge node[auto] {\(f\)} (A')
          (B) edge node[auto] {\(g\)} (B')
          (C) edge node[auto] {\(h\)} (C')
          (02) edge (A')
          (A') edge node[auto] {\(i\)} (B')
          (B') edge (C')
          (A') edge (ca)
          (B') edge (cb)
          (C') edge (cc)
;
\draw[->,gray] (ka) edge (kb)
               (kb) edge (kc)
               (ca) edge (cb)
               (cb) edge (cc)
;
\draw[->,gray,rounded corners] (kc) -| node[auto,text=black,pos=.7]
{\(\partial\)} ($(01.east)+(.5,0)$) |- ($(B)!.35!(B')$) -|
($(02.west)+(-.5,0)$) |- (ca);
\end{tikzpicture}
\end{document}