% Class for typesetting problem-sets.
%
% TODO: Once, perhaps, to be merged with exam.cls
%
% Peter Sarkoci on Sunday 14th of Nov, 2010.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exercises}[2010/12/06 class for problem-sets]

% To allow the users all the comfort one has in the article class
\LoadClass{article}

\newcount\exercise%

\def\exer@date{}
\def\exer@ordinal{}
\def\exer@firstissue{Y}
\edef\exer@suppresscomments{\empty}

% --- exarcises style layout constants ----------------------------------------

\def\exer@botpagethreshold{500pt}
\def\exer@toppagethreshold{4pt}

\def\exer@exername{\'{U}loha}

% --- back-end ----------------------------------------------------------------

% conditional separator macro - separator appears only when not to the bottom
% or top of a page. The magic being caused by the fact, that TeX ordinarily
% ignores final vertical glues in textblocks. Macro invoked internally from
% closing clause of enviroment "exer".
%
% Many thanks to discusion thread:
% http://tex.stackexchange.com/questions/6443
%
\def\exer@separ{%
    \medskip%
    \cleaders\vbox to 0.4pt{\hrule width\linewidth}\vskip0.4pt%
    \medskip%
}%

% --- front-end ---------------------------------------------------------------

\newenvironment{exer}{%
    \ifnum\exercise>0%
        \par\exer@separ%
    \fi%
    \global\advance\exercise by 1%
    \noindent%
    {\bfseries \exer@exername\ \the\exercise.}%
}{}%

\newenvironment{cmnt}{%
    \ifx\exer@suppresscomments\empty%
        \toks0={\medskip\small\noindent}%
    \else%
        \toks0={\setbox0=\vbox\bgroup}%
    \fi%
    \the\toks0%
}{%
    \ifx\exer@suppresscomments\empty%
        \toks0={\normalsize}%
    \else
        \toks0={\egroup}%
    \fi%
    \the\toks0%
}%

\def\suppresscomments{%
    \def\exer@suppresscomments{Y}%
}%

