3

I was trying to make a commutative diagram using something like \arrow[r, "A"] at some point, and I kept getting weird errors. I finally found out that I got no errors if I removed "dutch" from \usepackage[dutch, english]. Alternatively, I can get it to work by enclosing the tikzcd environment with \shorthandoff{"}...\shorthandon{"}. Apparently, something in "dutch" clashes with the use of " in \arrow[r, "A"]. Two questions.

  • What is exactly the clash here? What is "predefined" or whatever in the dutch option in babel that does not like the use of "" in the arrow command?

  • Is there a nicer solution to this problem? The only thing I can think of is to redefine the tikzcd environment to be something like

\shorthandoff{"}\begin{tikzcd}...\end{tikzcd}\shorthandon{"}

This is really just wrapping the earlier inelegant solution in a large blanket, so I'm not a fan.

Loading tikzlibrary{babel} solves the issue if one does not wrap the tikzcd in an align environment (and there is not a good reason to do this). I'm still curious what exactly align messes up here, though.

After all, a MWE. I do something like this.

\documentclass{report}

\usepackage[a4paper]{geometry}

\usepackage{libertine}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[dutch, english]{babel}

\usepackage{mathtools}

\usepackage{tikz}
    \usetikzlibrary{cd}
    \usetikzlibrary{babel}

\begin{document}

\begin{align*}
    \begin{tikzcd}[ampersand replacement = \&]
        A \arrow[r, "A"] \& B
    \end{tikzcd}
\end{align*}

\end{document}

15
  • 3
    \usepackage[dutch]{babel} probably makes " an active character. Did you try \usetikzlibrary{babel}?
    – frougon
    Commented Apr 4, 2020 at 13:28
  • This is what I have read elsewhere. I have tried your suggestion, but it gives me the same error. Edit: this does work in the normal case, my apologies. Now I should provide a MWE, and I will. Commented Apr 4, 2020 at 13:31
  • If the babel tikz lib does not work please post a full minimal example others can copy and test
    – daleif
    Commented Apr 4, 2020 at 13:33
  • It does fix the error with e.g. \documentclass{article} \usepackage[dutch]{babel} \usepackage{tikz-cd} \usetikzlibrary{babel} \begin{document} \begin{tikzcd} A \arrow[rd] \arrow[r, "\phi"] & B \\ & C \end{tikzcd} \end{document}. But since @BPasternak did not post a minimal working example, it is basically impossible to help without a crystal ball.
    – frougon
    Commented Apr 4, 2020 at 13:37
  • 3
    This proves once again that preparing an MWE allows people to solve many problems by themselves.
    – frougon
    Commented Apr 4, 2020 at 13:53

2 Answers 2

7

First some general words. We invite to present the question with a minimal example of code for several reasons:

  • often the question is presented with no hint about the actual error message(s);
  • preparing a MWE sometimes helps in spotting the error or in finding a workaround;
  • it's kind to whoever wants to help.

More specific to your post, you probably had two sources for errors. One due to babel making " active for Dutch, the other one because of using tikzcd inside an align environment.

Solution for the first problem: \usetikzlibrary{babel}.

Solution for the second problem: use the ampersand replacement=\& option and \& in the body of tikzcd to mark column delimiters. But also \shorthandoff{"} and \shorthandon{"}.

Why is that? Because align (and the other amsmath display environments) absorb the contents as the argument to a macro and so tikzcd cannot do the trick it usually does to &. Neither it can do the job for ".

If you're used to generally employ align or align* for single equation (or diagram), change your habit and use equation or equation* in these cases. It's semantically sounder, more efficient and avoids doing some tricks. Moreover, the spacing is better. I guess you can spot below the difference in spacing, which is excessive with align*.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[dutch, english]{babel}

\usepackage{mathtools}

\usepackage{tikz-cd}
\usetikzlibrary{babel}

\usepackage{lipsum} % for mock text

\begin{document}

\lipsum[2][1-2]
\begin{equation*}
    \begin{tikzcd}
        A \arrow[r, "A"] & B
    \end{tikzcd}
\end{equation*}
\lipsum[2][1-2]
\shorthandoff{"}\begin{align*}
    \begin{tikzcd}[ampersand replacement = \&]
        A \arrow[r, "A"] \& B
    \end{tikzcd}
\end{align*}\shorthandon{"}%
\lipsum[3]

\end{document}

enter image description here

2
  • I obviously agree, but I do think that the words "often" and "sometimes" definitively apply and leave room for questions without an MWE. Moving on now, MWEing everything and anything, happy times. Commented Apr 4, 2020 at 14:43
  • 2
    @BPasternak I'd say that depends a lot on how many points you have. Look at the plethora of questions where the first few comments are a request for an MWE. Just as the site tells commenters to be nice, it should also ask users to always provide an MWE, we waste sooo much time without it.
    – daleif
    Commented Apr 4, 2020 at 16:48
2

My answer is off-topic with the tags I hope to have understood your request. I have used xy package without the hard tip arrows 😉 with the options [all,cmtip] leaving your babel \usepackage[dutch]{babel}.

PS: I have only thinked an alternative.

\documentclass[a4paper,12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[dutch,english]{babel}
\usepackage{mathtools}
\usepackage[all,cmtip]{xy}

\begin{document}
One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. 
\begin{align*}
\xymatrix@1{
A\ar[r]^A & B}  
\end{align*}
The bedding was hardly able to cover it and seemed ready to slide off any moment.
\begin{align*}
\xymatrix@1{
A\ar[r]^A & B}  
\end{align*}
Gregor then turned to look out the window at the dull weather. Drops
\end{document}

enter image description here

You must log in to answer this question.

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