# Inserting a PDF File Into a LaTeX Document

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...
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?

\documentclass[12pt,oneside]{book}
\usepackage{hyperref}
\usepackage{titletoc}
\usepackage[toc]{appendix}
\usepackage{pdfpages}
\renewcommand{\appendixtocname}{APPENDICES}

\begin{document}
\includepdf[pages=-]{myfile.pdf}
\tableofcontents
\chapter{CHAPTERR}
\section{Sectionn}
Some stuff.
\chapter{CHAPTERRR}
\section{Sectionnn}
Other stuff.

\begin{appendices}
\chapter{TABLESS}
\section{DATA}
\chapter{FIGURESS}
\section{CODE}
\end{appendices}

\end{document}


I want the following outputs:

• 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
• 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...
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

to prevent \setcounter to be expanded prematurely. A lot of macros need protection when used in \addtocontents
• @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