1

What I'm trying to do

I have a document with an appendix that consists of multiple chapters.

  1. The first \chapter should not receive any special treatment.

  2. For the second \chapter I'd like to exclude \section headings from the TOC. This can be achieved by placing

    \addtocontents{toc}{\setcounter{tocdepth}{0}}
    

    in front of the \chapter.

  3. The third \chapter should include all pages of an external PDF file. This can be achieved by adding

    \includepdf[pages=-]{external.pdf}
    

    to the chapter.

MWE

\documentclass[11pt]{scrbook}
\usepackage{graphicx}
\usepackage{pdfpages}
\begin{document}

\tableofcontents


\part{Appendix}
\appendix

\chapter{First appendix}
\section{Section}

\addtocontents{toc}{\setcounter{tocdepth}{0}}
\chapter{Second appendix}
Don't list sections in TOC, please.

\section{Section}
Should not be listed in TOC.

\chapter{Third appendix}
Should include all pages of external PDF file.

\includepdf[pages=-]{external.pdf}
\end{document}

Problem

If I only set tocdepth (and omit the code that takes care of including external.pdf), the document compiles cleanly.

Similarly, if I only include external.pdf (and omit the code that changes tocdepth), the document also compiles cleanly.

However, when I try to compile the file as shown in the MWE above, I get the the following error message:

ERROR: Undefined control sequence.

--- TeX said ---
\@calc@post@scan ...st@scan \else \def \calc@next 
                                              {\calc@error #1}\fi \fi \f...
l.23 \addtocontents{toc}{\setcounter{tocdepth}{0}}

Q: How can I address all of the requirements stated above and get the document to compile cleanly?

3

The package pdfpages loads calc, which makes \setcounter fragile.

Solution:

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
  • Wow, that was fast. Case closed. Thanks a lot! – itsjeyd Nov 17 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.