\typeout{Document Style Option `thesis'.}

% Define the page heading to be page number only.
\newcommand{\properpagestyle}{ 
       \pagestyle{myheadings}\markboth{}{}\markright{}}

% First thing we do is make sure that report has been loaded.  A
% common error is to try to use suthesis as a documentstyle.
\@ifundefined{chapter}{\@latexerr{The `thesis' option should be used
with the `report' document style}{}}{}

% We need 1" margins except on the binding edge, where it is 1 1/2"
% Theses are single-sided, so we don't care about \evensidemargin
\oddsidemargin 0.5in \evensidemargin 0in
\marginparwidth 40pt \marginparsep 10pt
\topmargin 0pt \headsep .5in
\textheight 8.1in \textwidth 6in

% Disallow page breaks at hyphens (this will give some underfull vbox's,
% so an alternative is to use \brokenpenalty=100 and manually search
% for and fix such page breaks)
\brokenpenalty=10000

% Use 1.37 times the normal baseline-to-baseline skip
\renewcommand{\baselinestretch}{1.37}

% Redefine the macro used for floats (including figures and tables)
% so that single spacing is used.
% (Note \def\figure{\@float{figure}set single spacing} doesn't work
%  because figure has an optional argument)
\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
            {\if\@tempa h\advance\@tempcnta \@ne\fi
             \if\@tempa t\advance\@tempcnta \tw@\fi
             \if\@tempa b\advance\@tempcnta 4\relax\fi
             \if\@tempa p\advance\@tempcnta 8\relax\fi
     }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup 
    \def\baselinestretch{1}\@normalsize
    \boxmaxdepth\z@
    \hsize\columnwidth \@parboxrestore}

% Redefine the macro used for footnotes to use single spacing
\long\def\@footnotetext#1{\insert\footins{\def\baselinestretch{1}\footnotesize
    \interlinepenalty\interfootnotelinepenalty 
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
   \edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}\@makefntext
    {\rule{\z@}{\footnotesep}\ignorespaces
      #1\strut}}}

% \author, \title are defined in report; here are the rest of the
% front matter defining macros
\def\university#1{\gdef\@university{#1}}
\def\address#1{\gdef\@address{#1}}
\def\dept#1{\gdef\@dept{#1}}
\def\submitdate#1{\gdef\@submitdate{#1}}

\def\@title{}
\def\@author{}
\def\@university{Harvard University}
\def\@address{Cambridge, Massachusetts}
\def\@dept{Mathematics}
\def\@submitdate{\ifcase\the\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space \number\the\year}

\def\dedicate#1{\dedic@tiontrue\gdef\dedication@text{#1}}

\def\draft{\renewcommand{\properpagestyle}{\pagestyle{myheadings}
\markright{{\rm Draft Version -- \today}}}\draft@modetrue\properpagestyle}
\def\nobib{\print@bibfalse}
\def\nolistoffigures{\figurespagefalse}
\def\nolistoftables{\tablespagefalse}
\def\nofront{\front@pagesfalse\permissionfalse\figurespagefalse\tablespagefalse}

% New if constructs:    Default conditions:
\newif\ifpermission     \permissiontrue 
\newif\iffigurespage    \figurespagetrue 
\newif\iftablespage     \tablespagetrue
\newif\iffront@pages    \front@pagestrue
\newif\ifthird@reader   \third@readerfalse
\newif\iffourth@reader  \fourth@readerfalse
\newif\iffifth@reader   \fifth@readerfalse
\newif\ifph@d           \ph@dfalse
\newif\iftwo@supervisors \two@supervisorsfalse
\newif\ifdraft@mode     \draft@modefalse
\newif\ifprint@bib      \print@bibtrue
\newif\ifdedic@tion     \dedic@tionfalse

\def\no@breaks#1{{\def\\{ \ignorespaces}#1}}    % disallow explicit line breaks

\def\titlep{%
    \thispagestyle{empty}%
    \ifdraft@mode
      \begin{center} \Large DRAFT COPY\\ \large Printed \today \end{center}
    \fi
    \null\vskip0.5in
    \begin{center}
        \hyphenpenalty=10000\Large\uppercase\expandafter{\@title}
    \end{center}
    \null\vskip0.5in
    \begin{center}
        \large\rm  A SENIOR THESIS OF \\
        \@author
    \end{center}
    \null\vskip0.5in
    \begin{center}
        \footnotesize  \rm THESIS ADVISOR: WILLIAM A. STEIN \\
        \null\vskip0.3in
        \footnotesize SUBMITTED IN PARTIAL FULFILLMENT OF THE HONORS REQUIREMENTS \\
        FOR THE DEGREE OF BACHELOR OF ARTS TO THE \\
        \null\vskip0.3in 
        DEPARTMENT OF MATHEMATICS \\
        \uppercase\expandafter{\@university} \\
        \null\vskip0.3in 
        \uppercase\expandafter{\@address} \\
        \uppercase\expandafter{\@submitdate}
    \end{center}
}


\def\beforepreface{
\typeout{Most over/underfulls in first few pages are the fault of dalthesis.}
\typeout{Ignore all them.  If uncorrectable errors occur, notify staff.}
    \pagenumbering{roman}
    \pagestyle{plain}
    \titlep
%    \iffront@pages\signaturepage\else\addtocounter{page}{1}\fi
%    \ifpermission\permissionpage\else\addtocounter{page}{1}\fi
    \iffront@pages\ifdedic@tion
        \newpage\begin{center}\Large\em\null\vskip1in
        \dedication@text
        \vfill\end{center}
    \fi\fi
    \iffront@pages\tableofcontents\else\addtocounter{page}{1}\fi
    \newpage
    \iftablespage
        \addcontentsline{toc}{chapter}{List of Tables}\listoftables
        \newpage
    \fi
    \iffigurespage
        \addcontentsline{toc}{chapter}{List of Figures}\listoffigures
        \newpage
    \fi
    }

\def\nonumchapter#1{%
    \chapter*{#1}
    \addcontentsline{toc}{chapter}{#1}}

\def\prefacesection#1{%
    \chapter*{#1}
    \addcontentsline{toc}{chapter}{#1}}

\newenvironment{dedication}{\newpage\begin{center}\Large\em\null\vskip1in}%
{\vfill\end{center}}


\def\afterpreface{\newpage
    \pagenumbering{arabic}
    \typeout{Dalthesis preface pages completed.}
    \properpagestyle}

% Redefine \thebibliography to go to a new page and put an entry in the
% table of contents
\let\@ldthebibliography\thebibliography
\renewcommand{\thebibliography}[1]{%
    \newpage
    \addcontentsline{toc}{chapter}{Bibliography}
    \@ldthebibliography{#1}
}

\let\@ldbibliography\bibliography
\renewcommand{\bibliography}[1]{\ifprint@bib\@ldbibliography{#1}\fi}

% Start out normal
\properpagestyle
