\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$else$american,$endif$$if(papersize)$$papersize$paper,$else$letterpaper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
$if(fontfamily)$
%% CRMDA version 20180816
%% blends default-1.17.0.2 from rmarkdown with CRMDA
%% report-template.tex on 20180816
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$else$
\usepackage{lmodern}
%% CRMDA paste: 20180816
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
$endif$
\usepackage[utf8]{inputenc}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[yyyymmdd,hhmmss]{datetime}
\usepackage{lastpage}
\usepackage{babel}
\providecommand{\tabularnewline}{\\}
\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\let\PBS=\PreserveBackslash
\usepackage{setspace}
\usepackage{calc}
%% end paste
$if(linestretch)$
\setstretch{$linestretch$}
$endif$
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc}
  \usepackage[utf8]{inputenc}
$if(euro)$
  \usepackage{eurosym}
$endif$
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
$if(euro)$
  \newcommand{\euro}{€}
$endif$
$if(mainfont)$
    \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}
$endif$
$if(sansfont)$
    \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$}
$endif$
$if(monofont)$
    \setmonofont[Mapping=tex-ansi$if(monofontoptions)$,$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$endif$]{$monofont$}
$endif$
$if(mathfont)$
    \setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
$endif$
$if(CJKmainfont)$
    \usepackage{xeCJK}
    \setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$}
