0% found this document useful (0 votes)
152 views9 pages

Latex Guide

This document serves as a comprehensive guide to using LaTeX, a software system for creating high-quality technical and scientific documents. It covers getting started with Overleaf, basic LaTeX code writing, formatting text, creating sections, lists, tables, images, bibliographies, and mathematical expressions. The guide also includes tips for special characters, page formatting, and theorem settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views9 pages

Latex Guide

This document serves as a comprehensive guide to using LaTeX, a software system for creating high-quality technical and scientific documents. It covers getting started with Overleaf, basic LaTeX code writing, formatting text, creating sections, lists, tables, images, bibliographies, and mathematical expressions. The guide also includes tips for special characters, page formatting, and theorem settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

A Guide through LATEX

Aditya, MnP volcon 25-26; Sara Ahire, MnP volcon 24-25

1 Introduction
Latex (pronounced “lay-tek”) is a powerful software system for the preparation of technical and scientific
documents as it provides high-quality typesetting for mathematical symbols, equations, tables, bibliogra-
phies etc.
While you can make your project report in any format and way that you prefer (including in Google
Docs or handwritten document), we recommend learning LaTeX owing to its wide use case. This document
will help you get started with LaTeX and will probably teach you enough to write the report for your SoS
project. See Further learning section for more resources.

2 Getting started
We are going to use Overleaf online LaTeX editor for its ease of use. Go to the Overleaf website and
1. Sign in. If you don’t have an Overleaf account, make one and then sign in.
2. To start a new “project”, click on “New Project” on the main page, and from the drop-down select
blank project. From the same drop-down you can select “Example project” for an overview of basic
LaTeX.
Using something besides Overleaf: There are many other LaTeX editors also, two popular ones
are TexStudio and TeXWorks. VS code (with some extensions) can also be used as a LaTeX compiler.

3 Basics of Overleaf
You have to type your LaTeX code on the left, compile it, and then the output will be displayed on the right.

For Compiling Press “Ctrl+Enter”. You can also compile using the green “Recompile” button. If
you compile but your document is not changed, you may have an error. Check the left side for an “x”
symbol to see what went wrong. You can also compile using “Ctrl+S”.

Downloading PDF file for your LaTeX code: When you are satisfied with the output shown on
the right side, you can download the output as a PDF file by clicking the download PDF button near the
“Recompile” button on the right side.

Other Features: You can upload files to your “project” (for example images you want to attach in
your document) using the upload button near the top-left corner. You can double-click on the right side
to go to the corresponding line of LaTeX source code on the left side. You can also share Overleaf files
with collaborators.

4 Writing LaTeX code


In your report, you would probably want to add various sections, tables, images, lists, bibliography and
mathematics. This section will teach you the basics of the above-mentioned document elements. Addition-

1
ally, you might want to make some of your text bold or italic or you might want to change the color of the
text. We begin with that.

4.1 Text Formatting


For making the text bold, use the \textbf{<text>} command, for italicizing use \textit{<text>}, and
for underlining use \underline{<text>} command as shown in the example below. (Note that here the
angle brackets and the stuff inside them are just placeholders meant to be replaced with the content of
your choice. This convention would be followed throughout the document.)
1 This \ textbf { word } would be made bold .
2 This \ textit { word } would be italicized .
3 This \ underline { word } would be underlined .

To write text in the color of your choice, use the \textcolor{<color>}{<text>} command as shown
below.
1 \ textcolor { red }{ This text is red .}

4.2 Sections
You can write sections using \section{<section-name>}. You can write subsections using
\subsection{<subsection-name>}. \subsubsection{<subsubsection-name>} also works. A section
is terminated when you start a new section.
If you want a table of contents, use the \tableofcontents command wherever you want it to appear.

4.3 Lists
You can write bullet lists by using the \itemize environment. By environment, we mean a structured
block which starts at \begin{<environment name>} and ends at \end{<environment name>}.
You can add each item using the \item command. For example, take a look at the code below and the
corresponding list that is produced by it:
1 \ begin { itemize }
2 \ item First item
3 \ item Second item \ begin { itemize }
4 \ item First sub - item
5 \ item Second sub - item
6 \ item Third sub - item
7 \ end { itemize }
8 \ end { itemize }

• First item
• Second item
– First sub-item
– Second sub-item
– Third sub-item

Similarly, you can write numbered lists using the \enumerate environment instead of \itemize.
You can get custom number labels by importing enumitem (by writing the line \usepackage{enumitem}
at the start of your document) and writing the custom number labels in square brackets [· · ·]. Use \alph*
for small letters, \Alph* for capital letters, \roman* for roman etc. Look at the list below and the code
that produced it.
1 \ begin { enumerate }[ label =(\ alph *) ]
2 \ item First item
3 \ item Second item
4 \ end { enumerate }

2
(a) First item
(b) Second item

4.4 Tables
You can write tables using the \tabular environment. After \begin{tabular}, you need to specify where
you want vertical lines separating columns in each row of the table, and what alignment you want for
the text in each column. The pipe (|) character is used to show the position of vertical lines and the
text alignment of a column is shown by a lowercase letter: c, l, r for center, left and right alignment
respectively. Inside the tabular environment, & is used to separate the contents of each column and \\ is
used to separate rows. Use \hline to make a horizontal line separating rows. Look at the example below
for a better understanding.
1 \ begin { tabular }{| c | c | c |}
2 \ hline
3 $n$ & $n ^2 $ & $n ^3 $ \\
4 \ hline
5 1 & 1 & 1 \\
6 2 & 4 & 8 \\
7 3 & 9 & 27 \\
8 \ hline
9 \ end { tabular }

n n2 n3
1 1 1
2 4 8
3 9 27

4.5 Images
First, you need to upload the image file to your project using the upload button near the top left corner.
Then you can insert images in your document using the \figure environment. (You need the graphicx
package to insert images, which is already imported by default when you open a new blank project in
Overleaf).
1 \ begin { figure }[ H ]
2 \ centering
3 \ in cl u de gr ap h ic s [ scale =0.5]{ OIP . jpg }
4 \ caption { LaTeX }
5 \ end { figure }

Figure 1: LaTeX

By default, figures are placed at the top of the page. To override this, use the [H] option from float
package (make sure the package is imported using \usepackage{float}).

3
4.6 Bibliography
To put a bibliography in your document, write \begin{thebibliography}{99} at the beginning and
\end{thebibliography} at the end. The number 99 here indicates that the number of references can be
a two digit number. Usually the bibliography goes at the end of the document.
To add a new item, use \bibitem.
1 \ begin { t he bi bl i og ra ph y }{99}
2 \ bibitem { TLC } Frank Mittelbach , Michel Goossens . The Latex Companion . \ url { https :// www .
latex - project . org / help / books / bookpart_tlc2 - ch0 . pdf }
3 \ end { th eb ib l io gr ap h y }

References
[1] Frank Mittelbach, Michel Goossens. The Latex Companion. [Link]
books/bookpart_tlc2-[Link]

To cite items, write \cite{TLC}, which looks like [1].

4.7 Mathematics
4.7.1 Basics
Writing math
• Write math surrounded by dollar signs $...$. For example:
1 $x ^3 + 3 x ^2+ 3 x + 1 = ( x +1) ^3 $

this gives output: x3 + 3x2 + 3x + 1 = (x + 1)3


• Write math on a new line using \[...\]. For example:
1 \[ x ^3 + 3 x ^2+ 3 x + 1 = ( x +1) ^3\]

giving an output:
x3 + 3x2 + 3x + 1 = (x + 1)3 .
(You can also use double dollar signs $$...$$, but they behave worse with spacing.)

Superscripts, subscripts, inequalities, fractions.


• Write long superscripts like x11 by typing x^{11}. Write long subscripts like x777 by typing x_{777}.
Remember to put the contents of the supserscripts or subscripts in curly braces {}. If you write x^11
that will result in x1 1.
• Write inequalities like x ≤ x + 7 and x + 11 ≥ x using \leq and \geq. Note “leq” stands for “less
than or equal to”. For strict inequalities you can just write < and >.
• Write fractions like 12 using \frac{}{}. For example:
\[ \frac{1}{2} + \frac{1}{3} = \frac{5}{6}. \]
resulting in:
1 1 5
+ = .
2 3 6

4
Special symbols Each symbol usually starts with a backslash \.

• Write multiplication using \cdot, for example 3 · 3 = 9.


• You can write Greek letters like α and ∆ by writing \alpha and \Delta.
• You can write ∀ and ∃ like \forall and \exists.
• You can write sums like

X 1 π2
2
=
k 6
k=1

using the \sum command.


1 \[ \ sum_ { k =1}^\ infty \ frac {1}{ k ^2} = \ frac {\ pi ^2}{6} \]

For derivatives, you can write


1 \[ \ od {}{ x } x ^2 = 2 x . \]

d 2
x = 2x.
dx
For integrals, you can write
1 \[ \ int_0 ^1 x ^2 \ dif { x } = \ frac {1}{3}\]

Z 1
1
x2 dx = .
0 3
(To use these, put commath package in your preamble i.e. at the beginning of the latex source code.)
• You can type Z and P by writing \mathbb{Z} and \mathcal{P}. There is also B for more fanciness
by writing \mathfrak{B}. (To use them, you need to import amssymb package).
• The implies symbol =⇒ is \implies, and there are other arrows like ←, →, ⇐, ⇒, ⇐⇒ .
• Want to know how to write a symbol? Look it up in detexify. [Link]
org/[Link]
• For “comments” (writing stuff that doesn’t show up in your output document), start a line with a
percent symbol %.

4.7.2 Some more symbols


• You can work with sets by writing A ⊂ B, B ⊃ A, A ⊆ B, B ⊇ A. These commands are \subset,
\supset, \subseteq, and \supseteq respectively. There is also x ∈ A written \in.
• You can put a line over stuff using \overline. For example, 1
3 = 0.333.

. .
• Write · · · using \cdots. There are also other dots like . . , . . . , ...
• You can line up equations using \begin{align*}. For example,
1 \ begin { align *}
2 ( x +1) ^2 &= ( x +1) ( x +1) && \ text {( Definition of exponen tiation ) }\\
3 &= ( x +1) x + ( x +1) 1 && \ text {( Distributive property ) }\\
4 &= x ^2 + 1 \ cdot x + x \ cdot 1 + 1 \ cdot 1 && \ text {( Distributive property ) } \\
5 &= x ^2 + 1 \ cdot x + x \ cdot 1 + 1 && \ text {( Definition of 1) } \\
6 &= x ^2 + 1 \ cdot x + 1 \ cdot x + 1 && \ text {( Commutative property ) }\\
7 &= x ^2 + 2 x + 1. && \ text {( Distributive property ) }
8 \ end { align *}

5
(x + 1)2 = (x + 1)(x + 1) (Definition of exponentiation)
= (x + 1)x + (x + 1)1 (Distributive property)
2
=x +1·x+x·1+1·1 (Distributive property)
2
=x +1·x+x·1+1 (Definition of 1)
2
=x +1·x+1·x+1 (Commutative property)
2
= x + 2x + 1. (Distributive property)

(& is used to anchor the alignments inside the align environment)

5 Pretty features
5.1 Special characters
Special characters can be written directly (like Erdős) or they can be specified using LaTeX commands
(like Erd\H{o}s). A reference for common special characters can be found here: [Link]
org/wiki/LaTeX/Special_Characters#Escaped_codes.

5.2 The page


Import geometry package to adjust margins. You can change the font size as a documentclass option
(options are the stuff you write, inside square brackets next to the command, to change the behavior of
any command). Go up to the preamble to adjust these.
1 \ documentclass [11 pt ]{ article }
2 \ usepackage [ margin =1 in ]{ geometry }

You can add headers using fancyhdr package and \pagestyle{fancy} in the preamble. More details
can be found at: [Link]
package.
To add footnotes, write \footnote{<footnote content>}.1

5.3 Theorems, lemmas, and proofs


To get the nice formatting to work, import amsthm package and declare what theorem settings you want
to use using \newtheorem (Look at the end of this subsection for an example of the theorem settings you
can use). Then, put theorem text inside the thm environment. Same for proofs, lemmas, or whatever else
you would like to define.
1 \ begin { thm }\ label { thm - integers - two - div }
2 For all $a \ in \ mathbb { Z }$ , we have $2 \ mid a (a -1) $ .
3 \ end { thm }
4
5 \ begin { proof }
6 Let $a$ be an integer . If $a$ is even , then $2 \ mid a$ , so $2 \ mid a (a -1) $ . If $a$ is
odd , then $2 \ mid (a -1) $ , so $2 \ mid a (a -1) $ .
7 \ end { proof }

Theorem 5.1. For all a ∈ Z, we have 2 | a(a − 1).


Proof. Let a be an integer. If a is even, then 2 | a, so 2 | a(a − 1). If a is odd, then 2 | (a − 1), so
2 | a(a − 1).
Conjecture 5.2. For all b ∈ Z, we have 3 | b(b − 1)(b − 2).
1 Here is an example footnote.

