%% This package formats problem sets
%%
%% by Nils Barth
%% nbarth@fas.harvard.edu
%%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{homework}[1999/02/05 Problem Sets]
\RequirePackage{fancyhdr,lastpage}

% --------------------------------------------------------------------
%%% Options
% Draft -- include source specials in DVI
\DeclareOption{draft}{%
    \PassOptionsToClass{\CurrentOption}{amsart}%
    \AtEndOfClass{\RequirePackage{srcltx}}}

% Midterm
\DeclareOption{midterm}{\AtEndOfClass{
\title{\upcoursename\ Midterm}%
\renewcommand{\theproblemset}{M}
\lhead{\small{\textsc{\thecoursename\ Midterm}}}
}}

% Final Exam -- DON'T CONFUSE with final (vs. draft)
\DeclareOption{finalexam}{\AtEndOfClass{
\title{\upcoursename\ Final}%
\renewcommand{\theproblemset}{F}
\lhead{\small{\textsc{\thecoursename\ Final}}}
}}

% Solution Set
\DeclareOption{solutionset}{\AtEndOfClass{
\RequirePackage{fullpage} % Standard -- Save paper
\title{\upcoursename\\ Solution Set \theproblemset}
\lhead{\small{\textsc{\thecoursename\ Solution Set \theproblemset}}}
}}

% List type: enumerate vs. description
\def\ListType{}

\DeclareOption{enum}{
\def\ListType{
\AtBeginDocument{\begin{enumerate}}%
\AtEndDocument{\end{enumerate}}}}

\DeclareOption{desc}{
\def\ListType{
\renewenvironment{enumerate}
{\begin{list}{\stepcounter{enumi}(\theenumi)}{}}
{\end{list}\setcounter{enumi}{0}}
\def\theenumi{\alph{enumi}}
\AtBeginDocument{\begin{description}}%
\AtEndDocument{\end{description}}}}
% --------------------------------------------------------------------

%%% Pass options to amsart, and load amsart
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{amsart}}
\ProcessOptions
\LoadClass[oneside]{amsart}

%%% Title etc.
\newcounter{problemset}
\newcommand{\problemset}[1]{\setcounter{problemset}{#1}}
\newcommand{\coursename}[1]{\def\thecoursename{#1}%
\let\upcoursename\thecoursename
\uppercasenonmath{\upcoursename}}
%% The upcoursename convolutions are because \uppercase has
%% trouble with \def stuff.
\problemset{-1}\coursename{Math 201}
\date{\today}
\author[N.~R.~Barth]{Nils~R. Barth}
\title{\upcoursename\\ Problem Set \theproblemset}

%%% My revised \maketitle
\renewcommand{\maketitle}{%
\uppercasenonmath\@title%
\begin{center}
{\textbf \@title}\medskip

{\textsc \authors}

\@date
\end{center}
\bigskip}

\AtBeginDocument{\maketitle}

\ListType   % Process the list type

%% Number equations within problem set
\numberwithin{equation}{problemset}

%%%% Header
\AtEndOfClass{\pagestyle{fancy}}
\lhead{\small{\textsc{\thecoursename\ Problem Set \theproblemset}}}
\chead{\authors}
\rhead{\small{\thepage/\pageref{LastPage}}}
\lfoot{}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
