%%% TITLE PAGE START

% Set up alignment commands
$if(titlepage-theme.page-align)$
%Page
\newcommand{\titlepagepagealign}{
\ifthenelse{\equal{$titlepage-theme.page-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.page-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.page-align$}{left}}{\raggedright}{}
}
$endif$
$if(titlepage-theme.title-align)$
%% Titles
\newcommand{\titlepagetitlealign}{
\ifthenelse{\equal{$titlepage-theme.title-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.title-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.title-align$}{left}}{\raggedright}{}
\ifthenelse{\equal{$titlepage-theme.title-align$}{spread}}{\makebox[\linewidth][s]}{}
}
$endif$
$if(titlepage-theme.author-align)$
%Author
\newcommand{\titlepageauthoralign}{
\ifthenelse{\equal{$titlepage-theme.author-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.author-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.author-align$}{left}}{\raggedright}{}
\ifthenelse{\equal{$titlepage-theme.author-align$}{spread}}{\makebox[\linewidth][s]}{}
}
$endif$
$if(titlepage-theme.affiliation-align)$
%Affiliation
\newcommand{\titlepageaffiliationalign}{
\ifthenelse{\equal{$titlepage-theme.affiliation-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.affiliation-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.affiliation-align$}{left}}{\raggedright}{}
\ifthenelse{\equal{$titlepage-theme.affiliation-align$}{spread}}{\makebox[\linewidth][s]}{}
}
$endif$
$if(titlepage-theme.footer-align)$
%Footer
\newcommand{\titlepagefooteralign}{
\ifthenelse{\equal{$titlepage-theme.footer-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.footer-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.footer-align$}{left}}{\raggedright}{}
\ifthenelse{\equal{$titlepage-theme.footer-align$}{spread}}{\makebox[\linewidth][s]}{}
}
$endif$
$if(titlepage-theme.header-align)$
%Header
\newcommand{\titlepageheaderalign}{
\ifthenelse{\equal{$titlepage-theme.header-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.header-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.header-align$}{left}}{\raggedright}{}
\ifthenelse{\equal{$titlepage-theme.header-align$}{spread}}{\makebox[\linewidth][s]}{}
}
$endif$
$if(titlepage-theme.logo-align)$
%Logo
\newcommand{\titlepagelogoalign}{
\ifthenelse{\equal{$titlepage-theme.logo-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.logo-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.logo-align$}{left}}{\raggedright}{}
}
$endif$
$if(titlepage-theme.date-align)$
%% Titles
\newcommand{\titlepagedatealign}{
\ifthenelse{\equal{$titlepage-theme.title-align$}{right}}{\raggedleft}{}
\ifthenelse{\equal{$titlepage-theme.title-align$}{center}}{\centering}{}
\ifthenelse{\equal{$titlepage-theme.title-align$}{left}}{\raggedright}{}
}
$endif$

$-- % Set up commands based on themes
$_title-themes.tex()$
$_author-affiliation-themes.tex()$
$_header-footer-date-themes.tex()$

