Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I started out on this earlier question. I now have a simple and elegant etoolbox solution to making all-caps chapter entries, but leaving appendix entries untouched. Simple, elegant, and incompatible with hyperref, it seems.

MWE:

\documentclass{memoir}
\usepackage{etoolbox}
%\usepackage{hyperref}

\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

\begin{document}
\tableofcontents*

\chapter{One}
\chapter{Two}
\appendix \appendixpage
\chapter{Alpha}
\end{document}

which indicates that the \@chapter command can be patched, my patch succeeds, and I get the PDF output I wanted:

ToC with all-caps chapters, normal appendices, and no hyperrefs

Enabling the hyperref package reverts my changes to the ToC format, somehow:

ToC with normal chapters and appendices, plus hyperrefs


EDIT: After adding \tracingpatches to the preamble, the working version puts the following in the logs:

Chapter can be patched
[debug] tracing \patchcmd on input line 8
[debug] analyzing \@chapter
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] ++ search pattern found in replacement text
[debug] ++ patching possible
[debug] == retokenizing macro now
Succeeded

and the failing version puts instead:

Chapter can be patched
[debug] tracing \patchcmd on input line 8
[debug] analyzing \@chapter
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ macro can be retokenized cleanly
[debug] -- search pattern not found in replacement text
Failed

I don't see any obvious places where hyperref modifies \@chapter, but I could have certainly missed something.


Final Working Example (including hyperref):

\documentclass{memoir}
\usepackage{etoolbox}
\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}

ToC with hyperrefs, and in all caps

share|improve this question
    
Try loading hyperref after all the other packages. –  Seamus Feb 23 '11 at 22:45
    
I'm loading it after all the other packages in the MWE. –  Mike Renfro Feb 24 '11 at 0:54
    
And hyperref is redefining \@chapter considerably. So says \show\@chapter from the working version to the non-working one. –  Mike Renfro Feb 24 '11 at 1:04
add comment

1 Answer

up vote 5 down vote accepted

Load hyperref immediately before \begin{document} -- i.e., after all packages and after all macro redefinitions.

EDIT: This is not a general rule, only a solution for your minimal example.

share|improve this answer
    
And that makes my \@chapter patch work properly again. Thanks. –  Mike Renfro Feb 24 '11 at 1:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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