我发现 polyglossia 和 setlanguage 设置为 german 会破坏 pgfmath。我阅读了几个提示,最后得到了以下代码:
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new,babelshorthands=false]{german} % problem is here
\usepackage{tikz}
\usetikzlibrary{quotes,babel}
\begin{document}
\def\swNames{{"ERP", "CRM", "Analytics", "DB", "SCM"}}%
\foreach [count=\i] \farbe in {yellow, orange, green, blue} {%
Name \i: \pgfmathparse{\swNames[\i-1]}\pgfmathresult, }
\end{document}
结果应该是:
Name 0: ERP, Name 1: CRM, Name 2: Analytics, Name 3: DB,
第 3 行(标记为 % 问题的行在这里)被注释掉
但我得到了:
Name 0: 0, Name 1: 0, Name 2: 0, Name 3: 0,
错误如下:
! Package PGF Math Error: Unknown function `ERP' (in '{"ERP", "CRM", "Analytics
", "DB", "SCM"}[1-1]').
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...
l.10 ...gfmathparse{\swNames[\i-1]}\pgfmathresult, }
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
系统于 2023-01-16 在 ubuntu 22.04.lts 和 Overleaf 上使用 TeXlive2020
任何帮助的提示都非常受欢迎。问候 Lutz-Peter
答案1
您的示例在 texlive 2022 lualatex 中运行时没有错误,并且输出
在旧版本中,你似乎需要确保"
安全,例如
\edef\swNames{{\detokenize{"ERP", "CRM", "Analytics", "DB", "SCM"}}}%
适用于 texlive 2021(以及 overleaf 的 texlive 2022,缺少一些更新)
答案2
该babelshorthands=false
选项不会改变已激活的事实"
。这曾经是一个问题,直到 TeX Live 2022 才出现,那时您的问题不再出现。
如果您使用的是 TeX Live 2021 或更早版本,则可以将数组定义为包含标准双引号字符。
\documentclass{article}
\usepackage{polyglossia}
\usepackage{tikz}
\usetikzlibrary{quotes,babel}
\setdefaultlanguage[spelling=new,babelshorthands=false]{german} % problem is here
\makeatletter
\newcommand{\definepgfarray}[1]{%
\begingroup\catcode`"=12
\definepgfarray@{#1}%
}
\newcommand{\definepgfarray@}[2]{%
\endgroup\def#1{#2}%
}
\makeatother
\begin{document}
\definepgfarray\swNames{{"ERP", "CRM", "Analytics", "DB", "SCM"}}
\foreach [count=\i] \farbe in {yellow!95!magenta, orange, green!90!blue, blue!90!red} {%
Name \i: \pgfmathparse{\swNames[\i-1]}\textcolor{\farbe}{\pgfmathresult}, }
\end{document}