LaTeX

LaTeX is the language used in .tex files. It's mostly used to write formal documents such as

  • ๐Ÿ“ Text documents (books, reports, resumes...)
  • ๐Ÿซ Articles/thesis (academic research...)
  • ๐ŸŽ‰ Presentations (slides for programmers...)
  • ...

Where to learn?

Some qualities of LaTeX are

  • ๐ŸŒ Cross-platform
  • ๐Ÿชง Consistency
  • ๐Ÿงฎ Support for math formulas
  • ๐Ÿง‘โ€๐Ÿ’ป Support for code samples

Some ways to write LaTeX:

  • Overleaf: collaborative online tool (account required)
  • CoCalc (๐Ÿ‘ป)

โžก๏ธ LaTeX templates: Overleaf


Basics

A basic document looks like this. You can import packages, and you start writing inside the document block.

\documentclass{article} % book...
% import packages (preamble)
\usepackage[utf8]{inputenc}

\begin{document}
% body of the document
\end{document}

Document

\title{A title}
\author{An author}
\date{A date}

Usually before starting the document, we define some metadata. Then, inside the body, we can generate a title page with \maketitle.

Text

You can write text and use these to apply some style:

  • \textbf{word}: bold
  • \underline{word}: underlined
  • \textit{word}: italic
  • \emph{word}: emphasis, almost like italic
  • \vspace{NUMBERmm}: space between paragraphs

โžก๏ธ To force a newline, use \\ (once or twice) or \newline.

โžก๏ธ To center something, use \begin{center}something\end{center}.

Lists

\begin{itemize}
  \item an item
  \item an item
\end{itemize}

Use enumerate for ordered lists, and itemize for unordered lists.


Code in LaTeX

You can use the minted to write code in LaTeX.

\usepackage{minted}

You need to define a language, for instance, ocaml.

\newminted{ocaml}{breaklines}

โžก๏ธ You can write a block of code using this syntax:

\begin{minted}{ocaml}...\end{minted}

โžก๏ธ You can import a file using this syntax:

`\inputminted{ocaml}{file.ml}

๐Ÿ‘‰ There is also a package called listings.


Math in LaTeX

Math symbols or formulas can be either inline meaning inside a text, or block-level meaning they will take up a whole line.

  • ๐Ÿ’ฌ inline: $latex$ or \(latex\)
  • ๐Ÿงฎ block: \[latex\] or \begin{equation}latex\end{equation}

๐Ÿ‘‰ Use AtomURL to get the LaTeX code for most mathematical symbols and formulas.

๐Ÿ‘‰ With detexify, draw a symbol and get the LaTeX code.

โžก๏ธ Spaces are merged into one. Use \ to prevent it or use \quad.

โžก๏ธ You can create a horizontal space with \hspace{1cm}.

โžก๏ธ You can use \mathcal{H} for function names/...

โžก๏ธ Use \lfloor/\rfloor and \lceil/\rceil for the rounding symbols (partie entiรจre). Use \lvert/\rvert for absolute values.

๐ŸŒ Use mathjax or katex to render LaTeX formulas in a browser.


๐Ÿ‘ป To-do ๐Ÿ‘ป

Stuff that I found, but never read/used yet.

\verb! http://localhost:3000/!
\textbackslash{xxx}
\noindent
% https://tex.stackexchange.com/questions/450156/latex-indent-with-alphabet-list
\begin{enumerate}
    \item[$a)$] XXX
\end{enumerate}
\pagestyle{empty}\pagestyle{plain}\setcounter{page}{1}
\phantomsection
\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}