(commutative) diagrams in latex

niedziela, 21 lutego 2010 by Michał Jezierski
I spent a lot of time searching for good latex package for drawing diagrams - commutative diagrams and other "structures" which contains arrows and objects. I found pictexwd and dcpic packages. It produces clean and good-looking drawings but drawing diagrams is still not easy and time-consuming. Let's start with some diagram examples.

At first take a look at what you can do: http://jezier.net/files/latex-diagram-example.pdf (whole soure code is available at http://jezier.net/files/latex-diagram-example.tex). This document is a part of my master thesis available at http://jezier.net/files/equationaly-definable-functors.pdf where you can find much more latex diagram examples.

If you want to start working with diagrams you need this two packages: pictexwd, dcpic.

Let's start with our latex document preambule:

\documentclass[oneside,12pt, titlepage]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{ntheorem}
\usepackage{pictexwd, dcpic}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
\newcommand{\rmod}{R\operatorname{-Mod}}
\newcommand{\id}{\operatorname{id}}
\newcommand{\Lim}{\underset{\longrightarrow}{\lim}}
\newcommand{\Hom}{\operatorname{Hom}_R}
\newcommand{\F}{\mathcal{F}}
\newcommand{\map}{\operatorname{Map}}
\begin{document}
\baselineskip18pt
\theoremheaderfont{\scshape} \theorembodyfont{\normalfont\slshape} 

Notice that we created some user defined command shortcuts which we will use in our examples:

\newcommand{\rmod}{R\operatorname{-Mod}}
\newcommand{\id}{\operatorname{id}}
\newcommand{\Lim}{\underset{\longrightarrow}{\lim}}
\newcommand{\Hom}{\operatorname{Hom}_R}
\newcommand{\F}{\mathcal{F}}
\newcommand{\map}{\operatorname{Map}} 
 
Diagrams are created using \begindc{0}[3] opening and \enddc closing commands. In \begindc{0}[3] "0" indicates style of arrowheads and "3" is arrow length. Take a look at

$$
\begindc{0}[3]
\obj(10,11)[1]{$\ldots$}
\obj(28,11)[2]{$X_{i-1}$}
\obj(46,11)[3]{$X_i$}
\obj(64,11)[4]{$X_{i+1}$}
\obj(82,11)[5]{$\ldots$}
\mor{1}{2}{$ $}
\mor{2}{3}{$\scriptstyle f_i$}
\mor{3}{4}{$\scriptstyle f_{i+1}$}
\mor{4}{5}{$ $}
\enddc
$$



There are some \obj and \mor commands. \obj(46,11)[3]{$X_i$}
means, that at (46, 11) there will appear an object (diagram node) which we can refer back later as 3 (object name is arbitrary, here we use "3"). Typical \mor command looks like \mor{2}{3}{$\scriptstyle f_i$} and it means, that between objects called "2" and "3" there will appear an arrow with $\scriptstyle f_i$ text over it.

Of course you can write multi-row diagrams with different arrow styles:

$$
\begindc{0}[3]
\obj(15,20){$B$}
\obj(33,20){$X$}
\obj(33,2){$Y$}
\mor(15,20)(33,20){$\scriptstyle i$}[1,3]
\mor(15,20)(33,2){$\scriptstyle \alpha$}
\mor(33,20)(33,2){$\scriptstyle \bar{\alpha}$}[1,1]
\enddc
$$



$$
\begindc{0}[3]
\obj(0,8)[q]{$\Hom\!\big(\!G(X),Y\!\big)$}
\obj(35,8)[w]{$\Hom\!\big(\!\F(X),Y\!\big)$}
\obj(0,-8)[a]{$A(X,Y)$}
\obj(35,-8)[s]{$\map(X,Y)$}
\mor{q}{w}{$\scriptstyle \varphi^*_X$}
\mor{a}{s}{$ $}[1,3]
\mor{q}{a}{$\scriptstyle \simeq$}
\mor{w}{s}{$\scriptstyle \simeq$}
\enddc
$$




