回忆录多个目录:未定义错误

回忆录多个目录:未定义错误

这是我的第一篇帖子,我是一个相对较新的用户,所以我希望我的问题不是太琐碎,我搜索了一下,看看这个问题是否在其他地方得到解决,但没有找到任何东西。我开始格式化我的博士论文,以便及时完成,而不是在将来担心。我已经阅读了文档的相关部分,我不确定是不是因为我是新手,所以我无法在文档中看到答案。

对于该问题,直接复制并粘贴回忆录文献(第 203-205 页,第 9.2.5 节)创建不同的简短和详细目录,我遇到了以下错误:

Redoing nameref's sectioning
Redoing nameref's label
(./minworkingexampl.out) (./minworkingexampl.out)

! LaTeX Error: Command \cftpartformatpnum undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.10 \setupshorttoc
                                % This section is copied directly from pg. 203-205 fr...

产生错误的一个稍微简单的 .tex 示例是:

% Minimum working example for ! LaTeX Error: Command \cftpartformatpnum undefined.

\documentclass{memoir} 
\usepackage{Minworkingexample}
\usepackage{blindtext}
\usepackage{hyperref}           % Included hyperref: a) in case it was causing errors, b) hyperlink the TOC's

\begin{document}

\setupshorttoc              % This section is copied directly from pg. 203-205 from the `The memoir class'
\tableofcontents*               % documentation PDF. 
\clearpage
\setupparasubsecs
\setupmaintoc
\tableofcontents*
\setlength{\unitlength}{1pt}        % pg. 205 `The memoir class' PDF documentation
\newpage

\begin{abstract}
\blindtext
\end{abstract}

\chapter{Introduction}
\blindtext
\subsection{Intro}
\blindtext
\chapter{Test}
\blindtext

\end{document}

使用的.sty 文件是\usepackage{Minworkingexample}

% Minimum working example for ! LaTeX Error: Command \cftpartformatpnum undefined.

