我开始这个先前的问题。我现在有一个简单而优雅的etoolbox
解决方案,可以将章节条目全部大写,但附录条目保持不变。简单、优雅,但hyperref
似乎与 不兼容。
梅威瑟:
\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}
这表明该\@chapter
命令可以修补,我的修补成功,并且我得到了我想要的 PDF 输出:
启用该hyperref
包会以某种方式将我的更改恢复为 ToC 格式:
编辑:添加\tracingpatches
到序言后,工作版本将以下内容放入日志中:
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
而失败的版本则改为:
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
我没有看到 hyperref 修改的任何明显地方\@chapter
,但我肯定错过了一些东西。
最终工作示例(包括超链接):
\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}
答案1
加载超链接就在之前\begin{document}
-- 即,在所有包之后和在所有宏重新定义之后。
编辑:这不是一般规则,只是针对您的最小示例的解决方案。