%set up blocks so user can specify order
\newcommand{\titleblock}{$if(title)$
$if(subtitle)$
\newlength{\betweentitlesubtitle}
\setlength{\betweentitlesubtitle}{$if(titlepage-theme.title-subtitle-space-between)$$titlepage-theme.title-subtitle-space-between$$else$\baselineskip$endif$}
$endif$
{$if(titlepage-theme.title-align)$\titlepagetitlealign$endif$
$if(titlepage-theme.title-fontfamily)$\titlepagetitlefont$endif$
{\titlepagetitleblock}
}

\vspace{$if(titlepage-theme.title-space-after)$$titlepage-theme.title-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\authorblock}{$if(author)$
{$if(titlepage-theme.author-align)$\titlepageauthoralign
$endif$$if(titlepage-theme.author-fontfamily)$\titlepageauthorfont
$endif$\titlepageauthorblock}

\vspace{$if(titlepage-theme.author-space-after)$$titlepage-theme.author-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\affiliationblock}{$if(author)$
$if(titlepage-theme.affiliation-color)$\textcolor{$titlepage-theme.affiliation-color$}$endif${$if(titlepage-theme.affiliation-align)$\titlepageaffiliationalign
$endif$$if(titlepage-theme.affiliation-fontfamily)$\titlepageaffiliationfont
$endif$\titlepageaffiliationblock}

\vspace{$if(titlepage-theme.affiliation-space-after)$$titlepage-theme.affiliation-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\logoblock}{$if(titlepage-logo)$
{$if(titlepage-theme.logo-align)$\titlepagelogoalign
$endif$\includegraphics[width=$if(titlepage-theme.logo-size)$$titlepage-theme.logo-size$$else$0.2\textwidth$endif$]{$titlepage-logo$}}

\vspace{$if(titlepage-theme.logo-space-after)$$titlepage-theme.logo-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\footerblock}{$if(titlepage-footer)$
$if(titlepage-theme.footer-color)$\textcolor{$titlepage-theme.footer-color$}$endif${$if(titlepage-theme.footer-align)$\titlepagefooteralign
$endif$$if(titlepage-theme.footer-fontfamily)$\titlepagefooterfont
$endif$\titlepagefooterblock}

\vspace{$if(titlepage-theme.footer-space-after)$$titlepage-theme.footer-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\dateblock}{$if(date)$
$if(titlepage-theme.date-color)$\textcolor{$titlepage-theme.date-color$}$endif${$if(titlepage-theme.date-align)$\titlepagedatealign
$endif$$if(titlepage-theme.date-fontfamily)$\titlepagedatefont
$endif$\titlepagedateblock}

\vspace{$if(titlepage-theme.date-space-after)$$titlepage-theme.date-space-after$$else$0pt$endif$}
$else$$endif$}

\newcommand{\headerblock}{$if(titlepage-header)$
$if(titlepage-theme.header-color)$\textcolor{$titlepage-theme.header-color$}$endif${$if(titlepage-theme.header-align)$\titlepageheaderalign
$endif$$if(titlepage-theme.header-fontfamily)$\titlepageheaderfont$endif$\titlepageheaderblock

\vspace{$if(titlepage-theme.header-space-after)$$titlepage-theme.header-space-after$$else$0pt$endif$}
}$else$$endif$}
$--
$if(titlepage-geometry)$
\newgeometry{$for(titlepage-geometry)$$titlepage-geometry$$sep$,$endfor$}
$endif$
$--
$if(titlepage-theme.page-html-color)$
\definecolor{pgcolor}{HTML}{$titlepage-theme.page-html-color$}
\pagecolor{pgcolor}\afterpage{\nopagecolor}
$else$$if(titlepage-theme.page-color)$
\colorlet{pgcolor}{$titlepage-theme.page-color$}
\pagecolor{pgcolor}\afterpage{\nopagecolor}
$endif$$endif$
$--
$if(titlepage-bg-image)$
% background image
\newlength{\bgimagesize}
\setlength{\bgimagesize}{$if(titlepage-theme.bg-image-size)$$titlepage-theme.bg-image-size$$else$\paperwidth$endif$}
\LENGTHDIVIDE{\bgimagesize}{\paperwidth}{\theRatio} % from calculator pkg
\This$if(titlepage-theme.bg-image-location)$$titlepage-theme.bg-image-location$$else$ULCorner$endif$WallPaper{\theRatio}{$titlepage-bg-image$}
$endif$

\thispagestyle{empty} % no page numbers on titlepages
$if(titlepage-theme.page-fontfamily)$\titlepagefont$endif$

$if(titlepage-theme.vrule-width)$
$if(titlepage-theme.vrule-text)$
\newcommand{\vrulecode}{\noindent\colorbox{$titlepage-theme.vrule-color$}{\begin{minipage}[b][0.99\textheight][c]{\vrulewidth}$if(titlepage-theme.vrule-text)$
\centering\rotatebox{90}{\makebox[0.88\textheight][r]{$if(titlepage-theme.vrule-text-fontstyle)$$for(titlepage-theme.vrule-text-fontstyle)$\$titlepage-theme.vrule-text-fontstyle${$endfor$$endif$$if(titlepage-theme.vrule-text-color)$\color{$titlepage-theme.vrule-text-color$}$endif$$titlepage-theme.vrule-text$$for(titlepage-theme.vrule-text-fontstyle)$}$endfor$}}$endif$\end{minipage}}}
$else$
\newcommand{\vrulecode}{\textcolor{$titlepage-theme.vrule-color$}{\rule{\vrulewidth}{\textheight}}}
$endif$
\newlength{\vrulewidth}
\setlength{\vrulewidth}{$titlepage-theme.vrule-width$}
\newlength{\B}
\setlength{\B}{\ifdim\vrulewidth > 0pt $titlepage-theme.vrule-space$\else 0pt\fi}
\newlength{\minipagewidth}
\ifthenelse{\equal{$titlepage-theme.vrule-align$}{left} \OR \equal{$titlepage-theme.vrule-align$}{right} }
{% True case
\setlength{\minipagewidth}{\textwidth - \vrulewidth - \B - 0.1\textwidth}
}{
\setlength{\minipagewidth}{\textwidth - 2\vrulewidth - 2\B - 0.1\textwidth}
}
$else$
\newlength{\minipagewidth}
\setlength{\minipagewidth}{\textwidth}
$endif$
$if(titlepage-theme.vrule-width)$
\ifthenelse{\equal{$titlepage-theme.vrule-align$}{left} \OR \equal{$titlepage-theme.vrule-align$}{leftright}}
{% True case
\raggedleft % needed for the minipage to work
\vrulecode
\hspace{\B}
}{%
\raggedright % else it is right only and width is not 0
}
$else$
\raggedright % single minipage
$endif$
% [position of box][box height][inner position]{width}
% [s] means stretch out vertically; assuming there is a vfill
\begin{minipage}[b][\textheight][s]{\minipagewidth}
$if(titlepage-theme.page-align)$\titlepagepagealign$endif$
$for(titlepage-theme.elements)$
$titlepage-theme.elements$
$sep$

$endfor$
\par

\end{minipage}\ifthenelse{\equal{$titlepage-theme.vrule-align$}{right} \OR \equal{$titlepage-theme.vrule-align$}{leftright} }{
\hspace{\B}
\vrulecode}{}
\clearpage
$if(titlepage-geometry)$\restoregeometry
$endif$%%% TITLE PAGE END

