> LaTeX is a high-quality typesetting system; it includes features designed for the production of technical and scientific documentation. LaTeX is the de facto standard for the communication and publication of scientific documents. ## Documentation - [Appendix](http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/appendix/appendix.pdf) - [Latex Cheat Sheet](https://wch.github.io/latexsheet/latexsheet.pdf) - [Excel Tabular Data To LaTeX Tabular](https://tableconvert.com/?output=latex) - [LaTeX Wiki Book](https://en.wikibooks.org/wiki/LaTeX) - [LaTeX Short Intro](https://tobi.oetiker.ch/lshort/lshort.pdf) - [LaTeX Lecture notes in vim](https://castel.dev/post/lecture-notes-1/) ## Tricks - `\part` - `\chapter` - `\section` - `\subsection` - `\subsubsection` - `\paragraph` - `\subparagraph` Starred versions do not show up in the table of contents ### Draft Watermark <https://tex.stackexchange.com/questions/118939/add-watermark-that-overlays-the-images> Figures overlay the watermark: ```latex \documentclass{article} \usepackage[printwatermark]{xwatermark} \usepackage{xcolor} \usepackage{graphicx} \usepackage{lipsum} \newwatermark[allpages,color=red!50,angle=45,scale=3,xpos=0,ypos=0]{DRAFT} \begin{document} \lipsum[1-2] \begin{figure}[!ht] \centering \includegraphics[width=3cm]{example-image-a} \end{figure} \lipsum[1-2] \end{document} ``` Figures covered by watermark: ```latex \documentclass{article} \usepackage[printwatermark]{xwatermark} \usepackage{xcolor} \usepackage{graphicx} \usepackage{lipsum} \newwatermark*[allpages,color=red!50,angle=45,scale=3,xpos=0,ypos=0]{DRAFT} \begin{document} \lipsum[1-2] \begin{figure}[!ht] \centering \includegraphics[width=3cm]{example-image-a} \end{figure} \lipsum[1-2] \end{document} ``` ### Modular Documents `\input{<included file>}` This command take an entire `.tex` file with no preamble or meta content just text, sections, etc and drops it in this location like a header file in C. useful for modularizing your documentation ## Preamble ### Abstract To make an abstract for the paper you can use the abstract environment just after the `\maketitle` command: ```latex \maketitle \begin{abstract} <Your Content> \end{abstract} ``` ### Author To pass in your author credentials you can use `\author{Bryan Jenks}` and to use it as another argument in another command you can also use `\theauthor` ```latex % Overwrite existing command '\maktitle' \renewcommand{\maketitle}{ \begin{center} {\huge\bfseries *\theauthor*} \vspace{.25em} my email --- https://www.bryanjenks.xyz \end{center} } % first new arg from titling package ``` ### Custom Commands To create a new command that provides new behavior or functionality use the `\newcommand` command ```latex \newcommand{<your commands name>}[<number of arguments it takes>] {what your command does} ``` ```latex \newcommand{\bryan}[3]{\textit{#1}, \textbf{#2}, \underline{#3}} ``` ### Title `\title{My {\LaTeX} R\'esum\'e}` your title is defined in the title command but this is outsize of your document body, inside the document body you actually call: `\maketitle` to render your title onto the document you can customize the title with the [[#Titling]] package and the renewcommand command like so: ```latex \renewcommand{\maketitle}{ \begin{center} {\huge\bfseries \theauthor} \vspace{.25em} my email --- https://www.bryanjenks.xyz \end{center} } % first new arg from titling package ``` #### Documentation - [titlesec](https://mirrors.concertpass.com/tex-archive/macros/latex/contrib/titlesec/titlesec.pdf) #### Title Format ```latex \\titleformat{\<command\>}[\<shape\>] {\<format\>} {\<label\>} {\<sep\>} <!-- The Only required Arg --> {\<before-codee\>}[\<after-code\>] ``` ##### Examples ```latex \titleformat{\section}[frame] {\huge} {} {.25em} % The only required argument {\filcenter\bfseries\lowercase}% Horizontal line [\titlerule] % Optional param % SubSection Formatting \titleformat{\subsection} {\bfseries\Large} {\hspace{-.25in}$\bullet$} {.3em} {} % SubSubSection Formatting \titleformat{\subsubsection}[runin] % Optional param {\bfseries} {} {0em} {}[---] \titleformat{\section}[frame] {\normalfont} {\filright\footnotesize\enspace SECTION \thesection\enspace} {8pt} {\Large\bfseries\filcenter} ``` #### Title Spacing ```latex \\titlespacing*{command} {left} {before-sep} {after-sep}[right-sep] ``` ##### Examples ```latex \titlespacing{\subsubsection} {0em} % Left Margin {.25em} % Line Spacing {0em} % Right Margin ``` ## Document Class ### Article Does not work with `\chapter{}` as it is meant for short form writing, for long form use the [[LaTeX#Report|Report]] Document class ### Report This is meant for long form documentation unlike the [[LaTeX#Article|Article]] document class and an example using a chapter argument is below: ```latex \documentclass{report} \begin{document} \chapter{this is intersting} in this chapter i hope to... \section{section 1} this is the first section where stuff happens \section{section 2} \subsection{sub section 1} Oi hello world \subsection{sub section 2} \subsubsection{sub sub section 1} tis but a test \section{this is section 3} \section{this is section 4} ending thoughts... \end{document} ``` ## Document Components ### Table of Contents `\tableofcontents`: displays the table of contents, good to use after maketitle and abstract ### Figures ```latex \\begin{wrapfigure}{\<orientation `r` or `l`\>}{\<space to take up like 3in\>} \<your figure here\> \\end{wrapfigure} ``` to wrap a figure with text use the following code: ```latex \begin{wrapfigure} <your figure here> \end{wrapfigure} ``` ### Labels And References `\label{}` This will add an invisible label to any item like so: ```latex \section{Lists\label{List}} \item Butter \label{butter} ``` `\ref{}` This is the number of the referenced label if its the 3rd item then it will display only a '3' `(\ref{})` The same as above but wrapped in parens ### Lists `\begin{enumerate}` this is a numbered ordered list \\&lt;your items in here> `\end{enumerate}` `\begin{itemize}` this is an unordered bullet list \\&lt;your items in here> `\end{itemize}` `\item` \\&lt;your item text> ## Packages ### Beamer - [theme gallery](http://deic.uab.es/~iblanes/beamer_gallery/index_by_theme.html) #### Frame Title Inside the frame environment you run this command to give your slide a title ```latex \begin{frame} \frametitle{Roadmap} \end{frame} ``` #### Pauses For your slides to pause on say a list populating on the screen use pause to control it ```latex \begin{itemize} \item frame\pause \item beamer themes\pause \item pauses and slides\pause \item sections\pause \item images \item columns \end{itemize} ``` #### Sections in beamer the `\section{<section name>}` command will appear at the top of the slide deck slides and it also like a hyper link and they are evenly distributed spatially too. ### biblatex Use the package via: `\usepackage[backend=biber, style=authoryear-icomp]{biblatex}` `\addbibresource{<file path to .bib file>}` To print our your bibliography: `\printbibliography` `\textcite{<ref>}` will add a reference like _Mould [1]_ but 'Mould' would be the name of the ref you passed in and it has that number but adding `style=authoryear-icomp` to the biblatex package optional arg will change it to _Mould (2003)_ with no brackets and numbers `\parencite{<ref>}` is what I typically like and use and appears like _(Mould 2003)_ #### Documentation - [OverleafOnBiber](https://www.overleaf.com/learn/latex/Bibliography_management_with_bibtex) --- - address - annote - author - booktitle - chapter - crossref - edition - editor - institution - journal - key - month - note - number - organization - pages - publisher - school - series - title - type - volume - year - URL - ISBN - ISSN - LCCN - abstract - keywords - price - copyright - language - contents #### Notes This package is used for references and bibliographies ##### Reference guide ###### Standard entry types - **article** - Article from a magazine or journal - **booklet** - A work that is printed but have no publisher or sponsoring institution - **conference** - An article in a conference proceedings - **inbook** - A part of a book (section, chapter and so on) - **incollection** - A part of a book having its own title - **inproceedings** - An article in a conference proceedings - **manual** - Technical documentation - **masterthesis** - A Master's thesis - **misc** - Something that doesn't fit in any other type - **phdthesis** - A PhD thesis - **proceedings** - The same as conference - **techreport** - Report published by an institution - **unpublished** - Document not formally published, with author and title ### Fancy Header [Documentation](http://texdoc.net/texmf-dist/doc/latex/fancyhdr/fancyhdr.pdf) ### Geometry [Documentation](http://www.texdoc.net/texmf-dist/doc/latex/geometry/geometry.pdf) ### Graphicx - [Documentation](http://texdoc.net/texmf-dist/doc/latex/graphics/graphicx.pdf) he `\includegraphics{}` command is used to add images to a document and can take several optional parameters in square brackets as well an example of this function is: `\includegraphics[width=3in,height=5in,keepaspectratio,scale=0.5]{<path to image file.png>}` #### Params _width_: Obvious ``` - `width=\textwidth`: it will fit in within the span of a line of text or `width=0.5\textwidth` to fit it in 50% of the space of the width of your text span ``` _height_: Obvious _keepaspectratio_: uses width and height as maximum value args and make image keep its aspect ration _scale_: basically like saying the image should be a percentage of its original size so using a decimal like `scale=0.5` for 50% scale _angle_: this will rotate the image and uses a 360 degree number for the angle of rotation and to take an image and center it we can add it to the center environment `\begin{center}` `\includegraphics[width=3in]{<path to image file.png>}` `\end{center}` to center a figure you can use this example: ```latex \begin{figure} \begin{center} \includegraphics[width=0.3\textwidth]{../Pictures/archLinuxLogo.png} \end{center} \end{figure} ``` Figures are more flexible and they come with added bonuses like captions and automatic numbering which you can add or mess with this way ```latex \begin{figure} \begin{center} \includegraphics[width=0.3\textwidth]{../Pictures/archLinuxLogo.png} \caption{this is my caption} \end{center} \end{figure} ``` to center a figure you can also use the following command `\centering` with the figure code block ```latex \begin{figure} \centering \includegraphics[width=0.3\textwidth]{../Pictures/archLinuxLogo.png} \caption{this is my caption} \end{figure} ``` to keep a figure inline where you write it in you need to pass an optional arg to the figure command `[h]` ```latex \begin{figure}[h] \centering \includegraphics[width=0.3\textwidth]{../Pictures/archLinuxLogo.png} \caption{this is my caption} \end{figure} ``` the optional arg `[t]` will put the figure at the top of the page `\begin{figure}[t]` and `[b]` will put it at the bottom and `[p]` will put it on a page of its own ### Tikz #### Flow Chart ```latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Welcome to Overleaf --- just edit your LaTeX on the left, % and we'll compile it for you on the right. If you open the % 'Share' menu, you can invite other users to edit at the same % time. See www.overleaf.com/learn for more info. Enjoy! % % Note: you can export the pdf to see the result at full % resolution. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Decision tree % Author: Stefan Kottwitz % https://www.packtpub.om/hardware-and-creative/latex-cookbook \documentclass[border=10pt]{standalone} %%%< \usepackage{verbatim} %%%> \begin{comment} :Title: Decision tree :Tags: Trees;Cookbook :Author: Stefan Kottwitz :Slug: decision-tree A horizontal tree, growing to the right. I created a basic style for tree nodes, and derived styles for specific kinds of nodes. \end{comment} \usepackage{tikz} \tikzset{ treenode/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!20}, root/.style = {treenode, font=\Large, bottom color=red!30}, env/.style = {treenode, font=\ttfamily\normalsize}, dummy/.style = {circle,draw} } \begin{document} \begin{tikzpicture} [ grow = right, sibling distance = 6em, level distance = 10em, edge from parent/.style = {draw, -latex}, every node/.style = {font=\footnotesize}, sloped ] \node [root] {Formula} child { node [env] {equation} edge from parent node [below] {single-line?} } child { node [dummy] {} child { node [dummy] {} child { node [env] {align\\flalign} edge from parent node [below] {at relation sign?} } child { node [env] {alignat} edge from parent node [above] {at several} node [below] {places?} } child { node [env] {gather} edge from parent node [above] {centered?} } edge from parent node [below] {aligned?} } child { node [env] {multline} edge from parent node [above, align=center] {first left,\\centered,} node [below] {last right}} edge from parent node [above] {multi-line?} }; \end{tikzpicture} \end{document} ``` ```latex \usepackage{tikz} \usetikzlibrary{shapes.geometric, arrows} \tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30] \tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30] \tikzstyle{process} = [rectangle, text width=3cm, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30] \tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30] \tikzstyle{arrow} = [thick,->,>=stealth] \begin{tikzpicture}[node distance=2cm] \node (start) [startstop] {start}; \node (in1) [io, below of=start] {Input}; \node (pro1) [process, below of=in1] {Process 1}; \node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1}; \node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a}; \node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b}; \node (out1) [io, below of=pro2a] {Output}; \node (stop) [startstop, below of=out1] {See Step \textbf{\ref{test}}}; \draw [arrow] (start) -- (in1); \draw [arrow] (in1) -- (pro1); \draw [arrow] (pro1) -- (dec1); \draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a); \draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b); \draw [arrow] (pro2b) |- (pro1); \draw [arrow] (pro2a) -- (out1); \draw [arrow] (out1) -- (stop); \end{tikzpicture} ``` #### Documentation - [Tikz Documentations](http://texdoc.net/texmf-dist/doc/generic/pgf/pgfmanual.pdf) - [Short Intro To Tikz](https://cremeronline.com/LaTeX/minimaltikz.pdf) ### Titling `\renewcommand` [Documentation](http://www.texdoc.net/texmf-dist/doc/latex/titling/titling.pdf) ### Todo Notes `Todonotes` is a way to allow visual note items in your compiled LaTeX document The notes can be customized for different colors and themes to correspond to different topics/categories and can be placed in-line, in the margins, and even be used as placeholders for figures that have not yet been added. ```latex % Documentation \todo{this is my todo note} \todo[inline]{here is an inline todo note} \todo[background=red]{a note with a different background color} ``` #### Documentation - [texdoc documentation](http://texdoc.net/texmf-dist/doc/latex/todonotes/todonotes.pdf) ## Math ### Resources - <https://castel.dev/post/lecture-notes-1/> - <https://arachnoid.com/latex/> ### Math Environment to use LaTeX math you need to create a math environment: ``` $MATH GOES HERE$ ``` When rendered this will look like: $MATH GOES HERE$ This is an in-line equation For a multi-line equation that also centers itself you use double dollars ``` $MATH GOES HERE$ ``` Rendered it will center: $MATH GOES HERE$ ### Insertable Symbols #### Arrays and Matrices $ \Bigg\{\,\begin{array}{rcl} 0&6&6 \\ 0&6&6 \\ 0&6&6 \\ \end{array}\,\Bigg\} $ #### Calligraphic letter `\mathcal{LETTER}` == $\mathcal{LETTER}$ #### Dots Vertical dots == _$\vdots$_ Centered dots == _$\cdots$_ Low dots == _$\ldots$_ diagonal dots == _$\ddots$_ using the spacer comma `\,` _$\{2,3,\,\ldots\}$_ #### Fences - [ ] TODO #### Greek [[Greek Letters In Statistics]] `$\Sigma\,\Delta$` == $\Sigma\,\Delta$ #### Spacing | **LaTeX** | _Code_ | | :----------- | :------------- | | $x\,y$ | `$x\,y
| | $x\:y$ | `$x\:y
| | $x\;y$ | `$x\;y
| | $x \quad y$ | `$x \quad y
| | $x \qquad y$ | `$x \qquad y
| | $x\!y$ | `$x\!y
| Sometimes you may want some extra space between elements and a space wont work and you need something like `\,`: 50285a `\Sigma \Delta` == $\Sigma \Delta$ v.s. `\Sigma\,\Delta` == $\Sigma\,\Delta$ There is now a slight space between the two ### Common Constructs - `x^2` = $x^2$ d77d52 - `x_{ij}` = $x_{ij}$ 8a61f1 - `\sqrt{4}` = $\sqrt{4}$ - `\sqrt[n]{4}` = $\sqrt[n]{4}$ cc4666 - `\frac{2}{3}` = $\frac{2}{3}$ ### Escaped Operators and Characters things like `\pi` yield $\pi$ they have no braces `{ }` or brackets `[ ]` and instead are just themselves. This means they can be inserted into other commands and the only limitation might be a space after the escaped sequence so that it doesnt turn into something like `\pix` when you wanted $\pi x$ #### Equations are like sentences These sequences all together read like a sentence with symbols and syntax determining positioning and what is rendered in a logical format ```latex $\sum_{j=0}^7j^2$ ``` $\sum_{j=5}^7j^2$ Reads like "_$\sum$_, then below it add _$J=5$_, raise that whole combo to the power of _$7$_ then adjacent to that place _$J^2$_. ### Grouping Items using the braces `{ }` we can group items together V.S. `x_ij` = $x_ij$ Where the `J` is back at the normal level not the subscript level ### Optional Arguments Some commands take optional arguments in square brackets `[ ]` ### Super and sub script Super uses a carat `^` Sub-script uses an underscore `_`