aboutsummaryrefslogtreecommitdiff
path: root/projdoc.cls
blob: b43fe56a69da9b9218378b30b2307a3a901fb838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{projdoc}[2024-09-03 class projdoc]

% based on article
\LoadClass{article}

% default word page setup
\PassOptionsToPackage{margin=1in}{geometry}
\PassOptionsToPackage{a4paper}{geometry}
% confusing to acrobat/firefox users
\PassOptionsToPackage{hidelinks}{hyperref}
\PassOptionsToPackage{english}{babel}
\PassOptionsToPackage{noabbrev}{cleveref}
\PassOptionsToPackage{nosort}{cleveref}
\PassOptionsToPackage{nameinlink}{cleveref}
\PassOptionsToPackage{obeyspaces}{url}

% frequently used packages
\RequirePackage{geometry}
\RequirePackage{float}
\RequirePackage{babel}
\RequirePackage{siunitx}
\RequirePackage{csquotes}
\RequirePackage{url}
\RequirePackage{fancyvrb}
\RequirePackage{parskip}
\RequirePackage{fontspec}
\RequirePackage{tabularx}
\RequirePackage{booktabs}
\RequirePackage{needspace}
\RequirePackage{hyperref}
\RequirePackage{microtype}
\RequirePackage{xcolor}
\RequirePackage{etoolbox}
\RequirePackage{graphicx}
\RequirePackage{unicode-math}
\RequirePackage{amsmath}
\RequirePackage{cleveref}
\RequirePackage{adjustbox}
\RequirePackage{xparse}
\RequirePackage{ifdraft}
\RequirePackage{enumitem}
\RequirePackage{subcaption}

% font style
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
\setsansfont{Inter}
\setmonofont[Scale=0.85]{JetBrains Mono}

% fix fonts w/ siunitx
\sisetup{detect-all = true}

% no indented paragraphs, just skip
\parindent=0mm
\bigskipamount=7mm
\medskipamount=4mm

