% tech report
\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]{typearea}
\usepackage[includeheadfoot,paperheight=11in,paperwidth=8.5in,hmargin=1in,vmargin=0.5in,headheight=0.6in,headsep=11pt,footskip=0.5in]{geometry}
\usepackage[raggedright]{titlesec}
\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
      \if\instring{DCPS}{$program$}
      \definecolor{progcolor}{RGB}{56,122,88}
      \else
        \if\instring{NCDB}{$program$}
        \definecolor{progcolor}{RGB}{64,128,135}
        \else
          \definecolor{progcolor}{RGB}{0,0,0}
        \fi
      \fi
    \fi
  \fi
\fi


\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}{\color{progcolor}\HRule[12pt]}\mdseries\LARGE#1\end{center}
    }
}

\setlength{\droptitle}{-2em}

  \title{$title$}
    \pretitle{\vspace{\droptitle}\centering\HUGE\bfseries\emph}
  \posttitle{\par}

  \subtitle{$subtitle$}

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

  \date{$date$}
    \predate{\centering\large\bfseries}
  \postdate{\par}


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

% page breaks before each section
$if(manual)$
  \newcommand{\sectionbreak}{\clearpage}
$endif$

% 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}\nopunct}
\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[firstpage]{draftwatermark}
  \SetWatermarkColor[HTML]{FE7E7E}
  % \SetWatermarkLightness{.9}
  \SetWatermarkText{$watermark$}
$endif$

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


\usepackage{subcaption}
$if(manual)$
  \numberwithin{figure}{section}
  \numberwithin{table}{section}
  \numberwithin{equation}{section}
$endif$
\usepackage[singlelinecheck=false,justification=raggedright]{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}
\setlength{\cftfignumwidth}{3em}
\setlength{\cfttabnumwidth}{3em}
\cftsetpnumwidth{3em}
\cftsetrmarg{3em}

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

% title styles
$if(manual)$
  \titleformat{\section}{\bfseries\LARGE\center}{\thesection. }{0pt}{}
$else$
  \titleformat{\section}{\bfseries\LARGE}{\thesection. }{0pt}{}
$endif$
\titlespacing*{\section}{0pt}{6pt}{0pt}
\titleformat{\subsection}{\bfseries\Large\raggedright}{\thesubsection. }{0pt}{}
\titlespacing*{\subsection}{0pt}{10pt}{0pt}
\titleformat{\subsubsection}{\bfseries\itshape\Large\raggedright}{\thesubsubsection. }{0pt}{}
\titlespacing*{\subsubsection}{0pt}{10pt}{0pt}
\titleformat{\paragraph}{\bfseries\large\raggedright}{\theparagraph. }{0pt}{}
\titlespacing*{\paragraph}{0pt}{10pt}{0pt}
\titleformat{\subparagraph}{\bfseries\itshape\large\raggedright}{\thesubparagraph. }{0pt}{}
\titlespacing*{\subparagraph}{0pt}{10pt}{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}}
\renewcommand{\subsectionmark}[1]{}

% program name for header
\if\instring{DLM}{$program$}
\newcommand{\progName}{Dynamic Learning Maps}
\else
  \if\instring{DCPS}{$program$}
  \newcommand{\progName}{Delaware Communication Portfolio Summary}
  \else
    \if\instring{NCDB}{$program$}
    \newcommand{\progName}{National Center on Deaf-Blindness}
    \else
      \newcommand{\progName}{$program$}
    \fi
  \fi
\fi

\fancypagestyle{plain}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
  $else$
    \fancyfoot[C]{$copyright$}
  $endif$
}
\fancypagestyle{ack}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
  $endif$
}
\fancypagestyle{front}{%
  \lhead{}
  \chead{}
  \rhead{}
  \renewcommand{\headrulewidth}{0pt}
  \lfoot{}
  \cfoot{}
  \rfoot{}
  $if(internal)$
    \fancyfoot[L]{FOR INTERNAL CONSORTIUM REVIEW ONLY}
  $endif$
  \fancyfoot[R]{Page \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$
  $if(manual)$
    \fancyfoot[L]{Chapter \rightmark}
  $endif$

  \fancyfoot[R]{Page \thepage}
  \fancyhead[L]{\includegraphics[width=2in]{figures/pre-generated/letterhead.jpg}}

  $if(manual)$
    \if\instring{DLM}{$program$}
    \fancyhead[R]{$title$\\\progName{} Alternate Assessment System\\$subtitle$}
    \else
    \fancyhead[R]{$title$\\$subtitle$}
    \fi
  $else$
    \fancyhead[R]{$shorttitle$\\\progName{}\\$subtitle$}
  $endif$
}

\newcommand*{\useportrait}{%
  \clearpage
  \KOMAoptions{paper=portrait,DIV=current}%switch to portrait
  \newgeometry{includeheadfoot,hmargin=1in,vmargin=0.5in,headheight=0.6in,headsep=11pt,footskip=0.5in}%
  \fancyhfoffset{0pt}% <- recalculate head and foot width for fancyhdr
}
\newcommand*{\uselandscape}{%
  \clearpage
  \KOMAoptions{paper=landscape,DIV=current}%switch to landscape
  \newgeometry{includeheadfoot,hmargin=1in,vmargin=0.5in,headheight=0.6in,headsep=11pt,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}

% number spacing
\usepackage{enumitem}
\setlist{nolistsep}

% break long hyperlinks
\usepackage{xurl}


% start document
\begin{document}
\pagestyle{plain}
\includegraphics[width=\textwidth]{figures/pre-generated/$program$.png}
{\let\newpage\relax\maketitle}

\newpage
\pagestyle{ack}
$if(acknowledgements)$
  $acknowledgements$
$endif$

\begin{romanpages}
\pagestyle{front}

{
\setcounter{tocdepth}{3}
\tableofcontents
}

\clearpage
$if(lot)$
  \listoftables
$endif$

\clearpage
$if(lof)$
  \listoffigures
$endif$

\end{romanpages}
\pagenumbering{arabic}
\pagestyle{norm}

$body$

% \clearpage
% \addcontentsline{toc}{section}{References}
% \printbibliography[heading=bibintoc,title={References}]

\end{document}
