# xy + overrightarrow = error

M(non-)WE:

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
$\xymatrix{ \overrightarrow{C} }$
\end{document}


produces "ERROR: Illegal parameter number in definition of \lastprentry@@.". Any ideas?

-
For me, adding \usepackage{amsmath} fixes things: I suspect this is simply assumed by xy. – Joseph Wright Jul 12 '14 at 7:30

Add braces around the symbol, which is often the remedy to weird error messages from Xy-pic macros:

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
$\xymatrix{ {\overrightarrow{C}} }$
\end{document}


Or just add an empty group:

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
$\xymatrix{ {}\overrightarrow{C} }$
\end{document}


The problem is that \overrightarrow, being the first item in an alignment cell, gets expanded to

\vbox{\m@th\ialign{##\crcr <...>}


and this confuses the parsing commands of Xy-pic. This doesn't happen if a brace is found before \overrightarrow, because it will be expanded later. This doesn't happen also when amsmath is loaded, because the definition of \overrightarrow given by amsmath is “safer”.

-