0

I need to update my organization's style file to make it hyperref-compatible. It uses the memoir class and requires all of the table of contents entries to be in all-caps:

All-Caps Table of Contents

Per Lowercase TOC with memoir and hyperref and the memoir class documentation (p. 162) there isn't a built-in way to do this in the class itself, but I was able to tweak Gonzalo Medina's answer to How to make section name uppercase in ToC? to get the following MWE. This solution works with the rest of my organization's style file but only puts the top level (section) in all-caps.

\documentclass{memoir}
\usepackage{textcase}
\usepackage{hyperref}

\renewcommand{\thesection}{\arabic{section}} \setcounter{tocdepth}{4} \setcounter{secnumdepth}{4}

\makeatletter \let\oldcontentsline\contentsline \def\contentsline#1#2{% \expandafter\ifx\csname l@#1\endcsname\l@section \expandafter@firstoftwo \else \expandafter@secondoftwo \fi {% \oldcontentsline{#1}{\MakeTextUppercase{#2}}% }{% \oldcontentsline{#1}{#2}% }% } \makeatother \begin{document}

\tableofcontents
\section{A test section $a=b$}\label{sec:test}
\subsection{A test subsection}\label{sec:test2}
\section{Another test section with a reference:~\ref{sec:test}}
\subsection{A subsection with a reference~\ref{sec:test2}}
\subsubsection{A subsubsection}
\paragraph{A paragraph}

\end{document}

Output from above code snippet

I don't know enough about how the code snippet works to alter it to make other levels in all-caps as well. The above example goes down to paragraph, which is probably the most levels I'd ever need to take my ToCs, but because it's my organization's style file I'd like to learn how to implement this down to however many levels deep are needed. Can anyone offer any assistance? If it makes any difference, for other reasons our style file requires the uses of LuaLaTeX.

amizener
  • 173
  • 1
    your code contains a test \expandafter\ifx\csname l@#1\endcsname\l@section which restricts the redefinition to section. If you don't need that you can simply use \def\contentsline#1#2{\oldcontentsline{#1}{\MakeTextUppercase{#2}}}. (Personally I hate such all caps lines, imho they are much less readable and if there are many of them on a page it looks ugly.) – Ulrike Fischer May 10 '22 at 07:32
  • That worked! Thank you very much. (They're not my favorite but I didn't write my organization's style guide and do not get a vote in this matter of taste.) – amizener May 10 '22 at 14:29

0 Answers0