3

I'm trying to draw commutative diagrams with tikz-cd in a LaTeX presentation but I repeatedly get the error "! Argument of \language@active@arg" has an extra }.".

\documentclass{beamer}

\usepackage{tikz-cd}

\usepackage[ngerman]{babel}
\usetikzlibrary{babel}

\tikzset{
  every picture/.prefix style={
    execute at begin picture=\shorthandoff{"}
  }
}

\begin{document}
\begin{frame}
\begin{center}
\begin{tikzcd}[ampersand replacement=\&]
F(x) \arrow[r, "a"] \& G(x)
\end{tikzcd}
\end{center}
\end{frame}
\end{document}

Searching through this forum, I found several suggestions with \shorthandoff{"} or \usetikzlibrary{babel}. However, neither helps resolving the error (nor using both of them as in the above example code).

The code works without the "a" part in \arrow[r, "a"] and I also never had problems using tikzcd in english documents.

Where is my mistake and how can I possibly fix it?

2
  • @Zarko answer is the correct one, but if you do not need shorthands (if you use utf-8 they are not needed) you just load babel with \usepackage[ngerman, shorthands=off]{babel}.
    – Rmano
    Jul 23, 2020 at 9:51
  • @Rmano Thank you, that is an elegant solution!
    – Kezer
    Jul 23, 2020 at 9:57

2 Answers 2

3

See if the following workaround work for you:

\documentclass{beamer}
\usepackage[ngerman]{babel}
\usepackage{tikz-cd}
\usetikzlibrary{babel}

\usepackage{etoolbox}                       % <---
\AtBeginEnvironment{frame}{\shorthandoff{"}}% <---

\begin{document}
\begin{frame}
Some "text" \dots
    \begin{center}
\begin{tikzcd}[ampersand replacement=\&]
F(x) \arrow[r, "a"] \& G(x)
\end{tikzcd}
    \end{center}
\end{frame}
\end{document}

enter image description here

1

Another possibility is to use a different sintax to arrows so you don't have to turn off the shorthands:

\documentclass{beamer}

\usepackage{tikz-cd}

\usepackage[ngerman]{babel}
\usetikzlibrary{babel}

\begin{document}
\begin{frame}
\begin{center}
\begin{tikzcd}[ampersand replacement=\&]
F(x) \arrow[shift left]{r}{a} \arrow[shift right]{r}[swap]{b} \& G(x)
\end{tikzcd}
\end{center}
\end{frame}
\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 .