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}

  • 3
    \usepackage[dutch]{babel} probably makes " an active character. Did you try \usetikzlibrary{babel}? – frougon Apr 04 '20 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. – B. Pasternak Apr 04 '20 at 13:31
  • If the babel tikz lib does not work please post a full minimal example others can copy and test – daleif Apr 04 '20 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 Apr 04 '20 at 13:37
  • @frougon Perhaps read the edit to my comment first :D. – B. Pasternak Apr 04 '20 at 13:41
  • And there are still people with 2400+ rep who insist that they don't need to post an MWE! – frougon Apr 04 '20 at 13:44
  • Honestly, if I wasn't such an idiot as to use the align-environment in this case, your first comment (or me reading the tikzcd manual properly) would have solved my problem without an MWE. I don't like this public shaming thingy either, bruh. – B. Pasternak Apr 04 '20 at 13:49
  • 3
    This proves once again that preparing an MWE allows people to solve many problems by themselves. – frougon Apr 04 '20 at 13:53
  • No, it doesn't. I solved it without preparing the MWE. I did realise what was unstandard about my case by thinking about what I did that's not necessary to have such a commutative diagram with 2 languages. In any case, to make your point you do not have refer to another user. – B. Pasternak Apr 04 '20 at 13:56
  • I referred to the user (and did not name him) because his behavior is extremely selfish; I don't see why I would refrain to do so. – frougon Apr 04 '20 at 13:57
  • Because it serves no other purpose than providing anecdotal proof with a sample size of 1 that your statement is correct. But people will believe this without an example. What are you, a policeman here? You named him by linking directly to him! – B. Pasternak Apr 04 '20 at 13:58
  • I have a very wild guess as to where my downvote comes from! – B. Pasternak Apr 04 '20 at 14:15
  • Yet you are mistaken. Do you want me to show you? – frougon Apr 04 '20 at 14:18
  • Nah, I believe you, don't worry. It was a wild guess. – B. Pasternak Apr 04 '20 at 14:19
  • I added an upvoted! – Sebastiano Apr 04 '20 at 17:01

2 Answers2

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

egreg
  • 1,121,712
  • 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. – B. Pasternak Apr 04 '20 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 Apr 04 '20 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

Sebastiano
  • 54,118