[Xy-pic] Using macros in xymatrix

Andrew Clegg andrew.clegg at gmail.com
Thu Jul 26 17:22:51 CEST 2007


I'm using xymatrix to do various kinds of linguistic diagram, and it's
producing some great results. One thing I would like to do is define
some standard designs for common elements of the diagrams so that I
don't have to type them in each time I use them -- this would make the
xymatrix definitions quicker to write and much easier to read.

For example, one style that I use a lot is a word in fixed-space font
with a bit of extra spacing and a rectangular frame around it, like

*+[F]\txt{\tt sometext}

So I defined a macro called \lab (as in label) to represent this:

\newcommand{\lab}[1]{*+[F]\txt{\tt #1}}

I've also done the same for different arrow styles, e.g. arrows with
thicker lines:


So then you can say for example

\lab{foo} \arr{r}

for "foo" in a nice box with a thick arrow coming out the right side.
Works fine, and much simpler than the full xy syntax. However, I'd
also like to be able to use the style macros in labels on the arrows

\lab{foo} \arr{r}|\lab{bar}

But this doesn't work! I get an "Argument of \lab has an extra }"
message as if something fragile is getting expanded improperly. I
tried to protect it:

\lab{foo} \arr{r}|\protect\lab{bar}

but even more bizarrely, this results in an unbroken arrow with no label at all.

Does anyone have a workaround, or a better way to solve the problem
without using \newcommand?

Many thanks,


More information about the xy-pic mailing list