Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctex: 兼容 titletoc #472

Closed
muzimuzhi opened this issue Dec 29, 2019 · 1 comment
Closed

ctex: 兼容 titletoc #472

muzimuzhi opened this issue Dec 29, 2019 · 1 comment

Comments

@muzimuzhi
Copy link
Contributor

ctex 与 titletoc 共用时,会造成 <sec name><sec title> 部分出现重合,见 stone-zeng/fduthesis#73 (comment) 。一个 mwe(源自 stone-zeng/fduthesis#73 (comment) )是

\documentclass{ctexbook}
\usepackage{titletoc}

\begin{document}
\tableofcontents
\chapter{测试}
\chapter{测试}
\end{document}

ctex 因为修改了 \numberline 的定义,所以(很可能)需要为所有控制目录样式的包做兼容。目前兼容了 tocloft,没有兼容 titletoc。我在这篇文章的末尾提供了一种实现。

\documentclass{ctexbook}
\usepackage{titletoc}

%% make ctex works with titletoc
\makeatletter
\ExplSyntaxOn
\group_begin:
\char_set_catcode_other:N \#
\use:n
  {
    \group_end:
    \ctex_preto_cmd:NnnTF \numberline { \ExplSyntaxOff }
      { \CTEX@toc@width@n {#1} }
      { }
      { \ctex_patch_failure:N \numberline }
    \@ifpackageloaded { titletoc }
      { }
      {
        \ctex_at_end_package:nn { titletoc }
          {
            \ctex_preto_cmd:NnnTF \numberline
              { \char_set_catcode_letter:n { 64 } }
              { \CTEX@toc@width@n {#1} }
              { }
              { \ctex_patch_failure:N \numberline }
          }
      }
  }
\ExplSyntaxOff
\makeatother

\begin{document}
\tableofcontents
\chapter{测试}
\chapter{测试}
\end{document}

文章是大半年前写的,我自己也需要时间重新理解。

@muzimuzhi
Copy link
Contributor Author

看起来只需要在

ctex-kit/ctex/ctex.dtx

Lines 8271 to 8292 in dacf770

\group_begin:
\char_set_catcode_other:N \#
\use:n
{
\group_end:
\ctex_preto_cmd:NnnTF \numberline { \ExplSyntaxOff }
{ \CTEX@toc@width@n {#1} }
{ }
{ \ctex_patch_failure:N \numberline }
\@ifpackageloaded { tocloft }
{ }
{
\ctex_at_end_package:nn { tocloft }
{
\ctex_preto_cmd:NnnTF \numberline
{ \char_set_catcode_letter:n { 64 } }
{ \CTEX@toc@width@n {#1} }
{ }
{ \ctex_patch_failure:N \numberline }
}
}
}

里为 titletoc 增加一段相同的 patch 即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants