Tikz-cd problems whilst also using breqn package
In order to cope with babel
that may make ;
into an active character (with French, for instance), Tikz provides a definition for the active ;
as \tikz@nonactivesemicolon
which is just a standard category code 12 semicolon.
However, breqn
changes the mathcode of ;
to "8000
(hexadecimal, in decimal it is 32768), usually known as math active. This means that when TeX finds a semicolon in math mode it looks for its definition as an active character, which is \tikz@nonactivesemicolon
that becomes ;
, which is math active, so it is replaced by its definition, which is \tikz@nonactivesemicolon
…
Infinite loop.
Of course, breqn
defines the active semicolon in a different way, but in a tikzpicture
(or tikz-cd
which internally is a tikzpicture
) this meaning is overridden.
You could input the semicolon as
\mathchar\numexpr"6000+`;\relax
but it's simpler to not use breqn
.
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usepackage{breqn}
\DeclareMathOperator{\Hom}{Hom}
\begin{document}
\begin{tikzcd}
0 \arrow[r] & \ker h \arrow[r] &
H(C\mathchar\numexpr"6000+`;\relax G) \arrow[r] & \Hom(H_n(C),G) \arrow[r] & 0
\end{tikzcd}
\end{document}
Note how I input \ker
and define an operator name for \Hom
.
A more friendly solution:
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\makeatletter
\protected\edef\tikz@nonactivesemicolon{%
\noexpand\ifmmode
\mathchar\the\mathcode`;
\noexpand\else
;%
\noexpand\fi
}
\makeatother
\usepackage{breqn}
\DeclareMathOperator{\Hom}{Hom}
\begin{document}
\begin{tikzcd}
0 \arrow[r] & \ker h \arrow[r] &
H(C;G) \arrow[r] & \Hom(H_n(C),G) \arrow[r] & 0
\end{tikzcd}
\end{document}
Note that also colon, bar and exclamation mark might give a similar problem. A complete fix:
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\makeatletter
\def\fixtikzforbreqn#1#2{%
\protected\edef#1{\noexpand\ifmmode\mathchar\the\mathcode`#2 \noexpand\else#2\noexpand\fi}%
}
\fixtikzforbreqn\tikz@nonactivesemicolon;
\fixtikzforbreqn\tikz@nonactivecolon:
\fixtikzforbreqn\tikz@nonactivebar|
\fixtikzforbreqn\tikz@nonactiveexlmark!
\makeatother
\usepackage{breqn}
\DeclareMathOperator{\Hom}{Hom}
\begin{document}
\begin{tikzcd}
0 \arrow[r] & \ker h \arrow[r] &
H(C;G) \arrow[r] & \Hom(H_n(C),G) \arrow[r] & 0:!|
\end{tikzcd}
\end{document}
I agree with @daleif and @egreg that you shouldn't use breqn. Here is a way to use it, if you absolutely must, and do not have the egreg's knowledge about active characters, but want to add something that causes trouble. Just use a savebox.
\documentclass[11pt,a4paper]{article}
\usepackage{tikz-cd}
\usepackage{breqn}
% \usepackage{amsmath}
% \DeclareMathOperator{\Hom}{Hom}
% \DeclareMathOperator{\ker}{ker}
\newsavebox\DontUseBreqn
\begin{document}
\savebox\DontUseBreqn{$H(C; G)$}
\begin{tikzcd}
0 \arrow{r} & \mathrm{ker} h \arrow{r} & \usebox\DontUseBreqn \arrow{r} &
\mathrm{Hom}(H_n(C),G) \arrow{r} & 0 \\
\end{tikzcd}
\end{document}
But really you should just not use breqn.