% https://grad.wisc.edu/currentstudents/doctoralguide/

\ProvidesClass{dissertation}

% --- basic ---------------------------------------------------------------------------------------

% required: 10 to 12 point font

\LoadClass[11pt, twoside, openright]{report}
\RequirePackage[letterpaper, margin=1in]{geometry}  % 1 inch margins required
\RequirePackage{setspace}
\RequirePackage{afterpage}
\RequirePackage{xcolor}
\RequirePackage{array} 

% --- headers -------------------------------------------------------------------------------------

% required: page number in upper right, nothing else

\RequirePackage{fancyhdr}
\fancypagestyle{plain}{
	\fancyhf{}
	\fancyhead[R]{\thepage}
	\fancyfoot{}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{plain}{\rhead{\thepage}}

% --- text ----------------------------------------------------------------------------------------

% text
\RequirePackage[utf8]{inputenc}
\setlength\parindent{0pt}
\setlength{\parskip}{1em}
\renewcommand{\familydefault}{\sfdefault}

\newcommand{\RomanNumeral}[1]{\textrm{\uppercase\expandafter{\romannumeral #1\relax}}}
\RequirePackage{etoolbox}
\AtBeginEnvironment{verse}{\singlespacing}

\newenvironment{dquote}
  {
  \singlespacing
  \it
  }
  {
  }

\newcommand{\dsignature}[1]{\hfill \normalfont{-- #1}}
  
\RequirePackage[shortlabels]{enumitem}
\setlist[enumerate, 1]{nosep}
\setlist[enumerate, 2]{nosep, topsep=-5ex}
\setlist[enumerate, 3]{nosep, topsep=-5ex}
\setlist[enumerate, 4]{nosep, topsep=-5ex}
\newenvironment{denumerate}
  {
  \begin{enumerate}
  \singlespacing  
  }
  {
  \end{enumerate}
  }

\newenvironment{ditemize}
  {
  \begin{enumerate}
  \singlespacing  
  }
  {
  \end{enumerate}
  }  

% --- code environment ----------------------------------------------------------------------------

\RequirePackage{etoolbox}
\RequirePackage[section]{minted}
\usemintedstyle{colorfuli}
\setminted[python]{linenos=false, frame=none}

\definecolor{bg}{rgb}{0.95,0.95,0.95}

\setmintedinline[python]{bgcolor=bg}

\RequirePackage[many]{tcolorbox}
\tcbuselibrary{minted}

\NewTCBListing{codefragment}{mo}{%
  colback=bg,
  boxrule=1pt,
  colframe=bg,
  arc=0,
  shadow=false,
  boxsep=1ex, top=0pt, left=0pt, right=0pt, bottom=0pt,
  comment={\hfill(\arabic{chapter}.\arabic{equation})},
  listing outside comment,
  righthand width=2.5em,
  sidebyside gap=0pt,
  minted language=#1,
  before skip =-0.5\baselinestretch,
  after skip=2\baselinestretch,
}

\BeforeBeginEnvironment{codefragment}{\begin{singlespace}\stepcounter{equation}}
\AfterEndEnvironment{codefragment}{\end{singlespace}}

% --- tables --------------------------------------------------------------------------------------

\newenvironment{dtable}
  {
  \clearpage
  \begin{table}
  \centering
  }
  {
  \end{table}
  \clearpage
  }

% --- graphics ------------------------------------------------------------------------------------

\RequirePackage{graphics}
\RequirePackage{graphicx}
\RequirePackage{epsfig}
\RequirePackage{epstopdf}
\RequirePackage{etoc}
\RequirePackage{tikz}

\newenvironment{dfigure}
  {
  \clearpage
  \begin{figure}
  \centering
  }
  {
  \end{figure}
  \clearpage}

% --- math ----------------------------------------------------------------------------------------

\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage[cm]{sfmath}
\RequirePackage{bm} % bold mathtype
\DeclareMathOperator{\me}{e}

% --- misc / ? ------------------------------------------------------------------------------------

\RequirePackage[nottoc]{tocbibind}
\RequirePackage{fixltx2e}
\RequirePackage{pdfpages}
\RequirePackage[utf8]{inputenc}

% --- hyperref ------------------------------------------------------------------------------------

\RequirePackage[colorlinks=true, linkcolor=black, urlcolor=blue, citecolor=black,
anchorcolor=black]{hyperref}
\RequirePackage[all]{hypcap}  % helps hyperref work properly

% --- bibliography --------------------------------------------------------------------------------

\RequirePackage[backend=biber, natbib=true, sorting=none, maxbibnames=99, isbn=false]{biblatex}
\bibliography{bibliography}

% --- glossary ------------------------------------------------------------------------------------

\RequirePackage[acronym, nopostdot, nogroupskip]{glossaries}
\newcommand{\comma}{,\penalty \exhyphenpenalty}
\newlength\glsnamewidth
\setlength{\glsnamewidth}{0.3\hsize}
\setlength{\glsdescwidth}{1\hsize}
\newglossarystyle{myglossarystyle}{
	\setglossarystyle{super}
	\renewenvironment{theglossary}{
		\tablehead{}
		\tabletail{}
		\begin{supertabular}{p{\glsnamewidth}p{\glsdescwidth}}}{\end{supertabular}}
	\renewcommand{\glossentry}[2]{
		\raggedleft
		\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
		\glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline}}
\renewcommand{\arraystretch}{1}
\setglossarystyle{myglossarystyle}
\newglossary[slg]{symbolslist}{syi}{syg}{Symbols}
\makeglossaries
\include{glossary}

\RequirePackage{tocloft}
 
\setlength\cftparskip{0pt}
\setlength\cftbeforechapskip{-5pt}
\setlength\cftbeforesecskip{-7pt}
\setlength\cftbeforesubsecskip{-10pt}