Advertisement
syvshc

change toc

May 13th, 2022
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 0.87 KB | None | 0 0
  1. \documentclass{ctexbook}
  2. \usepackage{zhlipsum}
  3. \usepackage{xpatch}
  4. \ExplSyntaxOn
  5. \makeatletter
  6. \xpatchcmd{\addcontentsline}{\thepage}{\thechapter--\thepage}{\typeout{toc succeed}}{toc fail}
  7. \cs_set_eq:NN \oldaddcontentsline \addcontentsline
  8. \xpatchcmd{\@chapter}
  9.  {\CTEX@addtocline{chapter}{#1}}
  10.  {
  11.    \xpatchcmd{\addcontentsline}{\thechapter--\thepage}{}{\typeout{chaptoc succeed}}{chaptoc fail}
  12.    \CTEX@addtocline{chapter}{#1}
  13.    \let\addcontentsline\oldaddcontentsline
  14.  }{\typeout{Success}}{\typeout{Failed!}}
  15. \makeatother  
  16. \ExplSyntaxOff
  17.  
  18. \begin{document}
  19. \frontmatter
  20.  \tableofcontents
  21. \mainmatter
  22.  \chapter{测试}
  23.  \section{测试}
  24.  \zhlipsum
  25.  \section{测试}
  26.  \zhlipsum
  27.  \subsection{测试}
  28.  \zhlipsum
  29.  \chapter{测试}
  30.  \zhlipsum
  31.  \section{测试}
  32.  \zhlipsum
  33.  \section{测试}
  34.  \zhlipsum
  35.  \subsection{测试}
  36. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement