巴别塔和 pgf 间谍之间发生意外冲突

巴别塔和 pgf 间谍之间发生意外冲突

以下示例取自 pgfplots 手册 (第 121 页),仅当行 loadingbabel被注释时,才能正常工作

\documentclass{article}

\usepackage[frenchb]{babel} % this is the troubelsome line

\usepackage{pgfplots}
\usetikzlibrary{spy}

\begin{document}
\begin{tikzpicture}[spy using outlines=
{circle, magnification=6, connect spies}]
\begin{axis}[no markers,grid=major,
every axis plot post/.append style={thick}]
\addplot coordinates
{(0, 0.0) (0, 0.9) (1, 0.9) (2, 1) (3, 0.9) (80,
 0)};
\addplot +[line join=round] coordinates
{(0, 0.0) (0, 0.9) (2, 0.9) (3, 1) (4, 0.9) (80,
 0)};
\addplot +[line join=bevel] coordinates
{(0, 0.0) (0, 0.9) (3, 0.9) (4, 1) (5, 0.9) (80,
 0)};
\addplot +[miter limit=5] coordinates
{(0, 0.0) (0, 0.9) (4, 0.9) (5, 1) (6, 0.9) (80,
 0)};
\coordinate (spypoint) at (axis cs:3,1);
\coordinate (magnifyglass) at (axis cs:60,0.7);
\end{axis}
\spy [blue, size=2.5cm] on (spypoint)
in node[fill=white] at (magnifyglass);
\end{tikzpicture}

\end{document}

我收到以下错误

Runaway argument?
[fill=white] at (magnifyglass); 
! Paragraph ended before \tikz@lib@spy@parse@opta was complete.
<to be read again> 
                   \par 

我无法解释。

我使用的TeX Live是 Ubuntu 自带的发行版,但我手动安装了文本文件文件夹中一些软件包的较新版本,包括pgfpgfplots

您知道我该怎么做才能同时使用这两个工具babelspy图书馆吗?

答案1

语言french将设置;为活动字符:\shorthandoff{;}在图片前和\shorthandon{;}图片后使用不会出现问题。

\documentclass{article}

\usepackage[frenchb]{babel}

\usepackage{pgfplots}
\usetikzlibrary{spy}

\begin{document}
\shorthandoff{;}
\begin{tikzpicture}[spy using outlines=
{circle, magnification=6, connect spies}]
\begin{axis}[no markers,grid=major,
every axis plot post/.append style={thick}]
\addplot coordinates
{(0, 0.0) (0, 0.9) (1, 0.9) (2, 1) (3, 0.9) (80,
 0)};
\addplot +[line join=round] coordinates
{(0, 0.0) (0, 0.9) (2, 0.9) (3, 1) (4, 0.9) (80,
 0)};
\addplot +[line join=bevel] coordinates
{(0, 0.0) (0, 0.9) (3, 0.9) (4, 1) (5, 0.9) (80,
 0)};
\addplot +[miter limit=5] coordinates
{(0, 0.0) (0, 0.9) (4, 0.9) (5, 1) (6, 0.9) (80,
 0)};
\coordinate (spypoint) at (axis cs:3,1);
\coordinate (magnifyglass) at (axis cs:60,0.7);
\end{axis}
\spy [blue, size=2.5cm] on (spypoint)
in node[fill=white] at (magnifyglass);
\end{tikzpicture}
\shorthandon{;}
\end{document}

请注意,先前的 MWE 提出了以下警告

Package frenchb.ldf Warning: OT1 encoding should not be used for French.

可以通过以下方式避免:

\usepackage[T1]{fontenc} % before babel
\usepackage[frenchb]{babel}

和:

Package pgfplots Warning: running in backwards compatibility mode unsuitable tick labels; missing features).

可通过以下方式解决:

\usepackage{pgfplots}
\pgfplotsset{compat=1.6} % change this according to the current version of pgfplots

答案2

TikZ 通常对活动字符很智能,因此通常不需要\shorthandon,\shorthandoff对。但是,该spy库不包括 TikZ 在匹配其命令时使用的检查,并且只为加载时 catcode 分号的任何变体定义了一个变体。由于 babel 将其 catcode 更改为\begin{document},这意味着该\spy命令针对错误的 catcode 进行测试。正如 Claudio 所说,一种修复方法是将分号恢复到其原始状态。另一种修复方法是通过 TikZ 的智能分号处理来增强间谍库。以下代码执行第二种方法。

\documentclass{article}
%\url{http://tex.stackexchange.com/q/74860/86}
\usepackage[frenchb]{babel} % this is the troubelsome line

\usepackage{pgfplots}
\usetikzlibrary{spy}

\makeatletter
\def\tikz@lib@spy@parse@opt[#1]{%
    \let\tikz@spy@next=\tikz@lib@spy@parse@opta%
    \ifnum\the\catcode`\;=\active\relax
     \let\tikz@spy@next=\tikz@lib@spy@parse@opta@activesemicolon
    \fi
  \pgfutil@ifnextchar x{\tikz@spy@next[#1]}{\tikz@spy@next[#1]}%]
}
{
\catcode`\;=\active
\gdef\tikz@lib@spy@parse@opta@activesemicolon[#1]on#2in node#3;{%
  \pgfutil@g@addto@macro\tikz@lib@spy@collection{\tikz@lib@spy@do{#1}{#2}{#3}}%
}
}
\makeatother

\begin{document}

\begin{tikzpicture}[spy using outlines=
{circle, magnification=6, connect spies}]
\begin{axis}[no markers,grid=major,
every axis plot post/.append style={thick}]
\addplot coordinates
{(0, 0.0) (0, 0.9) (1, 0.9) (2, 1) (3, 0.9) (80,
 0)};
\addplot +[line join=round] coordinates
{(0, 0.0) (0, 0.9) (2, 0.9) (3, 1) (4, 0.9) (80,
 0)};
\addplot +[line join=bevel] coordinates
{(0, 0.0) (0, 0.9) (3, 0.9) (4, 1) (5, 0.9) (80,
 0)};
\addplot +[miter limit=5] coordinates
{(0, 0.0) (0, 0.9) (4, 0.9) (5, 1) (6, 0.9) (80,
 0)};
\coordinate (spypoint) at (axis cs:3,1);
\coordinate (magnifyglass) at (axis cs:60,0.7);
\end{axis}
\spy [blue, size=2.5cm] on (spypoint)
in node[fill=white] at (magnifyglass);
\end{tikzpicture}

\end{document}

结果:

监视 Babel

(虽然我猜真实的结果是它可以编译。)

相关内容