Files
PrimeTeX/PrimeManual.sty
Joshua Lucas 40b8836e51 - Add full-width float macros.
- Add reference macros.
- Add versions of marginfig and centerfig that allow custom widths.
2025-07-09 17:26:06 -05:00

306 lines
7.6 KiB
TeX

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latex-templates/PrimeManual}[2025-06-24]
% Suppress warning about \showhyphens being changed.
\let\CheckCommand\providecommand
\RequirePackage{microtype}
% Custom document properties.
%#region
\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}}
%#endregion
% Macros to insert document properties.
%#region
\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}}
%#endregion
% Specify Fonts
%#region
\RequirePackage{fontspec}
% Main font: Roboto Serif
\setmainfont{RobotoSerif}[
Path = ./fonts/RobotoSerif/,
Extension = .ttf,
UprightFont = *-Light,
BoldFont = *-SemiBold,
ItalicFont = *-LightItalic,
BoldItalicFont = *-SemiBoldItalic,
]
% Headings & Titles font: Roboto Slab
\setsansfont{RobotoSlab}[
Path = ./fonts/RobotoSlab/,
Extension = .ttf,
UprightFont = *-SemiBold,
BoldFont = *-Black,
]
% Monospace font: Roboto Mono
\setmonofont{RobotoMono}[
Path = ./fonts/RobotoMono/,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
]
%#endregion
% Page Layout
%#region
\RequirePackage[pass]{geometry}
\RequirePackage{calc}
\RequirePackage{ifoddpage}
\newlength{\contentwidth}
\setlength{\contentwidth}{\textwidth+\marginparsep+\marginparwidth}
\newlength{\bfFigureWidth}
\newlength{\bfMarginOffset}
\newcommand{\bigfloat}[2][1in]{%
\setlength{\bfFigureWidth}{#1*-2+\paperwidth}%
\checkoddpage%
\ifoddpage%
\setlength{\bfMarginOffset}{-1in+#1-\oddsidemargin}%
\else%
\setlength{\bfMarginOffset}{-1in+#1-\evensidemargin}%
\fi%
\begin{figure}[ht]%
{\leavevmode%
\put(\bfMarginOffset,0in){%
\begin{minipage}{\bfFigureWidth}%
#2%
\end{minipage}%
}%
}%
\end{figure}%
}
%#endregion
% Title & Heading Options
%#region
\RequirePackage[sf,raggedright]{titlesec}
%#endregion
% Header & Footer Options
%#region
\pagestyle{plain}
%#endregion
% Color import and definition
%#region
\RequirePackage{xcolor}
\definecolor{PrimeBlue}{RGB}{25,45,145}
%#endregion
% Cross references
%#region
%\newcommand{\sectionRef}[2]{\ref{#1:#2}: #2}
\newcommand{\refChapter}[1]{Chapter \ref{ch:#1}}
\newcommand{\refAppendix}[1]{Appendix \ref{ch:#1}}
\newcommand{\refSection}[1]{Section \ref{sec:#1}}
\newcommand{\refSubsection}[1]{Subsection \ref{subsec:#1}}
\newcommand{\refSubsubsection}[1]{Sub-subsection \ref{sssec:#1}}
\newcommand{\refParagraph}[1]{Paragraph \ref{par:#1}}
\newcommand{\refSubparagraph}[1]{Subparagraph \ref{subpar:#1}}
\newcommand{\refTable}[1]{Table \ref{tbl:#1}}
\newcommand{\refFigure}[1]{Figure \ref{fig:#1}}
\newcommand{\lblGeneral}[4][]{
\if\relax\detokenize{#1}\relax % Check if #1 is empty string.
#3{#2}\label{#4:#2}
\else
#3{#2}\label{#4:#1}
\fi
}
\newcommand{\lblChapter}[2][]{
\lblGeneral[#1]{#2}{\chapter}{ch}
}
\newcommand{\lblSection}[2][]{
\lblGeneral[#1]{#2}{\section}{sec}
}
\newcommand{\lblSubsection}[2][]{
\lblGeneral[#1]{#2}{\subsection}{subsec}
}
\newcommand{\lblSubsubsection}[2][]{
\lblGeneral[#1]{#2}{\subsubsection}{sssec}
}
\newcommand{\lblParagraph}[2][]{
\lblGeneral[#1]{#2}{\paragraph}{par}
}
\newcommand{\lblSubparagraph}[2][]{
\lblGeneral[#1]{#2}{\subparagraph}{subpar}
}
\newcommand{\lblTable}[2][]{
\textbf{\lblGeneral[#1]{#2}{\caption}{tbl}}
}
\newcommand{\lblFigure}[2][]{
\textbf{\lblGeneral[#1]{#2}{\caption}{fig}}
}
%#endregion
% Graphics package for including images
%#region
\RequirePackage{graphicx}
\RequirePackage[hypcap=true]{caption}
\newcommand{\ig}[2][0.5in]{
\includegraphics[keepaspectratio,width=#1]{#2}
}
\newcommand{\cfig}[4]{%
\begin{figure}[ht]%
\centering%
#4{#1}%
\caption{#3}%
\label{fig:#2}%
\end{figure}%
}
\newcommand{\centerfig}[3]{\cfig{#1}{#2}{#3}{\includegraphics}}
\newcommand{\centerfigw}[4][\textwidth]{\cfig{#2}{#3}{#4}{\includegraphics[keepaspectratio,width=#1]}}
\newcommand{\bigfig}[4][1in]{%
\bigfloat[#1]{%
\captionsetup{type=figure}%
\includegraphics[keepaspectratio,width=\bfFigureWidth]{#2}%
\captionof{figure}{#4}%
\label{fig:#3}%
}%
}
%#endregion
% Paragraph formatting.
%#region
\setlength{\parindent}{0pt}
\setlength{\parskip}{2ex plus 0.5ex minus 0.5ex}
%#endregion
% Table formatting.
%#region
\RequirePackage{tabularray}
\RequirePackage{csvsimple-l3}
%#endregion
% Glossary formatting.
%#region
\RequirePackage[xindy,nopostdot,toc,sort=standard]{glossaries}
%#endregion
% Index formatting.
%#region
\RequirePackage{makeidx}
\RequirePackage{xstring}
\newcommand{\idx}[1]{\StrSubstitute{#1}{!}{ }\index{#1}}
%#endregion
% Margin Note formatting.
%#region
\RequirePackage{marginnote}
\colorlet{marginTextColor}{PrimeBlue}
\renewcommand{\marginfont}{\small\color{marginTextColor}}
% Put a glossary definition in a margin note.
% Optional parameter is vertical adjustment of the note.
\newcommand{\mdef}[3][0pt]{%
\index{\glsentryname{#2}}% Add a reference to this in the index.
\textbf{#3{#2}}% This is the text that appears on the page.
\marginnote{% Create the margin note.
\textsf{\textbf{%
\Glsentryname{#2}:% Create the title of the margin note.
}}%
\glsdesc*{#2}% Create the text of the margin note.
}[#1]%
}
\newcommand{\margindef}[2][0pt]{%
\mdef[#1]{#2}{\gls}%
}
\newcommand{\Margindef}[2][0pt]{%
\mdef[#1]{#2}{\Gls}%
}
% Put a footnote in a margin note.
% Optional parameter is vertical adjustment of the note.
\newcommand{\mnote}[2][0pt]{%
\footnotemark%
\marginnote{%
\footnotemark[\value{footnote}]#2%
}[#1]%
}
\newcommand{\mfig}[5][0pt]{%
% This strut ensures that the margin figure is counted as part of the
% following paragraph and is vertically aligned with it.
\strut%
\marginnote{%
\captionsetup{%
type = figure,%
font = {color=marginTextColor},%
}%
{\centering#5{#2}\par}%
\captionof{figure}{#4}%
\label{fig:#3}%
}[#1]%
}
\newcommand{\marginfig}[4][0pt]{%
\mfig[#1]{#2}{#3}{#4}{\includegraphics}%
}
\newcommand{\marginfigw}[5][0pt]{%
\mfig[#1]{#2}{#3}{#4}{\includegraphics[keepaspectratio,width=#5]}%
}
%#endregion
% Use Hyperref to automatically create links in the document
%#region
\RequirePackage{hyperref}
\hypersetup{colorlinks=true, allcolors=PrimeBlue}
%#endregion
% Define custom title page.
%#region
\newcommand{\PrimeTitlePage}[1]{
\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{#1/prime_rule.pdf}
}
% The numbers here are just what looks good.
\put(100pt,0pt){
\includegraphics{#1/prime_heartbeat.pdf}
}
}
\sAuthor
Revision \sVersion
\sDate
\vfill
}
\end{sffamily}
\end{titlepage}
}
%#endregion