6
The use of \label{<label name>} above was to create references to theorems within the document.
Labels are not unique to theorems, you can make labels for equations, figures, tables, sections and other
elements also. You can reference the above theorems by writing \ref{thm-integers-two-div} and
\ref{thm-integers-three-div}. On doing that you will get something like 5.1, which you can click
it to go to the theorem statement.
In practice, just keep a template with your favorite theorem settings and start from that every time.
Here is an example of theorem settings:
1 \ newtheorem { thm }{ Theorem }[ section ]
2 \ newtheorem { lemma }[ thm ]{ Lemma }
3 \ newtheorem { cor }[ thm ]{ Corollary }
4 \ newtheorem { conj }[ thm ]{ Conjecture }
5 \ newtheorem { prop }[ thm ]{ Proposition }
6
7 \ theoremstyle { definition }
8 \ newtheorem { defn }[ thm ]{ Definition }
9 \ newtheorem { rmk }[ thm ]{ Remark }
10 \ newtheorem { ex }[ thm ]{ Example }
11 \ newtheorem { ques }[ thm ]{ Question }
12 \ newtheorem *{ youtry }{ Now you try }
13 \ theoremstyle { remark }
14 \ newtheorem *{ sk }{ Proof sketch }

Refer [Link] for more.

5.4 Tikz
tikz package can be used for making math diagrams. You can specify points using (x, y) coordinates, and
there are commands for drawing lines and curves between them. For example, a happy square:
1 \ begin { center }
2 \ begin { tikzpicture }
3 \ draw (0 ,0) -- (2 ,0) -- (2 ,2) -- (0 ,2) -- (0 ,0) ;
4 \ node at (.5 ,1) {\ textbullet };
5 \ node at (1.5 ,1) {\ textbullet };
6 \ draw [ < - >] (.25 ,.5) .. controls (1 ,.1) .. (1.75 ,.5) ;
7 \ end { tikzpicture }
8 \ end { center }

• •

center environment is used to center align its contents.


For more information on tikz, see [Link]

5.5 Beamer
Beamer is another powerful LaTeX document class used for making attractive presentations.
You’ll find a good resource and a step by step guide for the same at [Link]
latex/Beamer_Presentations%3A_A_Tutorial_for_Beginners_(Part_1)%E2%80%94Getting_Started.
A sample basic code for beamer and the output produced is shown below.
1 \ documentclass { beamer }
2
3 \ title { Sample title }
4 \ author { Anonymous }
5 \ institute { IIT Bombay }
6 \ date {2024}
7

7
8 \ begin { document }
9
10 \ frame {\ titlepage }
11
12 \ begin { frame }
13 \ frametitle { Frame title }
14 An introduction to Beamer .
15 \ end { frame }
16
17 \ end { document }

6 Useful packages
Here are some essential packages for writing math in LaTeX.
1 \ usepackage [ margin =1 in ]{ geometry }
2 \ usepackage { amsmath , amsthm , amssymb , mathtools } % Essential packages for math .
3 \ usepackage [ utf8 ]{ inputenc } % special characters
4 \ usepackage [ shortlabels ]{ enumitem } % Customizable lists
5 \ usepackage { hyperref } % use \ url {} for links
6 \ usepackage [ dvipsnames ]{ xcolor } % \ color command
7 \ usepackage { tikz } % tikz , for math drawing
8 \ usepackage { float } % make the [ H ] option work for figures
9 %\ usepackage { minted } % use for code in documents , filename cannot have spaces !
10 \ usepackage { commath } % \ dif { x } for the " dx " in integrals and \ od { f }{ x } for df / dx

In practice, you don’t have to worry about packages much. Just keep a template file with everything
you need and whenever you make a new LaTeX file, paste it in.

7 Further learning
1. Other good sources to learn LaTeX could be the overleaf tutorials [Link]
learn/latex/Tutorials
2. Google “⟨the thing you want⟩ in LaTeX”
3. All hail ChatGPT (and all other similar tools)!

4. Great sources are the TeX Stack Exchange and Overleaf’s documentation.
5. For advanced resources refer to this brief tutorial by Aryaman Maithani [Link]
[Link]/latex/

8
6. For a more comprehensive one, refer to this tutorial by Adway Girish [Link]
read/jcwsxzmtzxmb#c9df0c
7. Here are some tips for LaTeX, courtesy- Param Rathour [Link]
latex-tips/

8. A blank template by Hao Ren with helpful packages which can possibly be useful to make a report
could be found here: [Link]
kfqdrzrzpvvk. Feel free to make and edit your own copy for future LaTeX purposes.

You might also like