%  COURSE MACROS

\newcounter{problem}
\newcounter{totalpts}

\newcommand{\probpref}{Problem }

\newcommand{\problem}%
{\noindent\refstepcounter{problem}{\bf\probpref\theproblem} \quad}

\newcommand{\probpts}[1]%
{\noindent\refstepcounter{problem}{\bf\probpref\theproblem}
 (#1 points) \quad\addtocounter{totalpts}{#1}
 \typeout{\thetotalpts pts through problem \probpref\theproblem}}

\newcommand{\psproblems}[1]{\renewcommand{\probpref}{#1-}}

\newcommand{\probset}[1]{
 \begin{center}Assignment \##1\end{center}\psproblems{HW#1}}
\newcommand{\popq}[1]{
 \begin{center}Pop Quiz \##1\end{center}\psproblems{PQ#1}}
\newcommand{\quiz}[1]{
 \begin{flushright}\hspace*{1.5in}Quiz \##1\qquad\qquad Name\hrulefill\end{flushright}\psproblems{QZ#1}}

\newcommand{\probsolns}[1]{\solutionstrue
 \begin{center}Assignment \##1 Solutions\end{center}\psproblems{HW#1}}


% For printing exams with space reserved for solutions and printing exam
% with solutions from essentially same file.
% (I will also use this mechanism for notes that can be printed with
% metacomments (solutions) for me alone.)
% \solutionstrue/\solutionsfalse governs whether solutions printed.
% Solution specified in the form \soln{solutionbody}, which expands to
% \@soln{solutionbody}[\phantom{solutionbody}]
% Or if the phantom version causes a problem, the empty solution body
% can be specified with an optional argument to \soln as in
% \soln{solutionbody}[emptysolutionbody], which expands to
% \@soln{solutionbody}[emptysolutionbody].
\newif\ifsolutions
\solutionsfalse % solutions blank but with space reserved
\makeatletter
\long\def\soln#1{\@ifnextchar[{\@soln{#1}}{\@soln{#1}[\phantom{{\bf #1}}]}}
\long\def\@soln#1[#2]{\ifsolutions{\bf\color{red} #1}\else #2\fi}
\long\def\solnv#1{\soln{\vbox{\vspace*{\parskip}#1\vspace*{\parskip}}}}
\def\solutionsnull{\long\def\@soln##1[##2]{}} % Don't even reserve space
\makeatother


\newenvironment{compquote}{\vspace*{-1ex}\begin{quote}}{\vspace*{-2ex}\end{quote}}


% For syllabi
 \newcommand{\sessionname}{session}

\newcounter{session}
\renewcommand{\thesession}{\protect\printsession{\arabic{session}}{\thesessiondate}}

%\newcommand{\printsession}[2]{\sessionname~#1 on~#2}
 \newcommand{\printsession}[2]{\sessionname~#1}

\newcommand{\session}[2]{\item (#1)\def\thesessiondate{#1}\refstepcounter{session} #2}

\makeatletter
\newcommand{\exam}[1]{Exam \@arabic{#1}\label{session:exam#1}}
\newcommand{\examsession}[1]{\ref{session:exam#1}}
\makeatother

% For exams or homeworks that generate code from which solutions are obtained

% Following to write out code that can be run
% TeX code modeled on enotes.sty

\newwrite\codefile

\def\opencodefile#1{\immediate\openout\codefile=\basename.#1relax}
\def\closecodefile{\immediate\closeout\codefile}

\newcounter{queries}\setcounter{queries}{0}
\newcommand{\cl}[1]{{\tt #1}\immediate\write\codefile{#1}} % code line
\newcommand{\clq}[1]{\cl{#1}\ \ \hrulefill\stepcounter{queries}\ \arabic{queries}}  % code line with query
\newcommand{\icl}[1]{\item[]\cl{#1}} % code line
\newcommand{\iclq}[1]{\item[]\clq{#1}}  % code line with query
