Commutative Diagrams in TeX

Paul Taylor

since 1986

This is a macro package for drawing so-called "commutative" diagrams in category theory and related subjects.

The macros and the manual

Unlike many other packages there is no "installation procedure" - you just copy the macros themselves to your TEX macros directory.
The manual is available in several formats: LaTeX source, PDF, DVI, 600dpi A4 PostScript and 600dpi A5 PS booklet. The "booklet" form requires a two-sided printer with A4 paper; if you don't have such a thing, don't bother taking the file.
If you have not already done so, please register as a user by sending a message to pt @ cs.man.ac.uk with the words "commutative diagrams" in the subject line.
I have also written some macros for proofs and other things.

Diagonal arrows, PostScript and PDF

TEX itself and its basic output format (DVI) were designed by Donald Knuth to place letters and symbols from a variety of typefaces on an orthogonal grid, an idea that goes back to Gutenberg's original "movable type" printing press. This means that there is no natural way of drawing diagonal lines or rotating text.
Though DVI has the merit of simplicity, most complex documents nowadays in both the open-source and commercial worlds are distributed in Adobe's PostScript or PDF formats. In particular, the commonest way of printing (the DVI output from) TEX documents is to use Tomas Rokicki's program dvips.
PostScript and PDF have a much more general coordinate system than TEX has, and it is very easy to rotate blocks of text. The diagrams package was designed in 1992 to take advantage of this feature of PostScript and (from 2002) PDF. It was always intended to be used in this way, although only in 2004 was the default changed to use this.
Unfortunately, because of the inappropriately set optional behaviour, many users were not enjoying any of the benefits of the package. They were instead using the obsolete pre-1992 code (see below); this generated LATEX-style arrows, that had incompatible arrowheads and didn't meet the objects to which they were supposed to point.

There are other graphical packages, including several that are also used to draw categorical diagrams, that draw diagonal lines in other ways, some of which are understood by xdvi. Like LATEX's picture environment, they do this by juxtaposing many characters (such as diagonal line-segments or dots) from special fonts. These fonts need to be distributed and installed along with the macro packages themselves.
My diagrams package, on the other hand, needs no special fonts, and there is just the macro package itself to install. It achieves the same generality of diagonal arrows as it has horizontal ones by taking advantage of the method that most people use to print their documents. This design decision was taken following consultation with users, and I have always remained convinced that it was the correct one.
The method was adapted to pdftex. If xdvi or other programs implemented extensions to DVI to rotate boxes, it could be used for them too.

DVI previewers

DVI previewers such as xdvi and YAP do not understand the fragments of PostScript that are used to rotate the arrows, so what should be diagonal arrows appear horizontal instead. This behaviour is automatically corrected when you use dvips to print the document.
If, for some reason, you need to use xdvi or yap to display documents containing diagonals, you can still make use of the obsolete code. Use the command
\usepackage [UglyObsolete,tight,heads=LaTeX] {diagrams}
to load the diagrams package.

Please do not use the obsolete code for publication.

Previous generations understood that you had to understand what tools did and how they worked. Indeed, there was a saying that "bad workmen blame their tools". In the computer age, maybe even more so than in the pre-scientific one, people expect things to "just work", i.e. by magic, without understanding anything.
The pre-1992 pure DVI code in the diagrams package was a useful tool in its day, and I still try to make most of my diagrams work with it. However, if you wish to make extensive use of it, you too will have to understand how it works, and make the manual adjustments that are necessary to make up for the lack of magical programming behind it.
Firstly, since pure DVI cannot rotate characters, only the standard LATEX arrowheads are available for diagonals, so you should only use the heads=LaTeX option, and not (for example) heads=vee.
Second, since it uses LATEX's diagonal line and arrow characters, the only slopes that are allowed are those with numerator and denominator at most 4. However, since the package rounds slopes to simple rationals anyway (even in the "PostScript" code), this is not usually a problem in small diagrams.

But there is a more serious problem than this.
The package makes two "passes" when constructing each diagram: one in which it constructs a "matrix" from the data that you type, and a second in which it takes this matrix apart and stretches each of the arrows to meet its endpoints.
The obsolete "pure DVI" code constructs diagonal lines entirely in the first pass and does not stretch them in the second pass. It just makes a guess at the appropriate length, based on the width and height options for the diagram.

You should always choose the appropriate width and height yourself.

By default, the rows and columns of the diagram are loose - they stretch in the same way as any other matrix or table, and the "PostScript" code corrects for this. This default was chosen to make the package "just work", but diagrams look better if they are of a uniform regular size.
Since the obsolete pure DVI code does not make the necessary correction in the second pass, you have to make sure that its first guess is correct, by setting the width and height yourself, and making the diagram tight. When you set the tight option, you will find at first that the object labels sometimes overprint. The package generates error messages to tell you where this happens, and makes a suggestion for the appropriate size (common height and width), although this is usually too big.
Sometimes you will also need to adjust the shortfall of any arrows that point at large object labels, i.e. the distance between the end of the arrow and the object.

Finally, you may ask why I don't "fix" this code. Indeed I have looked into doing so several times. The answer is quite simply that the small benefit that would accrue from rewriting it does not justify the labour that would be needed. Not only is it much simpler to rotate horizontal arrows, but the the results are also far superior.

Arrowheads used in my book

You will see that the diagrams in my book Practical Foundations of Mathematics have arrowheads compatible with those of TEX's ordinary \rightarrow. This was done by modifying the MetaFont source of \rightarrow to reduce its shaft to nothing, ie to make it just an arrowhead.
I regret that I will not be releasing this MetaFont code, or PK files derived from it, because I am not prepared to undertake the support work that would be necessary afterwards. (Not even if you "promise to keep it to yourself", as you will inevitably release DVI files into the world containing references to these characters, obliging me to provide PK files to your readers, and explain to them why they keep getting checksum errors from dvips.)
However, if you are intending to create a new symbols font yourself (to follow the "St. Mary Road" fonts), and undertake the necessary support work, I will be very pleased to give you the MetaFont source for these arrowheads and the other new symbols that are introduced in the book. I now have these in a form that's compatible with teTeX.

Features introduced since September 1992

See also the top of the source file for bug fixes and adjustments to the positioning of things.

3.91 Released 1 September 2006

3.90 Released 11 April 2004

PostScript mode made default.

3.89 Released 7 July 2002

Added support for pdftex, which is recognised automatically.

3.88 Released 1 September 2000

3.87 Released 1 September 1999

This version was used for the absolutely final 1200dpi PostScript copy of the book, as it was handed over to CUP in December 1998.
The only change was a 0.2pt fudge to the positioning of the components of arrows. Previously a lot of tweaking had been done in this department.

3.86 Released 1 September 1998

3.85 Released 20 August 1997

3.84 Released 2 September 1996

Provided \NWclck etc 2-cell arrows.

3.83 Released 18 May 1995

3.81 Released 18 July 1994

Earlier Version numbers