%%% handout.sty by Leonidas Guibas, Thu Jan  1 16:39:18 PST 1998

%% Style file for class handouts, to be invoked by:
%%      \documentclass{handout}
%% This is basically the latex 'article' style, with several modifications
%% grafted around it. You can use all the usual article options.
 
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{handout}
[1997/12/31 v1.0
 Document class for course handouts]

%%% New \documentstyle Options

\@twosidetrue                           % make 'twoside' the default
\@namedef{ds@oneside}{\@twosidefalse}   % [oneside] option
\@namedef{ds@10pt}{\def\@ptsize{0}}     % [10pt] option
\newif\if@scribe \@scribefalse          % scribe (notes) format switch
\DeclareOption{scribe}{\@scribetrue}    % [scribe] turns it on
\newif\if@hmwk \@hmwkfalse              % hmwk (homework) format switch
\DeclareOption{hmwk}{\@hmwktrue}        % [hmwk] turns it on
\newif\if@soln \@solnfalse              % soln (solutions) switch
\DeclareOption{soln}{\@solntrue}        % [soln] turns it on

% Redefine options to make 12 the default pointsize:

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\PassOptionsToClass{twoside,12pt}{article}

\ProcessOptions

%%% article.cls

\LoadClass{article}

%%% Margins

\setlength{\textheight}{8.5in}
\setlength{\topmargin}{0in}
\setlength{\textwidth}{6.25in}
\setlength{\oddsidemargin}{0.125in}
\setlength{\evensidemargin}{0.125in}

% prevent half-empty floating figure pages:

\def\floatpagefraction{.9}      % default .5
\def\topfraction{.9}            % default .7
\def\bottomfraction{.9}         % default .3
\def\textfraction{.1}           % default .2

%%% Titling Variables ([hmwk] vs [soln] vs [scribe] options)

% The main difference between [scribe], [hmwk] and [soln] format options is
% the way \maketitle works.  Neither option is required in the
% \documentclass{handout} line, since there are several variables
% declarations below which implicitly turn on the associated format.

% Scribe format variables:

\def\topics#1{\title{#1}\@scribetrue}
\def\lecturer#1{\gdef\@lecturer{#1}\@scribetrue}
\def\scribe#1{\gdef\@scribe{#1}\@scribetrue}
\def\reviewer#1{\gdef\@reviewer{#1}\@scribetrue}
\def\lecturedate#1{\gdef\@lecturedate{#1}\@scribetrue}
\def\lecturenumber#1{\gdef\@lecturenumber{#1}\@scribetrue}

\@scribefalse

% \def\@topics{What  ???}   topics not required
% \def\@lecturer{Who ???}   lecturer not required
% \def\@scribe{Who ???}     scribe not required
% \def\@reviewer{Who ???}   reviewer not required
\def\@lecturedate{When ???}
\def\@lecturenumber{Number ???}

% Note: scribe format does not require a \title, but will use
% it if available.

% Homework format variables:

\def\hmwknumber#1{\gdef\@hmwknumber{#1}\@hmwktrue}
\def\duedate#1{\gdef\@duedate{#1}\@hmwktrue}
\def\topic#1{\title{#1}\@hmwktrue}

\@hmwkfalse

\def\@hmwknumber{Number ???}
\def\@duedate{When ???}
% \def\@topic{What ???} topics not required

% Note: hmwk mode *does* require a \title (aka \topic)
% For now we leave \@title undefined.

% Solution format variables: 

\def\solnnumber#1{\gdef\@solnnumber{#1}\@solntrue}
\def\solntopic#1{\title{#1}\@solntrue}

\@solnfalse

\def\@solnnumber{Number ???}
% \def\@solntopic{What ???} solntopics not required

% \maketitle bits used by all the formats (usually defined in
% handout.tex):

\def\subjnum#1{\gdef\@subjnum{#1}}      \subjnum{???}
\def\subject#1{\gdef\@subject{#1}}      \subject{Unknown Course ???}
\def\subjelab#1{\gdef\@subjelab{#1}}    \subjelab{???}
\def\handout#1{\gdef\@handout{#1}}      \handout{Handout ???}

