The following MWE shows that, if the \chapter
macro is redefined as in a previous question of mine: Prepend different stuffs to starred and unstarred \chapter commands, the \chaptertitle
macro from the titleps
(or in titlesec
?) package is ignored with e.g. \tableofcontents
, \listoffigures
and \listoftables
commands (but is not ignored with ordinary chapters).
\documentclass{book}
\usepackage{lipsum}
\usepackage{xparse,xpatch}
\usepackage{titleps}
\usepackage{tocvsec2}
%
\makeatletter%
% Hack to be sure \resetsecnumdepth* from tocvsec2 behaves well
\@ifpackagelater{tocvsec2}{2014/03/10}{%
}{%
\renewcommand\resetsecnumdepth{%
\@ifstar{%
\setcounter{secnumdepth}{\value{max@secnumdepth}}%
\edef\stack@secnumdepth{\the\c@secnumdepth\relax}%
}{%
\ifx\stack@secnumdepth\@empty%
\PackageWarning{tocvsec2}{There is no previous value for secnumdepth}%
\else%
\afterassignment\gobble@secnumdepth%
\expandafter\c@secnumdepth\expandafter\numexpr\stack@secnumdepth\@nil%
\fi%
}%
}%
}%
\makeatother%
\let\ORIchapter\chapter%
\RenewDocumentCommand\chapter{som}{%
\IfBooleanTF{#1}
{
\setsecnumdepth{none}%
}
{%
\resetsecnumdepth*
}
\IfNoValueTF{#2}
{\ORIchapter{#3}}
{\ORIchapter[#2]{#3}}%
}
% we don't want \chapter* for \tableofcontents and similar lists
\xpatchcmd{\tableofcontents}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\listoffigures}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\listoftables}{\chapter}{\ORIchapter}{}{}
% populate the stack
\AtBeginDocument{\setsecnumdepth{none}}
%
\newpagestyle{liminary}[]{%
\sethead[\thepage]%
[]%
[\chaptertitle]%
{%
\sectiontitle%
}%
{}%
{\thepage}%
\headrule%
}%
%
\pagestyle{liminary}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{A 1st chapter}
\lipsum[1-10]
\section{A 1st section of the 1st chapter}
\lipsum[1-10]
\end{document}
If the lines:
\xpatchcmd{\listoffigures}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\listoftables}{\chapter}{\ORIchapter}{}{}
are commented, the corresponding \chaptertitle
are not ignored (maybe with side effects I didn't notice) but if the line:
\xpatchcmd{\tableofcontents}{\chapter}{\ORIchapter}{}{}
is commented, a "TeX capacity exceeded" error arises:
! TeX capacity exceeded, sorry [input stack size=5000].
\@nameuse #1->\csname #1
\endcsname
l.62 \tableofcontents
! ==> Fatal error occurred, no output PDF file produced!
Maybe it could be helpful to notice that, with or without:
\xpatchcmd{\printglossary}{\chapter}{\ORIchapter}{}{}
the \printglossary
command behaves well w.r.t. \chaptertitle
, as shown by the following MWE:
\documentclass{book}
\usepackage{lipsum}
\usepackage{xparse,xpatch}
\usepackage{titleps}
\usepackage{tocvsec2}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{bar}{%
name={bar},
description={bar}
}
%
\makeatletter%
% Hack to be sure \resetsecnumdepth* from tocvsec2 behaves well
\@ifpackagelater{tocvsec2}{2014/03/10}{%
}{%
\renewcommand\resetsecnumdepth{%
\@ifstar{%
\setcounter{secnumdepth}{\value{max@secnumdepth}}%
\edef\stack@secnumdepth{\the\c@secnumdepth\relax}%
}{%
\ifx\stack@secnumdepth\@empty%
\PackageWarning{tocvsec2}{There is no previous value for secnumdepth}%
\else%
\afterassignment\gobble@secnumdepth%
\expandafter\c@secnumdepth\expandafter\numexpr\stack@secnumdepth\@nil%
\fi%
}%
}%
}%
\makeatother%
\let\ORIchapter\chapter%
\RenewDocumentCommand\chapter{som}{%
\IfBooleanTF{#1}
{
\setsecnumdepth{none}%
}
{%
\resetsecnumdepth*
}
\IfNoValueTF{#2}
{\ORIchapter{#3}}
{\ORIchapter[#2]{#3}}%
}
% we don't want \chapter* for \tableofcontents and similar lists
\xpatchcmd{\tableofcontents}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\listoffigures}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\listoftables}{\chapter}{\ORIchapter}{}{}
\xpatchcmd{\printglossary}{\chapter}{\ORIchapter}{}{}
% populate the stack
\AtBeginDocument{\setsecnumdepth{none}}
%
\newpagestyle{liminary}[]{%
\sethead[\thepage]%
[]%
[\chaptertitle]%
{%
\sectiontitle%
}%
{}%
{\thepage}%
\headrule%
}%
%
\pagestyle{liminary}
\glsaddall
\begin{document}
\printglossary
\tableofcontents
\listoffigures
\listoftables
\chapter{A 1st chapter}
\lipsum[1-10]
\section{A 1st section of the 1st chapter}
\lipsum[1-10]
\end{document}
Hence my question: is it possible to adjust the redefinition of the \chapter
macro as in a previous question of mine: Prepend different stuffs to starred and unstarred \chapter commands in order \chaptertitle
from titleps
package is not ignored for commands like \tableofcontents
, \listoffigures
and \listoftables
?
\gdef\chaptertitle{\contentsname}
before\ORIchapter
in the patch to\tableofcontents
seems to work. The problem seems to be in the fact that there are concurrent tries to redefine\chapter
\listoffigures
and\listoftables
(to make them use\ORIchapter
instead of the new\chapter
macro)?glossaries
is used (as in the second MWE above): in such a case, the\chaptertitle
of\tableofcontents
is theglossaries
' one: "Glossary".