使用@starttoc 会导致包 tocloft 警告:\@starttoc 已被重新定义;

使用@starttoc 会导致包 tocloft 警告:\@starttoc 已被重新定义;

我需要使用 .cls(下面的最小化代码),它会生成此警告:

软件包 tocloft 警告:@starttoc 已被重新定义;tocloft 正在退出。在输入行 1156。

任何关于如何消除此警告的想法都将受到赞赏。

我正在使用 overleaf.com(编译器 == pdfLaTeX,TeX Live 版本 == 2022)错误日志发布在下面。

\documentclass[nopardent]{test}
\begin{document}
\chapter{Introduction}
\end{document}

这是最小的 test.cls 文件

\ProvidesClass{test}[TEST class]
\newcommand{\classfile}{report}
\DeclareOption{nopardent}{\renewcommand{\classfile}{rapport3}}
\ProcessOptions\relax
\LoadClass[a4paper,openright,titlepage]{\classfile}
\RequirePackage[titles]{tocloft}

这是错误日志文件:

This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.8.9)  30 JUL 2023 17:20
entering extended mode
 \write18 enabled.
 %&-line parsing enabled.
**test.tex
(./test.tex
LaTeX2e <2022-06-01> patch level 5
L3 programming layer <2022-08-05> (./test.cls
Document Class: test TEST class
(/usr/local/texlive/2022/texmf-dist/tex/latex/ntgclass/rapport3.cls
Document Class: rapport3 2020-11-17 v2.1e NTG LaTeX document class
(/usr/local/texlive/2022/texmf-dist/tex/latex/ntgclass/ntg10.clo
File: ntg10.clo 2020-11-17 v2.1e NTG LaTeX file (size option)
)
\unitindent=\dimen138
\othermargin=\dimen139
\c@part=\count185
\c@chapter=\count186
\c@section=\count187
\c@subsection=\count188
\c@subsubsection=\count189
\c@paragraph=\count190
\c@subparagraph=\count191
\c@figure=\count192
\c@table=\count193
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
LaTeX Info: Redefining \em on input line 818.
\bibindent=\dimen140
)) (/usr/local/texlive/2022/texmf-dist/tex/latex/tocloft/tocloft.sty
Package: tocloft 2017/08/31 v2.3i parameterised ToC, etc., typesetting
Package tocloft Info: The document has chapter divisions on input line 51.
\cftparskip=\skip49
\cftbeforetoctitleskip=\skip50
\cftaftertoctitleskip=\skip51
\cftbeforepartskip=\skip52
\cftpartnumwidth=\skip53
\cftpartindent=\skip54
\cftbeforechapskip=\skip55
\cftchapindent=\skip56
\cftchapnumwidth=\skip57
\cftbeforesecskip=\skip58
\cftsecindent=\skip59
\cftsecnumwidth=\skip60
\cftbeforesubsecskip=\skip61
\cftsubsecindent=\skip62
\cftsubsecnumwidth=\skip63
\cftbeforesubsubsecskip=\skip64
\cftsubsubsecindent=\skip65
\cftsubsubsecnumwidth=\skip66
\cftbeforeparaskip=\skip67
\cftparaindent=\skip68
\cftparanumwidth=\skip69
\cftbeforesubparaskip=\skip70
\cftsubparaindent=\skip71
\cftsubparanumwidth=\skip72
\cftbeforeloftitleskip=\skip73
\cftafterloftitleskip=\skip74
\cftbeforefigskip=\skip75
\cftfigindent=\skip76
\cftfignumwidth=\skip77
\c@lofdepth=\count194
\c@lotdepth=\count195
\cftbeforelottitleskip=\skip78
\cftafterlottitleskip=\skip79
\cftbeforetabskip=\skip80
\cfttabindent=\skip81
\cfttabnumwidth=\skip82

Package tocloft Warning: \@starttoc has already been redefined; tocloft bailing out. on input line 1156.

) (/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def

答案1

该包通过将命令与内核命令进行比较tocloft来检查命令是否已被重新定义。该命令的标准版本与 中定义的命令之间的唯一区别是添加了。因此,我们可以在加载之前撤消该更改,然后在加载之后重新实现它:\@starttocrapport3\parskip\z@tocloft

\documentclass{rapport3}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@starttoc}{\parskip\z@}{}{}{\fail}
\makeatletter
\usepackage{tocloft}
\patchcmd{\@starttoc}{\makeatletter}{\makeatletter\parskip\z@}{}{\fail}
\makeatother
\begin{document}

\end{document}

在类文件中,你不需要\makeatletter/ \makeatother。因此,你的最小类文件可能看起来像这样:

\ProvidesClass{test}[TEST class]
\newcommand{\classfile}{report}
\DeclareOption{nopardent}{\renewcommand{\classfile}{rapport3}}
\ProcessOptions\relax
\LoadClass[a4paper,openright,titlepage]{\classfile}
\RequirePackage{etoolbox}
\patchcmd{\@starttoc}{\parskip\z@}{}{}{\fail}
\RequirePackage[titles]{tocloft}
\patchcmd{\@starttoc}{\makeatletter}{\makeatletter\parskip\z@}{}{\fail}
% rest of class file here
\endinput % end of class file

相关内容