Short explanation of XYPIC

[ambient page updated 11 Oct 05] ... [ home ] ... [ garrett@umn.edu ]

%% This is a brief intro to use of the TeX/LaTeX package "xypic",
%% whose principal use is to make diagrams and arrows.
%
%% To invoke the package, at the top of your document have lines

\input xy
\xyoption{all}

%% FYI, contrary to old documentation, the $X_Y$-pic homepage is NOT
%% 
%% $$\hbox{http://www.ens-lyon.fr/${}\,^~$}krisrose/Xy-pic.html}$$

%% The main function of this package is to create arrows of various
%% styles and shapes among entries in a "matrix". In plain TeX, for
%% example, entries are TeX expressions, separated by &'s, with \cr
%% (carriage returns) for end-of-lines. The xypic package creates
%% _arrows_ among the entries, by appending \ar (with modifiers) to
%% various of the matrix entries. As an example, 

$$\xymatrix{
A & B\ar[d] & C \cr
D\ar[ur] & E & F\ar[ull]\ar[ul] \cr
}
$$

%% (when TeX'd) creates a math-displayed matrix with entries A,B,C in
%% the top row, and D,E,F in the lower row. The arrow \ar[d] attached
%% to B goes Down. The arrow \ar[ur] attached to D, which means an
%% arrow to go Up+Right. The \ar[ull] 
%% arrow attached to the entry F goes Up+Left+Left, and the _second_
%% arrow, \ar[ul], attached to F goes Up+Left. The Up/Down and
%% Right/Left indications inside the brackets are the _hop_.

%% Arrow styles can be changed as \ar@{style}[hop]
%%
%% where "style" can be =>  .>  :>  ~>  --> - + or empty
%% The hop descriptor comes _after_ the style change.

$$\xymatrix{
A & B\ar@{.>}[d] & C \cr
D\ar[ur] & E & F\ar@{-->}[ull]\ar@{=}[ul] \cr
}
$$

%% Labels on arrows: syntax is
%%
%%   \ar@{style}[hop]^{toplabel}_{lowerlabel}
%%
%% That is, the label comes _last_.
%%
%% For centering/balancing of the label _on_the_arrow_, use minus -
%% after the ^ or _ 

%% E.g., the following is bad, as it is without centering

$$\xymatrix{
A \ar@{-}[r] \ar@{-}[d] \ar@{-->}[dr]
 & B \ar@{-}[d]
\cr
C \ar@{->}[r]^{a}_{b} & {A\times B\times C \times D} 
}
$$

%% repaired, with centering

$$\xymatrix{
A \ar@{-}[r] \ar@{-}[d] \ar@{-->}[dr]
 & B \ar@{-}[d]
\cr
C \ar@{->}[r]^-{a}_-{b} & {A\times B\times C \times D} 
}
$$

%% Breaks: \ar[r]|f inserts an f _in_ the arrow:

$$\xymatrix{
A \ar@{-}[r] \ar@{-}[d] \ar@{-->}[dr]|g
 & B \ar@{->}[d]
\cr
C \ar@{->}[r]|f & D 
}
$$

%% a break with no label is simply "\hole", as in

$$
\xymatrix{
A \ar@{=>}[r]|\hole & B \cr
}$$

%% Curving in arrow style, @/curvingstyle/, namely @/^/, @/_/

$$
\xymatrix{
A \ar@/^/[r] & B\ar@/^/[l] \cr
}$$

%% Can insert a dimension as an _amount_ to curve up or down

$$
\xymatrix{
A \ar@/^/[r]\ar@/^1pc/[r] & B\ar@/^/[l] \cr
}$$

%% Boxes around entries:

%% *+[F]{B} acts on "B" by making a box around it

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




Unless explicitly noted otherwise, everything here, work by Paul Garrett, is licensed under a Creative Commons Attribution 3.0 Unported License. ... [ garrett@umn.edu ]

The University of Minnesota explicitly requires that I state that "The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota."