-
Notifications
You must be signed in to change notification settings - Fork 16
/
kaobook.cls
266 lines (232 loc) · 8.97 KB
/
kaobook.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% kaobook
% LaTeX Class
% Version 0.9.7 (2021/06/02)
%
% This template originates from:
% https://www.LaTeXTemplates.com
%
% For the latest template development version and to make contributions:
% https://github.com/fmarotta/kaobook
%
% Authors:
% Federico Marotta ([email protected])
% Based on the doctoral thesis of Ken Arroyo Ohori (https://3d.bk.tudelft.nl/ken/en)
% and on the Tufte-LaTeX class.
% Modified for LaTeX Templates by Vel ([email protected])
%
% License:
% LPPL (see included MANIFEST.md file)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% CLASS CONFIGURATION
%----------------------------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{kaobook}[2021/06/02 v0.9.7 kaobook]
\newcommand{\@baseclass}{scrbook} % Base class name
%\RequirePackage{kvoptions} % Manage class key-value options
%\SetupKeyvalOptions{
% family = kao,
% prefix = kao@
%}
% Set the default options
\PassOptionsToClass{a4paper}{\@baseclass}
\PassOptionsToClass{fontsize=10pt}{\@baseclass}
\PassOptionsToClass{parskip=half}{\@baseclass}
\PassOptionsToClass{headings=optiontoheadandtoc}{\@baseclass}
% Pass through any other options to the base class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@baseclass}}
%\ProcessKeyvalOptions*
\ProcessOptions\relax % Process the options
\LoadClass{\@baseclass} % Load the base class
% Define kao-specific options
%\DeclareStringOption[1]{secnumdepth}
\DefineFamily{kao}
\DefineFamilyMember[kaobook]{kao}
\DefineFamilyKey[kaobook]{kao}{secnumdepth}[1]{\setcounter{secnumdepth}{#1}\FamilyKeyStateProcessed}
\FamilyProcessOptions[kaobook]{kao}
\RequirePackage{kao} % Load the code common to all classes
%----------------------------------------------------------------------------------------
% FRONT-, MAIN-, BACK- MATTERS BEHAVIOUR
%----------------------------------------------------------------------------------------
% Front matter
\let\oldfrontmatter\frontmatter % Store the old command
\renewcommand{\frontmatter}{%
\oldfrontmatter% First of all, call the old command
\pagestyle{plain.scrheadings}% Use a plain style for the header and the footer
\pagelayout{wide}% Use a wide page layout
\setchapterstyle{plain} % Choose the default chapter heading style
% \sloppy % Required to better break long lines
}
%------------------------------------------------
% Main matter
\let\oldmainmatter\mainmatter % Store the old command
\renewcommand{\mainmatter}{%
\oldmainmatter% Call the old command
\pagestyle{scrheadings}% Use a fancy style for the header and the footer
\pagelayout{margin}% Use a 1.5 column layout
\setchapterstyle{kao} % Choose the default chapter heading style
}
%------------------------------------------------
% Appendix
\let\oldappendix\appendix% Store the old command
\renewcommand{\appendix}{%
\oldappendix% Call the old command
\bookmarksetup{startatroot}% Reset the bookmark depth
}
%------------------------------------------------
% Back matter
\let\oldbackmatter\backmatter% Store the old command
\renewcommand{\backmatter}{%
\oldbackmatter% Call the old command
\bookmarksetup{startatroot}% Reset the bookmark depth
\pagestyle{plain.scrheadings}% Use a plain style for the header and the footer
\pagelayout{wide}% Use a wide page layout
\setchapterstyle{plain} % Choose the default chapter heading style
}
%----------------------------------------------------------------------------------------
% CHAPTER HEADING STYLES
%----------------------------------------------------------------------------------------
\DeclareDocumentCommand{\setchapterstyle}{m}{%
\ifthenelse{\equal{plain}{#1}}{\chapterstyleplain}{}
\ifthenelse{\equal{bar}{#1}}{\chapterstylebar}{}
\ifthenelse{\equal{lines}{#1}}{\chapterstylelines}{}
\ifthenelse{\equal{kao}{#1}}{\chapterstylekao}{}
}
% The default definition in KOMA script
\DeclareDocumentCommand{\chapterstyleplain}{}{%
\renewcommand{\chapterlinesformat}[3]{%
\@hangfrom{##2}{##3}}
\renewcommand*{\chapterformat}{%
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter%
\autodot\IfUsePrefixLine{}{\enskip}}}
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}
\setlength{\mtocshift}{-1\vscale}
}
% Gray bar
\DeclareDocumentCommand{\chapterstylebar}{}{%
\renewcommand*{\chapterformat}{%
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter%
\autodot\IfUsePrefixLine{}{\enskip}}%
}
\renewcommand{\chapterlinesformat}[3]{%
\begin{tikzpicture}[remember picture, overlay]
\node[
anchor=south west,
xshift=\dimexpr - \hoffset - \oddsidemargin - 1in -1mm,%-30\hscale,
yshift=4.3mm,
rectangle,
fill=gray!20!white,
fill opacity=0.8,
inner ysep=5\vscale,
inner xsep=\dimexpr \hoffset + \oddsidemargin + 1in,%30\hscale,
text opacity=1,
text width=\paperwidth-40\hscale,
]{\@hangfrom{##2}{##3}};
\end{tikzpicture}
}
\RedeclareSectionCommand[beforeskip=-55\vscale,afterskip=6\vscale]{chapter}
\setlength{\mtocshift}{-1\vscale}
}
% Lines
\renewcommand{\hrulefill}[1][0.4pt]{%
\leavevmode\leaders\hrule height #1\hfill\kern\z@%
}
\DeclareDocumentCommand{\chapterstylelines}{}{%
\renewcommand*{\chapterformat}{%
\chapappifchapterprefix{\nobreakspace}\scalebox{3.5}{\thechapter\autodot}%
}%
\renewcommand\chapterlinesformat[3]{%
%\vspace*{-1cm}%
\leavevmode%
\makebox[0pt][l]{%
\makebox[\textwidth][l]{\hrulefill[1pt]##2}%\hfill%\par%\bigskip
\makebox[\marginparsep][l]{}%
\makebox[\marginparwidth][l]{}%
}\\
%\vspace{.5cm}
\makebox[0pt][l]{%
\makebox[\textwidth][l]{##3}%
\makebox[\marginparsep][l]{}%
\makebox[\marginparwidth][l]{}%
}\\
\makebox[0pt][l]{%
\makebox[\textwidth+\marginparsep+\marginparwidth][l]{\hrulefill[1.1pt]}%
}%
}%
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}
\setlength{\mtocshift}{-1\vscale}%
}
% The Kao style
\DeclareDocumentCommand{\chapterstylekao}{}{%
\renewcommand*{\chapterformat}{%
\mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\thechapter\autodot}}%
}%
\renewcommand\chapterlinesformat[3]{%
\vspace{3.5\vscale}%
\if@twoside%
\Ifthispageodd{%
\smash{\makebox[0pt][l]{%
\parbox[b]{\textwidth}{\flushright{##3}}%
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
\parbox[b]{\marginparwidth}{##2}%
}}%
}{
\smash{\makebox[\textwidth][r]{%
\parbox[b]{\marginparwidth}{\flushright{##2}}%
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
\parbox[b]{\textwidth}{\flushleft{##3}}%
}}%
}
\else%
\smash{\makebox[0pt][l]{%
\parbox[b]{\textwidth}{\flushright{##3}}%
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
\parbox[b]{\marginparwidth}{##2}%
}}%
\fi%
}%
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}%
\setlength{\mtocshift}{-3\vscale}%
}
% Takes as input the image path and optionally the "beforeskip"
\DeclareDocumentCommand{\setchapterimage}{O{55\vscale} m}{%
\setchapterpreamble[o]{%
\vspace*{-27\vscale}\hspace*{\dimexpr - \hoffset - \oddsidemargin - 1in}%
\includegraphics[width=\paperwidth,height=#1+27\vscale,keepaspectratio=false]{#2}%
}%
\chapterstylebar%
% beforeskip=-(figure_height-top_margin)
\RedeclareSectionCommand[beforeskip=-#1, afterskip=6\vscale]{chapter}%
\setlength{\mtocshift}{0cm}%
}
% By default start with plain style
\chapterstyleplain
%----------------------------------------------------------------------------------------
% FONTS AND STYLES
%----------------------------------------------------------------------------------------
% Set KOMA fonts for book-specific elements
\addtokomafont{part}{\normalfont\scshape\bfseries}
\addtokomafont{partentry}{\normalfont\scshape\bfseries}
\addtokomafont{chapter}{\normalfont\bfseries}
\addtokomafont{chapterentry}{\normalfont\bfseries}
% Set KOMA fonts for elements common to all classes
\addtokomafont{section}{\normalfont\bfseries}
\addtokomafont{subsection}{\normalfont\bfseries}
\addtokomafont{subsubsection}{\normalfont\bfseries}
\addtokomafont{paragraph}{\normalfont\bfseries}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
%----------------------------------------------------------------------------------------
% TOC, LOF & LOT
%----------------------------------------------------------------------------------------
\PassOptionsToClass{toc=listof}{\@baseclass}
\PassOptionsToClass{toc=index}{\@baseclass}
\PassOptionsToClass{toc=bibliography}{\@baseclass}
%----------------------------------------------------------------------------------------
% NUMBERING
%----------------------------------------------------------------------------------------
%\setcounter{secnumdepth}{\kao@secnumdepth} % Set section numbering
%depth
\counterwithin*{sidenote}{chapter} % Uncomment to reset the sidenote counter at each chapter
%\counterwithout{sidenote}{chapter} % Uncomment to have one sidenote counter for the whole document