我想用三种不同的语言(加泰罗尼亚语、西班牙语和英语)制作同一份文档的三个版本,同时保留一份源文档。为此,我定义了一个“doclanguage”宏,向其传递值 1、2 或 3,并结合“\ifcase \or \else \fi”结构来打印文档所需的语言版本。
(我还定义了一个“TFGdate”命令来创建仅包含(本地化的)月份和年份的日期。我使用过“datetime2”包,但发现有点混乱,所以决定用这种方式获取所需的日期。但我确信 \TFGdate 宏不是罪魁祸首。)
该文档很大,一切都很顺利,直到我决定插入一个 TikZ 示例(实际上是 TikZ 手册的示例之一),然后英文版没有问题,但加泰罗尼亚语或西班牙语版本无法编译,我不明白为什么,虽然我怀疑罪魁祸首是一个模糊的 babel 问题。
我已将代码简化为显示问题的 MWE:
\documentclass[a4paper,12pt]{book}
\usepackage{tikz}
\usetikzlibrary{angles,calc,quotes}
% Setting this to "3" (english) makes the document compile smoothly,
% but "1" (catalan) or "2" (spanish) don't compile
\newcommand\doclanguage{1}
% Language selection based on the language variable defined above
\ifcase\doclanguage\or
% Case 1
\usepackage[catalan]{babel}
\selectlanguage{catalan}%
\newcommand\TFGdate{%
\ifcase\month\or%
Gener\or Febrer\or Març\or Abril\or
Maig\or Juny\or Juliol\or Agost\or
Setembre\or Octubre\or Novembre\or Desembre\fi
\space de~\number\year%
}%
\or % Case 2
\usepackage[spanish,es-noquoting]{babel}
\selectlanguage{spanish}%
\newcommand\TFGdate{%
\ifcase\month\or%
Enero\or Febrero\or Marzo\or Abril\or
Mayo\or Junio\or Julio\or Agosto\or
Septiembre\or Octubre\or Noviembre\or Diciembre\fi
\space de~\number\year%
}%
\else % Case 3 (default)
\usepackage[english]{babel}
\selectlanguage{english}%
\newcommand\TFGdate{%
\ifcase\month\or%
January\or February\or March\or April\or
May\or June\or July\or August\or
September\or October\or November\or December\fi
\space\number\year%
}%
\fi
\begin{document}
\TFGdate
\begin{figure}[ht]
\centering
\begin{tikzpicture}[angle radius=.75cm]
\node (A) at (-2,0) [red,left] {$A$};
\node (B) at ( 3,.5) [red,right] {$B$};
\node (C) at (-2,2) [blue,left] {$C$};
\node (D) at ( 3,2.5) [blue,right] {$D$};
\node (E) at (60:-5mm) [below] {$E$};
\node (F) at (60:3.5cm) [above] {$F$};
\coordinate (X) at (intersection cs:first line={(A)--(B)}, second line={(E)--(F)});
\coordinate (Y) at (intersection cs:first line={(C)--(D)}, second line={(E)--(F)});
\path
(A) edge [red, thick] (B)
(C) edge [blue, thick] (D)
(E) edge [thick] (F)
pic ["$\alpha$", draw, fill=yellow] {angle = F--X--A}
pic ["$\beta$", draw, fill=green!30] {angle = B--X--F}
pic ["$\gamma$", draw, fill=yellow] {angle = E--Y--D}
pic ["$\delta$", draw, fill=green!30] {angle = C--Y--E};
\node at ($ (D)!.5!(B) $) [right=1cm,text width=6cm,rounded corners,fill=red!20,inner sep=1ex]
{
When we assume that $\color{red}AB$ and $\color{blue}CD$ are
parallel, i.\,e., ${\color{red}AB} \mathbin{\|} \color{blue}CD$,
then $\alpha = \gamma$ and $\beta = \delta$.
};
\end{tikzpicture}
\end{figure}
\end{document}
将“doclanguage”设置为“1”或“2”进行编译会引发很多错误(太长,无法在此处粘贴),首先是:
! Argument of \language@active@arg" has an extra }.
<inserted text>
\par
l.62 pic ["$\alpha$", draw, fill=yellow]
{angle = F--X--A}
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
! Paragraph ended before \language@active@arg" was complete.
<to be read again>
...
如果我继续编译而忽略错误(-interaction=nonstopmode)那么最终会产生结果但没有角度定义的希腊字母:
有什么想法吗?我没有想法...
答案1
正如一些人在评论中所建议的那样,解决方案是使用“babel”TikZ 库:
\usetikzlibrary{babel}