I am trying to compile \xymatrix{A\ar@{\sim>}[r] & B} in LyX and I get the following error message: enter image description here

How can I fix this? The code compiles in ERT, just not in the native xypic mathmode.

Here is a link to MWE.lyx

  • \sim is mathmode. Try replacing it for a tilde ~ – JJM Driessen Sep 19 '15 at 13:43
  • @JJMDriessen didn't work either. Exactly the same errors. – Exterior Sep 19 '15 at 13:48
  • I've added some MWE code in the answer below that doesn't produce the error. – JJM Driessen Sep 19 '15 at 14:00
  • @Exterior can you please post an MWE .lyx file? Please read wiki.lyx.org/FAQ/MinimalExample – scottkosty Sep 19 '15 at 18:54
  • @scottkosty added a link. – Exterior Sep 22 '15 at 11:46

Your problem is that the xypic package requires some special characters (in particular the tilde ~), which is automatically rewritten by the math editor in LyX. It is somewhat cumbersome to make LyX insert a true tilde into the source code.

But this is a case where the LyX "Macro" feature comes in handy.

  1. Go to Insert -> Math -> Macro.
  2. Write \sqarrow instead of \newmacroname.
  3. Then you copy the text \ar@{~>}[r], and paste it directly into the TeX field of the LyX macro.
  4. Finally, in the LyX field of the macro, enter some symbol that resemble the output symbol, such as ~~> or \rightarrow.

You have now created a macro \sqarrow for the squiggly arrow, which you can use directly in the LyX math editor.

For the record, LyX rewrites this macro as \global\long\def\sqarrow{\ar@{~>}[r]} in the LaTeX source code.

  • If you think this is a bug in LyX (or you have an idea for how LyX can do this better), please open a ticket at lyx.org/trac – scottkosty Sep 26 '15 at 15:50
  • Actually, this issue is just now being discussed in the lyx-devel mailing list. As for today, there is no convenient way of inserting pure tex code into the LyX math editor. – akvilas Sep 27 '15 at 17:15
  • Ah I did not realize that was the same issue. Thanks for pointing that out! – scottkosty Sep 27 '15 at 20:08

The shape input of \xymatrix in \ar@{shape}[direction] does not use mathmode and uses its own interpreter to recognize types of arrow shapes. The input is independent of the environment, and works both in textmode and mathmode:

\usepackage[all,cmtip]{xy} % include cmtip or your arrow will be ugly

\xymatrix{A\ar@{~>}[r] & B}

\xymatrix{A\ar@{~>}[r] & B}

enter image description here

  • Ah, now I see that the problem is actually with LyX. If I write the code in ERT then it works, but it won't compile within the native xypic framework. Can you help me solve this? – Exterior Sep 19 '15 at 14:08
  • @Exterior. I don't use LyX. Maybe checking out chapter 1 & 2 from this document would help: wiki.lyx.org/uploads/Examples/XY-pic/xypic.pdf Did you include the preview package? – JJM Driessen Sep 19 '15 at 14:23
  • Thanks for the suggestion but it seems to be a very specific error. All other arrows and diagrams work well for me... :( – Exterior Sep 19 '15 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.