% Acadia University masters thesis template, based originally on the Stanford
% University Ph.D. thesis style, and then updated as described below:

% People are free to borrow as long as they change the name and date
% in the \typeout lines, the name of the file, and acknowledge the
% work that has been done by previous people.  Ideally they should
% comment their changes.

% Original version by Joseph Pallas back in 1989
% Modified by Emma Pease 5/7/92
%   added singlespace environment from doublespace.sty
%   added switches for variant title pages
%   modified the figure environment according to changes in latex.tex
%   corrected the signature page due to University rule changes
%   added an optional third reader to signature page
% Corrected a spacing problem with style changes 5/14/92 - Emma
% Modified by Emma Pease 1/10/95
% Modified for latex2e  5/17/95
%   changed \@xfloat and \@footnotetext to reflect latex2e changes
% Modified for latex2e 6/22/95 (Emma Pease)
%   changed singlespace environment so it would work (taken from
%   doublespace.sty)
% Modified 9/8/95 (Emma Pease)
%   removed doublespace.sty commands and explicitly inputted
%   doublespace
% Modified 12/17/96 (Emma Pease)
%   added optional \coprincipaladvisor (\coprincipaladvisor)
% Modified 5/29/98
%   replaced the required doublespace.sty by setspace.sty
% Modified 8/21/98
%   added a \businessthesis for the school of business
% Modified 8/22/98 
%   added a \lawthesis
% Modified 8/23/98
%   spelling error in \businessthesis def corrected
% Modified 5/14/1999 by Emma Pease
%   'By' dropped from title page
% Modified 7/26/1999 by Emma Pease
%   copyright page fixed
% Modified 9/28/99 by Emma Pease
%   more copyright page fixings
% Modified 10/28/99 by Emma Pease
%   and more copyright page fixings plus a minor mod on bibliography
%   need to start thinking of overhauling to standard package format
% Modified 11/26/99
%   fixed copyrightyear so that all Fall quarter theses are next
%   year's copyright

% Modified 5/31/01 by Emma Pease
%   fixed certification statement.  Setup for twoside option.
% Modified 6/4/01 by Emma Pease
%   emphasized that it is unofficial
% Modified 8/3/01 by Emma Pease
%   setup so that on twoside if the intro material (page numbered with
%   Roman numerals) ends on an odd page an extra blank page is included so
%   the main body (page numbered with Arabic numbers) starts on an odd
%   absolute page  (explanation modified 5/28/02)
% Modified 5/28/02 by Emma Pease
%   made first and second reader optional (not that the first reader
%   should ever be missing but someone managed to avoid a second reader)
%   If they aren't defined, they won't appear
% Modified 7/13/2003 by Emma Pease
%   dropped signature line for ``Approved for the University Committee
%   on Graduate Studies'' on signature page.  Also made sure the next
%   section starts on an odd page if two sided.
% Modified 11/19/03 by Emma Pease
%   fixed the bibliography so the addcontentsline works correctly with
%   hyperref.  Thanks to Peter Sturdza for pointing out this


% Changed for Acadia University Master of Science (Computer Science).
% Karim Rahim Spring 2004

% Acadia University Master of Science (Computer Science) template, updated
% July 18, 2005 by Greg Leighton
%	modified Approval of Thesis (page 2) to conform with new guidelines
%	added field for co-supervisor on signature page
%	removed unnecessary and outdated macros

% Updated November 30, 2006 by Brian Demmings
%    Removed field for co-supervisor on signature page and changed from acting
%               director to director
%    Added a table of listings (requires the lstlistings package)
%    Added library permissions pages

% Modified February 12, 2007 by Jim Diamond
% - various cleanup/optimizations

% Modified June 24, 2007 by Jim Diamond
% - yet more cleanup/optimizations
% - made default page dimensions suitable for Acadia theses.

% Modified November 21, 2013 by Jim Diamond & Ti Wang
% - updated librarian permission text
% - modified spacing to more closely match RGS template front pages

