% TODO: Redefine macros % TODO: References % TODO: Spacing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % These files will contain a reference to quickly reload nice % formatting tips in LaTeX. Links and exmaples will be included. % % Here is a website to draw and recover LaTeX commands: % http://detexify.kirelabs.org/classify.html % % When writing code, I like to use marker words "TODO", "UPDATE", % "TEMP", and "FIX" to signify, respectively, a task to finish, % a optional update, a temporary change (can be for logging or % experiment), and finally a fix to a problem % % Here is conversion spacing: % https://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/WhiteSpace.html % % Cool tricks: % https://tex.stackexchange.com/questions/19746/cunning-latex-tricks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{authblk} \usepackage [ a4paper,% other options: a3paper, a5paper, etc % left=2cm, % right=2cm, top=2.5cm, bottom=2.5cm, % use vmargin=2cm to make vertical margins equal to 2cm. % us hmargin=3cm to make horizontal margins equal to 3cm. % use margin=3cm to make all margins equal to 3cm. ] {geometry} \usepackage{lipsum} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{showkeys} \usepackage[sc,osf]{mathpazo} % With old-style figures and real smallcaps. \linespread{1.025} % Palatino leads a little more leading % Euler for math and numbers \usepackage[euler-digits,small]{eulervm} \usepackage{amsthm} \usepackage{amssymb} %% For equation references and formatting \usepackage{hyperref} \usepackage{bm} \usepackage{amsfonts} \usepackage{bbold} % \usepackage{bbm} %% For images \usepackage{graphicx} \usepackage{wrapfig} \usepackage{float} \usepackage{subcaption} %% For tables \usepackage{booktabs} %% For cool features \usepackage{xcolor} \usepackage{soul} \usepackage{tcolorbox} \tcbuselibrary{skins, breakable} \usepackage{enumitem} \usepackage{algorithm} % \usepackage{algorithmicx} % \usepackage{arevmath} % For math symbols \usepackage[noend]{algpseudocode} \usepackage{marginnote} % This is for showing LaTeX code \usepackage{fancyvrb} \usepackage{fvextra} % This is for hiding parts \usepackage{comment} \theoremstyle{plain} \newtheorem{theorem}{Theorem}[section] \newtheorem{corollary}{Corollary}[theorem] \newtheorem{lemma}[theorem]{Lemma} \theoremstyle{definition} \newtheorem{definition}{Definition}[section] \theoremstyle{remark} \newtheorem*{remark}{Remark} %% For algorithms \begin{document} \title{LaTeX Reference} \author[1]{Caleb \thanks{Email: calebju@gmail.com}} \date{\today} % \date{21 Januari 2010\\\small{(Edisi Revisi : 3 Januari 2019)}} % \affil[1]{\small{Hyang Language Foundation, Jakarta, Indonesia}} \maketitle \begin{abstract} We include brief descriptions of commonly used features encountered when writing documents and papers in \LaTeX. \end{abstract} \tableofcontents \section{Ground Zero (AA)} I've included an empty LaTeX file and Makefile. In my Makefile, I do a couple unconventional things. First, I make the input and output name differently. I like to call my main file ``main.tex'' but rename output since Adobe has a bug they seem to cache similarly named files. I also break large TeX files into chapters by saving them as separate files and saving them in ``\/chpts''. The choice of font is a metter of personal taste. I have enjoyed this forum on comparing fonts [\href{https://tex.stackexchange.com/questions/59702/suggest-a-nice-font-family-for-my-basic-latex-template-text-and-math/97128#97128}{link}]. I do like the standard Modern font (\texttt{lmodtern}) or Utopia, the latter which is added by \texttt{usepackage[utopia]\{mathdesign\}}. Now onto specifics for the LaTex file. Before we can use theorems, we have to explicitly define them. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Defining Theorem Macros, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \theoremstyle{plain} \newtheorem{theorem}{Theorem}[section] \newtheorem{corollary}{Corollary}[theorem] \newtheorem{lemma}[theorem]{Lemma} \theoremstyle{definition} \newtheorem{definition}{Definition}[section] \theoremstyle{remark} \newtheorem*{remark}{Remark} \end{Verbatim} \end{tcolorbox} Let's see how the \textit{theorem} macro is define. The first parameter is the LaTeX keyword. The second is the text that appears in the PDF. The third is the counter. Notice we can \textit{theorem}'s keyword as a counter. The location of where we include the counter impacts the numbering; if it included in the middle, the macro (e.g. \textit{lemma}) uses the same numbering. If the counter is at the end (e.g. \textit{corollary}), it is treated as a subheading to theorem and thus will reset with \textit{theorem} (I don't know why I would ever do this). Also, we can define macros with different styles, with the three default ones used above (see \href{https://en.wikibooks.org/wiki/LaTeX/Theorems}{here} for more information). In particular, theorem (denoted as ``plain'') includes both bolded and italicized text. Definition includes just bold. Remark is just bold. I find these to be sufficient, but the previous link shows how to define new ones. I often use plain for imporatnt results, definition for also examples and exercises, and remark for notes. \begin{theorem}[Fermat's Last Theorem] Given three positive integers $a$, $b$, and $c$, \begin{equation*} a^n + b^n = c^n. \end{equation*} \end{theorem} \begin{definition} This is a definition. \end{definition} \begin{remark} This is a remark. \end{remark} \noindent The proof package is automatically included \begin{corollary} If $a=b=c=0$, then the theorem above holds for any $n \in \mathbb{N}$. \end{corollary} \begin{proof} Proof is easy. Observe $0^n + 0^n = 0^n$. \end{proof} \noindent Notice that QED symbol is an empty box. We can fill it in. We can also bold ``Proof'' rather than italicize. \renewcommand\qedsymbol{$\blacksquare$} \renewenvironment{proof}{\noindent {\bfseries Proof.}}{\qed} \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Modifying QED, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \renewcommand\qedsymbol{$\blacksquare$} \renewenvironment{proof}{\noindent {\bfseries Proof}}{\qed} \end{Verbatim} \end{tcolorbox} \begin{lemma} When $a$, $b$, and $c$ are the side lengths of a right triangle, then \begin{equation*} a^2 + b^2 = c^2 \end{equation*} \end{lemma} \begin{proof} Draw a triangle. You shall see it. \end{proof} Something very useful, especially during the editting phase, is to see the labels of specific equations and images. To that end, we can visualized these in the PDF itself with the useful packcage, which is included in the \texttt{amsmath} package. \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{showkeys} \end{Verbatim} \end{tcolorbox} \subsection{Commands and Environments (AA1)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{comment} \end{Verbatim} \end{tcolorbox} Let's now briefly overview commands and environments, which we have already used earlier. Examples of commands include \texttt{textbackslash \text\{input\}}. There are three ways to define commands. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=New commands, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \newcommand{\B}[1]{\mathbb{#1}} \renewcommand*{\labelitemi}{\dag} \providecommand{\caleb}[1]{\textcolor{blue}{Caleb: \textcolor{blue}{#1}} \end{Verbatim} \end{tcolorbox} The new command defines a new command and throws an error if it is already defined. Renew overwrites an existing command or throws an error if it is not defined. Finally, the provide command defines a new command if it doesn't exist. Notice in each command, we can include parameters and such. I'll include this \href{https://www.dickimaw-books.com/latex/novices/html/newcom.html}{link} for more information, but the above is usually sufficient. While commands are suitable for smaller portions of text, environments are are designed to handle blocks of LaTex code. You may already be familiar with some environments, such as \texttt{\textbackslash begin\{equation\}}. Let's see how to create a simple environment with a numbering system \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=New commands, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \newcounter{example}[section] \newenvironment{example}[1][]{\refstepcounter{example}\par\medskip \noindent \textbf{Example~\thesection.\theexample. #1} \rmfamily}{\medskip} \end{Verbatim} \end{tcolorbox} % Creates new counter system, which restarts with a new section \newcounter{example}[section] \newenvironment{example}[1][]{\refstepcounter{example}\par\medskip \noindent \textbf{Example~\thesection.\theexample. #1} \rmfamily}{\medskip} \begin{example} This is an example of an example. \end{example} Note that we can also create environments that can hide. This is useful if you want to create solutions. For theis, we will make use of the comment package, as shown below. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=New commands, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \newtheorem*{sol}{Solution} \newif\ifshow % \showfalse \showtrue % swap with above to hide \ifshow \newenvironment{solution} {\begin{sol} \color{gray}} {\end{sol}} \else \excludecomment{solution} \fi \end{Verbatim} \end{tcolorbox} \newtheorem*{sol}{Solution} \newif\ifshow % \showfalse \showtrue \ifshow \newenvironment{solution} {\begin{sol} \color{gray}} {\end{sol}} \else \excludecomment{solution} \fi \begin{solution} This is the solution to blah blah \end{solution} There is apparently a way to set show to true or false during make. I've tried this \href{https://tex.stackexchange.com/questions/254370/compile-showtrue-and-showfalse-to-different-target-files}{solution} but it does not work with the prescribed solution. If interested, try to dig more into this. \section{Links and Formatting (BB)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{hyperref} % for linking \usepackage{bm} % for bolding math \usepackage{amsfonts} % for special characters \usepackage{bbold} % for calligrahic digits, e.g. \mathbb{1} \end{Verbatim} \end{tcolorbox} \noindent Let's say we have the following equation, \begin{equation} \label{eq:example1} \begin{split} \min & \hspace{10pt} \| \beta \| \\ \text{s.t.} & \hspace{10pt} y_i(\beta^\mathsf T x_i + \beta_0) \geq 1 - \zeta_i, \ i = 1,\ldots,N \\ & \hspace{10pt} \zeta_i \geq 0, \ \sum\limits_{i=1}^N \zeta_i \leq Z. \end{split} \end{equation} \noindent We can reference the above equation using the \LaTeX command \texttt{ref}, but by itself it will not cross-reference to the equation above (try removing the package). Instead, we must use the package {\texttt{hyperref} and we can now link equation~\eqref{eq:example1}. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Individual Label, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \begin{align} \min & \hspace{10pt} x_1 + x_2 + \ldots + x_n \nonumber \\ \text{s.t.} & \hspace{10pt} a_{i,1}x_1 + a_{i,2}x_2 + \ldots + a_{i,n}x_n \stackrel{(1)}{\leq} 1, \ i = 1,\ldots,m \label{eq:packing_constraints} \\ & \hspace{10pt} x_i \geq 0, \ i = 1,\ldots,n \label{eq:nonnegative_constraints}. \end{align} \end{Verbatim} \end{tcolorbox} We can also reference individual equations as well, \begin{align} \min & \hspace{10pt} x_1 + x_2 + \ldots + x_n \nonumber \\ \text{s.t.} & \hspace{10pt} a_{i,1}x_1 + a_{i,2}x_2 + \ldots + a_{i,n}x_n \stackrel{(1)}{\leq} 1, \ i = 1,\ldots,m \label{eq:packing_constraints} \\ & \hspace{10pt} x_i \geq 0, \ i = 1,\ldots,n \label{eq:nonnegative_constraints}. \end{align} \noindent Equation~\eqref{eq:packing_constraints} are the packing constraints and equation~\eqref{eq:nonnegative_constraints} are the non-negativity constraints. We can write this in matrix form. To get the bold font, we need the package {\texttt{bm}} and for blackboard fonts (special symbol for reals) we utilize packages {\texttt{amsfonts}} and {\texttt{bbold}} for digits. Note that we can also use the package {\texttt{bbm}}, however this only contains formatting for $1$ and $2$. We apply it below, \begin{align*} \min & \hspace{10pt} \mathbb{1}^\mathsf T x \\ \text{s.t.} & \hspace{10pt} \bm{A}x \leq \mathbb{1} \\ & \hspace{10pt} x \geq \mathbb{0}. \end{align*} \section{Images (CC)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{graphicx} % input images \usepackage{wrapfig} % enable small figures \usepackage{float} % enable "H" placement \usepackage{subcaption} % enable subimages/subcaptions \end{Verbatim} \end{tcolorbox} \noindent We start with a very basic image, which requires the {\texttt{graphicx}} package. The image is summoned with the code {\texttt{\textbackslash includegraphics[$\ldots$]}}. We specify the size of the image in the brackets, which can be absolute sizes (e.g. ``3cm'') or relative sizes (e.g., ``0.5 \textbackslash textwidth'', see \href{https://www.overleaf.com/learn/latex/Inserting_Images}{here} for more references). Additionally, we can the image using via \texttt{\textbackslash begin\{figure\}[X]}, where the variable X can be ``h'', ``t'', ``b'', ``p'', or ``H''. These, respectively, stand for placing the image \textit{approximately} at the same point in the source code, at the top of the page, at the top of the page, at the bottom of the page, put on a special page for image floats (likely won't be used except appendix of images), or exactly where the source code. We can add an ``!'' (e.g., ``h!'') to tell \LaTeX to override the internal parameters for ``good'' positions. Often, \texttt{h!} is equivalent to \texttt{H}, so use the former if the compiler complains (this is fixed by adding {\texttt{ \textbackslash usepackage\{float\}}}). Second, the image is not centered. To center it, we add the parameter \texttt{\textbackslash centering} with in the figure blocks. Third, we can add captions by include {\texttt{\textbackslash captions}}. The ordering of these commands is important. If we place the caption above the image, the caption will be above the image, and equivalently it will be below. Altogether, we get the following image. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries] \begin{Verbatim}[baselinestretch=0.1] \begin{figure}[h!] \includegraphics[width=6cm]{figs/Saddle_point} \centering \caption{Saddle point problem, $f(x,y) = x^2 + y^2$} \end{figure} \end{Verbatim} \end{tcolorbox} \begin{figure}[h!] \includegraphics[width=6cm]{figs/Saddle_point} \centering \caption{Saddle point problem, $f(x,y) = x^2 + y^2$} \end{figure} \noindent Note that it is possible to place the caption to the left or right using additional packages. See \href{https://www.overleaf.com/learn/latex/Inserting_Images}{this link}. Like equations and theorems, image can be referenced via \texttt{\textbackslash label\{fig:ref\_name\}}. Finally, \href{https://nixtricks.wordpress.com/2009/10/26/latex-crop-resize-and-rotate-figures-in-latex/}{here} is a brief note on formatting the size and positioning of the figure. When the image is small, we may want to wrap it alongside text. To do so, we utilize the command \texttt{subfigure} instead of \texttt{figure} and configure its position and size and we must include {\texttt{\textbackslash subcaption}}. While using \texttt{wrapfigure}, be wary of page breaks. One might have issues where the image is \textit{overlapped} with the text, see \href{https://tex.stackexchange.com/questions/73304/wrapfigure-problem-text-over-figure}{here}. Personally, I've found that if the \texttt{wrapfigure} must be between two texts of line. Without the text ``Random'' below, the image would be incorrectly placed. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries] \begin{Verbatim}[baselinestretch=0.1] \begin{wrapfigure}{r}{0.15\textwidth} \centering \includegraphics[width=0.15\textwidth]{figs/unit} \end{wrapfigure} \end{Verbatim} \end{tcolorbox} Random. \begin{wrapfigure}{r}{0.15\textwidth} \centering \includegraphics[width=0.15\textwidth]{figs/unit} \end{wrapfigure} \lipsum[2] We can also include multiple figures aligned. We utilize the \texttt{figure} and within each figure will use \texttt{\textbackslash subfigure}. This is a mechanical and so we just write the code below; copy when it is needed. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries] \begin{Verbatim}[baselinestretch=0.1] \begin{figure}[H] \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{figs/Saddle_point} \caption{1a} \label{fig:sfig1} \end{subfigure}% \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.40\linewidth]{figs/unit} \caption{1b} \label{fig:sfig2} \end{subfigure} \\[\smallskipamount] \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.40\linewidth]{figs/unit} \caption{1b} \label{fig:sfig2} \end{subfigure} \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{figs/Saddle_point} \caption{1a} \label{fig:sfig1} \end{subfigure}% \caption{Four figures in one} \label{fig:fig} \end{figure} \end{Verbatim} \end{tcolorbox} \begin{figure}[H] \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{figs/Saddle_point} \caption{1a} \label{fig:sfig1} \end{subfigure}% \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.40\linewidth]{figs/unit} \caption{1b} \label{fig:sfig2} \end{subfigure} \\[\smallskipamount] \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.40\linewidth]{figs/unit} \caption{1b} \label{fig:sfig2} \end{subfigure} \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=.8\linewidth]{figs/Saddle_point} \caption{1a} \label{fig:sfig1} \end{subfigure}% \caption{Four figures in one} \label{fig:fig} \end{figure} % TODO: margins. Check this link: https://tex.stackexchange.com/questions/57702/custom-margin-settings-for-figure-in-latex \section{Tables (DD)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{booktabs} \end{Verbatim} \end{tcolorbox} There is a bit of art to making tables. This dichotomy is displayed in the first couple of slides in this \href{https://people.inf.ethz.ch/markusp/teaching/guides/guide-tables.pdf}{presentation}. In general, \begin{enumerate} \item Avoid vertical lines (lines may also be referred to as ``rules'') \item Avoid double lines. Instead, opt for thickness. \item Put units in the headers (not in the body of the table) \item Always preceed a decimal point by a digit; e.g., 0.1 instead of .1 \item Avoid ``ditto'' signs or any other such convention to repeat a previous value. In many circumstances a blank will serve just as well. If it won’t, then repeat the value. \end{enumerate} \noindent With these guidelines in mind, we now introduce the two main components to creating tables: {\texttt{tabular}} and {\texttt{booktabs}}. The first package creates the table and the second package simple draws good (horizontal) lines to help organize the data. We start by briefly explaining \texttt{tabular}. A table is invoked by the command \texttt{\textbackslash \{ tabular \}[pos]\{cols\}}. The parameter \texttt{pos} is similar to ``h'' and ``H'' in figure. The second parameter \texttt{cols} explains how many columns we want, what the alignment of each column is, and also enables additional spacing for consecutive tiles. The code below shows an example, but a more detailed explanation can be found \href{http://www.emerson.emory.edu/services/latex/latex_69.html}{here}. The second relatively simple package, {\texttt{booktabs}}, is about nice looking horizontal lines. The three main commands one will utilize are \texttt{\textbackslash toprule}, \texttt{\textbackslash midrule}, and \texttt{\textbackslash bottomrule}. These will usually be placed beginning with the toprule, then separating headings and data with the thinner midrule, and closing the table with bottomrule. These are placed after the \textbackslash \textbackslash of the last corresponding row. We can also subdivide columns in categories by separating the two rows using \texttt{\textbackslash cmidrule}. A short \href{http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/booktabs/booktabs.pdf}{pdf} details more information to these commands. See the code below for a concrete example. % Optiona A: requires \usepackage{float} % \begin{table}[H] % \centering % Option B: % \begin{center} \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Create Table, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \begin{table}[H] \centering % \begin{tabular}{@{\extracolsep{1cm}}l@{}lr@{}} \toprule \begin{tabular}{@{}llr@{}} \toprule \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} Animal & Description & Price (\$)\\ \midrule Gnat & per gram & 13.65 \\ & each & 0.01 \\ Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \addlinespace[5pt] Total & & 150.10 \\ \bottomrule \end{tabular} \caption{This is a caption for the table} \end{table} \end{Verbatim} \end{tcolorbox} % Option C: { \centering. % However, it seems this can mess with the size of the table \begin{table}[H] \centering % \begin{tabular}{@{\extracolsep{1cm}}l@{}lr@{}} \toprule \begin{tabular}{@{}llr@{}} \toprule \multicolumn{2}{c}{Item} \\ \cmidrule(r){1-2} Animal & Description & Price (\$)\\ \midrule Gnat & per gram & 13.65 \\ & each & 0.01 \\ Gnu & stuffed & 92.50 \\ Emu & stuffed & 33.33 \\ Armadillo & frozen & 8.99 \\ \addlinespace[5pt] Total & & 150.10 \\ \bottomrule \end{tabular} \caption{This is a caption for the table} \end{table} % } % \end{center} % \end{table} \noindent Alternatively, \href{http://cpansearch.perl.org/src/LIMAONE/LaTeX-Table-v1.0.6/examples/examples.pdf}{here} is a list of example tables. \section{Cool Styling (EE)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1] \usepackage{xcolor} \usepackage{soul} \usepackage{tcolorbox} \tcbuselibrary{skins, breakable} \usepackage{enumitem} \end{Verbatim} \end{tcolorbox} \subsection{Text customization (EE1)} Like in word processing files, we would like to customize texts beyond the simple \textit{italization} and \textbf{bolding}: things like coloring, underlining, strikethrough, hiights, and more. We start with coloring. Start by importing {\texttt{\textbackslash usepackage\{xcolor\}}}. From here, colors can be invoked by either \texttt{\textbackslash textcolor\{colorname\}\{Text\}} or \texttt{\{\textbackslash color\{colorname\}Text\}}. By default, the colors include yellow ``base colors'' such as \textcolor{blue}{blue} and {\color{orange}orange}. These colors can be mixed by taking percentages of a color, suchas \texttt{green!55!blue}, a color that arises by taking 55\% green and what remains as blue (45\%). More colors can be obtained by including xcolor's different package options via {\texttt{\textbackslash usepackage[optionnames]\{xcolor\}}}. Option names include \texttt{dvipsnames}, \texttt{svgnames}, and \texttt{x11names}. Their specific colors can be found in the \href{https://ctan.math.illinois.edu/macros/latex/contrib/xcolor/xcolor.pdf#page=38}{documentation}. Next, we explore the world of \hl{highlighting} by invoking the macro \texttt{\textbackslash hl\{\}} after importing, {\texttt{\textbackslash usepackage\{soul\}}}. We can choose colors other than {yellow} by running the command \texttt{\textbackslash sethlcolor\{colorname\}}. Hightlighting and textcoloring can be combined by nesting the \texttt{hl} command within a \texttt{textcolor} or \texttt{color} command. We now move onto styling with lines, such as strikethroughs and underlines. The package \texttt{soul} already includes strikethroughs and underlines via \texttt{\textbackslash st\{\}} and \texttt{\textbackslash ul\{\}}, respectively. Other customizations, such as changing the the color of the lines, applying all caps, and spacings can be found in the package's \href{http://ctan.mirrors.hoobly.com/macros/generic/soul/soul.pdf}{documentation}. \subsection{tcolorbox (EE2)} The package {\texttt{tcolorbox}} is an \textit{extensive} package that allows beautiful displays of boxes to showcase important results/text/ideas. There are too many features to consider learning at once (or demo-ing for that matter -- the \href{http://ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/tcolorbox/tcolorbox.pdf}{documentation} is 530 pages long), so we only include the critical detail. The base package is included via \texttt{\textbackslash usepackage \{tcolorbox\}}. By itself, tcolorbox is boring. We can extend it by including additional programs via {\texttt{\textbackslash tcbuselibrary\{$\langle key list \rangle$\}}}. I typically include only {\texttt{skins}}, {\texttt{theorems}}, and {\texttt{breakable}}, but a fully laundry list can be found \href{http://ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/tcolorbox/tcolorbox.pdf#page=9}{here}. We can start with a barebones box. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1] \begin{tcolorbox} This is a \textbf{tcolorbox}. \tcblower Here, you see the lower part of the box. \end{tcolorbox} \end{Verbatim} \end{tcolorbox} \begin{tcolorbox} This is a \textbf{tcolorbox}. \tcblower Here, you see the lower part of the box. \end{tcolorbox} The options (the stuff inside the brackets) enables additional features, such as the color and fill of the box, the title, shadows, and many other features. I like the following setup the most so I'll only include this one. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1] \begin{tcolorbox}[colback=blue!5,colframe=blue!40!black, title=Example Title, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] This is an example box. \end{tcolorbox} \end{Verbatim} \end{tcolorbox} \begin{tcolorbox}[colback=blue!5,colframe=blue!40!black,title=Example Title, drop shadow, skin=enhanced, fonttitle=\bfseries, ] This is an example box. \end{tcolorbox} \noindent Notice in the above box we have included the \texttt{breakable} option. For larger boxes, this allows the box to \textit{cross pages}. An earlier version was used for the subfigure code. Now, we can set the default baseline tcolorbox-es using \texttt{tcbset}. The application will be applied to all subsequent tcolorbox-es. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1] \tcbset{ drop shadow, skin=enhanced, fonttitle=\bfseries, } \begin{tcolorbox} This is again a \textbf{tcolorbox}. \tcblower This was set using \texttt{tcbset}. \end{tcolorbox} \end{Verbatim} \end{tcolorbox} \tcbset{ drop shadow, skin=enhanced, fonttitle=\bfseries, } \begin{tcolorbox} This is again a \textbf{tcolorbox}. \tcblower This was set using \texttt{tcbset}. \end{tcolorbox} \noindent I consider these to be the essential setup for \texttt{tcolorbox}. More features, such as fitting the box to the exact size of the LaTeX object, defining new boxes, followed by a full list of options, can others can be found starting here \href{http://ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/tcolorbox/tcolorbox.pdf#page=14}{here}. % Explore theorem package of tcolorbox To end the quick tutorial on tcolorbox, here is a quick STOP sign that can be drawn with it. {\centering \begin{tcolorbox}[enhanced, size=minimal,auto outer arc, width=2.1cm,octogon arc, colback=red,colframe=white,colupper=white, fontupper=\fontsize{7mm}{7mm}\selectfont\bfseries\sffamily, halign=center,valign=center, square,arc is angular, borderline={0.2mm}{-1mm}{red} ] STOP \end{tcolorbox} } One more cool styling, which is useful in practice. We can try a nice gray box around an important result to highlight it. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1, breaklines=True] \newcommand{\greybox}[1]{ \begin{tcolorbox}[sharp corners,colback=black!10!white,colframe=black!10!white]#1\end{tcolorbox} } \end{Verbatim} \end{tcolorbox} \newcommand{\B}[1]{\bm{#1}} \newcommand{\greybox}[1]{ \begin{tcolorbox}[sharp corners,colback=black!10!white,colframe=black!10!white]#1\end{tcolorbox} } \greybox{ \begin{lemma}[Three point lemma] Let $\{x_t\}$ be generated by~\eqref{} with the Euclidian distance replaced by a Bregman divergence $D_\omega$. Then for any $\B x \in \Omega$ \begin{align*} \gamma_t \langle g(\B x_t), \B x_{t+1}-\B x \rangle + D(\B x_{t+1}, \B x_t) \leq D(\B x, \B x_t) - D(\B x,\B x_{t+1}). \end{align*} \end{lemma} } \subsection{Lists (EE3)} The popular commands, \texttt{enumerate} and \texttt{itemize}, can be further customized if we include the package via {\texttt{\textbackslash usepackage\{enumitem\}}} (with corresponding documentation found \href{https://mirrors.rit.edu/CTAN/macros/latex/contrib/enumitem/enumitem.pdf}{here}). First, enumerate, we can customize which symbols are used to list each item via the \texttt{label} option (see the code below). We can set this to either \texttt{\textbackslash alpha}, \texttt{\textbackslash Alpha}, \texttt{\textbackslash arabic}, \texttt{\textbackslash roman}, or \texttt{\textbackslash Roman}. Make sure to include an asterik at the end (I don't know what it does, all I know is that it doesn't compile otherwise). \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1] \begin{enumerate}[label=\textit{\arabic*})] \item blah \item blahh \item bblahh \end{enumerate} \end{Verbatim} \end{tcolorbox} % \begin{enumerate}[label=\emph{\alph*})] \begin{enumerate}[label=\textit{\arabic*})] \item blah \item blahh \item bblahh \end{enumerate} We can do other customizations. To get a ``tight'' enumerate (i.e., less spacing), we can add additional options (I will not write it, instead see the code). Second, we can redefine the nested itemizations to have unique symbols (typical of what you would encounter in a word document). To do so, one needs to redefine the macros \texttt{\textbackslash labelitemi} to \texttt{\textbackslash labelitemiv} (see the code below). And as always, there is more code \href{https://texblog.org/2008/10/16/lists-enumerate-itemize-description-and-how-to-change-them/}{here}. We display the end result below. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \renewcommand{\labelitemi}{$\bullet$} \renewcommand{\labelitemii}{$\cdot$} \renewcommand{\labelitemiii}{$\diamond$} \renewcommand{\labelitemiv}{$\ast$} % % \begin{enumerate}[label=\roman*), topsep=0pt, itemsep=-1ex, partopsep=1ex, parsep=1ex] \item {\texttt{\textbackslash topsep}}: space between first item and preceding paragraph. \item {\texttt{\textbackslash partopsep}}: extra space added to {\texttt{\textbackslash topsep}} when environment starts a new paragraph \begin{enumerate}[nosep] \item Is \begin{enumerate}[nosep] \item this \begin{enumerate}[nosep] \item Inception? \end{enumerate} \end{enumerate} \end{enumerate} \item {\texttt{\textbackslash itemsep}}: space between successive items. \end{enumerate} \end{Verbatim} \end{tcolorbox} \renewcommand{\labelitemi}{$\bullet$} \renewcommand{\labelitemii}{$\cdot$} \renewcommand{\labelitemiii}{$\diamond$} \renewcommand{\labelitemiv}{$\ast$} \begin{enumerate}[label=\roman*),topsep=0pt,itemsep=-1ex,partopsep=1ex,parsep=1ex] \item {\texttt{\textbackslash topsep}}: space between first item and preceding paragraph. \item {\texttt{\textbackslash partopsep}}: extra space added to {\texttt{\textbackslash topsep}} when environment starts a new paragraph \begin{enumerate}[nosep] \item Is \begin{enumerate}[nosep] \item this \begin{enumerate}[nosep] \item Inception? \end{enumerate} \end{enumerate} \end{enumerate} \item {\texttt{\textbackslash itemsep}}: space between successive items. \end{enumerate} \noindent A more succinct way to remove all spacing is to use the option {\texttt{\textbackslash nosep}}. \subsection{Buttons using Tikz (EE4)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \usepackage{tikz} \usetikzlibrary{calc} \end{Verbatim} \end{tcolorbox} We can also draw a button with Tikz drawing. I'll put the code below, which is borrowed from \href{https://tex.stackexchange.com/questions/7566/is-there-a-way-to-draw-3d-style-buttons}{StackOverflow}. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Drawing a Button, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \begin{tikzpicture}[ button/.style={ rectangle, minimum size=6mm, very thick, rounded corners, draw=red!50!black!74, top color=red!50!black!70, bottom color=white, }] \node[button] (button) {Button Text!}; \begin{scope}[opacity=.6, transparency group] \draw[white,fill=white,rounded corners={2pt}] ($ (button.north west) + (3pt,-3pt) $) rectangle ($ (button.north east) + (-3pt,-8pt) $); \draw[white,fill=white,rounded corners={.5pt}] ($ (button.north west) + (3pt,-5pt) $) rectangle ($ (button.north east) + (-3pt,-8pt) $); \end{scope} \draw[white,fill=white,opacity=.8,rounded corners={1pt}] ($ (button.south west) + (5pt,2pt) $) rectangle ($ (button.south east) + (-5pt,4pt) $); \end{tikzpicture} \end{Verbatim} \end{tcolorbox} \begin{tikzpicture}[ button/.style={ rectangle, minimum size=6mm, very thick, rounded corners, draw=red!50!black!74, top color=red!50!black!70, bottom color=white, }] \node[button] (button) {Button Text!}; \begin{scope}[opacity=.6, transparency group] \draw[white,fill=white,rounded corners={2pt}] ($ (button.north west) + (3pt,-3pt) $) rectangle ($ (button.north east) + (-3pt,-8pt) $); \draw[white,fill=white,rounded corners={.5pt}] ($ (button.north west) + (3pt,-5pt) $) rectangle ($ (button.north east) + (-3pt,-8pt) $); \end{scope} \draw[white,fill=white,opacity=.8,rounded corners={1pt}] ($ (button.south west) + (5pt,2pt) $) rectangle ($ (button.south east) + (-5pt,4pt) $); \end{tikzpicture} \section{Algorithm and Pseudocode (FF)} \begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=Imports, drop shadow, skin=enhanced, fonttitle=\bfseries, ] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \usepackage{algorithm} % \usepackage{algorithmicx} % automatically imported via algpseudocode \usepackage[noend]{algpseudocode} % noend = no keyword "end", e.g. "end if" \end{Verbatim} \end{tcolorbox} Looking online for packages for writing algorithms, one immediately finds there are a variety of packages that all appear to do the same thing. Naturally, one asks: which one do I use? I especially like \href{https://tex.stackexchange.com/questions/229355/algorithm-algorithmic-algorithmicx-algorithm2e-algpseudocode-confused/230789#230789?s=7b7f3d6980444fc9951ed918fdce0142}{this answer}, which I will summarize below. \begin{enumerate} \item \texttt{\textbackslash algorithmic} - basic and first algorithm typesetting environment. Think of this as version 1 \item {\texttt{\textbackslash algorithmicx}} - second and more customizable algorithm typesetting environment. Note that this package `` itself doesn’t define any algorithmic commands (e.g. \texttt{If}, \texttt{For}), but gives a set of macros to define such a command set''. Instead, one can import predefined commands (layouts) such as \texttt{algpseudocode}. \item \texttt{\textbackslash algorithm2e} - third typesetting environment \item {\texttt{\textbackslash algorithm}} - float wrapper. I.e., one writes their \texttt{algorithmic} or \texttt{algorithmicx} \textit{within} this to prevent page breaks, specify positioning, and starting line numbers. Makes it easier to read. \item {\texttt{\textbackslash algpseudocode}} - this is a layout style included in \texttt{algorithmicx} that mimics the style found in the \texttt{algorithmic} package. As previous described, this package will define the common algorithm macros in \texttt{algorithmicx} for us. Other layouts include \texttt{algcompatible}, \texttt{algpascal} (mimics pascal), and \texttt{algc} (mimics C). \end{enumerate} \vspace{10pt} \noindent \LaTeX users and myself seem to use the \texttt{algorithmicx} with the \texttt{algpseudocode} layout combined with the float wrapper \texttt{algorithm}. Note that if you import \texttt{algpseudocode} you do not need to import \texttt{algorithmicx} since the former imports the latter (\href{http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf#page=5}{source}). The main predefined macros are \texttt{\textbackslash For}, \texttt{\textbackslash While}, \texttt{\textbackslash Repeat}, \texttt{\textbackslash If\{$\langle Condition\rangle$\}} and \texttt{\textbackslash ElsIf} and \texttt{\textbackslash Else}, \texttt{\textbackslash Procedure\{$\langle name\rangle$\}\{$\langle params\rangle$\}}, \texttt{\textbackslash Function\{$\langle name\rangle$\}\{$\langle params\rangle$\}}, and \texttt{\textbackslash Loop}. When invoking these, make sure to end with and \texttt{\textbackslash EndX}, where X is the macro that is used. E.g., \texttt{\textbackslash EndFor}. Lines that are just code (i.e. $x = 5 + y$) start with the macro \texttt{\textbackslash State}. \begin{tcolorbox}[colback=red!5,colframe=red!40!black,title=Input an Image, drop shadow, skin=enhanced, fonttitle=\bfseries, breakable] \begin{Verbatim}[baselinestretch=0.1, breaklines=true] \begin{algorithm} \begin{algorithmic}[1] \caption{Breadth First Search} \Procedure{BFS}{$G=(V,E)$, $s \in V$} \State $X \gets \texttt{queue}(\{s\})$ \Comment{Becomes DFS if use stack} \While{$X \ne \emptyset$} \State $curr \gets X.\texttt{pop}()$ \State $curr.visited = \texttt{True}$ \State $\texttt{print}(curr)$ \For{$v \in N(curr)$} \If{$! v.visited$} \State $X.\texttt{push}(v)$ \EndIf \EndFor \EndWhile \EndProcedure \end{algorithmic} \end{algorithm} \end{Verbatim} \end{tcolorbox} \begin{algorithm}[H] \begin{algorithmic}[1] \caption{Breadth First Search} \Procedure{BFS}{$G=(V,E)$, $s \in V$} \State $X \gets \texttt{queue}(\{s\})$ \Comment{Becomes DFS if use stack} \While{$X \ne \emptyset$} \State $curr \gets X.\texttt{pop}()$ \State $curr.visited = \texttt{True}$ \State $\texttt{print}(curr)$ \For{$v \in N(curr)$} \If{$! v.visited$} \State $X.\texttt{push}(v)$ \EndIf \EndFor \EndWhile \EndProcedure \end{algorithmic} \end{algorithm} \noindent Note that instead of procedure, we can use \texttt{Function} instead. Typically, a function is synonmous with \textit{returning} whereas \texttt{Procedure} is for running a set of commands. \section{Other Tricks (GG)} For increased spacings between paragraphs, we can use \texttt{\textbackslash \textbackslash [\textbackslash defaultaddspace]} instead of the (often too large) \texttt{\textbackslash \textbackslash}. For between lines, we can similarly use \texttt{\textbackslash \textbackslash hspace\{10pt\}}. \newline \noindent While you want to include a backslash, use the command \texttt{\textbackslash textbackslash}.\newline \medskip \bibliographystyle{unsrt} \bibliography{biblio} \end{document}