introduction to latex · introduction to latex. basic latex document structure...

44
Introduction to L A T E X Brian McCutchon Brian McCutchon Introduction to L A T E X

Upload: others

Post on 18-Oct-2020

30 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Introduction to LATEX

Brian McCutchon

Brian McCutchon

Introduction to LATEX

Page 2: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 3: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 4: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 5: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 6: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 7: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 8: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

What is LATEX?

A document preparation/typesetting system

A markup language

Used by the vast majority of Math and Physics journal

submissions

Used to create this presentation and the flyer for this event

Better than Microsoft Word

TEX was created by Donald Knuth

LATEX was created by Leslie Lamport to make TEX more user

friendly

Brian McCutchon

Introduction to LATEX

Page 9: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Basic LATEX document structure

“documentclass–article˝

% This is where you put metadata

% like the author , title , and date.

“begin–document˝

This is where your content goes.

“end–document˝

Figure 1: A minimal LATEX document

Brian McCutchon

Introduction to LATEX

Page 10: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Breaking it down

This line indicates the type of document:

“documentclass–article˝

These tags define the document environment:

“begin–document˝...“end–document˝

Brian McCutchon

Introduction to LATEX

Page 11: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Math mode

Inline: simplest, put math between dollar-signs ($)

$xˆ2 + 1$ gives x2 + 1

Display: used for big/important equations, centers them ontheir own line; use “[ ... “] to enclose these

“[ a˙3 xˆ3 + a˙2 xˆ2 + a˙1 x + a˙0 “] gives:

a3x3 + a2x

2 + a1x + a0

There are even cooler ways to do display math that will be

explained later in the presentation

Brian McCutchon

Introduction to LATEX

Page 12: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Math mode

Inline: simplest, put math between dollar-signs ($)

$xˆ2 + 1$ gives x2 + 1

Display: used for big/important equations, centers them ontheir own line; use “[ ... “] to enclose these

“[ a˙3 xˆ3 + a˙2 xˆ2 + a˙1 x + a˙0 “] gives:

a3x3 + a2x

2 + a1x + a0

There are even cooler ways to do display math that will be

explained later in the presentation

Brian McCutchon

Introduction to LATEX

Page 13: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Math mode

Inline: simplest, put math between dollar-signs ($)

$xˆ2 + 1$ gives x2 + 1

Display: used for big/important equations, centers them ontheir own line; use “[ ... “] to enclose these

“[ a˙3 xˆ3 + a˙2 xˆ2 + a˙1 x + a˙0 “] gives:

a3x3 + a2x

2 + a1x + a0

There are even cooler ways to do display math that will be

explained later in the presentation

Brian McCutchon

Introduction to LATEX

Page 14: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Math mode

Inline: simplest, put math between dollar-signs ($)

$xˆ2 + 1$ gives x2 + 1

Display: used for big/important equations, centers them ontheir own line; use “[ ... “] to enclose these

“[ a˙3 xˆ3 + a˙2 xˆ2 + a˙1 x + a˙0 “] gives:

a3x3 + a2x

2 + a1x + a0

There are even cooler ways to do display math that will be

explained later in the presentation

Brian McCutchon

Introduction to LATEX

Page 15: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Commands

Every command has this form: “command–arg1˝–arg2˝...

Examples:

“alpha gives α

“sqrt–2˝ gives√

2

“frac–x˝–2˝ gives x2

Some commands take optional parameters:“command[optional]–arg1˝–arg2˝...

“sqrt[3]–x˝ gives 3√x

The above examples are all math mode commands, but some

commands are used in text mode (e.g. maketitle) and some

of these are used in the preamble (author, date, title)

Brian McCutchon

Introduction to LATEX

Page 16: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Commands

Every command has this form: “command–arg1˝–arg2˝...

Examples:

“alpha gives α

“sqrt–2˝ gives√

2

“frac–x˝–2˝ gives x2

Some commands take optional parameters:“command[optional]–arg1˝–arg2˝...

“sqrt[3]–x˝ gives 3√x

The above examples are all math mode commands, but some

commands are used in text mode (e.g. maketitle) and some

of these are used in the preamble (author, date, title)

Brian McCutchon

Introduction to LATEX

Page 17: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Commands

Every command has this form: “command–arg1˝–arg2˝...