% This code is copied directly from pg. 203-205 from the `The memoir class' documentation PDF

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Minworkingexample}[2021/06/28 Example package]

\newcommand*{\setupshorttoc}{%
    \renewcommand*{\contentsname}{Short contents}
    \let\oldchangetocdepth\changetocdepth
    \renewcommand*{\changetocdepth}[1]{}
    \let\oldprecistoctext\precistoctext
    \renewcommand{\precistoctext}[1]{}
    \let\oldcftchapterfillnum\cftchapterfillnum
    \setcounter{tocdepth}{0}% chapters and above
    \renewcommand*{\cftchapterfont}{\hfill\sffamily}
    \renewcommand*{\cftchapterleader}{ \textperiodcentered\space}
    \renewcommand*{\cftchapterafterpnum}{\cftparfillskip}
    \setpnumwidth{0em}
    \setpnumwidth{1.5em}
    \renewcommand*{\cftchapterfillnum}[1]{%
        {\cftchapterleader}\nobreak
        \hbox to 1.5em{\cftchapterpagefont ##1\hfil}\cftchapterafterpnum\par}
    \setrmarg{0.3\textwidth}
    \setlength{\unitlength}{\@tocrmarg}
    \addtolength{\unitlength}{1.5em} % Add curly brace here before %, comment the code below out and no error is produced.
    
    %The code below is what is causing the issues with \cftpartformatpnum
    
    \let\oldcftpartformatpnum\cftpartformatpnum
    \renewcommand*{\cftpartformatpnum}[1]{%
        \hbox to\unitlength{{\cftpartpagefont ##1}}}
    \let\oldcftbookformatpnum\cftbookformatpnum
    \renewcommand*{\cftbookformatpnum}[1]{%
        \hbox to\unitlength{{\cftbookpagefont ##1}}}}

    %The code above is what is causing the issues \cftpartformatpnum

%%% The code below seems to work correctly and has no issues
%%% so I believe it can be ignored. Needs to be included in this though I think

\newcommand*{\setupparasubsecs}{%
    \let\oldnumberline\numberline
    \renewcommand*{\cftsubsectionfont}{\itshape}
    \renewcommand*{\cftsubsectionpagefont}{\itshape}
    \renewcommand{\l@subsection}[2]{%
        \def\numberline####1{\textit{####1}~}%
        \leftskip=\cftsubsectionindent
        \rightskip=\@tocrmarg
        \parfillskip=\fill
        \ifhmode ,\ \else\noindent\fi
        \ignorespaces
    {\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
    \let\numberline\oldnumberline\ignorespaces}
    }
\AtEndDocument{\addtocontents{toc}{\par}}

\newcommand*{\setupmaintoc}{%
    \renewcommand{\contentsname}{Contents}
    \let\changetocdepth\oldchangetocdepth
    \let\precistoctext\oldprecistoctext
    \let\cftchapterfillnum\oldcftchapterfillnum
    \addtodef{\cftchapterbreak}{\par}{}
    \renewcommand*{\cftchapterfont}{\normalfont\sffamily}
    \renewcommand*{\cftchapterleader}{%
        \sffamily\cftdotfill{\cftchapterdotsep}}
    \renewcommand*{\cftchapterafterpnum}{}
    \renewcommand{\cftchapterbreak}{\par\addpenalty{-\@highpenalty}}
    \setpnumwidth{2.55em}
    \setrmarg{3.55em}
    \setcounter{tocdepth}{2}}
    \let\cftpartformatpnum\oldcftpartformatpnum
        \addtodef{\cftpartbreak}{\par}{}
    \let\cftbookformatpnum\oldcftbookformatpnum
        \addtodef{\cftbookbreak}{\par}{}

我将宏放在 .sty 文件中,因为它们包含 @ 符号,并且建议egreg 在另一篇文章中。我认为这样做是合适的,但对此有任何想法都会受到欢迎。如果我只是继续按 [enter] 来忽略错误,那么两个 ToC 都会正确加载,但我不想将来我的代码出现问题,并且希望它没有错误。

我将非常感激任何有关这个问题的帮助,以及任何关于我的帖子的建议,我是否包含了足够的内容等等,谢谢阅读。

答案1

您到底是从哪个版本的手册中复制的?在当前版本的回忆录手册中,第 203-205 页与 ToC 和朋友无关。

你有错误

\newcommand*{\setupmaintoc}{%
    \renewcommand{\contentsname}{Contents}
    \let\changetocdepth\oldchangetocdepth
    \let\precistoctext\oldprecistoctext
    \let\cftchapterfillnum\oldcftchapterfillnum
    \addtodef{\cftchapterbreak}{\par}{}
    \renewcommand*{\cftchapterfont}{\normalfont\sffamily}
    \renewcommand*{\cftchapterleader}{%
        \sffamily\cftdotfill{\cftchapterdotsep}}
    \renewcommand*{\cftchapterafterpnum}{}
    \renewcommand{\cftchapterbreak}{\par\addpenalty{-\@highpenalty}}
    \setpnumwidth{2.55em}
    \setrmarg{3.55em}
    \setcounter{tocdepth}{2}} % <---- error
    \let\cftpartformatpnum\oldcftpartformatpnum
        \addtodef{\cftpartbreak}{\par}{}
    \let\cftbookformatpnum\oldcftbookformatpnum
        \addtodef{\cftbookbreak}{\par}{}

行末}的一行tocdepth应移至末尾

\newcommand*{\setupmaintoc}{%
    \renewcommand{\contentsname}{Contents}
    \let\changetocdepth\oldchangetocdepth
    \let\precistoctext\oldprecistoctext
    \let\cftchapterfillnum\oldcftchapterfillnum
    \addtodef{\cftchapterbreak}{\par}{}
    \renewcommand*{\cftchapterfont}{\normalfont\sffamily}
    \renewcommand*{\cftchapterleader}{%
        \sffamily\cftdotfill{\cftchapterdotsep}}
    \renewcommand*{\cftchapterafterpnum}{}
    \renewcommand{\cftchapterbreak}{\par\addpenalty{-\@highpenalty}}
    \setpnumwidth{2.55em}
    \setrmarg{3.55em}
    \setcounter{tocdepth}{2}
    \let\cftpartformatpnum\oldcftpartformatpnum
        \addtodef{\cftpartbreak}{\par}{}
    \let\cftbookformatpnum\oldcftbookformatpnum
        \addtodef{\cftbookbreak}{\par}{}
}

当它}位于错误的位置时,我们最终会设置\cftpartformatpnum一个未定义的宏,并且无法\renewcommand对未定义的宏执行任何操作。

相关内容