[Tex/LaTex] Problem adding pdfpages to current class and/or tex file

packagespdfpdfpages

The following .tex script complies perfectly on my computer:

\documentclass{report}
\usepackage[final]{pdfpages}
\begin{document}
\includepdf{Elanderphdmath.pdf}
\end{document}

However, no matter if I put

\RequirePackage{pdfpages}

in the class file, or if I put

\usepackage{pdfpages}

in the main tex file that uses the class file, I get the same errors, primarily

! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...

which occurs at some random location where there is normally no problem.
Again, these errors occur simply by adding the \usepackage or \RequirePackage command. Has anyone heard of any conflicts with this package and other packages? I don't have the first clue why it's not working. Thanks in advance!

Update 20110419 0955: I am using MikTex 2.9 on Windows 7. I just added all packages necessary (I hope) for pdfpages to run properly. I'm assuming this is true since the sample code ran perfectly (see above). I have two files, the class file and the main file. Here is the header for the class file:

\NeedsTeXFormat{LaTeX2e}[1995/12/01]     % Minimal LaTeX version required
\ProvidesClass{unlvmathesis}[2010/3/13 UNLV Math Thesis class v1.0]
\LoadClassWithOptions{report}

% REQUIRED PACKAGES ----------------------------------------------------------
% Note that they are also included as comments where they are used.

\RequirePackage{amsmath, amsthm, amsfonts, amssymb}
\RequirePackage{epsfig}
\RequirePackage{float}
\RequirePackage{caption}
\RequirePackage{geometry}
\RequirePackage{tocloft}
%\RequirePackage{hyperref}
\RequirePackage{pdfpages}

Here is the header for the main TEX document:

\documentclass[12pt]{unlvmathesis}
%\usepackage{pdfpages}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{tocloft}
\usepackage{ulem}
\usepackage{wrapfig}
%\usepackage{subfig}
\usepackage{float,caption,array,multirow}
\usepackage{graphicx,graphics,epsfig,pictexwd}
\usepackage{rotating}
\usepackage{psfrag}
\usepackage{layout}
\usepackage{hyperref}
\usepackage{listings}

Let me know if there is any more info that I can provide which would be useful.

Update: 4:21pm. After some reading, I see that the calc package affects the setcounter function. The errors are occurring only at the \section locations. In the class file, this is the only line that I see that is related to section numbering:

\setcounter{secnumdepth}{1}    % SUBSECTIONS ARE NOT NUMBERED

Maybe something is undefined that the calc package is choking on? Does everything have to be initialized?

Update 4:50pm:
At the first section in the first chapter, I get all of the following error messages:

! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...
l.4 \section{History of Metamaterials}

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.

! Undefined control sequence.
\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next 

l.4 \section{History of Metamaterials}

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.

! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...
l.4 \section{History of Metamaterials}

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.

! Undefined control sequence.
\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next 

l.4 \section{History of Metamaterials}

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.

! Missing number, treated as zero.
<to be read again> 
                   \begingroup 
l.4 \section{History of Metamaterials}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
<to be read again> 
                   \afterassignment 
l.4 \section{History of Metamaterials}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)


! Undefined control sequence.
\GenericError  ...                                
                                                  \let \@err@               ...
l.4 \section{History of Metamaterials}

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.

! Missing { inserted.
<to be read again> 
                   \let 
l.4 \section{History of Metamaterials}

A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Extra }, or forgotten \endgroup.
\@hangfrom #1->\setbox \@tempboxa \hbox {{#1}}
                                              \hangindent \wd \@tempboxa \no...
l.4 \section{History of Metamaterials}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten \endgroup.
\H@old@sect ...c }\interlinepenalty \@M #8\@@par }
                                                  \endgroup \csname #1mark\e...
l.4 \section{History of Metamaterials}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing number, treated as zero.
<to be read again> 
                   \begingroup 
l.4 \section{History of Metamaterials}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...
l.4 \section{History of Metamaterials}

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.

! Undefined control sequence.
\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next 

l.4 \section{History of Metamaterials}

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.

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.4 \section{History of Metamaterials}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing number, treated as zero.
<to be read again> 
                   \vskip 
l.4 \section{History of Metamaterials}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Missing } inserted.
<inserted text> 
                }
l.4 \section{History of Metamaterials}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.4 \section{History of Metamaterials}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

LaTeX Font Info:    Try loading font information for U+msa on input line 6.
("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\amsfonts\umsa.fd"
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
)
LaTeX Font Info:    Try loading font information for U+msb on input line 6.

("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\amsfonts\umsb.fd"
File: umsb.fd 2009/06/22 v3.00 AMS symbols B
)

I get all of these same error messages for every \section of every chapter. So, it's got something to do with incorporating the Calc package and sections.

Best Answer

I had almost the same problem, and the workaround suggested at http://web.archiveorange.com/archive/v/tMRBZ9hKeamEnltObBFi solves it! It has to do with an interaction of calc and apacite and counters.

Hope it helps!

---Edited as suggested to include the workaround--- Here's an extract of the workaround suggested in the link above. (A further reply to that post suggests that the latest version of apacite should take this into account and solve this. I haven't tested it though.)

=============== Extract begin ==========================

I've tested your example and found that the incompatibility is triggered by the use of the calc.sty package ...

More specifically, calc.sty changes the way \setcounter works. The programming in apacite.sty does not take this into account. The problem occurs when using \citet and other \cite command variants defined by natbib.sty , since these require significant extra parsing beyond what LaTeX would do without natbib .

Here's a simple fix that seems to work:

\usepackage[tocbib]{apacite}
%%  ----  RRM  2008/10/03
%% for compatibility with calc.sty
%% we need an extra \protect as below before  \setcounter
%%
\renewcommand{\BCnt}[1]{\protect\setcounter{BibCnt}{#1}\protect
\theBibCnt}
\renewcommand{\BCntIP}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- 
\protect\theBibCnt}}
\renewcommand{\BCntND}[1]{\protect\setcounter{BibCnt}{#1}\mbox{- 
\protect\theBibCnt}}
...

This avoids \setcounter being expanded too early, at a place where it isn't actually being used. All still works correctly at the place where it is required.

An alternative solution, and perhaps a better one, would be to have made the commands \BCnt \BCntIP \BCntND robust in the first place; e.g. apacite.sty should use

\DeclareRobustCommand{\BCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt}
\DeclareRobustCommand{\BCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}}
\DeclareRobustCommand{\BCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- \theBibCnt}}

You can patch this solution cleanly into existing documents, as follows:

...
\DeclareRobustCommand{\robustBCnt}[1]{\setcounter{BibCnt}{#1}\theBibCnt}
\DeclareRobustCommand{\robustBCntIP}[1]{\setcounter{BibCnt}{#1}\mbox{- 
\theBibCnt}}
\DeclareRobustCommand{\robustBCntND}[1]{\setcounter{BibCnt}{#1}\mbox{- 
\theBibCnt}}
\let\BCnt\robustBCnt
\let\BCntIP\robustBCntIP
\let\BCntND\robustBCntND
 ...

=============== Extract end ==========================

Related Question