LaTeX Tutorial
LaTeX Tutorial
Stephanie Yao
1 Introduction
What is LATEX? LATEX is a macro language that lets you create PDFs out of code. It is made to handle formulas
well. It streamlines cross-page references. Science book/article use LATEX for publication in standard.
Keep bookkeeping information after the \documentclass{article} command and before \begin{document},
a place known as the preamble.
Materials between \begin{document} and \end{document}, a place known as the document body, show up
in the PDF.
LATEX Editors You can install a LATEX engine on your computer to compile LATEX. There are various LATEX Ed-
itors, including TeXLive, TeXmaker, vim, VSCode, etc. This tutorial recommends Overleaf, an awesome online
LATEXcompiler with collaboration features and a visual editor, which is very friendly to new LATEX users.
Commands For math mode, LATEX use , ^ for subscript and superscript respectively. To type them in text,
use \_, \^ . Similarly, to type $, %, & in text, use \$, \%, \& . For \, use $\backslash$
For example,
Command Symbol
PQ TS
$\sum\prod\cap\cup\bigcap\bigcup$ ∩∪
$\alpha \beta ... \omega$ αβγδϵεζηθϑικλµνξoπϖρϱσςτ υϕφχψω
Pn
$\sum^{n}_{i=1} n$ i=1 n
\LaTeX LATEX
$ < \leq \nleq > \geq \ngeq = \neq \approx$ <≤≰>≥≱≠=≈ ∀∃∀∃
$\in \subset \subseteq \nsubseteq \notin \varnothing$ ∈⊂⊆⊈∈/ ∀ ∃∅
R RR
$\partial \nabla \int \iint \Im \Re$ ∂∇ ℑℜ
$10 \equiv 1 \pmod{3}$ 10 ≡ 1 (mod 3)
$\rightarrow \Rightarrow \longrightarrow$ →⇒−→
$\mathbb{R}\mathbb{Q}\mathbb{Z}\mathbb{N}$ RQZN
$+ - \times \cdot \frac{a}{b}$ + − × · ab
Some of them are not so intuitive, but you can use Detexify, Mathpix to recognize symbols, or through some
LATEX Math Symbol lists
E
Inline Math Inline math can be inserted by using the dollar symbol $...$ and contents should be put
between the dollar marks. For example, $1+1+2$ will convert into 1 + 1 = 2.
Displayed Math When you want to separate the formulas from the text to make it a different line and centered,
you can use \[...\] or $$...$$ . \[...\] is more considered to be used when writing paper because
sometimes $$...$$ gets wrong without reasons (very old version command) while \[...\] always works.
For example,
compiles as
Difference in Math Symbols in Inline and Displayed Math limδx→0 f (x) and
lim f (x)
δx→0
are different in the position of δx → 0, to force inline math act the same as displayed ones, add \displaystyle
at the front.
For example,
n
X n
Y Pn Qn
can compile as lim f (x), ai , aj , different from limδx→0 f (x), i=1 ai , i=1 aj . The display style
δx→0
i=1 i=1
fraction originally exists as $\dfrac{}{}$ .
n
X
New Commands It is very annoying to type ai every time I am writing this in inline math, therefore we
i=1
want to change the command.
The command can be changed by inserting \newcommand{}[]{} at the preamble.
Here are a few examples
\newcommand{\dsum}{\displaystyle\sum}
% type the new command in the first brace, equivalent original command in the second brace
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
% $\floor{#1}=\lfloor #1 \rfloor$
\newcommand{\leg}[2]{\left(\dfrac{#1}{#2}\right)}
% $\leg{#1}{#2}=\left(\dfrac{#1}{#2}\right)$
n
X 16 2
ai , ⌊0.5⌋ = 0,
i=1
9 3
Align When writing papers, sometimes we write multiple formulas at one time or want to order them with
numbers, then the align, align* environments should be useful.
To use the align, align* environments, the format is
E
& is used for align the “=” at the same position, \\ is used to change the line.
In align environment,
sin(α + β)
tan(α + β) = (1)
cos(α + β)
sin(α + β) = sin α cos β + cos α sin β (2)
cos(α + β) = cos α cos β − sin α sin β (3)
formulas are centered and ordered.
In align* environment,
sin(α + β)
tan(α + β) =
cos(α + β)
sin(α + β) = sin α cos β + cos α sin β
cos(α + β) = cos α cos β − sin α sin β
the displayed formulas are unordered and centered.
3 Tables
For tables, either use the table environment or array environment.
table environment is used when texts should be included, for example
\begin{table}[htbp!] % to make the table appears at the right position (for most time)
\centering
\begin{tabular}{|c|c|}\hline
Alice & Bob \\\hline
10 pencils & 12 pens\\\hline
\end{tabular}
\caption{Table Example}
\label{tab:table example}
\end{table}
compiles as
Alice Bob
10 pencils 12 pens
while tables that only consist symbols and numbers can use the array environment.
For example
\begin{align*}
\begin{array}{|c|c|}\hline
a & b \\\hline
1 & 2 \\\hline
\end{array}
\end{align*}
compiles as
a b
1 2
The [htbp!] controls where the table or figure is placed. Tables (or figures) do not need to go where you put
them in the text. LATEXmoves them around to prevent large areas of white space from appearing in your paper.
{|c|c|} controls the column specification and the vertical lines between the cells. If you want a vertical line
between two columns, put a vertical line (|) in the column specification between the corresponding letters.
There are three possibilities of column specification:
\hline stands for horizontal line after a row. \hline\hline puts two horizontal lines before or after a row.
E
c centered column
l left-justified column
r right-justified column
\begin{table}[htbp!]
\begin{tabular}{|l||c|c|} \hline\hline
Ice Cream Store & Location & How to Get There \\ \hline
Toscanini’s & Central Square & Just walk! \\
Herrell’s & Harvard Square & Red Line \\
J.P. Licks & Davis Square & Red Line \\
Ben \& Jerry’s & Newbury Street & Green Line \\ \hline\hline
\end{tabular}
\end{table}
compiles as
If you are unfamiliar with commands, it is convenient to use the Table Generator. Also, Overleaf provides
with the function to paste tables from other apps, for example, excel and word.
4 Figures
Figures are very similar to tables. After upload a figure called image.png, you can insert that figure by
\begin{figure}[htbp!]
\centering
\includegraphics[width=0.5\linewidth]{image.png}
\caption{Example Figure}
\label{fig:example_figure}
\end{figure}
which compiles as a figure with a width equal to half of the text line:
\includegraphics[width=7cm]{image.png}
\includegraphics[width=6in]{image.png}
E
In Overleaf, you can directly insert a figure by pasting it in the Code Editor.
If you want to place two figures in a line, the package subfigure should be used by adding \usepackage{subfigure}
in the preamble.
For example
\begin{figure}[htbp!]
\centering
\subfigure[a figure]{\includegraphics[width=0.4\linewidth]{image.png}}
\subfigure[another figure]{\includegraphics[width=0.4\linewidth]{image.png}}
\caption{Subfigure Example}
\end{figure}
compiles as
5 Refer
In some previous examples, you might see \label{fig:example_figure} , etc. The \label{} are used for
future reference to the figure/table/formula.
For example,
E
compiles as
To refer to webpage, \usepackage{hyperref} can be used and webpage can be inserted by \href{webaddress}{Name} .
For example, \href{https://overleaf.com}{Overleaf} creates a hyperref to Overleaf .
6 Citation
A paper includes a bunch of references. To cite papers using LATEX, create another file with .bib.
To insert a paper into your reference database, we go to Google Scholar (or any other websites that provide a
bibtex-format citation).
For example, here we want to cite the paper What the fuck do I know? byBlöndal, Sara Hjördı́s, we searched
that on Google Scholar and click on cite.
Click on BibTeX, copy and paste the BibTeX code to the .bib file:
@phdthesis{blondalfuck,
title={What the fuck do I know?},
author={Bl{\"o}ndal, Sara Hj{\"o}rd{\’\i}s}
}
To link the .bib file with the main LATEX file, use
and to cite the paper, use \cite{}, \citep{}, \citet{} according to different conditions.
The paper established an idea that I don’t fucking know anything :thumb\_up:
\citep{blondalfuck}
which compiled as
The paper established an idea that I don’t fucking know anything :thumb up: [Blöndal(2023)]
• \par separates paragraphs, while leaving with a blank line also works
• Bold by \textbf{} , italic by \textit{} , underlined text by \underline{} ... Basically intuitive.
8 Remarks
4
1. ( ) is ugly, to change the parentheses use $\left(...\right)$
9
2. ~ can provide a space in both math and text
4. This guide is only for an introduction to how to use LATEX to help people dealing with HiMCM paper
writing, etc. A wide range of content isn’t included and can always be found on the internet. TeX
Stackexchange is always a good choice to look at.
5. In LATEX, use ‘‘’’ for quotes instead of "" , which doesn’t work well.
References
[Blöndal(2023)] Sara Hjördı́s Blöndal. What the fuck do I know? PhD thesis, 2023.