# How to draw a commutative diagram?

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}$$

• 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
• 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. May 7 '13 at 3:45
• @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. May 7 '13 at 5:16
• @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 Mod
May 7 '13 at 7:53
• @Asaf -- who said anything about MS Word?? Jun 18 '13 at 16:11
• I think it would be the same for all diagrams, not just commutative ones. Jan 22 '15 at 23:59
• @bubba As Michael Greinecker says: it can be really hard to match fonts in drawing programs sometimes. I once tried to use SolidWorks to prepare - in my mind - magnificent diagrams for mathematics expositions: SolidWorks is a CAD suite and produces the most stunning renderings of 3D geometry. But the fonts it uses are crap and overall the result looked simply dreadful - so a great deal of work wasted. Apr 17 '15 at 11:58
• @WetSavannaAnimalakaRodVance --SolidWorks uses whatever fonts you tell it to use. It can use any Windows font, so something like Latin Modern Math would be suitable if you're trying to match fonts in a traditional LaTeX document. Aug 1 '15 at 11:23
• @AsafKaragila -- the whole point is that LaTeX does not do an excellent job on its own. Look at all the posts on TeX.Stackexchange from people struggling to draw things using Tikz. Aug 1 '15 at 11:28
• @bubba Interesting. I don't pretend to have mastered SolidWorks, but it just didn't seem to be a very smooth fit at the time. I was struck by its amazing output, but it's not really meant for this kind of thing - indeed you need to think about geometry very differently in SolidWorks from what you would normally do in mathematics and this is wholly appropriate: mechanical design needs geometry to be defined by physical contact and one can't simply behest an object to have arbitrary co-ordinates of orientation as one does in thought experiments or in mathematical reasoning. Aug 1 '15 at 11:39
• @WetSavannaAnimalakaRodVance -- well, actually, most CAD systems do allow you to place objects with arbitrary locations and orientations, though typically they don't encourage this. I'm certainly not claiming that CAD systems are always the most suitable drawing tool, though. I think different types of drawings/diagrams require different apps. Sure, you can do everything in TeX or Tikz if you try hard enough, but personally I think it's goofy to struggle to do everything using one tool. That's why we have screw-drivers in addition to hammers. Aug 1 '15 at 13:41

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

• Are there any web pages that do similar things for tikzcd??
– user537667
Jul 11 '18 at 2:25
• @user537667 Yes, for example this one Feb 10 '20 at 8:11

A potential solution to posting a commutative diagram is to include it as an image. This can allow you have diagonal arrows. :) Here's my workflow for creating commutative diagrams in LaTeX using TikZ. A minimal working LaTeX document looks like this:

\documentclass{standalone}
\usepackage{tikz-cd}

$$\begin{document} \begin{tikzcd} C \arrow[d,hookrightarrow] \arrow[dr,hookrightarrow,bend left=50,dashed] & & \\ Y \arrow[r,hookrightarrow] \arrow[d,twoheadrightarrow] & X \arrow[d,twoheadrightarrow,dashed] \arrow[dr,twoheadrightarrow,bend left=50] & \\ B \arrow[r,hookrightarrow,dashed] & Y' \arrow[r,twoheadrightarrow,dashed] & A \end{tikzcd} \end{document}$$


Then you can compile this document however you do, zoom into your commutative diagram, take a screenshot, and crop the image.

Or you can avoid taking a screenshot and cropping if you have the other appropriate tools. On my Linux OS I can do this at the command line. I've used this technique on my website, where it's better to have the diagrams be PNG images with transparent backgrounds. For the PDF of the diagram named main.pdf, use

pdftoppm -png -r 600 main.pdf > white.png
convert white.png -fuzz 10% -transparent white transparent.png


That 600 corresponds to the resolution of the image white.png.