introduction to latex

47
What is L A T E X The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources Introduction to L A T E X Aleksandar Petrov EUROAVIA Delft October 8, 2015 EUROAVIA

Upload: aleksandar-petrov

Post on 03-Dec-2015

226 views

Category:

Documents


0 download

DESCRIPTION

A presention giving a short introduction to LaTeX

TRANSCRIPT

Page 1: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Introduction to LATEX

Aleksandar Petrov

EUROAVIA Delft

October 8, 2015

E U R O A V I A

Page 2: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 3: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Why use LATEX?

Focus on writing, not on typesetting or formatting

Deliver beautifully looking texts with minimum effort

Efficiently incorporate math expressions

Page 4: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

How does LATEXwork?

1 You type your content in a text file

2 A compiler processes your file

3 A beautiful PDF is generated for you

Page 5: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Where can I type LATEX?

In order to crate your file you need only the LATEXcompiler

However, typing your code can be much more easier if you usea dedicated editor

Many options exist both online and offline

Local installation depends on OS and editor choice

Suggested online option is ShareLatex.com

Page 6: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 7: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Document Layout

Hello World example:

\ d o c u m e n t c l a s s a r t i c l e \ b e g i n documentH e l l o World\enddocument

Some other types of documents are:report, book, memoir, letter, beamer

Page 8: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Document Layout

A report class example:

\ d o c u m e n t c l a s s r e p o r t

% T i t l e Page\ t i t l e Report T i t l e \ a u t h o r Author name

\ b e g i n document\m a k e t i t l e

\ b e g i n a b s t r a c t Sum up what i t i s a l l about\end a b s t r a c t

\ c h a p t e r I n t r o d u c t i o n Background i n f o r m a t i o n

\enddocument

Page 9: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Sectioning

LATEX understands how humans organize books, articles, reports,etc. and makes it easier.

\ c h a p t e r Chapter T i t l e \ s e c t i o n S e c t i o n T i t l e \ s u b s e c t i o n S u b s e c t i o n T i t l e \ s u b s u b s e c t i o n S u b s u b s e c t i o n T i t l e \ p a r a g r a p h Paragraph Topic Paragraph Text

Page 10: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Line Breaks

This is the first paragraph, contains some text to show how amazing an author I am. I know it is

magnificent, you don’t need to tell me this.

We are continuing with the fancy stuff. As you can see, the line of my thought has not changed. \par

Indeed, I am still wondering if you are impressed enough...\newline

For sure this text has some point. However, to be completely honest, I am not really sure

what it is. \\

That is why, although useful, it might be just a bit meaningless.

Page 11: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Line Breaks

To sum up:

empty line - new paragraph without adding an empty line(keeping the topic the same)

\par - new paragraph without adding an empty line (keepingthe topic the same)

\\ - new paragraph with adding an empty line (introducingnew topic)

\newline - new paragraph with adding an empty line(introducing new topic)

Page 12: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Table of contents

Automatic table of contents can be generated in a very simple way.It will update itself every time you build the PDF:

\tableofcontents

Note

If the table of contents has not updated, build the file again.

Appendices can be added in the same manner as chapters. The\appendix command switches the chapter numbering to letters.

Page 13: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Table of contents

\begindocument

\maketitle

\tableofcontents

\newpage

\chapterIntroduction

\chapterLiterature study

\sectionHistorical remarks

\sectionModern development

\chapterDesign propsal

\appendix

\chapterAdditional information

\enddocument

Page 14: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Big project management

Sometimes LATEX source code can get pretty huge. That is why itis handy to separate it over several files. Then these files can belinked to the main file. The way to do this is the\inputfilename command. When the compiler sees it, it firstprocesses the external file and then continues with the main file asif it is one whole thing. Meaning that no breaks in page andsection numbering, referencing and labeling will occur.

When interested in previewing only one part of the document, youcan comment the \input commands for the others. That willreduce the building time significantly.

Page 15: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Special characters

Note

There are some reserved characters and using them in your textwill most probably result in an error message from the compiler.

# $ % ^ & _ \

If you still want to use any of them, just put a backslash before it.