$$
\begindc{0}[3]
\obj(0,0)[a]{$x'$}
\obj(0,-15)[z]{$\bar{x}'$}
\obj(20,-15)[x]{$\nu_Y(y')$}
\obj(12,0)[s]{$f'\!(\!x'\!)$}
\obj(20,0)[s']{$y'$}
\obj(40,0)[d]{$i_Z(z)$}
\obj(40,-15)[c]{$0$}
\obj(40,15)[e]{$z$}
\mor{a}{z}{$ $}[1,4]
\mor{z}{x}{$ $}[1,4]
\mor(12,-1)(19,-15){$ $}[1,4]
\mor{s'}{x}{$ $}[1,4]
\mor{a}{s}{$ $}[1,4]
\mor{s'}{d}{$ $}[1,4]
\mor{x}{c}{$ $}[1,4]
\mor{e}{d}{$ $}[1,4]
\mor{d}{c}{$ $}[1,4]
\enddc
$$


If you want, your arrows can be curved:

$$
\begindc{0}[3]
\obj(0,20)[1]{$\F(X_\alpha)/K(X_\alpha)$}
\obj(40,20)[2]{$\F(X_\beta)/K(X_\beta)$}
\obj(20,-10)[3]{$Y$}
\obj(20,5)[4]{$\F(X)/K(X)$}
\mor{1}{2}{$\scriptstyle (\!\F\!/\!K\!)\!(\!f^\alpha_\beta\!)$}
\mor(0,18)(20,7){$\scriptstyle (\!\F\!/\!K\!)\!(\!f^\alpha\!)$}
\mor(38,18)(20,7){$\scriptstyle (\!\F\!/\!K\!)\!(\!f^\beta\!)$}
\mor{4}{3}{$\scriptstyle g$}[1,1]
\cmor((0,16)(4,-2)(18,-10))
\pright(6,0){$\scriptstyle g^\alpha$}
\cmor((41,16)(36,-2)(22,-10))
\pleft(40,0){$\scriptstyle g^\beta$}
\enddc
$$



Here we curved an arrow (line) using \cmor (curvede morphism) command. It can pass an arbitrary number of parameters which are realy points of inflections. \pright and \pleft commands are used to place arrow labels at specified position.

And here is our last example:

$$
\begindc{0}[3]
\obj(45,36)[2]{$0$}
\obj(80,36)[3]{$0$}
\obj(45,21)[w]{$K(Y)$}
\obj(80,21)[e]{$K(Z)$}
\obj(8,1)[a]{$\F(X)$}
\obj(45,1)[s]{$\F(Y)$}
\obj(80,1)[d]{$\F(Z)$}
\obj(8,-19)[z]{$\F(X)/K(X)$}
\obj(45,-19)[x]{$\F(Y)/K(Y)$}
\obj(80,-19)[c]{$\F(Z)/K(Z)$}
\obj(8,-34)[v]{$0$}
\obj(45,-34)[b]{$0$}
\obj(80,-34)[n]{$0$}
\obj(100,1)[f]{$0$}
\obj(100,-19)[g]{$0$}
\mor{d}{f}{}
\mor{c}{g}{}
\mor{z}{v}{}
\mor{x}{b}{}
\mor{c}{n}{}
\mor{2}{w}{}
\mor{3}{e}{}
\mor{w}{e}{$\scriptstyle K(g)$}
\mor{s}{d}{$\scriptstyle \F(g)$}
\mor{x}{c}{$\scriptstyle (\F\!/\!K)(g)$}
\mor{z}{x}{$\scriptstyle f''$}
\mor{a}{s}{$\scriptstyle f'$}
\mor{w}{s}{$\scriptstyle i_Y$}
\mor{e}{d}{$\scriptstyle i_Z$}
\mor{a}{z}{$\scriptstyle \nu_X$}
\mor{s}{x}{$\scriptstyle \nu_Y$}
\mor{d}{c}{$\scriptstyle \nu_Z$}
\enddc
$$



Don't forget to put \end{document} command at the end of your document :)

That's all. I hope these examples were helpful.


Posted in Etykiety: , | 0 Comments »

Brak komentarzy:

Prześlij komentarz