7

I get the following error when trying to use \MakeTextUppercase to customize the table of contents:

! Undefined control sequence.
\find@pdflink ...ode \protected@edef \Hy@testname 
                                              {#2}\ifx \Hy@testname \@em... 
l.2 ...entsline {chapter}{Contents}{1}{section*.1}

Any idea of what's going on? I've included a minimum example below for testing.

\documentclass[a4paper, 10pt, english]{memoir}

\usepackage{babel}
\usepackage{csquotes}
\usepackage{textcase}
\usepackage{lipsum}
\usepackage{hyperref}

\renewcommand{\cftchapterfont}{\MakeTextUppercase}



\begin{document}

\tableofcontents

\chapter{Test}
\lipsum

\end{document}
lockstep
  • 250,273
gablin
  • 17,006

2 Answers2

7

I remember \MakeUppercase and \MakeTextUppercase can easily break, also with hyperref.

Before you try to fix that, I suggest considering using small caps shape instead. That's much better than all caps, from a typographic view. This declaration works:

\renewcommand{\cftchapterfont}{\scshape}

table of contents with small caps

If it's really required, it can be solved by redefining memoir's \l@chapter, which is responsible for printing the chapter TOC entry, using \uppercase (\MakeTextUppercase and \Makeuppercase would break here as well):

\makeatletter
\renewcommand*{\l@chapter}[2]{%
  \l@chapapp{\uppercase{#1}}{#2}{\cftchaptername}}
\makeatother

all caps in TOC chapter entry

(This time with hyperref link border, which can be removed by options.)

Stefan Kottwitz
  • 231,401
  • 1
    While this is good stylistic advice, what if the formatting specifications require uppercase? – Alan Munn Aug 14 '11 at 18:52
  • @Alan: in that case I would redefine \l@chapter I'll show it – Stefan Kottwitz Aug 14 '11 at 19:41
  • Actually, at the moment it is formatted as small caps. And as there apparently is no elegant fix I think I'll stick to it. And as you said, it is good style to use small caps rather than upper case. Thanks. – gablin Aug 14 '11 at 20:42
2

Here's what I ended up with on this question from April (might want close this as a duplicate, or not). In my particular case, I needed to only make the chapter titles uppercase, and leave the appendix titles alone. I didn't want to keep a full copy of the \@chapter or related commands around, but there's the potential for long-term breakage either way if your code lives for many years (either the patch I use will fail, or your old copy of the \@chapter or related commands won't work the same way as the newer versions expect):

enter image description here

\documentclass{memoir}
\usepackage{etoolbox}
\makeatletter
\ifpatchable*{\@chapter}{\typeout{Chapter can be patched}}{\typeout{Chapter cannot be patched}}
\patchcmd{\@chapter}%
{\addcontentsline{toc}{chapter}}%
{\let\f@rtocold\f@rtoc \def\f@rtoc{\uppercase\expandafter{\f@rtocold}} \addcontentsline{toc}{chapter}}%
{\typeout{Succeeded}}%
{\typeout{Failed}}
\makeatother
\usepackage{hyperref}

\begin{document}
\tableofcontents*
\chapter{One}
\chapter{Two}
\appendix \appendixpage
\chapter{Alpha}
\end{document}

Since I still have some number of users with PC-TeX who don't get e-TeX support by default, I also have this option using the ted package.

\documentclass{memoir}
\usepackage{ted}
\makeatletter
\Substitute*[{\gdef\@chapter[##1]##2}]{\@chapter[#1]{#2}}%
{\addcontentsline{toc}{chapter}}%
{\let\f@rtocold\f@rtoc%
 \def\f@rtoc{\texorpdfstring{\uppercase\expandafter{\f@rtocold}}{\f@rtocold}}%
 \addcontentsline{toc}{chapter}}
\makeatother
\usepackage{hyperref}

\begin{document}
\tableofcontents*
\chapter{One}
\chapter{Two}
\appendix \appendixpage
\chapter{Alpha}
\end{document}

enter image description here

Mike Renfro
  • 20,550