1 \#, \$, \%, \ˆ, \&, \ , \, \, $\backslash$ #, $, %, ˆ, &, , , , \

Page 16: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 17: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Typesetting Math

The mathematical typesetting capabilities of LATEX are extremelyadvanced. They present one of the main strengths of LATEX.However, in order to “unlock” the full capability we need to usethe AMS-LATEX package.

Adding the AMS-LATEX package to your file can be done in thesame way as adding any other extension package. Just use the\usepackageamsmath in the preamble.

\documentclassreport

\usepackageamsmath

% Title Page

\titleReport Title

\authorAuthor name

\begindocument

\maketitle

...

Page 18: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Math vs. Text Mode

In order to start typing equations and other mathematicalexpressions you need to switch to math mode. There are manydifferent ways to do this but two are the major ones:

In-line (text style)

1 For example, $aˆ2 + bˆ2 = cˆ2$ For example, a2 + b2 = c2

Separately (display style)

1 And another important resultfollows :

2 \beginequation3 c = \sqrtaˆ2 + bˆ24 \endequation

And another important resultfollows:

c =√a2 + b2 (1)

Page 19: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Subscripts and Superscripts

1 The average $X avg$ of threenumbers $X 1$, $X 2$ and $X3$ is

2 \beginequation3 X avg = (X 1 + X 2 + X 3) / 34 \endequation5 However, their squared sum $X

sum$ equals6 \beginequation7 X sum = X 1ˆ2 + X 2ˆ2 + X 3ˆ28 \endequation9 Finally , their exponent can be

separated in the followingmanner:

10 \beginequation11 eˆX 1 + X 2 + X 3 = eˆX 1 e

ˆX 2 eˆX 312 \endequation

The average Xavg of three numbersX1, X2 and X3 is

Xavg = (X1 + X2 + X3)/3 (2)

However, their squared sum Xsum

equals

Xsum = X 21 + X 2

2 + X 23 (3)

Finally, their exponent can be sep-arated in the following manner:

eX1+X2+X3 = eX1eX2eX3 (4)

Page 20: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Some mathematical expressions

1 Let’ s compute $7 = \frac213 = \dfrac213$.2 \begingather3 X avg = \fracX 1 + X 2 + X 33\\4 c = \sqrt \fracaˆ2 + bˆ24 \\5 \lim x \rightarrow 0\frac\sin xx = 16 \endgather

Let’s compute 7 = 213 =

21

3.

Xavg =X1 + X2 + X3

3(5)

c =

√a2 + b2

4(6)

limx→0

sin x

x= 1 (7)

Page 21: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Greek letters

Greek letters can be easily entered in any math environment byjust typing \ and the name of the letter:

1 $\alpha, \beta, \gamma, \omega, \psi, \eta, \theta, \mu, \nu, \delta$

α, β, γ, ω, ψ, η, θ, µ, ν, δ

Some of the capital Greek letters can also be typed in LATEX:

1 $\Gamma, \Omega, \Psi, \Theta, \Delta$

Γ,Ω,Ψ,Θ,∆

Page 22: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Bars, vectors, dots and hats

Math accents can also be easily typed:

1 $\barX = X avg = \fracX 1 + X 2 + X 33$ \\2 $\vecr = \vecx + \vecy + \vecz$ \\3 $\vecr = x \hati + y \hatj + z \hatk$ \\4 $v = \dotx$ \\5 $a = \dotv = \ddotx$

X = Xavg = X1+X2+X33

~r = ~x + ~y + ~z~r = x i + y j + zkv = xa = v = x

Page 23: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Sums, Products and Integrals

1 $\sum k=0ˆ\infty \frac(−1)ˆk zˆ2k+1(2k+1)!=\sin z$2 \begingather3 \sum k=0ˆ\infty \frac(−1)ˆk zˆ2k+1(2k+1)!=\sin z \\4 \ int 0ˆ\ infty \frac Mx dx \\5 \prod n=1ˆ5\fracnn−16 \endgather

∑∞k=0

(−1)kz2k+1

(2k+1)! = sin z

∞∑k=0

(−1)kz2k+1

