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


    in front of the \chapter.

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


    to the chapter.





\chapter{First appendix}

\chapter{Second appendix}
Don't list sections in TOC, please.

Should not be listed in TOC.

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



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?

1 Answer 1


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


  • Wow, that was fast. Case closed. Thanks a lot!
    – itsjeyd
    Nov 17, 2014 at 13:16

You must log in to answer this question.

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