% Modified March 30, 2014 by Jim Diamond to further parameterize
% and regularize the style file, and to make the honours and masters
% style files as similar as possible.

% Modified April 27, 2015 by Jim Diamond:
% Added the (commented-out) code for tweaking the spacing between
% table of contents lines.
% Added the (mostly commented-out) code for (trying to) deal with widows and
% clubs (sometimes known as widows and orphans, as well as other names).
% Deleted a few lines of cruft.

% Modified Jan 19, 2016 by Jim Diamond
% -> cleaned up a couple of broken links
% -> improved a few sentences here and there
% -> made \raggedbottom the default.

% Modified Mar 29, 2016 by Jim Diamond
% -> cosupervisor line had supervisor's name (thanks to Scott Durno
%    for reporting this bug)

% Modified Apr 4, 2016 by Jim Diamond
% -> major changes to the citation section
% -> added a bit of stretch to \parskip to help with clubs and widows
% -> added text to the lists section to show how to automagically
%    avoid preceding and interior extra space (but, sadly, not the
%    extra space after a list).
% -> added extra entries in thesisbib.bib, mostly as examples for when
%    someone is trying to figure out what to put there.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%% ---------------  Ideas for dealing with widows and clubs -----------------
%
% A widow is a single line at the top of a page.
% A club is a single line at the bottom of a page.
% (Other people use different names.  Moving on...)

% Widows and clubs are typographically displeasing, and so by default
% the TeX typesetting engine has a moderate dislike for widows and
% clubs and will try to break paragraphs (when spitting out a page) to
% avoid them.  However, if you have lots of figures, tables, listings,
% or other such non-textual stuff, or if you like to write short
% paragraphs, you may find that TeX/LaTeX is not able to avoid them.

% Depending on your supervisor and the other readers you may get no
% grief or lots of grief.  This (mostly) commented out code discusses
% a couple of handraulic techniques for dealing with the problem.  You
% should not waste your time playing with this until you are about to
% hand a ``final draft'' to the reader(s).

% (1) TeX has two parameters that you can adjust to affect how much it
%     dislikes widows and clubs.  By default, it gives a ``penalty'' of 150
%     to a page any time it would have a widow or club.  That is a minor
%     penalty; a penalty of 10000 (the highest meaningful value) means
%     (very roughly) ``only do this if there is no better alternatives''.
%     You can set the penalties to larger values by uncommenting the
%     following two lines and tweaking the numbers:
%     \clubpenalty=9999
%     \widowpenalty=10000

