1

I'm curently trying to write a simple commutative diagram through xypic, which works on one of my files, but I can't make it work on a new one :

\documentclass{article}
\usepackage[french]{babel}
\usepackage{xypic}

\begin{document}

$$\xymatrix@!0 @R=2pc @C=3pc { \mathcal{E}_1 \ar[rr]&& \mathcal{E}_2}$$ \end{document}

LaTeX tells me \mathcal is not accepted out of math mode, but I can't add $ inside xypic brackets and it does not seem that there is an equivalent of mathcal out of math mode. It seems to trigger an error because of the babel package, as it works well when i remove it. Still even putting xy package before or after, i get the error. Any hint on how to fix this?

  • 1
    Please always provide a test file that shows the error, not just a fragment. I completed your code to a minimal document, but I get no error, please edit to make it show the error, or show your log file so we can debug the error message – David Carlisle May 03 '22 at 16:12
  • Oh sorry, it's part of a very long article, that's why. – user269676 May 03 '22 at 16:18
  • Ok i got what make it not work (not how to solve it) I edit the post. – user269676 May 03 '22 at 16:20
  • Your code seems to work just fine. Note that you should always use \[...\] instead of $$...$$ (see here). – Sandy G May 03 '22 at 16:20
  • The issue is with the Babel package, I edit the post to explain – user269676 May 03 '22 at 16:21
  • You do not need to post a long original document, but you do need to post a complete document so that you can check that what you post is in fact an example of the problem (apparently it was not in this case if the issue is a conflict with babel which was not mentioned) – David Carlisle May 03 '22 at 16:25
  • Yes, the error comes from a conflict btween xypic and \usepackage[french]{babel} – user269676 May 03 '22 at 16:27
  • Do you really need @!0? – Sigur May 03 '22 at 21:36

2 Answers2

2

You need to set ! to be a normal character, not a French punctuation shorthand

\documentclass{article}
\usepackage[french]{babel}
\usepackage{xypic}

\begin{document}

\shorthandoff*{!} $$\xymatrix@!0 @R=2pc @C=3pc { \mathcal{E}_1 \ar[rr]&& \mathcal{E}_2}$$ \shorthandon{!}

\end{document}

Note that in the original document the error message highlights the ! it does not say that \mathcal is a problem. The error message is:

<xymatrix
! Xy-pic error: <addop> or <direction> or one of 1RCMLHW*! expected.
\xyerror@ ...#2}\fi \errmessage {Xy-pic error: #1}
                                                  }
l.8 $$\xymatrix@!
                 0 @R=2pc @C=3pc { \mathcal{E}_1 \ar[rr]&& \mathcal{E}_2}$$
?

The line break shows how far TeX had read, and it occurs immediately after ! it has not yet seen the \mathcal

David Carlisle
  • 757,742
  • Why not \shorthandoff{!} inside \[...\] so \shorthandon is not needed (and $$ is avoided)? – egreg May 03 '22 at 21:25
  • @egreg doing it out of the math seems more natural, apart from anything else it is needed if you try align rather than \[ I left the $$ rather than changing \[ as it's bad style but not related to the question. – David Carlisle May 03 '22 at 21:33
0

In general, enclosing \xymatrix inside an xy environment is not needed, but with babel-french it might be the solution to your problems, because we can instruct LaTeX to disable the shorthand characters upon entering the environment.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[cmtip]{xypic}

\AtBeginEnvironment{xy}{\shorthandoff{;:!?}}

\begin{document}

[ \begin{xy} \xymatrix@!0 @R=2pc @C=3pc { \mathcal{E}_1 \ar[rr]&& \mathcal{E}_2} \end{xy} ]

\end{document}

enter image description here

Please, note that $$ should never be used in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

egreg
  • 1,121,712