-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctuth-pkg.tex
984 lines (822 loc) · 30.9 KB
/
ctuth-pkg.tex
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
%!TEX ROOT = ctutest.tex
\ProvidesExplFile{ctuth-pkg.tex}%
{2016/06/15}{0.1 t1606152353}%MY TIMESTAMP HERE {0.1}
{"Packages"\space part\space of\space the\space class\space ctuthesis}
% A lot of the code here is not latex3, but rather the good'ol latex2e code. The reason is that
% it heavily depends on l2e packages, and we decided not to mix the code together too much.
\RequirePackage{lmodern}
\RequirePackage[T1]{fontenc}
\RequirePackage{microtype}
\RequirePackage{graphicx}
\RequirePackage{pdfpages}
%%% BABEL -- LANGUAGE HANDLING
% The loading of the languages is a bit wicked, but it works this way. We load the main language once more
% to make it the default one.
\RequirePackage[\seq_use:Nn \g_ctuthesis_languages_seq {,},\g_ctuthesis_field_mainlanguage_tl]{babel}
% Used for setting title, main or second language
\NewDocumentCommand \selectctulanguage { m } {
\ctuthesis_field_exists:nTF { #1 language }
{ \exp_args:Nx \selectlanguage { \ctuthesis_field_use_default:nn { #1 language } { } } }
{ \msg_error:nnx { ctuthesis } { unknown-field } { #1 language } }
}
%%% COLORS, TEXT FLOW
\RequirePackage{xcolor}
% Define the colors, first in monochrome, then in colour.
\ctuifswitch { savetoner } {
% savetoner: true
\definecolor { ctublue } { CMYK } { 100, 43, 0, 0 }
\definecolor { ctulightblue } { RGB }{ 172, 214, 238 }
\colorlet { ctubluetext } { ctublue }
\colorlet { ctubluerule } { ctulightblue }
\colorlet { ctubluedarkbg } { white }
\colorlet { ctubluedarkfg } { ctublue!50!black }
\colorlet { ctubluedot } { white }%ctulightblue }
\colorlet { ctubluebg } { white }
\colorlet { ctulstbg } { ctubluebg }
\colorlet { ctublueitemi } { ctublue }
\colorlet { ctublueitemii } { ctulightblue }
\colorlet { ctugray } { gray }
\definecolor { ctuorange } { Hsb } { 22, 0.5, 1 }
} {
\ctuifswitch { monochrome } {
% savetoner: false, monochrome: true
\definecolor { ctublue } { gray } { 0.8 }
\definecolor { ctulightblue } { gray } { 0.9 }
\definecolor { ctubluetext } { gray } { 0.4 }
\definecolor { ctubluerule } { gray } { 0.4 }
\definecolor { ctubluedarkbg } { gray } { 0.2 }
\definecolor { ctubluedarkfg } { gray } { 1 }
\definecolor { ctubluedot } { gray } { 0.9 }
\definecolor { ctubluebg } { gray } { 0.95 }
\definecolor { ctulstbg } { gray } { 0.95 }
\definecolor { ctublueitemi } { gray } { 0.4 }
\definecolor { ctublueitemii } { gray } { 0.4 }
\definecolor { ctugray } { gray } { 0.5 }
\definecolor { ctuorange } { gray } { 0.9 }
} {
% savetoner: false, monochrome: false
\definecolor { ctublue } { cmyk } { 1, .43, 0, 0 }
\definecolor { ctulightblue } { cmyk }{ .3, .13, 0, 0 }
\colorlet { ctubluetext } { ctublue }
\colorlet { ctubluerule } { ctublue }
\colorlet { ctubluedarkbg } { ctublue }
\colorlet { ctubluedot } { ctulightblue }
\colorlet { ctubluebg } { ctulightblue!50!white }
\colorlet { ctulstbg } { ctulightblue!50!white }
\colorlet { ctublueitemi } { ctublue }
\colorlet { ctublueitemii } { ctulightblue }
\colorlet { ctugray } { gray }
\definecolor { ctuorange } { cmyk } { 0, .51, 1, 0 }
}
}
\setlength{\parskip}{0pt plus 1pt}
\setlength{\parindent}{11.2pt}
%%% FRONT MATTER --- TWOCOLUMN HANDLING
% This is a "ToC macro" for the twocolumn context
% Arguments: 1) suffix, 2) ToC name
\cs_new_protected:Nn \ctuthesis_maketoc_twocol:nn {
% Start the chapter
\chapter* { #2 }
% locally make rugged pages
\begingroup
\raggedbottom
% We use this trick to add nothing, but also to make sure that
% any \addvspace for less than 20pt is going to be ignored.
\vspace*{-20pt}\addvspace{20pt}
% call the original \@starttoc
\@starttoc { #1 }
\newpage
\endgroup
}
% Environment for the twocolumn frontmatter. It can appear more times in a row
% and should handle it nicely
\NewDocumentEnvironment{ twocolumnfrontmatterpage } { } {
% Set the page geometry to the title one (it's a bit wider)
\ctuthesis_geometry_title:
\newpage
\pagestyle{twocol}
% Start the twocolumn.
\twocolumn[]\relax
% We are narrow, so we wanna be sloppy
\sloppy
% Chapter behaves differently. Both the [] argument and the star * are ignored.
% \DeclareDocumentCommand\chapter{ s o m }{\relax
% % Vertical adjustment
% \vspace* { -\baselineskip }
% \nointerlineskip
% % Zero measure vertical box, the contents are raised by something and typeset
% \vbox to 0pt{\noindent\leavevmode\smash{\raise6pt\hbox to \linewidth{%
% % In the first column its right-aligned, in the second left-aligned.
% % It can't be more than one line.
% \if@firstcolumn\hfil\fi
% \color{ctubluetext}\LARGE\bfseries\sffamily##3
% \if@firstcolumn\else\hfil\fi
% }}}
% \everypar{\noindent}
% }
\DeclareDocumentCommand\chapter{ s o m }{\relax
% Compute the vertical adjustment
\skip_gset:Nn \g_ctuthesis_tempa_skip { - \box_ht:N \strutbox }
{ \LARGE \skip_gsub:Nn \g_ctuthesis_tempa_skip { \box_ht:N \strutbox + \box_dp:N \strutbox } }
% Space used if not at the beginning of a column
\skip_vertical:n { 12pt - \g_ctuthesis_tempa_skip }
% Add the space below the chapter title to the adjustment
\skip_gsub:Nn \g_ctuthesis_tempa_skip { 2pt }
% Vertical adjustment
\vspace* { \g_ctuthesis_tempa_skip }
% Zero measure vertical box, the contents are raised by something and typeset
\noindent \leavevmode
\hbox_to_wd:nn \linewidth {
% In the first column its right-aligned, in the second left-aligned.
% It can't be more than one line.
\if@firstcolumn\hfil\fi
\leavevmode\color{ctubluetext}\LARGE\strut\bfseries\sffamily##3
\if@firstcolumn\else\hfil\fi
}\par
\skip_vertical:n { 2pt }
\everypar{\noindent}
}
\DeclareDocumentCommand \tableofcontents { }{ \ctuthesis_maketoc_twocol:nn { toc } { \contentsname } }
\DeclareDocumentCommand \listoffigures { }{ \ctuthesis_maketoc_twocol:nn { lof } { \listfigurename } }
\DeclareDocumentCommand \listoftables { }{ \ctuthesis_maketoc_twocol:nn { lot } { \listtablename } }
} {
\ctuthesis_geometry_plain:
\clearpage
\onecolumn
\pagestyle{plain}
}
%%% LANGUAGES
% For every of the languages below, if it's initialized, add the
% custom captions of the class
\@ifundefined{captionsenglish}{}{\g@addto@macro\captionsenglish{\ctucaptionsenglish}}
\@ifundefined{captionsczech}{}{\g@addto@macro\captionsczech{\ctucaptionsczech}}
\@ifundefined{captionsslovak}{}{\g@addto@macro\captionsslovak{\ctucaptionsslovak}}
%%% GEOMETRY
% The ratios of inner:outer margins
% Needs to be separate as this to make the colon ":" have the right catcode
\cs_new:Nx \ctuthesis_geometry_hmarginratio: {4\string :6}
% Target textwidth is 33*basesize (10pt to 12pt)
\dim_const:Nn \g_ctuthesis_geometry_textwidth_dim { \tl_use:N \g_ctuthesis_fontsize_tl * 33 }
% Text occupies 75% of the height of the page by default, less if layout-short is active
% The vmargin ratio is set here in the same manner as the hmargin one above
\ctuifswitch { layout-short } {
\dim_const:Nn \g_ctuthesis_geometry_textheight_dim { 1.5\g_ctuthesis_geometry_textwidth_dim }
\cs_new:Nx \ctuthesis_geometry_vmarginratio: {4\string :3}
} {
\dim_const:Nn \g_ctuthesis_geometry_textheight_dim { 0.75\paperheight }
\cs_new:Nx \ctuthesis_geometry_vmarginratio: {5\string :6}
}
% Loading the geometry package.
% Almost the same setting appears again in \ctuthesis_geometry_plain:
\RequirePackage [ a4paper ,
hmarginratio = \ctuthesis_geometry_hmarginratio: ,
textwidth = \g_ctuthesis_geometry_textwidth_dim ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: , ignoreheadfoot ,
% Should be at least \baselineskip
headheight = 16pt ,
marginparsep = 10pt ,
] { geometry }
% Inner margin is 1in + \oddsidemargin. We wanna preserve this value through all
% the different page geometries
\dim_const:Nn \g_ctuthesis_geometry_innermargin_dim { 1in + \the\oddsidemargin }
% The frontmatter pages are a bit wider
\cs_new_protected:Nn \ctuthesis_geometry_title: {
\newgeometry {
% Use the stored innermargin value
inner = \g_ctuthesis_geometry_innermargin_dim ,
% Increase the width by 20%, but do not exceed 420pt
textwidth = \dim_min:nn { 420pt } { 1.2 \g_ctuthesis_geometry_textwidth_dim } ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: ,
headheight = 16pt ,
ignoreheadfoot ,
columnsep=30pt ,
}
}
\cs_new_protected:Nn \ctuthesis_geometry_plain: {
\newgeometry {
% Use the stored innermargin value
inner = \dim_use:N \g_ctuthesis_geometry_innermargin_dim ,
% Otherwise it's the same as in \RequirePackage[...]{geometry}
textwidth = \dim_use:N \g_ctuthesis_geometry_textwidth_dim ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: , ignoreheadfoot ,
headheight = 16pt ,
marginparsep = 10pt ,
}
% Compute the marginparwidth so that we leave 40pt from the page boundary
\marginparwidth \dimexpr \evensidemargin + 1in - \marginparsep - 40pt
}
% Re-initialize the geometry
\ctuthesis_geometry_plain:
%%% TITLES
\usepackage{titlesec}
% two basic parameters: the rule width and distance
\newlength \ctu@title@rulewidth
\newlength \ctu@title@rulesep
\setlength \ctu@title@rulewidth {11pt}
\setlength \ctu@title@rulesep {11pt}
% box used all the time
\newbox\ctu@title@box
% macro that boxifies the header and adds the rule
\long\def\ctu@title@boxify#1#2#3#4{
\sffamily
\bfseries
\setbox\ctu@title@box\vbox{\hsize\dimexpr\linewidth-\ctu@title@rulewidth-\ctu@title@rulesep\relax
\vskip#1
\raggedright
#3
\vskip#2
}
#4
\noindent\begin{tabular}{@{}l@{\hspace*{\ctu@title@rulesep}}l@{}}
\color{ctubluerule}\rule[-\dp\ctu@title@box]{\ctu@title@rulewidth}{\dimexpr\ht\ctu@title@box+\dp\ctu@title@box}
&
\box\ctu@title@box
\end{tabular}\hspace*{-10pt}
\par
}
\long\def\ctu@title@boxify@x#1#2#3#4#5{
\sffamily
\bfseries
\setbox\ctu@title@box\vbox{\parskip0pt\hsize\dimexpr\linewidth-\ctu@title@rulewidth-\ctu@title@rulesep\relax
\vskip#1
\raggedright
#4
\vskip#2
}
#5
\noindent\begin{tabular}{@{}l@{\hspace*{\ctu@title@rulesep}}l@{}}
\color{ctubluerule}
\rule
[\dimexpr\ht\ctu@title@box-#3-#1]
{\ctu@title@rulewidth}
{\dimexpr#1+#3}
&
\box\ctu@title@box
\end{tabular}\hspace*{-10pt}
\par
}
% the part style, very simply organized
\def\ttlh@ctupt#1#2#3#4#5#6#7#8{
\bool_gset_true:N \g_ctuthesis_title_haspart_bool
\ctu@title@boxify{#5}{#3}{
{#1\strut\ifttl@label#2\fi\par}
\vskip30pt
{\color{ctubluetext}#4\strut#8\strut\par}
}{\dp\ctu@title@box\dimexpr\textheight-\ht\ctu@title@box-\baselineskip\relax
}
}
\def\ttlh@ctuch#1#2#3#4#5#6#7#8{
% If the chapter is starred, we still want to \chaptermark it, just we use the variant \chapterstarmark.
\ifttl@label\else\chapterstarmark{#8}\fi
% If the chapter is starred, we still want it in the ToC.
\ifttl@label\else\addcontentsline{toc}{chapter}{#8}\fi
\ctu@title@boxify{#5}{#3}{
{#1\strut\ifttl@label#2\fi\par}
\medskip
{\color{ctubluetext}#4\strut#8\strut\par}
}{}
}
% The section style, very simply organized, subsection style differs only by a missing check for star variant and mark inclusion
% Comments to the chapter style apply here too.
\def\ttlh@ctus#1#2#3#4#5#6#7#8{
\ifttl@label\else\sectionstarmark{#8}\fi
\ifttl@label\else\addcontentsline{toc}{section}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
}
\def\ttlh@ctuss#1#2#3#4#5#6#7#8{
\ifttl@label\else\addcontentsline{toc}{subsection}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
}
\def\ttlh@ctusss#1#2#3#4#5#6#7#8{
\ifttl@label\else\addcontentsline{toc}{subsubsection}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
}
% Modified \ttl@page@ii to use \cleardoublepage instead of some idiocy
\def\ttl@page@ii#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\if@openright
\cleardoublepage
\else
\clearpage
\fi
\@ifundefined{ttl@ps@#6}%
{\thispagestyle{plain}}%
{\thispagestyle{\@nameuse{ttl@ps@#6}}}%
\if@twocolumn
\onecolumn
\@tempswatrue
\else
\@tempswafalse
\fi
\vspace*{\@tempskipa}%
\@afterindenttrue
\ifcase#5 \@afterindentfalse\fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@select{#6}{#1}{#2}{#7}%
\ttl@finmarks
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
\vspace{\@tempskipb}%
\cleardoublepage
\if@tempswa
\twocolumn
\fi
\ignorespaces}
% Part title setting
\bool_new:N \g_ctuthesis_title_haspart_bool
\titleformat \part [ctupt] {\Huge} {{\huge\partname\nobreakspace}\thepart} {0pt} {\huge} [0.6\textheight]
\titlespacing* \part {0pt} {0pt} {0pt}
% Tweak into titlesec to make part number contain \numberline. They did not include it for some reason.
\def\ttl@tocpart{\def\ttl@a{\protect\numberline{\thepart}}}
% Chapter title setting
\titleformat \chapter [ctuch] {\huge} {{\LARGE\chaptertitlename\ }\thechapter} {-0\dp\strutbox} {\LARGE} [40pt]
\titlespacing* \chapter {0pt} {40pt} {15pt}
% Section title setting
\titleformat \section [ctus] {\Large} {\thesection\quad} {14pt} {} [2pt]
\titleformat \subsection [ctuss] {\large} {\thesubsection\quad} {11pt} {} [0pt]
\titleformat \subsubsection [ctusss] {\normalsize} {\thesubsubsection\quad} {10pt} {} [0pt]
% Paragraph title setting: runin, with a dot.
\cs_new:Nn \ctuthesis_title_adddot:n {#1\@addpunct.\ignorespaces}
\titleformat \paragraph [runin] {\normalfont\normalsize\bfseries\sffamily} {\theparagraph} {1em} {\ctuthesis_title_adddot:n}
\titleformat \subparagraph [runin] {\normalfont\normalsize\itshape} {\thesubparagraph} {1em} {\ctuthesis_title_adddot:n}
\titlespacing* \paragraph {0pt} {2.25ex plus 1ex minus .2ex} {1em plus 0.3em minus 0.2em}
\titlespacing* \subparagraph {\parindent} {1.75ex plus 0.5ex minus .2ex} {0.7em plus 0.3em minus 0.15em}
% Subsections are the lowest numbered titles, and also the lowest included in ToC.
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
% Appendix treatment: Even if a chapter in appendix has a star, it will get a number (letter in this case), since
% once you get any appendix, it doesn't make sense not to number some of them.
% Users can use \chapter** if-need-be to get an unnumbered chapter in appendix, but we think it's ridiculous.
\cs_set_eq:NN \ctuthesis_title_orig_appendix: \appendix
\cs_set_eq:NN \ctuthesis_title_orig_chapter: \chapter
\cs_set_eq:NN \ctuthesis_title_orig_makeschapterhead: \@makeschapterhead
% an \if that is true only after \appendix
\newif\ifctu@app \ctu@appfalse
% The new \appendix
\DeclareDocumentCommand \appendix { s s } {
\ctu@apptrue
% Call the old \appendix
\ctuthesis_title_orig_appendix:
% If the document has \part division, let's make "Appendices" a part on their own
\bool_if:NT \g_ctuthesis_title_haspart_bool {
% But only make the notice in ToC if * is used
\IfBooleanTF { #2 } {
% Two stars: If nothing in ToC, at least put there a space.
\addtocontents{toc}{\vskip 2ex plus 0.2pt}
} {
\IfBooleanTF { #1 } {
% One star: Only add "Appendices" in ToC
\cleardoublepage
\addcontentsline { toc } { part } { \appendicesname }
} {
% Zero stars: Make "Appendices" page (will be in ToC implicitly
\part*{ \appendicesname }
}
}
}
% \chapter ignores one star, so that things like {thebibliography} are numbered
\DeclareDocumentCommand \chapter { s } { \ctuthesis_title_orig_chapter: }
% another \appendix will generate a warning and be silently ignored
\DeclareDocumentCommand \appendix { s s } {
\msg_warning:nn { ctuthesis } { appendix-twice }
}
}
\msg_new:nnn { ctuthesis } { appendix-twice } { The~macro~ \token_to_str:N \appendix\ should~
be~used~only~once.~Silently~ignoring. }
%%% TABLE OF CONTENTS, LISTS OF FIGURES AND TABLES
% Right margin in TOC, note that it need not be wider than the page numbers, so we're fine with 1em.
\def\@tocrmarg{1em}
% New dottedtocline, differs from the default by having numberline variable-width and accomodating to the number
\def\ctu@dottedtocline#1#2#3#4#5{\ifnum #1>\c@tocdepth \else
\addvspace{0pt plus .2pt}
{
\leftskip #2\relax
\rightskip\dimexpr\@tocrmarg plus 1fil
\parfillskip -\rightskip
\parindent #3\relax
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\hskip -\leftskip
\def\numberline##1{##1\ }
{#4}
\nobreak
\leaders \hbox {$\m@th \mkern 2mu\hbox {.}\mkern 2mu$}\hfill
\nobreak
{\kern0.5em#5}
\par
}
\fi}
% Part in ToC: centered, with no pagenumber, bf sf, and with nice space above.
\def\l@part#1#2{
\addvspace{2ex plus .2pt}
{
\centering
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\def\numberline##1{\partname \nobreakspace ##1\\}%
\sffamily \bfseries
#1
\par
}\penalty10000\relax
}
% Chapter in ToC: bf sf, no leaders, completely left-aligned, the numberline is variable-width,
% nice space above the chapter line
\def\l@chapter#1#2{
\addvspace{1ex plus .2pt}
{
\raggedright
\rightskip\dimexpr\@tocrmarg plus 1fil
\parfillskip -\rightskip
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\def\numberline##1{##1\hspace*{0.5em}}
\sffamily \bfseries
#1
\nobreak
\hfill
\nobreak
{\kern0.5em#2}
\par
}\penalty9999\relax
}
% The section and lower in Toc. We hope nobody would put `\paragraph`s in ToC
\def\l@section{\ctu@dottedtocline{1}{0.6em}{0em}}
\def\l@subsection{\ctu@dottedtocline{2}{1.2em}{0.6em}}
\def\l@subsubsection{\ctu@dottedtocline{3}{1.8em}{1.2em}}
% Figures and tables in LoF and LoT exactly as sections, just the level is set to -2 so that they're always shown
\def\l@figure{\ctu@dottedtocline{-2}{0.6em}{0em}}
\let\l@table\l@figure
%%% FANCY HEADERS
\RequirePackage{fancyhdr}
% Spacial pagestyle for twocolumnpages in the frontmatter: includes centered pagenumber in the bottom
% and we abuse \fancyhead[C] to include the dividing rule
\fancypagestyle{twocol}{
\fancyhf { }
\fancyfoot [ RO, LE ] { \texttt { \ctufield { preprint } } }
\fancyfoot [ C ] { \thepage }
\fancyhead [ C ] {
\leavevmode
\smash {
\color{ctubluerule}
\rule [ \dimexpr - \textheight - \headsep - 6pt ]{ 11pt }{ \textheight }
}
}
\renewcommand { \headrulewidth } { 0pt }
\renewcommand { \footrulewidth } { 0pt }
\dim_set_eq:NN \headwidth \textwidth
}
\fancypagestyle { cleardoublepage } {
% On \cleardoublepage (without star), we want the page number, but nothing else,
% that is, the same as plain pagestyle
\ps@plain
}
% Plain pagestyle for chapter and part titles: no rules, just the page number
\fancypagestyle { plain } {
\fancyhf { }
\fancyfoot [ RO, LE ] { \texttt { \ctufield { preprint } } }
\fancyfoot [ C ] { \thepage }
\renewcommand \headrulewidth { 0pt }
\renewcommand \footrulewidth { 0pt }
% reset headwidth to the global textwidth
\dim_set_eq:NN \headwidth \g_ctuthesis_geometry_textwidth_dim
}
% Headings pagestyle for standard text pages
\fancypagestyle { headings } {
% Copy the plain pagestyle
\ps@plain
% Include the left/rightmark and leaders
\fancyhead [ LE ] { \ctuthesis_fancy_xlap:nn { right } { \leftmark \ctuthesis_fancy_leaders:n { l } } }
\fancyhead [ RO ] { \ctuthesis_fancy_xlap:nn { left } { \ctuthesis_fancy_leaders:n { r } \rightmark } }
}
% The leaders macro for the fancyhead: nice little boxes. We make three of them: left, right and center-aligned
\box_new:N \g_ctuthesis_fancy_bluerule_l_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_l_box { 10.5pt } {
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
\hfil
}
\box_new:N \g_ctuthesis_fancy_bluerule_r_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_r_box { 10.5pt } {
\hfil
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
}
\box_new:N \g_ctuthesis_fancy_bluerule_c_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_c_box { 10.5pt } {
\hfil
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
\hfil
}
% The leaders macro for the fancyhead: nice little boxes,
% the parameter #1 chooses one of the boxes above
\cs_new_protected:Nn \ctuthesis_fancy_leaders:n {
\hspace*{-1pt}
\leaders \box_use:c {g_ctuthesis_fancy_bluerule_#1_box} \hfill
\hspace*{-1pt}
}
% This macro works as follows: The width of the material is actually zero. We use \hbox_overlap_left/right
% to make the headers as wide as we wish, the direction is in #1. In #2 is the contents, and we suppose
% that it contains \ctuthesis_fancy_leaders: and \left/rightmark in desired order; it's typeset gray sf it
\cs_new_protected:Nn \ctuthesis_fancy_xlap:nn {
\color{ctugray} \sffamily\itshape
\leavevmode \use:c { hbox_overlap_#1:n } {
\hbox_to_wd:nn { \paperwidth - 1in - \evensidemargin + 1em } { #2 }
}
}
% We rename the original \mark... commands and disable them; we do it ourselves
\cs_set_eq:NN \ctuthesis_fancy_markboth_orig:nn \markboth
\cs_set_eq:NN \ctuthesis_fancy_markright_orig:n \markright
\let\markboth\@gobbletwo
\let\markright\@gobble
% New chapter and section marks with no \MakeUppercase
\renewcommand \chaptermark [1] { \ctuthesis_fancy_markboth_orig:nn { \thechapter.\ #1 }{ \thechapter.\ #1 } }
\renewcommand \sectionmark [1] { \ctuthesis_fancy_markright_orig:n { \thesection.\ #1 } }
% Newly defined \chapter/sectionstarmark to be used with unnumbered chapters and sections.
% Not that we like unnumbered ones, but if they need to be there, they sould be in headings, too.
\newcommand \chapterstarmark [1] { \ctuthesis_fancy_markboth_orig:nn { #1 } { #1 } }
\newcommand \sectionstarmark [1] { \ctuthesis_fancy_markright_orig:n { #1 } }
% Better \cleardoublepage that takes proper treatment of the empty pages.
% The starred variant leaves the empty page inbetween really completely empty
\DeclareDocumentCommand \cleardoublepage { s } {
\clearpage
\if@twoside\ifodd\c@page\else
% \IfBooleanTF { #1 } {
% Starred variant: completely empty page
\leavevmode
\thispagestyle{empty}
% } {
% Non-starred variant: include page number
\leavevmode
\thispagestyle{cleardoublepage}
% }
\newpage
% In twocolumn, we need \newpage twice
\if@twocolumn\hbox{}\newpage\fi
\fi\fi
}
%%% FLOATS
\usepackage{float,caption}
% default placement of all floats is `t`
\floatplacement{figure}{t}
\floatplacement{table}{t}
\floatplacement{figure*}{t}
\floatplacement{table*}{t}
% minimum 70% of page height on float pages
\renewcommand{\floatpagefraction}{0.7}
% 2 floats on top, no on bottom
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{0}
\setcounter{totalnumber}{4}
% up to 90% of floats on a mixed page, at least 7% of text
\renewcommand{\topfraction}{0.7}
\renewcommand{\bottomfraction}{0.7}
\renewcommand{\textfraction}{0.2}
% float caption: justification with extra margins on both sides
\DeclareCaptionJustification{myjustify}{\leftskip.8em \rightskip.8em \parfillskip.8em plus 1fil}
% float caption: special format
\DeclareCaptionFormat{myformat}{%
% float name bf sf
\begingroup\sffamily\bfseries#1#2:~\endgroup
% float caption normal font
\begingroup#3\par\endgroup
}
\DeclareCaptionFormat{mysubformat}{%
% float name small caps
#1#2 %
% float caption normal font
\begingroup#3\par\endgroup
}
% plain float style is what we like, with captions at the bottom
\floatstyle{plain}
% restyle already existing floats
\restylefloat{figure}
\restylefloat{table}
% set up the captions: no indent of captions, no seperator (seperator is handled by {myformat})
\captionsetup{format=myformat,indent=0pt,labelsep=none,justification=myjustify,font={small},position=below}
% float-caption distance
\abovecaptionskip 8pt plus 3pt minus 1pt
% graphics allowed: pdf, png, jpg
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
% floats should be centered by default:
\g@addto@macro{\@floatboxreset}{\centering}
% nice table rules
\usepackage{booktabs}
\newcommand \Midrule { \midrule[\heavyrulewidth] }
% colored tables
\newenvironment{ctucolortab}{\begin{lrbox}{0}}{\end{lrbox}\ht0\dimexpr\ht0 + 2pt\relax{\fboxsep0pt\colorbox{ctubluebg}{\usebox{0}}}}
\newenvironment{ctucolortab*}{\begin{lrbox}{0}}{\end{lrbox}{\fboxsep0pt\colorbox{ctubluebg}{\usebox{0}}}}
%%% LISTS
% Temp box
\box_new:N \g_ctuthesis_tempa_box
% Macro used to generate the itemize labels
% parameters 1:depth, 2: raise (without ex), 3: scale, 4:color
\cs_new_protected:Nn \ctuthesis_list_prepare_labelitem:nnnn {
% Each label stored in a box
\box_new:c { g_ctuthesis_list_label_#1_box }
% use the temp box to measure the symbol
\hbox_gset:Nn \g_ctuthesis_tempa_box {
\scalebox{#3}{\fontfamily{lmss}\bfseries\color{#4}.}
}
% The label is actually a shifted up, scaled, coloured lmss bf dot
\hbox_gset:cn { g_ctuthesis_list_label_#1_box } {
\box_move_up:nn { #2 ex } \hbox_to_wd:nn {
\box_ht:N \g_ctuthesis_tempa_box
} {
\hss
\scalebox{#3}{\fontfamily{lmss}\bfseries\color{#4}.}
\hss
}
}
\cs_set:cpn { labelitem #1 } { \box_use:c { g_ctuthesis_list_label_#1_box } }
}
% The four labels for itemize
\ctuthesis_list_prepare_labelitem:nnnn { i } { 0.18 } { 3.6 } { ctublueitemi }
\ctuthesis_list_prepare_labelitem:nnnn { ii } { 0.18 } { 3.6 } { ctublueitemii }
\ctuthesis_list_prepare_labelitem:nnnn { iii } { 0.36 } { 2.4 } { black }
\ctuthesis_list_prepare_labelitem:nnnn { iv } { 0.48 } { 1.2 } { black }
% Macro for making the box with lmss bf dot "." scaled to the size of \strutbox
% #1 is the width of the box (relative to the width of the resulting dot) and
% #2 is the color of the box
\cs_new_protected:Nn \ctuthesis_list_enumdot:nn {
\hbox_to_wd:nn { #1\ht\strutbox + #1\dp\strutbox } {
\hss
\raisebox{-\dp\strutbox}{
\resizebox{!}{\dimexpr\ht\strutbox+\dp\strutbox}{
\fontfamily{lmss}\bfseries\color{#2}.
}
}
\hss
}
}
% \itembox takes 5 parameters.
% (#1)(#2) are the left and right padding
% [#3][#4] are the box color and text color
% #5 is the text
\DeclareDocumentCommand \itembox { D(){0.15em} D(){0.15em} >{\TrimSpaces}O{ctubluebg} >{\TrimSpaces}O{black} >{\TrimSpaces}m } {
\ooalign{
\hfil \ctuthesis_list_enumdot:nn {1} {#3}
\cr
\ctuthesis_list_enumdot:nn {1} {#3} \hfil
\cr
\skip_horizontal:n { 0.34\ht\strutbox + 0.34\dp\strutbox }
\cleaders \ctuthesis_list_enumdot:nn {0.34} {#3} \hfil
\skip_horizontal:n { 0.34\ht\strutbox + 0.34\dp\strutbox }
\cr
\hfil
\hbox:n { \hspace{#1} { \color{#4} #5 } \hspace{#2} }
\hfil
}
}
% Redefine the enumerate labels. The first two levels are boxed,
% the other two are not.
%\def\labelenumi{{\normalfont\itembox[ctubluedarkbg][white]{\bfseries\theenumi.}}}
\def\labelenumi{{\normalfont\itembox{\theenumi.}}}
\def\labelenumii{{\normalfont\itembox(0.1em)(0.1em){\theenumii.}}}
\def\labelenumiii{{\normalfont(\theenumiii)}}
\def\labelenumiv{{\normalfont(\theenumiv)}}
\leftmargini22.2pt
\labelsep6pt
%%% MATH, THEOREMS
\usepackage{amsmath,amssymb,amsfonts}
% Optional loading of amsthm
\ctuthesis_if_switch:nT { pkg-amsthm } {
\usepackage{amsthm}
% Redefine standard styles: plain is slanted, definition is normal, note has an italic head (like proof)
\newtheoremstyle{plain}{3pt plus 1pt}{3pt plus 1pt}{\slshape}{}{\bfseries\sffamily}{.}{.5em}{}
\newtheoremstyle{plainit}{3pt plus 1pt}{3pt plus 1pt}{\slshape}{}{\bfseries\sffamily}{.}{.5em}{}
\newtheoremstyle{definition}{3pt plus 1pt}{3pt plus 1pt}{}{}{\bfseries\sffamily}{.}{.5em}{}
\newtheoremstyle{note}{3pt plus 1pt}{3pt plus 1pt}{}{}{\itshape}{.}{.5em}{}
% Default style: plain
\theoremstyle{plain}
% We redefine proof to include a more reasonable spacing above it.
\DeclareDocumentEnvironment { proof } { O{\proofname} } {
\par
\pushQED{\qed}
\normalfont \topsep0pt plus 1pt
\trivlist
\item[
\hskip\labelsep
\itshape
#1\@addpunct{.}
]
\ignorespaces
}{
\popQED\endtrivlist\@endpefalse
}
}
%%% INDEX
\ctuthesis_if_switch:nT { pkg-makeidx } {
% Initialize makeindex
\usepackage{makeidx}
\makeindex
% We use multicol rather than twocolumn for the index
\usepackage{multicol}
% Redefine the index environment to just make the header and start the multicols* envrionment
% (starred because we don't want to balance the columns), then redefine \item as in original theindex
\DeclareDocumentEnvironment { theindex } { } {
\chapter* {\indexname }
\begin{multicols*}{2}
\let\item\@idxitem
% Do not put index sections in ToC. We save the tocdepth and set it to zero, only to restore it after.
\addtocontents{toc}{\protect\ctu@savetocdepth}
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
% Inside index, the sections are tighter together
\titlespacing*\section{}{10pt}{4pt}
} {
\addtocontents{toc}{\protect\ctu@restoretocdepth}
\end{multicols*}
\clearpage
}
% How does this work: in \ctu@tocdepth we save the current tocdepth
\newcommand\ctu@savetocdepth{\xdef\ctu@saved@tocdepth{\the\c@tocdepth}}
% This macro restores the saved value.
\newcommand\ctu@restoretocdepth{\global\c@tocdepth\ctu@saved@tocdepth\relax}
}
%%% LISTINGS
\ctuthesis_if_switch:nT { pkg-listings } {
\RequirePackage{listings}
\lstset{
backgroundcolor = \color{ctubluebg},
basicstyle = \ttfamily,
columns = fullflexible,
keepspaces = true,
tabsize = 4,
% frame = leftline,
% framesep = 0pt,
% framexleftmargin = 3pt,
% framerule = 0.667pt,
% rulecolor = \color{ctubluerule},
frame = single,
framesep = 0pt,
framexleftmargin = 2pt,
framerule = 2pt,
rulecolor = \color{ctubluebg},
framexrightmargin = 2pt,
xleftmargin = 4pt,
xrightmargin = 4pt,
}
\cs_new_eq:NN \ctuthesis_lst_orig_lstinline:w \lstinline
\newsavebox \ctuthesis_lst_box
\newcommand* \ctulstsep {0.2em}
\DeclareDocumentCommand \ctuthesis_lst_do_ctulstinline:nnw { m m m v } {
\leavevmode
\microtypesetup{activate=false}
\begin{lrbox}{\ctuthesis_lst_box}
\ctuthesis_lst_orig_lstinline:w[#2]#3#4#3
\end{lrbox}
\str_if_eq:xnTF {#1} {none}
{{ \hbox:n {\strut\hspace*{\ctulstsep}\box\ctuthesis_lst_box\hspace*{\ctulstsep}} }}
{{ \fboxsep0pt\colorbox{#1} {\strut\hspace*{\ctulstsep}\box\ctuthesis_lst_box\hspace*{\ctulstsep}} }}
\microtypesetup{activate=true}
}
\DeclareDocumentCommand \ctulst { D(){\g_ctuthesis_ctulstbg_tl} O{} m } {
\ctuthesis_lst_do_ctulstinline:nnw { #1 } { #2 } { #3 } #3
}
\DeclareDocumentCommand \ctulstbr { D(){ctulstbg} O{} m } {
\leavevmode
\begin{lrbox}{\ctuthesis_lst_box}
\ctuthesis_lst_orig_lstinline:w[#2]{#3}
\end{lrbox}
\colorbox{#1}{\box\ctuthesis_lst_box}
}
}
%%% HYPERREF
\ctuifswitch { pkg-hyperref } {
\usepackage[
pdfpagelayout=TwoPageRight, % Correct twopage layout with recto on the right
]{hyperref}
% Links with orange borders, in ToC only the page is linked
\hypersetup{
colorlinks=false,
linktocpage=true,
allbordercolors=ctuorange,
}
% Prepare PDFinfo
\tl_new:N \g_ctuthesis_hyperref_pdfinfo_tl
\tl_set:Nx \g_ctuthesis_hyperref_pdfinfo_tl {
pdfinfo = {
Title = \ctuthesis_field_use:nn { title } { title },
Author = \ctuthesis_field_use:n { author },
}
}
\exp_args:NV \hypersetup \g_ctuthesis_hyperref_pdfinfo_tl
}{}
%\ctuifswitch { pkg-hyperref } {
% \hypersetup{colorlinks=false,linktocpage=true,linkbordercolor=0 122 195}
%}
%%% VARIOUS TWEAKS
% Provide \phantomsection and \texorpdfstring to make them available in case hyperref wasn't loaded
\providecommand\phantomsection{}
\providecommand\texorpdfstring[2]{#1}
% Provide \microtypesetup to make it available in case microtype wasn't loaded
\providecommand\microtypesetup[1]{}
\endinput