There are two approaches to the construction of commutative diagrams
described here. The first approach, and the simplest, treats
commutative diagrams like fancy matrices, as Knuth does in Exercise
18.46 of The TeXbook. This case is covered by the macro
\commdiag
,
which is an altered version of the Plain TeX macro \matrix
.
An example suffices to demonstrate this macro. The following
commutative diagram (illustrating the covering homotopy property; Bott
and Tu, Differential Forms in Algebraic Topology)
is produced with the code
$$\commdiag{Y&\mapright^f&E\cr \mapdown&\arrow(3,2)\lft{f_t}&\mapdown\cr Y\times I&\mapright^{\bar f_t}&X}$$
Of course, the parameters may be changed to produce a different effect. The following commutative diagram (illustrating the universal mapping property; Warner, Foundations of Differentiable Manifolds and Lie Groups) is produced with the code
$$\varrowlength=20pt \commdiag{V\otimes W\cr \mapup\lft\phi&\arrow(3,-1)\rt{\tilde l}\cr V\times W&\mapright^l&U\cr}$$
A diagram containing isosceles triangles is achieved by placing the apex of the triangle in the center column, as shown in the example (illustrating all constant minimal realizations of a linear system; Brockett, Finite Dimensional Linear Systems) which is produced with the code
$$\sarrowlength=.42\harrowlength \commdiag{&R^m\cr &\arrow(-1,-1)\lft{\bf B}\quad \arrow(1,-1)\rt{\bf G}\cr R^n&\mapright^{\bf P}&R^n\cr \mapdown\lft{e^{{\bf A}t}}&&\mapdown\rt{e^{{\bf F}t}}\cr R^n&\mapright^{\bf P}&R^n\cr &\arrow(1,-1)\lft{\bf C}\quad \arrow(-1,-1)\rt{\bf H}\cr &R^q\cr}$$
Other commutative diagram examples appear in the file
commdiags.tex
, which is distributed with this package.
In these examples the arrow lengths and line slopes were carefully
chosen to blend with each other. In the first example, the default
settings for the arrow lengths are used, but a direction for the arrow
must be chosen. The ratio of the default horizontal and vertical arrow
lengths is approximately the golden mean
the arrow direction closest to this mean is (3,2)
. In the second
example, a slope of
is desired and the default horizontal arrow length is 60 pt; therefore,
choose a vertical arrow length of 20 pt. You may affect the interline
glue settings of \commdiag
by redefining the macro
\commdiagbaselines
.
(cf. Exercise 18.46 of The TeXbook and the section on
parameters below.)
The width, height, and depth of all morphisms are hidden so that the
morphisms' size do not affect arrow positions. This can cause a large
morphism at the top or bottom of a diagram to impinge upon the text
surrounding the diagram. To overcome this problem, use TeX's
\noalign
primitive to insert a \vskip
immediately above or
below the offending line, e.g.,
`$$\commdiag{\noalign{\vskip6pt}X&\mapright^\int&Y\cr ...}'.
The macro \commdiag
is too simple to be used for more complicated
diagrams, which may have intersecting or overlapping arrows. A second
approach, borrowed from Francis Borceux's Diagram macros for
LaTeX, treats the commutative diagram like a grid of identically
shaped boxes. To compose the commutative diagram, first draw an equally
spaced grid, e.g.,
on a piece of scratch paper. Then draw each element (vertices and
arrows) of the commutative diagram on this grid, centered at each
grid point. Finally, use the macro \gridcommdiag
to implement your design as a TeX alignment. For example, the cubic
diagram
that appears in Francis Borceux's documentation can be implemented on
a 7 by 7 grid, and is achieved with the code
$$\harrowlength=48pt \varrowlength=48pt \sarrowlength=20pt \def\cross#1#2{\setbox0=\hbox{$#1$}% \hbox to\wd0{\hss\hbox{$#2$}\hss}\llap{\unhbox0}} \gridcommdiag{&&B&&\mapright^b&&D\cr &\arrow(1,1)\lft a&&&&\arrow(1,1)\lft d\cr A&&\cross{\hmorphposn=12pt\mapright^c}{\vmorphposn=-12pt\mapdown\lft f} &&C&&\mapdown\rt h\cr\cr \mapdown\lft e&&F&&\cross{\hmorphposn=-12pt\mapright_j} {\vmorphposn=12pt\mapdown\rt g}&&H\cr &\arrow(1,1)\lft i&&&&\arrow(1,1)\rt l\cr E&&\mapright_k&&G\cr}$$
The dimensions \hgrid
and \vgrid
control the horizontal and vertical spacing of the grid used by
\gridcommdiag
. The default setting for both of these dimensions
is 15 pt. Note that in the example of the cube the arrow lengths must
be adjusted so that the arrows overlap into neighboring boxes by the
desired amount. Hence, the \gridcommdiag
method, albeit more
powerful, is less automatic than the simpler \commdiag
method.
Furthermore, the ad hoc macro \cross
is introduced to allow the
effect of overlapping arrows. Finally, note that the positions of four
of the morphisms are adjusted by setting \hmorphposn
and
\vmorphposn
.
One is not restricted to a square grid. For example, the proof of Zassenhaus's Butterfly Lemma can be illustrated by the diagram (appearing in Lang's book Algebra) This diagram may be implemented on a 9 by 12 grid with an aspect ratio of 1/2, and is set with the code
$$\hgrid=16pt \vgrid=8pt \sarrowlength=32pt \def\cross#1#2{\setbox0=\hbox{$#1$}% \hbox to\wd0{\hss\hbox{$#2$}\hss}\llap{\unhbox0}} \def\l#1{\llap{$#1$\hskip.5em}} \def\r#1{\rlap{\hskip.5em$#1$}} \gridcommdiag{&&U&&&&V\cr &&\bullet&&&&\bullet\cr &&\sarrowlength=16pt\sline(0,1)&&&&\sarrowlength=16pt\sline(0,1)\cr &&\l{u(U\cap V)}\bullet&&&&\bullet\r{(U\cap V)v}\cr &&&\sline(2,-1)&&\sline(2,1)\cr &&\cross{=}{\sline(0,1)}&&\bullet&&\cross{=}{\sline(0,1)}\cr\cr &&\l{^{\textstyle u(U\cap v)}}\bullet&&\cross{=}{\sline(0,1)}&& \bullet\r{^{\textstyle(u\cap V)v}}\cr &\sline(2,1)&&\sline(2,-1)&&\sline(2,1)&&\sline(2,-1)\cr \l{u}\bullet&&&&\bullet&&&&\bullet\r{v}\cr &\sline(2,-1)&&\sline(2,1)&&\sline(2,-1)&&\sline(2,1)\cr &&\bullet&&&&\bullet\cr &&u\cap V&&&&U\cap v\cr}$$
Again, the construction of this diagram requires careful choices for the
arrow lengths and is facilitated by the introduction of the ad hoc
macros \cross
, \r
, and \l
. Note also that
superscripts were used to adjust the position of the vertices
Many diagrams may be typeset with the predefined macros that appear
here; however, ingenuity is often required to handle special cases.