From David's Wiki
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

Typeset all of your papers using latex.


No Install

Use Overleaf to create latex documents in a web browser.

Partial Install

Download MikTex. It includes the TeXworks editor and will download packages as you use them. This will not take up as much disk space as a full install but will require internet access to download new packages.

Full Install


Download TexLive using the ISO images.
This is ~4 gigabytes since it includes all the popular LaTeX packages and takes a while to install. You'll also need an editor. I recommend installing Atom with the following packages:

  • latex for calling the TexLive compiler
  • language-latex for syntax highlighting
  • pdf-view for viewing the compiled pdf.
apm install latex language-latex pdf-view


sudo apt install texlive-full

Compile tex documents with

pdflatex [mydocument.tex]
  • Note to add bibliography, you need to run pdflatex, bibtex, pdflatex or rubber --pdf.


Fancy Math Font

See this answer.

% Use mathbb for the set of reals R or the set of complex numbers C
% Requires amsfonts


See Reference

Spaces in mathematical mode.
f(x) =& x^2\! +3x\! +2 \\
f(x) =& x^2+3x+2 \\
f(x) =& x^2\, +3x\, +2 \\
f(x) =& x^2\: +3x\: +2 \\
f(x) =& x^2\; +3x\; +2 \\
f(x) =& x^2\ +3x\ +2 \\
f(x) =& x^2\quad +3x\quad +2 \\
f(x) =& x^2\qquad +3x\qquad +2


For spacing between elements, use \hspace or \vspace.


Units in Latex
You can specify spacing in pt, mm, cm, ex, em, bp, dd, pc, in



   Indented Section



To change the section numbering from numbers to letters, add the following:

% Changes sections to use capital letters

% Changes subsections to use lowercase letters


Latex is a turing complete language.
You can use if statements and for loops in latex.

Custom Commands

You can define your own commands using \newcommand

\newcommand{\notdone}{{\color{red} Not done!!}}

Custom Operators

Latex packages like amsmath come with operators such as \sin and \log.
To get normal text for custom functions like arcsin, use \operatorname{arcsin}.
Below are some potentially useful math operators.

  • Adding * puts subscript elements beneath the operator.


For Each Loops

\foreach [count=\i] \j in {A,B,...,H}{
Element \i~is \j\\

Page Layout

There are many packages which adjust the page layout.
You can use the package wordlike for a MS Word layout.


Font size
Font type
  • Times New Roman - \usepackage{mathptmx}


Multirow and Multicolumns


\multirow{3}{4em}{Dataset A}


stackexchange line break in table cell
linebreak in multirow

To have a newline in a cell, you can use the makecell package.
\makecell{Some really \\ longer text}.
To make this align left: \makecell[l]{Some really \\ longer text}

For multirow cells, you can use \multirowcell{5}{Numbers\\from\\ 1 to 5}.
By default, this will align center. You can make it align left: \multirowcell{2}[0pt][l]{Number\\ Letter}.

Table Generator can generate table code from existing tables.



Be sure to use vector figures (pdf or pgf) instead of raster ones (png, jpeg).
See on how to export matplotlib to pgf.

In the snippet [!htbp] represents the placement preferences.

  • ! means to ignore some placement limitations
  • h mean to place the figure here
  • t means top of the page.
  • b means bottom of the page.
  • p means to place it on a figure only page.

If you add the the float package, you can also use [!H] which is a more strict version of [!h].


See overleaf reference

% In the header:

    \caption{This is graph1.}
    \caption{This is graph2.}


Enumerate is used to make lists

Change the label

Add the option for the labels:

  • label=(\alph*) for letters
  • label=(\Alph*) for upper-case letters
  • label=(\roman*) for roman numerals.
  • label=(\arabic*) for numbers
\item an apple
\item a banana
\item a carrot
\item a durian

Other Options

  • font=\bfseries for bold labels
  • align=left left align labels

Useful Commands

A list of potentially useful commands.
You can paste the following an a Macros.tex file and \input{Macros} in your main tex file.

\newcommand{\degree}{\ensuremath{^{\circ}} }
\newcommand{\etal}{{\em et al.}}
\newcommand{\ceil}[1]{{\lceil #1 \rceil}}
\newcommand{\floor}[1]{{\lfloor #1 \rfloor}}


Bibliography (Bibtex)

How to do references in Latex.
Bibtex Examples


Use \cite or some variant to cite references.
Natbib reference sheet

# Defaults to author-year citations
# For numerical citations

# If using author-year citations
\citet{jon90} ⇒ Jones et al. (1990)
\citep{jon90} ⇒ (Jones et al., 1990)
\citep[see][]{jon90} ⇒ (see Jones et al., 1990)

# If using numerical citations
\citet{jon90} ⇒ Jones et al. [21]
\citep{jon90} ⇒ [21]
\citep[see][]{jon90} ⇒ [see 21]

Case of Titles

If you do not want lower case titles, you can change your .bst file by commenting out the portion which alters the case.

FUNCTION {format.title}
  %title empty$
  %  { "" }
  %  { title "t"$ }


Tikz is used to draw graphs and other shapes

Drawing over images

    \node[anchor=south west,inner sep=0] (image) at (0,0) {
    };<br />
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[black,ultra thick,rounded corners] (0.0,0.1) rectangle (0.3,0.5);
        \draw[red,ultra thick,rounded corners] (0.5,0.1) rectangle (0.8,0.5);
        % \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
        % \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
        % \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }


How to insert pseudocode into your Latex document.

See algorithmc vs algorithmcx vs algorithm2e
Also Wikibooks: LaTeX/Algorithms for several examples


The algorithms bundle


The algorithmicx package




 \KwData{this text}
 \KwResult{how to write algorithm with \LaTeX2e }
 \While{not at end of this document}{
  read current\;
   go to next section\;
   current section becomes this one\;
   go back to the beginning of current section\;
 \caption{How to write algorithms}


The verbatim package gives you the environment verbatim. You can use \verbatiminput to embed text files.


The fancyvrb package gives you the environment Verbatim which has more options.
To embed in a figure, you can use BVerbatim.
There is also \VerbatimInput, \BVerbatimInput, \LVerbatimInput.

Document Class

Overleaf Writing your own class
Document classes are .cls files which provide a layout for your document. By writing your own document class, you can ensure a consistent layout across multiple latex documents. You can also encapsulate commands and macros or package requirements within your document class.


See Wikibooks: LaTeX/Document Structure for a list of common document classes and options.


Below is a basic example of a latex document

Article Example
\usepackage{lipsum}<br />

  \monthname[\THEMONTH] \THEYEAR}

\title{My Main Title\\
\large A Subtitle}
\author{My Name}










On Linux, you can convert PDF files to PNG files using:

pdftoppm paper.pdf paper-page -r 300 -png
  • -r specifies the DPI. Default is 150.

Latex Cleanup

If you need to submit the latex, e.g. to Arxiv, you can use this tool to help clean it up: