% MIT thesis class

% !TEX encoding = UTF-8 Unicode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%  This file provides the mitthesis LaTeX class for formatting theses according to 
%%  MIT Libraries' requirements as of 2023.
%%
%%  This file's version and date:
	\def\versionno{1.06}
	\def\versiondate{2023/08/29\space}
%%
%%  Author: John H. Lienhard, V
%%          Department of Mechanical Engineering
%%          Massachusetts Institute of Technology
%%          Cambridge, MA 02139-4307 USA
%%
%%  This class is compatible with either pdfLaTeX or LuaTeX. 
%%
%%	Use an up-to-date LaTeX distribution: TeX Live 2023 or later is strongly recommended!
%%	All packages required by the class are in TeX Live and available on CTAN (https://ctan.org/). 
%%
%%
% =========================================================
%%
%% LICENSE:
%%
%% Copyright (c) 2023 John H. Lienhard
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
%% associated documentation files (the "Software"), to deal in the Software without restriction, 
%% including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
%% and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
%% subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in all copies or 
%% substantial portions of the Software.
%%
%% The software is provided "as is", without warranty of any kind, express or implied, including but 
%% not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. 
%% In no event shall the authors or copyright holders be liable for any claim, damages or other liability, 
%% whether in an action of contract, tort or otherwise, arising from, out of or in connection with the 
%% software or the use or other dealings in the software.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mitthesis}[\versiondate MIT Thesis Template (JHL)]

\LoadClass[12pt,openright]{report}% [twoside] option can be issued in the .tex file; point size must be set here.

\ExplSyntaxOn
  \str_const:Nn \ClassName {mitthesis}
\ExplSyntaxOff

\RequirePackage{iftex}[2019/11/07]% provides \ifpdftex, etc.

%%%%%%%%%%%%%  Some compatibility for older latex distributions  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}% compare version to date; \If... added to latex 2020/10/01
\providecommand\IfPackageAtLeastTF{\@ifpackagelater}%    compare version to date; \If... added to latex 2020/10/01

\IfFormatAtLeastTF{2020/02/25}{%
	\typeout{^^JYour LaTeX format is dated \fmtversion. LaTeX distributions from 2022/11/01 or later are strongly recommended for best results^^J}
	}{%
	\ClassError{\ClassName}{Your LaTeX format is dated \fmtversion.  Formats dated 2022/11/01 or later are strongly recommended for this class. Older formats may generate errors}{Please UPDATE your LaTeX distribution to obtain best results. TeX Live is available for download at no charge: \string https://www.tug.org/texlive/.  You can try to click past the errors for now...}%
}

% check whether pdfmanagement (\DocumentMetadata) has been loaded (if not, fall back to hyperxmp)
\newif\ifmit@pdfmanagement
% As of 2021/07/23 we could instead do:\IfPDFManagementActiveTF{\mit@pdfmanagementtrue}{\mit@pdfmanagementfalse}
\ExplSyntaxOn
    \IfFormatAtLeastTF{2020/02/25}{%
        \bool_if:nTF
          {
            \bool_lazy_and_p:nn
              { \cs_if_exist_p:N \pdfmanagement_if_active_p: }
              { \pdfmanagement_if_active_p: }
          }
          { \mit@pdfmanagementtrue  }
          { \mit@pdfmanagementfalse }
     }{     \mit@pdfmanagementfalse }
\ExplSyntaxOff

% Enable pre-2020/10 formats to access essential macros later moved into LaTeX kernel
\ifdefined\NewDocumentCommand\else
  \RequirePackage{xparse}
\fi

%% Pre-2020/02 installations may need textcomp to be loaded, but we require only the copyright character:
\ifdefined\textcopyright\else
    \ifpdftex
    	\DeclareTextSymbol{\textcopyright}{TS1}{'251}
    	\DeclareTextSymbolDefault{\textcopyright}{TS1}
    \else
    	\newcommand*\textcopyright{\Uchar"00A9}
    \fi
\fi

%%%%%%%%%%%%%% Options for the class %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\IfFormatAtLeastTF{2022/11/01}{%
%	\typeout{^^JUsing native keyvalue support^^J}% diagnostic info
    \DeclareKeys{
    	fontset .store 	= \mit@fontset ,
    	fontset .usage 	= load ,
		lineno  .if		= mit@lineno ,
		lineno 	.usage	= load ,
		mydesign .if	= mit@mydesign,
		mydesign .usage	= load ,
    } 
    \SetKeys[\ClassName]{fontset=defaultfonts}%
	\DeclareUnknownKeyHandler[\ClassName]{\relax}% suppress warning about unused keys
	\ProcessKeyOptions
}{% Compatibility code for distributions pre-2022/11     
    \RequirePackage{kvoptions}
    \SetupKeyvalOptions{
      family=\ClassName,
      prefix=mit@,
      setkeys=\kvsetkeys,
    }
    % set key [fontset] for font selection
    \DeclareStringOption[defaultfonts]{fontset}[]
    %
    % set key [lineno] to load package lineno
    \DeclareBoolOption{lineno}
    %
    % set key [mydesign] to input file mydesign.tex
    \DeclareBoolOption{mydesign}
    %
    \ProcessKeyvalOptions{\ClassName}
    %
    %% Turn off these keys now that we're done with them
    \NewDocumentCommand\mit@DisableOption{m}{%
      \DisableKeyvalOption[%
        action=ignore,%
        class=\ClassName%
      ]{#1}{\ClassName}%
    }
    \NewDocumentCommand\mit@DisableKeys{>{\SplitList{;}}m}{\ProcessList{#1}{\mit@DisableOption}}
    %
    \mit@DisableKeys{fontset;lineno;mydesign}%
    %
    %% Suppress warnings about unused global options
    \DeclareOption*{}  
    \ProcessOptions \relax
}


%%%%%%%%%%%%%  Line numbering (class option)  %%%%%%%%%%%%%%%%%%%%%%%%%

%%% Adjustments when lineno option is used
\ifmit@lineno
    \RequirePackage[mathlines]{lineno}    
    \renewcommand{\linenumberfont}{\normalfont\footnotesize\color{red}} 
    \AtBeginDocument{\linenumbers}
\fi

%%% Enable dropping lineno option without trashing .aux file
\providecommand{\@LN@col}[1]{\relax}
\providecommand{\@LN}[2]{\relax}


%%%%%%%%%%%%%  Patch table of contents, list of figures, and list of tables  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\RequirePackage{etoolbox}% provides \patchcmd

% We'd like these sections to have pdf bookmarks and to have the two lists appear in the table of contents

\patchcmd{\tableofcontents}{\@starttoc{toc}}{\pdfbookmark[0]{Table of Contents}{toc}\@starttoc{toc}}{}{}
\patchcmd{\listoffigures}{\chapter*{\listfigurename}}{\chapter*{\listfigurename}\addcontentsline{toc}{chapter}{\protect\textbf{\listfigurename}}}{}{}
\patchcmd{\listoftables}{\chapter*{\listtablename}}{\chapter*{\listtablename}\addcontentsline{toc}{chapter}{\protect\textbf{\listtablename}}}{}{}


%%%%%%%%%%%%%  Geometry, mathtools, design, graphics, bibliography, hyperrefs, bookmarks, footnotes %%%%%%%%%%%%

\RequirePackage[letterpaper,top=1in,bottom=1in,left=1in,right=1in,marginparwidth=50pt,headsep=12pt,footskip=0.5in]{geometry}

\RequirePackage{mathtools}% loads and extends amsmath; must load before hyperref and unicode-math
%
% To free \eqref from the normal font (i.e., for use section headings)
\renewcommand{\eqref}[1]{\textup{\hbox{\m@th{(\ignorespaces\ref{#1}\unskip\@@italiccorr)}}}}
%
% amsmath def:  \newcommand{\eqref}[1]{\textup{\tagform@{\ref{#1}}}}
%				\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}
%				\def\maketag@@@#1{\hbox{\m@th\normalfont#1}}

% the packages in mydesign should come before babel (which may be loaded by fontset) and before hyperref
\ifmit@mydesign
	\IfFileExists{mydesign.tex}{\input{mydesign.tex}}{%
	\ClassError{\ClassName}{Missing file mydesign.tex. This file is necessary when using the class option [mydesign] }{%
			You have called the class option mydesign, but the file mydesign.tex is not found.  You can download a copy of that file from
			https://ctan.org/tex-archive/macros/latex/contrib/mitthesis/MIT-thesis-template.}%  
	}%
\else
	% options for xcolor
	\ifpdftex
		\def\MyColorOption{fixpdftex}\else
		\ifluatex\def\MyColorOption{luatex}\else
			\ifxetex\def\MyColorOption{xetex}\else
				\def\MyColorOption{}
			\fi
		\fi
	\fi
	\RequirePackage[hyperref,\MyColorOption,dvipsnames,svgnames,x11names]{xcolor}
%
	\RequirePackage{caption,subcaption}
%
    \RequirePackage{titlesec}    
    % these titlesec commands just automate the bold math in some headings (rest follows default styles)
    \titleformat{\section}{\mathversion{bold}\normalfont\Large\bfseries}{\thesection }{1em}{}
    \titleformat{\subsection}{\mathversion{bold}\normalfont\large\bfseries}{\thesubsection}{1em}{}
    \titleformat{\subsubsection}{\mathversion{bold}\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}    
    % ==> NOT every font includes a bold math version, so you may need to use other math macros in the headings to get bold math <==   	
\fi

%% Font loading %%%%%%%%%%
\typeout{^^JFontset key is \mit@fontset.^^J}
\IfFileExists{fontsets/\ClassName-\mit@fontset.tex}{% 2023/07/03
	\input{fontsets/\ClassName-\mit@fontset.tex}
}{%
	\ClassWarning{\ClassName}{^^JFontset file \ClassName-\mit@fontset.tex not found, using default fonts.}
	\ifpdftex
    	\typeout{^^JLoading Computer Modern text and math fonts (default for pdftex).^^J}
    	\RequirePackage[T1]{fontenc}
    	\RequirePackage{bm}
    \else
    	\typeout{^^JLoading Latin Modern text and math fonts (default for unicode engines).^^J}
        \RequirePackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
        % suppress tiresome warnings about lack of integration between mathtools and unicode-math.
        % Unicode-math loads fontspec package, but default fonts are not selected by fontspec in this case.
    \fi
}

\RequirePackage{graphicx}

\ifmit@pdfmanagement
	\ClassInfo{\ClassName}{pdfmanagement is defined. Will not load hyperxmp}%
\else
    \ClassInfo{\ClassName}{pdfmanagement is not defined. Will load hyperxmp}%
    \RequirePackage{hyperxmp}
\fi

\RequirePackage[psdextra]{hyperref}
% the new pdf-management scheme loads the bookmarks package internally.
% authors should use hypersetup to set details, in root .tex file

\urlstyle{same} 		% this changes font for \url to the current text font
\providecommand\hrefurl[2]{\href{#1}{#2}}% in case \DocumentMetadata has not been loaded
\RequirePackage{doi} 	% create macro for hyperlinking doi numbers

% the user can override all these design choices in the preamble, 
% or by using \AtBeginDocument{ \hypersetup{..} } in mydesign.tex 
\hypersetup{
    colorlinks=true,
	linkcolor=Blue3,% from xcolor package
	citecolor=Blue3,% from xcolor package
	urlcolor=violet,% from xcolor package
	filecolor=red, 
%	anchorcolor=yellow,% not all pdf viewers recognize this field (although Firefox does): hyperref issues a warning
%	colorscheme=phelype,% overrides link, cite, url, file colors with a preset scheme, through \DocumentMetadata
 	pdfborder={0 0 0},
	bookmarksnumbered=true,
	bookmarksopen=true,
	bookmarksopenlevel=1,
%	pdfpagemode=UseNone,% this option means don't open bookmarks panel
	pdfpagelayout=SinglePage,
	pdfdisplaydoctitle=true,
	pdfstartview=Fit,
	pdfnewwindow=true,
%
	pdfcontactaddress={Massachusetts Institute of Technology, 77 Massachusetts Avenue},
    pdfcontactcity={Cambridge, MA},
    pdfcontactpostcode={02139-4307},
    pdfcontactcountry={USA},
    pdfcontacturl={https://dspace.mit.edu/handle/1721.1/7582},% DSPACE@MIT theses page
}
 		
%%%%%%%%%%%%% Stuff related to PDF bookmarks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Since \bm may be useful in headings, this fix will reduce frequency with which
%%%    alternate pdfstrings must be given in revised section command as \section[pdfstring]{texstring}
\pdfstringdefDisableCommands{%
    \def\bm#1#{\relax}%
}
%%% Let's disable \( and \) in pdf bookmarks
\pdfstringdefDisableCommands{%
    \def\({\relax}%
    \def\){\relax}%
}
%%% Let's also make sure \NoCaseChange in section headings won't break pdf bookmarks
\pdfstringdefDisableCommands{%
    \let\NoCaseChange\relax%
}
%%% Let's just remove citations from pdf bookmarks
\pdfstringdefDisableCommands{%
    \def\cite{\@gobble}%
}
%%% Let's fix \eqref in pdf bookmarks
\pdfstringdefDisableCommands{%
    \def\eqref#1{(\ref{#1})}%
}
%%% Let's make sure footnotes in section headings don't break pdf bookmarks. (Note: redefined \footnote below is protected)
% \patchcmd{\section}{\sectionmark}{\let\footnote\@gobble\sectionmark}{}{}% <== not needed unless you implement running heads
\pdfstringdefDisableCommands{%
  \def\footnote#1{}%
}


\ExplSyntaxOn
%\debug_on:n {all}

%%%%%%%%%%  Put comma between successive footnotes %%%%%%%%%%%%%%%%%%%%%%%%%%% 

\cs_new:Npn   \__mitthesis_NoteComma:n { \peek_meaning:NTF \footnote {\textsuperscript{\mdseries,}} { } }
\cs_new_eq:NN \__savefootnote \footnote
\cs_gset_protected:Npn \footnote #1    { \__savefootnote{#1}\__mitthesis_NoteComma:n } 
	
%%%%%%%%%%  End Footnote comma  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%  MACROS FOR HANDLING TITLE AND ABSTRACT PAGES  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%  Degree Date Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\tl_new:N \g__dd_month_tl	
\tl_new:N \g__dd_year_tl
\cs_generate_variant:Nn \msg_error:nnn {nne}
\cs_generate_variant:Nn \str_casefold:n {e}
\cs_generate_variant:Nn \tl_gremove_all:Nn {No}
\cs_new_protected:Nn \__dd_setdates:nn {
	\tl_gset:Nn \g__dd_month_tl {#1}
	\tl_gset:Nn \g__dd_year_tl  {#2}
	\tl_gremove_all:No \g__dd_month_tl { \space }
	\tl_gremove_all:No \g__dd_year_tl { \space }
 	\str_case_e:nnF 
		{ \str_casefold:e { \tl_to_str:N  \g__dd_month_tl } }
	 	{ {february}{} {may}{} {june}{} {september}{}}
		{ \msg_error:nne {\ClassName} {wrong_month} { \text_titlecase:n {\g__dd_month_tl} } } 
}
\msg_new:nnnn {\ClassName} {wrong_month} {The\ degree\ month\ must\ be\ one\ of\ February,\ May,\ June,\ or\ September.} {You\ cannot\ use\ #1\ as\ the\ degree\ month.}

\cs_generate_variant:Nn \text_titlecase:n {o,V}
\NewDocumentCommand\DegreeDate{mm}{%   {month}{year}	
	\__dd_setdates:nn {#1}{#2}
	\cs_new:Npn \DegreeMonth { \text_titlecase:V { \g__dd_month_tl } }
	\cs_new:Npn \DegreeYear  { \text_titlecase:V { \g__dd_year_tl  } }
}
\msg_new:nnnn {\ClassName} {no_degree_date} {Missing\ degree\ date!}{
			You\ MUST\ issue\ the\ \DegreeDate{month}{year}\ command\ between\ \string\begin{document}\ and\ \string\maketitle.}
		
\NewDocumentCommand\ThesisDate{m}{
	\tl_if_exist:NTF \g_dd_thesisdate_tl { \g_dd_thesisdate_tl } { \__dd_thesisdate:n {#1} }% will use only value given first
}
\cs_new_protected:Nn \__dd_thesisdate:n {
	\tl_new:N  \g_dd_thesisdate_tl
	\tl_gset:Nx \g_dd_thesisdate_tl { \tl_trim_spaces:n {#1} }
}

%%%%%%%%%%  End Degree Date Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Author Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\seq_new:N \g_author_name_seq
\seq_new:N \g_author_department_seq
\seq_new:N \g_author_prevdegree_seq
\seq_new:N \g_author_secondprevdegree_seq
\seq_new:N \g_author_thirdprevdegree_seq
\seq_new:N \g_author_fourthprevdegree_seq
\int_gzero_new:N \g_author_authorcnt_int

\NewDocumentCommand\Author{mm O{}O{}O{}O{} }
 {
 	\tl_if_blank:nTF{#1}{
		\msg_error:nn {\ClassName} {blank_author}
		}{
		  \__author_data_add:nnnnnn { #1 } { #2 } { #3 } { #4 } { #5 } { #6 }
		}
	\tl_if_blank:nTF{#2}{\msg_error:nn {\ClassName} {blank_author_dep}}{}
 }
\cs_new_protected:Nn \__author_data_add:nnnnnn
 {
	\int_gincr:N \g_author_authorcnt_int
	\seq_gput_right:cx  { g_author_name_seq }        { \tl_trim_spaces:n {#1} } 
	\seq_gput_right:cx  { g_author_department_seq }  { \tl_trim_spaces:n {#2} }
	\seq_gput_right:cx  { g_author_prevdegree_seq }  { \tl_trim_spaces:n {#3} }
	\seq_gput_right:cx  { g_author_secondprevdegree_seq } { \tl_trim_spaces:n {#4} }
	\seq_gput_right:cx  { g_author_thirdprevdegree_seq }  { \tl_trim_spaces:n {#5} }
	\seq_gput_right:cx  { g_author_fourthprevdegree_seq } { \tl_trim_spaces:n {#6} }
 }
\msg_new:nnnn {\ClassName} {blank_author} {Missing\ author\ name,\ check\ for\ blank\ in\ \Author\ command.}{%
			You\ MUST\ provide\ an\ author\ name\ using\ the\ \Author{name}{department}\ command.}
\msg_new:nnnn {\ClassName} {blank_author_dep} {Missing\ author\ department,\ check\ for\ blank\ in\ \Author\ command.}{%
			You\ MUST\ provide\ the\ author's\ department\ using\ the\ \Author{name}{department}\ command.}

\NewExpandableDocumentCommand\CopyrightAuthor{}{
	\tl_if_exist:NTF \g__author_ca_tl
		{ \g__author_ca_tl }
		{ \__author_copyrightauthor: \g__author_ca_tl }
}

\cs_new_protected:Nn \__author_copyrightauthor: {
	\tl_new:N       \g__author_ca_tl
	\int_zero_new:N \l__author_autcrcnt_int
	\int_incr:N     \l__author_autcrcnt_int
    \tl_gset:Nx     \g__author_ca_tl  { \seq_item:cn { g_author_name_seq } { \l__author_autcrcnt_int } }
	\int_incr:N     \l__author_autcrcnt_int
	\int_while_do:nNnn { \l__author_autcrcnt_int } < { \g_author_authorcnt_int }
		{
			\tl_gput_right:Nx \g__author_ca_tl {,\ \seq_item:cn { g_author_name_seq } { \l__author_autcrcnt_int } }
			\int_incr:N \l__author_autcrcnt_int   
		}
	\int_compare:nNnT { \l__author_autcrcnt_int } = { \g_author_authorcnt_int } {
  	    \tl_gput_right:Nx \g__author_ca_tl {\ and\ \seq_item:cn { g_author_name_seq } { \l__author_autcrcnt_int } }
	}
	\tl_set:Nn \l_tmpa_tl {\tl_item:Nn \g__author_ca_tl {-1} }% get last token
 	\str_case_e:nnT 
		{ \l_tmpa_tl  }
	 	{ {.}{} }
		{ \__copyright_remove_period:N { \g__author_ca_tl } }% remove last token if it is a period 
	\__author_pdfcopyrightauthor:
}
\cs_new:Nn \__copyright_remove_period:N
	{
		\tl_gset:Nx #1 { \tl_range:Nnn #1 { 1 } { \tl_count:N #1 - 1 } }
	}
\cs_new_protected:Nn \__author_pdfcopyrightauthor: {
	\tl_new:N       \g__author_pdfca_tl
	\int_set:Nn     \l_tmpa_int {1}
    \tl_gset:Nx     \g__author_pdfca_tl  { { \seq_item:cn { g_author_name_seq } { \l_tmpa_int } } }
	\int_until_do:nNnn { \l_tmpa_int } = { \g_author_authorcnt_int }
		{
			\int_incr:N \l_tmpa_int   
			\tl_gput_right:Nx \g__author_pdfca_tl {,\ { \seq_item:cn { g_author_name_seq } { \l_tmpa_int } } }
		}	
}


\cs_new:Nn \__author_block: {
	\int_zero_new:N \l__author_authorno_int
	\int_incr:N     \l__author_authorno_int
	\int_compare:nNnTF { \g_author_authorcnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_author}
	}	
	{by\par
	\int_until_do:nNnn { \l__author_authorno_int } = { \g_author_authorcnt_int } {
		\seq_item:cn { g_author_name_seq } { \l__author_authorno_int } \par
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_prevdegree_seq } { \l__author_authorno_int} }
		\tl_if_empty:NF \l_tmpa_tl { \normalsize \l_tmpa_tl }% no linebreak or par for empty items
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_secondprevdegree_seq } { \l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl  }
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_thirdprevdegree_seq } { \l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl  }
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_fourthprevdegree_seq } { \l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl  }
		\par and\par
		\int_incr:N \l__author_authorno_int
	}
		\seq_item:cn { g_author_name_seq } { \l__author_authorno_int } \par
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_prevdegree_seq } { \l__author_authorno_int} }
		\tl_if_empty:NF \l_tmpa_tl { \normalsize \l_tmpa_tl }% no linebreak or par for empty items
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_secondprevdegree_seq } { \l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl }
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_thirdprevdegree_seq } { \l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl  }
		\tl_set:Nx \l_tmpa_tl { \seq_item:cn { g_author_fourthprevdegree_seq } {\l__author_authorno_int} } 
		\tl_if_empty:NF \l_tmpa_tl { \linebreak\normalsize \l_tmpa_tl  }
    	\par\medskip 
    }
}
\msg_new:nnnn {\ClassName} {no_author}
		{ Missing\ author!\ You\ must\ issue\ the\ \Author{name}{department}\ command. }{
		You\ MUST\ issue\ the\ \Author{name}{department}\ command\ after\ \string\begin{document}\ and\ before\ \string\maketitle. }

\cs_new:Nn \__author_abstractblock: {
	\int_zero_new:N \l__author_authorno_int
	\int_incr:N     \l__author_authorno_int
	\int_compare:nNnTF { \g_author_authorcnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_author}
		}	
		{by\par
		\int_until_do:nNnn { \l__author_authorno_int } = { \g_author_authorcnt_int } {
			\seq_item:cn { g_author_name_seq } { \l__author_authorno_int }
			\par and\par
			\int_incr:N \l__author_authorno_int
		}%
		\seq_item:cn { g_author_name_seq } { \l__author_authorno_int } 
    }%
}

%%%%%%%%%%  End Author Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Supervisor Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\seq_new:N \g_supervisor_name_seq
\seq_new:N \g_supervisor_title_seq
\int_gzero_new:N \g_supervisor_supervisorcnt_int

\NewDocumentCommand\Supervisor{mm}{
	\tl_if_blank:nTF{#1}{
		\msg_error:nn {\ClassName} {blank_supervisor}
		}{
		\__supervisor_data_add:nn { #1 } { #2 }
	}
	\tl_if_blank:nTF{#2}{\msg_error:nn {\ClassName} {blank_supervisor_title}}{}
}
\msg_new:nnnn {\ClassName} {blank_supervisor}
		{ Missing\ supervisor\ name, check\ for\ blank\ in\ \Supervisor{name}{title}\ command.}{
			You\ MUST\ provide\ the\ supervisor's\ name\ using\ the\ \Supervisor{name}{title}\ command.}
\msg_new:nnnn {\ClassName} {blank_supervisor_title}
		{ Missing\ supervisor\ title, check\ for\ blank\ in\ \Supervisor{name}{title}\ command. }{
			You\ MUST\ provide\ the\ supervisor's\ title\ using\ the\ \Supervisor{name}{title}\ command.}

\cs_new_protected:Nn \__supervisor_data_add:nn
 {
	\int_gincr:N \g_supervisor_supervisorcnt_int
	\seq_gput_right:cx  { g_supervisor_name_seq }       { \tl_trim_spaces:n {#1} } 
	\seq_gput_right:cx  { g_supervisor_title_seq } { \tl_trim_spaces:n {#2} }
 }


\cs_new:Nn \__supervisor_abstractblock: {
	\int_zero_new:N \l__supervisor_supervisorno_int
	\int_incr:N     \l__supervisor_supervisorno_int
	\setlength{\parindent}{0pt}
	\par\bigskip
	\int_compare:nNnTF { \g_supervisor_supervisorcnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_supervisor}
		}	
		{\int_until_do:nNnn { \l__supervisor_supervisorno_int } = { \g_supervisor_supervisorcnt_int } {
			Thesis\ supervisor:\space \seq_item:cn { g_supervisor_name_seq } { \l__supervisor_supervisorno_int }\par
			Title:\space              \seq_item:cn { g_supervisor_title_seq } { \l__supervisor_supervisorno_int }\par\medskip
			\int_incr:N \l__supervisor_supervisorno_int
		}
			Thesis\ supervisor:\space  \seq_item:cn { g_supervisor_name_seq } { \l__supervisor_supervisorno_int }\par
			Title:\space  \seq_item:cn { g_supervisor_title_seq } { \l__supervisor_supervisorno_int }\ignorespaces
    }
}
\msg_new:nnnn {\ClassName} {no_supervisor}
		{ Missing\ supervisor!\ You\ must\ issue\ the\ \Supervisor{name}{title}\ command. }{
		You\ MUST\ issue\ the\ \Supervisor{name}{title}\ command\ after\ \string\begin{document}\ and\ before\ \string\maketitle. }


%%%%%%%%%%  End Supervisor Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Acceptor Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\seq_new:N \g_acceptor_name_seq
\seq_new:N \g_acceptor_department_seq
\seq_new:N \g_acceptor_title_seq
\int_gzero_new:N \g_acceptor_acceptorcnt_int

\bool_new:N \g__acceptor_title_tf_bool
\bool_gset_false:N \g__acceptor_title_tf_bool

\NewDocumentCommand\Acceptor{mmm}{
	\tl_if_blank:nTF{#1}{
		\msg_error:nn {\ClassName} {blank_acceptor}
		}{
		\__acceptor_data_add:nnn {#1} {#2} {#3}
	}
	\tl_if_blank:nTF{#2}{\msg_error:nn {\ClassName} {blank_acceptor_dep}}{}
	\tl_if_blank:nTF{#3}{
		\bool_gset_true:N \g__acceptor_title_tf_bool
		\msg_warning:nn {\ClassName} {blank_acceptor_title}}{}
}
\msg_new:nnnn {\ClassName} {blank_acceptor}
		{ Missing\ acceptor\ name, check\ for\ blank\ in\ \Acceptor{name}{department}{title}\ command.}{
			You\ MUST\ provide\ the\ acceptor's\ name\ using\ the\ \Acceptor{name}{department}{title}\ command.}
\msg_new:nnnn {\ClassName} {blank_acceptor_dep}
		{ Missing\ acceptor\ department, check\ for\ blank\ in\ \Acceptor{name}{department}{title}\ command. }{
			You\ MUST\ provide\ the\ acceptor's\ department\ using\ the\ \Acceptor{name}{department}{title}\ command.}
\msg_new:nnn {\ClassName} {blank_acceptor_title}
		{ Missing\ acceptor\ title\ (blank\ in\ \Acceptor{name}{department}{title}\ command).\ Perhaps\ you\ are\ trying\ to\ save\ vertical\ space?\ 			You\ can\ put\ the\ acceptor\ title\ into\ department\ field\ instead.\ For\ consistency,\ I\ will\ omit\ titles\ of\ ALL\ acceptors.}

\cs_new_protected:Nn \__acceptor_data_add:nnn
 {
	\int_gincr:N \g_acceptor_acceptorcnt_int
	\seq_gput_right:cx  { g_acceptor_name_seq }       { \tl_trim_spaces:n {#1} } 
	\seq_gput_right:cx  { g_acceptor_department_seq } { \tl_trim_spaces:n {#2} }
	\seq_gput_right:cx  { g_acceptor_title_seq }      { \tl_trim_spaces:n {#3} }
 }

%%%%%%%%%%  End Acceptor Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Degree Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\seq_new:N \g_degree_name_seq
\seq_new:N \g_degree_department_seq
\int_gzero_new:N \g_degree_degreecnt_int
\int_gzero_new:N \g__degree_degreeflag_int

\NewDocumentCommand\Degree{mm}
 {
	\tl_if_blank:nTF {#1} {
		\msg_error:nn {\ClassName} {blank_degree}
		}{
		  \__degree_data_add:nn { #1 } { #2 } 
		}
	\tl_if_blank:nT {#2} {
		\int_gset_eq:NN \g__degree_degreeflag_int \g_degree_degreecnt_int
		\msg_warning:nnx {\ClassName} {blank_degree_dep} { \int_to_arabic:n { \g__degree_degreeflag_int } }
		\tl_if_blank:nT {#1} { \int_gincr:N \g__degree_degreeflag_int }% in case both are blank
		}
 }
\cs_new_protected:Nn \__degree_data_add:nn
 {
	\int_gincr:N \g_degree_degreecnt_int
	\seq_gput_right:cx  { g_degree_name_seq }        { \tl_trim_spaces:n {#1} } 
	\seq_gput_right:cx  { g_degree_department_seq }  { \tl_trim_spaces:n {#2} }
 }
\msg_new:nnnn {\ClassName} {blank_degree} {Missing\ degree\ name,\ check\ for\ blank\ in\ \Degree\ command.} 
			{You\ MUST\ provide\ a\ degree\ name\ using\ the\ \Degree{name}{department}\ command.}
\msg_new:nnnn {\ClassName} {blank_degree_dep} {Missing\ degree\ department\ for\ Degree\ command\ number\ 
			#1.\ Will\ treat\ as\ a\ duplicate\ of\ previous\ department.}{}
		
\int_zero_new:N \l__degree_degreeno_int
\int_zero_new:N \l__degree_departmentno_int

\cs_new:Nn \__degree_block: {
	\int_compare:nNnTF { \g_degree_degreecnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_degree}
	}	
	\int_zero_new:N \l__degree_degreeno_int
	\int_incr:N     \l__degree_degreeno_int
	\int_zero_new:N \l__degree_departmentno_int
	\int_incr:N     \l__degree_departmentno_int
	\cs_new:Nx \__degree_prevdept: {\seq_item:cn { g_degree_department_seq } { \l__degree_departmentno_int } }
	\cs_new:Nn \__degree_currdept: {}
	\mbox {Submitted\ to\ the\ } \mbox {\__degree_prevdept:}
	\int_until_do:nNnn { \l__degree_departmentno_int } = { \g_degree_degreecnt_int } {
		\int_incr:N      \l__degree_departmentno_int
		\cs_set:Nx \__degree_currdept: {\seq_item:cn { g_degree_department_seq } { \l__degree_departmentno_int } }
		\int_compare:nNnTF { \l__degree_departmentno_int } = {\g__degree_degreeflag_int } { \scan_stop: } 
			{
				\mbox {\ and\ the}\linebreak
				\mbox {\__degree_currdept: }
			}
		}
    \linebreak \mbox {in\ partial\ fulfillment\ of\ the\ requirements\ for\ the\ 
		\int_compare:nNnTF { \g_degree_degreecnt_int } > {1} {degrees} {degree}
	\ of}
	\par\medskip
	\int_until_do:nNnn { \l__degree_degreeno_int } = { \g_degree_degreecnt_int } {
    	\text_uppercase:n {\seq_item:cn { g_degree_name_seq } { \l__degree_degreeno_int }}\par and\par
		\int_incr:N     \l__degree_degreeno_int
		}
    \text_uppercase:n {\seq_item:cn { g_degree_name_seq } { \l__degree_degreeno_int }}\par\medskip
}
\msg_new:nnnn {\ClassName} {no_degree}
		{ Missing\ degree!\ You\ must\ issue\ the\ \Degree{name}{department}\ command. }{
		You\ MUST\ issue\ the\ \Degree{name}{department}\ command\ after\ \string\begin{document}\ and\ before\ \string\maketitle.\  You\ do\ want\ the\ degree,\ don't\ you?}


\cs_new:Nn \__degree_abstractblock: {
	\int_set:Nn  \l__degree_degreeno_int {1}
	\int_set:Nn  \l__degree_departmentno_int {1}
	\cs_set:Nx \__degree_prevdept: {\seq_item:cn { g_degree_department_seq } { \l__degree_departmentno_int } }
	\cs_set:Nn \__degree_currdept: {}
	\mbox {Submitted\ to\ the\ }\mbox{\__degree_prevdept:}
	\int_until_do:nNnn { \l__degree_departmentno_int } = { \g_degree_degreecnt_int } {
		\int_incr:N     \l__degree_departmentno_int
		\cs_set:Nx \__degree_currdept: {\seq_item:cn { g_degree_department_seq } { \l__degree_departmentno_int } }
		\int_compare:nNnTF { \g__degree_degreeflag_int } = { \g_degree_degreecnt_int } { \scan_stop: } 
			{
				\mbox {\ and\ the}\linebreak
				\mbox { \__degree_currdept: }
			}
		}
    \linebreak \mbox{on\ \g_dd_thesisdate_tl\ in\ partial\ fulfillment\ of\ the\ requirements\ for\ the\ 
		\int_compare:nNnTF { \g_degree_degreecnt_int } > {1} {degrees} {degree}
	\ of}
	\par\medskip
	\int_until_do:nNnn { \l__degree_degreeno_int } = { \g_degree_degreecnt_int } {
    	\text_uppercase:n {\seq_item:cn { g_degree_name_seq } { \l__degree_degreeno_int }}\par and\par
		\int_incr:N     \l__degree_degreeno_int
		}
    \text_uppercase:n {\seq_item:cn { g_degree_name_seq } { \l__degree_degreeno_int }}\par\medskip
}

%%%%%%%%%%  End Degree Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Signature Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NewDocumentCommand\SignatureBlockSize{m}{
	\__signature_sigsize:n {#1}
}
\tl_new:N \g__signature_sigsize_tl
\cs_new_protected:Nn \__signature_sigsize:n 
  {
	\tl_gset:Nf \g__signature_sigsize_tl { \tl_trim_spaces:n {#1} }
	\token_case_meaning:NnF \g__signature_sigsize_tl
	{ 
		\normalsize {} \small {} \footnotesize{} \scriptsize{} \tiny{}
	} {
		\msg_error:nn {\ClassName} {weird_sigsize}
	}
  }

\cs_new:Nn \__signature_block: {
	\int_compare:nNnT { \g_supervisor_supervisorcnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_supervisor}% this message is def'd in Abstract supervisor block
	}	
	\int_compare:nNnT { \g_acceptor_acceptorcnt_int } = {0} {
		\msg_error:nn {\ClassName} {no_acceptor}
	}	
	\tl_if_exist:NF \g_dd_thesisdate_tl { 
		\msg_error:nn {\ClassName} {no_thesis_date}
	}
	\int_gzero_new:N \g__signature_autno_int
	\int_gzero_new:N \g__signature_supno_int
	\int_gzero_new:N \g__signature_accno_int
    \g__signature_sigsize_tl
    \begin{tabbing}
    \hspace{1.35in} \= \hspace{1in} \kill
	\int_do_while:nNnn { \g__signature_autno_int } < { \g_author_authorcnt_int } {
		\int_gincr:N  \g__signature_autno_int
		Authored\ by: \> \seq_item:cn { g_author_name_seq } { \g__signature_autno_int } \\  
		\> \seq_item:cn { g_author_department_seq } { \g__signature_autno_int } \\
		\> \g_dd_thesisdate_tl \\[1em]
	}
	\int_do_while:nNnn { \g__signature_supno_int } < { \g_supervisor_supervisorcnt_int } {
		\int_gincr:N  \g__signature_supno_int
		Certified\ by: \> \seq_item:cn { g_supervisor_name_seq } { \g__signature_supno_int } \\
		\> \seq_item:cn { g_supervisor_title_seq } { \g__signature_supno_int },\ Thesis\ Supervisor\\[1em]
	}
	\int_compare:nNnF { \g_acceptor_acceptorcnt_int } = {0} {
    	\int_do_while:nNnn { \g__signature_accno_int } < { \g_acceptor_acceptorcnt_int } {
    		\int_gincr:N  \g__signature_accno_int
    		Accepted\ by: \> \seq_item:cn { g_acceptor_name_seq } { \g__signature_accno_int } \\
    		\> \seq_item:cn { g_acceptor_department_seq } { \g__signature_accno_int }
    			\bool_if:NF \g__acceptor_title_tf_bool
    			{
    				\\
    				\> \seq_item:cn { g_acceptor_title_seq } { \g__signature_accno_int }
    			}
    		\\[1em]
    	}
	}
	\end{tabbing}
}
\msg_new:nnnn {\ClassName} {weird_sigsize}
		{ \SignatureBlockSize\ expects\ a\ font-sizing\ command,\ such\ as\ \small,\ \footnotesize,\ etc.}{You\ used\ a\ weird\ input\ value\ 			here.\ If\ you\ did\ so\ deliberately,\ try\ continuing.}	
\msg_new:nnnn {\ClassName} {no_acceptor}
		{ Missing\ acceptor!\ You\ must\ issue\ the\ \Acceptor{name}{department}{title}\ command. }{
		You\ MUST\ issue\ the\ \Acceptor{name}{department}{title}\ command\ after\ \string\begin{document}\ and\ before\ \string\maketitle.}
\msg_new:nnnn {\ClassName} {no_thesis_date}
		{ Missing\ thesis\ date!\ You\ must\ issue\ the\ \ThesisDate{Date\ thesis\ is\ submitted}\ command.}{
		You\ MUST\ issue\ the\ \ThesisDate{Date thesis is submitted}\ command\ after\ \string\begin{document}\ and\ before\ \string\maketitle.}

% If for some reason you don't want a warning when you omit \Acceptor
\NewDocumentCommand\SuppressAcceptorError{}
  {
  	\msg_redirect_name:nnn { \ClassName } { no_acceptor } { none }
  }

%%%%%%%%%%  End Signature Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Copyright Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Directly add the xmp property that shows work is copyrighted. See l3pdfmeta.pdf. 
% This is not automatic with \DocumentMetadata. "True" must be capitalized.
%
\cs_if_exist:NTF \pdfmeta_xmp_add:n {\pdfmeta_xmp_add:n{<xmpRights:Marked>True</xmpRights:Marked>}}{}

\tl_new:N \g_copyright_ccname_tl
\tl_new:N \g_copyright_cclicensetext_tl
\tl_new:N \g_copyright_copyrightlicencse_tl
\tl_new:N \g_copyright_pdfrightstext_tl
\tl_new:N \g__copyright_crwords_tl_
\tl_new:N \g__copyright_mitpermissionlast_tl

\tl_new:N \g_copyright_mitpermission_tl
\tl_gset:Nn \g__copyright_mitpermissionlast_tl {to\ MIT\ a\ nonexclusive,\ worldwide,\ irrevocable,\ royalty-free\ license\ to\ exercise\ any\ and\ all\ rights\ under\ copyright,\ including\ to\ reproduce,\ preserve,\ distribute\ and\ publicly\ display\ copies\ of\ the\ thesis,\ or\ release\ the\  thesis\ under\ an\ open-access\ license.}

\bool_new:N \g__cclicense_tf_bool
\bool_gset_false:N \g__cclicense_tf_bool

\NewDocumentCommand\CClicense{mm}{
	\__copyright_licensedata:nn {#1}{#2}
%	\def\CCurl{ \tl_trim_spaces:n {#2} }% for backward compatibility with v1.05, if necessary
}
\cs_new_protected:Nn \__copyright_licensedata:nn 
  {
	\tl_gset:Nf \g_copyright_cclicensetext_tl {\hrefurl{ \tl_trim_spaces:n {#2} }{ \tl_trim_spaces:n {#1} } }% #1 - text, #2 - url  
	\tl_gset:Nx \g_copyright_ccname_tl        { \tl_trim_spaces:n {#1} } 
	\bool_gset_true:N \g__cclicense_tf_bool
	\cs_if_exist:NT \pdfmeta_xmp_add:n {
			\pdfmeta_xmp_add:n {<xmpRights:WebStatement>#2</xmpRights:WebStatement>}
	}
	\msg_note:nnx {\ClassName} {cclicense} { \text_expand:n {\g_copyright_ccname_tl} }
  }
\msg_new:nnn {\ClassName} {cclicense} { Using\ Creative\ Commons\ License\ #1.}


%%%%%%%%%%  End Copyright Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Title page Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RenewDocumentCommand{\title}{m}
	{
		\__mitthesis_title:n { #1 }
		\hypersetup{
			pdftitle={\g_mitthesis_title_tl},
		}
	}
%
\tl_new:N \g_mitthesis_title_tl
%
\cs_new_protected:Nn \__mitthesis_title:n
	{
		\tl_gset:Nn \g_mitthesis_title_tl { \tl_trim_spaces:n {#1} }
	}

\tl_new:N \g_titlepage_institution_name_tl
\tl_gset:Nn \g_titlepage_institution_name_tl {Massachusetts\ Institute\ of\ Technology} 
\cs_new:Npn \Institution #1 { \tl_gset:Nn \g_titlepage_institution_name_tl {\tl_trim_spaces:n #1} }


\RenewDocumentCommand\maketitle{s}{%
	\cs_if_exist:NTF \DegreeMonth { \scan_stop: } { \msg_error:nn {\ClassName} {no_degree_date} }% msg defined in degree-date section
%	
	\bool_if:NTF \g__cclicense_tf_bool { 
		\tl_gset:Nn \g_copyright_copyrightlicencse_tl 
			{This\ work\ is\ licensed\ under\ a\ \mbox{\g_copyright_cclicensetext_tl}\ license.\par\g_copyright_mitpermission_tl}
		\tl_gset:Nn \g_copyright_pdfrightstext_tl 	 
			{This\ work\ is\ licensed\ under\ a\ \g_copyright_ccname_tl\ license.\ \g_copyright_mitpermission_tl}
	}{
		\tl_gset:Nn \g_copyright_copyrightlicencse_tl 
			{All\ rights\ reserved. \par\g_copyright_mitpermission_tl}
		\tl_gset:Nn \g_copyright_pdfrightstext_tl 	 
			{All\ rights\ reserved.\ \g_copyright_mitpermission_tl}
   }
   \int_compare:nNnTF {\g_author_authorcnt_int} > {1} 
   		{   
			\tl_gset:Nn \g__copyright_crwords_tl_ {The\ authors\ hereby\ grant} 
		}
		{
			\tl_gset:Nn \g__copyright_crwords_tl_ {The\ author\ hereby\ grants} 
		}
    \IfBooleanTF{#1}{%
	    \tl_gset:Nn \g_copyright_mitpermission_tl {\scan_stop:}
    }{
	    \tl_gset:Nn \g_copyright_mitpermission_tl {\g__copyright_crwords_tl_\ \g__copyright_mitpermissionlast_tl}
    }
% 
	\clearpage
	\thispagestyle{empty}%
	\phantomsection\addcontentsline{toc}{chapter}{\protect\textbf{Title page}}%
 	{\centering \vbox_to_ht:nn { \vsize }% to prevent signature block from breaking across page
        {
            \setlength{\parskip}{0.5\baselineskip plus 2pt minus 2pt}\setlength{\parindent}{0pt}%
            {\Large\textbf{\g_mitthesis_title_tl}\par}
            \__author_block:
            \par
            \__degree_block:
            at\ the\par
            \text_uppercase:n { \g_titlepage_institution_name_tl }\par
            \DegreeMonth\ \DegreeYear
            \par
            \copyright\space\DegreeYear\space\CopyrightAuthor\@.\c_space_token \g_copyright_copyrightlicencse_tl % In case name ends with III, IV, V,...
            \par
            \skip_vertical:n {\baselineskip}
            %
            \__signature_block:
        	\vfill % to avoid overstretched glue
		}
	}%
    	\hypersetup{
    		pdfcopyright={Copyright\ ©\ \DegreeYear\ by\ \CopyrightAuthor.\ \g_copyright_pdfrightstext_tl},
    		pdfauthor={\g__author_pdfca_tl},
    		pdfcaptionwriter = {\g__author_pdfca_tl},
    	}
	\cleardoublepage
}

%%%%%%%%%%  End title page module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  Abstract page Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% to change abstract name, follow either of these approaches in your preamble:
%	\RenewExpandableDocumentCommand\abstractname{}{Summary}
%	\renewcommand\abstractname{Summary}

\RenewDocumentEnvironment{abstract}{+b}{
	\newpage
	\phantomsection\addcontentsline{toc}{chapter}{\protect\textbf{\abstractname}}
    \begin{center}
        {\large{\textbf{\g_mitthesis_title_tl}}\par}
        \setlength{\parskip}{0.5\baselineskip plus 2pt minus 2pt}
        \__author_abstractblock:
        \par
        \__degree_abstractblock:
	\end{center}
    \skip_vertical:n {\baselineskip}
	\textbf{ \text_uppercase:n {\abstractname} }\par
	\skip_vertical:n { 0.5em }
	\tl_trim_spaces:n {#1}
	\tl_if_blank:nT {#1} { MISSING\ ABSTRACT!  \msg_error:nn { \ClassName } { missing_abstract } }
}{
	\__supervisor_abstractblock:
	\cleardoublepage
}
\msg_new:nnnn {\ClassName} { missing_abstract } {Missing\ Abstract!! } { No\ file\ was\ input\ for\ the\ abstract.\  You\ need\ to\ do\ \string\input{abstract.tex}.}

%%%%%%%%%%  End abstract page Module  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\debug_off:n {all}
\ExplSyntaxOff

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% End title and abstract page codes  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%  A nomenclature environment  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\providecommand{\nomname}{Nomenclature}  
\newlength\nomenwidth
\newlength\savitemsep

% nomenclature entries
\NewDocumentCommand\entry{m m}{%
    \item[#1\hfill]#2%
    \@itempenalty=-\@lowpenalty
}
% nomenclature subheadings 
\NewDocumentCommand\EntryHeading{m}{%
	\itemsep3\p@ plus 1\p@ minus 1\p@
    \goodbreak\item[\itshape#1\hfill]\setlength\itemsep\savitemsep\@itempenalty=1000
}
%
%   Increase first optional argument to a dimension > 2em if wide entries cause undesired misalignment of columns. 
%   Second optional argument can be used to rename the environment, e.g., to List of Symbols.
%   Third optional argument selects section-level or chapter-level style for the nomenclature list.
\NewDocumentEnvironment{nomenclature}{O{2em} O{\nomname} O{section}}{%
    \setlength\columnsep{2em} 
    \setlength{\nomenwidth}{#1}
    \csname #3\endcsname *{#2}% this level will vary amongst users!
	\phantomsection\addcontentsline{toc}{#3}{#2}%
    \raggedright
    \begin{list}{}{%
         \setlength{\itemsep}{0pt}%
         \setlength{\parsep}{\itemsep}%
         \setlength{\labelsep}{1em}%
         \setlength{\labelwidth}{\nomenwidth}%
         \setlength{\leftmargin}{\labelwidth}%
         \addtolength{\leftmargin}{\labelsep}%
		 \setlength\savitemsep\itemsep%
    }%
}{\end{list}\ignorespacesafterend}


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

\endinput
%%
%% End of file `mitthesis.cls'.
