![有关 csquotes 和 LuaLaTeX 的这个错误该由谁来承担责任?](https://linux22.com/image/354266/%E6%9C%89%E5%85%B3%20csquotes%20%E5%92%8C%20LuaLaTeX%20%E7%9A%84%E8%BF%99%E4%B8%AA%E9%94%99%E8%AF%AF%E8%AF%A5%E7%94%B1%E8%B0%81%E6%9D%A5%E6%89%BF%E6%8B%85%E8%B4%A3%E4%BB%BB%EF%BC%9F.png)
我在使用该软件包时遇到了这个问题lilyglyphs
,但我不确定这个错误是谁的错。
当我使用以下命令编译以下内容时lualatex
:
\documentclass{article}
\usepackage{csquotes}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\directlua{print("hello")}
\end{document}
我收到一条错误消息
\directlua]:1: unexpected symbol near '\'. l.6 \directlua{print("hello")}
现在假设我不直接\directlua
在文档中书写,而是包含一个在内部执行此操作的包。例如
\documentclass{article}
\usepackage{fontspec, csquotes, lilyglyphs}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\wholeNote
\end{document}
我不知道为什么编译失败,因为错误现在变成了
! Missing number, treated as zero. <to be read again> \begingroup l.7 \end {document}
从我的用户角度来看,我没有做错什么,因为我正在使用软件包提供的公共 API。文档csquotes
具体说明:
请注意,所有字符在分配时都会自动检查其有效性。此包将拒绝不适合作为有效引号的字符……总之,以下字符将被视为此包的保留字符:
A–Z a–z 0–9 . , ; : ! ? ' - # $ % & ^ _ ` ~ \ @ * { } [ ]
所以我的问题是这个错误是谁的错?
- 这是我的错,这是用户的错,因为我应该知道(但是我怎么知道的?)尽管该引文在 csquotes 手册中没有被列为不合适,但实际上它是不合适的?
csquotes
因未提及实施或文件不当而导致的错误"
?- 该命令的实现存在错误,
\directlua
因为它不能阻止 LaTeX catcode 更改/活动字符影响其参数? - TeX 本身由于其基于全局状态的架构而存在缺点吗?
答案1
lilyglyphs
你的第一个例子和第二个例子实际上是完全不同的错误。第一个是你的错误(参见 David 的回答),但第二个是lua 代码中的错误。
但问题不在于 中的引号\directlua
。由于命令是在lilyglyphs
“ 的 catcode 中定义的,因此在那里冻结,因此没有问题。
lilyglyphs
用于tex.sprint
打印字符,并且参数包含"
。由于tex.sprint
默认使用当前活动的 catcode 机制,因此会爆炸。您可以告诉tex.sprint
使用另一个 catcode 表。(我不太确定\CatcodeTableLaTeX
我是否使用了最好的一个,但它有效):
\documentclass{article}
\usepackage{fontspec, csquotes,lilyglyphs}
%copied from lilyglyphs
\begin{luacode}
documentdata = documentdata or { }
local stringformat = string.format
local texsprint = tex.sprint
local slot_of_name = luaotfload.aux.slot_of_name
documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(\the\CatcodeTableLaTeX,
stringformat ([[\char"%X"]], chr))
end
end
\end{luacode}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\wholeNote
\end{document}
答案2
抱歉,既然你问了,我会说这是你的错:-)
在使角色活跃起来之后,您应该知道在将其传递给 Lua 之前要确保其安全。
例如:
\documentclass{article}
\usepackage{csquotes}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\directlua{print(\string"hello\string")}
\end{document}
请参阅 Ulrike 的回答以了解第二个例子。