2

I am working on a document that makes use of a document class file which forces all unnumbered chapters created with \chapter* to appear in the table of contents.

The problem is that I need to add an unnumbered chapter to the document which (exceptionally) I don't want it to appear in the TOC. But I can't because very time \chapter* is used it is added to the TOC via the \addcontentsline macro.

Here is the fragment of the .cls file that instructs every \chapter* to appear in the TOC:

\renewcommand{\@makeschapterhead}[1]{%
  \noindent
  \begin{center}
    \LARGE\sffamily\bfseries \MakeUppercase{#1} \par\nobreak
  \end{center}
  \vspace{3ex}
  \addcontentsline{toc}{chapter}{\large\sffamily\bfseries #1}  % <-- PUTS EVERY CHAPTER* IN THE TOC!
}

How can I circunvent this without affecting other chapters on the document that are defined with \chapter*?

Is it possible to define a custom chapter command that does everything \chapter* does except adding an entry in the TOC?

2
  • 2
    Simply type your headline and format it as specified in the definition. There is no need to put all in a newcommand. Oct 18, 2021 at 17:15
  • @HaraldLichtenstein I didn't realize that the definition in the .cls file is simply defining the formatting for the chapter headline until I read your comment. So I used the same formatting for the headline of my unlisted chapter and job done! Thank you! Oct 18, 2021 at 17:53

1 Answer 1

2

You can temporarily deactivate the \addcontentsline macro to just capture its arguments but do nothing with them. Something like

\begingroup
\renewcomand{\addcontentsline}[3]{}% Make \addcontentsline a no-op
\chapter*{Very special starred chapter}
\endgroup

The grouping provides a scope within which macro changes is considered temporary (unless changes are made explicitly global).

1
  • +1. And if you're using hyperref, you'll need to change the 3 to 5 (or 4?).
    – Teepeemm
    Oct 19, 2021 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .