# Undefined control sequence with Color Package in Custom LaTeX document class

I have the following class file shown here:

%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{puseniorthesis}
[2008/05/02 v1.4.1 Princeton University Thesis class]

\RequirePackage{setspace}
\RequirePackage{zref-totpages}

%report type option
\newif\if@progress
\@progressfalse
\DeclareOption{progress}{\@progresstrue}

%copy type option
\newif\if@filecopy
\@filecopyfalse
\DeclareOption{filecopy}{\@filecopytrue}

%abstract
\long\def\@abstract{\@latex@error{No \noexpand\abstract given}\@ehc}

%frontmatter numbered with roman numerals, mainmatter with arabic
\newcommand*{\frontmatter}{
\pagenumbering{roman}
}
\newcommand*{\mainmatter}{\pagenumbering{arabic}}
\newcommand*{\backmatter}{\pagenumbering{Roman}}
\newcommand*{\makelot}{}
\newcommand*{\makelof}{}
\newcommand*{\makelos}{}
\newcommand*{\begincmd}{
\onehalfspacing
\makeacknowledgements\makededication\tableofcontents\clearpage
\makelot\clearpage\makelof\clearpage\makelos
\clearpage\mainmatter
\renewcommand{\baselinestretch}{1.5}
}

%define required vars
\def\@deptpref{Department of}
\def\departmentprefix#1{\gdef\@deptpref{#1}}
\def\classyear#1{\gdef\@classyear{#1}}
\def\dept#1{\gdef\@dept{#1}}
\def\submitdate#1{\gdef\@submitdate{#1}}
\long\def\acknowledgements#1{\gdef\@acknowledgements{#1}}
\def\course#1{\gdef\@course{#1}}

%define optional vars
\def\dedication#1{\gdef\@dedication{#1}}
\def\extranotes#1{\gdef\@extranotes{#1}}
\extranotes{}

%title page
\newcommand{\maketitlepage}{{
\thispagestyle{empty}
\sc
\vspace*{0in}
\begin{center}
\LARGE \@title
\end{center}
\vspace{.1in}
\begin{center}
\large \@author,~\@classyear
\end{center}
\vspace{.3in}
\begin{center}
Submitted to the\\
\@deptpref~\@dept\\
Princeton University \\
in partial fulfillment of the requirements of\\
\vspace{.3in}
\if@progress
Progress Report\\
\else
Final Report\\
\fi
\vspace{.3in}
\@submitdate
\end{center}

\vfill

% \begin{flushright}
\hangindent=11.5cm\hangafter=0
\@course\\
\ztotpages \,  pages\\
\if@filecopy
File Copy
\fi
\fi
\fi
\ifx\@extranotes\@empty
\relax
\else
\\ \@extranotes\\
\fi
% \end{flushright}

\clearpage
}}

\thispagestyle{empty}
\vspace*{0in}
\begin{center}
\end{center}

This  \if@progress progress report
\else
thesis
\fi
represents my own work in accordance with University regulations.

%\vspace{1in}
%\@author \hspace{0.5cm} \makebox[2in]{\hrulefill}

\clearpage}
\newcommand*{\makeabstract}{
\newpage
\begin{center}
\Large \textbf{Abstract}
\end{center}
\@abstract
\clearpage
}

%acknowledgements
\def\makeacknowledgements{
\ifx\@acknowledgements\undefined
\else
\begin{center}
\Large \textbf{Acknowledgements}
\end{center}
\@acknowledgements
\clearpage
\fi
}

%dedication page
\def\makededication{
\ifx\@dedication\undefined
\else
\vspace*{1.5in}
\begin{flushright}
\@dedication
\end{flushright}
\clearpage
\fi
}

