% 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{Ligatures=TeX,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}
\urlstyle{same}  % don't use monospace font for urls

\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}

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

%%% Implement shading for echo = TRUE
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\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}}}}


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

% 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{dlmcolor}{RGB}{54,95,145}
\definecolor{dlmcolor2}{RGB}{79,129,189}

%\newcommand{\subtitle}[1]{
%  \posttitle{
%    \begin{flushleft}{\color{progcolor}}\mdseries\LARGE#1\end{flushleft}
    %\begin{center}{\color{progcolor}}\mdseries\LARGE#1\end{center}
%    }
%}

\setlength{\droptitle}{-2em}

  \title{$title$}
    \pretitle{\vspace{\droptitle}\color{dlmcolor}\LARGE\bfseries}
    %\pretitle{\vspace{\droptitle}\centering\Huge\bfseries\emph}
  \posttitle{\par}

  %\subtitle{$subtitle$}

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

  \date{$date$}
    \predate{\color{black}}
    %\predate{\centering\large\bfseries}
  \postdate{\par}


\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[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{dlmcolor}\Large\bfseries}{}{0pt}{}
\titlespacing*{\section}{0pt}{8pt plus 0pt minus 0pt}{0pt plus 0pt minus 0pt}

\titleformat{\subsection}{\color{dlmcolor2}\large\bfseries}{}{0pt}{}
\titlespacing*{\subsection}{0pt}{8pt plus 0pt minus 0pt}{0pt plus 0pt minus 0pt}

\titleformat{\subsubsection}{\color{dlmcolor}\bfseries\normalsize}{}{0pt}{}
\titlespacing*{\subsubsection}{0pt}{8pt 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}}

% program name for header
\if\instring{DLM}{$program$}
\newcommand{\progName}{Dynamic Learning Maps}
\else
\newcommand{\progName}{$program$}
\fi

\fancypagestyle{plain}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
    \fancyfoot[R]{\thepage}
  $endif$
}
\fancypagestyle{front}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
  $endif$
  \fancyfoot[R]{\thepage}
}
\fancypagestyle{norm}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  \renewcommand{\headrulewidth}{0pt}%
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
  $endif$
  \fancyfoot[R]{\thepage}
  \fancyhead[R]{\progName{}}
}

\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
}

% column environment for PLD tables
\newenvironment{cols}[1][]{}{}

\newenvironment{col}[1]{\begin{minipage}[t]{#1}\ignorespaces\vspace{0pt}}{%
\end{minipage}
\ifhmode\unskip\fi
\aftergroup\useignorespacesandallpars}

\def\useignorespacesandallpars#1\ignorespaces\fi{%
#1\fi\ignorespacesandallpars}

\makeatletter
\def\ignorespacesandallpars{%
  \@ifnextchar\par
    {\expandafter\ignorespacesandallpars\@gobble}%
    {}%
}
\makeatother

% other things
\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}
{\let\newpage\relax\maketitle}

$if(acknowledgements)$
  $acknowledgements$
$endif$

\pagenumbering{arabic}
\pagestyle{norm}

$body$

\end{document}
