I cannot insert a PDF file into the LaTeX document with the following code. When I run the following code, I get an error message in the log file like this:

"! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next
{\calc@error #1}\fi \fi \f...
l.20 \addtocontents{toc}{\setcounter{tocdepth}{0}}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined."

How can I insert a PDF file into the document?


 Some stuff.
 Other stuff.



I want the following outputs:

enter image description here

enter image description here

enter image description here

  • 1
    It would help if you would say which error message you get. – Ulrike Fischer Feb 20 at 23:36
  • I added the image of the error message in the above post. – oa-90 Feb 20 at 23:58
  • Show the real message from the log file, not the summary of your editor. – Ulrike Fischer Feb 21 at 0:04
  • How did you obtain that image of desired contents? Did you type by hand? – Sigur Feb 21 at 2:06
  • 1
    Now I can confirm a conflict with pdfpages with the line \addtocontents{toc}{\setcounter{tocdepth}{0}}. In the .toc file we find \let \calc@A \calc@Acount \let \calc@B \calc@Bcount \begingroup \aftergroup \calc@B \calc@A \begingroup \aftergroup \calc@B \calc@A \afterassignment \def {\GenericError {(calc) }{Package calc Error: '\global ' invalid at this point}{See the calc package documentation for explanation.}{I expected to see one of: + - * / )}}\calc@A 0!\global \calc@A \calc@B \endgroup \global \c@tocdepth \calc@B – Sigur Feb 21 at 11:55

This has nothing to do with the pdfpages package, but it loads calc and that is the issue, presumably calc leaves \setcounter unrobust or whatever...

If you want to change the counter in that location just use


to prevent \setcounter to be expanded prematurely. A lot of macros need protection when used in \addtocontents

  • Finally, an answer.... since last night I was thinking on it. – Sigur Feb 21 at 12:12
  • @Sigur it also helps taking a look inside the .toc or .aux files, then it is easy to see when something is expanded prematurely. – daleif Feb 21 at 12:26

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.