%various optional lists
\DeclareOption{myorder}{
\renewcommand*{\begincmd}{
\onehalfspacing
}}
\DeclareOption{lot}{\renewcommand*{\makelot}{
\DeclareOption{lof}{\renewcommand*{\makelof}{
\DeclareOption{los}{
\renewcommand*{\makelos}{
\newcommand*\l@symbol{\@dottedtocline{1}{1.5em}{3.5em}}
\chapter*{List of Symbols\@mkboth {LIST OF SYMBOLS}{LIST OF SYMBOLS}}
\@starttoc{los}
}
}
\addtocontents{los}{\protect \contentsline {symbol}{\protect \numberline {#1}{\ignorespaces #2}}{\thepage}}
}

%inherits report class and associated options
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions
%% Not necessary to specify the point size - we inherit it from above
\setlength{\oddsidemargin}{.5in}   %{.4375in}
\setlength{\evensidemargin}{.5in} %{.4375in}
\setlength{\topmargin}{-.5in}  %{-.5625in}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6in}
\long\def\abstract#1{\gdef\@abstract{#1}}
\AtBeginDocument{\begincmd}
\endinput
%%
%% End of file puthesis.cls'.


The problem is that when I try and us a simple thing like \usepackage{color} I run into the issue that:

! Undefined control sequence.
\set@color ...\@pdfcolorstack push{\current@color
}\aftergroup \reset@color
l.55 \begin{document}


However when I do the following with just the article.cls file I have no issue:

\documentclass{article}

\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
language=c,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fullflexible,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}

\begin{document}

\begin{lstlisting}

#include <stdio.h>

int main()
{
// A line comment
printf("A really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, REALLY long line. && & \n");
return 0;
}

\end{lstlisting}

\end{document}


So is there something in the puseniorthesis.cls I need to add so that color package works properly?

EDIT: The exact code that I am using that causes the error is here;

\documentclass[lof,lot,los,12pt,advisercopy]{puseniorthesis}
%options to class:
% lof - generate list of figures
% lot - generate list of tables
% Xpt - font size
% filecopy - note that this is 'File Copy' on title page
% advisercopy - note that this is 'Adviser Copy' on title page
% readercopy - note that this is 'Reader Copy' on title page
% progress - change title page to say 'Progress Report' instead of 'Final Report'

\usepackage{graphicx} %need for \includegraphics
\usepackage{amsmath}

\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
language=c,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fullflexible,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}

%required inputs:
\author{My Name}
\classyear{13}
\title{Thesis Title}
\dept{Mechanical and Aerospace Engineering}
\submitdate{May 2, 2013}
\course{MAE something}
\abstract{\input abstract} %read from file abstract.tex

%optional inputs (any of these can be omitted)
\extranotes{These are a few lines of optional notes}
\dedication{To myself.}
\acknowledgements{Thank you very much.}

\numberwithin{equation}{section}

\begin{document}

%\include{ch1} %read from file ch1.tex
%\include{ch2} %read from file ch2.tex

%\appendix

%\include{app1}  %read from file app1.tex

\end{document}

-
As it is now, your code is not a minimal working example (MWE), if the puseniorthesis class is used instead of the article class. I get a lot of errors unrelated to your issue. Title, author, reader etc. must be defined to get rid of those errors. Before we can study your issue with the color package in an efficient and timely manner, you must modify your code accordingly. –  Jubobs Mar 17 '13 at 20:07
I have added the exact code that I am using that causes the exact problem. –  eWizardII Mar 18 '13 at 1:08
When color is loaded it's apparently expecting a \current@color to be defined. Something about the class results in that not being defined (I have no idea what). Try putting \RequirePackage{color} before the \documentclass command (and remove the \usepackage{color} command from the preamble. –  Scott H. Mar 18 '13 at 2:04

The class uses \AtBeginDocument for typesetting. But this is not allowed, from LaTeX Companion, 2nd ed., p. 884:

Note, however, that code in the \AtBeginDocument hook is part of the preamble. Thus, restrictions limit what can be put there; in particular, no typesetting can be done.

In this case, package color has not yet finished its setup, defining \defaultcolor. The typesetting code calls \normalcolor that assigns \current@color to the yet undefined \defaultcolor.

Workaround:

\let\savedbegincmd\begincmd
\let\begincmd\relax
\begin{document}
\savedbegincmd


The class can be fixed by changing the line

\AtBeginDocument{\begincmd}


to

\RequirePackage{etoolbox}
\AfterEndPreamble{\begincmd}


that uses a more appropriate hook from package etoolbox.

-
Awesome thanks a lot - the fix solved the problem. –  eWizardII Mar 18 '13 at 4:10