This is my first post and I am a relatively new user so I hope my question is not too trivial, I searched to see if this problem had been solved elsewhere but could not find anything. I am beginning to format my PhD thesis so that it is out the way in good time and not a concern in the future. I have read through the relevant sections of the documentation, I am not sure if it is because I am new that I cannot see the answer in the documents.
For the problem, when directly copying and pasting code provided in the memoir documentation (pages 203-205, section 9.2.5) to create different short and detailed table of contents, I am running into the following error:
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...
A slightly minimum .tex example to produce the error is:
% 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. 205The memoir class' PDF documentation
\newpage
\begin{abstract}
\blindtext
\end{abstract}
\chapter{Introduction}
\blindtext
\subsection{Intro}
\blindtext
\chapter{Test}
\blindtext
\end{document}
The .sty file used is \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}{}
I placed the macros in a .sty file as they contained @ symbols and it was recommended by egreg in another post. I think this is appropriate to do but any thoughts on this would be appreciated. If I just keep pushing [enter] through the error then both ToC's load properly, but I don't want there to be issues with my code in the future and would prefer for it to be error free.
I would appreciate any help in regards to this issue and any advice about my post, have I included enough etc would also be appreciated, thanks for reading this.