% section placement / appearance
\newlength{\sectionpenalty}
\newlength{\subsectionpenalty}
\newlength{\subsubsectionpenalty}
\setlength{\sectionpenalty}{0.4\textheight}
\setlength{\subsectionpenalty}{0.1\textheight}
\setlength{\subsubsectionpenalty}{0pt}
\def\penaltycheck#1{\ifdimgreater{#1}{0pt}{\needspace{#1}}{}}
\ifdraft{\def\penaltycheck#1{\relax}}{}
\makeatletter
\renewcommand\section{%
	\@startsection{section}{1}%
		{0pt}%
		{1.50em}%
		{1.50ex}%
		{\penaltycheck{\sectionpenalty}\normalfont\bfseries\Large}%
}
\renewcommand\subsection{%
	\@startsection{subsection}{2}%
		{0pt}%
		{1.25em}%
		{1.25ex}%
		{\penaltycheck{\subsectionpenalty}\normalfont\bfseries\large}%
}
\renewcommand\subsubsection{%
	\@startsection{subsubsection}{2}%
		{0pt}%
		{1.00em}%
		{1.00ex}%
		{\penaltycheck{\subsubsectionpenalty}\normalfont\bfseries\normalsize}%
}
\makeatother

% default tight list spacing
\makeatletter
\newlength{\style@parsep}
\newlength{\style@itemsep}
\newlength{\style@itemizemargin}
\setlength{\style@parsep}{1mm}
\setlength{\style@itemsep}{1mm}
\setlength{\style@itemizemargin}{2mm}
\setlist{
	topsep=\dimexpr\style@itemizemargin-\parskip\relax,
	itemsep=\dimexpr\style@itemsep-\style@parsep\relax,
	parsep=\style@parsep,
}
\makeatother

% create a label using \customlabel[<creftype>]{<refname>}{<reftext>} that displays
% <reftext> when \ref{<refname>} is used, or <creftype> <reftext> when
% \cref{<refname>} is used
\makeatletter
\NewDocumentCommand{\customlabel}{omm}{%
  \begingroup
  \cref@constructprefix{#1}{\cref@result}%
  \protected@edef\@currentlabel{#3}%
  \protected@edef\@currentlabelname{#3}%
  \protected@edef\cref@currentlabel{[#1][][\cref@result]#3}
  \label[#1]{#2}%
  \endgroup
}
\makeatother

% \maketitle format
\makeatletter
\let\@project\relax
\def\project#1{\def\@project{#1}}
\let\@organization\relax
\def\organization#1{\def\@organization{#1}}
\let\@version\relax
\def\version#1{\def\@version{#1}}
\def\@maketitle{%
	\centering%
	\parskip=0pt%
	\vspace*{2in}%
	\par{%
		\par{%
			\bfseries\Huge%
			\strut\@title\strut%
		}%
		\par{%
			\Large%
			\strut\@project\strut%
		}%
	}%
	\vspace{1in}%
	\par{%
		\par{%
			\def\and{\par}%
			\parskip=0.5ex%
			\strut\@author\strut%
		}%
		\vspace{2em}%
		\par{%
			\footnotesize\itshape%
			\strut\@organization\strut%
		}%
	}%
	\vfill\flushright%
	\par{%
		\par{\strut{}Version \@version\strut}%
		\par{\strut\@date\strut}%
	}%
	\par\vspace*{2in}%
}
\makeatother

% float here by default
\usepackage{float}
\makeatletter
\def\fps@figure{H}
\def\fps@table{H}
\makeatother

% bibliography
\usepackage[
	backend=biber,
	bibencoding=utf8,
	style=iso-numeric,
	% Technically, Avans University of Applied Sciences requires that we always use APA
	% style references, but this often results in ugly citations when working with
	% technical or online resources. At the end of the day, the bibliography is there
	% to prove we didn't plagiarize or make shit up, so ISO 690 is *probably* fine.
	autocite=plain,
]{biblatex}
\addbibresource{sources.bib}

% default document header/trailer
\makeatletter
\def\projdoc@header{
	% start with title page
	\clearpage
	\begin{titlepage}
	\maketitle
	\thispagestyle{empty}
	\end{titlepage}
}
\newbool{projdoc@cited}
\apptocmd{\abx@aux@cite}{\global\booltrue{projdoc@cited}}{}{}
\def\projdoc@trailer{
	% end with bibliography (if citations used)
	\ifbool{projdoc@cited}{\printbibliography}{}%
}
\AtBeginDocument{\projdoc@header}
\AtEndDocument{\projdoc@trailer}
\makeatother

% store figure/table count in macros
\makeatletter
\def\figurecount{0}%
\def\tablecount{0}%
\def\pagecount{0}%
\AtEndDocument{
	\immediate\write\@mainaux{\string\global\string\def\string\figurecount{\the\value{figure}}}
	\immediate\write\@mainaux{\string\global\string\def\string\tablecount{\the\value{table}}}
	\immediate\write\@mainaux{\string\global\string\def\string\pagecount{\thepage}}
}
\makeatother

% generate table of contents, figures, tables
\def\tablestables{%
	\tableofcontents%
	\label{sec:toc}%
	\ifnumgreater{\figurecount}{0}{\listoffigures}{}%
	\label{sec:lof}%
	\ifnumgreater{\tablecount}{0}{\listoftables}{}%
	\label{sec:lot}%
}

% code
\DeclareUrlCommand\codeinline{%
	\urlstyle{tt}%
	\def\codebreak{\discretionary{\hbox{~\textbackslash{}}}{\hbox{~~}}{}}%
	\def\UrlSpecials{%
		\do\/{\hbox{/}\codebreak}%
		\do\_{\hbox{\_}\codebreak}%
		\do\ {\hbox{\ }\codebreak}%
		\do\-{\hbox{-}\codebreak}%
	}%
	\def\UrlNoBreaks{%
		\do\+%
		\do\.%
		\do\[%
		\do\]%
	}%
	\def\UrlLeft{\hbox{\,}}%
	\def\UrlRight{\hbox{\,}}%
}
\DefineVerbatimEnvironment{blockcode}{Verbatim}{
  tabsize=2,
  obeytabs,
}

% scale down image if it exceeds page margins
\newcommand{\fitimg}[1]{%
	\adjustbox{max width=\linewidth}{#1}%
}

% adjust scale for puml diagrams
\newcommand{\includepumldiag}[1]{%
	\fitimg{\includegraphics[scale=0.6]{#1}}%
}