%
%    *** mathtest.sty ***
%
%         Version 1.0
%
% For typesetting tests!!!!!!!
%

% The Identification Part

\ProvidesPackage{mathtest}[2001/05/12]
\NeedsTeXFormat{LaTeX2e}[1995/12/01]

% Formatting

%\topmargin 0pt
\topmargin -0.5in
\advance \topmargin by-\headheight
\advance \topmargin by-\headsep
\oddsidemargin 0pt
\evensidemargin 0pt
\marginparwidth 0.5in
\textwidth 6.5in
\parskip 0in
\parindent 0in
\linespread{1.2}

% Some Exam Commands
\begin{comment}
\newcommand{\examtitle}[3]{
  \begin{center}
    {\LARGE #1 \\ \vspace{0.1in}}
    {\large \@addanswer{#2} \\ \vspace{0.06in}
     \@titleordate{#3} \vspace{0.32in}}
  \end{center}
}
\end{comment}
\newcommand{\examtitle}[3]{
  \begin{center}
    {  \large  #1 \quad \LARGE #2 \quad \large \@titleordate{#3}
     \vspace{0.32in}\\ \LARGE \@addanswer }
  \end{center}
}


\newcommand{\studentinfo}{
  {\bf NAME (please print):} \hrulefill{} \\
  %{\bf Your University ID Number:} \hrulefill{} \\ % GBG 2015. Eliminate privacy issues.
}
\newcommand{\instructions}[1]{#1}
\newcommand{\content}[3]{
#1 \\
#2
}
\newcommand{\anotherpage}{\newpage}
% Below is the command for entering problems
% #1 is the number of points.
% #2 is for the questions.
% #3 is for the answer sheet for the students to fill in.
% #4 is for the solutions to the questions;  #1 will be followed by #3.
% #5 is the chapter material required to solve the problem GBG 2015
\newcommand{\problem}[5]{
  \stepcounter{problem}
  \stepcounter{consecutive}

\def\pointval{#1}
\def\chapterREF{#5}% GBG 2015

\ifx\@empty\pointval
  \addtocontents{pro}{\@chosencounter & \quad & \\ \protect\hline}
{\bf \@chosencounter.}
\else
  \addtocontents{pro}{\@chosencounter & \pointval \quad & \\ \protect\hline}
  \addtocounter{total}{\pointval}
{\bf \@chosencounter. (\chapterREF{}: \pointval \, points)}
\fi
  \content{#2}{#3}{#4}
}

% subproblem is same as problem, but use different counter and don't add points to total
\newcommand{\subproblem}[4]{
  \stepcounter{problem}
  \stepcounter{consecutive}

\def\pointval{#1}

\ifx\@empty\pointval
{\bf \@chosencounter.}
\else
{\bf \@chosencounter. (\pointval \, points)}
\fi
  \content{#2}{#3}{#4}
}


% Some Useful Macros

\newcommand{\pos}{\vspace{\@stdvspace}}
\newcommand{\nos}{\vspace{-\@stdvspace}}

\begin{comment}
\newenvironment{abcs}{
  \begin{list}
  {(\alph{subpart}) \hfill}
  {
    \usecounter{subpart}
    \setlength{\itemsep}{0in}          % We control the vertical!!
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\parsep}{\@stdvspace}
    \setlength{\leftmargin}{0.285in}   % We control the horizontal!!
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}
    \setlength{\labelsep}{0in}
    \setlength{\labelwidth}{\leftmargin}
    \advance \labelwidth by-\labelsep
  }
}{
  \end{list}
}\end{comment}

% I didn't like the old version of environment abcs because references returned numbers instead of letters.
% Here's another try.
\usepackage{enumerate}
\newenvironment{abcs}{\begin{enumerate}[\upshape (a)]}%
{\end{enumerate}}

% Spacing System

\newcommand{\@stdvspace}{0.15in}   % Determines parskip in the exam body!
\newcommand{\setstdvspace}[1]{\renewcommand{\@stdvspace}{#1}}

% Heading System

\newcommand{\@stdheading}{Part}    % Determines the style of headings!
\newcommand{\@currentheading}{\@stdheading}
\newcommand{\stackheading}[1]{\renewcommand{\@currentheading}{#1}}

% Default Command Definitions

\newcommand{\@partheading}{}                % onepart (vs. multipart)
\newcommand{\@tableheading}{}
\newcommand{\anotherpart}{}

\newcommand{\@newpage}{\newpage}            % standard (vs. answers)
\newcommand{\@titleordate}[1]{#1}
\newcommand{\@addanswer}{}
\newcommand{\finishfirstpage}{
  \vspace*{-10mm}
  {\large \@starttoc{pro}}
  \problemsstart
}
\newcommand{\answer}{\vspace{\@stdvspace} \hfill ANSWER: \rule{2.0in}{0.15mm}}

\newcommand{\@chosencounter}{{\bf Problem} \theproblem}   % nonconsecutive (vs. consecutive). Added "Problem" GBG 2018.

\newcommand{\@chosenstyle}[1]{\Alph{#1}}    % alphanumeric (vs. roman)

\newcommand{\@extrainstructions}{}
\newcommand{\additionalinstructions}[1]{
  \renewcommand{\@extrainstructions}{#1}
}

% The Declaration of Options

\DeclareOption{letter}{\textheight 8.9in}
\DeclareOption{mytest}{\textheight 10in}
\DeclareOption{legal}{
  \textheight 11.5in
  \paperheight 14in
}
\DeclareOption{landscape}
{
\paperheight 8.5in
\paperwidth 11in
\textheight 6.5in
\textwidth  9in
}

\DeclareOption{onepart}{}
\DeclareOption{multipart}{
  \renewcommand{\@partheading}{
   {\bf \@currentheading\ \@chosenstyle{part}}
   \vspace{-\@stdvspace} \par
  }
  \renewcommand{\@tableheading}{
    \addtocontents{pro}{\protect\multicolumn{3}{||c||}
    {\@currentheading\ \@chosenstyle{part}} \\}
    \addtocontents{pro}{\protect\hline \protect\hline}
    \renewcommand{\@currentheading}{\@stdheading}   % Used once and gone!
  }
  \renewcommand{\anotherpart}{
    \@partend
    \addtocontents{pro}{\hskip 1em}
    \@partstart
  }
}
\DeclareOption{standard}{}
\DeclareOption{answersheet}{}
\DeclareOption{answers}{
  \renewcommand{\@newpage}{}
  \renewcommand{\@titleordate}[1]{#1}
  \renewcommand{\studentinfo}{}
  \renewcommand{\@addanswer}{ANSWERS}
  \renewcommand{\finishfirstpage}{\problemsstart}
  \renewcommand{\answer}{}
  \renewcommand{\instructions}[1]{}
  \renewcommand{\vfill}{}
  % The following are used to insert additional content
  \renewcommand{\content}[3]{#1

\textbf{Answer:}

#3}
  \renewcommand{\anotherpage}{}
}
\DeclareOption{questions}{
  \renewcommand{\@newpage}{}
  \renewcommand{\@titleordate}[1]{#1}
  \renewcommand{\studentinfo}{}
  \renewcommand{\@addanswer}{}
  \renewcommand{\finishfirstpage}{\problemsstart}
  \renewcommand{\answer}{}
  \renewcommand{\instructions}[1]{}
  \renewcommand{\vfill}{}
  % The following are used to insert additional content
  \renewcommand{\content}[3]{#1}
}

\DeclareOption{nonconsecutive}{}
\DeclareOption{consecutive}{
  \renewcommand{\@chosencounter}{\theconsecutive}
}

\DeclareOption{alphanumeric}{}
\DeclareOption{roman}{
  \renewcommand{\@chosenstyle}[1]{\Roman{#1}}
}

% The Execution of Options

\ExecuteOptions{letter,onepart,standard,nonconsecutive,alphanumeric}
\ProcessOptions

% Definition of Counters

\newcounter{total}[part]
\newcounter{problem}[part]
\newcounter{consecutive}
\newcounter{subpart}

% The Following Commands Produce the Table as well as the Problems

\newcommand{\problemsstart}{
  \parskip \@stdvspace
  \addtocontents{pro}{\protect\begin{center}}
  \@partstart
}
\newcommand{\@partstart}{
  % This sets up the beginning of a part
  \@newpage
  \stepcounter{part}
  \@partheading
  % This starts the form of the table
  \addtocontents{pro}{\protect\tabular{||r|r|c||}}
  \addtocontents{pro}{\protect\multicolumn {3}{c}{\mbox{}} \\}
  \addtocontents{pro}{\protect\hline \protect\hline}
  \@tableheading
  \addtocontents{pro}{QUESTION & VALUE & SCORE \\}
  \addtocontents{pro}{\protect\hline \protect\hline}
}
\newcommand{\@partend}{
  % This finishes the form of the table
  \addtocontents{pro}{\protect\hline}
  \addtocontents{pro}{TOTAL & \thetotal\ \quad & \\ \protect\hline}
  \addtocontents{pro}{\protect\hline}
  \addtocontents{pro}{\protect\endtabular}
}
\newcommand{\problemsdone}{
  \@partend
  \addtocontents{pro}{\protect\end{center}\@extrainstructions}
  \marginpar{\mbox{}}  % See explanation below!
}

% The \mbox command is used to produce an invisible margin note
% on the last page.  This fixes a serious problem which can occur
% if a user inserts \newpage immediately before \problemsdone.
% In that case, however, a blank page will be produced.
