0% found this document useful (0 votes)
47 views15 pages

Getting Started With L TEX: Organized By: Maths Club, IISER Bhopal Date: March 30 To April 4, 2023 Venue: L4, LHC

Uploaded by

gbgbg
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)
47 views15 pages

Getting Started With L TEX: Organized By: Maths Club, IISER Bhopal Date: March 30 To April 4, 2023 Venue: L4, LHC

Uploaded by

gbgbg
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
You are on page 1/ 15

Getting started with LATEX

Organized by: Maths Club, IISER Bhopal


Date: March 30 to April 4, 2023
Venue: L4, LHC

Indian Institute of Science Education and Research Bhopal

Getting started with LATEX Dhawal Patil and Swapnil Tripathi


Getting started with LATEX

0 Why LATEX over Word?

ˆ 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).

Exercise 1. Check the difference between

ˆ {\it Italic {\bf Bold-Italic}}

ˆ \textit{ Italic \textbf{Bold-Italic} }

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.

4. \noindent - removes the default indentation at the start of a paragraph.


5. {\Large ...} - sets the font size to Large.
6. \vspace{10pt} - introduce a vertical spacing of 10 points.
7. \hrule - introduces a horizonal rule in the output.

My first LATEXdocument
March 30, 2023 Your name here
Through this document, we will learn a few basics of LAT EX.

To obtain the above output, we run the following code:


1 {\ centering
2 {\ Large My first \ LaTeX document }
3
4 \ today \ hfill Your name here
5 }
6 \ smallskip
7 \ hrule depth 0.6 pt \ vspace {1 pt }
8 \ hrule
9 \ smallskip
10 \ noindent Through this document , we will learn a few basics of \ LaTeX .

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.

ˆ {\tiny tiny} - tiny

ˆ {\small small} - small

ˆ {\normalsize normalsize} - normalsize

ˆ {\Large Large} - Large


ˆ {\Huge Huge} - Huge
3
Getting started with LATEX

Start by making a section as follows:


1 \ section { The AM - GM inequality }

3 The AM-GM inequality



We will now prove that a+b2 ≥ ab ∀a, b ∈ R. Inline math mode is used to write mathematical
expressions within paragraphs (not in a separate line). The above inline math can be generated by
using
1 \ begin { math }
2 \ frac { a + b }{2} \ geq \ sqrt { ab } \ quad \ forall a , b \ in \ mathbb { R }
3 \ end { math }.

ˆ \frac{}{}

ˆ \sqrt[]{} - optional bracket []

ˆ \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 “ &”

These require the amsmath package.

4
Getting started with LATEX

Add a subsection using the following command:


1 \ subsection { Writing a proof for the AM - GM inequality }

3.1 Writing a proof for the AM-GM inequality


We will now prove the AM-GM Inequality using the align environment. To do so, we need to import
the amsmath package as follows:
1 \ usepackage { amsmath }
Now, moving on to the proof.
√ √
0 ≤( a − b)2 (1)

0 ≤a − 2 ab + b (2)

2 ab ≤a + b (3)
√ a+b
ab ≤ (4)
2

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

One more nested section can be added by using:


1 \ subsubsection { Writing in Theorem - Proof style }

3.1.1 Writing in Theorem-Proof style


The proof environment \begin{proof}...\end{proof} is inbuilt. However, the theorem environment
\begin{theorem}...\end{theorem} is defined in the amsthm package.
1 \ usepackage { amsthm }
2 \ newtheorem { theorem }{ Theorem }

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.

1 \ begin { theorem }[ AM - GM inequality ]


2 For each $ a , b \ in \ mathbb { R } $ , we have $ \ frac { a + b }{2}\ ge \ sqrt { ab } $ .
3 \ end { theorem }
4
5 \ begin { proof }
6 Given $ a , b \ in \ mathbb { R } $ , we have
7 \ begin { align }
8 0 \ \ leq & \ ( \ sqrt { a } - \ sqrt { b } ) ^2 \ label { eq : sqpos }\\
9 0 \ \ leq & \ a - 2\ sqrt { ab } + b \ nonumber \\
10 2\ sqrt { ab } \ \ leq & \ a + b \ nonumber \\
11 \ sqrt { ab } \ \ leq & \ \ frac { a + b }{2} \ nonumber
12 \ end { align }
13 where equation ~\ ref { eq : sqpos } is true since square of any number is positive .
14 \ end { proof }

ˆ 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

∃a−1 ∈ S such that a−1 a = 1 = aa−1 ∀a ∈ S.

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

5 Sequence and its limit


