\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latex-templates/PrimeManual}[2025-06-24]
%
% Suppress warning about \showhyphens being changed.
\let\CheckCommand\providecommand

\RequirePackage{microtype}

\DeclareRobustCommand*{\customer}[1]{\gdef\@customer{#1}}
\DeclareRobustCommand*{\customerFull}[1]{\gdef\@customerFull{#1}}
\DeclareRobustCommand*{\projectNumber}[1]{\gdef\@projectNumber{#1}}
\DeclareRobustCommand*{\projectDesc}[1]{\gdef\@projectDesc{#1}}
\DeclareRobustCommand*{\version}[1]{\gdef\@version{#1}}

\newcommand{\sTitle}{\makeatletter{\@title}}
\newcommand{\sAuthor}{\makeatletter{\@author}}
\newcommand{\sDate}{\makeatletter{\@date}}
\newcommand{\sCustomer}{\makeatletter{\@customer}}
\newcommand{\sCustomerFull}{\makeatletter{\@customerFull}}
\newcommand{\sProjectNumber}{\makeatletter{\@projectNumber}}
\newcommand{\sProjectDesc}{\makeatletter{\@projectDesc}}
\newcommand{\sProjectTitle}{\makeatletter{Project \@projectNumber : \@projectDesc}}
\newcommand{\sVersion}{\makeatletter{\@version}}

%\RequirePackage[mark]{gitinfo2}

% Specify Fonts
\RequirePackage{fontspec}
% Main font: Roboto Serif
\setmainfont{RobotoSerif}[
	Path			= ./fonts/RobotoSerif/,
	Extension		= .ttf,
	UprightFont		= *-Light,
	BoldFont		= *-Bold,
	ItalicFont		= *-Italic,
	BoldItalicFont	= *-BoldItalic,
]
% Headings & Titles font: Roboto Slab
\setsansfont{RobotoSlab}[
	Path			= ./fonts/RobotoSlab/,
	Extension		= .ttf,
	UprightFont		= *-Regular,
	BoldFont		= *-Bold,
]
% Monospace font: Roboto Mono
\setmonofont{RobotoMono}[
	Path			= ./fonts/RobotoMono/,
	Extension		= .ttf,
	UprightFont		= *-Regular,
	BoldFont		= *-Bold,
	ItalicFont		= *-Italic,
	BoldItalicFont	= *-BoldItalic,
]

% Page Layout
\RequirePackage[pass]{geometry}

% Title & Heading Options
\RequirePackage[sf,raggedright]{titlesec}

% Header & Footer Options
\pagestyle{plain}

% Color import and definition
\RequirePackage{xcolor}
\definecolor{PrimeBlue}{RGB}{25,45,145}

% Use Hyperref to automatically create links in the document
\RequirePackage{hyperref}
\hypersetup{colorlinks=true, allcolors=PrimeBlue}

% Graphics package for including images
\RequirePackage{graphicx}
\RequirePackage{calc}

% Define custom title page.
\newcommand{\PrimeTitlePage}{
	\begin{titlepage}
		\begin{sffamily}
			{\raggedright\noindent\large
				\vspace*{\stretch{1}}

				\sCustomerFull
				\medbreak
				\sProjectTitle
				\bigbreak
				{\Huge \sTitle}
				\vfill
				{\leavevmode
					% Move the rule graphic to 0.25 in from the left edge of the 
					% paper and vertically centered on the heartbeat graphic.
					\put(-\oddsidemargin-0.75in,10pt){
						\includegraphics{graphics/prime_rule.pdf}
					}
					% The numbers here are just what looks good.
					\put(100pt,0pt){
						\includegraphics{graphics/prime_heartbeat.pdf}
					}
				}
				
				\sAuthor

				Revision \sVersion
				
				\sDate
				\vfill
			}
        \end{sffamily}
    \end{titlepage}
}

% Paragraph formatting.
\setlength{\parindent}{0pt}
\setlength{\parskip}{2ex plus 0.5ex minus 0.5ex}

% Table formatting.
\renewcommand{\arraystretch}{1.5}
\RequirePackage{csvsimple}
\RequirePackage{longtable}
\RequirePackage{colortbl}
\RequirePackage{booktabs}

% Glossary formatting.
\RequirePackage[nopostdot,toc,sort=standard]{glossaries}

% Index formatting.
\RequirePackage{makeidx}
\RequirePackage{xstring}
\newcommand{\idx}[1]{\StrSubstitute{#1}{!}{ }\index{#1}}

% Margin Note formatting.
\RequirePackage{marginnote}
% -38pt seems to be just the right vertical adjustment to align margin notes
% with the reference in the text.
\renewcommand{\marginnotevadjust}{-38pt}
\renewcommand{\marginfont}{\small\color{PrimeBlue}}

\newcommand{\margintitle}[1]{\paragraph{\textbf{#1}}}
\newcommand{\margindef}[2][0pt]{%
	\index{\glsentryname{#2}}% Add a reference to this in the index.
	\textbf{\gls{#2}}% This is the text that appears on the page.
	\marginnote{% Create the margin note.
		\margintitle{\Glsentryname{#2}:% Create the title of the margin note.
		} \glsdesc*{#2}}[#1]% Create the text of the margin note.
}

% Cross references
\newcommand{\refGeneral}[3][]{
	\if\relax\detokenize{#1}\relax % Check if #1 is empty string.
		#3{#2}\label{ch:#2}
	\else
		#3{#2}\label{ch:#1}
	\fi
}
\newcommand{\refChapter}[2][]{
	\refGeneral[#1]{#2}{\chapter}
}
\newcommand{\refSection}[2][]{
	\refGeneral[#1]{#2}{\section}
}
\newcommand{\refSubsection}[2][]{
	\refGeneral[#1]{#2}{\subsection}
}
\newcommand{\refSubsubsection}[2][]{
	\refGeneral[#1]{#2}{\subsubsection}
}
\newcommand{\refParagraph}[2][]{
	\refGeneral[#1]{#2}{\paragraph}
}
\newcommand{\refSubparagraph}[2][]{
	\refGeneral[#1]{#2}{\subparagraph}
}