(2k + 1)!= sin z (8)∫ ∞

0

M

xdx (9)

5∏n=1

n

n − 1(10)

Page 24: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Dots

You want to multiply something?Never do this:

1 $$ 2∗16\pi = 32\pi $$ 2 ∗ 16π = 32π

Instead, use \cdot:

1 $$ 2 \cdot 16\pi = 32\pi $$ 2 · 16π = 32π

Page 25: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Dots

You want to list some variables? Never do it like that:

1 $$ X n = \ x 1, ... , x n \ $$ Xn = x1, ..., xn

Instead, use the dedicated commands:

1 $$ X n = \ x 1, \ ldots , x n \ $$2 $$ S n = x 1 + \cdots + x n $$

Xn = x1, . . . , xn

Sn = x1 + · · ·+ xn

Page 26: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Typing some common functions

Which one looks better:

cosθ or cos θ?

The first one is typed as $cos \theta$ so is interpreted as the productof three variables - c ,o and s. However, the second option uses thecosine command $\cos \theta$ and the compiler understands it is thecosine function.

Some other functions that have dedicated commands are:

1 $$\sin , \cos, \tan, \cot, \log , \ln , \arccos , \arcsin , \arctan, \exp, \min, \max, \ldots$$

sin, cos, tan, cot, log, ln, arccos, arcsin, arctan, exp,min,max, . . .

Page 27: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Bracketing

These brackets don’t look good:

1 $$ f(x) = (\fracxˆ2 + 1 \sqrtx) (7−x)$$ f (x) = (

x2 + 1√x

)(7− x)

That way is better:

1 $$ f(x) = \ left ( \fracxˆ2 + 1 \sqrtx \right) (7−x)$$ f (x) =

(x2 + 1√

x

)(7− x)

This strategy works with any kind of brackets:

1 $$\ left [ \fracab \right ], \ left \lbrace \fracab \right\rbrace , \ left | \fracab \right | $$

[ab

],ab

,∣∣∣ab

∣∣∣

Page 28: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Equation numbering

Did you notice that some of the equations above had numbers on theright?

1 \beginequation2 f(x) = \sqrtx(xˆ2 + 1)3 \endequation

f (x) =√x(x2 + 1) (11)

This numbering makes referencing easy as we will see later. Note alsothat only display equations can have numbering.Removing the numbering of a given equation can be made in two ways:

Use equation* (or any other starred) environment instead ofequation

Put the \nonumber tag right after the equation (on the same line)

Page 29: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 30: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Floats

Floats are content that is considered separate from the main text.As such they can “float” around the pages and position themselvesat a suitable place. Another important aspect of floats is that (inthe general case) they cannot be broken over two or more pages.

Two types of objects are considered floats:

Figures

Tables

Page 31: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Figures

The basic code structure for including a figure (image) into a LATEXdocument is the following:

\beginfigure[position preference]

\centering

\includegraphics[width=somewidth]path to image

\captionSome caption

\endfigure

Page 32: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Figures

position preference

Although LATEX positions the figure at a place it considers optimal,you can still specify a preference. However, keep in mind that thisis only a preference and LATEX might not follow it.

Specifier Permission

hPlace the float here, i.e., approximately at the same point it occursin the source text (however, not exactly at the spot)

t Position at the top of the page.b Position at the bottom of the page.p Put on a special page for floats only.! Override internal parameters LATEX uses for determining ”good” float positions.

H

Places the float at precisely the location in the LATEX code.Requires the float package, e.g., \usepackagefloat.This is somewhat equivalent to h!.

Taken from https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Page 33: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Figures

width

This can be measured in any of the units LATEX understands (e.g.cm, px , in). However, for many cases it is most convenient tospecify the width of the picture as a percentage of the text width.For example:

\includegraphics[width=0.5\textwidth]path to image

Page 34: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Figures

Here we present an example of imported picture:

1 \beginfigure2 \centering3 \ includegraphics [width=0.7\linewidth

]./ logo4 \captionEUROAVIA logo5 \endfigure

E U R O A V I A

Figure : EUROAVIA logo

The caption of the figure can be above the image if the \caption

