不知何故我的代码中断了Missing number, treated as zero
......
\documentclass{article}
\ExplSyntaxOn
\newcommand{\Hsatz}[1]{%
\int_case:nn { #1 }{
{ 225 } { abc }
{ 319 } { def }
{ 336 } { ghi }
}
}
\ExplSyntaxOff
\begin{document}
\Hsatz{225}
\Hsatz{319}
\Hsatz{336}
\end{document}
这似乎与使用多位数字有关。当我仅使用一位数字时,代码就可以工作。我该如何解决这个问题?我的最终代码中肯定需要超过 10 个选项,而且我真的想使用三位数字……
答案1
白色空间必须是空格、制表符或换行符,但您有一个零宽度空格,U+200B,在 319 之后,请参阅
https://w3c.github.io/xml-entities/unicode-names.html?%20%20%7B%20319%E2%80%8B%20%7D
答案2
如果您正在使用 pdflatex,那么下一个错误消息将提供可能出现错误的正确线索:
./Untitled-4.tex:21: LaTeX Error: Unicode character (U+200B)
not set up for use with LaTeX.
使用 lualatex 或 xelatex 时这不起作用,因为 Unicode 引擎接受任何 Unicode 字符,因此在遇到奇怪的事情时不会发出叫声。
另一个有帮助的方法是将有问题的定义括起来
\tl_analysis_show:n{
\newcommand{\Hsatz}[1]{%
...
}
这也显示了问题,但不太容易识别:
...
> \int_case:nn (control sequence=\long macro:#1#2->\exp:w \exp_args:Nf \ETC.)
> { (begin-group character {)
> # (macro parameter character #)
> 1 (the character 1)
> } (end-group character })
> { (begin-group character {)
> { (begin-group character {)
> 2 (the character 2)
> 2 (the character 2)
> 5 (the character 5)
> } (end-group character })
> { (begin-group character {)
> a (the letter a)
> b (the letter b)
> c (the letter c)
> } (end-group character })
> { (begin-group character {)
> 3 (the character 3)
> 1 (the character 1)
> 9 (the character 9)
> (the character )
> } (end-group character })
> { (begin-group character {)
> d (the letter d)
> e (the letter e)
> f (the letter f)
...
您可以看到 后面有一个不显示的字符319
。也许 的代码\tl_analysis_show:n
可以改进,以另外显示字符的 Unicode 编号。
在这种情况下,再次使用 pdftex 可以更容易地识别问题:
> { (begin-group character {)
> 3 (the character 3)
> 1 (the character 1)
> 9 (the character 9)
> â (active character=\protected macro:->\UTFviii@three@octets â)
> (active character=\protected macro:->\UTFviii@invalid@err )
> (active character=\protected macro:->\UTFviii@invalid@err )
> } (end-group character })
> { (begin-group character {)
> d (the letter d)
> e (the letter e)