CTeX-org / ctex-kit

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

ctxdoc: 匹配 l3doc 的展开类型修改 #700

Closed atxy-blip closed 4 months ago

atxy-blip commented 4 months ago

今天编译文档时发现 \tl_replace_all:Non 的定义也消失了,粗略翻了一圈没能追溯到 l3kernel 中的修改时间,先凑合提交了一个补丁来让代码跑起来。

此外,关于 #678,为了向后兼容性还是把 e 型展开手动补上了。

如果有更好的改法请不吝赐教!

muzimuzhi commented 4 months ago

l3kernel 没有提供过 \tl_replace_all:NnnNon 变体 (variant),是 xecjk.sty 里定义的。

https://github.com/CTeX-org/ctex-kit/blob/0095bccd9e6901bad52d88ec3c7b0d0bfcb48250/xeCJK/xeCJK.dtx#L6579

我看了一下,ctex.pdf 是用 xelatex 编译的,于是变体缺失问题在 ctex-kit 项目内部没有触发。你是在其他引擎下使用 ctxdoc.cls 了吗?

此外,关于 #678,为了向后兼容性还是把 e 型展开手动补上了。

ctxdoc.cls 是一个 ctex-kit 内部使用的、非公开的文档类,我觉得没必要考虑向后兼容性。(ctxdoc.cls 使用 l3kernel 内部的 l3doc.cls 已经是不推荐的做法,ctex-kit 要承受相应的代价。)

The l3doc class was written as some internal hack to to provide some initial support for the documentation of the l3 kernel code. It was never meant (and still isn't) as a general purpose class even though people have used it as is given that it was around. https://github.com/latex3/latex3/pull/1497#issuecomment-1975202359

不论是 ctex-kit 本身还是其他使用了 ctxdoc.cls(不推荐这么做)的项目,编译文档时把老的 l3kernell3doc.clsl3kernel 的一部分,总是一起发版)和新的 ctxdoc.cls 搭配使用是错误的做法。

可以在 ctxdoc.cls 里(软性)要求 l3doc 的最低版本为 2023-10-10,见 https://github.com/latex3/latex3/commit/007b309a770f2973f7bdc2a24aad148821aa3f70

-\LoadClass{l3doc}
+\LoadClass{l3doc}[2023-10-10]
atxy-blip commented 4 months ago

xecjk.sty 里定义的

可是你引用的是 Nno 变体,实际上出现的是 Non,项目中也仅有 ctxdoc.cls 一处用到 orz

https://github.com/CTeX-org/ctex-kit/blob/0095bccd9e6901bad52d88ec3c7b0d0bfcb48250/support/ctxdoc.cls#L298

你是在其他引擎下使用 ctxdoc.cls 了吗?

我提供基于一个我使用的文档的 MWE 来复现问题,保存文件名为t.dtx,是用 xelatex 进行编译的。

% \iffalse meta-comment
% !TeX program  = XeLaTeX
% !TeX encoding = UTF-8
%
%<*internal>
\begingroup
  \def\NameOfLaTeXe{LaTeX2e}
\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else
\csname fi\endcsname
%</internal>
%
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse

\preamble
Preamble text
\endpreamble

\generate{
  \usedir{tex/latex/\jobname}
    \file{\jobname.cls}               {\from{\jobname.dtx}{class}}
%<*internal>
  \usedir{source/latex/\jobname}
    \file{\jobname.ins}               {\from{\jobname.dtx}{install}}
%</internal>
}

\endbatchfile
%</install>
%
%<*internal>
\fi
%</internal>
%
%
%<*driver>
\ProvidesFile{t.dtx}
\documentclass[fontset=fandol, scheme=plain]{ctxdoc}
\ExplSyntaxOn
\cs_generate_variant:Nn \__codedoc_get_hyper_target:nN { x } ^^A patch for current version of ctex
\ExplSyntaxOff
\begin{document}
  \DocInput{t.dtx}
\end{document}
%</driver>
% \fi
%
% \begin{implementation}
%
% \begin{macro}{\foo}
%    \begin{macrocode}
\foo
%    \end{macrocode}
% \end{macro}
%
% \end{implementation}
%

我觉得没必要考虑向后兼容性

这一点我了解了,会在全部问题讨论完后统一改一下。

muzimuzhi commented 4 months ago

xecjk.sty 里定义的

可是你引用的是 Nno 变体,实际上出现的是 Non,项目中也仅有 ctxdoc.cls 一处用到 orz

你说的对,我看错了。

l3kernel 2023-12-08 之前,l3doc.cls 定义并使用 \tl_replace_all:NnnNonNno variants。从 latex3/latex3@96a159e2 (Reduce variant-generation in l3doc, 2023-11-27) 开始,l3doc.cls 不再定义这两个 variants,改为使用 NVnNnV。(使用 V 而非 o 是 LaTeX Project 的 Joseph Wright 的倾向。V 更贴近一般编程语言(取值,_v_alue),V 也只比 o 慢一点点。我个人在意识得到时,会更倾向于 o。)

也许 ctxdoc.cls 也可以使用 \tl_replace_all:NVn.(V-type 和 N 类似,所以对应的参数不用加大括号。)

diff --git a/support/ctxdoc.cls b/support/ctxdoc.cls
index 2d476b0..56b7d01 100644
--- a/support/ctxdoc.cls
+++ b/support/ctxdoc.cls
@@ -295,8 +295,8 @@
       { \use:n }
       {
         \tl_set:Nn \l__codedoc_tmpa_tl {#1}
-        \tl_replace_all:Non \l__codedoc_tmpa_tl
-          { \c_catcode_other_space_tl }
+        \tl_replace_all:NVn \l__codedoc_tmpa_tl
+          \c_catcode_other_space_tl
           { \fontspec_visible_space: }
         \__codedoc_macroname_prefix:o \l__codedoc_tmpa_tl
         \__codedoc_macroname_suffix:N #2