# LaTeX/Xy-pic

* LaTeX
* Getting Started
* Introduction
* Installation
* Installing Extra Packages
* Basics
* How to get help
* Common Elements
* Document Structure
* Text Formatting
* Paragraph Formatting
* Colors
* Fonts
* List Structures
* Special Characters
* Internationalization
* Rotations
* Tables
* Title creation
* Page Layout
* Customizing Page Headers and Footers‎
* Importing Graphics
* Floats, Figures and Captions
* Footnotes and Margin Notes
* Hyperlinks
* Labels and Cross-referencing
* Initials
* Mechanics
* Errors and Warnings
* Lengths
* Counters
* Boxes
* Rules and Struts
* Technical Text
* Mathematics
* Advanced Mathematics
* Theorems
* Chemical Graphics
* Algorithms
* Source Code Listings
* Linguistics
* Special Pages
* Indexing
* Glossary
* Bibliography Management
* More Bibliographies
* Special Documents
* Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
* Letters
* Presentations
* Teacher's Corner
* Curriculum Vitae
* Academic Journals (MLA, APA, etc.)
* Creating Graphics
* Introducing Procedural Graphics
* MetaPost
* Picture
* PGF/TikZ
* PSTricks
* Xy-pic
* Creating 3D graphics
* Programming
* Macros
* Plain TeX
* Creating Packages
* Creating Package Documentation
* Themes
* Miscellaneous
* Modular Documents
* Collaborative Writing of LaTeX Documents
* Export To Other Formats
* Help and Recommendations
* FAQ
* Tips and Tricks
* Appendices
* Authors
* Links
* Package Reference
* Sample LaTeX documents
* Index
* Command Glossary
xy is a special package for drawing diagrams. To use it, simply add the following line to the preamble of your document:
where "all" means you want to load a large standard set of functions from Xy-pic, suitable for developing the kind of diagrams discussed here.
The primary way to draw Xy-pic diagrams is over a matrix-oriented canvas, where each diagram element is placed in a matrix slot:
* \xymatrix{A & B \\
* C & D }
The \xymatrix command puts its contents in math mode. Here, we specified two lines and two columns. To make this matrix a diagram we just add directed arrows using the \ar command.
* \xymatrix{ A \ar[r] & B \ar[d] \\
* D \ar[u] & C \ar[l] }
The arrow command is placed on the origin cell for the arrow. The arguments are the direction the arrow should point to (up, down, right, and left).
* \xymatrix{
* A \ar[d] \ar[dr] \ar[r] & B \\
* D & C }
To make diagonals, just use more than one direction. You can repeat directions to make bigger arrows.
* \xymatrix{
* A \ar[d] \ar[dr] \ar[drr] & & \\
* B & C & D }
We can draw even more interesting diagrams by adding labels to the arrows. To do this, we use the common superscript and subscript operators.
* \xymatrix{
* A \ar[r]^f \ar[d]_g & B \ar[d]^{g'} \\
* D \ar[r]_{f'} & C }
As shown, you use these operators as in math mode. The only difference is that that superscript means "on top of the arrow", and subscript means "under the arrow". There is a third operator, the vertical bar: | It causes text to be placed in the arrow.
* \xymatrix{
* A \ar[r]|f \ar[d]|g & B \ar[d]|{g'} \\
* D \ar[r]|{f'} & C }
To draw an arrow with a hole in it, use \ar[...]|\hole. In some situations, it is important to distinguish between different types of arrows. This can be done by putting labels on them or changing their appearance
* \xymatrix{
* \bullet\ar@{->}[rr] && \bullet\\
* \bullet\ar@{.<}[rr] && \bullet\\
* \bullet\ar@{~)}[rr] && \bullet\\
* \bullet\ar@{=[rr] && \bullet\\
* \bullet\ar@{~/}[rr] && \bullet\\
* \bullet\ar@{^{->}[rr] && \bullet\\
* \bullet\ar@2{->}[rr] && \bullet\\
* \bullet\ar@3{->}[rr] && \bullet\\
* \bullet\ar@{=+}[rr] && \bullet }
Notice the difference between the following two diagrams:
* \xymatrix{ \bullet \ar[r] \ar@{.>}[r] & \bullet }
* \xymatrix{
* \bullet \ar@/^/[r]
* \ar@/_/@{.>}[r] &
* \bullet }
The modifiers between the slashes define how the curves are drawn. Xy-pic offers many ways to influence the drawing of curves; for more information, check the Xy-pic documentation.
If you are interested in a more thorough introduction then consult the Xy-pic Home Page, which contains links to several other tutorials as well as the reference documentation.