% 
% This is the file 'thesis-me.cls', copyright 1997, Richard W Kaszeta
%
% Report errors to kaszeta@me.umn.edu
%
% A test implementation of a U of M compliant thesis format.  Designed
% to provide a robust, latex2e compatible thesis format.  Doesn't
% necessarily do everything you want, but leaves things in a format
% where it is easy for the user to customize it's behavior
%
% Important:
% If you modify this file for personal use, you are *not* allowed to
% redistribute it unless you do all of the following (unless you
% obtain written permission from myself):
%
% 1. You must rename the file before you make any changes to it.
% 2. You must leave the copyright above intact.
% 3. You must change the error report address above so I don't get
%    email about files not maintained by me.
% 4. You must either distribute this original file with the changed
%    version or provide a .diff file
%
% Distribution of modified copies of this file without meeting these
% requirements is a violation of US Copyright Code.
%
% Otherwise, feel free to distribute unchanged copies of this file.
%
% What this package does:
%   Sets a 0 point indent for paragraphs
%   Fixes the margins to be 1.5 in on left, 1 in otherwise
%   Sets text at 1.5 spacing, except captions and footnotes
%   Changes the default formatting of section headers
%   Disables Marginal Paragraphs
%   Uses the standard book \frontmatter, \mainmatter, and \backmatter
%     to properly to page counts and page numbering
%   Redefines \maketitle to produce the appropriate signature, title,
%     and copyright pages.
%   Provides 'abstract' and 'dedication' environments
%   Loads in user-supplied code from thesis.cnf
%
% What this package doesn't do:
%   Doesn't provide 'facing page captions'. (And probably won't,
%     unless the department comes up with a duplex printer)
%
%
% What this package requires in the preamble
%   \Author{Author Name}
%   \Title{Thesis Title}
%   \Month{Month of Thesis Publication}
%   \Year{Year of Thesis Publication}
%   \Adviser{Adviser Name}
% Other values can be set, see code.  Most likely masters students
% will want to set \Degree and \degreelevel appropriately.
%
% Recent Changes:
%   Spelling and Margin Changes (v1.0)
%   Minor Tweaks (v0.97)
%   Fixed 'level' argument in sectioning command (v0.96)
%   Advisor Name added to title page (v0.95)
%   Due to popular request, the front matter environments are
%     no longer typset as quotation environments (v0.95)
%   Changed formatting of Chapter and Appendix TOC entries (v0.94)
%   Increased header size for abstract-like environments (v0.93)
%   Tweaked Title Page formatting (v0.92)
%   Added code for ``Acknowledgments'' in the front matter (v0.91)
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{thesis-me}
              [1997/06/04 ME Thesis Format v1.0]
