Getting Started With L TEX: Organized By: Maths Club, IISER Bhopal Date: March 30 To April 4, 2023 Venue: L4, LHC
Getting Started With L TEX: Organized By: Maths Club, IISER Bhopal Date: March 30 To April 4, 2023 Venue: L4, LHC
LATEX is free.
LATEX is backward compatible. Ever shared a Word file with someone having an older version
of the software? Believe me, it is inconvenient. MS Word files are often backward incompatible,
but LaTeX script is a plaintext file. You can just edit a LaTeX script in any text editor and
compile it in any LaTeX IDE (Integrated Development Environment).
LATEX is faster than Word. Word takes up a lot of system resources. LATEX on the other
hand, is a lightweight application. Documents with a considerable amount of figures take much
longer to load on Word than on LATEX.
Adding code comments: Just like any other programming language, we can easily add code
comments in LATEX. Whenever you feel like taking some notes, or you want to delete some
sentences temporarily but not permanently, code comments are always a good choice.
The algorithms used by LATEX to justify text and control hyphenation work much better than
those used by Word. This is why a document written in LATEX will have a much more
professional typesetting.
Since aesthetics are handled well, you can focus more on the content, hence increasing your
productivity.
Handling references and bibliography: Referencing in Word takes time. By the end of this
workshop, you will see how simple it is to do the same in LATEX.
Typing mathematical expressions is simpler in LATEX. Imagine searching the expression
you need (for example, the integral sign) from a drop down menu in Word rather than typing
$\int_a^b$ in LATEX.
1
Getting started with LATEX
1 Starter Document
The following code will compile a basic document using the article class.
1 \ documentclass { article }
2
3 \ title { My first \ LaTeX ~ document \ thanks { and more to come .}}
4 \ author { Your name here }
5 \ date {\ today }
6
7 \ begin { document }
8 \ maketitle
9
10 \ newpage
11 Through this document , we will learn a few basics of \ LaTeX .
12
13
14 \ end { document }
The part of the document before \begin{document} is called the preamble. It comprises of in-
structions given to latex, like list of packages (containing pre-defined commands) and user-defined
commands. The following commands were used in this code:
1. \documentclass: to specify the document type (book, article, beamer, etc.)
2. \begin{document} ... \end{document}
3. \author
4. \today: displays today’s date
5. \thanks: displays additional information as a footnote
6. \newpage: instructs latex to start a new page
Notice that the appearance of “preamble” is made to stand out from the rest of the text. It is a
good practice to italicize or embolden the first appearance of a mathematical term.
{\it ...} and \textit{...} are used to italicize the text,
{\bf ...} and \textbf{...} are used to embolden the text, and
\emph{} or emphasis command to the rescue! “Un-italicizes” the text if used within \textit{}.
Works well with theorem environments (to be seen later).
2
Getting started with LATEX
2 Heading
Cover page can also be produced manually. We will use the following commands to create one:
1. \centering - centers the contents in the scope i.e., between the curly braces
2. \hfill - fills the space [1, Sec 19.3];
3. \smallskip - Gives a vertical spacing of 3pt plus 1pt minus 1pt.
My first LATEXdocument
March 30, 2023 Your name here
Through this document, we will learn a few basics of LAT EX.
Exercise 2. There are several sizes that can be used for headings. Check that the following commands
increase the font size as we move lower down the list.
\frac{}{}
\forall
\in
\geq
\mathbb{R} - blackboard font for real numbers. Requires amssymb package. This is achieved by
typing the following in the preamble.
1 \ usepackage { amssymb }
There are several ways of using the inline math mode: shorthand $. . . $ or \( ... \) can be used
instead, for example
1 \( \ frac { a + b }{2} \ geq \ sqrt { ab } \ quad \ forall a , b \ in \ mathbb { R } \) .
However, to output an equation in a new line, we use the display math mode. It is achieved using
1 \ begin { displaymath }
2 \ frac { a + b }{2} \ geq \ sqrt { ab } \ quad \ forall a , b \ in \ mathbb { R }.
3 \ end { displaymath }
Alternatively, it may be achieved using $$ . . . $$ or \[ ... \]. Observe that these commands do
not number the equations.
Example 1. Numbered equations in display math mode can be achieved through one of the following
commands
\begin{equation}...\end{equation} - does not allow multiple lines
\begin{align}...\end{align} - allows multiple lines and forced alignment of lines using “ &”
4
Getting started with LATEX
1 \ begin { align }
2 0 \ leq & ( \ sqrt { a } - \ sqrt { b } ) ^2 \\
3 0 \ leq & a - 2\ sqrt { ab } + b \\
4 2\ sqrt { ab } \ leq & a + b \\
5 \ sqrt { ab } \ leq & \ frac { a + b }{2} \\
6 \ end { align }
Apart from equation numbering, can you note the difference between the above equations and the
ones that follow?
√ √
0 ≤ ( a − b)2
√
0 ≤ a − 2 ab + b (1)
√
2 ab ≤ a + b
√ a+b
ab ≤
2
In this section, the following commands were illustrated
1. The command \nonumber can be used to skip numbering specific equations.
2. The spaces before and after ≤ can be obtained using “\ ”. More on spacing later.
3. The align environment. Read more about displayed equation environments in [2, Table 3.1].
4. Use align* instead of align when you don’t want to number any of the equations.
Exercise 3. To mark multiple equations with the same equation number, use the command
\begin{equation}\begin{aligned}....\end{aligned}\end{equation}.
What is the difference between this output and the last displayed equations?
5
Getting started with LATEX
a+b
√
Theorem 1 (AM-GM inequality). For each a, b ∈ R, we have 2 ≥ ab.
Proof. Given a, b ∈ R, we have
√ √
0 ≤ ( a − b)2 (1)
√
0 ≤ a − 2 ab + b
√
2 ab ≤ a + b
√ a+b
ab ≤
2
where equation (1) is true since square of any number is positive.
The command \label{} is used to mark equations/environments that might need referencing
later. The commands \eqref{} and \ref{} can be respectively used to refer to the equations/en-
vironments.
Difference between \eqref{} (requires amsmath package) and \ref?
~ produces a non-breaking space.
Exercise 4. There are clever ways to refer to the equations. It requires you to use the cleveref
package. Add the package in the preamble and use \cref{} to see how the output changes.
6
Getting started with LATEX
4 Spacing
Don’t make people reading your document space out: use spaces! Some important commands are
1. backslash space - ‘\ ’ spacing and indentation is automatically handled by latex in math mode.
The spaces inserted by the user are ignored as whitespace which is meant just to make the code
look cleaner but won’t affect the way the document looks. To insert a space in math mode, one
has to explicitly instruct the latex compiler to to do by using this command.
2. ~ produces a non-breaking space. It should be used while referencing theorems/equations and
while addressing others, for example, Dr.~XYZ.
3. italic correction “\/” in {\it f}\/H, were it not for the \/, the before-character italic f would hit
the after-character roman H. Compare f H with fH.
4. \quad and \qquad are the other two commands for font independent spacing. These are often used
in math mode to separate two equations as in f(x) = 2 x,\qquad g(x)= \sin x which compiles
to
f (x) = 2x, g(x) = sin x
and in separating the variable from the expression as in \exists a^{-1} \in S \text{ such that
} a^{-1}a=1=aa^{-1} \quad \forall a \in S which compiles to
5. In the previous sentence, note that a space has been explicitly inserted.
6. \hfill, \vfill - rubber spacing
7. \vspace - the rigid vertical spacing
8. \thinspace, \medspace, \thickspace, \negthinspace and their shorthands \,, \:, \;, \!. For
example see the difference between ∃ a−1 and ∃a−1 .
Example 2. Regarding point 2, we have the following example, with and without ‘~’ respectively.
aaaaa bbbbb ccccc ddddd eeeee fffff ggggg hhhhh iiiii jjjjj kkkkk lllll mmmmm nnnnn ooooo pp Dr.
XYZ.
aaaaa bbbbb ccccc ddddd eeeee fffff ggggg hhhhh iiiii jjjjj kkkkk lllll mmmmm nnnnn ooooo Dr. XYZ.
Similarly, if we want to disallow breaking of an inline math equation to two lines, we may use
${...}$ instead of $...$.
7
Getting started with LATEX
Exercise 5. Start a new section named “Sequence and its limit”. Use the following commands to
generate the above lines. The new commands required are
1. _ to write subscripts. For example, a_b generates ab .
2. \to command for → and \infty for ∞.
3. In Example 2, braces were used to hold things together as a single entity. Use this knowledge to
display limn→∞ xn = x in inline math mode.
4. Again, the braces are used to hold things together and hence are not displayed. To display
braces, we use \{...\}.
5. To print absolute values, we use \lvert ... \rvert.
6. \ldots is used to print ‘. . .’. Observe the difference between . . . and ‘...’ (typed manually).
7. ϵ and similarly other greek alphabets can be displayed by adding a ‘\’ in front of their English
spellings.
8. Delimiters including parenthesis, curly braces, square brackets, the pipe character and their
sizing. This is illustrated in [2, Sec 4.14].
Do the braces look bigg enough? Or are the left and right braces smaller than expected?
Exercise 7. Use the command obtained in the third step of Exercise 5 in display math mode and
observe the difference.
8
Getting started with LATEX
6 Supremum
The supremum of a set A is defined as
sup(A) = min {t ∈ R | x ≤ t ∀x ∈ A} .
The following commands were used in this code
1. \sup - is a predefined command in LaTeX. You can define your own operators using \DeclareMathOperator
{}{}. Refer [1, Section 16.3] or [2, Section 5.1] for an elaboration.
2. \vert - to display |.
3. Some prefer a colon over |. It can be printed using \colon.
1 Does \( \ left \{ \ chi ( n ) \ right \}_ n \) for \( \ chi \) as defined below have a
limit ?
2 \ begin { align *}
3 \ chi ( n ) =
4 \ begin { cases }
5 1 & \ colon \ text { if \( n \) is even } \\
6 -1 & \ colon \ text { if \( n \) is odd }
7 \ end { cases }
8 \ end { align *}
Exercise 8. Operators and known functions should not appear in italics. Using the command \sup is
the same as using \textup{sup}. Is it the same as using \text{sup}? Observe the difference between
\textup{sup} and \text{sup}
9
Getting started with LATEX
7 Limit of a function
Let f : R → R be a function. For c ∈ R, we say that the limit of f at c is L or limx→c f (c) = L if for
each ϵ > 0 there exists δ > 0 such that
Exercise 9. Add the following lines to the preamble to define the definition environment.
1 \ theoremstyle { definition }
2 \ newtheorem { defn }{ Definition }
You might have guessed the command for lim (hinting towards sup). Type commands to output
all of the lines above including a new section. Note that there is an additional line \theoremstyle{
definition} while defining the definition environment. This line did not appear while defining the
theorem environment. Check the difference between
\begin{defn} insert some text \end{defn}, and
Use \emph{} in each of the environments and check the output. What is the difference?
Exercise 10. Do you see a subtle difference between using f\colon \mathbb{R}\to\mathbb{R} and
f: \mathbb{R}\to\mathbb{R}?
Exercise 11. Recall that underscore ‘_’ produces subscripts. Similar to that, the hat symbol ‘^’
produces superscripts. Print
Rn 1
x2n
10
Getting started with LATEX
8 Listing
Lists can be made using enumerate and itemize environments as follows.
1. One 1 \ begin { enumerate }
2 \ item One
2. Two 3 \ item Two
4 \ item Three
3. Three 5 \ item Four
6 \ end { enumerate }
4. Four
1 \ begin { itemize }
$ One
2 \ item [\ $ ] One
% Two 3 \ item [\ % ] Two
4 \ item [ R 2.] Three
R2. Three 5 \ item [ label text .] Four . This
looks bad .
label text. Four. This looks bad. 6 \ end { itemize }
Remark. The items can be labeled and referred to later if need be.
Add the optional argument [C1] right after \begin{enumerate}. Play around with the optional argu-
ment to get different results.
Remark. The lists can be nested and the enumerate package automatically handles the numbering.
11
Getting started with LATEX
9 Differentiability
For f : R → R and x ∈ R, we define the derivative of f at x as the limit f ′ (x) as defined below if it
exists.
df f (y) − f (x)
(x) = f ′ (x) = lim
dx y→x y−x
If the limit exists, we say that f is differentiable at x. If f is differentiable at all points x ∈ R, we
say that f is differentiable everywhere or just f is differentiable.
f (y) − f (x)
f ′ (x) = lim
y→x y−x
y cos y − x cos y + x cos y − x cos x
= lim
y→x y−x
(y − x) cos y − 2x sin( y+x y−x
2 ) sin( 2 )
= lim
y→x y−x
y−x
sin( 2 ) x+y
= lim cos y − x y−x sin
y→x
2
2
= cos x − x sin x
12
Getting started with LATEX
1 \ noindent %
2 \ begin { table }[ h ]
3 \ centering
4 \ renewcommand {\ arraystretch }{1.5}
5 \ begin { tabular }{| >{ $ } l <{ $ }| l | l |}
6 \ toprule [1.2 pt ]
7 Function & continuous & differentiable \\\ midrule [1 pt ]
8 f ( x ) = \ sqrt { x } & & \\
9 f ( x ) = \ sum _{ k =0}^ m c _ k x ^ k & & \\
10 f ( x ) = 2^{3^{ x }} & & \\
11 f ( x ) = \ log ( x ) & & \\
12 f ( x ) = \ mathrm { e }^{ x } & & \\
13 \ bottomrule [1.2 pt ]
14 \ end { tabular }
15 \ end { table }
Example 1. Make the following tables using the tabcolsep and the @ commands. Note the difference
carefully and try to reproduce it.
Project
Date 21 March 2023
Name John Doe
Supervisor Dr XYZ
Project
Date 21 March 2023
Name John Doe
Supervisor Dr XYZ
13
Getting started with LATEX
Then F is uniformly continuous on [a, b] and differentiable on the open interval (a, b), and
F ′ (x) = f (x)
for all x in (a, b).
Additional Exercise
Add the following code to the preamble and then use the \maketitle command.
1 \ makeatletter
2 \ renewcommand \ maketitle {
3 \ begin { center }\ bfseries
4 \ @title
5
6 \ @author
7 \ end { center }
8
9 \ noindent \ @date \ hfill \ @day
10 \ smallskip
11 \ hrule depth 0.6 pt \ vspace {1 pt }\ hrule
12 \ smallskip
13 }
14 \ makeatother
References
[1] Torsten Martinsen George D. Greenwade, Stephen Gilmore and Karl Berry. LATEX2e: An unof-
ficial reference manual. January 2022 edition.
[2] The LATEX Project team. User’s Guide for the amsmath Package (Version 2.1).
14