tag is placed before the \includegraphics tag.

Page 35: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Tables

LATEX allows for the design of pretty sophisticated tables. However,we will discuss only the most simple table functions.

Typing big tables in LATEX by hand can be both time consumingand error-prone. That is why it is suggested to use a tablegenerator that simplifies the work considerably.TablesGenerator.com have a lot of formating options andfacilitate copy-paste from Excel and other spreadsheet programs.

Page 36: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Tables

An example table generated with TablesGenerator.com.

1 \begintable[b]2 \centering3 \captionMy caption4 \begintabular| ll |c|5 \hline6 Column A & Column B & Column C \\ \hline7 1 & 2 & abc \\8 4 & 5 & def \\9 7 & 8 & ghi \\ \hline

10 \endtabular11 \endtable

Table : My caption

Column A Column B Column C1 2 abc4 5 def7 8 ghi

Page 37: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Tables

Table contents goes between begintabular and\endtabular

Vertical alignment of the columns and column separators arespecified by the |ll|c| tag

Horizontal lines between two rows can be put with the\hline tag

The caption can be bellow the table if the \caption tag isplaced after the \endtabular tag

Page 38: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 39: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Referencing & Citing

Making sure that all the referencing and citing within your reportis correct can be quite a tedious task if you type your document ina typical word processor. LATEX incorporates a powerful, yet simpleand flexible methodology to keep track of all the references andcitations.

Page 40: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Referencing

Referencing is made of two parts:

Labeling your content

Connecting the text to the labels

Page 41: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Labels

Labels can be put with the \labellabel_name to manydifferent types of objects. It is important to never use the samelabel twice. This would produce a warning and a missing reference.You can label:

Chapters and sections: put the label right after the respective\chapter or \section tag

Equations: put the label right after the equation and beforeany new line tag

Floats (figures and tables): the \label tag must come rightafter the \caption tag

Page 42: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

References

There are two main reference commands:

\refmarker: Returns the number of the respectivechapter, section, equation, table or float.

\pagerefmarker: Returns the page at which therespective chapter, section, equation, table or float is situated

Note

LATEX does not know what type of content you are referencing to.It returns only a number. That is why if you are referencing to anequation you should type Equation \reflabel_name.

Page 43: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

References

As can be seen in Figure

\reffig: EUROAVIA_logo,

the EUROAVIA logo is green

and similar to the logo

of Superman.

\beginfigure

\centering

\includegraphics[width=

0.5\linewidth]./logo

\captionEUROAVIA logo

\labelfig: EUROAVIA_logo

\endfigure

Page 44: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Citing

Citing to external sources can be done in a similar way. The most simpleway to do this is to create a list with sources between\beginthebibliography and \endthebibliography tags. Then,wherever in the main text referencing to this source is needed use the\citecite_label in the same way as \ref.

\LaTeX is widely used for scientific papers. \citelamport94

\beginthebibliography9

\bibitemlamport94

Leslie Lamport,

\emph\LaTeX: a document preparation system,

Addison Wesley, Massachusetts,

2nd edition,

1994.

\endthebibliography

Page 45: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Citing

The \beginthebibliography and\endthebibliography tags are typically placed rightbefore the the \enddocument tag

If you use more than 9 sources, change\beginthebibliography9 to\beginthebibliography99

The label of a source is the argument of the\bibitemcite_label tag

Never use the same source label twice

For more powerful bibliography management use BibTeX

Page 46: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Contents

1 What is LATEX2 The Basics of the Basics

Document LayoutSectioningLine BreaksTable of contentsBig project managementSpecial characters

3 Typesetting MathMath environments

Typing symbolsBracketingEquation numbering

4 FloatsFiguresTables

5 Referencing & CitingReferencingCiting

6 Additional resources

Page 47: Introduction to LaTeX

What is LATEX The Basics of the Basics Typesetting Math Floats Referencing & Citing Additional resources

Additional resources

Wikipedia.org

CTAN.org

The Not So Short Introduction to LATEX2ε, Tobias Oetiker,https://tobi.oetiker.ch/lshort/lshort.pdf

Google

tex.stackexchange.com