-
Notifications
You must be signed in to change notification settings - Fork 0
/
masterthesis.cls
1695 lines (1408 loc) · 49.2 KB
/
masterthesis.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% !TEX TS-program = lualatex
% !TEX encoding = utf-8
% !TEX root = thesis.tex
% !TEX spellcheck = en-US
% !BIB TS-program = biber
% ################################################################ LICENSE
%
% masterthesis
%
% Copyright >= 2023 Jack Coleman
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3c of this license
% or (at your option) any later version. The latest version of this
% license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Jack Coleman.
%
% This work consists of the files present in the repo.
%
% See README.md for a detailed list of files and their usage
%
% See LICENSE for a copy of the license
%
% ################################################################ CONTENTS
% ┌───────────────────────────────────────────────────────────────┐
% │ Contents of masterthesis.cls │
% ├───────────────────────────────────────────────────────────────┘
% │
% ├── LICENSE
% ├── CONTENTS
% ├──┐CLASS
% │ ├── TOGGLES
% │ ├── OPTIONS
% │ └── DEFAULTS
% ├── ENGINE
% ├── PACKAGES
% ├──┐COMMANDS
% │ ├── TEXT
% │ ├── TABLES
% │ └──┐IMAGES
% │ ├──┐SMALL SIZE
% │ │ ├── SINGLE IMAGE
% │ │ ├── HORIZONTALLY ALIGNED IMAGES
% │ │ └── VERTICALLY ALIGNED IMAGES
% │ └──┐LARGE SIZE
% │ ├── HORIZONTAL ORIENTATION
% │ └── VERTICAL ORIENTATION
% ├──┐STYLE
% │ ├── TOC DEPTH
% │ ├──┐GEOMETRY
% │ │ ├── COVER
% │ │ └──┐BODY
% │ │ ├── TWOSIDE
% │ │ ├── ASYMMETRIC
% │ │ ├── ONESIDE
% │ │ └── GLOBAL
% │ ├── LENGTHS
% │ ├── ACRONYM
% │ ├── CAPTION
% │ ├──┐CSQUOTES
% │ │ ├── GLOBAL
% │ │ └── BLOCK
% │ ├── XCOLORS
% │ ├── EMPTYPAGE
% │ ├──┐ENUMITEM
% │ │ ├── GLOBAL
% │ │ ├── ENUMERATE
% │ │ ├── ITEMIZE
% │ │ └── RESEARCH QUESTIONS
% │ ├──┐FANCYHDR
% │ │ ├── DEFINING MARKS
% │ │ ├──┐DEFINING STYLES
% │ │ │ ├── FRONTMATTER
% │ │ │ ├── MAIN MATTER
% │ │ │ └── CHAPTER PAGES
% │ │ ├── DEFINING RULES
% │ │ └── APPLYING RULES
% │ ├── FLOATBARRIER
% │ ├── FONTSPEC
% │ ├──┐FOOTNOTES
% │ │ ├── XCOLOR
% │ │ ├── FOOTMISC
% │ │ └── FOOTNOTEBACKREF
% │ ├── HYPERREF
% │ ├── LETTRINE
% │ ├── LSTLISTING
% │ ├── NOINDENTAFTER
% │ ├── SIUNITX
% │ ├──┐TABULARRAY
% │ │ ├── GENERAL
% │ │ ├── NORMAL
% │ │ └── ROTATED
% │ ├──┐TITLESEC
% │ │ ├── FORMAT
% │ │ └── SPACING
% │ ├── TITLETOC
% │ ├── TOCBIBIND
% │ ├── TODONOTES
% │ ├── TOTALCOUNT
% │ ├── ZREF-CLEVER
% │ ├── WATERMARK
% │ └── WIP2 CLASS OPTION
% ├──┐PAGES
% │ ├── COVER
% │ └── PLACEHOLDER
% │
% └───────────────────────────────────────────────────────────────
% ################################################################ CLASS
\NeedsTeXFormat{LaTeX2e}[2022-11-01]
\ProvidesClass{masterthesis}[2024.10.19 Modern LuaLaTeX thesis class]
% ################################ TOGGLES
% used for toggles
\RequirePackage{etoolbox}
% according to your desired output (book or PDF), and your book layout (content on both pages or only on the right page),
% this class provides two toggles to activate three modes:
%
% a PDF for digital reading or stapled pages that you read one page at the time,
% and thus benefit from simmetric margins when scrolling
% this is the default mode
%
% ╔═══════════╗
% ║ HEADER ║
% ║ --------- ║
% ║ text text ║
% ║ text text ║
% ║ text text ║
% ║ text text ║
% ║ 3 ║
% ╚═══════════╝
%
% a normal book that is printed on both sides
% this mode requires the "twoside" option in the \documentclass command
%
\newtoggle{twoside}
%
% ╔═══════════╤═══════════╗
% ║ HEADER │ HEADER ║
% ║ --------- │ --------- ║
% ║ text text │ text text ║
% ║ text text │ text text ║
% ║ text text │ text text ║
% ║ text text │ text text ║
% ║ 2 │ 3 ║
% ╚═══════════╧═══════════╝
%
% a book that is printed on one side, and when binsws has content only on the right side
% may be required by your institution or to reach the minimum number of pages needed for binding
% this mode requires the "asymmetric" option in the \documentclass command
%
\newtoggle{asymmetric}
%
% ╔═══════════╤═══════════╗
% ║ │ HEADER ║
% ║ │ --------- ║
% ║ │ text text ║
% ║ │ text text ║
% ║ │ text text ║
% ║ │ text text ║
% ║ │ 3 ║
% ╚═══════════╧═══════════╝
% use this class options to add a draft watermark at the top of each page
% and reduce compilation time by not loading certain aesthetic commands
% but remember to remove it fwhen you compile the final version of your thesis
% we are not using the standard "draft" class option as we still want to see images in early thesis versions
\newtoggle{wip}
% use this class option to further reduce compilation time,
% but consider it will redefine some commands with dummy versions
% search for "\iftoggle{wip2}" below to get the complete list of affected commands
\newtoggle{wip2}
% ################################ OPTIONS
\DeclareOption{oneside}{
\togglefalse{twoside}
\togglefalse{asymmetric}
}
\DeclareOption{twoside}{
\toggletrue{twoside}
\togglefalse{asymmetric}
}
\DeclareOption{asymmetric}{
\togglefalse{twoside}
\toggletrue{asymmetric}
}
\DeclareOption{wip2}{
\toggletrue{wip2}
}
\DeclareOption{wip}{
\toggletrue{wip}
}
% if someone wants to use the draft mode, we also enable the other draft options
\DeclareOption{draft}{
\toggletrue{wip2}
\toggletrue{wip}
}
% ################################ DEFAULTS
% pass all unknown options to the book class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
% process all invoked options, activating the relative toggles
\ProcessOptions\relax
% printed layout, openright only matters for books printed on both sides
\iftoggle{twoside}{
\PassOptionsToClass{twoside,openright}{book}
}{
\PassOptionsToClass{oneside,openany}{book}
}
% load the book class
\LoadClass{book}
% ################################################################ ENGINE
% lualatex check
% https://tex.stackexchange.com/a/6716/213962
\ifcsname directlua\endcsname
% then lualatex is being used
\else
\ClassError{masterthesis}{LuaLaTeX is not being used}{Use LuaLaTeX, not XeLaTeX or pdfLaTeX!}
\stop
\fi
% ################################################################ PACKAGES
% loaded in alphabetical order, except when load order is important
% localized terms, hyphenation and typographic rules
\RequirePackage[italian,american]{babel}
% break long urls
% must be loaded before biblatex
\RequirePackage{xurl}
% bibliography generator powered by biber
% must be loaded after babel
\RequirePackage[backend=biber,backref,ibidtracker=constrict,parentracker=true,sorting=nyt,style=apa]{biblatex}
% customized quotes
% required by babel
\RequirePackage{csquotes}
% localized date in watermark
\RequirePackage[style=iso]{datetime2}
% blind text
\iftoggle{wip}{\RequirePackage{lipsum}}{}
% create proper empty pages
\iftoggle{twoside}{\RequirePackage{emptypage}}{}
% custom itemize and enumerate lists
\RequirePackage{enumitem}
% header and footer
\RequirePackage{fancyhdr}
% fonts
\RequirePackage{fontspec}
% hanged and spaced footnotes
\iftoggle{wip}{}{\RequirePackage[hang]{footmisc}}
% better footnote punctuation kerning and comma separator for multiple footnotes
% proper usage: text\footnote{foot text}.
\iftoggle{wip}{}{\RequirePackage{fnpct}}
% layout and margins
\RequirePackage{geometry}
% better word spacing and typographic improvements
% must be loaded before setspace
% it doubles compilation time, so it's only loaded for the final version of the thesis
\iftoggle{wip}{}{\RequirePackage{microtype}}
% line spacing
% must be loaded before hyperref for correct footnote links
% must be loaded before footmisc for correct spacing
\RequirePackage{setspace}
% format chapter and section titles
% must be loaded before hyperref
\RequirePackage[newparttoc]{titlesec}
% format toc
% must be loaded before hyperref
% must be loaded after titlesec
\RequirePackage{titletoc}
% faster compilation and bookmark creation, loads hyperref
% still requires two passes after biber, but it's way faster
\RequirePackage{bookmark}
% math font
\RequirePackage{amsmath}
\RequirePackage[math-style=ISO,bold-style=ISO]{unicode-math}
\iftoggle{wip}{}{\RequirePackage{lualatex-math}}
% output also the reference type when cross referencing (Figure 1.1 instead of 1.1)
% must be loaded after hyperref
% must be loaded after amsmath and glossaries
% replaces cleveref
\RequirePackage{zref-clever}
% list of acronyms
% must be loaded after hyperref and cleveref/zref-clever
\RequirePackage[printonlyused,withpage]{acronym}
% backref links in footnotes
% must be loaded after hyperref
\iftoggle{wip}{}{\RequirePackage{footnotebackref}}
% large first letter (drop cap) at the beginning of chapters or sections
\RequirePackage{lettrine}
% better line breaking
% slow down compilation
\iftoggle{wip}{}{\RequirePackage{linebreaker}}
% format monospaced text, used through lstlisting environment
\RequirePackage{listings}
% prevent line breaks in lettrine and code blocks
\RequirePackage{needspace}
% remove indentation after environments
\RequirePackage{noindentafter}
% allow to insert white pages before chapters and parts
\iftoggle{twoside}{\RequirePackage{nextpage}}{}
% control float positioning via \FloatBarrier
\RequirePackage{placeins}
% hyphenation in table cells
\RequirePackage{ragged2e}
% rotated tables
\RequirePackage{rotating}
% format numbers
\RequirePackage{siunitx}
% easily place and label more pictures in the same figure or table, loads caption
\RequirePackage{subcaption}
% better tables
\RequirePackage{tabularray}
% toc, lof and lot in toc
\RequirePackage{tocbibind}
% add todo in the document and collect them in a dedicated list, loads tikz
\iftoggle{wip}{
\RequirePackage[textwidth=15mm]{todonotes}
}{
\RequirePackage{tikz}
}
% store the total number of tables and figures
% used to display list of tables and figures only if they are effectively present
\RequirePackage{totalcount}
% colors
\RequirePackage{xcolor}
% add and splits cover from external PDF
% must be loaded after xcolor
\RequirePackage{pdfpages}
% resize images if they exceed size
% must be placed after xcolor and pgfornament
\RequirePackage{adjustbox}
% ################################################################ COMMANDS
% ################################ TEXT
% empty \lipsum[1] if package is not loaded
\ProvideDocumentCommand{\lipsum}{o}{}
% environment used to comment out many lines of code
\NewDocumentEnvironment{ignore}{+b}% +=multiple paragraphs in body, b=body in #1
{}% before
{}% after
% used to emphasize text in a paragraph using the italic font
\renewcommand{\emph}[1]{\textit{#1}}
% used to emphasize text at the beginning of a list, using the bold font and a colon
\newcommand{\startItem}[1]{\textbf{#1:}}
% used to emphasize technical terms, using the monospaced font
\newcommand{\snippet}[1]{\lstinline{#1}}
% ################################ TABLES
% define a cell in a table, useful for IDs
\newcommand{\iddef}[1]{\Hy@raisedlink{\hypertarget{#1}{}}#1}
% reference a cell in a table, useful for IDs
\newcommand{\idref}[1]{\hyperlink{#1}{#1}}
% ################################ IMAGES
% images can be added using an environment (outerImage) to wrap a layout command (innerImageOne, ...)
% outerImage is a figure environment with
% - float positioning with preference top > bottom > dedicated page
% - centered content
\newenvironment{outerImage}{
\begin{figure}[htbp]
\centering
}{
\end{figure}
}
% ################ SMALL SIZE
% these images are positioned in a normal page with text below or above them
% always use these commands inside a outerImage envionment
% ######## SINGLE IMAGE
\newcommand{\innerImageOne}[2]{
% arguments: 1 image id (no spaces), 2 image name
% not using captionbox as caption text starts from image, which can be less than \figuremaxwidth long
\adjustimage{width=\figuremaxwidth,max height=\figuremaxheight}{#1}
\caption{#2}
\label{#1}
}
% ######## HORIZONTALLY ALIGNED IMAGES
\newcommand{\innerImageTwoH}[6]{
% arguments: 1 figure id (no spaces), 2 figure short name, 3 figure long description caption, 4 left image name (no spaces), 5 left image caption text, 6 right image name (no spaces), 7 right image caption text
% remove \centering if most subcaptions are more than one line long
\subcaptionbox{\centering #2\label{#1}}{\adjustimage{width=0.48\figuremaxwidth,max height=\figuremaxheight}{#1}}%
\hfill
\subcaptionbox{\centering #4\label{#3}}{\adjustimage{width=0.48\figuremaxwidth,max height=\figuremaxheight}{#3}}%
%\caption[#6]{#6. #7}
\caption{#6}
\label{#5}
}
\newcommand{\innerImageThreeH}[8]{
% arguments: 1 figure id (no spaces), 2 figure short name, 3 figure long description caption, 4 left image name (no spaces), 5 left image caption text, 6 right image name (no spaces), 7 right image caption text
% remove \centering if most subcaptions are more than one line long
\subcaptionbox{\centering #2\label{#1}}{\adjustimage{width=0.32\figuremaxwidth,max height=\figuremaxheight}{#1}}%
\hfill
\subcaptionbox{\centering #4\label{#3}}{\adjustimage{width=0.32\figuremaxwidth,max height=\figuremaxheight}{#3}}%
\hfill
\subcaptionbox{\centering #6\label{#5}}{\adjustimage{width=0.32\figuremaxwidth,max height=\figuremaxheight}{#5}}%
\caption{#8}
\label{#7}
}
% ######## VERTICALLY ALIGNED IMAGES
\newcommand{\innerImageTwoV}[6]{
% arguments: 1 figure id (no spaces), 2 figure short name, 3 figure long description caption, 4 top image name (no spaces), 5 top image caption text, 6 bottom image name (no spaces), 7 bottom image caption text
% remove \centering if most subcaptions are more than one line long
\subcaptionbox{\centering #2\label{#1}}{\adjustimage{width=\figuremaxwidth,max height=\figuremaxheight}{#1}}%
\vspace{\baselineskip}
\subcaptionbox{\centering #4\label{#3}}{\adjustimage{width=\figuremaxwidth,max height=\figuremaxheight}{#3}}%
%\caption[#6]{#6. #7}
\caption{#6}
\label{#5}
}
\newcommand{\innerImageThreeV}[8]{
% arguments: 1 figure id (no spaces), 2 figure short name, 3 figure long description caption, 4 left image name (no spaces), 5 left image caption text, 6 right image name (no spaces), 7 right image caption text
% remove \centering if most subcaptions are more than one line long
\subcaptionbox{\centering #2\label{#1}}{\adjustimage{width=\figuremaxwidth,max height=8\baselineskip}{#1}}%
\vspace{\baselineskip}
\subcaptionbox{\centering #4\label{#3}}{\adjustimage{width=\figuremaxwidth,max height=8\baselineskip}{#3}}%
\vspace{\baselineskip}
\subcaptionbox{\centering #6\label{#5}}{\adjustimage{width=\figuremaxwidth,max height=8\baselineskip}{#5}}%
\caption{#8}
\label{#7}
}
% ################ LARGE SIZE
% these images are positioned in a dedicated page
% always use these commands inside a outerImage envionment
% ######## HORIZONTAL ORIENTATION
% long landscape images, you need to rotate your head or book
% https://tex.stackexchange.com/a/57531/213962
\newcommand{\innerImageRotated}[2]{
% arguments: 1 image id (no spaces), 2 image name
\begin{adjustbox}{
addcode={\begin{minipage}{\figuremaxheightrotated}}{\caption{#2}\label{#1}\end{minipage}},
rotate=90,
%textareacenter
}
% using \adjincludegraphics because \adjustimage throws error
% should be a bit less than textwidth, since there is also the caption
\adjincludegraphics[
% bad results if \textheight entirely
width=\figuremaxheightrotated,
% leave space for caption and space between
max height=\textwidth-2\baselineskip
]{#1}
\end{adjustbox}
}
% long landscape images with source, use inside outerImage
\newcommand{\innerImageRotatedSource}[3]{
% arguments: 1 image id (no spaces), 2 image name, 3 source
\begin{adjustbox}{
addcode={\begin{minipage}{\figuremaxheightrotated}}{\caption{#2}\label{#1}\source{#3}\end{minipage}},
rotate=90,
%textareacenter
}
\adjincludegraphics[
width=\figuremaxheightrotated,
max height=\textwidth-4\baselineskip
]{#1}
\end{adjustbox}
}
% ######## VERTICAL ORIENTATION
% tall portrait images
\newcommand{\innerImageTall}[2]{
% arguments: 1 image id (no spaces), 2 image name
\adjustimage{width=\figuremaxwidth,max height=\textheight-2\baselineskip}{#1}
\caption{#2}
\label{#1}
}
% ################################################################ STYLE
% ################################ TOC DEPTH
% possible section separators
\newcommand{\headingLevels}{4}
\setcounter{secnumdepth}{\headingLevels}
% sections visible in toc
\setcounter{tocdepth}{\headingLevels}
% sections opened in PDF bookmarks
\bookmarksetup{
numbered,
open,
openlevel=1
}
% ################################ GEOMETRY
% must be placed before setting lengths and configuring fancyhdr
% \geometry papersize or paperwidth have no effect here
% if needed, \geometry{papersize={209.6mm,279.4mm}} should be used in thesis.tex preamble, outside of the class file
\geometry{
%showframe,
heightrounded
}
% margins are stored in a variable so they can be also read by /pages/title.tex
% the same names are used for /contrib/cover.tex and /contrib/cover-bw.tex
\newlength{\outermargin}
\newlength{\innermargin}
\newlength{\abovemargin}% \topmargin is already defined
\setlength{\outermargin}{40mm}
\setlength{\innermargin}{30mm}
\setlength{\abovemargin}{40mm}
% ################ COVER
\newgeometry{
top=\abovemargin,
right=\innermargin,
bottom=\abovemargin,
left=\innermargin,
}
\savegeometry{CoverPage}
% ################ BODY
% ######## TWOSIDE
% use different margins for odd and even pages if two sides is specified
\iftoggle{twoside}{
\newgeometry{
top=\abovemargin,
outer=\outermargin,
bottom=\abovemargin,
inner=\innermargin,
%includehead, skip length before head
%includefoot skip length after foot
} % end twoside geometry
}{ % end twoside true
% ######## ASYMMETRIC
\iftoggle{asymmetric}{
\newgeometry{
top=\abovemargin,
right=\outermargin,
bottom=\abovemargin,
left=\innermargin
} % end asymmetric geometry
}{ % end asymmetric true
% ######## ONESIDE
\newgeometry{
top=\abovemargin,
right=\innermargin,
bottom=\abovemargin,
left=\innermargin
}% end oneside geometry
}% end asymmetric false
}% end twoside false
% ######## GLOBAL
\savegeometry{Body}
% ################################ LENGTHS
% 12pt font \baselineskip = 17.99446pt = 6.32436mm
% 1mm = 2.8453pt
% global 1.25 line spacing
\onehalfspacing
% move floats that are higher than this percentage to a dedicated float page
% (e.g. two images of \figuremaxheight)
% https://tex.stackexchange.com/a/28068/213962
\renewcommand\floatpagefraction{0.80}
\renewcommand\topfraction{0.90}
% https://tex.stackexchange.com/a/568459/213962
\setlength{\textfloatsep}{\baselineskip}
% difference between the \textwidth and the maximum width of figures
% storing this value in a variable also used by caption
\newlength{\figuremargin}
\setlength{\figuremargin}{0mm}
% maximum width of figures and tables
\newlength{\figuremaxwidth}
\setlength{\figuremaxwidth}{\textwidth-2\figuremargin}
% maximum height for small images, the ones surrounded by text, and not in a dedicated page
\newlength{\figuremaxheight}
\setlength{\figuremaxheight}{13\baselineskip}% ~ 70mm
% maximum height for large images, the ones taking a dedicated page
\newlength{\figuremaxheightrotated}
\setlength{\figuremaxheightrotated}{\textheight}
% background image for cover and title pages
\newlength{\bgfigurewidth}
% fancyhdr
\setlength{\headheight}{6mm}
% try to align the last line of every page to the end of the text area
% by stretching the spaces between paragraphs
% unfortunately it is not easy to have all the lines aligned,
% but this system gets the best results
% https://tex.stackexchange.com/q/134081/213962
% https://latexref.xyz/_005cflushbottom.html
% https://ctan.org/pkg/returntogrid
% https://ctan.org/pkg/gridset
\flushbottom
\setlength{\parskip}{0mm plus 1mm}
% without \flushbottom
% ╔═══════════╤═══════════╗
% ║ HEADER │ HEADER ║
% ║ --------- │ --------- ║
% ║ ▒▒▒▒▒▒▒▒▒ │ text text ║ <-- aligned at top
% ║ ▒▒▒▒▒▒▒▒▒ │ text text ║ <-- loss of alignment because of the picture
% ║ text text │ text text ║ however, line spacing is consistent
% ║ │ text text ║
% ║ 2 │ 3 ║
% ╚═══════════╧═══════════╝
%
% with \flushbottom
% ╔═══════════╤═══════════╗
% ║ HEADER │ HEADER ║
% ║ --------- │ --------- ║
% ║ ▒▒▒▒▒▒▒▒▒ │ text text ║ <-- aligned at top
% ║ ▒▒▒▒▒▒▒▒▒ │ text text ║
% ║ │ text text ║ <-- stretch line spacing if needed
% ║ text text │ text text ║ <-- aligned at bottom
% ║ 2 │ 3 ║
% ╚═══════════╧═══════════╝
%
% on pages dedicated to floats, figures are placed at the bottom and not vertically centered
% https://tex.stackexchange.com/a/28565/213962
\setlength{\@fpbot}{0mm}
\setlength{\@fptop}{0mm plus 1fil}
% ################################ ACRONYM
% disable hyperlink color
% https://tex.stackexchange.com/a/73068
\AtBeginDocument{%
\renewcommand*{\AC@hyperlink}[2]{%
\begingroup
\hypersetup{hidelinks}%
\hyperlink{#1}{#2}%
\endgroup
}
}
% ################################ CAPTION
% caption
\captionsetup{
format=hang,
labelfont=bf,
margin={\figuremargin,\figuremargin},
% don't center if the caption has only one line of content
singlelinecheck=false,
% don't invert margins if twoside is specified
oneside
}
% subcaption
\captionsetup[subfigure]{
labelsep=colon
}
% used for figures and tables taken from other publications
\newcommand{\source}[1]{\caption*{\textbf{Source:} #1}}
% ################################ CSQUOTES
% ################ GLOBAL
% define new style
% https://tex.stackexchange.com/a/641634/213962
\DeclareQuoteStyle{italic}% style name
[\itshape]% mark style
[\itshape]% text style
{\textquotedblleft}% opening outer mark
{\textquotedblright}% closing outer mark
{\textquoteleft}% inner opening mark
{\textquoteright}% inner closing mark
% apply new style to all quotes, inline and block
%\setquotestyle{italic}
% ################ BLOCK
% adust margins for for displayquote
% https://tex.stackexchange.com/a/468294/213962
\renewenvironment*{displayquote}
{\begingroup\setlength{\leftmargini}{\parindent}\csq@getcargs{\csq@bdquote{}{}}} % before
{\csq@edquote\endgroup}% after
% displayquote environment can be used to force a blockquote even for little text
\renewcommand{\mkbegdispquote}[2]{\openautoquote}
\renewcommand{\mkenddispquote}[2]{\closeautoquote#1#2}
% ################################ XCOLORS
% overridden in variables file with:
%\definecolor{PrimaryColor}{HTML}{9B0014}
%\colorlet{LinkColor}{PrimaryColor}
% primary
\definecolor{LinkColor}{HTML}{000000}
\definecolor{NumberColor}{HTML}{000000}
% secondary
\definecolor{TitleColor}{HTML}{000000}
\definecolor{HeaderColor}{HTML}{000000}
\definecolor{FooterColor}{HTML}{000000}
\definecolor{FootnoteColor}{HTML}{000000}
% used in presentation, not in the book
\definecolor{PresentationPrimaryColor}{HTML}{000000}
\definecolor{PresentationSecondaryColor}{HTML}{000000}
% ################################ EMPTYPAGE
% avoid empty pages with oneside option
\iftoggle{twoside}{}{
\renewcommand{\cleardoublepage}{\clearpage}
}
% ################################ ENUMITEM
% ################ GLOBAL
% all levels
\setlist{
leftmargin=*,
nosep,
}
% first level
\setlist[1]{
labelindent=\parindent,
topsep=0.5\baselineskip,
% avoid floats to be placed between items
% https://tex.stackexchange.com/a/488227/213962
before=\needspace{5\baselineskip}%
}
% ################ ENUMERATE
\setlist[enumerate]{label*=\arabic*.}
% ################ ITEMIZE
\renewcommand{\labelitemi}{\(\bullet\)}
\renewcommand{\labelitemii}{\(\circ\)}
\renewcommand{\labelitemiii}{\(\bullet\)}
\renewcommand{\labelitemiv}{\(\circ\)}
% ################ RESEARCH QUESTIONS
% custom list
% depth of two levels, first number, then lowercase (e.g. RQ1, RQ1a, RQ1b, RQ2)
% https://tex.stackexchange.com/a/547871/213962
% https://tex.stackexchange.com/a/116103/213962
\newlist{questions}{enumerate}{2}
% to use \ref instead of \cref or \zcref => RQ1, RQ1a, uncomment the following
%\setlist[questions,1]{label={\bfseries RQ\arabic*.},ref=RQ\arabic*}
% clever cross-referecing can be performed via \cref or \zcref
\setlist[questions,1]{
labelindent=0mm,
label={\bfseries RQ\ \arabic*.},
ref=\arabic*
}
\setlist[questions,2]{
label={\bfseries\alph*.},
ref=\thequestionsi\alph*
}
% ################################ FANCYHDR
% defining marks allow to customize the running heads at the top of most pages
% there are different styles according to the oneside/twoside/asymmetric option
% ################ DEFINING MARKS
% new latex marks that replace \markboth, \leftmark and \rightmark
% with \NewMarkClass, \InsertMark and \LastMark
\NewMarkClass{chapter}% Title of first chapter
\NewMarkClass{section}% Title of first section of first chapter
\NewMarkClass{chapternumber}% 1
\NewMarkClass{sectionnumber}% 1.1
% used at every \chapter
\renewcommand{\chaptermark}[1]{
% #1 is the chapter name
\InsertMark{chapter}{\textsc{#1}}
\InsertMark{section}{\textsc{#1}}
%\InsertMark{section}{\textsc{Synopsys}}
\InsertMark{chapternumber}{\textsc{\thechapter}}
\InsertMark{sectionnumber}{\textsc{\thechapter}}
}
% used at every \section
\renewcommand{\sectionmark}[1]{
% #1 is the section name
\InsertMark{section}{\textsc{#1}}
\InsertMark{sectionnumber}{\textsc{\thesection}}
}
% ################ DEFINING STYLES
% ######## FRONTMATTER
% this style is used for chapters in frontmatter or backmatter
% that are longer than one page, e.g. toc, lot, lof, bibliography
% these chapters have no number associated, so no \LastMark{sectionnumber} is used
% these chapters are not organized in sections, so no \LastMark{section} is used
% two-sided book:
% ╔═══════════╤═══════════╗
% ║ C │ C ║
% ║ --------- │ --------- ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ ii │ iii ║
% ╚═══════════╧═══════════╝
% right-sided book:
% ╔═══════════╤═══════════╗
% ║ │ C ║
% ║ │ --------- ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ iii ║
% ╚═══════════╧═══════════╝
% one-sided pdf:
% ╔═══════════╗
% ║ C ║
% ║ --------- ║
% ║ ║
% ║ ║
% ║ ║
% ║ ║
% ║ ii ║
% ╚═══════════╝
\fancypagestyle{frontmatter}{
\fancyhf{}
\iftoggle{twoside}{% style for two-sided book
% left pages
\fancyhead[EL]{\HeaderFont\color{HeaderColor}\LastMark{chapter}}
\fancyfoot[EL]{\thepage}
% right pages, this prevents sections in bibliography like \InsertMark{section}{\textsc{Articles}}
\fancyhead[OR]{\HeaderFont\color{HeaderColor}\LastMark{chapter}}
\fancyfoot[OR]{\thepage}
}{% style for right-sided book and one-sided pdf
\fancyhead[L]{\HeaderFont\color{HeaderColor}\LastMark{chapter}}
\iftoggle{asymmetric}{% style for right-sided book only
\fancyfoot[R]{\thepage}
}{% style for one-sided pdf only
\fancyfoot[C]{\thepage}
}% end asymmetric
}% end twoside
}% end fancypagestyle
% ######## MAIN MATTER
% for most pages of the mainmatter
% each chapter is numbered and organized in sections
% two-sided book:
% ╔═══════════╤═══════════╗
% ║ 1 C1 │ C1S1 1.1 ║
% ║ --------- │ --------- ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ 2 │ 3 ║
% ╚═══════════╧═══════════╝
% right-sided book:
% ╔═══════════╤═══════════╗
% ║ │ C1S1 1.1 ║
% ║ │ --------- ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ ║
% ║ │ 3 ║
% ╚═══════════╧═══════════╝
% one-sided pdf:
% ╔═══════════╗
% ║ 1.1 C1S1 ║
% ║ --------- ║
% ║ ║
% ║ ║
% ║ ║
% ║ ║
% ║ 2 ║
% ╚═══════════╝
% page numbers at the bottom of each page
\fancypagestyle{mainmatter}{
\fancyhf{}
\iftoggle{twoside}{% style for two-sided book
% left pages
\fancyhead[EL]{\HeaderFont\color{HeaderColor}\LastMark{chapternumber} \quad \LastMark{chapter}}
\fancyfoot[EL]{\thepage}
% right pages
\fancyhead[OR]{\HeaderFont\color{HeaderColor}\LastMark{section} \quad \LastMark{sectionnumber}}
\fancyfoot[OR]{\thepage}