2

When using memoir and hyperref I can't make chapters lowercase in the TOC or I get all sorts of errors.

Here's a MWE:

\documentclass{memoir}
\usepackage{lmodern}

% \renewcommand{\cftchapterfont}{\scshape}              % WORKS
\renewcommand{\cftchapterfont}{\scshape\MakeLowercase}  % DOESN'T WORK

\usepackage{hyperref} % Without hyperref it's all good

\begin{document}
  \tableofcontents*
  \chapter{One}
  \clearpage
  \chapter{Two}
\end{document}

Any ideas what's going on and how to fix it?

  • 1
    \MakeLowercase is not expandable... so hyperref goes mad about this ;-) – user31729 Oct 15 '17 at 22:21
  • @ChristianHupfer So what do I do, is there a way to work around that? – dbmrq Oct 15 '17 at 22:27
  • 3
    Well, yes and no. See p. 158 of the current memoir manual – user31729 Oct 15 '17 at 22:31
  • @ChristianHupfer Ah, that's great, thank you! I searched the manual a lot before asking here, but missed that part. – dbmrq Oct 15 '17 at 22:38
2

From the memoir user manual (p 158):

About upper or lower casing TOC entries

Some designs call for upper (or lower casing) TOC entries. This is possible but the solution depends on whether the hyperref package is used or not.

Without hyperref one can simply end the \cftKfont with say \MakeTextUppercase and the K-type entry will be upper cased.

With hyperref the possibilities are limited. Explanation: The upper/lower casing macros are not that robust, and need the content to be simple - for some definition of simple. When hyperref is used, the hyperlink is wrapped around the entry before \cftKfont gains access to it, and is thus generally too complicated for, say, \MakeTextUppercase to handle. The following workaround draws inspiration from hyperref breaks my all-caps ToC entries:

\settocpreprocessor{<type>}{<code>}

Here <type> is one of chapter, part or book. If needed we will attempt to add a similar feature to the rest of the sectional types, please write the maintainer. And <code> can be something like this:

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

Where \f@rtoc is a placeholder inside \chapter, \part and \book, holding the material to be written to the actual TOC file before hyperref accesses it. This way the upper casing is sneaked into the TOC file, and the bookmark part of hyperref will not complain about the \MakeTextUppercase in the data. Of course, you will not have upper cased titles in the bookmark list.

With the above in mind, you can use

enter image description here

\documentclass{memoir}

\makeatletter
\settocpreprocessor{chapter}{%
  \let\temp@f@rtoc\f@rtoc
  \def\f@rtoc{\texorpdfstring{\MakeTextLowercase{\temp@f@rtoc}}{\temp@f@rtoc}}
}
\makeatother
\renewcommand{\cftchapterfont}{\normalfont\scshape}% Formatting the \chapter ToC entries

\usepackage{hyperref}

\begin{document}

\tableofcontents*

\chapter{First}

\chapter{Second}

\end{document}
0

Try this

\documentclass{memoir}
\usepackage{lmodern}

\renewcommand{\cftchapterfont}[1]{\scshape\lowercase{#1}}

\usepackage{hyperref}

\begin{document}
  \tableofcontents*

  \chapter{One}
  \clearpage
  \chapter{Two}
\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.