6

Here is an example of the problem I encounter with xypic

\documentclass[10pt,a4paper,french,oneside]{amsbook}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[applemac]{inputenc}
\usepackage[all,cmtip]{xy}
\begin{document}
\[
\xymatrix@!{
P\ar[r]^{p_{2}}\ar[d]_{p_{1}}&Y\ar[d]^g\\
X\ar[r]^f&Z}
\]
\end{document}

And below is the error I got when I typeset

./essai.tex:16: Xy-pic error: <addop> or <direction> or one of    1RCMLHW*! expect
ed.
\xyerror@ ...#2}\fi \errmessage {Xy-pic error: #1}
                                              }
l.16     \xymatrix@!
                {

I strongly suspect it comes from babel and the french option messing up stuff, since the character ! does not seem to be recognized (@R works fine for instance). What can I do about that ?

2 Answers 2

4

Solving the problem for ! is not sufficient, as also ?;:^=" are used in Xy-pic syntax.

You can globally solve it by disabling shorthands in all Xy-pic constructions:

\documentclass[10pt,a4paper,french,oneside]{amsbook}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[all,cmtip]{xy}
\usepackage{etoolbox}

\preto\xy{\shorthandoff{!?;:^="}}

\begin{document}
\[
\xymatrix@!{
P\ar[r]^{p_{2}}\ar[d]_{p_{1}}&Y\ar[d]^g\\
X\ar[r]^f&Z}
\]
\end{document}

Without etoolbox it would be, instead of \preto\xy{...},

\toks0=\expandafter{\xy}
\edef\xy{\noexpand\shorthandoff{!?;:^="}\the\toks0 }
12
  • Very useful answer ! After the one of David Carlisle, I was using the option \shorthandoff as a global option parameter of the babel package, but I think yours is more precise and allow fine tuning with less side effects. Thank you very much.
    – brunoh
    Apr 30, 2015 at 18:19
  • I tested it but unfortunately a construction like A_{\varphi^{-1}(q)} \ar@{}[r]^(.25){}="a"^(.75){}="b" \ar "a";"b"^{\varphi_{q}} & B_{q} inside a xymatrix bracket does not seem to work anymore : the ; character does not seem to be handled well anymore ... Do you know what is happening ?
    – brunoh
    Apr 30, 2015 at 18:27
  • @brunoh Here's what I get from \xymatrix{ A_{\varphi^{-1}(q)} \ar@{}[r]^(.25){}="a"^(.75){}="b" \ar "a";"b"^{\varphi_{q}} & B_{q} } : i.sstatic.net/KTWQL.png
    – egreg
    Apr 30, 2015 at 21:07
  • Yes, you are right. In my main file, I used \preto\xy{\shorthandoff{!?;:}} before the declaration of the xy package. If I put it after, everything works fine ! Thank you again I will choose your answer as the preferred one but I also like the one of David Carlisle ...
    – brunoh
    Apr 30, 2015 at 21:59
  • 1
    @MetalMathician Added also "
    – egreg
    Jul 14, 2022 at 13:21
6

You can locally get ! back with \shorthandoff{!} :

\documentclass[10pt,a4paper,french,oneside]{amsbook}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[applemac]{inputenc}
\usepackage[all,cmtip]{xy}
\begin{document}
\[\shorthandoff{!}
\xymatrix@!{
P\ar[r]^{p_{2}}\ar[d]_{p_{1}}&Y\ar[d]^g\\
X\ar[r]^f&Z}
\]
\end{document}
1
  • @David_Carlisle Clear & precise answer ! Very useful for me because I also learn the mechanism of getting rid of shorthands in babel locally or globally. Thank you very much.
    – brunoh
    Apr 30, 2015 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .