%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-*-TeX-*-%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% IDENTIFICATION & PACKAGE LOADING
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{course}

\RequirePackage{ifthen}
\RequirePackage{amssymb}
\RequirePackage{xspace}
\RequirePackage{graphics}
\RequirePackage[pdflatex]{graphicx}
\RequirePackage[
    colorlinks, bookmarksopen, pdfpagemode=UseOutlines,
    pdfstartview=FitBH, linkcolor=blue, citecolor=blue,
    urlcolor=blue, backref, pagebackref]{hyperref}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% TEXT & MATHEMATICS
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Text --- Abbreviations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\apriori}{\textit{a~priori}\xspace~}
\newcommand{\aposter}{\textit{a~posteriori}\xspace~}
\newcommand{\etal}{\textit{et~al}.\@\xspace}
\newcommand{\ie}{\textit{i.e.}\xspace,\xspace}
\newcommand{\Ie}{\textit{I.e.}\xspace,\xspace}
\newcommand{\eg}{\textit{e.g.}\xspace,\xspace}
\newcommand{\Eg}{\textit{E.g.}\xspace,\xspace}
\newcommand{\etc}{\textit{etc}.\@\xspace}
\newcommand{\cf}{\textit{cf.}\xspace,\xspace}
\newcommand{\Cf}{\textit{Cf.}\xspace,\xspace}
\newcommand{\viz}{\textit{viz.}\xspace,\xspace}
\newcommand{\Viz}{\textit{Viz.}\xspace,\xspace}

