Babel 的 Package tikz 错误让我抓狂:预期 + 或 -

Babel 的 Package tikz 错误让我抓狂:预期 + 或 -

我正在与使用 calc 库时不断出现的 babel 作斗争Package tikz Error: + or - expected.。特别是,有些代码只有在\usetikzlibrary{babel}打开时才有效,而其他一些代码只有在\usetikzlibrary{babel}关闭时才有效……我的理智受到了严重威胁 ^^'

目前,我唯一能使它工作的方法是在 ...\shorthandoff{!}之前禁用\scalebox{},但我发现这非常不雅观,因为它有点违背了 babel 的目的,特别是当节点包含 时!。此外,当我编写库时,很难提前预测要自动禁用的简写列表……

需要 \usetikzlibrary{babel} 来编译的 MWE

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[french]{babel}

\usepackage{tikz}
\usetikzlibrary{calc}
%\usetikzlibrary{babel} % If you enable this, it compiles this example, but not the other one

\NewDocumentCommand{\myAnimatedNode}{}{%
  \node(afirsthidden){};%
  \node(asecondhidden){};%
  % Last node to be drawn
  \path node[at={($(afirsthidden.center)!.5!(asecondhidden.center)$)}]{A};%
}


\begin{document}

\begin{tikzpicture}
  \myAnimatedNode
\end{tikzpicture}

\end{document}

使用 \usetikzlibrary{babel} 失败的 MWE

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[french]{babel} % Use \begin{frame}[fragile] everywhere or you will get weird stuff with tikz

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{babel} % If you disable this, then it compiles this example, but not the other one

\begin{document}
\scalebox{.5}{
  \begin{tikzpicture}
    \node(a){};
    \node(b){};
    \node[] at ($(a.north)!.5!(b.north)$){};
  \end{tikzpicture}
}
%\end{frame}
\end{document}

两者的组合永远无法编译

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[french]{babel}

\usepackage{tikz}
\usetikzlibrary{calc}
% This document will never compile
\usetikzlibrary{babel} 

\NewDocumentCommand{\myAnimatedNode}{}{%
  \node(afirsthidden){};%
  \node(asecondhidden){};%
  % Last node to be drawn
  \path node[at={($(afirsthidden.center)!.5!(asecondhidden.center)$)}]{A};%
}


\begin{document}

\begin{tikzpicture}
  \myAnimatedNode
\end{tikzpicture}

\scalebox{.5}{
  \begin{tikzpicture}
    \node(a){};
    \node(b){};
    \node[] at ($(a.north)!.5!(b.north)$){};
  \end{tikzpicture}
}


\end{document}

答案1

有很多方法可以保证!安全,例如

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}


\usepackage[french]{babel}

\usepackage{tikz}
\usetikzlibrary{calc}
% This document will never compile
\usetikzlibrary{babel} 


\NewDocumentCommand{\myAnimatedNode}{}{%
  \node(afirsthidden){};%
  \node(asecondhidden){};%
  % Last node to be drawn
  \path node[at={($(afirsthidden.center)!.5!(asecondhidden.center)$)}]{A};%
}


\begin{document}

\begin{tikzpicture}
  \myAnimatedNode
\end{tikzpicture}


\scalebox{.5}{%
  \begin{tikzpicture}
    \node(a){};
    \node(b){};
    \node[] at \expanded{($(a.north)\string!.5\string!(b.north)$){}};
  \end{tikzpicture}%
}


\end{document}

相关内容