$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
}{}
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$else$
\usepackage[includehead,includefoot]{geometry}
\geometry{lmargin=1in,rmargin=1in,tmargin=0.75in,
bmargin=1.0in,headheight=0pt,headsep=0pt,marginparwidth=0pt,
footskip=2.5\baselineskip,
}
$endif$
\usepackage{hyperref}
$if(colorlinks)$
\PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref
$endif$
\hypersetup{unicode=true,
$if(title-meta)$
            pdftitle={$title-meta$},
$endif$
$if(author-meta)$
            pdfauthor={$author-meta$},
$endif$
$if(keywords)$
            pdfkeywords={$for(keywords)$$keywords$$sep$; $endfor$},
$endif$
$if(colorlinks)$
            colorlinks=true,
            linkcolor=$if(linkcolor)$$linkcolor$$else$darkblue$endif$,
            citecolor=$if(citecolor)$$citecolor$$else$darkblue$endif$,
            urlcolor=$if(urlcolor)$$urlcolor$$else$darkblue$endif$,
$else$
            pdfborder={0 0 0},
$endif$
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
$if(lang)$
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
$if(babel-newcommands)$
  $babel-newcommands$
$endif$
\else
  \usepackage{polyglossia}
  \setmainlanguage[$polyglossia-lang.options$]{$polyglossia-lang.name$}
$for(polyglossia-otherlangs)$
  \setotherlanguage[$polyglossia-otherlangs.options$]{$polyglossia-otherlangs.name$}
$endfor$
\fi
$endif$
$if(natbib)$
%%\usepackage{natbib}
\usepackage[natbibapa]{apacite}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$apacitex$endif$}
$endif$
$if(biblatex)$
\usepackage$if(biblio-style)$[style=$biblio-style$]$endif${biblatex}
$if(biblatexoptions)$\ExecuteBibliographyOptions{$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$}$endif$
$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
$endif$
$if(listings)$
\usepackage{listings}
\newcommand{\passthrough}[1]{#1}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
\usepackage{longtable,booktabs,dcolumn}
\usepackage{graphicx,grffile}
\usepackage{fancyhdr}
\lhead{}
\chead{}
\rhead{}
\renewcommand{\headrulewidth}{0pt}
\lfoot{}
\cfoot{{Page} \thepage { of} \pageref{LastPage}}
\rfoot{}

\fancypagestyle{firststyle}
{
\lfoot{}
% \cfoot{{Page} \thepage { of} \pageref{LastPage}}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[L]{$if(addr.l1)$$addr.l1$\\$endif$$if(addr.l2)$$addr.l2$\\$endif$$if(addr.l3)$$addr.l3$$endif$}
\fancyfoot[R]{$if(addr.r1)$$addr.r1$\\$endif$$if(addr.r2)$$addr.r2$\\$endif$$if(addr.r3)$$addr.r3$$endif$}
\renewcommand{\footrulewidth}{.1pt}
}

\pagestyle{fancy}
\thispagestyle{firststyle}

%% Eliminate reliance on Sweavel or Sweave
%% \usepackage{Sweavel}
%% \usepackage[noae]{Sweave}
\usepackage{listings}
\usepackage{upquote, fancyvrb, relsize, ae}

%%\lstset{tabsize=2, breaklines=true,style=Rstyle}
\definecolor{darkgreen}{RGB}{0,100,0}
\definecolor{indianred}{RGB}{205,92,92}
\definecolor{steelblue}{RGB}{70,130,180}
\definecolor{antwhite}{RGB}{139,119,101}
\definecolor{lightgray}{RGB}{240,240,240}
\definecolor{darkblue}{HTML}{1e2277}
\definecolor{kublue81186}{RGB}{0,81,186}
\newdateformat{monddyyy}{\small{}\textbf{\shortmonthname[\THEMONTH].~\THEDAY,~\THEYEAR}}

%% 20180817: remove old code from Brent's days
% \def\Sweavesize{\scriptsize} 
% \def\Rcolor{\color{black}} 
% \def\Rbackground{\color[gray]{0.95}}

% \lstdefinestyle{Rstylecrmda}{
%   language=R,
%   escapechar=`,
%   fancyvrb=false,%
%   tabsize=2,%
%   breaklines=true,
%   breakatwhitespace=true,%
%   captionpos=b,%
%   frame=single,%
%   framerule=0.2pt,%
%   framesep=1pt,%
%   showstringspaces=false,%
%   basicstyle=\normalsize\ttfamily,%
%   columns=fixed%,
%   \lst@ifdisplaystyle\scriptsize\fi,%
%   identifierstyle=,%
%   keywords=\bfseries,%
%   keywordstyle=\color[rgb]{0, 0.5, 0.5},
%   escapeinside={(*}{*)},
%   literate={~}{{$$\sim$$}}1 {==}{{=\,=}}2,
%   alsoother={$$},
%   alsoletter={.<-},%
%   otherkeywords={!,!=,~,$$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},
%   backgroundcolor=\Rbackground
% }%

% \lstset{style=Rstylecrmda}
% \fvset{listparameters={\setlength{\topsep}{0em}}}

%% 20180817 Paste in guidePreambleSweavel.tex

%%% From beamer slide:
\usepackage{Sweave}
%% 
%% This controls display of code chunks
\usepackage{ae,fancyvrb,relsize,listings}

\providecommand{\Sweavesize}{\normalsize}
\providecommand{\Rsize}{}
\renewcommand{\Rsize}{\normalsize}
\providecommand{\Routsize}{\scriptsize}

\providecommand{\Rcolor}{\color[rgb]{0.1, 0.1, 0.1}}
\providecommand{\Routcolor}{\color[rgb]{0.2, 0.2, 0.2}}
\providecommand{\Rcommentcolor}{\color[rgb]{0.101, 0.43, 0.432}}

\providecommand{\Rbackground}{\color[gray]{0.91}}
\providecommand{\Routbackground}{\color[gray]{0.935}}
% Can specify \color[gray]{1} for white background or just \color{white}

\lstdefinestyle{Rinput}{
  language=R,
  escapechar=`,
  fancyvrb=false,%
  tabsize=2,%
  breaklines=true,
  breakatwhitespace=true,%
  captionpos=b,%
  frame=single,%
  framerule=0.2pt,%
  framesep=1pt,%
  showstringspaces=false,%
  basicstyle=\Rsize\Rcolor\ttfamily,%
  columns=fixed%,
  \lst@ifdisplaystyle\scriptsize\fi,%,
  commentstyle=\Rcommentcolor\ttfamily,%
  identifierstyle=,%
  keywords=\bfseries,%
  keywordstyle=\color[rgb]{0, 0.5, 0.5},
  escapeinside={(*}{*)},
  literate={~}{{$$\sim$$}}1{==}{{=\,=}}2{--}{{-\,-}}2,
  alsoother={$$},
  alsoletter={.<-},%
  otherkeywords={!,!=,~,$$$$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},%
  backgroundcolor=\Rbackground,%
  numbers=left,%
  %numberblanklines=false,%
  stepnumber=5,
  firstnumber=1,
  numberstyle={\tiny}
}%

% Other options of interest:
% frame=single,framerule=0.1pt,framesep=1pt,rulecolor=\color{blue},
% numbers=left,numberstyle=\tiny,stepnumber=1,numbersep=7pt,
% keywordstyle={\bf\Rcolor}

\lstdefinestyle{Routput}{fancyvrb=false,
  literate={~}{{$$\sim$$}}1{R^2}{{$$R^{2}$$}}2{^}{{$$^{\scriptstyle\wedge}$$}}1{R-squared}{{$$R^{2}$$}}2,%
  basicstyle=\Routcolor\Routsize\ttfamily,%
  backgroundcolor=\Routbackground,
  language=R,
  escapechar=`,
  fancyvrb=false,%
  tabsize=2,%
  breaklines=true,
  breakatwhitespace=true,%
  captionpos=b,%
  frame=single,%
  framerule=0.2pt,%
  framesep=1pt,%
  showstringspaces=false,%
  columns=fixed%,
  \lst@ifdisplaystyle\scriptsize\fi,%
  identifierstyle=,%
  keywords=\bfseries,%
  keywordstyle=\color[rgb]{0, 0.5, 0.5},
  escapeinside={(*}{*)},
  literate={~}{{$$\sim$$}}1 {==}{{=\,=}}2,
  alsoother={$$},
  alsoletter={.<-},%
  otherkeywords={!,!=,~,$$,*,\&,\%/\%,\%*\%,\%\%,<-,<<-,/},
  numbers=left,
  %numberblanklines=false,%
  stepnumber=5,
  firstnumber=1,
  numberstyle={\tiny}
}

\renewenvironment{Schunk}{}{}
\renewenvironment{Sinput}{}{}
\let\Sinput\relax
\let\Scode\relax
\let\Soutput\relax
\lstnewenvironment{Sinput}{\lstset{style=Rinput}}{}
\lstnewenvironment{Scode}{\lstset{style=Rinput}}{}
\lstnewenvironment{Soutput}{\lstset{style=Routput}}{}
%%end paste in from guidePreambleSweavel.tex


\lstset{tabsize=2, breaklines=true, style=Rinput, breakatwhitespace=true}

\fvset{listparameters={\setlength{\topsep}{0em}}}

\usepackage{xcolor}
\definecolor{light-gray}{gray}{0.90}
\usepackage{realboxes}
\providecommand*{\code}[1]{\texttt{#1}}
\renewcommand{\code}[1]{%
\Colorbox{light-gray}{#1}%
}%

%% End of paste guidePreambleSweavel.tex



%%
\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}
%graphics and such inside floats are centered by default
\renewenvironment{figure}[1][]{%
 \ifthenelse{\equal{#1}{}}{%
   \@float{figure}
 }{%
   \@float{figure}[#1]%
 }%
 \centering
}{%
 \end@float
}
\renewenvironment{table}[1][]{%
 \ifthenelse{\equal{#1}{}}{%
   \@float{table}
 }{%
   \@float{table}[#1]%
 }%

 \centering
}{%
 \end@float
}
\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}
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
$if(indent)$
$else$
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
$endif$
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
$if(numbersections)$
\setcounter{secnumdepth}{5}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(subparagraph)$
$else$
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
$endif$
$if(dir)$
\ifxetex
  % load bidi as late as possible as it modifies e.g. graphicx
  $if(latex-dir-rtl)$
  \usepackage[RTLdocument]{bidi}
  $else$
  \usepackage{bidi}
  $endif$
\fi
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \TeXXeTstate=1
  \newcommand{\RL}[1]{\beginR #1\endR}
  \newcommand{\LR}[1]{\beginL #1\endL}
  \newenvironment{RTL}{\beginR}{\endR}
  \newenvironment{LTR}{\beginL}{\endL}
\fi
$endif$

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

$if(compact-title)$
%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}
$endif$

$for(header-includes)$
$header-includes$
$endfor$

\begin{document}
\setlength{\tabcolsep}{1pt}
\noindent\fcolorbox{kublue81186}{white}{
  \begin{minipage}[t][1\totalheight][c]{1\linewidth-2\fboxsep-2\fboxrule}%
    \begin{minipage}[c]{.15\linewidth}%
      \bigskip
      \begin{center}
        $if(logoleft)$\includegraphics[width=0.80\linewidth]{$logoleft$}$endif$
        \par
        \bigskip
        $if(guidenum)${\small{}\textbf{Guide No: $guidenum$}}\\$endif$
      \end{center}%
      \medskip
    \end{minipage} %
\begin{minipage}[c][1\totalheight][b]{.65\linewidth}%
  \medskip
  \begin{center}
     \begin{minipage}[t]{1\columnwidth}%
      \begin{center}
        \medskip
        \textbf{\larger{}$title$$if(subtitle)$: $subtitle$$endif$}
      \end{center}
      \color{kublue81186}\rule[1ex]{1\linewidth}{0.5pt}%
    \end{minipage}
    \par\end{center}{\Huge \par}
\begin{minipage}[t]{1\columnwidth}%
\begin{center}
  $for(author)$\textbf{$author.name$}$if(author.description)$,
  $author.description$$endif$$if(author.affiliation)$,
  $author.affiliation$$endif$$if(author.email)$
  <$author.email$>$endif$\\
  $endfor$\medskip
\par\end{center}%
\end{minipage}
%\smallskip{}%
\begin{flushleft}
  $if(keywords)$\textbf{keywords}: $keywords$.\\$endif$
  $if(guideurl)$See $guideurl$ for updates.$endif$
  \par\end{flushleft}%
\medskip
\end{minipage} %
\begin{minipage}[c]{.18\linewidth}%
  \bigskip
\begin{center}
$if(logoright)$\includegraphics[width=1.1in]{$logoright$}$endif$
   \par
   \bigskip
   \monddyyy\today
\par\end{center}
\medskip
\end{minipage}
\end{minipage}
}

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$for(include-before)$
$include-before$

$endfor$
$if(toc)$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$if(lot)$
\listoftables
$endif$
$if(lof)$
\listoffigures
$endif$
$body$

$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$if(toc)$
\addcontentsline{toc}{section}{\refname}
$endif$
$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$for(include-after)$
$include-after$

$endfor$

\end{document}