Examples:

“alpha gives α

“sqrt–2˝ gives√

2

“frac–x˝–2˝ gives x2

Some commands take optional parameters:“command[optional]–arg1˝–arg2˝...

“sqrt[3]–x˝ gives 3√x

The above examples are all math mode commands, but some

commands are used in text mode (e.g. maketitle) and some

of these are used in the preamble (author, date, title)

Brian McCutchon

Introduction to LATEX

Page 18: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Commands

Every command has this form: “command–arg1˝–arg2˝...

Examples:

“alpha gives α

“sqrt–2˝ gives√

2

“frac–x˝–2˝ gives x2

Some commands take optional parameters:“command[optional]–arg1˝–arg2˝...

“sqrt[3]–x˝ gives 3√x

The above examples are all math mode commands, but some

commands are used in text mode (e.g. maketitle) and some

of these are used in the preamble (author, date, title)

Brian McCutchon

Introduction to LATEX

Page 19: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Commands

Every command has this form: “command–arg1˝–arg2˝...

Examples:

“alpha gives α

“sqrt–2˝ gives√

2

“frac–x˝–2˝ gives x2

Some commands take optional parameters:“command[optional]–arg1˝–arg2˝...

“sqrt[3]–x˝ gives 3√x

The above examples are all math mode commands, but some

commands are used in text mode (e.g. maketitle) and some

of these are used in the preamble (author, date, title)

Brian McCutchon

Introduction to LATEX

Page 20: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Structuring your document

Create automatically numbered sections and subsections

with “section–Name˝, “subsection–Name˝, and

“subsubsection–Name˝ or even “chapter–Name˝

If you don’t want numbering, use “section*–Name˝

Put in an automatically generated table of contents fromthese sections with “tableofcontents

See also: “listoffigures and “listoftables

Brian McCutchon

Introduction to LATEX

Page 21: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Structuring your document

Create automatically numbered sections and subsections

with “section–Name˝, “subsection–Name˝, and

“subsubsection–Name˝ or even “chapter–Name˝

If you don’t want numbering, use “section*–Name˝

Put in an automatically generated table of contents fromthese sections with “tableofcontents

See also: “listoffigures and “listoftables

Brian McCutchon

Introduction to LATEX

Page 22: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Structuring your document

Create automatically numbered sections and subsections

with “section–Name˝, “subsection–Name˝, and

“subsubsection–Name˝ or even “chapter–Name˝

If you don’t want numbering, use “section*–Name˝

Put in an automatically generated table of contents fromthese sections with “tableofcontents

See also: “listoffigures and “listoftables

Brian McCutchon

Introduction to LATEX

Page 23: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Structuring your document

Create automatically numbered sections and subsections

with “section–Name˝, “subsection–Name˝, and

“subsubsection–Name˝ or even “chapter–Name˝

If you don’t want numbering, use “section*–Name˝

Put in an automatically generated table of contents fromthese sections with “tableofcontents

See also: “listoffigures and “listoftables

Brian McCutchon

Introduction to LATEX

Page 24: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Environments

Like commands, but bigger

Used to format blocks of text or math

Format:

“begin–environmentname˝...“end–environmentname˝

Common environments: document, itemize/enumerate,

center, abstract

Use the “abstract” environment to define an abstract

Brian McCutchon

Introduction to LATEX

Page 25: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Environments

Like commands, but bigger

Used to format blocks of text or math

Format:

“begin–environmentname˝...“end–environmentname˝

Common environments: document, itemize/enumerate,

center, abstract

Use the “abstract” environment to define an abstract

Brian McCutchon

Introduction to LATEX

Page 26: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Environments

Like commands, but bigger

Used to format blocks of text or math

Format:

“begin–environmentname˝...“end–environmentname˝

Common environments: document, itemize/enumerate,

center, abstract

Use the “abstract” environment to define an abstract

Brian McCutchon

Introduction to LATEX

Page 27: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Environments

Like commands, but bigger

Used to format blocks of text or math

Format:

“begin–environmentname˝...“end–environmentname˝

Common environments: document, itemize/enumerate,

center, abstract

Use the “abstract” environment to define an abstract

Brian McCutchon

Introduction to LATEX

Page 28: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Environments

Like commands, but bigger

Used to format blocks of text or math

Format:

“begin–environmentname˝...“end–environmentname˝

Common environments: document, itemize/enumerate,

center, abstract

Use the “abstract” environment to define an abstract

Brian McCutchon

Introduction to LATEX

Page 29: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Packages

Packages provide more commands and environments

Add a package to your document by putting this in the

preamble: “usepackage[options]–packagename˝

Examples

“usepackage–amsmath˝ provides many useful environments

(equation, align, bmatrix, etc.)

“usepackage–amssymb˝ provides many useful commands

that create symbols (mathbb, lhd)

“usepackage–amsthm˝ provides commands for creating

theorems, lemmata, corollaries, definitions, and more!

“usepackage[margin=1in]–geometry˝ sets page margins

to 1 inch

Brian McCutchon

Introduction to LATEX

Page 30: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Packages

Packages provide more commands and environments

Add a package to your document by putting this in the

preamble: “usepackage[options]–packagename˝

Examples

“usepackage–amsmath˝ provides many useful environments

(equation, align, bmatrix, etc.)

“usepackage–amssymb˝ provides many useful commands

that create symbols (mathbb, lhd)

“usepackage–amsthm˝ provides commands for creating

theorems, lemmata, corollaries, definitions, and more!

“usepackage[margin=1in]–geometry˝ sets page margins

to 1 inch

Brian McCutchon

Introduction to LATEX

Page 31: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Packages

Packages provide more commands and environments

Add a package to your document by putting this in the

preamble: “usepackage[options]–packagename˝

Examples

“usepackage–amsmath˝ provides many useful environments

(equation, align, bmatrix, etc.)

“usepackage–amssymb˝ provides many useful commands

that create symbols (mathbb, lhd)

“usepackage–amsthm˝ provides commands for creating

theorems, lemmata, corollaries, definitions, and more!

“usepackage[margin=1in]–geometry˝ sets page margins

to 1 inch

Brian McCutchon

Introduction to LATEX

Page 32: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Equations and References

“begin–equation˝

eˆ–“pi i˝ + 1 = 0

“label–eqn:euler˝

“end–equation˝

Equation ˜“ref–eqn:euler˝ shows Euler ’s

identity.

Figure 2: A labeled equation with a reference to it

Brian McCutchon

Introduction to LATEX

Page 33: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Figures and References

“begin–figure ˝[t]

“centering

Figure goes here.

“caption–A really cool figure that

illustrates my point perfectly˝

“label–fig:myfig˝

“end–figure˝

This is a reference to figure ˜“ref–fig:myfig

˝.

Figure 3: The structure of a figure, with a reference to it below

Brian McCutchon

Introduction to LATEX

Page 34: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Bibliography

“bibliography–mybib˝

“bibliographystyle–plain˝

Figure 4: How to include a bibliography named “mybib”

Include a bibliography file as shown in figure 4

Use the package “cite” for easy citations

Reference an entry in this bibliography using

“cite–bibentryname˝

Brian McCutchon

Introduction to LATEX

Page 35: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Making a Bibliography

@article–doe ,

author = ”John Doe”,

title = ”How to farm corn”,

journal = ”The Farmer ’s Periodical”,

year = ”2018” ,

˝

Figure 5: An example bibliography entry; this would go in “mybib.bib”

Brian McCutchon

Introduction to LATEX

Page 36: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 37: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 38: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 39: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 40: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 41: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Miscellaneous

quotation marks: ‘‘hi’’ gives “hi”

3 lengths of dashes: hyphen (-), en dash (–), em dash (—)

Empty lines between paragraphs

Forced line breaks with ““

Comments with %

Escaping $, %, {, }

Brian McCutchon

Introduction to LATEX

Page 42: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Further Reading

Detexify — look up symbols easily

LATEX Wikibook

Google — No, really

Brian McCutchon

Introduction to LATEX

Page 43: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Further Reading

Detexify — look up symbols easily

LATEX Wikibook

Google — No, really

Brian McCutchon

Introduction to LATEX

Page 44: Introduction to LaTeX · Introduction to LATEX. Basic LATEX document structure \documentclass{article} % This is where you put metadata % like the author, title, and date. \begin{document}

Further Reading

Detexify — look up symbols easily

LATEX Wikibook

Google — No, really

Brian McCutchon

Introduction to LATEX