% topic guide
\documentclass[$if(fontsize)$$fontsize$,$endif$]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage[math-style=french]{unicode-math}
    $if(mathfont)$
      \setmathfont{$mathfont$}[Scale=MatchLowercase]
    $endif$
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Scale=MatchLowercase}
    $if(mainfont)$
      \setmainfont[]{$mainfont$}
    $endif$
    $if(monofont)$
      \setmonofont[]{$monofont$}
    $endif$
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[usegeometry,DIV=calc]{typearea}
\usepackage[letterpaper,textwidth=6.5in,textheight=9in,lmargin=1in,tmargin=1in,footskip=0.5in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdftitle={$title$},
            pdfborder={0 0 0},
            breaklinks=true,
            linktocpage,
            linktoc=all,
            colorlinks=true,
            citecolor=.,
            linkcolor=.,
            urlcolor=[HTML]{D7263D}}
\urlstyle{same}  % don't use monospace font for urls

\usepackage{xcolor}

\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}

% code blocks
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}

\usepackage{longtable,booktabs,dcolumn}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage[normalem]{ulem}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 0pt minus 0pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}
\usepackage{moresize}

% Create subtitle command for use in maketitle
%\newcommand{\HRule}[1][\medskipamount]{\par
%  \vspace*{\dimexpr-\parskip-\baselineskip+#1}
%  \noindent\rule{\linewidth}{0.2mm}\par
%  \vspace*{\dimexpr-\parskip-.5\baselineskip+#1}}

% Create command for searching substrings
\makeatletter
\def\instring#1#2{TT\fi\begingroup
  \edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}
\makeatother

% Define color for rule on front page
\if\instring{DLM}{$program$}
\definecolor{progcolor}{RGB}{91,155,213}
\else
  \if\instring{I-SMART}{$program$}
  \definecolor{progcolor}{RGB}{38,92,179}
  \else
    \if\instring{ATLAS}{$program$}
    \definecolor{progcolor}{RGB}{22,91,126}
    \else
    \definecolor{progcolor}{RGB}{0,0,0}
    \fi
  \fi
\fi

\definecolor{measrdarkblue}{RGB}{2,48,71}
\definecolor{measrmediumblue}{RGB}{33,158,188}
\definecolor{measrlightblue}{RGB}{142,202,230}

%\newcommand{\subtitle}[1]{
%  \posttitle{
%    \begin{flushleft}{\color{progcolor}}\mdseries\LARGE#1\end{flushleft}
    %\begin{center}{\color{progcolor}}\mdseries\LARGE#1\end{center}
%    }
%}
\newfontfamily\headingfont[]{Playfair Display}
\setlength{\droptitle}{-2em}

  \title{$title$}
    \pretitle{\vspace{\droptitle}\color{measrdarkblue}\huge\raggedleft\headingfont}
    %\pretitle{\vspace{\droptitle}\centering\Huge\bfseries\emph}
  \posttitle{\par}

  %\subtitle{$subtitle$}

  \author{}
    \preauthor{}
  \postauthor{}

  \date{$date$}
    \predate{\normalsize\color{black}\raggedleft}
    %\predate{\centering\large\bfseries}
  \postdate{\par\vspace{-1.5em}}


\usepackage{float}
\usepackage{tabu}
\usepackage{caption}
\usepackage{setspace}
\usepackage{makecell}
\usepackage{colortbl}
\usepackage{hhline}
\raggedbottom
\raggedright

% page breaks before each section
\usepackage{titlesec}
%\newcommand{\sectionbreak}{\clearpage}

% footnote formatting
\interfootnotelinepenalty=10000
\usepackage[bottom,hang,ragged]{footmisc}
\setlength\footnotemargin{1em}

% references
\usepackage[natbib=true,style=apa]{biblatex}
\ExecuteBibliographyOptions{sortcites}
\DeclareFieldFormat{doi}{%
  \url{https://doi.org/#1}}
\DeclareFieldFormat{eprint:arXiv}{%
  arXiv\addperiod\space\url{https://arxiv.org/abs/#1}}

$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
\DeclareLanguageMapping{english}{american-apa}

% roman pages
\newenvironment{romanpages}
{\cleardoublepage\setcounter{page}{1}\renewcommand{\thepage}{\roman{page}}}
{\cleardoublepage\setcounter{page}{1}\renewcommand{\thepage}{\arabic{page}}}

% watermark
$if(watermark)$
  \usepackage{draftwatermark}
  \SetWatermarkColor[HTML]{FE7E7E}
  % \SetWatermarkLightness{.9}
  \SetWatermarkText{$watermark$}
$endif$

% $if(internal)$
%   \usepackage[firstpage]{draftwatermark}
%   \SetWatermarkLightness{.8}
%   \SetWatermarkFontSize{3cm}
%   \SetWatermarkText{\shortstack{DO NOT\\DISTRIBUTE}}
% $endif$

% table and figure numbering
\usepackage{pdflscape}
\usepackage{threeparttable}
\usepackage{threeparttablex}

\usepackage{subcaption}
\usepackage[singlelinecheck=false]{caption}
\DeclareCaptionFormat{tabformat}{#1#2\par#3}
\DeclareCaptionFormat{figformat}{#1#2\par#3}
\DeclareCaptionFormat{subformat}{#1#2#3}
\renewcommand\thesubfigure{\Alph{subfigure}}
\captionsetup[figure]{name={Figure},format=figformat,labelsep=none,labelfont=bf,textfont=it,parskip=6pt plus 0pt minus 0pt}
\captionsetup[table]{name={Table},format=tabformat,labelsep=none,labelfont=bf,textfont=it,parskip=6pt plus 0pt minus 0pt}
\captionsetup[subfigure]{format=subformat,labelformat=simple,labelsep=space,labelfont=normalfont}
\renewcommand{\eqref}[1]{\textup{\ref{#1}}}

% toc formatting
\usepackage{tocloft}
\tocloftpagestyle{front}
\renewcommand{\cfttoctitlefont}{\hfill\LARGE\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftlottitlefont}{\hfill\LARGE\bfseries}
\renewcommand{\cftafterlottitle}{\hfill}
\renewcommand{\cftloftitlefont}{\hfill\LARGE\bfseries}
\renewcommand{\cftafterloftitle}{\hfill}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}
\renewcommand\cftsecdotsep{\cftdot}
\renewcommand\cftsubsecdotsep{\cftdot}
\renewcommand\cftsubsubsecdotsep{\cftdot}
\renewcommand\cftparadotsep{\cftdot}
\renewcommand\cfttabdotsep{\cftdot}
\renewcommand\cftfigdotsep{\cftdot}

\makeatletter
\renewcommand{\@tocrmarg}{2.55em plus1fil}
\makeatletter

% title styles
\titleformat{\section}{\color{measrmediumblue}\Large\headingfont}{}{0pt}{}
\titlespacing*{\section}{0pt}{6pt plus 0pt minus 0pt}{0pt plus 0pt minus 0pt}

\titleformat{\subsection}{\color{measrlightblue}\large\headingfont}{}{0pt}{}
\titlespacing*{\subsection}{0pt}{6pt plus 0pt minus 0pt}{0pt plus 0pt minus 0pt}

\titleformat{\subsubsection}{\color{measrmediumblue}\normalsize\headingfont}{}{0pt}{}
\titlespacing*{\subsubsection}{0pt}{3pt plus 0pt minus 0pt}{0pt plus 0pt minus 0pt}

\titleformat{\paragraph}{\bfseries\large}{\theparagraph. }{0pt}{}
\titlespacing*{\paragraph}{0pt}{10pt}{-6pt plus 0pt minus 0pt}

\titleformat{\subparagraph}{\bfseries\itshape\large}{\thesubparagraph. }{0pt}{}
\titlespacing*{\subparagraph}{0pt}{10pt}{-6pt plus 0pt minus 0pt}

% changemargin definition
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist

% redefine hyperlinks
%\let\oldhref\href
%\renewcommand{\href}[2]{#2\footnote{\url{#1}}}

% page styles
\usepackage{fancyhdr}
\lhead{}
\chead{}
\rhead{}
\renewcommand{\headrulewidth}{0pt}
\lfoot{}
\cfoot{}
\rfoot{}

\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ -- \ #1}}

\fancypagestyle{plain}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL PROJECT REVIEW ONLY}
  $endif$
    \fancyfoot[R]{\thepage}
}
\fancypagestyle{front}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL PROJECT REVIEW ONLY}
  $endif$
  \fancyfoot[R]{\thepage}
  \fancyhead[L]{\includegraphics[width=2in]{figures/pre-generated/measr-letterhead.png}}
}

\newcommand*{\useportrait}{%
  \clearpage
  \KOMAoptions{paper=portrait,DIV=current}%switch to portrait
  \newgeometry{margin=1in,footskip=0.5in}%
  \fancyhfoffset{0pt}% <- recalculate head and foot width for fancyhdr
}
\newcommand*{\uselandscape}{%
  \clearpage
  \KOMAoptions{paper=landscape,DIV=current}%switch to landscape
  \newgeometry{margin=1in,footskip=0.5in}%
  \fancyhfoffset{0pt}% recalculate head and foot width for fancyhdr
}

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}{Lemma}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{proposition}{Proposition}[section]
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}[section]
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{solution}{Solution}

\begin{document}
\pagestyle{plain}
\noindent\raisebox{0mm}[0pt][0pt]{\rlap{\makebox[\textwidth][l]{\includegraphics[width=3in]{figures/pre-generated/measr-letterhead.png}}}}
{\let\newpage\relax\maketitle}

\pagenumbering{arabic}

$body$

\end{document}
