ctex: 关于 autoindent 功能的讨论
#401 提出的问题,已由提交 https://github.com/CTeX-org/ctex-kit/commit/ad3a301a60ba989088756c868e01fa4fc24d4b81 解决,该 issue 可适时关闭。现把该 issue 下关于 autoindent 功能的讨论移到这里。
@RuixiZhang42 在原 issue 下的评论引出了对函数 \ctex_update_parindent: 实现的讨论。
https://github.com/CTeX-org/ctex-kit/blob/ad3a301a60ba989088756c868e01fa4fc24d4b81/ctex/ctex.dtx#L6679-L6690
其中引起质疑的位于 L6686 的判断,是在这个提交 https://github.com/CTeX-org/ctex-kit/commit/3b686953795bca3735de60e2e123d4c35bb56d71 引入的。
@muzimuzhi \dim_compare:nNnF \parindent = \c_zero_dim 这个代码的存在时间,比你找到的那个提交要更加久远,早在 https://github.com/CTeX-org/ctex-kit/commit/520896bfe58a80ddd8f6f85bf03da37469a3d990 李清用 LaTeX3 重写 ctex.dtx 就有了。
我尝试着回溯了一下,这个内层的逻辑判断是从 ctex-cjk-common.def 里面的 \CTEXsetfont 继承过来的,我能找到的最早提交是 https://github.com/CTeX-org/ctex-kit/commit/dc21843feb096831f315714bb99e3e3c9a29f302 ,2009 年:
\newcommand*\CTEXsetfont{%
\settowidth\ccwd{\CTEX@spaceChar\CJKglue}%
\ifdim\parindent=0pt\else\parindent2\ccwd\fi}
也即:
- 如果原本段首 0 缩进,那么什么也不做,也就维持段首 0 缩进。
- 如果原本段首有缩进(不管是
10pt还是-2cm),都更新段首缩进为2\ccwd。
@Liam0205 在我通过 https://github.com/CTeX-org/ctex-kit/commit/659610c8926e81257560be8af35fafb14b6dbcc4 与 https://github.com/CTeX-org/ctex-kit/commit/ffc082236d8fc61785b6674738474c805cf02774 修了 #401 与 #403 之后,我发现将内层逻辑判断移除,似乎没有什么问题,即
\cs_new_protected_nopar:Npn \ctex_update_parindent:
{
\tl_if_empty:NF \l_@@_autoindent_tl
{
\dim_set:Nn \parindent { \l_@@_autoindent_tl }
}
}
要不我这两天把这个也修了吧?
内层有 \parindent 是否为 0pt 的判断一方面是出于兼容旧文档的考虑,因为那时没有 autoindent 选项,要想关闭自动调整段首缩进的功能,只能设置 \parindent 为 0pt。
另一方面,LaTeX 的一些结构是通过特殊的段落来实现的,一般都会将 \parindent 设置为 0pt,比如 \@arrayparboxrestore,\centering 这些。如果我们移除内层判断,就需要不断打补丁设置 autoindent 为 false,也并不「优雅」。
综合以上考虑,我认为还是保留内层判断比较好。