├── thesis.pdf ├── tikz └── README.md ├── chapters ├── paper1_app.tex ├── paper2_app.tex ├── background2.tex ├── conclusion.tex ├── paper1.tex ├── paper2.tex ├── overview.tex └── background1.tex ├── makefile ├── preamble ├── hyphenations.tex ├── lstlinebgrd.tex ├── colors.tex ├── tuetitle.sty ├── thesis.cls ├── kaobook.cls ├── kaorefs.sty ├── kaotheorems.sty ├── commands.tex ├── kaobiblio.sty ├── math_commands.tex ├── preamble.tex └── kao.sty ├── frontmatter ├── abstract.tex ├── zusammenfassung.tex ├── coverpage.tex ├── toc_lof_lot.tex ├── acknowledgments.tex └── notation.tex ├── backmatter └── bibliography.tex ├── bibliography └── bibliography.bib ├── README.org ├── .github └── workflows │ └── latex.yml ├── thesis.tex └── .gitignore /thesis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f-dangel/phd-thesis-template/HEAD/thesis.pdf -------------------------------------------------------------------------------- /tikz/README.md: -------------------------------------------------------------------------------- 1 | This directory contains externalized TikZ pictures after compiling the document. 2 | -------------------------------------------------------------------------------- /chapters/paper1_app.tex: -------------------------------------------------------------------------------- 1 | 2 | %%% Local Variables: 3 | %%% mode: latex 4 | %%% TeX-master: "../thesis" 5 | %%% End: 6 | -------------------------------------------------------------------------------- /chapters/paper2_app.tex: -------------------------------------------------------------------------------- 1 | 2 | %%% Local Variables: 3 | %%% mode: latex 4 | %%% TeX-master: "../thesis" 5 | %%% End: 6 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | .PHONY: thesis, thesis-force 2 | 3 | thesis: 4 | bash build.sh 5 | 6 | thesis-force: 7 | bash build-force.sh 8 | -------------------------------------------------------------------------------- /preamble/hyphenations.tex: -------------------------------------------------------------------------------- 1 | \hyphenation{au-ton-omous} 2 | 3 | %%% Local Variables: 4 | %%% mode: latex 5 | %%% TeX-master: "../thesis" 6 | %%% End: 7 | -------------------------------------------------------------------------------- /chapters/background2.tex: -------------------------------------------------------------------------------- 1 | \blindtext 2 | 3 | \section{Background topic 1 (advanced)}\label{sec:background-2::topic-1} 4 | 5 | \section{Background topic 2 (advanced)}\label{sec:background-2::topic-2} 6 | 7 | %%% Local Variables: 8 | %%% mode: latex 9 | %%% TeX-master: "../thesis" 10 | %%% End: -------------------------------------------------------------------------------- /frontmatter/abstract.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % ENGLISH ABSTRACT 3 | % =================================================================== 4 | 5 | \chapter{Abstract} 6 | \Blindtext 7 | 8 | %%% Local Variables: 9 | %%% mode: latex 10 | %%% TeX-master: "../thesis" 11 | %%% End: 12 | -------------------------------------------------------------------------------- /backmatter/bibliography.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % BIBLIOGRAPHY 3 | % =================================================================== 4 | 5 | \pagelayout{wide} % No margins 6 | \printbibliography[heading=bibintoc, title=Bibliography] 7 | 8 | %%% Local Variables: 9 | %%% mode: latex 10 | %%% TeX-master: "../thesis" 11 | %%% End: 12 | -------------------------------------------------------------------------------- /frontmatter/zusammenfassung.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % GERMAN SUMMARY 3 | % =================================================================== 4 | 5 | \begin{otherlanguage}{german} 6 | \chapter{Zusammenfassung} 7 | \Blindtext 8 | \end{otherlanguage} 9 | 10 | %%% Local Variables: 11 | %%% mode: latex 12 | %%% TeX-master: "../thesis" 13 | %%% End: 14 | -------------------------------------------------------------------------------- /bibliography/bibliography.bib: -------------------------------------------------------------------------------- 1 | @book{goodfellow2016deep, 2 | Title = {Deep Learning}, 3 | Author = {Ian J. Goodfellow and Yoshua Bengio and Aaron Courville}, 4 | Year = 2016, 5 | } 6 | 7 | @InProceedings{dangel2020backpack, 8 | author = {Felix Dangel and Frederik Kunstner and Philipp Hennig}, 9 | booktitle = {International Conference on Learning Representations (ICLR)}, 10 | title = {{BackPACK: Packing more into Backprop}}, 11 | year = 2020, 12 | } 13 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | This repository contains a template for my PhD thesis at the University of Tuebingen. 2 | 3 | The [[file:thesis.pdf][template]] demonstrates the most important features and looks. You can find a full thesis example [[https://github.com/f-dangel/phd-thesis][here]]. 4 | 5 | * How to use 6 | 7 | Clone this repository and start editing the [[file:thesis.tex][thesis.tex]] file. 8 | 9 | If you use externalize your TikZ figures, use the [[file:makefile][makefile]] to build via 10 | 11 | #+begin_src bash 12 | make thesis-force 13 | #+end_src 14 | -------------------------------------------------------------------------------- /frontmatter/coverpage.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % COVERPAGE 3 | % =================================================================== 4 | 5 | \title{Backpropagation Beyond the Gradient} 6 | \author[FJD]{Felix Julius Dangel, M.\,Sc.} 7 | 8 | \birthplace{Stuttgart} 9 | \submissionyear{2022} 10 | \dean{Prof.\,Dr.\,Thilo Stehle} 11 | \dateoforalexamination{To be announced} 12 | \experts{Prof.\,Dr.\,Philipp Hennig \and Dr.\,Georg Martius} 13 | 14 | \maketitle 15 | 16 | %%% Local Variables: 17 | %%% mode: latex 18 | %%% TeX-master: "../thesis" 19 | %%% End: 20 | -------------------------------------------------------------------------------- /.github/workflows/latex.yml: -------------------------------------------------------------------------------- 1 | name: Latex 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | pull_request: 8 | branches: 9 | - '*' 10 | 11 | jobs: 12 | thesis: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Set up Git repository 16 | uses: actions/checkout@v2 17 | - name: Compile LaTeX document 18 | uses: xu-cheng/latex-action@v2 19 | with: 20 | working_directory: . 21 | root_file: thesis.tex 22 | latexmk_shell_escape: true 23 | - name: Upload thesis as artifact 24 | uses: actions/upload-artifact@v3 25 | with: 26 | name: thesis 27 | path: thesis.pdf 28 | -------------------------------------------------------------------------------- /chapters/conclusion.tex: -------------------------------------------------------------------------------- 1 | \Blindtext 2 | 3 | \section{Summary \& Impact} 4 | 5 | \subsubsection{Extending Backpropagation to the Hessian} 6 | \blindtext 7 | 8 | \subsubsection{Packing More into Backprop} 9 | \blindtext 10 | 11 | \subsubsection{Enabling a Closer Look Into Neural Nets} 12 | \blindtext 13 | 14 | \subsubsection{Enabling Novel Ways to Compute with Curvature} 15 | \blindtext 16 | 17 | \section{Future Work} 18 | \blindtext 19 | 20 | \subsubsection{Extending Cockpit} 21 | \blindtext 22 | 23 | \subsubsection{Noise-aware Second-order Methods} 24 | \blindtext 25 | 26 | \subsubsection{Optimizing Run Time \& Advancing Automatic Differentiation} 27 | \blindtext 28 | 29 | %%% Local Variables: 30 | %%% mode: latex 31 | %%% TeX-master: "../thesis" 32 | %%% End: 33 | -------------------------------------------------------------------------------- /chapters/paper1.tex: -------------------------------------------------------------------------------- 1 | \subsubsection{Abstract} 2 | \blindtext 3 | 4 | \marginnote{% 5 | \begin{center} 6 | Code and experiments available at the Github repositories 7 | \href{https://github.com/f-dangel/backpack}{\texttt{f-dangel/backpack}}, 8 | \href{https://github.com/f-dangel/backpack-experiments}{\texttt{f-dangel/backpack-experiments}} 9 | \end{center} 10 | \begin{center} 11 | \includegraphics[height = 0.8\linewidth]{example-image-a} 12 | \end{center} 13 | }% 14 | 15 | \section{Introduction} 16 | 17 | \section{Theory \& Implementation}\label{paper-1::sec:theory-and-implementation} 18 | 19 | \section{Evaluation \& Benchmarks}\label{paper-1::sec:benchmark} 20 | 21 | \section{Experiments}\label{paper-1::sec:experiments} 22 | 23 | \section{Conclusion} 24 | 25 | %%% Local Variables: 26 | %%% mode: latex 27 | %%% TeX-master: "../thesis" 28 | %%% End: 29 | -------------------------------------------------------------------------------- /frontmatter/toc_lof_lot.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % TABLE OF CONTENTS & LIST OF FIGURES/TABLES 3 | % =================================================================== 4 | 5 | \begingroup % Local scope for the following commands 6 | 7 | % Choose the levels in table of contents 8 | \setcounter{tocdepth}{\sectiontocdepth} 9 | 10 | % Define TOC, LOF & LOT style 11 | % \setstretch{1} % Modify TOC line spacing 12 | % \hypersetup{linkcolor=blue} % Set color of TOC links 13 | \setlength{\textheight}{230\vscale} % Adjust the TOC page height 14 | 15 | % Turn on compatibility mode for the etoc package 16 | % \etocstandarddisplaystyle % "toc display" as if etoc was not loaded 17 | % \etocstandardlines % "toc lines as if etoc was not loaded 18 | 19 | \tableofcontents % Output the table of contents 20 | \endgroup 21 | 22 | %%% Local Variables: 23 | %%% mode: latex 24 | %%% TeX-master: "../thesis" 25 | %%% End: 26 | -------------------------------------------------------------------------------- /chapters/paper2.tex: -------------------------------------------------------------------------------- 1 | \subsubsection{Abstract} 2 | \Blindtext 3 | 4 | \marginnote{% 5 | \begin{center} 6 | Code and experiments available at the Github repositories 7 | \href{https://github.com/f-dangel/cockpit}{\texttt{f-dangel/cockpit}}, 8 | \href{https://github.com/f-dangel/cockpit-experiments}{\texttt{f-dangel/cockpit-experiments}} 9 | \end{center} 10 | \vspace{-5ex} 11 | \begin{center} 12 | \includegraphics[height = 0.8\linewidth]{example-image-a} 13 | \end{center} 14 | } 15 | 16 | \section{Introduction \& Motivation}\label{paper-2::sec:intro} 17 | 18 | \section{\cockpittitle's Instruments}\label{paper-2::sec:instruments} 19 | 20 | \section{Experiments}\label{paper-2::sec:experiments} 21 | 22 | \section{Showcase}\label{paper-2::sec:showcase} 23 | 24 | \section{Benchmark}\label{paper-2::sec:benchmark} 25 | 26 | \section{Conclusion}\label{paper-2::sec:conclusion} 27 | 28 | \section*{Acknowledgments} 29 | \blindtext 30 | 31 | %%% Local Variables: 32 | %%% mode: latex 33 | %%% TeX-master: "../thesis" 34 | %%% End: 35 | -------------------------------------------------------------------------------- /preamble/lstlinebgrd.tex: -------------------------------------------------------------------------------- 1 | % Loads the lstlinebgrd package, but with some changes since it is broken: 2 | % https://tex.stackexchange.com/questions/451532/recent-issues-with-lstlinebgrd-package-with-listings-after-the-latters-updates 3 | \makeatletter 4 | \let\old@lstKV@SwitchCases\lstKV@SwitchCases 5 | \def\lstKV@SwitchCases#1#2#3{} 6 | \makeatother 7 | \usepackage{lstlinebgrd} 8 | \makeatletter 9 | \let\lstKV@SwitchCases\old@lstKV@SwitchCases 10 | 11 | \lst@Key{numbers}{none}{% 12 | \def\lst@PlaceNumber{\lst@linebgrd}% 13 | \lstKV@SwitchCases{#1}% 14 | {none:\\% 15 | left:\def\lst@PlaceNumber{\llap{\normalfont 16 | \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\% 17 | right:\def\lst@PlaceNumber{\rlap{\normalfont 18 | \kern\linewidth \kern\lst@numbersep 19 | \lst@numberstyle{\thelstnumber}}\lst@linebgrd}% 20 | }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}} 21 | \makeatother 22 | 23 | % Define easier syntax for defining highlighted lines 24 | % https://tex.stackexchange.com/questions/58540/highlight-lines-in-listings 25 | \ExplSyntaxOn 26 | \NewDocumentCommand \lstcolorlines { O{SNSorange!30} m } 27 | { 28 | \clist_if_in:nVT { #2 } { \the\value{lstnumber} }{ \color{#1} } 29 | } 30 | \ExplSyntaxOff 31 | 32 | % Patch internal commands of lstlinebgrd to fix background color 33 | % https://tex.stackexchange.com/questions/398633/linebackgroundcolor-overwriting-backgroundcolor-in-lstinputlisting 34 | \makeatletter 35 | %alternative: patch \lst@bkgcolor 36 | \xpatchcmd\lst@linebgrd{\color{-.}}{\lst@bkgcolor}{}{\fail} 37 | \makeatother -------------------------------------------------------------------------------- /frontmatter/acknowledgments.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % DISCLAIMER 3 | % =================================================================== 4 | { 5 | \thispagestyle{empty} 6 | \raggedright\null\vfill 7 | \paragraph{Disclaimer:} this thesis uses Federico Marotta's \texttt{kaobook} 8 | template based on Ken Arroyo Ohori's doctoral thesis. I am grateful to Frank 9 | Schneider who added many stylistic features and would like to thank him, 10 | Katharina Ott, Frederik Kunstner, Julia Grosse, Jonathan Wenger, Matthias 11 | Werner, Marvin Pf\"ortner, Runa Eschenhagen, Nathanel Bosch, and Andr\'es 12 | Fern\'andez Rodr\'iguez for their help to improve the text. 13 | % 14 | } 15 | \cleardoublepage 16 | 17 | % =================================================================== 18 | % ACKNOWLEDGMENTS 19 | % =================================================================== 20 | 21 | \chapter{Acknowledgments} 22 | 23 | % PROFESSIONAL PART 24 | 25 | % Advisor 26 | \lipsum[66] 27 | 28 | % Committee 29 | \lipsum[66] 30 | 31 | % Administration 32 | \lipsum[66] 33 | 34 | % Collaborators 35 | \lipsum[66] 36 | % Lab members 37 | \lipsum[66] 38 | % Students 39 | \lipsum[66] 40 | 41 | % PRIVATE PART 42 | 43 | % Uni + MPI 44 | \lipsum[66] 45 | 46 | % Friends 47 | \lipsum[66] 48 | 49 | % Family 50 | \lipsum[66] 51 | 52 | % Partner 53 | \lipsum[66] 54 | 55 | Thank you! 56 | 57 | \begin{flushright} 58 | \textit{Felix Dangel}\\ 59 | T\"ubingen, August 31, 2022 60 | \end{flushright} 61 | 62 | %%% Local Variables: 63 | %%% mode: latex 64 | %%% TeX-master: "../thesis" 65 | %%% End: 66 | -------------------------------------------------------------------------------- /preamble/colors.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % UNI TUEBINGEN 3 | 4 | \definecolor{TUred}{RGB}{165,30,55} 5 | \definecolor{TUdark}{RGB}{50,65,75} 6 | \definecolor{TUgold}{RGB}{180,160,105} 7 | 8 | \definecolor{TUgray}{RGB}{185,184,188} 9 | 10 | \definecolor{TUdarkblue}{RGB}{65,90,140} 11 | \definecolor{TUblue}{RGB}{0,105,170} 12 | \definecolor{TUlightblue}{RGB}{80,170,200} 13 | 14 | \definecolor{TUlightgreen}{RGB}{130,185,160} 15 | \definecolor{TUgreen}{RGB}{125,165,75} 16 | \definecolor{TUdarkgreen}{RGB}{50,110,30} 17 | 18 | \definecolor{TUlightred}{RGB}{200,80,60} 19 | \definecolor{TUpurple}{RGB}{175,110,150} 20 | \definecolor{TUorange}{RGB}{210,150,0} 21 | 22 | % =================================================================== 23 | % SEABORN 24 | 25 | \definecolor{SNSblue}{rgb}{0.1216, 0.4666, 0.7059} 26 | \definecolor{sns_blue}{HTML}{1f77b4} 27 | \definecolor{SNSorange}{rgb}{1.0, 0.4980, 0.0549} 28 | \definecolor{sns_orange}{HTML}{ff7f0e} 29 | \definecolor{sns_orange_light}{HTML}{FFE5CE} 30 | \definecolor{SNSgreen}{rgb}{0.1725, 0.6274, 0.1725} 31 | \definecolor{sns_green}{rgb}{0.17254901960784313, 0.6274509803921569, 0.17254901960784313} 32 | \definecolor{SNSred}{rgb}{0.84, 0.15, 0.16} 33 | \definecolor{SNSpurple}{rgb}{0.58, 0.40, 0.74} 34 | 35 | \definecolor{SNSorange_shaded}{HTML}{ffcea3} 36 | \definecolor{SNSblue_shaded}{HTML}{8ebad9} 37 | \definecolor{SNSgreen_shaded}{HTML}{cae7ca} 38 | \definecolor{SNSred_shaded}{HTML}{ea9293} 39 | 40 | % =================================================================== 41 | % VIVIT 42 | 43 | % open office plot (quantities provided by vivit) 44 | \definecolor{oo_rot}{RGB}{204,0,0} 45 | \definecolor{oo_blau}{RGB}{51,153,255} 46 | \definecolor{oo_gruen}{RGB}{0,153,0} 47 | \definecolor{oo_gelb}{RGB}{153,153,102} 48 | % Color for SNR plot 49 | \definecolor{light_red}{RGB}{235,135,117} 50 | 51 | 52 | %%% Local Variables: 53 | %%% mode: latex 54 | %%% TeX-master: "../thesis" 55 | %%% End: 56 | -------------------------------------------------------------------------------- /chapters/overview.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % THESIS OVERVIEW 3 | % =================================================================== 4 | \section{Introduction}\label{sec:introduction} 5 | 6 | \Blindtext 7 | 8 | \begin{lstlisting}[ language=Python, caption={\textbf{Canonical deep learning 9 | training loop.} After setting up the data, model, loss function, and optimizer, 10 | iterate over batches: in each iteration, compute the mini-batch loss in a forward 11 | pass, and its gradient with a backward pass. Then use the gradient as learning 12 | signal to update the model parameters.}, label=alg:background::trainingLoop, 13 | captionpos=t, 14 | linebackgroundcolor={\ifnum\value{lstnumber}=15\color{secondcolor!50}\fi\ifnum\value{lstnumber}=16\color{secondcolor!50}\fi}] 15 | % dataset = ... # Learning task examples (@\label{line:background::dataset}@) 16 | 17 | model = ... # Practitioner's choice (@\label{line:background::model}@) 18 | loss_func = ... # Practitioner's choice (@\label{line:background::lossFunc}@) 19 | 20 | optimizer = ... # First-order method 21 | 22 | while not_converged: # Standard training loop 23 | features, targets = dataset.next_minibatch() 24 | 25 | # Forward pass: Compute the loss 26 | predictions = model(features) 27 | loss = loss_func(predictions, targets) 28 | 29 | # Backward pass: Compute the gradient 30 | loss.backward() (@\label{line:background::Backward}@) 31 | 32 | # Update model parameters using the gradient 33 | optimizer.step() 34 | optimizer.zero_grad() 35 | \end{lstlisting} 36 | 37 | Reference to \Cref{line:background::Backward}. 38 | 39 | \section{Outline} 40 | \Blindtext 41 | 42 | \textbf{You have to run one the script \texttt{build-force.sh} to generate the 43 | following externalized TikZ figure:} 44 | 45 | \begin{figure}[!h] 46 | \centering 47 | \tikzexternalenable 48 | % \tikzset{external/remake next=true} % force-recompile next figure 49 | \begin{tikzpicture} 50 | \node[circle, fill=secondcolor!50!white] {Test TikZ picture}; 51 | \end{tikzpicture} 52 | \tikzexternaldisable 53 | \caption{\textbf{A TikZ figure:} This figure checks if externalization works.} 54 | \end{figure} 55 | 56 | \begin{disclaimer} 57 | \Cref{chap:paper-1} is based on the peer-reviewed 58 | conference publication with the following co-author contributions: 59 | 60 | \fullcite{dangel2020backpack} \cite{dangel2020backpack} 61 | 62 | \vspace{-1.75ex} 63 | 64 | \begin{center} 65 | \begin{tabular}[!h]{lrrrr} 66 | & \textbf{Ideas} & \textbf{Experiments} & \textbf{Analysis} & \textbf{Writing} 67 | \\ 68 | \textbf{F.\,Dangel} & 33\,\% & 55\,\% & 45\,\% & 35\,\% 69 | \\ 70 | F.\,Kunstner & 33\,\%& 45\,\% & 45\,\% & 45\,\% 71 | \\ 72 | P.\,Hennig & 33\,\% & 0\,\% & 10\,\% & 20\,\% 73 | \end{tabular} 74 | \end{center} 75 | \end{disclaimer} 76 | 77 | \marginnote{% 78 | \Cref{chap:paper-1}: \backpack: an efficient framework built on top of 79 | \PyTorch that extends the backpropagation algorithm. 80 | \begin{center} \vspace{-5ex} 81 | \includegraphics[height=0.8\linewidth]{example-image-a} 82 | \href{https://github.com/f-dangel/backpack}{\texttt{github.com/f-dangel/backpack}} 83 | \end{center}} % 84 | 85 | %%% Local Variables: 86 | %%% mode: latex 87 | %%% TeX-master: "../thesis" 88 | %%% End: 89 | -------------------------------------------------------------------------------- /thesis.tex: -------------------------------------------------------------------------------- 1 | \input{preamble/preamble} 2 | 3 | \begin{document} 4 | 5 | % =================================================================== 6 | % FRONTMATTER 7 | % =================================================================== 8 | 9 | \frontmatter % start pre-document content, use roman numerals 10 | \input{frontmatter/coverpage} 11 | 12 | % Show page number in footer aligned to the outside of the page (excluding chapter pages) 13 | \pagestyle{pagenum.scrheadings} 14 | 15 | \input{frontmatter/acknowledgments} 16 | 17 | \input{frontmatter/abstract} 18 | 19 | \input{frontmatter/zusammenfassung} 20 | 21 | \input{frontmatter/toc_lof_lot} 22 | 23 | \input{frontmatter/notation} 24 | 25 | % =================================================================== 26 | % MAINMATTER 27 | % =================================================================== 28 | 29 | \mainmatter% start main document, reset page numbering, use arabic numbers 30 | 31 | % --------------------------------- 32 | % STRUCTURAL OVERVIEW 33 | % --------------------------------- 34 | 35 | \setchapterpreamble[u]{\margintoc} 36 | \pagelayout{margin} % restore margins 37 | \chapter{Overview}\label{chap:overview} 38 | \input{chapters/overview} 39 | 40 | % --------------------------------- 41 | % BACKGROUND 42 | % --------------------------------- 43 | 44 | \pagelayout{wide} % disable margins 45 | \part{Background \& Motivation}\label{part:background} 46 | \pagelayout{margin} % restore margins 47 | 48 | \setchapterpreamble[u]{\margintoc} 49 | \chapter{Background 1}\label{chap:background-1} 50 | \input{chapters/background1} 51 | 52 | \setchapterpreamble[u]{\margintoc} 53 | \chapter{Background 2 (advanced)}\label{chap:background-2} 54 | \input{chapters/background2} 55 | 56 | % --------------------------------- 57 | % MAIN WORK 58 | % --------------------------------- 59 | 60 | \pagelayout{wide} % disable margins 61 | \part{Backpropagation Beyond the Gradient}\label{part:papers} 62 | \pagelayout{margin} % restore margins 63 | 64 | \setchapterpreamble[u]{\margintoc} 65 | \chapter{Paper 1}\label{chap:paper-1} 66 | \input{chapters/paper1} 67 | 68 | \setchapterpreamble[u]{\margintoc} 69 | \chapter{Paper 2}\label{chap:paper-2} 70 | \input{chapters/paper2} 71 | 72 | 73 | % --------------------------------- 74 | % CONCLUSION 75 | % --------------------------------- 76 | 77 | \pagelayout{wide} % disable margins 78 | \part{Conclusion \& Future Directions}\label{part:conclusion} 79 | \pagelayout{margin} % restore margins 80 | 81 | \setchapterpreamble[u]{\margintoc} 82 | \chapter{Conclusion \& Future Directions}\label{chap:conclusion} 83 | \input{chapters/conclusion} 84 | 85 | % --------------------------------- 86 | % APPENDIX 87 | % --------------------------------- 88 | 89 | \appendix % number chapters with letters from here on 90 | 91 | \pagelayout{wide} % No margins 92 | \part{Appendix}\label{part:appendix} 93 | \pagelayout{margin} % Restore margins 94 | 95 | \setchapterpreamble[u]{\margintoc} 96 | \chapter{Additional Material for Chapter \ref{chap:paper-1}} 97 | \input{chapters/paper1_app} 98 | 99 | \setchapterpreamble[u]{\margintoc} 100 | \chapter{Additional Material for Chapter \ref{chap:paper-2}} 101 | \input{chapters/paper2_app} 102 | 103 | % =================================================================== 104 | % BACKMATTER 105 | % =================================================================== 106 | 107 | \backmatter% end of the main document content 108 | 109 | \input{backmatter/bibliography} 110 | 111 | \end{document} 112 | 113 | %%% Local Variables: 114 | %%% mode: latex 115 | %%% TeX-master: t 116 | %%% End: 117 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | potato.yml 2 | **.~undo-tree~ 3 | 4 | ## Core latex/pdflatex auxiliary files: 5 | *.aux 6 | *.lof 7 | *.log 8 | *.lot 9 | *.fls 10 | *.out 11 | *.toc 12 | *.fmt 13 | *.fot 14 | *.cb 15 | *.cb2 16 | .*.lb 17 | *.dep 18 | *.figlist 19 | *.makefile 20 | 21 | ## Intermediate documents: 22 | *.dvi 23 | *.xdv 24 | *-converted-to.* 25 | # these rules might exclude image files for figures etc. 26 | # *.ps 27 | # *.eps 28 | # *.pdf 29 | 30 | ## Generated if empty string is given at "Please type another file name for output:" 31 | .pdf 32 | 33 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 34 | *.bbl 35 | *.bcf 36 | *.blg 37 | *-blx.aux 38 | *-blx.bib 39 | *.run.xml 40 | 41 | ## Build tool auxiliary files: 42 | *.fdb_latexmk 43 | *.synctex 44 | *.synctex(busy) 45 | *.synctex.gz 46 | *.synctex.gz(busy) 47 | *.pdfsync 48 | *.pdf-view-restore 49 | 50 | ## Build tool directories for auxiliary files 51 | # latexrun 52 | latex.out/ 53 | 54 | ## Auxiliary and intermediate files from other packages: 55 | # algorithms 56 | *.alg 57 | *.loa 58 | 59 | # achemso 60 | acs-*.bib 61 | 62 | # amsthm 63 | *.thm 64 | 65 | # beamer 66 | *.nav 67 | *.pre 68 | *.snm 69 | *.vrb 70 | 71 | # changes 72 | *.soc 73 | 74 | # comment 75 | *.cut 76 | 77 | # cprotect 78 | *.cpt 79 | 80 | # elsarticle (documentclass of Elsevier journals) 81 | *.spl 82 | 83 | # endnotes 84 | *.ent 85 | 86 | # fixme 87 | *.lox 88 | 89 | # feynmf/feynmp 90 | *.mf 91 | *.mp 92 | *.t[1-9] 93 | *.t[1-9][0-9] 94 | *.tfm 95 | 96 | #(r)(e)ledmac/(r)(e)ledpar 97 | *.end 98 | *.?end 99 | *.[1-9] 100 | *.[1-9][0-9] 101 | *.[1-9][0-9][0-9] 102 | *.[1-9]R 103 | *.[1-9][0-9]R 104 | *.[1-9][0-9][0-9]R 105 | *.eledsec[1-9] 106 | *.eledsec[1-9]R 107 | *.eledsec[1-9][0-9] 108 | *.eledsec[1-9][0-9]R 109 | *.eledsec[1-9][0-9][0-9] 110 | *.eledsec[1-9][0-9][0-9]R 111 | 112 | # glossaries 113 | *.acn 114 | *.acr 115 | *.glg 116 | *.glo 117 | *.gls 118 | *.glsdefs 119 | *.lzo 120 | *.lzs 121 | 122 | # uncomment this for glossaries-extra (will ignore makeindex's style files!) 123 | # *.ist 124 | 125 | # gnuplottex 126 | *-gnuplottex-* 127 | 128 | # gregoriotex 129 | *.gaux 130 | *.gtex 131 | 132 | # htlatex 133 | *.4ct 134 | *.4tc 135 | *.idv 136 | *.lg 137 | *.trc 138 | *.xref 139 | 140 | # hyperref 141 | *.brf 142 | 143 | # knitr 144 | *-concordance.tex 145 | # TODO Comment the next line if you want to keep your tikz graphics files 146 | *.tikz 147 | *-tikzDictionary 148 | 149 | # listings 150 | *.lol 151 | 152 | # luatexja-ruby 153 | *.ltjruby 154 | 155 | # makeidx 156 | *.idx 157 | *.ilg 158 | *.ind 159 | 160 | # minitoc 161 | *.maf 162 | *.mlf 163 | *.mlt 164 | *.mtc[0-9]* 165 | *.slf[0-9]* 166 | *.slt[0-9]* 167 | *.stc[0-9]* 168 | 169 | # minted 170 | _minted* 171 | *.pyg 172 | 173 | # morewrites 174 | *.mw 175 | 176 | # nomencl 177 | *.nlg 178 | *.nlo 179 | *.nls 180 | 181 | # pax 182 | *.pax 183 | 184 | # pdfpcnotes 185 | *.pdfpc 186 | 187 | # sagetex 188 | *.sagetex.sage 189 | *.sagetex.py 190 | *.sagetex.scmd 191 | 192 | # scrwfile 193 | *.wrt 194 | 195 | # sympy 196 | *.sout 197 | *.sympy 198 | sympy-plots-for-*.tex/ 199 | 200 | # pdfcomment 201 | *.upa 202 | *.upb 203 | 204 | # pythontex 205 | *.pytxcode 206 | pythontex-files-*/ 207 | 208 | # tcolorbox 209 | *.listing 210 | 211 | # thmtools 212 | *.loe 213 | 214 | # TikZ & PGF 215 | *.dpth 216 | *.md5 217 | *.auxlock 218 | 219 | # todonotes 220 | *.tdo 221 | 222 | # vhistory 223 | *.hst 224 | *.ver 225 | 226 | # easy-todo 227 | *.lod 228 | 229 | # xcolor 230 | *.xcp 231 | 232 | # xmpincl 233 | *.xmpi 234 | 235 | # xindy 236 | *.xdy 237 | 238 | # xypic precompiled matrices and outlines 239 | *.xyc 240 | *.xyd 241 | 242 | # endfloat 243 | *.ttt 244 | *.fff 245 | 246 | # Latexian 247 | TSWLatexianTemp* 248 | 249 | ## Editors: 250 | # WinEdt 251 | *.bak 252 | *.sav 253 | 254 | # Texpad 255 | .texpadtmp 256 | 257 | # LyX 258 | *.lyx~ 259 | 260 | # Kile 261 | *.backup 262 | 263 | # KBibTeX 264 | *~[0-9]* 265 | 266 | # auto folder when using emacs and auctex 267 | ./auto/* 268 | *.el 269 | !*/.dir-locals.el 270 | 271 | # expex forward references with \gathertags 272 | *-tags.tex 273 | 274 | # standalone packages 275 | *.sta 276 | 277 | # Makeindex log files 278 | *.lpz 279 | 280 | 281 | # Python data files 282 | *-ubyte 283 | *.pt 284 | **/__pycache_ _ 285 | 286 | # pdf 287 | **.pdf 288 | !thesis.pdf 289 | 290 | # Python IDE files 291 | . -------------------------------------------------------------------------------- /preamble/tuetitle.sty: -------------------------------------------------------------------------------- 1 | % Titelblatt für die Dissertation bei 2 | % der Mathematisch-Naturwissenschaftlichen Fakultät der Universität Tübingen 3 | % 4 | % Without hyphens: grammatically wrong, but the university wants it so... 5 | % 6 | % Derived from the original tuetitle package with changes by me (Frank Schneider) 7 | % 8 | % Derived by the tuhhtitle.sty file: 9 | % Titelei für die Technische Universität Hamburg-Harburg 10 | % Copyright (c) Markus Kohm, 2007 11 | % 12 | % Redefines the \maketitle command to produce university-approved title page. 13 | % Details and examples are at the end of this file. 14 | % 15 | % This work consists of the file tuetitle.sty only. 16 | 17 | \NeedsTeXFormat{LaTeX2e} 18 | \ProvidesPackage{preamble/tuetitle}[2018/06/27 v3.2] 19 | 20 | \newif\if@internal@titlepage 21 | \DeclareOption{internal}{\@internal@titlepagetrue} 22 | \DeclareOption{external}{\@internal@titlepagefalse} 23 | 24 | \newif\if@phd 25 | \DeclareOption{dissertation}{\@phdtrue} 26 | \DeclareOption{habilitation}{\@phdfalse} 27 | 28 | \ExecuteOptions{dissertation,internal} 29 | \ProcessOptions\relax 30 | 31 | \newcommand*{\@birthplace}{% 32 | \PackageError{tuetitle}{\string\birthplace\space missing}{% 33 | You have to use \string\birthplace\space to set up the author's birthplace.}% 34 | } 35 | \newcommand*{\birthplace}[1]{\gdef\@birthplace{#1}} 36 | 37 | \newcommand*{\@submissionyear}{\@arabic{\year}% 38 | \PackageWarningNoLine{tuetitle}{\string\submissionyear\space missing, current year assumed}} 39 | \newcommand*{\submissionyear}[1]{\gdef\@submissionyear{#1}} 40 | 41 | 42 | \if@internal@titlepage 43 | \newcommand*{\@dean}{% 44 | \PackageError{tuetitle}{\string\dean\space missing}{% 45 | You have to use \string\dean\space to set up the faculty dean.}% 46 | } 47 | \newcommand*{\dean}[1]{\gdef\@dean{#1}} 48 | 49 | \newcommand*{\@experts}{% 50 | \PackageError{tuetitle}{\string\experts\space missing}{% 51 | You have to use \string\experts\space to set up the experts,\MessageBreak 52 | e.g. `\string\experts{Name of the First Expert\string\and\space 53 | Name of the Second Expert}'.}% 54 | } 55 | \newcommand*{\experts}[1]{\gdef\@experts{#1}} 56 | 57 | \newcommand*{\dateoforalexamination}[1]{\gdef\@date{#1}} 58 | \else 59 | \newcommand*{\dean}[1]{\PackageWarning{tuetitle}{No \string\dean\space necessary\MessageBreak in external title page}} 60 | \newcommand*{\experts}[1]{\PackageWarning{tuetitle}{No \string\experts\space necessary\MessageBreak in external title page}} 61 | \newcommand*{\dateoforalexamination}[1]% 62 | {\PackageWarning{tuetitle}{No \string\dateoforalexamination\space necessary\MessageBreak in external title page}} 63 | \fi 64 | 65 | 66 | \renewcommand*{\maketitle}{% 67 | \begin{titlepage} 68 | \centering 69 | \vspace*{\stretch{.5}} 70 | {\Huge\selectfont\sffamily\strut\ignorespaces\@title\strut}\\[0pt] 71 | \vspace*{\stretch{2}} 72 | \if@phd\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi 73 | {% code for PhD thesis 74 | {\fontsize{14.4}{18}\bfseries\sffamily Dissertation}\\[0pt] 75 | \vspace*{5pt} 76 | {\fontsize{12}{14}\sffamily \fontseries{l}\selectfont% 77 | der Mathematisch-Naturwissenschaftlichen Fakult\"{a}t\\[2.5pt] 78 | der Eberhard Karls Universit\"{a}t T\"{u}bingen\\[2.5pt] 79 | zur Erlangung des Grades eines\\[2.5pt] 80 | Doktors der Naturwissenschaften\\[2.5pt] 81 | (Dr.\ rer.\ nat.)}\\} 82 | {% code for Habil 83 | {\fontsize{14.4}{18}\selectfont\textsc{Habilitationsschrift}}\\[0pt] 84 | \vspace*{\stretch{1}}} 85 | \vspace*{\stretch{2}} 86 | {\fontsize{12}{14}\sffamily \fontseries{l}\selectfont vorgelegt von}\\[0pt] 87 | {\Large\sffamily\strut\ignorespaces\@author}\\[2pt] 88 | {\fontsize{12}{14}\sffamily \fontseries{l}\selectfont aus \@birthplace}\\[0pt] 89 | \vspace*{\stretch{1}} 90 | {\fontsize{12}{14}\sffamily \fontseries{l}\selectfont T\"{u}bingen\\[2.5pt] \@submissionyear} 91 | \clearpage\normalsize 92 | % 93 | \if@phd\if@internal@titlepage 94 | \thispagestyle{empty}\raggedright\null\vfill 95 | Gedruckt mit Genehmigung der Mathematisch-Naturwissenschaftlichen Fakult\"at der 96 | Eberhard Karls Universit\"at T\"ubingen.\par\bigskip\bigskip\bigskip\noindent 97 | \count@=\@ne 98 | \def\and{\unskip\strut\\ 99 | \global\advance\count@\@ne 100 | \the\count@.~Berichterstatter: & \ignorespaces}% 101 | \begin{tabular}{@{}ll} 102 | Tag der m\"{u}ndlichen Qualifikation: \qquad & \@date \\ 103 | &\\ 104 | Dekan: & \@dean \\ 105 | 1. Berichterstatter: & \@experts 106 | \end{tabular} 107 | \clearpage 108 | \fi\fi 109 | \end{titlepage} 110 | \global\let\maketitle\relax 111 | } 112 | 113 | \endinput -------------------------------------------------------------------------------- /chapters/background1.tex: -------------------------------------------------------------------------------- 1 | \blindtext 2 | 3 | \marginnote{% 4 | The arrangement of partial derivatives in the generalizations of Jacobian and 5 | Hessian implies the following chain rule generalization for second-order 6 | derivatives: 7 | \begin{theorem}[\textbf{Chain rule for the generalized 8 | Hessian}]\label{hbp::the:chainRuleHessians} 9 | Let $\vb: \mathbb{R}^n \to \mathbb{R}^m$ and $\vc: \mathbb{R}^m \to 10 | \mathbb{R}^p$ be twice differentiable and $\vd = \vc \circ \vb: \mathbb{R}^n 11 | \to \mathbb{R}^p, \va \mapsto \vd(\va) = \vc(\vb(\va))$. The relation 12 | between the Hessian of $\vd$ and the Jacobians and Hessians of the 13 | constituents $\vc$ and $\vb$ is given by 14 | \begin{align} 15 | \label{hbp::equ:chainRuleHessians} 16 | \begin{split} 17 | &\gradsquared{\va} 18 | \vd(\va) 19 | \\ 20 | &\,\,= 21 | \left[ 22 | \mI_p \otimes \jac_{\va} \vb(\va) 23 | \right]^\top 24 | \left[ 25 | \gradsquared{\vb} \vc(\vb) 26 | \right] 27 | \jac_{\va} \vb(\va) 28 | \\ 29 | &\,\,\phantom{= } 30 | + 31 | \left[ 32 | \jac_{\vb} \vc(\vb) \otimes \mI_n 33 | \right] 34 | \gradsquared{\va} \vb(\va) 35 | \end{split} 36 | \end{align} 37 | \end{theorem}}% 38 | 39 | \section{Background topic 1}\label{sec:background-1::topic-1} 40 | 41 | \begin{definition}[\textbf{Hessian}]\label{def:background::Hessian} 42 | Let $b: \sR^D \to \sR; \va \mapsto b(\va)$ be a differentiable 43 | vector-to-scalar function. The Hessian $\gradsquared{\va} b \in \sR^{D\times 44 | D}$ of $b$ \wrt $\va$ is a symmetric matrix containing the second-order 45 | partial derivatives 46 | \begin{align} 47 | \label{eq:background::HessianVectorToScalar} 48 | \gradsquared{\va}b = \frac{\partial^2 b}{\partial \va \partial \va^{\top}} 49 | \qquad 50 | \text{with} 51 | \qquad 52 | [\gradsquared{\va}b]_{i,j} = \frac{\partial^2 b}{\partial \eva_i \partial \eva_j} 53 | \end{align} 54 | The Hessian will often be denoted by $\mH$. \Eg $\mH_{\pdata}(\vtheta) := 55 | \gradsquared{\vtheta} \gL_{\pdata}(\vtheta)$ for the Hessian of the population 56 | risk, and $\mH_{\sD}(\vtheta) := \gradsquared{\vtheta} \gL_{\sD}(\vtheta)$ for 57 | the Hessian of the empirical risk on a dataset $\sD$ (with $\sD = \Dtrain,\sB$ 58 | for the train loss and mini-batch Hessian). 59 | \end{definition} 60 | 61 | \section{Background topic 2}\label{sec:background-1::topic-2} 62 | 63 | \begin{example}[\textbf{Least squares regression \& square 64 | loss}]\label{ex:background::Regression} 65 | Regression associates features in $\sX = \sR^M$ with targets in $\sY = 66 | \sR^C$. A prediction in $\sF = \sR^{C}$ compares to its ground truth via the 67 | mean squared error\sidenote{% 68 | There exist different conventions for the normalization factor. This text 69 | adapts the implementation of 70 | \inlinecode{\href{https://pytorch.org/docs/1.11/generated/torch.nn.MSELoss.html\#torch.nn.MSELoss}{MSELoss}} 71 | (with \inlinecode{reduction="mean"} mode) in \pytorch for consistency with 72 | the code presented in later chapters. Normalizing by $\nicefrac{1}{C}$ is 73 | also close to what the name, mean squared error, suggests.} 74 | \begin{align}\label{eq:background::squareLoss} 75 | \ell(\vf, \vy) 76 | = 77 | \frac{1}{C} \sum_{c=1}^C (\evy_c - \evf_c)^2 78 | = 79 | \frac{1}{C} \lVert \vy - \vf \rVert_{2}^{2} 80 | \end{align} 81 | \end{example} 82 | 83 | \blindtext 84 | 85 | \marginnote[*-6]{% 86 | \begin{remark}[\textbf{The log-probability's $\vtheta$-gradient vanishes in 87 | expectation}]\label{note:background::KLTaylorFirstOrderTermVanishes} 88 | \hspace{-\baselineskip} 89 | \begin{align*} 90 | -\int_{\sOmega} 91 | & p_{\vtheta}(\vz) 92 | \grad{\vtheta} \log p_{\vtheta}(\vz) 93 | \,\diff\vz 94 | \\ 95 | &= 96 | -\int_{\sOmega} p_{\vtheta}(\vz) 97 | \frac{\grad{\vtheta}p_{\vtheta}(\vz)}{p_{\vtheta}(\vz)} 98 | \,\diff\vz 99 | \\ 100 | &= 101 | - \grad{\vtheta} 102 | \left( 103 | \int_{\sOmega} 104 | p_{\vtheta}(\vz) 105 | \,\diff\vz 106 | \right) 107 | \\ 108 | &= 109 | -\grad{\vtheta} 1 = 0 110 | \end{align*} 111 | \end{remark} 112 | } 113 | % 114 | 115 | \blindtext 116 | 117 | \begin{table}[!t] 118 | \caption{\textbf{Forward pass for common modules used in feedforward 119 | networks.} Input and output are denoted $\vx, \vz$ rather than $\vz^{(l)}, 120 | \vz^{(l+1)}$ to avoid clutter. $\mI$ is the identity matrix. Bold upper-case 121 | symbols ($\mW, \mX, \mZ, \dots$) denote matrices and bold upper-case sans 122 | serif symbols ($\tW, \tX, \tZ, \dots$) denote tensors.} 123 | \label{tab:background::forward} 124 | \centering 125 | \begin{footnotesize} 126 | \begin{tabular}{ll} 127 | \toprule 128 | \textbf{OPERATION} & \textbf{FORWARD} 129 | \\ 130 | \midrule 131 | % matrix-vector multiplication 132 | Matrix-vector multiplication & $\vz(\vx, \mW) = \mW\vx$ 133 | \\ 134 | % matrix-matrix multiplication 135 | Matrix-matrix multiplication & $\mZ(\mX, \mW) = \mW\mX$ 136 | \\ 137 | % addition 138 | Addition & $\vz(\vx, \vb) = \vx + \vb$ 139 | \\ 140 | % elementwise activation 141 | Elementwise activation & $\vz(\vx) = \vphi(\vx)$\,,\ \text{s.t.} $z_i(\vx) = \phi(x_i)$ 142 | \\ 143 | \midrule 144 | % residual unit/skip-connection 145 | Skip-connection & $\vz(\vx, \vtheta) = \vx + \vs(\vx, \vtheta)$ 146 | \\ 147 | \midrule 148 | % reshape/view operation 149 | Reshape/view & $\tZ(\tX)= \mathrm{reshape}(\tX)$ 150 | \\ 151 | % extraction operator 152 | Index select/map $\pi$ & $\vz(\vx) = \mPi \vx\, ,$ $\emPi_{j,\pi(j)} = 1\,, $ 153 | \\ 154 | % convolution 155 | Convolution & $\tZ(\tX, \tW) = \tX \star \tW$\,, 156 | \\ 157 | & $\mZ(\mW, \llbracket\tX\rrbracket) = \mW \llbracket \tX \rrbracket$\,, 158 | \\ 159 | \midrule 160 | % square loss 161 | Square loss & $\ell(\vf, \vy) = \nicefrac{1}{C} (\vy-\vf)^\top (\vy - \vf)$ \\ 162 | % cross-entropy loss 163 | Softmax cross-entropy & $\ell(\vf, y) = - \onehot(y)^\top \log\left[\vp(\vf)\right]$ 164 | \\ 165 | \bottomrule 166 | \end{tabular} 167 | \end{footnotesize} 168 | \end{table} 169 | 170 | 171 | %%% Local Variables: 172 | %%% mode: latex 173 | %%% TeX-master: "../thesis" 174 | %%% End: 175 | -------------------------------------------------------------------------------- /preamble/thesis.cls: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e} 2 | \ProvidesClass{preamble/thesis}[2021/07/14 v0.0.1 Thesis] 3 | 4 | \LoadClassWithOptions{preamble/kaobook} 5 | 6 | %---------------------------------------------------------------------------------------- 7 | % CUSTOM FRONT-, MAIN-, BACK- MATTERS BEHAVIOUR 8 | %---------------------------------------------------------------------------------------- 9 | 10 | 11 | % CHANGED: AUTOMATICALLY USE CUSTOMKAO WHEN IN MAIN MATTER 12 | % Main matter 13 | \let\kaomainmatter\mainmatter % Store the old command 14 | \renewcommand{\mainmatter}{% 15 | \kaomainmatter% Call the old command 16 | \pagestyle{scrheadings}% Use a fancy style for the header and the footer 17 | \pagelayout{margin}% Use a 1.5 column layout 18 | \setchapterstyle{customkao} % Choose the default chapter heading style 19 | } 20 | 21 | %---------------------------------------------------------------------------------------- 22 | % CUSTOM CHAPTER HEADING STYLES 23 | %---------------------------------------------------------------------------------------- 24 | 25 | % CHANGED: INCLUDE CUSTOMKAO 26 | \DeclareDocumentCommand{\setchapterstyle}{m}{% 27 | \ifthenelse{\equal{plain}{#1}}{\chapterstyleplain}{} 28 | \ifthenelse{\equal{bar}{#1}}{\chapterstylebar}{} 29 | \ifthenelse{\equal{lines}{#1}}{\chapterstylelines}{} 30 | \ifthenelse{\equal{kao}{#1}}{\chapterstylekao}{} 31 | \ifthenelse{\equal{customkao}{#1}}{\chapterstylecustomkao}{} 32 | } 33 | 34 | % The Custom Kao style 35 | % CHANGED: COLORED NUMBER AN LINE 36 | % CHANGED: THICKER LINE 37 | \DeclareDocumentCommand{\chapterstylecustomkao}{}{% 38 | \renewcommand*{\chapterformat}{% 39 | \mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\color{maincolor}\thechapter\autodot}}% 40 | }% 41 | \renewcommand\chapterlinesformat[3]{% 42 | \vspace{3.5\vscale}% 43 | \if@twoside% 44 | \Ifthispageodd{% 45 | \smash{\makebox[0pt][l]{% 46 | \parbox[b]{\textwidth}{\flushright{##3}}% 47 | \makebox[\marginparsep][c]{\color{maincolor}\rule[-2\vscale]{2pt}{27.4\vscale+\f@size mm}}% 48 | \parbox[b]{\marginparwidth}{##2}% 49 | }}% 50 | }{ 51 | \smash{\makebox[\textwidth][r]{% 52 | \parbox[b]{\marginparwidth}{\flushright{##2}}% 53 | \makebox[\marginparsep][c]{\color{maincolor}\rule[-2\vscale]{2pt}{27.4\vscale+\f@size mm}}% 54 | \parbox[b]{\textwidth}{\flushleft{##3}}% 55 | }}% 56 | } 57 | \else% 58 | \smash{\makebox[0pt][l]{% 59 | \parbox[b]{\textwidth}{\flushright{##3}}% 60 | \makebox[\marginparsep][c]{\color{maincolor}\rule[-2\vscale]{2pt}{27.4\vscale+\f@size mm}}% 61 | \parbox[b]{\marginparwidth}{##2}% 62 | }}% 63 | \fi% 64 | }% 65 | \RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}% 66 | \setlength{\mtocshift}{-3\vscale}% 67 | } 68 | 69 | %---------------------------------------------------------------------------------------- 70 | % CUSTOM HEADERS AND FOOTERS 71 | %--------------------------------------------------------------------------------------- 72 | 73 | % Style with chapter number, chapter title, and page in the header (used throughout the document) 74 | \renewpagestyle{scrheadings}{% 75 | {\smash{\hspace{-\headmarginparwidth}\hspace{-\headmarginparsep}\makebox[\headtotal][l]{% 76 | \makebox[7\hscale][r]{\normalfont\sffamily\LARGE\color{lightgraycolor}\textbf\thepage}% 77 | \makebox[3\hscale]{}{\color{maincolor}\rule[-1mm]{1.5pt}{19\vscale-1mm}}\makebox[3\hscale]{}% 78 | \makebox[\headtextwidth][l]{\leftmark}}}}% 79 | {\smash{\makebox[0pt][l]{\makebox[\headtotal][r]{% 80 | \makebox[\headtextwidth][r]{\hfill\rightmark}% 81 | \makebox[3\hscale]{}{\color{maincolor}\rule[-1mm]{1.5pt}{19\vscale-1mm}}\makebox[3\hscale]{}% 82 | \makebox[7\hscale][l]{\normalfont\sffamily\LARGE\color{lightgraycolor}\textbf\thepage}}}}}% 83 | {\smash{\makebox[0pt][l]{\makebox[\headtotal][r]{% 84 | \makebox[\headtextwidth][r]{\hfill\rightmark}% 85 | \makebox[3\hscale]{}{\color{maincolor}\rule[-1mm]{1.5pt}{19\vscale-1mm}}\makebox[3\hscale]{}% 86 | \makebox[7\hscale][l]{\normalfont\sffamily\LARGE\color{lightgraycolor}\textbf\thepage}}}}}% 87 | }{% 88 | {}% 89 | {}% 90 | {}% 91 | } 92 | 93 | %---------------------------------------------------------------------------------------- 94 | % MARGIN TOC 95 | %---------------------------------------------------------------------------------------- 96 | 97 | % CHANGED: FIX BUG THAT SHOWED A "POP EMPTY COLOR PAGE STACK 0" WARNING 98 | 99 | % Command to print a table of contents in the margin 100 | \NewDocumentCommand{\custommargintoc}{O{\mtocshift}}{ % The first parameter is the vertical offset; by default it is \mtocshift 101 | \begingroup% 102 | % Move regular section and subsection to level 6 so that they won't be included and instead set let the mtoc versions take their place. 103 | % Adapted from https://tex.stackexchange.com/a/133559/226693 104 | \etocsetlevel{section}{6} 105 | \etocsetlevel{subsection}{6} 106 | \etocsetlevel{mtocsection}{1} 107 | \etocsetlevel{mtocsubsection}{2} 108 | 109 | % Define default widths 110 | \def\margintocnumwidth{-.8mm}% 111 | \def\margintocpagenumwidth{8pt}% 112 | \setlength{\RaggedRightParfillskip}{0pt} 113 | 114 | % Dry run to get the needed widths 115 | \etocsetstyle{mtocsection}% 116 | {}% 117 | {\sbox0{\usekomafont{section}\small\etocthenumber\kern.8mm}%% 118 | \sbox1{\usekomafont{section}\small\etocthepage}}% 119 | {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi%% 120 | \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}% 121 | {}% 122 | \etocsetstyle{mtocsubsection}% 123 | {}% 124 | {\sbox0{\usekomafont{section}\small\etocthenumber\kern.8mm}% 125 | \sbox1{\usekomafont{section}\small\etocthepage}}% 126 | {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi% 127 | \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}% 128 | {}% 129 | \etocsetstyle{subsubsection}% 130 | {}% 131 | {}% 132 | {}% 133 | {}% 134 | \etocsetstyle{paragraph}% 135 | {}% 136 | {}% 137 | {}% 138 | {}% 139 | \etocsettocstyle{}{% 140 | \global\let\margintocnumwidth\margintocnumwidth% 141 | \global\let\margintocpagenumwidth\margintocpagenumwidth% 142 | }% 143 | \localtableofcontents% 144 | 145 | % Set the style for section entries 146 | \etocsetstyle{mtocsection}% 147 | {\parindent 0pt \parskip 2.5pt \parfillskip 0pt \RaggedRight}% 148 | {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth} % 149 | {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\etocnumber}}\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\etocpage}}\par}% 150 | {}% 151 | % Set the style for subsection entries 152 | \etocsetstyle{mtocsubsection}% 153 | {\parindent 0pt \parskip 0pt \parfillskip 0pt \RaggedRight}% 154 | {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}% 155 | {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\etocnumber}}\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\etocpage}}\par}% 156 | {\parskip 2.5pt}% 157 | % Set the global style of the toc 158 | \etocsettocstyle{\usekomafont{section}\small}{}% 159 | \etocsetnexttocdepth{\themargintocdepth}% 160 | % Print the table of contents in the margin 161 | \marginnote[#1]{\localtableofcontents}% 162 | \FloatBarrier% 163 | \endgroup% 164 | } -------------------------------------------------------------------------------- /preamble/kaobook.cls: -------------------------------------------------------------------------------- 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{preamble/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{preamble/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 283 | -------------------------------------------------------------------------------- /preamble/kaorefs.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{kaorefs} 2 | 3 | %---------------------------------------------------------------------------------------- 4 | % PACKAGE OPTIONS AND DEPENDENCIES 5 | %---------------------------------------------------------------------------------------- 6 | 7 | % Easily label and reference elements with this package 8 | % Note that, in figures and tables, \label must appear after \caption 9 | % Load this package last 10 | 11 | % Pass this package's options to hyperref and varioref 12 | \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{varioref}} 13 | \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{hyperref}} 14 | \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{cleveref}} 15 | \ProcessOptions\relax 16 | 17 | \let\thmname\relax % Workaround to get rid of an annoying error 18 | \RequirePackage{amsthm} % Needed by cleveref 19 | \RequirePackage{varioref} 20 | \RequirePackage{hyperref} 21 | \RequirePackage[capitalise,nameinlink,noabbrev]{cleveref} 22 | 23 | 24 | %---------------------------------------------------------------------------------------- 25 | % LANGUAGE-SPECIFIC STRINGS 26 | %---------------------------------------------------------------------------------------- 27 | 28 | % #LANGUAGE 29 | \newcommand{\chapternameshort}{} 30 | \newcommand{\sectionname}{} 31 | \newcommand{\sectionnameshort}{} 32 | \newcommand{\subsectionname}{} 33 | \newcommand{\subsectionnameplural}{} 34 | \newcommand{\subsectionnameshort}{} 35 | \newcommand{\figurenameshort}{} 36 | \newcommand{\tablenameshort}{} 37 | \newcommand{\eqname}{} 38 | \newcommand{\eqnameshort}{} 39 | \newcommand{\defname}{} 40 | \newcommand{\assumname}{} 41 | \newcommand{\thmname}{} 42 | \newcommand{\propname}{} 43 | \newcommand{\lemmaname}{} 44 | \newcommand{\remarkname}{} 45 | \newcommand{\examplename}{} 46 | \newcommand{\exercisename}{} 47 | 48 | \addto\captionsdanish{% 49 | \renewcommand{\chapternameshort}{Kap.} 50 | \renewcommand{\sectionname}{Sektion} 51 | \renewcommand{\sectionnameshort}{Sek.} 52 | \renewcommand{\subsectionname}{Undersektion} 53 | \renewcommand{\subsectionnameplural}{Undersectioner} 54 | \renewcommand{\subsectionnameshort}{Undersek.} 55 | \renewcommand{\figurenameshort}{Fig.} 56 | \renewcommand{\tablenameshort}{Tab.} 57 | \renewcommand{\eqname}{Formel} 58 | \renewcommand{\eqnameshort}{Frml.} 59 | \renewcommand{\defname}{Definition} 60 | \renewcommand{\assumname}{Hypotese} 61 | \renewcommand{\thmname}{Sætning} 62 | \renewcommand{\propname}{Postulat} 63 | \renewcommand{\lemmaname}{Hjælpesætning} 64 | \renewcommand{\remarkname}{Bemærkning} 65 | \renewcommand{\examplename}{Eksempel} 66 | \renewcommand{\exercisename}{Øvelse} 67 | } 68 | \addto\captionsenglish{% 69 | \renewcommand{\chapternameshort}{Chap.} 70 | \renewcommand{\sectionname}{Section} 71 | \renewcommand{\sectionnameshort}{Sec.} 72 | \renewcommand{\subsectionname}{Subsection} 73 | \renewcommand{\subsectionnameplural}{Subsections} 74 | \renewcommand{\subsectionnameshort}{Subsec.} 75 | \renewcommand{\figurenameshort}{Fig.} 76 | \renewcommand{\tablenameshort}{Tab.} 77 | \renewcommand{\eqname}{Equation} 78 | \renewcommand{\eqnameshort}{Eq.} 79 | \renewcommand{\defname}{Definition} 80 | \renewcommand{\assumname}{Assumption} 81 | \renewcommand{\thmname}{Theorem} 82 | \renewcommand{\propname}{Proposition} 83 | \renewcommand{\lemmaname}{Lemma} 84 | \renewcommand{\remarkname}{Remark} 85 | \renewcommand{\examplename}{Example} 86 | \renewcommand{\exercisename}{Exercise} 87 | } 88 | \addto\captionsitalian{% 89 | \renewcommand{\chapternameshort}{Cap.} 90 | \renewcommand{\sectionname}{Sezione} 91 | \renewcommand{\sectionnameshort}{Sez.} 92 | \renewcommand{\subsectionname}{Sottosezione} 93 | \renewcommand{\subsectionnameplural}{Sottosezioni} 94 | \renewcommand{\subsectionnameshort}{Sottosezione} 95 | \renewcommand{\figurenameshort}{Fig.} 96 | \renewcommand{\tablenameshort}{Tab.} 97 | \renewcommand{\eqname}{Equazione} 98 | \renewcommand{\eqnameshort}{Eq.} 99 | \renewcommand{\defname}{Definizione} 100 | \renewcommand{\assumname}{Assunzione} 101 | \renewcommand{\thmname}{Teorema} 102 | \renewcommand{\propname}{Proposizione} 103 | \renewcommand{\lemmaname}{Lemma} 104 | \renewcommand{\remarkname}{Osservazione} 105 | \renewcommand{\examplename}{Esempio} 106 | \renewcommand{\exercisename}{Esercizio} 107 | } 108 | % Do you speak other languages? Please, feel free to add the captions! 109 | 110 | 111 | %---------------------------------------------------------------------------------------- 112 | % LABELLING COMMANDS 113 | %---------------------------------------------------------------------------------------- 114 | 115 | \newcommand{\labpage}[1]{\label{page:#1}} 116 | \newcommand{\labpart}[1]{\label{part:#1}} 117 | \newcommand{\labch}[1]{\label{ch:#1}} 118 | \newcommand{\labsec}[1]{\label{sec:#1}} 119 | \newcommand{\labsubsec}[1]{\label{subsec:#1}} 120 | \newcommand{\labfig}[1]{\label{fig:#1}} 121 | \newcommand{\labtab}[1]{\label{tab:#1}} 122 | \newcommand{\labeq}[1]{\label{eq:#1}} 123 | \newcommand{\labdef}[1]{\label{def:#1}} 124 | \newcommand{\labthm}[1]{\label{thm:#1}} 125 | \newcommand{\labassum}[1]{\label{assum:#1}} 126 | \newcommand{\labprop}[1]{\label{prop:#1}} 127 | \newcommand{\lablemma}[1]{\label{lemma:#1}} 128 | \newcommand{\labremark}[1]{\label{remark:#1}} 129 | \newcommand{\labexample}[1]{\label{example:#1}} 130 | \newcommand{\labexercise}[1]{\label{exercise:#1}} 131 | 132 | 133 | %---------------------------------------------------------------------------------------- 134 | % REFERENCING COMMANDS 135 | %---------------------------------------------------------------------------------------- 136 | 137 | \newcommand{\refpage}[1]{\hyperref[#1]{\pagename}\xspace\pageref{page:#1}} % Page 84 138 | \newcommand{\vrefpage}[1]{\vpageref*{page:#1}} % on the following page, on page 84 139 | 140 | % For unnumbered parts 141 | \newcommand{\arefpart}[1]{\hyperref[part:#1]{\partname}\xspace`\nameref{part:#1}'} % Part `Name of the Part' 142 | \newcommand{\avrefpart}[1]{\hyperref[part:#1]{\partname}\xspace`\nameref{part:#1}' \vpageref{part:#1}} % Part `Name of the Part' on page 84 143 | 144 | % For numbered parts 145 | \newcommand{\refpart}[1]{\hyperref[part:#1]{\partname}\xspace\ref{part:#1}} % Part IV 146 | \newcommand{\vrefpart}[1]{\hyperref[part:#1]{\partname}\xspace\vref{part:#1}} % Part IV, Part IV on the following page, Part IV on page 84 147 | \newcommand{\nrefpart}[1]{\hyperref[part:#1]{\partname}\xspace\ref{part:#1} (\nameref{part:#1})} 148 | \newcommand{\frefpart}[1]{\hyperref[part:#1]{\partname\xspace\ref{part:#1} (\nameref{part:#1}) \vpageref{part:#1}}} % Part IV (Name of the Part), Part IV (Name of the Part) on the following page, Part IV (Name of the Part) on page 84) 149 | 150 | %\newcommand{\refch}[1]{\hyperref[#1]{\chaptername\xspace\usekomafont{chapter}\normalsize\nameref{ch:#1}}\xspace\vpageref{ch:#1}\,} 151 | \newcommand{\refchshort}[1]{\hyperref[ch:#1]{\chapternameshort\xspace\ref{ch:#1}}} 152 | \newcommand{\refch}[1]{\hyperref[ch:#1]{\chaptername\xspace\ref{ch:#1}}} 153 | \newcommand{\vrefch}[1]{\hyperref[ch:#1]{\chaptername\xspace\ref{ch:#1} \vpageref{ch:#1}}} 154 | \newcommand{\nrefch}[1]{\hyperref[ch:#1]{\chaptername\xspace\ref{ch:#1} (\nameref{ch:#1})}} 155 | \newcommand{\frefch}[1]{\hyperref[ch:#1]{\chaptername\xspace\ref{ch:#1} (\nameref{ch:#1}) \vpageref{ch:#1}}} 156 | 157 | %\newcommand{\refsec}[1]{Section~{\usekomafont{section}\normalsize\nameref{sec:#1}}\xspace\vpageref{sec:#1}\,} 158 | \newcommand{\refsecshort}[1]{\hyperref[sec:#1]{\sectionnameshort\xspace\ref{sec:#1}}} 159 | \newcommand{\refsec}[1]{\hyperref[sec:#1]{\sectionname\xspace\ref{sec:#1}}} 160 | \newcommand{\vrefsec}[1]{\hyperref[sec:#1]{\sectionname\xspace\vref{sec:#1}}} 161 | \newcommand{\nrefsec}[1]{\hyperref[sec:#1]{\sectionname\xspace\ref{sec:#1} (\nameref{sec:#1})}} 162 | \newcommand{\frefsec}[1]{\hyperref[sec:#1]{\sectionname\xspace\ref{sec:#1} (\nameref{sec:#1}) \vpageref{sec:#1}}} 163 | 164 | \newcommand{\refsubsecshort}[1]{\hyperref[subsec:#1]{\sectionnameshort\xspace\ref{subsec:#1}}} 165 | \newcommand{\refsubsec}[1]{\hyperref[subsec:#1]{\subsectionname\xspace\ref{subsec:#1}}} 166 | \newcommand{\vrefsubsec}[1]{\hyperref[subsec:#1]{\subsectionname\xspace\vref{subsec:#1}}} 167 | \newcommand{\nrefsubsec}[1]{\hyperref[subsec:#1]{\subsectionname\xspace\ref{subsec:#1} (\nameref{subsec:#1})}} 168 | \newcommand{\frefsubsec}[1]{\hyperref[subsec:#1]{\subsectionname\xspace\ref{subsec:#1} (\nameref{subsec:#1}) \vpageref{subsec:#1}}} 169 | 170 | %\newcommand{\reffig}[1]{{\hypersetup{colorlinks=false}\usekomafont{captionlabel}\hyperref[fig:#1]{Figure}\xspace\ref{fig:#1}}} 171 | \newcommand{\reffigshort}[1]{\hyperref[fig:#1]{\figurenameshort\xspace\ref{fig:#1}}} 172 | \newcommand{\reffig}[1]{\hyperref[fig:#1]{\figurename}\xspace\ref{fig:#1}} 173 | \newcommand{\vreffig}[1]{\hyperref[fig:#1]{\figurename\xspace\vref{fig:#1}}} 174 | 175 | %\newcommand{\reftab}[1]{{\hypersetup{colorlinks=false}\usekomafont{captionlabel}\hyperref[tab:#1]{Table}\xspace\ref{tab:#1}}} 176 | \newcommand{\reftab}[1]{\hyperref[tab:#1]{\tablename}\xspace\ref{tab:#1}} 177 | \newcommand{\vreftab}[1]{\hyperref[tab:#1]{\tablename\xspace\vref{tab:#1}}} 178 | 179 | \newcommand{\refeqshort}[1]{\hyperref[eq:#1]\eqnameshort\xspace(\ref{eq:#1})} 180 | \newcommand{\refeq}[1]{\hyperref[eq:#1]\eqname\xspace\ref{eq:#1}} 181 | \newcommand{\vrefeq}[1]{\hyperref[eq:#1]\eqname\xspace\vref{eq:#1}} 182 | 183 | \newcommand{\refdef}[1]{\hyperref[def:#1]\defname\xspace\ref{def:#1}} 184 | \newcommand{\vrefdef}[1]{\hyperref[def:#1]\defname\xspace\vref{def:#1}} 185 | 186 | \newcommand{\refassum}[1]{\hyperref[assum:#1]\assumname\xspace\ref{assum:#1}} 187 | \newcommand{\vrefassum}[1]{\hyperref[assum:#1]\assumname\xspace\vref{assum:#1}} 188 | 189 | \newcommand{\refthm}[1]{\hyperref[thm:#1]\thmname\xspace\ref{thm:#1}} 190 | \newcommand{\vrefthm}[1]{\hyperref[thm:#1]\thmname\xspace\vref{thm:#1}} 191 | 192 | \newcommand{\refprop}[1]{\hyperref[prop:#1]\propname\xspace\ref{prop:#1}} 193 | \newcommand{\vrefprop}[1]{\hyperref[prop:#1]\propname\xspace\vref{prop:#1}} 194 | 195 | \newcommand{\reflemma}[1]{\hyperref[lemma:#1]\lemmaname\xspace\ref{lemma:#1}} 196 | \newcommand{\vreflemma}[1]{\hyperref[lemma:#1]\lemmaname\xspace\vref{lemma:#1}} 197 | 198 | \newcommand{\refremark}[1]{\hyperref[remark:#1]\remarkname\xspace\ref{remark:#1}} 199 | \newcommand{\vrefremark}[1]{\hyperref[remark:#1]\remarkname\xspace\vref{remark:#1}} 200 | 201 | \newcommand{\refexample}[1]{\hyperref[example:#1]\examplename\xspace\ref{example:#1}} 202 | \newcommand{\vrefexample}[1]{\hyperref[example:#1]\examplename\xspace\vref{example:#1}} 203 | 204 | \newcommand{\refexercise}[1]{\hyperref[exercise:#1]\exercisename\xspace\ref{exercise:#1}} 205 | \newcommand{\vrefexercise}[1]{\hyperref[exercise:#1]\exercisename\xspace\vref{exercise:#1}} 206 | 207 | 208 | %---------------------------------------------------------------------------------------- 209 | % CLEVEREF CUSTOMISATION 210 | %---------------------------------------------------------------------------------------- 211 | 212 | % Hyperlink the page reference as well 213 | \let\oldvpageref\vpageref 214 | \renewcommand{\vpageref}[1]{\hyperref[#1]{\oldvpageref{#1}}} 215 | 216 | % Remove parentheses around equations 217 | \creflabelformat{equation}{#2\textup{#1}#3} 218 | 219 | % Set the refname for subsections 220 | \crefname{subsection}{\subsectionname}{\subsectionnameplural} 221 | \Crefname{subsection}{\subsectionname}{\subsectionnameplural} 222 | 223 | % Set the refname for side notes 224 | \crefname{sidenote}{side note}{side notes} 225 | \Crefname{sidenote}{Side note}{Side notes} 226 | 227 | % Set the refname for theorems 228 | \Crefname{theorem}{Theorem}{Theorems} -------------------------------------------------------------------------------- /frontmatter/notation.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % NOTATION 3 | % =================================================================== 4 | \chapter{Notation} 5 | 6 | The notation is influenced by \citet{goodfellow2016deep}. 7 | 8 | \section*{Tensors, Matrices, Vectors, Numbers} 9 | 10 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 11 | $a$ & A scalar 12 | \\ 13 | $\va$ & A column vector 14 | \\ 15 | $\mA$ & A matrix 16 | \\ 17 | $\tA$ & A tensor 18 | \\ 19 | $\eva_{i}$ or $[\va]_i$& The $i$th entry of the vector $\va$ 20 | \\ 21 | $A_{i,j}$ or $[\mA]_{i,j}$ & The $(i,j)$th entry of the matrix $\mA$ (row $i$, 22 | column $j$) 23 | \\ 24 | $[\mA]_{i,:}$ (or $[\mA]_{:,j}$) & The $i$th row (or $j$th column) of the matrix $\mA$ 25 | \\ 26 | $\mathsfit{A}_{i,j,k}$ or $ [\tA]_{i,j,k}$ & The $(i,j,k)$th entry of the tensor 27 | $\tA$ 28 | \\ 29 | $\vec(\mA), \vec(\tA)$ & Matrix/tensor flattened into a vector; convention 30 | implies $\vec(\mA\mB\mC) = ( \mC^\top \otimes \mA ) \vec(\mB)$ 31 | \\ 32 | $\diag(\va)$ & The square matrix with vector $\va$ on the diagonal and zeros 33 | elsewhere 34 | \\ 35 | $\diag(\mA)$ & The vector containing the diagonal elements of the matrix $\mA$ 36 | \\ 37 | $\diag(\mA_{1}, \dots, \mA_{L})$ & A block-diagonal matrix with diagonal 38 | blocks given by square matrices $\mA_{1}, \dots, \mA_{L}$ 39 | \\ 40 | $\Tr(\mA), \det(\mA)$ & Trace and determinant of a matrix $\mA$ 41 | \\ 42 | $\lVert \va \rVert_2$ & $L_2$ norm of vector $\va$, \ie $\lVert \va \rVert_2^2 43 | = \va^{\top}\va$ 44 | \\ 45 | $\eig(\mA) := \{ (\lambda_{k}, \ve_{k})\}_{k}$ & Eigendecomposition of the matrix 46 | $\mA$, eigenpairs $(\lambda_{k}, \ve_{k})$ satisfy $\mA \ve_{k} = \lambda_{k} 47 | \ve_{k}$ 48 | \\ 49 | $(\lambda_{k}(\mA), \ve_{k}(\mA))$ & $k$th eigenpair (eigenvalue, eigenvector) 50 | of matrix $\mA$ 51 | \\ 52 | $\mA \otimes \mB$ & Kronecker product of two matrices, For two vectors $\va, 53 | \vb$, one has $\va \otimes \vb^{\top} = \va \vb^{\top}$ 54 | \\ 55 | $\tA \odot \tB, \mA \odot \mB, \va \odot \vb$ & Elementwise multiplication 56 | (Hadamard product) of two tensors, matrices, vectors 57 | \\ 58 | $\tA \oslash \tB, \mA \oslash \mB, \va \oslash \vb$ & Elementwise division 59 | (Hadamard division) of two tensors, matrices, vectors 60 | \\ 61 | $\tA^{\odot 2}, \mA^{\odot 2}, \va^{\odot 2}$ & Elementwise square of a 62 | tensor, matrix, vector 63 | \\ 64 | $\tA^{\odot \nicefrac{1}{2}}, \mA^{\odot \nicefrac{1}{2}}, \va^{\odot 65 | \nicefrac{1}{2}}$ & Elementwise square root of a tensor, matrix, vector 66 | \\ 67 | \end{longtable} 68 | 69 | \section*{Empirical Risk Minimization} 70 | 71 | A datum is usually indicated by a subscript $_{n}$. 72 | 73 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 74 | $(\vx, \vy)$ & Labeled datum with input features $\vx$ and target $\vy$ 75 | \\ 76 | $(\vx_n, \vy_n)$ & Datum $n$ from a dataset 77 | \\ 78 | $D$ & Total number of parameters in a model 79 | \\ 80 | $\vtheta \in \sTheta := \sR^D$ & Parameter vector of a model 81 | \\ 82 | $\vf:= f_{\vtheta}(\vx)$ & Prediction of a model $f_{\vtheta}$ for input features 83 | $\vx$ 84 | \\ 85 | $\ell$ or $\ell(\vf, \vy)$ & Loss function to compare prediction and target; 86 | convex in $\vf$ 87 | \\ 88 | $\sD := \{(\vx_n, \vy_n)\}_{n=1}^{|\sD|}$ & A dataset containing instances of 89 | labeled data $(\vx_n, \vy_n)$ indexed by $n$ 90 | \\ 91 | $\sB$ & A mini-batch $\sB \subseteq \sD$ 92 | \\ 93 | $N$ & Number of data in a mini-batch or a dataset, depending on the context 94 | \\ 95 | $\vf_n := f_{\vtheta}(\vx_n)$ & Model prediction for datum $n$ 96 | \\ 97 | $\ell_n$ or $\ell(\vf_n, \vy_n)$ & Loss of datum $n$ 98 | \\ 99 | $p_{\sD}(\vx,\vy)$ & Empirical distribution of a dataset $\sD$ 100 | \\ 101 | $\gL_{\sD}(\vtheta)$ & Empirical risk implied by the empirical distribution of 102 | a dataset $\sD$ 103 | \\ 104 | $\gL_{\Dtrain}(\vtheta), \gL_{\sB}(\vtheta), \etc$ & Training loss, mini-batch 105 | loss, \etc 106 | \end{longtable} 107 | 108 | \section*{Neural Networks} 109 | 110 | The layer number is indicated by parenthesized superscripts $^{(l)}$. 111 | 112 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 113 | $L$ 114 | & Total number of layers 115 | \\ 116 | $d^{(l)}$ 117 | & Number of parameters in layer $l$; total number of parameters is $D = 118 | \sum_{l=1}^L d^{(l)}$ 119 | \\ 120 | $\vtheta^{(l)} \in \sR^{d^{(l)}}$ 121 | & Parameter vector of layer $l$, potentially empty 122 | for parameter-free layers like activations 123 | \\ 124 | $h^{(l-1)}$ 125 | & Number of (hidden) inputs fed into layer $l$ 126 | \\ 127 | $M := h^{(0)},C := h^{(L)}$ & Input feature dimension, output dimension 128 | (number of classes for classification) 129 | \\ 130 | $\vz^{(l-1)} \in \sR^{h^{(l-1)}}$ 131 | & (Hidden) features fed into layer $l$ (output of layer $l-1$) 132 | \\ 133 | $\vx := \vz^{(0)}, \vf := \vz^{(L)}$ 134 | & Input to the neural network, and its prediction for input $\vx$ 135 | \\ 136 | $f^{(l)}_{\vtheta^{(l)}}$ 137 | & Layer $l$ parameterized by $\vtheta^{(l)}$, mapping input 138 | $\vz^{(l-1)}$ to output $\vz^{(l)}$ 139 | \\ 140 | $f_{\vtheta}:= f^{(L)}_{\vtheta^{(L)}} \circ \ldots \circ f^{(1)}_{\vtheta^{(1)}}$ 141 | & Sequential feedforward neural network parameterized by $\vtheta$, maps input $\vx$ to output $\vf$ 142 | \\ 143 | $\vtheta$ 144 | & Parameter vector, concatenation of parameters over layers 145 | $\vtheta := (\vtheta^{(1)\top}, \dots, \vtheta^{(L)\top})^\top$ 146 | \\ 147 | \end{longtable} 148 | 149 | \section*{Derivatives} 150 | 151 | $\grad{},\jac$ and $\gradsquared{}$ denote the gradient, Jacobian, and Hessian, 152 | respectively. 153 | 154 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 155 | $\jac_{\va}\vb$ & Jacobian matrix of a vector $\vb$ \wrt a vector $\va$, 156 | $[\jac_{\va}\vb]_{i,j} = \nicefrac{\partial [\vb]_i}{\partial [\va]_j}$ 157 | \\ 158 | $\jac_{\tA}\tB$ & Generalized Jacobian matrix for tensor variables, 159 | $[\jac_{\tA}\tB]_{i,j} = \nicefrac{\partial[\vec{\tB}]_i}{\partial 160 | [\vec{\tA}]_j}$ 161 | \\ 162 | $\grad{\va} b := (\jac_{\va}b)^{\top}$ & Gradient vector of a scalar $b$ \wrt 163 | a vector $\va$, $[\grad{\va} b]_{i} = \nicefrac{\partial b}{\partial a_{i}}$ 164 | \\ 165 | $\gradsquared{\va} b$ & Hessian matrix of a scalar $b$ \wrt a vector $\va$, 166 | $[\gradsquared{\va} b]_{i,j} = \nicefrac{\partial^2 b}{\partial [\va]_i 167 | \partial [\va]_j}$ (symmetric) 168 | \\ 169 | $\gradsquared{\va} \vb$, $\gradsquared{\tA} \tB$ & Generalized Hessian matrix 170 | (in general not quadratic, hence not symmetric) of a vector $\vb$ \wrt a 171 | vector $\va$, or more general tensor variables 172 | \\ 173 | $\vg_{n}(\vtheta):= \grad{\vtheta} \ell_{n}(\vtheta)$ & Gradient of the loss 174 | implied by sample $n$ 175 | \\ 176 | $\vg_{\sD}(\vtheta):= \grad{\vtheta} \gL_{\sD}(\vtheta)$ & Gradient of the 177 | empirical risk implied by a dataset $\sD$ 178 | \\ 179 | $\vg_{\sB}(\vtheta):= \grad{\vtheta} \gL_{\sB}(\vtheta)$ & Mini-batch gradient 180 | \\ 181 | $\mH_{n}(\vtheta):= \gradsquared{\vtheta} \ell_{n}(\vtheta)$ & Hessian of the 182 | loss implied by sample $n$ 183 | \\ 184 | $\mH_{\sD}(\vtheta):= \gradsquared{\vtheta} \gL_{\sD}(\vtheta)$ & Hessian of 185 | the empirical risk implied by a dataset $\sD$ 186 | \\ 187 | $\mH_{\sB}(\vtheta):= \gradsquared{\vtheta} \gL_{\sB}(\vtheta)$ & Mini-batch 188 | Hessian 189 | \\ 190 | $\mH^{(l)}(\vtheta^{(l)})$ or $\mH(\vtheta^{(l)})$ & The block in the Hessian 191 | corresponding to layer $l$ 192 | \\ 193 | $\mG_{\sD}(\vtheta)$ & Generalized Gauss-Newton matrix on a dataset $\sD$ 194 | \\ 195 | $\mG^{(l)}(\vtheta^{(l)})$ or $\mG(\vtheta^{(l)})$ & The block in the 196 | generalized Gauss-Newton matrix corresponding to layer $l$ 197 | \end{longtable} 198 | 199 | \section*{Statistics} 200 | 201 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 202 | $\gU(\{1, \dots, N\})$ & Uniform distribution over $\{ 1, \dots, N\}$ 203 | \\ 204 | $\gN(\giventhat{x}{\mu, \sigma^2})$ & Uni-variate normal/Gaussian distribution 205 | of random variable $x$, with mean $\mu$, positive variance $\sigma^2$, and 206 | density $\gN(\giventhat{x}{\mu, \sigma^2}) = \nicefrac{1}{\sigma \sqrt{2\pi}} 207 | \exp[- \nicefrac{1}{2} ( \nicefrac{(x - \mu)}{\sigma} )^2 ]$ 208 | \\ 209 | $\gN(\giventhat{\vx}{\vmu, \mSigma})$ & Multi-variate normal/Gaussian 210 | distribution of random vector $\vx$ with mean vector $\vmu$, PSD covariance 211 | matrix $\mSigma$, and density $\gN(\giventhat{\vx}{\vmu, \mSigma}) = 212 | \nicefrac{1}{( \sqrt{2\pi \det \mSigma})} \exp[- \nicefrac{1}{2} (\vx - 213 | \vmu)^{\top}\mSigma^{-1}(\vx - \vmu) ] $ 214 | \\ 215 | $\Cat(\giventhat{c}{\vp})$ & Multinomial/Categorical distribution with 216 | probabilities $\vp$ for categories $c$ 217 | \end{longtable} 218 | 219 | \section*{Miscellaneous} 220 | 221 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 222 | $\log$ & The natural logarithm (base $\mathrm{e}$, \ie $\log(\mathrm{e}) = 1$) 223 | \\ 224 | $\onehot(c)$ & One-hot vector of class $c$ with 225 | $\onehot(c) = \delta_{i,c}$ 226 | \\ 227 | $\softmax(\va)$ & Softmax probabilities of the logits $\va$, 228 | $[\softmax(\va)]_c = \nicefrac{\exp(\eva_{c})}{\sum_{i=1} \exp(\eva_{i})}\,.$ 229 | \\ 230 | $\delta_{i,j}$, $\delta(\vx - \va)$ & Kronecker delta ($\delta_{i,i} = 1$ and $\delta_{i,j\neq i} = 231 | 0$), Dirac delta distribution 232 | \\ 233 | $(\sX \to \sY)$ & Signature of a function that maps between $\sX$ and $\sY$ 234 | \\ 235 | $\{ \vx_n \}$ or $\{\vx_n\}_n$ & A set/collection of vectors $\vx_1, \vx_2, \dots$ over the 236 | index set implied by $n$ 237 | % \\ 238 | % $\mathrm{id}$ & Identity operation 239 | \\ 240 | $\vehat_i$ 241 | & 242 | Unit vector in direction $i$, \ie $\vehat_{i} = \onehot(i)$ 243 | \\ 244 | $\vone_{m}$ 245 | & 246 | An $m$-dimensional vector containing ones everywhere 247 | \\ 248 | $\log(\va), \exp(\va)$ 249 | & 250 | Elementwise natural logarithm and exponential function of a vector 251 | \\ 252 | $m_{\vtheta_t}(\vtheta)$ 253 | & 254 | Local approximation of the loss in around $\vtheta_t$ 255 | \\ 256 | \end{longtable} 257 | 258 | \section*{Acronyms \& Abbreviations} 259 | 260 | \begin{longtable}{p{.2\linewidth}p{.8\linewidth}} 261 | \Eg or \eg & For example (\emph{exempli gratia}) 262 | \\ 263 | \Etc or \etc & And so on (\emph{et cetera}) 264 | \\ 265 | \Ie or \ie & That is (\emph{id est}) 266 | \\ 267 | \Iid or \iid & Independent and identically distributed 268 | \\ 269 | \Wrt or \wrt & With respect to 270 | \\ 271 | AD & Automatic differentiation 272 | \\ 273 | API & Application Programming Interface 274 | \\ 275 | BDA & Block diagonal approximation 276 | \\ 277 | CG & Conjugate gradients 278 | \\ 279 | CNN & Convolutional neural network 280 | \\ 281 | CPU & Central processing unit 282 | \\ 283 | DNN & Deep neural network 284 | \\ 285 | DP & Differential privacy 286 | \\ 287 | FCNN & Fully-connected neural network 288 | \\ 289 | GGN & Generalized Gauss-Newton (matrix) 290 | \\ 291 | GN & Gauss-Newton (matrix) 292 | \\ 293 | GPU & Graphics processing unit 294 | \\ 295 | HBP & Hessian backpropagation 296 | \\ 297 | JMP & Jacobian-matrix product 298 | \\ 299 | JVP & Jacobian-vector product 300 | \\ 301 | KFAC & Kronecker-factored curvature 302 | \\ 303 | KFC & Kronecker factors for convolution 304 | \\ 305 | KFLR & Kronecker-factored low rank 306 | \\ 307 | KFRA & Kronecker-factored recursive approximation 308 | \\ 309 | MAP & Maximum a posteriori (estimation) 310 | \\ 311 | MC & Monte Carlo 312 | \\ 313 | MJP & Matrix-Jacobian product 314 | \\ 315 | ML & Machine learning 316 | \\ 317 | MLE & Maximum likelihood estimation 318 | \\ 319 | MLP & Multi-layer perceptron 320 | \\ 321 | NGD & Natural gradient descent 322 | \\ 323 | PCH & Positive-curvature Hessian 324 | \\ 325 | PD & Positive definite 326 | \\ 327 | PSD & Positive semi-definite 328 | \\ 329 | ResNet & Residual (neural) network 330 | \\ 331 | SNR & Signal-to-noise ratio 332 | \\ 333 | TPU & Tensor processing unit 334 | \\ 335 | VJP & Vector-Jacobian product 336 | \end{longtable} 337 | 338 | %%% Local Variables: 339 | %%% mode: latex 340 | %%% TeX-master: "../thesis" 341 | %%% End: 342 | -------------------------------------------------------------------------------- /preamble/kaotheorems.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{preamble/kaotheorems} 2 | 3 | %---------------------------------------------------------------------------------------- 4 | % PACKAGE OPTIONS AND DEPENDENCIES 5 | %---------------------------------------------------------------------------------------- 6 | 7 | \RequirePackage{kvoptions} % Handle package options 8 | \SetupKeyvalOptions{ 9 | family = kaotheorems, 10 | prefix = kaotheorems@ 11 | } 12 | 13 | \DeclareBoolOption{framed}% If true, put theorems into colorful boxes, otherwise write them like normal text 14 | 15 | % Define the options to finely tune the background color of each element. 16 | % If only the 'background' option is specified, all types of theorem will have that background. If more specific options are set, the previous option will be overwritten. 17 | \newcommand{\kaotheorems@defaultbg}{Goldenrod!45!white} 18 | \DeclareStringOption[\kaotheorems@defaultbg]{background} 19 | \DeclareStringOption[\kaotheorems@defaultbg]{theorembackground} 20 | \DeclareStringOption[\kaotheorems@defaultbg]{propositionbackground} 21 | \DeclareStringOption[\kaotheorems@defaultbg]{lemmabackground} 22 | \DeclareStringOption[\kaotheorems@defaultbg]{corollarybackground} 23 | \DeclareStringOption[\kaotheorems@defaultbg]{definitionbackground} 24 | \DeclareStringOption[\kaotheorems@defaultbg]{assumptionbackground} 25 | \DeclareStringOption[\kaotheorems@defaultbg]{remarkbackground} 26 | \DeclareStringOption[\kaotheorems@defaultbg]{examplebackground} 27 | \DeclareStringOption[\kaotheorems@defaultbg]{exercisebackground} 28 | 29 | \ProcessKeyvalOptions{kaotheorems} % Process the options 30 | 31 | \let\openbox\relax % Workaround to avoid a nasty error 32 | \RequirePackage{amsmath} % Improved mathematics 33 | \RequirePackage{amsthm} % Mathematical environments 34 | \RequirePackage{thmtools} % Theorem styles 35 | 36 | %---------------------------------------------------------------------------------------- 37 | % STYLE DEFINITIONS 38 | %---------------------------------------------------------------------------------------- 39 | 40 | \ifkaotheorems@framed% Define the style of the mdframed boxes for theorems 41 | \RequirePackage{tikz} % Required by mdframed 42 | \RequirePackage[framemethod=TikZ]{mdframed} % Required for colorful boxes 43 | 44 | % Box style 45 | \mdfsetup{skipabove=\topskip,skipbelow=0pt}%{-.5\topskip} 46 | \mdfdefinestyle{mdfkao}{ 47 | skipabove=\topskip, 48 | skipbelow=\topskip, % Does not work :( 49 | rightmargin=0pt, 50 | leftmargin=0pt, 51 | innertopmargin=7pt, 52 | innerbottommargin=5pt, 53 | innerrightmargin=5pt, 54 | innerleftmargin=5pt, 55 | topline=true, 56 | bottomline=true, 57 | rightline=true, 58 | leftline=true, 59 | linewidth=1pt, 60 | linecolor=maincolor, 61 | roundcorner=5pt, 62 | font={\color{maincolor}}, 63 | backgroundcolor=maincolor!5!white, 64 | frametitlerule=true, 65 | } 66 | 67 | % Theorem styles 68 | \declaretheoremstyle[ 69 | %spaceabove=.5\thm@preskip, 70 | %spacebelow=.5\thm@postskip, 71 | %headfont=\normalfont\bfseries,%\scshape, 72 | %notefont=\normalfont, notebraces={ (}{)}, 73 | bodyfont=\normalfont,%\itshape, 74 | %headformat={\NAME\space\NUMBER\space\NOTE}, 75 | headpunct={}, 76 | %postheadspace={.5em plus .1em minus .1em}, 77 | %prefoothook={\hfill\qedsymbol} 78 | ]{kaoplain} 79 | \declaretheoremstyle[ 80 | %spaceabove=.5\thm@preskip, 81 | %spacebelow=.5\thm@postskip, 82 | %headfont=\normalfont\bfseries,%\scshape, 83 | %notefont=\normalfont, notebraces={ (}{)}, 84 | bodyfont=\normalfont,%\itshape, 85 | %headformat={\NAME\space\NUMBER\space\NOTE}, 86 | headpunct={}, 87 | postheadspace={.5em plus .1em minus .1em}, 88 | %prefoothook={\hfill\qedsymbol} 89 | ]{kaodefinition} 90 | \declaretheoremstyle[ 91 | %spaceabove=.5\thm@preskip, 92 | %spacebelow=.5\thm@postskip, 93 | %headfont=\normalfont\bfseries,%\scshape, 94 | %notefont=\normalfont, notebraces={ (}{)}, 95 | bodyfont=\normalfont,%\itshape, 96 | %headformat={\NAME\space\NUMBER\space\NOTE}, 97 | headpunct={}, 98 | postheadspace={.5em plus .1em minus .1em}, 99 | %prefoothook={\hfill\qedsymbol} 100 | ]{kaoassumption} 101 | \declaretheoremstyle[ 102 | %spaceabove=.5\thm@preskip, 103 | %spacebelow=.5\thm@postskip, 104 | %headfont=\normalfont\bfseries, 105 | %notefont=\normalfont, notebraces={ (}{)}, 106 | %bodyfont=\normalfont, 107 | %headformat={\footnotesize$\triangleright$\space\normalsize\NAME\space\NUMBER\space\NOTE}, 108 | %headformat={\NAME\space\NUMBER\space\NOTE}, 109 | headpunct={}, 110 | postheadspace={.5em plus .1em minus .1em}, 111 | %refname={theorem,theorems}, 112 | %Refname={Theorem,Theorems}, 113 | ]{kaoremark} 114 | \declaretheoremstyle[ 115 | %spaceabove=.5\thm@preskip, 116 | %spacebelow=.5\thm@postskip, 117 | %headfont=\normalfont\bfseries, 118 | %notefont=\normalfont, notebraces={ (}{)}, 119 | %bodyfont=\normalfont, 120 | %headformat={\NAME\space\NUMBER\space\NOTE}, 121 | headpunct={}, 122 | postheadspace={.5em plus .1em minus .1em}, 123 | %prefoothook={\hfill\qedsymbol} 124 | %refname={theorem,theorems}, 125 | %Refname={Theorem,Theorems}, 126 | ]{kaoexample} 127 | \declaretheoremstyle[ 128 | %spaceabove=.5\thm@preskip, 129 | %spacebelow=.5\thm@postskip, 130 | %headfont=\normalfont\bfseries, 131 | %notefont=\normalfont, notebraces={ (}{)}, 132 | %bodyfont=\small, 133 | %headformat={\NAME\space\NUMBER\space\NOTE}, 134 | headpunct={}, 135 | postheadspace={.5em plus .1em minus .1em}, 136 | %prefoothook={\hfill\qedsymbol} 137 | %refname={theorem,theorems}, 138 | %Refname={Theorem,Theorems}, 139 | ]{kaoexercise} 140 | 141 | % Theorems using the 'kaoplain' style 142 | \theoremstyle{kaoplain} 143 | \declaretheorem[ 144 | name=Theorem, 145 | style=kaoplain, 146 | refname={theorem,theorems}, 147 | Refname={Theorem,Theorems}, 148 | numberwithin=chapter, 149 | mdframed={ 150 | style=mdfkao, 151 | }, 152 | ]{theorem} 153 | \declaretheorem[ 154 | name=Proposition, 155 | %refname={proposition,propositions}, 156 | refname={Proposition,Propositions}, 157 | Refname={Proposition,Propositions}, 158 | sibling=theorem, 159 | mdframed={ 160 | style=mdfkao, 161 | backgroundcolor=\kaotheorems@propositionbackground, 162 | %frametitlebackgroundcolor=\@theorembackground, 163 | }, 164 | ]{proposition} 165 | \declaretheorem[ 166 | name=Lemma, 167 | %refname={lemma,lemmas}, 168 | refname={Lemma,Lemmas}, 169 | Refname={Lemma,Lemmas}, 170 | sibling=theorem, 171 | mdframed={ 172 | style=mdfkao, 173 | backgroundcolor=\kaotheorems@lemmabackground, 174 | %frametitlebackgroundcolor=\@theorembackground, 175 | }, 176 | ]{lemma} 177 | \declaretheorem[ 178 | name=Corollary, 179 | %refname={corollary,corollaries}, 180 | refname={Corollary,Corollaries}, 181 | Refname={Corollary,Corollaries}, 182 | sibling=theorem, 183 | mdframed={ 184 | style=mdfkao, 185 | backgroundcolor=\kaotheorems@corollarybackground, 186 | %frametitlebackgroundcolor=\@theorembackground, 187 | }, 188 | ]{corollary} 189 | 190 | % Theorems using the 'kaodefinition' style 191 | \theoremstyle{kaodefinition} 192 | \declaretheorem[ 193 | name=Definition, 194 | %refname={definition,definitions}, 195 | refname={Definition,Definitions}, 196 | Refname={Definition,Definitions}, 197 | numberwithin=chapter, 198 | mdframed={ 199 | style=mdfkao, 200 | }, 201 | ]{definition} 202 | 203 | % Theorems using the 'kaoassumption' style 204 | \theoremstyle{kaoassumption} 205 | \declaretheorem[ 206 | name=Assumption, 207 | %refname={assumption,assumptions}, 208 | refname={Assumption,Assumptions}, 209 | Refname={Assumption,Assumptions}, 210 | numberwithin=chapter, 211 | mdframed={ 212 | style=mdfkao, 213 | backgroundcolor=\kaotheorems@assumptionbackground, 214 | %frametitlebackgroundcolor=\@theorembackground, 215 | }, 216 | ]{assumption} 217 | 218 | % Theorems using the 'kaoremark' style 219 | \theoremstyle{kaoremark} 220 | \declaretheorem[ 221 | name=Remark, 222 | %refname={remark,remarks}, 223 | refname={remark,remarks}, 224 | Refname={Remark,Remarks}, 225 | numberwithin=chapter, 226 | mdframed={ 227 | style=mdfkao, 228 | }, 229 | ]{remark} 230 | 231 | \theoremstyle{kaoremark} 232 | \declaretheorem[ 233 | name=Disclaimer, 234 | refname={disclaimer,disclaimers}, 235 | Refname={Disclaimer,Disclaimers}, 236 | numberwithin=chapter, 237 | mdframed={ 238 | style=mdfkao, 239 | }, 240 | ]{disclaimer} 241 | 242 | % Theorems using the 'kaoexample' style 243 | \theoremstyle{kaoexample} 244 | \declaretheorem[ 245 | name=Example, 246 | %refname={example,examples}, 247 | refname={Example,Examples}, 248 | Refname={Example,Examples}, 249 | numberwithin=chapter, 250 | mdframed={ 251 | style=mdfkao, 252 | }, 253 | ]{example} 254 | 255 | % Theorems using the 'kaoexample' style 256 | \theoremstyle{kaoexample} 257 | \declaretheorem[ 258 | name=Update Rule, 259 | refname={update rule,update rules}, 260 | Refname={Update Rule,Update Rules}, 261 | numberwithin=chapter, 262 | mdframed={ 263 | style=mdfkao, 264 | }, 265 | ]{updaterule} 266 | 267 | % Theorems using the 'kaoexercise' style 268 | \theoremstyle{kaoexercise} 269 | \declaretheorem[ 270 | name=Exercise, 271 | %refname={example,examples}, 272 | refname={Exercise,Exercises}, 273 | Refname={Exercise,Exercises}, 274 | numberwithin=chapter, 275 | mdframed={ 276 | style=mdfkao, 277 | backgroundcolor=\kaotheorems@exercisebackground, 278 | %frametitlebackgroundcolor=\@theorembackground, 279 | }, 280 | ]{exercise} 281 | 282 | %\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{section}.\arabic{theorem}} 283 | %\renewcommand{\thetheorem}{\arabic{subsection}.\arabic{theorem}} 284 | %\renewcommand{\qedsymbol}{$\blacksquare$} 285 | \else % If not using mdframed 286 | % Theorem styles 287 | \declaretheoremstyle[ 288 | spaceabove=.6\thm@preskip, 289 | spacebelow=.1\thm@postskip, 290 | %headfont=\normalfont\bfseries,%\scshape, 291 | %notefont=\normalfont, notebraces={ (}{)}, 292 | bodyfont=\normalfont,%\itshape, 293 | %headformat={\NAME\space\NUMBER\space\NOTE}, 294 | headpunct={}, 295 | %postheadspace={.5em plus .1em minus .1em}, 296 | %prefoothook={\hfill\qedsymbol} 297 | ]{kaoplain} 298 | \declaretheoremstyle[ 299 | spaceabove=.6\thm@preskip, 300 | spacebelow=.1\thm@postskip, 301 | %headfont=\normalfont\bfseries,%\scshape, 302 | %notefont=\normalfont, notebraces={ (}{)}, 303 | bodyfont=\normalfont,%\itshape, 304 | %headformat={\NAME\space\NUMBER\space\NOTE}, 305 | headpunct={}, 306 | %postheadspace={.5em plus .1em minus .1em}, 307 | %prefoothook={\hfill\qedsymbol} 308 | ]{kaodefinition} 309 | \declaretheoremstyle[ 310 | spaceabove=.6\thm@preskip, 311 | spacebelow=.1\thm@postskip, 312 | %headfont=\normalfont\bfseries, 313 | %notefont=\normalfont, notebraces={ (}{)}, 314 | %bodyfont=\normalfont, 315 | %headformat={\footnotesize$\triangleright$\space\normalsize\NAME\space\NUMBER\space\NOTE}, 316 | %headformat={\NAME\space\NUMBER\space\NOTE}, 317 | headpunct={}, 318 | %postheadspace={.5em plus .1em minus .1em}, 319 | %refname={theorem,theorems}, 320 | %Refname={Theorem,Theorems}, 321 | ]{kaoremark} 322 | \declaretheoremstyle[ 323 | spaceabove=.6\thm@preskip, 324 | spacebelow=.1\thm@postskip, 325 | %headfont=\normalfont\bfseries, 326 | %notefont=\normalfont, notebraces={ (}{)}, 327 | %bodyfont=\normalfont, 328 | %headformat={\NAME\space\NUMBER\space\NOTE}, 329 | headpunct={}, 330 | %postheadspace={.5em plus .1em minus .1em}, 331 | %prefoothook={\hfill\qedsymbol} 332 | %refname={theorem,theorems}, 333 | %Refname={Theorem,Theorems}, 334 | ]{kaoexample} 335 | \declaretheoremstyle[ 336 | %spaceabove=.5\thm@preskip, 337 | %spacebelow=.5\thm@postskip, 338 | %headfont=\normalfont\bfseries, 339 | %notefont=\normalfont, notebraces={ (}{)}, 340 | %bodyfont=\normalfont, 341 | %headformat={\NAME\space\NUMBER\space\NOTE}, 342 | headpunct={}, 343 | postheadspace={.5em plus .1em minus .1em}, 344 | %prefoothook={\hfill\qedsymbol} 345 | %refname={theorem,theorems}, 346 | %Refname={Theorem,Theorems}, 347 | ]{kaoexercise} 348 | 349 | % Theorems using the 'kaoplain' style 350 | \theoremstyle{kaoplain} 351 | \declaretheorem[ 352 | name=Theorem, 353 | refname={theorem,theorems}, 354 | Refname={Theorem,Theorems}, 355 | numberwithin=chapter, 356 | ]{theorem} 357 | \declaretheorem[ 358 | name=Proposition, 359 | refname={proposition,propositions}, 360 | Refname={Proposition,Propositions}, 361 | sibling=theorem, 362 | ]{proposition} 363 | \declaretheorem[ 364 | name=Lemma, 365 | refname={lemma,lemmas}, 366 | Refname={Lemma,Lemmas}, 367 | sibling=theorem, 368 | ]{lemma} 369 | \declaretheorem[ 370 | name=Corollary, 371 | refname={corollary,corollaries}, 372 | Refname={Corollary,Corollaries}, 373 | sibling=theorem, 374 | ]{corollary} 375 | 376 | % Theorems using the 'kaodefinition' style 377 | \theoremstyle{kaodefinition} 378 | \declaretheorem[ 379 | name=Definition, 380 | refname={definition,definitions}, 381 | Refname={Definition,Definitions}, 382 | numberwithin=chapter, 383 | ]{definition} 384 | 385 | % Theorems using the 'kaoremark' style 386 | \theoremstyle{kaoremark} 387 | \declaretheorem[ 388 | name=Remark, 389 | refname={remark,remarks}, 390 | Refname={Remark,Remarks}, 391 | numberwithin=chapter, 392 | ]{remark} 393 | 394 | % Theorems using the 'kaoexample' style 395 | \theoremstyle{kaoexample} 396 | \declaretheorem[ 397 | name=Example, 398 | refname={example,examples}, 399 | Refname={Example,Examples}, 400 | numberwithin=chapter, 401 | ]{example} 402 | 403 | % Theorems using the 'kaoexercise' style 404 | \theoremstyle{kaoexercise} 405 | \declaretheorem[ 406 | name=Exercise, 407 | %refname={example,examples}, 408 | refname={Exercise,Exercises}, 409 | Refname={Exercise,Exercises}, 410 | numberwithin=chapter, 411 | mdframed={ 412 | style=mdfkao, 413 | backgroundcolor=\@exercisebackground, 414 | %frametitlebackgroundcolor=\@theorembackground, 415 | }, 416 | ]{exercise} 417 | 418 | %\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{section}.\arabic{theorem}} 419 | %\renewcommand{\thetheorem}{\arabic{subsection}.\arabic{theorem}} 420 | %\renewcommand{\qedsymbol}{$\blacksquare$} 421 | \fi 422 | -------------------------------------------------------------------------------- /preamble/commands.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % MATH 3 | % =================================================================== 4 | \newcommand{\verylongrightarrow}{\xrightarrow{\hspace*{1.5cm}}} 5 | \newcommand{\explainmath}[1]{\ensuremath{&&{\footnotesize\text{#1}}}} % Only works in align environments 6 | 7 | % punctuation of equations, see for example the first answer in 8 | % https://www.reddit.com/r/LaTeX/comments/5xnzg7/correct_grammar_for_putting_an_equation/ 9 | \newcommand{\equationPunctuation}[1]{\,{#1}} 10 | 11 | % =================================================================== 12 | % REFERENCES 13 | % =================================================================== 14 | \makeatletter 15 | % TODO Allow arbitrary number of arguments in \subfigref 16 | % https://davidyat.es/2016/07/27/writing-a-latex-macro-that-takes-a-variable-number-of-arguments/ 17 | % \newcommand{\subfigref}[1]{\textbf{(\subref{#1}\subfigrefchecknextarg)}} 18 | % \newcommand{\subfigrefchecknextarg}{\@ifnextchar\bgroup{\subfigrefgobblenextarg}{}} 19 | % \newcommand{\subfigrefgobblenextarg}[1]{, \subref{#1}\@ifnextchar\bgroup{\subfigrefgobblenextarg}{}} 20 | 21 | \newcommand{\subfigref}[1]{\textbf{(\subref{#1})}} 22 | 23 | % =================================================================== 24 | % COMMON ABBREVIATONS 25 | 26 | \newcommand{\PhD}{Ph.D.\@\xspace} 27 | \newcommand*{\citeeg}{\textit{e.\nobreak\hairsp{}g.},} % Special \eg command used in citations (doesn't result in weird space) 28 | %\newcommand*{\ie}{i.e.\@\xspace} 29 | \newcommand*{\cf}{cf.\@\xspace} 30 | %\newcommand*{\etal}{et. al.\@\xspace} 31 | %\makeatletter\newcommand*{\etc}{% 32 | % \@ifnextchar{.}% 33 | % {etc}% 34 | % {etc.\@\xspace}% 35 | %} 36 | \makeatother 37 | 38 | \newcommand{\hl}[1]{\textbf{#1}} % Highlight something. Alternative to \emph 39 | 40 | \usepackage[super]{nth} % For things like 2nd, 3rd, etc. 41 | 42 | % =================================================================== 43 | % SHORTHAND 44 | 45 | \newcommand{\ai}{artificial intelligence\xspace} 46 | \newcommand{\AI}{Artificial intelligence\xspace} 47 | \newcommand{\ml}{machine learning\xspace} 48 | \newcommand{\ML}{Machine learning\xspace} 49 | \newcommand{\MLabbr}{ML\xspace} 50 | \newcommand{\dl}{deep learning\xspace} 51 | \newcommand{\DL}{Deep learning\xspace} 52 | \newcommand{\DLabbr}{DL\xspace} 53 | \newcommand{\dataset}{data set\xspace} 54 | \newcommand{\datasets}{data sets\xspace} 55 | \newcommand{\runtime}{runtime\xspace} 56 | \newcommand{\mvp}{matrix-vector product\xspace} 57 | \newcommand{\mvps}{matrix-vector products\xspace} 58 | \newcommand{\earlystopping}{early stopping\xspace} 59 | \newcommand{\Earlystopping}{Early stopping\xspace} 60 | 61 | 62 | % =================================================================== 63 | % COLORED ITEMS 64 | 65 | % Coloured dots 66 | \DeclareRobustCommand{\colordot}[1]{% 67 | \begin{tikzpicture}[baseline=(a.south)] 68 | \node[circle, scale=0.75,color=white, fill=#1] (a) {}; 69 | \end{tikzpicture}% 70 | } 71 | 72 | % Coloured square 73 | \DeclareRobustCommand{\colorsquare}[1]{% 74 | \begin{tikzpicture}[baseline=(a.south)] 75 | \node[rectangle, scale=0.9,color=white, fill=#1] (a) {}; 76 | \end{tikzpicture}% 77 | } 78 | 79 | % Coloured line 80 | \DeclareRobustCommand{\colorline}[1]{% 81 | \begin{tikzpicture} 82 | \raisebox{1.5pt}{ 83 | \draw[#1,solid,line width=1.5pt] (0,0) -- (1em,0); 84 | } 85 | \end{tikzpicture}% 86 | } 87 | 88 | % Coloured arrow 89 | \DeclareRobustCommand{\colorarrow}[1]{% 90 | \begin{tikzpicture} 91 | \raisebox{2.5pt}{ 92 | \draw[#1, thick, -stealth] (0,0) -- (1em,0); 93 | } 94 | \end{tikzpicture}% 95 | } 96 | 97 | % Coloured shade 98 | \newcommand{\colorshade}[1]{\textcolor{#1}{\ding{122}}} 99 | 100 | 101 | % =================================================================== 102 | % NUMBERS 103 | 104 | \newcommand{\nopts}{$15$\xspace} % Number of benchmarked optimizer 105 | \newcommand{\noptstext}{fifteen\xspace} % -"- in words 106 | \newcommand{\nruns}{\mbox{$53$,$760$}\xspace} % Number of total benchmark runs 107 | \newcommand{\nrunsapprox}{\mbox{$50$,$000$}\xspace} % Rounded number of total benchmark runs 108 | \newcommand{\nrunsapproxbold}{\mbox{$\mathbf{50}$,$\mathbf{000}$}\xspace} % -"- + bold (for titles) 109 | \newcommand{\nconfigs}{\mbox{$1$,$920$}\xspace} % Number of benchmarked configurations 110 | \newcommand{\ntests}{\mbox{$128$}\xspace} % Number of benchmarked test per optimizer 111 | \newcommand{\nreruns}{\mbox{ten}\xspace} % Number of re-runs with different seeds. 112 | 113 | 114 | % =================================================================== 115 | % PACKAGES 116 | 117 | % Personal Packages 118 | \newcommand{\cockpit}{Cockpit\xspace} 119 | \newcommand{\deepobs}{DeepOBS\xspace} 120 | \newcommand{\DeepOBS}{\deepobs} 121 | % title versions 122 | \newcommand{\cockpittitle}{Cockpit\xspace} 123 | \newcommand{\deepobstitle}{DeepOBS\xspace} 124 | 125 | % Group Packages 126 | \newcommand{\backpack}{BackPACK\xspace} 127 | \newcommand{\BackPACK}{\backpack} 128 | \newcommand{\backpacktitle}{BackPACK\xspace} 129 | \newcommand{\vivit}{ViViT\xspace} 130 | \newcommand{\bfvivit}{\textbf{ViViT}\xspace} 131 | \newcommand{\vivittitle}{ViViT\xspace} % Special command for the title 132 | 133 | % General Tools & Packages 134 | \newcommand{\python}{Python\xspace} 135 | \newcommand{\matplotlib}{matplotlib\xspace} 136 | \newcommand{\numpy}{NumPy\xspace} 137 | \newcommand{\pytorch}{PyTorch\xspace} 138 | \newcommand{\PyTorch}{\pytorch} 139 | \newcommand{\pytorchtitle}{PyTorch\xspace} 140 | \newcommand{\pyhessian}{PyHessian\xspace} 141 | \newcommand{\taskset}{TaskSet\xspace} 142 | \newcommand{\tensorboard}{TensorBoard\xspace} 143 | \newcommand{\tensorflowdataset}{TensorFlow Datasets\xspace} 144 | \newcommand{\tensorflow}{TensorFlow\xspace} 145 | \newcommand{\TensorFlow}{\tensorflow} 146 | \newcommand{\jax}{JAX\xspace} 147 | \newcommand{\torchvision}{torchvision\xspace} 148 | \newcommand{\wandb}{Weights \& Biases\xspace} 149 | \newcommand{\pgfplots}{pgfplots\xspace} 150 | \newcommand{\caffe}{Caffe\xspace} 151 | \newcommand{\chainer}{Chainer\xspace} 152 | \newcommand{\Chainer}{\chainer} 153 | \newcommand{\MXNet}{\textsc{MXNet}\xspace} 154 | \newcommand{\theano}{Theano\xspace} 155 | \newcommand{\lasagne}{Lasagne\xspace} 156 | \newcommand{\cuda}{CUDA\xspace} 157 | 158 | 159 | % =================================================================== 160 | % URLs 161 | 162 | \newcommand{\deepobsurl}{\url{https://github.com/fsschneider/deepobs}\xspace} 163 | \newcommand{\deepobsdocs}{\url{https://deepobs.readthedocs.io/}\xspace} 164 | \newcommand{\benchmarkurl}{\url{https://github.com/SirRob1997/Crowded-Valley---Results}\xspace} 165 | \newcommand{\cockpiturl}{\url{https://github.com/f-dangel/cockpit}\xspace} 166 | \newcommand{\cockpitexpurl}{\url{https://github.com/fsschneider/cockpit-experiments}\xspace} 167 | \newcommand{\cockpitdocurl}{\url{https://cockpit.readthedocs.io/en/latest/}\xspace} 168 | \newcommand{\viviturl}{\url{https://github.com/jbzrE7bp/vivit}\xspace} 169 | 170 | 171 | % =================================================================== 172 | % OPTIMIZERS 173 | 174 | \newcommand{\adabelief}{AdaBelief\xspace} 175 | \newcommand{\adabound}{AdaBound\xspace} 176 | \newcommand{\adadelta}{Adadelta\xspace} 177 | \newcommand{\adagrad}{AdaGrad\xspace} 178 | \newcommand{\adam}{Adam\xspace} 179 | \newcommand{\amsbound}{AMSBound\xspace} 180 | \newcommand{\amsgrad}{AMSGrad\xspace} 181 | \newcommand{\lamom}{LA(Mom.)\xspace} 182 | \newcommand{\laradam}{LA(RAdam)\xspace} 183 | \newcommand{\ranger}{Ranger\xspace} 184 | \newcommand{\lookaheadopt}{Lookahead\xspace} 185 | \newcommand{\momentum}{Momentum\xspace} 186 | \newcommand{\nadam}{Nadam\xspace} 187 | \newcommand{\nag}{NAG\xspace} 188 | \newcommand{\nagfull}{Nesterov Accelerated Gradient\xspace} 189 | \newcommand{\otheropt}{Other\xspace} 190 | \newcommand{\radam}{RAdam\xspace} 191 | \newcommand{\rmsprop}{RMSProp\xspace} 192 | \newcommand{\sgd}{SGD\xspace} 193 | \newcommand{\SGD}{\sgd} 194 | \newcommand{\sgdfull}{Stochastic Gradient Descent\xspace} 195 | 196 | \newcommand{\gd}{GD\xspace} 197 | \newcommand{\gdfull}{Gradient Descent\xspace} 198 | \newcommand{\newtonsmethod}{Newton's method\xspace} 199 | 200 | \newcommand{\lars}{LARS\xspace} 201 | \newcommand{\lamb}{LAMB\xspace} 202 | \newcommand{\adamw}{AdamW\xspace} 203 | 204 | \newcommand{\cg}{CG\xspace} 205 | \newcommand{\cgfull}{conjugate gradient\xspace} 206 | 207 | \newcommand{\ggn}{GGN\xspace} 208 | \newcommand{\GGN}{\ggn} 209 | \newcommand{\ggnfull}{generalized Gauss-Newton\xspace} 210 | 211 | \newcommand{\lbfgs}{L-BFGS\xspace} 212 | \newcommand{\kbfgs}{K-BFGS\xspace} 213 | \newcommand{\kfac}{K-FAC\xspace} 214 | \newcommand{\kfra}{KFRA\xspace} 215 | \newcommand{\shampoo}{Shampoo\xspace} 216 | \newcommand{\adahessian}{ADAHESSIAN\xspace} 217 | 218 | \newcommand{\sam}{SAM\xspace} 219 | \newcommand{\samfull}{Sharpness-Aware Minimization\xspace} 220 | \newcommand{\entropysgd}{Entropy-SGD\xspace} 221 | 222 | 223 | % =================================================================== 224 | % DATA SETS 225 | 226 | \newcommand{\fmnist}{Fashion-MNIST\xspace} 227 | \newcommand{\fmnistshort}{F-MNIST\xspace} 228 | \newcommand{\imagenet}{ImageNet\xspace} 229 | \newcommand{\mnist}{MNIST\xspace} 230 | \newcommand{\svhn}{SVHN\xspace} 231 | \newcommand{\tolstoi}{Tolstoi\xspace} 232 | \newcommand{\warandpeace}{War and Peace\xspace} 233 | \newcommand{\squad}{SQuAD\xspace} 234 | \newcommand{\wmt}{WMT 2016\xspace} 235 | \newcommand{\afhq}{AFHQ\xspace} 236 | \newcommand{\CIFAR}[1]{CIFAR-#1\xspace} 237 | \newcommand{\CIFARTEN}{\CIFAR{10}} 238 | \newcommand{\cifarten}{\CIFARTEN} 239 | \newcommand{\CIFARHUN}{\CIFAR{100}} 240 | \newcommand{\cifarhun}{\CIFAR{100}} 241 | \newcommand{\cifartenhun}{\CIFAR{10/100}} 242 | \newcommand{\MNIST}{\mnist} 243 | \newcommand{\FMNIST}{\fmnist} 244 | 245 | 246 | % =================================================================== 247 | % MODELS 248 | 249 | \newcommand{\MNISTNET}{LogReg\xspace} 250 | \newcommand{\allcnnc}{All-CNN-C\xspace} 251 | \newcommand{\ALLCNNC}{\allcnnc} 252 | \newcommand{\lstm}{LSTM\xspace} 253 | \newcommand{\LSTM}{\lstm} 254 | \newcommand{\gru}{GRU\xspace} 255 | \newcommand{\mlp}{MLP\xspace} 256 | \newcommand{\resnet}{ResNet\xspace} 257 | \newcommand{\resnetthirtytwo}{ResNet-32\xspace} 258 | \newcommand{\resnetfifty}{ResNet-50\xspace} 259 | \newcommand{\resnetfiftysix}{ResNet-56\xspace} 260 | \newcommand{\resnethundred}{ResNet-101\xspace} 261 | \newcommand{\resnethundredfifty}{ResNet-152\xspace} 262 | \newcommand{\wrn}{Wide ResNet 16-4\xspace} 263 | \newcommand{\threecthreed}{3c3d\xspace} 264 | \newcommand{\CIFARTENNET}{\threecthreed} 265 | \newcommand{\twoctwod}{2c2d\xspace} 266 | \newcommand{\FMNISTNET}{\twoctwod} 267 | \newcommand{\vggsixteen}{VGG16\xspace} 268 | \newcommand{\vgg}{\vggsixteen} 269 | \newcommand{\vggnineteen}{VGG19\xspace} 270 | \newcommand{\rnn}{RNN\xspace} 271 | \newcommand{\rnns}{RNNs\xspace} 272 | \newcommand{\rnnfull}{recurrent neural network\xspace} 273 | \newcommand{\rnnsfull}{recurrent neural networks\xspace} 274 | \newcommand{\Rnnsfull}{Recurrent neural networks\xspace} 275 | 276 | \newcommand{\cnn}{CNN\xspace} 277 | \newcommand{\cnns}{CNNs\xspace} 278 | \newcommand{\cnnsfull}{convolutional neural networks\xspace} 279 | \newcommand{\Cnnsfull}{Convolutional neural networks\xspace} 280 | 281 | \newcommand{\gptthree}{GPT-3\xspace} 282 | \newcommand{\bert}{BERT\xspace} 283 | \newcommand{\mobilenet}{MobileNet\xspace} 284 | 285 | \newcommand{\gan}{GAN\xspace} 286 | \newcommand{\gans}{GANs\xspace} 287 | \newcommand{\gansfull}{generative adversarial networks\xspace} 288 | 289 | \newcommand{\gnn}{GNN\xspace} 290 | \newcommand{\gnns}{GNNs\xspace} 291 | \newcommand{\gnnsfull}{graph neural networks\xspace} 292 | 293 | \newcommand{\transformer}{transformer\xspace} 294 | \newcommand{\transformers}{transformers\xspace} 295 | 296 | \newcommand{\vae}{VAE\xspace} 297 | \newcommand{\vaes}{VAEs\xspace} 298 | \newcommand{\vaesfull}{variational autoencoder\xspace} 299 | \newcommand{\Vaesfull}{Variational autoencoder\xspace} 300 | 301 | 302 | % =================================================================== 303 | % BACKPACK QUANTITIES 304 | 305 | \newcommand{\MC}{MC\xspace} 306 | \newcommand{\mc}{\MC} 307 | \newcommand{\DiagGGN}{DiagGGN\xspace} 308 | \newcommand{\DiagGGNMC}{DiagGGN-MC\xspace} 309 | \newcommand{\KFAC}{KFAC\xspace} 310 | \newcommand{\KFLR}{KFLR\xspace} 311 | \newcommand{\KFRA}{KFRA\xspace} 312 | 313 | % =================================================================== 314 | % QUANTITIES 315 | 316 | \newcommand{\qalpha}{\texttt{\mbox{Alpha}}\xspace} 317 | 318 | \newcommand{\qcabs}{\texttt{\mbox{CABS}}\xspace} 319 | \newcommand{\cabs}{\textsc{\mbox{CABS}}\xspace} 320 | 321 | \newcommand{\qearlystopping}{\texttt{\mbox{EarlyStopping}}\xspace} 322 | 323 | \newcommand{\qgradhistoned}{\texttt{\mbox{GradHist1d}}\xspace} 324 | \newcommand{\qgradhisttwod}{\texttt{\mbox{GradHist2d}}\xspace} 325 | 326 | \newcommand{\qnormtest}{\texttt{\mbox{NormTest}}\xspace} 327 | \newcommand{\qinnertest}{\texttt{\mbox{InnerTest}}\xspace} 328 | \newcommand{\qorthotest}{\texttt{\mbox{OrthoTest}}\xspace} 329 | 330 | \newcommand{\qhessmaxev}{\texttt{\mbox{HessMaxEV}}\xspace} 331 | \newcommand{\qhesstrace}{\texttt{\mbox{HessTrace}}\xspace} 332 | 333 | \newcommand{\qtictrace}{\texttt{\mbox{TICTrace}}\xspace} 334 | \newcommand{\qticdiag}{\texttt{\mbox{TICDiag}}\xspace} 335 | \newcommand{\tic}{\textsc{\mbox{TIC}}\xspace} 336 | 337 | \newcommand{\qmeangsnr}{\texttt{\mbox{MeanGSNR}}\xspace} 338 | \newcommand{\gsnr}{\textsc{\mbox{GSNR}}\xspace} 339 | 340 | \newcommand{\qloss}{\texttt{\mbox{Loss}}\xspace} 341 | \newcommand{\qparams}{\texttt{\mbox{Parameters}}\xspace} 342 | \newcommand{\qdistance}{\texttt{\mbox{Distance}}\xspace} 343 | \newcommand{\qupdatesize}{\texttt{\mbox{UpdateSize}}\xspace} 344 | \newcommand{\qgradnorm}{\texttt{\mbox{GradNorm}}\xspace} 345 | \newcommand{\qtime}{\texttt{\mbox{Time}}\xspace} 346 | 347 | 348 | % =================================================================== 349 | % ACTIVIATONS 350 | 351 | \newcommand{\relu}{ReLU\xspace} 352 | 353 | % =================================================================== 354 | % OTHER 355 | 356 | \newcommand{\refGPU}{\textsc{\mbox{Tesla K80}} GPU\xspace} 357 | \newcommand{\github}{\textsc{\mbox{GitHub}}\xspace} 358 | \newcommand{\arxiv}{\mbox{\normalfont\textsc{arXiv}}\xspace} 359 | \newcommand{\arxivtitle}{\textsc{\mbox{arXiv}}\xspace} 360 | \newcommand{\coursera}{\mbox{\normalfont\textsc{Coursera}}\xspace} 361 | 362 | \newcommand{\fid}{\textsc{\mbox{FID}}\xspace} 363 | \newcommand{\fidfull}{\textsc{\mbox{Fréchet inception distance}}\xspace} 364 | 365 | \newcommand{\alphafold}{\textsc{\mbox{AlphaFold}}\xspace} 366 | \newcommand{\lasso}{\textsc{\mbox{Lasso}}\xspace} 367 | \newcommand{\tikhonov}{\textsc{\mbox{Tikhonov}}\xspace} 368 | 369 | \newcommand{\klfull}{\textsc{\mbox{Kullback}-\mbox{Leibler}}\xspace} 370 | \newcommand{\kl}{\textsc{\mbox{KL}}\xspace} 371 | 372 | \newcommand{\smac}{\textsc{\mbox{SMAC}}\xspace} 373 | \newcommand{\bohb}{\textsc{\mbox{BOHB}}\xspace} 374 | \newcommand{\tpe}{\textsc{\mbox{TPE}}\xspace} 375 | \newcommand{\spearmint}{\textsc{\mbox{Spearmint}}\xspace} 376 | 377 | \newcommand{\mlcommons}{\textsc{\mbox{MLCommons}}\xspace} 378 | 379 | \newcommand{\nnsvg}{\textsc{\mbox{NN-SVG}}\xspace} 380 | 381 | %%% Local Variables: 382 | %%% mode: latex 383 | %%% TeX-master: "../thesis" 384 | %%% End: 385 | -------------------------------------------------------------------------------- /preamble/kaobiblio.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{preamble/kaobiblio} 2 | 3 | %---------------------------------------------------------------------------------------- 4 | % PACKAGE OPTIONS AND DEPENDENCIES 5 | %---------------------------------------------------------------------------------------- 6 | 7 | \RequirePackage{etoolbox} % Easy programming to modify TeX stuff 8 | \RequirePackage{perpage} % Reset counters 9 | \RequirePackage{iflang} % Check the document language 10 | \RequirePackage{xparse} % Parse arguments for macros 11 | \RequirePackage{xstring} % Parse strings 12 | \RequirePackage{hyperref} % Required for hyperlinks 13 | \RequirePackage{kvoptions} % Handle package options 14 | 15 | % Set up the package options 16 | \SetupKeyvalOptions{ 17 | family = kaobiblio, 18 | prefix = kaobiblio@ 19 | } 20 | 21 | \DeclareBoolOption{addspace}% If true, automatically add a space before printing the citation marker 22 | \DeclareBoolOption{linkeverything}% If true, the author name is a hyperlink in citation styles that support it 23 | 24 | % Choose the default options, which will be overwritten by the options 25 | % passed to this package. 26 | \PassOptionsToPackage{ 27 | %style=numeric-comp, 28 | %citestyle=authortitle-icomp, 29 | citestyle=numeric-comp, 30 | %bibstyle=authoryear, 31 | bibstyle=numeric, 32 | sorting=none, 33 | %sorting=nyt, 34 | %sortcites=true, 35 | %autocite=footnote, 36 | backend=bibtex, % Compile the bibliography with biber 37 | hyperref=true, 38 | backref=false, 39 | citecounter=true, 40 | pagetracker=true, 41 | citetracker=true, 42 | ibidtracker=context, 43 | autopunct=true, 44 | autocite=plain, 45 | natbib=true, % make \citep command (provided by natbib) work 46 | firstinits=true, % abbreviate author first names by initials. 47 | }{biblatex} 48 | 49 | % Pass the unknown options to biblatex, overwriting the previous settings. Avoid passing the kao-specific options. 50 | \DeclareDefaultOption{% 51 | \IfBeginWith{\CurrentOption}{addspace}{}{% 52 | \IfBeginWith{\CurrentOption}{linkeverything}{}{% 53 | \PassOptionsToPackage{\CurrentOption}{biblatex}% 54 | }}% 55 | } 56 | 57 | % Process the options 58 | \ProcessKeyvalOptions{kaobiblio} 59 | 60 | % Load biblatex 61 | \RequirePackage{biblatex} 62 | 63 | % Remove some unwanted entries from the bibliography 64 | \AtEveryBibitem{ 65 | \clearfield{issn} 66 | \clearfield{isbn} 67 | % \clearfield{archivePrefix} 68 | % \clearfield{arxivId} 69 | \clearfield{pmid} 70 | % \clearfield{eprint} 71 | \ifentrytype{online}{}{\ifentrytype{misc}{}{\clearfield{url}}} 72 | \ifentrytype{book}{\clearfield{doi}}{} 73 | } 74 | 75 | % Convert months to integers 76 | \DeclareSourcemap{ 77 | \maps[datatype=bibtex]{ 78 | \map[overwrite]{ 79 | \step[fieldsource=month, match={jan}, replace=${1}] 80 | \step[fieldsource=month, match={feb}, replace=${2}] 81 | \step[fieldsource=month, match={mar}, replace=${3}] 82 | \step[fieldsource=month, match={apr}, replace=${4}] 83 | \step[fieldsource=month, match={may}, replace=${5}] 84 | \step[fieldsource=month, match={jun}, replace=${6}] 85 | \step[fieldsource=month, match={jul}, replace=${7}] 86 | \step[fieldsource=month, match={aug}, replace=${8}] 87 | \step[fieldsource=month, match={sep}, replace=${9}] 88 | \step[fieldsource=month, match={oct}, replace=${10}] 89 | \step[fieldsource=month, match={nov}, replace=${11}] 90 | \step[fieldsource=month, match={dec}, replace=${12}] 91 | } 92 | } 93 | } 94 | 95 | %---------------------------------------------------------------------------------------- 96 | % BACK REFERENCES 97 | %---------------------------------------------------------------------------------------- 98 | 99 | % Check if a string is in a comma-separated list 100 | \newcommand\IfStringInList[2]{\IfSubStr{,#2,}{,#1,}} 101 | 102 | % Set the language-specific back reference strings 103 | % #LANGUAGE 104 | \@ifpackageloaded{polyglossia}{% 105 | \IfLanguageName{danish}{% 106 | \DefineBibliographyStrings{danish}{% 107 | backrefpage = {citeret på side}, 108 | backrefpages = {citeret på sider}, 109 | } 110 | }{} 111 | \IfLanguageName{english}{% 112 | \DefineBibliographyStrings{english}{% 113 | backrefpage = {cited on page}, 114 | backrefpages = {cited on pages}, 115 | } 116 | }{} 117 | \IfLanguageName{italian}{% 118 | \DefineBibliographyStrings{italian}{% 119 | backrefpage = {citato a pag.}, 120 | backrefpages = {citato a pagg.}, 121 | } 122 | }{} 123 | }{ 124 | \@ifpackageloaded{babel}{% 125 | \IfStringInList{danish}{\bbl@loaded}{% 126 | \DefineBibliographyStrings{danish}{% 127 | backrefpage = {citeret på side}, 128 | backrefpages = {citeret på sider}, 129 | } 130 | }{} 131 | \IfStringInList{english}{\bbl@loaded}{% 132 | \DefineBibliographyStrings{english}{% 133 | backrefpage = {cited on page}, 134 | backrefpages = {cited on pages}, 135 | } 136 | }{} 137 | \IfStringInList{italian}{\bbl@loaded}{% 138 | \DefineBibliographyStrings{italian}{% 139 | backrefpage = {citato a pag.}, 140 | backrefpages = {citato a pagg.}, 141 | } 142 | }{} 143 | }{} 144 | } 145 | 146 | %---------------------------------------------------------------------------------------- 147 | % CITATION COMMANDS 148 | %---------------------------------------------------------------------------------------- 149 | 150 | % Command to format the marginnote created for cited items 151 | \NewDocumentCommand{\formatmargincitation}{m}{% The parameter is a single citation key 152 | \parencite{#1}: \citeauthor*{#1} (\citeyear{#1}), \citetitle{#1}% 153 | } 154 | 155 | % Command to format the marginnote created for supercited items 156 | \NewDocumentCommand{\formatmarginsupercitation}{m}{% The parameter is a single citation key 157 | \supercite{#1} \citeauthor*{#1} (\citeyear{#1})% 158 | } 159 | 160 | % The following command needs to be redefined every time \sidecite is called in order for \DeclareCiteCommand's wrapper to work correctly 161 | \NewDocumentCommand{\kaobiblio@marginnote}{m}{% 162 | \marginnote{#1}% 163 | } 164 | 165 | % biblatex-like commands that also print a citation in the margin 166 | % Usage: 167 | % First optional argument is always vertical shift and must be given as an (empty) argument when using following a postnote and/or prenote 168 | % Second optional argument is always the postnote if the third argument isn't specified or is the prenote if the third argument is specified (same pattern as the biblatex commands) 169 | % Third optional argument is always the postnote 170 | % Mandatory argument is always the citation key(s) 171 | 172 | % Command to \cite and print a citation in the margin 173 | % First optional argument: vertical shift 174 | % Second optional argument: postnote if the third argument isn't specified; prenote if the third argument is specified (same pattern as the \textcite command) 175 | % Third optional argument: postnote 176 | % Mandatory argument: citation key 177 | \NewDocumentCommand{\sidecite}{o o o m}{% 178 | \RenewDocumentCommand{\kaobiblio@marginnote}{m}{% 179 | \marginnote[#1]{##1}% 180 | }% 181 | \DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{% 182 | }{% 183 | \formatmargincitation{\thefield{entrykey}}% 184 | }{% 185 | \\% separator between multiple citations 186 | }{% 187 | }% 188 | % With this we print the marker in the text and add the item to the bibliography at the end 189 | \IfNoValueOrEmptyTF{#2}% 190 | {\def\@tempa{\cite{#4}\kaobiblio@sidecite{#4}}}% 191 | {\IfNoValueOrEmptyTF{#3}% 192 | {\IfNoValueTF{#3}% 193 | {\def\@tempa{\cite[#2]{#4}\kaobiblio@sidecite{#4}}}% 194 | {\def\@tempa{\cite[#2][]{#4}\kaobiblio@sidecite{#4}}}% postnote is empty, so pass empty postnote 195 | }% 196 | {\def\@tempa{\cite[#2][#3]{#4}\kaobiblio@sidecite{#4}}}% 197 | }% 198 | \ifkaobiblio@addspace% 199 | \unskip~\@tempa% 200 | \else% 201 | \@tempa% 202 | \fi% 203 | } 204 | 205 | % Command to \supercite and print a citation in the margin 206 | % First optional argument: vertical shift 207 | % Second optional argument: postnote if the third argument isn't specified; prenote if the third argument is specified (same pattern as the \textcite command) 208 | % Third optional argument: postnote 209 | % Mandatory argument: citation key 210 | \NewDocumentCommand{\sidesupercite}{o o o m}{% 211 | \RenewDocumentCommand{\kaobiblio@marginnote}{m}{% 212 | \marginnote[#1]{##1}% 213 | }% 214 | \DeclareCiteCommand{\kaobiblio@sidesupercite}[\kaobiblio@marginnote]{% 215 | }{% 216 | \formatmarginsupercitation{\thefield{entrykey}}% 217 | }{% 218 | \\% separator between multiple citations 219 | }{% 220 | }% 221 | % With this we print the marker in the text and add the item to the bibliography at the end 222 | \IfNoValueOrEmptyTF{#2}% 223 | {\def\@tempa{\supercite{#4}\kaobiblio@sidesupercite{#4}}}% 224 | {\IfNoValueOrEmptyTF{#3}% 225 | {\IfNoValueTF{#3}% 226 | {\def\@tempa{\supercite[#2]{#4}\kaobiblio@sidesupercite{#4}}}% 227 | {\def\@tempa{\supercite[#2][]{#4}\kaobook@sidesupercite{#4}}}% postnote is empty, so pass empty postnote 228 | }% 229 | {\def\@tempa{\supercite[#2][#3]{#4}\kaobiblio@sidesupercite{#4}}}% 230 | }% 231 | \@tempa% 232 | } 233 | 234 | % Command to \textcite and print a citation in the margin 235 | % First optional argument: vertical shift 236 | % Second optional argument: postnote if the third argument isn't specified; prenote if the third argument is specified (same pattern as the \textcite command) 237 | % Third optional argument: postnote 238 | % Mandatory argument: citation key 239 | \NewDocumentCommand{\sidetextcite}{o o o m}{% 240 | \RenewDocumentCommand{\kaobiblio@marginnote}{m}{% 241 | \marginnote[#1]{##1}% 242 | }% 243 | \DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{% 244 | }{% 245 | \formatmargincitation{\thefield{entrykey}}% 246 | }{% 247 | \\% separator between multiple citations 248 | }{% 249 | }% 250 | % With this we print the marker in the text and add the item to the bibliography at the end 251 | \IfNoValueOrEmptyTF{#2}% 252 | {\def\@tempa{\textcite{#4}\kaobiblio@sidecite{#4}}}% 253 | {\IfNoValueOrEmptyTF{#3}% 254 | {\IfNoValueTF{#3}% 255 | {\def\@tempa{\textcite[#2]{#4}\kaobiblio@sidecite{#4}}}% 256 | {\def\@tempa{\textcite[#2][]{#4}\kaobook@sidecite{#4}}}% postnote is empty, so pass empty postnote 257 | }% 258 | {\def\@tempa{\textcite[#2][#3]{#4}\kaobiblio@sidecite{#4}}}% 259 | }% 260 | \ifkaobiblio@addspace% 261 | \unskip~\@tempa% 262 | \else% 263 | \@tempa% 264 | \fi% 265 | } 266 | 267 | % Command to \parencite or \parencite* and print a citation in the margin 268 | % First optional (star) argument: use \parencite* if included; otherwise use \parencite 269 | % Second optional argument: vertical shift 270 | % Third optional argument: postnote if the fourth argument isn't specified; prenote if the fourth argument is specified (same pattern as the \parencite command) 271 | % Fourth optional argument: postnote 272 | % Mandatory argument: citation key 273 | \NewDocumentCommand{\sideparencite}{s o o o m}{% 274 | \RenewDocumentCommand{\kaobiblio@marginnote}{m}{% 275 | \marginnote[#2]{##1}% 276 | }% 277 | \DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{% 278 | }{% 279 | \formatmargincitation{\thefield{entrykey}}% 280 | }{% 281 | \\% separator between multiple citations 282 | }{% 283 | }% 284 | % With this we print the marker in the text and add the item to the bibliography at the end 285 | \IfBooleanTF#1% 286 | {\IfNoValueOrEmptyTF{#3}% 287 | {\parencite*{#5}}% 288 | {\IfNoValueOrEmptyTF{#4}% 289 | {\IfNoValueTF{#4}% 290 | {\def\@tempa{\parencite*[#3]{#5}}}% 291 | {\def\@tempa{\parencite*[#3][]{#5}}}% postnote is empty, so pass empty postnote 292 | }% 293 | {\def\@tempa{\parencite*[#3][#4]{#5}}}% 294 | }% 295 | }% 296 | {\IfNoValueOrEmptyTF{#3}% 297 | {\def\@tempa{\parencite{#5}}}% 298 | {\IfNoValueOrEmptyTF{#4}% 299 | {\IfNoValueTF{#4}% 300 | {\def\@tempa{\parencite[#3]{#5}}}% 301 | {\def\@tempa{\parencite[#3][]{#5}}}% postnote is empty, so pass empty postnote 302 | }% 303 | {\def\@tempa{\parencite[#3][#4]{#5}}}% 304 | }% 305 | }% 306 | \ifkaobiblio@addspace% 307 | \unskip~\@tempa% 308 | \else% 309 | \@tempa% 310 | \fi% 311 | } 312 | 313 | 314 | %---------------------------------------------------------------------------------------- 315 | % LINKING THE AUTHOR'S NAME 316 | %---------------------------------------------------------------------------------------- 317 | 318 | % In biblatex, when citing with the style authoryear or using \textcite, only the year is linked to the reference in the bibliography. Despite the arguments of one of the mantainers of the biblatex package (https://github.com/plk/biblatex/issues/428), some users think that in the author* style the author name should be a link as well. The `linkeverything' option provides an easy way to activate this behaviour. 319 | 320 | \ifkaobiblio@linkeverything 321 | \xpatchbibmacro{cite} 322 | {\usebibmacro{cite:label}% 323 | \setunit{\printdelim{nonameyeardelim}}% 324 | \usebibmacro{cite:labeldate+extradate}} 325 | {\printtext[bibhyperref]{% 326 | \DeclareFieldAlias{bibhyperref}{default}% 327 | \usebibmacro{cite:label}% 328 | \setunit{\printdelim{nonameyeardelim}}% 329 | \usebibmacro{cite:labeldate+extradate}}} 330 | {} 331 | {\PackageWarning{biblatex-patch} 332 | {Failed to patch cite bibmacro}} 333 | 334 | % Include labelname in labelyear link 335 | \xpatchbibmacro{cite} 336 | {\printnames{labelname}% 337 | \setunit{\printdelim{nameyeardelim}}% 338 | \usebibmacro{cite:labeldate+extradate}} 339 | {\printtext[bibhyperref]{% 340 | \DeclareFieldAlias{bibhyperref}{default}% 341 | \printnames{labelname}% 342 | \setunit{\printdelim{nameyeardelim}}% 343 | \usebibmacro{cite:labeldate+extradate}}} 344 | {} 345 | {\PackageWarning{biblatex-patch} 346 | {Failed to patch cite bibmacro}} 347 | 348 | % Access hyperref's citation link start/end commands 349 | \makeatletter 350 | \protected\def\blx@imc@biblinkstart{% 351 | \@ifnextchar[%] 352 | {\blx@biblinkstart} 353 | {\blx@biblinkstart[\abx@field@entrykey]}} 354 | \def\blx@biblinkstart[#1]{% 355 | \blx@sfsave\hyper@natlinkstart{\the\c@refsection @#1}\blx@sfrest} 356 | \protected\def\blx@imc@biblinkend{% 357 | \blx@sfsave\hyper@natlinkend\blx@sfrest} 358 | \blx@regimcs{\biblinkstart \biblinkend} 359 | \makeatother 360 | 361 | \newbool{cbx:link} 362 | 363 | % Include parentheses around labelyear in \textcite only in 364 | % single citations without pre- and postnotes 365 | \def\iflinkparens{% 366 | \ifboolexpr{ test {\ifnumequal{\value{multicitetotal}}{0}} and 367 | test {\ifnumequal{\value{citetotal}}{1}} and 368 | test {\iffieldundef{prenote}} and 369 | test {\iffieldundef{postnote}} }} 370 | 371 | \xpatchbibmacro{textcite} 372 | {\printnames{labelname}} 373 | {\iflinkparens 374 | {\DeclareFieldAlias{bibhyperref}{default}% 375 | \global\booltrue{cbx:link}\biblinkstart% 376 | \printnames{labelname}} 377 | {\printtext[bibhyperref]{\printnames{labelname}}}} 378 | {} 379 | {\PackageWarning{biblatex-patch} 380 | {Failed to patch textcite bibmacro}} 381 | 382 | \xpatchbibmacro{textcite} 383 | {\usebibmacro{cite:label}} 384 | {\iflinkparens 385 | {\DeclareFieldAlias{bibhyperref}{default}% 386 | \global\booltrue{cbx:link}\biblinkstart% 387 | \usebibmacro{cite:label}} 388 | {\usebibmacro{cite:label}}} 389 | {} 390 | {\PackageWarning{biblatex-patch} 391 | {Failed to patch textcite bibmacro}} 392 | 393 | \xpretobibmacro{textcite:postnote} 394 | {\ifbool{cbx:link} 395 | {\ifbool{cbx:parens} 396 | {\bibcloseparen\global\boolfalse{cbx:parens}} 397 | {}% 398 | \biblinkend\global\boolfalse{cbx:link}} 399 | {}} 400 | {} 401 | {\PackageWarning{biblatex-patch} 402 | {Failed to patch textcite:postnote bibmacro}} 403 | \else 404 | \fi 405 | 406 | %---------------------------------------------------------------------------------------- 407 | % CITATION ENVIRONMENTS 408 | %---------------------------------------------------------------------------------------- 409 | 410 | % TODO: create a fancy environment for this. Perhaps printing also the 411 | % abstract. 412 | 413 | % Cite commands (assuming biblatex is loaded) 414 | \DeclareCiteCommand{\fullcite}{% 415 | \defcounter{maxnames}{99}% 416 | \usebibmacro{prenote}} 417 | {\clearfield{url}% 418 | \clearfield{pages}% 419 | \clearfield{pagetotal}% 420 | \clearfield{edition}% 421 | \clearfield{issn}% 422 | \clearfield{doi}% 423 | \usedriver 424 | {\DeclareNameAlias{sortname}{default}} 425 | {\thefield{entrytype}} 426 | } 427 | {\multicitedelim} 428 | {\usebibmacro{postnote}} 429 | -------------------------------------------------------------------------------- /preamble/math_commands.tex: -------------------------------------------------------------------------------- 1 | \newcommand{\tensor}[1]{\ensuremath{\mathsf{#1}}} 2 | \renewcommand{\vec}{\operatorname{vec}} 3 | \newcommand{\D}{\mathrm{D}} 4 | \newcommand{\Gmat}{\mathrm{G}} 5 | \newcommand{\F}{\mathrm{F}} 6 | \newcommand{\He}{\mathrm{H}} 7 | \newcommand{\HeCal}{\mathcal{H}} 8 | \newcommand{\diff}{\mathrm{d}} 9 | \newcommand{\average}[1]{\overline{ #1 }} 10 | 11 | \newcommand{\Loss}{\mathcal{L}} 12 | \newcommand{\jac}{\mathrm{J}} 13 | \newcommand{\lin}[1]{\left\langle #1 \right\rangle} 14 | 15 | \newcommand{\nablasquaredsub}[1]{ 16 | \nabla^{\kern -.0em \raise.1em\hbox{\tiny$2$}} {\kern -.6em \raise-.1em\hbox{\tiny$#1$}}{} 17 | } 18 | \newcommand{\nablasub}[1]{ 19 | \nabla {\kern -.2em \raise-.1em\hbox{\tiny$#1$}}{} 20 | } 21 | 22 | % Mark sections of captions for referring to divisions of figures 23 | \newcommand{\figleft}{{\em (Left)}} 24 | \newcommand{\figcenter}{{\em (Center)}} 25 | \newcommand{\figright}{{\em (Right)}} 26 | \newcommand{\figtop}{{\em (Top)}} 27 | \newcommand{\figbottom}{{\em (Bottom)}} 28 | \newcommand{\captiona}{{\em (a)}} 29 | \newcommand{\captionb}{{\em (b)}} 30 | \newcommand{\captionc}{{\em (c)}} 31 | \newcommand{\captiond}{{\em (d)}} 32 | 33 | % Highlight a newly defined term 34 | \newcommand{\newterm}[1]{{\bf #1}} 35 | 36 | % Figure reference, lower-case. 37 | \def\figref#1{figure~\ref{#1}} 38 | % Figure reference, capital. For start of sentence 39 | \def\Figref#1{Figure~\ref{#1}} 40 | \def\twofigref#1#2{figures \ref{#1} and \ref{#2}} 41 | \def\quadfigref#1#2#3#4{figures \ref{#1}, \ref{#2}, \ref{#3} and \ref{#4}} 42 | % Section reference, lower-case. 43 | \def\secref#1{section~\ref{#1}} 44 | % Section reference, capital. 45 | \def\Secref#1{Section~\ref{#1}} 46 | % Reference to two sections. 47 | \def\twosecrefs#1#2{sections \ref{#1} and \ref{#2}} 48 | % Reference to three sections. 49 | \def\secrefs#1#2#3{sections \ref{#1}, \ref{#2} and \ref{#3}} 50 | % Reference to an equation, lower-case. 51 | \def\eqref#1{equation~\ref{#1}} 52 | % Reference to an equation, upper case 53 | \def\Eqref#1{Equation~\ref{#1}} 54 | % A raw reference to an equation---avoid using if possible 55 | \def\plaineqref#1{\ref{#1}} 56 | % Reference to a chapter, lower-case. 57 | \def\chapref#1{chapter~\ref{#1}} 58 | % Reference to an equation, upper case. 59 | \def\Chapref#1{Chapter~\ref{#1}} 60 | % Reference to a range of chapters 61 | \def\rangechapref#1#2{chapters\ref{#1}--\ref{#2}} 62 | % Reference to an algorithm, lower-case. 63 | \def\algref#1{algorithm~\ref{#1}} 64 | % Reference to an algorithm, upper case. 65 | \def\Algref#1{Algorithm~\ref{#1}} 66 | \def\twoalgref#1#2{algorithms \ref{#1} and \ref{#2}} 67 | \def\Twoalgref#1#2{Algorithms \ref{#1} and \ref{#2}} 68 | % Reference to a part, lower case 69 | \def\partref#1{part~\ref{#1}} 70 | % Reference to a part, upper case 71 | \def\Partref#1{Part~\ref{#1}} 72 | \def\twopartref#1#2{parts \ref{#1} and \ref{#2}} 73 | 74 | \def\ceil#1{\lceil #1 \rceil} 75 | \def\floor#1{\lfloor #1 \rfloor} 76 | \def\1{\bm{1}} 77 | \newcommand{\train}{\mathcal{D}} 78 | \newcommand{\valid}{\mathcal{D_{\mathrm{valid}}}} 79 | \newcommand{\test}{\mathcal{D_{\mathrm{test}}}} 80 | 81 | \def\eps{{\epsilon}} 82 | 83 | 84 | % Random variables 85 | \def\reta{{\textnormal{$\eta$}}} 86 | \def\ra{{\textnormal{a}}} 87 | \def\rb{{\textnormal{b}}} 88 | \def\rc{{\textnormal{c}}} 89 | \def\rd{{\textnormal{d}}} 90 | \def\re{{\textnormal{e}}} 91 | \def\rf{{\textnormal{f}}} 92 | \def\rg{{\textnormal{g}}} 93 | \def\rh{{\textnormal{h}}} 94 | \def\ri{{\textnormal{i}}} 95 | \def\rj{{\textnormal{j}}} 96 | \def\rk{{\textnormal{k}}} 97 | \def\rl{{\textnormal{l}}} 98 | % rm is already a command, just don't name any random variables m 99 | \def\rn{{\textnormal{n}}} 100 | \def\ro{{\textnormal{o}}} 101 | \def\rp{{\textnormal{p}}} 102 | \def\rq{{\textnormal{q}}} 103 | \def\rr{{\textnormal{r}}} 104 | \def\rs{{\textnormal{s}}} 105 | \def\rt{{\textnormal{t}}} 106 | \def\ru{{\textnormal{u}}} 107 | \def\rv{{\textnormal{v}}} 108 | \def\rw{{\textnormal{w}}} 109 | \def\rx{{\textnormal{x}}} 110 | \def\ry{{\textnormal{y}}} 111 | \def\rz{{\textnormal{z}}} 112 | 113 | % Random vectors 114 | \def\rvepsilon{{\mathbf{\epsilon}}} 115 | \def\rvtheta{{\mathbf{\theta}}} 116 | \def\rva{{\mathbf{a}}} 117 | \def\rvb{{\mathbf{b}}} 118 | \def\rvc{{\mathbf{c}}} 119 | \def\rvd{{\mathbf{d}}} 120 | \def\rve{{\mathbf{e}}} 121 | \def\rvf{{\mathbf{f}}} 122 | \def\rvg{{\mathbf{g}}} 123 | \def\rvh{{\mathbf{h}}} 124 | \def\rvu{{\mathbf{i}}} 125 | \def\rvj{{\mathbf{j}}} 126 | \def\rvk{{\mathbf{k}}} 127 | \def\rvl{{\mathbf{l}}} 128 | \def\rvm{{\mathbf{m}}} 129 | \def\rvn{{\mathbf{n}}} 130 | \def\rvo{{\mathbf{o}}} 131 | \def\rvp{{\mathbf{p}}} 132 | \def\rvq{{\mathbf{q}}} 133 | \def\rvr{{\mathbf{r}}} 134 | \def\rvs{{\mathbf{s}}} 135 | \def\rvt{{\mathbf{t}}} 136 | \def\rvu{{\mathbf{u}}} 137 | \def\rvv{{\mathbf{v}}} 138 | \def\rvw{{\mathbf{w}}} 139 | \def\rvx{{\mathbf{x}}} 140 | \def\rvy{{\mathbf{y}}} 141 | \def\rvz{{\mathbf{z}}} 142 | 143 | % Elements of random vectors 144 | \def\erva{{\textnormal{a}}} 145 | \def\ervb{{\textnormal{b}}} 146 | \def\ervc{{\textnormal{c}}} 147 | \def\ervd{{\textnormal{d}}} 148 | \def\erve{{\textnormal{e}}} 149 | \def\ervf{{\textnormal{f}}} 150 | \def\ervg{{\textnormal{g}}} 151 | \def\ervh{{\textnormal{h}}} 152 | \def\ervi{{\textnormal{i}}} 153 | \def\ervj{{\textnormal{j}}} 154 | \def\ervk{{\textnormal{k}}} 155 | \def\ervl{{\textnormal{l}}} 156 | \def\ervm{{\textnormal{m}}} 157 | \def\ervn{{\textnormal{n}}} 158 | \def\ervo{{\textnormal{o}}} 159 | \def\ervp{{\textnormal{p}}} 160 | \def\ervq{{\textnormal{q}}} 161 | \def\ervr{{\textnormal{r}}} 162 | \def\ervs{{\textnormal{s}}} 163 | \def\ervt{{\textnormal{t}}} 164 | \def\ervu{{\textnormal{u}}} 165 | \def\ervv{{\textnormal{v}}} 166 | \def\ervw{{\textnormal{w}}} 167 | \def\ervx{{\textnormal{x}}} 168 | \def\ervy{{\textnormal{y}}} 169 | \def\ervz{{\textnormal{z}}} 170 | 171 | % Random matrices 172 | \def\rmA{{\mathbf{A}}} 173 | \def\rmB{{\mathbf{B}}} 174 | \def\rmC{{\mathbf{C}}} 175 | \def\rmD{{\mathbf{D}}} 176 | \def\rmE{{\mathbf{E}}} 177 | \def\rmF{{\mathbf{F}}} 178 | \def\rmG{{\mathbf{G}}} 179 | \def\rmH{{\mathbf{H}}} 180 | \def\rmI{{\mathbf{I}}} 181 | \def\rmJ{{\mathbf{J}}} 182 | \def\rmK{{\mathbf{K}}} 183 | \def\rmL{{\mathbf{L}}} 184 | \def\rmM{{\mathbf{M}}} 185 | \def\rmN{{\mathbf{N}}} 186 | \def\rmO{{\mathbf{O}}} 187 | \def\rmP{{\mathbf{P}}} 188 | \def\rmQ{{\mathbf{Q}}} 189 | \def\rmR{{\mathbf{R}}} 190 | \def\rmS{{\mathbf{S}}} 191 | \def\rmT{{\mathbf{T}}} 192 | \def\rmU{{\mathbf{U}}} 193 | \def\rmV{{\mathbf{V}}} 194 | \def\rmW{{\mathbf{W}}} 195 | \def\rmX{{\mathbf{X}}} 196 | \def\rmY{{\mathbf{Y}}} 197 | \def\rmZ{{\mathbf{Z}}} 198 | 199 | % Elements of random matrices 200 | \def\ermA{{\textnormal{A}}} 201 | \def\ermB{{\textnormal{B}}} 202 | \def\ermC{{\textnormal{C}}} 203 | \def\ermD{{\textnormal{D}}} 204 | \def\ermE{{\textnormal{E}}} 205 | \def\ermF{{\textnormal{F}}} 206 | \def\ermG{{\textnormal{G}}} 207 | \def\ermH{{\textnormal{H}}} 208 | \def\ermI{{\textnormal{I}}} 209 | \def\ermJ{{\textnormal{J}}} 210 | \def\ermK{{\textnormal{K}}} 211 | \def\ermL{{\textnormal{L}}} 212 | \def\ermM{{\textnormal{M}}} 213 | \def\ermN{{\textnormal{N}}} 214 | \def\ermO{{\textnormal{O}}} 215 | \def\ermP{{\textnormal{P}}} 216 | \def\ermQ{{\textnormal{Q}}} 217 | \def\ermR{{\textnormal{R}}} 218 | \def\ermS{{\textnormal{S}}} 219 | \def\ermT{{\textnormal{T}}} 220 | \def\ermU{{\textnormal{U}}} 221 | \def\ermV{{\textnormal{V}}} 222 | \def\ermW{{\textnormal{W}}} 223 | \def\ermX{{\textnormal{X}}} 224 | \def\ermY{{\textnormal{Y}}} 225 | \def\ermZ{{\textnormal{Z}}} 226 | 227 | % Vectors 228 | \def\vzero{{\bm{0}}} 229 | \def\vone{{\bm{1}}} 230 | \def\vmu{{\bm{\mu}}} 231 | \def\vnu{{\bm{\nu}}} 232 | \def\vtheta{{\bm{\theta}}} 233 | \def\vgamma{{\bm{\gamma}}} 234 | \def\vdelta{{\bm{\delta}}} 235 | \def\vDelta{{\bm{\Delta}}} 236 | \def\vepsilon{{\bm{\epsilon}}} 237 | \def\va{{\bm{a}}} 238 | \def\vb{{\bm{b}}} 239 | \def\vc{{\bm{c}}} 240 | \def\vd{{\bm{d}}} 241 | \def\ve{{\bm{e}}} 242 | \def\vehat{\bm{\hat{e}}} 243 | \def\vetilde{\bm{\tilde{e}}} 244 | \def\vell{{\bm{\ell}}} 245 | \def\vf{{\bm{f}}} 246 | \def\vfhat{{\bm{\hat{f}}}} 247 | \def\vg{{\bm{g}}} 248 | \def\vgtilde{\bm{\tilde{g}}} 249 | \def\vghat{\bm{\hat{g}}} 250 | \def\vh{{\bm{h}}} 251 | \def\vi{{\bm{i}}} 252 | \def\vj{{\bm{j}}} 253 | \def\vk{{\bm{k}}} 254 | \def\vl{{\bm{l}}} 255 | \def\vm{{\bm{m}}} 256 | \def\vmhat{{\bm{\hat{m}}}} 257 | \def\vn{{\bm{n}}} 258 | \def\vo{{\bm{o}}} 259 | \def\vp{{\bm{p}}} 260 | \def\vphi{{\bm{\phi}}} 261 | \def\vq{{\bm{q}}} 262 | \def\vr{{\bm{r}}} 263 | \def\vs{{\bm{s}}} 264 | \def\vstilde{\bm{\tilde{s}}} 265 | \def\vt{{\bm{t}}} 266 | \def\vu{{\bm{u}}} 267 | \def\vv{{\bm{v}}} 268 | \def\vvhat{{\bm{\hat{v}}}} 269 | \def\vw{{\bm{w}}} 270 | \def\vx{{\bm{x}}} 271 | \def\vy{{\bm{y}}} 272 | \def\vytilde{{\bm{\tilde{y}}}} 273 | \def\vyhat{{\bm{\hat{y}}}} 274 | \def\vz{{\bm{z}}} 275 | 276 | % Elements of vectors 277 | \def\evalpha{{\alpha}} 278 | \def\evbeta{{\beta}} 279 | \def\evepsilon{{\epsilon}} 280 | \def\evlambda{{\lambda}} 281 | \def\evomega{{\omega}} 282 | \def\evmu{{\mu}} 283 | \def\evpsi{{\psi}} 284 | \def\evsigma{{\sigma}} 285 | \def\evtheta{{\theta}} 286 | \def\eva{{a}} 287 | \def\evb{{b}} 288 | \def\evc{{c}} 289 | \def\evd{{d}} 290 | \def\eve{{e}} 291 | \def\evf{{f}} 292 | \def\evg{{g}} 293 | \def\evh{{h}} 294 | \def\evi{{i}} 295 | \def\evj{{j}} 296 | \def\evk{{k}} 297 | \def\evl{{l}} 298 | \def\evm{{m}} 299 | \def\evn{{n}} 300 | \def\evo{{o}} 301 | \def\evp{{p}} 302 | \def\evq{{q}} 303 | \def\evr{{r}} 304 | \def\evs{{s}} 305 | \def\evt{{t}} 306 | \def\evu{{u}} 307 | \def\evv{{v}} 308 | \def\evw{{w}} 309 | \def\evx{{x}} 310 | \def\evy{{y}} 311 | \def\evyhat{{\hat{y}}} 312 | \def\evz{{z}} 313 | 314 | % Matrix 315 | \def\mA{{\bm{A}}} 316 | \def\mB{{\bm{B}}} 317 | \def\mC{{\bm{C}}} 318 | \def\mD{{\bm{D}}} 319 | \def\mE{{\bm{E}}} 320 | \def\mF{{\bm{F}}} 321 | \def\mG{{\bm{G}}} 322 | \def\mGtilde{\bm{\tilde{G}}} 323 | \def\mH{{\bm{H}}} 324 | \def\mI{{\bm{I}}} 325 | \def\mJ{{\bm{J}}} 326 | \def\mK{{\bm{K}}} 327 | \def\mL{{\bm{L}}} 328 | \def\mM{{\bm{M}}} 329 | \def\mN{{\bm{N}}} 330 | \def\mO{{\bm{O}}} 331 | \def\mP{{\bm{P}}} 332 | \def\mQ{{\bm{Q}}} 333 | \def\mR{{\bm{R}}} 334 | \def\mS{{\bm{S}}} 335 | \def\mT{{\bm{T}}} 336 | \def\mU{{\bm{U}}} 337 | \def\mV{{\bm{V}}} 338 | \def\mW{{\bm{W}}} 339 | \def\mWhat{{\bm{\hat{W}}}} 340 | \def\mX{{\bm{X}}} 341 | \def\mY{{\bm{Y}}} 342 | \def\mZ{{\bm{Z}}} 343 | \def\mBeta{{\bm{\beta}}} 344 | \def\mPhi{{\bm{\Phi}}} 345 | \def\mPi{{\bm{\Pi}}} 346 | \def\mLambda{{\bm{\Lambda}}} 347 | \def\mSigma{{\bm{\Sigma}}} 348 | \def\mStilde{\bm{\tilde{\mS}}} 349 | \def\mGtilde{\bm{\tilde{\mG}}} 350 | \def\mGoverline{{\bm{\overline{G}}}} 351 | 352 | % Tensor 353 | \DeclareMathAlphabet{\mathsfit}{\encodingdefault}{\sfdefault}{m}{sl} 354 | \SetMathAlphabet{\mathsfit}{bold}{\encodingdefault}{\sfdefault}{bx}{n} 355 | \newcommand{\tens}[1]{\bm{\mathsfit{#1}}} 356 | \def\tA{{\tens{A}}} 357 | \def\tB{{\tens{B}}} 358 | \def\tC{{\tens{C}}} 359 | \def\tD{{\tens{D}}} 360 | \def\tE{{\tens{E}}} 361 | \def\tF{{\tens{F}}} 362 | \def\tG{{\tens{G}}} 363 | \def\tH{{\tens{H}}} 364 | \def\tI{{\tens{I}}} 365 | \def\tJ{{\tens{J}}} 366 | \def\tK{{\tens{K}}} 367 | \def\tL{{\tens{L}}} 368 | \def\tM{{\tens{M}}} 369 | \def\tN{{\tens{N}}} 370 | \def\tO{{\tens{O}}} 371 | \def\tP{{\tens{P}}} 372 | \def\tQ{{\tens{Q}}} 373 | \def\tR{{\tens{R}}} 374 | \def\tS{{\tens{S}}} 375 | \def\tT{{\tens{T}}} 376 | \def\tU{{\tens{U}}} 377 | \def\tV{{\tens{V}}} 378 | \def\tW{{\tens{W}}} 379 | \def\tX{{\tens{X}}} 380 | \def\tY{{\tens{Y}}} 381 | \def\tZ{{\tens{Z}}} 382 | 383 | 384 | % Graph 385 | \def\gA{{\mathcal{A}}} 386 | \def\gB{{\mathcal{B}}} 387 | \def\gC{{\mathcal{C}}} 388 | \def\gD{{\mathcal{D}}} 389 | \def\gE{{\mathcal{E}}} 390 | \def\gF{{\mathcal{F}}} 391 | \def\gG{{\mathcal{G}}} 392 | \def\gH{{\mathcal{H}}} 393 | \def\gI{{\mathcal{I}}} 394 | \def\gJ{{\mathcal{J}}} 395 | \def\gK{{\mathcal{K}}} 396 | \def\gL{{\mathcal{L}}} 397 | \def\gM{{\mathcal{M}}} 398 | \def\gN{{\mathcal{N}}} 399 | \def\gO{{\mathcal{O}}} 400 | \def\gP{{\mathcal{P}}} 401 | \def\gQ{{\mathcal{Q}}} 402 | \def\gR{{\mathcal{R}}} 403 | \def\gS{{\mathcal{S}}} 404 | \def\gT{{\mathcal{T}}} 405 | \def\gU{{\mathcal{U}}} 406 | \def\gV{{\mathcal{V}}} 407 | \def\gW{{\mathcal{W}}} 408 | \def\gX{{\mathcal{X}}} 409 | \def\gY{{\mathcal{Y}}} 410 | \def\gZ{{\mathcal{Z}}} 411 | 412 | % Sets 413 | \def\sA{{\mathbb{A}}} 414 | \def\sB{{\mathbb{B}}} 415 | \def\sC{{\mathbb{C}}} 416 | \def\sD{{\mathbb{D}}} 417 | % Don't use a set called E, because this would be the same as our symbol 418 | % for expectation. 419 | \def\sF{{\mathbb{F}}} 420 | \def\sG{{\mathbb{G}}} 421 | \def\sH{{\mathbb{H}}} 422 | \def\sI{{\mathbb{I}}} 423 | \def\sJ{{\mathbb{J}}} 424 | \def\sK{{\mathbb{K}}} 425 | \def\sL{{\mathbb{L}}} 426 | \def\sM{{\mathbb{M}}} 427 | \def\sN{{\mathbb{N}}} 428 | \def\sO{{\mathbb{O}}} 429 | \def\sP{{\mathbb{P}}} 430 | \def\sQ{{\mathbb{Q}}} 431 | \def\sR{{\mathbb{R}}} 432 | \def\sS{{\mathbb{S}}} 433 | \def\sT{{\mathbb{T}}} 434 | \def\sU{{\mathbb{U}}} 435 | \def\sV{{\mathbb{V}}} 436 | \def\sW{{\mathbb{W}}} 437 | \def\sX{{\mathbb{X}}} 438 | \def\sY{{\mathbb{Y}}} 439 | \def\sYhat{{\hat{\mathbb{Y}}}} 440 | \def\sZ{{\mathbb{Z}}} 441 | % Blackboard Greek characters: https://tex.stackexchange.com/a/3260 442 | \DeclareSymbolFont{bbold}{U}{bbold}{m}{n} 443 | \DeclareSymbolFontAlphabet{\mathbbold}{bbold} 444 | \def\sOmega{{\mathbbold{\Omega}}} 445 | \def\sPhi{{\mathbbold{\Phi}}} 446 | \def\sTheta{{\mathbbold{\Theta}}} 447 | 448 | % Entries of a matrix 449 | \def\emLambda{{\Lambda}} 450 | \def\emA{{A}} 451 | \def\emB{{B}} 452 | \def\emC{{C}} 453 | \def\emD{{D}} 454 | \def\emE{{E}} 455 | \def\emF{{F}} 456 | \def\emG{{G}} 457 | \def\emH{{H}} 458 | \def\emI{{I}} 459 | \def\emJ{{J}} 460 | \def\emK{{K}} 461 | \def\emL{{L}} 462 | \def\emM{{M}} 463 | \def\emN{{N}} 464 | \def\emO{{O}} 465 | \def\emP{{P}} 466 | \def\emQ{{Q}} 467 | \def\emR{{R}} 468 | \def\emS{{S}} 469 | \def\emT{{T}} 470 | \def\emU{{U}} 471 | \def\emV{{V}} 472 | \def\emW{{W}} 473 | \def\emX{{X}} 474 | \def\emY{{Y}} 475 | \def\emZ{{Z}} 476 | \def\emSigma{{\Sigma}} 477 | \def\emPi{{\Pi}} 478 | 479 | % entries of a tensor 480 | % Same font as tensor, without \bm wrapper 481 | \newcommand{\etens}[1]{\mathsfit{#1}} 482 | \def\etLambda{{\etens{\Lambda}}} 483 | \def\etA{{\etens{A}}} 484 | \def\etB{{\etens{B}}} 485 | \def\etC{{\etens{C}}} 486 | \def\etD{{\etens{D}}} 487 | \def\etE{{\etens{E}}} 488 | \def\etF{{\etens{F}}} 489 | \def\etG{{\etens{G}}} 490 | \def\etH{{\etens{H}}} 491 | \def\etI{{\etens{I}}} 492 | \def\etJ{{\etens{J}}} 493 | \def\etK{{\etens{K}}} 494 | \def\etL{{\etens{L}}} 495 | \def\etM{{\etens{M}}} 496 | \def\etN{{\etens{N}}} 497 | \def\etO{{\etens{O}}} 498 | \def\etP{{\etens{P}}} 499 | \def\etQ{{\etens{Q}}} 500 | \def\etR{{\etens{R}}} 501 | \def\etS{{\etens{S}}} 502 | \def\etT{{\etens{T}}} 503 | \def\etU{{\etens{U}}} 504 | \def\etV{{\etens{V}}} 505 | \def\etW{{\etens{W}}} 506 | \def\etX{{\etens{X}}} 507 | \def\etY{{\etens{Y}}} 508 | \def\etZ{{\etens{Z}}} 509 | 510 | % The true underlying data generating distribution 511 | \newcommand{\pdata}{p_{\mathrm{data}}} 512 | % The empirical distribution defined by the training set 513 | \newcommand{\ptrain}{\hat{p}_{\mathrm{data}}} 514 | \newcommand{\Ptrain}{\hat{P}_{\mathrm{data}}} 515 | % The model distribution 516 | \newcommand{\pmodel}{p_{\rm{model}}} 517 | \newcommand{\Pmodel}{P_{\rm{model}}} 518 | \newcommand{\ptildemodel}{\tilde{p}_{\rm{model}}} 519 | % Stochastic autoencoder distributions 520 | \newcommand{\pencode}{p_{\rm{encoder}}} 521 | \newcommand{\pdecode}{p_{\rm{decoder}}} 522 | \newcommand{\precons}{p_{\rm{reconstruct}}} 523 | 524 | \newcommand{\laplace}{\mathrm{Laplace}} % Laplace distribution 525 | 526 | \newcommand{\E}{\mathbb{E}} 527 | \newcommand{\Ls}{\mathcal{L}} 528 | \newcommand{\R}{\mathbb{R}} 529 | \newcommand{\emp}{\tilde{p}} 530 | \newcommand{\lr}{\alpha} 531 | \newcommand{\reg}{\lambda} 532 | \newcommand{\rect}{\mathrm{rectifier}} 533 | \newcommand{\softmax}{\mathrm{softmax}} 534 | \newcommand{\onehot}{\mathrm{onehot}} 535 | \newcommand{\sigmoid}{\sigma} 536 | \newcommand{\softplus}{\zeta} 537 | \newcommand{\KL}{D_{\mathrm{KL}}} 538 | \newcommand{\Var}{\mathrm{Var}} 539 | \newcommand{\standarderror}{\mathrm{SE}} 540 | \newcommand{\Cov}{\mathrm{Cov}} 541 | % Wolfram Mathworld says $L^2$ is for function spaces and $\ell^2$ is for vectors 542 | % But then they seem to use $L^2$ for vectors throughout the site, and so does 543 | % wikipedia. 544 | \newcommand{\normlzero}{L^0} 545 | \newcommand{\normlone}{L^1} 546 | \newcommand{\normltwo}{L^2} 547 | \newcommand{\normlp}{L^p} 548 | \newcommand{\normmax}{L^\infty} 549 | 550 | \newcommand{\parents}{Pa} % See usage in notation.tex. Chosen to match Daphne's book. 551 | 552 | \DeclareMathOperator*{\argmax}{arg\,max} 553 | \DeclareMathOperator*{\argmin}{arg\,min} 554 | \DeclareMathOperator*{\minimize}{minimize} 555 | 556 | \DeclareMathOperator{\sign}{sign} 557 | \DeclareMathOperator{\mean}{mean} 558 | \DeclareMathOperator{\vmap}{vmap} 559 | \DeclareMathOperator{\reshape}{reshape} 560 | \DeclareMathOperator{\Tr}{Tr} 561 | \DeclareMathOperator{\diag}{diag} 562 | \DeclareMathOperator{\eig}{eig} 563 | \DeclareMathOperator{\rank}{rank} 564 | \DeclareMathOperator{\vecspan}{span} 565 | \DeclareMathOperator{\overlap}{overlap} 566 | \DeclareMathOperator{\Cat}{Cat} 567 | 568 | %%%%% NEW MATH DEFINITIONS %%%%% 569 | \newcommand{\grad}[1]{\ensuremath{\nabla_{\!{#1}}}} 570 | \newcommand{\naturalgrad}[1]{\ensuremath{\tilde{\nabla}_{\!{#1}}}} 571 | \newcommand{\gradsquared}[1]{\ensuremath{\nabla_{\!{#1}}^{2}}} 572 | \newcommand{\hess}[1]{\ensuremath{\mathrm{H}_{#1}}} 573 | 574 | \newcommand{\Dtrain}{\ensuremath{\sD_{\mathrm{train}}}} 575 | \newcommand{\Dtest}{\ensuremath{\sD_{\mathrm{test}}}} 576 | \newcommand{\Dvalid}{\ensuremath{\sD_{\mathrm{valid}}}} 577 | 578 | % || for KLDivergence 579 | \DeclarePairedDelimiterX{\KLdivx}[2]{(}{)}{% 580 | #1\;\delimsize\|\;#2% 581 | } 582 | \newcommand{\KLdiv}{\KL\KLdivx} 583 | 584 | % | for a | b 585 | \newcommand{\giventhat}[2]{#1\;|\;#2} 586 | 587 | \let\ab\allowbreak 588 | 589 | %%% Local Variables: 590 | %%% mode: latex 591 | %%% TeX-master: "../thesis" 592 | %%% End: 593 | -------------------------------------------------------------------------------- /preamble/preamble.tex: -------------------------------------------------------------------------------- 1 | % =================================================================== 2 | % GENERAL PREAMBLE 3 | 4 | \documentclass[ 5 | a4paper, 6 | fontsize=11pt, 7 | twoside=true, 8 | numbers=noenddot, 9 | open=any, 10 | secnumdepth=2, 11 | % draft % Shows black boxes next to overful hboxes (ignore the errors) 12 | ]{preamble/thesis} 13 | 14 | \usepackage[ngerman,english]{babel} % English language/hyphenation 15 | \usepackage[dissertation, internal]{preamble/tuetitle} 16 | 17 | 18 | % =================================================================== 19 | % COLORS 20 | 21 | \usepackage{xcolor} % To define colors 22 | \input{preamble/colors.tex} % Pre-define a bunch of often-used colors 23 | 24 | \colorlet{maincolor}{TUblue} % Main color, used for headings, etc. 25 | \colorlet{secondcolor}{TUred} % Secondary color, used for references, etc. 26 | \colorlet{thirdcolor}{TUgold} % Tertiary color, used for citations, etc. 27 | \colorlet{fourthcolor}{TUgold} % Fourth color, used for URLs, etc. 28 | \colorlet{lightgraycolor}{TUdark!50}% A gray color, used for lines, etc. 29 | \colorlet{darkgraycolor}{TUdark!80} % A dark color, used for numbers, etc. 30 | 31 | % Optimizer colors 32 | \definecolor{adabelief}{HTML}{63FFA4} 33 | \definecolor{amsbound}{HTML}{FFFF00} 34 | \definecolor{amsgrad}{HTML}{A63D08} 35 | \definecolor{adabound}{HTML}{FF8C00} 36 | \definecolor{adadelta}{HTML}{735859} 37 | \definecolor{adagrad}{HTML}{F3CC9A} 38 | \definecolor{adam}{HTML}{F90004} 39 | \definecolor{lookaheadmomentum}{HTML}{008B8B} 40 | \definecolor{lookaheadradam}{HTML}{35CC38} 41 | \definecolor{momentum}{HTML}{00CBFF} 42 | \definecolor{nag}{HTML}{991bf5} 43 | \definecolor{nadam}{HTML}{8E8E05} 44 | \definecolor{radam}{HTML}{FF00FF} 45 | \definecolor{rmsprop}{HTML}{000000} 46 | \definecolor{sgd}{HTML}{1E3CFF} 47 | \definecolor{otheropt}{HTML}{B2B2B2} 48 | 49 | % DeepOBS colors 50 | \colorlet{deepobsclass}{TUgold} 51 | \colorlet{deepobscli}{TUdark} 52 | \colorlet{deepobsdata}{TUblue} 53 | \colorlet{deepobsscript}{TUred} 54 | 55 | \colorlet{deepobsimageclass}{TUgold} 56 | \colorlet{deepobsgenerative}{TUblue} 57 | \colorlet{deepobsnlp}{TUred} 58 | \colorlet{deepobstoy}{TUdark} 59 | 60 | \colorlet{deepobssmall}{SNSgreen!45} 61 | \colorlet{deepobslarge}{SNSorange!45} 62 | 63 | \colorlet{deepobsgood}{SNSgreen!70} 64 | \colorlet{deepobsbad}{TUred!70} 65 | 66 | % Benchmark colors 67 | \colorlet{lrschedules}{maincolor} 68 | \colorlet{lrbg}{lightgraycolor!25} 69 | 70 | % =================================================================== 71 | % GRAPHICS 72 | 73 | \usepackage{pifont} % For special symbols like checkmarks 74 | \usepackage[labelsep=colon]{caption} % Options for caption 75 | \DeclareCaptionFont{labelcolor}{\color{maincolor}} 76 | \captionsetup{labelfont={labelcolor,bf}} % e.g. coloring the word "Figure" in caption 77 | \usepackage{subcaption} % For subcaptioning images 78 | \usepackage{fancybox} % Allows shadowbox around figure (for screenshot) 79 | 80 | % path where the \includegrahics looks for figures 81 | \graphicspath{ 82 | {../repos/cockpit-paper/fig/03_scalar_deep/output/} 83 | {../repos/vivit-paper/tex/paper/} 84 | } 85 | 86 | \newcommand{\goldenRatio}{1.61803398875} 87 | \newcommand{\goldenRatioInv}{0.61803398875} 88 | 89 | % Tikz 90 | \usetikzlibrary{ 91 | shapes, 92 | pgfplots.groupplots, 93 | shadings, 94 | calc, 95 | arrows, 96 | backgrounds, 97 | colorbrewer, 98 | shadows.blur, 99 | external, 100 | shapes, 101 | shapes.arrows, 102 | shapes.symbols, 103 | arrows.meta, 104 | fit % For extending the bounding box 105 | } 106 | 107 | % PGFPlot 108 | \usepackage{pgfplots} 109 | \usepgfplotslibrary{groupplots,fillbetween} 110 | \pgfplotsset{compat=1.15} 111 | 112 | % Externalize (disabled by default) 113 | \usepgfplotslibrary{external} 114 | \tikzexternalize[prefix=tikz/, mode=list and make] 115 | \tikzexternaldisable 116 | 117 | % Create new lenght for pgfplots 118 | \newlength\figureheight 119 | \newlength\figurewidth 120 | \setlength\figureheight{\textheight} 121 | \setlength\figurewidth{\textwidth} 122 | 123 | % width in figure* environments 124 | \newlength{\thesiswidewidth} 125 | \setlength{\thesiswidewidth}{457.8024pt} 126 | 127 | \pdfsuppresswarningpagegroup=1 % Surpress the "PDF inclusion: multiple pdfs with apge group..." warning (https://tex.stackexchange.com/questions/76273/multiple-pdfs-with-page-group-included-in-a-single-page-warning) 128 | 129 | % Customized shadow color for shadowbox 130 | \makeatletter 131 | \newcommand\Cshadowbox{\VerbBox\@Cshadowbox} 132 | \def\@Cshadowbox#1{% 133 | \setbox\@fancybox\hbox{\fbox{#1}}% 134 | \leavevmode\vbox{% 135 | \offinterlineskip 136 | \dimen@=\shadowsize 137 | \advance\dimen@ .5\fboxrule 138 | \hbox{\copy\@fancybox\kern.5\fboxrule\lower\shadowsize\hbox{% 139 | \color{lightgraycolor}\vrule \@height\ht\@fancybox \@depth\dp\@fancybox \@width\dimen@}}% 140 | \vskip\dimexpr-\dimen@+0.5\fboxrule\relax 141 | \moveright\shadowsize\vbox{% 142 | \color{lightgraycolor}\hrule \@width\wd\@fancybox \@height\dimen@}}} 143 | \makeatother 144 | 145 | % =================================================================== 146 | % FONTS 147 | 148 | \usepackage[defaultsans]{lato} % Sans Font: Lato (would allow for thin) 149 | %\usepackage{gillius} % Sans Font: Tufte font 150 | 151 | \usepackage{anyfontsize} % Allows arbitrary font sizes 152 | 153 | % Headings should use sans serif font 154 | \addtokomafont{part}{\normalfont\sffamily\color{maincolor}} 155 | 156 | % Colored chapter number but not the chapter title 157 | \addtokomafont{chapter}{\normalfont\sffamily} 158 | \addtokomafont{chapterprefix}{\normalfont\sffamily\color{maincolor}} 159 | \addtokomafont{section}{\normalfont\sffamily\color{maincolor}} 160 | \addtokomafont{subsection}{\normalfont\sffamily\color{maincolor}} 161 | \addtokomafont{subsubsection}{\normalfont\sffamily\color{maincolor}} 162 | 163 | \addtokomafont{pagehead}{\normalfont\sffamily} % Also use sans serif font in header 164 | 165 | % Checkmarks 166 | \newcommand{\cmark}{\ding{51}}% 167 | \newcommand{\xmark}{\ding{55}}% 168 | 169 | % Use Computer Modern Symbols for mathcal 170 | \DeclareMathAlphabet{\mathcal}{OMS}{cmsy}{m}{n} 171 | \SetMathAlphabet{\mathcal}{bold}{OMS}{cmsy}{b}{n} 172 | 173 | % Fixes overful hboxes in references 174 | % see https://tex.stackexchange.com/questions/171999/overfull-hbox-in-biblatex 175 | \emergencystretch=1em 176 | 177 | 178 | % =================================================================== 179 | % REFERENCES 180 | % =================================================================== 181 | 182 | \usepackage{varioref} 183 | \usepackage{hyperref} 184 | \usepackage[capitalize,nameinlink,noabbrev]{cleveref} 185 | 186 | % Customization of hyperref options 187 | \hypersetup{ 188 | unicode, % Use unicode for links 189 | pdfborder={0 0 0}, % Suppress border around pdf 190 | bookmarksdepth=section, 191 | bookmarksopen=true, % Expand the bookmarks as soon as the pdf file is opened 192 | %bookmarksopenlevel=4, 193 | % linktoc=all, % Toc entries and numbers links to pages 194 | linktocpage=true, % Only the page number links to pages 195 | breaklinks=true, 196 | colorlinks=true, 197 | citecolor = thirdcolor, 198 | linkcolor = secondcolor, 199 | urlcolor = fourthcolor, 200 | } 201 | 202 | 203 | % =================================================================== 204 | % MATH 205 | % =================================================================== 206 | 207 | % Fix "Too many math alphabets" error (https://tex.stackexchange.com/a/243541) 208 | \newcommand\hmmax{0} 209 | \newcommand\bmmax{0} 210 | 211 | \usepackage{amsfonts} % blackboard math symbols 212 | \usepackage{amsmath} % for all basic math operations 213 | \usepackage{amssymb} 214 | \usepackage{nicefrac} % compact symbols for 1/2, etc. 215 | %\usepackage{ntheorem} % required by kaobook (otherwise \theoremstyle is not defined) 216 | \usepackage{siunitx} % SI units (used for run times) 217 | \usepackage{xfrac} % For slanted fractions "sfrac" like the nicefrac 218 | \usepackage{bm} % Offers \bm to create bold math (used by Goodfellow) 219 | \usepackage{derivative} % Handy commands for typesetting derivatives 220 | \usepackage{mathtools} % for vcentcolon a centered colon used in \eqdef 221 | % Load mathematical packages for theorems and related environments 222 | \usepackage[framed=true,definitionbackground=lightgraycolor!25,theorembackground=lightgraycolor!25, 223 | examplebackground=lightgraycolor!25]{preamble/kaotheorems} 224 | 225 | % Bugfix: https://tex.stackexchange.com/questions/262142/thmtools-notebraces-bug 226 | \makeatletter 227 | %%% from amsthm.sty 228 | \def\thmhead@plain#1#2#3{% 229 | \thmname{#1}\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}% 230 | %%% the line below had (##3) 231 | \thmnote{ {\the\thm@notefont\thm@lparen#3\thm@rparen}}} 232 | 233 | %%% from thm-amsthm.sty 234 | \def\thmt@setheadstyle#1{% 235 | \thmt@style@headstyle{% 236 | \def\NAME{\the\thm@headfont ##1}% 237 | \def\NUMBER{\bgroup\@upn{##2}\egroup}% 238 | %%% the line below had (##3) 239 | \def\NOTE{\if=##3=\else\bgroup\thmt@space\the\thm@notefont\thm@lparen##3\thm@rparen\egroup\fi}% 240 | }% 241 | \def\thmt@tmp{#1}% 242 | \@onelevel@sanitize\thmt@tmp 243 | %\tracingall 244 | \ifcsname thmt@headstyle@\thmt@tmp\endcsname 245 | \thmt@style@headstyle\@xa{% 246 | \the\thmt@style@headstyle 247 | \csname thmt@headstyle@#1\endcsname 248 | }% 249 | \else 250 | \thmt@style@headstyle\@xa{% 251 | \the\thmt@style@headstyle 252 | #1% 253 | }% 254 | \fi 255 | %\showthe\thmt@style@headstyle 256 | } 257 | %%% the line below had (#3) 258 | \def\thmt@embrace#1#2\thm@lparen#3\thm@rparen{#1#3#2} 259 | %%% added for default 260 | \def\thm@lparen{(}\def\thm@rparen{)} 261 | \makeatother 262 | 263 | \xspaceaddexceptions{]} 264 | 265 | % \declaretheoremstyle[ 266 | % %spaceabove=.5\thm@preskip, 267 | % %spacebelow=.5\thm@postskip, 268 | % %headfont=\normalfont\bfseries,%\scshape, 269 | % notefont=\bfseries, 270 | % notebraces={ [}{]}, 271 | % bodyfont=\normalfont, 272 | % %headformat={\NAME\space\NUMBER\space\NOTE}, 273 | % headpunct={}, 274 | % postheadspace=\newline, 275 | % %prefoothook={\hfill\qedsymbol} 276 | % ]{mytheoremstyle} 277 | 278 | % \theoremstyle{mytheoremstyle} 279 | % \declaretheorem[ 280 | % name=Definition, 281 | % %refname={definition,definitions}, 282 | % refname={Definition,Definitions}, 283 | % Refname={Definition,Definitions}, 284 | % numberwithin=section, 285 | % mdframed={ 286 | % style=mdfkao, 287 | % backgroundcolor=lightgraycolor!25, 288 | % %frametitlebackgroundcolor=\@theorembackground, 289 | % }, 290 | % ]{thesisdefinition} 291 | 292 | 293 | % \declaretheorem[name=Update Rule, 294 | % refname={update rule,update rules}, 295 | % Refname={Update Rule,Update Rules}, 296 | % numberwithin=section, 297 | % mdframed={ 298 | % style=mdfkao, 299 | % backgroundcolor=lightgraycolor!25, 300 | % % %frametitlebackgroundcolor=\@theorembackground, 301 | % }, 302 | % sibling=thesisdefinition]{thesisupdaterule} 303 | 304 | % \declaretheorem[ 305 | % name=Theorem, 306 | % refname={Theorem,Theorems}, 307 | % Refname={Theorem,Theorems}, 308 | % numberwithin=section, 309 | % mdframed={ 310 | % style=mdfkao, 311 | % backgroundcolor=lightgraycolor!25, 312 | % % %frametitlebackgroundcolor=\@theorembackground, 313 | % }, 314 | % sibling=thesisdefinition 315 | % ]{thesistheorem} 316 | 317 | % =================================================================== 318 | % CODE 319 | % !!! Important to keep this after the definition of fancybox package 320 | % as it otherwise will create a weird bug !!! 321 | 322 | % Inline code that looks similar to markdown inline code snippets 323 | \newcommand{\inlinecode}[1]{% 324 | \begin{tikzpicture}[baseline=0ex]% 325 | \node[anchor=base,% 326 | text height=1em,% 327 | text depth=1ex,% 328 | inner ysep=0pt,% 329 | draw=darkgraycolor!30!white,% 330 | fill=lightgraycolor!20!white,% 331 | rounded corners=2pt] at (0,0) {\footnotesize\texttt{#1}};% 332 | \end{tikzpicture}% 333 | } 334 | % TikZ code contains fragile commands which throws errors when used in captions 335 | % and section titles. This robust command can be used as drop-in 336 | % (https://tex.stackexchange.com/a/56081) 337 | \DeclareRobustCommand\robustInlinecode[1]{\inlinecode{#1}} 338 | 339 | \usepackage{listings} % For full code blocks 340 | 341 | \input{preamble/lstlinebgrd.tex} % Inclue lstlinebgrd (with some fixes) for highlighting code lines 342 | 343 | \lstdefinestyle{thesisstyle}{ 344 | backgroundcolor=\color{maincolor!5!white}, 345 | commentstyle=\bfseries\itshape\color{maincolor}, 346 | keywordstyle=\bfseries\color{maincolor}, 347 | numberstyle=\tiny\color{maincolor}, 348 | stringstyle=\bfseries\color{thirdcolor}, 349 | basicstyle=\ttfamily\footnotesize, 350 | xleftmargin=3.2ex, 351 | breakatwhitespace=false, 352 | breaklines=true, 353 | captionpos=t, 354 | keepspaces=true, 355 | numbers=left, 356 | numbersep=7pt, 357 | showspaces=false, 358 | showstringspaces=false, 359 | showtabs=false, 360 | tabsize=4, 361 | escapeinside={(@}{@)}, 362 | rulecolor=\color{maincolor}, 363 | } 364 | \lstset{style=thesisstyle} 365 | 366 | % =================================================================== 367 | % CITATION 368 | 369 | % CHANGE IN THE KAOBILBIO STYLE!!! 370 | % DO NOT CLEARFIELD FOR archivePrefix, arxivId, and eprint!!! 371 | % NEED TO DO THIS IF UPDATE THE KAOBOOK TEMPLATE!!! 372 | 373 | \usepackage[ 374 | bibstyle=numeric, % Use numeric citations in bibliography, e.g. [5] 375 | citestyle=numeric-comp, % Use compact numeric citations, e.g. [1-5,7] 376 | sorting=nyt, % Sort Bibliography by name then year then title (alternative: none=citation order) 377 | maxnames=99, % Show a maximum of 99 author names in Bibliography 378 | mincitenames=1, % Show at least two author names when citing ... 379 | maxcitenames=2, % ... But never more than two 380 | sortcites=true, % Automatically sort citations numerically, e.g. [5,1,3] -> [1,3,5] 381 | date=year, % Printed dates only show year 382 | abbreviate=false, % Don't abbreviate string such as editor -> ed. or Tech. rep. 383 | % Hide some information generally: 384 | isbn=false, 385 | doi=false, 386 | related=false, 387 | ]{preamble/kaobiblio} 388 | 389 | \usepackage{xpatch} % Patch to customize the look of the Bibliography 390 | 391 | \addbibresource{bibliography/bibliography.bib} % Bibliography file 392 | 393 | % Customize what appears in the margin citation (removed the ":") 394 | \renewcommand{\formatmargincitation}[1]{% 395 | \parencite{#1} \citeauthor*{#1} (\citeyear{#1}), \citetitle{#1}% 396 | } 397 | 398 | % A custom command for only creating a marginnote with the citation 399 | \newcommand{\onlysidecite}[2][]{\marginnote[#1]{% 400 | \parencite{#2} \citeauthor*{#2} (\citeyear{#2}), \citetitle{#2}% 401 | }} 402 | 403 | \renewbibmacro{in:}{} % Remove "in:" from Bibliography 404 | 405 | % Put quotes around the title of misc entries (e.g. arXiv papers) similar to "regular" paper 406 | \DeclareFieldFormat[misc,book,techreport]{citetitle}{\mkbibquote{#1\isdot}} 407 | \DeclareFieldFormat[misc,book,techreport]{title}{\mkbibquote{#1\isdot}} 408 | 409 | % Publisher in Book in italics (similar to paper) 410 | \DeclareListFormat{publisher}{% 411 | \usebibmacro{list:delim}{#1}% 412 | \mkbibemph{#1\isdot} 413 | \usebibmacro{list:andothers}} 414 | 415 | % Currently this is missing a period to seperate it from the rest! 416 | %% Remove paranthesis around the date of article 417 | %\renewbibmacro*{issue+date}{% 418 | % \printfield{issue}% 419 | % \setunit*{\addspace}% 420 | % \usebibmacro{date}% 421 | % \newunit} 422 | 423 | 424 | % =================================================================== 425 | % TABLES 426 | 427 | \usepackage{tabularx} % Tables with flexible column width 428 | \usepackage{multirow} % Allow cells spread over multiple rows 429 | \usepackage{colortbl} % define BG colors of cells via \cellcolor 430 | \usepackage{makecell} % Multi-lined tabular cells (used in DeepOBS results table) 431 | 432 | % Customization of makecell package 433 | \renewcommand{\cellalign}{tl} 434 | \renewcommand\theadalign{bc} 435 | \renewcommand\theadfont{\bfseries} 436 | \renewcommand\theadgape{\Gape[4pt]} 437 | \renewcommand\cellgape{\Gape[4pt]} 438 | 439 | % New columntypes for centering columns 440 | \newcolumntype{C}{>{\centering\arraybackslash}p{3cm}} 441 | \newcolumntype{Y}{>{\centering\arraybackslash}X} 442 | 443 | \newcolumntype{R}{>{\raggedleft\arraybackslash}X} 444 | 445 | 446 | % =================================================================== 447 | % TODONOTES 448 | 449 | \usepackage{blindtext} 450 | \usepackage{lipsum} 451 | \usepackage{xargs} % Use more than one optional parameter in a new commands 452 | 453 | \PassOptionsToPackage{colorinlistoftodos,prependcaption}{todonotes} 454 | \newcommandx{\unsure}[2][1=]{\todo[linecolor=secondcolor,backgroundcolor=secondcolor!25,bordercolor=secondcolor,size=\footnotesize,#1]{\textbf{Unsure:}\xspace#2}} 455 | \newcommandx{\change}[2][1=]{\todo[linecolor=maincolor,backgroundcolor=maincolor!25,bordercolor=maincolor,size=\footnotesize,#1]{\textbf{Change:}\xspace#2}} 456 | \newcommandx{\info}[2][1=]{\todo[linecolor=darkgraycolor,backgroundcolor=darkgraycolor!25,bordercolor=darkgraycolor,size=\footnotesize,#1]{\textbf{Info:}\xspace#2}} 457 | \newcommandx{\improvement}[2][1=]{\todo[linecolor=thirdcolor,backgroundcolor=thirdcolor!25,bordercolor=thirdcolor,size=\footnotesize,#1]{\textbf{Improve:}\xspace#2}} 458 | 459 | % =================================================================== 460 | % CUSTOMIZATIONS 461 | 462 | % Only show sections in margin TOC (don't show subsections, etc.) 463 | \setcounter{margintocdepth}{\sectiontocdepth} 464 | 465 | % Move section numbers in margin 466 | %\newcommand*{\numberinmargin}[1]{% 467 | % \makebox[0pt][r]{#1\autodot\hskip\marginparsep}} 468 | % 469 | %\renewcommand*{\sectionformat}{\numberinmargin{\textcolor{lightgraycolor}{\thesection}}} 470 | %\renewcommand*{\subsectionformat}{\numberinmargin{\textcolor{lightgraycolor}{\thesubsection}}} 471 | 472 | % OR 473 | % Color section number in gray 474 | \renewcommand*{\sectionformat}{\textcolor{maincolor}{\thesection}\enskip} 475 | \renewcommand*{\subsectionformat}{\textcolor{maincolor}{\thesubsection}\enskip} 476 | 477 | % Change style of the headers (chapter and section titles) 478 | \renewcommand*{\chaptermarkformat}{\textbf{\chapapp~\thechapter}\enskip\color{maincolor}} 479 | \renewcommand*{\sectionmarkformat}{\textbf{\thesection}\enskip\color{maincolor}} 480 | 481 | % Call TOC "Table of Contents" instead of "Contents" 482 | \addto\captionsenglish{% Replace "english" with the language you use 483 | \renewcommand{\contentsname}% 484 | {Table of Contents}% 485 | } 486 | 487 | % TOC Style of Parts (add color) 488 | \newcommand\tocpartstyle[1] 489 | {\scshape\large\bfseries\textcolor{maincolor}{#1}} 490 | \DeclareTOCStyleEntries[pagenumberwidth=2.5em, entryformat=\tocpartstyle]{tocline}{part}% 491 | 492 | % Rename Listing to Algorithm 493 | \renewcommand{\lstlistingname}{Procedure}% Listing -> Procedure 494 | \crefname{listing}{procedure}{Procedure} 495 | 496 | 497 | % =================================================================== 498 | % OTHER (ordered here for special reasons) 499 | 500 | \usepackage{csquotes} % English quotes 501 | \usepackage{scrhack} 502 | \usepackage{xurl} % Allow line-breaks in URLs (loaded after biblatex) 503 | 504 | % =================================================================== 505 | % INPUT 506 | 507 | \input{preamble/hyphenations} % Custom hyphenations 508 | \input{preamble/commands} % General Abbreviations, code envs, etc. 509 | \input{preamble/math_commands} % Math Commands from the Deep Learning book 510 | 511 | % =================================================================== 512 | % HOTFIXES 513 | \renewcommand*{\figureformat}{% 514 | \figurename~\thefigure% 515 | % \autodot% DELETED 516 | } 517 | \renewcommand*{\tableformat}{% 518 | \tablename~\thetable% 519 | % \autodot% DELETED 520 | } 521 | 522 | %%% Local Variables: 523 | %%% mode: latex 524 | %%% TeX-master: "../thesis" 525 | %%% End: 526 | -------------------------------------------------------------------------------- /preamble/kao.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{preamble/kao} 2 | 3 | %---------------------------------------------------------------------------------------- 4 | % KAO-SPECIFIC OPTIONS 5 | %---------------------------------------------------------------------------------------- 6 | 7 | \DefineFamily{kao}% Define the family name 8 | \DefineFamilyMember{kao}% Add a member to the family 9 | \DefineFamilyKey{kao}{secnumdepth}[1]{\setcounter{secnumdepth}{#1}\FamilyKeyStateProcessed}% Define a key and a default value 10 | \FamilyProcessOptions{kao}% Process the options 11 | 12 | %---------------------------------------------------------------------------------------- 13 | % USEFUL PACKAGES AND COMMANDS 14 | %---------------------------------------------------------------------------------------- 15 | 16 | \RequirePackage{etoolbox} % Easy programming to modify TeX stuff 17 | \RequirePackage{calc} % Make calculations 18 | \RequirePackage[usenames,dvipsnames,table]{xcolor} % Colours 19 | \RequirePackage{iftex} % Check wether XeTeX is being used 20 | \RequirePackage{xifthen} % Easy conditionals 21 | \RequirePackage{options} % Manage class options 22 | \RequirePackage{xparse} % Parse arguments for macros 23 | \RequirePackage{xpatch} % Patch LaTeX code in external packages 24 | \RequirePackage{xstring} % Parse strings 25 | \RequirePackage{afterpage} % Run commands after specific pages 26 | \RequirePackage{imakeidx} % For the index; must be loaded before the 'caption' and 'hyperref' packages 27 | \RequirePackage{varioref} % For the cross-references; must be loaded before the 'hyperref' and 'cleveref' packages 28 | \AtEndPreamble{\RequirePackage{scrhack}} % Make some packages compatible with KOMAScript 29 | 30 | % Define \Ifthispageodd (with a capital 'i') to make kaobook compatible with older KOMAScript versions 31 | \@ifpackagelater{scrbase}{2019/12/22}{% 32 | }{% 33 | \let\Ifthispageodd\ifthispageodd% 34 | } 35 | 36 | 37 | %---------------------------------------------------------------------------------------- 38 | % TITLE AND AUTHOR MACROS 39 | %---------------------------------------------------------------------------------------- 40 | 41 | % Provide an optional argument to the \title command in which to store a plain text title, without any formatting 42 | % Usage: \title[Plain Title]{Actual Title} 43 | \newcommand{\@plaintitle}{} 44 | \renewcommand{\title}[2][]{% 45 | \gdef\@title{#2} % Store the full title in @title 46 | \ifthenelse{\isempty{#1}}{ % If there is no plain title 47 | \renewcommand{\@plaintitle}{\@title} % Use full title 48 | }{ % If there is a plain title 49 | \renewcommand{\@plaintitle}{#1} % Use provided plain-text title 50 | }% 51 | \hypersetup{pdftitle={\@plaintitle}} % Set the PDF metadata title 52 | } 53 | 54 | % Provide an optional argument to the \author command in which to store a plain text author, without any formatting 55 | % Usage: \author[Plain Author]{Actual Author} 56 | \newcommand{\@plainauthor}{} 57 | \renewcommand{\author}[2][]{% 58 | \gdef\@author{#2} % Store the full author in @author 59 | \ifthenelse{\isempty{#1}}{ % If there is no plain author 60 | \renewcommand{\@plainauthor}{\@author}% Use full author 61 | }{ % If there is a plain author 62 | \renewcommand{\@plainauthor}{#1}% Use provided plain-text author 63 | }% 64 | \hypersetup{pdfauthor={\@plainauthor}} % Set the PDF metadata author 65 | } 66 | 67 | % Make a bookmark to the title page 68 | \pretocmd{\maketitle}{\pdfbookmark[1]{\@plaintitle}{title}}{}{}% 69 | 70 | %---------------------------------------------------------------------------------------- 71 | % PAGE LAYOUT 72 | %---------------------------------------------------------------------------------------- 73 | 74 | % Define lengths to set the scale of the document. Changing these 75 | % lengths should affect all the other pagesize-dependent elements in the 76 | % layout, such as the geometry of the page, the spacing between 77 | % paragraphs, and so on. (As of now, not all the elements rely on hscale 78 | % and vscale; future work will address this shortcoming.) 79 | \newlength{\hscale} 80 | \newlength{\vscale} 81 | 82 | % By default, the scales are set to work for a4paper 83 | \setlength{\hscale}{1mm} 84 | \setlength{\vscale}{1mm} 85 | 86 | % Define hscale and vscale for all types of paper 87 | \@ifclasswith{\@baseclass}{a0paper}{\setlength{\hscale}{4mm}\setlength{\vscale}{4mm}}{} 88 | \@ifclasswith{\@baseclass}{a1paper}{\setlength{\hscale}{2.828mm}\setlength{\vscale}{2.828mm}}{} 89 | \@ifclasswith{\@baseclass}{a2paper}{\setlength{\hscale}{2mm}\setlength{\vscale}{2mm}}{} 90 | \@ifclasswith{\@baseclass}{a3paper}{\setlength{\hscale}{1.414mm}\setlength{\vscale}{1.414mm}}{} 91 | \@ifclasswith{\@baseclass}{a4paper}{\setlength{\hscale}{1mm}\setlength{\vscale}{1mm}}{} 92 | \@ifclasswith{\@baseclass}{a5paper}{\setlength{\hscale}{0.704mm}\setlength{\vscale}{0.704mm}}{} 93 | \@ifclasswith{\@baseclass}{a6paper}{\setlength{\hscale}{0.5mm}\setlength{\vscale}{0.5mm}}{} 94 | \@ifclasswith{\@baseclass}{b0paper}{\setlength{\hscale}{4.761mm}\setlength{\vscale}{4.761mm}}{} 95 | \@ifclasswith{\@baseclass}{b1paper}{\setlength{\hscale}{3.367mm}\setlength{\vscale}{3.367mm}}{} 96 | \@ifclasswith{\@baseclass}{b2paper}{\setlength{\hscale}{2.380mm}\setlength{\vscale}{2.380mm}}{} 97 | \@ifclasswith{\@baseclass}{b3paper}{\setlength{\hscale}{1.681mm}\setlength{\vscale}{1.681mm}}{} 98 | \@ifclasswith{\@baseclass}{b4paper}{\setlength{\hscale}{1.190mm}\setlength{\vscale}{1.190mm}}{} 99 | \@ifclasswith{\@baseclass}{b5paper}{\setlength{\hscale}{0.837mm}\setlength{\vscale}{0.837mm}}{} 100 | \@ifclasswith{\@baseclass}{b6paper}{\setlength{\hscale}{0.570mm}\setlength{\vscale}{0.570mm}}{} 101 | \@ifclasswith{\@baseclass}{c0paper}{\setlength{\hscale}{4.367mm}\setlength{\vscale}{4.367mm}}{} 102 | \@ifclasswith{\@baseclass}{c1paper}{\setlength{\hscale}{3.085mm}\setlength{\vscale}{3.085mm}}{} 103 | \@ifclasswith{\@baseclass}{c2paper}{\setlength{\hscale}{2.180mm}\setlength{\vscale}{2.180mm}}{} 104 | \@ifclasswith{\@baseclass}{c3paper}{\setlength{\hscale}{1.542mm}\setlength{\vscale}{1.542mm}}{} 105 | \@ifclasswith{\@baseclass}{c4paper}{\setlength{\hscale}{1.090mm}\setlength{\vscale}{1.090mm}}{} 106 | \@ifclasswith{\@baseclass}{c5paper}{\setlength{\hscale}{0.771mm}\setlength{\vscale}{0.771mm}}{} 107 | \@ifclasswith{\@baseclass}{c6paper}{\setlength{\hscale}{0.542mm}\setlength{\vscale}{0.542mm}}{} 108 | \@ifclasswith{\@baseclass}{b0j}{\setlength{\hscale}{4.904mm}\setlength{\vscale}{4.904mm}}{} 109 | \@ifclasswith{\@baseclass}{b1j}{\setlength{\hscale}{3.467mm}\setlength{\vscale}{3.467mm}}{} 110 | \@ifclasswith{\@baseclass}{b2j}{\setlength{\hscale}{2.452mm}\setlength{\vscale}{2.452mm}}{} 111 | \@ifclasswith{\@baseclass}{b3j}{\setlength{\hscale}{1.733mm}\setlength{\vscale}{1.733mm}}{} 112 | \@ifclasswith{\@baseclass}{b4j}{\setlength{\hscale}{1.226mm}\setlength{\vscale}{1.226mm}}{} 113 | \@ifclasswith{\@baseclass}{b5j}{\setlength{\hscale}{0.867mm}\setlength{\vscale}{0.867mm}}{} 114 | \@ifclasswith{\@baseclass}{b6j}{\setlength{\hscale}{0.613mm}\setlength{\vscale}{0.613mm}}{} 115 | \@ifclasswith{\@baseclass}{ansiapaper}{\setlength{\hscale}{1.028mm}\setlength{\vscale}{0.939mm}}{} 116 | \@ifclasswith{\@baseclass}{ansibpaper}{\setlength{\hscale}{1.328mm}\setlength{\vscale}{1.454mm}}{} 117 | \@ifclasswith{\@baseclass}{ansicpaper}{\setlength{\hscale}{2.057mm}\setlength{\vscale}{1.882mm}}{} 118 | \@ifclasswith{\@baseclass}{ansidpaper}{\setlength{\hscale}{2.662mm}\setlength{\vscale}{2.909mm}}{} 119 | \@ifclasswith{\@baseclass}{ansiepaper}{\setlength{\hscale}{4.114mm}\setlength{\vscale}{3.764mm}}{} 120 | \@ifclasswith{\@baseclass}{letterpaper}{\setlength{\hscale}{1.028mm}\setlength{\vscale}{0.939mm}}{} 121 | \@ifclasswith{\@baseclass}{executivepaper}{\setlength{\hscale}{0.876mm}\setlength{\vscale}{0.898mm}}{} 122 | \@ifclasswith{\@baseclass}{legalpaper}{\setlength{\hscale}{1.028mm}\setlength{\vscale}{1.198mm}}{} 123 | \@ifclasswith{\@baseclass}{smallpocketpaper}{\setlength{\hscale}{0.571mm}\setlength{\vscale}{0.639mm}}{} 124 | \@ifclasswith{\@baseclass}{pocketpaper}{\setlength{\hscale}{0.642mm}\setlength{\vscale}{0.723mm}}{} 125 | \@ifclasswith{\@baseclass}{juvenilepaper}{\setlength{\hscale}{0.738mm}\setlength{\vscale}{0.740mm}}{} 126 | \@ifclasswith{\@baseclass}{smallphotopaper}{\setlength{\hscale}{0.809mm}\setlength{\vscale}{0.572mm}}{} 127 | \@ifclasswith{\@baseclass}{photopaper}{\setlength{\hscale}{1.00mm}\setlength{\vscale}{0.707mm}}{} 128 | \@ifclasswith{\@baseclass}{appendixpaper}{\setlength{\hscale}{1.000mm}\setlength{\vscale}{0.505mm}}{} 129 | \@ifclasswith{\@baseclass}{cookpaper}{\setlength{\hscale}{0.809mm}\setlength{\vscale}{0.740mm}}{} 130 | \@ifclasswith{\@baseclass}{illustratedpaper}{\setlength{\hscale}{0.905mm}\setlength{\vscale}{0.909mm}}{} 131 | \@ifclasswith{\@baseclass}{f24paper}{\setlength{\hscale}{0.762mm}\setlength{\vscale}{0.808mm}}{} 132 | \@ifclasswith{\@baseclass}{a4paperlandscape}{\setlength{\hscale}{1.414mm}\setlength{\vscale}{0.707mm}}{} 133 | 134 | % Set the default page layout 135 | \RequirePackage[ 136 | paperwidth=210\hscale, 137 | paperheight=297\vscale, 138 | ]{geometry} 139 | 140 | % Command to choose among the three possible layouts 141 | \DeclareDocumentCommand{\pagelayout}{m}{% 142 | \ifthenelse{\equal{margin}{#1}}{\marginlayout\marginfloatsetup}{}% 143 | \ifthenelse{\equal{wide}{#1}}{\widelayout\widefloatsetup}{}% 144 | \ifthenelse{\equal{fullwidth}{#1}}{\fullwidthlayout\widefloatsetup}{}% 145 | } 146 | 147 | \newif\ifwidelayout% 148 | \def\IfWideLayout{% 149 | \ifwidelayout% 150 | \expandafter\@firstoftwo% 151 | \else% 152 | \expandafter\@secondoftwo% 153 | \fi% 154 | } 155 | 156 | % Layout #1: large margins 157 | \newcommand{\marginlayout}{% 158 | \newgeometry{ 159 | top=27.4\vscale, 160 | bottom=27.4\vscale, 161 | inner=24.8\hscale, 162 | textwidth=107\hscale, 163 | marginparsep=6.2\hscale, 164 | marginparwidth=47.7\hscale, 165 | }% 166 | \recalchead% 167 | \widelayoutfalse% 168 | } 169 | 170 | % Layout #2: small, symmetric margins 171 | \newcommand{\widelayout}{% 172 | \newgeometry{ 173 | top=27.4\vscale, 174 | bottom=27.4\vscale, 175 | inner=24.8\hscale, 176 | outer=24.8\hscale, 177 | marginparsep=0mm, 178 | marginparwidth=0mm, 179 | }% 180 | \recalchead% 181 | \widelayouttrue% 182 | } 183 | 184 | % Layout #3: no margins and no space above or below the body 185 | \newcommand{\fullwidthpage}{% 186 | \newgeometry{ 187 | top=0mm, 188 | bottom=0mm, 189 | inner=0mm, 190 | outer=0mm, 191 | marginparwidth=0mm, 192 | marginparsep=0mm, 193 | }% 194 | \recalchead% 195 | \widelayouttrue% 196 | } 197 | 198 | % Set the default page layout 199 | \AtBeginDocument{\pagelayout{margin}} 200 | 201 | %---------------------------------------------------------------------------------------- 202 | % HEADERS AND FOOTERS 203 | %---------------------------------------------------------------------------------------- 204 | 205 | \RequirePackage{scrlayer-scrpage} % Customise head and foot regions 206 | 207 | % Set the header height to prevent a warning 208 | %\setlength{\headheight}{27.4\vscale} 209 | % Increase the space between header and text 210 | \setlength{\headsep}{11\vscale} 211 | 212 | % Define some LaTeX lengths used in the page headers 213 | \newlength{\headtextwidth} % This is the width of the text 214 | \newlength{\headmarginparsep} % This is the width of the whitespace between text and margin 215 | \newlength{\headmarginparwidth} % This is the width of the margin 216 | \newlength{\headtotal} % This is the total width of the header 217 | \newlength{\contentwidth} % An alias for \headtotal 218 | \newcommand{\recalchead}{% Command to recalculate the header-related length when needed 219 | \setlength{\headtextwidth}{\textwidth}% 220 | \setlength{\headmarginparsep}{\marginparsep}% 221 | \setlength{\headmarginparwidth}{\marginparwidth}% 222 | \setlength{\headtotal}{\headtextwidth+\headmarginparsep+\headmarginparwidth}% 223 | \setlength{\contentwidth}{\headtotal}% 224 | } 225 | 226 | \AtBeginDocument{% Recalculate the header-related lengths 227 | \recalchead% 228 | } 229 | 230 | % Header style with chapter number, chapter title, and page in the header (used throughout the document) 231 | \renewpagestyle{scrheadings}{% 232 | {\smash{\hspace{-\headmarginparwidth}\hspace{-\headmarginparsep}\makebox[\headtotal][l]{% 233 | \makebox[7\hscale][r]{\thepage}% 234 | \makebox[3\hscale]{}\rule[-1mm]{0.5pt}{19\vscale-1mm}\makebox[3\hscale]{}% 235 | \makebox[\headtextwidth][l]{\leftmark}}}}% 236 | {\smash{\makebox[0pt][l]{\makebox[\headtotal][r]{% 237 | \makebox[\headtextwidth][r]{\hfill\rightmark}% 238 | \makebox[3\hscale]{}\rule[-1mm]{0.5pt}{19\vscale-1mm}\makebox[3\hscale]{}% 239 | \makebox[7\hscale][l]{\thepage}}}}}% 240 | {\smash{\makebox[0pt][l]{\makebox[\headtotal][r]{% 241 | \makebox[\headtextwidth][r]{\hfill\rightmark}% 242 | \makebox[3\hscale]{}\rule[-1mm]{0.5pt}{19\vscale-1mm}\makebox[3\hscale]{}% 243 | \makebox[7\hscale][l]{\thepage}}}}}% 244 | }{% 245 | {}% 246 | {}% 247 | {}% 248 | } 249 | 250 | % Header style with neither header nor footer (used for special pages) 251 | \renewpagestyle{plain.scrheadings}{% 252 | {}% 253 | {}% 254 | {}% 255 | }{% 256 | {}% 257 | {}% 258 | {}% 259 | } 260 | 261 | % Header style with an empty header and the page number in the footer 262 | \newpagestyle{pagenum.scrheadings}{% 263 | {}% 264 | {}% 265 | {}% 266 | }{% 267 | {\makebox[\textwidth][r]{\thepage}}% 268 | {\makebox[\textwidth][l]{\thepage}}% 269 | {\makebox[\textwidth][l]{\thepage}}% 270 | } 271 | 272 | % Header style with an empty header and the page number in the footer 273 | \newpagestyle{centeredpagenum.scrheadings}{% 274 | {}% 275 | {}% 276 | {}% 277 | }{% 278 | {\hspace{-\headmarginparwidth}\hspace{-\headmarginparsep}\makebox[\headtotal][l]{\hfill\thepage\hfill}} 279 | {\makebox[0pt][l]{\makebox[\headtotal][r]{\hfill\thepage\hfill}}}% 280 | {\makebox[0pt][l]{\makebox[\headtotal][r]{\hfill\thepage\hfill}}}% 281 | } 282 | 283 | % Command to print a blank page 284 | \newcommand\blankpage{% 285 | \null% 286 | \thispagestyle{empty}% 287 | \newpage% 288 | } 289 | 290 | % Set the default page style 291 | \pagestyle{plain.scrheadings} 292 | 293 | %---------------------------------------------------------------------------------------- 294 | % PARAGRAPH FORMATTING 295 | %---------------------------------------------------------------------------------------- 296 | 297 | \RequirePackage{ragged2e} % Required to achieve better ragged paragraphs 298 | \RequirePackage{setspace} % Required to easily set the space between lines 299 | \RequirePackage{hyphenat} % Hyphenation for special fonts 300 | \RequirePackage{microtype} % Improves character and word spacing 301 | \RequirePackage{needspace} % Required to prevent page break right after a sectioning command 302 | \RequirePackage{xspace} % Better print trailing whitespace 303 | 304 | % TODO: recognize space/indent justified/raggedright class options 305 | 306 | % Settings for a normal paragraph 307 | \newcommand{\@body@par}{% 308 | \justifying% Justify text 309 | \singlespacing% Set the interline space to a single line 310 | \frenchspacing% No additional space after periods 311 | \normalfont% Use the default font 312 | \normalsize% Use the default size 313 | } 314 | 315 | % Settings for paragraphs in the margins 316 | \newcommand{\@margin@par}{% 317 | \justifying% justify text 318 | \setlength{\RaggedRightParindent}{0em}% Suppress indentation 319 | \setlength{\parindent}{0em}% Suppress indentation 320 | \setlength{\parskip}{0.5pc}% Set the space between paragraphs 321 | %\singlespacing% Set the space between lines 322 | \frenchspacing% No additional space after periods 323 | \normalfont% Use the default font 324 | \footnotesize% Use a smaller size 325 | } 326 | 327 | % By default, use @body@par settings 328 | \@body@par 329 | 330 | %---------------------------------------------------------------------------------------- 331 | % WIDE PARAGRAPHS 332 | %---------------------------------------------------------------------------------------- 333 | 334 | % Environment for a wide paragraph 335 | \NewDocumentEnvironment{widepar}{}{% 336 | \if@twoside% 337 | \Ifthispageodd{% 338 | \begin{addmargin}[0cm]{-\marginparwidth-\marginparsep}% 339 | }{% 340 | \begin{addmargin}[-\marginparwidth-\marginparsep]{0cm}% 341 | }% 342 | \else% 343 | \begin{addmargin}[0cm]{-\marginparwidth-\marginparsep}% 344 | \fi% 345 | }{% 346 | \end{addmargin}% 347 | } 348 | 349 | % Environment for a full width paragraph 350 | \NewDocumentEnvironment{fullwidthpar}{}{% 351 | \if@twoside% 352 | \Ifthispageodd{% 353 | \begin{addmargin}[-1in-\hoffset-\oddsidemargin]{-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth}% 354 | }{% 355 | \begin{addmargin}[-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth]{-\paperwidth+1in+\hoffset+\oddsidemargin+\marginparsep+\marginparwidth+\textwidth}% 356 | }% 357 | \else% 358 | \begin{addmargin}[-1in-\hoffset-\oddsidemargin]{-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth}% 359 | \fi% 360 | }{% 361 | \end{addmargin}% 362 | } 363 | 364 | % Environment for a wide equation 365 | \NewDocumentEnvironment{wideequation}{}{% 366 | \begin{widepar}% 367 | \begin{equation}% 368 | }{% 369 | \end{equation}% 370 | \end{widepar}% 371 | } 372 | 373 | %---------------------------------------------------------------------------------------- 374 | % FOOTNOTES, MARGINNOTES AND SIDENOTES 375 | %---------------------------------------------------------------------------------------- 376 | 377 | \RequirePackage[section]{placeins} % Prevent floats to cross sections 378 | \extrafloats{100} % Require more floats 379 | 380 | \RequirePackage{marginnote} % Provides options for margin notes 381 | %\RequirePackage{marginfix} % Make marginpars float freely; it should not be loaded as it prevents the marginnotes to stay aligned with the main text 382 | \RequirePackage{sidenotes} % Use sidenotes 383 | \RequirePackage{chngcntr} % Reset counters at sections 384 | 385 | % TODO: see also page 440 of the KOMA-script guide 386 | \RequirePackage[ 387 | bottom, 388 | symbol*, 389 | hang, 390 | flushmargin, 391 | % perpage, 392 | stable, 393 | ]{footmisc} % Required to set up the footnotes 394 | \RequirePackage{footnotebackref} % Creates back references from footnotes to text 395 | 396 | % Fix the color of the footnote marker when back-referenced 397 | \patchcmd{\footref}{\ref}{\hypersetup{colorlinks=black}\ref}{}{}% 398 | % Workaround to fix back references 399 | \edef\BackrefFootnoteTag{bhfn:\theBackrefHyperFootnoteCounter}% 400 | 401 | % FIXME: I am not able to choose the paragraph layout of footnotes, probably the footnotes package conflicts with scrbook. 402 | %\renewcommand{\footnotelayout}{\@margin@par} 403 | 404 | %---------------------------------------------------------------------------------------- 405 | 406 | % Justify and format margin notes 407 | \renewcommand*{\raggedleftmarginnote}{} % Suppress left margin 408 | \renewcommand*{\raggedrightmarginnote}{} % Suppress right margin 409 | \renewcommand*{\marginfont}{\@margin@par} % Format marginnotes according to \@marginpar (see above) 410 | \renewcommand{\marginnotevadjust}{0.8\vscale} % Bring all marginnotes downwards a bit 411 | %\marginposadjustment=1\vscale % Bring downwards also the marginpars 412 | %\marginheightadjustment=10cm % Adjust the height of the margins for each page 413 | %\RequirePackage[marginnote=true]{snotez} % Provides options for sidenotes 414 | 415 | % Copied from snotez's \sidenote 416 | \def\kao@if@nblskip#1{% 417 | \expandafter\ifx\@car#1\@nil*% 418 | \expandafter\@firstoftwo% 419 | \else% 420 | \expandafter\@secondoftwo% 421 | \fi% 422 | } 423 | 424 | % Command to detect whether we are inside an mdframed environment 425 | \newif\ifinfloat % First, set this flag whenever we are in an mdframed environment... 426 | \AtBeginEnvironment{mdframed}{\infloattrue} 427 | \AtBeginEnvironment{minipage}{\infloattrue} 428 | 429 | \def\IfInFloatingEnvir{% ...Then, detect the flag 430 | \ifinfloat% 431 | \expandafter\@firstoftwo% 432 | \else% 433 | \expandafter\@secondoftwo% 434 | \fi% 435 | } 436 | 437 | 438 | % Redefine the command to print marginnotes: 439 | % (a) the optional offset argument goes at the first position 440 | % (b) the offset can also be a multiple of baselineskip, like for snotez's \sidenote 441 | % Usage: \marginnote[]{Text of the note.} 442 | \let\oldmarginnote\marginnote% 443 | \RenewDocumentCommand\marginnote{ o m }{% 444 | \IfNoValueOrEmptyTF{#1}{% 445 | \IfInFloatingEnvir{% 446 | \oldmarginnote{#2}% 447 | }{% 448 | \marginpar{\@margin@par#2}% 449 | }% 450 | }{% 451 | \oldmarginnote{#2}[\kao@if@nblskip{#1}{\@cdr#1\@nil\baselineskip}{#1}]% 452 | }% 453 | } 454 | 455 | % Initially set the sidenote counter to zero instead of 1, and update it before printing the sidenote. 456 | \setcounter{sidenote}{0}% 457 | \RenewDocumentCommand\sidenote{ o o +m }{% 458 | \IfNoValueOrEmptyTF{#1}{% 459 | \refstepcounter{sidenote}% This command has been moved here 460 | }{% 461 | }% 462 | \sidenotemark[#1]% 463 | \sidenotetext[#1][#2]{#3}% 464 | \@sidenotes@multimarker% 465 | } 466 | 467 | % Formatting sidenote markers 468 | \RenewDocumentCommand\@sidenotes@thesidenotemark{ m }{% Format the marker 469 | \leavevmode% 470 | \ifhmode% 471 | \edef\@x@sf{\the\spacefactor}% 472 | \nobreak% 473 | \fi% 474 | \hbox{\@textsuperscript{\normalfont#1}}% 475 | \ifhmode% 476 | \spacefactor\@x@sf% 477 | \fi% 478 | \relax% 479 | }% 480 | 481 | % Formatting the sidenote text 482 | \RenewDocumentCommand\sidenotetext{ o o +m }{% number, offset, text 483 | \IfNoValueOrEmptyTF{#1}{% 484 | \marginnote[#2]{\thesidenote:\enskip#3}% 485 | }{% 486 | \marginnote[#2]{#1:\enskip#3}% 487 | }% 488 | } 489 | 490 | %---------------------------------------------------------------------------------------- 491 | % FIGURES, TABLES, LISTINGS AND CAPTIONS 492 | %---------------------------------------------------------------------------------------- 493 | 494 | \RequirePackage{graphicx} % Include figures 495 | \setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio} % Improves figure scaling 496 | \RequirePackage{tikz} % Allows to draw custom shapes 497 | \RequirePackage{tikzpagenodes} % Allows to anchor tikz nodes to page elements 498 | \RequirePackage{booktabs} % Nicer tables 499 | \RequirePackage{multirow} % Cells occupying multiple rows in tables 500 | \RequirePackage{multicol} % Multiple columns in dictionary 501 | \RequirePackage{rotating} % Allows tables and figures to be rotated 502 | \RequirePackage{listings} % Print code listings 503 | %\RequirePackage{minted} 504 | \RequirePackage[hypcap=true]{caption} % Correctly placed anchors for hyperlinks 505 | % \RequirePackage{atbegshi} 506 | % \RequirePackage{perpage} 507 | \let\c@abspage\relax 508 | % \newcommand{\pp@g@sidenote}{} 509 | \RequirePackage{floatrow} % Set up captions of floats 510 | %\RequirePackage{dblfloatfix} % Better positioning of wide figures and tables 511 | 512 | % Improve the figure placing (see https://www.overleaf.com/learn/latex/Tips) 513 | \def\topfraction{.9}% 514 | \def\textfraction{0.35}% 515 | \def\floatpagefraction{0.8}% 516 | 517 | % Set the space between floats and main text 518 | \renewcommand\FBaskip{.4\topskip}% 519 | \renewcommand\FBbskip{\FBaskip}% 520 | 521 | % Tighten up space between displays (e.g., equations) and make symmetric (from tufte-latex) 522 | \setlength\abovedisplayskip{6pt plus 2pt minus 4pt}% 523 | \setlength\belowdisplayskip{6pt plus 2pt minus 4pt}% 524 | \abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@% 525 | \abovedisplayshortskip \z@ \@plus3\p@% 526 | \belowdisplayskip \abovedisplayskip% 527 | \belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@% 528 | 529 | \setlength\columnseprule{.4pt} % Set the width of vertical rules in tables 530 | 531 | % The marginfix package prevents the margin notes to stay aligned with the main text, so it cannot be used. However, we define the \marginskip command, which is the only command we need from that package. 532 | \newcommand\marginskip[1]{% 533 | \marginpar{\@margin@par\vspace{#1 - \baselineskip}}% We subtract the \baselineskip that we have in margin pars. 534 | } 535 | 536 | \newlength{\kaomarginskipabove} % Specify the space above a marginfigure, margintable or marginlisting 537 | \newlength{\kaomarginskipbelow} % Specify the space below a marginfigure, margintable or marginlisting 538 | \setlength{\kaomarginskipabove}{3mm plus 2pt minus 2pt} 539 | \setlength{\kaomarginskipbelow}{3mm plus 2pt minus 2pt} 540 | 541 | % Environment to hold a margin figure (from the sidenotes package) 542 | % We redefine it here because we want to use our own caption formatting. 543 | \RenewDocumentEnvironment{marginfigure}{o}{% 544 | \FloatBarrier% 545 | \marginskip{\kaomarginskipabove}% 546 | \begin{lrbox}{\@sidenotes@marginfigurebox}% 547 | \begin{minipage}{\marginparwidth}% 548 | \captionsetup{type=figure}% 549 | }{% 550 | \end{minipage}% 551 | \end{lrbox}% 552 | \marginnote[#1]{\usebox{\@sidenotes@marginfigurebox}}% 553 | \marginskip{\kaomarginskipbelow}% 554 | } 555 | 556 | % Environment to hold a margin table (from the sidenotes package) 557 | \RenewDocumentEnvironment{margintable}{o}{% 558 | \FloatBarrier% 559 | \marginskip{\kaomarginskipabove}% 560 | \begin{lrbox}{\@sidenotes@margintablebox}% 561 | \begin{minipage}{\marginparwidth}% 562 | \captionsetup{type=table}% 563 | }{% 564 | \end{minipage}% 565 | \end{lrbox}% 566 | \marginnote[#1]{\usebox{\@sidenotes@margintablebox}}% 567 | \marginskip{\kaomarginskipbelow}% 568 | } 569 | 570 | % Environment to hold a margin listing 571 | \newsavebox{\@sidenotes@marginlistingbox}% 572 | \NewDocumentEnvironment{marginlisting}{o}{% The optional parameter is the vertical offset 573 | \FloatBarrier% 574 | \marginskip{\kaomarginskipabove}% 575 | \begin{lrbox}{\@sidenotes@marginlistingbox}% 576 | \begin{minipage}{\marginparwidth}% 577 | \captionsetup{type=lstlisting}% 578 | }{% 579 | \end{minipage}% 580 | \end{lrbox}% 581 | \marginnote[#1]{\usebox{\@sidenotes@marginlistingbox}}% 582 | \marginskip{\kaomarginskipbelow}% 583 | } 584 | 585 | % Change the position of the captions 586 | \DeclareFloatSeparators{marginparsep}{\hskip\marginparsep}% 587 | 588 | % Detect whether there is a caption in the current environment by switching the kaocaption toggle when \caption is called. If there is no caption, reset the floatsetup. Without this fix, the floatrow package will align the environment to the main text if there is a caption, but to the margin if there is no caption. 589 | \newtoggle{kaocaption} 590 | \AtBeginEnvironment{figure}{% 591 | \let\oldcaption\caption% 592 | \RenewDocumentCommand{\caption}{s o m}{% 593 | \IfBooleanTF{#1}{% 594 | \oldcaption*{#3}% 595 | }{% 596 | \IfValueTF{#2}{% 597 | \oldcaption[#2]{#3}% 598 | }{% 599 | \oldcaption{#3}% 600 | }% 601 | }% 602 | \toggletrue{kaocaption}% 603 | }% 604 | } 605 | \AtEndEnvironment{figure}{% 606 | \iftoggle{kaocaption}{% 607 | }{% 608 | \RawFloats% 609 | \centering% 610 | }% 611 | \togglefalse{kaocaption}% 612 | } 613 | \AtBeginEnvironment{table}{% 614 | \let\oldcaption\caption% 615 | \RenewDocumentCommand{\caption}{s o m}{% 616 | \IfBooleanTF{#1}{% 617 | \oldcaption*{#3}% 618 | }{% 619 | \IfValueTF{#2}{% 620 | \oldcaption[#2]{#3}% 621 | }{% 622 | \oldcaption{#3}% 623 | }% 624 | }% 625 | \toggletrue{kaocaption}% 626 | }% 627 | } 628 | \AtEndEnvironment{table}{% 629 | \iftoggle{kaocaption}{% 630 | }{% 631 | \RawFloats% 632 | \centering% 633 | }% 634 | \togglefalse{kaocaption}% 635 | } 636 | 637 | % Change the formatting of the captions 638 | \addtokomafont{captionlabel}{\bfseries} % Bold font for the figure label 639 | % Declare a new style to format the caption according to \@margin@par (see above) 640 | \DeclareCaptionFormat{margin}{\@margin@par #1#2#3} 641 | % Declare a new caption style for lstlistings 642 | \newsavebox\mycap 643 | \DeclareCaptionFormat{llap}{% 644 | \begin{lrbox}{\mycap}% 645 | \begin{minipage}{\marginparwidth}% 646 | \@margin@par #1:#2#3% 647 | \end{minipage}% 648 | \end{lrbox}% 649 | \marginnote[0.2cm]{\usebox\mycap}% 650 | } 651 | % Set the global caption style 652 | \captionsetup{ 653 | format=margin, % Use the style previously declared 654 | strut=no,% 655 | %hypcap=true, % Links point to the top of the figure 656 | singlelinecheck=false,% 657 | %width=\marginparwidth, 658 | indention=0pt, % Suppress indentation 659 | parindent=0pt, % Suppress space between paragraphs 660 | aboveskip=6pt, % Increase the space between the figure and the caption 661 | belowskip=6pt, % Increase the space between the caption and the table 662 | } 663 | 664 | % Needed to have continued figures and tables (https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Figures_in_multiple_parts) 665 | \DeclareCaptionLabelFormat{cont}{#1~#2\alph{ContinuedFloat}} 666 | \captionsetup[ContinuedFloat]{labelformat=cont} 667 | 668 | % Captions for the 'margin' layout 669 | \NewDocumentCommand{\marginfloatsetup}{}{% 670 | \if@twoside% 671 | \floatsetup[figure]{% Captions for figures 672 | margins=hangoutside,% Put captions in the margins 673 | facing=yes,% 674 | capposition=beside,% 675 | capbesideposition={bottom,outside},% 676 | capbesideframe=yes,% 677 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 678 | capbesidesep=marginparsep,% 679 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 680 | }% 681 | \floatsetup[widefigure]{% Captions for wide figures 682 | margins=hangoutside,% Put captions below the figure 683 | facing=yes,% 684 | capposition=bottom% 685 | }% 686 | \floatsetup[table]{% Captions for tables 687 | margins=hangoutside,% Put captions in the margin 688 | facing=yes,% 689 | capposition=beside,% 690 | capbesideposition={top,outside},% 691 | %capbesideposition=outside, 692 | capbesideframe=yes,% 693 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 694 | capbesidesep=marginparsep,% 695 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 696 | }% 697 | \floatsetup[widetable]{% Captions for wide tables 698 | margins=hangoutside,% Put captions above the table 699 | facing=yes,% 700 | capposition=above% 701 | }% 702 | \floatsetup[longtable]{% Captions for longtables 703 | margins=raggedright,% Overwrite the hangright setting from the `table' environment 704 | %LTcapwidth=table,% Set the width of the caption equal to the table's 705 | }% 706 | \floatsetup[lstlisting]{% Captions for lstlistings 707 | margins=hangoutside,% Put captions in the margin 708 | facing=yes,% 709 | capposition=beside,% 710 | capbesideposition={top,outside},% 711 | %capbesideposition=outside, 712 | capbesideframe=yes,% 713 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 714 | capbesidesep=marginparsep,% 715 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 716 | }% 717 | \floatsetup[listing]{% Captions for listings (minted package) 718 | margins=hangoutside,% Put captions in the margin 719 | facing=yes,% 720 | capposition=beside,% 721 | capbesideposition={top,outside},% 722 | %capbesideposition=outside, 723 | capbesideframe=yes,% 724 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 725 | capbesidesep=marginparsep,% 726 | floatwidth=\textwidth,%Width of the figure equal to the width of the text 727 | }% 728 | \captionsetup*[lstlisting]{% 729 | format=llap,% 730 | labelsep=space,% 731 | singlelinecheck=no,% 732 | belowskip=-0.6cm,% 733 | }% 734 | \else% 735 | \floatsetup[figure]{% Captions for figures 736 | margins=hangright,% Put captions in the margins 737 | facing=yes,% 738 | capposition=beside,% 739 | capbesideposition={bottom,right},% 740 | capbesideframe=yes,% 741 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 742 | capbesidesep=marginparsep,% 743 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 744 | }% 745 | \floatsetup[widefigure]{% Captions for wide figures 746 | margins=hangright,% Put captions below the figure 747 | facing=no,% 748 | capposition=bottom% 749 | }% 750 | \floatsetup[table]{% Captions for tables 751 | margins=hangright,% Put captions in the margin 752 | facing=yes,% 753 | capposition=beside,% 754 | capbesideposition={top,right},% 755 | %capbesideposition=outside, 756 | capbesideframe=yes,% 757 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 758 | capbesidesep=marginparsep,% 759 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 760 | }% 761 | \floatsetup[widetable]{% Captions for wide tables 762 | margins=hangright,% Put captions above the table 763 | facing=no,% 764 | capposition=above% 765 | }% 766 | \floatsetup[longtable]{% Captions for longtables 767 | margins=raggedright,% Overwrite the hangright setting from the `table' environment 768 | %LTcapwidth=table,% Set the width of the caption equal to the table's 769 | }% 770 | \floatsetup[lstlisting]{% Captions for lstlisting 771 | margins=hangright,% Put captions in the margin 772 | facing=yes,% 773 | capposition=beside,% 774 | capbesideposition={top,right},% 775 | %capbesideposition=outside, 776 | capbesideframe=yes,% 777 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 778 | capbesidesep=marginparsep,% 779 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 780 | }% 781 | \floatsetup[listing]{% Captions for listing (minted package) 782 | margins=hangright,% Put captions in the margin 783 | facing=yes,% 784 | capposition=beside,% 785 | capbesideposition={top,right},% 786 | %capbesideposition=outside, 787 | capbesideframe=yes,% 788 | capbesidewidth=\marginparwidth,% Width of the caption equal to the width of the margin 789 | capbesidesep=marginparsep,% 790 | floatwidth=\textwidth,% Width of the figure equal to the width of the text 791 | }% 792 | \captionsetup*[lstlisting]{% 793 | format=llap,% 794 | labelsep=space,% 795 | singlelinecheck=no,% 796 | belowskip=-0.6cm,% 797 | }% 798 | \fi% 799 | } 800 | 801 | % Captions for the 'wide' layout 802 | \NewDocumentCommand{\widefloatsetup}{}{% 803 | \floatsetup[figure]{ % Captions for figures 804 | capposition=bottom,% 805 | margins=centering,% 806 | floatwidth=\textwidth% 807 | } 808 | \floatsetup[widefigure]{ % Captions for wide figures 809 | margins=hangoutside, % Put captions below the figure 810 | facing=yes,% 811 | capposition=bottom% 812 | } 813 | \floatsetup[table]{ % Captions for tables 814 | capposition=above,% 815 | margins=centering,% 816 | floatwidth=\textwidth% 817 | } 818 | \floatsetup[widetable]{ % Captions for wide tables 819 | margins=hangoutside, % Put captions above the table 820 | facing=yes,% 821 | capposition=above% 822 | } 823 | \floatsetup[lstlisting]{ % Captions for lstlistings 824 | capposition=above,% 825 | margins=centering,% 826 | floatwidth=\textwidth% 827 | } 828 | \floatsetup[listing]{ % Captions for listings (minted package) 829 | capposition=above,% 830 | margins=centering,% 831 | floatwidth=\textwidth% 832 | } 833 | \captionsetup*[lstlisting]{% Captions style for lstlistings 834 | %format=margin,% 835 | labelsep=colon,% 836 | strut=no,% 837 | singlelinecheck=false,% 838 | indention=0pt,% 839 | parindent=0pt,% 840 | aboveskip=6pt,% 841 | belowskip=6pt,% 842 | belowskip=-0.1cm% 843 | } 844 | } 845 | 846 | %---------------------------------------------------------------------------------------- 847 | % TOC, LOF & LOT 848 | %---------------------------------------------------------------------------------------- 849 | 850 | \RequirePackage{tocbasic} % Required to customise the TOC 851 | 852 | % Show an entry for the TOC in the TOC 853 | \setuptoc{toc}{totoc} 854 | 855 | % Choose the levels in table of contents 856 | \setcounter{tocdepth}{\subsectiontocdepth} 857 | 858 | % Customise the list of listings 859 | \renewcommand{\lstlistlistingname}{List of Listings}% Change the title 860 | \newcommand{\lstlistingtocdepth}{\sectiontocdepth}% Set the depth 861 | \newcommand{\listoflistings}{\lstlistoflistings}% Provide the alias \listoflistings 862 | \newcommand{\listoflstlistings}{\lstlistoflistings}% Provide the alias \listoflstlistings 863 | 864 | % Define the style for toc entries 865 | \@ifpackagelater{scrbase}{2019/10/11}{% 866 | \DeclareTOCStyleEntries[indent=0em,numwidth=2em,dynnumwidth=yes,pagenumberwidth=2.1em]{tocline}{figure,table,lstlisting}% 867 | \DeclareTOCStyleEntries[dynnumwidth=yes]{tocline}{subsubsection,subsection,section,chapter,part}% 868 | \DeclareTOCStyleEntries[pagenumberwidth=2.5em]{tocline}{chapter,part}% 869 | \DeclareTOCStyleEntries[pagenumberwidth=2.1em]{tocline}{subsubsection,subsection,section}% 870 | }{% 871 | \DeclareTOCStyleEntries[indent=0em,numwidth=2em,dynnumwidth=yes]{tocline}{figure,table,lstlisting}% 872 | \DeclareTOCStyleEntries[dynnumwidth=yes]{tocline}{subsubsection,subsection,section,chapter,part}% 873 | } 874 | 875 | % Define the names for the headings 876 | % \renewcaptionname{english}{\contentsname}{Detailed Contents} 877 | % \renewcaptionname{english}{\listfigurename}{Figures} 878 | % \renewcaptionname{english}{\listtablename}{Tables} 879 | % \newcaptionname{english}{\listtheoremname}{Theorems} 880 | 881 | %---------------------------------------------------------------------------------------- 882 | % MARGIN TOC 883 | %---------------------------------------------------------------------------------------- 884 | 885 | \RequirePackage{etoc} % Required to insert local tables of contents 886 | 887 | \newcounter{margintocdepth} % Set the depth of the margintoc 888 | \setcounter{margintocdepth}{\subsectiontocdepth} % By default to subsections 889 | 890 | \newlength{\mtocshift} % Length of the vertical offset used for margin tocs 891 | \setlength{\mtocshift}{1\vscale}% \mtocshift is overridden by \setchapterstyle 892 | 893 | % Optional title for margintoc (by hCarlFelix, 894 | % https://github.com/fmarotta/kaobook/issues/101) 895 | % We want to create an additional entries in the toc which is to be used for the margintoc 896 | % We define these as mtocsection and mtocsubsection for section and subsection` 897 | \newcommand{\mtocsection}[1]{ 898 | \etoctoccontentsline{mtocsection}{% 899 | \ifnum\value{secnumdepth}>0 \protect\numberline{\thesection}% 900 | \else \protect\nonumberline% 901 | \fi #1}% 902 | } 903 | \newcommand{\mtocsubsection}[1]{ 904 | \etoctoccontentsline{mtocsubsection}{% 905 | \ifnum\value{secnumdepth}>1 \protect\numberline{\thesubsection}% 906 | \else \protect\nonumberline% 907 | \fi #1}% 908 | } 909 | 910 | % Next, we redefine \section and \subsection so that they accept an additional parameter 911 | % \section[alternative-title-for-toc]{title-as-written-in-text}[alternative-title-for-margintoc] 912 | 913 | % Adapted from Frank Mittelbach's answer at Stackexchange 914 | % https://tex.stackexchange.com/a/109560/226693 915 | \let\oldsection\section % save the old command 916 | \let\oldsubsection\subsection % save the old command 917 | 918 | \RenewDocumentCommand\section{s o m o}{% 919 | \IfBooleanTF{#1}{% 920 | \oldsection*{#3} 921 | \IfNoValueF{#2}{% if TOC arg is given create a TOC entry 922 | \addxcontentsline{toc}{section}[\thesection]{#2}% 923 | }% 924 | }{% no star given 925 | \IfNoValueTF{#2}{% 926 | \oldsection{#3}% 927 | }{% no TOC arg 928 | \oldsection[#2]{#3}% 929 | }% 930 | \IfNoValueTF{#4}{% optional label given, if not we do nothing 931 | % \mtocsection{#3}% 932 | \IfNoValueTF{#2}{% 933 | \mtocsection{#3}% when no optional toc title, use main title 934 | }{% no TOC arg 935 | \mtocsection{#2}% when toc optional title is given, use it 936 | }% 937 | }{% 938 | \mtocsection{#4}% 939 | }% 940 | }% 941 | } 942 | 943 | \RenewDocumentCommand\subsection{s o m o}{% 944 | \IfBooleanTF{#1}{% 945 | \oldsubsection*{#3}% 946 | \IfNoValueF{#2}{% if TOC arg is given create a TOC entry 947 | \addxcontentsline{toc}{subsection}[\thesubsection]{#2}% 948 | }% 949 | }{% no star given 950 | \IfNoValueTF{#2}{% 951 | \oldsubsection{#3}% 952 | }{% no TOC arg 953 | \oldsubsection[#2]{#3}% 954 | }% 955 | \IfNoValueTF{#4}{% optional label given, if not we do nothing 956 | \IfNoValueTF{#2}{% 957 | \mtocsubsection{#3}% when no optional toc title, use main title 958 | }{% no TOC arg 959 | \mtocsubsection{#2}% when toc optional title is given, use it 960 | }% 961 | }{% 962 | \mtocsubsection{#4}% 963 | }% 964 | }% 965 | } 966 | 967 | \etocsetlevel{mtocsection}{6}% dummy sectioning level 968 | \etocsetlevel{mtocsubsection}{6}% dummy sectioning level 969 | 970 | % Command to print a table of contents in the margin 971 | \NewDocumentCommand{\margintoc}{O{\mtocshift}}{ % The first parameter is the vertical offset; by default it is \mtocshift 972 | \begingroup% 973 | % Move regular section and subsection to level 6 so that they won't be included and instead set let the mtoc versions take their place. 974 | % Adapted from https://tex.stackexchange.com/a/133559/226693 975 | \etocsetlevel{section}{6} 976 | \etocsetlevel{subsection}{6} 977 | \etocsetlevel{mtocsection}{1} 978 | \etocsetlevel{mtocsubsection}{2} 979 | 980 | % Define default widths 981 | \def\margintocnumwidth{-.8mm}% 982 | \def\margintocpagenumwidth{8pt}% 983 | \setlength{\RaggedRightParfillskip}{0pt} 984 | 985 | % Dry run to get the needed widths 986 | \etocsetstyle{mtocsection}% 987 | {}% 988 | {\setbox0\hbox{{\usekomafont{section}\small\etocthenumber\kern.8mm}}%% 989 | \setbox1\hbox{{\usekomafont{section}\small\etocthepage}}}% 990 | {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi%% 991 | \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}% 992 | {}% 993 | \etocsetstyle{mtocsubsection}% 994 | {}% 995 | {\setbox0\hbox{{\usekomafont{section}\small\mdseries\etocthenumber\kern.8mm}}% 996 | \setbox1\hbox{{\usekomafont{section}\small\mdseries\etocthepage}}}% 997 | {\ifdim\wd0>\margintocnumwidth \edef\margintocnumwidth{\the\wd0} \fi% 998 | \ifdim\wd1>\margintocpagenumwidth \edef\margintocpagenumwidth{\the\wd1} \fi}% 999 | {}% 1000 | \etocsetstyle{subsubsection}% 1001 | {}% 1002 | {}% 1003 | {}% 1004 | {}% 1005 | \etocsetstyle{paragraph}% 1006 | {}% 1007 | {}% 1008 | {}% 1009 | {}% 1010 | \etocsettocstyle{}{% 1011 | \global\let\margintocnumwidth\margintocnumwidth% 1012 | \global\let\margintocpagenumwidth\margintocpagenumwidth% 1013 | }% 1014 | \localtableofcontents% 1015 | 1016 | % Set the style for section entries 1017 | \etocsetstyle{mtocsection}% 1018 | {\parindent 0pt \parskip 2.5pt \parfillskip 0pt \RaggedRight}% 1019 | {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}% 1020 | {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\etocnumber}}\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\etocpage}}\par}% 1021 | {}% 1022 | % Set the style for subsection entries 1023 | \etocsetstyle{mtocsubsection}% 1024 | {\parindent 0pt \parskip 0pt \parfillskip 0pt \RaggedRight}% 1025 | {\leftskip \margintocnumwidth \rightskip \margintocpagenumwidth}% 1026 | {\makebox[0pt][r]{\makebox[\margintocnumwidth][l]{\mdseries\etocnumber}}{\mdseries\etocname\nobreak\leaders\hbox{\hbox to 1.5ex {\hss.\hss}}\hfill\rlap{\makebox[\margintocpagenumwidth][r]{\mdseries\etocpage}}}\par}% 1027 | {\parskip 2.5pt}% 1028 | % Set the global style of the toc 1029 | \etocsettocstyle{\usekomafont{section}\small}{}% 1030 | \etocsetnexttocdepth{\themargintocdepth}% 1031 | % Print the table of contents in the margin 1032 | \marginnote[#1]{\localtableofcontents}% 1033 | \FloatBarrier% 1034 | \endgroup% 1035 | } 1036 | 1037 | %---------------------------------------------------------------------------------------- 1038 | % ENCODING AND FONTS 1039 | %---------------------------------------------------------------------------------------- 1040 | 1041 | % https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation 1042 | % Introduce a command to find out whether the compiler is XeTeX or LuaTeX 1043 | \newif\ifxetexorluatex 1044 | \ifxetex 1045 | \xetexorluatextrue 1046 | \else 1047 | \ifluatex 1048 | \xetexorluatextrue 1049 | \else 1050 | \xetexorluatexfalse 1051 | \fi 1052 | \fi 1053 | 1054 | \ifxetexorluatex 1055 | \RequirePackage{amssymb} % Must be loaded before unicode-math 1056 | \RequirePackage[force]{filehook} % Fixes an error 1057 | \RequirePackage{unicode-math} % Math fonts in xetexorluatex 1058 | \setromanfont[ % Libertinus Serif font 1059 | Scale=1.04 1060 | ]{Libertinus Serif} 1061 | \setsansfont[ % Libertinus Sans font 1062 | Scale=1 1063 | ]{Libertinus Sans} 1064 | \setmonofont[ % Libertinus Mono font 1065 | Scale=.89 1066 | ]{Liberation Mono} 1067 | \setmathfont{Libertinus Math} % Libertinus Math font 1068 | \ifluatex 1069 | \else 1070 | \RequirePackage{morewrites} % Fix some errors related to floats (not necessary with LuaLaTeX 1071 | \fi 1072 | \else 1073 | \RequirePackage[utf8]{inputenc} % utf8 encoding in the input (.tex) file 1074 | \RequirePackage[T1]{fontenc} % utf8 encoding in the output (.pdf) file 1075 | 1076 | \RequirePackage{amssymb} % Math symbols, including \blacktriangleright, used for bullets 1077 | \RequirePackage[scaled=.97,helvratio=.93,p,theoremfont]{newpxtext} % Serif palatino font 1078 | \RequirePackage[vvarbb,smallerops,bigdelims]{newpxmath} % Math palatino font 1079 | \RequirePackage[scaled=.85]{beramono} % Monospace font 1080 | \RequirePackage[scr=rsfso,cal=boondoxo]{mathalfa} % Mathcal from STIX, unslanted a bit 1081 | \RequirePackage{morewrites} % Fix some errors related to floats 1082 | \fi 1083 | 1084 | % When using the Palatino (newpxtext) font, it is better to use a 1085 | % slightly larger stretch. 1086 | %\setstretch{1.10} 1087 | \linespread{1.07} % Give Palatino more leading (space between lines) 1088 | 1089 | %---------------------------------------------------------------------------------------- 1090 | % HYPERREFERENCES 1091 | %---------------------------------------------------------------------------------------- 1092 | 1093 | \RequirePackage{hyperref} % Required for hyperlinks 1094 | \RequirePackage{bookmark} % Required for pdf bookmarks 1095 | 1096 | \PassOptionsToPackage{hyphens}{url} % Break long URLs and use hyphens to separate the pieces 1097 | 1098 | \hypersetup{ % Set up hyperref options 1099 | unicode, % Use unicode for links 1100 | pdfborder={0 0 0}, % Suppress border around pdf 1101 | %xetex, 1102 | %pagebackref=true, 1103 | %hyperfootnotes=false, % We already use footmisc 1104 | bookmarksdepth=section, 1105 | bookmarksopen=true, % Expand the bookmarks as soon as the pdf file is opened 1106 | %bookmarksopenlevel=4, 1107 | linktoc=all, % Toc entries and numbers links to pages 1108 | breaklinks=true, 1109 | colorlinks=true, 1110 | %allcolors=DarkGreen, 1111 | citecolor = DarkOrange, 1112 | linkcolor = Blue, 1113 | %pagecolor = Blue, 1114 | urlcolor = OliveGreen, 1115 | } 1116 | 1117 | % Define a new color for the footnote marks 1118 | \def\@footnotecolor{black} 1119 | \define@key{Hyp}{footnotecolor}{% 1120 | \HyColor@HyperrefColor{#1}\@footnotecolor% 1121 | } 1122 | \def\@footnotemark{% 1123 | \leavevmode 1124 | \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi 1125 | \stepcounter{Hfootnote}% 1126 | \global\let\Hy@saved@currentHref\@currentHref 1127 | \hyper@makecurrent{Hfootnote}% 1128 | \global\let\Hy@footnote@currentHref\@currentHref 1129 | \global\let\@currentHref\Hy@saved@currentHref 1130 | \hyper@linkstart{footnote}{\Hy@footnote@currentHref}% 1131 | \@makefnmark 1132 | \hyper@linkend 1133 | \ifhmode\spacefactor\@x@sf\fi 1134 | \relax 1135 | } 1136 | 1137 | % Redefine the \thanks command to allow users to use \label within \thanks without getting warnings 1138 | \let\oldthanks\thanks 1139 | \renewcommand\thanks[1]{% 1140 | \label{bhfn:0}% 1141 | \oldthanks{#1}% 1142 | } 1143 | 1144 | % Adjust the colour of the footnotes marks using the colour defined above 1145 | \renewcommand\@makefntext[1]{% 1146 | \renewcommand\@makefnmark{% 1147 | \mbox{\textsuperscript{\normalfont% 1148 | \hyperref[\BackrefFootnoteTag]{% 1149 | \color{\@footnotecolor}{\@thefnmark}% 1150 | }}\,% 1151 | }% 1152 | }% 1153 | \BHFN@OldMakefntext{#1}% 1154 | } 1155 | 1156 | %---------------------------------------------------------------------------------------- 1157 | % COLOURS 1158 | %---------------------------------------------------------------------------------------- 1159 | 1160 | % Uncomment to have coloured headings 1161 | %\addtokomafont{title}{\color{Maroon}} 1162 | %\addtokomafont{part}{\color{Maroon}} 1163 | %\addtokomafont{chapter}{\color{Maroon}} 1164 | %\addtokomafont{section}{\color{Maroon}} 1165 | %\addtokomafont{subsection}{\color{Maroon}} 1166 | %\addtokomafont{subsubsection}{\color{Maroon}} 1167 | %\addtokomafont{paragraph}{\color{Maroon}} 1168 | %\addtokomafont{captionlabel}{\color{Blue}} 1169 | %\addtokomafont{pagenumber}{\color{Maroon}} 1170 | 1171 | % Choose the default colors 1172 | \hypersetup{ 1173 | %anchorcolor=Red, 1174 | %citecolor=DarkOrange!70!black, 1175 | citecolor=OliveGreen, 1176 | filecolor=OliveGreen, 1177 | %linkcolor=Blue, 1178 | linkcolor=Black, 1179 | %menucolor=Red, 1180 | %runcolor=Red, 1181 | urlcolor=OliveGreen, 1182 | } 1183 | 1184 | %---------------------------------------------------------------------------------------- 1185 | % ITEMS 1186 | %---------------------------------------------------------------------------------------- 1187 | 1188 | \renewcommand{\labelitemi}{\small$\blacktriangleright$} % Use a black triangle for the first level of \item's 1189 | \renewcommand{\labelitemii}{\textbullet} % Use a bullet for the second level of \item's 1190 | \RequirePackage[inline]{enumitem} % Used to customise lists (in particular, we don't want to put whitespace between items) 1191 | \setlist[itemize]{noitemsep} 1192 | \setlist[enumerate]{noitemsep} 1193 | \setlist[description]{noitemsep} 1194 | 1195 | %---------------------------------------------------------------------------------------- 1196 | % SIMPLE BOXED ENVIRONMENT 1197 | %---------------------------------------------------------------------------------------- 1198 | 1199 | % kaobox (while tcolorbox may be more rich, I find it too complicated so I prefer mdframed) 1200 | \RequirePackage{tikz} 1201 | \RequirePackage[framemethod=TikZ]{mdframed} 1202 | 1203 | % Define a new style for mdframed boxes 1204 | %\mdfsetup{skipabove=\topskip,skipbelow=0pt} 1205 | \mdfdefinestyle{kaoboxstyle}{ 1206 | skipabove=1.5\topskip, 1207 | skipbelow=.5\topskip, 1208 | rightmargin=0pt, 1209 | leftmargin=0pt, 1210 | %innertopmargin=3pt, 1211 | %innerbottommargin=3pt, 1212 | innerrightmargin=7pt, 1213 | innerleftmargin=7pt, 1214 | topline=false, 1215 | bottomline=false, 1216 | rightline=false, 1217 | leftline=false, 1218 | %linewidth=1pt, 1219 | %roundcorner=0pt, 1220 | %font={}, 1221 | %frametitlefont={}, 1222 | frametitlerule=true, 1223 | linecolor=black, 1224 | %backgroundcolor=LightBlue, 1225 | fontcolor=black, 1226 | %frametitlebackgroundcolor=LightBlue, 1227 | } 1228 | 1229 | % Define a new environment using the style created above 1230 | \newmdenv[ 1231 | style=kaoboxstyle, 1232 | backgroundcolor=RoyalBlue!25!White, 1233 | frametitlebackgroundcolor=RoyalBlue!25!White, 1234 | ]{kaobox} 1235 | 1236 | %---------------------------------------------------------------------------------------- 1237 | % ENVIRONMENT WITH A COUNTER 1238 | %---------------------------------------------------------------------------------------- 1239 | 1240 | % Define an environment titled 'Comment' and numbered incrementally 1241 | \newenvironment{kaocounter}{ 1242 | \refstepcounter{kaocounter} 1243 | \begin{kaobox}[frametitle=Comment~\thekaocounter\autodot] 1244 | }{ 1245 | \end{kaobox} 1246 | } 1247 | 1248 | % Define the commands to manage the counter for the 'kaocounter' environment 1249 | \newcounter{kaocounter} 1250 | \counterwithin{kaocounter}{section} 1251 | \newcommand*{\kaocounterformat}{% Format for the caption 1252 | Comment~\thekaocounter\csname autodot\endcsname} 1253 | \newcommand*{\fnum@kaocounter}{\kaocounterformat} 1254 | 1255 | 1256 | %---------------------------------------------------------------------------------------- 1257 | % FLOATING ENVIRONMENT WITH TOC ENTRIES 1258 | %---------------------------------------------------------------------------------------- 1259 | 1260 | % Define a floating environment 1261 | \newenvironment{kaofloating}{% 1262 | \@float{kaofloating}% 1263 | }{% 1264 | \end@float% 1265 | } 1266 | 1267 | % Configure the 'kaofloating' environment 1268 | \newcommand*{\fps@floatingbox}{tbph}% Allowed positions for the environment (top, bottom, own page, here) 1269 | \newcommand*{\ftype@floatingbox}{5}% Set the type of float (floats of the same type cannot change their order; figures and tables are type 1 and 2 respectively) 1270 | \newcommand*{\floatingboxformat}{% Set a title of the environment 1271 | Insight~\thefloatingbox\csname autodot\endcsname} 1272 | \newcommand*{\fnum@floatingbox}{\floatingboxformat}% Use the environment title 1273 | \newcommand*{\ext@floatingbox}{loi}% Choose the extension of the auxiliary file for this environment 1274 | 1275 | \addtotoclist[float]{loi}% Keep track of 'kaofloating' environments for a "List of Insights" 1276 | \newcommand*{\listofloiname}{List of Insights}% Choose the title for the "List of Insights" 1277 | \newcommand*{\l@floatingbox}{\l@figure}% Format the LOI 1278 | \newcommand*{\listofinsights}{\listoftoc{loi}}% User-friendly command to print the LOI 1279 | 1280 | %---------------------------------------------------------------------------------------- 1281 | % ADDITIONAL PACKAGES 1282 | %---------------------------------------------------------------------------------------- 1283 | 1284 | % Productivity 1285 | \RequirePackage{pdfpages} % Insert PDF pages 1286 | \RequirePackage{subfiles} % Adopt a modular structure 1287 | \RequirePackage{todonotes} % Add useful notes in the margins 1288 | 1289 | % Listings code 1290 | \RequirePackage{listings} % Code 1291 | %\RequirePackage{minted} (must be loaded before scrhack) 1292 | 1293 | % Configure the listings 1294 | \definecolor{listingkeywords}{rgb}{0.0, 0.5, 0.0} 1295 | \definecolor{listingidentifiers}{rgb}{0, 0, 0} 1296 | \definecolor{listingcomments}{rgb}{0.25, 0.5, 0.5} 1297 | \definecolor{listingstrings}{rgb}{0.73, 0.13, 0.13} 1298 | \definecolor{listingnumbers}{rgb}{0.25, 0.25, 0.25} 1299 | % Define a fancy style 1300 | \lstdefinestyle{kaolst}{ 1301 | aboveskip=0.7\topskip, 1302 | belowskip=0.1\topskip, 1303 | basicstyle=\small\ttfamily, 1304 | commentstyle=\color{listingcomments}\itshape, 1305 | keywordstyle=\color{listingkeywords}\bfseries, 1306 | numberstyle=\scriptsize\color{listingnumbers}\ttfamily, 1307 | stringstyle=\color{listingstrings}, 1308 | identifierstyle=\color{listingidentifiers}, 1309 | backgroundcolor=\color{White}, 1310 | breakatwhitespace=false, 1311 | breaklines=true, 1312 | captionpos=t, 1313 | keepspaces=true, 1314 | showspaces=false, 1315 | showstringspaces=false, 1316 | showtabs=false, 1317 | numbers=left, 1318 | numbersep=1em, 1319 | %frame=lines, 1320 | frame=l, 1321 | framerule=.7pt, 1322 | tabsize=4, 1323 | defaultdialect=[LaTeX]Tex, 1324 | } 1325 | % Define a plain style as well 1326 | \lstdefinestyle{kaolstplain}{ 1327 | aboveskip=0.6\topskip, 1328 | belowskip=-0.1\topskip, 1329 | basicstyle=\small\ttfamily, 1330 | commentstyle=\color{listingcomments}\itshape, 1331 | keywordstyle=\color{listingkeywords}\bfseries, 1332 | numberstyle=\scriptsize\color{listingnumbers}\ttfamily, 1333 | stringstyle=\color{listingstrings}, 1334 | identifierstyle=\color{listingidentifiers}, 1335 | backgroundcolor=\color{White}, 1336 | breakatwhitespace=false, 1337 | breaklines=true, 1338 | captionpos=b, 1339 | keepspaces=true, 1340 | showspaces=false, 1341 | showstringspaces=false, 1342 | showtabs=false, 1343 | numbers=none, 1344 | frame=none, 1345 | tabsize=4, 1346 | defaultdialect=[LaTeX]Tex, 1347 | } 1348 | \lstset{style=kaolst}% Use the fancy style 1349 | 1350 | % Verbatim 1351 | %\RequirePackage{fancyvrb} % Customization of verbatim environments 1352 | %\fvset{fontsize=\normalsize} % Change here the font size of all 1353 | %verbatim \preto{\@verbatim}{\topsep=0pt \partopsep=0pt } 1354 | 1355 | % Algorithms 1356 | \RequirePackage[linesnumbered, ruled, vlined]{algorithm2e} % Algorithms 1357 | 1358 | % Special gliphs 1359 | \RequirePackage{ccicons} % Creative Commons icons 1360 | \RequirePackage{metalogo} % XeTeX logo 1361 | 1362 | % Index, glossary and nomenclature 1363 | \RequirePackage{imakeidx} 1364 | \RequirePackage[xindy,toc,numberedsection=nameref]{glossaries} 1365 | \RequirePackage[intoc]{nomencl} 1366 | 1367 | % Commands to print specific words always in the same way 1368 | % TODO: in \Command, automatically escape braces {} and replace backslashes with \textbackslash 1369 | \newcommand{\Class}[1]{\texttt{#1}} 1370 | \newcommand{\Package}[1]{\texttt{#1}} 1371 | \newcommand{\Option}[1]{\texttt{#1}} 1372 | \newcommand{\Command}[1]{\texttt{\textbackslash#1}} 1373 | \newcommand{\Environment}[1]{\texttt{#1}} 1374 | \newcommand{\Path}[1]{\texttt{#1}} 1375 | 1376 | % Print latin words in italics (The xspace package is required but we already loaded it in the class) 1377 | \newcommand{\hairsp}{\hspace{1pt}} % Command to print a very short space 1378 | \newcommand{\invitro}{\textit{in vitro}\xspace} 1379 | \newcommand{\invivo}{\textit{in vivo}\xspace} 1380 | \newcommand{\cis}{\textit{cis}\xspace} 1381 | \newcommand{\trans}{\textit{trans}\xspace} 1382 | \newcommand{\etal}{\textit{et al.}\xspace} 1383 | \newcommand{\denovo}{\textit{de novo}\xspace} 1384 | \newcommand{\adhoc}{\textit{ad hoc}\xspace} 1385 | \newcommand{\etcetera}{\textit{et cetera}\xspace} 1386 | \newcommand{\etc}{\textit{etc.}\xspace} 1387 | \newcommand{\Etc}{\textit{Etc.}\xspace} 1388 | \newcommand{\ie}{\textit{i.\nobreak\hairsp{}e.}\xspace} 1389 | \newcommand{\Ie}{\textit{I.\nobreak\hairsp{}e.}\xspace} 1390 | \newcommand{\eg}{\textit{e.\nobreak\hairsp{}g.}\xspace} 1391 | \newcommand{\Eg}{\textit{E.\nobreak\hairsp{}g.}\xspace} 1392 | \newcommand{\iid}{\textit{i.\nobreak\hairsp{}i.\nobreak\hairsp{}d.}\xspace} 1393 | \newcommand{\Iid}{\textit{I.\nobreak\hairsp{}i.\nobreak\hairsp{}d.}\xspace} 1394 | \newcommand{\wrt}{\textit{w.\nobreak\hairsp{}r.\nobreak\hairsp{}t.}\xspace} 1395 | \newcommand{\Wrt}{\textit{W.\nobreak\hairsp{}r.\nobreak\hairsp{}t.}\xspace} 1396 | \newcommand{\vs}{\textit{vs}\xspace} 1397 | \newcommand{\cfr}{\textit{cfr.}\xspace} 1398 | 1399 | % Tables 1400 | \newcommand{\na}{\quad--} % Used in tables for N/A cells 1401 | \newcommand{\hangp}[1]{\makebox[0pt][r]{(}#1\makebox[0pt][l]{)}} % Create parentheses around text in tables which take up no horizontal space - this improves column spacing 1402 | \newcommand{\hangstar}{\makebox[0pt][l]{*}} % Create asterisks in tables which take up no horizontal space - this improves column spacing 1403 | 1404 | % A command to print the current month and year (from tufte-latex) 1405 | \newcommand{\monthyear}{\ifcase\month\or January\or February\or March\or 1406 | April\or May\or June\or July\or August\or September\or October\or 1407 | November\or December\fi\space\number\year} 1408 | --------------------------------------------------------------------------------