% We take over the \@date variable to be the date of the handout, i.e.
% when it is handed out.  Because there are so many dates floating
% around, we disable the \date command as too ambiguous:

\let\handoutdate=\date
\handoutdate{Handout Date ???} % do not use default (\today)
\def\date#1{\@warning{Ambiguous \noexpand\date{#1} command ignored}}

%%% Handout Cross-Referencing (handouts.tex data file)

% \hlabel{FILENAME}{NUMBER}{DATE}
% -------------------------------
% 
% Suppose '\hlabel{hw3}{8}{March 22, 1989}' appears in handouts.tex.
% Then the hw3 handout number is available as \ref{hw3},
% and the hw3 handout date is available as \pageref{hw3}. (a kludge!)
% This way handouts can refer to one another, i.e. hw4 might contain:
% 
% ... using problem~1 of homework~3 (handout~\ref{hw3}). ...
% ... Due date: \pageref{hw4-sol} ...
% 
% All this is so these handouts can be reused in future years with
% a minimum of editing (i.e. you only need to edit the data file).

% Define \hlabel, read the cross-ref info from handouts.tex:

\def\hlabel#1#2#3{\newlabel{#1}{{#2}{#3}}}
\@input{../handouts.tex} % complain but keep going if file not found

% Print warning message if the present job was not listed:

