-
Notifications
You must be signed in to change notification settings - Fork 15
/
hkuthesis.cls
297 lines (247 loc) · 8.46 KB
/
hkuthesis.cls
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
%%
%% LaTeX Template for HKU MPhil and PhD Thesis
%%
%% Developed by Macro Yau
%% https://github.com/MacroYau/HKU-Thesis-LaTeX-Template
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{hkuthesis}[2019/02/11 v1.2.0 HKU MPhil and PhD Thesis Class]
\def\HKU{The University of Hong Kong}
%% Global Dependencies
\RequirePackage{etoolbox}
\RequirePackage{calc}
%% Metadata
% Degree types
\def\MPhil{Master of Philosophy}
\def\PhD{Doctor of Philosophy}
\newcommand{\degreename}{\PhD}
\DeclareOption{mphil}{\renewcommand{\degreename}{\MPhil}}
\DeclareOption{phd}{\renewcommand{\degreename}{\PhD}}
% Previous degrees and professional qualifications
\def\qualifications#1{\gdef\@qualifications{#1}}
% Notice of "Temporary Binding for Examination Purposes"
\def\exam{Temporary Binding for Examination Purposes}
\newcommand{\printexamnotice}{}
\DeclareOption{exam}{\renewcommand{\printexamnotice}{\exam\\}}
%% Global Styles
% Customisable parameters
\def\dotfillwidth{0.5em} % Dot fill width for signature line and the table of contents
\def\parspacing{1em} % Spacing between two paragraphs
\def\linespacing{1.25} % Line spacing factor (1.25 equivalent to typical "1.5 line spacing")
\def\appendixnumbering{\Roman} % Appendix numbering style (\Roman or \arabic)
% Template based on the book class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions\relax
\LoadClass[a4paper,openany]{book}
% Page layout
\RequirePackage[a4paper,top=25mm,bottom=25mm,left=35mm,right=35mm]{geometry}
\pagestyle{plain} % Page number at the bottom
\RequirePackage{emptypage} % Disables page number on empty pages
% Text formatting
\RequirePackage{mathptmx} % Uses Times New Roman font by default
\RequirePackage{setspace} % Customises line spacing
\setstretch{\linespacing} % Global line spacing
\setlength{\parskip}{\parspacing} % Increases spacing between paragraphs
\RequirePackage{titlesec} % Customises chapter and section headings
\RequirePackage{indentfirst} % First paragraphs should be indented
\RequirePackage[final]{microtype} % Enhances text spacing and justification
% Chapter and section headings formatting
\titlespacing*{\chapter}{0pt}{-20pt}{40pt}
\titleformat{\chapter}[display]{\centering\Large\bfseries}{\@chapapp~\thechapter}{0pt}{}{}
\titlespacing*{name=\chapter,numberless}{0pt}{20pt}{40pt}
\titleformat{\section}{\large\bfseries}{\thesection}{\parspacing}{}{}
\titleformat{name=\section,numberless}{\centering\large\bfseries}{}{\parspacing}{}{}
\titleformat{\subsection}{\normalsize\bfseries}{\thesubsection}{\parspacing}{}{}
% Signature box
\def\signaturewidth{0.75} % Signature box width in percentage of \textwidth
\def\dotfill#1{\cleaders\hbox to #1{.}\hfill}
\newcommand\dotline[2][\dotfillwidth]{\leavevmode\hbox to #2{\dotfill{#1}\hfil}}
\def\signature#1#2{
\noindent #1 \enspace \dotline{\signaturewidth\textwidth} \\
\vspace*{-0.25em}
{\center #2}
}
%% Front Matter
% Macro for adding a front matter page to the table of contents
\newcommand{\addfrontmattertotoc}[1]{
\addcontentsline{toc}{chapter}{#1}
}
% Abstract
\RequirePackage{xifthen}
\newcommand{\abstract}[1][]{
\pagestyle{empty}
\pagenumbering{alph}
\begin{center}
\printexamnotice
\vspace{2em}
Abstract of thesis entitled \\
\vspace{2em}
{\large{\bf ``\@title''}} \\
\vspace{1em}
Submitted by \\
\vspace{1em}
{\large{\bf \@author}} \\
\vspace{1em}
\begin{spacing}{1.0}
for the degree of \degreename \\
at \HKU \\
in \@date \\
\end{spacing}
\end{center}
\vspace{2em}
\input{contents/frontmatter/abstract} \\
\newline
\ifthenelse{\isempty{#1}}{}{\rightline{(#1 words)}}
\vspace*{\fill}
}
% Title page
\renewcommand{\titlepage}{
\cleardoublepage
\thispagestyle{empty}
\large
\vspace*{2em}
\begin{center}
\begin{spacing}{2.0}
{\LARGE{\bf \@title}} \\
\vspace{0.5em}
by \\
\vspace{0.5em}
{\LARGE{\bf \@author}} \\
\vspace{0.5em}
\@qualifications \\
\end{spacing}
\vspace*{\fill}
\printexamnotice
\vspace{2em}
\begin{spacing}{1.0}
A thesis submitted in partial fulfilment of the requirements for \\
the Degree of \degreename \\
at \HKU. \\
\end{spacing}
\vspace{2em}
\@date
\vspace{2em}
\end{center}
\normalsize
}
% Dedication
\newcommand{\dedication}{
\cleardoublepage
\thispagestyle{empty}
\vspace*{\fill}
\begin{center}
{\large \input{contents/frontmatter/dedication}}
\end{center}
\vspace*{\fill}
}
% Declaration
\newcommand{\declaration}{
\cleardoublepage
\pagestyle{plain}
\setcounter{page}{1}
\pagenumbering{roman}
\chapter{Declaration}
I declare that this thesis represents my own work, except where due acknowledgement is made, and that it has not been previously included in a thesis, dissertation or report submitted to this University or to any other institution for a degree, diploma or other qualifications.
\IfFileExists{contents/frontmatter/declaration}{\input{contents/frontmatter/declaration}}{}
\vspace{8em}
\begin{center}
\signature{Signed}{\@author}
\vspace{8em}
\end{center}
}
% Acknowledgements
\newcommand{\acknowledgements}{
\chapter{Acknowledgements}
\input{contents/frontmatter/acknowledgements}
}
%% Table of Contents
% Items
\appto\tableofcontents{\addfrontmattertotoc{Table of Contents}} % Includes itself
\appto\listoffigures{\addfrontmattertotoc{List of Figures}} % Includes the list of figures
\preto\listoffigures{\protect\setcounter{tocdepth}{1}} % Forces to appear
\appto\listoftables{\addfrontmattertotoc{List of Tables}} % Includes the list of tables
\preto\listoftables{\protect\setcounter{tocdepth}{1}} % Forces to appear
\BeforeBeginEnvironment{chapters}{\protect\setcounter{tocdepth}{2}} % Shows subsections
\appto\appendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}} % Hides sections in appendices
\appto\backmatter{\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}} % Hides sections in back matter pages
% Spacing
\newlength{\tocsep}
\setlength{\tocsep}{\parspacing*2}
\BeforeBeginEnvironment{chapters}{\addtocontents{toc}{\vspace{\tocsep}}} % Separates the chapters from front matter
\AfterEndEnvironment{chapters}{\addtocontents{toc}{\vspace{\tocsep}}} % Separates the chapters from back matter
% Formatting
\RequirePackage{titletoc}
\def\tocdottedlineformat{\hspace*{\dotfillwidth}\titlerule*[\dotfillwidth]{.}\contentspage}
% Front matter
\newcommand\frontmattertocformat{
\titlecontents{chapter}[0em]{\itshape}
{}{}
{\tocdottedlineformat}
}
\appto\frontmatter{\frontmattertocformat}
% Chapters
\newcommand\chapterstocformat{
\titlecontents{chapter}[1.6em]{\bfseries}
{\contentslabel{1.6em}}{}
{\normalfont\hspace*{\fill}\bfseries\contentspage}
}
\appto\mainmatter{\chapterstocformat}
% Section
\titlecontents{section}[4em]{}
{\contentslabel{2.4em}}{\hspace*{-2.4em}}
{\tocdottedlineformat}
% Subsection
\titlecontents{subsection}[7.2em]{}
{\contentslabel{3.2em}}{\hspace*{-3.2em}}
{\tocdottedlineformat}
% Appendices
\newcommand\appendixtocformat{
\titlecontents{chapter}[6em]{\normalfont}
{\contentslabel[\appendixname~\thecontentslabel]{6em}}{}
{\tocdottedlineformat}
}
\appto\appendix{\appendixtocformat}
% Back matter
\newcommand\backmattertocformat{
\titlecontents{chapter}[0em]{\normalfont}
{}{}
{\tocdottedlineformat}
}
\appto\backmatter{\backmattertocformat}
% List of figures
\titlecontents{figure}[2em]{\normalfont}
{\hspace*{-2em}\contentslabel[{\bf \figurename~\thecontentslabel}]{0em}\\*}{}
{\tocdottedlineformat}
% List of tables
\titlecontents{table}[2em]{\normalfont}
{\hspace*{-2em}\contentslabel[{\bf \tablename~\thecontentslabel}]{0em}\\*}{}
{\tocdottedlineformat}
%% Chapters
\newenvironment{chapters}{
\mainmatter
\pagestyle{plain}
}{}
%% Appendices
\newenvironment{appendices}{
\appendix
\pagestyle{plain}
\renewcommand{\thechapter}{\appendixnumbering{chapter}}
}{}
%% Figures and Tables
% Always centres figure and table environments
\appto\@floatboxreset\centering
% Increases separation from text
\AtBeginEnvironment{figure}{\addvspace{\parspacing}}
\AtBeginEnvironment{table}{\addvspace{\parspacing}}
% Table spacing
\renewcommand{\arraystretch}{\linespacing} % Increases the distance between two table rows
\setlength{\tabcolsep}{\parspacing} % Spacing between two columns
% Captions
\RequirePackage{caption}
\newlength{\captionskip}
\setlength{\captionskip}{\parspacing*2}
\captionsetup{labelfont=bf,labelsep=quad,format=hang,skip=\captionskip}
\captionsetup{margin={\parindent,0pt},oneside}
\RequirePackage{subcaption}
\captionsetup[sub]{position=below,labelfont=rm,skip=\parspacing}
\newcommand{\subfigurerow}{\par\vspace{\captionskip}}