%===============================================================% % % % Commutative Diagrams in TeX % % % % by Paul Taylor (Imperial College) % % % % 12 September 1989 % % % %===============================================================% \documentstyle[a4]{article} \title{Commutative Diagrams in \TeX} \author{{\bf Paul Taylor}\\ Department of Computing,\\ Imperial College of Science, Technology and Medicine,\\ 180 Queen's Gate, London SW7 2BZ \\ +44 71 589 5111 {\em ext.} 5057\\ {\tt}} \date{4 July 1990} \let\volx\relax % for ltugbot.sty \maketitle \begin{abstract} \noindent \TeX\ and \LaTeX\ have become standard as a way of writing papers in Computer Science, and are being adopted in Category Theory. Even in source form they are easier to compose and read than attempts to write mathematics in ASCII. In~Category Theory ``commutative diagrams'' are essential for a clear visual understanding of the paper, but the graphics capabilities of \TeX\ are so limited that it is very difficult to draw them nicely, if at all. This manual describes some methods which have been used for doing so, criticising them for either their source syntax or for the printed result (``semantics''), and sets out design criteria. Then the author's package is described, with examples. \end{abstract} %===============================================================% \input{diagrams} \input{mssymb} \makeatletter % I prefer paragraphs spaced rather than indented \parskip=2pt plus 2pt minus 1pt % and I don't like hypenation \spaceskip=.5em plus .6em minus .2em \pretolerance=2000 \binoppenalty=2000 \relpenalty=1500 % Penalty for splitting paragraphs \interlinepenalty=150 \predisplaypenalty=10000 \postdisplaypenalty=400 \@beginparpenalty=\predisplaypenalty \def\Id{{\rm id}} \def\Assl{{\rm assl}} \def\AMSTeX{{$\cal A\!M\!S$}-\TeX} \newenvironment{clean}{}{} \newenvironment{pageblock}% {\vbox\bgroup}% {\egroup} \newcommand{\bsl}{$\backslash$} \makeatother %================================================================= % % verbatim array % %================================================================= \makeatletter % This defines two new LaTeX environments: verbarray and verbdiag. % The first is like the verbatim array, except that it treats each % cell individually, centering the text within aligned &s. The two % arguments specify the text to be used for & and \\. Because of the % eager parsing at the beginning of a cell, \relax is needed before % commands that expand to anything other than their own text. % For example, % \begin{verbarray}{\ \&\ }{\ \string\\ \ } % A&\relax\rTo^f&B\\ % \relax\dTo^g&&\relax\dTo^h\\ % C&\relax\rTo^k&D % \end{verbarray} % produces the contents of a simple diagram. % The second packages this to produce a verbatim diagram, ie it encloses % the text in ``$$\begin{diagram}'' and ``\end{diagram}''. Any text which % follows ``\begin{verbdiag}'' on the same line is copied verbatim after % the opening $$. % Here is a list of the characters that have been specially catcoded % except & [adapted from plain.tex] \def\dospecialsexceptand{\do\\\do\{\do\}\do\$% \do\^\do\^^K\do\_\do\^^A\do\%\do\~} % (not counting ascii null, tab, linefeed, formfeed, return, delete) % Each symbol in the list is preceded by \do, which can be defined % if you want to do something to every item in the list. \def\lverbcell{\begingroup \catcode``=13 \@noligs \tt \let\do\@makeother \dospecialsexceptand \dolverbcell} \def\dolverbcell#1\rverbcell{#1\endgroup} \def\verbarraycr{\omit{\verbarraycrstring}\cr} \newenvironment{verbarray}[2]% {\abovedisplayskip\z@ \abovedisplayshortskip\abovedisplayskip \belowdisplayskip\abovedisplayskip\belowdisplayshortskip\abovedisplayskip $$\hss\vbox\bgroup \tabskip\z@ \let\\\verbarraycr\edef\verbarraycrstring{#2}% \halign\bgroup \hfil\lverbcell##\rverbcell\hfil&&{#1}\hfil\lverbcell##\rverbcell\hfil\cr %$$ }% {%$$ \verbarraycr\egroup\egroup\hss$$} \def\ke{\kern.25em} \newenvironment{verbdiag}% {\begin{pageblock}% \vspace{2ex}\bgroup \let\do\@makeother \def\par{% what to do at the end of the line (\obeylines makes cr=\par) \egroup \tt\string\begin\{diagram\} \begin{verbarray}{\ke\tt\&\ke}{\ke\string\\}% }% \noindent\tt\$\$% \obeylines\dospecials }% {\end{verbarray}% \string\end\{diagram\}\$\$ \vspace{2ex}% \end{pageblock}% } \makeatother %=================================================================== \begin{document} \section{Introduction} In papers in mathematics and computer science which employ Category Theory, there is much benefit in clarity if ``commutative diagrams'' are used as much as possible to illustrate definitions, equations and universal properties. Here is a typical such diagram: it is one of the Mac~Lane-Kelly equations. \begin{clean} \newcommand\ce[1] {\makebox(0,0)[c]{#1}} \begin{center} \setlength \unitlength {0.25em} \begin{picture}(150,30)(-75,-15) \put(-60,6){\vector(0,-1){12}} \put(60,-6){\vector(0,1){12}} \put(-40,10){\vector(1,0){20}} \put(20,10){\vector(1,0){20}} \put(-40,-10){\vector(1,0){80}} \put(-60,10){\ce{$A * (B * (C * D))$}} \put(0,10){\ce{$(A * B) * (C * D)$}} \put(60,10){\ce{$((A * B) * C) * D$}} \put(-60,-10){\ce{$A * ((B * C) * D)$}} \put(60,-10){\ce{$(A * (B * C)) * D$}} \put(-50,0){\ce{$\Id * \Assl$}} \put(50,0){\ce{$\Assl * \Id$}} \put(-30,13){\ce{$\Assl$}} \put(30,13){\ce{$\Assl$}} \put(0,-7){\ce{$\Assl$}} \put(0,0){\ce{$=$}} \end{picture}\end{center} \end{clean} %----------------------------------------------------------------- \noindent The majority of such diagrams are rectangular, although triangles are often required, and sometimes we need to depict a ``cube.'' \subsection{\LaTeX\ pictures} For \LaTeX\footnote{But I usually use {\tt plain}~\TeX, so it is one of my design criteria that the package work with both \LaTeX\ and {\tt plain}~\TeX.} users, an obvious approach to this problem is to use the {\tt picture} environment. For instance, in his paper {\it The Linear Abstract Machine}, Yves Lafont produced the diagram above as follows: %================================================================= % % LaTeX picture verbatim % %================================================================= \begin{pageblock} \begin{verbatim} \newcommand\object[1] {\makebox(0,0)[c]{$#1$}} \newcommand\Id{{\rm id}}} \newcommand\Assl{{\rm assl}} \begin{center} \setlength \unitlength {0.25em} \begin{picture}(150,30)(-75,-15) \put(-60, 6){\vector(0,-1){12}} \put( 60, -6){\vector(0,1){12}} \put(-40, 10){\vector(1,0){20}} \put( 20, 10){\vector(1,0){20}} \put(-40,-10){\vector(1,0){80}} \put(-60, 10){\object{A * (B * (C * D))}} \put( 0, 10){\object{(A * B) * (C * D)}} \put( 60, 10){\object{((A * B) * C) * D}} \put(-60,-10){\object{A * ((B * C) * D)}} \put( 60,-10){\object{(A * (B * C)) * D}} \put(-50, 0){\object{\Id * \Assl}} \put( 50, 0){\object{\Assl * \Id}} \put(-30, 13){\object{\Assl}} \put( 30, 13){\object{\Assl}} \put( 0, -7){\object{\Assl}} \put( 0, 0){\object{=}} \end{picture} \end{center} \end{verbatim} \end{pageblock} %----------------------------------------------------------------- Of course the co-ordinates of the arrow labels are dependent on those of the arrows themselves, so it would not be difficult to package the \verb/\vector/ command with an additional argument for the label, and also provide variants for tailed and double-headed arrows (for monos and epis). It is true that the majority of the diagrams one needs are just squares and triangles, so an alternative approach would be to write a collection of macros which would fill in labels in standard diagrams. For instance, for their book {\it Category Theory for Computing Science\/}\footnote{% Prentice-Hall, 1990, ISBN 0-13-120486-6}, Michael Barr and Charles Wells created a package called {\tt catmac}\footnote{% Available from Mike Barr at Mc~Gill University, Montreal, {\tt}, {\tt} or {\tt}. {\sc BITNET} is not recommended because it corrupts important characters.} which produces a square essentially with the command $$\verb/\square[A`B`C`D;f`g`h`k]/$$ However the extended example which they give uses 32~lines of code (including at least 60~specified distances and numerous \verb/\phantom/s, {\em i.e.}~text printed in white ink) to describe 12~objects, 15~labelled arrows and 7~cells. The code is therefore {\em more\/} difficult to follow and shorter than our first bare-hands approach. However one attempts to simplify this, it remains necessary to draw each diagram individually on graph paper before typing it in this opaque notation. This is a serious dis-incentive to the author to use diagrams, whereas Barr and Wells' book itself shows how much clearer Category Theory becomes when they are used. Francis Borceux's package\footnote{Universit\'e Catholique de Louvain-la-Neuve, Belgium: {\tt}} is also based on \LaTeX\ {\tt picture}s, but the need to quote co-ordinates is eliminated by use of a standard grid: objects and arrows are placed at the ``current'' position, with commands to advance by columns and rows. A~variety of arrows is provided, with systematic names. A \LaTeX\ user may consider that the {\tt picture} environment provides the basis for a general package, but \LaTeX\ was never designed to be used in this way. It provides excellent facilities for global management of documents which \TeX\ does not supply, but the popularity of the \verb/picture/ environment is way out of proportion to the facilities actually provided or the amount of code (200~lines or 10kb without comments) involved. As a programming language it also effectively deprives the user of those few but useful programming primitives which \TeX\ has. \LaTeX\ documents, and even more so \LaTeX\ programs, are therefore characterised by verbosity and awkward syntax: compare our \begin{center} ...\verb/ X & \rTo^f & Y/... \end{center} with Borceux's \begin{center} ...\verb/ {X} \n {\Ear{f}} \n {Y}/... \end{center} Let me say, however, to be fair, that if I had had \LaTeX\ and Francis Borceux's package available when I first started using \TeX, I would never have gone to the trouble of programming the package described in this paper. \subsection{{\TeX}ercise 18.46} Considering the fact that most diagrams are essentially rectangular arrays, they carry with them an ``intrinsic'' co-ordinate system given by the cell structure. Borceux has already exploited this fact, but his cells are translated directly into co-ordinates and so are forced to be the same size. However in general the cells may be of different widths and heights depending on the sizes of the object and morphism labels. This adjustment is something which should be the responsibility of the diagram package, not of the user. A simple solution\footnote{I~have partly translated it into \LaTeX\ but it is still necessary to descend to the \TeX\ level to define the commands.} to these problems was provided by Donald Knuth in {\it The \TeX book}. Notice that the ``co-ordinate system'' adopted places each object and each morphism in a separate cell, rather than using the ``categorical 2-cells'' which Mike Barr seems to have had in mind. %================================================================= % % Knuth's exercise 18.46 % %================================================================= \begin{clean} \begin{pageblock} \begin{verbatim} \newcommand\rTo[1]{\smash{\mathop{\longrightarrow}\limits^{#1}}} \newcommand\lTo[1]{\smash{\mathop{\longleftarrow}\limits^{#1}}} \newcommand\dTo[1]{\Big\downarrow\rlap{$\vcenter{\hbox{$\scriptstyle#1$}}$}} \newcommand\uTo[1]{\Big\uparrow\rlap{$\vcenter{\hbox{$\scriptstyle#1$}}$}} \newenvironment{diagram}% {\renewcommand{\arraystretch}{2}\begin{array}{*{20}{c}}}% {\end{array}} \end{verbatim} \end{pageblock} \begin{verbdiag} A*(B*(C*D))&\relax\rTo{\Assl}&(A*B)*(C*D)&\relax\rTo{\Assl}&((A*B)*C)*D&\\ \relax\dTo{\Id*\Assl}&&=&&\relax\uTo{\Assl*\Id}&\\ A*((B*C)*D)&&\relax\rTo{\Assl}&&(A*(B*C))*D& \end{verbdiag} \noindent which produces the following result: \newcommand{\rToK}[1]% (suffix -K to avoid conflict) {\smash{\mathop{\longrightarrow}\limits^{#1}}} \newcommand{\lToK}[1] {\smash{\mathop{\longleftarrow}\limits^{#1}}} \newcommand{\dToK}[1] {\Big\downarrow\rlap{$\vcenter{\hbox{$\scriptstyle#1$}}$}} \newcommand{\uToK}[1] {\Big\uparrow\rlap{$\vcenter{\hbox{$\scriptstyle#1$}}$}} \newenvironment{diagramK}% {\renewcommand{\arraystretch}{2}\begin{array}{*{20}{c}}}% {\end{array}} $$ \begin{diagramK} A*(B*(C*D))&\rToK{\Assl}&(A*B)*(C*D)&\rToK{\Assl}&((A*B)*C)*D&\\ \dToK{\Id*\Assl}&&=&&\uToK{\Assl*\Id}&\\ A*((B*C)*D)&&\relax\rToK{\Assl}&&(A*(B*C))*D&\\ \end{diagramK} $$ \end{clean} %----------------------------------------------------------------- \pagebreak[0] \noindent Already we can see a very great improvement, in particular \begin{itemize} \item the \LaTeX\ source is set out in the same way as the intended diagram, and \item there are no co-ordinates. \end{itemize} %================================================================= % % AMS-TeX \CD macros % % These have been simplified a bit syntactically (the "@" features % in AMS-TeX have not been included) but no change has been made to % the commutative diagram features. % %================================================================= \begin{clean} \makeatletter \newdimen\ex@ \ex@.2326ex \let\ampersand@\relax \newdimen\bigaw@ \newdimen\minaw@ \minaw@11.11128\ex@ \newdimen\minCDaw@ \minCDaw@2.5pc %\newif\ifincommdiag % borrow from PT's version; also \ssize=\scriptstyle \def\minCDarrowwidth#1{\relax\ifmmode\ifinner\onlydmatherr@\minCDarrowwidth \else\minCDaw@#1\relax\fi\else\onlydmatherr@\minCDarrowwidth\fi} \def\setupvspace{\def\vspace##1{\noalign{\vskip##1\relax}}} \def\Let@{\relax\iffalse{\fi\let\\=\cr\iffalse}\fi} \def\CD{\bgroup\setupvspace\relax\iffalse{\fi\let\ampersand@&\iffalse}\fi \incommdiagtrue\vcenter\bgroup\Let@\tabskip\z@skip\baselineskip20\ex@ \lineskip3\ex@\lineskiplimit3\ex@\halign\bgroup &\hfill$\m@th##$\hfill\cr} \def\endCD{\cr\egroup\egroup\egroup} %\atdef@>#1>#2> - this has been simplified \def\amsrto#1>#2>{\ampersand@\setbox\z@\hbox{$\scriptstyle % make labels \;{#1}\;\;$}\setbox\@ne\hbox{$\scriptstyle\;{#2}\;\;$}\setbox\tw@ \hbox{$#2$}\ifincommdiag \global\bigaw@\minCDaw@\else\global\bigaw@\minaw@\fi % calculate max size \ifdim\wd\z@>\bigaw@\global\bigaw@\wd\z@\fi \ifdim\wd\@ne>\bigaw@\global\bigaw@\wd\@ne\fi \ifincommdiag\hskip.5em\fi \ifdim\wd\tw@>\z@ \mathrel{\mathop{\hbox to\bigaw@{\rightarrowfill}}\limits^{#1}_{#2}}\else \mathrel{\mathop{\hbox to\bigaw@{\rightarrowfill}}\limits^{#1}}\fi \ifincommdiag\hskip.5em\fi\ampersand@} \def\amslto#1<#2<{\ampersand@\setbox\z@\hbox{$\scriptstyle \;\;{#1}\;$}\setbox\@ne\hbox{$\scriptstyle\;\;{#2}\;$}\setbox\tw@ \hbox{$#2$}\ifincommdiag \global\bigaw@\minCDaw@\else\global\bigaw@\minaw@\fi \ifdim\wd\z@>\bigaw@\global\bigaw@\wd\z@\fi \ifdim\wd\@ne>\bigaw@\global\bigaw@\wd\@ne\fi \ifincommdiag\hskip.5em\fi \ifdim\wd\tw@>\z@ \mathrel{\mathop{\hbox to\bigaw@{\leftarrowfill}}\limits^{#1}_{#2}}\else \mathrel{\mathop{\hbox to\bigaw@{\leftarrowfill}}\limits^{#1}}\fi \ifincommdiag\hskip.5em\fi\ampersand@} \def\amsuto#1A#2A{\llap{$\vcenter{\hbox {$\scriptstyle#1$}}$}\Big\uparrow\rlap{$\vcenter{\hbox{$\scriptstyle#2$}}$}&&} \def\amsdto#1V#2V{\llap{$\vcenter{\hbox {$\scriptstyle#1$}}$}\Big\downarrow\rlap{$\vcenter{\hbox{$\scriptstyle#2$}}$}&&} \def\amsheq{&\hskip.5em\mathrel {\vbox{\hrule width\minCDaw@\vskip3\ex@\hrule width \minCDaw@}}\hskip.5em&} \def\amsveq{\Big\Vert&&} \def\pretend#1\haswidth#2{\setbox\z@\hbox{$\scriptstyle{#2}$}\hbox to\wd\z@{\hfill$\scriptstyle{#1}$\hfill}} \makeatother %================================================================= % % AMS-TeX example % %================================================================= \subsection{\AMSTeX} In \AMSTeX\ this is developed and using the code \vspace{1ex} \begin{pageblock} \noindent\verb/$$\CD/ \begin{verbarray}{}{\ke\tt\string\\} A*(B*(C*D))&\quad&@>\Assl>>&\quad&(A*B)*(C*D)&\quad &@>\Assl>>&\quad&((A*B)*C)*D&\\ @V\Id*\AsslVV&&&&=&\&&&\&&@AA\Assl*\Id A&\\ A*((B*C)*D)&\&&&&@>\Assl>>&\&&&&(A*(B*C))*D& \end{verbarray} \verb/\endCD$$/\par \end{pageblock} \vspace{1ex} \noindent we can get \catcode`\@=\active $$ \CD A*(B*(C*D)) \amsrto{\Assl}>> (A*B)*(C*D) \amsrto{\Assl}>> ((A*B)*C)*D \\ \amsdto{\Id*\Assl}VV = && \amsuto A{\Assl*\Id}A \\ A*((B*C)*D) & \amsrto{\Assl}>> & (A*(B*C))*D \\ \endCD $$ \end{clean} %----------------------------------------------------------------- \noindent This is better than Knuth's version in that \begin{itemize} \item the arrows will stretch to fit their labels (this is done simply by replacing \verb/\longrightarrow/ with \verb/\rightarrowfill/), \item there is an interesting syntactic\footnote{A simplified extract from \AMSTeX\ is included in the source of this document, but this feature has been omitted.} idea using \verb/@>f>g>/ to produce the two labels, and \item the column delimiters (\verb/&/) are implicit in the arrows. \end{itemize} \pagebreak[2] \noindent However, \begin{itemize} \item if the label on one arrow in a column is larger than another, the arrows will be of different lengths. Although a hack is provided to overcome this: \verb/\pretend f \haswidth{long label}/, the arrows can only stretch as far as the edge of the enclosing cell, so in the case of {\em objects} of different lengths we still get gaps. \item the implicit column delimiters don't work, as you see, \item the label on the lower arrow causes the vertical arrows to fall short of their endpoints, and \item there is no provision for different arrowheads or for diagonals. \end{itemize} \subsection{{\sc Postscript} pictures} \TeX\ and \LaTeX\ users will already be aware of the {\em wysiwyg\/}\footnote{``What you see is what you get.''} fallacy. Nevertheless the suggestion is frequently made that the best way to solve this problem would be to~``draw it on the screen.'' Given that, by hypothesis, we are using \TeX\ or \LaTeX\ and not a {\sc Mac}\footnote{The words in {\sc Small Capitals} are trade marks.} to compose the {\em text\/} of the document, let us consider the implications of using the latter to draw just the diagrams. \begin{itemize} \item The positioning of the object and morphism labels is part of the same problem as the calculation of the lengths of the arrows, so these labels must be inserted on the {\sc Mac} too, using its fonts and not enjoying the advantages of uniform \TeX\ definitions. \item Bringing the diagrams and the text together either involves physical scissors-and-paste or requires a {\tt dvi} driver which translates into {\sc Postscript}. There are plenty of high-resolution printers around which are capable of printing {\tt dvi} documents without using {\sc Postscript} --- and they're faster,~too! Even those drivers which can incorporate {\sc Postscript} are mutually incompatible. \item For each diagram in the document you need a separate {\sc Postscript} file (a~recent 30-page paper of mine contained 68~diagrams). Drawing each of the diagrams separately and down-loading them from a {\sc Mac} to {\sc Unix} would be very time-consuming, and keeping all of these files together would make the source of the document very unwieldy. \item Alternatively, you could incorporate {\sc Postscript} directly into the \TeX\ source {\em via\/} a~\verb/\special/ command. Though more manageable, this is still not portable. Now that you're no longer using a~{\sc Mac} to draw the pictures, it's just as difficult to do this as programming the problem in \TeX\ in the first place. \item The missing features of \TeX, notably diagonal lines, could be added by (low-level) use of embedded {\sc PostsScript} in \verb/\special/s. The results would be superior, but portability would be lost. \end{itemize} \subsection{Design Criteria} Having studied several partial solutions to the problem, we now set out our basic design criteria. \begin{enumerate} \item There must be no preprocessing ({\em cf.}~{\tt eqn} in {\sc Unix}) or inclusion of files (such as {\sc Postscript} pictures inserted using \verb/\special/ commands): the entire diagram must form part of the source of the document itself. \item Simple diagrams must be able to be drawn ``on the fly'' and not need to be drawn on paper first (although obviously complex diagrams will already have been worked out on paper anyway). \item The layout of the source code must resemble the intended diagram as far as syntactically possible. \item There must be no measuring of labels to calculate co-ordinates or lengths of arrows. \item There must be a variety of arrow styles, with facilities for defining new ones. Diagonal arrows should be provided at various slopes, albeit with limited choice and features. \item The package must be compatible both with {\tt plain}~\TeX\ and with \LaTeX, and not rely on non-standard fonts\footnote{Diagonal lines can {\em only\/} be drawn using \LaTeX's {\tt line10} and {\tt linew10} fonts, and for exotic arrow styles the AMS maths symbols fonts may be useful: we regard these as standard.} or language features. \item Future versions which improve the appearance of the diagrams should be compatible with past papers written using the package (but you hack at your own risk). \end{enumerate} \noindent In addition there are {\ae}sthetic criteria, some of which may be a matter of opinion: \begin{itemize} \item Arrows should stretch to meet the objects which are intended to be their endpoints. \item Arrows should be aligned (both horizontally and vertically) with the centres of the objects. \item Labels on arrows should not affect the spacing of the diagram except to avoid overlapping. \item Stretching of arrows should not affect the centering of their labels. \end{itemize} \section{User Manual} %================================================================= % % my version % %================================================================= My version of the diagram is produced as follows: \begin{pageblock} \noindent\verb/\input diagrams/\\ \begin{verbdiag} A*(B*(C*D))&\relax\rTo^\Assl&(A*B)*(C*D)&\relax\rTo^\Assl&((A*B)*C)*D&\\ \relax\dTo^{\Id*\Assl}&&=&&\relax\uTo_{\Assl*\Id}&\\ A*((B*C)*D)&&\relax\rTo^\Assl&&(A*(B*C))*D& \end{verbdiag} \end{pageblock} \noindent which yields $$\diagram A*(B*(C*D)) &\relax\rTo^\Assl & (A*B)*(C*D) &\relax\rTo^\Assl & ((A*B)*C)*D \\ \dTo^{\Id*\Assl} & & = & &\relax\uTo_{\Assl*\Id} \\ A*((B*C)*D) & &\relax\rTo^\Assl & & (A*(B*C))*D \\ \enddiagram $$ \noindent As you see, it is based on Knuth's version but does not adopt \AMSTeX's confusing attempts to eliminate {\tt\&}s. It also stretches the arrows to meet the objects. \pagebreak[3] \subsection{Typing the diagram} The basic rule is to divide the diagram into cells: $$ \CellSize=2em\diagram &&\relax\ && \ && \ && \ \\ &A*(B*(C*D)) & & \rTo^\Assl & & (A*B)*(C*D) & & \rTo^\Assl & & ((A*B)*C)*D \\ \ &\HonV{}&&&& \rDots &&&&\HonV{}& \ \\ &\MapsAbut\dTo^{\Id*\Assl} & \uDots && \uDots &=& \uDots && \uDots & \MapsAbut \uTo_{\Assl*\Id}\\ \ &\HonV{}&&&& \rDots &&&&\HonV{}& \ \\ &A*((B*C)*D) & & & & \rTo^\Assl & & & & (A*(B*C))*D \\ && \ && \ && \ && \ \\ \enddiagram$$ \noindent just like the cells of a matrix, and then type the contents of the cells with columns delimited by ``{\tt\&}'' and rows by ``\verb/\\/''. The bottom arrow extends through the empty cells either side of~it. Notice that although the matrix imposes a kind of co-ordinate system, the widths of the columns and the heights of the rows are variable and chosen automatically (by \TeX, in the same way as it does for matrices, tables,~{\it etc.}) Each cell should contain {\it either\/} an object (an~ordinary mathematical expression, set in maths mode) {\it or\/}~a~morphism (an~arrow such as \verb/\rTo^f/). Horizontal and vertical arrows cannot be mixed in one cell, and only one horizontal arrow per cell is allowed (but see the section on parallel maps below). Likewise, re-alignment of objects using \verb/\hfil/ is likely to fail since objects end up being set in an \verb/\hbox/ to their natural width (and height). Do not enclose the arrow commands in boxes or braces, because this also prevents the automatic stretching from working. Every morphism must have an object at each end to terminate it: it must not meet another morphism or extend off the edge of the diagram. If~you want to use the arrow commands for other lines without objects to terminate them (this is how the above diagram with dotted cells was drawn), then the object position must be occupied by a space command such as \verb/\;/ or by something else that produces an object but does not print, such as \verb/{}/ or \verb/\null/. Even \verb/\relax/ or \verb/\empty/ would do, so long as there's something other than white space (or~comments) between successive \verb/&/s. If~you forget to terminate an arrow, part or all of it will be lost. Any \LaTeX\ environment, say \verb/\begin{env}/...\verb/\end{env}/, is just a packaged way of invoking the commands \verb/\env/ and \verb/\endenv/% \footnote{There is also an extra level of grouping, and \LaTeX\ checks that the the same environment type occurs at the beginning and the end.}, so for {\tt plain} \TeX\ you just use \verb/\diagram/...\verb/\enddiagram/ instead. There is also a command \verb/\commdiag/ with an argument, but this is only included for reverse compatibility. Of course \LaTeX\ users can also substitute \verb/\[/...\verb/\]/ or \verb/begin{displaymath}/...\verb/\end{displaymath}/ for \verb/$$/...\verb/$$/. $$ \hbox to 7.5em \bgroup$\vcenter\bgroup \begin{verbatim} $$ \diagram ... \enddiagram $$ \end{verbatim} {\em needed for\/} \TeX \egroup\hss$\egroup \mbox{or}\hspace{2em} \hbox to 6em \bgroup$\vcenter\bgroup \begin{verbatim} $$ \commdiag{ ... } $$ \end{verbatim} {\em obsolete} \egroup\hss$\egroup \mbox{or}\hspace{2em} \hbox to 11em \bgroup$\vcenter\bgroup \begin{verbatim} \begin{displaymath} \begin{diagram} ... \end{diagram} \end{displaymath} \end{verbatim} \LaTeX\ {\em only} \egroup\hss$\egroup \mbox{or}\hspace{2em} \hbox to 8em \bgroup$\vcenter\bgroup \begin{verbatim} \[ \begin{diagram} ... \end{diagram} \] \end{verbatim} \LaTeX\ {\em only} \egroup\hss$\egroup $$ The {\em horizontal\/} arrow commands may also be used in text, $A \rTo^f B$. Since there is no enclosing matrix, this is written as \verb/$A \rTo^f B$/ {\em without}~\verb/&/. Arrows may be made to come right up to the objects by using the \verb/\MapsAbut/ command; this is in fact an abbreviation for \verb/\MapShortFall=0pt/ which sets the actual amount of space at the ends of the arrows (default~0.4em). Individual arrows may be altered in this way by using this command inside a cell. Each cell in the diagram is forced to be at least \verb/\DiagramCellWidth/ wide and \verb/\DiagramCellHeight/ high% \footnote{Actually, height plus depth}. The default values are 3em, which allows for objects of width ``$MMM$''; if they're wider or narrower, the best way to adjust the size of the diagram is by using the command \verb/\CellSize=5em/ which changes both parameters together. \subsection{Labels} Each arrow potentially carries two labels, called {\em leading\/} and {\em trailing\/}, which are given like superscripts and subscripts% \footnote{However they are {\em not} recognised syntactically in the same way, and so for instance {\tt\bsl nolimits} will not work.} respectively. For reverse compatibility, there may instead be two positional arguments, which {\em must be enclosed in braces, e.g.}~\verb/\rTo{f}{g}/ but not \verb/\rTo f g/. The arrow commands are {\em fragile\/} in the \LaTeX\ sense: they cannot, for instance, be used in footnotes. The rule for positioning the labels is \begin{itemize} \item for {\bf horizontal} arrows, \verb/\rTo^f_g/ and \verb/\rTo{f}{g}/ give \smash{$\rTo^f_g$}; \item for {\bf vertical} arrows, \verb/\dTo^f_g/ and \verb/\dTo{f}{g}/ give $f{\big\downarrow}g$; \item for {\bf diagonal} arrows, \verb/\SW^f_g/ and \verb/\SW{f}{g}/ put $f$ above and $g$ below. \item Using tilde, the label may instead break the arrow \verb/\rTo~f/ gives $$\diagram A & \rTo~f & B \enddiagram$$ \end{itemize} Although the arrows extend into adjacent cells, the labels remain centred {\em in~the cell in which the arrow was declared.} Any ordinary (mathematical) text you put in the cell with an arrow will appear in the usual way. For horizontal arrows it will therefore be attached to the arrowhead/tail, whilst for vertical and diagonal arrows it will lie to the side of (or between) the arrows. However if you want to put a superscript on the arrow-head you should define a new arrow command: section~2.4 explains how to do this. By default the labels on the arrows are set in \verb/\textstyle/ (the same size as in text) when they are part of a matrix, and in \verb/\scriptstyle/ (like subscripts) in text. However this may be changed by re-defining the command \verb/\labelstyle/, for instance \begin{verbatim} \begin{displaymath} \renewcommand\labelstyle{\displaystyle} \begin{diagram} A &\rTo^{\sum^n_1 f_i}_{\rm display} & B \end{diagram} \qquad ... \end{displaymath} \end{verbatim} \noindent gives \begin{displaymath} \renewcommand\labelstyle{\displaystyle} \hss\begin{diagram} A &\relax\rTo^{\sum^n_1 f_i}_{\rm display} & B \end{diagram} \qquad \renewcommand\labelstyle{\textstyle} \begin{diagram} A & \rTo^{\sum^n_1 f_i}_{\rm text} & B \end{diagram} \qquad \renewcommand\labelstyle{\scriptstyle} \begin{diagram} A & \rTo^{\sum^n_1 f_i}_{\rm script} & B \end{diagram} \qquad \renewcommand\labelstyle{\scriptscriptstyle} \begin{diagram} A & \rTo^{\sum^n_1 f_i}_{\rm scriptscript} & B \end{diagram} \hss\end{displaymath} Similarly, objects are set in \verb/\displaystyle/ unless the \verb/\objectstyle/ command is redefined. \subsection{Arrow styles currently available} The following arrow styles are available, annotated with their names as the leading (first, upper, superscript or left-hand) argument, {\it e.g.} \verb/\rTo^{\tt rTo}/. The arrows are made up of juxtaposed pieces, as explained in the next section. Please note that good alignment depends to a large extent on having an accurate {\tt dvi} driver, which most are not. Wherever possible, the arrows have been designed to be tolerant of inaccuracies, but this is difficult to achieve, although it may improve with future versions. Some of the arrows have synonyms such as \verb/\lFrom/ for reverse compatibility. \def\do(#1){\csname #1\endcsname{\backslash{\tt #1}}{}} $$ \commdiag{A&\do(rTo)&B\cr\do(uTo)&&\do(dTo)\cr C&\do(lTo)&D\cr} \hspace{80pt} \commdiag{A&\do(rDotsto)&B\cr\do(uDotsto)&&\do(dDotsto)\cr C&\do(lDotsto)&D\cr} $$ $$ \commdiag{A&\do(rArr)&B\cr\do(uArr)&&\do(dArr)\cr C&\do(lArr)&D\cr} \hspace{80pt} \commdiag{A&\do(rOnto)&B\cr\do(uOnto)&&\do(dOnto)\cr C&\do(lOnto)&D\cr} $$ $$ \commdiag{A&\do(rImplies)&B\cr\do(uImplies)&&\do(dImplies)\cr C&\do(lImplies)&D\cr} \hspace{80pt} \commdiag{A&\do(rMapsto)&B\cr\do(uMapsto)&&\do(dMapsto)\cr C&\do(lMapsto)&D\cr} $$ $$ \commdiag{A&\do(rIntoA)&B\cr\do(uIntoA)&&\do(dIntoA)\cr C&\do(lIntoA)&D\cr} \hspace{80pt} \commdiag{A&\do(rIntoB)&B\cr\do(uIntoB)&&\do(dIntoB)\cr C&\do(lIntoB)&D\cr} $$ $$ \commdiag{A&\do(rEmbed)&B\cr\do(uEmbed)&&\do(dEmbed)\cr C&\do(lEmbed)&D\cr} \hspace{80pt} \commdiag{A&\do(rProject)&B\cr\do(uProject)&&\do(dProject)\cr C&\do(lProject)&D\cr} $$ $$ \commdiag{A&\do(hDots)&B\cr\do(vDashes)&&\do(vDots)\cr C&\do(hDashes)&D\cr} \hspace{80pt} \commdiag{A&\do(hEq)&B\cr\do(vEq)&&\do(vLine)\cr C&\do(hLine)&D\cr} $$ $$ \commdiag{A&\do(rDashto)&B\cr\do(uDashto)&&\do(dDashto)\cr C&\do(lDashto)&D\cr} \hspace{80pt} \commdiag{A&\do(rPto)&B\cr\do(uPto)&&\do(dPto)\cr C&\do(lPto)&D\cr} $$ $$\CellSize2em \commdiag{&&A\cr&\do(NE)&&\do(SE)\cr D&&&&B\cr&\do(NW)&&\do(SW)\cr&&C\cr}$$ % \subsection{Defining additional arrows} The arrow commands such as \verb/\rTo/ are defined in a systematic way from five parts. From left to right or top to bottom, these are: \begin{center} leading tip,\quad first filler,\quad middle,\quad second filler,\quad trailing tip \end{center} The tips and middle are arrowheads, hooks, {\em etc.\/} of fixed sizes, whilst the fillers are repeatable line-segments. This is just like \TeX's expandable brackets. \pagebreak[1] For example, \begin{verbatim} \newcommand\rCrossedInto{\HorizontalMap \rthooka - + - \rhvee } $$\begin{diagram} A & \rCrossedInto^f & B \cr \end{diagram}$$ \end{verbatim} \noindent produces \begin{clean} \newcommand\rCrossedInto{\HorizontalMap \rthooka - + - \rhvee } $$\commdiag{ A & \rCrossedInto^f & B \cr }$$ \end{clean} \noindent and similarly for \verb/\VerticalMap/. Unlike the optional labels, the five arguments are mandatory; null arguments must be given as~\verb/{}/~or~\verb/\empty/. Some symbols may be used directly as bits of arrows, whilst others need to be moved into the correct positions. For instance ``\verb/>/'' (greater than) makes a good arrow-{\em tail\/} but is not suitable as a {\em head\/} because the shaft of the arrow would not join up with its point. In these cases it is better to define a new symbol ({\em e.g.}~\verb/\rhvee/) for use as part of an arrow. The obvious symbols $$\verb/-/,\quad \verb/=/,\quad \verb/\equiv/~(\equiv), \quad \verb/|/\quad {\rm and}\quad \verb/\|/\ (\|)$$ are suitable as horizontal and vertical fillers. The single lines (\verb/-/~and~\verb/|/) are treated as special cases: a rule is produced instead of a repeating symbol. The extra symbols $$\verb/\hfdot/,\quad\verb/\vfdot/,\quad \verb/\hfdash/\quad {\rm and}\quad \verb/\vfdash/$$ can be used for horizontal and vertical dotted and dashed lines. Repeating symbols are overlapped slightly to ensure a good join; this also makes them stick out at the end, so the same symbol should also be used as a tail if otherwise there would be none. It is also a good idea to repeat dots and dashes as middles to ensure regularity. \def\do(#1){{\csname #1\endcsname}&{\tt\backslash #1}} The arrows $$\begin{array}{clclclcl} \do(leftarrow) & \do(Leftarrow) & \do(leftharpoonup) & \do(leftharpoondown) \\ \do(rightarrow)& \do(Rightarrow)& \do(rightharpoonup)& \do(rightharpoondown)\\ \do(uparrow) & \do(Uparrow) & \do(upharpoonleft) & \do(upharpoonright) \\ \do(downarrow) & \do(Downarrow) &\do(downharpoonleft) &\do(downharpoonright)\\ \end{array}$$ may be used as heads, although they are rather small and also unsuitable for dotted lines (some of these symbols come from the AMS {\tt msxm10} and {\tt msym10} fonts). Instead $$\begin{array}{clclclcl} \do(lhvee)\qquad & \do(rhvee)\qquad & \do(dhvee)\qquad & \do(uhvee) \\ \do(lhcvee)\qquad & \do(rhcvee)\qquad & \do(dhcvee)\qquad & \do(uhcvee) \\ \do(lhvvee)\qquad & \do(rhvvee)\qquad & \do(dhvvee)\qquad & \do(uhvvee) \\ \do(lhla)\qquad & \do(rhla)\qquad & \do(dhla)\qquad & \do(uhla) \\ \end{array}$$ produce better results. The following are also useful: $$\begin{array}{clclcl} \do(twoheadleftarrow) & \do(triangleleft) & \do(blacktriangleleft) \\ \do(twoheadrightarrow) & \do(triangleright) & \do(blacktriangleright) \\ \do(twoheaduparrow) &\do(triangleup) &\do(blacktriangle) \\ \do(twoheaddownarrow) &\do(littletriangledown) & \do(blacktriangledown) \\ \end{array}$$ some of which have been ``made up.'' The following are useful as tails: $$\begin{array}{clclclcl} \do(gt) & \do(lt) & \do(blacktriangle) & \do(blacktriangleleft) \\ \do(wedge) & \do(vee) & \do(blacktriangledown) & \do(blacktriangleright)\\ \end{array}$$ together with the following made up symbols: $$\begin{array}{clclclcl} \do(ltbar) & \do(rtbar) & \do(utbar) & \do(dtbar) \\ \do(rthooka) & \do(rthookb) & \do(lthooka) & \do(lthookb) \\ \do(uthooka) & \do(uthookb) & \do(dthooka) & \do(dthookb) \\ \end{array}$$ \noindent which are designed for \verb/\rMapsto/, \verb/\rIntoA/, {\em etc.} \pagebreak[2] Subscripts and superscripts can be added to arrowheads: \begin{verbatim} \newcommand\rToStar{\HorizontalMap \empty - \empty - {\mathop{\rhvee}\limits^*}} $$\begin{diagram} A &\rToStar^f & B \\ \end{diagram}$$ \end{verbatim} \newcommand\rToStar {\HorizontalMap \empty - \empty - {\mathop{\rhvee}\limits^*}} \noindent produces $A \rToStar^f B$. When designing new arrow styles you need to know the exact rules governing the way the bits are put together. \begin{itemize} \item All bits are individually set in \verb/\hbox/es in maths mode. \item The shaft of the {\em horizontal} arrows is centred on the ``math~axis'', so that symbols (such as \verb/\scriptstyle/ arrowheads) which are not aligned on this axis must be \verb/\raise/d. \item The middle and tips of {\em horizontal} arrows are narrowed by ${1\over12}$em on each side (this being the margin for most of the {\tt cmmi10} and {\tt cmsy10} characters) so that they join up with the filler. \item The middle and tips of the {\em vertical} arrows are horizontally centred, so to shift them left or right relative to the shaft it is necessary to kern by {\em twice\/} the required shift. Since there is no top or bottom margin on the standard characters, no shortening is done. \item The filler segments are shortened at each end by up to 0.15em (horizontal) or 0.35ex (vertical) so that when the repetitions are spaced out they will join up. \end{itemize} Note that certain composite symbols such as \verb/\cong/~($\cong$) cannot be used as bits of arrows. \subsection{Application to adjunctions} Here is a side application of commutative diagrams to displaying ``adjoint correspondences.'' It also illustrates the way arrows stretch to meet their endpoints but keep their labels centered in the column of arrows. Without the \verb/\CellSize/ command we'd get lots of extra space around the cells, which in this case we don't want. Notice also the invisible ``objects'' terminating the \verb/\hLine/ ``morphism'' command. \begin{verbdiag}\CellSize=1em &Z\times X&\relax\rTo^f&Y&\\ \relax\ &&\relax\hLine&&\relax\ &\\ &Z&\relax\rTo^{{\bf curry}(f)}&Y^X& \end{verbdiag} \noindent This produces $$ \CellSize=1em \diagram &Z \times X &\relax\rTo^f & Y \\ \ &&\relax\hLine && \ \\ &Z & \rTo^{{\bf curry}(f)} & Y^X \\ \enddiagram$$ If you want the $Z$s lined up, it's no good \verb/\hfill/ing the second one on the right, because the arrow wont stretch to meet it\footnote{There is no way of detecting {\em where\/} glue is placed inside a box, so the stretching algorithm {\em assumes\/} the object is centred and extends the arrow by half the amount of glue in the object box.}. The best solution is probably to split the object into two cells: \begin{verbdiag}\CellSize=1em &Z&\relax{}\times X&\relax\rTo^f&Y&\\ \relax\ &&&\relax\hLine&&\relax\ &\\ &Z&&\relax\rTo^{{\bf curry}(f)}&Y^X& \end{verbdiag} \noindent giving $$ \CellSize=1em \diagram &Z & {} \times X &\relax\rTo^f & Y \\ \ &&& \hLine&& \ \\ &Z & & \rTo^{{\bf curry}(f)} & Y^X \\ \enddiagram$$ \noindent The \verb/{}/ makes sure \verb/\times/ still gets the spacing appropriate to a binary operator. \subsection{Extending vertical arrows} The cube offers a good example of how horizontal and vertical arrows stretch. Notice how the cells have been sub-divided further to give the ``3D'' effect., and that the positions of the labels on the maps betray the cells in which they were declared. \begin{verbdiag} A'&&\relax\rArr^{f'}&&B'&&&\\ &\relax\SE_a&&&\relax\vLine^{h'}&\relax\SE_b&&\\ \relax\dArr^{g'}&&A&\relax\rArr^f&\relax\HonV&&B&\\ &&\relax\dArr^g&&\relax\dArr&&&\\ C'&\relax\hLine&\relax\VonH&\relax\rArr^{k'}&D'&&\relax\dArr_h&\\ &\relax\SE_c&&&&\relax\SE_d&&\\ &&C&&\relax\rArr^k&&D& \end{verbdiag} The broken lines ($h'$~and~$k'$) are simply two arrows. The commands \verb/\HonV/ (``horizontal on vertical'') and \verb/\VonH/ (``vertical on horizontal'') allow arrows in one direction to pass through, whilst obstructing arrows in the other direction as if an object were present. They each have an optional argument: \verb/\HonV[=]/ and \verb/\VonH[\|]/ should be used to allow extra space for double lines. There is also a command \verb/\HmeetV/ which causes single horizontal and vertical lines to meet, forming a corner. Here is the result: $$ \begin{diagram} A' & &\rArr^{f'} & & B' \\ & \SE_a & & & \vLine^{h'}& \SE_b \\ \dArr^{g'} & & A & \rArr^f & \HonV & & B \\ & & \dArr^g & & \dArr \\ C' & \hLine & \VonH & \rArr^{k'} & D' & & \dArr_h \\ & \SE_c & & & & \SE_d \\ & & C & & \rArr^k & & D \\ \end{diagram} $$ With a little practice, you will be able to read and compose the source of these diagrams as easily as the printed version, although one would not normally go to the trouble of aligning the \verb/&/s in the source code!% \footnote{To do so neatly in this manual required special programming: the {\tt verbatim} environment produced unsatisfactory results.} \subsection{Parallel arrows} One can draw two arrows between the same two vertices (possibly including extra things like the adjoint symbol in~between) very simply: \begin{verbdiag} A&\relax\pile{\rTo^f\\ \bot\\ \lTo_g}&B&\\ \relax\dTo^h\dashv\uTo_k&&&\\ C&&& \end{verbdiag} $$\diagram A & \pile{ \rTo^f \\ \bot \\ \lTo_g } & B \\ \dTo^h \relax\dashv \uTo_k \\ C \\ \enddiagram$$ \begin{itemize} \item {\bf Horizontal} arrows may be \verb/\pile/d on top of each other. Effectively, a one-column diagram is created, which may have {\em either\/} a horizontal arrow {\em or\/} an object in each row. This works both in diagrams and in text. The spacing (\verb/\baselineskip/) between the rows is \verb/.5\PileSpacing/, on the assumption that you will put something between parallel arrows; a blank line (\verb/\\ \\/) will suffice, then the spacing is the same as that for vertical arrows. \item {\bf Vertical} arrows may simply be put together in the same cell, with any text between them. The spacing is always \verb/\PileSpacing/. (\verb/\pile/ must not be used.) \item The experimental \verb/\ParallelMap/ command (which appeared in the source of previous versions but never worked) has not been and will not be implemented. \item {\bf Diagonal} lines are currently implemented as fixed (non-stretching) boxes and can therefore be juxtaposed, separated with explicit space and moved with \verb/\raise/ or \verb/\raisebox/ commands. However this will be incompatible with future versions. \end{itemize} \subsection{Diagonal lines} As we have already said, \TeX\ makes drawing diagonal lines {\em very\/} difficult: \begin{itemize} \item there is no diagonal rule primitive: juxtaposed characters have to be used, \item there is no square root function to enable one to compute the diagonal length of a character (using Pythagoras), \item there is no diagonal leader function for repetition, \item positioning of line segments involves so many horizontal and vertical shifts that {\tt dvi} drivers inevitably ``lose their place'' with rounding errors, so that the segments don't join up. \end{itemize} Consequently, the provision of diagonal arrows in this package is rather primitive, and only single unbroken \LaTeX-style arrows (like \verb/\rArr/) are provided at the slopes indicated by the diagram. Notice that all of the diagonal lines lie between objects two cells apart in one direction and two, three, four or six cells apart the other way. Longer lines may be obtained with \verb/\NE(4,4)^f/ or \verb/\sSE(4,6)_g/, for instance, but the numbers must be consistent and \verb/\DiagramCellHeight/ and \verb/\DiagramCellWidth/ must be equal. \iffalse \footnote{This is partly because \LaTeX's code for choosing the characters is so horrendous that I didn't want to reproduce it.}. In the current version, the diagonal line commands (unlike their horizontal and vertical counterparts) produce things which have fixed size and position (like objects), and it is up to the user to specify the characters used to form the lines and the number of repetitions, and use whatever means are available to shift the result into the required position.\footnote{\LaTeX\ users may prefer to embed {\tt\bsl picture}s instead.} Only four diagonal arrow commands are provided: \verb/\NW/, \verb/\NE/, \verb/\SE/ and~\verb/\SW/. However like the horizontal and vertical lines they are defined using a diagonal line primitive: \begin{verbatim} \def\NW{\NorthWest\DiagonalMap{\lah111}{\laf100}{\laf100}{\laf100}{\laf100}} \end{verbatim} The command \verb/\NorthWest/ declares the direction of the arrow so that \verb/\DiagonalMap/ can arrange the repeats properly. The four arguments are the leading (left) and trailing (right) tips, the filler and the middle as before, although currently the middle isn't used. Again the parts are individually \verb/\hbox/ed in maths mode. \TeX's little diagonal arrows (\verb/\nwarrow/,~{\em etc.}) may be used, but only provide $45^\circ$ arrows. Instead, the \LaTeX\ symbols may be used, where \verb/\laf/$\langle$octal~number$\rangle$ is a filler and \verb/\lah/$\langle$octal~number$\rangle$ the corresponding arrow-head. The octal numbers are chosen from the following tables: % \def\do(#1){\hbox{\tenln\char'#1}&\it#1} $$\def\arraystretch{1.2}\begin{array}{r|cr|cr|cr|cr|cr|cr} &x=&1&&2&&3&&4&&5&&6\\\hline \llap{$y={}$} 1 & \do(00)&\do(10)&\do(20)&\do(30)&\do(40)&\do(50)\\\hline 2 & \do(01)&&&\do(21)&&&\do(41)&&\\\hline 3 & \do(02)&\do(12)&&&\do(32)&\do(42)&&\\\hline 4 & \do(03)&&&\do(23)&&&\do(43)&&\\\hline 5 & \do(04)&\do(14)&\do(24)&\do(34)&&&\do(54)\\\hline 6 & \do(05)&&&&&&&\do(45)&&\\ \end{array}$$ (add {\it100} for negative gradient) $$\hss\def\arraystretch{1.5}\begin{array}{r|cr|cr|cr|cr|cr|cr|cr|cr|cr} &x=&-4&&-3&&-2&&-1&&0&&+1&&+2&&+3&&+4\\\hline \llap{$y={}$} +4 &&&\do(157)&&&\do(117)&&&\do(27)&&&\do(67)&&\\\hline +3 &\do(175)&&&\do(135)&\do(115)&&&\do(16)&\do(36)&&&\do(76)\\\hline +2 &&&\do(153)&&&\do(113)&&&\do(25)&&&\do(63)&&\\\hline +1 &\do(171)&\do(151)&\do(131)&\do(111)&\do(66)&\do(22)&\do(52)&\do(61)& \do(72)\\\hline 0 &&&&&&&\do(33)&&&\do(55)&&&&&&\\\hline -1 &\do(71)&\do(51)&\do(31)&\do(11)&\do(77)&\do(122)&\do(152)&\do(161)& \do(172)\\\hline -2 &&&\do(53)&&&\do(13)&&&\do(125)&&&\do(163)&&\\\hline -3 &\do(75)&&&\do(35)&\do(15)&&&\do(116)&\do(136)&&&\do(176)\\\hline -4 &&&\do(57)&&&\do(17)&&&\do(127)&&&\do(167)&&\\ \end{array}\hss$$ \fi Those arrows which extend through several rows are declared in the top cell in which they print, {\em i.e.\/} in the row and column adjacent to the upper terminating object (irrespective of the sense of the arrow). For example, here is the diagram defining a pullback: \begin{verbdiag} U&&&&&\\ &\relax\SE\ESE^x\SSE_y&&&&\\ &&X\times_Z\SEpbk Y&\relax\rTo_p&X&\\ &&\relax\dTo^q&&\relax\dTo_f&\\ &&Y&\relax\rTo^g&Z& \end{verbdiag} \noindent which gives $$\begin{diagram} U \\ &\relax\SE \ESE^x \SSE_y \\ & & X\times_Z \SEpbk Y & \rTo_p & X \\ & & \dTo^q & & \dTo_f \\ & & Y & \rTo^g & Z \\ \end{diagram}$$ The ``right angle'' symbol \verb/\SEpbk/ is just like a character which prints way outside its (zero-size) bounding box. There are also three others for the rare cases where the pullback is not upwards and leftwards! Notice that the stretching algorithm aligns the $g$ with~the~$p$. \iffalse \subsection{Bent lines} The diagonal lines in the previous section were difficult to draw and rather ugly. Here is a prettier way of doing it: \begin{verbdiag} U&&\relax\hLine^x&&\relax\dlBentto&\\ &\relax\SE^{\langle x,y\rangle}&\\ \vLine^y&&X\times_Z\SEpbk Y&\relax\rTo^p&X&\\ &&\relax\dTo^q&&\relax\dTo_f\\ \relax\ruBentto&&Y&\relax\rTo^g&Z&\\ \end{verbdiag} which gives: $$\begin{diagram} U && \hLine^x & & \dlBentto \\ & \SE^{\langle x,y\rangle} \\ \vLine^y && X \times_Z \SEpbk Y & \rTo^p & X \\ &&\dTo^q && \dTo_f \\ \ruBentto&& Y & \rTo^g & Z \\ \end{diagram}$$ Notice that the bent lines consist of two separate arrow commands, one of them an ordinary \verb/\hLine/ or \verb/\vLine/ and the other a ``bent'' arrow. The latter are designed to meet orthogonal lines exactly, or rather would if we had automatic vertical stretching like the horizontal stretching. To be precise, \begin{itemize} \item \verb/\dlBentto/, {\em etc.}, has a corner which is vertically positioned on the maths axis and includes a short horizontal line to compensate for the space at the end of \verb/\hLine/. {\em It~must be placed in the cell corresponding to the corner.} The arrow needs to be extended manually. There are similar commands \verb/\ulBentto/ for upward maps, \verb/\drBentto/ to meet lines on the right and \verb/\dlBent/ without an arrowhead (and all the combinations). \item \verb/\ruBentto/, {\em etc.}, has a corner which is horizontally positioned in the centre of the {\em next\/} cell (assuming that's empty). So {\em it must be placed in the cell next to the corner, in fact that corresponding to the edge.} The arrow is extended automatically (often \verb/\across/ will be used) but the vertical line meeting it needs manual extension. Again there are commands with variant names. \end{itemize} These bent line commands are defined in exactly the same way as ordinary horizontal and vertical arrows, except that \begin{itemize} \item \verb/\dlBentto/ has only a bottom half, {\em i.e.}~the leading tip and first filler are \verb/\empty/. The second filler and trailing tip are quite ordinary but the middle is special (\verb/\ldmcorner/). \item \verb/\ruBentto/, on the other hand, is a complete arrow, the {\em tail\/} now being a special corner. \end{itemize} Other middles could be defined to give rounded corners, using \LaTeX's {\tt circle10} font. \fi \subsection{Posets (Hasse Diagrams)} Posets are trivial categories, but in practice they're the most difficult diagrams to draw! Here is an example which illustrates many of the foregoing techniques. [Make it more complicated!] \begin{verbdiag}\CellSize=1em\MapsAbut o&&o&&o&&o&&o&&o&\\ &\relax\WNW\WWNW&&\relax\NW\WNW&\relax\uArr&\relax\NW\NE&\relax\uArr&\relax\ENE\NE&&\relax\EENE\ENE&&\\ &&&&o&&o&&&&& \end{verbdiag} $$\CellSize=1.5em \MapsAbut % small diagram with arrows meeting points \begin{diagram} o && o && o && o && o && o \\ & \WNW \WWNW && \NW\WNW & \uArr & \NW \NE & \uArr & \ENE \NE && \EENE \ENE \\ &&&& o && o \\ \end{diagram} $$ \section{Implementation and compatibility} The diagram package is currently available as a single 30kb\footnote{Without comments; the development version is twice this size.} printable \TeX\ source file which is compatible with both \LaTeX\ and {\tt plain} \TeX. It loads the \LaTeX\ {\tt line10} font as \verb/\tenln/ (its \LaTeX\ name) and also defines some (exotic) arrow commands in terms the AMS symbols, but if these are to be used then the file {\tt mssymb.tex} must be loaded separately. Compatibility with past and future versions (the numbers of which have been assigned {\em post facto\/}) is as follows: \begin{description} \item[Version 0:] Original implementation of \TeX ercise 18.46; April 1986. \begin{itemize} \item \verb/\matrix{..}/ must be changed to \verb/\diagram..\enddiagram/ (or~\verb/\commdiag{..}/). \item \verb/\mapright/, {\em etc.,} must be changed to (or~defined as) \verb/\rTo/. Positional arguments are still recognised, {\em so long as they are enclosed in braces.} \item \verb/\cr/ should be changed to \verb/\\/. \end{itemize} \item[Version 1:] Horizontal arrows made to stretch to edge of cell; 1987--9. \begin{itemize} \item \verb/\rTo{f}{g}/ works, but \verb/\rTo f g/ doesn't: it must be changed to \verb/\rTo^f_g/. \item \verb/\mkern-20mu\rTo{f}{g}\mkern-20mu/ idiom for manual stretching of horizontal arrows to meet objects must be removed. \item \verb/\VerticalMapHeight/ and \verb/\VerticalMapDepth/ commands should be removed. \item There are now five arguments to \verb/\HorizontalMap/, \verb/\VerticalMap/ and \verb/\DiagonalMap/. \item Nested \verb/\commdiag/ commands for parallel maps should be changed to \verb/\pile/. \item Parallel maps contructed by putting them in the rows or columns before and after must be moved to the correct cell and put in a \verb/\pile/. \end{itemize} \item[Version 2:] Horizontal arrows made to stretch to meet objects and ``superscript'' labels introduced; widely circulated versions with a banner dated September to December 1989. \begin{itemize} \item \verb/&\rTo\across3&/ should be changed to \verb/&&\rTo&&/; \verb/\across/ doesn't work at all with objects, and is only supported for arrows for backwards compatibility. \item The parameters \verb/\HorizontalMapLength/, \verb/\VerticalMapHeight/, \verb/\VerticalMapDepth/, \verb/\VerticalMapExtraHeight/, \verb/\VerticalMapExtraDepth/ and \verb/\DiagonalLineSegments/ are obsolete and should be removed. \item The labels on southeast and northwest diagonal lines have been interchanged (\verb/^/~and \verb/_/ previously meant left and right respectively for diagonals; they now mean --- more logically --- above and below). \item Diagonal lines are constructed differently; user-defined diagonal arrows should be replaced with \verb/\NNW/ {\em etc.,} and explicit movement of them removed. Where it is still necessary to define additional diagonal arrow commands, the coordinates, {\em e.g.\/} \verb/(2,4)/ must be given, and should be added to the definition. \item Bent lines, with \verb/\dlBent/ and \verb/\ruBentto/, currently do not work. Instead \verb/\HmeetV/ must be placed at the corner. \end{itemize} \item[Version 3:] Vertical maps also made to stretch to meet objects; current. \item[Future:] Diagonal lines will be made to stretch in so far as this is possible, so explicit movement of diagonals will become incompatible. It~is intended that a single command, such as \verb/\nwTo/, will serve for all slopes, the slope being given by coordinates; since the parts of the arrow command will then the slope-dependent, the way of defining them will change. \end{description} The general rule with this version is to remove the hacks which were needed to position verticals {\em etc.\/} before. You must also be careful to ensure that every arrow is terminated by an object or pseudo-object at each end, and that there is the correct number of \verb/&/s. Because of the way terminating objects control the behavious of arrows, this version is much less tolerant than earlier ones. Suggestions for improvements and further applications ({\em e.g.\/} proof nets and Petri nets) are welcome. In Imperial College, the package is available on {\tt/home/leonardo} and will be picked up automatically by the {\tt tex} and {\tt latex} commands. I would like to thank {\em Simon Ambler,} {\em Roger Crew,} {\em Valeria de~Paiva,} {\em Eugenio Moggi,}, {\em Luke Ong,} {\em Vaughn Pratt\/} and {\em Jane Spurr,} who have used pre-release versions, for their comments and suggestions {\em and request those who use this package in their published papers to acknowledge me.} \clearpage \begin{verbdiag} &&&&&&&&&&&&&\\ &&&&&\relax\NNNW&&\relax\NNNE&&&&&&\\ &&&&&&&&&&&&&\\ &&&&&\relax\NNW&&\relax\NNE&&&&&&\\ &&&&&\relax\nNW&&\relax\nNE&&&&&&\\ &\relax\WWNW&&\relax\WNW&\relax\wNW&\relax\NW&\relax \uArr&\relax\NE&\relax\eNE&\relax\ENE&&\relax\EENE&&\\ &&&&&\relax\lArr&*&\relax\rArr&&&&&&\\ &\multispan5\verb/&&&&&\WWSW\WSW\wSW\SW\sSW\SSW\SSSW/&\relax\dArr& \multispan6\verb/&\SE\eSE\sSE\ESE\SSE\SSSE\EESE&&&&&/&\\ &&&&&&&&&&&&&\\ &&&&&&&&&&&&&\\ &&&&&&&&&&&&&\\ &&&&&&&&&&&&&\\ &&&&&&&&&&&&& \end{verbdiag} \noindent produces (the arrows but not the labels of): $$\hidewidth\diagram &&&&\verb/\NNNW/&&&&\verb/\NNNE/\\ &&&&&\NNNW&&\NNNE\\ &&&&\verb/\NNW/&&&& \verb/\NNE/\\ &&&& \verb/\nNW/ &\NNW & \verb/\uArr/ &\NNE & \verb/\nNE/ \\ \verb/\WWNW/&&\verb/\WNW/&\verb/\wNW/ & \verb/\NW/ & \nNW & & \nNE & \verb/\NE/ & \verb/\eNE/ & \verb/\ENE/ &&\verb/\EENE/\\ &\WWNW&&\WNW& \wNW & \NW & \uArr & \NE &\eNE &\ENE &&\EENE\\ &&&\verb/\lArr/ & & \lArr & * & \rArr & & \verb/\rArr/ \\ &&&&&\WWSW\WSW \wSW \SW \sSW\SSW\SSSW & \dArr & \SE \eSE \sSE \ESE \SSE \SSSE \EESE \\ \verb/\WWSW/&&\verb/\WSW/&\verb/\wSW/ & \verb/\SW/ & & & & \verb/\SE/ & \verb/\eSE/ &\verb/\ESE/&&\verb/\EESE/\\ &&&& \verb/\sSW/ & & \verb/\dArr/ & & \verb/\sSE/ \\ &&&&\verb/\SSW/&&&& \verb/\SSE/\\ \\ &&&&\verb/\SSSW/&&&&\verb/\SSSE/\\ \enddiagram\hidewidth$$ \end{document}