# Weird error with xymatrix and pmatrix.

Please look at the following minimal example:

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
$$\xymatrix{ \begin{pmatrix} 1 & 1\end{pmatrix} }$$
\end{document}


The output I get is the following:

[PDFLaTeX] test.tex => test.pdf (pdflatex)
[PDFLaTeX] finished with exit status 1
./test.tex:0:No file test.aux.
./test.tex:7:Extra }, or forgotten \endgroup. }
./test.tex:7:Missing \endgroup inserted. }
./test.tex:7:Missing } inserted. }
./test.tex:7:\begin{document} ended by \end{pmatrix}. }
./test.tex:7:Missing } inserted. }
./test.tex:7:Missing \$ inserted. }
./test.tex:7:Missing } inserted. }
./test.tex:7:Missing } inserted. }
./test.tex:7:Missing } inserted. }
./test.tex:7:Missing } inserted. }
./test.tex:7:Missing \cr inserted. }
./test.tex:7:Misplaced \cr. }
./test.tex:7:Missing \cr inserted. }
./test.tex:7:Misplaced \cr. }
./test.tex:7:Missing \cr inserted. }
./test.tex:7:Misplaced \cr. }
./test.tex:7:Missing \cr inserted. }
./test.tex:7:Misplaced \cr. }
./test.tex:7:Missing \cr inserted. }


It goes on like that "for ever". What's the problem here? Does xymatrix not work well with pmatrix?

use it this way:

\documentclass{article}
\usepackage[all]{xy}
\usepackage{amsmath}
\begin{document}

\xymatrix{ {\begin{pmatrix} 1 & 1\end{pmatrix}} }

\end{document}

• @Rasmus: Don't forget that you can "accept" the answer if it worked for you -- click the checkbox on the left of this answer right below its score. This will notify the others that this solution worked for you. Mar 8 '11 at 17:47
• @Martin: I'd usually wait with such comments (see our Building Blocks), but probably you've seen that. Mar 8 '11 at 18:37
• @Martin: Thanks, I am aware of that (as becomes apparent when looking at my profile). I do not think that it is advisable to accept the first answer right after posting the question. This answer helped me very much, though, and I will soon accept it unless someone comes across who explaines me even why the extra parentheses are necessary. Mar 8 '11 at 21:21
• @Rasmus: The alignment character & has a meaning both to \xymatrix and to pmatrix. By grouping the complete inner matrix in braces, you ensure that pmatrix evaluates it before \xymatrix does. Mar 8 '11 at 22:17

Notice that the xyguide explain that entries should not start with a macro.

But here, the real problem is the "&" who is interpreted by xypic like a separator in the xymatrix (and not in the pmatrix).

For exemple, \xymatrix{ \begin{pmatrix} 1 \end{pmatrix} } works fine.