A sequence of real numbers is a function from the set of natural numbers to the set of real numbers.
It is written as {xn }n = {x1 , x2 , x3 , . . . }. We say that {xn }n converges to the real number x or
limn→∞ xn = x if for any ϵ > 0, there exists K ∈ N such that |xn − x| < ϵ whenever n ≥ K.

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

1 A sequence of real numbers is a function from the set of natural numbers to


the set of real numbers . It is written as $ \{ x _ n \}_ n = \{ x _1 , x _2 , x _3 ,
\ dots \} $ . We say that $ \{ x _ n \}_ n $ converges to the real number $ x $
or $ \ lim _{ n \ to \ infty } x _ n = x $ if for any $ \ epsilon > 0 $ , there exists
$ K \ in \ mathbb { N } $ such that $ \ lvert x _ n - x \ rvert < \ epsilon $ whenever
$ n \ geq K $ .

Exercise 6. Display the sequence  


1 1
1, , , . . .
2 3
in display math mode using what you have learnt until now.

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.

Example 3. Type the following using \left\{...\right\}


 
1
sup n ∈ N .
n
Does the middle part look alright?

The next example will illustrate:


1. \text (already seen before), and
2. \cases environment.
Example 4. Does {χ(n)}n for χ as defined below have a limit?
(
1 : if n is even
χ(n) =
−1 : if n is odd

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}

1. outside theorem environment, and


2. inside theorem environment.

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

|f (x) − L| < ϵ whenever |x − c| < δ

Definition 1. f : R → R is said to be continuous on a domain D ⊆ R if limy→x f (y) = f (x) for all


x ∈ D.

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

ˆ \begin{theorem} insert some text \end{theorem}.

Use \textit{} in each of the environments and check the output.

Use \emph{} in each of the environments and check the output. What is the difference?

This again emphasizes the upper hand of \emph{} over \textit{}.

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

ˆ limy→x+ f (y) = f (x)

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

ˆ One 1 \ begin { itemize }


2 \ item One
ˆ Two 3 \ item Two
4 \ item Three
ˆ Three
5 \ item Four
ˆ Four 6 \ end { itemize }

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.

Exercise 12. Add the following package in the preamble.


1 \ usepackage [ shortlabels ]{ enumitem }

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.

Exercise 13. Let f : R → R be defined by f (x) = x cos x. Then, for fixed x ∈ R

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

10 Matrices and tables

F unction continuous differentiable



f (x) = x
Pm k
f (x) = k=0 ck x
x
f (x) = 23
f (x) = log(x)
f (x) = ex

This example illustrates the following commands


1. \tabular [1, Section 8.23] helps make tables whereas table helps position and caption them. The
latter is a type of float. Floats are typographic elements, such as figures and tables which cannot
be broken across pages. The other kind of float in LaTeX is figure [1, Section 8.10].
2. Pay attention to use of \mathrm{e} to distinguish e from the upright e representing Euler’s
number.

12
Getting started with LATEX

3. \tabular* is used for a table with width specification.


The following can be ignored by first time users of tables
4. The array package offers the >{decl.} directive. It can be used before an l, r, c, p{..}, {..} or
a b{..} option. It inserts decl. directly in front of the entry of the column.
5. <{decl.} Can be used after an l, r, c, p{..}, {..} or a b{..} option. It inserts decl. right after
the entry of the column.
6. The < and > options were originally developed for the following application: >{$}c<{$} generates
a column in math mode in a tabular-environment.
7. The \toprule, \midrule and \bottomrule commands require the booktabs package. LaTeX only
supports \hline out of the box which does not take a width argument.

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

Theorem 2 (Fundamental Theorem of Calculus). Let f be a continuous real-valued function defined


on a closed interval [a, b]. Let F be the function defined for all x ∈ [a, b] by
Z x
F (x) = f (t) dt.
a

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

1 \ begin { theorem }[ Fundamental Theorem of Calculus ]\ label { thm : ftc }


2 Let $ f $ be a continuous real - valued function defined on a closed
interval $ [ a , b ] $ . Let $ F $ be the function defined for all $ x \ in [a
, b ] $ by \[
3 F ( x ) =\ int _ a ^ x f ( t ) \ ,\ mathrm { d } t .
4 \]
5 Then $ F $ is uniformly continuous on $ [ a , b ] $ and differentiable on the
open interval $ ( a , b ) $ , and \[
6 F ’( x ) = f ( x )
7 \]
8 for all $ x $ in $ ( a , b ) $ .
9 \ end { theorem }

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

You might also like