6

I have a problem with TikZ diagram, I don't get to make the diagram with babel under the brazil language. I used the code with french and everything is OK!

\documentclass[a4paper,12pt, brazil]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[body={16.5cm,24cm}]{geometry}
\usepackage{amsthm, amssymb}
\usepackage{babel}
\usepackage{comment} 
\usepackage{amsmath}
\usepackage{color}
\usepackage{graphicx}
\usepackage{tikz-cd}

\begin{document}

\begin{defi}

\[\begin{tikzcd}[column sep=small]
Y_1 \ar[dr, "\pi_1"'] \ar[rr, "f"]& & \ar[ld, "\pi_2"] Y_2 \\
& X &
\end{tikzcd}\]

\end{defi}

\end{document}
5

This is essentially the same as Tikz and babel error

\documentclass[a4paper,12pt, brazil]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{tikz-cd}

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

\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}

Unfortunately, \usetikzlibrary{babel} doesn't seem to work with tikz-cd.

Update

As of tikz-cd version 0.9c (released 2014/10/20), the babel library is supported and the following works.

\documentclass[a4paper,12pt, brazil]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{tikz-cd}[2014/10/20] % ensure it's version 0.9c or later
\usetikzlibrary{babel}

\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}
9

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.