[Tex/LaTex] Undefined control sequence when including pdfpages package

errorspdfpdfpages

Problem:

I try to include the following packages in my .tex file:

\usepackage{graphicx}
\usepackage{pdfpages}

For this I get the following errors:

thesis.tex (line 186)
Undefined control sequence (\mainmatterSU ...)

I Google a bit and find this: https://en.wikibooks.org/wiki/LaTeX/Errors_and_Warnings#Undefined_control_sequence

Which tells me that it might be a typo, but then I open up the .cls file and check there, which gives me:

% MAINMATTER
\newcommand{\mainmatterSU}{

\begingroup
\cleardoublepage
\edef\x{\endgroup
\noexpand\mainmatter
\setcounter{page}{\the\value{page}}%
}%
\x

\cleardoublepage

\fancypagestyle{plain}
{
    \fancyhead{}
    \fancyfoot[LE,RO]{{\fontfamily{verdana}\selectfont\thepage}}
}   % re-define plain page

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[LE,RO]{{\fontfamily{verdana}\selectfont\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}

So I'm going a bit insane over here because I don't see the miss-spelling or what I could have done wrong by just including a package.

Removing those two packages will remove the errors.

Any help is appreciated!

Best Answer

The error message is

./thesis.tex:186: Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next
                                                 {\calc@error #1}\fi \fi \f...
l.186 \mainmatter

so the undefined command is \calc@next

as I guessed in initial comment, the \edef usage is incorrect and \setcounter is not safe in that context, although the error is usually not detected if calc is not loaded. put \noexpand before \setcounter

Related Question