% (2) While the honours regulations want uniform margins, no one seems
%     to squeal if the page is a bit short (for example, when a new
%     section is about to start, but there is only 1/2 inch left at the
%     bottom of the page, and we decide to start the next section on
%     the next page, wasting 1/2" of paper).  By default, LaTeX will
%     stretch out the page to force the bottom line to the bottom
%     margin, but in many cases this is fairly ugly.  The following line
%     tells LaTeX to allow space between the last bit of content and
%     the bottom margin (although the page number stays where it should).
%     If you want stricter spacing, comment out the following line (by
%     putting a % at the beginning):
\raggedbottom
% This line tells LaTeX that it is allowed to stretch the amount
% between paragraphs by up to 2 extra points.  This also helps it
% avoid single lines at the top or bottom of the page.  4 pts helps a
% lot for the sample thesis, and yet isn't really noticeable when
% using \raggedbottom.
\setlength{\parskip}{0pt plus 4pt}

% (3) Regardless of whether or not you are using \raggedbottom, you
%     might want to force a page break in a given place, *only if it
%     turns out that you are close to the bottom of the page*.  (Since
%     LaTeX is not a WYSIWYG system, you will only know this when you
%     run LaTeX to get a PDF file.)  If, when looking at a draft of
%     your thesis, you decide you want a page break because (for
%     example) a new section would start near the bottom of a page, it
%     would be unwise to put in an unconditional page break, because
%     future changes to your thesis may move content from near the
%     bottom of one page to the middle or near the top of the next
%     page.  Such an unconditional page break would now be undesired
%     and you would have to look for it and delete it.
%     Instead, anywhere in your document where you want a page break
%     between paragraphs or before a new section, if (at the time of
%     pdflatex'ing your thesis) there is not AT LEAST a given amount
%     of space left, 
%     insert a line like
%            \need 1.4 in
%     to tell LaTeX to start a new page if there isn't at least 1.4 inch
%     left on the current page.
%     For example, if you find a new section shows up too close to the
%     bottom of a page, you can put
%	\need 2 in
%       \section{some new section}
%     to only start that new section on the current page if there is
%     at least 2 inches of space left on the current page.
%     The following TeX code is needed to implement this, don't mess
%     with it unless you know what you are doing.
\def\need{\afterassignment\zneed\dimen@=}
\def\zneed{\relax
    \ifnum\pagetotal>\pagegoal  % Page may be full, but not yet gone
        % See if we can easily (0.3\pageshrink?) shrink the page to fit...
        % If so, bite the bullet & eject the page
        \dimen@=\pagetotal
        \advance\dimen@ by -0.3\pageshrink
        \ifnum\dimen@<\pagegoal
            \eject
         \else
            \penalty-500
        \fi
    \else
        \vskip 0pt \par
        \ifnum\pagetotal>\pagegoal
            % At great risk, assume an \eject is safe here, since all
            % we've added is glue to get past the end of the page
            \eject
        \fi
        \advance\dimen@ by \pagetotal
        \ifdim\dimen@>\pagegoal
            \vfill\eject
        \fi
    \fi
}

% (4) If all else fails, rewrite a sentence or two.  (Not kidding.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%
%%%%%   PRELIMS
%%%%%

\typeout{Document Style Option `acadia-masters-thesis' for latex2e <$Date: 2016/04/04$>.}
\typeout{Note that the authors believe this fulfills the current}
\typeout{Acadia University masters thesis requirements, but it has}
\typeout{not received official confirmation.}

% First thing we do is make sure that report has been loaded.
% A common error is to try to use acadia-masters-thesis as a document style.
\@ifundefined{chapter}{\@latexerr{The `acadia-masters-thesis' option 
    should be used with the `report' document style}{You should
    probably read the acadia-masters-thesis documentation.}}{}

%%%%%
%%%%%   DOCUMENTATION
%%%%%

\long\def\comment#1{}
\comment{
    With luck, you won't need to modify acadia-masters-thesis.sty or header.tex.
    
    In thesis.tex, you should delete the indicated lines immediately
    following ``\begin{document}'' down to the ``END OF START NOTE'' line.
    After that, replace all the lines which \include chapters and appendices
    with the ones which include your chapters and appendices.
    
    In preliminaries.tex, you will want to edit the personalization lines;
    here is an example:
    
    \title{A Practical Investigation of Mustard on Chocolate Cake}
    \author{Bob Smith}
    \dept{Music}
    \deptOrSchool{School}   % or Department
    \degree{Arts}

    \convocationAndYear{Spring Convocation 2018}
    \defenseDate{April 1, 2018)}
    \copyrightYear{2018}

    % Use a "~" after the "r." of "Dr." so that TeX doesn't think you have
    % ended a sentence (at which point it gives extra space).
    \chair{(Dr.~The Chair of the Committee)}
    \externalReader{(Dr.~Your External Reader)}
    \internalReader{(Dr.~Your Internal Reader)}
    \supervisor{Dr.~Samuel Kazoo}

    % Remove the '%' from the next line and fill in the name if desired.
    %\cosupervisor{(Dr.~Your Other Supervisor)}

    \headOrDirector{Dr.~Johann Liszt}
    % If the head or director is an ``acting'' head or director, uncomment
    % the next line (i.e., delete the '%'):
    % \justActing
    
    The following switches allow for special frontmatter pages; if you
    wish to use them, put them in thesis.tex between ``\include{header}''
    and ``\begin{document}'':
	\algorithmspagetrue   % If you have numbered algorithms in your thesis
	\listingspagetrue     % If you have numbered listings in your thesis
	\figurespagefalse     % If you have no numbered figures in your thesis
	\tablespagefalse      % If you have no numbered tables in your thesis
}

%%%%%
%%%%%   SETUP DOUBLE SPACING
%%%%%

% include doublespace.sty for some of the stuff below
\RequirePackage{setspace}

% Use 1.3 times the normal baseline-to-baseline skip
\setstretch{1.3}

%%%%%
%%%%%   SETUP MARGINS AND PENALTIES
%%%%%

% We need 1" margins except on the binding edge, where it is 1 1/2"
% Theses may be either single or double sided
\if@twoside
    \setlength\evensidemargin  {0 in}
\else
    \setlength\evensidemargin  {0.5 in}
\fi

\setlength\oddsidemargin   {0.5in}
\setlength\marginparwidth  {40\p@}

\topmargin 0.0in
\headsep .5in
\textheight 8.1in
\textwidth 6in


% Disallow page breaks at hyphens (this will give some under-full vbox's,
% so an alternative is to use \brokenpenalty=100 and manually search
% for and fix such page breaks)
\brokenpenalty=10000

%%%%%
%%%%%   SETUP COMMANDS PECULIAR TO THESES
%%%%%

% \author, \title are defined in report; here are the rest of the
% front matter defining macros
\def\dept#1{\gdef\@dept{#1}}
\def\deptOrSchool#1{\gdef\@deptOrSchool{#1}}
\def\degree#1{\gdef\@degree{#1}}
\def\convocationAndYear#1{\gdef\@convocationandyear{#1}}
\def\defenseDate#1{\gdef\@defensedate{#1}}
\def\externalReader#1{\gdef\@externalreader{#1}}
\def\internalReader#1{\gdef\@internalreader{#1}}
\def\supervisor#1{\gdef\@supervisor{#1}}
\def\cosupervisor#1{\@cosupervisedtrue\gdef\@cosupervisor{#1}}
\def\headOrDirector#1{\gdef\@director{#1}}
\def\justActing{\@directorIsActingtrue}
\def\chair#1{\gdef\@chair{#1}}
\def\copyrightYear#1{\gdef\@copyrightyear{#1}} % \author, \title in report

\def\@title{}
\def\@author{}
\def\@dept{}
\def\@deptOrSchool{}
\def\@degree{}

% If you don't know why this is here, don't touch it!
\def\@Skule{School}


\newif\ifcopyright	    \copyrighttrue
\newif\iffigurespage	    \figurespagetrue
\newif\iftablespage	    \tablespagetrue
\newif\ifthesiscopyright    \thesiscopyrighttrue
\newif\if@cosupervised	    \@cosupervisedfalse
\newif\if@directorIsActing  \@directorIsActingfalse

% Add support for "List of Listings" and "List of Algorithms" pages in
% the frontmatter of your thesis:
\newif\iflistingspage
\newif\ifalgorithmspage
% Those pages are turned off by default; to get whichever one(s) you
% want, add
%	\listingspagetrue
% or
%	\algorithmspagetrue
% (WITHOUT the % !) in thesis.tex BEFORE the ``\begin{document}'' line. 

\def\titlep{%
    \thispagestyle{empty}
    \null
    \vskip 0.5 in
    \begin{center}
	{
	  \Large\uppercase\expandafter{\@title}%
	}
	\vskip 0.75 in
	by
	\vskip 0.75 in
	\@author
        \vskip 1 in
	Thesis\\
	submitted in partial fulfillment of the requirements for\\
	the Degree of Master of \@degree (\@dept)\\[.35in]
	Acadia University\\
	\@convocationandyear
    \end{center}
    \vfill
    \copyright{} by \@author, \@copyrightyear
    \newpage
}

\def\signaturepage{%
    \noindent
    This thesis by \@author{} was defended successfully in an oral
    examination on \@defensedate.

    \vspace {0.20 in}
    \noindent The examining committee for the thesis was:

    \vspace{0.45 in}
    \noindent\rule{2.5in}{1pt}\\
    \@chair, Chair

    \vspace{0.45 in}
    \noindent\rule{2.5in}{1pt}\\
    \@externalreader, External Reader

    \vspace{0.45 in}
    \noindent\rule{2.5in}{1pt}\\
    \@internalreader, Internal Reader

    \vspace{0.45 in}
    \noindent\rule{2.5in}{1pt}\\
    \@supervisor, Supervisor

    \if@cosupervised
        \vspace{0.45 in}
	\noindent\rule{2.5in}{1pt}\\
	\@cosupervisor, Supervisor
    \fi

    \vspace{0.45 in}
    \noindent\rule{2.5in}{1pt}\\
    \@director, \if@directorIsActing Acting \fi
	\ifx\@Skule\@deptOrSchool Director\else Head\fi

    \vspace{0.50 in}
    \noindent
    This thesis is accepted in its present form by the Division of
    Research and Graduate Studies as satisfying the thesis
    requirements for the degree Master of \@degree\ (\@deptOrSchool).
    \vspace{0.50 in}

    % What in heaven's name are these dots for?
    % And they don't fit when there is a co-supervisor.
    % \noindent\hbox to 2.5 in{\dotfill}
    \newpage
}

\def\copyrightpage{%
    \noindent
    I, \@author{}, grant permission to the University Librarian
    at Acadia University to reproduce, loan or distribute copies
    of my thesis in \hbox{microform}, paper or electronic formats on a
    non-profit basis.  I, however, retain the copyright in my thesis.
	

    \begin{flushright}
        \vspace{0.75 in}
	\noindent\rule{2.5in}{1pt}\\
	Author

	\vspace{0.45 in}
	\noindent\rule{2.5in}{1pt}\\
	Supervisor

	\vspace{0.45 in}
	\noindent\rule{2.5in}{1pt}\\
	Date
    \end{flushright}
    \newpage
}


\def\firstThreePages{%
    \pagenumbering{roman}
    \pagestyle{plain}
    \titlep
    % Don't have the signature page on the back of the title page!  Blech!
    \if@twoside
        \null\vfill\newpage
    \fi
    \signaturepage
    % Ditto for the copyright page.
    \if@twoside
        \null\vfill\newpage
    \fi
    \copyrightpage
}

\def\tocAndSuch{%
    % If you need to shrink the spacing between table of contents
    % lines (for example, so that you don't end up with one ToC entry
    % on a page by itself) uncomment the following '\begin{spacing}'
    % line *AND* the \end{spacing} line (remove the '%').  You might
    % need to further tweak the 1.25 value.  Wash, rinse, repeat.
    % (Don't bother doing this until you have a ``final'' copy, or at
    % least a ``final'' draft for your supervisor.)
    %\begin{spacing}{1.25}
    \tableofcontents
    %\end{spacing}

    \iftablespage
        \listoftables
    \fi

    \iffigurespage
        \listoffigures
    \fi

    \iflistingspage
        \lstlistoflistings
    \fi

    \ifalgorithmspage
        \listofalgorithms
    \fi
}


\def\Acknowledgments{%
    \chapter*{Acknowledgements}
}
        

\def\prefacesection#1{%
    \chapter*{#1}
    \addcontentsline{toc}{chapter}{#1}
}

\def\afterpreface{%
    \cleardoublepage
    \pagenumbering{arabic}
    \pagestyle{headings}
}

% Redefine \thebibliography to go to a new page and put an entry in the
% table of contents
\let\@ldthebibliography\thebibliography
\renewcommand{\thebibliography}[1]{\newpage
                \@ldthebibliography{#1}%
\addcontentsline{toc}{chapter}{\bibname}}

% Start out normal
\pagestyle{headings}
