2

I have a weird question, or rather two. I would like to hide a level of organization, e.g. chapters, from the table of contents. BUT I want to keep the lower levels (e.g. sections) and I also want to keep chapters for the pdf table of contents for navigation, and keep chapters for page headers. This prob sounds weird but in the book I'm editing it makes sense. (I have parts, chapters and sections. I will reformat the TOC with titletoc so it will look OK)

so the two questions are

  1. Is it possible to separate the in-document TOC from the one in the pdf, and how?
  2. What is the simplest way to omit chapters from the in-document TOC, but keep the chapter names, numbers etc for other purposes (headers, equation numbering, etc)?

I only want to keep chapters for headers and the pdf TOC, but I don't use them elsewhere. They are only for the headers, the non-print organization, and for equation numbering. I already don't display the chapter headings in the text using

\makeatletter
\newcommand{\unchapter}[1]{%
  \begingroup
  \let\@makechapterhead\@gobble % make \@makechapterhead do nothing
  \chapter{#1}
  \endgroup
}
\makeatother

Using chapter* doesn't work as that disables headers, counters, and the pdf TOC. I couldn't make \chapter[]{} work either with the above hack. I was trying to manipulate the TOC entries but that also manipulates the pdf navigation.

I was thinking of perhaps keeping the "real" TOC for the pdf navigation only, but not displaying it in the document, and crafting a custom TOC for display, if that is possible? (Not sure how to)

I appreciate if anybody has a suggestion.

4
  • 1
    set the tocdepth counter to declare what should go in the toc, set bookmarkdepth to declare what should go into the bookmarks. Commented Jul 31, 2022 at 19:34
  • Oh! Wait I thought tocdepth means "up to" something, can it also skip specific levels? I want parts and sections, but not chapters.
    – fusionfan
    Commented Jul 31, 2022 at 19:49
  • 1
    that sounds rather odd, but you can change the levels of sectioning command. Alternatively you can temporarly change the level before a chapter and then back again. Commented Jul 31, 2022 at 20:26
  • Good idea! I could perhaps modify my unchapter macro accordingly.
    – fusionfan
    Commented Jul 31, 2022 at 20:43

1 Answer 1

0

Thanks to Ulrike above, who pointed out that bookmarkdepth is different from tocdepth, I figured a solution that works nicely:

\makeatletter
\newcommand{\unchapter}[1]{%
  \begingroup
  \let\@makechapterhead\@gobble % make \@makechapterhead do nothing
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
  \chapter{#1}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
  \endgroup
}
\makeatother

All one needs to do is purge the .toc file before recompilation.

You must log in to answer this question.

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