0% found this document useful (0 votes)
3 views

LaTeX Tutorial

This document is a comprehensive guide to using LATEX, a macro language for creating PDFs, particularly suited for handling mathematical formulas. It covers various aspects including LATEX editors, math commands, tables, figures, referencing, citations, and basic commands. The guide is intended for beginners and provides useful tips and examples for effective LATEX usage.

Uploaded by

wutianhao192418
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

LaTeX Tutorial

This document is a comprehensive guide to using LATEX, a macro language for creating PDFs, particularly suited for handling mathematical formulas. It covers various aspects including LATEX editors, math commands, tables, figures, referencing, citations, and basic commands. The guide is intended for beginners and provides useful tips and examples for effective LATEX usage.

Uploaded by

wutianhao192418
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

A LATEX Guide

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.

2 Use LATEX for Math


When writing math in LATEX, the packages amsfonts,amsmath,amssymb,amsthm are really useful, provided by
American Mathematics Society with many math symbols. The command \usepackage{amsfonts,amsmath,amssymb,amsthm}
can use the packages in the file.

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,

The free fall equation is $y_t-y_0= gt^2/2$.

compiles as The free fall equation is yt − y0 = gt2 /2. .


Special symbols in math mode all begin with a backslash, and end when a space, number or another command
appears.
For example, $\sin(\alpha+\beta)=\sin(\alpha)\cos(\beta)+\cos(\alpha)\sin(\beta)$ will be sin(α+
β) = sin(α) cos(β) + cos(α) sin(β)
There are a lot of math symbols, usually named exactly the same way you would expect.

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

Table 1: Some frequently-used symbols

Some of them are not so intuitive, but you can use Detexify, Mathpix to recognize symbols, or through some
LATEX Math Symbol lists
E

• One LATEX Math Symbols List


• Another LATEX Math Symbols List

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,

Gauss proved that \[\sum_{k=0}^n k=\frac{n(n+1)}{2}.\]

compiles as

Gauss proved that


n
X n(n + 1)
k= .
2
k=0

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,

$\displaystyle\lim_{\delta x\to 0}f(x),


\displaystyle\sum^{n}_{i=1}a_i,
\displaystyle\prod^{n}_{i=1}a_j$

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

\begin{align*} % (or align)


\tan(\alpha + \beta) &= \dfrac{\sin(\alpha + \beta) }{\cos(\alpha + \beta)}\\
\sin(\alpha + \beta) & = \sin \alpha \cos \beta + \cos \alpha \sin \beta \\
\cos(\alpha + \beta) & = \cos \alpha \cos \beta - \sin \alpha \sin \beta
\end{align*}

& 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

Table 2: Table Example

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

b Bottom Place the table at the bottom of the current page.


h Here Place the table at the spot where the table environment appears in the text (sometimes break)
t Top Place the table at the top of the current page.
p Page Place the table at the top of the next page.

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

Ice Cream Store Location How to Get There


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

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:

Figure 1: Example Figure

the width can also be changed to

\includegraphics[width=7cm]{image.png}
\includegraphics[width=6in]{image.png}
E

Figure 2: 7cm Example

Figure 3: 4in Example

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

(a) a figure (b) another figure

Figure 4: Subfigure Example

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

A figure of minions is presented in Figure \ref{fig:example_figure}.

I don’t know what Table \ref{tab:table_example} means.

compiles as

A figure of minions is presented in Figure 1.


I don’t know what Table 2 means.

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

\bibliographystyle{plainnat} % reference style.


\bibliography{main}

and to cite the paper, use \cite{}, \citep{}, \citet{} according to different conditions.

\citet{} the authors name(s) are to be read as part of the text


\citep{} the entire citation id parenthetical.

For example, I write

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)]

Besides, some informal citations use footnotes by \footnote{} .


E

7 Basic Dumb Knowledge


• \section{} creates a section

• \subsection{} creates a subsection

• \subsubsection{} creates a subsubsection

• \paragraph{} creates a paragraph (something smaller than subsubsubsection)

• \par separates paragraphs, while leaving with a blank line also works

• Ordered list by \begin{itemize}\item ... \end{itemize}

• Unordered list (bullets) by \begin{enumerate}\item ... \end{enumerate}

• 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

3. Some useful packages: \usepackage{siunitx} for SI units, \usepackage{mhchem} for chemistry.

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.

You might also like