7

There is a known conflict between the memoir class and the hyperref package. hyperref cannot process Table of Contents headings that include the \MakeTextUppercase macro.

The memoir manual (texdoc memoir) provides a bit of code that is supposed to fix the problem, but I can't get it to work.

Am I using the manual's solution incorrectly, or is another solution required?

\documentclass{memoir}

\renewcommand*{\cftpartfont}{\MakeTextUppercase}

% From Memoir manual p. 158
\makeatletter
\settocpreprocessor{part}{%
    \let\tempf@rtoc\f@rtoc%
    \def\f@rtoc{%
        \texorpdfstring{\MakeTextUppercase{\tempf@rtoc}}{\tempf@rtoc}}%
}
\makeatother

\usepackage{hyperref}

\begin{document}

\tableofcontents*

\part{A Whale}
\chapter{A Tale}
\section{A Sail}
\subsection{A Beachball}

\part{A Poodle}
\chapter{A Noodle}
\section{A Doodle}

\end{document}

Compiling this MWE I get the following error:

! Argument of \contentsline has an extra }.
<inserted text> 
                \par 
l.2 \contentsline
                  {chapter}{\chapternumberline {1}A Tale}{5}

Other solutions have been proposed:

But ideally the solution in the class manual would be the correct one.

musarithmia
  • 12,463
  • Simply comment \renewcommand*{\cftpartfont}{\MakeTextUppercase} and it compiles fine. – karlkoeller Dec 22 '14 at 20:00
  • @karlkoeller Yes, that line is what makes this a non-working example. The idea is to use memoir's interface to automatically uppercase certain headings in the toc. But when you process such a document with hyperref, it breaks. The question is how to fix that so the line you mentioned can be preserved. – musarithmia Dec 22 '14 at 20:04
  • So you're looking for a workaround different from the one suggested by memoir's manual, aren't you? – karlkoeller Dec 22 '14 at 20:06
  • @karlkoeller I would like to know why the one suggested in the manual, which I use literally above, does not work. – musarithmia Dec 22 '14 at 20:10
  • It does. The manual says that changing \cftpartfont doesn't work... – karlkoeller Dec 22 '14 at 20:14
  • 1
    @karlkoeller I misunderstood the manual. I am supposed to use the \settocpreprocessor command instead of the \cftpartfont command. If you write that as an answer I will gladly accept it. – musarithmia Dec 22 '14 at 20:17

1 Answers1

8

I think you are misunderstanding memoir's manual.

It says that when loading hyperref you can't set an uppercase font for parts in the ToC with

\renewcommand*{\cftpartfont}{\MakeTextUppercase}

It says that you can instead use \settocpreprocessor in this way:

\makeatletter
\settocpreprocessor{part}{%
    \let\tempf@rtoc\f@rtoc%
    \def\f@rtoc{%
        \texorpdfstring{\MakeTextUppercase{\tempf@rtoc}}{\tempf@rtoc}}%
}
\makeatother

So simply removing the offending line from your MWE gives the desired result

\documentclass{memoir}

%\renewcommand*{\cftpartfont}{\MakeTextUppercase}

% From Memoir manual p. 158
\makeatletter
\settocpreprocessor{part}{%
    \let\tempf@rtoc\f@rtoc%
    \def\f@rtoc{%
        \texorpdfstring{\MakeTextUppercase{\tempf@rtoc}}{\tempf@rtoc}}%
}
\makeatother

\usepackage{hyperref}

\begin{document}

\tableofcontents*

\part{A Whale}
\chapter{A Tale}
\section{A Sail}
\subsection{A Beachball}

\part{A Poodle}
\chapter{A Noodle}
\section{A Doodle}

\end{document} 

enter image description here

karlkoeller
  • 124,410