%%% Math --- General %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\paren}[1]{\left(#1\right)}
\newcommand{\ang}[1]{\left\langle#1\right\rangle}

\newcommand{\suchthat}{\mid}
\newcommand{\eqdef}{\mathbin{::=}}
\renewcommand{\bar}[1]{\overline{#1}}

%%% Math --- Logic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\And}{\wedge}
\newcommand{\conj}{\And}
\newcommand{\smand}{\And}
\newcommand{\AND}{\bigwedge}
\newcommand{\Land}{\AND}
\newcommand{\lgand}{\AND}

\newcommand{\Or}{\vee}
\newcommand{\disj}{\Or}
\newcommand{\smor}{\Or}
\newcommand{\OR}{\bigvee}
\newcommand{\Lor}{\OR} 
\newcommand{\lgor}{\OR}

\renewcommand{\implies}{\longrightarrow}
\renewcommand{\iff}{\longleftrightarrow}

%%% Math --- Set theory %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\card}[1]{\left|#1\right|}

\newcommand{\union}{\cup}
\newcommand{\lgunion}{\bigcup}
\newcommand{\intersect}{\cap}
\newcommand{\lgintersect}{\bigcap}
\newcommand{\cross}{\times}
\newcommand{\compose}{\circ}
\newcommand{\composition}{\circ} 
\newcommand{\power}{\mathcal{P}}

%%% Math --- Famous sets %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\naturals}{\mathbb{N}}
\newcommand{\integers}{\mathbb{Z}}
\newcommand{\rationals}{\mathbb{Q}}
\newcommand{\reals}{\mathbb{R}}
\newcommand{\complexes}{\mathbb{C}}

%%% Math --- Arithmetic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil#1\right\rceil}

\newcommand{\divides}{|}
\DeclareMathOperator*{\lcm}{lcm}

%%% Math --- Probability %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\pr}[1]{\textup{Pr}\left\{#1\right\}}
\newcommand{\prob}[1]{\pr{#1}}
\newcommand{\prsub}[2]{\textup{Pr}_{#2}\left\{#1\right\}}
\newcommand{\prcond}[2]{\textup{Pr}\left\{#1\mid#2\right\}}

\newcommand{\Ex}{\mathop{\textup{E}}\nolimits}
\newcommand{\Var}{\mathop{\textup{Var}}\nolimits}
\newcommand{\Cov}{\mathop{\textup{Cov}}\nolimits}
\newcommand{\expect}[1]{\Ex\left[#1\right]}
\newcommand{\expectsq}[1]{{\Ex}^2\left[#1\right]}
\newcommand{\variance}[1]{\Var\left[#1\right]}
\newcommand{\varsq}[1]{{\Var}^2\left[#1\right]}
\newcommand{\covar}[1]{\Cov\left[#1\right]}

%%% Math --- Theorems & Proofs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{falsethm}[theorem]{False theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{falseclm}[theorem]{False claim}
\newtheorem{rul}[theorem]{Rule}

\newtheorem*{theorem*}{Theorem}
\newtheorem*{falsethm*}{False theorem}
\newtheorem*{lemma*}{Lemma}
\newtheorem*{proposition*}{Proposition}
\newtheorem*{corollary*}{Corollary}
\newtheorem*{claim*}{Claim}
\newtheorem*{falseclm*}{False claim}
\newtheorem*{rul*}{Rule}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{axiom}[theorem]{Axiom}

\newtheorem{problem*}{Problem}
\newtheorem*{definition*}{Definition}
\newtheorem*{fact*}{Fact}
\newtheorem*{axiom*}{Axiom}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{example}[theorem]{Example}
\newtheorem{xample}[theorem]{Example}

\newtheorem*{remark*}{Remark}
\newtheorem*{example*}{Example}
\newtheorem*{xample*}{Example}

\newenvironment{falseproof}
{\begin{proof}[False proof]}
{\end{proof}}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% FORMATTING
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Page formatting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\parindent}{0in}                     
\setlength{\parskip}{\medskipamount}            
\hoffset        = -1.0 in
\voffset        = -1.0 in
\paperheight    = 11.0 in
\paperwidth     =  8.5 in
\topmargin      = 0.75 in
\headheight     = \baselineskip
\headsep        = \baselineskip
\footskip       = 1.00 in
\textheight     = \paperheight
\addtolength{\textheight}{-\topmargin}
\addtolength{\textheight}{-\headheight}
\addtolength{\textheight}{-\headsep}
\addtolength{\textheight}{-\footskip}
\textwidth      = \paperwidth
\oddsidemargin  = 1.0 in
\evensidemargin = 1.0 in
\addtolength{\textwidth}{-\oddsidemargin}
\addtolength{\textwidth}{-\evensidemargin}
\linewidth      = \textwidth

\newcommand{\printlayout}{%
  \typeout{----------------------- LaTeX Page Layout Parameters}
  \typeout{\string\paperwidth\space\space\the\paperwidth}
  \typeout{\string\paperheight\space\the\paperheight}
  \typeout{\string\textwidth\space\space\the\textwidth}
  \typeout{\string\textheight\space\the\textheight}
  \typeout{\string\oddsidemargin\space\space\the\oddsidemargin}
  \typeout{\string\evensidemargin\space\the\evensidemargin}
  \typeout{\string\topmargin\space\space\the\topmargin}
  \typeout{\string\headheight\space\the\headheight}
  \typeout{\string\headsep\space\the\headsep}
  \typeout{\string\footskip\space\space\space\the\footskip}
  \typeout{\string\marginparwidth\space\the\marginparwidth}
  \typeout{\string\marginparsep\space\space\space\the\marginparsep}
  \typeout{\string\hoffset\space\the\hoffset}
  \typeout{\string\voffset\space\the\voffset}
  \typeout{(1in=72.27pt, 1cm=28.45pt)}
  \typeout{-----------------------------------------}%
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Mini pages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Generates a _framed_ minipage with its width as an optional argument.
% If the width is not specified, \linewidth is used. 
%
% Usage  :  \begin{fminibox}{width} ... \end{fminibox}
% Example:  \begin{fminibox}{3in}  blah, blah... \end{fminibox}
%
\newsavebox{\fminibox}
\newlength{\fminilength}
\newenvironment{fminipage}[1][\linewidth]%
{% begin fminipage
  \setlength{\fminilength}{#1}
  \addtolength{\fminilength}{-2\fboxsep}
  \addtolength{\fminilength}{-2\fboxrule}
  \begin{lrbox}{\fminibox}\begin{minipage}{\fminilength}}%
{% end fminipage
  \end{minipage}\end{lrbox}\noindent\fbox{\usebox{\fminibox}}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Formatting the top matter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
% Formats the title, given the paper type, paper num, paper title, and
% release date.  
%	The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \formattitle[revision info]{type}{number}{title}{date out}
% Example: \formattitle[v1.1]{Handout}{23}{Tutorial 13}{Fri, Nov 13} 
%
\newcommand{\formattitle}[5][\stamp]{%
  \mbox{}\vspace*{-\headheight}\mbox{}\vspace*{-\headsep}\mbox{}\newline
  \noindent
  \parbox{\textwidth}{
    \courseinstitute             \hfill       #2~#3 \newline%
    \coursenumber : \coursetitle \hfill          #5 \newline%
    \courseprofessors            \hfill          #1 \newline%
    \mbox{}\hrulefill\mbox{}}
  \mbox{}                                           \newline%
  \bigskip
  \begin{center}       {\Large\textbf{#4}}       \end{center}}

\newcommand{\stamp}{{\scriptsize{revised \today, \the\time\ minutes}}}

% Formats the top matter (title+headers), given the paper type,
% paper num, paper title, and release date. 
% 	The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed. 
%
% Usage  : \formatpages[revision info]{type}{number}{title}{date out}
% Example: \formatpages[v1.1]{Handout}{33}{Tutorial 13}{Fri, Nov 13}
%
\newcommand{\formatpages}[5][\stamp]{%
  \thispagestyle{empty}
  \markboth{#2~#3: #4}{#2~#3: #4}
  \pagestyle{myheadings}
  \formattitle[#1]{#2}{#3}{#4}{#5}}

% Formats the top matter (title+headers) appropriately for an exam
% paper, given the paper type, paper num, paper title, and release
% date.  
% 	The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed. 
%
% Usage  : \formatexampages[rev info]{type}{number}{title}{date out}
% Example: \formatexampages[v1.1]{Handout}{33}{Quiz 13}{Fri, Nov 13}
%
% 	The command \exampreamble is used, meant to be renewed by the
% user: it contains the introductory coments for the exam. The current
% definition is an informative warning. Here is an example of how the
% command is meant to be renewed: 
%
%\renewcommand{\exampreamble}{
%  \textbf{Circle the name of your Tutorial Instructor}:
%  \begin{center}
%  \renewcommand{\arraystretch}{1.5}
%  \begin{tabular}{llll}
%  Yu-Han    & Christos & Nikos & Ashish \\
%  Thien-Loc & Jaime    & Tina  & Tong   
%  \end{tabular}
%  \end{center}
%  \medskip
%  \begin{itemize}
%  \item 
%  This quiz is \textbf{closed book}.  There is an Appendix giving the 
%  definitions of some standard operations on relations.
%  \item 
%  There are four (4) problems totaling 100 points.  Problems are
%  labeled with their point values.
%  \item 
%  Put your name on the top of {\bf every} page -- \emph{these
%  pages may be separated for grading}.
%  \item 
%  Write your solutions in the space provided.  If you need more
%  space, write on the back of the sheet containing the problem.
%  Please keep your entire answer to a problem on that problem's page.
%  \item 
%  You may assume any of the results presented in class or in the
%  lecture notes.
%  \item  
%  \textbf{Be neat and write legibly}.  You will be graded not only on
%  the correctness of your answer, but also on the clarity with which
%  you express it.
%  \item 
%  GOOD LUCK!
%  \end{itemize}}
%
\newcommand{\formatexampages}[5][\stamp]{%
  \thispagestyle{empty}
  \markboth{\hspace{2em}Your name:\hrulefill{}\hfill#2~#3: #4}
	   {#2~#3: #4\hfill{}Your name:\hrulefill\hspace{2em}}
  \pagestyle{myheadings}
  \formattitle[#1]{#2}{#3}{#4}{#5}
  \bigskip\bigskip\textbf{Your name:}\hrulefill\par\bigskip
    \exampreamble
  \vfill
  \bigskip\hrule\smallskip
  \centerline{\textbf{DO NOT WRITE BELOW THIS LINE}}
  \smallskip\hrule\bigskip
    \examtable
  \clearpage}

\newcommand{\exampreamble}{
  \vfill\noindent
  You have to renew command  \texttt{exampreamble} in the preamble of
  your paper to have something printed in this space! For example, 
  \begin{center}
  \texttt{%
    $\backslash$renewcommand$\{\backslash$exampreamble$\}$
      $\{\backslash$vfill GOOD LUCK FOLKS! $\backslash$vfill$\}$}
  \end{center}
  See also \texttt{course.sty} for a longer example.%
  \message{^^JExam preamble is *INCORRECT*.^^J^^J}
  \vfill}
\newcommand{\examtable}{
  \vfill
  \begin{center}
  This is where the grades table is supposed to be printed. Compile
  the paper once more to get it right. See \texttt{course.sty} for
  details.
  \end{center}%
  \message{^^JGrades table was *NOT PRINTED*.^^J^^J}
  \vfill}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Problems %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newlength{\standardproblemsep}
\newlength{\standardproblempartsep}
\newlength{\problemsep}
\newlength{\problempartsep}
\setlength{\standardproblemsep}{1cm}
\setlength{\standardproblempartsep}{1ex}
\setlength{\problemsep}{\standardproblemsep}
\setlength{\problempartsep}{\standardproblempartsep}

\theoremstyle{definition}
\newtheorem{problemthm}{Problem}
\newcommand{\countersunderproblem}{
  \renewcommand{\thetheorem}{\theproblemthm.\arabic{theorem}}}

%%% Simple problems %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{simpleproblem}
  {\vspace{\problemsep}
   \begin{problemthm}}
  {\end{problemthm}}

%%% Exam problems %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In any of the exam papers (quiz, final, practicequiz), use
% environment ``examproblem'' to define a problem along with its grade
% points; for example:
%      \begin{examproblem}{25}
%      Prove that you are a nice guy.
%      \end{examproblem}
% prints a problem that counts for 25 points. This causes the string
% ``(25 points)'' to appear next to the problem label.  
%   In addition, the points from all examproblems are collected and
% the grading table for the front page of the exam is formatted: just
% define each problem as an examproblem along with its points, then
% compile the paper twice; the second time the correct grades table
% will appear on the front page of the exam.
%
\newcounter{examtotal}
\newcommand{\examtablecontents}{}

\newenvironment{examproblem}[1]
  {% Formatting : 
   \vspace{\problemsep}
   \begin{problemthm}[#1 point\ifthenelse{1=#1}{}{s}]
   % Updating .aux file :
   \examtableupdate{#1}
   \examtotalupdate{#1}}
  {\end{problemthm}}

\newcommand{\examtableupdate}[1]{
   \immediate\unexpandedwrite\@auxout{%
     \g@addto@macro\examtablecontents{%
       \addtocounter{problemthm}{1}\theproblemthm&#1&&\\\hline}}}
\newcommand{\examtotalupdate}[1]{
   \immediate\unexpandedwrite\@auxout{%
     \addtocounter{examtotal}{#1}}}
\newcommand{\examtableupdatefinish}{%
     \unexpandedwrite\@auxout{%
        \gdef\examtable{
          \begin{center}
          \renewcommand{\arraystretch}{1.5}
          \begin{tabular}{|c|c|c|c|}           \hline
          Problem & Points & Grade  & Grader \\\hline\hline
          \examtablecontents                   \hline
          Total   & \theexamtotal & &        \\\hline
          \end{tabular}
          \end{center}
          \setcounter{problemthm}{0}}}}
\AtEndDocument{\examtableupdatefinish}

%%% Problems & problem parts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{problem}[1][0]
  {\begin{simpleproblem}}
  {\end{simpleproblem}}
\newcommand{\useexamproblems}{
  \renewenvironment{problem}[1][0]
    {\begin{examproblem}{##1}}
    {\end{examproblem}}}
\newcommand{\usesimpleproblems}{
  \renewenvironment{problem}[1][0]
    {\begin{simpleproblem}}
    {\end{simpleproblem}}}

\newcounter{problempart}
\renewcommand{\theproblempart}{\alph{problempart}}
\newenvironment{problemparts}
  {\begin{list}
         {\textbf{(\alph{problempart})}}
         {\usecounter{problempart}
          \settowidth{\labelwidth}{\textbf{(m)}}
          \setlength{\labelsep}{1ex}
          \setlength{\leftmargin}{0pt}
          \setlength{\itemindent}{\labelwidth}
            \addtolength{\itemindent}{\labelsep}
          \setlength{\rightmargin}{0pt}
          \setlength{\listparindent}{\itemindent}
          \setlength{\itemsep}{\problempartsep}}}
  {\end{list}}
\newcommand{\problempart}{\item}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Solutions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifshowsolutions
\showsolutionsfalse

\theoremstyle{definition}
\newtheorem*{solution*}{Solution}
\newcommand{\solution}[1]{
  \ifshowsolutions
  \begin{solution*}
  #1
  \hfill$\blacksquare$
  \end{solution*}
  \fi}

\newcommand{\askaboutsolutions}{
\typein[\answer]{Include solutions? (y/n) }
\def\yes{y}
\ifx\answer\yes
  \typeout{}
  \typeout{Solutions *INCLUDED*.} 
  \showsolutionstrue
\else
  \typeout{}
  \typeout{Solutions *NOT INCLUDED*.} 
  \showsolutionsfalse
\fi}
\newcommand{\decideaboutsolutions}{
  \askaboutsolutions
  \countersunderproblem
  \ifshowsolutions
    \setlength{\problemsep}{2\standardproblemsep}
    \setlength{\problempartsep}{\standardproblemsep}
  \else
    \setlength{\problemsep}{\standardproblemsep}
    \setlength{\problempartsep}{\standardproblempartsep}
  \fi
}

\newcommand{\showsolutions}{
  \renewcommand{\askaboutsolutions}{\showsolutionstrue}}
\newcommand{\hidesolutions}{
  \renewcommand{\askaboutsolutions}{\showsolutionsfalse}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Starting a paper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Starts any paper (that has been defined in course.dat), given the
% paper's id and title.
% 	The optional argument allows for revision info: if used, the 
% specified revision info is printed; if not, the \stamp info is
% printed. 
%
% Usage  : \paper[revision info]{paper id}{paper title}
% Example: Assuming the definition 
%		\newpaper{ln1}{Lecture Notes}{1}{Sep 5, 2001}{}
%	   in course.dat, the command
%		\paper[v1.1]{ln1}{Proofs}
%	   starts v1.1 of the first lecture notes, titled ``Proofs''. 
%
% [ The command is the Same as \formatpages, but some of the
% information (paper type, paper num, release date; but not paper
% title) is communicated via the paper id. ]  
%
\newcommand{\paper}[3][\stamp]{%
  \formatpages[#1]
    {\typeofpaper{#2}}
    {\numofpaper{#2}}
    {#3}
    {\releasedateofpaper{#2}}}

% Starts an exam paper (that has been defined in course.dat), given the
% paper's id and title.
% 	The optional argument allows for revision info: if used, the 
% specified revision info is printed; if not, the \stamp info is
% printed. 
%
% Usage  : \exam[revision info]{paper id}{paper title}
% Example: Assuming the definition 
%		\newpaper{ex1}{Handout}{7}{Sep 31, 2001}{}
%	   in course.dat, the command
%		\exampaper[v1.1]{ex1}{Surprise Exam 1}
%	   starts v1.1 of the first surprise exam. 
%
% [ The command is the Same as \formatexampages, but some of the
% information (paper type, paper num, release date; but not paper
% title) is communicated via the paper id. ]  
%
\newcommand{\exampaper}[3][\stamp]{%
  \formatexampages[#1]
    {\typeofpaper{#2}}
    {\numofpaper{#2}}
    {#3}
    {\releasedateofpaper{#2}}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Starting lecture notes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Starts lecture notes, given the lecture notes number and title. The
% corresponding paper must have been defined in course.dat, with id:
% 	ln<number>
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \lecturenotes[revision info]{number}{title}
% Example: \lecturenotes[v1.1]{1}{Proofs}
%
\newcommand{\lecturenotes}[3][\stamp]{\paper[#1]{ln#2}{#3}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Starting a problem list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Starts a Practice Problems Set, given its number. Asks whether
% solutions should be included. If the answer is yes, the
% corresponding solutions paper is started. (Use \showsolutions or
% \hidesolutions to preselect the answer before the query ---and skip
% the query). The corresponding papers must have been defined in
% course.dat, with ids:  
%	pp<number> 	(for the problem statements only), 
%	pps<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \practiceproblems[revision info]{number}
% Example: \practiceproblems[v1.1]{13}  % for Practice Problems Set #13, v1.1
%
\newcommand{\practiceproblems}[2][\stamp]{%
  \decideaboutsolutions
  \ifshowsolutions
    \paper[#1]{pps#2}{Solutions to Practice Problems #2}
  \else
    \paper[#1]{pp#2}{Practice Problems #2}
    \centerline{\emph{Due}: \duedateofpaper{pp#2}}
  \fi}

% Starts a Problem Set, given its number. Asks whether solutions
% should be included. If the answer is yes, the corresponding
% solutions paper is started. (Use \showsolutions or \hidesolutions
% to preselect the answer before the query ---and skip the query). The
% corresponding papers must have been defined in course.dat, with ids:   
%	ps<number> 	(for the problem statements only), 
%	pss<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \problemset[revision info]{number}
% Example: \problemset[v1.1]{13}   % for Problem Set #13, v1.1
%
\newcommand{\problemset}[2][\stamp]{%
  \decideaboutsolutions
  \ifshowsolutions
    \paper[#1]{pss#2}{Solutions to Problem Set #2}
  \else
    \paper[#1]{ps#2}{Problem Set #2}
    \centerline{\emph{Due}: \duedateofpaper{ps#2}}
    \bigskip
    \collaborationnote
    \medskip
    \readingnote
  \fi}

% Starts a Tutorial, given its number. Asks whether solutions
% should be included. If the answer is yes, the corresponding
% solutions paper is started. (Use \showsolutions or \hidesolutions
% to preselect the answer before the query ---and skip the query). The
% corresponding papers must have been defined in course.dat, with ids:   
%	tu<number> 	(for the problem statements only), 
%	tus<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \tutorial[revision info]{number}
% Example: \tutorial[v1.1]{13}   % for Tutorial #13, v1.1
%
\newcommand{\tutorial}[2][\stamp]{%
  \decideaboutsolutions
  \ifshowsolutions
    \paper[#1]{tus#2}{Solutions to Tutorial #2 Problems}
  \else
    \paper[#1]{tu#2}{Tutorial #2}
  \fi}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Starting an exam %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Starts a Quiz, given its number. Asks whether solutions
% should be included. If the answer is yes, the corresponding
% solutions paper is started. (Use \showsolutions or \hidesolutions
% to preselect the answer before the query ---and skip the query). The
% corresponding papers must have been defined in course.dat, with ids:   
%	qu<number> 	(for the problem statements only), 
%	qus<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \quiz[revision info]{number}
% Example: \quiz[v1.1]{3}   % for Quiz #3, v1.1
%
\newcommand{\quiz}[2][\stamp]{%
  \decideaboutsolutions
  \useexamproblems
  \ifshowsolutions
    \paper[#1]{qus#2}{Solutions to Quiz #2}
  \else
    \exampaper[#1]{qu#2}{Quiz #2}
  \fi}

% Starts a Practice Quiz, given its number. Asks whether solutions
% should be included. If the answer is yes, the corresponding
% solutions paper is started. (Use \showsolutions or \hidesolutions
% to preselect the answer before the query ---and skip the query). The
% corresponding papers must have been defined in course.dat, with ids:   
%	pq<number> 	(for the problem statements only), 
%	pqs<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \practicequiz[revision info]{number}
% Example: \practicequiz[v1.1]{3}   % for Practice Quiz #3, v1.1
%
\newcommand{\practicequiz}[2][\stamp]{%
  \decideaboutsolutions
  \useexamproblems
  \ifshowsolutions
    \paper[#1]{pqs#2}{Solutions to Practice Quiz #2}
  \else
    \exampaper[#1]{pq#2}{Practice Quiz #2}
  \fi}

% Starts a Final Exam. Asks whether solutions should be included. If
% the answer is yes, the corresponding solutions paper is
% started. (Use \showsolutions or \hidesolutions to preselect the
% answer before the query ---and skip the query). The corresponding
% papers must have been defined in course.dat, with ids:    
%	fe 	(for the problem statements only), 
%	fes	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \final[revision info]
% Example: \final[v1.1]  % for v1.1 of the Final Exam
%
\newcommand{\final}[1][\stamp]{%
  \decideaboutsolutions
  \useexamproblems
  \ifshowsolutions
    \paper[#1]{fes}{Solutions to the Final Examination}
  \else
    \exampaper[#1]{fe}{Final Examination}
  \fi}

% Starts a Practice (Final) Exam, given its number. Asks whether
% solutions should be included. If the answer is yes, the
% corresponding solutions paper is started. (Use \showsolutions or
% \hidesolutions to preselect the answer before the query ---and skip
% the query). The corresponding papers must have been defined in
% course.dat, with ids:    
%	pe<number> 	(for the problem statements only), 
%	pes<number>	(for the solutions).
% The optional argument allows for revision info: if used, the
% specified revision info is printed; if not, the \stamp info is
% printed.  
%
% Usage  : \practiceexam[revision info]{number}
% Example: \practiceexam[v1.1]{3}   % for Practice Exam #3, v1.1
%
\newcommand{\practiceexam}[2][\stamp]{%
  \decideaboutsolutions
  \useexamproblems
  \ifshowsolutions
    \paper[#1]{pes#2}{Solutions to Practice Exam #2}
  \else
    \exampaper[#1]{pe#2}{Practice Exam #2}
  \fi}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% COURSE PARAMETERS (NAMES & NUMBERS)
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Defines a new paper, given the paper's id, number, release date, and
% due date (if any). That is,
%    \paper{id}{number}{release date}{due date}
% For example:
%    \paper{ln1}{1}{September  5, 2001}{ }
% defines the first Lecture Notes. They are out on Sep 5, 2001. There
% is no due date. Similarly,
%    \paper{ps2}{7}{September 21, 2001}{September 28, 2001} 
% defines the 2nd Problem Set, which is (Handout) #7, released on Sep
% 21, 2001, and due on Sep 28, 2001.
%
\newcommand{\newpaper}[5]{
  \global\expandafter\def\csname @paper@#1@typ\endcsname{#2}
  \global\expandafter\def\csname @paper@#1@num\endcsname{#3}
  \global\expandafter\def\csname @paper@#1@out\endcsname{#4}
  \global\expandafter\def\csname @paper@#1@due\endcsname{#5}}

% Returns the number/releasedate/due date of a paper, given the
% paper's id. For example, given the definitions of the examples
% above, \numofpaper{ps2} returns ``7'', \releasedateofpaper{ln1}
% returns ``September 5, 2001'', and so on.
%
\newcommand{\typeofpaper       }[1]{\csname @paper@#1@typ\endcsname}
\newcommand{\numofpaper        }[1]{\csname @paper@#1@num\endcsname}
\newcommand{\releasedateofpaper}[1]{\csname @paper@#1@out\endcsname}
\newcommand{\duedateofpaper    }[1]{\csname @paper@#1@due\endcsname}

% Loads the definitions of all papers for the current term. This file
% should be hold in the same directory as the paper being
% processed. (This style file, course.sty, can be in any directory.)
\input{course.dat}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% BACKWARDS COMPATIBILITY            
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Use this command in the preamble, if you want some of the old
% features included. Please use  `course.old'  to add material that is
% needed for backwards compatibility only.
\newcommand{\backwardscompatibility}{\input{course.old}}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% DIRTY HACKING      
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Use this command to write unexpanded material to a file 
% [The TeXbook, pages 376-377]. 
%
\def\\{\let\stoken= } \\
\long\def\unexpandedwrite#1#2{\def\finwrite{\write#1}%
  {\aftergroup\finwrite\aftergroup{\sanitize#2\endsanity}}}
\def\sanitize{\futurelet\next\sanswitch}
\def\sanswitch{\let\n@xt\endsanity \ifx\next\endsanity
  \else\ifcat\noexpand\next\stoken\aftergroup\space\let\n@xt=\eat
  \else\ifcat\noexpand\next\bgroup\aftergroup{\let\n@xt=\eat
  \else\ifcat\noexpand\next\egroup\aftergroup}\let\n@xt=\eat
  \else\let\n@xt=\copytok\fi\fi\fi\fi \n@xt}
\def\eat{\afterassignment\sanitize \let\next= }
\long\def\copytok#1{\ifcat\noexpand#1\relax\aftergroup\noexpand\fi
  \ifcat\noexpand#1\noexpand~\aftergroup\noexpand\fi
  \aftergroup#1\sanitize}
\def\endsanity\endsanity{}





\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
