install
source · Clone the upstream repo
git clone https://github.com/plurigrid/asi
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/plurigrid/asi "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/xypic-latex" ~/.claude/skills/plurigrid-asi-xypic-latex && rm -rf "$T"
manifest:
skills/xypic-latex/SKILL.mdsource content
XY-pic LaTeX Diagrams
Typeset commutative diagrams, automata, and categorical constructions using XY-pic in LaTeX, with inline Emacs preview via AUCTeX.
Setup
Preamble
\usepackage[all,cmtip]{xy}
loads every XY-pic extension (matrix, arrow, curve, frame, etc.)all
uses Computer Modern arrowheads (cleaner than default)cmtip
Emacs / AUCTeX preview
Add to init.el for inline
C-c C-p C-p preview of xymatrix environments:
(eval-after-load "preview" '(add-to-list 'preview-default-preamble "\\PreviewEnvironment{xymatrix}" t))
Ensure PDF mode is active:
C-c C-t C-p.
Core Syntax
Diagrams are matrices.
& separates columns, \\ separates rows. Arrows use \ar[direction] where direction combines: u(up), d(down), l(left), r(right).
Commutative Square
\[ \xymatrix{ A \ar[r]^f \ar[d]_g & B \ar[d]^h \\ C \ar[r]_k & D } \]
Arrow Labels
| Syntax | Position |
|---|---|
| label above/right of arrow |
| label below/left of arrow |
| label on arrow (breaks it) |
| `\ar[r] | -{f}` |
Arrow Styles
\ar@{->}[r] % normal (default) \ar@{.>}[r] % dotted \ar@{=>}[r] % double (natural transformation) \ar@{-->}[r] % dashed \ar@{~>}[r] % squiggly \ar@{->>}[r] % two-headed (epi) \ar@{^{(}->}[r] % hook (mono) \ar@{=}[r] % equals \ar@{}[r] % phantom (for label placement only)
Curved Arrows
\ar@/^/[r]^f % curve up/right \ar@/_/[r]_g % curve down/left \ar@/^1pc/[r] % curve with specific radius \ar@(ur,dr)[r] % loop from upper-right to down-right
Spacing Control
\xymatrix@R=2pc@C=3pc{...} % set row/column spacing \xymatrix@C-1pc{...} % reduce column spacing by 1pc \xymatrix@1{...} % entries are 1em wide
Common Diagram Patterns
Pullback / Fiber Product
\[ \xymatrix{ U \ar@/_/[ddr]_y \ar@/^/[drr]^x \ar@{.>}[dr]|-{(x,y)} \\ & X \times_Z Y \ar[d]^q \ar[r]_p & X \ar[d]_f \\ & Y \ar[r]^g & Z } \]
Short Exact Sequence
\[ \xymatrix{ 0 \ar[r] & A \ar[r]^i & B \ar[r]^p & C \ar[r] & 0 } \]
Adjunction
\[ \xymatrix@C=4pc{ \mathcal{C} \ar@<1ex>[r]^{F} \ar@{}[r]|{\perp} & \mathcal{D} \ar@<1ex>[l]^{G} } \]
Natural Transformation (2-cell)
\[ \xymatrix{ \mathcal{C} \rtwocell^F_G{\alpha} & \mathcal{D} } \]
(Requires
\usepackage[all,2cell]{xy} \UseTwocells)
Long Exact Sequence (wrapping)
\[ \xymatrix{ \cdots \ar[r] & H_n(A) \ar[r]^{i_*} & H_n(X) \ar[r]^{j_*} & H_n(X,A) \ar[dll]_{\partial} \\ & H_{n-1}(A) \ar[r]^{i_*} & H_{n-1}(X) \ar[r] & \cdots } \]
Cube Diagram
\[ \xymatrix{ A \ar[rr] \ar[dd] \ar[dr] && B \ar[dd] \ar[dr] \\ & C \ar[rr] \ar[dd] && D \ar[dd] \\ E \ar[rr] \ar[dr] && F \ar[dr] \\ & G \ar[rr] && H } \]
Automaton (DFA)
\[ \xymatrix{ *+[o][F-]{q_0} \ar[r]^a \ar@(ul,dl)[]_b & *+[o][F=]{q_1} \ar@/^/[r]^a \ar@(ur,dr)[]^b & *+[o][F-]{q_2} \ar@/^/[l]^{a,b} } \]
= circle, single border*+[o][F-]
= circle, double border (accepting state)*+[o][F=]
Tips
- Diagonal arrows:
goes down-right,\ar[dr]
goes up-left-left (two columns)\ar[ull] - Phantom arrows
place a symbol between entries without drawing\ar@{}[r]|{\cong} - Compile twice if arrow positions look wrong on first pass
- Debugging: add
to baseline-align entries\entrymodifiers={+!!<0pt,\fontdimen22\textfont2>} - 2-cells: load
and\usepackage[all,2cell]{xy}
for natural transformations\UseTwocells
Alternative: tikz-cd
For simpler syntax with TikZ backend:
\usepackage{tikz-cd} \[ \begin{tikzcd} A \arrow[r, "f"] \arrow[d, "g"'] & B \arrow[d, "h"] \\ C \arrow[r, "k"'] & D \end{tikzcd} \]
Both are available in
texliveFull.
References
- XY-pic User's Guide (PDF) — official reference
- Alsani's examples (PDF) — beginner walkthrough
- Milne's CD package comparison — xy-pic vs tikz-cd vs amscd
- Debray's automata guide (PDF) — XY-pic for DFA/NFA
- Run
locally for offline docstexdoc xypic