CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
966 stars 124 forks source link

[与 ctex 无关] 在 CTeX 存在的情况下 nicematrix 的 `\RowStyle` 宏出现编译错误 #611

Closed lynzrand closed 2 years ago

lynzrand commented 2 years ago

复现步骤

  1. 使用 LaTeX 编译以下代码
\documentclass{ctexart}

\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{l}[]
    \RowStyle{} Foo \\
\end{NiceTabular}

\end{document}
  1. 欣赏报错信息
! Package xcolor Error: Undefined color `仟'.

See the xcolor package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.10     \RowStyle{}
                   Foo \\

可复现的环境

未能成功复现的环境

备注

我对 LaTeX 的了解仅限于使用的程度,所以 Debug 还是得靠专业用户来……

lhy7889678 commented 2 years ago

看样子是 nicematrix 中用到了临时变量 \l_tmpa_tl 来储存某种颜色,但该变量同时也被 ctex 使用(被设定为 ),导致冲突。(我对 LaTeX3 也并不是很了解,希望有大佬来详细解释一下)

具体的 debug 方式是,首先在 nicematrix 中 \RowStyle 命令的定义中看到使用了 \l_tmpa_tl,于是在报错时输入 I,插入 \ExplSyntaxOn\show\l_tmpa_tl,得到

> \l_tmpa_tl=macro:
->仟.
lynzrand commented 2 years ago

在 ctex 代码里搜了一下对于这个临时变量的使用情况,只发现了一个文件里用到了:

https://github.com/CTeX-org/ctex-kit/blob/5bdb9cbaca6467e92ec9bd7726e2b3bdd1943303/zhnumber/zhnumber.dtx#L1221-L1229

https://github.com/CTeX-org/ctex-kit/blob/5bdb9cbaca6467e92ec9bd7726e2b3bdd1943303/zhnumber/zhnumber.dtx#L1339-L1399

同一个文件中提到 字的地方:

https://github.com/CTeX-org/ctex-kit/blob/5bdb9cbaca6467e92ec9bd7726e2b3bdd1943303/zhnumber/zhnumber.dtx#L1924

希望对解决问题有帮助。个人感觉可能是两个库的局部变量名称冲突了?

zepinglee commented 2 years ago

应该是 nicematrix 的问题,大概是没有将 \l_tmpa_tl “初始化”,跟 ctex-kit 无关。

\documentclass{article}

\usepackage{nicematrix}

\begin{document}

\ExplSyntaxOn
  \tl_set:Nn \l_tmpa_tl {foo}
\ExplSyntaxOff

\begin{table}
  \begin{NiceTabular}{l}[]
    \RowStyle{} Foo \\
  \end{NiceTabular}
\end{table}

\end{document}

这样会报错

./main.tex:13: Package xcolor Error: Undefined color `foo'.

See the xcolor package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.13     \RowStyle{}
                     Foo \\
./main.tex:13:  ==> Fatal error occurred, no output PDF file produced!
lynzrand commented 2 years ago

感谢!我去联系一下 nicematrix 的作者

lynzrand commented 2 years ago

nicematrix 的作者已经修复了这个问题