1

I would like to have the \partname (Part) display in the table of content.

Example:

Part II: This is the title of my part 2

instead of

"II This is the title of my part 2"

For now, I use this:

\renewcommand*{\cftpartname}{Part}
\renewcommand*{\cftpartpresnum}{\space}
\renewcommand*{\cftpartaftersnum}{:}
\renewcommand*{\cftpartaftersnumb}{\space}

But it is language depended because I specify the name of the partname manually. I would rather have something which print automatically the partname according to the language.

I tried:

 \renewcommand*{\cftpartname}{\partname~}

but it does not work. It seems babel package create an error when I select French as language.

MWE (not compiling because of babel):

\documentclass{memoir}

\usepackage[english,francais]{babel}

\renewcommand*{\cftpartname}{\partname~}
\begin{document}

\tableofcontents

\part{Name of the part 1}
\label{part:part-1}

\chapter{Chapter 1}
\label{cha:chapter-1}


\section{Section 1}
\label{sec:section-1}

\subsection{subsection 1}
\label{sec:subsection-1}

\subsection{subsection 2}
\label{sec:subsection-2}

\section{Section 2}
\label{sec:3}




\end{document}
8
  • \renewcommand*{\cftpartname}{\partname~} works for me
    – user31729
    Commented Sep 22, 2017 at 13:53
  • @ChristianHupfer Indeed, it works in the MWE but not in my big document. I identified the package which blocks the compilation : babel. If I add \usepackage[english,francais]{babel}, I have an error. Any idea?
    – ppr
    Commented Sep 23, 2017 at 9:34
  • You must give memoir give a chance in order to detect the language for babel: Try \documentclass[french]{memoir} \usepackage[T1]{fontenc} \usepackage[english]{babel}
    – user31729
    Commented Sep 23, 2017 at 9:43
  • Test done, adding [french] to memoir package does not work, I still have an error if I select French as language in babel.
    – ppr
    Commented Sep 23, 2017 at 9:45
  • It worked for me in your MWE, have you removed the .aux file in between?
    – user31729
    Commented Sep 23, 2017 at 9:46

1 Answer 1

2

french has done changing things over the years for a long time (I don't know since when) a specific deal with \partname. Jump to bottom of answer for the brief version. This is in fact a long-standing problem... (which I bump into again every few years).


Thus you need to communicate version numbers (check the log). Perhaps option PartNameFull=false will help in your case if you use latest not too old version of french. You can find its documentation in French at this location. Check particularly pages 13 and 14 of this French language documentation.

[I know my answer is presumably not what is at stake here, I will delete this once the actual question is clarified]

Incomplete explanation

In fact I had encountered similar issue in the past. The toc file will contain

\contentsline {part}{\partnumberline {I}Name of the part 1}{3}

Then the expansion of \l@part at some point invokes (using up-to-date TL2017 as of today 2017/09/23)

\FB@partname  ->\ifFBPartNameFull \csname ordinal\romannumeral \value {part}\endcsname \space \frenchpartnameord \FB@emptypart \else Partie\fi 

But at this stage when the TOC is typeset, the part counter is at zero. Hence we end up with \ordinal which fetches \space as argument. But french.ldf only defines \ordinali, \ordinalii, etc... macros:

   \SetStringLoop{ordinal#1}{%
     \frenchpartfirst,\frenchpartsecond,Troisième,Quatrième,%
     Cinquième,Sixième,Septième,Huitième,Neuvième,Dixième,Onzième,%
     Douzième,Treizième,Quatorzième,Quinzième,Seizième,%
     Dix-septième,Dix-huitième,Dix-neuvième,Vingtième}

and never defines \ordinal. The \ordinal macro is provided by memoir class.

$ latexdef -c memoir ordinal
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^\\\@protected\@testopt { <-- HERE ?\\.*? }? *(\\\\.*?) / at /usr/local/bin/latexdef line 391.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^\\\@testopt { <-- HERE ?(\\.*?) }?/ at /usr/local/bin/latexdef line 394.

\ordinal:
macro:#1->\begingroup \let \fnumbersep \relax \form@tnumber {#1}\let \ordstring \nthstring \ifnum \c@xsm@mctr =\@ne \else \ifcase \c@ism@mctr \or \let \ordstring \iststring \or \let \ordstring \iindstring \or \let \ordstring \iiirdstring \fi \fi \ordscript {\ordstring }\endgroup 

and it ends up in an error with #1 being \space.

(please someone, tell me how to get rid of the annoying warnings from usage of latexdef ...)

I am sure I met this earlier, but I forget the details.

Using

\frenchsetup{PartNameFull=false}

is workaround because it avoids the bad branch in

\FB@partname  ->\ifFBPartNameFull \csname ordinal\romannumeral \value {part}\endcsname \space \frenchpartnameord \FB@emptypart \else Partie\fi 

Alternative is to do \setcounter{part}{1} before the TOC, but this is just proof of concept because result is of course bad.

The gist of it, in short

The \tableofcontents executes \l@part and the latter will expand under memoir class the \cftpartname.

If you modify \cftpartname to use the babel \partname, then with French babel module, this will, by default try to expand to something which depends upon the current value of the part counter.

But, typically, the \tableofcontents is before the first \part, thus the part counter has value zero. The french.ldf code does not foresee that part could be zero, and ultimately an error is raised due to the fact that the memoir \ordinal macro is expanded with a wrong argument.


In essence, french.ldf by default makes usage of \partname in the TOC resulting into at best non-sense, and at worst a TeX error at some stage. It restricts its use to the sectioning units themselves only.

(so what goes in the .toc file is already expanded and ok; the problem is if the .toc file itself attempts to use on its own \partname)

2
  • You answer is very relevant. Adding \def\frenchpartname{Partie} or PartNameFull=false inside \frenchsetup{} fixes the problem.
    – ppr
    Commented Sep 23, 2017 at 10:04
  • 1
    well, turns out this problem is mentioned in the etoc code comments: because \frenchpartname does things depending on the current value of the counter part. ... under class memoir the bug showed up. And the v1.08b [2015/03/18] "Change history" entry in the doc contains: \etocpartname ... was defined to be \partname, but this is not compatible at least with babel+french context. Now simply expands to Part.
    – user4686
    Commented Sep 23, 2017 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .