%
% chowto.cls
%   Latex Class file for Hall C howto documents
%
% $Log: chowto.cls,v $
% Revision 1.1  2004/11/16 14:00:01  jones
% Optics code documentation
%
% Revision 1.2  2003/03/06 20:41:18  saw
% Change bad comment character (#) to correct comment character (%)
%
% Revision 1.1  2003/03/06 20:20:30  saw
% Initial Checkin
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{chowto}[2003/03/04 Hall C HOWTO LaTeX class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[12pt,letterpaper]{article}
\RequirePackage{hthtml}
\RequirePackage{graphicx}
\RequirePackage{epsfig}

\let\originalmaketitle\maketitle

\renewcommand{\maketitle}{

\ifx \@experiment \@undefined
\relax
\else
\let\@xoldtitle\@title
\renewcommand{\@title}{Experiment: \@experiment\\ \bigskip
\@xoldtitle}
\fi

\let\@oldtitle\@title
\renewcommand{\@title}{{\Huge Hall C \@howtotype}\\ \bigskip
\@oldtitle}
\ifx \@maintainer \@undefined
\relax
\else
\let\@oldauthor\@author
\renewcommand{\@author}{\@oldauthor\\ Maintained by \@maintainer}
\fi

\originalmaketitle}

\def\howtotype#1{
  \def\user{user}
  \def\expert{expert}
  \def\reference{reference}
  \def\thearg{#1}
  \ifx\user\thearg\gdef\@howtotype{User Howto}
  \else\ifx\expert\thearg\gdef\@howtotype{Expert Howto}
  \else\ifx\reference\thearg\gdef\@howtotype{Reference}
  \else
  \@latex@error{Invalid \noexpand\howtotype given}
  \fi\fi\fi
}  
\def\@howtotype{\@latex@error{No \noexpand\howtotype given}\@def}
\def\howtofilename#1{\gdef\@howtofilename{#1}}
\def\@howtofilename{\@latex@error{No \noexpand\howtofilename given}\@def}
\def\maintainer#1{\gdef\@maintainer{#1}}
\def\experiment#1{\gdef\@experiment{#1}}
\def\category#1{\gdef\@category{#1}}

\newif\if@hascitations
\let\if@hascitations\iffalse
\let\originalcite\cite
\let\originalnocite\nocite
\renewcommand{\cite}{
  \let\if@hascitations\iftrue
  \originalcite
}
\renewcommand{\nocite}{
  \let\if@hascitations\iftrue
  \originalnocite
}

\AtBeginDocument{
% Don't do \maketitle if latex2html is running to make figures
  \@ifundefined{tex2html_wrap}
	       {\maketitle}
	       {}
}

\AtEndDocument{
  \if@hascitations
    \IfFileExists{chowto-auto.bib}
                 {\def\biblist{chowto,chowto-auto.bib}}
		 {\def\biblist{chowto}}
    \IfFileExists{\jobname.bib}
		 {\bibliography{\biblist,\jobname}}
		 {\bibliography{\biblist}}
  \fi
}

\bibliographystyle{chowto}

