2

My question begins like this one: Polyglossia and toc.

For some reason, the french option of polyglossia removes part numbers from the table of contents, leaving an ugly space in its wake. The question linked above asks for a way to add these numbers back, and it received a good but very complicated answer. I'm not asking for the same thing: I don't want the numbers back, I just want to remove that space, and I believe there is an easy way to do that.

Indeed, adding an \unskip in the argument of \part is sufficient to remove the unwanted horizontal space from the table of contents. See the MWE:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{french}

\begin{document}
\tableofcontents

\part{English part with a number}

\begin{french}

\part{French part with an ugly space}

\part{\unskip French part with nothing}

\end{french}
\end{document}

(The change of language between parts is only there to show the difference. My document will be in French only.)

Result:

Table of contents example

Now I just want to find a way to remove that space to all parts, without needing to add \unskip every time. I thought of a naive way:

\renewcommand{\part}[1]{\part{\unskip #1}}

But when I try to compile, nothing happens, the compilation seems stuck.

So, what's the easiest way to get rid of that unwanted space in the table of contents?

1
  • As a side-note, I eventually found a quick but limited fix to my problem by adding \let\oldpart\part \renewcommand{\part}[1]{\oldpart{\unskip #1}}. However, egreg's answer is undoubtedly more appropriate, which is why I accepted it. I don't think my own fix would add much value if I posted it as a second answer, so I'm just mentioning it here, in case someone went through the same reasoning. – SDF Jun 17 '17 at 5:56
2

Bad design of the standard classes, but they’ve been like that for many years…

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{french}

\makeatletter
\patchcmd{\@part}
  {\thepart\hspace{1em}}
  {\partnumberline{\thepart}}
  {}{}
\makeatother
\newrobustcmd{\partnumberline}[1]{%
  \if\relax\detokenize{#1}\relax\else #1\hspace{1em}\fi
}


\begin{document}
\tableofcontents

\part{English part with a number}

\begin{french}

\part{French part with nothing}

\end{french}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.