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

%\usepackage{comment}
%\usepackage{verbatim}
\makeatletter

\newcounter{ProbNum}
%\setcounter{ProbNum}{0}
\newcounter{pPartNum}[ProbNum]

%\def\Problems{\pagestyle{problems}\section*{Problems}\setcounter{ProbNum}{0}}

\def\Problems{%
	\section*{Problems}%
	\setcounter{ProbNum}{0}%
	\mark{{Problems for \ChapTitle/ \ChapterNumber}}%
	\gdef\SectionName{Problems for \ChapTitle/ \ChapterNumber}
	\normalfalse
}

%\def\Pref#1{\ref{[#1]}}% the [] are now part of the label
%\def\Pref#1{[\ref{Prob.#1}]}% 30 april 2014, removed [] 
%\def\Pref#1{[\ref{\the\tok@Prob#1}]}% 6 sept2015
\def\Pref#1{[\REF{\the\tok@Prob#1}]}% 6 sept2015

\def\problem[#1]{%
	\gdef\star@{}%
	\problem@[#1]%
}

\def\starproblem[#1]{%
	\gdef\star@{*}%
	\problem@[#1]%
}
	
\def\problem@[#1]{%
	\bigskip
	\stepcounter{ProbNum}%
	\bgroup
%	\def\@currentlabel{[\theProbNum]}%
	\def\@currentlabel{\theProbNum}%
%	\ifshowlabels\label{ #1}\fi%    added 11 sep 2012; note the space
%	\label{Prob.#1}%    
	%\protected@write \@auxout {}{\string \newlabel {[#1]}{{\theProbNum}{\thepage}}}%
	\noindent
%	\llap{\star@[\ref{Prob.#1}]\qquad}\ignorespaces%
	\llap{\star@[\ref{\the\tok@Chap\the\tok@Prob#1}]\qquad}\ignorespaces%
	\LABEL{\the\tok@Prob#1}%    
	\egroup
	\ignorespaces% added 1 May 2014
	%\ifshowlabels\marginpar{\small\itshape #1}\fi
}

%\def\ppart{% \smallskip\item{(\romannumeral\thepPartNum)}\stepcounter{pPartNum}}
%\def\ppart{\smallskip(\romannumeral\thepPartNum)\stepcounter{pPartNum}}
%
%\def\ppart{\smallskip\stepcounter{pPartNum}\noindent\llap{(\roman{pPartNum})\quad}}

\def\ppart{\par\smallskip\stepcounter{pPartNum}\noindent\llap{(\roman{pPartNum}) }}
\def\starppart{\par\smallskip\stepcounter{pPartNum}\noindent\llap{$^*$(\roman{pPartNum}) }}


\makeatother



% The following macros are intended for use with problem sets and their solutions


\ifx\coursename\isnotdefined
	\def\coursename{COURSENAME?}%
\fi




\newenvironment{nohide}[0]{\vskip-\lastskip\smallskip\indent\color{black}\normalfont}{\vskip-\lastskip\bigskip}

\def\HW#1#2{%
\def\HWsheetNum{##1}
\pagestyle{blank}%
\begin{flushleft}%
\normalsize\textbf
\coursename\newline
Homework \# #1\newline
Due: #2
\end{flushleft}\small
}

\def\HW#1#2{%
\gdef\HWsheetNum{#1}%
\let\soln=\comment
\pagestyle{blank}%
\gdef\StateProb{\relax}
\gdef\endStateProb{\relax}
%\setlength{\marginparwidth}{0.5in}%
\oddsidemargin = 1in
\begin{flushleft}%
\normalsize\textbf
\coursename\newline
Homework \# #1\newline
Due: #2
\end{flushleft}\small
}

\def\Orchidit{\color{DarkOrchid3}\it}

\def\StartSolutionSheet#1#2{%
\global\def\HWsheetNum{#1}%
\let\soln=\nohide
\pagestyle{blank}%
%\setlength{\marginparwidth}{0.5in}%
\oddsidemargin = 1in
\begin{flushleft}%
\normalsize\textbf
\coursename\newline
Solutions to sheet #1  \hfil
\end{flushleft}
%\small
%%\line{\bf Statistics 241/541 \hfil}
%\line{\bf2011: Solutions to sheet #1  \hfil}
\bigskip
%\color{DarkOrchid3}\it
\Orchidit
}	

\let\solveHW=\StartSolutionSheet

\def\bQuote{\begin{quotation}\noindent\itshape}
\def\eQuote{\end{quotation}}

\long\def\StateProb{\bgroup\color{DarkOrchid3}\it\small\noindent}
%\def\endStateProb{\smallskip\egroup\par}
\def\endStateProb{\vskip-\lastskip\smallskip\egroup\par}