% Initial Code
\RequirePackage{ifthen}
\newboolean{doendnotes}
% Declaration of Options
\DeclareOption{twoside}{\OptionNotUsed}
\DeclareOption{endnotes}{\setboolean{doendnotes}{true}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
% Execution of Options
\ProcessOptions
% Package and Class Loading
\RequirePackage{geometry} % for margins
\RequirePackage{setspace} % For stretching baseline
\LoadClass[oneside]{book} % Make sure it doesn't twoside it
% Main Code

% UMN style guide suggests 0-pt indentation.
\setlength{\parindent}{0pt}
\setlength{\parskip}{10pt plus 1pt minus 1pt}

% Fix margins so they are U of M compliant.
%
% For now this uses vmargin, but I'd like to do a bit better.
%
% This breaks marginal notes, but this is fine for now since the
% style doesn't allow it.
\geometry{nohead,lmargin=1.5in, rmargin=1in, tmargin=1in, bmargin=1in, footskip=24pt}

% Fix line spacing.  Use setspace.sty, as it is much more robust than
% just resetting the \baselinestretch, in that material can be
% included in a 'singlespace' environment if desired.  It also turns
% off stretched spacing in footnotes, floats, figures, tables, etc.
% and doesn't interfere with the spacing of displayed math.
%
% This is set with \AtBeginDocument since some of the spacing
% parameters it needs such as \@normalsize are defined after all the
% classes are loaded.
%
\AtBeginDocument{\onehalfspacing}

% Fix Section Headers so that they are more reasonably sized.
%
% Also set the secnumdepth and tocdepth so that up to level 4 sections
% are properly numbered and included in the TOC
%
% These are pretty personal preferences, and will probably change.
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\renewcommand{\section}{\@startsection{section}{1}{0pt}{10pt}{0.1pt}{\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0pt}{10pt}{0.1pt}{\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0pt}{10pt}{0.1pt}{\normalfont\normalsize}}

% Danger Will Robinson! Here is a bit of dirty code to improve 
% the handling of chapter titles and TOC entries.
%
% This rather complicated redefinition of \@chapter does two things
% different from the standard \chapter definition.  It allows \\ in
% chapter titles (but protects these from hurting TOC typesetting),
% and causes the TOC entries to start with ``Chapter'' or
% ``Appendix'', as appropriate.
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         % Here's where I added the \\ handline
                         {\def\\{ } \addcontentsline{toc}{chapter}%
                                % Here's where I add ``Chapter''
                         {\protect\numberline{\@chapapp\ \thechapter}#1}}%
                       \else
                         {\def\\{ }\addcontentsline{toc}{chapter}{#1}}%
                       \fi
                    \else
                      {\def\\{ }\addcontentsline{toc}{chapter}{#1}}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
% Now we have to fix \l@chapter to allow extra space for the
% ``chapter'' or ``appendix'' we added
\def\l@chapter#1#2{ 
  % encourage page breaks (but not too much)
  \pagebreak[3]
  % Insert a bit of healthy space between chapter headings
  \vspace*{1.0em plus 1pt} 
  % Fill a horizontal box with the chapter title.  Moderate TeX Wizardry.
  \@tempdima 78pt \begingroup
  \parindent \z@ \rightskip \@pnumwidth \parfillskip -\@pnumwidth
  \bfseries \leavevmode \advance\leftskip\@tempdima \hskip
  -\leftskip #1\nobreak\hfil
  \nobreak\hbox to\@pnumwidth{\hss #2}\par \endgroup }

% Disable marginpar since it isn't appropriate for a thesis
\renewcommand{\marginpar}[1]{}

% No shorthand definitions for figures, tables, etc, since those
% belong in a user-customization file to be coded later.  
%
% Especially important since constructs like
% \newcommand{\beq}{\begin{equation} break some of the math mechanisms.

% Page numbering considerations:
%
% The are mostly handled when doing the front matter.
%
% We start off with no page numbering (\pagestyle{empty}) which is
% used when building the signature page, title page, and copyright
% page.

\pagestyle{empty}\thispagestyle{empty}

% After the copyright page, we reset the pagestyle to
% \pagestyle{plain} and set the numbering to roman with
% \pagenumbering{roman}.  But actually the book class does this for us
% with the \frontmatter command, so we let the user do this.
%
% Similarly, \mainmatter command says we are starting the main part of
% the book and resets the page style and counter for us.
%
% And \backmatter fixes it so that \chapter doesn't increment the
% pointer, so we use it like \appendix\section{}

% Information for Signature, Title, and Copyright Pages

\def\Title#1{\gdef\@Title{#1}}\Title{}
\def\Author#1{\gdef\@Author{#1}}\Author{}
\def\Month#1{\gdef\@Month{#1}}\Month{}
\def\Year#1{\gdef\@Year{#1}}\Year{\number\year}
\def\Degree#1{\gdef\@Degree{#1}}\Degree{DOCTOR OF PHILOSOPHY}
\def\degreelevel#1{\gdef\@degreelevel{#1}}\degreelevel{doctoral}
\def\Adviser#1{\gdef\@Adviser{#1}}\Adviser{\ }
\def\School#1{\gdef\@School{#1}}\School{UNIVERSITY OF MINNESOTA}
\def\thesistext#1{\gdef\@thesistext{#1}} 
  \thesistext{A THESIS\\
    SUBMITTED TO THE FACULTY OF THE GRADUATE SCHOOL\\
    OF THE UNIVERSITY OF MINNESOTA\\
    BY}
\def\Degreetext#1{\gdef\@Degreetext{#1}} 
  \Degreetext{IN PARTIAL FULFILLMENT OF THE REQUIREMENTS\\
     FOR THE DEGREE OF}
\def\certifytext#1{\gdef\@certifytext{#1}} 
  \certifytext{This is to certify that I have examined this bound copy 
    of a \@degreelevel\ thesis by}
\def\satisfytext#1{\gdef\@satisfytext{#1}} 
  \satisfytext{and have found that it is complete and satisfactory in 
    all respects,\\
    and that any and all revisions required by the final\\
    examining committee have been made.}
\def\advisernametext#1{\gdef\@advisernametext{#1}} 
  \advisernametext{Name of Faculty Adviser}
\def\signaturetext#1{\gdef\@signaturetext{#1}} 
  \signaturetext{Signature of Faculty Adviser}

% The Copyright page is simplest

\newcommand{\copyrightpage}{
  \vspace*{\fill}
  \begin{center}
    \copyright\ \@Author\ \@Month\ \@Year    
  \end{center}
  \vspace*{\fill}
  \clearpage
}

% The signature page is lifted from the umnthes2e file
\newcommand{\signaturepage}{
    \vspace*{7pc}
    \begin{center} 
      \lineskip 3ex
      \@School
      \par\vskip0pt plus2fill
      \@certifytext
      \par\vskip0pt plus1fill
      \@Author
      \par\vskip0pt plus1fill
      \@satisfytext
      \par\vskip0pt plus2fill
      \@Adviser\\[-\baselineskip]
      \underline{\hspace*{4in}}\\
      \@advisernametext
      \par\vskip0pt plus2fill
      \makebox[4in]{\hrulefill}\\
      \@signaturetext
      \par\vskip0pt plus2fill
      \makebox[4in]{\hrulefill}\\
      Date
      \par\vskip0pt plus2fill
      GRADUATE SCHOOL 
    \end{center}
    \vskip0pt plus2fill
    \clearpage
}

\renewcommand{\titlepage}{
   \vspace*{\fill}
    \begin{center}
      {\Large
      \lineskip 3ex
      \@Title\par}
      \par\vskip0pt plus2fill
      \@thesistext
      \par\vskip0pt plus2fill
      \@Author
      \par\vskip0pt plus2fill
      \@Degreetext\\
      \@Degree
      \par\vskip0pt plus2fill
      \@Adviser, Adviser\\
      \par\vskip0pt plus2fill
      \@Month\ \@Year
     \end{center}
     \vskip0pt plus2fill
     \clearpage
}

% Clean it all up with a single call to \maketitle
\renewcommand{\maketitle}{\signaturepage\titlepage\copyrightpage\pagestyle{plain}}

% The abstract environment is not provided by book.  So we define it.
\newcommand{\abstractname}{Abstract}
\newenvironment{abstract}{\begin{center}{\Large \bfseries \abstractname\vspace{-.5em}\vspace{\z@}}\end{center}}{}

% Similarly, the dedication page
\newcommand{\dedicationname}{Dedication}
\newenvironment{dedication}{\begin{center}{\Large \bfseries \dedicationname\vspace{-.5em}\vspace{\z@}}\end{center}}{}

% And an acknowledgements page
\newcommand{\acknowledgmentsname}{Acknowledgments}
\newenvironment{acknowledgments}{\begin{center}{\Large \bfseries \acknowledgmentsname\vspace{-.5em}\vspace{\z@}}\end{center}}{}

% Load in endnote support if wanted
\ifthenelse{\boolean{doendnotes}}
   {%
     \RequirePackage{endnotes}
     \renewcommand{\footnote}{\endnote}
     \newcommand{\showendnotes}{%
     \begingroup
     \parindent 0pt
     \parskip 2ex
     \def\enotesize{\normalsize}
     \theendnotes
     \endgroup
       }
     }{}

% Finally, process user-local code
\InputIfFileExists{thesis.cfg}{\ClassInfo{thesis-me}{Using local configuration file}}{\ClassInfo{thesis-me}{No local configuration file}}
