% \iffalse meta-comment
%
% Copyright (C) 2009 by J.V. Lassaline <jvl@ryerson.ca>
% -------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX 
% version 2008/05/04 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{ryethesis.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<class>\ProvidesClass{ryethesis}
%<*class>
    [2010/06/18 v1.3 Ryerson University thesis class definition]
%</class>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{hyperref}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\newcommand{\DescribeOption}[2]{\mbox{}\marginpar{\raggedleft\textbf{\textit{#1}}\slash\textit{#2}}}
\newcommand{\DescribeToggle}[4]{\mbox{}\marginpar{\raggedleft\textbf{\textit{#1}}\slash\textit{#2}\\\strut \MacroFont \string #3\ \\\strut \MacroFont \string #4\ }}
\begin{document}
  \DocInput{ryethesis.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{845}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2009/09/30}{Initial version}
% \changes{v1.1}{2010/06/18}{Fixed bug with previous degrees. Added
% xcolor package earlier in file.}
% \changes{v1.2}{2010/07/05}{Changed \\degree to \\degreeName to avoid
% conflict with package unitsdef.}
% \changes{v1.3}{2010/07/08}{Removed xcolor. Include hyperref to avoid
% problems for users with List of Appendices. Fixed \\cleardoublepage
% for two-sided mode to insert empty page. Fixed draft mode to be
% one-sided. }
%
% \GetFileInfo{ryethesis.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment}
% 
%
% \title{The \textsf{ryethesis} class\thanks{This document
%   corresponds to \textsf{ryethesis}~\fileversion, dated \filedate.}}
% \author{Jason V. Lassaline \\ \texttt{jvl@ryerson.ca}}
%
% \maketitle
%
% \section{Introduction}
%
% This class provides a document formatted to the Ryerson University School of
% Graduate Studies policy on Thesis Requirements, as published at the
% \href{http://www.ryerson.ca/graduate/policies}{Ryerson SGS policy Web site}.  This class includes formatting for dissertations and reports (e.g.\ MEng reports), handles the formatting of all required front and back matter, and defines a number of commands for specifying content. Page numbering as per Ryerson SGS requirements is handled automatically as is the ordering of information. Some content (e.g.\ author declaration) are inserted automatically. Other commands (e.g.\ |\dedication|) are provided to define optional information. The intent of this class is to allow Ryerson students to focus on the content of the thesis or dissertation and have \LaTeX{} handle the minutia of formatting to SGS requirements. If you are aware of any deficiencies or errors, please contact the author or submit your own patches. 
%
% This class file is largely built upon the existing |book| class and
% thus inherits many options (e.g. |oneside|, |twoside|) from this class.
% There are some specifications in Ryerson's thesis formatting regulations that differ from typical \LaTeX{} formatting (e.g.\ Appendices appear in a separate List of Appendices instead of within the Table of Contents). To better control the order in which content appears, the user should make use of the commands described in Section~\ref{sec::usage} to specify content (e.g.\ |\abstract| and |\appendix| commands). This deviates somewhat from typical \LaTeX{} usage where the author specifies front, main and back matter manually in the order in which they wish the material to appear.

% \section{Usage}\label{sec::usage}
%
% Several macros are available for defining the various content within the thesis, dissertation or report. Please refer to the included sample, ryesample.tex, for additional examples of usage. In writing the thesis you should focus on inserting the main matter of the document within the |document| environment. Front and back matter content, such as the abstract and appendices should be defined using the respective commands listed below. Most of the following macros should be called in the preamble of the document (i.e.\ before the |\begin{document}| environment), with exceptions noted below.
%
% \DescribeMacro{\title}
% This macro is used to define the title of the work, as in the base \LaTeX{}
% classes. This title will appear on the title page and abstract page. \index{title|usage}
% Capitalize your title as normal. The title on the title page will be
% typeset using small caps. 
% \begin{flushleft}|\title| \marg{Your Document Title}\end{flushleft}
%
% \DescribeMacro{\author}
% Your full name as it will appear on the title and abstract page. The usage is the same as with the |book| and other classes. 
% \begin{flushleft}|\author| \marg{Your Name}\end{flushleft}
%
% \DescribeMacro{\degreeName}
% The full name of your degree (e.g.\ Doctor of Philosophy, Masters of Applied Science). Do not use abbreviations.
% \begin{flushleft}|\degreeName| \marg{Full Degree Name}\end{flushleft}
%
% \DescribeMacro{\degreeYear}
% The year that the degree will be awarded, typically the year of convocation. 
% \begin{flushleft}|\degreeYear| \marg{Year of Convocation}\end{flushleft}
%
% \DescribeMacro{\program}
% The name of the graduate program (e.g.\ Aerospace Engineering).
% \begin{flushleft}|\program| \marg{Program Name}\end{flushleft}
%
% \DescribeMacro{\prevDegreeA}
% \DescribeMacro{\prevDegreeB}
% \DescribeMacro{\prevDegreeC}
% \DescribeMacro{\prevDegreeD}
% The full name, location and year of any previous completed degrees, starting with the most recent (|\prevDegreeA|) through to the oldest (|\prevDegreeD|). Currently only a maximum of four previous degrees are implemented. The arguments to each |\prevDegree?| command is the same.
% \begin{flushleft}|\prevDegreeA|\marg{Full Degree Name}\marg{University}\marg{Year of Degree}\end{flushleft} 
%
% \DescribeMacro{\partnerUniversity}
% The name of any partner University or school affiliated with the granting of this degree. As Ryerson has a full-fledged graduate program this command is optional and likely rarely used. 
% \begin{flushleft}|\partnerUniversity|\marg{University Name}\end{flushleft}
%
% \DescribeMacro{\abstract}
% This macro defines the content of the abstract which should abide by SGS policy. Do not use equations and avoid symbols if possible. The header of the abstract will be formatted automatically using the content defined by the previous commands. The current Ryerson word limit on abstracts is 350 words for a PhD thesis, 150 words otherwise. If no abstract is defined a message regarding ``Abstract goes here'' will appear within your document. An abstract is mandatory for the final version of your thesis.
% \begin{flushleft}|\abstract|\marg{The summary of your document, abiding by the word limit rules}\end{flushleft}
% 
% \DescribeMacro{\acknowledgements}
% \DescribeMacro{\dedication}
% The acknowledgements and dedication sections are optional, but can be defined using these commands.
% \begin{flushleft}|\acknowledgements|\marg{Any person(s) whose work or help you wish to acknowledge}\end{flushleft}
% \begin{flushleft}|\dedication|\marg{Anyone to whom you wish to dedicate this work}\end{flushleft}
%
% \DescribeMacro{\addtoreferences}
% As this class tightly controls the order of appearance of content within the document, it is necessary to provide a command for specifying \BibTeX{} input files. For each .bib file you wish to use, use a |\addtoreferences| command before the end of the |document| environment. Do not use the |\bibliography| command directly within the document. You do not need to specify the .bib extension to the filename. You should also use the |\bibliographystyle| command in your preamble to define the formatting style of your reference list. You'll need to process your document source with \BibTeX{} as normal. 
% \begin{flushleft}|\addreferences|\marg{.bib file name}\end{flushleft}
% 
% \DescribeMacro{\usebibliography}
% \DescribeMacro{\usereferences}
% \DescribeMacro{\useendnotes}
% The default header for the list of references is ``References''. Some document styles prefer the header read ``Bibliography'' or ``End Notes''. Use the commands |\usereferences|, |\usebibliography|, or |\useendnotes| anywhere before the end of the |document| environment.
% \begin{flushleft}|\usebibliography|\\|\usereferencs|\\|\useendnotes|\end{flushleft}
%
% \DescribeMacro{\appendix}
% The |book| class |\appendix| command has been redefined to take an argument to specify the appendices. Use the |\chapter|, |\section|, etc commands as normal within the argument to |\appendix| as normal to create each appendix and sub-sections. You can call this command in the preamble or anywhere before closing the document with the |\end{document}|.
% \begin{flushleft}|\appendix|\marg{All sectioned content for the appendix.}\end{flushleft}
%
% \section{Class Options}
% There are a number of class options defined in addtion to the default |book| class options. The default option |10pt| is applied but you can override this option using the |11pt| or |12pt| command, which is acceptable according to the current SGS policy. Most options appear in pairs which turn on or off various features. Most are  complemented by a corresponding macro which can be used in the document preamble. These options and macros are described below, grouped by function. Options are indicated in the margin as default and opposite pairs as \textbf{\textit{default}}\slash\textit{option}.
% 
% \DescribeOption{final}{draft}
% Switch between a final and draft versions of the document. Draft versions do not include some content (e.g.\ declaration) and figures, if using the |graphics| package, will likely be marked using placeholders. The |draft| option will enable the |oneside| option, while the |final| option will enable the |twoside| option. Override this if you wish.
%
% \DescribeToggle{lof}{nolof}{\includelistoffigures}{\nolistoffigures}
% Include a List of Figures. This list is generated by the use of |figure| floats as normally used in \LaTeX{}.
%
% \vspace{\baselineskip} \DescribeToggle{nolop}{lop}{\includelistofplates}{\nolistofplates}
% The use of plates (as opposed to figures or illustrations) is optional. If a List of Plates is requested, a new float environment |plate| is defined. Behaviour is similar to another float environment.
%
% \vspace{\baselineskip}
% \DescribeToggle{noloi}{loi}{\includelistofillustrations}{\nolistofillustrations}
% The SGS formatting requirements specify the option of a List of Illustrations, although a List of Figures will likely suffice. A new |illustration| float environment is declared if this option is enabled.
%
% \vspace{\baselineskip} 
% \DescribeToggle{lot}{nolot}{\includelistoftables}{\nolistoftables}
% A List of Tables is generated based upon the use of the |table| environment. As tables are commonly used in theses, this option is enabled by default.
%
% \vspace{\baselineskip} 
% \DescribeToggle{los}{nolos}{\includenomenclature}{\nonomenclature}
% A List of Symbols is generated using the |nomenclature| package. As the SGS policy makes no reference to requirements for a nomenclature list, this list is inserted as the last item in the front matter. Nomenclatures are commonly used in math, science, and engineering theses. See the |nomenclature| package for available commands, but note that there is no need to issue the |\printnomenclature| command as it is handled automatically. You will need to do additional processing using the |makeindex| command.
%
% \DescribeToggle{loa}{noloa}{\includelistofappendices}{\nolistofappendices}
% Typically, most documents which include an appendix list the appendices within the Table of Contents. SGS formatting policy indicates a separate List of Appendices. This switch is enabled by default, and any |\chapter| or lower sectioning will appear in a separate List of Appendices. You must use the |\appendix| command for the appendices to be numbered and inserted correctly. No List of Appendices will appear if you do not use the |\appendix| command.
%
% \DescribeToggle{glossary}{noglossary}{\includeglossary}{\noglossary}
% Glossaries are supported using the |glossaries| package but are
% optional. You will need to do additional processing using the
% |makeglossaries| command to generate the glossary content. See the
% |glossaries| package for more details. Include glossary commands for
% identifying glossary items but do not issue the |\printglossary|
% command as this is handled automatically if glossaries are
% enabled. Acronyms can be defined in the glossary using the
% |\newacronym| command and will be listed separately within the
% glossary
%
% \vspace{\baselineskip}\DescribeToggle{index}{noindex}{\includeindex}{\noindex}
% An optional index is supported using the |makeindex| command in the normal fashion. Indicate index items using the |\index| command but do not issue the |\printindex| command as this is handled automatically if indices enabled.
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
% \textit{This information is provided to document the source code of this class definition. It can be safely ignored by the casual user.}
% 
% This class is derived from the |book| class, with a number of commands
% used to define the various sections of the document. The
% class is responsible for inserting the content in the correct order according to SGS policy. Thus the focus of this class is to provide a set of commands for defining the content of the sections, rather than provide environments which delimit the sections and expecting the user to use them in the correct order.
% 
% The class definition begins with the following package requirements.
%
%    \begin{macrocode}
% A minimal set of packages as required by the class
\RequirePackage{ifthen}
\RequirePackage{fancyhdr}
\RequirePackage{setspace}
% If using pdfpages, note that it does not appear to play 
% well with vmargin and XeTeX (inserted pdfs are not 
% anchored in the correct location).
\RequirePackage{vmargin}
%    \end{macrocode}
% 
% The class defines a number of options for enabling and disabling certain features. Note that SGS policy requires a separate List of Appendices instead of including appendices within the Table of Contents. No requirement for nomenclature is specified, thus a List of Symbols is inserted after all other lists.
%
%    \begin{macrocode}
% The following commands are based upon SGS policy effective Sept. 2009
% Class options:
% Font size must 10 to 12 pt. Default will be 10pt, aka '10pt' option
%   Alternate options: '11pt','12pt'
%
% Papersize must be US letter size (8.5"x11"), ie always 'letterpaper' option
%
% Booleans for option switches, with default states below. 
% These switches are modifiable by options to the class 
% and by toggle commands
%
\newboolean{@ryedraft} \setboolean{@ryedraft}{false} % not draft == final
\newboolean{@ryelistoftables} \setboolean{@ryelistoftables}{true}
%
% The distinction between plates, illustrations and figures is subtle. 
% SGS policy indicates separate lists for each. Only LoF is enabled by default.
%
\newboolean{@ryelistofplates} \setboolean{@ryelistofplates}{false}
\newboolean{@ryelistoffigures} \setboolean{@ryelistoffigures}{true}
\newboolean{@ryelistofillustrations} \setboolean{@ryelistofillustrations}{false}
%
% Ryerson SGS policy specifies that appendices should be listed 
% in a separate list, and not within the ToC. 
%
\newboolean{@ryelistofappendices} \setboolean{@ryelistofappendices}{true}
% As the List of Appendices overrides the |\addtocontents| command,
% hyperef is included by this class to avoid broken links when
% including the table of contents or list of appendices.
\newboolean{@ryehyperref} \setboolean{@ryehyperref}{true}
%
% Ryerson SGS policy does not specify anything about a list of 
% symbols or nomenclature, however in engineering, math, and 
% science, this is a common front matter feature. A List of Symbols 
% is inserted after all the previous lists and toc.
%
\newboolean{@ryenomenclature} \setboolean{@ryenomenclature}{false}
% Glossaries and indices require extra processing. These are disabled by default as they are likely uncommon in a thesis or dissertation.
\newboolean{@ryeglossary} \setboolean{@ryeglossary}{false}
\newboolean{@ryeindex} \setboolean{@ryeindex}{false}
%
% This class is based upon the book class
\DeclareOption*{%
 \PassOptionsToClass{\CurrentOption}{book}
}

% Class options to control what appears in the document

% Draft is equivalent to the book class sense of draft.
\DeclareOption{draft}{
   \typeout{Ryerson-Thesis Class Option: `draft'}
   \ExecuteOptions{10pt,oneside}
   \PassOptionsToClass{draft,oneside}{book}
   \setboolean{@ryedraft}{true}
}

% Final is the opposite of draft. This is the default mode. 
\DeclareOption{final}{
   \typeout{Ryerson-Thesis Class Option: `final'}
   \ExecuteOptions{10pt,twoside}
   \PassOptionsToClass{final,twoside}{book}
   \setboolean{@ryedraft}{false}
}

% Include a list of figures (on by default).
\DeclareOption{lof}{
    \typeout{Ryerson-Thesis Class Option: `lof' Enabling List of Figures}
    \setboolean{@ryelistoffigures}{true}
}

% Do not include a list of figures
\DeclareOption{nolof}{
    \typeout{Ryerson-Thesis Class Option: `nolof' Disabling List of Figures}
    \setboolean{@ryelistoffigures}{false}
}

% Include a list of plates
\DeclareOption{lop}{
    \typeout{Ryerson-Thesis Class Option: `lop' Enabling List of Plates}
    \setboolean{@ryelistofplates}{true}
}

% Do not include a list of plates
\DeclareOption{nolop}{
    \typeout{Ryerson-Thesis Class Option: `nolop' Disabling List of Plates}
    \setboolean{@ryelistofplates}{false}
}

% Include a list of illustrations
\DeclareOption{loi}{
    \typeout{Ryerson-Thesis Class Option: `loi' Enabling List of Illustrations}
    \setboolean{@ryelistofillustrations}{true}
}

% Do not include a list of illustrations
\DeclareOption{noloi}{
    \typeout{Ryerson-Thesis Class Option: `noloi' Disabling List of Illustrations}
    \setboolean{@ryelistofillustrations}{false}
}

% Include a list of tables (on by default)
\DeclareOption{lot}{
    \typeout{Ryerson-Thesis Class Option: `lot' Enabling List of Tables}
    \setboolean{@ryelistoftables}{true}
}

% Do not include a list of tables.
\DeclareOption{nolot}{
    \typeout{Ryerson-Thesis Class Option: `nolot' Disabling List of Tables}
    \setboolean{@ryelistoftables}{false}
}

% Include a list of appendices (on by default)
\DeclareOption{loa}{
    \typeout{Ryerson-Thesis Class Option: `loa' Enabling List of Appendices}
    \setboolean{@ryelistofappendices}{true}
}

% Disable the list of appendices. Appendices will appear in the ToC as is normal for the book class.
\DeclareOption{noloa}{
    \typeout{Ryerson-Thesis Class Option: `noloa' Disabling List of Appendices}
    \setboolean{@ryelistofappendices}{false}
}

% Do not include hyperref
\DeclareOption{nohyperref}{
    \typeout{Ryerson-Thesis Class Option: `nohyperref' Do not include hyperref}
    \setboolean{@ryehyperref}{false}
}


% Include a list of symbols (i.e. a nomenclature). Requires additional processing of the document.
\DeclareOption{los}{
     \typeout{Ryerson-Thesis Class Option: `los' Enabling Nomenclature}
     \typeout{*********************************************************************}
     \typeout{}
     \typeout{ Use: makeindex filename.nlo -s nomencl.ist -o filename.nls }
     \typeout{         where filename is the root file name of the TeX source file.}
     \typeout{}
     \typeout{*********************************************************************}
     \setboolean{@ryenomenclature}{true}
}

% Disable the list of symbols.
\DeclareOption{nolos}{
     \typeout{Ryerson-Thesis Class Option: `nolos' Disabling Nomenclature}
     \setboolean{@ryenomenclature}{false}
}

% Enable the glossary. Requires additional processing.
\DeclareOption{glossary}{
    \typeout{Ryerson-Thesis Class Option: `glossary' Enabling Glossary}
     \typeout{*********************************************************************}
     \typeout{}
     \typeout{ Use: makeglossaries filename }
     \typeout{         where filename is the root file name of the TeX source file.}
     \typeout{}
     \typeout{*********************************************************************}
   \setboolean{@ryeglossary}{true}
}

% Do not include a glossary (the default).
\DeclareOption{noglossary}{
     \typeout{Ryerson-Thesis Class Option: `noglossary' Disabling Glossary}
     \setboolean{@ryeglossary}{false}
}

% Include an index. Requires additional processing
\DeclareOption{index}{
    \typeout{Ryerson-Thesis Class Option: `index' Enabling Index}
     \typeout{*********************************************************************}
     \typeout{}
     \typeout{ Use: makeindex filename }
     \typeout{         where filename is the root file name of the TeX source file.}
     \typeout{}
     \typeout{*********************************************************************}
   \setboolean{@ryeindex}{true}
}

% Do not include an index (the default).
\DeclareOption{noindex}{
     \typeout{Ryerson-Thesis Class Option: `noindex' Disabling Index}
     \setboolean{@ryeindex}{false}
}

% Execute options, including specifying the required US letter paper size and default 10pt font.
\ExecuteOptions{letterpaper,10pt}
\ProcessOptions\relax

% Load the base book document class.
\LoadClass{book}
%    \end{macrocode}
%
% Page size and margin as specified in the SGS policy, using the |vmargin| package.
% 
%    \begin{macrocode}

% Always use 8.5"x11" paper.
\setpapersize{USletter}
% Set left, top, right, bottom margins
% An extra 0.25in added to left margin (right margin on even pages) to allow for binding.
\setmargrb{1.25in}{1in}{1in}{1in}
%    \end{macrocode}

% The book class commands |\frontmatter|, |\mainmatter|, and |\backmatter| are redefined, based upon SGS policy effective Sept.\ 2009.  Each use the following page styles:
% \begin{description}
% \item \textbf{Front matter} roman page numbering, plain page style (page number only)
% \item \textbf{Main matter} arabic page numbering, fancy headers with alternating chapter and section
% \item \textbf{Back matter} no format specified so keeping same style as main matter
% \end{description}

% \begin{macro}{\cleardoublepage}
% Create a new page, set page style to empty (no footer or header), then issue a clear page if in |twoside| mode. Used before every ToC, list, or start of new chapter. This results in part (e.g.\ Table of Contents) starting on the right hand side (odd page number) in |twoside| mode.
%    \begin{macrocode}
% based upon clearemptydoublepage from page 92 of 
% The LaTeX Companion, 1993.
\renewcommand{\cleardoublepage}{\newpage{\pagestyle{empty}%
\clearpage\if@twoside \ifodd\c@page\else%
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}}
% An internal clearpage command
\newcommand{\ryethesis@clearpage}
{\if@openright\cleardoublepage\else\clearpage\fi}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\frontmatter}
% Inserts all front matter content. This function is called by the class at the beginning of the document and does not need to be called by the user.
%    \begin{macrocode}
\newif\if@ryethesismatchtoc \@ryethesismatchtocfalse
\renewcommand\frontmatter{%
  \@mainmatterfalse
  \@ryethesismatchtocfalse
 \pagenumbering{roman}
  \pagestyle{plain}
  \maketitle
  \ryethesis@insertdeclaration
  \ryethesis@insertabstract
  \ryethesis@insertacknowledgements
  \ryethesis@insertdedication
  \ryethesis@inserttoc
  \ryethesis@insertlot
  \ryethesis@insertlop
  \ryethesis@insertlof
  \ryethesis@insertloi
  \ryethesis@insertloa
  \ryethesis@insertnom
  \ryethesis@clearpage
  \pagenumbering{arabic}
  \pagestyle{fancy}
  % If the acronym feature is used with the glossary of terms, \gls
  % commands for acronyms will be expanded on first use if used in the
  % front matter (e.g. in the abstract). Reset this usage so that the
  % first use of a \gls acronym is expanded in the main matter as well.
  \ifthenelse{\boolean{@ryeglossary}}{\glsresetall}{}
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\mainmatter}
% Sets up page style of the main matter (i.e. the body) of the document. This function is called by the class after |\frontmatter| and does not need to be called by the end user. 
%    \begin{macrocode}
\renewcommand\mainmatter{%
  \@mainmattertrue
  \pagenumbering{arabic}
  \pagestyle{fancy}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\backmatter}
% Insert the back matter, beginning with the appendices, if any. This function is called by the class at the end of the document and does not need to be called by the end user. This means that the appendices and bibliography must be defined in a similar way as the front matter content is defined. 
%    \begin{macrocode}
\renewcommand\backmatter{%
% Redirect toc entries to toa if a List of Appendices is used
 \ifthenelse{\boolean{@ryelistofappendices}}{\@ryethesismatchtoctrue}{\@ryethesismatchtocfalse}
 \ryethesis@insertappendix
% Restore toc entries back to toc
 \@ryethesismatchtocfalse
 \ryethesis@insertreferences
  \ryethesis@insertglossary
  \ryethesis@insertindex
 \@mainmatterfalse
}
%    \end{macrocode}
% \end{macro}
% The |fancyhdr| package is used to define the |fancy| page style for main and back matter.
%    \begin{macrocode}
\fancyhead{} % Clear all header fields
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot{} % Clear all footer fields
\fancyfoot[C]{\thepage}
%    \end{macrocode}
% Global variables are defined to hold a variety of content. These variables are used by the various |\ryethesis@insert| commands that appear below as well as the redefined |\titlepage| command. 
%    \begin{macrocode}

% Variables for storing degree, discipline, etc. Mostly related to the title page
% Some values are taken from those defined by the book class, namely \@title, \@author

% Initial values (most are blank)
\global\def\ryethesis@documentType{thesis} % Alternate forms include 'dissertation' or 'project'
\global\def\ryethesis@degree{}
\global\def\ryethesis@prevDegreeA{}
\global\def\ryethesis@prevDegreeB{}
\global\def\ryethesis@prevDegreeC{}
\global\def\ryethesis@prevDegreeD{}
\global\def\ryethesis@prevLocationA{}
\global\def\ryethesis@prevLocationB{}
\global\def\ryethesis@prevLocationC{}
\global\def\ryethesis@prevLocationD{}
\global\def\ryethesis@prevYearA{}
\global\def\ryethesis@prevYearB{}
\global\def\ryethesis@prevYearC{}
\global\def\ryethesis@prevYearD{}
\global\def\ryethesis@program{}
\global\def\ryethesis@degreeyear{}
\global\def\ryethesis@partnerUniv{}
\global\def\ryethesis@theabstract{}
\global\def\ryethesis@theacknowledgements{}
\global\def\ryethesis@thededication{}
\global\def\ryethesis@listofbibfiles{}
\global\def\ryethesis@theappendices{}
%    \end{macrocode}

% The following commands are used to define the above variable content.

% \begin{macro}{\title}
% Override the default behaviour of |\title|
%     \begin{macrocode}
\def\title#1{\gdef\@title{#1}\if@ryehyperref\hypersetup{pdftitle={#1}}\fi}
%     \end{macrocode}
% \end{macro}

% \begin{macro}{\author}
% Override the default behaviour of |\author|
%     \begin{macrocode}
\def\author#1{\gdef\@author{#1}\if@ryehyperref\hypersetup{pdfauthor={#1}}\fi}
%     \end{macrocode}
% \end{macro}

% \begin{macro}{\documentype}
% Specify the document type (e.g. thesis, dissertation, or project. Users may use this command to override the currently defined options.
%    \begin{macrocode}
\newcommand{\documenttype}[1]{\ifx\empty#1\else\gdef\ryethesis@documentType{#1}\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thesis}
% Use the ``thesis'' document type. This affects the content of the title page. This command may have more features at a later time.
%    \begin{macrocode}
\newcommand{\thesis}{\documenttype{thesis}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\dissertation}
% Use the ``dissertation'' document type. This affects the content of the title page. This command may have more features at a later time.
%    \begin{macrocode}
\newcommand{\dissertation}{\documenttype{dissertation}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\project}
% Use the ``project'' document type. This affects the content of the title page. This command may have more features at a later time.
%    \begin{macrocode}
\newcommand{\project}{\documenttype{project}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{degree}
% Specify the name of the degree (e.g. ``Doctor of Philosophy'' or ``Masters of Applied Science''). This affects the content of the title and abstract page.
%    \begin{macrocode}
% Was \degree but changed to the more specific \degreeName to avoid
% conflict with other packages
\newcommand{\degreeName}[1]{\gdef\ryethesis@degree{#1}\if@ryehyperref\hypersetup{pdfsubject={#1}}\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\degreeYear}
% The official year of the degree. This affects the content of the title and abstract page.
%    \begin{macrocode}
\newcommand{\degreeYear}[1]{\gdef\ryethesis@degreeYear{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\program}
% The program or department which is awarding the degree. This affects the content of the title and abstract page.
%    \begin{macrocode}
\newcommand{\program}[1]{\gdef\ryethesis@program{#1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\prevDegreeA}
% \begin{macro}{\prevDegreeB}
% \begin{macro}{\prevDegreeC}
% \begin{macro}{\prevDegreeD}
% Up to four previous degrees can be specified by |\prevDegreeA| through |\prevDegreeD|, typically used with the most recent degree as degree A. A complete degree definition is the name, location, and year. This affects the title and abstract pages.
%    \begin{macrocode}
\newcommand{\prevDegreeA}[3]{%
\gdef\ryethesis@prevDegreeA{#1}\gdef\ryethesis@prevLocationA{#2}\gdef\ryethesis@prevYearA{#3}}
\newcommand{\prevDegreeB}[3]{%
\gdef\ryethesis@prevDegreeB{#1}\gdef\ryethesis@prevLocationB{#2}\gdef\ryethesis@prevYearB{#3}}
\newcommand{\prevDegreeC}[3]{%
\gdef\ryethesis@prevDegreeC{#1}\gdef\ryethesis@prevLocationC{#2}\gdef\ryethesis@prevYearC{#3}}
\newcommand{\prevDegreeD}[3]{%
\gdef\ryethesis@prevDegreeD{#1}\gdef\ryethesis@prevLocationD{#2}\gdef\ryethesis@prevYearD{#3}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}

% \begin{macro}{\partnerUniversity}
% Specify the partner university awarding the degree, if any. This affects the title and abstract pages.
%    \begin{macrocode}
\newcommand{\partnerUniversity}[1]{\gdef\ryethesis@partnerUniv{#1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\maketitle}
% A redefinition of the |\maketitle| command, structured according to SGS policy. Some fields, if empty are ignored.
%    \begin{macrocode}
\renewcommand{\maketitle}
{\begin{titlepage}
 %% Set the line spacing to 1 for the title page.
   \begin{spacing}{2}  
   \begin{large}
  \begin{center}
    \vfill
     {\LARGE\textsc{\@title}}\\
     \vfill%\vspace{2\baselineskip}
      by \\
     \vfill%\vspace{\baselineskip}
      {\@author}\\
      {\ifx\empty\ryethesis@prevDegreeA\else{\ryethesis@prevDegreeA, \ryethesis@prevLocationA, \ryethesis@prevYearA}\\\fi}
      {\ifx\empty\ryethesis@prevDegreeB\else{\ryethesis@prevDegreeB, \ryethesis@prevLocationB, \ryethesis@prevYearB}\\\fi}
      {\ifx\empty\ryethesis@prevDegreeC\else{\ryethesis@prevDegreeC, \ryethesis@prevLocationC, \ryethesis@prevYearC}\\\fi}
      {\ifx\empty\ryethesis@prevDegreeD\else{\ryethesis@prevDegreeD, \ryethesis@prevLocationD, \ryethesis@prevYearD}\\\fi}
     \vfill%\vspace{3\baselineskip}
     {A \ryethesis@documentType}\\
      {presented to Ryerson University}\\
      {\ifx\empty\ryethesis@partnerUniv\else{and \ryethesis@partnerUniv}\\\fi}
     \vspace{\baselineskip}
    {in partial fulfillment of the}\\
      {requirements for the degree of}\\
      {\ryethesis@degree}\\
      {in the Program of}\\
      {\ryethesis@program}\\
     \vfill
     {Toronto, Ontario, Canada, \ryethesis@degreeYear}\\
      {\copyright\@author~\ryethesis@degreeYear}\\
 \end{center}
 \end{large}
  \end{spacing}
  \end{titlepage}

}
%    \end{macrocode}
% \end{macro}


% \begin{macro}{\declaration}
% \begin{macro}{\ryethesis@insertdeclaration}
% The |\declaration| is used to define the authors declaration of sole authorship and Ryerson's right to reproduction and distribution of the document. Normally this will be inserted automatically by the |\ryethesis@insertdeclaration| command.
%    \begin{macrocode}
\newcommand{\declaration}{% Author declaration and release per SGS policy Sept. 2009.
 \begin{flushleft}
  I hereby declare that I am the sole author of this \ryethesis@documentType{}.\\
  \vspace{\baselineskip}
  I authorize Ryerson University to lend this \ryethesis@documentType{} to other institutions or individuals for the purpose of scholarly research.\\
  \vspace{0.75in}
  \hrule
  \vspace{0.75in}
  I further authorize Ryerson University to reproduce this \ryethesis@documentType{}  by photocopying or by other means, in total or in part, at the request of other institutions or individuals for the purpose of scholarly research.\\
  \vspace{0.75in}
  \hrule
\end{flushleft}
}
% If not in draft mode, insert the declaration on an new page.
\newcommand{\ryethesis@insertdeclaration}{%
\ifthenelse{\boolean{@ryedraft}}
{}
{\ryethesis@clearpage\declaration}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{\abstract}
% \begin{macro}{\ryethesis@insertabstract}
% This code will insert a UMI/ProQuest compatible abstract, double spaced as required. The |\abstract| command is redefined to set the content of the abstract variable |\ryethesis@theabstract|.
%    \begin{macrocode}
\newcommand{\abstract}[1]{\ifx\empty#1\else\gdef\ryethesis@theabstract{\begin{center}\section*{Abstract}\end{center}#1}\fi}
\newcommand{\ryethesis@insertabstract}{%
\ryethesis@clearpage
% A UMI/ProQuest compatible abstract
\begin{spacing}{2}
\begin{center}
\normalsize
\@title\\
\ryethesis@degree{} \ryethesis@degreeYear\\
\@author\\
\ryethesis@program\\
Ryerson University{\ifx\empty\ryethesis@partnerUniv\else{ and
    \ryethesis@partnerUniv}\fi}\\
\end{center}
%\begin{minipage}{\textwidth}
{\ifx\empty\ryethesis@theabstract{\begin{center}\textit{Abstract goes here!}\end{center}}\else\ryethesis@theabstract\fi}
%\end{minipage}
\end{spacing}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{\acknowledgements}
% \begin{macro}{\dedication}
% \begin{macro}{\ryethesis@insertacknowledgements}
% \begin{macro}{\ryethesis@insertdedication}
% The acknowledgements and dedication pages are both optional, and defined by the respective commands |\acknowledgements| and |\dedication|. Insertion of new pages for each, if not empty, is handled by the |\ryethesis@insertacknowledgements| and |\ryethesis@insertdedication| commands. None of the |\ryethesis@insert*| commands are intended to be called by the end user.
%    \begin{macrocode}

\newcommand{\acknowledgements}[1]{\ifx\empty#1\else\gdef\ryethesis@theacknowledgements{#1}\fi}

\newcommand{\ryethesis@insertacknowledgements}{%
\ifx\empty\ryethesis@theacknowledgements\else{
\ryethesis@clearpage
\begin{center}
\section*{Acknowledgements}
\end{center}
\ryethesis@theacknowledgements
}\fi
}

\newcommand{\dedication}[1]{\ifx\empty#1\else\gdef\ryethesis@thededication{#1}\fi}

\newcommand{\ryethesis@insertdedication}{%
\ifx\empty\ryethesis@thededication\else{
\ryethesis@clearpage
\begin{center}
\section*{Dedication}
\end{center}
\ryethesis@thededication
}\fi
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}

% \begin{macro}{\includelistoftables}
% \begin{macro}{\nolistoftables}
% \begin{macro}{\includelistoffigures}
% \begin{macro}{\nolistoffigures}
% \begin{macro}{\includelistofplates}
% \begin{macro}{\nolistofplates}
% \begin{macro}{\includelistofillustrations}
% \begin{macro}{\nolistofillustrations}
% \begin{macro}{\includelistofappendices}
% \begin{macro}{\nolistofappendices}
% \begin{macro}{\includenomenclature}
% \begin{macro}{\nonomenclature}
% \begin{macro}{\includeindex}
% \begin{macro}{\noindex}
% \begin{macro}{\includeglossary}
% \begin{macro}{\noglossary}
% The following |\include*| and |\no*| commands are intended to be called from the document preamble and toggle the same class options
%    \begin{macrocode}
\newcommand{\includelistoftables}{\setboolean{@ryelistoftables}{true}}
\newcommand{\nolistoftables}{\setboolean{@ryelistoftables}{false}}
\newcommand{\includelistoffigures}{\setboolean{@ryelistoffigures}{true}}
\newcommand{\nolistoffigures}{\setboolean{@ryelistoffigures}{false}}
\newcommand{\includelistofplates}{\setboolean{@ryelistofplates}{true}}
\newcommand{\nolistofplates}{\setboolean{@ryelistofplates}{false}}
\newcommand{\includelistofillustrations}{\setboolean{@ryelistofillustrations}{true}}
\newcommand{\nolistofillustrations}{\setboolean{@ryelistofillustrations}{false}}
\newcommand{\includelistofappendices}{\setboolean{@ryelistofappendices}{true}}
\newcommand{\nolistofappendices}{\setboolean{@ryelistofappendices}{false}}
\newcommand{\includenomenclature}{\setboolean{@ryenomenclature}{true}}
\newcommand{\nonomenclature}{\setboolean{@ryenomenclature}{false}}
\newcommand{\includeindex}{\setboolean{@ryeindex}{true}}
\newcommand{\noindex}{\setboolean{@ryeindex}{false}}
\newcommand{\includeglossary}{\setboolean{@ryeglossary}{true}}
\newcommand{\noglossary}{\setboolean{@ryeglossary}{false}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}

% A number of |\ryethesis@insert*| commands follow. Each command has a similar function, creating a new page with the necessary content (e.g. List of Figures, Table of Contents, etc). None of these commands are intended to be called by the end user.
%    \begin{macrocode}
\newcommand{\ryethesis@inserttoc}{
\ryethesis@clearpage
\tableofcontents
}

\newcommand{\ryethesis@insertlot}{
\ifthenelse{\boolean{@ryelistoftables}}{\ryethesis@clearpage\listoftables}{}
}

\ifthenelse{\boolean{@ryelistofplates}}
{\RequirePackage{float}\newfloat{plate}{h}{lop}}{}

\newcommand{\ryethesis@insertlop}{
\ifthenelse{\boolean{@ryelistofplates}}{\ryethesis@clearpage\listof{plate}{List of Plates}}{}
}

\newcommand{\ryethesis@insertlof}{
\ifthenelse{\boolean{@ryelistoftables}}{\ryethesis@clearpage\listoffigures}{}
}

\ifthenelse{\boolean{@ryelistofillustrations}}
{\RequirePackage{float}\newfloat{illustration}{h}{loi}}{}
 
\newcommand{\ryethesis@insertloi}{
\ifthenelse{\boolean{@ryelistofillustrations}}{\ryethesis@clearpage\listof{illustration}{List of Illustrations}}{}
}

\ifthenelse{\boolean{@ryelistofappendices}}
{
\newcommand{\nohyphens}{\hyphenpenalty=10000\exhyphenpenalty=10000\relax}
\newcommand{\listofappendices}{\chapter*{List of Appendices}\@starttoc{toa}}
}
{}

\newcommand{\ryethesis@insertloa}{%
\ifthenelse{\boolean{@ryelistofappendices}}{\ryethesis@clearpage\listofappendices}{}
}

\renewcommand{\appendix}[1]{\ifx\empty#1\else\gdef\ryethesis@theappendices{#1}\fi}

\newcommand{\ryethesis@insertappendix}{%
% If a list of appendices is requested, redirect the toc entries into a different file 
\ifx\empty\ryethesis@theappendices\else{
\ryethesis@clearpage
\renewcommand{\thechapter}{\Alph{chapter}}
\renewcommand{\chaptername}{Appendix}
\setcounter{chapter}{0}
\ryethesis@theappendices
}\fi
}

% Insert hyperref package, if not disabled by class option
\if@ryehyperref
\RequirePackage[pageanchor,hyperindex]{hyperref}
\RequirePackage{bookmark}
\fi

\ifthenelse{\boolean{@ryeglossary}}
{\RequirePackage[acronym,toc]{glossaries}\makeglossaries%
  %Glossaries prints a confusing warning
  \global\let\warn@noprintglossary\relax
}{}

\ifthenelse{\boolean{@ryeindex}}
{
%\RequirePackage{index}\makeindex
\RequirePackage{makeidx}\makeindex
\RequirePackage{multicol}
\renewenvironment{theindex}
               {\begin{multicols}{2}[\@makeschapterhead{\indexname}\addcontentsline{toc}{chapter}{\indexname}%
                \@mkboth{\MakeUppercase\indexname}%
                        {\MakeUppercase\indexname}]%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
               {\end{multicols}\clearpage}
}
{}

\ifthenelse{\boolean{@ryenomenclature}}{%
\RequirePackage{nomencl}
\renewcommand{\nomname}{List of Symbols}
\makenomenclature
}{}

\newcommand{\ryethesis@insertnom}{%
\ifthenelse{\boolean{@ryenomenclature}}{\ryethesis@clearpage\printnomenclature}{}
}

\newcommand{\ryethesis@insertreferences}{%
\ifx\emtpy\ryethesis@listofbibfiles
\else
 \ryethesis@clearpage\bibliography{\ryethesis@listofbibfiles}
 \addcontentsline{toc}{chapter}{\bibname}
\fi
}

\newcommand{\ryethesis@insertglossary}{%
\ifthenelse{\boolean{@ryeglossary}}
{\ryethesis@clearpage%
\printglossaries%glossaries.sty prints a false warning.
\global\let\warn@noprintglossary\relax%
}
{}
}

\newcommand{\ryethesis@insertindex}{%
\ifthenelse{\boolean{@ryeindex}}
{\ryethesis@clearpage%
\printindex
}
{}
}

%    \end{macrocode}

% \begin{macro}{\addtoreferences}
% As the position of bibliographic data is now more tightly controlled, it is necessary to provide the user with a command for specifying the bib input files. Each call to |\addtoreferences| will append another bib input file to the list of files to load. The user can specify the bibliography style in the document preamble as is normal. 
%    \begin{macrocode}
\newcommand{\addtoreferences}[1]{%
\ifx\empty\ryethesis@listofbibfiles\edef\ryethesis@listofbibfiles{#1}\else\edef\ryethesis@listofbibfiles{#1,\ryethesis@listofbibfiles}\fi
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\usebibliography}
% \begin{macro}{\usereferences}
% \begin{macro}{\useendnotes}
% These commands provide the user with an easy way of altering the heading of the bibliographic data.
%    \begin{macrocode}
\newcommand{\usebibliography}{\renewcommand{\bibname}{Bibliography}}
\newcommand{\usereferences}{\renewcommand{\bibname}{References}}
\newcommand{\useendnotes}{\renewcommand{\bibname}{End Notes}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}

% \begin{macrocode}
%Adjust |\addtocontents| to switch from toc to toa file if using List
%of Appendices
\newcommand{\Saved@addtocontents}{}
\let\Saved@addtocontents\addtocontents
\def\addtocontents#1#2{%
\if@ryethesismatchtoc%
{\ifthenelse{\equal{#1}{toc}}%
{\Saved@addtocontents{toa}{#2}}
{\Saved@addtocontents{#1}{#2}}}
\else
{\Saved@addtocontents{#1}{#2}}
\fi}
% \end{macrocode}

% Final commands to issue at the end of the class. In the case of draft mode, the line spacing is set to double spacing. In final mode, a line spacing of 1.5 is used, as required by SGS. The |\usereferences| command is used to label the bibliographic section as ``References'' by default.
%    \begin{macrocode}

\AtEndOfClass{
\ifthenelse{\boolean{@ryedraft}}
{% Draft mode uses double spacing
\doublespacing}
{% Final mode uses 1.5 spacing as specified in SGS policy Sept. 2009.
\onehalfspacing}
\usereferences
}
%    \end{macrocode}
% The |\AtBeginDocument| and |\AtEndDocument| are used to insert the front, main, and back matter in the correct place for the user. This tightly controls the order of appearance of each type of content.
%    \begin{macrocode}
% Insert front matter & mainmatter settings before user's material
\AtBeginDocument{
\frontmatter\mainmatter
}
% Insert back matter at the end
\AtEndDocument{\backmatter}
%    \end{macrocode}
% \Finale
\endinput
