-
Notifications
You must be signed in to change notification settings - Fork 126
Description
从失败的每周 CI 运行出发,我发现 ctex 里对 cleveref 的 patch 已部分失效。
背景
为了兼容 \labelformat,ctex.dtx patch 了 cleveref:替换
\csname p@<counter>\endcsname\csname the<counter>\endcsname为(加了一个 \expandafter)
\csname p@<counter>\expandfter\endcsname\csname the<counter>\endcsname这是因为 \labelformat 会把 \p@<counter> 定义为接受一个参数的宏,这个参数通常为同名计数器的 \the<counter>。
从 LaTeX2e 2024-11-01 起,\theHcounter 的定义和 \@currentHref 的更新从由 hyperref 提供改为由 LaTeX 直接提供。hyperref 随之做了相应改动,如不再重定义 \refstepcounter。
这些改动带来了蝴蝶效应,使 cleveref(最近更新于 2018-03-27)和 LaTeX2e 2024-11-01、hyperref 部分不兼容。一部分不兼容已在 LaTeX2e firstaid(已打包到格式里) 和 hyperref 中处理,但还遗留了一些,见我报告的
\p@<counter>andclevereffirstaid latex3/latex2e#1544- Changed behavior of
cleverefafter\appendixlatex3/hyperref#361
问题
对 ctex 来说,上述变化使 patch 部分失效。章节标题设置功能开启时,ctex 和 cleveref 不兼容。
沿用 latex3/latex2e#1544 里的例子
\documentclass{article}
\usepackage[fontset=none, heading]{ctex}
\usepackage{hyperref,cleveref}
\begin{document}
\section{title}
\makeatletter
\show\cref@currentlabel
\makeatother
\end{document}- 预期
> \cref@currentlabel=macro: ->[section][1][]1. - 实际
> \cref@currentlabel=macro: ->[section][1][]1thesection\endcsname .
尝试和解决方案
muzimuzhi@5b786a4 (branch muzimuzhi:fix/cleveref-patch) 是一个尝试。它让 CI 通过了,但我担心新 patch 之一不够好(来自 latex3/hyperref#361 (comment) 里 Ulrike Fischer 的建议,见后面的代码片段),patch 可能频繁改动的 firstaid 也不是好的做法(ctex 会跟不上变化)。
\ExplSyntaxOn
\AddToHook{package/cleveref/before}{\clist_put_right:cn {[email protected]}{implicit=false}}
\ExplSyntaxOff最好是在 cleveref 那头解决和更新。