Is it possible to draw a (simple) commutative diagram using MathJax?

Amscd doesn't seem to work here on math.SE.

M(N)WE:

$$ \begin{CD} K(X) @>{ch}>> H(X;\mathbb Q);\\ @VVV @VVV \\ K(Y) @>{ch}>> H(Y;\mathbb Q); \end{CD} $$

Edit: [A.K. May 7, 2013]

As pointed elsewhere by Davide, this can be remedied now that MathJax 2.2 [beta] is deployed, by adding \require{AMScd}:

$$\require{AMScd} \begin{CD} K(X) @>{ch}>> H(X;\mathbb Q);\\ @VVV @VVV \\ K(Y) @>{ch}>> H(Y;\mathbb Q); \end{CD}$$

share
1  
As a temporary workaround, I think that you should be able to adapt Arturo's solution here to your needs. (maybe replacing \rightarrow by \longrightarrow looks a bit better, but I haven't tried). –  t.b. Jun 9 '11 at 14:15
1  
Sorry about all the edits and the bumps... I'm just excited to have new features! :-) –  Asaf Karagila May 6 '13 at 22:35
3  
@Asaf You're the least person I would have thought to get excited over commutative diagrams... –  Michael Greinecker May 6 '13 at 23:44
1  
@Michael: Point well made! Regardless, I'm always happy when the expressibility requires less hacks, and get more built-in support. –  Asaf Karagila May 6 '13 at 23:45
    
All this is very puzzling, to me. If people want to draw commutative diagrams, why don't they use software that's intended for drawing?? Writing code to define a picture seems strange. Even more strange than writing code to define a textual document. –  bubba May 7 '13 at 3:45
1  
@bubba commutative diagrams contain still a lot of text and you want the typography of your diagrams to match the typography of your main text. –  Michael Greinecker May 7 '13 at 5:16
1  
@bubba: because mathematicians don't work with MS Word most of the time, and they using external software is bothersome and annoying. The output in LaTeX is much cleaner, better, contains less mistakes, and it notifies you of any possible mistake. Since diagrams are not graphs and pie charts, but rather arrows and labels, there is no sense in adding an external software when LaTeX does an excellent work on its own (with the occasional help of prepared packages, of course). So mathematicians are used to working with just LaTeX, and they want to have that with MathJax as well. –  Asaf Karagila May 7 '13 at 7:53
    
@Asaf -- who said anything about MS Word?? –  bubba Jun 18 '13 at 16:11

5 Answers 5

up vote 10 down vote accepted

MathJax 2.2 beta was released recently, and it includes support for AMScd. I hope that we'll see this support on m.SE soon enough (recall that 2.1 beta was also tested on this site). We have Mathjax 2.2 beta deployed, although without AMScd support for now. Hopefully that too would be added soon enough.

While AMScd doesn't support diagonal arrows, it will make rectangular diagrams easier to draw.

Edit: As Davide Cervone points out, one can manually load AMScd by adding \require{AMScd} and using \begin{CD}...\end{CD}. One may want to consult the AMScd manual.

share

Here is the commutative diagram from Arturo's fix, touched up to use extensible arrows, and with some spacing tightened up a bit.

$$ \newcommand{\ra}[1]{\!\!\!\!\!\!\!\!\!\!\!\!\xrightarrow{\quad#1\quad}\!\!\!\!\!\!\!\!} \newcommand{\da}[1]{\left\downarrow{\scriptstyle#1}\vphantom{\displaystyle\int_0^1}\right.} % \begin{array}{llllllllllll} 0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\ \da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\ 0 & \ra{h_1} & 0 & \ra{h_2} & E & \ra{h_3} & F & \ra{h_4} & 0 & \ra{h_5} & 0 \\ \end{array} $$

The code is valid in both mathjax and latex. In latex, one should include the amsmath package to get extensible arrows, and I would also recommend less negative spacing (or use a better commutative diagram environment).

$$
\newcommand{\ra}[1]{\!\!\!\!\!\!\!\!\!\!\!\!\xrightarrow{\quad#1\quad}\!\!\!\!\!\!\!\!}
\newcommand{\da}[1]{\left\downarrow{\scriptstyle#1}\vphantom{\displaystyle\int_0^1}\right.}
%
\begin{array}{llllllllllll}
0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\
\da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\
0 & \ra{h_1} & 0 & \ra{h_2} & E & \ra{h_3} & F & \ra{h_4} & 0 & \ra{h_5} & 0 \\
\end{array}
$$
share
    
Interesting, thank you. And I didn't know, MathJaX supports \newcommand. –  Grigory M Jun 9 '11 at 16:43
2  
+1, this is a very clever solution to the issue of labeling! –  Zev Chonoles Jun 9 '11 at 16:56
    
This diagram code doesn't show up in Internet Explorer. Is there a fix for that? –  tomcuchta Jul 8 '11 at 22:29

It is possible to do (somewhat primitive) commutative diagrams using \array:

$$\begin{array}{ccccccccc} 0 & \xrightarrow{i} & A & \xrightarrow{f} & B & \xrightarrow{q} & C & \xrightarrow{d} & 0\\ \downarrow & \searrow & \downarrow & \nearrow & \downarrow & \searrow & \downarrow & \nearrow & \downarrow\\ 0 & \xrightarrow{j} & D & \xrightarrow{g} & E & \xrightarrow{r} & F & \xrightarrow{e} & 0\end{array}$$

Code:

\begin{array}{ccccccccc}
0 & \xrightarrow{i} & A & \xrightarrow{f} & B & \xrightarrow{q} & C & \xrightarrow{d} & 0\\

\downarrow & \searrow & \downarrow & \nearrow & \downarrow & \searrow & \downarrow & \nearrow & \downarrow\\

0 & \xrightarrow{j} & D & \xrightarrow{g} & E & \xrightarrow{r} & F & \xrightarrow{e} & 0
end{array}

I'm not sure it's possible to label diagonal arrows using this approach though.

share
1  
As far as I know amscd doesn't support diagonal arrows either, so this should be good enough for the moment. –  t.b. Jun 9 '11 at 14:19

I would modify Jack's answer slightly:

\newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex}
\newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex}
\newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}}
\begin{array}{c}
0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\
\da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\
0 & \ras{h_1} & 0 & \ras{h_2} & E & \ras{h_3} & F & \ras{h_4} & 0 & \ras{h_5} & 0 \\
\end{array}

$$ \newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex} \newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex} \newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}} \begin{array}{c} 0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\ \da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\ 0 & \ras{h_1} & 0 & \ras{h_2} & E & \ras{h_3} & F & \ras{h_4} & 0 & \ras{h_5} & 0 \\ \end{array} $$

This would also work in true $\rm\LaTeX$ except for one thing: the \rlap{\scriptstyle#1} would need to be \rlap{$\scriptstyle#1$}.

share

I have used presheaf in the past, it's really easy (if you know xypic) and comfortable to use.

share

You must log in to answer this question.

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