Beyond the EU: DORA and NIS 2 Directive's Global Impact
Introduction to LaTeX - Workshop Day 1
1. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics
Introduction to LATEX
Suddhasheel Ghosh
Department of Civil Engineering,
Jawaharlal Nehru Engineering College
Aurangabad, Maharashtra
431003
LATEX for Technical and Scientific Documents
January 12 - 16, 2015
Day I
shudh@JNEC LATEX@ JNEC 1 / 31
2. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics
Outline
1 Why should we use LATEX
Etymology
2 Parts of a LATEX document
The Preamble
The body
Text styles
3 Mathematical typesetting
4 Graphics
Tables
shudh@JNEC LATEX@ JNEC 2 / 31
3. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
Outline
1 Why should we use LATEX
Etymology
2 Parts of a LATEX document
The Preamble
The body
Text styles
3 Mathematical typesetting
4 Graphics
Tables
shudh@JNEC LATEX@ JNEC 3 / 31
4. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
Why should we use LATEX
Motivation
Free Software (I do not have to worry about viruses and
software piracy)
Rendering mathematics is easier
No worries about setting the font size and styles again and
again
Because I am tired of figures and tables jumping from here and
there
Because I want my sections and subsections autonumbered
Because my fingers are tired with a click-find-click approach
What all do I have to do?
Remember the basic structure of a document
Remember a few macros
shudh@JNEC LATEX@ JNEC 4 / 31
5. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
Etymology of LATEX
... the origins
Initially TEX was developed by Donald Knuth
Leslie Lamport extended the software to LATEX
TEX is pronounced ‘Tech’ and was initially written as τ χ
LATEX stands for Lamport TEX and is pronounced as ‘Lay-Tech’
However, many pronounce it as ‘Lateks’ (as in rubber)
What can we do with LATEX?
We can create research papers, reports, thesis, presentations,
posters and leaflets.
shudh@JNEC LATEX@ JNEC 5 / 31
6. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
In this workshop:
Day 1: Introduction to LATEX
Day 2: Typesetting Mathematics
Day 3: Writing your thesis / technical report
Day 4: Make your presentations
Day 5: Basics of science communication
shudh@JNEC LATEX@ JNEC 6 / 31
7. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
Where do I get LATEX?
...and use it
LaTeX Software
For Windows:
www.miktex.org
Download a complete DVD as torrent from www.texlive.org
For Linux:
Download a complete DVD as torrent from www.texlive.org
Part of the Ubuntu Linux distribution (sudo apt-get
install texlive)
shudh@JNEC LATEX@ JNEC 7 / 31
8. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Etymology
Writing files in LATEX
... and getting outputs
The LATEX “code” is written in a .tex file
LaTeX package compiles the file to produce PDF, DVI or PS files
Windows editors (IDE)
WinEdit
TeXNicCenter
LyX (What you see is what you get type)
Linux editors (IDE)
Texworks
TeXStudio
TeXMaker
LyX
shudh@JNEC LATEX@ JNEC 8 / 31
9. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Outline
1 Why should we use LATEX
Etymology
2 Parts of a LATEX document
The Preamble
The body
Text styles
3 Mathematical typesetting
4 Graphics
Tables
shudh@JNEC LATEX@ JNEC 9 / 31
10. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Parts of a LATEX document
Preamble
Style or class of a document
Packages to be used
Macro definitions
Body
Sections and subsections
Tables and figures
Body text
shudh@JNEC LATEX@ JNEC 10 / 31
11. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Parts of a LATEX document
The preamble
Makes announcements
Style of the document
Packages to be used
Definitions of macros
shudh@JNEC LATEX@ JNEC 11 / 31
12. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty!
The Preamble
We shall use the base class article
documentclass{article}
Want A4 paper size? Two-sided document?
documentclass[a4paper,twoside]{article}
What about setting the margins?
usepackage[top=2cm,bottom=4cm,left=1.5cm,
right=3cm,assymetric]{geometry}
Therefore, overall settings for A4 size paper, and margins:
documentclass[a4paper,twoside]{article}
usepackage[top=2cm,bottom=4cm,left=1.5cm,right=3cm,
asymmetric]{geometry}
shudh@JNEC LATEX@ JNEC 12 / 31
13. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
...and let’s start writing papers
Announce the title, the author and date
title{My first LaTeX
paper}
author{Suddhasheel Ghosh}
%write here or the date
appears automatically
date{}
And then declare the contents of the document:
begin{document}
%this puts the title on
top
maketitle
end{document}
Here LaTeX, title, author, date, begin, end are all macros.
Macros are like functions. Anything between the braces “{}”, is the
argument to the function / macro.
shudh@JNEC LATEX@ JNEC 13 / 31
14. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Bold, italics, slanted underline
We can have {bf bold
text}, {textit
italicised text},
{sl slanted text}
and
underline{underlined
text}.
We can have bold text, italicised text, slanted text and
underlined text.
shudh@JNEC LATEX@ JNEC 14 / 31
15. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Subscripts and superscripts
In your preamble, add the following line
usepackage{fixltx2e}
and inside the body write:
It is found that heighttextsubscript{apple tree} is
different than heighttextsubscript{orange tree}
and we obtain:
It is found that heightapple tree is different than
heightorange tree
shudh@JNEC LATEX@ JNEC 15 / 31
16. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Line spacing
Line spacing can be set to single line, one and a half line, double line
spacings, and any other customized spacings. In the preamble, use
usepackage{setspace}
... and in the body write any one:
singlespacing
onehalfspacing
doublspacing
setstretch{1.1}
shudh@JNEC LATEX@ JNEC 16 / 31
17. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Coloured text
In your preamble, add the following line
usepackage{color}
%this gives about 16 colour options
Alternatively, one can write:
usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
%Gives about 16+64+150
colours
Therefore, we can have red coloured text, and a blue coloured text,
and back to the black colour, by
Therefore, we can have {color{red}red coloured text},
and a {color{blue}blue coloured text}, and back to
the black colour.
shudh@JNEC LATEX@ JNEC 17 / 31
18. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Itemized and numbered lists
begin{itemize}
item Item 1
item Item 2
item Item 3
end{itemize}
begin{enumerate}
item Item 1
item Item 2
item Item 3
end{enumerate}
Item 1
Item 2
Item 3
1 Item 1
2 Item 2
3 Item 3
Can you guess how we get multilevel lists?
shudh@JNEC LATEX@ JNEC 18 / 31
19. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Typesetting environments
LaTeX has various environments, which start and end with the
begin and end commands.
abstract
equation
center
raggedright
For example
begin{abstract}
Tomatoes have long been
considered as the
cause of kidney
stones. Researches
have been trying to
eliminate this trait
of the tomatoes
through genetic
engineering.
end{abstract}
shudh@JNEC LATEX@ JNEC 19 / 31
20. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Preamble Body Style
Let us get our hands dirty
Font sizes
Sample
Sample
Sample
Sample
Sample
Sample
Sample
Sample
Sample
Sample
tiny Sample
scriptsize
Sample
footnotesize
Sample
small Sample
normalsize
Sample
large Sample
Large Sample
LARGE Sample
huge Sample
Huge Sample
shudh@JNEC LATEX@ JNEC 20 / 31
21. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics
Outline
1 Why should we use LATEX
Etymology
2 Parts of a LATEX document
The Preamble
The body
Text styles
3 Mathematical typesetting
4 Graphics
Tables
shudh@JNEC LATEX@ JNEC 21 / 31
22. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics
Playing with mathematics text
Mathematics environments
There are two kinds of math used in LATEX.
Inline math
Display math
About any point $x$ in a
metric space $M$ we define the
open ball of radius $r > 0$
about $x$ as the set
$$
B(x;r) = {y in M :
d(x,y) < r}.
$$
About any point x in a metric
space M we define the open ball
of radius r > 0 about x as the set
B(x;r) = {y ∈ M : d(x,y) < r}.
shudh@JNEC LATEX@ JNEC 22 / 31
23. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics
Typesetting equations
Numbered equations
Numbered equations can be typeset by using
begin{equation}
R(x,y) =
frac{Ax^3+Bx^2+Cx+D}{Ey^3
+ Fy + G}
end{equation}
R(x,y) =
Ax3
+Bx2
+Cx+D
Ey3 +Fy +G
(1)
shudh@JNEC LATEX@ JNEC 23 / 31
24. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Outline
1 Why should we use LATEX
Etymology
2 Parts of a LATEX document
The Preamble
The body
Text styles
3 Mathematical typesetting
4 Graphics
Tables
shudh@JNEC LATEX@ JNEC 24 / 31
25. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting images
To include a graphics file duck.jpg in a LATEX file, type in the
preamble
%in the preamble
usepackage{graphicx}
and in the body
includegraphics{duck.jpg}
And, here it is:
shudh@JNEC LATEX@ JNEC 25 / 31
26. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting images
..and numbering them
A paper would require numbering the images.
begin{figure}
centering
includegraphics{duck.jpg}
caption{A
picture
of a
duck
used at
muggle
homes
as a
toy}
end{figure}
Figure 1: A picture of a duck
used at muggle homes as a
toy
shudh@JNEC LATEX@ JNEC 26 / 31
27. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting graphs in a LaTeX file
A gnuplot and LATEX combo
Start gnuplot, and write the following codes:
set term tikz color solid
size 4in,3in
set output "sin.tex"
set xr [-2*pi:2*pi]
plot sin(x) with lines
exit
In your preamble, use the following
usepackage{gnuplot-lua-tikz}
and, in the body, wherever you wish to insert the figure, type
input{sin}
shudh@JNEC LATEX@ JNEC 27 / 31
28. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting graphs in a LaTeX file
A gnuplot and LATEX combo
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
-6 -4 -2 0 2 4 6
sin(x)
shudh@JNEC LATEX@ JNEC 28 / 31
29. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting tables
Tables require the tabular environment.
begin{tabular}{lccc}
{} &Judge 1 &Judge 2 &Judge 3 hline
Katrina &7 &9 &10
Karishma &9 &10 &7
Kareena &10 &7 &9 hline
end{tabular}
will give:
Judge 1 Judge 2 Judge 3
Katrina 7 9 10
Karishma 9 10 7
Kareena 10 7 9
shudh@JNEC LATEX@ JNEC 29 / 31
30. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
Inserting tables
... and numbering them
begin{table}
begin{tabular}{lccc}
{} &Judge 1
&Judge 2
&Judge 3
hline
Katrina &7 &9
&10
Karishma &9 &10
&7
Kareena &10 &7
&9 hline
end{tabular}
caption{Scores
given by the
judges for
different
participants
in a beauty
competition.
end{table}
Judge 1 Judge 2 Judge 3
Katrina 7 9 10
Karishma 9 10 7
Kareena 10 7 9
Table 1: Scores given by the judges for different
participants in a beauty competition.
Meanings:
lccc: Left,centered,centered,centered
hline: Horizontal line
: Line break
&: Tab character
shudh@JNEC LATEX@ JNEC 30 / 31
31. SU
D
D
H
ASH
EEL.CO
M
Motivation Parts Math Graphics Tables
In the upcoming sessions
Typesetting advanced mathematics
Typesetting aligned and multiline equations
Typesetting Matrices
Vector notations: Cross product, dot product, bold vectors
shudh@JNEC LATEX@ JNEC 31 / 31