# Missing \endcsname in Tikzcd

I have a problem with tikzcd.

I want to make the following diagram:

\begin{tikzcd}
G \ar[d, two heads, swap, "\varphi_1"] \ar[r, "\varphi_2"] & F_2 \\
F_1 \ar[ur, dashed, swap, "\varphi"] &
\end{tikzcd}


When I put it in a separate document, it works just as it should. But when I put it into a full document and compile it with MikTex (using Texworks) I get the following error:

! Missing \endcsname inserted.
\varphi
l.260 \end{tikzcd}


Any ideas what I can do with it?

• (1) welcome, (2) the best thing to do is take your problematic file, give it a new name. Start deleting/out commenting stuff, recompile, repeat. Then you'll figure out what is important to this issue, and what is not. Then post the result. As it fits now we cannot help as we have no information about the problematic doc. Sep 26, 2016 at 20:18

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[polish]{babel}

\usepackage{tikz-cd}

\begin{document}

\title{Tytuł}
\author{Paweł Piwek}

\maketitle

\begin{tikzcd}
G \ar[d, two heads, swap, "\varphi_1"] \ar[r, "\varphi_2"] & F_2 \\
F_1 \ar[ur, dashed, swap, "\varphi"] &
\end{tikzcd}

\end{document}


In this case, the first error message, which is the one you should report, is

! Argument of \language@active@arg" has an extra }.
<inserted text>
\par
l.18 \end{tikzcd}


and this is a babel problem. Fix it with \usetikzlibrary{babel}.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[polish]{babel}

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

\begin{document}

\title{Tytuł}
\author{Paweł Piwek}

\maketitle

\begin{tikzcd}
G \ar[d, two heads, swap, "\varphi_1"] \ar[r, "\varphi_2"] & F_2 \\
F_1 \ar[ur, dashed, swap, "\varphi"] &
\end{tikzcd}

\end{document}


For me the problems were caused by loading Babel with ngerman, i.e. \usepackage[ngerman]{babel}. Unfortunately, \usetikzlibrary{babel} suggested in the other answer did not fix the problem.

The solution which worked for me was to make " inactive again:

\begin{document}

% Then very soonish execute the following:
\shorthandoff{"}

...
...

• This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question. - From Review Jun 19, 2019 at 11:16
• @BambOo I don't have a question, instead, I wanted to give users visiting this question e.g. from Google (cf. the view count of 700!) an "additional" fix. Indeed, my answer might not have been the solution for OP, but at least on StackOverflow it's common to give additional useful answers to highly viewed questions. Jun 19, 2019 at 11:58
• IMHO, your answer is right (solves the OP issue) in the content but wrong in the form. Here, this type of answer is more likely to be a comment. Moreover, if your comment is relevant enough, people tend to ask you to re-post it as an answer. Finally, there are several clashes between babel and tikz, hence the answer from egreg and the babel tikzlibrary. Jun 19, 2019 at 13:06
• @BambOo I was under the impression that comments with contents (and which do not simply ask for clarification) are discouraged throughout the SE network. At leave I've already seen users being called out for this on multiple sites. Indeed, egreg's answer did not solve it in my case. I added that to the answer. Jun 19, 2019 at 13:13

I wanted to just add this in as a comment, but I'm new here. I thought it was worth mentioning that I encountered the same error message while using square brackets in tikzcd:

\begin{tikzcd}[row sep=tiny]

[ \Sigma^j X, \Sigma^j Y ]  \arrow{dr}{\phi_j} \arrow{dd}{\Sigma^{i}}\\

& Z \\

[ \Sigma^{i+j} X, \Sigma^{i+j} Y ] \arrow{ur}[below]{\phi_{i+j}}

\end{tikzcd}


It was solved by replacing [ and ] with \left[ and \right].

• Welcome to TeX.SX!. The error is different, and can be solved by changing \\ into \\ \relax when a bracket [ follows \\. Another method is using \lbrack and \rbrack instead of [ and ]. Oct 30, 2018 at 17:20

I had a very similar problem (Missing \endcsname inserted.) with a Tikz figure.

None of the above answers worked (even though I am using babel), so, after lots of searching, I commented out my package imports one by one, and found that the siunitx package singlehandedly caused the Tikz figure to crash at compilation. Might help someone out with the same error message and usage of Tikz.

• Welcome to TeX.SE! Jun 20, 2020 at 14:07