TikZ 图表中的巴西语言问题

TikZ 图表中的巴西语言问题

我在使用 TikZ 图表时遇到了问题,我无法使用babelbrazil语言制作图表。我使用了代码french,一切正常!

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

答案1

这基本上等同于Tikz 和 babel 错误

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

不幸的是,\usetikzlibrary{babel}似乎不起作用tikz-cd

更新

tikz-cd0.9c 版本(2014 年 10 月 20 日发布)开始,该babel库已得到支持并可进行以下工作。

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

答案2

portuges.ldf(通过选项加载brazil)会"激活简写,从而扰乱tikz-cd代码。可以通过以下方式禁用简写\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}此示例不起作用,tikz-cd似乎期望"catcode 为 12(其他),请参阅\tikzcd@enablequotes。)

补丁版本

以下示例修补一些 TikZ 宏以支持活动引号:

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

相关内容