% -----------------------------*- LaTeX -*------------------------------
%
%   handout.sty -- definitions for notes, class handouts, homeworks,
%   		   exams, and so forth.
%
% ----------------------------------------------------------------------

\newcommand{\plural}[1]{%
	\ifnum #1=1%
	\else%
		s%
	\fi%
}

\newcommand{\points}[1]{%
	\textbf{[#1 point\plural{#1}]}%
}

\newcommand{\pointsf}[1]{%
	\textbf{[#1 points]}%
}

\newcommand{\ppoints}[2]{%
	\textbf{[#1 parts, #2 point\plural{#2} each]}%
}

\newcommand{\ppointsf}[2]{%
	\textbf{[#1 parts, #2 points each]}%
}


% set one-inch margins all around, NOT counting the headers and footers

\setlength{\textwidth}{\paperwidth}
\addtolength{\textwidth}{-2in}
\setlength{\oddsidemargin}{1in}
\addtolength{\oddsidemargin}{-1in}
\setlength{\evensidemargin}{\oddsidemargin}

\setlength{\textheight}{\paperheight}
\addtolength{\textheight}{-2in}

\setlength{\topmargin}{1in}
\addtolength{\topmargin}{-1in}
\addtolength{\topmargin}{-\headheight}
\addtolength{\topmargin}{-\headsep}

%
%  \headers{left}{middle}{right} -- set up boldface underlined headers
%	left	-- left header item
%	middle	-- middle header item
%	right	-- right header item
%  
%  \headers{CS 170}{Final Exam}{Fall 1992}
%  \headers{CS 277}{Homework 1 (9/15/92)}{Jeff Erickson}
%
\newcommand{\headers}[3]{
   \newpage\setcounter{page}{1}
   \def\@oddhead{$\underline{\hbox to\textwidth{%
	\textbf{\rlap{#1}\phantom{hj}\hfill #2 \hfill \llap{#3}}}}$}
   \def\@oddfoot{\hfill\thepage\hfill}
}

%
%  ``Problems'' environment.
%  Just like ``enumerate'', except (try to) indent second and
%  succeeding paragraphs in each item, and (try to) separate items by
%  as much space as possible.  Doesn't work very well.
%
\newlength\tmplen
\newcounter{probnum}[section]
\newenvironment{problems}
{\tmplen=\parindent\begin{enumerate}\parindent=\tmplen\itemsep=2ex plus 0.05fil}
{\setcounter{probnum}{\theenumi}\end{enumerate}}

%
%  Solution environment.
%
\newproof{solution}{Solution}(\normalsize\rm\parindent1.5em)[\markatright{$\blacksquare$}]
\newenvironment{Solution}{\normalsize\rm\begin{solution}\parindent1.5em}
{\end{solution}}

%
%  \hidesolutions does just what it sounds like.
%
\RequirePackage{verbatim}
\def\hidesolutions{\let\solution\comment\let\endsolution\endcomment} 

%
%  Boxes for rubrics and other comments
%
\newsavebox{\Rubric}
\newenvironment{rubric}
  {\begin{lrbox}{\Rubric}\begin{tabular}{p{5.5in}}\small\sf}
  {\end{tabular}\end{lrbox}\centerline{\fbox{\usebox{\Rubric}}}}


%
%  Add stars and other marks in front of enumerated items.
%
\def\itemstars{}
\def\itemding{}
\def\resetmarks{\xdef\itemding{}\xdef\itemstars{}}
\def\Hard{\def\itemstars{$^\star$}}
\def\ReallyHard{\def\itemstars{$^\bigstar$}}
\def\ReallyReallyHard{\def\itemstars{{\Large$\bigstar$}}}
\def\ugradmark{{\large $\blacktriangleright$}}
\def\gradmark{{\large $\rhd$}}
\def\Ugrad{\def\itemding{\ugradmark}}
\def\Grad{\def\itemding{\gradmark}}

\def\labelenumi{\llap{\itemding\itemstars}\theenumi.\resetmarks}		% 1.
\def\labelenumii{\llap{\itemding\itemstars}(\theenumii)\resetmarks}	% (b)
\def\labelenumiii{\llap{\itemding\itemstars}\theenumiii.\resetmarks}	% iii.

\def\Hint#1{\textsl{[Hint: #1]}}

%
%  Add stars in front of sections and subsections.
%
\def\hardsection#1{\refstepcounter{section}\subsection*{*\thesection\quad #1}}
\def\hardsubsection#1{\refstepcounter{subsection}\subsection*{*\thesubsection\quad #1}}


%
%  ``Exercise'' environment (for course notes)
%
\newproof{exercise}{Exercise}

%
%  Inline figure environment
%
\newenvironment{inline}{\begin{center}\footnotesize\sf}{\end{center}}

%
%  Signature.
%
\RequirePackage{hyperref}\urlstyle{same}

\def\License#1{\par\vfill\tiny\noindent \textcopyright\ Copyright {#1} Jeff Erickson.  Released under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License (\url{http://creativecommons.org/licenses/by-nc-sa/2.5/})} 
