将回忆录章节条目设为目录全大写,将附录条目设为常规大小写,而不会破坏超链接

将回忆录章节条目设为目录全大写,将附录条目设为常规大小写,而不会破坏超链接

我有一个论文风格,但大约 10% 的代码是回忆录的副本,\def\@chapter它允许我将所有常规章节条目全部大写,并将附录条目保留为常规大小写。这可行,但我认为有更简单的方法。

理想情况下,我希望我的学生继续使用该\chapter命令,而不是定义我自己的文档部门。

我设法找到了 memoir.cls 中章节和附录之间的逻辑分歧——章节调用命令\l@chapter,附录调用\l@appendix命令:

\newcommand*{\l@chapter}[2]{%
  \l@chapapp{#1}{#2}{\cftchaptername}}

\newcommand*{\l@appendix}[2]{%
  \l@chapapp{#1}{#2}{\cftappendixname}}

我尝试\uppercase在第一个中添加 ,如下所示,但这样做会破坏超链接——链接仍然存在,但有一个黑色边框,并且没有链接到正确的位置。最小示例(注释掉\renewcommand具有正确链接但大小写错误的目录,或保留它以用于正确大小写和死链接):

\documentclass{memoir}
\usepackage{lipsum}
\usepackage{hyperref}
\makeatletter
\renewcommand*{\l@chapter}[2]{%
  \l@chapapp{\uppercase{#1}}{#2}{\cftchaptername}}
\makeatother

\begin{document}
\tableofcontents*

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

包含断开链接的目录 带有完整链接的目录


编辑(2011/02/23):我有另一个想法来修补,\@chapter而不是复制其所有代码并进行一次更改。但那也失败了。我怀疑这是因为我没有正确转义反斜杠或其他字符:

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

\makeatletter
\ifpatchable*{\@chapter}{\typeout{Chapter can be patched}}{\typeout{Chapter cannot be patched}}
\patchcmd{\@chapter}{\protect\chapternumberline{\thechapter}\f@rtoc}{\protect\chapternumberline{\thechapter}\uppercase\expandafter{\f@rtoc}}{\typeout{Succeeded}}{\typeout{Failed}}
\makeatother

\begin{document}
\tableofcontents*

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

在日志中返回

Chapter can be patched
Failed

第二次编辑(2011/02/23):可用的 etoolbox 补丁已发布这个帖子,但 hyperref 仍然会干扰。

答案1

接下来只是部分解决方案,因为它将常规章节条目排版为小的大写(使用\scshape)。我不知道有没有不带参数的全大写宏(这并不意味着没有参数:-)),而且我还怀疑这与更基本的方式的机制\uppercase不兼容hyperref。(TeX 大师们,请对此发表评论!)

\documentclass{memoir}
\usepackage{lipsum}
\usepackage{hyperref}
\renewcommand{\cftchapterfont}{\scshape}
\makeatletter
\g@addto@macro{\appendixpage}{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchapterfont}{}%
  }%
}

\begin{document}
\tableofcontents*

\chapter{One}
\lipsum
\chapter{Two}
\lipsum
\appendix \appendixpage

\chapter{Alpha}
\lipsum
\end{document}

相关内容