# Modifying a Latex Template # Introduction We all start learning Latex at the first level: - Create a document - Include packages - Change fonts - Make a table - Include figures - ... These tasks are often easy to do and well documented. When it comes to making a custom template, the documentation is more limited. In this post, I will explain a little bit how to "read/understand" how is organized a template. I will not present everything, only things that are necessary to survive and which were useful in my case. I won't cover for instance how to change the design, color, position of the slidebar, or how to modify the background image. Nevertheless, with the knowledge presented here, you will be able to better navigate to obtain the behavior you want. ## Table of Content 1. [Notions about Latex syntax](#basic-notions) 2. [Understanding Beamer organization](#files) 3. [Modifying the template](#target) ---- # Basic Notions Here, we assume you (at least) know how to use LaTeX, i.e. loading a template, changing page format, inserting math equation, bold effect, and compiling the document. Before this post, my state was the following: - I didn know how to write a latex function - I didn't understand how a template was organized - `.sty` or `.cls`, what's the difference ? We won't detail how to create a package from scratch. There are already some articles about that on [Overleaf](https://www.overleaf.com/learn/latex/Writing_your_own_package) for instance. Based on my recent exploration, I will try to answer partially to these questions. ## Tex vs LaTex [^TexTexTex] - Tex : This is the low-level programming language. - LaTex: This is an upper layer with predefined macros (sections, navigations bars, ...) - Xelatex, Lualatex, ...: These are like LaTex, extension of the Tex language. [^TexTexTex]: [Tex, LaTex, XeTex](https://fr.overleaf.com/learn/latex/Articles/The_TeX_family_tree%3A_LaTeX%2C_pdfTeX%2C_XeTeX%2C_LuaTeX_and_ConTeXt) ### Useful Path Where you can find info about what is installed on your Linux (if no custom install): - `/usr/share/texlive`: package installed - `/usr/share/texlive/texmf-dist/tex`: tex language supported (luatex, xelatex, latex, xetex in my case) ## Files [^STY] [^STY]: [STY VS CLS](https://tug.org/pracjourn/2005-3/asknelly/nelly-sty-&-cls.pdf) In both `.sty` and `.cls`, you can write tex code. When searching on Github, sometimes people make their custom templates by writing a `.sty`, sometimes by writing a `.cls`. This is not forbidden, they work barely the same. However, for code hygiene, for sharing, it is better to use them appropriately. ### Classes `.cls` are class files. They are used to defined global behavior of the document. For instance, setting margin width, page size, automated bibliography at the end of the doc, in other words, things we don't really want to customize. Classes are here to provide the minimal viable document without any customization. In the default classes, you have: - `article`, `report`, `lettre` - `book`, `memoir` - `slides`, `beamer` In a `.tex` file, only one class is imported at a time, with `\documentclass{article}` (without the `.cls` if in the current folder). Within this file, we can import `.sty` files to define some behaviors with `\RequirePackage{}`. ### Packages [FR: How to create your package](https://www.tuteurs.ens.fr/logiciels/latex/nouveau_package.html) A `.sty` file is a package file. A package file can include other package files to write more complex functions. Packages are often a set of functions which help you to perform a particular task: - writing algorithms - import pictures - draw diagrams In a `.tex` file, we can import multiple different packages with `\usepackage{...}`. They can be [generated](https://texfaq.org/FAQ-dtx) from `.dtx` files. If you are always importing the same packages for writing your tex documents, you can create a package `custom.sty` where your list all the libraries you would need. Therefore, in a single import you would have all your libraires loaded. ### Summary | | `.sty` | `.cls`| |--------|-------------|------------| | Load | `\usepackage{...}` | ` \documentclass{...}` | | What? | style / package | classes | | Number | Many ! | A few | | Github Ex | [beamerbaseboxes](https://github.com/josephwright/beamer/blob/main/base/beamerbaseboxes.sty) | [Beamer.cls](https://github.com/josephwright/beamer/blob/main/base/beamer.cls) | | Complexity | Hard | Simple | | Number of import | several | one | The difference between the two types of files can be blurred: - Classes define the basic behavior of the document, shape, and page format. - Packages define high level functions that can be used, and can modify the class behavior. ## Commands Latex is to Lisp what brackets and backslash are to parenthesis. I will try to cover: - `\newcommand` - `\renewcommand` - `\def` - Functions with `@` ### Making a function [^Command] [^Command]: [Overleaf course for defining commands](https://www.overleaf.com/learn/latex/Commands) #### Without Argument If I have one command without arguments: `\newcommand{\myfunctionName}{}` For instance for `\newcommand{\R}{\mathbb{R}}` - Whenever I want to call my function, I write `\R` - What it does is that it is replaced by the mathematical symbol $$\mathbb{R}$$ #### With Arguments If I have $$k$$ arguments, I add `[k]` (must be a positive integer), such as: `\newcommand{\myfunctionName}[k]{}` For instance, if I want to make any letter with double bar: `\newcommand{\bb}[1]{\mathbb{#1}}`, where `\bb{R}` would have the same effect as `\R` You call the 1st argument with `#1`, the second with `#2`, etc. *Note*: I cannot name arguments. Its `#1#2#3#4`. #### With Optional Argument We can add **one** optional argument. The first argument (`#1`) would be optional if you specify a default value. `\newcommand{\functionName}[numberOfArg][DefaultValue]{functionDescripiton}` For instance, with this function with `3` arguments, and the first set to `2`: `\newcommand{\plusbinomial}[3][2]{(#2 + #3)^#1}` You can call it with or without using the default value: - `\plusbinomial{a, b}` exploits the default value, and returns $$(a + b)^2$$ while - `\plusbinomial[3]{a, b}` replaces the default value by `3`, and returns $$(a + c)^3$$. For more than one arguments, you need to look at packages: - [TexFAQ](https://texfaq.org/FAQ-twooptarg) - [StackOverflow](https://tex.stackexchange.com/questions/29973/more-than-one-optional-argument-for-newcommand) ### Replacing existing commands You may not know that a function with the same name already exists, or it is defined in the theme and you want to overwrite it. For that case, `\newcommand` would throw an error. To overwrite the function, you need to use `\renewcommand`, with the same syntax. ### Different way to define[^defnewcom] [^telecom] [^long] - `\def`: (TeX primitive) these are the sensible definition. Can be overwritten. - `\newcommand`: (LaTeX primitive), with the same behavior as `\def` - `\newcommand\foo{}`: `\long\def\foo{}` - `\newcommand*\foo{}`: `\def\foo{}` (not long). with `\long`, it reads all the code within the bracket. Without, it reads the first definition line... It seems that the `*` allows when closing bracket are missing to pass through. [^telecom]: [Telecom (FR): Def vs Newcommand and others](https://perso.telecom-paristech.fr/rodrigez/resources/latex/astuce_8.pdf) [^defnewcom]: [Def vs Newcommand](https://tex.stackexchange.com/questions/655/what-is-the-difference-between-def-and-newcommand) [^long]: [TexFAQ: Latex \long](https://texfaq.org/FAQ-cvtlatex) ### `\def` VS `\define` [^definekey] [^definekey]: [How to read definekey](https://tex.stackexchange.com/questions/34312/how-to-create-a-command-with-key-values) `\define` is used to defined **macros**, which follows the format: ```latex \define@key{}{}{} ``` [Overleaf macro tutorial](https://www.overleaf.com/learn/latex/How_TeX_macros_actually_work%3A_Part_4) [About macros](https://www.tug.org/TUGboat/tb25-2/tb81adriaens.pdf) ### The "At" @ In packages, we can find function with `@` in, for instance `\mymodule@mysubmodule@myfunction{}`. These are private functions, that can only be used within the current module, therefore cannot be used outside. Even if they are private, they can be redefined with the command `\patchcmd` which uses the syntax `\patchcmd{}{}{}{}{}` to correct the command ([Source](https://tex.stackexchange.com/questions/152773/please-tutor-the-usage-of-patchcmd-and-xpatch)). ### Environment `\newenvironment{myenv}`: allows to defines stuff in a limited scope. The syntax is similar to a function: `\newenvironment{}[][]{}{}` To call an environment, you know the syntax, it is like `\begin{enumerate}`: ```latex \begin{myenv}[myoptionalarg]{My necessary arg} Whatever you need to write \end{myenv} ``` Environment allows to define things that happens before text is inputted (`{opening definition}`), and what happens after. This is helpful for changing fontsize, color, adding some extra space, centering, ... This is one way to define a local style. --- # Files ## Beamer and its configuration Files Our target objective is to customize a template to make beautiful beamer slides. If you don't know about beamer, the user guide is a good place to start. You can find it here [^beamerguide]. [^CTAN]. [^beamerguide]: [Beamer User Guide](http://tug.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf) [^CTAN]: [The Comprehensive TeX Archive Network](https://www.ctan.org/) ## Structure of a Beamer Slide The most important picture in the Beamer documentation is the following, helping to know which item is above the other. ![](/assets/images/Latex/beamer_structure.png) ## Special Functions In beamer packages files, you will find `\defbeamertemplate` and `\setbeamertemplate`. - The `\defbeamertemplate` is about defining a behavior with the syntax `\defbeamertemplate{}{}{}` - The `\setbeamertemplate` is about enforcing it with two cases: - `\setbeamertemplate{}[]` (use the template) - `\setbeamertemplate{}{Custom behavior}` (live definition) *Note*: Optional arguments can be used, with (p.169 [^beamerguide]): ```latex \defbeamertemplate{}{}[]{} \setbeamertemplate{}[]{arg1}{arg...}{argk} ``` The list of objects that are modifiable in beamer is available here [^standardobj]. These object are defined in the "core of beamer engine". You can have multiple styles for the same object. For instance: - `\defbeamertemplate{section page}{simple}` defines the behavior `simple` for the object `section page`. - `\defbeamertemplate{section page}{progressbar blue}` defines the behavior `progressbar blue` for the same object. To select the one we want to use, we need to "set" the template, for instance with `\setbeamertemplate{section page}[progressbar blue]`. A local behavior can be enforced, by using the bracket: ```latex {\setbeamertemplate{xx}{xx} text, items, frames, where I want this template to be applied } ``` ## Models There are many built-in **themes** for beamer. Themes are packages (`.sty` files) which defines and enforce the style of the document. You can find them on the [Beamer Github Repository)](https://github.com/josephwright/beamer/tree/main/base). It is helpful if you have no time for configuration. ### Classes VS Packages: The Beamer Example Beamer is first a class of documents, which is defined [here](https://github.com/josephwright/beamer/blob/main/base/beamer.cls). It loads some necessary external packages, plus the package `beamerbaserequires.sty` stored in the same directory with: ```latex \RequirePackage{beamerbaserequires} ``` The [beamerbaserequires.sty](https://github.com/josephwright/beamer/blob/main/base/beamerbaserequires.sty) is just a file that loads all components: ```latex ... % Commands for constructing the title page \RequirePackage{beamerbasetitle} % Parts, sections, subsections, appendix \RequirePackage{beamerbasesection} % Commands for constructing frames \RequirePackage{beamerbaseframe} \RequirePackage{beamerbaseverbatim} \RequirePackage{beamerbaseframesize} % Headlines, sidebars, columns \RequirePackage{beamerbaseframecomponents} ... ``` The syntax in the beamer components is very difficult to understand from a beginner perspective. We can understand that in each is define the default behavior in different cases. For instance, for the [Table of Content](https://github.com/josephwright/beamer/blob/main/base/beamerbasetoc.sty) component, we have the line: ```latex \define@key{beamertoc}{currentsection}[]{\beamer@toc@sectionstyle{show/shaded}\beamer@toc@subsectionstyle{show/show/shaded}\beamer@toc@subsubsectionstyle{show/show/shaded}} ``` which is a macro where: - the `family` is `beamertoc` - the `key` is `currentsection` - There is no arguments `[]` and the function call three functions: - `\beamer@toc@sectionstyle` with argument `show/shaded` (this is one argument) - `\beamer@toc@subsectionstyle` with argument `show/show/shaded` - `\beamer@toc@subsubsectionstyle` with argument `show/show/shaded` They both works the same way, so we will look at the first one, which is defined somewhere eles as: ```latex \def\beamer@toc@sectionstyle#1{\beamer@toc@process\beamer@toc@cs\beamer@toc@os#1//} ``` It takes one argument (`#1` after the name definition), and call three functions: - `\beamer@toc@process`, defined by `\def\beamer@toc@process#1#2#3/#4/{\ifblank{#4}{\def#1{#3}\def#2{#3}}{\def#1{#3}\def#2{#4}\@gobble}}` (Note the `/#4/` for argument definition.) - `\beamer@toc@cs` defined as `\def\beamer@toc@cs{show}`, i.e. a function with no argument that returns `show` - `\beamer@toc@os` defined as `\def\beamer@toc@os{show}` (same than the previous one) Explained in natural language, `\beamer@toc@process`: - if the 4th argument is not defined (blank), then argument `#1` is taken as a function name calling `#3 `(`\def#1{#3}`), and `#2` also call `#3` - If defined, `#1` still call `#3`, but now `#2` returns `#4`. The `\@globble` consumes the additional parameter [^globble]. For `#1=show/shaded` in `\beamer@toc@sectionstyle#1`, the command calls `\beamer@toc@process{show}{show}{show/shaded}//`. Maybe with the latex magic, it will find the `/` and identify `#3=show` and `#4=shaded` When interpreting the `\def#1{#3}\def#2{#4}`, I don't quite understand if it really defines twice the function `show`, one outputing `show` while the other `shaded`... [^globble]: [StackEx: Why does gobble take one argument ?](https://tex.stackexchange.com/questions/85796/why-does-gobble-take-one-argument) ### Command `\tableofcontents` TODO: Put it later or organize. To call the table of content, we can use the command `\tableofcontents`. We can add the option `\tableofcontents[currentsection]` to highlight the current section, and shade the other. In the tableofcontents methods, the argument `currentsection` would be send to `\setkeys{beamertoc}{#1}`. `\setkeys` will use the definition of the corresponding `\define@key`. ```latex \def\beamer@tableofcontents[#1]{ \def\beamer@toc@cs{show} \def\beamer@toc@os{show} \def\beamer@toc@css{show} \def\beamer@toc@oss{show} \def\beamer@toc@ooss{show} \def\beamer@toc@csss{show} \def\beamer@toc@osss{show} \def\beamer@toc@oosss{show} \def\beamer@toc@ooosss{show} \beamer@showpartnumber=\c@part \beamer@pausesectionsfalse \beamer@pausesubsectionsfalse \def\beamer@tocsections{<*>} \setkeys{beamertoc}{firstsection=1} \setkeys{beamertoc}{#1} \vspace*{-.5em}{\makeatletter \pause[0] \@input{\jobname.toc} \vfill} } ``` ### Theme Gallery If you look at theme galleries ([Here](https://deic.uab.cat/~iblanes/beamer_gallery/index_by_theme.html), [also here](https://www.overleaf.com/gallery/tagged/presentation), [then there](https://hartwork.org/beamer-theme-matrix/), [again](https://latex-beamer.com/tutorials/beamer-themes/), [CTAN repository](https://ctan.org/tex-archive/macros/latex/contrib/beamer/base/themes/color), [or on a github list](https://github.com/martinbjeldbak/ultimate-beamer-theme-list)), you will quickly see that the main differentiating characteristic is **color**, and the front page organisation. For the rest, everything is often left unchanged. It is often easy to guess that the slide deck has been made with LaTex. There are two templates that I found out of the group (they don't belong to Beamer default templates): - [Metropolis](https://github.com/matze/mtheme), clean, well know. The color are not the most inspiring, but compared to the bluish color of the default template, this is much better - [sthlm NORD](https://github.com/mholson/sthlmNordBeamerTheme), found on the Github ultimate beamer repository, clean with nice palettes. ### Theme Architecture To facilitate template edition, it is suggested by the beamer repository to separate style modification in distinct files: - `beamercolorthemeXXX.sty`: color for theme `XXX` (imported by `beamerthemeXXX`) - `beamerfontthemeXXX.sty`: fonts - `beamerinnerthemeXXX.sty`: define section / subsection / list / toc behaviors - `beamerouterthemeXXX.sty`: page numbering, slidebar, menu, ... - `beamerthemeXXX.sty`: Package that load everything. You need to import this file to apply all the behaviors defined in the other files. The name `XXX` is not necessarily the same for all these files. It is possible to combine a color theme `X` with a font theme `Y`. To avoid loadding these barbaric names, there are predefined loading command defined in [beamerbasethemes.sty](https://github.com/josephwright/beamer/blob/main/base/beamerbasethemes.sty). For instance, looking at the code of [beamerthemedarmstadt.sty](https://github.com/josephwright/beamer/blob/main/base/themes/theme/beamerthemeDarmstadt.sty), it calls the inner, outer, and two color themes, but no font (keep the default of beamer): ```latex \useoutertheme{smoothbars} \useinnertheme[shadow=true]{rounded} \usecolortheme{orchid} \usecolortheme{whale} ``` If you look at [`orchid`](https://github.com/josephwright/beamer/blob/main/base/themes/color/beamercolorthemeorchid.sty) and [`whale`](https://github.com/josephwright/beamer/blob/main/base/themes/color/beamercolorthemewhale.sty), the palettes do not overlap, so both style are fully imported. ### Loading a Theme If we want to load a complete style, we need to use `\usetheme{}` which will look at the corresponding `beamerthemeXXX.sty` (in the local directory first, and in the default repository where package are installed next). ```latex \documentclass{beamer} \usetheme{metropolis} \title{Test for slides} \begin{document} My blabla \end{document} ``` # Modifying the Template ## How we Would Proceed Writting a template from scratch is not easy. Our goal is only to change some properties of a template to fits our needs. If prevents from defining too many things and reinventing the wheel. I attended a talk from a Google Researcher, with very clean slides. I wanted to recreate a similar template. ![](/assets/images/Latex/slide_theme.png) - Table of content - Figure with grey background (and no title) - List with icons, subtitles gray - Code boxes, with code on the left, and description on the right The goal is not to recreate exactly the same template, but to have something similar, like the table of content, and the circle/squares with text. For this, we will start take: - the `metropolis` template for the global behavior. Compared to usual beamer templates, it is lighter (no navigation bars, menu, numbers everywhere that would distract the audience) - `sthlm NORD` for its colors. ![](/assets/images/Latex/nord_palette.png){:width="70%"} ## Adjusting Color This is the easiest thing to do. We just need to define the colors in the `beamercolorthemeXXX.sty` (here we added them it into `beamercolorthememetropolis.sty`) ```latex ... \definecolor{nordOne}{HTML}{3B4252} \definecolor{nordTwo}{HTML}{434C5e} \definecolor{nordThree}{HTML}{4C566A} \definecolor{nordFour}{HTML}{D8DEE9} \definecolor{nordFive}{HTML}{E5E9F0} \definecolor{nordSix}{HTML}{ECEFF4} \definecolor{nordSeven}{HTML}{8FBCBB} \definecolor{nordEight}{HTML}{88C0D0} \definecolor{nordNine}{HTML}{81A1C1} \definecolor{nordTen}{HTML}{5E81AC} \definecolor{nordEleven}{HTML}{BF616A} \definecolor{nordTwelve}{HTML}{D08770} \definecolor{nordThirteen}{HTML}{EBCB8B} \definecolor{nordFourteen}{HTML}{A3BE8C} \definecolor{nordFifteen}{HTML}{B48EAD} ... ``` ### Setting color for an object Next, we used these colors to customize the existing elements: If we take this piece of code: ```latex \setbeamercolor{frametitle}{ use=normal text, parent=normal text, fg=nordThree, bg=normal text.bg } ``` - `frametitle` is the title on the top of the slide - `use=` argument to load a previously defined object to get its attribute. Multiple objects can be loaded with `use={obj1,obj2}` - `parent=`: inheritance, i.e. use all the color of the previous object. Here useless because color redefined. You need to set `use` to access the object. It sets `fg` and `bg` to its values. - `bg`: background color. Overwrite parent inheritance if set. - `fg`: foreground color. Overwrite parent inheritance if set. Here, it access the property of a previous object with `.fg` Here, `normal text` is a previously defined object, where we take the background color: ```latex \setbeamercolor{normal text}{ fg=nordThree, bg=nordSix } ``` `normal text` is one of the first defined object. In `metropolis` theme, most of the other objects inherit from its style. In some way, it allows to define the background color. Example with multiple objects and transparency usagee: ```latex \setbeamercolor{block body}{ use={block title, normal text}, bg=block title.bg!50!normal text.bg % Combine block title background (50% transparency) with normal text background } ``` Example with direct inheritance: ```latex \setbeamercolor{block body alerted}{use=block body, parent=block body} ``` For the full list of customizable objects, see [^standardobj]. ### Progress bar: ```latex \setbeamercolor{progress bar}{ fg=nordTen, bg=nordTen!50!nordEight!50 } ``` - `fg`: represent the achieved part of the presentation (left) - `bg`: the non-achieved part (right) ![](/assets/images/Latex/progress.png){:width="70%"} ## Syntax Variations In `innertheme`: - `\setbeamertemplate{block alerted begin}{\metropolis@block{ alerted}}` define the behavior - `\setbeamertemplate{block alerted end}{\end{beamercolorbox}\vspace*{0.2ex}}` Define the bottom behavior (here add some space) Called with: ```latex \begin{alertblock}{Conclusion} This is an alert. \end{alertblock} ``` In `color`, we can modify it: Around the title: ```latex \setbeamercolor{block title alerted}{ bg=nordTwelve, fg=nordSix, } ``` Content of the box: ```latex \setbeamercolor{alerted text}{ fg=nordZero } ``` *Note*: For some elements, it is useless to define the background (or the foreground) because the color is ignored in the object definition itself. You need to look at the documentation code, or do a test/try/fail/success loop until the desired result is obtained. --- # Target The goal is not to have a perfect copycat, but to have a nice template reusing some of the elements seen in a previous presentation. There are several parts we want to reproduce: - Table of Content - Blocks with text in - Dark code blocks ## Table of Content The original model is the following: ![](/assets/images/Latex/target_google.png) We can identify different noticeable aspect: - Items are centered - Everything is uppercase - The title use another font - For the toc lines, the first letter of each word is accentuated - Highlight: The current part is highlighted. ### Re-defining a TOC template There are multiple items that are dedicated to the toc [^standardobj]: - `section in toc` - `section in toc shaded` - `section number projected` - `subsection in toc` - `subsection in toc shaded` - `subsubsection in toc` - `subsubsection in toc shaded` In our case, we won't have `subsection` or `subsubsection`, only `section` (simple presentation for less than 45 minutes). Therefore, we only need to modify the two first elements. `section in toc` define the behavior around each section printed (when not shaded), while `section in toc shaded` the behavior when shaded. In our case, the "*not shaded*" behavior is with a rounded box, while the `shaded` one with no visible box. We need to define these behaviors in the `beamerinnertheme.sty`. We defines them with the special name `special`, to not rewrite any existing function and to be able to recognize it in our template. For the current section to highlight, we set our custom colors: ```latex \defbeamertemplate{section in toc}{special} { \begin{tcolorbox}[halign=center, colback=nordNine!50, colframe=nordFour, boxrule=0pt] \textsc{\inserttocsection} \end{tcolorbox} } ``` We used transparency for the background color to obtain something lighter than the original color. For the other sections, we want no highlight. This is exactly the same box, but with its color set to the background color. We could do it without using the `tcolorbox`, however, we want to keep spacing homogeneous. To reuse the color of the normal background color, we use `\usebeamercolor{normal text}` and set the box background color to `bg` (reserved keyword): ```latex \defbeamertemplate{section in toc shaded}{special} { \usebeamercolor{normal text} \begin{tcolorbox}[halign=center, colback=bg, boxrule=0pt, colframe=nordFour] \textsc{\inserttocsection} \end{tcolorbox} } ``` We needed also to change the page number behavior: ```latex \defbeamertemplate{footline}{centered page number} {\% \hspace*{\fill}% Space from left border \usebeamercolor[fg]{page number in head/foot}%Set color \usebeamerfont{page number in head/foot}% Set size \insertpagenumber% \hspace*{\fill} % Space from right border \vskip2pt% Space from the bottom } ``` ### Selecting our defined styles We have defined the style, but we did not applied it yet. For that, we need to call them in `bearmertheme.sty`: In Theme, we needed to call all the definitions. Because spacing between toc entries was too large, we needed to redefine it. Therefore, the code in `beamertheme.sty` is: ```latex \setbeamertemplate{section in toc}[special] \setbeamertemplate{section in toc shaded}[special] \setbeamertemplate{footline}[centered page number] ``` Next, the spacing between the items was to small. We redefined the toc command to add larger spaces with: ```latex \patchcmd{\beamer@sectionintoc} {\vfill} {\vskip\itemsep} {} {} ``` ### Results When calling `\tableofcontents[currentsection]`: - With progress bar (`\usetheme[progressbar=frametitle]{metropolis}`): ![](/assets/images/Latex/TOC/02.png) - Without progress bar (`\usetheme{metropolis}`): ![](/assets/images/Latex/TOC/03.png) When calling `\tableofcontents`: ![](/assets/images/Latex/TOC/04.png) --- ## Grayed Subtitles The original model is the following: ![](/assets/images/Latex/train/header_grey.png){:width="70%"} - A rectangular box with gray background - Text is centered - All icons are gray To build this headline, we defined a command to set it. This is easier because we don't want the theme to apply everywhere. ```latex \newcommand{\grayheadline}[2][nordFour]{ \begin{tcolorbox}[spread sidewards, halign=center, valign=center, sharp corners, colframe=#1, colback=#1, colupper=nordZero, fontupper=\large\sffamily, height=1.5cm ] \textbf{#2} \end{tcolorbox} } ``` We set the text in bold as a default. ![](/assets/images/Latex/Box/02.png) With the light-gray background color, the box limit are very hard to identify. With white background: ![](/assets/images/Latex/Box/06.png) If we want to put the box up (when there isn't much text), we can finish a frame with the `\vspace{3cm}` command. ![](/assets/images/Latex/Box/08.png) ```latex # Try Gray box \grayheadline{This is something very important} \begin{center} \begin{tabular}{ r l } \large{\textbf{\cGrey{Point 1}}} & Chocolate and bananas \\ \\ \large{\textbf{\cGrey{Point 2}}} & Flour and sugar. \\ & I would like to put a paragraph here but that \\ & might be impossible because of the table ... \\ \\ \large{\textbf{\cGrey{Point 3}}} & Something else \\ \end{tabular} \end{center} \vspace{3cm} ``` ### With `\newenvironment` The problem with tikz is when we want to write complex stuff (table, code, ...). For simple text, it is okay but we need to inset line breaks when needed with `\\`. `\newenvironment` can help for inserting complex text: ```latex \newenvironment{grayheader}[1][nordFour]{ \setbeamercolor{mytestcolor}{fg=nordThree,bg=#1} \begin{beamercolorbox}[wd=\paperwidth, center]{mytestcolor} \bfseries }{ \end{beamercolorbox} } ``` In the code, you just have to write normally: ```markdown # Beamercolorbox \begin{grayheader} This is within the box $$P = f(x + y)^2$$ Under the equation within the block. \end{grayheader} And this is outside the box \vspace{10cm} ``` ![](/assets/images/Latex/Box/09.png) ## List with Colored items Initial model: ![](/assets/images/Latex/train/list_color.png) We have already done the exercise in the previous example. We only need to color left text. ![](/assets/images/Latex/Box/03.png) ```latex \begin{center} \begin{tabular}{ r l } \large{\textbf{\cYellow{Point 1}}} & Chocolate and bananas \\ \\ \large{\textbf{\cGreen{Point 2}}} & Flour and sugar. \\ & I would like to put a paragraph here but that \\ & might be impossible because of the table ... \\ \\ \large{\textbf{\cLightBlue{Point 3}}} & Something else \\ \end{tabular} \end{center} ``` ## Making Balls and Squares From the original presentation: ![](/assets/images/Latex/train/balls.png){:width="70%"} ![](/assets/images/Latex/train/dark_block.png){:width="70%"} ![](/assets/images/Latex/train/block_clear.png){:width="70%"} ### Code With `tikz`, it is possible to draw balls and rectangles. ```latex \newcommand{\filledcircle}[2][nordThree]{ \begin{tikzpicture} \node[circle,text=nordZero,fill=#2,draw=#2, align=center, minimum size=4cm] (c) at (0,0){#2}; \end{tikzpicture} } ``` For squares, we just need to replace `circle` by `rectangle`. For the squares with a border, we have to set `line width=1mm`, and to not set the background color. ```latex \newcommand{\emptysquare}[2][nordThirteen]{ \begin{tikzpicture} \node[rectangle,text=nordZero,draw=#1, align=center, minimum size=4cm, line width=1mm] (c) at (0,0){#2}; \end{tikzpicture} } ``` ### Setup with pandoc Next, we have to play with the colors to get all the different examples. To display the first one with pandoc: ```md :::::::::::::: {.columns} ::: {.column width="33%"} \filledcircle{nordNine}{\textbf{My Text}\\and the rest.\\Color Nine} ::: ::: {.column width="33%"} \filledcircle{nordEight}{\textbf{My Text}\\and the rest\\Color Eight} ::: ::: {.column width="33%"} \filledcircle{nordSeven}{\textbf{My Text}\\and the rest\\Color Seven} ::: :::::::::::::: ``` When writing text in these boxes, we need to break lines manually with `\\`. Otherwise, the box would expend, or it will throw an error if you add a newline with `\n`. ### Results Giving the result: ![](/assets/images/Latex/form/01.png) Changing `circle` to `rectangle`: ![](/assets/images/Latex/form/02.png) Two big square (`6cm` instead of `4cm`): ![](/assets/images/Latex/form/03.png) With dark colors: ![](/assets/images/Latex/form/04.png) With borders: ![](/assets/images/Latex/form/06.png) --- ## Code block ![](/assets/images/Latex/train/code_blocks.png){:width="70%"} This is about making blocks with dark color, rounded or not. Second is in three distinct columns. ![](/assets/images/Latex/Box/05.png) For this, we used the package listing. It only puts in bold the keywords, and doesn't play on the colors. For the coloring, it is very soft. ```latex \begin{tcolorbox}[colback=nordThree,colframe=nordThree,colupper=nordFourteen] \begin{minipage}{.2\textwidth} \lstinputlisting[language=python]{pytest.py} \end{minipage} \hfill \begin{minipage}{.4\textwidth} This is the documentation text. Multiple lines. It can help to explain the code or not. To add. \end{minipage} \end{tcolorbox} ``` There is the main `tcolorbox` defining background and text color. `minipage` are here to create the illusion of two columns. The width need to be adjusted. With pandoc, I got errors with `listing` and `minted` packages. The only way to make them works was to input code from a file, and to set `--pdf-engine-opt=--shell-escape` for pandoc. ```latex \inputminted[fontsize=\footnotesize, linenos]{python}{relief.py} \lstinputlisting[language=python, basicstyle=\footnotesize]{relief.py} ``` `minted` gives the traditional editor coloring, while `listing` would only put in bold the keywords. `listing` would better adapt to the slide colors, but is less expressive / more difficult to read. It is good to have both under the hand. --- # Conclusion I dived into template edition and command creation. There are things that are still unknown to me (understanding tex perfectly or `pgfkeys` for instance). However, I learned how to edit elements, to use the main template functions, which is enought to customize an existing template. There are some objects that don't need to be added to the template (box and square). We often need to customize many thing (multiple colors, changing the shape and the size). For this case, a command was easier to manipulate. # Sources [Fonts Catalogue](https://tug.org/FontCatalogue/) [^standardobj]: [Apparence Sheet](https://www.cpt.univ-mrs.fr/~masson/latex/Beamer-appearance-cheat-sheet.pdf) [Syntax highlight](https://pandoc.org/MANUAL.html#syntax-highlighting) [Upper Lowercase Syntax](https://tex.stackexchange.com/questions/335990/is-there-a-command-to-make-first-letter-upper-case)