\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{microstructure}

\RequirePackage[letterpaper]{geometry}
\geometry{
	top	= 1in,
	bottom	= 1in,
	left	= 1in,
	right	= 1in
}

\RequirePackage{graphicx,amsmath,amssymb,ulem}

\newlength{\unit}
\setlength{\unit}{12bp}

\setlength{\parindent}{0bp}
\setlength{\parskip}{\unit}

\renewcommand{\normalsize}{\fontsize{12bp}{18bp}\selectfont}
\newcommand{\footnotesize}{\fontsize{9bp}{12bp}\selectfont}

\newcommand{\tiny}{\normalsize}
\newcommand{\scriptsize}{\normalsize}
\newcommand{\small}{\normalsize}
\newcommand{\large}{\normalsize}
\newcommand{\Large}{\normalsize}
\newcommand{\LARGE}{\normalsize}
\newcommand{\huge}{\normalsize}
\newcommand{\Huge}{\normalsize}

\RequirePackage[quiet]{mathspec}
\RequirePackage{realscripts}
\RequirePackage{microtype}
\defaultfontfeatures{
	Language	= English,
	Script		= Latin
}
\newcommand{\case}{\addfontfeature{Letters=Uppercase}}
\setmainfont{Neue Haas Grotesk Text Pro}[
	BoldFont 	= NHaasGroteskTXPro-75Bd,
	ItalicFont	= NHaasGroteskTXPro-56It, 
	Mapping 	= tex-text,
	StylisticSet 	= {1,3},
	Contextuals	= Alternate
]
\newfontfamily\display{Neue Haas Grotesk Display Pro}[
	BoldFont 	= NHaasGroteskDSPro-75Bd,
	ItalicFont	= NHaasGroteskDSPro-56It, 
	Mapping		= tex-text,
	StylisticSet 	= {1,3},
	Contextuals	= Alternate
]
\setmonofont{JetBrains Mono}
\setmathfont(Latin)[Uppercase=Plain,Lowercase=Plain,Arabic=Plain]{Neue Haas Grotesk Text Pro}
\renewcommand{\bold}[1]{{\bfseries #1}}
\newcommand{\italic}[1]{{\itshape #1}}
\newcommand{\mono}[1]{{\ttfamily #1}}

\RequirePackage{returntogrid}
\returntogridsetup{
	step	= 0.5\unit,
	offset	= 0bp
}
\newcommand{\reset}{\returntogrid}
\newcommand{\resetv}[1]{\rule{0bp}{0bp}\vspace{#1}\reset}

\renewcommand{\ULthickness}{1bp}

\newcommand{\inmath}[1]{{\fontsize{15bp}{12bp}\selectfont $#1$}}

\newcommand{\section}[1]{{\fontsize{32bp}{36bp}\selectfont \bfseries \display #1 \par}}
\newcommand{\subsection}[1]{{\fontsize{24bp}{24bp}\selectfont \bfseries \display #1 \par}}
\newcommand{\subsubsection}[1]{{\fontsize{16bp}{18bp}\selectfont \bfseries \display #1 \par}}

\newcommand{\hr}{\vspace{-1.5\unit}\reset\rule{\textwidth}{0.5bp}\vspace{-0.5\unit}\par}

\@ifundefined{thepage}{\def\thepage{\arabic{page}}}{}
\RequirePackage[hidelinks]{hyperref}
\newcommand{\link}[2]{{\bfseries\href{#1}{#2}}{{\ttfamily\textsuperscript* ↗}}}

\RequirePackage[hang,multiple]{footmisc}
\renewcommand\footnoterule{\smash{\rule[4bp]{2in}{0.5bp}}}
\renewcommand{\hangfootparskip}{\unit}
\renewcommand{\footnotemargin}{\unit}
\setlength{\skip\footins}{\unit}

\newenvironment{description}{}{}
\RequirePackage{enumitem}
\setlist[itemize,enumerate]{
	align		= parleft,
	labelsep	= 1.5\unit,
	leftmargin	= \labelsep
}
\setlist[itemize,1]{label=\raisebox{1bp}{$\bullet$}}
\setlist[itemize,2]{label=\raisebox{1bp}{$\circ$}}
\setlist[itemize,3]{label=\raisebox{1bp}{$\diamond$}}
\newcommand{\labelenumi}{\theenumi.}
\newcommand{\labelenumii}{\theenumii.}
\newcommand{\labelenumiii}{\theenumiii.}
\renewcommand{\theenumi}{\@arabic\c@enumi}
\renewcommand{\theenumii}{\@Alph\c@enumii}
\renewcommand{\theenumiii}{\@Roman\c@enumiii}
\setlist[description]{
	align		= left,
	labelsep	= \unit,
	labelwidth	= \dimexpr1in-\labelsep,
	leftmargin	= \labelsep
}

\RequirePackage{listings}
\lstdefinestyle{code}{
	basicstyle		= \ttfamily,
	tabsize			= 4,
	breaklines, breakatwhitespace,
	breakindent		= 0bp,
	aboveskip		= \dimexpr1.5\unit-1.5bp,
	belowskip		= 0bp,
	frame			= single,
	xleftmargin		= \unit,
	xrightmargin		= \unit,
	framesep		= 0bp,
	framextopmargin		= \dimexpr\unit-0.5bp,
	framexbottommargin	= \dimexpr0.5\unit+0.5bp,
	framexleftmargin	= \unit,
	framexrightmargin	= \unit,
	framerule		= 0.5bp
}
\lstdefinestyle{enum}{
	numbers			= right,
	numbersep		= -0.5\unit,
	numberstyle		= {\textsuperscript}
}
\lstnewenvironment{codeblock}[1][]{\lstset{style=code,#1}}{}
\lstnewenvironment{codeblockenum}[1][]{\lstset{style=code,style=enum,#1}}{}
\newcommand{\inputblock}[2][]{\lstinputlisting[style=code,#1]{#2}}
\newcommand{\inputblockenum}[2][]{\lstinputlisting[style=code,style=enum,#1]{#2}}

\setlength{\abovedisplayskip}{0bp}
\setlength{\belowdisplayskip}{0bp}
\renewenvironment{math}{
	\begingroup
	\fontsize{15bp}{12bp}\selectfont
	\setlength{\jot}{\unit}
	\nonumber\align
}{
	\endalign\endgroup
}

\RequirePackage{tabularx}
\setlength{\arrayrulewidth}{0.5bp}
\setlength{\tabcolsep}{6bp}
\renewcommand{\arraystretch}{1.666667}
\newcolumntype{x}{>{\raggedright\arraybackslash}X}
\newenvironment{table}[1]{
	\vspace{-0.5\unit}\hspace{\unit}\tabularx{\dimexpr\textwidth-2\unit}{#1}
}{
	\endtabularx\par
}

\newcommand{\aligntwo}{\hspace{0.5\textwidth}\=\kill}
\newcommand{\alignthree}{\hspace{0.333333\textwidth}\=\hspace{0.333333\textwidth}\=\kill}
\newcommand{\alignfour}{\hspace{0.25\textwidth}\=\hspace{0.25\textwidth}\=\hspace{0.25\textwidth}\=\kill}

\setkeys{Gin}{
	width = \textwidth,
	height = \dimexpr\textheight-6\unit,
	keepaspectratio
}
\renewcommand{\caption}[1]{\\{\footnotesize\italic{#1}}\vspace{1.5\unit}}
\newenvironment{figure}{
	\setlength{\parskip}{1.5\unit}\centering
}{
	\par
}

\RequirePackage{lastpage,datetime2}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\DTMnewdatestyle{yyyymmdd}{\renewcommand{\DTMdisplaydate}[4]{\number##1\DTMtwodigits{##2}\DTMtwodigits{##3}}}
\DTMsetdatestyle{yyyymmdd}
\renewcommand{\headruleskip}{2bp}
\renewcommand{\footruleskip}{0bp}
\renewcommand{\headrulewidth}{0bp}
\renewcommand{\footrulewidth}{0bp}
\setlength{\headheight}{\unit}
\setlength{\headsep}{\unit}
\setlength{\topmargin}{\dimexpr 0bp-\headsep-\headheight}
\setlength{\footskip}{\dimexpr \headsep+0.5\unit}
\fancyhead[R]{\raisebox{0.666667bp}{\case\footnotesize \today--\hspace{0bp}--\hspace{0bp}--\hspace{0bp}--\@author}}
\fancyfoot[C]{}
\fancyfoot[R]{\case\footnotesize \thepage/\pageref{LastPage}}

\RequirePackage{tikz,eso-pic}
\DeclareOption{debug}{
	\AddToShipoutPicture{\begin{tikzpicture}[overlay,remember picture]
		\draw[black!30!white,thin,shift={(current page.north west)}]
		(current page.north west) grid[step=0.5\unit]
		(current page.south east);
	\end{tikzpicture}}
}
\DeclareOption{fleqn}{
	\AtBeginDocument{\@mathmargin1.5\unit\relax}
}
\DeclareOption{nohf}{
	\fancyhead[L,C,R]{}
	\fancyfoot[L,C,R]{}
}
\ProcessOptions\relax

% vim:ft=tex
