The following memoir
documentclass source produces two tables of contents -- a short one and a detailed one. (The difference is that only the latter includes subsections.)
Question: How do I get the name of each of those (the values of \shortcontentsname
and \longcontentsname
, respectively), to appear in the headers of its pages after its first? E.g., I want to see
iv Detailed Contents
and
Detailed Contents v
for the left-hand page iv and the right-hand page v, respectively.
As the source shows, I tried
\createplainmark{shorttableofcontents}{both}{\shortcontentsname}
\createplainmark{longtableofcontents}{both}{\longcontentsname}
within \makepsmarks{main}
, but that produces headers with just the page numbers. I also tried, instead
\createplainmark{shortttoc}{both}{\shortcontentsname}
\createplainmark{longtoc}{both}{\longcontentsname}
and
\createplainmark{toc::shorttoc}{both}{\shortcontentsname}
\createplainmark{toc::longtoc}{both}{\longcontentsname}
but with the same results.
\documentclass{memoir}
%% PAGE STYLEs
\nouppercaseheads
\makepagestyle{main}
\makeheadrule{main}{\textwidth}{\normalrulethickness}
\makeevenhead{main}{\bfseries\sffamily\thepage}{}{\bfseries\sffamily\leftmark}
\makeoddhead{main}{\bfseries\sffamily\rightmark}{}{\bfseries\sffamily\thepage}
\addtopsmarks{main}{}{%
% insert "Chapter\space" & "Section\space" if desired as 4th argument:
\createmark{chapter}{left}{shownumber}{}{\enspace}
\createmark{section}{right}{shownumber}{}{\enspace}
}
% daleif (https://tex.stackexchange.com/a/512636/13492):
\makepsmarks{main}{%
\createmark{chapter}{both}{shownumber}{}{\enspace} % use both not left
\createmark{section}{right}{shownumber}{}{\enspace}
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}
% ---> My attempted additions: <---
\createplainmark{shorttableofcontents}{both}{\shortcontentsname}
\createplainmark{longtableofcontents}{both}{\longcontentsname}
}
\chapterstyle{default}
\pagestyle{main}
%% SECTIONING STYLES
\setsecnumdepth{subsection}
% CROSS-REFERENCING
\usepackage[pdftex]{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev]{cleveref}
\usepackage{crossreftools}
%% SHORT & LONG TOCs
%% Code by Christian Hupfer
% Just in case we're not loading hyperref
\makeatletter
%
\@ifpackageloaded{hyperref}{%
}{
\providecommand{\@currentHref}{}
\providecommand{\hyperlink}[2]{#2}
\providecommand{\getrefnumber}[1]{}
\providecommand{\phantomsection}{}
}
\AtBeginDocument{%
\newcommand{\shortcontentsstuff}{%
\contentsline{chapter}{\hyperlink{\getrefnumber{toc::shorttoc::anchor}}{\shortcontentsname}}{\pageref{toc::shorttoc}}{\getrefnumber{toc::shorttoc::anchor}}
}
\newcommand{\longcontentsstuff}{%
\contentsline{chapter}{\hyperlink{\getrefnumber{toc::longtoc::anchor}}{\longcontentsname}}{\pageref{toc::longtoc}}{\getrefnumber{toc::longtoc::anchor}}
}
}
\newif\if@shorttoc
%
\renewcommand{\tableofcontents}{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
% Addition
\if@shorttoc
\protected@edef\@currentlabel{shorttoc}% Rather unimportant
\edef\@currentlabelname{\shortcontentsname}% For \nameref
\label{toc::shorttoc}%
% Now let us fix the hyperanchor for the short toc
\edef\@currentlabelname{}%
\protected@edef\@currentlabel{\@currentHref}\label{toc::shorttoc::anchor}
\else
\protected@edef\@currentlabel{longtoc}% Rather unimportant
\edef\@currentlabelname{\longcontentsname}
\label{toc::longtoc}%
% Now let us fix the hyperanchor for the long toc
\edef\@currentlabelname{}%
\protected@edef\@currentlabel{\@currentHref}\label{toc::longtoc::anchor}
\fi
% End of additions
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
%
\newcommand{\longcontentsname}{Detailed Contents}
\newcommand{\shortcontentsname}{Short Contents}
%
\newcommand{\shorttableofcontents}[1][1]{%
\begingroup
\@shorttoctrue
\setcounter{tocdepth}{#1}
\let\shortcontentsstuff\relax
\phantomsection
\write\@auxout{\string\@writefile{toc}{\protect\longcontentsstuff}}
\let\contentsname\shortcontentsname% Disabling the \shortcontentsstuff in toc
\tableofcontents
\endgroup
\@shorttocfalse% Disable the short toc
}
\newcommand{\longtableofcontents}[1][3]{%
\begingroup
\setcounter{tocdepth}{#1}
\phantomsection
\let\longcontentsstuff\relax% Disabling the \longcontentsstuff in toc
\write\@auxout{\string\@writefile{toc}{\protect\shortcontentsstuff}}
\let\contentsname\longcontentsname
\tableofcontents
\endgroup
}
%
\makeatother
%% FOR THIS DEMO:
\usepackage{lipsum}
\begin{document}
\frontmatter
\shorttableofcontents\cleardoublepage
\longtableofcontents
\mainmatter
\chapter{One}
\lipsum[1]
\section{A section}
\subsection{First}
\lipsum[1-7]
% Many (sub-)sections to force multi-page TOC
\subsection{Second}
\subsection{Third}\subsection{Four}\subsection{Five}\subsection{Six}
\subsection{Seven}\subsection{Eight}\subsection{Nine}
\subsection{Ten}\subsection{Eleven}\subsection{Twelve}
\subsection{Thirteen}\subsection{Fourteen}\subsection{Fifteen}
\subsection{Sixteen}\subsection{Seventeen}\subsection{Eighteen}
\subsection{Nineteen}\subsection{Twenty}\subsection{Twenty-one}
\subsection{Twenty-two}\subsection{Twenty-three}\subsection{Twenty-four}
\subsection{Twenty-five}\subsection{Twenty-six}\subsection{Twenty-seven}
\section{B section}\section{C section}\section{D section}
\section{E section}\section{F section}\section{G section}\section{H section}
\section{I section}\section{J section}\section{K section}\section{L section}
\section{M section}\section{N section}\section{O section}\section{P section}
\section{Q section}\section{R section}\section{S section}\section{T section}
\section{U section}\section{V section}\section{W section}\section{X section}
\section{Y section}\section{Z section}\section{AA section}\section{BB section}
\section{CC section}\section{DD section}\section{EE section}\section{FF section}
\section{GG section}\section{HH section}\section{II section}\section{JJ section}
\section{KK section}\section{LL section}\section{MM section}\section{NN section}
\section{OO section}\section{PP section}\section{QQ section}\section{RR section}
\section{SS section}\section{TT section}\section{UU section}\section{VV section}
\section{WW section}\section{XX section}\section{YY section}\section{ZZ section}
\end{document}
Here's what I get now for pages in the detailed table of contents:
References:
- This question is a follow-up to https://tex.stackexchange.com/a/512636/13492 (which is working as desired for other frontmatter and mainmatter.
- The code for the two tables of contents comes in part from https://tex.stackexchange.com/a/346433/13492.
Thsy method, unfortunately, does not preserve the
pagestyle
for pages after chapter page in the Short Contents and the Long Contents. It does, however, produce the wanted entries of each of the two TOCs in, and only in, the other; and it makes the links on each of those entries point to the top of the corresponding TOC page.
Partial solution:
Using the etoc
package allows a short and a long table of contents that do preserve the page style and chapter style -- without, however, seeming to allow each of the two TOCs to have an entry only for the other TOC.
See: memoir: Exclude entry of other TOC from each of two TOCs,
\createmark
as the name of the toc is not something that changes and thus one can get aways with a simpler interface. Guess what the ` \createplainmark{toc}{both}{\contentsname}` lines does?\newcommand{\shorttableofcontents}[1][1]{% \begingroup \setcounter{tocdepth}{#1} \let\contentsname\shortcontentsname \tableofcontents* \endgroup }
and your definition for the name seems to work fine. That redefinition of\tableofcontents
removes everything that memoir does so of course everything you try via memoir interfaces fail