kaobook.cls (10126B)
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 % kaobook 3 % LaTeX Class 4 % Version 0.9.8 (2021/08/23) 5 % 6 % This template originates from: 7 % https://www.LaTeXTemplates.com 8 % 9 % For the latest template development version and to make contributions: 10 % https://github.com/fmarotta/kaobook 11 % 12 % Authors: 13 % Federico Marotta (federicomarotta@mail.com) 14 % Based on the doctoral thesis of Ken Arroyo Ohori (https://3d.bk.tudelft.nl/ken/en) 15 % and on the Tufte-LaTeX class. 16 % Modified for LaTeX Templates by Vel (vel@latextemplates.com) 17 % 18 % License: 19 % LPPL (see included MANIFEST.md file) 20 % 21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 23 %---------------------------------------------------------------------------------------- 24 % CLASS CONFIGURATION 25 %---------------------------------------------------------------------------------------- 26 27 \NeedsTeXFormat{LaTeX2e} 28 \ProvidesClass{kaobook}[2021/08/23 v0.9.8 kaobook] 29 \newcommand{\@baseclass}{scrbook} % Base class name 30 31 % Set the default options 32 \PassOptionsToClass{a4paper}{\@baseclass} 33 \PassOptionsToClass{fontsize=10pt}{\@baseclass} 34 \PassOptionsToClass{parskip=half}{\@baseclass} 35 \PassOptionsToClass{headings=optiontoheadandtoc}{\@baseclass} 36 37 % Pass through any other options to the base class 38 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@baseclass}} 39 40 \ProcessOptions\relax % Process the options 41 42 \LoadClass{\@baseclass} % Load the base class 43 44 \RequirePackage{kao} % Load the code common to all classes 45 46 %---------------------------------------------------------------------------------------- 47 % FRONT-, MAIN-, BACK- MATTERS BEHAVIOUR 48 %---------------------------------------------------------------------------------------- 49 50 % Front matter 51 \let\oldfrontmatter\frontmatter % Store the old command 52 \renewcommand{\frontmatter}{% 53 \oldfrontmatter% First of all, call the old command 54 \pagestyle{plain.scrheadings}% Use a plain style for the header and the footer 55 \pagelayout{wide}% Use a wide page layout 56 \setchapterstyle{plain} % Choose the default chapter heading style 57 % \sloppy % Required to better break long lines 58 } 59 60 %------------------------------------------------ 61 62 % Main matter 63 \let\oldmainmatter\mainmatter % Store the old command 64 \renewcommand{\mainmatter}{% 65 \oldmainmatter% Call the old command 66 \pagestyle{scrheadings}% Use a fancy style for the header and the footer 67 \pagelayout{margin}% Use a 1.5 column layout 68 \setchapterstyle{kao} % Choose the default chapter heading style 69 } 70 71 %------------------------------------------------ 72 73 % Appendix 74 \let\oldappendix\appendix% Store the old command 75 \renewcommand{\appendix}{% 76 \oldappendix% Call the old command 77 \bookmarksetup{startatroot}% Reset the bookmark depth 78 } 79 80 %------------------------------------------------ 81 82 % Back matter 83 \let\oldbackmatter\backmatter% Store the old command 84 \renewcommand{\backmatter}{% 85 \oldbackmatter% Call the old command 86 \bookmarksetup{startatroot}% Reset the bookmark depth 87 \pagestyle{plain.scrheadings}% Use a plain style for the header and the footer 88 \pagelayout{wide}% Use a wide page layout 89 \setchapterstyle{plain} % Choose the default chapter heading style 90 } 91 92 %---------------------------------------------------------------------------------------- 93 % CHAPTER HEADING STYLES 94 %---------------------------------------------------------------------------------------- 95 96 % Command to easily switch between chapter styles 97 \DeclareDocumentCommand{\setchapterstyle}{m}{% 98 \ifthenelse{\equal{plain}{#1}}{\chapterstyleplain}{} 99 \ifthenelse{\equal{bar}{#1}}{\chapterstylebar}{} 100 \ifthenelse{\equal{lines}{#1}}{\chapterstylelines}{} 101 \ifthenelse{\equal{kao}{#1}}{\chapterstylekao}{} 102 } 103 104 % The default definition in KOMA script 105 \DeclareDocumentCommand{\chapterstyleplain}{}{% 106 \renewcommand{\chapterlinesformat}[3]{% 107 \@hangfrom{##2}{##3}} 108 \renewcommand*{\chapterformat}{% 109 \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter% 110 \autodot\IfUsePrefixLine{}{\enskip}}} 111 \RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter} 112 \setlength{\mtocshift}{-1\vscale} 113 } 114 115 % Gray bar 116 \DeclareDocumentCommand{\chapterstylebar}{}{% 117 \renewcommand*{\chapterformat}{% 118 \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter% 119 \autodot\IfUsePrefixLine{}{\enskip}}% 120 } 121 \renewcommand{\chapterlinesformat}[3]{% 122 \begin{tikzpicture}[remember picture, overlay] 123 \node[ 124 anchor=south west, 125 xshift=\dimexpr - \hoffset - \oddsidemargin - 1in -1mm,%-30\hscale, 126 yshift=4.3mm, 127 rectangle, 128 fill=gray!20!white, 129 fill opacity=0.8, 130 inner ysep=5\vscale, 131 inner xsep=\dimexpr \hoffset + \oddsidemargin + 1in,%30\hscale, 132 text opacity=1, 133 text width=\paperwidth-40\hscale, 134 ]{\@hangfrom{##2}{##3}}; 135 \end{tikzpicture} 136 } 137 \RedeclareSectionCommand[beforeskip=-55\vscale,afterskip=6\vscale]{chapter} 138 \setlength{\mtocshift}{-1\vscale} 139 } 140 141 % Lines 142 \renewcommand{\hrulefill}[1][0.4pt]{% 143 \leavevmode\leaders\hrule height #1\hfill\kern\z@% 144 } 145 \DeclareDocumentCommand{\chapterstylelines}{}{% 146 \renewcommand*{\chapterformat}{% 147 \chapappifchapterprefix{\nobreakspace}\scalebox{3.5}{\thechapter\autodot}% 148 }% 149 \renewcommand\chapterlinesformat[3]{% 150 %\vspace*{-1cm}% 151 \leavevmode% 152 \makebox[0pt][l]{% 153 \makebox[\textwidth][l]{\hrulefill[1pt]##2}%\hfill%\par%\bigskip 154 \makebox[\marginparsep][l]{}% 155 \makebox[\marginparwidth][l]{}% 156 }\\ 157 %\vspace{.5cm} 158 \makebox[0pt][l]{% 159 \makebox[\textwidth][l]{##3}% 160 \makebox[\marginparsep][l]{}% 161 \makebox[\marginparwidth][l]{}% 162 }\\ 163 \makebox[0pt][l]{% 164 \makebox[\textwidth+\marginparsep+\marginparwidth][l]{\hrulefill[1.1pt]}% 165 }% 166 }% 167 \RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter} 168 \setlength{\mtocshift}{-1\vscale}% 169 } 170 171 % The Kao style 172 \DeclareDocumentCommand{\chapterstylekao}{}{% 173 \IfWideLayout{% 174 \renewcommand*{\chapterformat}{% 175 \mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\thechapter\autodot}}% 176 }% 177 \renewcommand\chapterlinesformat[3]{% 178 \vspace{3.5\vscale}% 179 \if@twoside% 180 \Ifthispageodd{% 181 \smash{\makebox[0pt][l]{% 182 \parbox[b]{\textwidth - 6.2\hscale}{\flushright{##3}}% 183 \makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 184 \parbox[b]{\marginparwidth}{##2}% 185 }}% 186 }{ 187 \smash{\makebox[\textwidth + 6.2\hscale][r]{% 188 \parbox[b]{47.7\hscale + 6.2\hscale}{\flushright{##2}}% 189 \makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 190 \parbox[b]{\textwidth}{\flushleft{##3}}% 191 }}% 192 } 193 \else% 194 \smash{\makebox[0pt][l]{% 195 \parbox[b]{\textwidth - 6.2\hscale}{\flushright{##3}}% 196 \makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 197 \parbox[b]{\marginparwidth}{##2}% 198 }}% 199 \fi% 200 }% 201 }{% 202 \renewcommand*{\chapterformat}{% 203 \mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\thechapter\autodot}}% 204 }% 205 \renewcommand\chapterlinesformat[3]{% 206 \vspace{3.5\vscale}% 207 \if@twoside% 208 \Ifthispageodd{% 209 \smash{\makebox[0pt][l]{% 210 \parbox[b]{\textwidth}{\flushright{##3}}% 211 \makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 212 \parbox[b]{\marginparwidth}{##2}% 213 }}% 214 }{ 215 \smash{\makebox[\textwidth][r]{% 216 \parbox[b]{\marginparwidth}{\flushright{##2}}% 217 \makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 218 \parbox[b]{\textwidth}{\flushleft{##3}}% 219 }}% 220 } 221 \else% 222 \smash{\makebox[0pt][l]{% 223 \parbox[b]{\textwidth}{\flushright{##3}}% 224 \makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}% 225 \parbox[b]{\marginparwidth}{##2}% 226 }}% 227 \fi% 228 }% 229 }% 230 \RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}% 231 \setlength{\mtocshift}{-3.5\vscale}% 232 } 233 234 % Takes as input the image path and optionally the "beforeskip" 235 \DeclareDocumentCommand{\setchapterimage}{O{55\vscale} m}{% 236 \setchapterpreamble[o]{% 237 \vspace*{-27\vscale}\hspace*{\dimexpr - \hoffset - \oddsidemargin - 1in}% 238 \includegraphics[width=\paperwidth,height=#1+27\vscale,keepaspectratio=false]{#2}% 239 }% 240 \chapterstylebar% 241 % beforeskip=-(figure_height-top_margin) 242 \RedeclareSectionCommand[beforeskip=-#1, afterskip=6\vscale]{chapter}% 243 \setlength{\mtocshift}{0cm}% 244 } 245 246 % By default start with the plain style 247 \chapterstyleplain 248 249 %---------------------------------------------------------------------------------------- 250 % FONTS AND STYLES 251 %---------------------------------------------------------------------------------------- 252 253 % Set KOMA fonts for book-specific elements 254 \addtokomafont{part}{\normalfont\scshape\bfseries} 255 \addtokomafont{partentry}{\normalfont\scshape\bfseries} 256 \addtokomafont{chapter}{\normalfont\bfseries} 257 \addtokomafont{chapterentry}{\normalfont\bfseries} 258 259 % Set KOMA fonts for elements common to all classes 260 \addtokomafont{section}{\normalfont\bfseries} 261 \addtokomafont{subsection}{\normalfont\bfseries} 262 \addtokomafont{subsubsection}{\normalfont\bfseries} 263 \addtokomafont{paragraph}{\normalfont\bfseries} 264 \setkomafont{descriptionlabel}{\normalfont\bfseries} 265 266 %---------------------------------------------------------------------------------------- 267 % TOC, LOF & LOT 268 %---------------------------------------------------------------------------------------- 269 270 % Set default options regarding the table of contents 271 \PassOptionsToClass{toc=listof}{\@baseclass} 272 \PassOptionsToClass{toc=index}{\@baseclass} 273 \PassOptionsToClass{toc=bibliography}{\@baseclass} 274 275 %---------------------------------------------------------------------------------------- 276 % NUMBERING 277 %---------------------------------------------------------------------------------------- 278 279 %\setcounter{secnumdepth}{\kao@secnumdepth} % Set section numbering depth 280 281 \counterwithin*{sidenote}{chapter} % Uncomment to reset the sidenote counter at each chapter 282 %\counterwithout{sidenote}{chapter} % Uncomment to have one sidenote counter for the whole document