\@ifundefined{r@\jobname}
{\@warning{Handout file `\jobname' not listed in handouts.tex}}
{\handout{Handout \#\protect\ref{\jobname}}\handoutdate{\pageref{\jobname}}}

%%% ``titling'' list environment, may have some independent use

\def\mklableft#1{#1\hfil} % transpose of usual \@mklab
\newdimen\titlingitemwidth
\titlingitemwidth 18ex % wide enough for ``Handout #99'', etc.

\def\titling{\list{}{%
\let\makelabel\mklableft
\labelwidth \titlingitemwidth
\leftmargin \titlingitemwidth
\labelsep 0pt
\parsep0pt
\itemsep0pt}}
\let\endtitling=\endlist

%%% New Title Macros (\@maketitle, \maketitle)

% Different format depending on [scribe] or [hmwk] or [soln] version,
% makes a standard header for the course.

\def\@maketitle{% Put up the `class banner', with handout # and date:
\vfill\eject\vspace*{-2\headheight}\vspace*{-\headsep}
\vbox{\hbox to\textwidth{{\bf\@subjnum: \@subject}\hfil\@handout
\ifdim\overfullrule>\z@{\rm\bf\ DRAFT}\fi\strut}
\hbox to\textwidth{{\bf\@subjelab}\hfil\strut}
\hbox to\textwidth{{\sf Stanford University}\hfil\@date\strut}\hrule}
% Check that one of the formats is specified:
\if@hmwk
 \if@scribe
  \@warning{[scribe] format overriding [hmwk] format}
  \@hmwkfalse
 \fi
\else
 \if@scribe\else
    \if@soln\else
      \@warning{[scribe],[hmwk] or [soln] format not specified, no title}
    \fi
 \fi
\fi
% scribe format: optional centered title, list lecture#, date, and scribe
\if@scribe
 \medskip
 \titling
 \item[Lecture \#\@lecturenumber:]\@lecturedate
 \item[Topics:]\@title
 \@ifundefined{@lecturer}{}{\item[Lecturer:]\@lecturer}
 \@ifundefined{@scribe}{}{\item[Scribe:]\@scribe}
 \@ifundefined{@reviewer}{}{\item[Reviewer:]\@reviewer}
 \endtitling
\fi
% hmwk format: list homework #, topics, and duedate
\if@hmwk
 \medskip
 \titling
 \item[Homework \#\@hmwknumber:]
  \@ifundefined{@title}{\bf What is the topic ???}{\@title}
 \item[Due Date:]\@duedate
 \endtitling
\fi
% soln format: list homework #, and topics
\if@soln
 \medskip
 \titling
 \item[Solutions for homework \#\@solnnumber: ]
  \@ifundefined{@title}{\bf What is the topic ???}{\@title}
 \endtitling
\fi
% final skip before text
\bigskip
}

% \maketitle definition from article.dtx, modified to set
% \thispagestyle to empty rather than plain:

\def\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle
    \thispagestyle{empty}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@scribe\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax

  %%% Page Numbering Style

  % Modify the default page numbering style on subsequent pages,
  % to have headers only, page number away from staple.  Must do
  % this in \maketitle, since \@handout is not defined until then.

  \pagestyle{myheadings}
  \markboth{\@subjnum: \@handout}{\@subjnum: \@handout}

}

%%% Theorems

% Modify theorem environments (from latex.tex) to add a period
% after the theorem number:

\def\thmstyle{\sl} % style of text in theorem environment
\def\@begintheorem#1#2{\it \trivlist \item[\hskip
        \labelsep{\bf #1\ #2.}]\thmstyle}
\def\@opargbegintheorem#1#2#3{\it \trivlist \item[\hskip
        \labelsep{\bf #1\ #2\ (#3).}]\thmstyle}

% Main theorem env, for ``Theorem 2.1'' format delete the next '%':

\newtheorem{theorem}{Theorem}%[section]
% all these use the same ``theorem'' counter
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{porism}[theorem]{Porism}
\newtheorem{definition}[theorem]{Definition}

% short-cuts theorem macros, with optional arguments; for example:
%  \lem[Zorn]{What is yellow and equivalent to the axiom of choice?}

\def\makeshortcutthm#1#2{%
 \@namedef{#1}{\@ifnextchar[{\@nameuse{scto@#1}}{\@nameuse{sct@#1}}}
 \@namedef{sct@#1}##1{\begin{#2}##1\end{#2}}
 \@namedef{scto@#1}[##1]##2{\begin{#2}[##1]##2\end{#2}}}
\makeshortcutthm{thm}{theorem}
\makeshortcutthm{cor}{corollary}
\makeshortcutthm{clm}{claim}
\makeshortcutthm{lem}{lemma}
\makeshortcutthm{por}{porism}
\makeshortcutthm{Def}{definition}

%% Proof macros, e.g.: \Pf Because I say so.\qed

\newcommand{\Pf}{\par\noindent{\bf Proof:\quad}} % or \textindent
\newcommand{\qed}{~\hfill$\Box$\par\smallskip} % good ifmmode version?
\newenvironment{proof}{\Pf}{\qed}

% Same thing inside a \thm (i.e. when we don't prove anything :-):

\newcommand {\noqed}{~\hfill$\Box$}

%%% Problems and Solutions

% problems and subproblems (like sections), for example:
%  \problem{[10 points]} blah blah blah
%  \subproblem{} blah blah
%  \solution blah blah

\newcounter{problem}
\newcounter{subproblem}[problem]
% Note: this is really an incorrect use of \the... macros,
% how else to get this effect?
\def\theproblem{Problem \arabic{problem}.}
\def\thesubproblem{\arabic{problem}(\alph{subproblem}).}
\def\problem{\@startsection{problem}{2}{\z@}{-2.5ex plus -.7ex minus
    -.2ex}{1.5 ex plus .2ex}{\normalsize\bf}}
\def\problemmark#1{}
\def\subproblem{\@startsection {subproblem}{3}{\parindent}{-2ex plus
    -.5ex minus -.2ex}{-1em}{\normalsize\bf}}
\def\subproblemmark#1{}
% Old (non-sectioning) versions:
%\def\problem[#1]{\refstepcounter{problem}\par\bigskip\noindent{\bf
%Problem \theproblem.} [#1]\par\nobreak\smallskip\ignorespaces}
%\def\subproblem[#1]{\refstepcounter{subproblem}\par\bigskip\noindent{\bf
%\thesubproblem.} [#1]\par\nobreak\smallskip}

%% To start solutions (rather like \Pf):

\newcommand{\solution}{\medskip\noindent{\bf Solution:}\quad}

%%% Random useful Mathy Macros

% Size-sensitive bracketing commands:
\def\mathify#1{\ifmmode{#1}\else\mbox{$#1$}\fi} % guarantee math mode
\def\unmathify#1{\ifmmode\mbox{#1}\else{#1}\fi} % guarantee not math mode
\def\Cal#1{\mathify{\cal #1}}
\newcommand{\set}[1]{\mathify{\left\{{#1}\right\}}}
\newcommand{\bracket}[1]{\mathify{\left [{#1}\right]}}
\newcommand{\brocket}[1]{\mathify{\left\langle{#1}\right\rangle}}
\newcommand{\norm}[1]{\left\|{#1}\right\|}
\newcommand{\ceil}[1]{\mathify{\left\lceil {#1}\right\rceil}}
\newcommand{\floor}[1]{\mathify{\left\lfloor {#1}\right\rfloor}}
\newcommand{\paren}[1]{\mathify{\left({#1}\right)}}
% (don't forget \brack, \choose, \brace)

% Font for number systems (need 12pt versions!?)  From comp.text.tex faq:

% 21) How do I get symbols for "the real numbers", "the complex numbers",
%     and so on?
% 
%     These symbols are known as "blackboard bold" and are available in
%     the recently released AMS fonts "msam" (e.g., "msam10" for 10pt)
%     and "msbm". They replace the older "msxm" and "msym." The fonts 
%     have a large number of mathematical symbols to supplement the ones 
%     provided by TeX. The fonts are available via anonymous ftp from
%     e-math.ams.com (130.44.1.100) in the directory ./ams/amsfonts.
%     Two files which load the fonts and define the symbols are provided,
%     and both work with either TeX or LaTeX. Additionally a replacement
%     for the old amssymbols.sty file using the new fonts was posted
%     by Tony Li on August 13, 1990, but does not seem to have made it
%     into the major style repositories. Questions or suggestions 
%     regarding these fonts should be directed to 
%     tech-support@math.ams.com.

%\newfont {\msym}{msym10}
%\def\C{\mbox{\msym C}} % Complex numbers
%\def\N{\mbox{\msym N}} % Natural numbers
%\def\R{\mbox{\msym R}} % Real    numbers
%\def\Z{\mbox{\msym Z}} % Integer numbers

%%% Figures

% Modify 'caption' command to by default take a null [optional]
% argument.  This avoids problems where a very long caption would
% be sent to the aux file (on the other hand, it will change
% the expected list-of-figures behavior, i.e. many figures will
% not have any caption in the list.

%\def\caption{\refstepcounter\@captype \@dblarg{\@caption\@captype}}
\def\caption{\refstepcounter\@captype
        \@ifnextchar[{\@caption\@captype}{\@caption\@captype[]}}

%% Modify figure numbering to be ``problem.figure'':
% This does not work (figure counter does not reset), why?
%\@addtoreset{figure}{problem}
%\def\thefigure{\arabic{problem}.\arabic{figure}}

% Centered PostScript figure, assumes you use [epsfig] option:

\def\cpsfig#1{\centering \mbox{\epsfig{#1}}}

% Even more telegraphic (assumes standardized naming of ps figure
% files, no need to fool with width/height etc):

\def\cpsjob#1#2{\begin{figure}\cpsfig{figure=\jobname-#1.ps}
 \caption[]{\label{fig:#1}#2}\end{figure}}

% same for eps figures.

\def\cpsjobeps#1#2{\begin{figure}\cpsfig{figure=\jobname-#1.eps}
 \caption[]{\label{fig:#1}#2}\end{figure}}

%%% Miscellany

% Use [draft] option to reveal these inline comments; they
% will not show up in the output otherwise.
\long\def\comment#1{\ifdim\overfullrule>\z@{\sf[{#1}]}\fi}

% End of handout.cls
