portuges.ldf
(loaded by option brazil
) makes "
an active shorthand
that disturbs the tikz-cd
code. The shorthand can be disabled via \shorthandoff
:
\documentclass[a4paper,12pt,brazil]{article}
\usepackage{babel}
\usepackage{tikz-cd}
\begin{document}
\shorthandoff{"}
\[\begin{tikzcd}[column sep=small]
Y_1 \ar[dr, "\pi_1"'] \ar[rr, "f"]& & \ar[ld, "\pi_2"] Y_2 \\
& X &
\end{tikzcd}\]
\shorthandon{"}
\end{document}
(\usetikzlibrary{babel}
didn't work for this example, tikz-cd
seems to expect a "
with catcode 12 (other), see \tikzcd@enablequotes
.)
Patch version
The following example patches some TikZ macros to support the active quotes:
\documentclass[a4paper,12pt,brazil]{article}
\usepackage{babel}
\usepackage{tikz-cd}
\makeatletter
\shorthandon{"}
% Patch for tikzlibarycd.code.tex
\g@addto@macro\tikzcd@enablequotes{%
\pgfkeys{%
/handlers/first char syntax/\meaning"/.initial=\tikzcd@passquotes
}%
}
% Patch for tikzlibraryquotes.code.tex
\def\active@tikz@quote@parser#1{\active@tikz@quote@@parser#1\pgf@stop}
\def\active@tikz@quote@@parser"#1"{%
\pgfutil@ifnextchar\bgroup{%
\tikz@quote@@parser@group{#1}}{%
\pgfutil@ifnextchar'{%
\tikz@quote@@parser@apo{#1}}{%
\tikz@quote@@parser@normal{#1}}}}
\g@addto@macro\tikz@enable@node@quotes{%
\pgfkeyssetvalue{/handlers/first char syntax/\meaning"}%
{\active@tikz@quote@parser}%
}
\g@addto@macro\tikz@enable@edge@quotes{%
\pgfkeyssetvalue{/handlers/first char syntax/\meaning"}%
{\active@tikz@quote@parser}%
}
\g@addto@macro\tikz@enable@pic@quotes{%
\pgfkeyssetvalue{/handlers/first char syntax/\meaning"}%
{\active@tikz@quote@parser}%
}
\shorthandoff{"}
\makeatother
\begin{document}
\[\begin{tikzcd}[column sep=small]
Y_1 \ar[dr, "\pi_1"'] \ar[rr, "f"]& & \ar[ld, "\pi_2"] Y_2 \\
& X &
\end{tikzcd}\]
\end{document}