0% found this document useful (0 votes)
250 views213 pages

LaTeX Wikibook

Hints and tips about how to use LaTeX

Uploaded by

john.savage
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)
250 views213 pages

LaTeX Wikibook

Hints and tips about how to use LaTeX

Uploaded by

john.savage
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

LaTeX Wikibook

Contents
1

Getting Started

1.1

LaTeX/Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.1.1

What is TeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.1.2

What is LaTeX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.1.3

Philosophy of use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.1.4

Terms regarding TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.1.5

What next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LaTeX/Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.1

Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.2

Custom installation with TeX Live . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.3

Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.4

Bibliography management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.5

Viewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.6

Tables and graphics tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.7

Online solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2.8

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

LaTeX/Installing Extra Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3.1

Automatic installation

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3.2

Manual installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3.3

Checking package status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.3.4

Package documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.3.5

External resources

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.3.6

See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

LaTeX/Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.4.1

The LaTeX syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.4.2

Our rst document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

1.4.3

Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

1.4.4

Files

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

1.4.5

And what now? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

1.2

1.3

1.4

Common Elements

16

2.1

LaTeX/Document Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

2.1.1

16

Global structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
i

ii

CONTENTS

2.2

2.3

2.4

2.5

2.1.2

Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

2.1.3

The document environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

2.1.4

Book structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19

2.1.5

Special pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19

2.1.6

Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

20

LaTeX/Text Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

20

2.2.1

Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

20

2.2.2

Hyphenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21

2.2.3

Quote-marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21

2.2.4

Diacritics and accents

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.5

Margin misalignment and interword spacing . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.6

Ligatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.7

Slash marks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.8

Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.9

Formatting macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

2.2.10 Text mode superscript and subscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2.11 Text gures (old style numerals) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2.12 Dashes and hyphens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2.13 Ellipsis ()

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2.14 Ready-made strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2.15 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

LaTeX/Paragraph Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24

2.3.1

Paragraph alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24

2.3.2

Paragraph indent and break

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24

2.3.3

Line spacing

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24

2.3.4

Manual breaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25

2.3.5

Special paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25

2.3.6

Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

LaTeX/Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

2.4.1

Adding the color package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

2.4.2

Entering colored text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

2.4.3

Entering colored background for the text . . . . . . . . . . . . . . . . . . . . . . . . . . .

27

2.4.4

Predened colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

27

2.4.5

Dening new colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

27

2.4.6

Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

LaTeX/Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

2.5.1

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

2.5.2

Font families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

2.5.3

Emphasizing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

29

2.5.4

Font encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

29

2.5.5

Font styles

29

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CONTENTS

iii

2.5.6

Local font selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

2.5.7

Arbitrary font size

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

2.5.8

Finding fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

2.5.9

Using arbitrary system fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

2.5.10 PDF fonts and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

2.5.11 Useful websites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

2.5.12 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

LaTeX/List Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

2.6.1

List structures

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

2.6.2

Nested lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

2.6.3

Customizing lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

2.6.4

Inline lists

33

2.6.5

Easylist package

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33

2.6.6

Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

LaTeX/Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

2.7.1

Input encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

2.7.2

Escaped codes

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

2.7.3

Less than < and greater than > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

2.7.4

Euro currency symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

2.7.5

Degree symbol for temperature and math

. . . . . . . . . . . . . . . . . . . . . . . . . .

36

2.7.6

Other symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

2.7.7

In special environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

2.7.8

Unicode keyboard input

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

2.7.9

External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

2.7.10 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

LaTeX/Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

2.8.1

Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

2.8.2

Babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

2.8.3

Multilingual versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38

2.8.4

Specic languages

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39

2.8.5

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

LaTeX/Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

2.9.1

The rotating package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

2.9.2

The rotoat package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

44

2.10 LaTeX/Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

44

2.10.1 The tabular environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

44

2.10.2 Row specication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46

2.10.3 Spanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46

2.10.4 Controlling table size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47

2.10.5 Colors

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47

2.10.6 Width and stretching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47

2.6

2.7

2.8

2.9

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

iv

CONTENTS
2.10.7 Table across several pages

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48

2.10.8 Partial Vertical Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48

2.10.9 Vertically centered images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48

2.10.10 Footnotes in tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

48

2.10.11 Professional tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49

2.10.12 Sideways tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49

2.10.13 Table with legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

50

2.10.14 The eqparbox package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

50

2.10.15 Floating with table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

50

2.10.16 Using spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

50

2.10.17 Need more complicated features?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

2.10.18 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

2.11 LaTeX/Title Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

2.11.1 Standard Title Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

2.11.2 Custom Title Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

2.11.3 Packages for custom titles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

2.11.4 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

2.12 LaTeX/Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

2.12.1 Two-sided documents

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

2.12.2 Page dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

53

2.12.3 Page size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

54

2.12.4 Margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

55

2.12.5 Page orientation

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

55

2.12.6 Margins, page size and rotation of a specic page . . . . . . . . . . . . . . . . . . . . . .

56

2.12.7 Page styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

56

2.12.8 Page background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

2.12.9 Multi-column pages

58

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.12.10 Manual page formatting

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

2.12.11 Widows and orphans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

2.12.12 Notes and References

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13 LaTeX/Importing Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13.1 Raster graphics vs. vector graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13.2 The graphicx package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13.3 Document Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13.4 Supported image formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

2.13.5 Including graphics

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

60

2.13.6 Graphics storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

61

2.13.7 Images as gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

61

2.13.8 Text wrapping around pictures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

61

2.13.9 Seamless text integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

61

2.13.10 Including full PDF pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

62

CONTENTS

2.13.11 Converting graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

62

2.13.12 Third-party graphics tools

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

63

2.13.13 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

65

2.14 LaTeX/Floats, Figures and Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

65

2.14.1 Floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

65

2.14.2 Keeping oats in their place

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

66

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

66

2.14.4 Lists of gures and tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

66

2.14.5 Labels and cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

67

2.14.6 Wrapping text around gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

67

2.14.7 Suboats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

67

2.14.8 Wide gures in two column documents . . . . . . . . . . . . . . . . . . . . . . . . . . . .

68

2.14.9 Custom oats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

68

2.14.10 Labels in the gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.14.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.14.12 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.15 LaTeX/Hyperlinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.15.1 Hyperref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

69

2.15.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

70

2.15.3 Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

70

2.15.4 Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

71

2.15.5 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

72

2.16 LaTeX/Labels and Cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

72

2.16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

72

2.16.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

73

2.16.3 The varioref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

74

2.16.4 The hyperref package

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

75

2.16.5 The cleveref package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

75

2.16.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

75

2.16.7 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

75

2.14.3 Captions

Mechanics

76

3.1

LaTeX/Errors and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

3.1.1

Error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

3.1.2

Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

3.1.3

Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

3.1.4

Software that can check your .tex Code

. . . . . . . . . . . . . . . . . . . . . . . . . . .

78

LaTeX/Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

3.2.1

Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

3.2.2

Box lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

3.2.3

Length manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

3.2.4

LaTeX default lengths

79

3.2

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

vi

CONTENTS

3.3

3.4

3.5

3.2.5

Fixed-length spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

79

3.2.6

Rubber/Stretching lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

79

3.2.7

Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.2.8

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.2.9

See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

LaTeX/Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.3.1

Counter manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.3.2

Counter access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.3.3

Counter style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.3.4

LaTeX default counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

3.3.5

Book with parts, sections, but no chapters . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.3.6

Custom enumerate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.3.7

Custom sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

LaTeX/Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.4.1

TeX character boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.4.2

makebox and mbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.4.3

framebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.4.4

framed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

3.4.5

raisebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.6

minipage and parbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.7

savebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.8

rotatebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.9

colorbox and fcolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.10 resizebox and scalebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.4.11 fancybox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

LaTeX/Rules and Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.5.1

Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.5.2

Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

3.5.3

Stretched rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

83

Technical Texts

84

4.1

LaTeX/Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

84

4.1.1

Mathematics environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

84

4.1.2

Symbols

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

4.1.3

Greek letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

4.1.4

Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

4.1.5

Powers and indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

4.1.6

Fractions and Binomials

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

4.1.7

Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

86

4.1.8

Sums and integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

86

4.1.9

Brackets, braces and delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

86

4.1.10 Matrices and arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

87

CONTENTS

4.2

4.3

4.4

vii

4.1.11 Adding text to equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

87

4.1.12 Formatting mathematics symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

87

4.1.13 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

88

4.1.14 Plus and minus signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

88

4.1.15 Controlling horizontal spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

88

4.1.16 Advanced Mathematics: AMS Math package . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.17 List of Mathematical Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.18 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.19 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.20 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

89

4.1.21 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

89

LaTeX/Advanced Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

90

4.2.1

Equation numbering

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

90

4.2.2

Vertically aligning displayed mathematics . . . . . . . . . . . . . . . . . . . . . . . . . .

90

4.2.3

Indented Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

91

4.2.4

Page breaks in math environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

91

4.2.5

Boxed Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

91

4.2.6

Custom operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

92

4.2.7

Advanced formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

92

4.2.8

Text in aligned math display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

92

4.2.9

Changing font size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

92

4.2.10 Forcing \displaystyle for all math in a document . . . . . . . . . . . . . . . . . . . . . . .

93

4.2.11 Adjusting vertical whitespace around displayed math

. . . . . . . . . . . . . . . . . . . .

93

4.2.12 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93

LaTeX/Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93

4.3.1

Basic theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93

4.3.2

Theorem counters

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93

4.3.3

Proofs

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93

4.3.4

Theorem styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

94

4.3.5

Conicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

94

4.3.6

Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

94

4.3.7

External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

94

LaTeX/Chemical Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

94

4.4.1

Basic Usage

95

4.4.2

Skeletal Diagrams

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95

4.4.3

Rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95

4.4.4

Lewis Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95

4.4.5

Ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95

4.4.6

Resonance Structures and Formal Charges . . . . . . . . . . . . . . . . . . . . . . . . . .

95

4.4.7

Chemical Reactions

95

4.4.8

Naming Chemical Graphics

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

95

viii

CONTENTS
4.4.9

4.5

4.6

4.7

Advanced Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

96

4.4.10 mhchem Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

96

4.4.11 XyMTeX package

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

96

LaTeX/Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

96

4.5.1

Typesetting using the algorithmic package . . . . . . . . . . . . . . . . . . . . . . . . . .

97

4.5.2

Typesetting using the algorithm2e package . . . . . . . . . . . . . . . . . . . . . . . . . .

97

4.5.3

Typesetting using the algorithmicx package . . . . . . . . . . . . . . . . . . . . . . . . . .

97

4.5.4

The algorithm environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

98

4.5.5

Typesetting using the program package . . . . . . . . . . . . . . . . . . . . . . . . . . . .

99

4.5.6

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

LaTeX/Source Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100


4.6.1

Using the listings package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

4.6.2

The minted package

4.6.3

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

LaTeX/Linguistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.7.1

Enumerated examples

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

4.7.2

Syntactic trees

4.7.3

Glosses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

4.7.4

IPA characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

4.7.5

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

4.7.6

External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

Special Pages
5.1

5.2

5.3

LaTeX/Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.1.1

Using makeidx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

5.1.2

Abbreviation list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

5.1.3

Multiple indices

5.1.4

Adding index to table of contents

5.1.5

International indices

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

LaTeX/Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.2.1

Jump start

5.2.2

Using glossaries

5.2.3

Dening glossary entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

5.2.4

Dening terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

5.2.5

Using dened terms

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Displaying the Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112


5.3.1

5.4

108

Building your document

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Example for use in windows with Texmaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113


5.4.1

Compile glossary with xindy - In Windows with Texmaker . . . . . . . . . . . . . . . . . . 113

5.4.2

Document preamble

5.4.3

Glossary denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

5.4.4

Include glossary denitions and print glossary . . . . . . . . . . . . . . . . . . . . . . . . 113

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

CONTENTS
5.4.5
5.5

5.6

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

LaTeX/Bibliography Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114


5.5.1

Embedded system

5.5.2

Citations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

5.5.3

BibTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

5.5.4

Bibliography in the table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

5.5.5

biblatex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

5.5.6

Multiple bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

5.5.7

Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

6.2

6.3

6.4

5.6.1

The example data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

5.6.2

The limits of BibTeX styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

5.6.3

Natbib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

5.6.4

Citation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

6.1.1

The letter class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

6.1.2

Envelopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

6.1.3

Windowed envelopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

6.1.4

Reference: [Link] commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

6.1.5

Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

LaTeX/Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
6.2.1

The Beamer package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

6.2.2

The powerdot package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

6.2.3

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

6.2.4

Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

LaTeX/Teachers Corner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135


6.3.1

Intro

6.3.2

The exam class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

6.3.3

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

LaTeX/Curriculum Vitae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135


6.4.1

curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

6.4.2

europecv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

6.4.3

moderncv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

6.4.4

Multilingual support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

6.4.5

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
137

LaTeX/Introducing Procedural Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137


7.1.1

7.2

128

LaTeX/Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Creating Graphics
7.1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

LaTeX/More Bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

Special Documents
6.1

ix

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

LaTeX/MetaPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

CONTENTS
7.3

LaTeX/Picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
7.3.1

Basic commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

7.3.2

Line segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

7.3.3

Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

7.3.4

Circles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

7.3.5

Text and formulae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3.6

\multiput and \linethickness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3.7

Ovals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3.8

Multiple use of predened picture boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3.9

Quadratic Bzier curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3.10 Catenary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139


7.3.11 Plotting graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
7.3.12 The picture environment and gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
7.4

7.5

LaTeX/PGF/TikZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
7.4.1

Loading Package, Libraries - tikzpicture environment . . . . . . . . . . . . . . . . . . . . 140

7.4.2

Specifying Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

7.4.3

Syntax for Paths

7.4.4

Nodes

7.4.5

Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

LaTeX/PSTricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
7.5.1

The pspicture environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

7.5.2

Fundamental objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

7.5.3

Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

7.5.4

Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

7.5.5

Generic parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

7.5.6

Object location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

7.5.7

The PDFTricks extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

7.6

LaTeX/Xy-pic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

7.7

LaTeX/Creating 3D graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

Programming
8.1

149

LaTeX/Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.1.1

New commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

8.1.2

New environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.3

declare commands within newenvironment . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.4

Extending the number of arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.5

Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.6

Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.7

Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

8.1.8

Strings

8.1.9

LaTeX Hooks

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

8.1.10 Command-line LaTeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

CONTENTS

xi

8.1.11 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151


8.2

LaTeX/Plain TeX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151


8.2.1

Vocabulary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

8.2.2

Catcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

8.2.3

Plain TeX macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

8.2.4

Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

8.2.5

Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

8.2.6

Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

8.2.7

Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

8.2.8

Doing nothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

8.2.9

TeX characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

8.2.10 Verbatim lines and spaces

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

8.2.11 Macros dening macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155


8.2.12 Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
8.3

8.4

LaTeX/Creating Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155


8.3.1

makeatletter and makeatother

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

8.3.2

Creating your own package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

8.3.3

Creating your own class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

8.3.4

Hooks

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

LaTeX/Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.4.1

Introduction

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

8.4.2

Package conguration

8.4.3

Header and footer

8.4.4

Table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

8.4.5

Sectioning

8.4.6

Notes and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

Miscellaneous
9.1

9.2

158

LaTeX/Modular Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158


9.1.1

Project structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

9.1.2

Getting LaTeX to process multiple les

9.1.3

The le [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

9.1.4

The main document [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

9.1.5

External Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

. . . . . . . . . . . . . . . . . . . . . . . . . . . 158

LaTeX/Collaborative Writing of LaTeX Documents . . . . . . . . . . . . . . . . . . . . . . . . . 162


9.2.1

Abstract

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

9.2.2

Introduction

9.2.3

Interchanging Documents

9.2.4

The Version Control System Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

9.2.5

Hosting LaTeX les in Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

9.2.6

Subversion really makes the dierence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

9.2.7

Managing collaborative bibliographies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

xii

CONTENTS
9.2.8

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

9.2.9

Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

9.2.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168


9.3

LaTeX/Export To Other Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168


9.3.1

Tools installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

9.3.2

Preview mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

9.3.3

Convert to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

9.3.4

Convert to PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

9.3.5

Convert to RTF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

9.3.6

Convert to HTML

9.3.7

Convert to image formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

9.3.8

Convert to plain text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

10 Help and Recommendations

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

172

10.1 LaTeX/FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172


10.1.1 Margins are too wide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
10.1.2 Avoid excessive double line breaks in source code . . . . . . . . . . . . . . . . . . . . . . 172
10.1.3 Simplied special character input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
10.1.4 Writing the euro symbol directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
10.1.5 LaTeX paragraph headings have title and content on the same line . . . . . . . . . . . . . . 172
10.1.6 Fonts are ugly/jagged/bitmaps or PDF search fails or Copy/paste from PDF is messy . . . . . 172
10.1.7 Manual formatting: use of line breaks and page breaks . . . . . . . . . . . . . . . . . . . . 172
10.1.8 Always nish commands with {} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.9 Avoid bold and underline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.10 The proper way to use gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.11 Text stops justifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.12 Rules of punctuation and spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.13 Compilation fails after a Babel language change . . . . . . . . . . . . . . . . . . . . . . . 173
10.1.14 Learning LaTeX quickly or correctly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.15 Non-breaking spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.16 Smart mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.17 Use vector graphics rather than raster images . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.18 Stretching tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.19 Tables are easier than you think . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.1.20 Relieving cumbersome code (lists and long command names) . . . . . . . . . . . . . . . . 174
10.1.21 Reducing the size of your LaTeX installation . . . . . . . . . . . . . . . . . . . . . . . . . 174
10.2 LaTeX/Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.2.1 Always writing LaTeX in roman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.2.2 id est and exempli gratia (i.e. and e.g.) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.2.3 Grouping Figure/Equation Numbering by Section . . . . . . . . . . . . . . . . . . . . . . 175
10.2.4 Generic header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.2.5 Graphics and Graph editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

CONTENTS

xiii

10.2.6 Spell-checking and Word Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177


10.2.7 New even page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2.8 Sidebar with information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10.2.9 Hide auxiliary les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
11 Appendix

179

11.1 LaTeX/Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179


11.1.1 Included books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.1.2 Wiki users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.2 LaTeX/Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
11.3 LaTeX/Package Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
11.4 LaTeX/Sample LaTeX documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.1 General examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.4.2 Semantics of Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5 LaTeX/Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.1 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.2 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.3 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.4 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.5 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
11.5.6 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.7 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.8 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.9 I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.10 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.11 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.12 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.13 Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.14 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
11.5.15 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.16 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.17 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.18 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.19 W . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.5.20 X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6 LaTeX/Command Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6.1 #

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

11.6.2 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
11.6.3 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.4 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.5 D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.6 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

xiv

CONTENTS
11.6.7 F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.8 G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.9 H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.6.10 I

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

11.6.11 K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.12 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.13 M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.14 N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.6.15 O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.16 P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.17 R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.18 S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.6.19 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.20 U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
11.6.21 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
12 Text and image sources, contributors, and licenses

188

12.1 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188


12.2 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
12.3 Content license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

Chapter 1

Getting Started
1.1 LaTeX/Introduction

ages is called LaTeX.

1.1.1

1.1.2 What is LaTeX?

What is TeX?

LaTeX (pronounced either Lah-tech or Lay-tech) is


a macro package based on TeX created by Leslie Lamport. Its purpose is to simplify TeX typesetting, especially for documents containing mathematical formulae.
Within the typesetting system, its name is formatted as
LaTeX.

TeX is a low-level markup and programming language


created by Donald Knuth to typeset documents attractively and consistently. Knuth started writing the TeX
typesetting engine in 1977 to explore the potential of
the digital printing equipment that was beginning to inltrate the publishing industry at that time, especially in
the hope that he could reverse the trend of deteriorating typographical quality that he saw aecting his own
books and articles. With the release of 8-bit character
support in 1989, TeX development has been essentially
frozen with only bug xes released periodically. TeX is
a programming language in the sense that it supports the
if-else construct: you can make calculations with it (that
are performed while compiling the document), etc., but
you would nd it very hard to do anything else but typesetting with it. The ne control TeX oers over document structure and formatting makes it a powerfuland
formidabletool. TeX is renowned for being extremely
stable, for running on many dierent kinds of computers, and for being virtually bug free. The version numbers
of TeX are converging toward , with a current version
number of 3.1415926.

Many later authors have contributed extensions, called


packages or styles, to LaTeX. Some of these are bundled
with most TeX/LaTeX software distributions; more can
be found in the Comprehensive TeX Archive Network
(CTAN).
Since LaTeX comprises a group of TeX commands, LaTeX document processing is essentially programming.
You create a text le in LaTeX markup, which LaTeX
reads to produce the nal document.
This approach has some disadvantages in comparison
with a WYSIWYG (What You See Is What You Get) program such as [Link] Writer or Microsoft Word.
In LaTeX:
You don't (usually) see the nal version of the document when editing it.

The name TeX is intended by its developer to be /'tx/,


with the nal consonant of loch or Bach. (Donald E.
Knuth, The TeXbook) The letters of the name are meant
to represent the capital Greek letters tau, epsilon, and chi,
as TeX is an abbreviation of ( techn),
Greek for both art and craft, which is also the root
word of technical. English speakers often pronounce it
/'tk/, like the rst syllable of technical.

You generally need to know the necessary commands for LaTeX markup.
It can sometimes be dicult to obtain a certain look
for the document.

On the other hand, there are certain advantages to the LaProgramming in TeX generally progresses along a very TeX approach:
gradual learning curve, requiring a signicant investment
of time to build custom macros for text formatting. Fortu Document sources can be read with any text edinately, document preparation systems based on TeX, contor and understood, unlike the complex binary and
sisting of collections of pre-built macros, do exist. These
XML formats used with WYSIWYG programs.
pre-built macros are time saving, and automate certain
You can concentrate purely on the structure and conrepetitive tasks and help reduce user introduced errors;
tents of the document, not get caught up with superhowever, this convenience comes at the cost of complete
cial layout issues.
design exibility. One of the most popular macro pack1

CHAPTER 1. GETTING STARTED


You don't need to manually adjust fonts, text sizes, problem before may have published their solution as a
line heights, or text ow for readability, as LaTeX package.
takes care of them automatically.
CTAN is a good place to nd many resources regarding
In LaTeX the document structure is visible to the TeX and derivative packages. It is the rst place where
user, and can be easily copied to another document. you should begin searching.
In WYSIWYG applications it is often not obvious
how a certain formatting was produced, and it might Questions and documentation
be impossible to copy it directly for use in another
document.
Besides internet resources being plentiful, the best doc The layout, fonts, tables and so on are consistent umentation source remains the ocial manual for every
specic package, and the reference documentation, i.e.,
throughout the document.
the TeXbook by D. Knuth and LaTeX: A document prepa Mathematical formulae can be easily typeset.
ration system by L. Lamport.
Indexes, footnotes, citations and references are gen- Therefore before rushing on your favorite web search engine, we really urge you to have a look at the package
erated easily.
documentation that causes troubles. This ocial docu Since the document source is plain text, tables, g- mentation is most commonly installed along your TeX
ures, equations, etc. can be generated programmat- distribution, or may be found on CTAN.
ically with any language.
You are forced to structure your documents cor- 1.1.4
rectly.

Terms regarding TeX

Document preparation systems


The LaTeX-like approach can be called WYSIWYM, i.e.
What You See Is What You Mean: you can't see what the LaTeX is a document preparation system based on TeX.
nal version will look like while typing. Instead you see So the system is the combination of the language and the
the logical structure of the document. LaTeX takes care macros.
of the formatting for you.
The LaTeX document is a plain text le containing the
content of the document, with additional markup. When
the source le is processed by the macro package, it can
produce documents in several formats. LaTeX natively
supports DVI and PDF, but by using other software you
can easily create PostScript, PNG, JPEG, etc.

1.1.3

Philosophy of use

Flexibility and modularity


One of the most frustrating things beginners and even advanced users might encounter using LaTeX is the lack of
exibility regarding the document design and layout. If
you want to design your document in a very specic way,
you may have trouble accomplishing this. Keep in mind
that LaTeX does the formatting for you, and mostly the
right way. If it is not exactly what you desired, then the
LaTeX way is at least not worse, if not better. One way to
look at it is that LaTeX is a bundle of macros for TeX that
aims to carry out everything regarding document formatting, so that the writer only needs to care about content.
If you really want exibility, use plain TeX instead.

Distributions
TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable
you to typeset without having to manually fetch les and
congure things.
Engines
An engine is an executable that can turn your source code
into a printable output format. The engine by itself only
handles the syntax, it also needs to load fonts and macros
to fully understand the source code and generate output
properly. The engine will determine what kind of source
code it can read, and what format it can output (usually
DVI or PDF).

All in all, distributions are an easy way to install what you


need to use the engines and the systems you want. Distributions usually target specic operating systems. You
can use dierent systems on dierent engines, but sometimes there are restrictions. Code written for TeX, LaTeX or ConTeXt are (mostly) not compatible. Additionally, engine-specic code (like font for XeTeX) may not
One solution to this dilemma is to make use of the mod- be compiled by every engine.
ular possibilities of LaTeX. You can build your own When searching for information on LaTeX, you might
macros, or use macros developed by others. You are also stumble upon XeTeX, ConTeXt, LuaTeX or other
likely not the rst person to face some particular format- names with a -TeX sux. Lets recap most of the terms
ting problem, and someone who encountered a similar in this table.

1.2. LATEX/INSTALLATION

1.1.5

What next?

3
things. LaTeX is just a set of macro packages built for
TeX.

In the next chapter we will proceed to the installation. The recommended distributions for each of the major opThen we will compile our rst LaTeX le.
erating systems are:
Throughout this book you should also utilise other means
for learning about LaTeX. Good sources are:
TeX Live is a major TeX distribution for *BSD,
GNU/Linux, Mac OS X and Windows.
the #latex IRC channel on Freenode,
the TeX Stack Exchange Q&A,
the TeX FAQ,
and the [Link] Community.

1.2 LaTeX/Installation
If this is the rst time you are trying out LaTeX, you don't
even need to install anything. For quick testing purpose
you may just create a user account with an online LaTeX editor and continue this tutorial in the next chapter. These websites oer collaboration capabilities while
allowing you to experiment with LaTeX syntax without
having to bother with installing and conguring a distribution and an editor. When you later feel that you would
benet from having a standalone LaTeX installation, you
can return to this chapter and follow the instructions below.

MiKTeX is a Windows-specic distribution.


MacTeX is a Mac OS-specic distribution based on
TeX Live.
These, however, do not necessarily include an editor. You
might be interested in other programs that are not part
of the distribution, which will help you in writing and
preparing TeX and LaTeX les.
*BSD and GNU/Linux
In the past, the most common distribution used to be
teTeX. As of May 2006 teTeX is no longer actively maintained and its former maintainer Thomas Esser recommended TeX Live as the replacement.[1]

The easy way to get TeX Live is to use the package manager or portage tree coming with your operating system.
Usually it comes as several packages, with some of them
being essential, other optional. The core TeX Live packLaTeX is not a program by itself; it is a language. Using ages should be around 200-300 MB.
LaTeX requires a bunch of tools. Acquiring them man- If your *BSD or GNU/Linux distribution does not have
ually would result in downloading and installing multiple the TeX Live packages, you should report a wish to
programs in order to have a suitable computer system that the bug tracking system. In that case you will need to
can be used to create LaTeX output, such as PDFs. TeX download TeX Live yourself and run the installer by hand.
Distributions help the user in this way, in that it is a sinYou may wish to install the content of TeX Live more
gle step installation process that provides (almost) everyselectively. See below.
thing.
At a minimum, you'll need a TeX distribution, a good
text editor and a DVI or PDF viewer. More specically,
the basic requirement is to have a TeX compiler (which is
used to generate output les from source), fonts, and the
LaTeX macro set. Optional, and recommended installations include an attractive editor to write LaTeX source
documents (this is probably where you will spend most of
your time), and a bibliographic management program to
manage references if you use them a lot.

1.2.1

Distributions

TeX and LaTeX are available for most computer platforms, since they were programmed to be very portable.
They are most commonly installed using a distribution,
such as teTeX, MiKTeX, or MacTeX. TeX distributions are collections of packages and programs (compilers, fonts, and macro packages) that enable you to typeset without having to manually fetch les and congure

Mac OS X
Mac OS X users may use MacTeX, a TeX Live-based distribution supporting TeX, LaTeX, AMSTeX, ConTeXt,
XeTeX and many other core packages. Download [Link] on the MacTeX page, unzip it and follow
the instructions. Further information for Mac OS X users
can be found on the TeX on Mac OS X Wiki.
Since Mac OS X is also a Unix-based system, TeX Live is
naturally available through MacPorts and Fink. Further
information for Mac OS X users can be found on the TeX
on Mac OS X Wiki.
Microsoft Windows
Microsoft Windows users can install MiKTeX onto their
computer. It has an easy installer that takes care of setting
up the environment and downloading core packages. This

CHAPTER 1. GETTING STARTED

distribution has advanced features, such as automatic installation of packages, and simple interfaces to modify
settings, such as default paper sizes.

3. Change the umask to 022 to make sure other users


will have read-only access to the installed distribution.

There is also a port of TeX Live available for Windows.


# umask 022

1.2.2

Custom installation with TeX Live

This section targets users who want ne-grained control


over their TeX distribution, like an installation with a
minimum of disk space usage. If it is none of your concern, you may want to jump to the next section.
Picky users may wish to have more control over their installation. Common distributions might be tedious for the
user caring about disk space. In fact, MikTeX and MacTeX and packaged TeX Live features hundreds of LaTeX
packages, most of them which you will never use. Most
Unix with a package manager will oer TeX Live as a
set of several big packages, and you often have to install
300400 MB for a functional system.
TeX Live features a manual installation with a lot of possible customizations. You can get the network installer at
[Link]. This installer allows you to select precisely the
packages you want to install. As a result, you may have
everything you need for less than 100 MB. TeX Live is
then managed through its own package manager, tlmgr. It
will let you congure the distributions, install or remove
extra packages and so on.
You will need a Unix-based operating system for the following. Mac OS X, GNU/Linux or *BSD are ne. It may
work for Windows but the process must be quite dierent.
TeX Live groups features and packages into dierent
concepts:
Collections are groups of packages that can always be
installed individually, except for the Essential programs and les collection. You can install collections at any time.
Installation Schemes group collections and packages.
Schemes can only be used at installation time. You
can select only one scheme at a time.
Minimal installation

1. Launch install-tl.
2. Select the minimal scheme (plain only).
3. You may want to change the directory options. For
example you may want to hide your personal macro
folder which is located at TEXMFHOME. It is
~/texmf by default. Replace it by ~/.texmf to hide
it.
4. Now the options:
(a) use letter size instead of A4 by default:
mostly for users from the USA.
(b) execution of restricted list of programs: it
is recommended to select it for security reasons. Otherwise it allows the TeX engines to
call any external program. You may still congure the list afterwards.
(c) create format les: targetting a minimal disk
space, the best choice depends on whether
there is only one user on the system, then deselecting it is better, otherwise select it. From
the help menu: If this option is set, format
les are created for system-wide use by the installer. Otherwise they will be created automatically when needed. In the latter case format les are stored in users directory trees and
in some cases have to be re-created when new
packages are installed.
(d) install font/macro doc tree: useful if you are
a developer, but very space consuming. Turn
it o if you want to save space.
(e) install font/macro source tree: same as
above.
(f) Symlinks are ne by default, change it if you
know what you are doing.
5. Select portable installation if you install the distribution to an optical disc, or any kind of external media.
Leave to default for a traditional installation on the
system hard drive.

We will give you general guidelines to install a minimal


At this point it should display
TeX distribution (i.e., only for plain TeX).
1 collections out of 85, disk space required: 40 MB
1. Download the installer at [Link] or a similar space usage.
systems/texlive/tlnet/[Link] and exYou can now proceed to installation: start installation to
tract it to a temporary folder.
hard disk.
2. Open a terminal in the extracted folder and log in as
root.

Don't forget to add the binaries to your PATH as its noticed at the end of the installation procedure.

1.2. LATEX/INSTALLATION

First test

Note that if you have been using another TeX distribution


beforehand, you may still have hyphenation cache stored
In a terminal write
in you home folder. You need to remove it so that the new
$ tex '\empty Hello world!\bye' $ pdftex '\empty Hello packages are taken into account. The TeX Live cache
is usually stored in the ~/.texliveYYYY folder (YYYY
world!\bye'
stands for the year). You may safely remove this folder
You should get a DVI or a PDF le accordingly.
as it contains only generated data. TeX compilers will
re-generate the cache accordingly on next compilation.
Conguration
Uninstallation
Formerly, TeX distributions used to be congured with
the texcong tool from the teTeX distribution. TeX Live
still features this tool, but recommends using its own tool
instead: tlmgr. Note that as of January 2013 not all texcong features are implemented by tlmgr. Only use texcong when you cannot do what you want with tlmgr.

By default TeX Live will install in /usr/local/texlive. The


distribution is quite proper as it will not write any le outside its folder, except for the cache (like font cache, hyphenation patters, etc.). By default,

List current installation options:

the system cache goes in /var/lib/texmf;

tlmgr option

the user cache goes in ~/.texliveYYYY.

You can change the install options:

Therefore TeX Live can be installed and uninstalled safely


tlmgr option src 1 tlmgr option doc 0 tlmgr option paper by removing the aforementioned folders.
letter
Still, TeX Live provides a more convenient way to do this:
See the TLMGR(1) man page for more details on its usage. If you did not install the documents as told previ- # tlmgr uninstall
ously, you can still access the tlmgr man page with
You may still have to wipe out the folders if you put untracked les in them.
tlmgr help
Installing LaTeX

1.2.3 Editors

Now we have a running plainTeX environment, lets in- TeX and LaTeX source documents (as well as related
les) are all text les, and can be opened and modied
stall the base packages for LaTeX.
in almost any text editor. You should use a text editor
# tlmgr install latex latex-bin latexcong latex-fonts
(e.g. Notepad), not a word processor (Word, OpenOfIn this case you can omit latexcong latex-fonts as they ce). Dedicated LaTeX editors are more useful than
are auto-resolved dependencies to LaTeX. Note that generic plain text editors, because they usually have autlmgr resolves some dependencies, but not all. It may tocompletion of commands, spell and error checking and
happen to install dependencies manually. Thankfully this handy macros.
is rarely too cumbersome.
Other interesting packages:

Cross-platform

# tlmgr install amsmath babel carlisle ec geometry graphics hyperref lm marvosym oberdiek parskip pdftex-def BaKoMa TeX BaKoMa TeX is an editor for Windows
and Mac OS with WYSIWYG-like features. It takes care
url
of compiling the LaTeX source and updating it constantly
If you installed a package you do not need anymore, use to view changes to document almost in real time.
# tlmgr remove <package>
Emacs Emacs is a general purpose, extensible text processing system. Advanced users can program it (in elisp)
Hyphenation
to make Emacs the best LaTeX environment that will t
If you are using Babel for non-English documents, you theirs needs. In turn beginners may prefer using it in comneed to install the hyphenation patterns for every language bination with AUCTeX and Reftex (extensions that may
you are going to use. They are all packaged individually. be installed into the Emacs program). Depending on your
conguration, Emacs can provide a complete LaTeX editFor instance, use
ing environment with auto-completion, spell-checking,
# tlmgr install hyphen-{nnish,sanskrit}
a complete set of keyboard shortcuts, table of contents
for nnish and sanskrit hyphenation patterns.
view, document preview and many other features.

CHAPTER 1. GETTING STARTED

gedit-latex-plugin
Gedit with gedit-latex-plugin is
also worth trying out for users of GNOME. GEdit is a
cross-platform application for Windows, Mac, and Linux

Screenshot of TeXworks on Ubuntu 12.10.

with the idea that a simple interface is better than a cluttered one, and thus to make it easier for people in their
early days with LaTeX to get to what they want to do:
Screenshot of Gummi.
write their documents. TeXworks originally came about
precisely because a math professor wanted his students to
Gummi Gummi is a LaTeX editor for Linux, which have a better initial experience with LaTeX.
compiles the output of pdatex in realtime and shows it
You can install TeXworks with the package manager of
on the right half of the screen[2] .
your Linux distribution or choose it as an install option in
the Windows or Mac installer.
Vim Vim is another general purpose text editor for a
wide variety of platforms including UNIX, Mac OS X and
Windows. A variety of extensions exist including LaTeX
Box and Vim-LaTeX.
*BSD and GNU/Linux-only

LyX1.6.3

LyX LyX is a popular LaTeX editor for Windows,


Linux and Mac OS. It contains formula and table editors and shows visual clues of the nal document on the
screen enabling users to write LaTeX documents without
worrying about the actual syntax[3] .
Screenshot of Kile.

TeXmaker TeXmaker is a cross-platform editor very


similar to Kile in features and user interface. In addition Kile Kile is a LaTeX editor for KDE (cross platform),
providing a powerful GUI for editing multiple documents
it has its own PDF viewer.
and compiling them with many dierent TeX compilers.
Kile is based on Kate editor, has a quick access toolbar for
TeXstudio TeXstudio is a cross-platform open source symbols, document structure viewer, a console and cusLaTeX editor forked from Texmaker.
tomizable build options. Kile can be run in all operating
systems that can run KDE.
TeXworks TeXworks is a dedicated TeX editor that
is included in MiKTeX and TeX Live. It was developed LaTeXila

LaTeXila is another text editor for Linux

1.2. LATEX/INSTALLATION

(Gnome).

technical documents in collaboration. Authoreas frontend allows you to enter text in LaTeX or Markdown, as
well as gures, and equations (in LaTeX or MathML).
Mac OS X-only
Authorea renders and compiles everything to the web
(HTML5), in addition to PDF (export to numerous jourTeXShop TeXShop is a TeXworks-like editor and pre- nal formats is provided). Authoreas versioning control
viewer for Mac OS that is bundled with the MacTeX dis- system is entirely based on Git (every article is a Git
tribution. It uses multiple windows, one for editing the repository).
source, one for the preview, and one as a console for error messages. It oers one-click updating of the preview
and allows easy crossnding between the code and the 1.2.4 Bibliography management
preview by using CMD-click.
Bibliography les (*.bib) are most easily edited and modied using a management system. These graphical user
TeXnicle TeXnicle is a free editor for Mac OS that in- interfaces all feature a database form, where information
cludes the ability to perform live updates. It includes a is entered for each reference item, and the resulting text
code library for the swift insertion of code and the abil- le can be used directly by BibTeX.
ity to execute detailed word counts on documents. It also
performs code highlighting and the editing window is customisable, permitting the user to select the font, colour, Cross-platform
background colour of the editing environment. It is in
active development.
Archimedes Archimedes is an easy-to-use LaTeX and
Markdown editor designed from the ground up for Mac
OS X. It includes a built-in LaTeX library, code completion support, live previews, macro support, integration with sharing services, and PDF and HTML export
options. Archimedess Magic Type feature lets users insert mathematical symbols just by drawing them on their
MacBooks trackpad or Magic Trackpad.
Windows-only
LEd

LEd

TeXnicCenter TeXnicCenter is a popular free and


open source LaTeX editor for Windows. It also has a
similar user interface to TeXmaker and Kile.

Screenshot of JabRef.

JabRef
Mendeley

WinEdt WinEdt is a powerful and versatile text ed- Mac OS X-only


itor with strong predisposition towards creation of LaTeX/TeX documents for Windows. It has been designed
and congured to integrate with TeX Systems such as MiTeX or TeX Live. Its in-built macro helps in compiling
the LaTeX source to the WYSIWYG-like DVI or PDF or
PS and also in exporting the document to other mark-up
languages as html or XML.
WinShell WinShell
Web-based
Authorea Authorea is not a LaTeX installation per se, Screenshot of BibDesk
but an integrated online framework for the creation of

CHAPTER 1. GETTING STARTED


BibDesk is a bibliography manager based on a BibTeX le. It imports references from the internet and
makes it easy to organize references using tags and
categories[4] .

1.2.5

Viewers

style with the rest of your document (font, size, etc.).


Some tools have the capability to export to LaTeX, which
will partially solve this issue. See Importing Graphics for
more details.

1.2.7 Online solutions

Finally, you will need a viewer for the les LaTeX out- To get started without needing to install anything, you can
puts. Normally LaTeX saves the nal document as a .dvi use a web-hosted service featuring a full TeX distribution
(Device independent le format), but you will rarely want and a web LaTeX editor.
it to. DVI les do not contain embedded fonts and many
document viewers are unable to open them.
Google Documents or LaTeX Lab allows real-time
simultaneous collaborative editing of text les for
Usually you will use a LaTeX compiler like pdatex to
anyone with a Google account (and its option to
produce a PDF le directly, or a tool like dvi2pdf to conmake the document available through a URL makes
vert the DVI le to PDF format. Then you can view the
local download and compilation easily scriptable).
result with any PDF viewer.
Practically all LaTeX distributions have a DVI viewer for
viewing the default output of latex, and also tools such
as dvi2pdf for converting the result automatically to PDF
and PS formats.

LIMSUP is an online LaTeX editor allowing


real time collaboration of LaTeX documents
(announcement)

Here follows a list of various PDF viewers.

Monkey TeX is free and allows team sharing.

Adobe Reader
epdfview
Evince
Foxit
Okular
Sumatra
Zathura

1.2.6

Tables and graphics tools

LaTeX is a document preparation system, it does not aim


at being a spreadsheet tool nor a vector graphics tool.
If LaTeX can render beautiful tables in a dynamic and
exible manner, it will not handle the handy features you
could get with a spreadsheet like dynamic cells and calculus. Other tools are better at that. The ideal solution is to
combine the strength of both tools: build your dynamic
table with a spreadsheet, and export it to LaTeX to get
a beautiful table seamlessly integrated to your document.
See Tables for more details.
The graphics topic is a bit dierent since it is possible
to write procedural graphics from within your LaTeX
document. Procedural graphics produce state-of-the-art
results that integrates perfectly to LaTeX (e.g. no font
change), but have a steep learning curve and require a lot
of time to draw.
For easier and quicker drawings, you may want to use a
WYSIWYG tool and export the result to a vector format like PDF. The drawback is that it will contrast in

[Link] is a real-time collaborative LaTeX


editor.
[Link] is one of the most mature systems
available, with git push and pull access it allows for
powerful version control. The new sign ups are now
directed to use [Link] however accounts
are still available upon request.
[Link] is a secure cloud based LaTeX editor oering unlimited free project. Premium accounts are available for extra features such as version
control and Dropbox integration.
SpanDeX is a cloud-based LaTeX collaboration
platform designed to make collaborating with LaTeX seamless and to reduce the learning curve to
LaTeX. It oers simultaneous real-time editing and
collaboration, live document preview, Dropbox integration, and a built-in LaTeX resource system.
Verbosus is a professional Online LaTeX Editor that
supports collaboration with other users and is free to
use. Merge conicts can easily resolved by using a
built-in merge tool that uses an implementation of
the di-algorithm to generate information required
for a successful merge.
[Link] is a secure, easy to use online
LaTeX editor with integrated rapid preview - like
EtherPad for LaTeX. Start writing with one click
(no signup required) and share the link. It supports
real time preview, gures, bibliographies and custom styles.

1.3. LATEX/INSTALLING EXTRA PACKAGES

1.2.8

References

[1] teTeX Home Page (Retrieved January 31, 2007)


[2] Gummi
[3] LyX
[4] BibDesk

1.3 LaTeX/Installing Extra Packages


Add-on features for LaTeX are known as packages.
Dozens of these are pre-installed with LaTeX and can
be used in your documents immediately. They should
all be stored in subdirectories of texmf/tex/latex named
after each package. The directory name texmf stands
for TEX and METAFONT. To nd out what other
packages are available and what they do, you should use
the CTAN search page which includes a link to Graham
Williams comprehensive package catalogue.
A package is a le or collection of les containing extra LaTeX commands and programming which add new
styling features or modify those already existing. There
are two main le types: class les with .cls extension, and
style les with .sty extension. There may be ancillary les
as well. When you try to typeset a document which requires a package which is not installed on your system,
LaTeX will warn you with an error message that it is missing. You can download updates to packages you already
have (both the ones that were installed along with your
version of LaTeX as well as ones you added). There is no
limit to the number of packages you can have installed
on your computer (apart from disk space!), but there is a
congurable limit to the number that can be used inside
any one LaTeX document at the same time, although it
depends on how big each package is. In practice there is
no problem in having even a couple of dozen packages
active.
Most LaTeX installations come with a large set of preinstalled style packages, so you can use the package manager of the TeX distribution or the one on your system to
manage them. See the automatic installation. But many
more are available on the net. The main place to look for
style packages on the Internet is CTAN. Once you have
identied a package you need that is not in your distribution, use the indexes on any CTAN server to nd the
package you need and the directory where it can be downloaded from. See the manual installation.

9
With MikTeX there is a package manager that allows you
to pick the package you want individually. As a convenient feature, upon the compilation of a le requiring noninstalled packages, MikTeX will automatically prompt to
install the missing ones.
With TeX Live, it is common to have the distribution
packed into a few big packages. For example, to install
something related to internationalization, you might have
to install a package like texlive-lang. With TeX Live manually installed, use tlmgr to manage packages individually.
tlmgr install <package1> <package2> ... tlmgr remove
<package1> <package2> ...
The use of tlmgr is covered in the Installation chapter.
If you cannot nd the wanted package with any of the
previous methods, see the manual installation.

1.3.2 Manual installation


Downloading packages
What you need to look for is usually two les, one ending
in .dtx and the other in .ins. The rst is a DOCTeX le,
which combines the package program and its documentation in a single le. The second is the installation routine
(much smaller). You must always download both les. If
the two les are not there, it means one of two things:
Either the package is part of a much larger bundle which you shouldn't normally update unless you
change LaTeXversion of LaTeX;
or its an older or relatively simple package written
by an author who did not use a .dtx le.
Download the package les to a temporary directory.
There will often be a [Link] with a brief description
of the package. You should of course read this le rst.
Installing a package
There are ve steps to installing a LaTeX package.
(These steps can also be used on the pieces of a complicated package you wrote yourself; in this case, skip
straight to Step 3.)

1. Extract the les Run LaTeX on the .ins le. That


is, open the le in your editor and process it as if it were
a LaTeX document (which it is), or if you prefer, type
latex followed by the .ins lename in a command window
in your temporary directory. This will extract all the les
needed from the .dtx le (which is why you must have
1.3.1 Automatic installation
both of them present in the temporary directory). Note
down or print the names of the les created if there are
If on an operating system with a package manager or a a lot of them (read the log le if you want to see their
portage tree, you can often nd packages in repositories. names again).

10

CHAPTER 1. GETTING STARTED

2. Create the documentation Run LaTeX on the .dtx


le. You might need to run it twice or more, to get the
cross-references right (just like any other LaTeX document). This will create a .dvi le of documentation explaining what the package is for and how to use it. If you
prefer to create PDF then run pdfLaTeX instead. If you
created a .idx as well, it means that the document contains
an index, too. If you want the index to be created properly, follow the steps in the indexing section. Sometimes
you will see that a .glo (glossary) le has been produced.
Run the following command instead:
makeindex -s [Link] -o [Link] [Link]
3. Install the les While the documentation is printing,
move or copy the package les from your temporary directory to the right place[s] in your TeX local installation directory tree. Packages installed by hand should always be placed in your local directory tree, not in the
directory tree containing all the pre-installed packages.
This is done to a) prevent your new package accidentally overwriting les in the main TeX directories; and b)
avoid your newly-installed les being overwritten when
you next update your version of TeX.
For a TDS(TeX Directory Structure)-conformant system,
your local installation directory tree is a folder and
its subfolders. The outermost folder should probably be
called texmf-local/ or texmf/. Its location depends on
your system:
MacTeX:
Users/username/Library/texmf/.
Unix-type systems: Usually ~/texmf/.
MikTeX: Your local directory tree can be
any folder you like, as long as you then
register it as a user-managed texmf directory (see [Link]
[Link]#id573803)

4. Update your index Finally, run your TeX indexer


program to update the package database. This program
comes with every modern version of TeX and has various names depending on the LaTeX distribution you use.
(Read the documentation that came with your installation to nd out which it is, or consult [Link]
fonts/[Link]#fndb):
teTeX, TeX Live, fpTeX: texhash
web2c: mktexlsr
MacTeX: MacTeX appears to do this for
you.
MikTeX: initexmf --update-fndb (or use
the GUI)
MiKTeX 2.7 or later versions, installed
on Windows XP through Windows 7:
Start -> All Programs -> MikTex -> Settings. In Windows 8 use the keyword
Settings and choose the option of Settings
with the MiKTex logo. In Settings menu
choose the rst tab and click on Refresh
FNDB-button (MikTex will then check
the Program Files directory and update
the list of File Name DataBase). After
that just verify by clicking 'OK'.
5. Update font maps If your package installed any TrueType or Type 1 fonts, you need to update the font mapping les in addition to updating the index. Your package author should have included a .map le for the fonts.
The map updating program is usually some variant on updmap, depending on your distribution:
TeX Live and MacTeX: updmap --enable
Map=[Link] (if you installed the
les in a personal tree) or updmap-sys
--enable Map=[Link] (if you installed the les in a system directory).

The right place sometimes causes confusion, especially if your TeX installation is old or does not con MikTeX: Run initexmf --edit-cong-le
form to the TeX Directory Structure(TDS). For a TDSupdmap, add the line Map [Link]
conformant system, the right place for a LaTeX .sty
to the le that opens, then run initexmf
le is a suitably-named subdirectory of texmf/tex/latex/.
--mkmaps.
Suitably-named means sensible and meaningful (and
probably short). For a package like paralist, for exam- See [Link]
ple, I'd call the directory texmf/tex/latex/paralist.
The reason this process has not been automated widely
Often there is just a .sty le to move, but in the case of is that there are still thousands of installations which do
complex packages there may be more, and they may be- not conform to the TDS, such as old shared Unix syslong in dierent locations. For example, new BibTeX tems and some Microsoft Windows systems, so there is no
packages or font packages will typically have several les way for an installation program to guess where to put the
to install. This is why it is a good idea to create a sub- les: you have to know this. There are also systems where
directory for the package rather than dump the les into the owner, user, or installer has chosen not to follow the
misc along with other unrelated stu. If there are cong- recommended TDS directory structure, or is unable to
uration or other les, read the documentation to nd out do so for political or security reasons (such as a shared
if there is a special or preferred location to move them to. system where she cannot write to a protected directory).
For most fonts on CTAN, the foundry is public.
The reason for having the texmf-local directory (called

1.4. LATEX/BASICS
[Link] on some systems) is to provide a place for local modications or personal updates, especially if you
are a user on a shared or managed system (Unix, Linux,
VMS, Windows NT/2000/XP, etc.) where you may not
have write-access to the main TeX installation directory
tree. You can also have a personal texmf subdirectory in
your own login directory. Your installation must be congured to look in these directories rst, however, so that
any updates to standard packages will be found there before the superseded copies in the main texmf tree. All
modern TeX installations should do this anyway, but if
not, you can edit texmf/web2c/[Link] yourself.

1.3.3

Checking package status

The universal way to check if a le is available to TeX


compilers is the command-line tool kpsewhich.
$ kpsewhich tikz /usr/local/texlive/2012/texmfdist/tex/plain/pgf/frontendlayer/[Link]

11
documentation with the texdoc command:
texdoc <package-name>

1.3.5 External resources


The best way to look for LaTeX packages is the already
mentioned CTAN: Search. Additional resources form
The TeX Catalogue Online:
Alphabetic catalogue
With brief descriptions
Topical catalogue with packages sorted systematically
Hierarchical mirroring the CTAN folder hierarchy

kpsewhich will actually search for les only, not for pack- 1.3.6 See Also
ages. It returns the path to the le. For more details on a
LaTeX/Package Reference
specic package use the command-line tool tlmgr (TeX
Live only):
tlmgr info <package>

1.4 LaTeX/Basics

The tlmgr tool has lot more options. To consult the documentation:
This tutorial is aimed at getting familiar with the bare
bones of LaTeX.
tlmgr help

1.3.4

Package documentation

To nd out what commands a package provides (and thus


how to use it), you need to read the documentation. In the
texmf/doc subdirectory of your installation there should
be directories full of .dvi les, one for every package installed. This location is distribution-specic, but is typically found in:
Generally, most of the packages are in the latex subdirectory, although other packages (such as BibTeX and
font packages) are found in other subdirectories in doc.
The documentation directories have the same name of
the package (e.g. amsmath), which generally have one
or more relevant documents in a variety of formats (dvi,
txt, pdf, etc.). The documents generally have the same
name as the package, but there are exceptions (for example, the documentation for amsmath is found at latex/amsmath/[Link]). If your installation procedure
has not installed the documentation, the DVI les can
all be downloaded from CTAN. Before using a package,
you should read the documentation carefully, especially
the subsection usually called User Interface, which describes the commands the package makes available. You
cannot just guess and hope it will work: you have to read
it and nd out.

Before starting, ensure you have LaTeX installed on your


computer (see Installation for instructions of what you
will need).
We will rst have a look at the LaTeX syntax.
We will create our rst LaTeX document.
Then we will take you through how to feed this le
through the LaTeX system to produce quality output, such as postscript or PDF.
Finally we will have a look at the le names and
types.

1.4.1 The LaTeX syntax


LaTeX uses a markup language in order to describe document structure and presentation. LaTeX converts your
source text, combined with the markup, into a high quality document. For the purpose of analogy, web pages
work in a similar way: the HTML is used to describe the
document, but it is your browser that presents it in its full
glory - with dierent colours, fonts, sizes, etc.

The input for LaTeX is a plain text le. You can create it
with any text editor. It contains the text of the document,
as well as the commands that tell LaTeX how to typeset
You can usually automatically open any installed package the text.

12

CHAPTER 1. GETTING STARTED

A minimal example looks something like the following LaTeX groups


(the commands will be explained later):
A group is basically dened by a pair of braces. The range
of commands put between braces is limited to them. The
\begingroup and \endgroup commands are equivalent to
Spaces
opening brace and closing brace.
The LaTeX compiler normalises whitespace so that
whitespace characters, such as [space] or [tab], are
treated uniformly as space": several consecutive
spaces are treated as one, space opening a line is generally ignored, and a single line break also yields space.
A double line break (an empty line), however, denes the
end of a paragraph; multiple empty lines are also treated
as the end of a paragraph. An example of applying these
rules is presented below: the left-hand side shows the
users input (.tex), while the right-hand side depicts the
rendered output (.dvi/.pdf/.ps).

Example:
For some commands it is important to restrict their range
of action, and thats where groups come to be very useful.
LaTeX environments
Environments in LaTeX have a role that is quite similar
to commands, but they usually have eect on a wider part
of the document. Their syntax is:

Between the \begin and the \end you can put other commands and nested environments. The internal mechanism
of environments denes a group, which makes its usage
safe (no inuence on the other parts of the document).
Reserved Characters
In general, environments can accept arguments as well,
but this feature is not commonly used and so it will be
The following symbols are reserved characters that either discussed in more advanced parts of the document.
have a special meaning under LaTeX or are unavailable
Anything in LaTeX can be expressed in terms of comin all the fonts. If you enter them directly in your text,
mands and environments.
they will normally not print, but rather make LaTeX do
things you did not intend.
LaTeX commands
#$%^&_{}~\
As you will see, these characters can be used in your doc- LaTeX commands are case sensitive, and take one of the
uments all the same by adding a prex backslash:
following two formats:
The backslash character \ cannot be entered by adding
They start with a backslash \ and then have a name
another backslash in front of it (\\); this sequence is used
consisting of letters only. Command names are terfor line breaking. For introducing a backslash in math
minated by a space, a number or any other nonmode, you can use \backslash instead.
letter.
The commands \~ and \^ produce respectively a tilde and
They consist of a backslash \ and exactly one nona hat which is placed over the next letter. For example
letter.
\~n gives . Thats why you need braces to specify there
is no letter as argument. You can also use \textasciitilde
and \textasciicircum to enter these characters; or other Some commands need an argument, which has to be
given between curly braces { } after the command name.
commands .
Some commands support optional parameters, which are
If you want to insert text that might contain several paradded after the command name in square brackets [ ].
ticular symbols (such as URIs), you can consider using
The general syntax is:
the \verb command, which will be discussed later in the
section on formatting. For source code, see Source Code Most standard LaTeX commands have a switch equivalent. Switches have no arguments but apply on the rest of
Listings
the scope, i.e. the current group or environment. A switch
The 'less than' (<) and 'greater than' (>) characters are the
should (almost) never be called outside of any scope, othonly visible ASCII characters (not reserved) that will not
erwise it will apply on the rest of the document.
print correctly. See Special Characters for an explanation
Example:
and a workaround.
Non-ASCII characters (e.g. accents, diacritics) can be
typed in directly for most cases. However you must congure the document appropriately. The other symbols
and many more can be printed with special commands
in mathematical formulae or as accents. We will tackle
this issue in Special Characters.

Comments
When LaTeX encounters a % character while processing
an input le, it ignores the rest of the current line, the line
break, and all whitespace at the beginning of the next line.

1.4. LATEX/BASICS

13

This can be used to write notes into the input le, which
will not show up in the printed version.

latex executable calls tex with LaTeX initialization


les, reads a LaTeX .tex le and creates a .dvi

Note that the % character can be used to split long input


lines that do not allow whitespace or line breaks, as with
Supercalifragilisticexpialidocious above.

pdatex executable calls pdftex with LaTeX initialization les, reads a LaTeX .tex le and creates a
.pdf

The core LaTeX language does not have a predened syntax for commenting out regions spanning multiple lines. If you compile a Plain TeX document with a LaTeX comRefer to multi-line comments for simple workarounds.
piler (such as pdatex) it will work while the opposite is
not true: if you try to compile a LaTeX source with a TeX
compiler you will get many errors.

1.4.2

Our rst document

As a matter of fact, following your operating system latex


Now we can create our rst document. We will produce and pdatex are simple scripts or symbolic links.
the absolute bare minimum that is needed in order to get Most of the programs should be already within your Lasome output; the well known Hello World! approach will TeX distribution; the others come with w:Ghostscript,
be suitable here.
which is a free and multi-platform software as well. Here
are common programs you expect to nd in any LaTeX
Open your favorite text-editor.
vim, emacs, distribution:
Notepad++, and other text editors will have syntax
highlighting that will help to write your les.
dvi2ps converts the .dvi le to .ps (postscript).
Reproduce the following text in your editor. This is
the LaTeX source.
Save your le as [Link].
When picking a name for your le, make sure it bears a
.tex extension.
What does it all mean?
As we have said before, each of the LaTeX commands begins with a backslash (\). This is LaTeXs way of knowing
that whenever it sees a backslash, to expect some commands. Comments are not classed as a command, since
all they tell LaTeX is to ignore the line. Comments never
aect the output of the document.

1.4.3

Compilation

Compilation process
The general concept is to transform a plain text document
into a publishable format, mosty a DVI, PS or PDF le.
This process is called compilation, which is done by an
executable le called a compiler.
There are two main compilers.

dvi2pdf converts the .dvi le to .pdf (dvi2pdfm is an


improved version).
and with Ghostscript:
ps2pdf and pdf2ps converts the .ps le to .pdf and
vice-versa.
When LaTeX was created, the only format it could create was DVI; later PDF support was added by pdatex.
PDF les can be created with both pdatex and dvipdfm.
The output of pdatex takes direct advantage of modern
features of PDF such as hyperlinks and embedded fonts,
which are not part of DVI. Passing through DVI imposes
limitations of its older format. On the other hand, some
packages, such as PSTricks, exploit the process of conversion to DVI, and therefore will not work with pdatex. Some of those packages embed information in the
DVI that doesn't appear when the DVI is viewed, but
reemerges when the DVI is converted to another, newer
format.
You would write your document slightly dierently depending on the compiler you are using (latex or pdatex).
But as we will see later it is possible to add a sort of abstraction layer to hide the details of which compiler you're
using, while the compiler can handle the translation itself.

The following diagram shows the relationships between


tex compiler reads a TeX .tex le and creates a .dvi. the LaTeX source code and the formats you can create
pdftex compiler reads a TeX .tex le and creates a from it:
.pdf.

The boxed red text represents the le formats, the blue


text on the arrows represents the commands you have to
These compilers are basically used to compile Plain TeX, use, the small dark green text under the boxes represents
not LaTeX. There is no such LaTeX compiler since La- the image formats that are supported. Any time you pass
TeX is just a bunch of macros for TeX. However, there through an arrow you lose some information, which might
are two executables related to the previous compilers:
decrease the features of your document. Therefore, you

14

CHAPTER 1. GETTING STARTED

pdftex

on Windows you can use a program called yap (yet another previewer). (Now evince and okular, the standard
document viewers for many Linux distributions are able
to view DVI les.)

tex

pdatex

This way you created the DVI le, but with the same
source le you can create a PDF document. The steps
are exactly the same as before, but you have to replace
the command latex with pdatex:

latex

Source formats

Output formats

PDF
(pdf,
png,
jpg)

ps2pdf
pdf2ps

PostScript

dvi2ps

DVI
(eps)

dvipdfm

should choose the shortest route to reach your target format. This is probably the most convenient way to obtain
an output in your desired format anyway. Starting from
a LaTeX source, the best way is to use only latex for a
DVI output or pdatex for a PDF output, converting to
PostScript only when it is necessary to print the document.

1. Type the command: pdatex hello (as before, the


.tex extension is not required)
2. Various bits of info about LaTeX and its progress
will be displayed. If all went well, the last two lines
displayed in the console will be:
Output written on [Link] (1 page, 5548 bytes). Transcript written on [Link].

you can notice that the PDF document is bigger than the
DVI, even if it contains exactly the same information.
The main dierences between the DVI and PDF formats
Chapter Export To Other Formats discusses more about are:
exporting LaTeX source to other le formats.
DVI needs less disk space and it is faster to create.
It does not include the fonts within the document, so
Generating the document
if you want the document to be viewed properly on
another computer, there must be all the necessary
It is clearly not going to be the most exciting document
fonts installed. It does not support any interactivity
you have ever seen, but we want to see it nonetheless. I
such as hyperlinks or animated images. DVI viewers
am assuming that you are at a command prompt, already
are not very common, so you can consider using it
in the directory where [Link] is stored. LaTeX itself
for previewing your document while typesetting.
does not have a GUI (graphical user interface), since it
is just a program that crunches away at your input les,
PDF needs more disk space and it is slower to creand produces either a DVI or PDF le. Some LaTeX
ate, but it includes all the necessary fonts within
installations feature a graphical front-end where you can
the document, so you will not have any problem of
click LaTeX into compiling your input le. On other sysportability. It supports internal and external hypertems there might be some typing involved, so here is how
links. It also supports advanced typographic feato coax LaTeX into compiling your input le on a text
tures: hanging punctuation, font expansion and marbased system. Please note: this description assumes that
gin kerning resulting in more exibility available to
you already have a working LaTeX installation on your
the TeX engine and better looking output. Nowacomputer.
days it is the de facto standard for sharing and publishing documents, so you can consider using it for
the nal version of your document.
1. Type the command: latex hello (the .tex extension
is not required, although you can include it if you
wish)
About now, you saw you can create both DVI and PDF
document from the same source. This is true, but it gets a
2. Various bits of info about LaTeX and its progress bit more complicated if you want to introduce images or
will be displayed. If all went well, the last two lines links. This will be explained in detail in the next chapters,
displayed in the console will be:
but for now assume you can compile in both DVI and
PDF without any problem.
Output written on [Link] (1 page, 232 bytes). Tran- Note, in this instance, due to the simplicity of the le, you
script written on [Link].
only need to run the LaTeX command once. However, if
This means that your source le has been processed and
the resulting document is called [Link], which takes up
1 page and 232 bytes of space. Now you may view the
DVI le. On Unix with X11 you can type xdvi [Link],

you begin to create complex documents, including bibliographies and cross-references, etc, LaTeX needs to be
executed multiple times to resolve the references. But
this will be discussed in the future when it comes up.

1.4. LATEX/BASICS

15

Autobuild Systems

ment twice. There is no need to re-compile if no section


moved.

Compiling using only the latex binary can be quite tricky


as soon as you start working on more complex documents
as previously stated. A number of programs exist to automatically read in a TeX document and run the appropriate
compilers the appropriate number of times. For example,
latexmk can generate a PDF from most TeX les simply:
$ latexmk -pdf [Link]
Note that most editors will take care of it for you.
Compressed PDF

For example, the temporary le for the table of contents


data is [Link].
None of these les contains unrecoverable information.
It means you can delete them safely, compiling will regenerate them automatically.
When you work with various capabilities of LaTeX (index, glossaries, bibliographies, etc.) you will soon nd
yourself in a maze of les with various extensions and
probably no clue. The following list explains the most
common le types you might encounter when working
with TeX:

For a PDF output, you may have noticed that the output
PDF le is not always the same size depending on the
engine you used to compile the le. So latex dvips 1.4.5 And what now?
ps2pdf will usually be much smaller than pdatex. If you
want pdatex features along with a small output le size, Common Elements
you can use the Ghostscript command:
See Document Structure and the Common Elements
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite - part for all the common features that belong to every type
sOutputFile="[Link] [Link]
of document.

1.4.4

Files

Non-English documents and special characters

Picking suitable lenames

LaTeX has some nice features for most languages in the


world. You can tell LaTeX to follow typography rules of
Never, ever use directories (folders) or le names that the target language, ease special characters input, and so
contain spaces. Although your operating system probably on. See Special Characters and Internationalization.
supports them, some don't, and they will only cause grief
and tears with TeX. Make lenames as short or as long as
you wish, but strictly avoid spaces. Stick to lower-case let- Modular document
ters without accents (a-z), the digits 0-9, the hyphen (),
and only one full point or period (.) to separate the le ex- See Modular Documents for good recommendations
tension (somewhat similar to the conventions for a good about the way to organize big projects into multiple les.
Web URL): it will let you refer to TeX les over the Web
more easily and make your les more portable. Some Questions and Issues
operating systems do not distinguish between upper-case
and lower-case letters, others do. Therefore its best not We highly urge you to read the FAQ if you have issues
to mix them.
about basic features, or if you want to read essential recAncillary les
The TeX compilers are single-pass processes. It means
that there is no way for a compiler to jump around the
document, which would be useful for the table of contents and references. Indeed the compiler cannot guess
at which page a specic section is going to be printed, so
when the table of contents is printed before the upcoming
sections, it cannot set the page numbers.

ommendations. For the more specic questions and issues, refer to the Tips and Tricks page. If you cannot nd
what you want here, use the Q&A page.
Macros for the utmost eciency
The full power of LaTeX resides in macros. They make
your documents very dynamic and exible. See the
dedicated part.

To circumvent this issue, many LaTeX commands which


Working in a team
need to jump use ancillary les which usually have the
same le name as the current document but a dierent
See chapter Collaborative Writing of LaTeX Documents.
extension. It stores temporary data into these les and
use them for the next compilation. So to have an upto-date table of contents, you need to compile the docu-

Chapter 2

Common Elements
2.1 LaTeX/Document Structure

Document classes

The main point of writing a text is to convey ideas, information, or knowledge to the reader. The reader will understand the text better if these ideas are well-structured,
and will see and feel this structure much better if the typographical form reects the logical and semantic structure
of the content.

When processing an input le, LaTeX needs to know the


type of document the author wants to create. This is
specied with the \documentclass command. It is recommended to put this declaration at the very beginning.

LaTeX is dierent from other typesetting systems in that


you just have to tell it the logical and semantical structure
of a text. It then derives the typographical form of the text
according to the rules given in the document class le
and in various style les. LaTeX allows users to structure
their documents with a variety of hierarchical constructs,
including chapters, sections, subsections and paragraphs.

2.1.1

Global structure

Here, class species the type of document to be created.


The LaTeX distribution provides additional classes for
other documents, including letters and slides. It is also
possible to create your own, as is often done by journal
publishers, who simply provide you with their own class
le, which tells LaTeX how to format your content. But
we'll be happy with the standard article class for now. The
options parameter customizes the behavior of the document class. The options have to be separated by commas.
Example: an input le for a LaTeX document could start
with the line

which instructs LaTeX to typeset the document as an arWhen LaTeX processes an input le, it expects it to fol- ticle with a base font size of 11 points, and to produce a
low a certain structure. Thus every input le must contain layout suitable for double sided printing on A4 paper.
the commands
Here are some document classes that can be used with
The area between \documentclass{...} and \be- LaTeX:
gin{document} is called the preamble. It normally The standard document classes that are a part of LaTeX
contains commands that aect the entire document.
are built to be fairly generic, which is why they have a
After the preamble, the text of your document is enclosed lot of options in common. Other classes may have dierbetween two commands which identify the beginning and ent options (or none at all). Normally, third party classes
come with some documentation to let you know. The
end of the actual document:
most common options for the standard document classes
You would put your text where the dots are. The reason are listed in the following table:
for marking o the beginning of your text is that LaTeX
allows you to insert extra setup specications before it For example, if you want a report to be in 12pt type on
(where the blank line is in the example above: we'll be us- A4, but printed one-sided in draft mode, you would use:
ing this soon). The reason for marking o the end of your
text is to provide a place for LaTeX to be programmed to
do extra stu automatically at the end of the document, Packages
like making an index.
While writing your document, you will probably nd that
A useful side-eect of marking the end of the document
there are some areas where basic LaTeX cannot solve
text is that you can store comments or temporary text unyour problem. If you want to include graphics, colored
derneath the \end{document} in the knowledge that Latext or source code from a le into your document, you
TeX will never try to typeset them:
need to enhance the capabilities of LaTeX. Such enhancements are called packages. Some packages come
with the LaTeX base distribution. Others are provided
2.1.2 Preamble
separately. Modern TeX distributions come with a large
16

2.1. LATEX/DOCUMENT STRUCTURE

17

number of packages pre-installed. Packages are activated you use the AMS article class (amsart), then you can use
with the
several dierent commands to enter author information.
command, where package is the name of the package and The email address is at the end, and the \texttt commands
options is a list of keywords that trigger special features formats the email address using a mono-spaced font. The
in the package. For example, to use the color package, built-in command called \today will be replaced with the
current date when processed by LaTeX. But you are free
which lets you typeset in colors, you would type:
to put whatever you want as a date, in no set order. If
You can include several package names in one \usepack- braces are left empty, then the date is omitted.
age command by separating the names with commas, like
Using this approach, you can create only basic output
this:
whose layout is very hard to change. If you want to create
and you can have more than one \usepackage command. your title freely, see the Title Creation section.
Some packages allow optional settings in square brackets.
If you use these, you must give the package its own separate \usepackage command, like geometry shown below: Abstract
Many packages can have additional formatting specications in optional arguments in square brackets, in the
same way as geometry does. Read the documentation for
the package concerned to nd out what can be done. You
can pass several options together separated by a comma:

2.1.3

The document environment

Top matter
At the beginning of most documents there will be information about the document itself, such as the title and
date, and also information about the authors, such as
name, address, email etc. All of this type of information within LaTeX is collectively referred to as top matter.
Although never explicitly specied (there is no \topmatter command) you are likely to encounter the term within
LaTeX documentation.
A simple example:
The \title, \author, and \date commands are selfexplanatory. You put the title, author name, and date in
curly braces after the relevant command. The title and
author are usually compulsory (at least if you want LaTeX to write the title automatically); if you omit the \date
command, LaTeX uses todays date by default. You always nish the top matter with the \maketitle command,
which tells LaTeX that its complete and it can typeset the
title according to the information you have provided and
the class (style) you are using. If you omit \maketitle, the
titling will never be typeset (unless you write your own).
Here is a more complicated example:
as you can see, you can use commands as arguments of
\title and the others. The double backslash (\\) is the LaTeX command for forced linebreak. LaTeX normally decides by itself where to break lines, and its usually right,
but sometimes you need to cut a line short, like here, and
start a new one.

As most research papers have an abstract, there are predened commands for telling LaTeX which part of the
content makes up the abstract. This should appear in its
logical order, therefore, after the top matter, but before
the main sections of the body. This command is available
for the document classes article and report, but not book.
By default, LaTeX will use the word Abstract as a title
for your abstract. If you want to change it into anything
else, e.g. Executive Summary, add the following line
before you begin the abstract environment:
Sectioning commands
The commands for inserting sections are fairly intuitive.
Of course, certain commands are appropriate to dierent
document classes. For example, a book has chapters but
an article doesn't. Here are some of the structure commands found in [Link].
Notice that you do not need to specify section numbers;
LaTeX will sort that out for you. Also, for sections, you
do not need to use \begin and \end commands to indicate
which content belongs to a given block.
LaTeX provides 7 levels of depth for dening sections
(see table below). Each section in this table is a subsection
of the one above it.
All the titles of the sections are added automatically to
the table of contents (if you decide to insert one). But
if you make manual styling changes to your heading, for
example a very long title, or some special line-breaks or
unusual font-play, this would appear in the Table of Contents as well, which you almost certainly don't want. LaTeX allows you to give an optional extra version of the
heading text which only gets used in the Table of Contents and any running heads, if they are in eect. This
optional alternative heading goes in [square brackets] before the curly braces:

If there are two authors separate them with the \and com- Section numbering Numbering of the sections is permand:
formed automatically by LaTeX, so don't bother adding
If you are provided with a class le from a publisher, or if them explicitly, just insert the heading you want between

18

CHAPTER 2. COMMON ELEMENTS

the curly braces. Parts get roman numerals (Part I, Part


II, etc.); chapters and sections get decimal numbering like
this document, and appendices (which are just a special
case of chapters, and share the same structure) are lettered (A, B, C, etc.).

Table of contents

All auto-numbered headings get entered in the Table of


Contents (ToC) automatically. You don't have to print a
ToC, but if you want to, just add the command \tableofcontents at the point where you want it printed (usually
You can change the depth to which section numbering
after the Abstract or Summary).
occurs, so you can turn it o selectively. By default it
is set to 2. If you only want parts, chapters, and sections Entries for the ToC are recorded each time you process
numbered, not subsections or subsubsections etc., you can your document, and reproduced the next time you prochange the value of the secnumdepth counter using the cess it, so you need to re-run LaTeX one extra time to
\setcounter command, giving the depth level you wish. ensure that all ToC pagenumber references are correctly
calculated. We've already seen how to use the optional
For example, if you want to change it to 1":
argument to the sectioning commands to add text to the
A related counter is tocdepth, which species what depth
ToC which is slightly dierent from the one printed in
to take the Table of Contents to. It can be reset in exactly
the body of the document. It is also possible to add extra
the same way as secnumdepth. For example:
lines to the ToC, to force extra or unnumbered section
To get an unnumbered section heading which does not headings to be included.
go into the Table of Contents, follow the command name
The commands \listogures and \listoftables work in exwith an asterisk before the opening curly brace:
actly the same way as \tableofcontents to automatically
All the divisional commands from \part* to \subpara- list all your tables and gures. If you use them, they norgraph* have this starred version which can be used on mally go after the \tableofcontents command. The \tablespecial occasions for an unnumbered heading when the ofcontents command normally shows only numbered secsetting of secnumdepth would normally mean it would be tion headings, and only down to the level dened by the
numbered.
tocdepth counter, but you can add extra entries with the
If you want the unnumbered section to be in the table of \addcontentsline command. For example if you use an
contents anyway, use the \addcontentsline command like unnumbered section heading command to start a preliminary piece of text like a Foreword or Preface, you can
this:
write:
Note that if you use PDF bookmarks you will need to add
a phantom section so that bookmark will lead to the cor- This will format an unnumbered ToC entry for Preface
rect place in the document. The \phantomsection com- in the subsection style. You can use the same mechamand is dened in the hyperref package, and is imple- nism to add lines to the List of Figures or List of Tables
by substituting lof or lot for toc. If the hyperref packmented normally as follows:
age is used and the link does not point to the correct
For chapters you will also need to clear the page (this will chapter, the command \phantomsection in combination
also correct page numbering in the ToC):
with \clearpage or \cleardoublepage can be used (see also
The value where the section numbering starts from can Labels and Cross-referencing):
be set with the following command:
To change the title of the TOC, you have to paste this
The next section after this command will now be num- command \renewcommand{\contentsname}{<New table
of contents title>} in your document preamble. The List
bered 5.
of Figures (LoF) and List of Tables (LoT) names can be
For more details on counters, see the dedicated chapter.
changed by replacing the \contentsname with \listgurename for LoF and \listtablename for LoT.

Section number style

See Counters.

Depth The default ToC will list headings of level 3 and


above. To change how deep the table of contents displays
automatically the following command can be used in the
preamble:

This will make the table of contents include everything


down to paragraphs. The levels are dened above on this
page. Note that this solution does not permit changing
Paragraphs of text come after section headings. Simply the depth dynamically.
type the text and leave a blank line between paragraphs.
The blank line means start a new paragraph here": it You can change the depth of specic section type, which
does not mean you get a blank line in the typeset output. could be useful for PDF bookmarks (if you are using the
For formatting paragraph indents and spacing between hyperref package) :
In order to further tune the display or the numbering of
paragraphs, refer to the Paragraph Formatting section.
Ordinary paragraphs

2.1. LATEX/DOCUMENT STRUCTURE


the table of contents, for instance if the appendix should
be less detailed, you can make use of the tocvsec2 package (CTAN, doc).

19
5. Dedication if any, else empty
6. Table of contents
7. List of gures (can be in the backmatter too)

2.1.4

Book structure

8. Preface chapter
The standard LaTeX book class follows the same layout
described above with some additions. By default a book Mainmatter
will be two-sided, i.e. left and right margins will change
according to the page number parity. Furthermore cur1. Main topic
rent chapter and section will be printed in the header.
If you do not make use of chapters, it is barely useful to
Appendix
use the book class.
Additionally the class provides macros to change the formatting of some places of the document. We will give
you some advice on how to use them properly.[1]

1. Some subordinate chapters


Backmatter

The frontmatter chapters will not be numbered.


Page numbers will be printed in roman numerals.
Frontmatter is not supposed to have sections, since
they will be number 0.n because there is no chapter
numbering. Check the Counters chapter for a x.

1. Bibliography
2. Glossary / Index

The mainmatter chapters works as usual. The com- Introductory chapters with main page numbering
mand resets the page numbering. Page numbers will
be printed in arabic numerals.
You may be tempted to put your introductory chapters in
The \appendix macro can be used to indicate that the main matter so that it follows the same numbering as
following sections or chapters are to be numbered as the main chapters. This is not how the class was meant
appendices. Appendices can be used for the article to be used, so you will run into an issue if you don't want
the chapter to be numbered.
class too:
In the above code sample, the second page of the introduction will have TABLE OF CONTENTS printed in the
header. This is because the starred \chapter* command
The backmatter behaves like the frontmatter. It has does not set the leftmark -- see Page Layout. And it will
not be printed in the table of contents either.
the same issue with section numbering.
The trick is to set the leftmark and the TOC manually:
As a general rule you should avoid mixing the command TABLE OF CONTENTS is traditionally printed both left
order. Nonetheless all commands are optional, so you and right, but here we print it like other chapters, only
might consider using only a few.
right on even pages.
Note that the special content like the table of contents is To make it more convenient, you might use a macro:
considered as an unnumbered chapter.
Only use the \appendix macro once for all appendices.

Page order
This is one traditional page order for books.
Frontmatter

2.1.5 Special pages


Comprehensive papers often feature special pages at the
end, like indices, glossaries and bibliographies. Since this
is a quite complex topic, we will give you details in the
dedicated part Special Pages.

1. Half-title
2. Empty
3. Title page
4. Information (copyright notice, ISBN, etc.)

Bibliography
Any good research paper will have a complete list of references. LaTeX has two ways of inserting your references into a document:

20

CHAPTER 2. COMMON ELEMENTS

you can embed them within the document itself. Its


simpler, but it can be time-consuming if you are
writing several papers about similar subjects so that
you often have to cite the same books.

The setspace package allows more ne-grained control


over line spacing. To set one and a half line spacing
document-wide, but not where it is usually unnecessary
(e.g. footnotes, captions):

you can store them in an external BibTeX le and


then link them via a command to your current document and use a Bibtex style to dene how they appear. This way you can create a small database of
the references you might use and simply link them,
letting LaTeX work for you.

To change line spacing within the document, the setspace


package provides the environments singlespace, onehalfspace, doublespace and spacing:
Non-breaking spaces

This essential feature is a bit unknown to newcomers,


To learn how to add a bibliography to your document, see
although it is available on most WYSIWYG document
the Bibliography Management section.
processors. A non-breaking space between two tokens
(e.g. words, punctuation marks) prevents the processors
from inserting a line break between them. Besides a non2.1.6 Notes and references
breaking space cannot be enlarged. It is very important
for a consistent reading.
[1] [Link]
what-is-the-right-order-when-using-frontmatter-tableofcontents-mainmatter

2.2 LaTeX/Text Formatting


This section will guide you through the formatting techniques of the text. Formatting tends to refer to most things
to do with appearance, so it makes the list of possible topics quite eclectic: text style, spacing, etc. If formatting
may also refer to paragraphs and to the page layout, we
will focus on the customization of words and sentences
for now.
A lot of formatting techniques are required to dierentiate certain elements from the rest of the text. It is often
necessary to add emphasis to key words or phrases. Footnotes are useful for providing extra information or clarication without interrupting the main ow of text. So, for
these reasons, formatting is very important. However, it
is also very easy to abuse, and a document that has been
over-done can look and read worse than one with none at
all.
LaTeX is so exible that we will actually only skim the
surface, as you can have much more control over the presentation of your document if you wish. Having said that,
one of the purposes of LaTeX is to take away the stress
of having to deal with the physical presentation yourself,
so you need not get too carried away!

2.2.1

Spacing

Line Spacing
If you want to use larger inter-line spacing in a document,
you can change its value by putting the
command into the preamble of your document. Use \linespread{1.3} for one and a half line spacing, and \linespread{1.6} for double line spacing. Normally the lines
are not spread, so the default line spread factor is 1.

LaTeX uses the '~' symbol as a non-breaking space. You


would usually use non-breaking spaces for punctuation
marks in some languages, for units and currencies, for
initials, etc. In French typography, you would put a nonbreaking space before all two-parts punctuation marks.
Examples:
Space between words and sentences
To get a straight right margin in the output, LaTeX inserts varying amounts of space between the words. By
default, it also inserts slightly more space at the end of
a sentence. However, the extra space added at the end
of sentences is generally considered typographically oldfashioned in English language printing. (The practice is
found in nineteenth century design and in twentieth century typewriter styles.) Most modern typesetters treat the
end of sentence space the same as the interword space.
(See for example, Bringhursts Elements of Typographic
Style.) The additional space after periods can be disabled
with the command
which tells LaTeX not to insert more space after a period than after ordinary character. Frenchspacing can be
turned o later in your document via the \nonfrenchspacing command.
If an author wishes to use the wider end-of-sentence spacing, care must be exercised so that punctuation marks are
not misinterpreted as ends of sentences. TeX assumes
that sentences end with periods, question marks or exclamation marks. Although if a period follows an uppercase
letter, this is not taken as a sentence ending, since periods
after uppercase letters normally occur in abbreviations.
Any exception from these assumptions has to be specied
by the author. A backslash in front of a space generates a
space that will not be enlarged. A tilde ~ character generates a non-breaking space. The command \@ in front
of a period species that this period terminates a sentence
even when it follows an uppercase letter. (If you are us-

2.2. LATEX/TEXT FORMATTING

21

ing \frenchspacing, then none of these exceptions need be prevents FORTRAN, Fortran and fortran from bespecied.)
ing hyphenated at all. No special characters or symbols
are allowed in the argument. Example:
The command \- inserts a discretionary hyphen into a
word. This also becomes the only point where hyphenation is allowed in this word. This command is especially
You can insert a horizontal stretched space with \hll in a
useful for words containing special characters (e.g., acline so that the rest gets pushed toward the right margin.
cented characters), because LaTeX does not automatiFor instance this may be useful in the header.
cally hyphenate words containing special characters.
Similarly you can insert vertical stretched space with
LaTeX does not hyphenate compound words that contain
\vll. It may be useful for special pages.
a dash[1] . There are two packages that can add back exiSee Lengths for more details.
bility. The hyphenat package supplies the \hyp command.
This command typesets the dash and then subjects the
constituent words to automatic hyphenation. After loadManual spacing
ing the package:
Stretched spaces

The spaces between words and sentences, between paragraphs, sections, subsections, etc. is determined automatically by LaTeX. It is against LaTeX philosophy to insert
spaces manually and will usually lead to bad formatting.
Manual spacing is a matter of macro writing and package
creation.
See Lengths for more details.

2.2.2

Hyphenation

LaTeX hyphenates words whenever necessary. Hyphenation rules will vary for dierent languages. LaTeX
only supports english by default, so if you want to have
correct hyphenation rules for your desired language, see
Internationalization.

one should write, instead of electromagnetic-endioscopy:


The extdash package also oers features for controlling
the hyphenation of compound words containing dashes
as opposed to the words themselves which it leaves to
LaTeX. The shortcuts option enables a more compressed
syntax:
Typical usage is as follows, assuming the compressed syntax. In both cases, LaTeX can break and hyphenate the
constituent words, but in the latter case, it will not break
after the L:
One or more words can be kept together on the one line
with the standard LaTeX command:
This prevents hyphenation and causes its argument to be
kept together under all circumstances. For example:

\fbox is similar to \mbox, but in addition there will be a


If the hyphenation algorithm does not nd the correct hy- visible box drawn around the content.
phenation points, you can remedy the situation by using To avoid hyphenation altogether, the penalty for hyphenthe following commands to tell TeX about the exception. ation can be set to an extreme value:
The command
You can change the degree to which LaTeX will hyphencauses the words listed in the argument to be hyphenated ate by changing the value of \tolerance=1000 and \hyonly at the points marked by -. The argument of the phenpenalty=1000. You'll have to experiment with the
command should only contain words built from normal values to achieve the desired eect. A document which
letters, or rather characters that are considered to be nor- has a low tolerance value will cause LaTeX not to tolmal letters by LaTeX. It is known that the hyphenation erate uneven spacing between words, hyphenating words
algorithm does not nd all correct American English hy- more frequently than in documents with higher tolerphenation points for several words. A log of known ex- ances. Also note that using a higher text width will deceptions is published periodically in the TUGboat jour- crease the probability of encountering badly hyphenated
nal. (See a 2008 list: [Link] word. For example adding
Articles/tb29-2/[Link])
will widen the text width and reduce the amount of marThe hyphenation hints are stored for the language that gin overruns.
is active when the hyphenation command occurs. This
means that if you place a hyphenation command into the
preamble of your document it will inuence the English 2.2.3 Quote-marks
language hyphenation. If you place the command after the \begin{document} and you are using some pack- LaTeX treats left and right quotes as dierent entities.
age for national language support like babel, then the hy- For single quotes, ` (on American keyboards, this symbol
phenation hints will be active in the language activated is found on the tilde key (adjacent to the number 1 key
through babel. The example below will allow hyphen- on most keyboards) gives a left quote mark, and ' is the
ation to be hyphenated as well as Hyphenation, and it right. For double quotes, simply double the symbols, and

22

CHAPTER 2. COMMON ELEMENTS

LaTeX will interpret them accordingly. (Don't use the "


for right double quotes: when the babel package is used
for some languages (e.g. German), the " is redened to
produce an umlaut accent; using " for right double quotes
will either lead to bad spacing or it being used to produce
an umlaut). On British keyboards, ' ` ' is left of the ' 1 ' key
and shares the key with ' ', and sometimes ' ' or ' | '. The
apostrophe (') key is to the right of the colon/semicolon
key and shares it with the ' @ ' symbol.

the string "nally). If one desires, for greater accessibility, to disable ligatures altogether in the whole document,
the \DisableLigatures from the microtype package can be
used:
Note that this will also disable ligatures such as "--" to
"", "---" to "", etc.

If you are using XeLaTeX and OpenType fonts, the


fontspec package allows for standard ligatures to be
turned o as well as fancy swash ligatures to be turned
The right quote is also used for apostrophe in LaTeX on.
without trouble.
Another solution is to use the cmap package, which will
For left bottom quote and European quoting style you help the reader to interpret the ligatures:
need to use T1 font encoding enabled by:
See Fonts for more details on font encoding.
The package csquotes oers a multi-lingual solution to
quotations, with integration to citation mechanisms of- 2.2.7 Slash marks
fered by BibTeX. This package allows one for example
to switch languages and quotation styles according to ba- The normal typesetting of the / character in LaTeX
bel language selections.
does not allow following characters to be broken onto
new lines, which often create overfull errors in output
(where letters push o the margin). Words that use slash
marks, such as input/output should be typeset as in2.2.4 Diacritics and accents
put\slash output, which allow the line to break after
Most accents and diacritics may be inserted with direct the slash mark (if needed). The use of the / character in
keyboard input by conguring the preamble properly. For LaTeX should be restricted to units, such as mm/year,
symbols unavailable on your keyboard, diacritics may be which should not be broken over multiple lines.
added to letters by placing special escaped metacharacters
before the letter that requires the diacritic.
See Special Characters.

2.2.5

2.2.8 Fonts

Margin misalignment and interword To change the font family, emphasize text, and other fontrelated issues, see Fonts.
spacing

Some very long words, numbers or URLs may not be hyphenated properly and move far beyond the side margin.
One solution for this problem is to use sloppypar envi- 2.2.9 Formatting macros
ronment, which tells LaTeX to adjust word spacing less
strictly. As a result, some spaces between words may be Even if you can easily change the output of your fonts
a bit too large, but long words will be placed properly.
using those commands, you're better o not using explicit
Another solution is to edit the text to avoid long words, commands like this, because they work in opposition to
the basic idea of LaTeX, which is to separate the logical
numbers or urls approaching the side margin.
and visual markup of your document. This means that
if you use the same font changing command in several
places in order to typeset a special kind of information,
2.2.6 Ligatures
you should use \newcommand to dene a logical wrapper
Some letter combinations are typeset not just by setting command for the font changing command.
the dierent letters one after the other, but by actually
using special symbols (like ""), called ligatures. Ligatures can be prohibited by inserting {} or, if this does
not work, {\kern0pt} between the two letters in question.
This might be necessary with words built from two words.
Here is an example:

This approach has the advantage that you can decide at


some later stage that you want to use some visual representation of danger other than \textit, without having
to wade through your document, identifying all the occurrences of \textit and then guring out for each one
whether it was used for pointing out danger or for some
Some tools are unable to perform search in documents other reason.
that contain ligatures (a search for "nally wouldn't nd See Macros for more details.

2.2. LATEX/TEXT FORMATTING

2.2.10

23

Text mode superscript and sub- include them as well.


script

Note
To superscript text in text-mode, you can use the \textsuperscript{} command. This allows you to, for instance,
A subsequent use of the \pagenumbering command, e.g.,
typeset 6th as 6th :
\pagenumbering{arabic}, will reset the \thepage comSubscripting in text-mode is not supported by LaTeX mand back to the original. Thus, if you use the \pagenumalone; however, several packages allow the use of bering command in your document, be sure to reinstate
the \textsubscript{} command. For instance, bpchem, your \myThePage denition from the code above:
KOMA-Script2, and xltx2e all support this command.
Of these, xltx2e is perhaps the most universal option
since it is distributed with LaTeX and requires no addi- 2.2.12 Dashes and hyphens
tional packages to be implemented.
If you do not load a package that supports \textsub- LaTeX knows four kinds of dashes: a hyphen (-), en dash
script{}, the math mode must be used. This is easily ac- (), em dash (), or a minus sign (). You can accomplished in running text by bracketing your text with cess three of them with dierent numbers of consecutive
the $ symbol. In math mode subscripting is done using dashes. The fourth sign is actually not a dash at allit is
the mathematical minus sign:
the underscore: _{}.
The names for these dashes are: -(-) hyphen , --() endash , ---() em-dash and () minus sign. They
Note that in math mode text will appear in a font suit- have dierent purposes:
able for mathematical variables. In math mode, to generate roman text, for example, one would use the \mathrm
command:
For example, the formula for water is written as:

Note the use of \<space> to insert a space in math mode.


Similarly, you can superscript using:
A very common use of subscripts within the text environment is to typeset chemical formulae. For this purposes,
a highly recommended package is mhchem. This package is easy to use, and works with your text fonts (rather
than math fonts). To insert a chemical formula, use \ce{}
with the text-equivalent formula, for example:

Use \hyp{} macro from hyphenat package instead of hyphen if you want LaTeX to break compound words between lines.
The commands \textendash and \textemdash are also used
to produce en-dash (), and em-dash (), respectively.

See also Chemical Graphics for chemical symbols and


2.2.13
formulas.

2.2.11

Text gures (old style numerals)

Many typographers prefer to use titling gures, sometimes called lining gures, when numerals are interspersed with full caps, when they appear in tables, and
when they appear in equations, using text gures elsewhere. LaTeX allows this usage through the \oldstylenums{} command:

Ellipsis ()

A sequence of three dots is known as an ellipsis, which is


commonly used to indicate omitted text. On a typewriter,
a comma or a period takes the same amount of space as
any other letter. In book printing, these characters occupy
only a little space and are set very close to the preceding
letter. Therefore, you cannot enter ellipsis by just typing
three dots, as the spacing would be wrong. Instead, there
is a special command for these dots. It is called \ldots:

Alternatively, you can use the \textellipsis command


Some fonts do not have text gures built in; the textcomp which allows the spacing between the dots to vary.
package attempts to remedy this by eectively generating
text gures from the currently-selected font. Put \usepackage{textcomp} in your preamble. textcomp also al- 2.2.14 Ready-made strings
lows you to use decimal points, properly formatted dollar
There are some very simple LaTeX commands for typesigns, etc. within \oldstylenums{}.
setting special text strings:
One common use for text gures is in section, paragraph,
and page numbers. These can be set to use text gures by
placing some code in your preamble:

2.2.15 Notes and References

Should you use additional sectioning or paragraphing


commands, you may adapt the previous code listing to

[1] hyphenat package documentation, p3

24

CHAPTER 2. COMMON ELEMENTS


use the indentrst package: once loaded, the beginning
of any chapter/section is indented by the usual paragraph
indentation.
To create a non-indented paragraph, you can use
as the rst command of the paragraph. This might come
in handy when you start a document with body text and
not with a sectioning command.

This page uses material from Andy Roberts Getting to grips


Be careful, however, if you decide to set the indent to
with LaTeX with permission from the author.
zero, then it means you will need a vertical space between
paragraphs in order to make them clear. The space beparagraphs is held in \parskip, which could be al2.3 LaTeX/Paragraph Formatting tween
tered in a similar fashion as above. However, this parameter is used elsewhere too, such as in lists, which means
Altering the paragraph formatting is not often required, you run the risk of making various parts of your docuespecially in academic writing. However, it is useful to ment look very untidy by changing this setting. If you
know, and applications tend to be for formatting text in want to use the style of having no indentation with a space
oats, or other more exotic documents.
between paragraphs, use the parskip package, which does
this for you, while making adjustments to the spacing of
lists and other structures which use paragraph spacing, so
2.3.1 Paragraph alignment
they don't get too far apart. If you want both indent and
break, use
Paragraphs in LaTeX are usually fully justied, i.e. ush
with both the left and right margins. For whatever rea- To indent subsequent lines of a paragraph, use the TeX
son, should you wish to alter the justication of a para- command \hangindent. (While the default behaviour is
graph, there are three environments at hand, and also La- to apply the hanging indent after the rst line, this may
be changed with the \hangafter command.) An example
TeX command equivalents.
follows.
All text between the \begin and \end of the specied environment will be justied appropriately. The commands The TeX commands \leftskip and \rightskip add addilisted are for use within other environments. For exam- tional space to the left and right sides of each line, allowing the formatting for subsequent paragraphs to dier
ple, p (paragraph) columns in tabular.
from the overall document margins. This space is in addition to the indentation added by \parindent and \hangindent.
2.3.2 Paragraph indent and break
By default, the rst paragraph after a heading follows the
standard Anglo-American publishers practice of no indentation. The size of subsequent paragraph indents is
determined by a parameter called \parindent. The default length that this constant holds is set by the document
class that you use. It is possible to override it by using the
\setlength command. This will set paragraph indents to
1cm:
White-space in LaTeX can also be made exible (what
Lamport calls rubber lengths). This means that values
such as extra vertical space inserted before a paragraph
\parskip can have a default dimension plus an amount
of expansion minus an amount of contraction. This is
useful on pages in complex documents where not every
page may be an exact number of xed-height lines long,
so some give-and-take in vertical space is useful. You
specify this in a \setlength command like this:
If you want to indent a paragraph that is not indented, you
can use
at the beginning of the paragraph. Obviously, this will
only have an eect when \parindent is not set to zero. If
you want to indent the beginning of every section, you can

To change the indentation of the last line in a paragraph,


use the TeX command \parllskip.

2.3.3 Line spacing


To change line spacing in the whole document use the
command \linespread covered in Text Formatting.
Alternatively, you can use the \usepackage{setspace}
package, which is also covered in Text Formatting. This package provides the commands \doublespacing, \onehalfspacing, \singlespacing and \setstretch{baselinestretch}, which will specify the line spacing for all sections and paragraphs until another command
is used. Furthermore, the package provides the following
environments in order to change line spacing within the
document but not document-wide:
doublespace: lines are double spaced;
onehalfspace: line spacing set to one-and-half spacing;
singlespace: normal line spacing;

2.3. LATEX/PARAGRAPH FORMATTING


spacing: customizable line spacing, e.g. \begin{spacing}{baselinestretch} ... \end{spacing}.

25
will print \textbf{Hi mate!}, ignoring the eect \textbf
should have on text.

For more control over formatting, however, you can try


See the section on customizing lists for information on the fancyvrb package, which provides a Verbatim environment (note the capital letter) which lets you draw a
how to change the line spacing in lists.
rule round the verbatim text, change the font size, and
even have typographic eects inside the Verbatim environment. It can also be used in conjunction with the
2.3.4 Manual breaks
fancybox package and it can add reference line numbers
LaTeX takes care of the formatting, breaks included. You (useful for chunks of data or programming), and it can
should avoid manual breaking as much as possible, for it even include entire external les.
could lead to very bad formatting.
Controlling the breaks should be reserved to macro and Typesetting URLs One of either the hyperref or url
package writers. Here follows a quick reference.
packages provides the \url command, which properly
The page breaks are covered in Page Layout. More details typesets URLs, for example:
on manual spaces between paragraphs (such as \bigskip) will show this URL exactly as typed (similar to the \verb
can be found in Lengths.
command), but the \url command also performs a hyphenless break at punctuation characters (only in PDFLaTeX, not in plain LaTeX+ dvips). It was designed for
2.3.5 Special paragraphs
Web URLs, so it understands their syntax and will never
break mid-way through an unpunctuated word, only at
Verbatim text
slashes and full stops. Bear in mind, however, that spaces
are forbidden in URLs, so using spaces in \url arguments
There are several ways to introduce text that won't be in- will fail, as will using other non-URL-valid characters.
terpreted by the compiler. If you use the verbatim enWhen using this command through the hyperref package,
vironment, everything input between the begin and end
the URL is clickable in the PDF document, whereas it
commands are processed as if by a typewriter. All spaces
is not linked to the web when using only the url packand new lines are reproduced as given, and the text is disage. Also when using the hyperref package, to remove
played in an appropriate xed-width font. Any LaTeX
the border placed around a URL, insert pdfborder = {0 0
command will be ignored and handled as plain text. This
0 0} inside the \hypersetup{}. (Alternately pdfborder =
is ideal for typesetting program source code. Here is an
{0 0 0} might work if the four zeroes do not.)
example:
You can put the following code into your preamble to
Note: once in the verbatim environment, the only comchange the style, how URLs are displayed to the normal
mand that will be recognized is \end{verbatim}. Any othfont:
ers will be output. The font size in the verbatim environment can be adjusted by placing a font size command be- See also Hyperlinks
fore \begin{verbatim}. If this is a problem, you can use
the alltt package instead, providing an environment with
Listing environment This is also an extension of the
the same name:
verbatim environment provided by the moreverb packRemember to add \usepackage{alltt} to your preamble to age. The extra functionality it provides is that it can add
use it though! Within the alltt environment, you can use line numbers along side the text. The command: \bethe command \normalfont to get back the normal font. To gin{listing}[step]{rst line}. The mandatory rst line arwrite equations within the alltt enviroment, you can use gument is for specifying which line the numbering shall
\( and \) to enclose them, instead of the usual $.
commence. The optional step is the step between numbered
lines (the default is 1, which means every line will
When using \textbf{} inside the alltt enviroment, note
be
numbered).
that the standard font has no bold TT font. Txtfonts has
bold fonts: just add \renewcommand{\ttdefault}{txtt} To use this environment, remember to add \usepackafter \usepackage{alltt}.
age{moreverb} to the document preamble.
If you just want to introduce a short verbatim phrase, you
don't need to use the whole environment, but you have
Multi-line comments
the \verb command:
The rst character following \verb is the delimiter: here
we have used "+", but you can use any character you like
except *; \verb will print verbatim all the text after it until
it nds the next delimiter. For example, the code:

As we have seen, the only way LaTeX allows you to add


comments is by using the special character %, that will
comment out all the rest of the line after itself. This
approach is really time-consuming if you want to insert

26
long comments or just comment out a part of your document that you want to improve later, unless you're using
an editor that automates this process. Alternatively, you
can use the verbatim package, to be loaded in the preamble as usual:

CHAPTER 2. COMMON ELEMENTS


indicated using the newline command, \\. If a line
takes up more than one line on the page, then all subsequent lines are indented until explicitly separated
with \\.

(you can also use the comment package instead) you can
Abstracts
use an environment called comment that will comment
out everything within itself. Here is an example:
In scientic publications it is customary to start with an
Note that this wont work inside complex environments, abstract which gives the reader a quick overview of what
like math for example. You may be wondering, why to expect. See Document Structure.
should I load a package called verbatim to have the possibility to add comments? The answer is straightforward:
commented text is interpreted by the compiler just like 2.3.6 Notes and References
verbatim text, the only dierence is that verbatim text is
introduced within the document, while the comment is This page uses material from Andy Roberts Getting to grips
just dropped.
with LaTeX with permission from the author.
Alternatively, you can dene a \comment{} command, by
adding the following to the documents preamble:
Then, to comment out text, simply do something like this:

2.4 LaTeX/Colors

This approach can, however, produce unwanted spaces in


the document, so it may work better to use
Adding colors to your text is supported by the color packThen if you supply only one argument to \comment{}, age. Using this package, you can set the color of the font
this has the desired eect without producing extra spaces. of the text, and set the background color of the page. You
can use one of the predened colors such as white, red,
Another drawback is that content is still parsed and pos- or yellow, or you can dene your own named colors. Its
sibly expanded, so you cannot put anything you want in it also possible to color formulas in math-environments.
(such as LaTeX commands).
Skipping parts of the source

2.4.1 Adding the color package

A more robust way of making the TeX engine skip some To make use of these color features the color package
part of the source is to use the TeX \if-command with a must be inserted into the preamble.
false statement. The typical use is
Alternatively, one can write:
The \if-command compares the two following statements, The \usepackage is obvious, but the initialization of addiso we provide two dierent (0 and 1).
tional commands like usenames allows you to use names
of the default colors, the same 16 base colors as used in
HTML. The dvipsnames allows you access to more colQuoting text
ors, another 64, and svgnames allows access to about 150
colors. The initialization of table allows colors to be
LaTeX provides several environments for quoting text; added to tables by placing the color command just before
they have small dierences and they are aimed for dif- the table. The package loaded here is the xcolor package.
ferent types of quotations. All of them are indented on
either margin, and you will need to add your own quota- If you need more colors, then you may also want to look at
tion marks if you want them. The provided environments adding the x11names to the initialization section as well,
this oers more than 300 colors, but you need to make
are:
sure your xcolor package is the most recent you can download.
quote for a short quotation, or a series of small quotes,
separated by blank lines.
quotation for use with longer quotations, of more than 2.4.2 Entering colored text
one paragraph, because it indents the rst line of
The simplest way to type colored text is by:
each paragraph.
verse is for quotations where line breaks are important, where declared-color is a color that was dened before by
such as poetry. Once in, new stanzas are created \denecolor.
with a blank line, and new lines within a stanza are Another possible way by

2.4. LATEX/COLORS

27

that will switch the standard text color to the color you Method
want. It will work until the end of the current TeX group.
For example:
In the abstract, the colors are dened following this
The dierence between \textcolor and \color is the same scheme:
as that between \texttt and \ttfamily, you can use the one where:
you prefer. The \color environment allows the text to run
over multiple lines and other text environments whereas
name is the name of the color; you can call it as you
the text in \textcolor must all be one paragraph and not
like
contain other environments.
model is the way you describe the color, and is one
You can change the background color of the whole page
of gray, rgb, RGB, HTML, and cmyk.
by:
color-spec is the description of the color

2.4.3

Entering colored background for the


Color Models
text

If the background color and the text color is changed, Among the models you can use to describe the color are
the following (several more are described in the xcolor
then:
manual):
There is also \fcolorbox to make framed background
color in yet another color:
Examples

2.4.4

Predened colors

The predened color names are


white, black, red, green, blue, cyan, magenta, yellow.

To dene a new color, follow the following example,


which denes orange for you, by setting the red to the
maximum, the green to one half (0.5), and the blue to the
minimum:

The following code should give a similar results to the last


There may be other pre-dened colors on your system,
code chunk.
but these should be available on all systems.
If you loaded the xcolor package, you can dene colors
If you would like a color not pre-dened, you can use one
upon previously dened ones.
of the 68 dvips colors, or dene your own. These options
The rst species 20 percent blue and 80 percent white;
are discussed in the following sections
the second is a mixture of 20 percent blue and 80 percent
black; and the last one is a mixture of (20*0.3) percent
blue, ((100-20)*0.3) percent black and (100-30) percent
The 68 standard colors known to dvips
green.
Invoke the package with the usenames and dvipsnames xcolor also feature a handy command to dene colors
option. If you are using tikz or pstricks package you must from color mixes:
declare the xcolor package before that, otherwise it will
not work.
Using colour specications directly
Normally one would predeclare all the colours as above,
but sometimes it is convenient to directly use a colour
without naming it rst. To achieve this, \color and \textIf the predened colors are not adequate, you may wish
color have an alternative syntax specifying the model
to dene your own.
in square brackets, and the color specication in curly
braces. For example:

2.4.5

Dening new colors

Place
Creating / Capturing colors
Dene the colors in the preamble of your document.
(Reason: do so in the preamble, so that you can already
refer to them in the preamble, which is useful, for instance, in an argument of another package that supports
colors as arguments, such as the listings package.)

You may want to use colors that appear on another document, web pages, pictures, etc. Alternatively, you may
want to play around with rgb values to create your own
custom colors.

28

CHAPTER 2. COMMON ELEMENTS

Image processing suites like the free GIMP suite for


Linux/Windows/Mac oer colour picker facilities to capture any color on your screen or synthesize colors directly
from their respective rgb / hsv / hexadecimal values.
Smaller, free utilities also exist:

Truetype font (ttf) and OpenType font (otf). With modern TeX compilers such as xetex and luatex it is possible
to make use of such fonts in LaTeX documents. If you
want/have to stick with the standard compilers, the aforementioned font types must rst be converted and made
available to LaTeX (e.g. converted to Type1 fonts). The
external links section below has some useful resources.

Linux/BSD: The gcolor2 tool (usually also available


In LaTeX, there are many ways to specify and control
in repositories)
fonts. It is a very complex matter in typography.
Microsoft Windows: The open-source Color Selector tool.

2.5.2 Font families

Apple Macs: Hex Color Picker for creating custom


colors and the built-in DigitalColor Meter for capThere are many font families e.g. Computer Modern,
turing colors on screen.
Times, Arial and Courier. Those families can be grouped
Online utilities: See here for a Wikipedia article into three main categories: roman (rm) or serif, sans serif
(sf) and monospace (tt) (see Typeface for more details).
with several external links
Each font family comes with the default design which falls
into one of those categories; however, it is interchange2.4.6 Sources
able among them. Computer Modern Roman is the default font family for LaTeX. Fonts in each family also have
The xcolor manual
dierent properties (size, shape, weight, etc.). Families
are meant to be consistent, so it is highly discouraged to
The color package documentation
change fonts individually rather than the whole family.

2.5 LaTeX/Fonts
Fonts are a complex topic. For common documents, only
Font families, Emphasizing text, and Font encoding are
really needed. The other sections are more useful to
macro writers or for very specic needs.

The three families are dened by their respective variables:


\rmdefault
\sfdefault
\ttdefault

The default family is contained in the \familydefault variable, and it is meant to have one of the three aforemenThe digital fonts have a long and intricate history. See tioned variables as value. The default is dened like the
following assignment:
Adobe Font Metrics for some more details.
Originally TeX was conceived to use its own font system, This will turn all the part of the document using the deMetaFont, designed by D. Knuth. The default font family fault font to the default sans serif, which is Computer
for TeX and friends is called Computer Modern. These Modern Sans Serif if you did not change the default font.

2.5.1

Introduction

high quality fonts are scalable, and have a wide range of Changing font families usually works in two steps:
typographical ne tuning capabilities.
Standard tex compilers will let you use other fonts.
There are many dierent font types, such as PostScript
Type1/Type3 fonts and bitmap fonts. Type1 are outline
fonts (vector graphics) which are commonly used by pdftex. Bitmap fonts are raster graphics, and usually have
very poor quality, which can easily be seen when zooming or printing a document. Type3 is a superset of Type1
and has more functionalities from Postscript, such as embedding raster graphics. In the TeX world, Type3 fonts
are often used to embed bitmap fonts.

1. First specify which family you want to change (rm,


sf or tt).
2. Second specify the new default family if it is not rm.
Mathematical fonts is a more complex matter. Fonts may
come with a package that will take care of dening all
three families plus the math fonts. You can do it by yourself, in which case you do not have to load any package.

Below is an example[1] that demonstrates how to change


It should be noticed that fonts get generated the rst time a specic family.
they are required, hence the long compilation time.
The three default family font variables and the \familydeHowever, MetaFont is internally a quite complex font sys- fault variable should not be confused with their respective
tem, and the most popular font systems as of this day are switch:

2.5. LATEX/FONTS

29

\normalfont

To overcome these shortcomings, several 8-bit CM-like


font sets were created. Extended Cork (EC) fonts in T1
\rmfamily
encoding contains letters and punctuation characters for
most of the European languages based on Latin script.
\samily
The LH font set contains letters necessary to typeset documents in languages using Cyrillic script. Because of
\ttfamily
the large number of Cyrillic glyphs, they are arranged
into four font encodingsT2A, T2B, T2C, and X2. The
CB bundle contains fonts in LGR encoding for the com2.5.3 Emphasizing text
position of Greek text. By using these fonts you can
In order to add some emphasis to a word or a phrase, the improve/enable hyphenation in non-English documents.
simplest way is to use the \emph{text} command, which Another advantage of using new CM-like fonts is that
usually italicizes the text. Italics may be specied explic- they provide fonts of CM families in all weights, shapes,
and optically scaled font sizes.
itly with \textit{text}.
Note that the \emph command is dynamic: if you empha- All this is not possible with OT1; thats why you may want
size a word which is already in an emphasized sentence, to change the font encoding of your document.
it will be reverted to the upright font.
Note that changing the font encoding will have some reText may be emphasized more heavily through the use quirements over the fonts being used. The default Comof boldface, particularly for keywords the reader may be puter Modern font does not support T1. You will need
trying to nd when reading the text. As bold text is gen- Computer Modern Super (cm-super) or Latin Modern
erally read before any other text in a paragraph or even on (lmodern), which are Computer Modern-like fonts with
a page, it should be used sparingly. It may also be used in T1 support. If you have none of these, it is quite frequent
place of italics when using sans-serif typefaces to provide (depends on your TeX installation) that tex chooses a
a greater contrast with unemphasized text. Bold text can Type3 font such as the Type3 EC, which is a bitmap font.
Bitmap fonts look rather ugly when zoomed or printed.
be generated with the \textbf{text} command.

2.5.4

Font encoding

A character is a sequence of bytes, and should not be confused with its representation, the glyph, which is what the
reader sees. So the character 'a' has dierent representations following the used font, for example the upright
version, the italic version, various weights and heights,
and so on.
Upon compilation, tex will have to choose the right font
glyph for every character. This is what is called font encoding. The default LaTeX font encoding is OT1, the encoding of the original Computer Modern TeX text fonts.
It contains only 128 characters, many from ASCII, but
leaving out some others and including a number that are
not in ASCII. When accented characters are required,
TeX creates them by combining a normal character with
an accent. While the resulting output looks perfect, this
approach has some caveats.

The fontenc package tells LaTeX what font encoding to


use. Font encoding is set with:
where encoding is the font encoding. It is possible to load
several encodings simultaneously.
There is nothing to change in your document to use CM
Super fonts (assuming they are installed), they will get
loaded automatically if you use T1 encoding. For lmodern, you will need to load the package after the T1 encoding has been set:
The package ae (almost European) is obsolete. It provided some workarounds for hyphenation of words with
special characters. These are not necessary any more with
fonts like lmodern. Using the ae package leads to text encoding problems in PDF les generated via pdatex (e.g.
text extraction and searching), besides typographic issues.

2.5.5 Font styles

Each family has its own font characteristics (such as italic


It stops the automatic hyphenation from working inand bold), also known as font styles, or font properties.
side words containing accented characters.
Font styles are usually implemented with dierent font
Searches for words with accents in PDFs will fail.
les. So it is possible to build a new font family by specifying the font styles of dierent font families.
Extracting ('e.g.' copy paste) the umlaut '' via a
PDF viewer actually extracts the two characters '"A'.
Besides, some of Latin letters could not be created Shapes
by combining a normal character with an accent,
to say nothing about letters of non-Latin alphabets, The following table lists the commands you will need to
access the typical font shapes:
such as Greek or Cyrillic.

30
The commands in column two are not entirely equivalent to the commands in column one: They do not correct spacing after the selected font style has ended. The
commands in column one are therefore in general recommended.
You may have noticed the absence of underline. This is
because underlining is not recommended for typographic
reasons (it weighs the text down). You should use emph
instead. However underlining text provides a useful extra
form of emphasis during the editing process, for example to draw attention to changes. Although underlining
is available via the \underline{...} command, text underlined in this way will not break properly. This functionality has to be added with the ulem (underline emphasis) package. Stick \usepackage{ulem} in your preamble. By default, this overrides the \emph command with
the underline rather than the italic style. It is unlikely
that you wish this to be the desired eect, so it is better
to stop ulem taking over \emph and simply call the underline command as and when it is needed.

CHAPTER 2. COMMON ELEMENTS


These commands change the size within a given scope, so
for instance {\Large some words} will change the size of
only some words, and does not aect the font in the rest
of the document. It will work for most parts of the text.
These commands cannot be used in math mode. However, part of a formula may be set in a dierent size by
using an \mbox command containing the size command.
The new size takes eect immediately after the size command; if an entire paragraph or unit is set in a certain
size, the size command should include the blank line or
the \end{...} which delimits the unit.
The default for \normalsize is 10 point (option 10pt), but
it may dier for some Document Styles or their options.
The actual size produced by these commands also depends on the Document Style and, in some styles, more
than one of these size commands may produce the same
actual size.
Note that the font size denitions are set by the document class. Depending on the document style the actual
font size may dier from that listed above. And not every
document class has unique sizes for all 10 size commands.

To restore the usual \emph formatting, add


\normalem straight after the document envi- As a technical note, points in TeX follow the standard
ronment begins.
Alternatively, use \usepack- American point size in which 1 pt is approximately
0.35136 mm. The standard point size used in most modage[normalem]{ulem}.
ern computer programs (known as the desktop publish To underline, use \uline{...}.
ing point or PostScript point) has 1 pt equal to approximately 0.3527 mm while the standard European point
To add a wavy underline, use \uwave{...}.
size (known as the Didot point) had 1 pt equal to approximately 0.37597151 mm (see: point (typography)).
For a strike-out (strikethrough), use \sout{...}.
For a slash through each individual character
2.5.6
\xout{...}.

Local font selection

You can change font for a specic part of the text. There
Some font styles are not compatible one with the other. are four font properties you can change.
But some extra packages will ll this hole. For bold small
capitals, you might want to use:
\fontencoding The font encoding, such as OT1 (TeX
default) or T1 (extended characters support, better
PDF support, widely used).
Sizing text
To apply dierent font sizes, simply follow the commands \fontfamily The font family.
on this table:
\fontseries The series: l=light, m=medium, b=bold,
bx=very bold.
\fontshape The shape: it=italic, n=normal, sl=slanted,
sc=small capitals.
The \selectfont command is mandatory, otherwise the
font will not be changed. It is highly recommended to
enclose the command in a group to cleanly return to the
previous font selection when desired.
You can use all these commands in a row:
The default values are stored in \encodingdefault, \familydefault, \seriesdefault and \shapedefault. Setting back
the default font properties can be done with

2.5. LATEX/FONTS

31

For
short,
you
can
use
the
\use- UTF-8 and load fontspec, which will take care of the font
font{<encoding>}{<family>}{<series>}{<shape>}
encoding. To make your document support both pdacommand.
tex and xelatex/lualatex you can use the \ifxetex/ \iuatex
macro from the ifxetex/ iuatex package. For example
for xelatex

2.5.7

Arbitrary font size

The \tiny...\Huge commands are often enough for most


contents. These are xed sizes however. In most document processors, you can usually choose any size for any
font. This is because the characters actually get magnied. If it usually looks correct for medium sizes, it will
look odd at extreme sizes because of an unbalanced thickness. In TeX it is possible to change the magnication of
anything, but highly discouraged for the aforementioned
reason. Changing the font size is made by changing the
font le. Yes, there is a le for every size: cmr10 for
Computer Modern Roman 10pt, cmr12 for Computer
Modern Roman 12pt, etc. This ensure the characters
are correctly balanced and remain readable at all dened
sizes.
You may choose a particular font size with the \fontsize{<size>}{<line space>} command. Example:
If you are using the default Computer Modern font with
OT1 encoding, you may get the following message:
LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size
<142.26378> not available (Font) size <24.88> substituted on input line 103.
In that case you will notice that the font size cannot be
changed beyond \tiny and \Huge. You must switch to a
more sizable font, e.g.

2.5.8

Finding fonts

2.5.10 PDF fonts and properties


PDF documents have the capability to embed font les. It
makes them portable, hence the name Portable Document
Format.
Many PDF viewers have a Properties feature to list embedded fonts and document metadata.
Many Unix systems make use of the poppler tool set
which features pdnfo to list PDF metadata, and pdonts
to list embedded fonts.

2.5.11 Useful websites


The Latex Font Catalogue
LaTeX font commands
How to change fonts in Latex
Understanding the world of TEX fonts and mastering the basics of fontinst
Font installation the shallow way For one-o
projects, you can cut corners with font installation
(i.e. fontinst) and end up with a more manageable set
of les and a cleaner TEX installation. This article
shows how and why

You will nd a huge font directory along examples and TrueType (ttf) fonts
congurations at TUG Font Catalogue.
Step-by-step guide to manually install a ttf-font for
PdfTeX

2.5.9

Using arbitrary system fonts

If you use the XeTeX or LuaTeX engine and the fontspec


package, you'll be able to use any font installed in the
system eortlessly. XeTeX also allows using OpenType
technology of modern fonts like specifying alternate
glyphs and optical size variants. XeTeX also uses
Unicode by default, which might be helpful for font issues.
To use the fonts, simply load the fontspec package and set
the font:

A bash script for installing a LaTeX font family


(MikTeX / TeXLive)
LaTeX And TrueType Font
True Type Fonts with LaTeX under Linux + MiKTeX 2.5
Unicode Truetype font installer for LaTeX under
Windows + MikTeX

Using TrueType fonts with TeX (LaTeX) and pdfThen compile the document with xelatex or lualatex.
TeX (pdfLaTeX) (for MikTeX)
Note that you can only generate .pdf les, and that you
need a suciently new TeX distribution (TeX Live 2009
should work for XeTeX and Tex Live 2010 for LuaTeX). 2.5.12 References
Also you should not load the inputenc or fontenc package. Instead make sure that your document is encoded as [1] found at the Google discussion group latexlovers

32

CHAPTER 2. COMMON ELEMENTS

2.6 LaTeX/List Structures

2.6.3 Customizing lists

Convenient and predictable list formatting is one of the


many advantages of using LaTeX. Users of WYSIWYG
word processors can sometimes be frustrated by the softwares attempts to determine when they intend lists to begin and end. As a mark-up language, LaTeX gives more
control over the structure and content of lists.

Customizing LaTeX is outside the beginners domain.


While not necessarily dicult in itself, because beginners
are already overwhelmed with the array of commands and
environments, moving on to more advanced topics runs
the risk of confusion.

2.6.1

List structures

However, since the tutorial aims at being complete, we


shall still include a brief guide on customizing lists. Feel
free to skip!

Note that in the following when \renewcommand is used


Lists often appear in documents, especially academic, as it must appear after the \begin{document} instruction so
their purpose is often to present information in a clear the changes made are taken into account. This is needed
and concise fashion. List structures in LaTeX are sim- for both enumerated and itemized lists.
ply environments which essentially come in three avors: Also beware of the spaces in the label denitions. It is a
itemize, enumerate and description.
common error!
All lists follow the basic format:
All three of these types of lists can have multiple paragraphs per item: just type the additional paragraphs in the
normal way, with a blank line between each. So long as
they are still contained within the enclosing environment,
they will automatically be indented to follow underneath
their item.

Line spacing
As you may have noticed, in standard LaTeX document
classes, the vertical spacing between items, and above and
below the lists as a whole, is more than between paragraphs: it may look odd if the descriptions are too short.

Itemize

Using packages If you want tightly-packed lists, use


the mdwlist package (included in the mdwtools bundle),
This environment is for your standard bulleted list of which provides compact, starred versions of the previitems.
ous environments, i.e. itemize*, enumerate* and description*. They work exactly in the same way, but the output
is more compact. Other packages providing compacted
Enumerate
lists are paralist and enumitem.
The enumerate environment is for ordered lists, where by Alternatively, use the memoir class and with \tightlists.
default, each item is numbered sequentially.
Description
The description environment is slightly dierent. You
can specify the item label by passing it as an optional argument (although optional, it would look odd if you didn't
include it!). Ideal for a series of denitions, such as a
glossary.

Customizing manually Inside lists you can redene


some length/dimension variables of LaTeX, for example
using:
Alternatively, to create a unied look in your document
you can redene the enumerate environment:
Another approach is to redene the \item command globally.

Sometimes you want a description where the text begins


on a new line. This cannot easily be done with \\. The
Customizing enumerated lists
trick is to use \hll[1] .

2.6.2

Nested lists

Using packages The thing people want to change most


often with Enumerated lists are the counters. A quick solution to this problem is provided by the enumerate package of David Carlisle[2] , or the more sophisticated package enumitem by Javier Bezos[3] . When using enumerate,
it is possible to specify the style of the numbering: \begin{enumerate}[style].

LaTeX will happily allow you to insert a list environment


into an existing one (up to a depth of fourif you need
more than four, use the easylist package). Simply begin
the appropriate environment at the desired point within
the current list. Latex will sort out the layout and any The options A, a, I, i and 1 dene the style and are selfexplanatory, anything else is treated as text. To use any
numbering for you.

2.6. LATEX/LIST STRUCTURES

33

of the style tokens as text they can be enclosed in braces, With package paralist
e.g. {A} will give a literal A. [4]
The paralist package provides the inparaenum environSometimes you may want to place some short text in front
ment (with an optional formatting specication in square
of the enumeration for example: Exercise 1, Exercise 2,
brackets):
Execise 3, .... This is possible with the enumitem packTo change the styles of the counter, tokens A, a, I, i, and
age:
1 can be used in the optional argument to produce the
\bfseries makes it bold, Exercise is the text and \arabic*
counter with one of the styles \Alph, \alph, \Roman, \roinserts the counter followed by a colon (:) which is treated
man and \arabic. For example: \begin{inparaenum}[(i)]
as text again.
produces the labels (i), (ii), (iii) ...
Manually To go any further and do it yourself instead, With package enumitem
a brief introduction to LaTeX counters is required. You
should check the dedicated chapter as we will not delve Package shortlst also provides inline lists.
into the details for now.
There are four individual counters that are associated with 2.6.5 Easylist package
itemized lists, each one represents the four possible levels
of nesting, which are called:
The easylist package [5] allows you to create list using a
The counter is incremented by \item before it is printed. more convenient syntax and with innite nested levels. It
is also very customizable.
For example to reset enumi use:
The command responsible for formatting the various lev- Load the package with the control character as optional
argument:
els of nesting are
The easylist environment will default to enumerations.
Example:
This simply redenes the appearance of the label, which is It features predened styles which you can set as optional
ne, providing that you do not intend to cross-reference to argument.
a specic item within the list, in which case the reference Available styles:
will be printed in the original format. This issue does not
arise if you redene the counter printer:
tractatus

Customizing itemized lists


Itemized lists are not as complex as they do not need
to count. Therefore, to customize, you simply change
the labels. It can be done manually for each entry with
\item[new symbol], eg \item[$\star$].
The itemize labels are accessed via \labelitemi, \labelitemii, \labelitemiii, \labelitemiv, for the four respective levels.
The above example would set the labels for the rst level
to a greater than (>) symbol. Of course, the text symbols
available in Latex are not very exciting. Why not use one
of the ZapfDingbat symbols, as described in the Symbols
section. Or use a mathematical symbol:

checklist - All items have empty check boxes next


to them
booktoc - Approximately the format used by the table of contents of the book class
articletoc - Approximately the format used by the
table of contents of the article class
enumerate - The default
itemize
You can customize lists with the \ListProperties(...) command and revert back the customization with \newlist{}.
Yes, thats parentheses for \ListProperties parameters.

The Style parameter sets the style of counters and text,


the Style* parameter sets the sytle of counters, and the
Itemized list with tightly set items, that is with no vertical
Style** parameter sets the style of text. The parameter
space between two consecutive items, can be created as
Numbers determines the way that the numbers are disfollows.
played and the possible values are r or R (for lower and
upper case Roman numerals), l or L (for lower and upper
case letters), a (for Arabic numbers, the default), and z
(for Zapfs Dingbats).
2.6.4 Inline lists
Inline lists can be achieved as follows.

The FinalMark parameter sets the punctuation of the nal counter (Ex: FinalMark3={)}) while FinalSpace sets

34

CHAPTER 2. COMMON ELEMENTS

the amount of space between the item and the items text. The rules for producing characters with diacritical marks,
The Margin parameter sets the distance from the left mar- such as accents, dier somewhat depending whether you
gin (Ex: FinalSpace2=1cm). The Progressive parameter are in text mode, math mode, or the tabbing environment.
sets the distance from the left margin of all items in proportion to their level.
The {{{1}}} parameter prevents the rst n counters from 2.7.1 Input encoding
appearing in all levels. If there is a number after a parameter (Ex: Style3*) then this numbers indicates the level A technical matter
that it will aect (Ex: Style3=\color{red}).
Most of the modern computer systems allow you to input
Example of custom enumerate:
letters of national alphabets directly from the keyboard. If
Note that we put the FinalMark argument between {} to you tried to input these special characters in your LaTeX
avoid LaTeX understanding it as the end of the proper- source le and compiled it, you may have noticed that
ties list. Now we change the default properties to print a they do not get printed at all.
custom itemize:
A LaTeX source document is a plain text le. A computer
Spaces in Style parameters are important. The Style* stores data in a binary format, that is a sequence of bits
parameter acts as a default value and easylist will use a (0 and 1). To display a plain text le, we need a code
which tells which sequence of bits corresponds to which
medium dash for level 1, 5 and onward.
sequence of characters. This association is called input
You can also dene custom styles using LaTeX macros: encoding, character encoding, or more informally charset.
Important note: easylist has some drawbacks. First if you For historical reasons, there are many dierent input enneed to put an easylist inside an environment using the codings. There is an attempt to unify all the encoding
same control character as the one specied for easylist, with a specication that contains all existent symbols that
you may get an error. To circumvent it, use the following are known from human history. This specication is Unicommands provided by easylist:
code. It only denes code points, which is a number for
Besides using easylist along with gures may cause some a symbol, but not the way symbols are reprensented in
trouble to the layout and the indentation. LaTeX lists do binary value. For that, unicode encodings are in charge.
There are also several unicode encodings available, UTFnot have this problem.
8 being one of them.
To use easylist with Beamer, each frame that uses easylist
The ASCII encoding is an encoding which denes 128
must be marked as fragile:
characters on 7 bits. Its widespread use has led the vast
majority of encodings to have backward compatibility
2.6.6 Notes and references
with ASCII, by dening the rst 128 characters the same
way. The other characters are added using more bits (8
[1] [Link]
or more).
[2] The enumerate package, David Carlisle 1999

This is actually a big issue, since if you do not use the


right encoding to display a le, it will show weird characters. What most programs try to do is guess statistically
[4] CTAN documentation for enumerate
the encoding by analyzing the frequent sequences of bits.
Sadly, it is not 100% safe. Some text editors may not
[5] easylist documentation
bother guessing the encoding and will just use the OS
default encoding. You should consider that other people
might not be able to display directly your input les on
2.7 LaTeX/Special Characters
their computer, because the default encoding for text le
is dierent. It does not mean that the user cannot use anIn this chapter we will tackle matters related to input enother encoding, besides the default one, only that it has
coding, typesetting diacritics and special characters.
to be congured. For example, the German umlaut on
In the following document, we will refer to special char- OS/2 is encoded as 132, with Latin1 it is encoded as 228,
acters for all symbols other than A-Za-z0-9 and English while in Cyrillic encoding cp1251 this letter does not expunctuation marks.
ist at all. Therefore you should consider encoding with
care.
This chapter is tightly linked with the font encoding issue.
You should have a look at Fonts on the topic.
The following table shows the default encodings for some
Some languages usually need a dedicated input system to operating systems.
[3] The enumitem package, Javier Bezos 2011

ease document writing. This is the case for Arabic, Chi- UTF-8 and Latin1 are not compatible. It means that if
nese, Japanese, Korean and others. This specic matter you try to open a Latin1-encoded le using a UTF-8 dewill be tackled in Internationalization.
coding, it will display odd symbols only if you used ac-

2.7. LATEX/SPECIAL CHARACTERS


cents in it, since both encoding are ASCII superset they
encode the classic letters the same way. There aren't
many advantages in using Latin1 over UTF-8, which is
technically superior. UTF-8 is also becoming the most
widely used encoding (on the Web, in modern Unices,
etc.).
Dealing with LaTeX
TeX uses ASCII by default. But 128 characters is not
enough to support non-english languages. TeX has its
own way to do that with commands for every diacritical
marking (see Escaped codes). But if we want accents and
other special characters to appear directly in the source
le, we have to tell TeX that we want to use a dierent
encoding.
There are several encodings available to LaTeX:

35
denes those symbols that are known to be available with
the current font encoding. You might encounter a situation where using UTF-8 might result in error:
! Package inputenc Error: Unicode char \u8: not set up
for use with LaTeX.
This is due to the utf8 denition not necessarily having a
mapping of all the character glyphs you are able to enter
on your keyboard. Such characters are for example

In such case, you may try need to use the utf8x option
to dene more character combinations. utf8x is not ocially supported, but can be viable in some cases. However it might break up compatibility with some packages
like csquotes.
Another possiblity is to stick with utf8 and to dene the
characters yourself. This is easy:

where codepoint is the unicode codepoint of the desired


ASCII: the default. Only bare english characters are character. TeX sequence is what to print when the charsupported in the source le.
acter matching the codepoint is met. You may nd codepoints on this site. Codepoints are easy to nd on the web.
ISO-8859-1 (a.k.a. Latin 1): 8-bits encoding. It
Example:
supports most characters for latin languages, but
Now inputting '' will eectively print ''.
thats it.
UTF-8: a Unicode multi-byte encoding. Supports With XeTeX and LuaTeX the inputenc package is no
longer needed. Both engines support UTF-8 directly and
the complete Unicode specication.
allow the use of TTF and OpenType fonts to support Uni Others...
code characters. See the Fonts section for more information.
In the following we will assume you want to use UTF-8.
There are some important steps to specify encoding.

2.7.2 Escaped codes

Make sure your text editor decodes the le in UTF8.

In addition to direct UTF-8 input, LaTeX supports the


composition of special characters. This is convenient if
your keyboard lacks some desired accents and other dia Make sure it saves your le in UTF-8. Most text critics.
editors do not make the distinction, but some do,
The following accents may be placed on letters. Although
such as Notepad++.
'o' letter is used in most of the examples, the accents may
If you are working in a terminal, make sure it is set be placed on any letter. Accents may even be placed
to support UTF-8 input and output. Some old Unix above a missing letter; for example, \~{} produces a
terminals may not support UTF-8. PuTTY is not set tilde over a blank space.
to use UTF-8 by default, you have to congure it.
The following commands may be used only in paragraph
Tell LaTeX that the source le is UTF-8 encoded.

(default) or LR (left-right) mode.

To place a diacritic on top of an i or a j, its dot has to be


inputenc [2] package tells LaTeX what the text encoding removed. The dotless version of these letters is accomplished by typing \i and \j. For example:
format of your .tex les is.
The inputenc package allows as well the user to change
the encoding within the document by means of the command \inputencoding{'encoding name'}.

\^\i should be used for i circumex '';


\"\i should be used for i umlaut ''.

If a document is to be written completely in a language


that requires particular diacritics several times, then using
The LaTeX support of UTF-8 is fairly specic: it includes the right conguration allows those characters to be writonly a limited range of unicode input characters. It only ten directly in the document. For example, to achieve easExtending the support

36

CHAPTER 2. COMMON ELEMENTS

ier coding of umlauts, the babel package can be congured as \usepackage[german]{babel}. This provides the
short hand o for \"o. This is very useful if one needs to
use some text accents in a label, since no backslash will
be accepted otherwise.

Some keyboard layouts feature the degree symbol, you


can use it directly if you are using UTF-8 and textcomp.
For better results (font quality) we recommend the use of
an appropriate font, like lmodern:

More information regarding language conguration can


be found in the Internationalization section.

2.7.3

Less than < and greater than >

The two symbols '<' and '>' are actually ASCII characters, but you may have noticed that they will print '' and
'' respectively. This is a font encoding issue. If you want
them to print their real symbol, you will have to use another font encoding such as T1, loaded with the fontenc
package. See Fonts for more details on font encoding.
Alternatively, they can be printed with dedicated commands:

2.7.4

Euro currency symbol

When writing about money these days, you need the euro
sign. The textcomp package features a \texteuro command which gives you the euro symbol as supplied by
your current text font. Depending on your chosen font
this may be quite far from the ocial symbol.

2.7.6 Other symbols

LaTeX has lots of symbols at its disposal. The majority of


An ocial version of the euro symbol is provided by eu- them are within the mathematical domain, and later chaprosym. Load it in the preamble (optionally with the o- ters will cover how to get access to them. For the more
cial option):
common text symbols, use the following commands:
then you can insert it with the \euro{} command. Finally,
if you want a euro symbol that matches with the current
font style (e.g., bold, italics, etc.) you can use a dierent
option:
again you can insert the euro symbol with \euro{}.
Alternatively you can use the marvosym package which
also provides the ocial euro symbol.
Now that you have succeeded in printing a euro sign, you
may want the '' on your keyboard to actually print the
euro sign as above. There is a simple method to do that.
You must make sure you are using UTF-8 encoding along
with a working \euro{} or \EUR{}command.
Complete example:

2.7.5

Not mentioned in above table, tilde (~) is used in LaTeX

Degree symbol for temperature and code to produce non-breakable space. To get printed tilde
math
sign, either write \~{} or \textasciitilde{}. And a visible

space can be created with \textvisiblespace.


A common mistake is to use the \circ command. It will For some more interesting symbols, the Postscript ZipfDnot print the correct character. Use the textcomp package ingbats font is available thanks to the pifont package. Add
instead, which provides a \textdegree command.
the declaration to your preamble: \usepackage{pifont}.
For temperature, you can use the same command or opt Next, the command \ding{number}, will print the specifor the gensymb package and write
ed symbol. Here is a table of the available symbols:

2.8. LATEX/INTERNATIONALIZATION

37
compose key.
Many X applications (*BSD and GNU/Linux) support
the Ctrl+Shift+u combination. A 'u' symbol should appear. Type the code point and press enter or space to
actually print the character. Example:
<Ctrl+Shift+u> 20AC <space>
will print the euro character.
Desktop environments like GNOME and KDE may feature a customizable compose key for more memorizable
sequences.
Xorg features advanced keyboard layouts with variants
that let you enter a lot of characters easily with combination using the aprioriate modier, like Alt Gr. It highly
depends on the selected layout+variant, so we suggest you
to play a bit with your keyboard, preceeding every key and
dead key with the Alt Gr modier.

2.7.9 External links


A few other LaTeX accents and symbols
NASA GISS: Accents
PDF document with a lengthy list of symbols provided by various packages
.

2.7.10 Notes and References


2.7.7

In special environments

Math mode
Several of the above and some similar accents can also be
produced in math mode. The following commands may
be used only in math mode.
When applying accents to letters i and j, you can use
\imath and \jmath to keep the dots from interfering with
the accents:
Tabbing environment
Some of the accent marks used in running text have other
uses in the tabbing environment. In that case they can be
created with the following command:
\a' for an acute accent
\a` for a grave accent
\a= for a macron accent

2.7.8

[1] For a quick explanation on character sets, see this article


on Joel Spolskis blog.
[2] For a detailed information on the package, see complete
specications written by the packages authors.

2.8 LaTeX/Internationalization
LaTeX has to be congured and used appropriately when
it is used to write documents in languages other than English. This has to address three main areas:
1. LaTeX needs to know how to hyphenate the language(s) to be used.
2. The user needs to use language-specic typographic
rules. In French for example, there is a mandatory
space before each colon character (:).
3. The input of special characters, especially for languages using an input system (Arab, Chinese,
Japanese, Korean).

Unicode keyboard input

It is convenient to be able to insert language-specic speSome operating systems provide a keyboard combination cial characters directly from the keyboard instead of usto input any Unicode code point, the so-called unicode ing cumbersome coding (for example, by typing instead

38

CHAPTER 2. COMMON ELEMENTS

of \"{a}). This can be done by conguring input encod- text according to the rules of the other language, but
ing properly. We will not tackle this issue here: see the keeps the language specic string for ancillary things like
Special Characters chapter.
gures, in the main language of the document. The enviSome languages require special fonts with the proper font ronment hyphenrules switches only the hyphenation patterns used; it can also be used to disallow hyphenation by
encoding set. See Font encoding.
using the language name 'nohyphenation'.
Some of the methods described in this chapter may be
The babel manual provides much more information on
useful when dealing with non-English author names in
these and many other options.
bibliographies.
Here is a collection of suggestions about writing a LaTeX document in a language other than English. If you 2.8.3 Multilingual versions
have experience in a language not listed below, please add
some notes about it.
It is possible in LaTeX to typeset the content of one document in several languages and to choose upon compilation which language to output. This might be convenient
2.8.1 Prerequisites
to keep a consistent sectioning and formatting across the
dierent languages. It is also useful if you make use of
Most non-english language will need to input special multiple proper nouns and other untranslated content.
characters very often. For a convenient writing you will
need to set the input encoding and the font encoding properly.
Preamble
The following conguration is optimal for many languages (most latin languages). Make sure your document Add this into the preamble. Since you cannot do this easily in LaTeX, we are going to write it in Plain TeX.
is saved using the UTF-8 encoding.
For more details check Font encoding and Special Char- You can use as many \localedef as you want. You are free
to choose the language command names. Keep it short
acters.
since you are going to use it often.

2.8.2

Babel

For an explanation on the Plain TeX code, see Macros.

The babel package by Johannes Braams and Javier Bezos Usage


will take care of everything (with XeTeX and LuaTeX
you should consider polyglossia). You can load it in your Very simple: enclose the desired content in the appropripreamble, providing as an argument name of the language ate language command. Example:
you want to use (usually its English name, but not always):
You should place it soon after the \documentclass command, so that all the other packages you load afterwards
will know the language you are using. Babel will automatically activate the appropriate hyphenation rules for
the language you choose. If your LaTeX format does not
support hyphenation in the language of your choice, babel will still work but will disable hyphenation, which has
quite a negative eect on the appearance of the typeset
document. Babel also species new commands for some
languages, which simplify the input of special characters.
See the sections about languages below for more information.
If you call babel with multiple languages:

Language choice on compilation


You can choose the language on compilation, which
might come in handy, especially if you want to generate
dierent version of the document automatically.
Remove the language selection from the source and compile with
latex '\providecommand\locale{en}\input{[Link]}'
to output the english version of your document.
See Command-line LaTeX for more details.

then the last language in the option list will be active (i.e.
Alternative choice using iang
languageB), and you can use the command
to change the active language. You can also add short The current language can also be tested by using the iang
pieces of text in another language using the command
package by Heiko Oberdiek (the built-in feature from the
Babel also oers various environments for entering larger babel package is not reliable). Here comes a simple expieces of text in another language:
ample:
The starred version of this environment typesets the main \IfLanguageName{ngerman}{Hallo}{Hello}

2.8. LATEX/INTERNATIONALIZATION

39

This allows to easily distinguish between two languages However, documents are not restricted to a single font
without the need of dening own commands. The babel encoding. For multilingual documents using Cyrillic and
language is changed by setting
Latin-based languages it makes sense to include Latin
font encoding explicitly. Babel will take care of switch\selectlanguage{english}
ing to the appropriate font encoding when a dierent language is selected within the document.

2.8.4

Specic languages

Arabic script

On modern operating systems it is benecial to use Unicode (utf8 or utf8x) instead of KOI8-RU (koi8-ru) as an
input encoding for Cyrillic text.

For languages which use the Arabic script, including Ara- In addition to enabling hyphenations, translating automatbic, Persian, Urdu, Pashto, Kurdish, Uyghur, etc., add the ically generated text strings, and activating some language
specic typographic rules (like \frenchspacing), babel
following code to your preamble:
provides some commands allowing typesetting according
You can input text in either romanized characters or na- to the standards of Bulgarian, Russian, or Ukrainian lantive Arabic script encodings. Use any of the following guages.
commands and environments to enter in text:
For all three languages, language specic punctuation is
See the ArabTeX Wikipedia article for further details.
provided: the Cyrillic dash for the text (it is little narYou may also use the Arabi package within Babel to type- rower than Latin dash and surrounded by tiny spaces), a
dash for direct speech, quotes, and commands to facilitate
set Arabic and Persian
hyphenation:
You may also copy and paste from PDF les produced
with Arabi thanks to the support of the cmap package. The Russian and Ukrainian options of babel dene the
You may use Arabi with LyX, or with tex4ht to produce commands
HTML.
which act like \Alph and \alph (commands for turning
counters into letters, e.g. a, b, c...), but produce capiSee Arabi page on CTAN
tal and small letters of Russian or Ukrainian alphabets
(whichever is the active language of the document).
Armenian
The Bulgarian option of babel provides the commands
The Armenian script uses its own characters, which will
require you to install a text editor that supports Unicode
and will allow you to enter UTF-8 text, such as Texmaker
or WinEdt. These text editors should then be congured
to compile using XeLaTeX.

which make \Alph and \alph produce letters of either


Bulgarian or Latin (English) alphabets. The default behaviour of \Alph and \alph for the Bulgarian language option is to produce letters from the Bulgarian alphabet.

See the Bulgarian translation of The Not So Short IntroOnce the text editor is set up to compile with XeLaTeX, duction to LaTeX [2] for a method to type Cyrillic letters
the fontspec package can be used to write in Armenian: directly from the keyboard using a dierent distribution.
or
The Sylfaen font lacks italic and bold, but DejaVu Serif Chinese
supports them.
See Armenian Wikibooks for further details, especially One possible Chinese support is made available thanks to
on how to congure the Unicode supporting text editors the CJK package collection. If you are using a package
manager or a portage tree, the CJK collection is usually
to compile with XeLaTeX.
in a separate package because of its size (mainly due to
fonts).
Cyrillic script
Make sure your document is saved using the UTF-8 charVersion 3.7h of babel includes support for the T2* encod- acter encoding. See Special Characters for more details.
ings and for typesetting Bulgarian, Russian and Ukrainian Put the parts where you want to write chinese characters
texts using Cyrillic letters[1] . Support for Cyrillic is based in a CJK environment.
on standard LaTeX mechanisms plus the fontenc and The last argument species the font. It must t the desired
inputenc packages. AMS-LaTeX packages should be language, since fonts are dierent for Chinese, Japanese
loaded before fontenc and babel. If you are going to use and Korean. Possible choices for Chinese include:
Cyrillics in mathmode, you also need to load mathtext
package before fontenc:
gbsn (
, simplied Chinese)
Generally, babel will automatically choose the default
gkai (
, simplied Chinese)
font encoding, for the above three languages this is T2A.

40
bsmi (
bkai (

CHAPTER 2. COMMON ELEMENTS


, traditional Chinese)

You can use the numprint package along Babel. It will let
you print numbers the French way.

, traditional Chinese)

You will also notice that the layout of lists changes when
switching to the French language. This is customizable
using the \frenchbsetup command. For more information
Czech
on what the frenchb option of babel does and how you can
customize its behavior, run LaTeX on le [Link] and
Czech is ne using
read the produced le [Link] or [Link]. You
UTF-8 allows you to have czech quotation marks di- can get the PDF version on CTAN.
rectly in your text. Otherwise, there are macros \clqq
and \crqq to produce left and right quote. You can place
German
quotated text inside \uv.

Finnish
Finnish language hyphenation is enabled with:

You can load German language support using either one


of the two following commands.
For traditional (old) German orthography use

or for reform reform (new) German orthography use


This will also automatically change document language
This enables German hyphenation, if you have cong(section names, etc.) to Finnish.
ured your LaTeX system accordingly. It also changes
all automatic text into German, e.g. Chapter becomes
Kapitel. A set of new commands also becomes availFrench
able, which allows you to write German input les more
You can load French language support with the following quickly even when you don't use the inputenc package.
Check out the table below for inspiration. With inpucommand:
tenc, all this becomes moot, but your text also is locked
There are multiple options for typesetting French doc- in a particular encoding world.
uments, depending on the avor of French: french,
frenchb, and francais for Parisian French, and acadian and In German books you sometimes nd French quotation
canadien for new-world French. If you do not know or do marks (guillemets). German typesetters, however, use
them dierently. A quote in a German book would look
not really care, we would recommend using frenchb.
like this. In the German speaking part of Switzerland,
All enable French hyphenation, if you have congured typesetters use guillemets the same way the French do.
your LaTeX system accordingly. All of these also change A major problem arises from the use of commands like
all automatic text into French: \chapter prints Chapitre, \q: If you use the OT1 font encoding (which is the de\today prints the current date in French and so on. A set fault) the guillemets will look like the math symbol "
of new commands also becomes available, which allows ", which turns a typesetters stomach. T1 encoded fonts,
you to write French input les more easily. Check out the on the other hand, do contain the required symbols. So
following table for inspiration:
if you are using this type of quote, make sure you use the
You may want to typeset guillemets and other French T1 encoding.
characters directly if your keyboard have them. Running Decimal numbers usually have to be written like 0{,}5
Xorg (*BSD and GNU/Linux), you may want to use the (not just 0,5). Packages like zier enable input like 0,5.
oss variant which features some nice shortcuts, like
You will need the T1 font encoding for guillemets to print
Greek
properly.
For the degree character you will get an error like

This is the preamble you need to write in the Greek lan! Package inputenc Error: Unicode char \u8: not set up guage. Note the particular input encoding.
for use with LaTeX.
This preamble enables hyphenation and changes all automatic text to Greek. A set of new commands also beThe textcomp package will x it for you.
comes available, which allows you to write Greek input
The great advantage of Babel for French is that it will les more easily. In order to temporarily switch to Enhandle some elements of French typography for you, es- glish and vice versa, one can use the commands \textpecially non-breaking spaces before all two-parts punctu- latin{english text} and \textgreek{greek text} that both
ation marks. So now you can write:
take one argument which is then typeset using the reThe non-breaking space before the euro symbol is still quested font encoding. Otherwise you can use the comnecessary because currency symbols and other units or mand \selectlanguage{...} described in a previous secnot supported in general (thats not specic to French).
tion. Use \euro for the Euro symbol.

2.8. LATEX/INTERNATIONALIZATION

41

Hungarian

in Korean MS-Windows, CP949/Windows-949/UHC. In


these encodings each US-ASCII character represents its
Use the following lines:
normal ASCII character similar to other ASCII compatible encodings such as ISO-8859-x, EUC-JP, Big5, or
More information in hungarian.
Shift_JIS. On the other hand, Hangul syllables, Hanjas
(Chinese characters as used in Korea), Hangul Jamos,
Hiraganas, Katakanas, Greek and Cyrillic characters and
Icelandic and Faroese
other symbols and letters drawn from KS X 1001 are
The following lines can be added to write Icelandic text: represented by two consecutive octets. The rst has its
This changes text like Part into Hluti. It makes additional MSB set. Until the mid-1990s, it took a considerable
amount of time and eort to set up a Korean-capable encommands available:
vironment under a non-localized (non-Korean) operating
To make special characters such as and become system. You can skim through the now much-outdated
available just add:
[Link] to get a glimpse of what it was like to
The default LATEX font encoding is OT1, but it contains use Korean under non-Korean OS in mid-1990s.
only the 128 characters. The T1 encoding contains letters TeX and LaTeX were originally written for scripts with
and punctuation characters for most of the European lan- no more than 256 characters in their alphabet. To make
guages using Latin script.
them work for languages with considerably more characters such as Korean or Chinese, a subfont mechanism was
developed. It divides a single CJK font with thousands or
Italian
tens of thousands of glyphs into a set of subfonts with 256
glyphs each.
Italian is well supported by LaTeX. Just add
For Korean, there are three widely used packages.
at the beginning of your document and the output of all
the commands will be translated properly.
HLATEX by UN Koaunghi
Japanese

hLATEXp by CHA Jaechoon

One possible way to write in japanese is to use Lualatex


and the luatex-ja package. An example from the Luatexja
documentation :

the CJK package by Werner Lemberg

HLATEX and hLATEXp are specic to Korean and provide Korean localization on top of the font support. They
both can process Korean input text les encoded in EUCKR. HLATEX can even process input les encoded in
CP949/Windows-949/UHC and UTF-8 when used along
Use UTF-8 as your encoding. In case you don't know with , .
how to do this, take a look at Texmaker, a LaTeX editor The CJK package is not specic to Korean. It can process
which use UTF-8 by default.
input les in UTF-8 as well as in various CJK encodings
Another (but old) possible Japanese support is made including EUC-KR and CP949/Windows-949/UHC, it
available thanks to the CJK package collection. If you can be used to typeset documents with multilingual conare using a package manager or a portage tree, the CJK tent (especially Chinese, Japanese and Korean). The CJK
collection is usually in a separate package because of its package has no Korean localization such as the one offered by HLATEX and it does not come with as many
size (mainly due to fonts).
special Korean fonts as HLATEX.
Make sure your document is saved using the UTF-8 character encoding. See Special Characters for more details. The ultimate purpose of using typesetting programs like
Put the parts where you want to write japanese characters TeX and LaTeX is to get documents typeset in an aesthetically satisfying way. Arguably the most important
in a CJK environment.
element in typesetting is a set of welldesigned fonts. The
The last argument species the font. It must t the desired HLATEX distribution includes UHC PostScript fonts of
language, since fonts are dierent for Chinese, Japanese 10 dierent families and Munhwabu fonts (TrueType) of
and Korean. min is an example for Japanese.
5 dierent families. The CJK package works with a set
of fonts used by earlier versions of HLATEX and it can
use Bitstreams cyberbit True-Type font.
Korean
To use the HLATEX package for typesetting your Korean
The two most widely used encodings for Korean text les text, put the following declaration into the preamble of
are EUC-KR and its upward compatible extension used your document:
You can also use capabilities provided by the Fontspec
package and those provided by Luatexja-fontspec to declare the font you want to use in your paper. Let us take
an example :

42
This command turns the Korean localization on. The
headings of chapters, sections, subsections, table of content and table of gures are all translated into Korean and
the formatting of the document is changed to follow Korean conventions. The package also provides automatic
particle selection. In Korean, there are pairs of post-x
particles grammatically equivalent but dierent in form.
Which of any given pair is correct depends on whether
the preceding syllable ends with a vowel or a consonant.
(It is a bit more complex than this, but this should give
you a good picture.) Native Korean speakers have no
problem picking the right particle, but it cannot be determined which particle to use for references and other
automatic text that will change while you edit the document. It takes a painstaking eort to place appropriate
particles manually every time you add/remove references
or simply shue parts of your document around. HLATEX relieves its users from this boring and error-prone
process.

CHAPTER 2. COMMON ELEMENTS


This is achieved by redening few LaTeX macros.
For books:
For articles:
Alternatively you can use dedicated document classes:
the mwart class instead of article,
mwbk instead of book
and mwrep instead of report.
Those classes have much more European typography settings but do not require the use of Polish babel settings or
character encoding.
Simple usage:

Full documentation for those classes is available at


[Link]
In case you don't need Korean localization features but [Link]/~{}pmazur/LaTeX/[Link]
just want to typeset Korean text, you can put the following (Polish).
line in the preamble, instead.
For more details on typesetting Korean with HLATEX,
refer to the HLATEX Guide. Check out the web site of Indentation It may be customary (depending on publisher) to indent the rst paragraph in sections and chapthe Korean TeX User Group (KTUG).
ters:
Persian script
Hyphenation and typography
Its much more
For Persian language, there is a dedicated package called frowned upon to set pages with hyphenation between
XePersian which uses XeLaTeX as the typesetting en- pages than it is customary in American typesetting.
gine. Just add the following code to your preamble:
To adjust penalties for hyphenation spanning pages, use
this command:
See XePersian page on CTAN
Moreover, Arabic script can be used to type Persian as To adjust penalties for leaving widows and orphans (clubs
in TeX nomenclature) use those commands:
illustrated in the corresponding section.
Commas in math According to Polish typography
rules, fractional parts of numbers should be delimited by
If you plan to use Polish in your UTF-8 encoded docu- a comma, not a dot. To make LaTeX not insert additional space in math mode after a comma (unless there is
ment, use the following code
a space after the comma), use the icomma package.
The above code merely allows to use Polish letters and
translates the automatic text to Polish, so that chapter Unfortunately, it is partially incompatible with the dcolbecomes rozdzia". There are a few additional things one umn package. One needs to either use dots in columns
with numerical data in the source le and make dcolumn
must remember about.
switch them to commas for display or dene the column
as follows:
Connectives Polish has many single letter connectives:
The alternative is to use the numprint package, but it is
a, o, w, i, u, z, etc., grammar and typography
much less convenient.
rules don't allow for them to end a printed line. To ensure
that LaTeX won't set them as last letter in the line, you
have to use non breakable space:
Further information
Refer the Sownik Ortograczny (in Polish) for additional information on
Numerals According to Polish grammar rules, you Polish grammar and typography rules.
Polish

have to put dots after numerals in chapter, section, sub- Good extract is available at Zasady Typograczne
Skadania Tekstu (in Polish).
section, etc. headers.

2.9. LATEX/ROTATIONS
Portuguese
Add the following code to your preamble:

43
command supports accented or spaced operators: the
\acute{<letter>} command puts an accent, and the \,
command adds a small space. For instance, the following operators are dened by default.

You can substitute the language for brazilian portuguese


Finally, the macro \spanishdeactivate{<list of characby choosing brazilian.
ters>} disables some active characters, to keep you out
of trouble if they are redened by other packages. The
Slovak
candidates for deactivation are the set {<>."'}. Please,
beware that some option preempt the availability of some
Basic settings are ne when left the same as Czech, but active characters. In particular, you should not combine
Slovak needs special signs for '', '', ''. To be able to the es-noquoting option with \spanishdeactivate{<>}, or
type them from keyboard use the following settings:
the es-noshorthands with \spanishdeactivate{<>."}.
Spanish

Please check the documentation for Babel or [Link]


for further details.

Include the appropriate Babel option:

Tibetan

The trick is that Spanish has several options and commands to control the layout. The options may be loaded
either at the call to Babel, or before, by dening the command \spanishoptions. Therefore, the following commands are roughly equivalent:

One option to use Tibetan script in LaTeX is to add

to your preamble and use a slightly modied Wylie


transliteration for input. Refer to the excellent package documentation for details. More information can be
On average, the former syntax should be preferred, as the found on
latter is a deviation from standard Babel behavior, and
thus may break other programs (LyX, latex2rtf) interact2.8.5 References
ing with LaTeX.
Spanish also denes shorthands for the dot and << >> so
that they are used as logical markup: the former is used as
decimal marker in math mode, and the output is typically
either a comma or a dot; the latter is used for quoted text,
and the output is typically either or . This allows
dierent typographical conventions with the same input,
as preferences may be quite dierent from, say, Spain and
Mexico.

[1] The Not So Short Introduction to LaTeX, 2.5.6 Support


for Cyrillic, Maksym Polyakov
[2] The Not So Short Introduction to LaTeX, Bulgarian translation

2.9 LaTeX/Rotations

Two particularly useful options are es-noquoting,esnolists: some packages and classes are known to collide
with Spanish in the way they handle active characters, and
these options disable the internal workings of Spanish to
allow you to overcome these common pitfalls. Moreover,
these options may simplify the way LyX customizes some
features of the Spanish layout from inside the GUI.

2.9.1 The rotating package

The options mexico,mexico-com provide support for local custom in Mexico: the former using decimal dot, as
customary, and the latter allowing decimal comma, as required by the Mexican Ocial Norm (NOM) of the Department of Economy for labels in foods and goods. More
localizations are in the making.

it will rotate the whole argument by 90 degrees counterclockwise. Moreover:

The package rotating gives you the possibility to rotate


any object of an arbitrary angle. Once you have loaded it
with the standard command in the preamble:
you can use three new environments:

it will turn the argument of 30 degrees. You can give any


angle as an argument, whether it is positive or negative.
It will leave the necessary space to avoid any overlapping
of text.

The other commands modify the spanish layout after like turn, but it will not add any extra space.
loading Babel. Two particularly useful commands are
If you want to make a oat sideways so that the caption is
\spanishoperators and \spanishdeactivate.
also rotated, you can use
The macro \spanishoperators{<list of operators>}{ contains a list of spanish mathematical operators, and may or
Note, though, they will be placed on a separate page.
be redened at will. For instance, the command
only denes sen, overriding all other denitions; the com- If you would like to rotate a TikZ picture you could use
mand \let\spanishoperators\relax disables them all. This sideways together with minipage.

44

CHAPTER 2. COMMON ELEMENTS

You can also use the \rotatebox command. Lets rotate a always being compatible with one another. Sometimes
tabular inside a table for example:
you had to make trade-os. The situation changed recently (2010) with the release of the tabu package which
combines the power of longtable, tabularx and much
Options
more. The tabu environment is far less fragile and restricted than the older alternatives. Nonetheless, before
Default is sidewaysgures/sidewaystables are oriented de- attempting to use this package for the rst time it will
pending on page number in two sided documents (takes be benecial to understand how the classic environment
two passes).
works, since tabu works the same way. Note however that
the author of tabu will not x bugs to the current version,
The rotating package takes the following options.
and that the next version introduces new syntax that will
[1]
counterclockwise/anticlockwise In single sided docu- likely break existing documents.
ments turn sidewaysgures/sidewaystables counterclockwise.
clockwise In single sided documents turn sidewaysg- 2.10.1 The tabular environment
ures/sidewaystables clockwise (default).
The tabular environment can be used to typeset tables
guresright In two sided documents all sidewaysg- with optional horizontal and vertical lines. LaTeX deures/sidewaystables are same orientation (left of g- termines the width of the columns automatically.
ure, table now bottom of page). This is the style
preferred by the Chicago Manual of Style (broad- The rst line of the environment has the form:
side).
The table spec argument tells LaTeX the alignment to be
used in each column and the vertical lines to insert.
guresleft In two sided documents all sidewaysgures/sidewaystables are same orientation (left of g- The number of columns does not need to be specied as
it is inferred by looking at the number of arguments proure, table now at top of page).
vided. It is also possible to add vertical lines between the
columns here. The following symbols are available to de2.9.2 The rotoat package
scribe the table columns (some of them require that the
package array has been loaded):
When it is desirable to place the rotated table at the exact
By default, if the text in a column is too wide for the page,
location where it appears in the source (.tex) le, rotoat
LaTeX wont automatically wrap it. Using p{'width'}
package may be used. Then one can use
you can dene a special type of column which will wrapjust like for normal tables. The H option can not be used around the text as in a normal paragraph. You can pass
without this package.
the width using any unit supported by LaTeX, such as 'pt'
and 'cm', or command lengths, such as \textwidth. You
can nd a list in chapter Lengths.

2.10 LaTeX/Tables

The optional parameter pos can be used to specify the


vertical position of the table relative to the baseline of the
Tables are a common feature in academic writing, often surrounding text. In most cases, you will not need this
used to summarise research results. Mastering the art of option. It becomes relevant only if your table is not in a
table construction in LaTeX is therefore necessary to pro- paragraph of its own. You can use the following letters:
duce quality papers and with sucient practice one can
To specify a font format (such as bold, italic, etc.) for
print beautiful tables of any kind.
an entire column, you can add >{\format} before you
Keeping in mind that LaTeX is not a spreadsheet, it makes
sense to use a dedicated tool to build tables and then to
export these tables into the document. Basic tables are not
too taxing, but anything more advanced can take a fair bit
of construction; in these cases, more advanced packages
can be very useful. However, rst it is important to know
the basics. Once you are comfortable with basic LaTeX
tables, you might have a look at more advanced packages
or the export options of your favorite spreadsheet. Thanks
to the modular nature of LaTeX, the whole process can
be automated in a fairly comfortable way.

declare the alignment. For example \begin{tabular}{


>{\bfseries}l c >{\itshape}r } will indicate a three column table with the rst one aligned to the left and in bold
font, the second one aligned in the center and with normal
font, and the third aligned to the right and in italic. The
array package needs to be activated in the preamble for
this to work.

In the rst line you have pointed out how many columns
you want, their alignment and the vertical lines to separate
them. Once in the environment, you have to introduce
the text you want, separating between cells and introducFor a long time, LaTeX tables were quite a chaotic topic, ing new lines. The commands you have to use are the
with dozens of packages doing similar things, while not following:

2.10. LATEX/TABLES

45

Note, any white space inserted between these commands Manually broken paragraphs in table cells
is purely down to ones preferences. I personally add
Sometimes it is necessary to not rely on the breaking alspaces between to make it easier to read.
gorithm when using the p specier, but rather specify the
line breaks by hand. In this case it is easiest to use a \parbox:
Basic examples
This example shows how to create a simple table in La- Space between columns
TeX. It is a three-by-three table, but without any lines.
To tweak the space between columns (LaTeX will by deExpanding upon that by including some vertical lines:
fault choose very tight columns), one can alter the colTo add horizontal lines to the very top and bottom edges umn separation: \setlength{\tabcolsep}{5pt}. The default value is 6pt.
of the table:
And nally, to add lines between all rows, as well as
centering (notice the use of the center environment - of Space between rows
course, the result of this is not obvious from the preview
on this web page):
Re-dene the \arraystretch command to set the space between rows:
Default value is 1.0.
Text wrapping in tables

An alternative way to adjust the rule spacing is to


add \noalign{\smallskip} before or after the \hline and
LaTeXs algorithms for formatting tables have a few \cline{i-j} commands:
shortcomings. One is that it will not automatically wrap You may also specify the skip after a line explicitly using
text in cells, even if it overruns the width of the page. glue after the line terminator
For columns that will contain text whose length exceeds
the columns width, it is recommended that you use the p
attribute and specify the desired width of the column (al- Other environments inside tables
though it may take some trial-and-error to get the result
you want). For a more convenient method, have a look at If you use some LaTeX environments inside table cells,
The tabularx package, or The tabulary package.
like verbatim or enumerate:
Instead of p, use the m attribute to have the lines aligned you might encounter errors similar to
toward the middle of the box or the b attribute to align
! LaTeX Error: Somethings wrong--perhaps a missing
along the bottom of the box.
\item.
Here is a simple example. The following code creates two
To solve this problem, change column specier to paratables with the same code; the only dierence is that the
graph (p, m or b).
last column of the second one has a dened width of 5
centimeters, while in the rst one we didn't specify any
width. Compiling this code:
Dening multiple columns
You get the following output:
It is possible to dene many identical columns at once
using the *{''num''}{''str''} syntax. This is particularly
useful when your table has many columns.
Here is a table with six centered columns anked by a
single column on each side:
Column specication using >{\cmd} and <{\cmd}
The column specication can be altered using the array
package. This is done in the argument of the tabular environment using >{\command} for commands executed
right before each column element and <{\command} for
commands to be executed right after each column eleNote that the rst table has been cropped, since the output ment. As an example: to get a column in math mode enis wider than the page width.
ter: \begin{tabular}{>{$}c<{$}}. Another example is

46

CHAPTER 2. COMMON ELEMENTS

changing the font: \begin{tabular}{>{\small}c} to print specier for oating point data. See the dcolumn package
the column in a small font.
documentation for more information, but a simple way to
The argument of the > and < specications must be cor- use dcolumn is as follows.
rectly balanced when it comes to { and } characters.
This means that >{\bfseries} is valid, while >{\textbf}
will not work and >{\textbf{} is not valid. If there
is the need to use the text of the table as an argument (for instance, using the \textbf to produce bold
text), one should use the \bgroup and \egroup commands:
>{\textbf\bgroup}c<{\egroup} produces the intended effect. This works only for some basic LaTeX commands.
For other commands, such as \underline to underline text,
it is necessary to temporarily store the column text in a
box using lrbox. First, you must dene such a box with
\newsavebox{\boxname} and then you can dene:
This stores the text in a box and afterwards, takes the text
out of the box with \unhbox (this destroys the box, if the
box is needed again one should use \unhcopy instead) and
passing it to \underline. (For LaTeX2e, you may want to
use \usebox{\boxname} instead of \unhbox\boxname.)

A negative argument provided for the number of decimal


places in the new column type allows unlimited decimal
places, but may result in rather wide columns. Rounding is not applied, so the data to be tabulated should
be adjusted to the number of decimal places specied.
Note that a decimal aligned column is typeset in math
mode, hence the use of \mathrm for the column heading in the example above. Also, text in a decimal aligned
column (for example the header) will be right-aligned before the decimal separator (assuming theres no decimal
separator in the text). While this may be ne for very
short text, or numeric column headings, it looks cumbersome in the example above. A solution to this is to
use the \multicolumn command described below, specifying a single column and its alignment. For example to center the header Decimal over its column in the
above example, the rst line of the table itself would be
Left&Right&Center&\multicolumn{1}{c}{Decimal}\\

This same trick done with \raisebox instead of \underline


can force all lines in a table to have equal height, instead of
the natural varying height that can occur when e.g. math Bold text and dcolumn To draw attention to particular
entries in a table, it may be nice to use bold text. Orditerms or superscripts occur in the text.
narily this is easy, but as dcolumn needs to see the deciHere is an example showing the use of both p{...} and
mal point it is rather harder to do. In addition, the usual
>{\centering} :
bold characters are wider than their normal counterparts,
Note the use of \tabularnewline instead of \\ to avoid a meaning that although the decimals may align nicely, the
Misplaced \noalign error.
gures (for more than 2-3 digits on one side of the decimal point) will be visibly misaligned. It is however possible to use normal width bold characters and dene a new
@-expressions
bold column type, as shown below.[2]
The column separator can be specied with the @{...}
construct.
2.10.2 Row specication
It typically takes some text as its argument, and when appended to a column, it will automatically insert that text It might be convenient to apply the same command over
into each cell in that column before the actual data for every cell of a row, just as for column. Unfortunately the
that cell. This command kills the inter-column space and tabular environment cannot do that by default. We will
replaces it with whatever is between the curly braces. To need tabu instead, which provides the \rowfont option.
add space, use @{\hspace{''width''}}.
Admittedly, this is not that clear, and so will require a few 2.10.3 Spanning
examples to clarify. Sometimes, it is desirable in scientic tables to have the numbers aligned on the decimal To complete this tutorial, we take a quick look at how
point. This can be achieved by doing the following:
to generate slightly more complex tables. Unsurprisingly,
The space-suppressing qualities of the @-expression ac- the commands necessary have to be embedded within the
tually make it quite useful for manipulating the horizontal table data itself.
spacing between columns. Given a basic table, and varying the column descriptions:
Rows spanning multiple columns
Aligning columns at decimal points using dcolumn
Instead of using @-expressions to build columns of decimals aligned to the decimal point (or equivalent symbol),
it is possible to center a column on the decimal separator
using the dcolumn package, which provides a new column

The command for this looks like this: \multicolumn{'num_cols}{'alignment'}{'contents}. num_cols is


the number of subsequent columns to merge; alignment
is either l, c, r, or to have text wrapping specify a width
p{5.0cm} . And contents is simply the actual data you
want to be contained within that cell. A simple example:

2.10. LATEX/TABLES

47

Columns spanning multiple rows

notesize) in the table scope, which may be after the \begin{table} statement if you use oats, otherwise you need
The rst thing you need to do is add \usepack- to add a group delimiter.
age{multirow} to the preamble[3] . This then proAlternatively, you can change the default font for all the
vides the command needed for spanning rows: \multables in your document by placing the following code in
tirow{''num_rows'}{''width''}{''contents'}. The arguthe preamble:
ments are pretty simple to deduce (* for the width means
See Fonts for named font sizes. The table caption font
the contents natural width).
size is not aected. To control the caption font size, see
The main thing to note when using \multirow is that a
Caption Styles.
blank entry must be inserted for each appropriate cell in
each subsequent row to be spanned.
If there is no data for a cell, just don't type anything, but 2.10.5 Colors
you still need the "&" separating it from the next columns
data. The astute reader will already have deduced that for Alternate row colors in tables
a table of n columns, there must always be n 1 ampersands in each row (unless \multicolumn is also used).
The xcolor package provides the necessary commands
to produce tables with alternate row colors, when
loaded with the table option. The command \rowcolSpanning in both directions simultaneously
ors{<''starting row''>}{<''odd color''>}{<''even color''>}
Here is a nontrivial example of how to use spanning in has to be specied right before the tabular environment
both directions simultaneously and have the borders of starts.
the cells drawn correctly:

The command \hiderowcolors is available to deactivate


highlighting from a specied row until the end of the table. Highlighting can be reactivated within the table via
the \showrowcolors command. If while using these commands you experience misplaced \noalign errors then
use the commands at the very beginning or end of a row
in your tabular.

The command \multicolumn{1}{ is just used to draw


vertical borders both on the left and on the right of the
cell. Even when combined with \multirow{2}{*}{...}, it
still draws vertical borders that only span the rst row.
To compensate for that, we add \multicolumn{1}{ in the
following rows spanned by the multirow. Note that we
cannot just use \hline to draw horizontal lines, since we or
do not want the line to be drawn over the text that spans
several rows. Instead we use the command \cline{2-6}
and opt out the rst column that contains the text Pow- Colors of individual Cells
ers.
Here is another example exploiting the same ideas to As above this uses the xcolor package.
make the familiar and popular 2x2 or double dichotomy:

2.10.4

2.10.6 Width and stretching

Controlling table size

We keep providing documentation for tabular* and tabularx although they are completely eclipsed by the much
Resize tables
more powerful and exible tabu environment. Actually
tabu is greatly inspired by those environments, so it may
The graphicx packages features the command \resize- be worth it to have an idea how they work, particularly
box{width}{height}{object} which can be used with tab- for tabularx.
ular to specify the height and width of a table. The following example shows how to resize a table to 8cm width
while maintaining the original width/height ratio.
The tabular* environment
Resizing table including the caption

This is basically a slight extension on the original tabular


Alternatively you can use \scalebox{ratio}{object} in the version, although it requires an extra argument (before the
same way but with ratios rather than xed sizes:
column descriptions) to specify the preferred width of the
table.
However, that may not look quite as intended. The
columns are still at their natural width (just wide enough
A table can be globally switched to a dierent font size to t their contents) while the rows are as wide as the table
by simply adding the desired size command (here: \foot- width specied. If you do not like this default, you must
Changing font size

48
also explicitly insert extra column space. LaTeX has rubber lengths, which, unlike others, are not xed. LaTeX
can dynamically decide how long the lengths should be.
So, an example of this is the following.

CHAPTER 2. COMMON ELEMENTS


The rst parameter is the maximum width. tabulary will
try not to exceed it, but it will not stretch to it if there is
not enough content, contrary to tabularx.

The second parameter is the column disposition. Possible


You will notice the @{...} construct added at the begin- values are those from the tabular environment, plus
ning of the column description. Within it is the \extra- These are all capitals.
colsep command, which requires a width. A xed width
could have been used. However, by using a rubber length,
such as \ll, the columns are automatically spaced evenly. The tabu environment
The tabularx package

It works pretty much like tabularx.

'to \linewidth' species the target width. The X parameter


This package provides a table environment called tabu- can have an optional span factor.
larx which is similar to the tabular* environment, except
that it has a new column specier X (in uppercase). The
column(s) specied with this specier will be stretched 2.10.7 Table across several pages
to make the table as wide as specied, greatly simplifyLong tables are natively supported by LaTeX thanks to
ing the creation of tables.
the longtable environment. Unfortunately this environThe content provided for the boxes is treated as for a ment does not support stretching (X columns).
p column, except that the width is calculated automatically. If you use the package array, you may also apply The tabu packages provides the longtabu environment. It
any >{\cmd} or <{\cmd} command to achieve specic has most of the features of tabu, with the additional cabehavior (like \centering, or \raggedright\arraybackslash) pability to span multiple pages.
as described previously.
LaTeX can do well with long tables: you can specify a
Another option is the use of \newcolumntype in order to header that will repeat on every page, a header for the
get selected columns formatted in a dierent way. It de- rst page only, and the same for the footer.
nes a new column specier, e.g. R (in uppercase). In It uses syntax similar to longtable, so you should have a
this example, the second and fourth column is adjusted look at its documentation if you want to know more.
in a dierent way (\raggedleft):
Alternatively you can try one of the following packages
Tabularx with rows spanning multiple columns using supertabular or xtab, an extended and somewhat im\multicolumn. The two central columns are posing as one proved version of supertabular.
by using the X@{} option. Note that the \multicolumn
width (which in this example is 2) should equal the (in
this example 1+1) width of the spanned columns:
2.10.8 Partial Vertical Lines
In a way analogous to how new commands with arguments can be created with \newcommand, new column Adding a partial vertical line to an individual cell:
types with arguments can be created with \newcolumn- Removing part of a vertical line in a particular cell:
type as follows:
where since there are 4 columns, the sum of the \hsizes
(1 + 0.5 + 0.5 + 2) must be equal to 4. The default value 2.10.9 Vertically centered images
used by tabularx for \hsize is 1.
Inserting images into a table row will align it at the top of
the cell. By using the array package this problem can be
solved. Dening a new columntype will keep the image
The tabulary package
vertically centered.
tabulary is a modied tabular* allowing width of columns Or use a parbox to center the image.
set for equal heights. tabulary allows easy and convenient
A raisebox works as well, also allowing to manually newriting of well balanced tables.
tune the alignment with its rst parameter.
The problem with tabularx is that it leaves much blank if
your cells are almost empty. Besides, it is not easy to have
dierent column sizes.
2.10.10 Footnotes in tables
tabulary tries to balance the column widths so that each
column has at least its natural width, without exceeding The tabular environment does not handle footnotes properly. The longtabular xes that.
the maximum length.

2.10. LATEX/TABLES

49

Instead of using longtabular we recommend tabu which Using array


handles footnotes properly, both in normal and long ta\usepackage{array}
bles.
%or \usepackage{dcolumn}
...
\begin{tabular}{llr}
\rsthline
2.10.11 Professional tables
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Many professionally typeset books and journals feature Animal & Description & Price (\$) \\
simple tables, which have appropriate spacing above and \hline
below lines, and almost never use vertical rules. Many ex- Gnat & per gram & 13.65 \\
amples of LaTeX tables (including this Wikibook) show- & each & 0.01 \\
case the use of vertical rules (using "|"), and double-rules Gnu & stued & 92.50 \\
(using \hline\hline or "||"), which are regarded as unnec- Emu & stued & 33.33 \\
essary and distracting in a professionally published form. Armadillo & frozen & 8.99 \\
The booktabs package is useful for easily providing this \lasthline
professionalism in LaTeX tables, and the documentation \end{tabular}
also provides guidelines on what constitutes a good table.
Using booktabs
In brief, the package uses \toprule for the uppermost rule
(or line), \midrule for the rules appearing in the middle \usepackage{booktabs}
of the table (such as under the header), and \bottom- ...
rule for the lowermost rule. This ensures that the rule \begin{tabular}{llr}
weight and spacing are acceptable. In addition, \cmidrule \toprule
can be used for mid-rules that span specied columns. \multicolumn{2}{c}{Item} \\
The following example contrasts the use of booktabs and \cmidrule(r){1-2}
two equivalent normal LaTeX implementations (the sec- Animal & Description & Price (\$) \\
ond example requires \usepackage{array} or \usepack- \midrule
age{dcolumn}, and the third example requires \usepack- Gnat & per gram & 13.65 \\
& each & 0.01 \\
age{booktabs} in the preamble).
Gnu & stued & 92.50 \\
Emu & stued & 33.33 \\
Armadillo & frozen & 8.99 \\
\bottomrule
Normal LaTeX
\end{tabular}
\begin{tabular}{llr}
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stued & 92.50 \\
Emu & stued & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}

Usually the need arises for footnotes under a table (and


not at the bottom of the page), with a caption properly
spaced above the table. These are addressed by the ctable
package. It provides the option of a short caption given
to be inserted in the list of tables, instead of the actual
caption (which may be quite long and inappropriate for
the list of tables). The ctable uses the booktabs package.

2.10.12 Sideways tables


Tables can also be put on their side within a document using the rotating or the rotoat package. See the Rotations

50

CHAPTER 2. COMMON ELEMENTS

chapter.

2.10.13

The environment names may now seem quite confusing.


Lets sum it up:

Table with legend

tabular is for the content itself (columns, lines, etc.).

table is for the location of the table on the document,


To add a legend to a table the caption package can be
plus caption and label support.
used. With the caption package a \caption*{...} statement can be added besides the normal \caption{...}. Ex- In the table, we used a label, so now we can refer to it just
ample:
like any other reference:
The normal caption is needed for labels and references.
The table environment is also useful when you want to

2.10.14

The eqparbox package

On rare occasions, it might be necessary to stretch every row in a table to the natural width of its longest line,
for instance when one has the same text in two languages
and wishes to present these next to each other with lines
synching up. A tabular environment helps control where
lines should break, but cannot justify the text, which leads
to ragged right edges. The eqparbox package provides
the command \eqmakebox which is like \makebox but instead of a width argument, it takes a tag. During compilation it bookkeeps which \eqmakebox with a certain tag
contains the widest text and can stretch all \eqmakeboxes
with the same tag to that width. Combined with the array
package, one can dene a column specier that justies
the text in all lines:

have a list of tables at the beginning or end of your document with the command
The captions show now up in the list of tables, if displayed.
You can set the optional parameter position specier to
dene the position of the table, where it should be placed.
The following characters are all possible placements. Using sequences of it dene your wishlist to LaTeX.
Default is tbp, which means that it is by default placed on
the top of the page. If thats not possible, its placed at
the bottom if possible, or nally with other oating environments on an extra page.

You can force LaTeX to use one given position. E.g. [!h]
forces LaTeX to place it exactly where you place it (Except when its really impossible, e.g you place a table here
and this place would be the last line on a page). Again,
understand it correctly: it urges LaTeX to put the table at
See the documentation of the eqparbox package for more a specic place, but it will not be placed there if LaTeX
details.
thinks it will not look great. If you really want to place
your table manually, do not use the table environment.
Centering the table horizontally works like everything
else, using the \centering command just after opening the
table environment, or by enclosing it with a center enviIn WYSIWYG document processors, it is common to put
ronment.
tables in the middle of the text. This is what we have
been doing until now. Professional documents, however,
often make it a point to print tables on a dedicated page 2.10.16 Using spreadsheets
so that they do not disrupt the ow. From the point of
view of the source code, one has no idea on which page For complex or dynamic tables, you may want to use a
the current text is going to lie, so it is hardly possible to spreadsheet. You might save lots of time by building taguess which page may be appropriate for our table. La- bles using specialized software and exporting them in LaTeX can automate this task by abstracting objects such TeX format. The following plugins and libraries are availas tables, pictures, etc., and deciding for us where they able for some popular software:
might t best. This abstraction is called a oat. Generally, an object that is oated will appear in the vicinity of
calc2latex: for [Link] Calc spreadsheets,
its introduction in the source le, but one can choose to
excel2latex: for Microsoft Oce Excel,
control its position also.

2.10.15

Floating with table

To tell LaTeX we want to use our table as a oat, we need


to place a tabular environment in a table environment,
which is able to oat and add a label and caption.

matrix2latex: for MATLAB,

The table environment initiates a type of oat just as the


environment gure. In fact, the two bear a lot of similarities (positioning, captions, etc.). More information
about oating environments, captions etc. can be found
in Floats, Figures and Captions.

latex-tools: a Ruby library,

matrix2latex: for Python and MATLAB,

xtable: a library for R,


org-mode: for Emacs users, org-mode tables can be
used inline in LaTeX documents, see for a tutorial.

2.11. LATEX/TITLE CREATION

51

Emacs align commands: the align commands can 2.10.18


clean up a messy LaTeX table.
Online Table generator for LATeX: An online tool
for creating simple tables within the browser. LaTeX format is directly generated as you type.
However, copying the generated source code to your document is not convenient at all. For maximum exibility,
generate the source code to a separate le which you can
input from your main document le with the \input command. If your speadsheet supports command-line, you
can generate your complete document (table included) in
one command, using a Makele for example.
See Modular Documents for more details.

2.10.17

Need more complicated features?

References

[1] [Link]
is-the-tabu-package-obsolete
[2] D Carlisle.
Decimals in table don't align
Stackexchange.
with dcolumn when bolded.
[Link]
decimals-in-table-dont-align-with-dcolumn-when-bolded.
[3] Package multirow on CTAN

2.11 LaTeX/Title Creation


For documents such as basic articles, the output of
\maketitle is often adequate, but longer documents (such
as books and reports) often require more involved formatting. We will detail the process here.

There are several situations where you might want to create a title in a custom format, rather than in the format na hhline: do whatever you want with horizontal lines tively supported by LaTeX. While it is possible to change
the output of \maketitle, it can be complicated even with
array: gives you more freedom on how to dene minor changes to the title. In such cases it is often better
columns
to create the title from scratch, and this section will show
you how to accomplish this.
colortbl: make your table more colorful

Have a look at one of the following packages:

threeparttable makes it possible to put footnotes


2.11.1
both within the table and its caption

Standard Title Pages

arydshln: creates dashed horizontal and vertical Many document classes will form a title page for you.
lines
One must specify what to ll it with using these commands placed in the top matter:
ctable: allows for footnotes under table and properly
spaced caption above (incorporates booktabs pack- Commonly the date is excluded from the title page by using \date{}. It defaults to \today if not in the source le.
age)
slashbox: create 2D tables with the rst cell contain- To form a title page, use
ing a description for both axes. Not available in Tex This should go after the preceding commands. For most
Live 2011 or later.
document styles, this will form a separate page, while the
article document style will place the title on the top of
diagbox: compatible to slashbox, come with Tex
the rst page. Note that the abstract environment should
Live 2011 or later
precede the \maketitle command in AMS documents.
dcolumn: decimal point alignment of numeric cells Footnotes within the title page can be specied with the
rccol: advanced decimal point alignment of numeric \thanks command. For example, one may add
cells with rounding
The \thanks command can also be used in the \title.
numprint: print numbers, in the current mode (text
or math) in order to use the correct font, with
separators, exponent and/or rounded to a given
number of digits. tabular(*), array, tabularx, and
longtable environments is supported using all features of numprint

It is dependent on the document class which commands


are used in the title page generated by \maketitle. For
example, the amsart uses commands such as \address,
\dedicatory, \email and more in the title page while other
classes may only use \title.

spreadtab: spread sheets allowing the use of formu- 2.11.2 Custom Title Pages
lae
Create the title
siunitx: alignment of tabular entries
pgfplotstable: Loads, rounds, formats and postpro- Normally, the benet of using LaTeX instead of tradicesses numerical tables.
tional word processing programs is that LaTeX frees you

52

CHAPTER 2. COMMON ELEMENTS

to concentrate on content by handling margins, justicagin{gure} as you usually do because you don't want
tion, and other typesetting concerns. On the other hand,
it to be oating, you just want it there where you
if you want to write your own title format, it is exactly
placed it. When handling it, remember that it is considered like a big box by the TeX engine.
the opposite: you have to take care of everything--this
time LaTeX will do nothing to help you. It can be challenging to create your own title format since LaTeX was Text size If you want to change the size of some text just
not designed to be graphically interactive in the adjustplace it within brackets, {like this}, and you can use
ment of layout. The process is similar to working with
the following commands (in order of size): \Huge,
raw HTML with the added step that each time you want
\huge, \LARGE, \Large, \large, \small, \footnoteto see how your changes look, you have to re-compile the
size, \tiny. So for example:
source. While this may seem like a major inconvenience,
the benet is that once the customized title format has
been written, it serves as a template for all other docu- \normalsize is used to create text at the default size for
ments that would use the title format you have just made.
the document.
In other words, once you have a layout you like, you can
use it for any other documents where you would like the
New lines you can force the start of a new line by \\.
same layout without any additional ddling with layout.
If you want to add more vertical space, do so by
First step: since you'll be working only on the rst page
adding the desired space in square brackets after the
of your document and you'll have to compile very often,
\\ command. For example, \\[1cm] will insert 1 cm
you don't have to compile the whole document each time,
of empty space before the new line (which will not
you only need to take a look at the rst page. That is
be indented). Using multiple \\ commands will prowhy we'll rst create a dummy document for preparing
duce Underfull hbox messages.
the title and then we'll simply include it within the existing
big document we are writing. Call the dummy document Date you can insert the date of the current day with the
test_title.tex and put the following code in it:
command \today. If you do not wish to insert any
It is meant to be compiled with pdatex to create a PDF
as its output. It is a very basic document, but take care
that it has the same settings of the document you are writing, so the output won't change when you include the title
in your document. In this case (see the rst line) the font
size is set to 12pt and the paper size is an A4. The package graphicx is included to insert an image in the title.
Then a command is dened called \HRule; it will just insert a horizontal line whose length is equal to a line of text
and whose thickness is 0.5 mm. (Note that you will need
to precede the command \HRule with \noindent, otherwise it will be indented and you will get an overfull hbox
warning equal to the normal indent of a paragraphs rst
line.) If you want you can change its settings in the denition. Finally the document starts and it simply includes
the [Link] le, that must be placed in the same directory
of our dummy le test_title.tex.
Now create the [Link] and write in it:
all the things you want to put in the title must be inside the
titlepage environment. Now if you compile test_title.tex
you will see a preview of your title in the test_title.pdf
le. Here is what you need to know to write your title:

date, keep it blank e.g.\date{}


Filling the page the command \vll as the last item of
your content will add empty space until the page is
full. If you put it within the page, you will ensure
that all the following text will be placed at the bottom
of the page.

A practical example
All these tips might have made you confused. Then, here
is a practical example. Get the test_title.tex described
above and here is an example of a [Link]. On the right
you can see the output after you compile test_title.tex in
PDF:
The picture is from a le called [Link] that is in the
same directory of both [Link] and test_title.tex. Since
I wanted to insert both the author and supervisor names
properly aligned I used a trick: I created two small minipages, one on left and one on the right. Their width is a
bit less than half of page width (as you can see, they are
exactly 40% of the text width). Within the minipages I
have used dierent alignments. Using \vll I could write
the date exactly at the bottom of the page.

Alignment if you want to center some text just use \begin{center} ... \end{center}. If you want to align
it dierently you can use the environment ushright
for right-alignment and ushleft for left-alignment. As you can see, the code looks dirtier than standard
LaTeX source because you have to take care of the output
Images the command for including images is the fol- as well. If you start changing fonts output it will get more
lowing (the example is for a small logo, but you can confused, but you can do it: its only for the title and your
introduce any image of any size): \includegraph- complicated code will be isolated from all the rest within
ics[width=0.15\textwidth]{./logo}. There is no \be- its own le [Link].

2.12. LATEX/PAGE LAYOUT

53

Integrating the title page

2.12.2 Page dimensions

Assuming that your title page is now contained in a


le named [Link], it must be placed in the same directory as the main document. In order to integrate
it, the input command must be used by placing \input{./[Link]} at the top of the document. Don't forget to
add the commands \usepackage[pdftex]{graphicx} and
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} in
the preamble section as well.

A page in LaTeX is dened by many internal parameters. Each parameter corresponds to the length of an element of the page, for example, \paperheight is the physical height of the page. Here you can see a diagram showing all the variables dening the page. All sizes are given
in TeX points (pt), there are 72.27pt in an inch or 1pt
0.3515mm.

For example, the top section of your document would


look like:

4
5
Header

2.11.3

Packages for custom titles

The titling package[1] provides control over the typesetting of the \maketitle and \thanks commands. The titlepages package presents many styles of designs for title
pages. Italian users may also want to use the frontespizio
package[2] .
Margin notes

2.11.4

Body

Notes and References


9

[1] Titling package webpage in CTAN

10
3

[2] Frontespizio package webpage in CTAN


8
11

2.12 LaTeX/Page Layout

Footer

LaTeX and the document class will normally take care of


page layout issues for you. For submission to an academic
publication, this entire topic will be out of your hands, as
the publishers want to control the presentation. However,
for your own documents, there are some obvious settings
that you may wish to change: margins, page orientation
and columns, to name but three. The purpose of this tutorial is to show you how to congure your pages.
We will often have to deal with TeX lengths in this chapter. You should have a look at Lengths for comprehensive
details on the topic.

1. one inch + \hoset


2. one inch + \voset
3. \oddsidemargin = 31pt
4. \topmargin = 20pt
5. \headheight = 12pt

2.12.1

Two-sided documents

Documents can be either one- or two-sided. Articles


are by default one-sided, books are two-sided. Twosided documents dierentiate the left (even) and right
(odd) pages, whereas one-sided do not. The most notable eect can be seen in page margins. If you want
to make the article class two-sided, use \documentclass[twoside]{article}.
Many commands and variables in LaTeX take this concept into account. They are referred to as even and odd.
For one-sided document, only the odd commands and
variables will be in eect.

6. \headsep = 25pt
7. \textheight = 592pt
8. \textwidth = 390pt
9. \marginparsep = 10pt
10. \marginparwidth = 35pt
11. \footskip = 30pt
\marginparpush = 7pt (not shown)
\hoset = 0pt

54

CHAPTER 2. COMMON ELEMENTS

\voset = 0pt
\paperwidth = 597pt
\paperheight = 845pt

In the preamble, \paperwidth and \paperheight in all


cases.
After the preamble, \pdfpagewidth and \pdfpageheight if you are using pdftex.

The current details plus the layout shape can be printed Using the PDF dedicated commands has one immediate
from a LaTeX document itself. Use the layout pack- advantage: it will let you change the page dimension anyage and the command of the same name: \usepack- where in the document.
age{layout} ... \layout{}
To render a frame marking the margins of a document
Page size issues
you are currently working on, add
\usepackage{showframe}

If you intend to get a PDF in the end, there are basically


three ways:

to the document.
TeX PDF

2.12.3

Page size

pdatex myle # TeX PDF

It will not have been immediately obvious - because it


TeX DVI PDF
doesn't really cause any serious problems - that the default page size for all standard document classes is US letter. This is shorter by 18 mm (about 3/4 inch), and slightly latex myle # TeX DVI dvipdf myle # DVI PDF
wider by 8 mm (about 1/4 inch), compared to A4 (which
TeX DVI PS PDF
is the standard in almost all the rest of the world). While
this is not a serious issue (most printers will print the document without any problems), it is possible to specify al- latex myle # TeX DVI dvips myle -o [Link] #
DVI PS ps2pdf [Link] [Link] # PS PDF
ternative sizes as class option. For A4 format:
Sadly the PDF output page size may not be completely respectful of your settings. Some of these tools do not have
More size options with geometry
the same interpretation of the DVI, PS and PDF speciOne of the most versatile packages for page layout is cations, and you may end up with a PDF which has not
the geometry package. The immediate advantage of this exactly the right size. Thankfully there is a solution to
package is that it lets you customize the page size even that: the \special command lets the user pass PostScript
with classes that do not support the options. For instance, or PDF parameters, which can be used here to set the
to set the page size, add the following to your preamble: page size appropriately.
The geometry package has many pre-dened page sizes,
like a4paper, built in. Others include:
a0paper, a1paper, ..., a6paper,
b0paper, b1paper, ..., b6paper,
letterpaper,
legalpaper,
executivepaper.

For pdatex to work ne, using the package geometry usually works.
For the DVI and PS ways, the safest way to always
get the right paper size in the end is to add
to the tex le, and to append the appropriate parameters
to the processors used during output generation:
dvips -t a4 ... ps2pdf -sPAPERSIZE=a4 ... # On Windows: ps2pdf -sPAPERSIZE#a4 ... [1]

If you want US Letter instead, replace 210mm,297mm


To explicitly change the paper dimensions using the ge- by 8.5in,11in and a4paper by letter. Also replace a4 by
ometry package, the paperwidth and paperheight options letter in command-line parameters.
can be used. For example:
Page size for tablets
Changing size manually
Those who want to read on tablets or other handheld digUse the \setlength command to adjust the parameters to ital devices need to create documents without the exthe appropriate dimensions. See the Lengths chapter.
tra whitespace. In order to create PDF documents with

2.12. LATEX/PAGE LAYOUT


optimal handheld viewing, not only must the text eld
and margins be adjusted, so must the page size. If you
are looking for a sensible dimension, consider following
the paper size used by the Supreme Court of the United
States, 441pt by 666pt (or 6.125 inches by 9.25 inches),
which looks great on tablets. You could also use the
Supreme Courts text eld size of 297 pt by 513 pt, but
this is too wide for fonts other than Century Schoolbook,
the font required by the Supreme Court.

2.12.4

Margins

Readers used to perusing typical physical literature are


probably wondering why there is so much white space
surrounding the text. For example, on A4 paper a document will typically have 44 mm margin widths on the
left and right of the page, leaving about 60% of the page
width for text. The reason is improved readability. Studies have shown[2][3] that its easier to read text when there
are 6070 characters per lineand it would seem that 66
is the optimal number. Therefore, the page margins are
set to ensure optimal readability, and excessive margin
white space is tolerated as a consequence. Sometimes,
this white space is left in the inner margin with the assumption that the document will be bound.

55
Odd and even margins
Using the geometry package, the options left and right are
used for the inside and outside margins respectively. They
also have aliases inner and outer. Thus, the easiest way to
handle dierent margins for odd and even pages is to give
the twoside option in the document class command and
specify the margins as usually.
This will result in a value of 4cm on all inner margins (left
margin for odd number pages and right margin for even
pages) and 2cm margin on outer margins.
Setting the same value for the inner and outer for geometry will remove the dierence between the margins. Another quick way to eliminate the dierence in position
between even and odd numbered pages would be setting
the values to evensidemargin and oddsidemargin to the
half of odds default:
By default, the value of evensidemargin is larger than
oddsidemargin in the two-sided layout, as one could
wish to write notes on the side of the page. The side
for the large margin is chosen opposite to the side where
pages are joined together.
See the Lengths.

If you wish to change the margins of your document,


Top margin above Chapter
there are many ways to do so:
Simply use the fullpage package for somewhat stan- The top margin above a chapter can be changed using the
dardized smaller margins (around an inch):
titlesec package. Example:
For an even greater eect give it the cm option (around The command \titleformat must be used when the spacing
of a chapter is changed. In case of a section this command
1.5cm):
can be omitted.
Use the geometry package. This package allows you
to specify the 4 margins without needing to remember the particular page dimensions commands. You
2.12.5 Page orientation
can enter the measures in centimeters and inches as
well. Use cm for centimeters and in for inches after
each value (e.g. 1.0in or 2.54cm). Note that by de- When you talk about changing page orientation, it usually
fault (i.e. without any options) this package already means changing to landscape mode, since portrait is the
reduces the margins, so for a 'standard layout' you default. We shall introduce two slightly dierent styles of
may not need to specify anything. These values are changing orientation.
relative to the edge of paper (0in) and go inward it.
It may be implemented as follows:
Change orientation of the whole document
or all in a row
You can combine the margin options with the page size The rst is for when you want all of your document to be
in landscape from the very beginning. There are various
options seen in this paragraph.
packages available to achieve this, but the one we prefer
You should not use the a4wide package for a page is the geometry package. All you need to do is call the
with A4 document size with smaller margins. It is package, with landscape as an option:
obsolete and buggy. Use geometry package instead
Although, if you intend to use geometry to set your paper
like this:
size, don't add the \usepackage commands twice, simply
Edit individual page dimension variables described string all the options together, separating with a comma:
above, using the \addtolength and \setlength com- Using standard LaTeX classes, you can use the same class
mands. See the Lengths chapter. For instance,
options:

56

CHAPTER 2. COMMON ELEMENTS

Change orientation of specic part

With myheadings, the commands \markright (in the standard document classes, book, report and article) and
\markboth (only in the book class) are used to control
the headings. The following commands placed at the beginning of an article document will set the header of all
pages to contain John Smith top left, On page styles
centered and the page number top right:

The second method is for when you are writing a document in portrait, but you have some contents, like a large
diagram or table that would be displayed better on a landscape page. However, you still want the consistency of
your headers and footers appearing the same place as the
other pages.
There are special commands containing details on the
The lscape package is for this very purpose. It supplies running page of the document.
a landscape environment, and anything inside is basically Note that \leftmark and \rightmark convert the names to
rotated. No actual page dimensions are changed. This uppercase, whichever was the formatting of the text. If
approach is more applicable to books or reports than to you want them to print the actual name of the chapter
typical academic publications. Using pdscape instead of without converting it to uppercase use the following comlscape when generating a PDF document will make the mand:
page appear right side up when viewed: the single page
that is in landscape format will be rotated, while the rest Now \leftmark and \rightmark will just print the name of
the chapter and section, without number and without afwill be left in portrait orientation.
fecting the formatting. Note that these redenitions must
Also, to get a table to appear correctly centered on a land- be inserted after the rst call of \pagestyle{fancy}. The
scaped page, one must place the tabular environment in- standard book formatting of the \chaptermark is:
side a table environment, which is itself inside the landscape environment. For instance it should look like this: Watch out: if you provide long text in two dierent
parts only in the footer or only in the header, you might
see overlapping text.
Change orientation of oating environment
Moreover, with the following commands you can dene
the thickness of the decorative lines on both the header
If you use the above code, you will see that the table is and the footer:
inserted where it is in the code. It will not be oated! To
x this you need the package rotating. See the Rotations The rst line for the header, the second for the footer.
Setting it to zero means that there will be no line.
chapter.

2.12.6

Plain pages issue

If you need to rotate the page so that the gure ts, the
chances are good that you need to scale the margins and
the font size too. Again, the geometry package comes in
handy for specifying new margins for a single page only.
Note that order matters!

2.12.7

An issue to look out for is that the

Margins, page size and rotation of a major sectioning commands (\part, \chapter or \maketispecic page
tle) specify a \thispagestyle{plain}. So, if you wish to

Page styles

Page styles in Latex terms refers not to page dimensions,


but to the running headers and footers of a document.
These headers typically contain document titles, chapter
or section numbers/names, and page numbers.

suppress all styles by inserting a \pagestyle{empty} at the


beginning of your document, then the style command at
each section will override your initial rule, for those pages
only. To achieve the intended result one can follow the
new section commands with \thispagestyle{empty}. The
\part command, however, cannot be xed this way, because it sets the page style, but also advances to the next
page, so that \thispagestyle{} cannot be applied to that
page. Two solutions:
simply write \usepackage{nopageno} in the preamble. This package will make \pagestyle{plain} have
the same eect as \pagestyle{empty}, eectively
suppressing page numbering when it is used.
Use fancyhdr as described below.

Standard page styles


The possibilities of changing the headers in plain Latex are actually quite limited. There are two commands
available: \pagestyle{''style''} will apply the specied
style to the current and all subsequent pages, and \thispagestyle{''style''} will only aect the current page. The
possible styles are:

The tricky problem when customizing headers and footers is to get things like running section and chapter names
in there. Standard LaTeX accomplishes this with a twostage approach. In the header and footer denition, you
use the commands \rightmark and \leftmark to represent
the current section and chapter heading, respectively. The
values of these two commands are overwritten whenever

2.12. LATEX/PAGE LAYOUT

57

a chapter or section command is processed. For ultimate


You can also use the command \fancyhead for
exibility, the \chapter command and its friends do not reheader and \fancyfoot for footer. They work in the
dene \rightmark and \leftmark themselves. They call yet
same way, so we'll explain only the rst one. The
another command (\chaptermark, \sectionmark, or \subsyntax is:
sectionmark) that is responsible for redening \rightmark
and \leftmark, except if they are starred -- in such a case, You can use multiple selectors optionally separated by a
\markboth{Chapter/Section name}{} must be used in- comma. The selectors are the following:
side the sectioning command if header and footer lines
so CE,RO will refer to the center of the even pages and
are to be updated.
to the right side of the odd pages.
Again, several packages provide a solution:
\fancyhf is a merge of \fancyhead and \fancyfoot,
hence the name. There are two additional selectors
an alternative one-stage mechanism is provided by
H and F to specify the header or the footer, respecthe package titleps);
tively. If you omit the H and the F, it will set the
elds for both.
fancyhdr will handle the process its own way.
Customizing with fancyhdr
To get better control over the headers, one can use the
package fancyhdr written by Piet van Oostrum. It provides several commands that allow you to customize the
header and footer lines of your document. For a more
complete guide, the author of the package produced this
documentation.

These commands will only work for fancy and fancyplain.


To customize LaTeX default style you need the \fancyplainstyle command. See below for examples.
For a clean customization, we recommend you start from
scratch. To do so you should erase the current pagestyle.
Providing empty values will make the eld blank. So
will just delete the current heading/footer conguration,
so you can make your own.

To begin, add the following lines to your preamble:


You can now observe a new style in your document.

Plain pages There are two ways to change the style of


plain pages like chapters and titlepage.

The \headheight needs to be 13.6pt or more, otherwise


you will get a warning and possibly formatting issues. First you can use the fancyplain style. If you do so, you
Both the header and footer comprise three elements each can use the command \fancyplain{...}{...} inside fancyaccording to its horizontal position (left, centre or right). hdr commands like \lhead{...}, etc.
When LaTeX wants to create a page with an empty style,
The styles supported by fancyhdr:
it will insert the rst argument of \fancyplain, in all the
other cases it will use the second argument. For instance:
the four LaTeX styles;
It has the same behavior of the previous code, but you
fancy denes a new header for all pages but plain- will get empty header and footer in the title and at the
beginning of chapters.
style pages such as chapters and titlepage;
Alternatively you could redene the plain style, for example to have a really plain page when you want. The
command to use is \fancypagestyle{plain}{...} and the argument can contain all the commands explained before.
Style customization The styles can be customized An example is the following:
with fancyhdr specic commands. Those two styles may
be congured directly, whereas for LaTeX styles you In that case you can use any style but fancyplain because
it would override your redenition.
need to make a call to the \fancypagestyle command.
fancyplain is the same, but for absolutely all pages.

To set header and footer style, fancyhdr provides three


interfaces. They all provide the same features, you just Examples For two-sided, its common to mirror the
style of opposite pages, you tend to think in terms of inner
use them dierently. Choose the one you like most.
and outer. So, the same example as above for two-sided
is:
You can use the following six commands.
This is eectively saying author name is top outer, toHopefully, the behaviour of the above commands is fairly days date is top inner, and current page number is bottom
intuitive: if it has head in it, it aects the head etc, and outer. Using \fancyhf can make it shorter:
obviously, l, c and r means left, centre and right respec- Here is the complete code of a possible style you could
tively.
use for a two-sided document:

58

CHAPTER 2. COMMON ELEMENTS

Using \fancypagestyle one can additionally dene multiple styles for ones document that are easy to switch between. Heres a somewhat complicated example for a
two-sided book style:

Column environments can be easily customised locally or globally.


Using multicol package

Page n of m

The multicol package overcomes some of the shortcomings of twocolumn and provides the multicol environSome people like to put the current page number in con- ment. To create a typical two-column layout:
text with the whole document. LaTeX only provides acFloats are not fully supported by this environment. It can
cess to the current page number. However, you can use
only cope if you use the starred forms of the oat comthe lastpage package to nd the total number of pages,
mands (e.g., \begin{gure*} ) which makes the oat span
like this:
all columns. This is not hugely problematic, since oats
Note the capital letters. Also, add a backslash after \thep- of the same width as a column may be too small, and you
age to ensure adequate space between the page number would probably want to span them anyway. See this secand 'of'. And recall, when using references, that you tion for a more detailed discussion.
have to run LaTeX an extra time to resolve the crossThe multicol package has two important parameters
references.
which can be set using \setlength:
Alternative packages
Other packages for page styles are scrpage2, very similar to fancyhdr, and titleps, which takes a one-stage approach, without having to use \leftmark or \rightmark.

2.12.8

Page background

The eso-pic package will let you print content in the background of every page or individual pages.

\columnseprule, sets the width of the vertical rule


between columns and defaults to 0pt
\columnsep, sets the horizontal space between
columns and the defaults to 10pt, which is quite narrow
To force a break in a column, the command \columnbreak
is used.

The starred-version of the \AddToShipoutPicture com- 2.12.10 Manual page formatting


mand applies to the current page only.
There may be instances, especially in very long documents, such as books, that LaTeX will not get all page
breaks looking as good as it could. It may, therefore,
2.12.9 Multi-column pages
be necessary to manually tweak the page formatting. Of
course, you should only do this at the very nal stage of
Using the twocolumn optional class argument
producing your document, once all the content is comUsing a standard Latex document class, like article, you plete. LaTeX oers the following:
can simply pass the optional argument twocolumn to the
document class: \documentclass[twocolumn]{article}
2.12.11 Widows and orphans
which will give the desired eect.
While this approach is useful, it has limitations:

In professional books, its not desirable to have single lines


at the beginning or end of a page. In typesetting such sitCan support up to ten columns.
uations are called 'widows and 'orphans. Normally it is
possible that widows and orphans appear in LaTeX docuImplements a multicols environment, therefore, it is ments. You can try to deal with them using manual page
possible to mix the number of columns within a doc- formatting, but theres also an automatic solution.
ument.
LaTeX has a parameter for 'penalty' for widows and orAdditionally, the environment can be nested inside phans ('club lines in LaTeX terminology). With the
other environments, such as gure.
greater penalty LaTeX will try more to avoid widows
and orphans. You can try to increase these penalties by
multicol outputs balanced columns, whereby the putting following commands in your document preamble:
columns on the nal page will be of roughly equal
If this does not help, you can try increasing these values
length.
even more, to a maximum of 10000. However, it is not
Vertical rules between columns can be customised. recommended to set this value too high, as setting it to

2.13. LATEX/IMPORTING GRAPHICS

59

10000 forbids LaTeX from doing this altogether, which This package accepts as an argument the external driver to
might result in strange behavior.
be used to manage pictures; however, the latest version of
It also helps to have rubber band values for the space be- this package takes care of everything by itself, changing
the driver according to the compiler you are using, so you
tween paragraphs:
don't have to worry about this. Still, just in case you want
Alternatively, you can use the needspace package to re- to understand better how it works, here are the possible
serve some lines and thus to prevent page breaking for options you can pass to the package:
those lines.

2.12.12

Notes and References

This page uses material from Andy Roberts Getting to grips


with LaTeX with permission from the author.
[1] How to use Ghostscript
[2] [Link]

dvips (default if compiling with latex), if you are


compiling with latex to get a DVI and you want to
see your document with a DVI or PS viewer.
dvipdfm, if you are compiling with latex to get a
DVI that you want to convert to PDF using dvipdfm,
to see your document with any PDF viewer.
pdftex (default if compiling with pdatex), if you
are compiling with pdftex to get a PDF that you will
see with any PDF viewer.

[3] [Link]

2.13 LaTeX/Importing Graphics


There are two possibilities to include graphics in your
document. Either create them with some special code,
a topic which will be discussed in the Creating Graphics part, (see Introducing Procedural Graphics) or import
productions from third party tools, which is what we will
be discussing here.
Strictly speaking, LaTeX cannot manage pictures directly: in order to introduce graphics within documents,
LaTeX just creates a box with the same size as the image you want to include and embeds the picture, without
any other processing. This means you will have to take
care that the images you want to include are in the right
format to be included. This is not such a hard task because LaTeX supports the most common picture formats
around.

2.13.1

Raster graphics vs. vector graphics

But, again, you don't need to pass any option to the package because the default settings are ne in most of the
cases.
In many respects, importing your images into your document using LaTeX is fairly simple... once you have your
images in the right format that is! Therefore, I fear for
many people the biggest eort will be the process of converting their graphics les. Now we will see which formats we can include and then we will see how to do it.

2.13.3 Document Options


The graphics and graphicx packages recognize the draft
and nal options given in the \documentclass[...]{...}
command at the start of the le. (See Document Classes.)
Using draft as the option will suppress the inclusion of the
image in the output le and will replace the contents with
the name of the image le that would have been seen. Using nal will result in the image being placed in the output
le. The default is nal.

2.13.4 Supported image formats

Raster graphics will highly contrast with the quality of the


document if they are not in a high resolution, which is the As explained before, the image formats you can use decase with most graphics. The result may be even worse pend on the driver that graphicx is using but, since the
driver is automatically chosen according to the compiler,
once printed.
then the allowed image formats will depend on the comMost drawing tools (e.g. for diagrams) can export in vec- piler you are using.
tor format. So you should always prefer PDF or EPS to
Consider the following situation: you have added some
PNG or JPG.
pictures to your document in JPG and you have successfully compiled it in PDF. Now you want to compile it in
DVI, you run latex and you get a lot of errors... because
2.13.2 The graphicx package
you forgot to provide the EPS versions of the pictures you
As stated before, LaTeX can't manage pictures directly, want to insert.
so we will need some extra help: we have to load the At the beginning of this book, we had stated that the same
graphicx package in the preamble of our document:
LaTeX source can be compiled in both DVI and PDF

60
without any change. This is true, as long as you don't
use particular packages, and graphicx is one of those. In
any case, you can still use both compilers with documents
with pictures as well, as long as you always remember to
provide the pictures in two formats (EPS and one of JPG,
PNG or PDF).
Compiling with latex

CHAPTER 2. COMMON ELEMENTS

2.13.5 Including graphics


Now that we have seen which formats we can include and
how we could manage those formats, its time to learn
how to include them in our document. After you have
loaded the graphicx package in your preamble, you can
include images with \includegraphics, whose syntax is the
following:

As usual, arguments in square brackets are optional,


The only format you can include while compiling with whereas arguments in curly braces are compulsory.
latex is Encapsulated PostScript (EPS).
The argument in the curly braces is the name of the imThe EPS format was dened by Adobe Systems for mak- age. Write it without the extension. This way the Laing it easy for applications to import postscript-based TeX compiler will look for any supported image format
graphics into documents. Because an EPS le declares in that directory and will take the best one (EPS if the
the size of the image, it makes it easy for systems like La- output is DVI; JPEG, PNG or PDF if the output is PDF).
TeX to arrange the text and the graphics in the best way. Images can be saved in multiple formats for dierent purEPS is a vector formatthis means that it can have very poses. For example, a directory can have [Link]
high quality if it is created properly, with programs that for high-resolution printing, while [Link] can be
are able to manage vector graphics. It is also possible to used for previewing on the monitor. You can specify
store bit-map pictures within EPS, but they will need a which image le is to be used by pdatex through the
preamble command:
lot of disk space.
Compiling with pdatex

which species the les to include in the document (in order of preference), if les with the same basename exist,
but with dierent extensions.

If you are compiling with pdatex to produce a PDF, you The variety of possible attributes that can be set is fairly
large, so only the most common are covered below:
have a wider choice. You can insert:
In order to use more than one option at a time, simply sep JPG, widely used on Internet, digital cameras, etc. arate each with a comma. The order you give the options
They are the best choice if you want to insert photos. matters. E.g you should rst rotate your graphic (with
angle) and then specify its width.
PNG, a very common format (even if not as much as
JPG); its a lossless format and its the best choice for Included graphics will be inserted just there, where you
diagrams (if you were not able to generate a vector placed the code, and the compiler will handle them as
big boxes. As we will see in the oats section, this can
version) and screenshots.
disrupt the layout; you'll probably want to place graphics
PDF, it is widely used for documents but can be inside oating objects.
used to store images as well. It supports both vec- Also note that the trim option does not work with XeLator and bit-map images, but its not recommended Tex.
for the latter, as JPG or PNG will provide the same
Be careful using any options, if you are working with
result using less disk space.
the chemnum-package. The labels dened by \cmp EPS can be used with the help of the epstopdf pack- dref{<label name>} might not behave as expected. Scalage. Depending on your installation,
ing the image for instance may be done by \scalebox instead.
you may just need to have it installed, there is
The star version of the command will work for .eps les
no need to load it in your document;
only. For a more portable solution, the standard way
if it does not work, you need to load it just after should take precedence. The star command will take the
the graphicx package. Additionally, since ep- crop dimension as extra parameter:
stopdf will need to convert the EPS le into a
PDF le and store it, you need to give writing
permissions to your compiler. This is done by
Examples
adding an option to the compiling command,
e.g. pdatex -shell-escape [Link] (if you use a
LaTeX editor, they usually allow to modify the OK, its time to see graphicx in action. Here are some
command in the conguration options). Check examples. Say you had a le '[Link]' you would include
the epstopdf documentation for other compil- it like:
This simply imports the image, without any other proers.

2.13. LATEX/IMPORTING GRAPHICS

61

cessing. However, it is very large (so we won't give a ex- in the same directory as your main tex le, i.e. this is
ample of how it would look here!) So, lets scale it down: RELATIVE addressing.
This has now scaled it by half. If you wish to be more Using absolute paths, \graphicspath makes your le less
specic and give actual lengths of the image dimensions, portable, while using relative paths (like the third examthis is how to go about it:
ple), there should not be any problem with portability.
One can also specify the scale with respect to the width The fourth example uses the safe (MS-DOS) form of
the Windows MyPictures folder because its a bad idea to
of a line in the local environment (\linewidth), the width
use
directory names containing spaces. Again, ensure le
of the text on a page (\textwidth) or the height of the text
names
do not contain spaces or alternatively if you are
on a page (\textheight) (pictures not shown):
using PDFLaTeX, you can use the package grle which
To rotate (I also scaled the image down):
will allow you to use spaces in le names.
And nally, an example of how to crop an image should Note that you cannot make the graphicx package search
you wish to focus on one particular area of interest:
directories recursively. Under Linux/Unix, you can
Note the presence of clip, as the trim operation will not achieve a recursive search using the environment variable
TEXINPUTS, e.g., by setting it to
work without it.
Trick: You can also use negative trim values to add blank export TEXINPUTS=./images//:./Snapshots//
space to your graphics, in cases where you need some
manual alignment.
before running latex/pdatex or your TeX-IDE. (But this,
of course, is not a portable method.)
Spaces in names

2.13.7 Images as gures

If the image le were called chick [Link], then you


need to include the full lename when importing the im- The gure environment is not exclusively used for images.
We will only give a short preview of gures here. More
age:
information on the gure environment and how to use it
One option is to not use spaces in le names (if possible), can be found in Floats, Figures and Captions.
or to simply replace spaces with underscores (chick picThere are many scenarios where you might want to [Link] to chick_picture.png)
company an image with a caption and possibly a crossreference. This is done using the gure environment. The
following code sample shows the bare minimum required
Borders
to use an image as a gure.
It is possible to have LaTeX create a border around your The above code extract is relatively trivial, and doesn't ofimage by using \fbox:
fer much functionality. The following code sample shows
You can control the border padding with the an extended use of the gure environment which is almost
\setlength\fboxsep{0pt} command, in this case I set it to universally useful, oering a caption and label, centering
0pt to avoid any padding, so the border will be placed the image and scaling it to 80% of the width of the text.
tightly around the image. You can control the thickness
of the border by adjusting the \setlength\fboxrule{0.5pt}
2.13.8 Text wrapping around pictures
command.
See Boxes for more details on \framebox and \fbox.

See Floats, Figures and Captions.

2.13.6

2.13.9 Seamless text integration

Graphics storage

The command \graphicspath tells LaTeX where to look


for images, which can be useful if you store images centrally for use in many dierent documents. The \graphicspath command takes one argument, which species the
additional paths you want to be searched when the \includegraphics command is used. Here are some examples
(trailing / is required):

The drawback of importing graphics that were generated with a third-party tool is that font and size will not
match with the rest of the document. There are still some
workarounds though.

The easiest solution is to use the picture environment and


then simply use the put command to put a graphics le
inside the picture, along with any other desired LaTeX
Please see [Link] element. For example:
latex/required/graphics/[Link]. In the third exam- Note that the border around the picture in the above exple shown there should be a directory named images ample was added by using \fbox, so the contents of the

62

CHAPTER 2. COMMON ELEMENTS

border is the picture as generated by the above code.

In Windows, multiple les can be converted by placing


Tools like Inkscape or Xg have a dedicated LaTeX ex- the following line in a batch le (a text le with a .bat
port feature that will let you use correct font and size for extension) in the same directory as the images:
text in vector graphics. See #Third-party graphics tools. for %%f in (*.eps) do epstopdf %%f
For a perfect integration of graphics, you might consider
procedural graphics capabilities of some LaTeX packages which can then be run from the command line.
like TikZ or PSTricks. It lets you draw from within a If epstopdf produces whole page with your small graphics
document source. While the learning curve is steeper, it somewhere on it, use
is worth it most of the time.
$ epstopdf --gsopt=-dEPSCrop [Link]

2.13.10

Including full PDF pages

or try using ps2pdf utility which should be installed with


Ghostscript (required for any TeX distribution).

There is a great package for including full pages of PDF


les: pdfpages. It is capable of inserting entire pages as $ ps2pdf -dEPSCrop [Link]
is and more pages per one page in any layout (e.g. 2x3).
to crop nal PDF.
The package has several options:
Options:

eps2eps

nal: Inserts pages. This is the default.

When all of the above fails, one can simplify the EPS le
draft: Does not insert pages, but prints a box and before attempting other conversions, by using the eps2eps
the lename instead.
tool (also see next section):
enable-survey: Activates survey functionalities. $ eps2eps [Link] [Link]
(Experimental, subject to change.)
This will convert all the fonts to pre-drawn images, which
is sometimes desirable when submitting manuscripts for
The rst command is
publication. However, on the downside, the fonts are
Options for key=val (A comma separated list of options
NOT converted to lines, but instead to bitmaps, which
using the key = value syntax)
reduces the quality of the fonts.
You can also inserts pages of several external PDF documents.
imgtops
Several PDFs can be placed table-like on one page. See
more information in its documentation.
imgtops is a lightweight graphics utility for conversions
between raster graphics (JPG, PNG, ...) and EPS/PS
les.
2.13.11 Converting graphics
Note

Inkscape

You should also take a look at Export To Other Formats Inkscape can also convert les from and to several forfor other possibilities.
mats, either from the GUI or from the command-line. For
instance, to obtain a PDF from a SVG image you can do:
epstopdf
$ inkscape -z -D --le=[Link] --export-pdf=[Link]
You can convert EPS to PDF with the epstopdf utility,
included in package of the same name. This tool is actually called by pdatex to convert EPS les to PDF in the
background when the graphicx package is loaded. This
process is completely invisible to the user.

It is possible to run this from within a LaTeX le,


the Template:LaTeX/package package (when running
(pdf)latex with the --shell-escape option) can do this using Inkscapes pdf+tex export option, or a simple macro
can be used. See How to include SVG diagrams in LaYou can batch convert les using the command-line. In TeX? -- Stackexchange See Export To Other Formats for
more details.
Bourne Shell (Unix) this can be done by:
$ for i in *.eps; do epstopdf "$i"; done
pstoedit

2.13. LATEX/IMPORTING GRAPHICS

63

To properly edit an EPS le, you can convert it to an ed- 2.13.12 Third-party graphics tools
itable format using pstoedit. For instance, to get an XgWe will not tackle the topic of procedural graphics creeditable le, do:
ated from within LaTeX code here (TikZ, PSTricks,
$ pstoedit -f g [Link] output.g
MetaPost and friends). See Introducing Procedural
Graphics for that.
And to get an SVG le (editable with any vector graphics
You should prefer vector graphics over raster graphics for
tool like Inkscape) you can do:
their quality. Raster graphics should only be used in case
$ pstoedit -f plot-svg [Link] [Link]
of photos. Diagrams of any sort should be vectors.
As we have seen before, LaTeX handles
Sometimes pstoedit fails to create the target format (for
example when the EPS le contains clipping information).
PDFCreator

EPS and PDF for vector graphics;


PNG and JPG for raster graphics.
If some tools cannot save in those formats, you may want
to convert them before importing them.

Under Windows, PDFCreator is an open source software


that can create PDF as well as EPS les. It installs a
virtual printer that can be accessed from other software Vector graphics
having a print... entry in their menu (virtually any proDia
gram).
Raster graphics converters
Sam2p (convert) or
ImageMagick (convert) or
GraphicsMagick (gm convert).
These three programs operate much the same way, and
can convert between most graphics formats. Sam2p however is the most recent of the three and seems to oer
both the best quality and to result in the smallest les.
PNG alpha channel
Acrobat Reader sometimes has problems with displaying
colors correctly if you include graphics in PNG format
with alpha channel. You can solve this problem by dropping the alpha channel. On Linux it can be achieved with
convert from the ImageMagick program:
convert -alpha o [Link] [Link]

Converting a color EPS to grayscale


Sometimes color EPS gures need to be converted to
black-and-white or grayscale to meet publication requirements. This can be achieved with the eps2eps of the
Ghostscript package and programs:

Dia is a cross platform diagramming utility which can


export eps images, or generate tex drawn using the tikz
package.
Inkscape
Another program for creating vector graphics is Inkscape.
It can run natively under Windows, Linux or Mac OS
X (with X11). It works with Scalable Vector Graphics (SVG) les, although it can export to many formats that can be included in LaTeX les, such as
EPS and PDF. From version 0.48, there is a combined
PDF/EPS/PS+LaTeX output option, similar to that offered by Xg. There are instructions on how to save your
vector images in a PDF format understood by LaTeX and
have LaTeX manage the text styles and sizes in the image automatically.[1] . Today there is the svg-package[2]
which provides an \includesvg command to convert and
include svg-graphics directly in your LaTeX document
using Inkscape. You may have a look at this extended
example too.
An extremely useful plug-in is textext, which can import
LaTeX objects. This can be used for inserting mathematical notation or LaTeX fonts into graphics (which may
then be imported into LaTeX documents).
Ipe

The Ipe extensible drawing editor is a free vector graphics


editor for creating gures in PDF or EPS format. Unlike
Xg, Ipe represents LaTeX fonts in their correct size on
the screen which makes it easier to place text labels at
$ eps2eps [Link] [Link] $ pscol 0gray input- the right spot. Ipe also has various snapping modes (for
[Link] [Link]
example, snapping to points, lines, or intersections) that
can be used for geometric constructions.

64
lpic
Yet another solution is provided by the lpic packages ,
which allows TeX annotations to imported graphics. See
Labels in the gures.
[Link]
It is also possible to export vector graphics to EPS format using [Link] Draw, which is an open source
oce suite available for Windows, Linux and Mac.

CHAPTER 2. COMMON ELEMENTS


4. In your LaTeX document, where the picture should
be, use the following, where test is replaced by the
name of the image:
Observe that this is just like including a picture, except that rather than using \includegraphics, we use
\input. If the export was into PS/LaTeX, the le
extension to include would be .pstex_t instead of
.pdf_t.
5. Make sure to include packages graphicx and color in
the le, with the \usepackage command right below
the \documentclass command, like this:

TpX
And you're done!
Vector editor TpX separates geometric objects from text
objects. Geometric objects are saved into .PDF le, the For more details on using xg with LaTeX, this chapter
rest is saved in .TpX le to be processed by LaTeX. User of the xg User Manual may prove helpful.
just create the graphics in TpX editor and calls the .TpX
Other tools
le from latex le by command \input{...TpX}.
Xg

Commercial vector graphics software, such as Adobe


Illustrator, CorelDRAW, and FreeHand are commonly
Xg is a basic program that can produce vector graphics, used and can read and write EPS gures. However, these
which can be exported to LaTeX. It can be installed on products are limited to Windows and Mac OS X platUnix platforms.
forms.
On Microsoft Windows systems, Xg can only be installed using Cygwin-X; however, this will require a fast Raster graphics
internet connection and about 2 gigabytes of space on
your computer. With Cygwin, to run Xg, you need to Adobe Photoshop
rst start the Start X - Server, then launch xterm to
bring up a terminal. In this terminal type xg (without It can save to EPS.
the quotation marks) and press return.
Alternatively, WinFIG is an attempt to achieve the func- GIMP
tionality of xg on Windows computers.
There are many ways to use xg to create graphics for LaTeX documents. One method is to export the drawing as
a LaTeX document. This method, however, suers from
various drawbacks: lines can be drawn only at angles that
are multiples of 30 and 45 degrees, lines with arrows can
only be drawn at angles that are multiples of 45 degrees,
several curves are not supported, etc.

GIMP, has a graphical user interface, and it is multiplatform. It can save to EPS and PDF.
Plots and Charts
Generic Mapping Tools (GMT)

Exporting a le as PDF/LaTeX or PS/LaTeX, on the Generic Mapping Tools (GMT), maps and a wide range
other hand, oers a good deal more exibility in draw- of highly customisable plots.
ing. Heres how its done:
1. Create the drawing in xg. Wherever you need LaTeX text, such as a mathematical formula, enter a
LaTeX string in a textbox.

Gnumeric
Gnumeric, spreadsheets has SVG, EPS, PDF export

2. Use the Edit tool to open the properties of each of Gnuplot


those textboxes, and change the option on the Special Flag eld to Special. This tells LaTeX to inter- Gnuplot, producing scientic graphics since 1986. If you
pret these textboxes when it opens the gure.
want to make mathematical plots, then Gnuplot can save
3. Go to File -> Export and export the le as in any format. You can get best results when used along
PDF/LaTeX (both parts) or PS/LaTeX (both parts), PGF/TikZ.
depending on whether you are using pdatex or psmatplotlib
latex to compile your le.

2.14. LATEX/FLOATS, FIGURES AND CAPTIONS


matplotlib, plotting library written in python, with PDF
and EPS export. On the other hand there is a PGF export
also. There are some tricks to be able to import formats
other than EPS into your DVI document, but they're very
complicated. On the other hand, converting any image to
EPS is very simple, so its not worth considering them.

65
present page, and to help when you really don't want the
object here just now.

Floats are not part of the normal stream of text, but separate entities, positioned in a part of the page to themselves
(top, middle, bottom, left, right, or wherever the designer
species). They always have a caption describing them
and they are always numbered so they can be referred to
R
from elsewhere in the text. LaTeX automatically oats
Tables and Figures, depending on how much space is left
on the page at the point that they are processed. If there is
R, statistical and scientic gures.
not enough room on the current page, the oat is moved to
the top of the next page. This can be changed by moving
Editing EPS graphics
the Table or Figure denition to an earlier or later point
in the text, or by adjusting some of the parameters which
As described above, graphics content can be imported control automatic oating.
into LaTeX from outside programs as EPS les. But
Authors sometimes have many oats occurring in rapid
sometimes you want to edit or retouch these graphics les.
succession, which raises the problem of how they are supAn EPS le can be edited with any text editor since it
posed to t on the page and still leave room for text. In
is formatted as ASCII. In a text editor, you can achieve
this case, LaTeX stacks them all up and prints them tosimple operations like replacing strings or moving items
gether if possible, or leaves them to the end of the chapter
slightly, but anything further becomes cumbersome. Vecin protest. The skill is to space them out within your text
tor graphics editors, like Inkscape, may also be able to
so that they intrude neither on the thread of your arguimport EPS les for subsequent editing. This approach
ment or discussion, nor on the visual balance of the typealso for easier editing. However, the importing process
set pages.
may occassionally modify the original EPS image.

2.13.13

Notes and References

[1] Johan B. C. Engelen.


How to include an
SVG image in LATEX.
[Link].
[Link]
[Link].
[2] Philip Ilten. The svg-package on CTAN. [Link]. http:
//[Link]/tex-archive/graphics/svg.

Figures
To create a gure that oats, use the gure environment.
The previous section mentioned how oats are used to
allow LaTeX to handle gures, while maintaining the best
possible presentation. However, there may be times when
you disagree, and a typical example is with its positioning
of gures. The placement specier parameter exists as a
compromise, and its purpose is to give the author a greater
degree of control over where certain oats are placed.

What you do with these placement permissions is to list


which of the options you wish to make available to LaTeX. These are simply possibilities, and LaTeX will decide when typesetting your document which of your supThe previous chapter introduced importing graphics. plied speciers it thinks is best. Frank Mittelbach de[2]
However, just having a picture stuck in between para- scribes the algorithm :
graphs does not look professional. For starters, we want a
way of adding captions, and to be able to cross-reference.
If a oat is encountered, LaTeX attempts to place it
What we need is a way of dening gures. It would also
immediately according to its rules (detailed later)
be good if LaTeX could apply principles similar to when
if this succeeds, the oat is placed and that deit arranges text to look its best to arranging pictures as
cision is never changed;
well. This is where oats come into play.

2.14 LaTeX/Floats, Figures and


Captions

2.14.1

Floats

Floats are containers for things in a document that cannot be broken over a page. LaTeX by default recognizes
table and gure oats, but you can dene new ones of
your own (see Custom oats below). Floats are there to
deal with the problem of the object that won't t on the

if this does not succeed, then LaTeX places the


oat into a holding queue to be reconsidered
when the next page is started (but not earlier).
Once a page has nished, LaTeX examines this
holding queue and tries to empty it as best as possible. For this it will rst try to generate as many oat
pages as possible (in the hope of getting oats o
the queue). Once this possibility is exhausted, it will

66

CHAPTER 2. COMMON ELEMENTS


next try to place the remaining oats into top and package can be used to place all oats at the end of a
bottom areas. It looks at all the remaining oats and document. The oat package provides the H option to
either places them or defers them to a later page (i.e., oating environments, which stops them from oating.
re-adding them to the holding queue once more).

After that, it starts processing document material for 2.14.3 Captions


this page. In the process, it may encounter further
oats.
It is always good practice to add a caption to any gure or
If the end of the document has been reached or if a table. Fortunately, this is very simple in LaTeX. All you
\clearpage is encountered, LaTeX starts a new page, need to do is use the \caption{''text''} command within
relaxes all restrictive oat conditions, and outputs all the oat environment. LaTeX will automatically keep
oats in the holding queue by placing them on oat track of the numbering of gures, so you do not need to
include this within the caption text.
page(s).
In some special cases LaTeX won't follow these positioning parameters and additional commands will be necessary, for example, if one needs to specify an alignment
other than centered for a oat that sits alone in one page[3] .

The location of the caption is traditionally underneath the


oat. However, it is up to you to therefore insert the caption command after the actual contents of the oat (but
still within the environment). If you place it before, then
the caption will appear above the oat. Try out the following example to demonstrate this eect:

Use \listogures to add a list of the gures in the beginning of the document. To change the name used in Note that the command \reectbox{...} ips its content
the caption from Figure to Example, use \renewcom- horizontally.
mand{\gurename}{Example} in the gure contents.

Side captions
Figures with borders Its possible to get a thin border
around all gures. You have to write the following once It is sometimes desirable to have a caption appear on the
at the beginning of the document:
side of a oat, rather than above or below. The sidecap
package can be used to place a caption beside a gure
The border will not include the caption.
or table. The following example demonstrates this for a
gure by using a SCgure environment in place of the
Tables
gure environment.
Floating tables are covered in a separate chapter. Lets
give a quick reminder here. The tabular environment that Unnumbered captions
was used to construct the tables is not a oat by default.
Therefore, for tables you wish to oat, wrap the tabular In some types of document (such as presentations), it may
environment within a table environment, like this:
not be desirable for gure captions to start Figure:. This is
You may feel that it is a bit long winded, but such distinc- easy to suppress by just placing the caption text in the Figtions are necessary, because you may not want all tables ure environment, without enclosing it in a Caption. This
however means that there is no caption available for into be treated as a oat.
clusion in a list of gures.
Use \listoftables to add a list of the tables in the beginning
of the document.

2.14.4 Lists of gures and tables


2.14.2

Keeping oats in their place

The placeins package provides the command \FloatBarrier, which can be used to prevent oats from being
moved over it. This can, e.g., be useful at the beginning of each section. The package even provides
an option to change the denition of \section to automatically include a \FloatBarrier. This can be set by
loading the package with the option [section] (\usepackage[section]{placeins}). \FloatBarrier may also be useful
to prevent oats intruding on lists created using itemize
or enumerate. The after package can be used to force
oats to appear after they are dened, and the endoat

Captions can be listed at the beginning of a paper or report in a List of Tables or a List of Figures section
by using the \listoftables or \listogures commands, respectively. The caption used for each gure will appear in
these lists, along with the gure numbers, and page numbers that they appear on.
The \caption command also has an optional parameter,
\caption[''short'']{''long''} which is used for the List of Tables or List of Figures. Typically the short description is
for the caption listing, and the long description will be
placed beside the gure or table. This is particularly useful if the caption is long, and only a one-liner is desired

2.14. LATEX/FLOATS, FIGURES AND CAPTIONS

67

in the gure/table listing. Here is an example of this us- oats with oat package. See below in the section on cusage:
tom oats.

2.14.5

Labels and cross-referencing

Tip for gures with too much white space

Labels and cross-references work fairly similarly to the It happens that you'll generate gures with too much (or
general case - see the Labels and Cross-referencing sec- too little) white space on the top or bottom. In such a
case, you can simply make use of the optional argument
tion for more information.
[lineheight]. It species the height of the gure in numIf the label picks up the section or list number instead ber of lines of text. Also remember that the environment
of the gure number, put the label inside the caption to center adds some extra white space at its top and bottom;
ensure correct numbering. If you get an error when the consider using the command \centering instead.
label is inside the caption, use \protect in front of the \laAnother possibility is adding space within the oat using
bel command.
the \vspace{...} command. The argument is the size of
the space you want to add, you can use any unit you want,
including pt, mm, in, etc. If you provide a negative ar2.14.6 Wrapping text around gures
gument, it will add a negative space, thus removing some
Although not normally the case in academic writing, an white space. Using \vspace tends to move the caption
author may prefer that some oats do not break the ow of relative to the oat while the [lineheight] argument does
text, but instead allow text to wrap around it. (Obviously, not. Here is an example using the \vspace command, the
this eect only looks decent when the gure in question code is exactly the one of the previous case, we just added
some negative vertical spaces to shrink everything up:
is signicantly narrower than the text width.)
A word of warning: Wrapping gures in LaTex will In this case it may look too shrunk, but you can manage
require a lot of manual adjustment of your document. spaces the way you like. In general, it is best not to add
There are several packages available for the task, but none any space at all: let LaTeX do the formatting work!
of them works perfectly. Before you make the choice of (In this case, the problem is the use of \begin{center}
including gures with text wrapping in your document, to center the image. The center environment adds extra
make sure you have considered all the options. For ex- space that can be avoided if \centering is used instead.)
ample, you could use a layout with two columns for your
You can use intextsep parameter to control
documents and have no text-wrapping at all.
additional space above and below the gure:
Anyway, we will look at the package wrapg. Note that \setlength\intextsep{0pt}
wrapg may not come with the default installation of LaAlternatively you might use the picins package instead
TeX; you might need to install additional packages.
of the wrapg package which produces a correct version
To use wrapg, you must rst add this to the preamble:
without the excess white space out of the box without any
hand tuning.
This then gives you access to:
There is also an alternative to wrapg: the package oatt
There are overall eight possible positioning targets:
.
The uppercase-character allows the gure to oat, while
To remove the white space from a gure once for all, one
the lowercase version means exactly here. [4]
should refer to the program pdfcrop, included in most
The width is, of course, the width of the gure. An ex- TeX installations.
ample:
You can also allow LaTeX to assign a width to the wrap
by setting the width to 0pt. \begin{wrapgure}{l}{0pt} 2.14.7
Note that we have specied a size for both the wrapgure
environment and the image we have included. We did it
in terms of the text width: it is always better to use relative sizes in LaTeX, let LaTeX do the work for you! The
wrap is slightly bigger than the picture, so the compiler
will not return any strange warning and you will have a
small white frame between the image and the surrounding text. You can change it to get a better result, but if
you don't keep the image smaller than the wrap, you
will see the image over the text.

Suboats

A useful extension is the subcaption package which uses


suboats within a single oat. The subgure and subg
packages are deprecated however they are useful alternatives when used in-conjunction with latex templates (i.e
templates for journals from Springer and IOP, IEEETran
and ACM SIG) that are not compatible with subcaption.
These packages gives the author the ability to have subgures within gures, or subtables within table oats. Suboats have their own caption, and an optional global caption. An example will best illustrate the usage of the subThe wrapg package can also be used with user-dened caption package:

68

CHAPTER 2. COMMON ELEMENTS


To prevent the gures from being placed out-of-order
with respect to their non-starred counterparts, the
package xltx2e [5] should be used (e.g. \usepackage{xltx2e}).

2.14.9 Custom oats


If tables and gures are not adequate for your needs, then
You will notice that the gure environment is set up as you always have the option to create your own! Examusual. You may also use a table environment for subta- ples of such instances could be source code examples, or
bles. For each suboat, you need to use:
maps. For a program oat example, one might therefore
If you intend to cross-reference any of the suboats, see wish to create a oat named program. The package oat
where the label is inserted; \caption outside the subgure- is your friend for this task. All commands to set up the
new oat must be placed in the preamble, and not within
environment will provide the global caption.
the document.
subcaption will arrange the gures or tables side-by-side
providing they can t, otherwise, it will automatically
1. Add \usepackage{oat} to the preamble of your
shift suboats below. This eect can be added manually,
document
by putting the newline command (\\) before the gure you
wish to move to a newline.
2. Declare
your
new
oat
using:
Horizontal spaces between gures are controlled by one
\newoat{type}{placement}{ext}[outer counter],
of several commands, which are placed in between \bewhere:
gin{subgure} and \end{subgure}:
type - the new name you wish to call your oat,
in this instance, 'program'.
A non-breaking space (specied by ~ as in the example above) can be used to insert a space in between
placement - t, b, p, or h (as previously dethe subgs.
scribed in Placement), where letters enumer Math spaces: \qquad, \quad, \;, and \,
Generic space: \hspace{''length''}
Automatically expanding/contracting space: \hll

2.14.8

Wide gures in two column documents

If you are writing a document using two columns (i.e.


you started your document with something like \documentclass[twocolumn]{article}), you might have noticed
that you can't use oating elements that are wider than the
width of a column (using a LaTeX notation, wider than
0.5\textwidth), otherwise you will see the image overlapping with text. If you really have to use such wide elements, the only solution is to use the starred variants
of the oating environments, that are {gure*} and {table*}. Those starred versions work like the standard
ones, but they will be as wide as the page, so you will get
no overlapping.
A bad point of those environments is that they can be
placed only at the top of the page or on their own page. If
you try to specify their position using modiers like b or
h they will be ignored. Add \usepackage{dbloatx} to
the preamble in order to alleviate this problem with regard
to placing these oats at the bottom of a page, using the
optional specier [b]. Default is [tbp]. However, h still
does not work.

ate permitted placements.


ext - the le name extension of an auxiliary
le for the list of gures (or whatever). Latex
writes the captions to this le.
outer counter - the presence of this parameter
indicates that the counter associated with this
new oat should depend on outer counter, for
example 'chapter'.
3. The default name that appears at the start of the caption is the type. If you wish to alter this, use \oatname{type}{oatname}
4. Changing oat style can be issued with \oatstyle{style} (Works on all subsequent \newoat
commands, therefore, must be inserted before
\newoat to be eective).
plain - the normal style for Latex oats, but the
caption is always below the content.
plaintop - the normal style for Latex oats, but
the caption is always above the content.
boxed - a box is drawn that surrounds the oat,
and the caption is printed below.
ruled - the caption appears above the oat,
with rules immediately above and below. Then
the oat contents, followed by a nal horizontal rule.

2.15. LATEX/HYPERLINKS

69

Float styles can also be customized as the second example in the same way is TikZ. TikZ is a front-end to a drawbelow illustrates.
ing library called pgf (which is used to make beamer for
instance). It can be used to label gures by adding text
An example document using a new program oat type:
nodes on top of an image node.
The verbatim environment is an environment that is already part of Latex. Although not introduced so far, its
name is fairly intuitive! LaTeX will reproduce everything 2.14.11 Summary
you give it, including new lines, spaces, etc. It is good for
source code, but if you want to introduce a lot of code That concludes all the fundamentals of oats. You will
you might consider using the listings package, that was hopefully see how much easier it is to let LaTeX do all
made just for it.
the hard work and tweak the page layouts in order to get
While this is useful, one should be careful when embed- your gures in the best place. As always, the fact that
ding the oat within another oat. In particular, the error LaTeX takes care of all caption and reference numbering
is a great time saver.
not in outer par mode
may occur. One solution might be to use the [H] option
(not any other) on the inner oat, as this option pins the 2.14.12
inner oat to the outer one.
Newly created oats with \newoat can also be used in
combination with the wrapg package from above. E.g.
the following code creates a oating text box, which oats
in the text on the right side of the page and is complete
with caption, numbering, an index le with the extension
.lob and a customization of the oats visual layout:
Caption styles
To change the appearance of captions, use the caption
package. For example, to make all caption labels small
and bold:

Notes and references

[1] [Link]
float/
[2] Float environment positioning, by Frank Mittelbach
[3] [Link]
how-to-place-a-float-at-the-top-of-a-floats-only-page
[4] [Link]
contrib/wrapfig/[Link]
[5] [Link]
2colfltorder

This page uses material from Andy Roberts Getting to grips


The KOMA script packages have their own caption cus- with LaTeX with permission from the author.
tomizing features with e.g. \captionabove, \captionformat
and \setcapwidth. However these denitions have limited
eect on newly created oat environments with the wrap2.15 LaTeX/Hyperlinks
g package.
Alternatively, you can redene the \thegure command:

LaTeX enables typesetting of hyperlinks, useful when the


See this page for more information on counters. Finally, resulting format is PDF, and the hyperlinks can be folnote that the caption2 package has long been deprecated. lowed. It does so using the package hyperref.

2.14.10

Labels in the gures

2.15.1 Hyperref

The package hyperref[1] provides LaTeX the ability to


create hyperlinks within the document. It works with
pdatex and also with standard latex used with dvips
and ghostscript or dvipdfm to build a PDF le. If you
load it, you will have the possibility to include interactive external links and all your internal references will be
turned to hyperlinks. The compiler pdatex makes it possible to create PDF les directly from the LaTeX source,
and PDF supports more features than DVI. In particular
PDF supports hyperlinks, and the only way to introduce
A very similar package, with somewhat dierent syntax, them in LaTeX is using hyperref. Moreover, PDF can
is pinlabel . The link given also points to the packages contain other information about a document such as the
psfrag and overpic.
title, the author, etc., which can be edited using this same
A much more complicated package which can be used package.
There is a LaTeX package lpic to put LaTeX on top of
included graphics, thus allowing to add TeX annotations
to imported graphics. It denes a convenient interface to
put TeX over included graphics, and allows for drawing
a white background under the typeset material to overshadow the graphics. It is a better alternative for labels
inside of graphics; you do not have to change text size
when rescaling pictures, and all LaTeX power is available
for labels.

70

CHAPTER 2. COMMON ELEMENTS

2.15.2

Usage

It just shows your email address (so people can know it


even if the document is printed on paper) but, if the reader
The basic usage with the standard settings is straightfor- clicks on it, (s)he can easily send you an email. Or, to
incorporate the url packages formatting and line breaking
ward. Just load the package in the preamble:
abilities into the displayed text, use[2]
This will automatically turn all your internal references
into hyperlinks. It won't aect the way to write your When using this form, note that the \nolinkurl command
documents: just keep on using the standard \label-\ref is fragile and if the hyperlink is inside of a moving argusystem (discussed in the chapter on Labels and Cross- ment, it must be preceeded by a \protect command.
referencing); with hyperref those connections will become links and you will be able to click on them to be
redirected to the right page. Moreover the table of con- Local le Files can also be linked using the url or the
tents, list of gures/tables and index will be made of hy- href commands. You simply have to add the string run:
perlinks, too. The hyperlinks will not show-up if you are at the beginning of the link string:
working in draft mode.
Following
[Link]
46488/link-to-local-pdf-file the version with url does
not always work, but href does.
Commands
It is possible to use relative paths to link documents near
The package provides some useful commands for insert- the location of your current document; in order to do so,
ing links pointing outside the document.
use the standard Unix-like notation (./ is the current directory, ../ is the previous directory, etc.)
\hyperref

Usage:

This will have the same eect as \ref{label_name} but


will make the text link text a full link, instead. The two
can be combined. If the lemma labelled as mainlemma
was number 4.1.1 the following example would result in

Hyperlink and Hypertarget It is also possible to create an anchor anywhere in the document (with or without
caption) and to link to it. To create an anchor, use:
and to link to it, use:

with the hyperlink as expected. Note the "*" after \ref where the target caption and link caption are the text that
for avoiding nested hyperlinks.
is displayed at the target location and link location respectively.
\url

Usage:

It will show the URL using a mono-spaced font and, if 2.15.3 Customization
you click on it, your browser will be opened pointing at
it.
The standard settings should be ne for most users, but
if you want to change something, that is also possible.
There are several variables and two methods to pass those
\href Usage:
to the package. Options can be passed as an argument of
It will show the string description using standard docu- the package when it is loaded (the standard way packages
ment font but, if you click on it, your browser will be work), or the \hypersetup command can be used as folopened pointing at my_url. Here is an example:
lows:
Both point at the same page, but in the rst case the URL
will be shown, while in the second case the URL will be
hidden. Note that, if you print your document, the link
stored using \href will not be shown anywhere in the document.
Other possibilities

you can pass as many options as you want; separate them


with a comma. Options have to be in the form:
exactly the same format has to be used if you pass those
options to the package while loading it, like this:
Here is a list of the possible variables you can change (for
the complete list, see the ocial documentation). The
default values are written in an upright font:

Checkout 3.8 Big list at hyperref-manual at [Link]


Apart from linking to websites discussed above, hyperref
can be used to provide mailto links, links to local les, Please note, that explicit RGB specication is only allowed for the border colors (like linkbordercolor etc.),
and links to anywhere within the PDF output le.
while the others may only assigned to named colors
(which you can dene your own, see Colors). In order
E-mail address A possible way to insert email links is to speed up your customization process, here is a list with
by
the variables with their default value. Copy it in your doc-

2.15. LATEX/HYPERLINKS

71

ument and make the changes you want. Next to the vari- 1 would not be unique anymore, hence the notice that
ables, there is a short explanations of their meaning:
duplicate has been ignored. The counter measure conIf you don't need such a high customization, here are sists of putting plainpages=false into the hyperref options.
some smaller but useful examples. When creating PDFs This unfortunately only helps with the page counter. An
destined for printing, colored links are not a good thing as even more radical solution is to use the option hypertexthey end up in gray in the nal output, making it dicult names=false, but this will cause the page links in the index
to read. You can use color frames, which are not printed: to stop working.
or make links black:

The best solution is to give each page a unique name by


using the \pagenumbering command:

When you just want to provide information for the Document Info section of the PDF le, as well as enabling Another solution is to use \pagenumbering{alph} before
the command \maketitle, which will give the title page
back references inside bibliography:
the label page.a. Since the page number is suppressed, it
By default, URLs are printed using mono-spaced fonts. won't make a dierence to the output.
If you don't like it and you want them to be printed with
By changing the page numbering every time before the
the same style of the rest of the text, you can use this:
counter is reset, each page gets a unique name. In this
case, the pages would be numbered a, b, c, i, ii, iii, iv, v,
1, 2, 3, 4, 5, ...
2.15.4 Troubleshooting
Problems with Links and Equations 1
Messages like the following

If you don't want the page numbers to be visible (for example, during the front matter part), use
\pagestyle{empty} ... \pagestyle{plain}. The important
point is that although the numbers are not visible, each
page will have a unique name.

! pdfTeX warning (ext4): destination with the same identier (name{ equation.[Link]}) has been already used, Another more exible approach is to set the counter to
something negative:
duplicate ignored
appear, when you have made something like

which will give the rst pages a unique negative number.

The problem can also occur with the algorithms package:


because each algorithm uses the same line-numbering
Beware that the shown line number is often completely
scheme, the line identiers for the second and follow-on
dierent from the erroneous line.
algorithms will be duplicates of the rst.
Possible solution: Place the amsmath package before the
The problem occurs with equation identiers if you
hyperref package.
use \nonumber on every line of an eqnarray environment. In this case, use the *'ed form instead, e.g. \begin{eqnarray*} ... \end{eqnarray*} (which is an unnumProblems with Links and Equations 2
bered equation array), and remove the now unnecessary
\nonumber commands.
Messages like the following
The error disappears, if you use instead this form:

! Runaway argument? {\@rstove }\ ), Some text If your urls are too long and running o of the page, try
from your document here (\ref {re\ETC. Latex Error: using the breakurl package to split the url over multiple
Paragraph ended before \Hy@setref@link was complete. lines. This is especially important in a multicolumn environment where the line width is greatly shortened.
appear when you use \label inside an align environment.
Possible solution: Add the following to your preamble:

Problems with bookmarks

The text displayed by bookmarks does not always look


like you expect it to look. Because bookmarks are just
text, much fewer characters are available for bookmarks
Messages like the following:
than for normal LaTeX text. Hyperref will normally no! pdfTeX warning (ext4): destination with the same iden- tice such problems and put up a warning:
tier (name{page.1}) has been already used, duplicate igPackage hyperref Warning: Token not allowed in a PDFnored
DocEncoded string:
appear when a counter gets reinitialized, for example by
using the command \mainmatter provided by the book You can now work around this problem by providing a
document class. It resets the page number counter to 1 text string for the bookmarks, which replaces the oendprior to the rst chapter of the book. But as the preface ing text:
of the book also has a page number 1 all links to page Math expressions are a prime candidate for this kind of
Problems with Links and Pages

72
problem:

CHAPTER 2. COMMON ELEMENTS


Problems with footnotes and special characters

which turns \section{$E=mc^2$} to E=mc2 in the bookmark area. Color changes also do not travel well into See the relevant section.
bookmarks:
produces the string redRed!". The command \textcolor Problems with Beamer
gets ignored but its argument (red) gets printed. If you
Using the command
use:
is broken when pointed at a label. Instead of sending the
user to the desired label, upon clicking the user will be
If you write your document in unicode and use the unisent to the rst frame. A simple work around exists; incode option for the hyperref package you can use unicode
stead of using
characters in bookmarks. This will give you a much larger
selection of characters to pick from when using \texor- to label your frames, use
pdfstring.
and reference it with
the result will be much more legible.

Problems with tables and gures

Problems with draft mode

The links created by hyperref point to the label created


within the oat environment, which, as previously described, must always be set after the caption. Since the
caption is usually below a gure or table, the gure or table itself will not be visible upon clicking the link[4] . A
workaround exists by using the package hypcap with:

WARNING! Please note that if you have activated the


draft"-option in your \documentclass declaration the hyperlinks will not show up in the table of contents!!!

Be sure to call this package after loading hyperref.


If you use the wrapg package[5] mentioned in the
"Wrapping text around gures" section of the Floats,
Figures and Captions chapter, or other similar packages
that dene their own environments, you will need to manually include \capstart in those environments, e.g.:
Problems with long caption and \listogures or long
title
There is an issue when using \listogures with hyperref for long captions or long titles. This happens when
the captions (or the titles) are longer than the page width
(about 7-9 words depending on your settings). To x this,
you need to use the option breaklinks when rst declaring:
This will then cause the links in the \listogures to word
wrap properly.

2.15.5 Notes and References


[1] Hyperref package webpage in CTAN
[2] Email link with hyperref, url packages. [Link]
User Group.
[Link]
[Link]/browse_thread/thread/ae160fd2fc5680a5/
71a5a7c7bfceb3cb?lnk=gst&q=email+url+hyperref#
71a5a7c7bfceb3cb. Retrieved 2008.
[3] Other possible values are dened in the hyperref manual
[4] [Link]
hyperref/README
[5] Wrapg package webpage in CTAN

2.16 LaTeX/Labels
referencing

and

Cross-

2.16.1 Introduction

Problems with already existing .toc, .lof and similar Another good point of LaTeX is that you can easily reference almost anything that is numbered (sections, gures,
les
formulas), and LaTeX will take care of numbering, upThe format of some of the auxilliary les generated by la- dating it whenever necessary. The commands to be used
tex changes when you include the hyperref package. One do not depend on what you are referencing, and they are:
can therefore encounter errors like
! Argument of \Hy@setref@link has an extra }.

\label{marker} you give the object you want to reference


a marker, you can see it like a name.

when the document is typeset with hyperref for the rst


time and these les already exist. The solution to the \ref{marker} you can reference the object you have
marked before. This prints the number that was asproblem is to delete all the les that latex uses to get refsigned to the object.
erences right and typeset again.

2.16. LATEX/LABELS AND CROSS-REFERENCING

73

\pageref{marker} It will print the number of the page document. For more information see the Packages secwhere the object is.
tion.
LaTeX will calculate the right numbering for the objects
in the document; the marker you have used to label the
object will not be shown anywhere in the document. Then
LaTeX will replace the string "\ref{marker}" with the
right number that was assigned to the object. If you reference a marker that does not exist, the compilation of
the document will be successful but LaTeX will return a
warning:
LaTeX Warning: There were undened references.
and it will replace "\ref{unknown-marker}" with "??" (so
it will be easy to nd in the document).

2.16.2 Examples
Here are some practical examples, but you will notice that
they are all the same because they all use the same commands.
Sections
\section{Greetings}
\label{sec:greetings}
Hello!
\section{Referencing} I greeted in section~\ref{sec:
greetings}.

As you may have noticed reading how it works, it is a twostep process: rst the compiler has to store the labels with
the right number to be used for referencing, then it has to
replace the \ref with the right number. That is why, when
you use references, you have to compile your document
twice to see the proper output. If you compile it only
once, LaTeX will use the older information it collected
in previous compilations (that might be outdated), but the
compiler will inform you printing on the screen at the end
of the compilation:
You could place the label anywhere in the section; however, in order to avoid confusion, it is better to place it
immediately after the beginning of the section. Note how
LaTeX Warning: Label(s) may have changed.
the marker starts with sec:, as suggested before. The laRerun to get cross-references right.
bel is then referenced in a dierent section. The tilde (~)
indicates a non-breaking space.
Using the command \pageref{} you can help the reader
to nd the referenced object by providing also the page
number where it can be found. You could write some- Pictures
thing like:
You can reference a picture by inserting it in the gure
See gure~\ref{fig:test} on page~\pageref{fig:test}.
oating environment.
Since you can use exactly the same commands to reference almost anything, you might get a bit confused after
you have introduced a lot of references. It is common
practice among LaTeX users to add a few letters to the label to describe what you are referencing. Some packages,
such as fancyref, rely on this meta information. Here is
an example:

\begin{gure}
\centering
\includegraphics[width=0.5\textwidth]{gull} \caption{Close-up of a
gull} \label{fig:gull} \end{gure} Figure~\ref{fig:gull}
shows a photograph of a gull.
When a label is declared within a oat environment, the

Following this convention, the label of a gure will look


like \label{g:my_gure}, etc. You are not obligated to
use these prexes. You can use any string as argument of
\label{...}, but these prexes become increasingly useful
as your document grows in size.
Another suggestion: try to avoid using numbers within
labels. You are better o describing what the object is
about. This way, if you change the order of the objects,
you will not have to rename all your labels and their references.
If you want to be able to see the markers you are using
in the output document as well, you can use the showkeys
package; this can be very useful while developing your \ref{...} will return the respective g/table number, but it

74
must occur after the caption. When declared outside, it
will give the section number. To be completely safe, the
label for any picture or table can go within the \caption{}
command, as in

CHAPTER 2. COMMON ELEMENTS


of the times you will be using the equation environment;
that is the best choice for one-line formulae, whether you
are using amsmath or not. Note also the eq: prex in the
label.

\caption{Close-up of a gull\label{fig:gull}}
eqref The amsmath package adds a new command for
See the Floats, Figures and Captions section for more referencing formulae; it is \eqref{}. It works exactly like
\ref{}, but it adds parentheses so that, instead of printing
about the gure and related environments.
a plain number as 5, it will print (5). This can be useful
to help the reader distinguish between formulae and other
Fixing wrong labels The command \label must ap- things, without the need to repeat the word formula bepear after (or inside) \caption. Otherwise, it will pick up fore any reference. Its output can be changed as desired;
the current section or list number instead of what you in- for more information see the amsmath documentation.
tended.
\begin{gure}
\centering
\includegraphics[width=0.5\textwidth]{gull}
\caption{Close-up tag The \tag{eqnno} command is used to manually set
equation numbers where eqnno is the arbitrary text string
of a gull} \label{fig:gull} \end{gure}
you want to appear in the document. It is normally better
to use labels, but sometimes hard-coded equation numbers might oer a useful work-around. This may for inIssues with links to tables and gures handled by stance be useful if you want to repeat an equation that is
hyperref In case you use the package hyperref to cre- used before, e.g. \tag{\ref{eqn:before}}.
ate a PDF, the links to tables or gures will point to the
caption of the table or gure, which is always below the
table or gure itself[1] . Therefore the table or gure will numberwithin The amsmath package adds the
not be visible, if it is above the pointer and one has to \numberwithin{countera}{counterb} command which
scroll up in order to see it. If you want the link point to replaces the simple countera by a more sophistiFor example \numberthe top of the image you can give the option hypcap to cated [Link].
within{equation}{section} in the preamble will prepend
the caption package:
the section number to all equation numbers.
\usepackage[hypcap]{caption}

Formulae
Here is an example showing how to reference formulae:
\begin{equation} \label{eq:solve} x^2 - 5 x + 6 =
0 \end{equation} \begin{equation} x_1 = \frac{5 +
\sqrt{25 - 4 \times 6}}{2} = 3 \end{equation} \begin{equation} x_2 = \frac{5 - \sqrt{25 - 4 \times 6}}{2}
= 2 \end{equation} and so we have solved equation
~\ref{eq:solve}

cases The cases package adds the \numcases and


the \subnumcases commands, which produce multi-case
equations with a separate equation number and a separate
equation number plus a letter, respectively, for each case.

2.16.3 The varioref package


The varioref package introduces a new command called
\vref{}. This command is used exactly like the basic \ref,
but it has a dierent output according to the context. If
the object to be referenced is in the same page, it works
just like \ref; if the object is far away it will print something like 5 on page 25, i.e. it adds the page number automatically. If the object is close, it can use more rened
sentences like on the next page or on the facing page
automatically, according to the context and the document
class.

This command has to be used very carefully. It outputs


more than one word, so it may happen its output falls on
two dierent pages. In this case, the algorithm can get
confused and cause a loop. Lets make an example. You
label an object on page 23 and the \vref output happens
As you can see, the label is placed soon after the begin- to stay between page 23 and 24. If it were on page 23,
ning of the math mode. In order to reference a formula, it would print like the basic ref, if it were on page 24, it
you have to use an environment that adds numbers. Most would print on the previous page, but it is on both, and

2.16. LATEX/LABELS AND CROSS-REFERENCING


this may cause some strange errors at compiling time that
are very hard to be xed. You could think that this happens very rarely; unfortunately, if you write a long document it is not uncommon to have hundreds of references,
so situations like these are likely to happen. One way to
avoid problems during development is to use the standard
ref all the time, and convert it to vref when the document
is close to its nal version, and then making adjustments
to x possible problems.

2.16.4

The hyperref package

75
nameref
The hyperref package also automatically includes the
nameref package, and a similarly named command. It
is similar to \autoref{}, but inserts text corresponding to
the section name, for example.
Input:
\section{MyFirstSection} \label{sec:marker} \section{MySecondSection} In section~\nameref{sec:
marker} we dened...
Output:

autoref

In section MyFirstSection we dened...

The hyperref package introduces another useful command; \autoref{}. This command creates a reference
with additional text corresponding to the targets type,
all of which will be a hyperlink. For example, the command \autoref{sec:intro} would create a hyperlink to the
\label{sec:intro} command, wherever it is. Assuming
that this label is pointing to a section, the hyperlink would
contain the text section 3.4, or similar (the full list of
default names can be found here). Note that, while theres
an \autoref* command that produces an unlinked prex
(useful if the label is on the same page as the reference),
no alternative \Autoref command is dened to produce
capitalized versions (useful, for instance, when starting
sentences); but since the capitalization of autoref names
was chosen by the package author, you can customize the
prexed text by redening \typeautorefname to the prex
you want, as in:

Anchor manual positioning


When you dene a \label outside a gure, a table, or other
oating objects, the label points to the current section. In
some cases, this behavior is not what you'd like and you'd
prefer the generated link to point to the line where the
\label is dened. This can be achieved with the command
\phantomsection as in this example:
%The link location will be placed on the line below.
\phantomsection \label{the_label}

2.16.5 The cleveref package

The cleveref package introduces the new command


\cref{} which includes the type of referenced object like
\def\sectionautorefname{Section}
\autoref{} does. The alternate \labelcref{} command
works more like standard \ref{}. References to pages are
This renaming trick can, of course, be used for other pur- handled by the \cpageref{} command.
poses as well.
The \crefrange{}{} and \cpagerefrange{} commands expect a start and end label in either order and provide a
natural language (babel enabled) range. If labels are enu If you would like a hyperlink reference, but merated as a comma-separated list with the usual \cref{}
do not want the predened text that \autoref{} command, it will sort them and group into ranges autoprovides, you can do this with a command such matically.
as
\hyperref[sec:intro{]}\protect\char"007B\
The format can be specied in the preamble.
relaxAppendix~{}\char"005C\relax{}ref*\
protect\char"007B\relaxsec:intro}}.
Note that
you can disable the creation of hyperlinks in hy- 2.16.6 See also
perref, and just use these commands for automatic
text.
LaTeX/Glossary
Keep in mind that the \label must be placed inside 2.16.7 Notes and References
an environment with a counter, such as a table or
a gure. Otherwise, not only the number will refer [1] [Link]
hyperref/README
to the current section, as mentioned above, but the
name will refer to the previous environment with a
counter. For example, if you put a label after closing
a gure, the label will still say gure n, on which
n is the current section number.

Chapter 3

Mechanics
3.1 LaTeX/Errors and Warnings
LaTeX describes what it is typesetting while it does it. If
it encounters something it doesn't understand or can't do,
it will display a message saying what is wrong. It may also
display warnings for less serious conditions.

cessfully) by interfering with the letter spacing, LaTeX


takes the view that the author or editor should be able to
contribute. While it is certainly possible to set LaTeXs
parameters so that the spacing is suciently sloppy that
you will almost never get a warning about badly-tting
lines or pages, you will almost certainly just be delaying
matters until you start to get complaints from your readers
or publishers.

Don't panic if you see error messages: it is very common


to mistype or misspell commands, forget curly braces,
type a forward slash instead of a backslash, or use a special character by mistake. Errors are easily spotted and
3.1.3 Examples
easily corrected in your editor, and you can then run LaTeX again to check you have xed everything. Some of
Only a few common error messages are given here: those
the most common errors are described in next sections.
most likely to be encountered by beginners. If you nd
another error message not shown here, and its not clear
what you should do, ask for help.
3.1.1 Error messages
The format of an error message is always the same. Error messages begin with an exclamation mark at the start
of the line, and give a description of the error, followed
by another line starting with the number, which refers to
the line-number in your document le which LaTeX was
processing when the error was spotted. Heres an example, showing that the user mistyped the \tableofcontents
command:
! Undened control sequence. l.6 \tableofcotnetns

Most error messages are self-explanatory, but be aware


that the place where LaTeX spots and reports an error
may be later in the le than the place where it actually
occurred. For example if you forget to close a curly brace
which encloses, say, italics, LaTeX won't report this until
something else occurs which can't happen until the curly
brace is encountered (e.g. the end of the document!)
Some errors can only be righted by humans who can read
and understand what the document is supposed to mean
or look like.

When LaTeX nds an error like this, it displays the error Newcomers should remember to check the list of special
message and pauses. You must type one of the following characters: a very large number of errors when you are
learning LaTeX are due to accidentally typing a special
letters to continue:
character when you didn't mean to. This disappears after
Some systems (Emacs is one example) run LaTeX with a few days as you get used to them.
a nonstop switch turned on, so it will always process
through to the end of the le, regardless of errors, or until
a limit is reached.
Too many }'s

3.1.2

! Too many }'s. l.6 \date December 2004}

Warnings

Warnings don't begin with an exclamation mark: they are


just comments by LaTeX about things you might want
to look into, such as overlong or underrun lines (often
caused by unusual hyphenations, for example), pages running short or long, and other typographical niceties (most
of which you can ignore until later). Unlike other systems,
which try to hide unevennesses in the text (usually unsuc-

The reason LaTeX thinks there are too many }'s here is
that the opening curly brace is missing after the \date control sequence and before the word December, so the closing curly brace is seen as one too many (which it is!).
In fact, there are other things which can follow the \date
command apart from a date in curly braces, so LaTeX
cannot possibly guess that you've missed out the opening
curly brace until it nds a closing one!

76

3.1. LATEX/ERRORS AND WARNINGS

77

Undened control sequence

typesetting when it found this, and the number in square


brackets is the number of the page onto which the of! Undened control sequence. l.6 \dtae {December fending line was printed. The codes separated by slashes
are the typeface and font style and size used in the line.
2004}
Ignore them for the moment.
In this example, LaTeX is complaining that it has no such
command (control sequence) as \dtae. Obviously its This comes up if you force a linebreak, e.g., \\, and have
been mistyped, but only a human can detect that fact: all a return before it. Normally TeX ignores linebreaks, proLaTeX knows is that \dtae is not a command it knows viding full paragraphs to ragged text. In this case it is
about: its undened. Mistypings are the most common necessary to pull the linebreak up one line to the end of
source of errors. Some editors allow common commands the previous sentence.
and environments to be inserted using drop-down menus
or icons, which may be used to avoid these errors.
Overfull hbox
Not in Mathematics Mode
! Missing $ inserted
A character that can only be used in the mathematics was
inserted in normal text. If you intended to use mathematics mode, then use $...$ or \begin{math}...\end{math} or
use the 'quick math mode': \ensuremath{...}. If you did
not intend to use mathematics mode, then perhaps you are
trying to use a special character that needs to be entered
in a dierent way; for example _ will be interpreted as a
subscript operator in mathematics mode, and you need \_
to get an underscore character.
This can also happen if you use the wrong character
encoding, for example using utf8 without "\usepackage[utf8]{inputenc}" or using iso8859-1 without "\usepackage[latin1]{inputenc}", there are several character
encoding formats, make sure to pick the right one.
Runaway argument

[101] Overfull \hbox (9.11617pt too wide) in paragraph at lines 860-861 []\LY1/brm/m/n/10 Windows,
\LY1/brm/m/it/10 see \LY1/brm/m/n/10 X WinAn overfull \hbox means that there is a hyphenation or
justication problem: moving the last word on the line
to the next line would make the spaces in the line wider
than the current limit; keeping the word on the line would
make the spaces smaller than the current limit, so the
word is left on the line, but with the minimum allowed
space between words, and which makes the line go over
the edge.
The warning is given so that you can nd the line in the
code that originates the problem (in this case: 860-861)
and x it. The line on this example is too long by a shade
over 9pt. The chosen hyphenation point which minimizes
the error is shown at the end of the line (Win-). Line numbers and page numbers are given as before. In this case,
9pt is too much to ignore (over 3mm), and a manual correction needs making (such as a change to the hyphenation), or the exibility settings need changing.

Runaway argument? {December 2004 \maketitle ! Para- If the overfull word includes a forward slash, such as
graph ended before \date was complete. <to be read input/output, this should be properly typeset as input\slash output. The use of \slash has the same eect
again> \par l.8
as using the "/" character, except that it can form the end
In this error, the closing curly brace has been omitted of a line (with the following words appearing at the start
from the date. Its the opposite of the error of too many of the next line). The "/" character is typically used in
}'s, and it results in \maketitle trying to format the title units, such as mm/year character, which should not be
page while LaTeX is still expecting more text for the date! broken over multiple lines.
As \maketitle creates new paragraphs on the title page,
this is detected and LaTeX complains that the previous The warning can also be issued when the \end{document}
tag was not included or was deleted.
paragraph has ended but \date is not yet nished.
Easily spotting overfull hboxes in the document To
easily nd the location of overfull hbox in your document,
Underfull \hbox (badness 1394) in paragraph at lines 28- you can make latex add a black bar where a line is too
30 [][]\LY1/brm/b/n/10 Bull, RJ: \LY1/brm/m/n/10 wide:
Ac-count-ing in Busi- [94]
Underfull hbox

This is a warning that LaTeX cannot stretch the line wide


enough to t, without making the spacing bigger than its
currently permitted maximum. The badness (0-10,000)
indicates how severe this is (here you can probably ignore
a badness of 1394). It says what lines of your le it was

Missing package
! LaTeX Error: File `[Link]' not found. Type X
to quit or <RETURN> to proceed, or enter new name.
(Default extension: sty) Enter le name:

78

CHAPTER 3. MECHANICS

When you use the \usepackage command to request LaTeX to use a certain package, it will look for a le with
the specied name and the letype .sty. In this case the
user has mistyped the name of the paralist package, so its
easy to x. However, if you get the name right, but the
package is not installed on your machine, you will need
to download and install it before continuing. If you don't
want to aect the global installation of the machine, you
can simply download from Internet the necessary .sty le
and put it in the same folder of the document you are
compiling.

Package babel Warning: No hyphenation patterns


were loaded for the language X

nag
([Link]/tex-archive/macros/latex/
contrib/nag) is a LaTeX package designed to
indicate the use of obsolete commands.
lacheck
([Link]/tex-archive/support/
lacheck) is a consistency checker intended to spot
mistakes in code. It is available as source code or
compiled for Windows and OS/2
chktex ([Link]/proj/chktex/) is a LaTeX
semantic checker available as source code for Unixlike systems.

3.2 LaTeX/Lengths

Although this is a warning from the Babel package and In TeX, a length is
not from LaTeX, this error is very common and (can) give
a oating point number followed by a unit, optionally
some strange hyphenation (word breaking) problems in
followed by a stretching value;
your document. Wrong hyphenation rules can decrease
the neatness of your document.
a oating point factor followed by a macro that exPackage babel Warning: No hyphenation patterns were
pands to a length.
loaded for (babel) the language `Latin' (babel) I will use
the patterns loaded for \language=0 instead.
This can happen after the
LaTeX/Internationalization)

usage

of:

(see 3.2.1

Units

First, we introduce the LaTeX measurement units. All


LaTeX units are two-letter abbreviations. You can
The solution is not dicult, just install the used language choose from a variety of units. Here are the most common ones.[1]
in your LaTeX distribution.
\usepackage[latin]{babel}

And here are some less common units.[2]


Package babel Error: You haven't loaded the option
X yet.
3.2.2

Box lengths

If you previously set the X language, and then decided A box in TeX is characterized by three lengths:
to switch to Y, you will get this error. This may seem
awkward, as there is obviously no error in your code if
depth
you did not change anything. The answer lies in the .aux
height
le, where babel dened your language. If you try the
compilation a second time, it should work. If not, delete
width
the .aux le, then everything will work as usual.
See Boxes.
No error message, but won't compile

3.2.3 Length manipulation

One common cause of (pdf)LaTeX getting stuck is forgetting to include \end{document}


You can change the values of the variables dening the
page layout with two commands. With this one you can
set a new value for an existing length variable:

3.1.4

Software that can check your .tex with this other one, you can add a value to the existing
Code
one:

There are several programs capable of checking LaTeX


source, with the aim of nding errors or highlighting bad
practice, and providing more help to (particularly novice)
users than the built-in error messages.

You can create your own length with the command, and
you must create a new length before you attempt to set it:
You may also set a length from the size of a text with one
of these commands:

3.2. LATEX/LENGTHS

79

When using these commands, you may duplicate the text \topmargin The size of the top margin.
that you want to use as reference if you plan to also display it. But LaTeX also provides \savebox to avoid this \unitlength Units of length in picture environment.
duplication. You may wish to look at the example below
to see how you can use these. See Boxes for more details. 3.2.5 Fixed-length spaces
You can also dene stretched values. A stretching value
is a length preceded by plus or minus to specify to what To insert a xed-length space, use:
extent tex is authorized to change the length. Example:
\hspace stands for horizontal space, \vspace for vertical
It means that tex will try to use a length of 10pt; if it is un- space.
derfull, it will raise the length up to a maximum of 15pt; If such a space should be kept even if it falls at the end or
if it is overfull, it will lower the length up to a minimum the start of a line, use \hspace* instead.
of 7pt.
If the space should be preserved at the top or at the botNote that it is not mandatory to specify both the plus and tom of a page, use the starred version of the command,
the minus values, but if you do, latxpar must be placed \vspace*, instead of \vspace. If you want to add space
before minus.
at the beginning of the document, without anything else
written before, then you may use
To print a length, you can use the \the command:
Plain TeX

Its important you use the \vspace* command instead of


\vspace, otherwise LaTeX can silently ignore the extra
space.

To create a new length:

TeX features some macros for xed-length spacing.

To set a length:
To view, it is the same as with LaTeX, using the command
\the.

3.2.4

LaTeX default lengths

Common length macros are:

\smallskip Inserts a small space in vertical mode (between two paragraphs).


\medskip Inserts a medium space in vertical mode (between two paragraphs).
\bigskip Inserts a big space in vertical mode (between
two paragraphs).

\baselineskip The normal vertical distance between The vertical mode is during the process of assembling
boxes vertically, like paragraphs to build a page. The
lines in a paragraph.
horizontal mode is during the process of assembling
boxes horizontally, like letters to build a word or words
\baselinestretch Multiplies \baselineskip.
to build a paragraph.
\columnsep The distance between columns.
The fact they are vertical mode commands mean they will
\columnwidth The width of the column.
be ignored (or fail) in horizontal mode such as in the middle of a paragraph. The rst token next the a double line\evensidemargin The margin for 'even' pages (think of
break is still in vertical mode if it does not expand to chara printed booklet).
acters.
\linewidth The width of a line in the local environment.
\oddsidemargin The margin for 'odd' pages (think of a
printed booklet).
\paperwidth The width of the page.
\paperheight The height of the page.
\parindent The normal paragraph indentation.
\parskip The extra vertical space between paragraphs.
\tabcolsep The default separation between columns in a
tabular environment.
\textheight The height of text on the page.
\textwidth The width of the text on the page.

3.2.6 Rubber/Stretching lengths


The command:
generates a special rubber space where factor is a number,
possibly a oat. It stretches until all the remaining space
on a line is lled up. If two \hspace{\stretch{factor}}
commands are issued on the same line, they grow according to the stretch factor.
The same way, you can stretch vertically:
You can also use \ll instead of \stretch{1}.
The \stretch command, in connection with \pagebreak,
can be used to typeset text on the last line of a page, or to
center text vertically on a page.

80

CHAPTER 3. MECHANICS

There are 'shortcut commands for stretching with factor or


1 (i.e. with \stretch{1} or \ll): \hll and \vll.
here the number can also be negative. For automatic reExample:
setting you need to use \stepcounter.
To set the counter value explicitly, use
Fill the rest of the line
Several macros allow lling the rest of the line -- or 3.3.2 Counter access
stretching parts of the line -- in dierent manners.
There are several ways to get access to a counter.
\hll will produce empty space.
\dotll will produce dots.
\hrulell will produce a rule.

3.2.7

Examples

Resize an image to take exactly half the text width :


Make distance between items larger (inside an itemize environment) :

\theNameOfTheNewCounter will print the formatted string related to the counter.


\value{NameOfTheNewCounter} will return the
counter value which can be used by other counters
or for calculations. It is not a formatted string, so it
cannot be used in text.
\arabic{NameOfTheNewCounter} will print the
formatted counter using arabic numbers.

Note that \arabic{NameOfTheNewCounter} may be


Use of \savebox to resize an image to the height of the
used as a value too, but not the others.
text:
Strangely enough, LaTeX counters are not introduced by
a backslash in any case, even with the \the command.
3.2.8 References
plainTeX equivalents \count and \newcounter\mycounter
do abide by the backslash rule.
[1] [Link]
[2] [Link]

3.3.3 Counter style

Each counter also has a default format that dictates how


it is displayed whenever LaTeX needs to print it. Such
University of Cambridge > Engineering Department formats are specied using internal LaTeX commands:
> computing help > LaTeX > Squeezing Space in
LaTeX

3.2.9

See also

3.3.4 LaTeX default counters

3.3 LaTeX/Counters

part
chapter

Counters are an essential part of LaTeX: they allow you


to control the numbering mechanism of everything (sections, lists, captions, etc.).

3.3.1

Counter manipulation

In LaTeX it is fairly easy to create new counters and even


counters that reset automatically when another counter
is increased (think subsection in a section for example).
With the command
you create a new counter that is automatically set to zero.
If you want the counter to be reset to zero every time
another counter is increased, use:

section
subsection
subsubsection
paragraph
subparagraph
page
equation
gure

To increase the counter, either use

table

or

footnote

3.4. LATEX/BOXES
mpfootnote
For the enumerate environment:
enumi
enumii

81
The height is the length between the baseline and the
top of the box.
The depth is the length between the baseline and the
bottom of the box.
The width is the width of the box.

enumiii
enumiv

3.3.5

Book with parts, sections, but no


chapters

Here follows an example where we want to use parts and 3.4.2 makebox and mbox
sections, but no chapters in the book class :
While \parbox packs up a whole paragraph doing line
breaking and everything, there is also a class of boxing
commands that operates only on horizontally aligned ma3.3.6 Custom enumerate
terial. We already know one of them; its called \mbox.
It simply packs up a series of boxes into another one, and
See the List Structures chapter.
can be used to prevent LaTeX from breaking two words.
(See Hyphenation.) As you can put boxes inside boxes,
3.3.7 Custom sectioning
these horizontal box packers give you ultimate exibility.
Here is an example for recreating something similar to a width denes the width of the resulting box as seen from
section and subsection counter that already exist in La- the outside. This means it can be smaller than the material
inside the box. You can even set the width to 0pt so that
TeX:
the text inside the box will be typeset without inuencing
the surrounding boxes. Besides the length expressions,
you can also use \width, \height, \depth and \totalheight
3.4 LaTeX/Boxes
in the width parameter. They are set from values obtained
by measuring the typeset text. The pos parameter takes
LaTeX builds up its pages by pushing around boxes. At a one letter value: center, ushleft, ushright, or spread
rst, each letter is a little box, which is then glued to other the text to ll the box.
letters to form words. These are again glued to other
words, but with special glue, which is elastic so that a
series of words can be squeezed or stretched as to exactly 3.4.3 framebox
ll a line on the page.
The command \framebox works exactly the same as
Admittedly, this is a very simplistic description of what
\makebox, but it draws a box around the text.
really happens, but the point is that TeX operates with
glue and boxes. Letters are not the only things that can The following example shows you some things you could
be boxes. One can put virtually everything into a box, do with the \makebox and \framebox commands:
including other boxes. Each box will then be handled by You can tweak the following frame lengths.
LaTeX as if it were a single letter.
\fboxsep: the distance between the frame and the
The past chapters have already dealt with some boxes, alcontent.
though they weren't described as such. The tabular environment and the \includegraphics, for example, both
\fboxrule: the thickness of the rule.
produce a box. This means that one can easily arrange
two tables or images side by side. You just have to make
sure that their combined width is not larger than the \tex- This prints a thick and more distant frame:
twidth.
This shows the box frame of a letter.

3.4.1

TeX character boxes

3.4.4 framed

TeX characters are stored in boxes like every printed el- An alternative to these approaches is the usage of the
ement. Boxes have three dimensional properties:
framed environment (you will need to include the framed

82

CHAPTER 3. MECHANICS

package to use it). This provides an easy way to box a text will be wrapped:
paragraph within a document:
You can do it manually with a parbox.

3.4.7 savebox

3.4.5

A \savebox is a reference to a box lled with contents.


You can use it as a way to print or manipulate something
repeatedly.

raisebox

Now that we control the horizontal, the obvious next step


The command \newsavebox creates a placeholder for
is to go for the vertical. No problem for LaTeX. The
storing a text; the command \savebox stores the specicommand lets you dene the vertical properties of a box.
ed text in this placeholder, and does not display anyYou can use \width, \height, \depth and \totalheight in the
thing in the document; and \usebox recalls the content of
rst three parameters, in order to act upon the size of the
the placeholder into the document.
box inside the text argument. The two optional parameters set for the height and depth of the raisebox. For
instance you can observe the dierence when embedded 3.4.8 rotatebox
in a framebox.
See Rotations.

3.4.6

minipage and parbox


3.4.9 colorbox and fcolorbox

Most standard LaTeX boxes are not long commands, i.e. they do not support breaks nor para- See Colors. \fcolorbox can also be tweaked with \fboxsep
graphs.
However you can pack a paragraph and \fboxrule.
of your choice into a box with either the \parbox[pos][height][contentpos]{width}{text} command or
the \begin{minipage}[pos][height][contentpos]{width} 3.4.10 resizebox and scalebox
text \end{minipage} environment.
The pos parameter can take one of the letters center, top The graphicx package feature additional boxes.
or bottom to control the vertical alignment of the box,
relative to the baseline of the surrounding text. The height
3.4.11 fancybox
parameter is the height of the parbox or minipage. The
contentpos parameter is the position of the content and
the fancybox package provides additional boxes.
can be one of center, top, bottom or spread. width takes
a length argument specifying the width of the box. The
\doublebox
main dierence between a minipage and a \parbox is that
you cannot use all commands and environments inside a
\ovalbox
parbox, while almost anything is possible in a minipage.
\shadowbox
This should print 3 boxes on the same line. Do not put
another linebreak between the \fbox, otherwise you will
put the following \fbox in another paragraph on another
line.

3.5 LaTeX/Rules and Struts

Paragraphs in all boxes

3.5.1 Rules

You can make use of the long capabilities of minipage The \rule command in normal use produces a simple
and parbox to embed paragraphs in non-long boxes. For black box:
instance:
The depth, width and height parameters are explained in
the Boxes chapter.
This prevents the overfull badness.
You can also use

Here is an example:

from the pbox package which will create a box of minimal This is useful for drawing vertical and horizontal lines.
size around the text. Note that the \pbox command takes
an optional argument that species the vertical position
3.5.2 Struts
of the text:
The valid values are b (bottom), t (top), and c (center). If A special case is a rule with no width but a certain height.
you specify a length in the rst (required) argument, the In professional typesetting, this is called a strut. It is used

3.5. LATEX/RULES AND STRUTS


to guarantee that an element on a page has a certain minimal height. You could use it in a tabular environment
or in boxes to make sure a row has a certain minimum
height.
In LaTeX a strut is dened as

3.5.3

Stretched rules

LaTeX provides the \hrulell command, which work like


a stretched horizontal space. See the Lengths chapter.

83

Chapter 4

Technical Texts
4.1 LaTeX/Mathematics

displayed displayed formulas are separate from


the main text.

One of the greatest motivating forces for Donald Knuth


when he began developing the original TeX system was
to create something that allowed simple construction of
mathematical formulas, while looking professional when
printed. The fact that he succeeded was most probably
why TeX (and later on, LaTeX) became so popular within
the scientic community. Typesetting mathematics is one
of LaTeXs greatest strengths. It is also a large topic due
to the existence of so much mathematical notation.

As maths require special environments, there are naturally the appropriate environment names you can use in
the standard way. Unlike most other environments, however, there are some handy shorthands to declaring your
formulas. The following table summarizes them:

Suggestion: Using the $$...$$ should be avoided, as it


may cause problems, particularly with the AMS-LaTeX
macros. Furthermore, should a problem occur, the error
If your document requires only a few simple mathemat- messages may not be helpful.
ical formulas, plain LaTeX has most of the tools that
The equation* and displaymath environments are funcyou will need. If you are writing a scientic document
tionally equivalent.
that contains numerous complicated formulas, the amsmath package[1] introduces several new commands that If you are typing text normally, you are said to be in text
are more powerful and exible than the ones provided mode, but while you are typing within one of those mathby LaTeX. The mathtools package xes some amsmath ematical environments, you are said to be in math mode,
quirks and adds some useful settings, symbols, and envi- that has some dierences compared to the text mode:
ronments to amsmath.[2] To use either package, include:
1. Most spaces and line breaks do not have any signicance, as all spaces are either derived logically from
the mathematical expressions, or have to be specied with special commands such as \quad

\usepackage{amsmath}
or
\usepackage{mathtools}

2. Empty lines are not allowed. Only one paragraph


per formula.

in the preamble of the document. The mathtools package


loads the amsmath package and hence there is no need
to \usepackage{amsmath} in the preamble if mathtools
is used.

4.1.1

3. Each letter is considered to be the name of a variable


and will be typeset as such. If you want to typeset
normal text within a formula (normal upright font
and normal spacing) then you have to enter the text
using dedicated commands.

Mathematics environments

LaTeX needs to know beforehand that the subsequent


text does indeed contain mathematical elements. This is
because LaTeX typesets maths notation dierently from
normal text. Therefore, special environments have been
declared for this purpose. They can be distinguished into
two categories depending on how they are presented:

Inserting Displayed maths inside blocks of text

In order for some operators, such as \lim or \sum to be


displayed correctly inside some math environments (read
$......$), it might be convenient to write the \displaystyle
class inside the environment. Doing so might cause the
line to be taller, but will cause exponents and indices to be
text text formulas are displayed inline, that is, displayed correctly for some math operators. For examwithin the body of text where it is declared, for ex- ple, the $\sum$ will print a smaller
and $\displaystyle
, like in equations (This
ample, I can say that a + a = 2a within this sentence. \sum$ will print a bigger one
84

4.1. LATEX/MATHEMATICS
only works with AMSMATH package). It is also possible to force this behaviour for all math environments by
declaring \everymath{\displaystyle} at the very beginning
(i.e. before \begin{document}), which is useful in longer
documents.

4.1.2

Symbols

85

4.1.5 Powers and indices


Powers and indices are equivalent to superscripts and subscripts in normal text mode. The caret (^) character is
used to raise something, and the underscore (_) is for lowering. If more than one expression is raised or lowered,
they should be grouped using curly braces ({ and }).

For powers with more than one digit, surround the power
Mathematics has many symbols! One of the most dif- with {}.
cult aspects of learning LaTeX is remembering how to An underscore (_) can be used with a vertical bar ( | ) to
produce symbols. There is of course a set of symbols that denote evaluation using subscript notation in mathematcan be accessed directly from the keyboard:
ics:
+-=! /()[]<>|':
Beyond those listed above, distinct commands must be
issued in order to display the desired symbols. There are 4.1.6 Fractions and Binomials
a great deal of examples such as Greek letters, set and
A
fraction
is
created
using
the
relations symbols, arrows, binary operators, etc.
\frac{numerator}{denominator} command.
(for
For example:
those who need their memories refreshed, thats the
Fortunately, theres a tool that can greatly simplify the top and bottom respectively!). Likewise, the binomial
search for the command for a specic symbol. Look for coecient (aka the Choose function) may be written
[3]
Detexify in the external links section below. Another using the \binom command :
option would be to look in the The Comprehensive La- It is also possible to use the \choose command without
TeX Symbol List in the external links section below.
the amsmath package:
You can embed fractions within fractions:

4.1.3

Greek letters

4.1.4

Operators

Note that when appearing inside another fraction, or in


inline text ab , a fraction is noticeably smaller than in disGreek letters are commonly used in mathematics, and played mathematics.
The \tfrac and \dfrac commands[3]
they are very easy to type in math mode. You just have to force the use of the respective styles, \textstyle and \distype the name of the letter after a backslash: if the rst playstyle. Similarly, the \tbinom and \dbinom commands
letter is lowercase, you will get a lowercase Greek letter, typeset the binomial coecient.
if the rst letter is uppercase (and only the rst letter),
then you will get an uppercase letter. Note that some up- Another way to write fractions is to use the \over compercase Greek letters look like Latin ones, so they are not mand without the amsmath package:
provided by LaTeX (e.g. uppercase Alpha and Beta are For relatively simple fractions, especially within the text,
just A and B respectively). Lowercase epsilon, theta, it may be more aesthetically pleasing to use powers and
kappa, phi, pi, rho, and sigma are provided in two dier- indices:
ent versions. The alternate, or variant, version is created
If this looks a little loose (overspaced), a tightened verby adding var before the name of the letter:
sion can be dened by inserting some negative space
Scroll down to #List of Mathematical Symbols for a comIf you use them throughout the document, usage of xfrac
plete list of Greek symbols.
package is recommended. This package provides \sfrac
command to create slanted fractions. Usage:
If fractions are used as an exponent curly braces have to
be used around the \sfrac command:

An operator is a function that is written as a word: e.g.


trigonometric functions (sin, cos, tan), logarithms and ex- $x^\frac{1}{2}$ % no error $x^\sfrac{1}{2}$ % error
ponentials (log, exp). LaTeX has many of these dened $x^{\sfrac{1}{2}}$ % no error
as commands:
Alternatively, the nicefrac package provides the \nicefrac
For certain operators such as limits, the subscript is command, whose usage is similar to \sfrac.
placed underneath the operator:
For the modular operator there are two commands: Continued fractions
\bmod and \pmod:
To use operators that are not pre-dened, such as argmax, Continued fractions should be written using \cfrac
see custom operators
command[3] :

86

CHAPTER 4. TECHNICAL TEXTS

Multiplication of two numbers

mand:

However if you want this to apply to ALL integrals, it is


To make multiplication visually similar to a fraction, a
preferable to specify the intlimits option when loading the
nested array can be used, for example multiplication of
amsmath package:
numbers written one below the other.
Subscripts and superscripts in other contexts as well as
other parameters to amsmath package related to them are
described in Advanced Mathematics chapter.
4.1.7 Roots
For bigger integrals, you may use personal declarations,
The \sqrt command creates a square root surrounding an or the bigints package [4] .
expression. It accepts an optional argument specied in
square brackets ([ and ]) to change magnitude:
Some people prefer writing the square root closing it
over its content. This method arguably makes it more
clear what is in the scope of the root sign. This habit is
not normally used while writing with the computer, but
if you still want to change the output of the square root,
LaTeX gives you this possibility. Just add the following
code in the preamble of your document:

4.1.9 Brackets, braces and delimiters


How to use braces in multi line equations is described in the
Advanced Mathematics chapter.

The use of delimiters such as brackets soon becomes important when dealing with anything but the most trivial
equations. Without them, formulas can become ambiguThis TeX code rst renames the \sqrt command as \old- ous. Also, special types of mathematical structures, such
sqrt, then redenes \sqrt in terms of the old one, adding as matrices, typically rely on delimiters to enclose them.
something more. The new square root can be seen in the There are a variety of delimiters available for use in Lapicture on the left, compared to the old one on the right. TeX:
Unfortunately this code won't work
if you want to use
multiple roots: if you try to write b a as \sqrt[b]{a} after
you used the code above, you'll just get a wrong output. Automatic sizing
In other words, you can redene the square root this way
only if you are not going to use multiple roots in the whole Very often mathematical features will dier in size, in
which case the delimiters surrounding the expression
document.
should vary accordingly. This can be done automatically
An alternative piece of TeX code that does allow multiple
using the \left, \right, and \middle commands. Any of
roots is
the previous delimiters may be used in combination with
However this requires the \usepackage{letltxmacro} these:
package
Curly braces are dened dierently by using \left\{ and
\right\},

4.1.8

Sums and integrals

If a delimiter on only one side of an expression is required, then an invisible delimiter on the other side may
The \sum and \int commands insert the sum and integral be denoted using a period (.).
symbols respectively, with limits specied using the caret
(^) and underscore (_). The typical notation for sums is:
Manual sizing
The limits for the integrals follow the same notation. Its
also important to represent the integration variables with In certain cases, the sizing produced by the \left and \right
an upright d, which in math mode is obtained through the commands may not be desirable, or you may simply want
\mathrm{} command, and with a small space separating ner control over the delimiter sizes. In this case, the \big,
it from the integrand, which is attained with the \, com- \Big, \bigg and \Bigg modier commands may be used:
mand.
These commands are primarily useful when dealing with
There are many other big commands which operate in
nested delimiters. For example, when typesetting
a similar manner:
we notice that the \left and \right commands produce the
For more integral symbols, including those not included same size delimiters as those nested within it. This can
by default in the Computer Modern font, try the esint be dicult to read. To x this, we write
package.
Manual sizing can also be useful when an equation is too
The \substack command[3] allows the use of \\ to write large, trails o the end of the page, and must be separated
the limits over multiple lines:
into two lines using an align command. \left and \right
If you want the limits of an integral to be specied above will give errors if the left and right appear on dierent
and below the symbol (like the sum), use the \limits com- lines.

4.1. LATEX/MATHEMATICS

87

Typesetting intervals

4.1.11 Adding text to equations

To denote open and half-open intervals, the notations


]a,b[, (a,b), ]a,b], (a,b], [a,b[ and [a,b) are used. If the
square bracket notation is used, then the interval must be
put between curly braces ({ and }) in order to have correct
spacing. Similarly, if a (half-)open interval starts with a
negative number, then the number including its minussymbol must also be put between curly brackets, so that
LaTeX understands that the minus-symbol is the unary
operation. Compare:

The math environment diers from the text environment


in the representation of text. Here is an example of trying
to represent text within the math environment:

4.1.10

Matrices and arrays

A basic matrix may be created using the matrix


environment[3] : in common with other table-like structures, entries are specied by row, with columns separated using an ampersand (&) and a new rows separated
with a double backslash (\\)

There are two noticeable problems: there are no spaces


between words or numbers, and the letters are italicized
and more spaced out than normal. Both issues are simply
artifacts of the maths mode, in that it treats it as a mathematical expression: spaces are ignored (LaTeX spaces
mathematics according to its own rules), and each character is a separate element (so are not positioned as closely
as normal text).
There are a number of ways that text can be added properly. The typical way is to wrap the text with the \text{...}
command [3] (a similar command is \mbox{...}, though
this causes problems with subscripts, and has a less descriptive name). Lets see what happens when the above
equation code is adapted:

To specify alignment of columns in the table, use starred The text looks better. However, there are no gaps between the numbers and the words. Unfortunately, you
version[5] :
are required to explicitly add these. There are many ways
The alignment by default is c but it can be any column
to add spaces between maths elements, but for the sake
type valid in array environment.
of simplicity we may simply insert space characters into
However matrices are usually enclosed in delimiters of the \text commands.
some kind, and while it is possible to use the \left and
\right commands, there are various other predened environments which automatically include delimiters:
Formatted text
When writing down arbitrary sized matrices, it is common to use horizontal, vertical and diagonal triplets of
dots (known as ellipses) to ll in certain columns and
rows. These can be specied using the \cdots, \vdots and
\ddots respectively:
In some cases you may want to have ner control of the
alignment within each column, or want to insert lines between columns or rows. This can be achieved using the
array environment, which is essentially a math-mode version of the tabular environment, which requires that the
columns be pre-specied:

Using the \text is ne and gets the basic result. Yet, there
is an alternative that oers a little more exibility. You
may recall the introduction of font formatting commands,
such as \textrm, \textit, \textbf, etc. These commands
format the argument accordingly, e.g., \textbf{bold text}
gives bold text. These commands are equally valid within
a maths environment to include text. The added benet
here is that you can have better control over the font formatting, rather than the standard text achieved with \text.

You may see that the AMS matrix class of environments 4.1.12 Formatting mathematics symbols
doesn't leave enough space when used together with fractions resulting in output similar to this:
See also: w:Mathematical Alphanumeric Sym5 1

bols, w:Help:Displaying a formula#Alphabets


0
6
6
5
1
and
typefaces and w:Wikipedia:LaTeX symM = 6 0 6
1
5
bols#Fonts
0 6 6
To counteract this problem, add additional leading space
We can now format text; what about formatting mathewith the optional parameter to the \\ command:
matical expressions? There are a set of formatting comIf you need border or indexes on your matrix, plain
mands very similar to the font formatting ones just used,
TeX provides the macro \bordermatrix
except that they are specically aimed at text in math
mode (requires amsfonts)
Matrices in running text

These formatting commands can be wrapped around the


entire equation, and not just on the textual elements: they
To insert a small matrix, and not increase leading in the only format letters, numbers, and uppercase Greek, and
line containing it, use smallmatrix environment:
other math commands are unaected.

88

CHAPTER 4. TECHNICAL TEXTS

To bold lowercase Greek or other symbols use the


\boldsymbol command[3] ; this will only work if there
exists a bold version of the symbol in the current font.
As a last resort there is the \pmb command[3] (poor
mans bold): this prints multiple versions of the character slightly oset against each other.

horizontal spacing. In these events, the output is still satisfactory, yet any perfectionists will no doubt wish to netune their formulas to ensure spacing is correct. These are
generally very subtle adjustments.

There are other occasions where LaTeX has done its job
correctly, but you just want to add some space, maybe
To change the size of the fonts in math mode, see to add a comment of some kind. For example, in the
Changing font size.
following equation, it is preferable to ensure there is a
decent amount of space between the maths and the text.
This code produces errors with Miktex 2.9 and does not
yield the results seen on the right. Use \textrm instead of
So what to do when you run out of symbols and fonts? just \text.
Well the next step is to use accents:
(Note that this particular example can be expressed in
more elegant code by the cases construct provided by the
amsmath package described in Advanced Mathematics
4.1.13 Color
chapter.)
Accents

The package xcolor, described in Colors, allows us to add LaTeX has dened two commands that can be used anywhere in documents (not just maths) to insert some horcolor to our equations. For example,
izontal space. They are \quad and \qquad
The only problem is that this disrupts the default LaTeX
formatting around the - operator. To x this, we enclose A \quad is a space equal to the current font size. So, if you
it in a \mathbin environment, since - is a binary operator. are using an 11pt font, then the space provided by \quad
will also be 11pt (horizontally, of course.) The \qquad
This process is described here.
gives twice that amount. As you can see from the code
from the above example, \quads were used to add some
4.1.14 Plus and minus signs
separation between the maths and the text.
Latex deals with the + and signs in two possible ways.
The most common is as a binary operator. When two
maths elements appear on either side of the sign, it is
assumed to be a binary operator, and as such, allocates
some space either side of the sign. The alternative way
is a sign designation. This is when you state whether a
mathematical quantity is either positive or negative. This
is common for the latter, as in maths, such elements are
assumed to be positive unless a is prexed to it. In this
instance, you want the sign to appear close to the appropriate element to show their association. If you put a + or
a with nothing before it but you want it to be handled
like a binary operator you can add an invisible character
before the operator using {}. This can be useful if you
are writing multiple-line formulas, and a new line could
start with a = or a +, for example, then you can x some
strange alignments adding the invisible character where
necessary.
A plus-minus sign is written as:
Similarly, there exists also a minus-plus sign:

OK, so back to the ne tuning as mentioned at the beginning of the document. A good example would be displaying the simple equation for the indenite integral of
y with respect to x:

y dx
If you were to try this, you may write:
However, this doesn't give the correct result. LaTeX
doesn't respect the white-space left in the code to signify
that the y and the dx are independent entities. Instead, it
lumps them altogether. A \quad would clearly be overkill
in this situationwhat is needed are some small spaces to
be utilized in this type of instance, and thats what LaTeX
provides:
NB you can use more than one command in a sequence
to achieve a greater space if necessary.
So, to rectify the current problem:
The negative space may seem like an odd thing to use,
however, it wouldn't be there if it didn't have some use!
Take the following example:

The matrix-like expression for representing binomial coecients is too padded. There is too much space between
the brackets and the actual contents within. This can easLaTeX is obviously pretty good at typesetting mathsit ily be corrected by adding a few negative spaces after the
was one of the chief aims of the core TeX system that left bracket and before the right bracket.
LaTeX extends. However, it can't always be relied upon In any case, adding some spaces manually should be
to accurately interpret formulas in the way you did. It avoided whenever possible: it makes the source code
has to make certain assumptions when there are ambigu- more complex and its against the basic principles of
ous expressions. The result tends to be slightly incorrect

4.1.15

Controlling horizontal spacing

4.1. LATEX/MATHEMATICS

89

a What You See is What You Mean approach. The


best thing to do is to dene some commands using all
the spaces you want and then, when you use your command, you don't have to add any other space. Later, if
you change your mind about the length of the horizontal
space, you can easily change it modifying only the command you dened before. Let us use an example: you
want the d of a dx in an integral to be in roman font and
a small space away from the rest. If you want to type
an integral like \int x \; \mathrm{d} x, you can dene a
command like this:
in the preamble of your document. We have chosen \dd
just because it reminds the d it replaces and it is fast to
type. Doing so, the code for your integral becomes \int x
\dd x. Now, whenever you write an integral, you just have
to use the \dd instead of the d, and all your integrals will
have the same style. If you change your mind, you just
have to change the denition in the preamble, and all your
integrals will be changed accordingly.

4.1.16

Advanced Mathematics:
Math package

The default treatment for the various kinds follows American Mathematical Society conventions.
Write an equation with the align environment
How to write an equation with the align environment with
the amsmath package is described in Advanced Mathematics.

4.1.17 List of Mathematical Symbols


All the pre-dened mathematical symbols from the \TeX\
package are listed below. More symbols are available
from extra packages.
Note: To use the Greek Letters in LaTeX that have the
same appearance as their Roman equivalent, just use the
Roman form: e.g., A instead of Alpha, B instead of Beta,
etc.

AMS 4.1.18 Summary

The AMS (American Mathematical Society) mathematics package is a powerful package that creates a higher
layer of abstraction over mathematical LaTeX language;
if you use it it will make your life easier. Some commands amsmath introduces will make other plain LaTeX
commands obsolete: in order to keep consistency in the
nal output you'd better use amsmath commands whenever possible. If you do so, you will get an elegant output without worrying about alignment and other details,
keeping your source code readable. If you want to use it,
you have to add this in the preamble:

As you begin to see, typesetting math can be tricky at


times. However, because LaTeX provides so much control, you can get professional quality mathematics typesetting with relatively little eort (once you've had a bit of
practice, of course!). It would be possible to keep going
and going with math topics because it seems potentially
limitless. However, with this tutorial, you should be able
to get along suciently.

4.1.19 Notes
[1] [Link]

Introducing text and dots in formulas

[2] [Link]
mathtools/[Link]

amsmath denes also the \dots command, that is a generalization of the existing \ldots. You can use \dots in
both text and math mode and LaTeX will replace it with
three dots "" but it will decide according to the context
whether to put it on the bottom (like \ldots) or centered
(like \cdots).

[3] requires the amsmath package


[4] [Link]
[5] requires the mathtools package

4.1.20 Further reading


Dots

meta:Help:Displaying a formula: Wikimedia uses a


subset of LaTeX commands.

LaTeX gives you several commands to insert dots in your


formulae. This can be particularly useful if you have to
type big matrices omitting elements. First of all, here are 4.1.21 External links
the main dots-related commands LaTeX provides:
LaTeX maths symbols
Instead of using \ldots and \cdots, you should use the semantically oriented commands. It makes it possible to
adapt your document to dierent conventions on the y,
in case (for example) you have to submit it to a publisher
who insists on following house tradition in this respect.

detexify: applet for looking up LaTeX symbols by


drawing them
amsmath documentation

90

CHAPTER 4. TECHNICAL TEXTS

LaTeX - The Student Room

gin{subequations} command, which will reference the


main equation (1.1 above), or adding a label at the end
The Comprehensive LaTeX Symbol List
of each line, before the \\ command, which will refer MathLex - LaTeX math translator and equation ence the sub-equation (1.1a or 1.1b above). It is possible
to add both labels in case both types of references are
builder
needed.

4.2 LaTeX/Advanced Mathematics

4.2.2 Vertically aligning displayed mathematics


This page outlines some more advanced uses of mathematics markup using LaTeX. In particular it makes
heavy use of the AMS-LaTeX packages supplied by the An often encountered problem with displayed environments (displaymath and equation) is the lack of any abilAmerican Mathematical Society.
ity to span multiple lines. While it is possible to dene
lines individually, these will not be aligned.

4.2.1

Equation numbering

The equation environment automatically numbers your Above and below


equation:
The \overset and \underset commands[1] typeset symbols
You can also use the \label and \ref (or \eqref from
above and below expressions. Without AmsTex the same
the amsmath package) commands to label and reference
result of \overset can be obtained with \stackrel. This can
equations, respectively. For equation number 1, \ref rebe particularly useful for creating new binary relations:
sults in 1 and \eqref results in (1) :
or to show usage of L'Hpitals rule:
Further information is provided in the labels and crossIt is convenient to dene a new operator that will set the
referencing chapter.
equal sign with H and the provided fraction:
To have the enumeration follow from your section or subsection heading, you must use the amsmath package or which reduces the above example to:
use AMS class documents. Then enter
If the purpose is to make comments on particular parts of
to the preamble to get enumeration at the section level or an equation, the \overbrace and \underbrace commands
may be more useful. However, they have a dierent synto have the enumeration go to the subsection level.
tax (and can be aligned with the \vphantom command):
If the style you follow requires putting dots after ordiSometimes the comments are longer than the formula benals (as it is required at least in Polish typography) the
ing commented on, which can cause spacing problems.
\numberwithin{equation}{subsection} command in the
These can be removed using the \mathclap command[2] :
preamble will result in the equation number in the above
Alternatively, to use brackets instead of braces use \unexample to be rendered in this way: (1.1..1).
derbracket and \overbracket commands[2] :
To remove the duplicate dot, add the following command
The optional arguments set the rule thickness and bracket
immediately after \numberwithin{equation}{section}:
height respectively:
For a numbering scheme using \numberThe \xleftarrow and \xrightarrow commands[1] produce
within{equation}{subsection}, use:
arrows which extend to the length of the text. Yet again,
in the preamble of the document.
the syntax is dierent: the optional argument (using [ and
Note: Though it may look like the \renewcommand works ]) species the subscript, and the mandatory argument
by itself, it won't reset the equation number with each new (using { and }) species the superscript (which can be
section. It must be used together with manual equation left empty by inserting a blank space).
number resetting after each new section beginning or with
For more extensible arrows, you must use mathtools
the much cleaner \numberwithin.
package:
Subordinate equation numbering

and for harpoons:

To number subordinate equations in a numbered equation align and align*


environment, place the part of document containing them
in a subequations environment:
The align and align* environments, available through the
Referencing subordinate equations can be done using amsmath package, are used for arranging equations of
either of two methods: adding a label after the \be- multiple lines. As with matrices and tables, \\ species

4.2. LATEX/ADVANCED MATHEMATICS

91

a line break, and & is used to indicate the point at which


a=
the lines should be aligned.

x dx

b
The align* environment is used like the displaymath or Display style may be used instead, by using the dcases
equation* environment:
environment[2] from mathtools:
Note that the align environment must not be nested inside Often the second column consists mostly of normal text,
an equation (or similar) environment. Instead, align is a to set it in the normal roman font of the document the
replacement for such environments; the contents inside dcases* environment may be used:[2]
an align are automatically placed in math mode.
align* suppresses numbering. To force numbering on a
specic line, use the \tag{...} command before the line- Other environments
break.
align is similar, but automatically numbers each line like Although align and align* are the most useful, there are
the equation environment. Individual lines may be re- several other environments which may also be of interest:
ferred to by placing a \label{...} before the linebreak. The There are also few environments that don't form a math
\nonumber or \notag command can be used to suppress environment by themselves and can be used as building
blocks for more elaborate structures:
the number for a given line:
Notice that we've added some indenting on the second For example:
line. Also, we need to insert the double braces ({}) before
the + sign, otherwise latex won't create the correct spacing after the + sign. The reason for this is that without 4.2.3 Indented Equations
the braces, latex interprets the + sign as a unary operator,
instead of the binary operator that it really is.
In order to indent an equation, you can set eqn in the
More complicated alignments are possible. The following document class and then specify a certain value for the
\mathindent variable:
example illustrates the alignment rule of align*:
Braces spanning multiple lines

4.2.4 Page breaks in math environments

Additional &'s on a single line will specify multiple To suggest LaTeX insert a page break inside an amsmath
equation columns, each of which is aligned. If you want environment you may use the \displaybreak command bea brace to continue across a new line, do the following:
fore the line break. Just like with \pagebreak, \displayIn this construction, the sizes of the left and right braces break can take an optional argument between 0 and 4 deare not automatically equal, in spite of the use of \left\{ noting the level of desirability of a page break. While 0
and \right\}. This is because each line is typeset as a com- means it is permissible to break here, 4 forces a break.
pletely separate equation notice the use of \right. and No argument means the same as 4.
\left. so there are no unpaired \left and \right commands Alternatively, you may enable automatic page breaks in
within a line (these aren't needed if the formula is on one math environments with \allowdisplaybreaks. It too can
line). You can control the size of the braces manually have an optional argument denoting the priority of page
with the \big, \Big, \bigg, and \Bigg commands.
breaks in equations. Similarly, 1 means allow page
Alternatively, the height of the taller equation can be breaks but avoid them and 4 means break whenever you
want. You can prohibit a page break after a given line
replicated in the other using the \vphantom command:
using \\*.
LaTeX will insert a page break into a long equation if it
Using aligned braces for piecewise functions You
has additional text added using \intertext{} without any
can also use \left\{ and \right\} to typeset piecewise funcadditional commands.
tions:
Specic usage may look like this:
The cases environment

4.2.5 Boxed Equations

The cases environment[1] allows the writing of piecewise


functions:
For a single equation or alignment building block, with
LaTeX will then take care of dening and or aligning the the tag outside the box, use \boxed{}:
columns.
If you want the entire line or several equations to be
Within cases, text style math is used with results such as: boxed, use a minipage inside an \fbox{}:

92

CHAPTER 4. TECHNICAL TEXTS

There is also the mathtools \Aboxed{} which is able to If you wish to place them on the corners of an arbitrary
box across alignment marks:
symbol, you should use \fourIdx from the fouridx package.

4.2.6

Custom operators

Although many common operators are available in LaTeX, sometimes you will need to write your own, e.g. to
typeset the argmax operator. The \operatorname and \operatorname* commands[1] display custom operators; the
* version sets the underscored option underneath like the
\lim operator:

However, a simple grouping can solve the problem:


since a math operator can be used with limits or no limits.
If you want to change its state, simply group it. You can
make it another math operator if you want, and then you
can have limits and then limits again.

Multiline subscripts

However, if the operator is frequently used, it is preferable to dene a new operator that can be used through- To produce multiline subscript use \substack command:
out the entire document. The \DeclareMathOperator and
\DeclareMathOperator* commands[1] are specied in the
4.2.8 Text in aligned math display
header of the document:
This denes a new command which may be referred to in
To add small interjections in math environments use \inthe body:
tertext command:

4.2.7

Advanced formatting

Note that any usage of this command does not change the
alignment.

Also, in the above example, the command \shortintertext{} from the mathtools package could have been used
There are defaults for placement of subscripts and super- instead of intertext to reduce the amount of vertical
scripts e.g. limits for the lim operator are usually placed whitespace added between the lines.
below the symbol:
Limits

To override this behavior, use the \nolimits operator:

4.2.9 Changing font size

A lim in running text (inside $...$) will have its limits


placed on the side, so that additional leading won't be re- There may be a time when you would prefer to have
quired. To override this behavior, use the \limits com- some control over the size. For example, using text-mode
maths, by default a simple fraction will look like this: ab
mand.
, whereas you may prefer to have it displayed larger, like
Similarly one can put subscripts under a symbol that usuwhen in display mode, but still keeping it in-line, like this:
ally have them on the side:
a
.
b
Limits below and under:
A simple approach is to utilize the predened sizes for
To change the default placement of summation-type symmaths elements:
bols to the side for every case, add the nosumlimits option
to the amsmath package. To change the placement for in- A classic example to see this in use is typesetting contegral symbols, add intlimits to the options. nonamelimits tinued fractions (though its better to use the \cfrac
can be used to change the default for named operators like command[1] described in the Mathematics chapter over
the method provided below). The following code prodet, min, lim, etc.
vides an example.
To produce one-sided limits, use \underset as follows:
As you can see, as the fractions continue, they get smaller
(although they will not get any smaller as in this example,
Subscripts and superscripts
they have reached the \scriptstyle limit). If you wanted to
keep the size consistent, you could declare each fraction
While you can place symbols in subscript or superscript to use the display style instead, e.g.:
(in summation style symbols) with \nolimits:
Another approach is to use the \DeclareMathSizes comIts impossible to mix them with typical usage of such mand to select your preferred sizes. You can only dene
symbols:
sizes for \displaystyle, \textstyle, etc. One potential downTo add both prime and a limit to a symbol, one might use side is that this command sets the global maths sizes, as
\sideset command:
it can only be used in the document preamble.
It is very exible: for example, to put letters in each cor- However, its fairly easy to use: \DeclareMathner of the symbol use this command:
Sizes{ds}{ts}{ss}{sss}, where ds is the display size, ts is

4.3. LATEX/THEOREMS

93

the text size, etc. The values you input are assumed to be put it in the preamble. The rst argument is the name you
point (pt) size.
will use to reference it, the second argument is the output
NB the changes only take place if the value in the rst LaTeX will print whenever you use it. For example:
argument matches the current document text size. It \newtheorem{mydef}{Denition}
is therefore common to see a set of declarations in the
preamble, in the event of the main font being changed. will dene the mydef environment; if you use it like this:
E.g.,
\begin{mydef} Here is a new denition \end{mydef}

4.2.10

Forcing \displaystyle for all math in It will look like this:


a document
Denition 3 Here is a new denition

Put
before

with line breaks separating it from the rest of the text.

to force all math to


.

4.3.2 Theorem counters

4.2.11

Adjusting
vertical
whitespace Often the counters are determined by section, for example Theorem 2.3 refers to the 3rd theorem in the 2nd
around displayed math

section of a document. In this case, specify the theorem


There are four parameters which control the vertical as follows:
whitespace around displayed math:
\newtheorem{name}{Printed output}[numberby]
Short skips are used if the preceding line ends, horizontally, before the formula. These parameters must be set where numberby is the name of the section level (secafter
tion/subsection/etc.) at which the numbering is to take
place.
.

4.2.12

Notes

[1] Requires amsmath package

By default, each theorem uses its own counter. However it


is common for similar types of theorems (e.g. Theorems,
Lemmas and Corollaries) to share a counter. In this case,
dene subsequent theorems as:
\newtheorem{name}[counter]{Printed output}

[2] requires the mathtools package

4.3 LaTeX/Theorems
With "theorem" we can mean any kind of labelled enunciation that we want to look separated from the rest of the
text and with sequential numbers next to it. This approach
is commonly used for theorems in mathematics, but can
be used for anything. LaTeX provides a command that
will let you easily dene any theorem-like enunciation.

4.3.1

Basic theorems

First of all, make sure you have the amsthm package enabled:
\usepackage{amsthm}

where counter is the name of the counter to be used. Usually this will be the name of the master theorem.
The \newtheorem command may have at most one optional argument.
You can also create a theorem environment that is not
numbered by using the newtheorem* command[1] . For
instance,
\newtheorem*{mydef}{Denition}
denes the mydef environment, which will generate definitions without numbering. This requires amsthm package.

4.3.3 Proofs

The easiest is the following:

The proof environment[1] can be used for adding the


proof of a theorem. The basic usage is:

\newtheorem{name}{Printed output}

\begin{proof} Here is my proof \end{proof}

94

CHAPTER 4. TECHNICAL TEXTS

It just adds Proof in italics at the beginning of the text


given as argument and a white square (Q.E.D. symbol,
also known as a tombstone) at the end of it. If you are
writing in another language than English, just use babel
with the right argument and the word Proof printed in
the output will be translated accordingly; anyway, in the
source the name of the environment remains proof.

(Any arguments that are left blank will assume their default value). Here is an example headspec:
\thmname{#1}\thmnumber{ #2}:\thmnote{ #3}
which would look something like:
Denition 2: Topology
for the following:

If you would like to manually name the proof, include the


\begin{denition}[Topology]...
name in square brackets:

\begin{proof}[Proof of important theorem] Here is my


(The note argument, which in this case is Topology, is
important proof \end{proof}
always optional, but will not appear by default unless you
specify it as above in the head spec).
If the last line of the proof is displayed math then the
Q.E.D. symbol will appear on a subsequent empty line.
To put the Q.E.D. symbol at the end of the last line, use
the \qedhere command:
4.3.5 Conicts
\begin{proof} Here is my proof: \[ a^2 + b^2 = c^2
The theorem environment conicts with other environ\qedhere \] \end{proof}
ments, for example wrapgure. A work around is to redene theorem, for example the following way:
The method above does not work with the deprecated en% Fix latex \def\smallskip{\vskip\smallskipamount}
vironment eqnarray*. Use align* instead.
\def\medskip{\vskip\medskipamount}
To use a custom Q.E.D. symbol, redene the \qedsymbol
\def\bigskip{\vskip\bigskipamount}
%
Hand
command. To hide the Q.E.D. symbol altogether, redemade
theorem
\newcounter{thm}[section]
\rene it to be blank:
newcommand{\thethm}{\thesection.\arabic{thm}}
\renewcommand{\qedsymbol}{}
\def\claim#1{\par\medskip\noindent\refstepcounter{thm}\hbox{\bf
\arabic{chapter}.\arabic{section}.\arabic{thm}. #1.}
\it\ %\ignorespaces } \def\endclaim{ \par\medskip}
\newenvironment{thm}{\claim}{\endclaim}

4.3.4

Theorem styles

It adds the possibility to change the output of the environ- In this case theorem looks like:
ments dened by \newtheorem using the \theoremstyle \begin{thm}{Claim}\label{lyt-prob} Let it be.
command[1] in the header:
you know. \end{thm}

Then

\theoremstyle{stylename}
the argument is the style you want to use. All subse- 4.3.6 Notes
quently dened theorems will use this style. Here is a
list of the possible pre-dened styles:
[1] Requires the amsthm package
Custom styles
To dene your own style, use the \newtheoremstyle
command[1] :
\newtheoremstyle{stylename}% name of the style to be
used {spaceabove}% measure of space to leave above the
theorem. E.g.: 3pt {spacebelow}% measure of space to
leave below the theorem. E.g.: 3pt {bodyfont}% name
of font to use in the body of the theorem {indent}%
measure of space to indent {headfont}% name of head
font {headpunctuation}% punctuation between head and
body {headspace}% space after theorem head; " " =
normal interword space {headspec}% Manually specify
head

4.3.7 External links


amsthm documentation

4.4 LaTeX/Chemical Graphics


chemg is a package used to draw 2D chemical structures. It is an alternative to ochem. Whereas ochem requires Perl to draw chemical structures, chemg uses the
tikz package to produce its graphics. chemg is used by
adding the following to the preamble:
\usepackage{chemg}

4.4. LATEX/CHEMICAL GRAPHICS

4.4.1

Basic Usage

95

4.4.5 Ions

The primary command used in this package is \chem- For example, consider an acetate ion:
g{}:
Because the chemg commands enters the math mode,
\chemg{<atom1><bond type>[<angle>,<coe>,<tikz ion charges can be added as superscripts (one caveat: a
negative ion requires that the minus sign be enclosed in
code>]<atom2>}
brackets, as in the example).
<angle> is the bond angle between two atoms (or nodes).
There are three types of angles: absolute, relative, and
predened. Absolute angles give a precise angle (generally, 0 to 360, though they can also be negative), and are
represented with the syntax [:<absolute angle>]. Relative
angles require the syntax [::<relative angle>] and produce
an angle relative to the angle of the preceding bond. Finally, predened angles are whole numbers from 0 to 7
indicating intervals of 45 degrees. These are produced
with the syntax [< predened angle>]. The predened
angles and their corresponding absolute angles are represented in the diagram below.

The charge of an ion can be circled by using \oplus and


\ominus:
Alternatively, charges can be placed above ions using
\chemabove{}{}:

4.4.6 Resonance Structures and Formal


Charges
Resonance structures require a few math commands:

% see Advanced Mathematics for use of


\left and \right % add to preamble: % \usep<bond type> describes the bond attaching <atom1> and ackage{mathtools}
%
\Longleftrightarrow
<atom2>. There are 9 dierent bond types:
$\left\{\chemg{O-N(=[:60]O)-[:300]O}\right\}
\left\{\chemg{O=N(-[:60]O)<coe> represents the factor by which the bonds length \Longleftrightarrow
[:300]O}\right\} \Longleftrightarrow \left\{\chemg{Owill be multiplied.
N(-[:60]O)=[:300]O}\right\}$
<tikz code> includes additional options regarding the
color or style of the bond.
A methane molecule, for instance, can be produced with
the following code:
4.4.7

Chemical Reactions

Linear molecules (such as methane) are a weak example


of this, but molecules are formed in chemg by nesting. Chemical reactions can be created with the following
commands:

4.4.2

Skeletal Diagrams

Skeleton diagrams can be produced as follows:

4.4.3

Rings

\chemrel[<arg1>][<arg2>]{<arrow code>}
\chemsign+ % produces a +
In \chemrel{}, <arg1> and <arg2> represent text placed
above and below the arrow, respectively.
There are four types of arrows that can be produced with
\chemrel{}:

A\chemrel{->}B\par
A\chemrel{<-}B\par
Rings follow the syntax <atom>*<n>(code), where n A\chemrel{<->}B\par A\chemrel{<>}B
indicates the number of sides in the ring and code represents the specic content of each ring (bonds and atoms).

4.4.8 Naming Chemical Graphics


4.4.4

Lewis Structures

Lewis
structures
use
the
syntax
\lewis{<n1><n2>...<ni>,<atom>}, where <ni> is a
number between 0 and 7 representing the position of
the electrons. By default, the electrons are represented
by a dash (-). Appending a period (.) or colon (:)
after a number will display single and paired electrons
respectively.

Molecules can be named with the command


\chemname[<dim>]{\chemg{<code
molecule>}}{<name>}

of

the

<dim> is inserted between the bottom of the molecule


and the top of the name dened by <name>. It is 1.5ex
by default.

<name> will be centered relative to the molecule it deLewis structures can also be included within \chemg{}. scribes.

96

CHAPTER 4. TECHNICAL TEXTS

\chemname{\chemg{R-C([:30]OH)=[:30]O}}{Carboxylic
acid}
\chemsign{+}
\chemname{\chemg{ROH}}{Alcohol}
\chemrel{->}
\chemname{\chemg{R-C([:30]OR)=[:30]O}}{Ester} \chemsign{+} \chemname{\chemg{H_2O}}{Water}
In the reaction above, \chemname{} inserts 1.5ex plus the
depth of the carboxylic acid molecule in between each
molecule and their respective names. This is because the
graphic for the rst molecule in the reaction (carboxylic
acid) extends deeper than the rest of the molecules. A
dierent result is produced by putting the alcohol rst:
\chemname{\chemg{ROH}}{Alcohol}
\chemsign{+}
\chemname{\chemg{R-C([:30]OH)=[:30]O}}{Carboxylic
acid}
\chemrel{->}
\chemname{\chemg{R-C([:30]OR)=[:30]O}}{Ester} \chemsign{+} \chemname{\chemg{H_2O}}{Water}

A few things here are automatically typeset; The 2 in


\ce{H2O} is automatically subscripted without requiring
additional commands. The amount of the species precedes the formula. 1/2 and other fractional amounts are
automatically typeset as in \ce{1/2H2O}. The charge in
\ce{AgCl2-} is automatically superscripted. If the charge
is neither 1 or 1, a ^ will superscript it, as in \ce{AgCl2}. The phase is not automatically subscripted and needs
to be enclosed in parenthesis preceded with a _ as in
\ce{H2_{(aq)}.

4.4.11 XyMTeX package


The following code produces the image for corticosterone
below.

\documentclass{letter}
\usepackage{epic,carom}
\pagestyle{empty}
\begin{document}
\begin{picture}(1000,500)
This is xed by adding \chemnameinit{<deepest
\put(0,0){\steroid[d]{3D==O;{{10}}==\lmoiety{H$_{3}$C};{{13}}==\lm
molecule>} before the rst instance of \chemname{}
\put(684,606){\sixunitv{}{2D==O;1==OH}{cdef}}
in a reaction and by adding \chemnameinit{} after the
\end{picture} \end{document}
reaction:
\chemnameinit{\chemg{R-C(-[:30]OH)=[:30]O}}
\chemname{\chemg{ROH}}{Alcohol}
\chemsign{+}
\chemname{\chemg{R-C([:30]OH)=[:30]O}}{Carboxylic
acid}
\chemrel{->}
\chemname{\chemg{R-C([:30]OR)=[:30]O}}{Ester} \chemsign{+} \chemname{\chemg{H_2O}}{Water} \chemnameinit{}
Lastly, adding \\ in <name> will produce a line-break,
allowing the name to span multiple lines.

4.4.9

Advanced Graphics

For advanced commands and examples, refer to the


chemg manual, where a more thorough and complete
introduction to the package can be found.
Corticosterone as rendered by XyMTeX

4.4.10

mhchem Package

mhchem is a package used to typeset chemical formulae and equations. As well as typeset basic 2D chemical
structures. To use this package, add the following to your
preamble:

4.5 LaTeX/Algorithms

LaTeX has several packages for typesetting algorithms in


form of "pseudocode". They provide stylistic enhancements over a uniform style (i.e., all in typewriter font) so
Chemical species are included using the \ce command. that constructs such as loops or conditionals are visually
For example
separated from other text. For typesetting real code, writ\ce{3H2O} \\ \ce{1/2H2O} \\ \ce{AgCl2-} \\ ten in a real programming language, consider the listings
\ce{H2_{(aq)}} \\
package described in Source Code Listings.
\usepackage[version=3]{mhchem}

4.5. LATEX/ALGORITHMS

4.5.1

97

Typesetting using the algorithmic and a simple example, taken from the v4.01 manual, is
package
\begin{algorithm}[H] \KwData{this text} \KwRe-

sult{how to write algorithm with \LaTeX2e } initialThe algorithmic package uses a dierent set of commands ization\; \While{not at end of this document}{ read
than the algorithmicx package. This is not compatible current\; \eIf{understand}{ go to next section\; current
with revtex4-1. Basic commands are:
section becomes this one\; }{ go back to the beginning of
\STATE <text> \IF{<condition>} \STATE{<text>} current section\; } } \caption{How to write algorithms}
\ELSE \STATE{<text>} \ENDIF \FOR{<condition>} \end{algorithm}
\STATE{<text>}
\ENDFOR
\FOR{<condition>
\TO <condition> } \STATE{<text>} \ENDFOR which produces
\FORALL{<condition>} \STATE{<text>} \ENDFOR
\WHILE{<condition>} \STATE{<text>} \ENDWHILE
\REPEAT \STATE{<text>} \UNTIL{<condition>}
\LOOP \STATE{<text>} \ENDLOOP \REQUIRE
<text> \ENSURE <text> \RETURN <text> \PRINT
<text> \COMMENT{<text>} \AND, \OR, \XOR,
\NOT, \TO, \TRUE, \FALSE
Complete documentation is listed at . Most commands
are similar to the algorithmicx equivalents, but with different capitalization. The package algorithms bundle at
the ctan repository, dated 2009-08-24, describes both the
algorithmic environment (for typesetting algorithms) and More details are in the manual hosted on the ctan website.
the algorithm oating wrapper (see below) which is designed to wrap around the algorithmic environment.
The algorithmic package is suggested for IEEE journals
4.5.3
as it is a part of their default style sheet.[1]

4.5.2

Typesetting using the algorithmicx


package

Typesetting using the algorithm2e The algorithmicx package provides a number of


package
popular constructs for algorithm designs. Put \usep-

ackage{algpseudocode} in the preamble to use the


algorithmic environment to write algorithm pseudocode
(\begin{algorithmic}...\end{algorithmic}).
You might want to use the algorithm environment (\usepackage{algorithm}) to wrap your algorithmic code in an algorithm environment (\beUnlike algorithmic, algorithm2e provides a relatively gin{algorithm}...\end{algorithm}) to produce a oating
huge number of customization options to the algorithm environment with numbered algorithms.
suiting to the needs of various users. The CTAN-manual The command \begin{algorithmic} can be given the opprovides a comprehensible list of examples and full set of tional argument of a positive integer, which if given will
cause line numbering to occur at multiples of that intecontrols.
ger. E.g. \begin{algorithmic}[5] will enter the algorithTypically, the usage between \begin{algorithm} and
mic environment and number every fth line.
\end{algorithm} would be
The algorithm2e package (rst released 1995, latest updated January 2013 according to the v5.0 manual) allows typesetting algorithms with a lot of customization.
Like algorithmic, this package is also not compatible with
Revtex-4.1.[2]

1. Declaring a set of keywords(to typeset as functions/operators), layout controls, caption, title, header
text (which appears before the algorithms main steps e.g.:
Input,Output)
2. Writing the main steps of the algorithm, with each step
ending with a \;
This may be taken in analogy with writing a latexpreamble before we start the actual document.

Below is an example of typesetting a basic algorithm


using the algorithmicx package (remember to add the
\usepackage{algpseudocode} statement to your document preamble):

The package is loaded like

The LaTeX source can be written to a format familiar


to programmers so that it is easy to read. This will not,
however, aect the nal layout in the document.

\usepackage[]{algorithm2e}

\begin{algorithmic} \If {$i\geq maxval$} \State $i\gets


0$ \Else \If {$i+k\leq maxval$} \State $i\gets i+k$
\EndIf \EndIf \end{algorithmic}

98

CHAPTER 4. TECHNICAL TEXTS


source; there are no limitations as in the old algorithmic
package.

Renaming things: algorithm to procedure, require/ensure to input/output


\oatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
Basic commands have the following syntax:
Statement (\State causes a new line, can also be used in Custom algorithmic blocks
front of other commands)
The algorithmicx package allows you to dene your own
\State $x\gets <value>$
environments.
Three forms of if-statements:

To dene blocks beginning with a starting command and


ending with an ending command, use

\If{<condition>} <text> \EndIf


\algblock[<block>]{<start>}{<end>}
\If{<condition>} <text> \Else <text> \EndIf
\If{<condition>} <text> \ElsIf{<condition>} <text>
This denes two commands \<start> and \<end> which
\Else <text> \EndIf
have no parameters. The text displayed by them is
\textbf{<start>} and \textbf{<end>}.
The third form accepts as many \ElsIf{} clauses as reWith \algblockdefx you can give the text to be output by
quired. Note that it is \ElsIf and not \ElseIf.
the starting and ending command and the number of paLoops:
rameters for these commands. In the text the n-th parameter is referenced by #n.
\For{<condition>} <text> \EndFor
\ForAll{<condition>} <text> \EndFor
\algblockdefx[<block>]{<start>}{<end>} [<startparam\While{<condition>} <text> \EndWhile
count>][<default value>]{<start text>} [<endparam\Repeat <text> \Until{<condition>}
count>][<default value>]{<end text>}
\Loop <text> \EndLoop
Pre- and postcondition:
\Require <text>
\Ensure <text>
Functions
\Function{<name>}{<params>} <body> \EndFunction
\Return <text>
\Call{<name>}{<params>}

Example:
\algblock[Name]{Start}{End}
\algblockdefx[NAME]{START}{END}%
[2][Unknown]{Start
#1(#2)}%
{Ending}
\algblockdefx[NAME]{}{OTHEREND}% [1]{Until (#1)}
\begin{algorithmic} \Start \Start \START[One]{x}
\END \START{0} \OTHEREND{\texttt{True}} \End
\Start \End \End \end{algorithmic}

More advanced customization and other constructions are


described in the algorithmicx manual: [Link]
This command will usually be used in conjunction with a
org/macros/latex/contrib/algorithmicx/[Link]
\State command as follows:
\Function{Increment}{$a$} \State $a \gets a+1$ \State
\Return $a$ \EndFunction
4.5.4

The algorithm environment

It is often useful for the algorithm produced by algorithmic to be oated to the optimal point in the document
\Comment{<text>}
to avoid it being split across pages. The algorithm environment provides this and a few other useful features.
Note to users who switched from the old algorithmic Include it by adding the
package: comments may be placed everywhere in the \usepackage{algorithm} to your documents preamble. It
is entered into by
Comments:

4.5. LATEX/ALGORITHMS

99

\begin{algorithm} \caption{<your caption for this The ocial manual is located at [Link]
algorithm>} \label{<your label for references later in
org/macros/latex/contrib/algorithms/algorithms.
your document>} \begin{algorithmic} <algorithmic
pdf
environment> \end{algorithmic} \end{algorithm}

Algorithm numbering
The default numbering system for the algorithm package
is to number algorithms sequentially. This is often not desirable, particularly in large documents where numbering
according to chapter is more appropriate. The numbering
of algorithms can be inuenced by providing the name of
the document component within which numbering should
be recommenced. The legal values for this option are:
part, chapter, section, subsection, subsubsection or nothing (default). For example:
\usepackage[chapter]{algorithm}

List of algorithms

4.5.5 Typesetting using the program package


The program package provides macros for typesetting algorithms. Each line is set in math mode, so all the indentation and spacing is done automatically. The notation
|variable_name| can be used within normal text, maths
expressions or programs to indicate a variable name. Use
\origbar to get a normal | symbol in a program. The commands \A, \B, \P, \Q, \R, \S, \T and \Z typeset the corresponding bold letter with the next object as a subscript
(eg \S1 typesets {\bf S$_1$} etc). Primes work normally,
eg \S.
Below is an example of typesetting a basic algorithm using the program package (remember to add the \usepackage{program} statement to your document preamble):

\begin{program} \mbox{A fast exponentiation proceWhen you use gures or tables, you can add a list of them dure:} \BEGIN \\ % \FOR i:=1 \TO 10 \STEP 1 \DO
close to the table of contents; the algorithm package pro- |expt|(2,i); \\ |newline|() \OD % \rcomment{This text
will be set ush to the right margin} \WHERE \PROC
vides a similar command. Just put
|expt|(x,n) \BODY z:=1; \DO \IF n=0 \THEN \EXIT \FI;
\listofalgorithms
\DO \IF |odd|(n) \THEN \EXIT \FI; \COMMENT{This
is a comment statement}; n:=n/2; x:=x*x \OD; \{ n>0
anywhere in the document, and LaTeX will print a list of \}; n:=n-1; z:=z*x \OD; |print|(z) \ENDPROC \END
the algorithm environments in the document with the \end{program}
corresponding page and the caption.
An example from the manual
This is an example taken from the manual (ocial manual, p.14)
\begin{algorithm} % enter the algorithm environment
\caption{Calculate $y = x^n$} % give the algorithm a
caption \label{alg1} % and a label for \ref{} commands
later in the document \begin{algorithmic} % enter the
algorithmic environment \REQUIRE $n \geq 0 \vee x
\neq 0$ \ENSURE $y = x^n$ \STATE $y \Leftarrow
1$ \IF{$n < 0$} \STATE $X \Leftarrow 1 / x$ \STATE
$N \Leftarrow -n$ \ELSE \STATE $X \Leftarrow x$
\STATE $N \Leftarrow n$ \ENDIF \WHILE{$N \neq
0$} \IF{$N$ is even} \STATE $X \Leftarrow X \times
X$ \STATE $N \Leftarrow N / 2$ \ELSE[$N$ is odd]
\STATE $y \Leftarrow y \times X$ \STATE $N \Left- The commands \( and \) are redened to typeset an alarrow N - 1$ \ENDIF \ENDWHILE \end{algorithmic} gorithm in a minipage, so an algorithm can appear as a
\end{algorithm}
single box in a formula. For example, to state that a particular action system is equivalent to a WHILE loop you
can write:
More information about all possible commands avail\[ \( \ACTIONS A: A \EQ \IF \B{} \THEN \S{}; \CALL
able at the project page
[Link]
A \ELSE \CALL Z \FI \QE \ENDACTIONS \) \EQT \(
3442
\WHILE \B{} \DO \S{} \OD \) \]

100

CHAPTER 4. TECHNICAL TEXTS


macros/latex/contrib/algorithms/[Link]

Dijkstra conditionals and loops:


\begin{program} \IF x = 1 \AR y:=y+1 \BAR 4.6 LaTeX/Source Code Listings
x = 2 \AR y:=y^2 \utdots \BAR x = n \AR
y:=\displaystyle\sum_{i=1}^n y_i \FI \DO 2 \origbar x \AND x>0 \AR x:= x/2 \BAR \NOT 2 \origbar x 4.6.1 Using the listings package
\AR x:= \modbar{x+3} \OD \end{program}
Using the package listings you can add non-formatted text
as you would do with \begin{verbatim} but its main aim is
Loops with multiple exits:
to include the source code of any programming language
\begin{program} \DO \DO \IF \B1 \THEN \EXIT \FI; within your document. If you wish to include pseudocode
\S1; \IF \B2 \THEN \EXIT(2) \FI \OD; \IF \B1 \THEN or algorithms, you may nd Algorithms and Pseudocode
useful also.
\EXIT \FI \OD \end{program}
To use the package, you need:
A Reverse Engineering Example.

The listings package supports highlighting of all the most


common languages and it is highly customizable. If you
just want to write code within your document the package
\begin{program} \VAR \seq{m := 0, p := 0, |last| := ``
provides the lstlisting environment:
''}; \ACTIONS |prog|: |prog| \ACTIONEQ % \seq{|line|
:= `` '', m := 0, i := 1}; \CALL |inhere| \ENDACTION l Another possibility, that is very useful if you created a
\ACTIONEQ % i := i+1; \IF (i=(n+1)) \THEN \CALL program on several les and you are still editing it, is to
|alldone| \FI ; m := 1; \IF |item|[i] \neq |last| \THEN import the code from the source itself. This way, if you
|write|(|line|); |line| := `` ''; m := 0; \CALL |inhere| \FI ; modify the source, you just have to recompile the LaTeX
\CALL |more| \ENDACTION |inhere| \ACTIONEQ % code and your document will be updated. The command
p := |number|[i]; |line| := |item|[i]; |line| := |line| \concat `` is:
'' \concat p; \CALL |more| \ENDACTION |more| \AC- in the example there is a Python source, but it doesn't
TIONEQ % \IF (m=1) \THEN p := |number|[i]; |line| := matter: you can include any le but you have to write
|line| \concat ``, '' \concat p \FI ; |last| := |item|[i]; \CALL the full le name. It will be considered plain text and it
l \ENDACTION |alldone| \ACTIONEQ |write|(|line|); will be highlighted according to your settings, that means
\CALL Z \ENDACTION \ENDACTIONS \END it doesn't recognize the programming language by itself.
\end{program}
You can specify the language while including the le with
Heres the original program:

the following command:


And heres the transformed and corrected version:

You can also specify a scope for the le.

\begin{program} \seq{|line| := `` '', i := 1}; \WHILE


i \neq n+1 \DO |line| := |item|[i] \concat `` '' \concat
|number|[i]; i := i+1; \WHILE i \neq n+1 \AND |item|[i]
= |item|[i-1] \DO |line| := |line| \concat ``, '' \concat |number|[i]); i := i+1 \OD ; |write|(|line|) \OD \end{program}

This comes in handy if you are sure that the le will not
change (at least before the specied lines). You may also
omit the rstline or lastline parameter: it means everything up to or starting from this point.
This is a basic example for some Pascal code:

The package also provides a macro for typesetting a set


like this: \set{x \in N | x > 0}.
Lines can be numbered by setting \NumberProgramstrue
and numbering turned o with \NumberProgramsfalse
Package page
Package documentation

4.5.6

References

[1]
[2] [Link]
revtex4-1-and-algorithm2e-indentation-clash

Supported languages
It supports the following programming languages:

The ocial manual for the algorithms pack- For some of them, several dialects are supported. For
age, Rogrio Brito (2009), [Link] more information, refer to the documentation that comes

4.6. LATEX/SOURCE CODE LISTINGS

101

with the package, it should be within your distribution puts(LaTeX is also great for programmers!"); } return
under the name listings-*.dvi.
0; } \end{lstlisting} \lstinputlisting[caption=Scheduler,
style=customc]{hello.c}
Notes
1. It supports Mathematica code only if you are typing
in plain text format. You can't include *.NB les
\lstinputlisting{...} as you could with any other programming language, but Mathematica can export in
a pretty-formatted LaTeX source.
2. Specication of the dialect is
tory for these languages (e.g.
guage={[x86masm]Assembler}).

The C part will print as

mandalan-

3. Modelica is supported via the dtsyntax package


available here.
4. For these languages, multiple dialects are supported.
C, for example, has ANSI, Handel, Objective and
Sharp. See p. 12 of the listings manual for an
overview.
Settings
You can modify several parameters that will aect how
the code is shown. You can put the following code anywhere in the document (it doesn't matter whether before
or after \begin{document}), change it according to your
needs. The meaning is explained next to any line.

Automating le inclusion
If you have a bunch of source les you want to include,
you may nd yourself doing the same thing over and over
again. This is where macros show their real power.

In this example, we create one command to ease source


code inclusion. We set the default style to be customc. All
listings will have their name as caption: we do not have
The escapeinside line needs an explanation. The option to write the le name twice thanks to the macro. Finally
escapeinside={A}{B} will dene delimiters for escaping we list all listings with this command from the listings
into LaTeX code, i.e. all the code between the string A package.
and B will be parsed as LaTeX over the current listings
See Macros for more details.
style. In the example above, the comments for Octave
start with %, and they are going to be printed in the document unless they start with %*, in which case they are Encoding issue
read as LaTeX (with all LaTeX commands fullled) until they're closed with another *). If you add the above By default, listings does not support multi-byte encoding
paragraph, the following can be used to alter the settings for source code. The extendedchar option only works for
within the code:
8-bits encodings such as latin1.
escapeinside

There are many more options, check the ocial docu- To handle UTF-8, you should tell listings how to interpret
mentation.
the special characters by dening them like so
The above table will cover most characters in latin languages. For a more detailed explanation of the usage of
the literate option check section 5.4 in the Listings DocThe package lets you dene styles, i.e. proles specifying umentation.
a set of settings.
Another possibility is to replace \usepackage{listings} (in
Example
the preamble) with \usepackage{listingsutf8}.
Style denition

In our example, we only set two options globally: the default style and the escape character. Usage:

Customizing captions
\begin{lstlisting} #include <stdio.h> #dene N 10 /*
Block * comment */ int main() { int i; // Line com- You can have fancy captions (or titles) for your listings
ment. puts(Hello world!"); for (i = 0; i < N; i++) { using the caption package. Here is an example for listings.

102

4.6.2

CHAPTER 4. TECHNICAL TEXTS

The minted package

Attribute-Value Matrices (AVMs): avm

minted is an alternative to listings which has become pop John Framptons expex: expex
ular. It uses the external Python library Pygments for
code highlighting, which as of Nov 2014 boasts over 300
supported languages and text formats.
4.7.1 Enumerated examples
As the package relies on external Python code, the setup
require a few more steps than a usual LaTeX package, so There are several commonly used packages for creating
please have a look at their GitHub repo and their manual. the kinds of numbered examples that are used in linguistics publications.

4.6.3

References

gb4e
A lot more detailed information can be found in a PDF
by Carsten Heinz and Brooks Moses.
The gb4e package[2] is called with:
Details and documentation about the Listings package \usepackage{gb4e}
can be found at its CTAN website.

4.7 LaTeX/Linguistics
There are a number of LaTeX packages available for
writing linguistics papers. Various packages have been
created for enumerated examples, syntactic trees, OT
tableaux, feature matrices, IPA fonts, and many other applications. Some packages such as the tipa package are
eectively standard within the eld, while others will vary
by author preference.

IMPORTANT: If you use gb4e package, let it be the last


\usepackage call in the documents preamble. Otherwise
you may get exceeded parameter stack size error.
Examples for this package are placed within the exe environment, and each example is introduced with the \ex
command.
\begin{exe} \ex This is an example. \end{exe}
produces:

Some recommended packages[1] :


Glosses: gb4e;

Multiple examples can be included within the environment, and each will have its own number.

IPA symbols: tipa;

\begin{exe} \ex This is the rst example. \ex This is the


second example. \ex This is the third. \end{exe}

OT Tableaux: OTtablx;
Syntactic trees: qtree + tree-dvips (for drawing arrows);

produces:

Alternatively, xyling is very powerful but


not as user friendly as qtree;
The xy package itself has a steep learning
curve, but allows a lot of control; for simplest trees use the xymatrix feature and
arrows;
tikz-qtree has the same syntax as qtree,
but uses PGF/TikZ, which allows more
options for drawing arrows, etc.
Dependency trees and bubble parses:
The TikZ-dependency package provides
a high-level, convenient interface to draw
dependency graphs. It is based on
PGF/TikZ but does not require prior
knowledge of TikZ in order to be used
productively.

To create nested lists of examples, the xlist enviroment is


used.
\begin{exe} \ex \begin{xlist} \ex This is a sub-example.
\ex This is a second sub-example. \ex \begin{xlist}
\ex This is a sub-sub-example. \ex This is a second
sub-sub-example. \end{xlist} \end{xlist} \end{exe}
produces:

4.7. LATEX/LINGUISTICS

103

For notating acceptability judgments, the \ex command


can take an optional argument. When including a judgment marker, the corresponding sentence must be surrounded by braces.
\begin{exe} \ex This sentence is grammatical English.
\ex[*] {This sentence English in ungrammatical is.}
Full documentation can be found here.
\end{exe}
produces:

4.7.2 Syntactic trees

Often, linguists will have to illustrate the syntactic structure of a sentence. One device for doing this is through
syntactic trees. Unfortunately, trees look very dierent
Referencing examples in text works as it does in norin dierent grammar formalisms, and dierent LaTeX
mal LaTeX documents. See the labeling and crosspackages are suited for dierent formalisms.
referencing section for more details.
\begin{exe} \ex\label{ex1} Godzilla destroyed the city.
\ex\label{ex2} Godzilla roared. \end{exe} Sentence Constituent trees
(\ref{ex1}) contains two arguments, but (\ref{ex2})
While there are several packages for drawing syntactic
contains only one.
trees available for LaTeX, this article focuses on the qtree
and xyling packages.
Further details can be found in the full documentation
available here.
qtree Drawing trees with qtree is relatively straightforward. First, the qtree package has to be included in the
documents preamble:
lingmacros

\usepackage{qtree}

The lingmacros package[3] created by Emma Pease is an


alternate method for example numbering. This package
uses two main commands, \enumsentence and \eenumsentence. The former is used for singleton examples,
while the latter command is used for nested examples.

A new tree is started using the \Tree command, each


(sub-)tree is indicated by brackets [ ]. The root of a (sub)tree is always preceded by a ., leaf nodes are simply expressed by their labels.

\enumsentence{This is an example.}

For example, the following code


\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]

produces this syntactic tree as output:


\enumsentence{This is the rst example.} \enumsenNote that the spaces before the closing brackets are
tence{This is the second example.} \enumsentence{This
mandatory.
is the third.}
By default, qtree centers syntactic trees on the page. This
behaviour can be turned o by either specifying the behaviour when loading the package
\usepackage[nocenter]{qtree} % do not center trees
or via the command
Multiply nested examples make use of the normal LaTeX
\qtreecenterfalse % do not center trees from here on
list environments.
\eenumsentence{\item This is a sub-example. \item
This is a second sub-example. \item \begin{enumerate} anywhere in the document. The eect of the latter can be
\item This is sub-sub-example. \item This is a second undone by using the command
\qtreecentertrue % center trees from here on
sub-sub-example. \end{enumerate} }
produces:

IMPORTANT: If you use gb4e package, let it be the last

104

CHAPTER 4. TECHNICAL TEXTS

\usepackage call in the documents preamble. Otherwise


you may get exceeded parameter stack size error.
tikz-qtree Using the same syntax as qtree, tikz-qtree
is another easy-to-use alternative for drawing syntactic
trees.
For simple trees, tikz-qtree is completely interchangable
with qtree. However, some of qtrees advanced features
are implemented in a dierent way, or not at all. On the
other hand, tikz-qtree provides other features such as controlling the direction of the trees growth (top to bottom,
left to right etc.) or dierent styles for edges.

change the direction of a single tree, it has to be put into


a \tikzpicture environment:

\begin{tikzpicture} % all changes only aect trees


within this environment \tikzset{grow'=right} %
To use the tikz-qtree package for drawing trees, put the make trees grow from left to right \tikzset{every tree
node/.style={anchor=base west}} % allign nodes of the
following into the documents preamble:
tree to the left (west) \Tree [.S [.NP LaTeX ] [.VP [.V is
\usepackage{tikz} \usepackage{tikz-qtree}
] [.NP fun ] ] ] \end{tikzpicture}
The syntax of tikz-qtree and result when drawing a simple
tree is the same as for qtree.

Dependency Trees
\Tree [.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
Note that, other than for qtree, trees are not centered by Dependency trees can take multiple visual forms. Comdefault. To center them, put them into a centered envi- monly, they quite resemble phrase structure trees. Alterronment:
natively, they can be captured by brackets drawn above
\begin{center} \Tree [.S [.NP LaTeX ] [.VP [.V is ] running text.
[.NP fun ] ] ] \end{center}
For setting the style of trees, tikz-qtree provides the
\tikzset command. For example, to make a tree grow
from left to right instead of from top to bottom, use the
following code:
\tikzset{grow'=right} % make trees grow from left
to right \tikzset{every tree node/.style={anchor=base
west}} % allign nodes of the tree to the left (west) \Tree
[.S [.NP LaTeX ] [.VP [.V is ] [.NP fun ] ] ]
The above code changes the default orientation for all
trees that are dened after \tikzset commands. To only

Two-dimensional Dependency Trees These can be


either achieved using the fairly universal drawing package
TikZ, like so:
% In the preamble: \usepackage{tikz} % In the document: \begin{tikzpicture} \node (is-root) {is} [sibling
distance=3cm] child { node {this} } child { node {tree}
[sibling distance=1.5cm] child { node {an} } child {
node {example} } child { node {.} } child[missing]
}; \path (is-root) +(0,2.5\tikzleveldistance) node
{\textit{This is an example tree.}}; \end{tikzpicture}

4.7. LATEX/LINGUISTICS
which gives you the following drawing:

105
the LaTeX code to DVI (and perhaps converting to PDF
using the tools dvips and ps2pdf later).
An example code:
% In the preamble: \usepackage{xytree} % In the
document: \xytext{ \xybarnode{Peter} &~~~& \xybarnode{and}
\xybarconnect(UL,U){2}"_{\small
conj}"
\xybarconnect(UR,U){2}"^{\small
conj}"
&~~~&
\xybarnode{Mary}
&~~~&
\xybarnode{bought} \xybarconnect[8](UL,U){4}"_{\small
subj}"
\xybarconnect[13]{6}"^{\small
punct}"
\xybarconnect[8](UR,U){4}"^{\small
obj}"
&~~~& \xybarnode{a} &~~~& \xybarnode{car}
\xybarconnect(UL,U){2}"_{\small det}" &~~~&
\xybarnode{.} }
results in:

A dependency tree created using TikZ

TikZ has the advantage that it allows for generating PDF


directly from the LaTeX source, without need for any detour of compiling to DVI using latex, and then converting to PDF probably via PS using tools such as dvips and
A dependency tree above running text created using xytree
ps2pdf. Latter is the case of another package based on
the package xy, namely xyling.
The code for a similar tree using xyling might look like:
% In the preamble: \usepackage{xytree} % In the
document: \Tree{ & \K{is}\B{dl}\B{drr} \\ \K{this}
&&& \K{tree}\B{dll}\B{dl}\B{dr} \\ & \K{an} &
\K{example} && \K{.} } \medskip \textit{This is an
example tree.}
which gives you a drawing like this:

Dependency Trees using TikZ-dependency


The
package provides high level commands to design and style
dependency graphs. To draw a graph, you only need to
create a dependency environment, write the text of the
sentence within the deptext environment and use depedge
commands to draw the edges. Global and local optional
parameters can be used to style and ne tune the looks of
the graph, as shown in the following example:
% In the preamble: \usepackage{tikz-dependency}
% In the document:
\begin{dependency}[theme
=
simple]
\begin{deptext}[column
sep=1em]
A \& hearing \& is \& scheduled \& on \&
the \& issue \& today \& .
\\ \end{deptext}
\deproot{3}{ROOT}
\depedge{2}{1}{ATT}
\depedge[edge start x oset=6pt]{2}{5}{ATT}
\depedge{3}{2}{SBJ}
\depedge{3}{9}{PU}
\depedge{3}{4}{VC}
\depedge{4}{8}{TMP}
\depedge{5}{7}{PC}
\depedge[arc
angle=50]{7}{6}{ATT} \end{dependency}
This code snippet would produce the following result:

A dependency tree created using xyling

Dependency Trees as Brackets above Text One way


to typeset dependency brackets above running text is using the package xytree. It gives you fairly good control A dependency tree drawn with TikZ-dependency.
of how the brackets are typeset but requires compiling

106

4.7.3

CHAPTER 4. TECHNICAL TEXTS

Glosses

\begin{IPA} text in IPA format here \end{IPA}

Below, it is explained how to make glossed examples with


This method is useful for long stretches of text that need
dierent packages.
to be in IPA. Alternatively, there is the \textipa command
that will format the text in its argument into IPA. This
command is similar to other font typesetting commands.
With gb4e
To create a glossed example, use the normal exe environment. But after the \ex tag, introduce the example and its
gloss using \gll and the translation after it with \trans tag.

\textipa{text in IPA format here}

\begin{exe} \ex \gll \\ [Link] Basic symbols


[Link] [Link]\\ \trans `The cat eats
The IPA format works by translating ASCII characters
sour cream' \end{exe}
into corresponding IPA symbols. Lower case letters are
rendered as usual,
The code will produce the following output:
\textipa{abcdefghijklmnopqrstuvwxyz}

however capital letters are rendered dierently.


\textipa{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
Vertically aligned glosses are separated by spaces, so if
its necessary to include a space in part the gloss, simply produces:
enclose the connected parts inside braces.
\begin{exe} \ex \gll Pekka pel\"astyi karhusta.\\ Pekka
{became afraid} [Link]\\ \trans `Pekka became afraid Punctuation marks that are normally used in LaTeX are
also rendered faithfully in the IPA environment.
because of the/a bear.' \end{exe}
\textipa{! * + = ? . , / [ ] ( ) ` ' | ||}
With lingmacros
The lingmacros package uses the \shortex command to introduce glossed examples inside the \enumsentence and
\eenumsentence commands. This command takes four
arguments and builds o the normal tabular environment.
Its rst argument species the number of columns in the
gloss. The second and third arguments give the text and
its gloss respectively, and items within each column are
divided by the usual & tabular separator. The fourth argument is the translation.

produces:

Numerals and @ also have variants in the tipa environment.


\textipa{1234567890 @}
produces:

\enumsentence{\shortex{3} {Pekka & pel\"astyi & In addition, there are a number of special macros for
karhu-sta.} {Pekka & became afraid & [Link]} representing symbols that don't have other associations,
{`Pekka became afraid because of the/a bear.'} }
some of which are listed here. For a complete list see the
ocial TIPA Manual[4] .

4.7.4

IPA characters

The tipa package is the standard LaTeX package for International Phonetic Alphabet symbols.
\usepackage{tipa}

The \; macro preceding a capital letter produces a small


caps version of the letter.
\textipa{\;A \;B \;E \;G \;H \;I \;L \;R \;Y}
produces:

There are two methods for getting IPA symbols into a The \: macro produces retroex symbols.
document. The rst way is to use the IPA environment. \textipa{\:d \:l \:n \:r \:s \:t \:z}

4.7. LATEX/LINGUISTICS

gets you:

The \! macro produces implosive symbols and the bilabial


click.
\textipa{\!b \!d \!g \!j \!G \!o}
gets you:

4.7.5

References

[1] LaTeX for Linguists presentation


[2] The gb4e package on CTAN
[3] The lingmacros package on CTAN
[4] TIPA manual

4.7.6

External links

LaTeX for Linguists


The qtree package for drawing syntactic trees.
The gb4e package page on CTAN.

107

Chapter 5

Special Pages
5.1 LaTeX/Indexing

Compiling indices

Especially useful in printed books, an index is an alphabetical list of words and expressions with the pages of
the book upon which they are to be found. LaTeX supports the creation of indices with its package makeidx,
and its support program makeindex, called on some systems makeidx.

When the input le is processed with LaTeX, each \index command writes an appropriate index entry, together
with the current page number, to a special le. The le
has the same name as the LaTeX input le, but a dierent
extension (.idx). This .idx le can then be processed with
the makeindex program. Type in the command line:
makeindex lename

Note that lename is without extension: the program will


look for [Link] and use that. You can optionally
pass [Link] directly to the program as an argument.
The makeindex program generates a sorted index with the
same base le name, but this time with the extension .ind.
5.1.1 Using makeidx
If now the LaTeX input le is processed again, this sorted
index gets included into the document at the point where
To enable the indexing feature of LaTeX, the makeidx LaTeX nds \printindex.
package must be loaded in the preamble with:
The index created by latex with the default options may
and the special indexing commands must be enabled by not look as nice or as suitable as you would like it. To imputting the
prove the looks of the index makeindex comes with a set
command into the input le preamble. This should be of style les, usually located somewhere in the tex direcdone within the preamble, since it tells LaTeX to create tory structure, usually below the makeindex subdirectory.
the les needed for indexing. To tell LaTeX what to in- To tell makeindex to use a specic style le, run it with
the command line option:
dex, use
where key is the index entry and does not appear in the
nal layout. You enter the index commands at the points
in the text that you want to be referenced in the index,
likely near the reason for the key. For example, the text

makeindex -s <style le> lename


If you use a GUI for compiling latex and index les, you
may have to set this in the options. Here are some conguration tips for typical tools:

can be re-written as
to create an entry called 'Fourier Series with a reference
to the target page. Multiple uses of \index with the same MakeIndex settings in WinEdt Say you want to add
key on dierent pages will add those target pages to the an index style le named [Link]
same index entry.
To show the index within the document, merely use the
command
It is common to place it at the end of the document. The
default index format is two columns.
The showidx package that comes with LaTeX prints out
all index entries in the right margin of the text. This is
quite useful for proofreading a document and verifying
the index.
108

Texify/PDFTexify:
OptionsExecution
ModesAccessoriesPDFTeXify, add to the
Switches: --mkidx-option="-s [Link]
MakeIndex
alone:
OptionsExecution
ModesAccessoriesMakeIndex, add to command line: -s [Link]

5.1. LATEX/INDEXING

109

Sophisticated indexing

saries package described in the Glossary chapter. Another option is the package acronym .

Below are examples of \index entries:

To enable the Nomenclature feature of LaTeX, the


nomencl package must be loaded in the preamble with:

Subentries If some entry has subsections, these can be Issue


the
\nomenclamarked o with !. For example,
ture[prex]{symbol}{description}
command
for
each
symbol
you
want
to
have
included
in the
would create an index entry with 'cp850' categorized unnomenclature
list.
The
best
place
for
this
command
is
der 'input' (which itself is categorized into 'encodings).
immediately
after
you
introduce
the
symbol
for
the
rst
These are called subsubentries and subentries in makeidx
time. Put \printnomenclature at the place you want to
terminology.
have your nomenclature list.
Controlling sorting In order to determine how an index key is sorted, place a value to sort by before the key
with the @ as a separator. This is useful if there is any
formatting or math mode, so one example may be
so that the entry in the index will show as ' F ' but be
sorted as 'F'.

Run LaTeX 2 times then


makeindex [Link] -s [Link] -o [Link]
followed by running LaTeX once again.
To add the abbreviation list to the table of content, intoc
option can be used when declare the nomencl package,
i.e.

To combine with the above feature for subentries, you


instead of using the code in Adding Index to Table Of
should style the appropriate component(s):
Contents section.
The title of the list can be changed using the following
Changing page number style To change the format- command:
ting of a page number, append a | and the name of some
command which does the formatting. This command
should only accept one argument.
5.1.3 Multiple indices
For example, if on page 3 of a book you introduce bullIf you need multiple indices you can use the package
dogs and include the command
multind .
and on page 10 of the same book you wish to show the
This package provides the same commands as makeidx,
main section on bulldogs with a bold page number, use
but now you also have to pass a name as the rst argument
This will appear in the index as bulldog, 3, 10
to every command.
If you use texindy in place of makeindex, the classied
entries will be sorted too, such that all the bolded entries
5.1.4 Adding index to table of contents
will be placed before all others by default.
By default, Index won't show in Table Of Contents, so
Multiple pages To perform multi-page indexing, add you have to add it manually.
a |( and |) to the end of the \index command, as in
To add index as a chapter, use these commands:
The entry in the index for the subentry 'History' will be If you use the book class, you may want to start it on an
the range of pages between the two \index commands.
odd page by using \cleardoublepage.
Using special characters In order to place values with
!, @, or |, which are otherwise escape characters, in the
index, one must quote these characters in the \index command by putting a double quotation mark (") in front of
them, and one can only place a " in the index by quoting
it (i.e., a key for " would be \index{""}).

5.1.5 International indices

If you want to sort entries that have international characters (such as , , , , etc.) you may nd that the sorting is not quite right. In most cases the characters are
treated as special characters and end up in the same group
This rule does not hold for \", so to put the letter in the as @, or . In most languages that use Latin alphabet
index, one may still use \index{a@\"{a}}.
its not correct.

5.1.2

Abbreviation list

Generating index

You can make a list of abbreviations with the package Unfortunately, current version of xindy and hyperref are innomencl . You may also be interested in using the glos- compatible. When you use textbf or textit modiers, texindy

110

will print error message:unknown cross-reference-class `hyperindexformat'! (ignored) and won't add those pages to index.
Work-around for this bug is described on the talk page.

To generate international index le you have to use


texindy instead of makeindex.

CHAPTER 5. SPECIAL PAGES


in folder
/usr/share/xindy/tex/inputenc
(You must have root privileges)

xindy is a much more extensible and robust indexing sys- xindy in kile To use texindy instead of makeindex in
kile, you have to either redene the MakeIndex tool in
tem than the makeindex system.
Settings Congure Kile... Tools Build, or dene
For example, one does not need to write:
new tool and redene other tools to use it (for example by
to get the Lin entry after LAN and before LZA, instead, adding it to QuickBuild).
its enough to write
The xindy denition should look similar to this:
But what is much more important, it can properly sort General: Command: texindy Options: -L polish -M
index les in many languages, not only English.
lang/polish/utf8 -I latex '%[Link]' Advanced: Type: Run
Unfortunately, generating indices ready to use by LaTeX Outside of Kile Class: Compile Source extension: idx
using xindy is a bit more complicated than with makein- Target extension: ind Target le: <empty> Relative dir:
<empty> State: Editor Menu: Add tool to Build menu:
dex.
Compile Icon: the one you like
First, we need to know in what encoding the .tex project
le is saved. In most cases it will be UTF-8 or ISO-88591, though if you live, for example in Poland it may be ISO8859-2 or CP-1250. Check the parameter to the inputenc 5.2 LaTeX/Glossary
package.
Second, we need to know which language is prominently Many technical documents use terms or acronyms unused in our document. xindy can natively sort indices known to the general population. It is common practice
in Albanian, Belarusian, Bulgarian, Croatian, Czech, to add a glossary to make such documents more accessiDanish, Dutch, English, Esperanto, Estonian, Finnish, ble.
French, Georgian, German, Greek, Gypsy, Hausa, Hebrew, Hungarian, Icelandic, Italian, Klingon, Kurdish,
Latin, Latvian, Lithuanian, Macedonian, Mongolian,
Norwegian, Polish, Portuguese, Romanian, Russian, Serbian Slovak, Slovenian, Sorbian, Spanish, Swedish, Turkish, Ukrainian and Vietnamese,

The glossaries package can be used to create glossaries.


It supports multiple glossaries, acronyms, and symbols.
This package replaces the glossary package and can be
used instead of the nomencl package.[1] Users requiring a simpler solution should consider hand-coding their
entries by using the description environment, or the
I don't know if other languages have similar problems, longtabu environment provided by the tabu package.
but with Polish, if your .tex is saved using UTF-8, the
.ind produced by texindy will be encoded in ISO-8859-2
5.2.1 Jump start
if you use only -L polish. While its not a problem for
entries containing polish letters, as LaTeX internally enPlace \usepackage{glossaries} and \makeglossaries in
codes all letters to plain ASCII, it is for accented letters at
your preamble (after \usepackage{hyperref} if present).
beginning of words, they create new index entry groups,
Then dene any number of \newglossaryentry and
if you have, for example an "rednia entry, you'll get a
\newacronym glossary and acronym entries in your
"" encoded in ISO-8859-2 .ind le. LaTeX doesn't like
preamble (recommended) or before rst use in your docif part of the le is in UTF-8 and part is in IS-8859-2. The
ument proper. Finally add a \printglossaries call to locate
obvious solution (adding -C utf8) doesn't work, texindy
the glossaries list within your document structure. Then
stops with
pepper your writing with \gls{mylabel} macros (and simERROR: Could not nd le tex/inputenc/[Link]
ilar) to simultaneously insert your predened text and
error. The x this, you have to load the deniton style for build the associated glossary. File processing must now
include a call to makeglossaries followed by at least one
the headings using -M switch:
further invocation of latex or pdatex.
-M lang/polish/utf8
In the end we have to run such command:
texindy -L polish -M lang/polish/utf8 [Link]

5.2.2 Using glossaries

Additional way to x this problem is use iconv to create To use the glossaries package, you have to load it explicitly:
[Link] from [Link]
iconv -f latin2 -t utf8 [Link] >[Link]

if you wish to use xindy (recommended) for the indexing


phase, as opposed to makeindex (the default), you need

5.2. LATEX/GLOSSARY

111

to specify the xindy option:

So far, the glossary entries have been dened as key-value


For the glossary to show up in your Table of Contents, lists. Sometimes, a description is more complex than just
a paragraph. For example, you may want to have multiple
you need to specify the toc option:
paragraphs, itemized lists, gures, tables, etc. For such
See also Custom Name at the bottom of this page.
glossary entries use the command longnewglossaryentry
Finally, place the following command in your document in which the description follows the key-value list. The
computer entry then looks like this:
preamble in order to generate the glossary:
Any links in resulting glossary will not be clickable unless you load the glossaries package after the hyperref Dening symbols
package.
In addition, users who wish to make use of makeglos- Dened entries can also be symbols:
saries will need to have Perl installed this is not nor- You can also dene both a name and a symbol:
mally present by default on Microsoft Windows platforms. That said, makeglossaries simply provides a con- Note that not all glossary styles show dened symbols.
venient interface to makeindex and xindy and is not essential.
Dening acronyms

5.2.3

Dening glossary entries

To dene a new acronym you use the \newacronym


macro:

To use an entry from a glossary you rst need to dene it. where <label> is the unique label identifying the
There are few ways to dene an entry depending on what acronym, <abbrv> is the abbreviated form of the
you dene and how it is going to be used.
acronym and <full> is the expanded text. For example:
Note that a dened entry won't be included in the printed Dened acronyms can be put in separate list if you use
glossary unless it is used in the document. This enables acronym package option:
you to create a glossary of general terms and just \include
it in all your documents.

5.2.5 Using dened terms


5.2.4

Dening terms

When you have dened a term, you can use it in a document. There are many dierent commands used to refer
To dene a term in glossary you use the \newglossaryentry to glossary terms.
macro:
<label> is a unique label used to identify an entry in glossary, <settings> are comma separated key=value pairs General references
used to dene an entry.
A general reference is used with \gls command. If, for
For example, to dene a computer entry:
example, you have glossary entries dened as those above,
The above example denes an entry that has the same la- you might use it in this way:
bel and entry name. This is not always the case as the
Description of commands used in above example:
next entry will show:
When you dene terms, you need to remember that they This command prints the term associated with <label>
will be sorted by makeindex or xindy. While xindy is passed as its argument. If the hyperref package was
a bit more LaTeX aware, it does it by omitting latex loaded before glossaries it will also be hyperlinked to the
macros (\"{\i}) thus incorrectly sorting the above exam- entry in glossary.
ple as nave. makeindex won't fare much better, because it
doesn't understand TeX macros, it will interpret the word
exactly as it was dened, putting it inside symbol class,
before words beginning with naa. Therefore its needed
to extend our example and specify how to sort the word:

This command prints the plural of the dened term, other


than that it behaves in the same way as gls.
This command prints the singular form of the term with
the rst character converted to upper case.

This command prints the plural form with rst letter of


You can also specify plural forms, if they are not formed the term converted to upper case.
by adding s (we will learn how to use them in next secThis command creates the link as usual, but typesets the
tion):
alternate text instead. It can also take several options
Or, for acronyms:
which changes its default behavior (see the documentaThis will avoid the wrong long plural: Frame per Seconds. tion).

112

CHAPTER 5. SPECIAL PAGES

This command prints what ever is dened in \newglos- Syntax: \newdualentry[glossary options][acronym opsaryentry{<label>}{symbol={Output of glssymbol}, ...} tions]{label}{abbrv}{long}{description}
This command prints what ever is dened in \newglos- then, dene new (dual) entries for glossary and acronym
saryentry{<label>}{description={Output of glsdesc}, list like this:
...}
Custom Name
Referring acronyms
Acronyms behave a bit dierently than normal glossary
terms. On rst use the \gls command will display "<full>
(<abbrv>)". On subsequent uses only the abbreviation
will be displayed.

The name of the glossary section can be replaced with a


custom name or translated to a dierent language. Add
the option title to \printglossary to specify the glossarys
title. Add the option toctitle to specify a the title used in
the table of content (if not used, title is used as default).
[4]

To reset the rst use of an acronym use:


or, if you want to reset the use status of all acronyms:
If you just want to print the long version of an acronym
without the abbreviation "<full>", use :

Remove the point

To omit the dot at the end of each description, use this


If you just want to print the long version of an acronym code:
with the abbreviation "<full> (<abbrv>)", use :
If you just want to print the abbreviation "<abbrv>", use
Changing Glossary Entry Presentation Using Glos:
sary Styles

5.3 Displaying the Glossary

A number of pre-built styles are available, and can be


changed easily using
Commonly used styles include list

To display the sorted list of terms you need to add:

My Term Has some long description 7, 9


at the place you want the glossary and the list of acronyms
altlist (inserts newline after term and indents description)
to appear.
My Term Has some long description 7, 9
If all entries are to be printed the command
altlistgroup or listgroup (group adds grouping based on
can be inserted before \printglossaries. You may also
the rst letters of the terms)
want to use \usepackage[nonumberlist]{glossaries} to
M My First Term Has some long description 7, 9 My
suppress the location list within the glossary.
Second Term Has some long description 7, 9
Separate Glossary and List of Acronyms

altlisthypergroup or listhypergroup (hyper adds an hyperlinked 'index' at the top of each glossary to jump to a
group)

\printglossaries will display all the glossaries in the order


in which they were dened.[2] If no custom glossaries are A|B|C|D|F|G|I|M|O|R|S|C|D|G|M|P A A First term Has
dened, the default glossary and the list of acronyms will some long description 7, 9 B Barely missed rst Has
some long description 7, 9
be displayed.
The glossary and the list of acronyms can be displayed
separately in dierent places[3] :

5.3.1 Building your document

Dual entries with reference to a glosssary entry from Building your document and its glossary requires three
an ancronym It may be useful to have both an acronym steps:
and a glossary entry for the same term. To link these two,
1. build your LaTeX document this will also generdene the acronym with a reference to the glossary entry
ate the les needed by makeglossaries
like this:
Refer to acronym with \gls{OWD} and the glossary with
\gls{gls-OWD}
To make this easier, we can use this command (modied
from example in the ocial docs):

2. invoke makeglossaries a script which selects the


correct character encodings and language settings
and which will also run xindy or makeindex if these
are specied in your document le

5.4. EXAMPLE FOR USE IN WINDOWS WITH TEXMAKER


3. build your LaTeX document again to produce a
document with glossary entries
Thus:

113

5.4.2 Document preamble


In preample should be included (note, hyperref should
be loaded before the glossaries):

\usepackage[nomain,acronym,xindy,toc]{glossaries} %
nomain, if you dene glossaries in a le, and you
where latex is your usual build call (perhaps pdatex) and use \include{INP-00-glossary} \makeglossaries \usepadoc is the name of your LaTeX master le.
ckage[xindy]{imakeidx} \makeindex
latex doc makeglossaries doc latex doc

If your entries are interlinked (entries themselves link to


other entries with \gls calls), you will need to run steps 1
5.4.3
and 2 twice, that is, in the following order: 1, 2, 1, 2, 3.

Glossary denitions

If you encounter problems, view the [Link] and [Link] Write all your glossaries/acronyms in a le: Ex: INP-00les in a text editor for clues.
[Link]

\newacronym{ddye}{D$_{\text{dye}}$}{donor
dye,
ex.
Alexa
488}
\newacronym[description={\glslink{r0}{F\"{o}rster
5.4 Example for use in windows
distance}}]{R0}{$R_{0}$}{F\"{o}rster
with Texmaker
distance}
\newglossaryentry{r0}{name=\glslink{R0}{\ensuremath{R_{0}}},text=F\"{o}rster
distance,
5.4.1 Compile glossary with xindy - In distance,description={F\"{o}rster
where
50\%
...},
sort=R}
\newglossaryenWindows with Texmaker
try{kdeac}{name=\glslink{R0}{\ensuremath{k_{DEAC}}},text=$k_{DE
In TeX Live xindy is already included, but users of MiK- description={is the rate of deactivation from ... and
TeX need rst do download and install xindy for Win- emission)}, sort=k}
dows.
There are two approaches:
The easy one.

This install program includes the Perl interpreter for


makeglossaries, and of course xindy for sorting, and also
adds the binaries to your windows PATH:
Download xindy, and install (original source here). But
note: This installs deprecated versions of them all!
The more dicult one.

5.4.4 Include glossary denitions and print


glossary
Include glossary denitions in the preamble (Before "\begin{document}")
\loadglsentries[main]{INP-00-glossary} % or using
\input: %\input{INP-00-glossary} \begin{document}
Print glossaries, near end
\appendix
\bibliographystyle{plainnat}
\bibliography{bibtex}
\printindex
\printglossaries
\end{document}

5.4.5 References
See description on [Link]: How to use Xindy with MiKTeX? This way you can update yourself if necessary.
You need to restart Texmaker after installation of xindy,
to update PATH references to xindy and Perl binaries.
Then, in Texmaker, go to User -> User Commands ->
Edit User Commands.
Choose command 1

1. Menuitem = makeglossaries
2. Command = makeglossaries %
Now push Alt+Shift+F1and then ->F1

[1] [Link]
[2] [Link]
contrib/glossaries/[Link]#dx1-35001
[3] [Link]
contrib/glossaries/[Link]#dx1-43001
[4] User Manual for [Link] v4.02 as of 2014.01.13
[Link]
contrib/glossaries/[Link]#sec:printglossary

The glossaries documentation, [Link]


tex-archive/macros/latex/contrib/glossaries/
Using LaTeX to Write a PhD Thesis, Nicola L.C. Talbot,

114

CHAPTER 5. SPECIAL PAGES

glossaries FAQ, Nicola L. C. Talbot, glossaries FAQ OK, so what is going on here? The rst thing to notice is
the establishment of the environment. thebibliography is
a keyword that LaTeX recognizes as everything between
Glossaries, Nomenclature, Lists of Symbols and
the begin and end tags as being data for the bibliograAcronyms, Nicola L. C. Talbot, link
phy. The mandatory argument, which I supplied after
the begin statement, is telling LaTeX how wide the item
label will be when printed. Note however, that the num5.5 LaTeX/Bibliography Manage- ber itself is not the parameter, but the number of digits is.
Therefore, I am eectively telling LaTeX that I will only
ment
need reference labels of one character in length, which ultimately means no more than nine references in total. If
For any academic/research writing, incorporating ref- you want more than nine, then input any two-digit numerences into a document is an important task. Fortu- ber, such as '56' which allows up to 99 references.
nately, LaTeX has a variety of features that make dealing Next is the actual reference entry itself. This is prewith references much simpler, including built-in support xed with the \bibitem{cite_key} command. The cite_key
for citing references. However, a much more powerful should be a unique identier for that particular reference,
and exible solution is achieved thanks to an auxiliary and is often some sort of mnemonic consisting of any setool called BibTeX (which comes bundled as standard quence of letters, numbers and punctuation symbols (alwith LaTeX). Recently, BibTeX has been succeeded by though not a comma). I often use the surname of the rst
BibLaTeX, a tool congurable within LaTeX syntax.
author, followed by the last two digits of the year (hence
BibTeX provides for the storage of all references in an
external, at-le database. (BibLaTeX uses this same
syntax.) This database can be referenced in any LaTeX document, and citations made to any record that is
contained within the le. This is often more convenient
than embedding them at the end of every document written; a centralized bibliography source can be linked to as
many documents as desired (write once, read many!). Of
course, bibliographies can be split over as many les as
one wishes, so there can be a le containing sources concerning topic A ([Link]) and another concerning topic B
([Link]). When writing about topic AB, both of these les
can be linked into the document (perhaps in addition to
sources [Link] specic to topic AB).

5.5.1

Embedded system

If you are writing only one or two documents and aren't


planning on writing more on the same subject for a
long time, you might not want to waste time creating a
database of references you are never going to use. In this
case you should consider using the basic and simple bibliography support that is embedded within LaTeX.

lamport94). If that author has produced more than one


reference for a given year, then I add letters after, 'a', 'b',
etc. But, you should do whatever works for you. Everything after the key is the reference itself. You need to
type it as you want it to be presented. I have put the different parts of the reference, such as author, title, etc.,
on dierent lines for readability. These linebreaks are ignored by LaTeX. I wanted the title to be in italics, so I
used the \emph{} command to achieve this.

5.5.2 Citations
To actually cite a given document is very easy. Go to
the point where you want the citation to appear, and use
the following: \cite{cite_key}, where the cite_key is that
of the bibitem you wish to cite. When LaTeX processes
the document, the citation will be cross-referenced with
the bibitems and replaced with the appropriate number
citation. The advantage here, once again, is that LaTeX
looks after the numbering for you. If it were totally manual, then adding or removing a reference would be a real
chore, as you would have to re-number all the citations by
hand.

LaTeX provides an environment called thebibliography Instead of WYSIWYG editors, typesetting systems like
that you have to use where you want the bibliography; \TeX{} or \LaTeX{} \cite{lamport94} can be used.
that usually means at the very end of your document, just
before the \end{document} command. Here is a practical
Referring more specic
example:
\begin{thebibliography}{9}
\bibitem{lamport94}
Leslie Lamport,
\emph{\LaTeX: a document preparation system}.
Addison Wesley, Massachusetts,
2nd edition,
1994.
\end{thebibliography}

Sometimes you want to refer to a certain page, gure or


theorem in a text book. For that you can use the arguments to the \cite command:
\cite[p.~215]{citation01}
The argument, p. 215, will show up inside the same
brackets. Note the tilde in [p.~215], which replaces the
end-of-sentence spacing with a non-breakable inter-word

5.5. LATEX/BIBLIOGRAPHY MANAGEMENT

115

space. There are two reasons: end-of-sentence spacing is mind that for instance abbrvnat does not support \citet*
too wide, and p. should not be separated from the page and will automatically choose between all authors and et
number.
al..
The nal area that I wish to cover about Natbib is customizing its citation style. There is a command called
Multiple citations
\bibpunct that can be used to override the defaults and
When a sequence of multiple citations are needed, you change certain settings. For example, I have put the folshould use a single \cite{} command. The citations are lowing in the preamble:
then separated by commas. Note that you must not use \bibpunct{(}{)}{;}{a}{,}{,}
spaces between the citations. Heres an example:
The command requires six mandatory parameters.
\cite{citation01,citation02,citation03}
The result will then be shown as citations inside the same
brackets.

2. The symbol for the closing bracket.


3. The symbol that appears between multiple citations.

No cite
If you only want a reference to appear in the bibliography,
but not where it is referenced in the main text, then the
\nocite{} command can be used, for example:
Lamport
showed
\nocite{lamport95}.

1. The symbol for the opening bracket.

in

1995

something...

A special version of the command, \nocite{*}, includes


all entries from the database, whether they are referenced
in the document or not.
Natbib
Using the standard LaTeX bibliography support, you will
see that each reference is numbered and each citation corresponds to the numbers. The numeric style of citation is
quite common in scientic writing. In other disciplines,
the author-year style, e.g., (Roberts, 2003), such as Harvard is preferred. A discussion about which is best will
not occur here, but a possible way to get such an output
is by the natbib package. In fact, it can supersede LaTeXs own citation commands, as Natbib allows the user
to easily switch between Harvard or numeric.

4. This argument takes a letter:


n - numerical style.
s - numerical superscript style.
any other letter - author-year style.
5. The punctuation to appear between the author and
the year (in parenthetical case only).
6. The punctuation used between years, in multiple citations when there is a common author. e.g., (Chomsky 1956, 1957). If you want an extra space, then
you need {,~}.
Some of the options controlled by \bibpunct are also accessible by passing options to the natbib package when it
is loaded. These options also allow some other aspect of
the bibliography to be controlled, and can be seen in the
table (right).

So as you can see, this package is quite exible, especially


as you can easily switch between dierent citation styles
by changing a single parameter. Do have a look at the
Natbib manual, its a short document and you can learn
The rst job is to add the following to your preamble in even more about how to use it.
order to get LaTeX to use the Natbib package:
\usepackage[options]{natbib}
Also, you need to change the bibliography style le to
be used, so edit the appropriate line at the bottom of the
le so that it reads: \bibliographystyle{plainnat}. Once
done, it is basically a matter of altering the existing \cite
commands to display the type of citation you want.

5.5.3 BibTeX

I have previously introduced the idea of embedding references at the end of the document, and then using the
\cite command to cite them within the text. In this tutorial, I want to do a little better than this method, as its
not as exible as it could be. I will concentrate on using
The main commands simply add a t for 'textual' or p for BibTeX.
'parenthesized', to the basic \cite command. You will also
notice how Natbib by default will compress references A BibTeX database is stored as a .bib le. It is a plain text
with three or more authors to the more concise 1st sur- le, and so can be viewed and edited easily. The structure
name et al version. By adding an asterisk (*), you can of the le is also quite simple. An example of a BibTeX
override this default and list all authors associated with entry:
that citation. There are some other specialized commands @article{greenwade93, author = George D. Greenthat Natbib supports, listed in the table here. Keep in wade, title = The {C}omprehensive {T}ex {A}rchive

116

CHAPTER 5. SPECIAL PAGES

{N}etwork ({CTAN})", year = 1993, journal = Authors


TUGBoat, volume = 14, number = 3, pages =
BibTeX can be quite clever with names of authors. It
342-351 }
can accept names in forename surname or surname, forename. I personally use the former, but remember that
Each entry begins with the declaration of the reference
the order you input them (or any data within an entry for
type, in the form of @type. BibTeX knows of practically
that matter) is customizable and so you can get BibTeX
all types you can think of, common ones are: book, artito manipulate the input and then output it however you
cle, and for papers presented at conferences, there is inlike. If you use the forename surname method, then you
proceedings. In this example, I have referred to an article
must be careful with a few special names, where there
within a journal.
are compound surnames, for example John von NeuAfter the type, you must have a left curly brace '{' to sig- mann. In this form, BibTeX assumes that the last word
nify the beginning of the reference attributes. The rst is the surname, and everything before is the forename,
one follows immediately after the brace, which is the ci- plus any middle names. You must therefore manually tell
tation key, or the BibTeX key. This key must be unique BibTeX to keep the 'von' and 'Neumann' together. This
for all entries in your bibliography. It is this identier that is achieved easily using curly braces. So the nal result
you will use within your document to cross-reference it to would be John {von Neumann}". This is easily avoided
this entry. It is up to you as to how you wish to label each with the surname, forename, since you have a comma to
reference, but there is a loose standard in which you use separate the surname from the forename.
the authors surname, followed by the year of publication.
Secondly, there is the issue of how to tell BibTeX when a
This is the scheme that I use in this tutorial.
reference has more than one author. This is very simply
Next, it should be clear that what follows are the rele- done by putting the keyword and in between every author.
vant elds and data for that particular reference. The As we can see from another example:
eld names on the left are BibTeX keywords. They are
@book{goossens93, author = Michel Goossens and
followed by an equals sign (=) where the value for that
Frank Mittelbach and Alexander Samarin, title =
eld is then placed. BibTeX expects you to explicitly laThe LaTeX Companion, year = 1993, publisher =
bel the beginning and end of each value. I personally use
Addison-Wesley, address = Reading, Massachusetts
quotation marks ("), however, you also have the option
}
of using curly braces ('{', '}'). But as you will soon see,
curly braces have other roles, within attributes, so I prefer
not to use them for this job as they can get more confus- This book has three authors, and each is separated as deing. A notable exception is when you want to use char- scribed. Of course, when BibTeX processes and outputs
acters with umlauts (, , etc), since their notation is in this, there will only be an 'and' between the penultimate
the format \"{o}, and the quotation mark will close the and last authors, but within the .bib le, it needs the ands
one opening the eld, causing an error in the parsing of so that it can keep track of the individual authors.
the reference. Using \usepackage[utf8]{inputenc} in the
preamble to the .tex source le can get round this, as the
accented characters can just be stored in the .bib le with- Standard templates
out any need for special markup. This allows a consistent
Be careful if you copy the following templates, the % sign
format to be kept throughout the .bib le, avoiding the
is not valid to comment out lines in bibtex les. If you
need to use braces when there are umlauts to consider.
want to comment out a line, you have to put it outside the
Remember that each attribute must be followed by a entry.
comma to delimit one from another. You do not need to
add a comma to the last attribute, since the closing brace @article An article from a magazine or a journal.
will tell BibTeX that there are no more attributes for this
Required elds: author, title, journal, year.
entry, although you won't get an error if you do.
Optional elds: volume, number, pages,
It can take a while to learn what the reference types are,
month, note.
and what elds each type has available (and which ones
are required or optional, etc). So, look at this entry type
reference and also this eld reference for descriptions of @article{Xarticle, author = "", title = "", journal = "",
all the elds. It may be worth bookmarking or printing %volume = "", %number = "", %pages = "", year =
these pages so that they are easily at hand when you need XXXX, %month = "", %note = "", }
them. Much of the information contained therein is repeated in the following table for your convenience.
@book A published book
+ Required elds, O Optional elds
Required elds: author/editor, title, publisher,
year.

5.5. LATEX/BIBLIOGRAPHY MANAGEMENT

117

Optional elds: volume/number, series, ad- @inproceedings An article in a conference proceeddress, edition, month, note.
ings.
@book{Xbook, author = "", title = "", publisher = "",
%volume = "", %number = "", %series = "", %address =
"", %edition = "", year = XXXX, %month = "", %note
= "", }

Required elds: author, title, booktitle, year.


Optional elds: editor, volume/number, series, pages, address, month, organization, publisher, note.

@inproceedings{Xinproceedings, author = "", title


@booklet A bound work without a named publisher or = "", booktitle = "", %editor = "", %volume = "",
sponsor.
%number = "", %series = "", %pages = "", %address
= "", %organization = "", %publisher = "", year = "",
Required elds: title.
Optional elds: author, howpublished, ad- %month = "", %note = "", }
dress, month, year, note.
@booklet{Xbooklet, %author = "", title = "", %howpub- @manual Technical manual
lished = "", %address = "", year = XXXX, %month =
Required elds: title.
"", %note = "", }
Optional elds: author, organization, address,
edition, month, year, note.
@conference Equal to inproceedings
@manual{Xmanual, title = "", %author = "", %organi Required elds: author, title, booktitle, year.
zation = "", %address = "", %edition = "", year = "",
Optional elds: editor, volume/number, se- %month = "", %note = "", }
ries, pages, address, month, organization, publisher, note.
@conference{Xconference, author = "", title = "",
booktitle = "", %editor = "", %volume = "", %number
= "", %series = "", %pages = "", %address = "", year
= XXXX, %month = "", %publisher= "", %note = "", }

@mastersthesis Masters thesis


Required elds: author, title, school, year.
Optional elds: type (eg. diploma thesis),
address, month, note.

@mastersthesis{Xthesis, author = "", title = "", school


= "", %type = diploma thesis, %address = "", year =
Required elds: author/editor, title, chapter XXXX, %month = "", %note = "", }
and/or pages, publisher, year.
Optional elds: volume/number, series, type,
address, edition, month, note.
@misc Template useful for other kinds of publication

@inbook A section of a book without its own title.

@inbook{Xinbook, author = "", editor = "", title = "",


chapter = "", pages = "", publisher= "", %volume = "",
%number = "", %series = "", %type = "", %address= "",
%edition= "", year = "", %month = "", %note = "", }
@incollection A section of a book having its own title.

Required elds: none


Optional elds: author, title, howpublished,
month, year, note.
@misc{Xmisc, %author = "", %title = "", %howpublished = "", %year = XXXX, %month = "", %note =
"", }

Required elds: author, title, booktitle, publisher, year.


Optional elds: editor, volume/number, se- @phdthesis Ph.D. thesis
ries, type, chapter, pages, address, edition,
Required elds: author, title, year, school.
month, note.
Optional elds: address, month, keywords,
note.
@incollection{Xincollection, author = "", title = "",
booktitle= "", publisher= "", %editor = "", %volume =
"", %number = "", %series = "", %type = "", %chapter= @phdthesis{Xphdthesis, author = "", title = "", school =
"", %pages = "", %address= "", %edition= "", year = "", "", %address = "", year = "", %month = "", %keywords
= "", %note = "", }
%month = "", %note = "", }

118

CHAPTER 5. SPECIAL PAGES

@proceedings The proceedings of a conference.

title = The {LaTeX} Companion,

Required elds: title, year.

However, avoid putting the whole title in curly braces, as


Optional elds: editor, volume/number, se- it will look odd if a dierent capitalization format is used:
ries, address, month, organization, publisher,
note.
title = "{The LaTeX Companion}",
@proceedings{Xproceedings, title = "", %editor = "",
%volume = "", %number = "", %series = "", %address
= "", %organization = "", %publisher = "", year = "",
%month = "", %note = "", }

@techreport Technical report from educational, commercial or standardization institution.

For convenience though, many people simply put double


curly braces, which may help when writing scientic articles for dierent magazines, conferences with dierent
BibTex styles that do sometimes keep and sometimes not
keep the capital letters:
title = {{The LaTeX Companion}},

As an alternative, try other BibTex styles or modify the


existing. The approach of putting only relevant text in
Optional elds: type, number, address, month, curly brackets is the most feasible if using a template unnote.
der the control of a publisher, such as for journal submissions. Using curly braces around single letters is also to
@techreport{Xtreport, author = "", title = "", institution be avoided if possible, as it may mess up the kerning, es= "", %type = "", %number = "", %address = "", year = pecially with biblatex,[1] so the rst step should generally
XXXX, %month = "", %note = "", }
be to enclose single words in braces.
Required elds: author, title, institution, year.

@unpublished An unpublished article, book, thesis, A few additional examples


etc.
Below you will nd a few additional examples of bibliog Required elds: author, title, note.
raphy entries. The rst one covers the case of multiple
Optional elds: month, year.
authors in the Surname, Firstname format, and the second one deals with the incollection case.
@unpublished{Xunpublished, author = "", title = "",
@article{AbedonHymanThomas2003,
%year = "", %month = "", note = "", }
author = Abedon, S. T. and Hyman, P. and Thomas, C.,
year = 2003,
title = Experimental examination of bacteriophage
latent-period evolution as a response to bacterial availNot standard templates
ability,
@patent BiBTeX entries can be exported from Google journal = Applied and Environmental Microbiology,
Patents.
volume = 69,
pages = 7499-7506
(see Cite Patents with Bibtex for an alternative)
},
@incollection{Abedon1994,
@collection
author = Abedon, S. T.,
title = Lysis and the interaction between free phages and
@electronic
infected cells,
pages = 397-405,
booktitle = Molecular biology of bacteriophage T4,
Preserving case of letters
editor = Karam, Jim D. Karam and Drake, John W. and
In the event that BibTeX has been set by the chosen style Kreuzer, Kenneth N. and Mosig, Gisela
to not preserve all capitalization within titles, problems and Hall, Dwight and Eiserling, Frederick A. and Black,
can occur, especially if you are referring to proper nouns, Lindsay W. and Kutter, Elizabeth
or acronyms. To tell BibTeX to keep them, use the good and Carlson, Karin and Miller, Eric S. and Spicer,
old curly braces around the letter in question, (or letters, Eleanor,
if its an acronym) and all will be well! It is even possible publisher = ASM Press, Washington DC,
that lower-case letters may need to be preserved - for ex- year = 1994
ample if a chemical formula is used in a style that sets a },
title in all caps or small caps, or if pH is to be used is a If you have to cite a website you can use @misc, for exstyle that capitalises all rst letters.
ample:

5.5. LATEX/BIBLIOGRAPHY MANAGEMENT


@misc{website:fermentas-lambda,
author = Fermentas Inc.,
title = Phage Lambda: description \& restriction map,
month = November,
year = 2008,
url = "[Link]
[Link]"
},

119
than one reference at the same time, do the following:
\cite{ref_key1, ref_key2, ..., ref_keyN}.
Why won't LaTeX generate any output?

The addition of BibTeX adds extra complexity for the


processing of the source to the desired output. This is
largely hidden to the user, but because of all the comThe note eld comes in handy if you need to add unstrucplexity of the referencing of citations from your source
tured information, for example that the corresponding isLaTeX le to the database entries in another le, you acsue of the journal has yet to appear:
tually need multiple passes to accomplish the task. This
@article{blackholes,
means you have to run LaTeX a number of times. Each
author="Rabbert Klein,
pass will perform a particular task until it has managed to
title="Black Holes and Their Relation to Hiding Eggs,
resolve all the citation references. Heres what you need
journal="Theoretical Easter Physics,
to type (into command line):
publisher="Eggs Ltd.,
year="2010,
1. latex latex_source_code.tex
note="(to appear)"
}
2. bibtex latex_source_code.aux
3. latex latex_source_code.tex
Getting current LaTeX document to use your .bib le
4. latex latex_source_code.tex
At the end of your LaTeX le (that is, after the content,
but before \end{document}), you need to place the fol- (Extensions are optional, if you put them note that the
lowing commands:
bibtex command takes the AUX le as input.)
\bibliographystyle{plain}
After the rst LaTeX run, you will see errors such as:
\bibliography{sample1,sample2,...,samplen}
% Note the lack of whitespace between the commas and LaTeX Warning: Citation `lamport94' on page 1 undened on input line 21. ... LaTeX Warning: There were
the next bib le.
undened references.
Bibliography styles are les recognized by BibTeX that
tell it how to format the information stored in the .bib le The next step is to run bibtex on that same LaTeX source
when processed for output. And so the rst command (or more precisely the corresponding AUX le, however
listed above is declaring which style le to use. The style not on the actual .bib le) to then dene all the references
le in this instance is [Link] (which comes as standard within that document. You should see output like the folwith BibTeX). You do not need to add the .bst extension lowing:
when using this command, as it is assumed. Despite its This is BibTeX, Version 0.99c (Web2C 7.3.1) The topname, the plain style does a pretty good job (look at the level auxiliary le: latex_source_code.aux The style le:
output of this tutorial to see what I mean).
[Link] Database le #1: [Link]
The second command is the one that actually species
the .bib le you wish to use. The ones I created for this
tutorial were called [Link], [Link], . . ., [Link], but once again, you don't include the le extension. At the moment, the .bib le is in the same directory as the LaTeX document too. However, if your
.bib le was elsewhere (which makes sense if you intend to maintain a centralized database of references
for all your research), you need to specify the path as
well, e.g \bibliography{/some/where/sample} or \bibliography{../sample1} (if the .bib le is in the parent directory of the .tex document that calls it).
Now that LaTeX and BibTeX know where to look for the
appropriate les, actually citing the references is fairly
trivial. The \cite{ref_key} is the command you need,
making sure that the ref_key corresponds exactly to one
of the entries in the .bib le. If you wish to cite more

The third step, which is invoking LaTeX for the second


time will see more errors like LaTeX Warning: Label(s)
may have changed. Rerun to get cross-references right..
Don't be alarmed, its almost complete. As you can guess,
all you have to do is follow its instructions, and run LaTeX
for the third time, and the document will be output as
expected, without further problems.
If you want a pdf output instead of a dvi output you can
use pdatex instead of latex as follows:
1. pdatex latex_source_code.tex
2. bibtex latex_source_code.aux
3. pdatex latex_source_code.tex
4. pdatex latex_source_code.tex

120

CHAPTER 5. SPECIAL PAGES

(Extensions are optional, if you put them note that the


bibtex command takes the AUX le as input.)
Note that if you are editing your source in vim and attempt to use command mode and the current le shortcut
(%) to process the document like this:
1. :! pdatex %

plain

2. :! bibtex %
You will get an error similar to this:
1. I couldn't open le name 'current_le.[Link]'
It appears that the le extension is included by default
when the current le command (%) is executed. To process your document from within vim, you must explicitly abbrv
name the le without the le extension for bibtex to work,
as is shown below:
1. :! pdatex %
2. :! bibtex %:r (without le extension, it looks for the
AUX le as mentioned above)
3. :! pdatex %
4. :! pdatex %

alpha

However, it is much easier to install the Vim-LaTeX plu Overview of Bibtex-Styles: Filterable list of styles
gin from here. This allows you to simply type \ll when
with preview.
not in insert mode, and all the appropriate commands are
automatically executed to compile the document. Vim Preview of several often used styles
LaTeX even detects how many times it has to run pdatex, and whether or not it has to run bibtex. This is just
one of the many nice features of Vim-LaTeX, you can
read the excellent Beginners Tutorial for more about the
Including URLs in bibliography
many clever shortcuts Vim-LaTeX provides.
Another option exists if you are running Unix/Linux or
any other platform where you have make. Then you can
simply create a Makele and use vims make command
or use make in shell. The Makele would then look like
this:

As you can see, there is no eld for URLs. One possibility


is to include Internet addresses in howpublished eld of
@misc or note eld of @techreport, @article, @book:

latex_source_code.pdf:
latex_source_code.tex latex_source_code.bib pdatex latex_source_code.tex
bibtex
latex_source_code.aux
pdatex
latex_source_code.tex pdatex latex_source_code.tex

Note the usage of \url command to ensure proper appearance of URLs.

howpublished = "\url{[Link]

Another way is to use special eld url and make bibliography style recognise it.
url = "[Link]

Bibliography styles

You need to use \usepackage{url} in the rst case or


\usepackage{hyperref} in the second case.

Below you can see three of the styles available with LaStyles provided by Natbib (see below) handle this eld,
TeX:
other styles can be modied using urlbst program. ModiHere are some more often used styles:
cations of three standard styles (plain, abbrv and alpha)
However, keep in mind that you will need to use the nat- are provided with urlbst.
bib package to use most of these.
If you need more help about URLs in bibliography, visit
More examples can be found here:

FAQ of UK List of TeX.

5.5. LATEX/BIBLIOGRAPHY MANAGEMENT


Customizing bibliography appearance

121
Localizing bibliography appearance

When writing documents in languages other than English,


you may nd it desirable to adapt the appearance of your
bibliography to the document language. This concerns
words such as editors, and, or in as well as a proper typographic layout. The babelbib package can be used here.
One of the main advantages of BibTeX, especially for For example, to layout the bibliography in German, add
people who write many research papers, is the ability to the following to the header:
customize your bibliography to suit the requirements of
a given publication. You will notice how dierent pub- \usepackage[xlanguage]{babelbib}
lications tend to have their own style of formatting ref- \selectbiblanguage{german}
erences, to which authors must adhere if they want their Alternatively, you can layout each bibliography entry acmanuscripts published. In fact, established journals and cording to the language of the cited document:
conference organizers often will have created their own
bibliography style (.bst le) for those users of BibTeX, to \usepackage{babelbib}
do all the hard work for you.
The language of an entry is specied as an additional eld
It can achieve this because of the nature of the .bib in the BibTeX entry:
database, where all the information about your references @article{mueller08, % ... language = {german} }
is stored in a structured format, but nothing about style.
This is a common theme in LaTeX in general, where it
For babelbib to take eect, a bibliography style supported
tries as much as possible to keep content and presentaby it - one of babplain, babplai3, babalpha, babunsrt,
tion separate.
bababbrv, and bababbr3 - must be used:
A bibliography style le (.bst) will tell LaTeX how to for\bibliographystyle{babplain}
mat each attribute, what order to put them in, what punc\bibliography{sample}
tuation to use in between particular attributes etc. Unfortunately, creating such a style by hand is not a trivial task.
Which is why Makebst (also known as custom-bib) is the Showing unused items
tool we need.
Usually LaTeX only displays the entries which are reMakebst can be used to automatically generate a .bst le
ferred to with \cite. Its possible to make uncited entries
based on your needs. It is very simple, and actually asks
visible:
you a series of questions about your preferences. Once
complete, it will then output the appropriate style le for \nocite{Name89} % Show Bibliography entry of
Name89
you to use.
\nocite{*} % Show all Bib-entries
It should be installed with the LaTeX distribution (otherwise, you can download it) and its very simple to initiate.
At the command line, type:
Getting bibliographic data
latex makebst
LaTeX will nd the relevant le and the questioning process will begin. You will have to answer quite a few (although, note that the default answers are pretty sensible),
which means it would be impractical to go through an
example in this tutorial. However, it is fairly straightforward. And if you require further guidance, then there
is a comprehensive manual available. I'd recommend experimenting with it and seeing what the results are when
applied to a LaTeX document.

Many online databases provide bibliographic data in


BibTeX-Format, making it easy to build your own
database. For example, Google Scholar oers the option to return properly formatted output, which can also
be turned on in the settings page.
One should be alert to the fact that bibliographic
databases are frequently the product of several generations of automatic processing, and so the resulting BibTex code is prone to a variety of minor errors, especially
in older entries.

If you are using a custom built .bst le, it is important


that LaTeX can nd it! So, make sure its in the same
directory as the LaTeX source le, unless you are using Helpful tools
one of the standard style les (such as plain or plainnat,
that come bundled with LaTeX - these will be automatically found in the directories that they are installed. Also,
Mendeley Mendeley is cost-free academic software
make sure the name of the .bst le you want to use is
for managing PDFs which can manage a bibliograreected in the \bibliographystyle{style} command (but
phy in Open Oce and read BibTeX.
don't include the .bst extension!).

122

CHAPTER 5. SPECIAL PAGES


erate a BibTeX bibliography le.
Citavi Commercial software (with size-limited free
demo version) which even searches libraries for citations and keeps all your knowledge in a database.
Export of the database to all kinds of formats is
possible. Works together with MS Word and Open
Oce Writer. Moreover plug ins for browsers and
Acrobat Reader exist to automatically include references to your project.

Literatur-Generator

cb2Bib The cb2Bib is a tool for rapidly extracting


unformatted, or unstandardized bibliographic references from email alerts, journal Web pages, and
PDF les.
KBibTeX KBibTeX is a BibTeX editor for KDE to
edit bibliographies used with LaTeX. Features include comfortable input masks, starting web queries
(e. g. Google or PubMed) and exporting to PDF,
PostScript, RTF and XML/HTML. As KBibTeX is
using KDEs KParts technology, KBibTeX can be
embedded into Kile or Konqueror.

JabRef

KBib Another BibTeX editor for KDE. It has similar capabilities, and slightly dierent UI. Features
include BibTeX reference generation from PDF
les, plain text, DOI, arXiv & PubMed IDs. Web
queries to Google Scholar, PubMer, arXiv and a
number of other services are also supported.
Bibwiki Bibwiki is a Specialpage for MediaWiki to
manage BibTeX bibliographies. It oers a straightforward way to import and export bibliographic
records.
BibDesk BibDesk is a bibliographic reference manager for Mac OS X. It features a very usable user interface and provides a number of features like smart
folders based on keywords and live tex display.

BibDesk

Zotero Zotero is a free and open reference manager


working as a Firefox plugin or standalone application, capable of importing and exporting bib les.
JabRef is a Java program (under the GPL license)
which lets you search many bibliographic databases
such as Medline, Citeseer, IEEEXplore and arXiv
and feed and manage your BibTeX local databases
with your selected articles. Based on BiBTeX,
JabRef can export in many other output formats
such as html, MS Word or EndNote. It can be
used online without being installed ([Link]
[Link]/jws/[Link])
Referencer Referencer is a Gnome application to organise documents or references, and ultimately gen-

CiteULike CiteULike is a free online service to organise academic papers. It can export citations in
BibTeX format, and can scrape BibTeX data from
many popular websites.
Bibtex Bibtex is a DokuWiki plugin that allows
for the inclusion of bibtex formatted citations in
DokuWiki pages and displays them in APA format.
Note: This Plugins is vulnerable to an XSS attack ->
[Link]
BibSonomy A free social bookmark and publication management system based on BibTeX.
Synapsen Hypertextual Card Index / Reference
Manager with special support for BiBTeX / biblatex,
written in Java.
Ebib a BibTeX database manager for Emacs, well
resolved and never more than a few keystrokes away.

5.5. LATEX/BIBLIOGRAPHY MANAGEMENT

123

Literatur-Generator is a German-language online This will include the Bibliography in the Table of Contool for creating a bibliography (Bibtex, Endnote, tents without numbering. If you want to have proper
Din 1505, ...).
numbering, include the following code in the preamble:
\usepackage[nottoc,numbib]{tocbibind}
Bibtex Editor - An online BibTeX entry generator
and bibliography management system. Possible to The tocbibind package can also handle including the List
of Figures, List of Tables and the Table of Contents itself
import and export Bibtex les.
in the Table of Contents. It has many options for numbering, document structure etc. to t almost any scenario.
See the tocbibind CTAN page for detailed documentaSummary
tion.
Although it can take a little time to get to grips with BibTeX, in the long term, its an ecient way to handle your
references. Its not uncommon to nd .bib les on web- Other methods
sites that people compile as a list of their own publications, or a survey of relevant works within a given topic, As unnumbered item If you want your bibliography
etc. Or in those huge, online bibliography databases, you to be in the table of contents, just add the following two
often nd BibTeX versions of publications, so its a quick lines just before the thebibliography environment:
cut-and-paste into your own .bib le, and then no more \clearpage
hassle!
\addcontentsline{toc}{chapter}{Bibliography}
Having all your references in one place can be a big ad- (OR \addcontentsline{toc}{section}{Bibliography} if
vantage. And having them in a structured form, that al- you're writing an article)
lows customizable output is another one. There are a variety of free utilities that can load your .bib les, and allow The rst line just terminates the current paragraph and
you to view them in a more ecient manner, as well as page. If you are writing a book, use \cleardoublepage to
match the style used. The second line will add a line in
sort them and check for errors.
the Table of Contents (rst option, toc), it will be like the
ones created by chapters (second option, chapter), and
5.5.4 Bibliography in the table of contents the third argument will be printed on the corresponding
line in the Table of Contents; here Bibliography was chosen because its the same text the thebibliography environIf you are writing a book or report, you'll likely insert your
ment will automatically write when you use it, but you are
bibliography using something like:
free to write whatever you like. If you are using separate
\begin{thebibliography}{99}
bib le, add these lines between \bibliographystyle and
\bibitem{bib:one_book} some information
\bibliography.
\bibitem{bib:one_article} other information
If you use hyperref package, you should also use \phan\end{thebibliography}
tomsection command to enable hyperlinking from the taOr, if you are using BibTeX, your references will be saved ble of contents to bibliography.
in a .bib le, and your TeX document will include the
\cleardoublepage
bibliography by these commands:
\phantomsection
\bibliographystyle{plain}
\addcontentsline{toc}{chapter}{Bibliography}
\bibliography{mybibtexle}
This trick is particularly useful when you have to insert
Both of these examples will create a chapter-like (or the bibliography in the Table of Contents, but it can work
section-like) output showing all your references. But even for anything. When LaTeX nds the code above, it will
though the resulting References looks like a chapter or record the info as described and the current page number,
section, it will not be handled quite the same: it will not inserting a new line in the Contents page.
appear in the Table of Contents.

Using tocbibind
The most comfortable way of adding your bibliography
to the table of contents is to use the dedicated package tocbibind that works with many standard document
classes. Simply include this code in the preamble of your
document:
\usepackage[nottoc]{tocbibind}

As numbered item If you instead want bibliography


to be numbered section or chapter, you'll likely use this
way:
\cleardoublepage % This is needed if the book class
is used, to place the anchor in the correct page, %
because the bibliography will start on its own page. %
Use \clearpage instead if the document class uses the
oneside argument \renewcommand*{\refname}{} %
This will dene heading of bibliography to be empty, so

124

CHAPTER 5. SPECIAL PAGES

you can... \section{Bibliography} % ...place a normal Some eld types are dened, but the documentation does
section heading before the bibliography entries. \be- not say which entry types they can be used with. This
gin{thebibliography}{99} ... \end{thebibliography}
is either because they depend on another eld being set
to be useful or they can always be used in a user-dened
Another even easier solution is to use \section inside of manner, but will never be used in standard styles:
the \renewcommand block:
\renewcommand{\refname}{\section{Sources}}
%
Using Sources as the title of the section \begin{thebibliography}{99} ... \end{thebibliography}
You
may
wish
to
use
\renewcommand*{\refname}{\vspace*{1em}}
followed by \vspace*{1em} to counteract the extra
space the blank \refname inserts.
Note: Use \bibname instead of \refname if you use
the book or report class.

5.5.5

biblatex

As we said before, biblatex is widely considered the `successor' of BibTeX. Intended as a full replacement for BibTeX, it is more congurable in its output and provides a
multitude of new styles (for output) and elds (for the
database) that can be used in a document. For now, refer
to its comprehensive documentation on CTAN.

abstract, annotation
entrysubtype
le
label
library
nameaddon
origdate, origlocation, origpublisher
origtitle, reprinttitle, indextitle
pagination, bookpagination
shortauthor, shorteditor, shorthand, shorthandintro,
shortjournal, shortseries shorttitle
The only eld that is always mandatory, is title. All entry types also require either date or year and they specify
which of author and editor they expect or whether they
can use both. Some eld types can optionally be used
with any entry type:

Entry and eld types in .bib les

addendum, note

The following table shows most eld types. Some eld


types are lists, either lists of person names, others are
literal lists. A date can either be given in parts or full,
some keys are necessary, page references are provided as
ranges and certain special elds contain verbatim code.
There are many kinds of titles.

language
pubstate
urldate

All physical (print) entry types share further optional eld


Some entry types are hard to distinguish and are treated types:
the same by standard styles:
url, doi
@article is the same as hypothetic *@inperiodical
and therefore encompasses existing @suppperiodical

eprint, eprintclass, eprinttype


Multimedia entry types

@inbook = @bookinbook = @suppbook


@collection = @reference
@mvcollection = @mvreference
@incollection = @suppcollection = @inreference

@artwork
@audio
@image
@movie

@online = @electronic = @www

@music

@report = @techreport

@performance

@thesis = @mastersthesis = @phdthesis

@video

5.6. LATEX/MORE BIBLIOGRAPHIES


@software
and legal entry types
@commentary
@jurisdiction
@legislation
@legal
@letter
@review
@standard

125

5.5.6 Multiple bibliographies


Using multibib
This package is for multiple Bibliographies for dierent
sections in your work. For example, you can generate a
bibliography for each chapter. You can nd information
about the package on CTAN[2]

Using bibtopic
The bibtopic-Package[3] is created to dier the citations
on more les, so that you can divide the bibliography into
more parts.

\documentclass[11pt]{article} \usepackage{bibtopic}
\begin{document}
\bibliographystyle{alpha}
\section{Testing}
Lets
cite
all the books:
The entry types @bibnote, @set and @xdata are special.
\cite{ColBenh:93} and \cite{Munt:93}; and an article: \cite{RouxSmart:95}. File [Link] is used for
this listing: \begin{btSect}{books} \section{References
Printing bibliography
from books} \btPrintCited \end{btSect} Here, the artiPresuming we have dened our references in a le called [Link] is used, and the listing is in plain-format instead
[Link], we add this to biblatex by adding the fol- of the standard alpha. \begin{btSect}[plain]{articles}
lowing to the preamble:
\section{References from articles} \btPrintCited \section{Articles not cited} \btPrintNotCited \end{btSect}
\addbibresource{[Link]}
Just print all entries here with \btPrintAll \begin{btSect}[plain]{internet} \section{References from
Print the bibiography with this macro (usually at the end the internet} \btPrintAll \end{btSect} \end{document}
of the document body):
are dened, but not yet supported (well).

\printbibliography

5.5.7 Notes and references


Printing separate bibliographies We want to separate the bibliography into papers, books and others

[1] The biblatex manual

If the bib entries are located in multiple les we can add


them like this:

[2] [Link]

We can also lter on other elds, such as entrysubtype. If


we dene our online resources like this:

[3] [Link]

we lter with \printbibliography[title={Online re- This page uses material from Andy Roberts Getting to grips
sources}, subtype=inet]
with LaTeX with permission from the author.
Example with prex keys, subheadings and table of
contents As the numbering of the bibliographies are
5.6 LaTeX/More Bibliographies
independent, it can be useful to also separate the bibliographies using prexnumbers such as a, b and c. In addition we add a main heading for the bibliographies and This is a gentle introduction to using some of the bibliography functionality available to LaTeX users beyond
add that to the table of contents.
the BibTeX basics. This introduction won't be discussing
To make Hyperref links point to the correct bibliography how to create new styles or packages but rather how to
section, we also add \phantomsection before printing each use some existing ones. It is worth noting that Harvard,
bibliography
for example, is a citation style. It is associated with an alTo add each of the bibliographies to the table of contents phabetical reference list secondarily ordered on date, but
as sub-sections to the main Bibliography, replace head- the only strictly dened element of Harvard style is the
ing=subbibliography with heading=subbibintoc.
citation in author-date format.

126

5.6.1

CHAPTER 5. SPECIAL PAGES

The example data

\documentclass[]{article} \usepackage[round]{natbib}
\begin{document} Document body text with citations.
The database used for my examples contains just the fol- \bibliographystyle{plainnat}
\bibliography{myrefs}
lowing
\end{document}
@article{Erdos65, title = {Some very hard sums}, journal={Dicult Maths Today}, author={Paul Erd\H{o}s
and Arend Heyting and Luitzen Egbertus Brouwer}, Options Options available with Natbib can be specied
year={1930}, pages={30} }
in the brackets on the \usepackage command. Among
them are:
Clearly some of these options require explanation but that
will be achieved via examples below. For now, we just
note that they can be passed through \usepackage[]{} in
Using [Link] and BibTeX makes it very easy to produce the preamble of your LaTeX le.
some bibliography styles. But author-date styles - for example the often mentioned, never dened Harvard - are
not so easy. Its true that you can download some .bst 5.6.4 Citation
les from CTAN that will handle some variants but using
them is not always straightforward. This guide deals with Basic Citation Commands
Natbib a supplementary package that can access .bib les
and has sophisticated functionality for producing custom To cite with Natbib, use the commands \citet or \citep in
or default author-year format citations and bibliographies your document. The plain versions of these commands
as well as the numerical styles handled by BibTeX.
produced abbreviated lists in the case of multiple authors
but both have * variants which result in full author listings.
We assume the use of the round option in these examples.

5.6.2

The limits of BibTeX styles

5.6.3

Natbib

Natbib is a package created by Patrick Daly as a replacement for the [Link] package when author-date citation
styles are required. Natbib provides three associated bibliography styles:
plainnat

\citet and \citet* The \citet command is used for textual citations, that is to say that author names appear in
the text outside of the parenthetical reference to the date
of publication. This command can take options for chapter, page numbers etc. Here are examples
Here are the \citet* versions

abbrvnat
unsrtnat

\citep and \citep* The \citep command is used where


the author name is to appear inside the parentheses alongside the date.

which correspond to the three styles available by default


in BibTeX where you have a plain numbered style, an Here are the \citep* versions
abbreviated numbered style and an unsorted numbered
style.
The Reference List
Alongside these new styles is an extended set of citation
commands to provide exible citation formats. These are Having dealt with basic varieties of citation, we turn to
the creation of the bibliography or reference list.
\citet[]{}
and
\citep[]{}
each of which has a number of variants.
The Preamble

Inserting a correct and correctly formatted bibliography


when using Natbib is no dierent than when using plain
BibTeX. There are two essential commands \bibliography{mybibliographydatabase}
which LaTeX interprets as an instruction to read a bibliographic database le (eg [Link]) and insert the relevant data here, and

All Natbib styles require that you load the package in your \bibliographystyle{plainnat}
document preamble. So, a skeleton LaTeX le with Natbib might look like this:
which species how the data are to be presented.

5.6. LATEX/MORE BIBLIOGRAPHIES


Above the three basic Natbib styles were mentioned
as analogues of the partially homonymous styles in
BibTeX. Let us imagine documents bearing citations
as in the section about citation above. Here is, approximately, how these citations would appear in plainnat.

What more is there?


This covers the basic functionality provided by the package Natbib. It may not, of course, provide what you are
looking for. If you don't nd what you want here then you
should probably next investigate [Link] which provides a slighly dierent set of author-date citation functions. Providing a gentle guide to [Link] is my next
rainy day project.

127

Chapter 6

Special Documents
6.1 LaTeX/Letters
Sometimes the mundane things are the most painful.
However, it doesn't have to be that way because of
evolved, user-friendly templates. Thankfully, LaTeX allows for very quick letter writing, with little hassle.

6.1.1

The letter class

To write letters use the standard document class letter.


You can write multiple letters in one LaTeX le - start
each one with \begin{letter}{''recipient''} and end with
\end{letter}. You can leave recipient blank. Each letter
consists of four parts.
1. Opening (like \opening{Dear Sir or Madam,} or
\opening{Dear Kate,}).
2. Main body (written as usual in LaTeX).
3. Closing (like \closing{Yours sincerely,}).
A sample letter.

LaTeX will leave some space after closing for your hand-written signature; then
it will put your name and surname, if you
have declared them.

6.1.2 Envelopes
4. Additional elements: post scripta, carbon copy and
list of enclosures.
Using the envlab package
If you want your name, address and telephone number to
appear in the letter, you have to declare them rst signaThe envlab package provides customization to the \maketure, address and telephone.
labels command, allowing the user to print on any of an
The output letter will look like this:
assortment of labels or envelope sizes. For example, beginning your LaTeX le the following way produces a
Here is the examples code:
document which includes the letter and a business-size
To move the closing and signature parts to the left, insert (#10) envelope on the following page.
the following before \begin{document}:
Refer to the envlab user guide for more information about
\longindentation=0pt
this capable package. Note that the envlab package has
The amount of space to the left can be adjusted by in- issues displaying characters outside the base ASCII character set, see this bug report for more information.
creasing the 0pt.
128

6.2. LATEX/PRESENTATIONS

129

Using the geometry package


Here is a relatively simple envelope which uses the geometry package which is used because it vastly simplies
the task of rearranging things on the page (and the page
itself).

A sample envelope to be printed in landscape mode.

Printing
The above will certainly take care of the spacing but the
actual printing is between you and your printer. One user
reports that printing envelopes created with envlab is relatively painless. If you use the geometry package, you
may nd the following commands useful for printing the A sample letter with folding marks ready for standardized winenvelope.
dowed envelopes.
$ pdatex [Link] $ pdf2ps [Link] $ lpr -o
landscape [Link]
Alternatively, you can use the latex dvi output driver.

placed into standardized windowed envelopes DIN C6/5,


DL, C4, C5 or C6.

In the rst line, dvips command converts the .dvi le pro- In addition to the default, the KOMA-package includes
duced by latex into a .ps (PostScript) le. In the second predened format denitions for dierent standardized
line, the PostScript le is sent to the printer.
Swiss and Japanese letter formats.
$ latex [Link] && dvips -t unknown -T
9.5in,4.125in [Link] $ lpr -o landscape enve6.1.4
[Link]

Reference: [Link] commands

It is reported that pdatex creates the right page size but 6.1.5 Sources
not dvips despite what it says in the geometry manual.
It will never work though unless your printer settings are
KOMA-Script - The Guide
adjusted to the correct page style. These settings depend
on the printer lter you are using and in CUPS might be
available on the lpr command line.

6.2 LaTeX/Presentations

6.1.3

Windowed envelopes

LaTeX can be used for creating presentations. There are


several packages for the task, including the beamer packAn alternative to separately printing addresses on en- age.
velopes is to use the letter class from the KOMA package.
It supports additional features like folding marks and the
correct address placement for windowed envelopes. Us- 6.2.1 The Beamer package
ing the scrlttr2 document class from the KOMA package
The beamer package is provided with most LaTeX distrithe example letter code is:
butions, but is also available from CTAN. If you use MikThe output is generated via
TeX, all you have to do is to include the beamer package
$ pdatex koma_env Folding the print of the resulting and let LaTeX download all wanted packages automatile koma_env.pdf according the folding marks it can be cally. The documentation explains the features in great

130

CHAPTER 6. SPECIAL DOCUMENTS

detail. You can also have a look at the PracTex article then you could use a pdf reader with a fullscreen mode,
Beamer by example.[1]
such as Okular, Evince or Adobe Reader. If you want
The beamer package also loads many useful packages in- to navigate in your presentation, you can use the almost
invisible links in the bottom right corner without leaving
cluding hyperref.
the fullscreen mode.
Introductory example

Document Structure

The beamer package is loaded by calling the beamer class: Title page and information You give information
about authors, titles and dates in the preamble.
\documentclass{beamer}
\title[Crisis] % (optional, only for long titles) {The
Economics of Financial Crisis} \subtitle{Evidence from
The usual header information may then be specied.
India} \author[Author, Anders] % (optional, for multiple
Note that if you are compiling with XeTeX then you
authors) {F.~Author\inst{1} \and S.~Anders\inst{2}}
should use
\institute[Universities Here and There] % (optional) {
\documentclass[xetex,mathserif,serif]{beamer}
\inst{1}% Institute of Computer Science\\ University
Here \and \inst{2}% Institute of Theoretical PhilosoInside the usual document environment, multiple frame phy\\ University There } \date[KPT 2004] % (optional)
environments specify the content to be put on each slide. {Conference on Presentation Techniques, 2004} \subThe frametitle command species the title for each slide ject{Computer Science}
(see image):
\begin{document} \begin{frame} \frametitle{This is In the document, you add the title page :
the rst slide} %Content goes here \end{frame} \be- \frame{\titlepage}
gin{frame} \frametitle{This is the second slide} \framesubtitle{A bit more information about this} %More
content goes here \end{frame} % etc \end{document}
Table of Contents The table of contents, with the current section highlighted, is displayed by:
\begin{frame} \frametitle{Table of Contents} \tableofcontents[currentsection] \end{frame}
This can be done automatically at the beginning of each
section using the following code in the preamble:
\AtBeginSection[] { \begin{frame} \frametitle{Table of
Contents} \tableofcontents[currentsection] \end{frame}
}
Or for subsections:
\AtBeginSubsection[]
{
\begin{frame}
\frametitle{Table
of
Contents}
\tableofcontents[currentsection,currentsubsection]
\end{frame}
}

References (Beamer) Beamer does not ocially supThe usual environments (itemize, enumerate, equation, port BibTeX. Instead bibliography items will need to be
partly set by hand (see [Link] 3.20). The
etc.) may be used.
following example shows a references slide containing
Inside frames, you can use environments like block, the- two entries:
orem, proof, ... Also, \maketitle is possible to create the
\begin{frame}[allowframebreaks]
\frametifrontpage, if title and author are set.
tle<presentation>{Further
Reading}
\beTrick: Instead of using \begin{frame}...\end{frame}, gin{thebibliography}{10}
\beamertemplatebookyou can also use \frame{...}.
bibitems \bibitem{Autor1990} A.~Autor. \newblock
For the actual talk, if you can compile it with pdatex {\em Introduction to Giving Presentations}. \newblock

6.2. LATEX/PRESENTATIONS
Klein-Verlag, 1990. \beamertemplatearticlebibitems
\bibitem{Jemand2000} S.~Jemand.
\newblock On
this and that. \newblock {\em Journal of This and
That}, 2(1):50-100, 2000. \end{thebibliography}
\end{frame}

131
sidebar
smoothbars
smoothtree
split

As the reference list grows, the reference slide will di tree


vide into two and so on, through use of the allowframebreaks option. Individual items can be cited after adding
an 'optional' label to the relevant bibitem stanza. The ci- Then you can add the innertheme:
tation call is simply \cite. Beamer also supports limited \useinnertheme{rectangles}
customization of the way references are presented (see
the manual). Those who wish to use natbib, for example,
Here is a list of all available inner themes:
with Beamer may need to troubleshoot both their document setup and the relevant BibTeX style le.
rectangles
circles

Style
Themes The rst solution is to use a built-in theme
such as Warsaw, Berlin, etc. The second solution is to
specify colors, inner themes and outer themes.

inmargin
rounded
You can dene the color of every element:

The Built-in solution


the following line:

To the preamble you can add

\usetheme{Warsaw}
to use the Warsaw theme. Beamer has several themes,
many of which are named after cities (e.g. Frankfurt,
Madrid, Berlin, etc.).
This Theme Matrix contains the various theme and color
combinations included with beamer. For more customizing options, have a look to the ocial documentation included in your distribution of beamer, particularly the
part Change the way it looks.
The full list of themes is:
Color themes, typically with animal names, can be specied with
\usecolortheme{beaver}
The full list of color themes is:
The do it yourself solution First you can specify the
outertheme. The outertheme denes the head and the
footline of each slide.
\useoutertheme{infolines}
Here is a list of all available outer themes:
infolines
miniframes
shadow

\setbeamercolor{alerted text}{fg=orange} \setbeamercolor{background canvas}{bg=white} \setbeamercolor{block body alerted}{bg=normal [Link]!90!black}


\setbeamercolor{block
body}{bg=normal
[Link]!90!black} \setbeamercolor{block body example}{bg=normal [Link]!90!black} \setbeamercolor{block title alerted}{use={normal text,alerted
text},fg=alerted [Link]!75!normal [Link],bg=normal
[Link]!75!black}
\setbeamercolor{block
title}{bg=blue} \setbeamercolor{block title example}{use={normal
text,example
text},fg=example
[Link]!75!normal [Link],bg=normal [Link]!75!black}
\setbeamercolor{ne
separation
line}{}
\setbeamercolor{frametitle}{fg=brown}
\setbeamercolor{item
projected}{fg=black}
\setbeamercolor{normal
text}{bg=black,fg=yellow}
\setbeamercolor{palette sidebar primary}{use=normal
text,fg=normal
[Link]}
\setbeamercolor{palette
sidebar
quaternary}{use=structure,fg=[Link]}
\setbeamercolor{palette
sidebar
secondary}{use=structure,fg=[Link]}
\setbeamercolor{palette
sidebar
tertiary}{use=normal
text,fg=normal [Link]} \setbeamercolor{section in
sidebar}{fg=brown} \setbeamercolor{section in sidebar shaded}{fg=grey} \setbeamercolor{separation
line}{} \setbeamercolor{sidebar}{bg=red} \setbeamercolor{sidebar}{parent=palette primary} \setbeamercolor{structure}{bg=black, fg=green} \setbeamercolor{subsection in sidebar}{fg=brown} \setbeamercolor{subsection in sidebar shaded}{fg=grey}
\setbeamercolor{title}{fg=brown}
\setbeamercolor{titlelike}{fg=brown}
Colors can be dened as usual:

132

CHAPTER 6. SPECIAL DOCUMENTS

\denecolor{chocolate}{RGB}{33,33,33}

The allowframebreaks option will auto-create new frames


if there is too much content to be displayed on one.

Block styles can also be dened:

\frame[allowframebreaks]{ % ... }

\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{background
canvas}[vertical
shading][bottom=white,top=[Link]!25]
\setbeamertemplate{sidebar canvas left}[horizontal shading][left=white!40!black,right=black]
You can also suppress the navigation bar:
\beamertemplatenavigationsymbolsempty

Before using any verbatim environment (like listings),


you should pass the option fragile to the frame environment, as verbatim environments need to be typeset differently. Usually, the form fragile=singleslide is usable
(for details see the manual). Note that the fragile option
may not be used with \frame commands since it expects
to encounter a \end{frame}, which should be alone on a
single line.

\begin{frame}[fragile] \frametitle{Source code} \begin{lstlisting}[caption=First C example] int main()


Fonts You may also change the fonts for particular el- { printf(Hello World!"); return 0; } \end{lstlisting}
ements. If you wanted the title of the presentation as ren- \end{frame}
dered by \frame{\titlepage} to occur in a serif font instead
of the default sanserif, you would use:
\setbeamerfont{title}{family=\rm}

Hyperlink navigation

You could take this a step further if you are using Open- Internal and external hyperlinks can be used in beamer
Type fonts with Xe(La)TeX and specify a serif font with to assist navigation. Clean looking buttons can also be
increased size and oldstyle proportional alternate number added.
glyphs:
By default the beamer class adds navigation buttons in the
\setbeamerfont{title}{family=\rm\addfontfeatures{Scale=1.18,
bottom left corner. To remove them one can place
Numbers={Lining, Proportional}}}
\beamertemplatenavigationsymbolsempty
in the preamble.
Math Fonts The default settings for beamer use a different set of math fonts than one would expect from creating a simple math article. One quick x for this is to Animations
use at the beginning of the le the option mathserif
\documentclass[mathserif]{beamer}
Others have proposed to use the command
\usefonttheme[onlymath]{serif}

The following is merely an introduction to the possibilities in beamer. Chapter 8 of the beamer manual provides
much more detail, on many more features.
Making items appear on a slide is possible by simply using
the \pause statement:

\begin{frame} \frametitle{Some background} We


but it is not clear if this works for absolutely every math
start our discussion with some concepts. \pause The
character.
rst concept we introduce originates with Erd\H os.
\end{frame}
Frames Options
The plain option. Sometimes you need to include a large
gure or a large table and you don't want to have the bottom and the top of the slides. In that case, use the plain
option :

Text or gures after \pause will display after one of the


following events (which may vary between PDF viewers):
pressing space, return or page down on the keyboard, or
using the mouse to scroll down or click the next slide button. Pause can be used within \itemize etc.

\frame[plain]{ % ... }
Text animations For text animations, for example in
If you want to include lots of text on a slide, use the shrink the itemize environment, it is possible to specify appearoption.
ance and disappearance of text by using <a-b> where a
\frame[shrink]{ % ... }
and b are the numbers of the events the item is to be displayed for (inclusive). For example:

6.2. LATEX/PRESENTATIONS
\begin{itemize} \item This one is always shown \item<1> The rst time (i.e. as soon as the slide loads) \item<2->
The second time \item<1-> Also the rst time \only<11> {This one is shown at the rst time, but it will
hide soon (on the next event after the slide loads).}
\end{itemize}

133
only statements, but the second one show the rst one
plus some other graphs and you don't need the rst one to
appear in the handout. You can thus precise the handout
mode not to include some only commands by:
\only<1|
handout:0>{\includegraphics{[Link]}}
\only<2>{\includegraphics{[Link]}}

A simpler approach for revealing one item per click is to The command can also be used to hide frames, e.g.
use \begin{itemize}[<+->].
\begin{frame}<handout:0>
\begin{frame} \frametitle{`Hidden higher-order concepts?'} \begin{itemize}[<+->] \item The truths of
arithmetic which are independent of PA in some sense or even, if you have written a frame that you don't want
themselves `{contain} essentially {\color{blue}{hidden anymore but maybe you will need it later, you can write
higher-order}}, or innitary, concepts??? \item `Truths \begin{frame}<0| handout:0>
in the language of arithmetic which \ldots \item That suggests stronger version of Isaacsons thesis. \end{itemize}
and this will hide your slide in both modes. (The order
\end{frame}
matters. Don't put handout:0|beamer:0 or it won't work.)
In all these cases, pressing page up, scrolling up, or click- A last word about the handout mode is about the notes.
ing the previous slide button in the navigation bar will Actually, the full syntax for a frame is
backtrack through the sequence.
\begin{frame} ... \end{frame} \note{...} \note{...} ...
Handout mode

and you can write your notes about a frame in the eld
note (many of them if needed). Using this, you can add
an option to the class calling, either

In beamer class, the default mode is presentation which


makes the slides. However, you can work in a dierent \documentclass[12pt,handout,notes=only]{beamer}
mode that is called handout by setting this option when
calling the class:
or
\documentclass[12pt,handout]{beamer}
\documentclass[12pt,handout,notes=show]{beamer}
This mode is useful to see each slide only one time with all
its stu on it, making any \itemize[<+->] environments
visible all at once (for instance, printable version). Nevertheless, this makes an issue when working with the only
command, because its purpose is to have only some text
or gures at a time and not all of them together.

The rst one is useful when you make a presentation to


have only the notes you need, while the second one could
be given to those who have followed your presentation or
those who missed it, for them to have both the slides with
what you said.

Note that the 'handout' option in the \documentclass line


If you want to solve this, you can add a statement to spec- suppress all the animations.
ify precisely the behavior when dealing with only commands in handout mode. Suppose you have a code like Important: the notes=only mode is literally doing only
the notes. This means there will be no output le but the
this
DVI. Thus it requires you to have run the compilation
\only<1>{\includegraphics{[Link]}}
in another mode before. If you use separate les for a
\only<2>{\includegraphics{[Link]}}
better distinction between the modes, you may need to
copy the .aux le from the handout compilation with the
These pictures being completely dierent, you want them slides (w/o the notes).
both in the handout, but they cannot be both on the same
slide since they are large. The solution is to add the handout statement to have the following:
Columns and Blocks
\only<1|
handout:1>{\includegraphics{[Link]}}
\only<2| handout:2>{\includegraphics{[Link]}}
There are two handy environments for structuring a
slide: blocks, which divide the slide (horizontally) into
This will ensure the handout will make a slide for each headed sections, and columns which divides a slide
picture.
(vertically) into columns. Blocks and columns can be
Now imagine you still have your two pictures with the used inside each other.

134
Columns

CHAPTER 6. SPECIAL DOCUMENTS


Example

\begin{frame}{Example of columns 1} \begin{columns}[c] % the c option species center


vertical alignment \column{.5\textwidth} % column
designated by a command Contents of the rst column
\column{.5\textwidth} Contents split \\ into two lines
\end{columns} \end{frame} \begin{frame}{Example
of columns 2} \begin{columns}[T] % contents are
top vertically aligned \begin{column}[T]{5cm}
% each column can also be its own environment
Contents of rst column \\ split into two lines
\end{column} \begin{column}[T]{5cm} % alternative top-align thats better for graphics \includegraphics[height=3cm]{[Link]}
\end{column}
\end{columns} \end{frame}

PDF options
You can specify the default options of your PDF.[2]
\hypersetup{pdfstartview={Fit}} % ts the presentation
to the window when rst displayed

6.2.2 The powerdot package


The powerdot package is available from CTAN. The
documentation explains the features in great detail.
The powerdot package is loaded by calling the powerdot
class:
\documentclass{powerdot}
The usual header information may then be specied.
Inside the usual document environment, multiple slide environments specify the content to be put on each slide.
\begin{document} \begin{slide}{This is the rst slide}
%Content goes here \end{slide} \begin{slide}{This is
the second slide} %More content goes here \end{slide}
Blocks Enclosing text in the block environment creates
% etc \end{document}
a distinct, headed block of text (a blank heading can be
used). This allows to visually distinguish parts of a slide
easily. There are three basic types of block. Their formatting depends on the theme being used.
6.2.3 References
Simple
[1] Andrew Mertz and William Slough Beamer by Example

\begin{frame} \begin{block}{This is a Block}


This is important information \end{block} \be- [2] Other possible values are dened in the hyperref manual
gin{alertblock}{This is an Alert block} This is an important alert \end{alertblock} \begin{exampleblock}{This
is an Example block} This is an example 6.2.4 Links
\end{exampleblock} \end{frame}
Wikipedia:Beamer (LaTeX)

6.4. LATEX/CURRICULUM VITAE


Beamer user guide (pdf) from CTAN
The powerdot class (pdf) from CTAN
A tutorial for creating presentations using beamer

6.3 LaTeX/Teachers Corner


6.3.1

135
Introduction
The macro \numquestions gives the total number of
questions. The macro \numpoints gives the total number of points.
\begin{minipage}{.8\textwidth} This exam includes
\numquestions\ questions. The total number of points is
\numpoints. \end{minipage}

Intro

The backslash after \numquestion prevents the macro


LaTeX has specic features for teachers. We present the from gobbling the following whitespace as it normally
exam class[1] which is useful for designing exams and ex- would.
ercises with solutions. Interested people could also have
a look at the probsoln package[2] or the mathexm document class[3] .
6.3.3 References

6.3.2

The exam class

[1] examdoc Using the exam document class


[2] Probsoln creating problem sheets optionally with solutions

We present the exam class. The exam class is well suited


to design exams with solutions. You just have to specify
in the preamble if you want the solutions to be printed or
not. You can also count the number of points.
Preamble
In the preamble you can specify the following lines :
You can replace the 3 rst lines with the following :
Document

[3] [Link]
exams/[Link]

6.4 LaTeX/Curriculum Vitae


A curriculum vit or rsum has a universal requirement:
its formatting must be awless. This is a great example
of cases where the power of LaTeX comes to the front.
Thanks to its strong typographical stance, LaTeX is definitely a document processor of choice to write a CV.

Of course you can design you own CV by hand. Otherwise, you may want to use a dedicated class for that task.
The command \question introduces a new question. This way, writing a CV in LaTeX is as simple as lling
the forms, and you are done. [Link] makes 4 of
The number of points is specied in squared brack- them available from a simple web form: no coding or edets.
itor required.
The exam is included in the questions environment.

The solution is given in the solution environment. A full list of CV packages is available at CTAN.
It appears only if \printanswers or answers as an
option of the \documentclass are specied in the
preamble.
6.4.1 curve
Here is an example :
\begin{questions} % Begins the questions environment
\question[2] What is the solution? % Introduces a
new question which is worth 2 points \begin{solution}
Here is the solution \end{solution} \question[5] What
is your opinion? \begin{solution} This is my opinion
\end{solution} \end{questions}

6.4.2 europecv
6.4.3 moderncv
From CTAN:

Moderncv provides a documentclass for typesetting


modern curriculums vitae, both in a classic and in a casual
style. It is fairly customizable, allowing you to dene your
It is also possible to add stu only if answers are printed own style by changing the colours, the fonts, etc.
using the \ifprintanswers command.
The ocial package provides some well commented tem\ifprintanswers Only if answers are printed \else Only if plates which may be a good start. You can nd those templates in your distribution (if documentation is installed
answers are not printed \
along packages) or ultimately on CTAN.

136

CHAPTER 6. SPECIAL DOCUMENTS

We will not repeat the templates here, so we will only


provide a crash course. You should really have a look at
the templates for more details.
First document
Most commands are self-explanatory.
Theme previews
Themes
Banking black theme
Classic green theme

6.4.4

Multilingual support

It is especially convenient for rsums to have only one


document for several output languages, since many parts
are shared among versions (personal data, structure, etc.).
LaTeX with appropriate macros provide a comfortable
way to manage it. See Internationalization.

6.4.5

References

Chapter 7

Creating Graphics
7.1 LaTeX/Introducing Procedural Graphics

tional graphics les to be dragged along.

Packages like epic, eepic or pstricks enhance the original


picture environment, and greatly strengthen the graphical
In the Importing Graphics chapter, you learned that you power of LaTeX.
can import or link graphics into LaTeX, such as graph- While the former two packages just enhance the picture
ics that you have created in another program or obtained environment, the pstricks package has its own drawing
elsewhere. In this chapter, you will learn how to create environment, pspicture. The power of pstricks stems
or embed graphics directly in a LaTeX document. The from the fact that this package makes extensive use of
graphics is marked up using commands similar to those PostScript possibilities. Unfortunately it has one big
for typesetting bold text or creating mathematical for- shortcoming: it doesn't work together with pdfLaTeX, as
mulas, as the following example of embedded graphics such. To generate a PDF document from TeX source, you
shows:
have to go from TeX to DVI to PDF, losing hyperlinks,
There are several packages supporting the creation of metadata, and microtypographic features of pdatex in
graphics directly in LaTeX, including picture, xy-Pic and the process.
PGF/TikZ, described in the following sections.

In addition, numerous packages have been written for


Compared to WYSIWIG tools like Xg or Inkscape, this specic purposes. One of them is XY-pic, described at
approach is more time consuming, but leads to much bet- the end of this chapter. A wide variety of these packages
ter results. Furthermore, the ouput is awlessly integrated are described in detail in The LaTeX Graphics Companion (not to be confused with The LaTeX Companion).
to your document (no contrast in size nor fonts).
See the Importing Graphics for more details on graphics Perhaps the most powerful graphical tool related with
importation and some attempts to circumvent to integra- LaTeX is MetaPost, the twin of Donald E. Knuths
METAFONT. MetaPost has the very powerful and
tion issue.
mathematically sophisticated programming language of
METAFONT. Contrary to METAFONT, which generates bitmaps, MetaPost generates encapsulated PostScript
7.1.1 Overview
les, which can be imported in LaTeX. For an introducThe picture environment allows programming pictures tion, see A Users Manual for MetaPost. A very thorough
directly in LaTeX. On the one hand, there are rather se- discussion of LaTeX and TEX strategies for graphics (and
vere constraints, as the slopes of line segments as well fonts) can be found in TEX Unbound.
as the radii of circles are restricted to a narrow choice The last but certainly not least are the PGF/TikZ and
of values. On the other hand, the picture environment Asymptote systems. While the previous systems (picof LaTeX2e brings with it the \qbezier command, q ture, epic, pstricks or metapost) focus on the how to draw,
meaning quadratic. Many frequently-used curves such TikZ and Asymptote focus more on the what to draw.
as circles, ellipses, and catenaries can be satisfactorily One could say that TikZ and Asymptote are to drawing
approximated by quadratic Bzier curves, although this in LaTeX as LaTeX is to digital typesetting. Its recommay require some mathematical toil. If a programming mended to use one of these if your LaTeX distribution
language like Java is used to generate \qbezier blocks of includes it. TikZ is a pure (La)TeX system, not reliant
LaTeX input les, the picture environment becomes quite on external software, while Asymptote is an external syspowerful.
tem which integrates seamlessly with (La)TeX. If using
Although programming pictures directly in LaTeX is Asymptote, it is very helpful to use latexmk to manage
severely restricted, and often rather tiresome, there are the compilation steps.
still reasons for doing so. The documents thus produced In many cases, especially for more advanced diagrams, it
are small with respect to bytes, and there are no addi137

138
may be easier to draw the graphics using external vector
graphics software, and then import the le into the document (see LaTeX/Importing_Graphics). However most
software does not support LaTeX fonts or mathematical
notation, which can result in not suitable and inconsistent
graphics. There are several solutions to this problem.

7.2 LaTeX/MetaPost

CHAPTER 7. CREATING GRAPHICS


Bzier curves are an exception. They are drawn with the
command
With the package picture absolute dimension (like 15pt)
and expression are allowed, in addition to numbers relative to \unitlength.

7.3.2 Line segments


Line segments are drawn with the command:

7.3 LaTeX/Picture
The picture environment allows programming pictures
directly in LaTeX. On the one hand, there are rather severe constraints, as the slopes of line segments as well
as the radii of circles are restricted to a narrow choice
of values. On the other hand, the picture environment
of LaTeX2e brings with it the \qbezier command, q
meaning quadratic. Many frequently-used curves such
as circles, ellipses, and catenaries can be satisfactorily
approximated by quadratic Bzier curves, although this
may require some mathematical toil. If a programming
language like Java is used to generate \qbezier blocks of
LaTeX input les, the picture environment becomes quite
powerful.

The \line command has two arguments:


1. a direction vector,
2. a length (sort of: this argument is the vertical
length in the case of a vertical line segment and in all
other cases the horizontal distance of the line, rather
than the length of the segment itself).
The components of the direction vector are restricted to
the integers (6, 5, ... , 5, 6) and they have to be coprime (no common divisor except 1). The gure below
illustrates all 25 possible slope values in the rst quadrant.
The length is relative to \unitlength.

Although programming pictures directly in LaTeX is


severely restricted, and often rather tiresome, there are
still reasons for doing so. The documents thus produced
7.3.3 Arrows
are small with respect to bytes, and there are no additional graphics les to be dragged along.
Arrows are drawn with the command
Packages like pict2e, epic, eepic or pstricks enhance the
original picture environment, and greatly strengthen the For arrows, the components of the direction vector are
even more narrowly restricted than for line segments,
graphical power of LaTeX.
namely to the integers (4, 3, ... , 3, 4). Components
also have to be coprime (no common divisor except 1).
Notice the eect of the \thicklines command on the two
7.3.1 Basic commands
arrows pointing to the upper left.
A picture environment is available in any LaTeX distribution, without the need of loading any external package.
This environment is created with one of the two com- 7.3.4 Circles
mands
The command
or
The rst pair, (x, y) , aects the reservation, within the draws a circle with center (x, y) and diameter (not radius)
specied by diameter. The picture environment only addocument, of rectangular space for the picture.
mits diameters up to approximately 14mm, and even beThe optional second pair, (x0 , y0 ) , assigns arbitrary co- low this limit, not all diameters are possible. The \circle*
ordinates to the bottom left corner of the reserved rect- command produces disks (lled circles). As in the case of
angle.
line segments, one may have to resort to additional packThe numbers x, y, x0, y0 are numbers (lengths) in the ages, such as eepic, pstricks, or tikz.
units of \unitlength, which can be reset any time (but not There is another possibility within the picture environwithin a picture environment) with a command such as
ment. If one is not afraid of doing the necessary calculations (or leaving them to a program), arbitrary circles and
The default value of \unitlength is 1pt.
ellipses can be patched together from quadratic Bzier
Most drawing commands have one of the two forms
curves. See Graphics in LaTeX2e for examples and Java
or
source les.

7.3. LATEX/PICTURE

7.3.5

Text and formulae

139

7.3.9 Quadratic Bzier curves

As this example shows, text and formulae can be written The command
in the environment with the \put command in the usual
draws a quadratic bezier curve where P1 = (x1 , y1 ) ,
way:
P2 = (x2 , y2 ) denote the end points, and S = (x, y)
denotes the intermediate control point. The respective
tangent slopes, m1 and m2 , can be obtained from the
equations
7.3.6 \multiput and \linethickness
The command

{
1 x1 (y2 y1 )
x = m2 x2 m
has 4 arguments: the starting point, the translation vector
m2 m1
from one object to the next, the number of objects, and
y = yi + mi (x xi ); (i = 1, 2 gives same solution)
the object to be drawn. The \linethickness command applies to horizontal and vertical line segments, but neither
to oblique line segments, nor to circles. It does, however, See Graphics in LaTeX2e for a Java program which generates the necessary \qbezier command line.
apply to quadratic Bzier curves!
As this example illustrates, splitting up a circle into 4
quadratic Bzier curves is not satisfactory. At least 8
are needed. The gure again shows the eect of the
7.3.7 Ovals
\linethickness command on horizontal or vertical lines,
and of the \thinlines and the \thicklines commands on
The command
oblique line segments. It also shows that both kinds of
commands aect quadratic Bzier curves, each command
or
overriding all previous ones.
produces an oval centered at (x, y) and having width w and
height h. The optional position arguments b, t, l, r refer to
top, bottom, left, right, and can be combined, as
the example illustrates. Line thickness can be controlled
7.3.10 Catenary
by two kinds of commands: \linethickness{''length''} on
the one hand, \thinlines and \thicklines on the other.
While \linethickness{''length''} applies only to horizontal In this gure, each symmetric half of the catenary y =
and vertical lines (and quadratic Bzier curves), \thinlines cosh x 1 is approximated by a quadratic Bzier curve.
and \thicklines apply to oblique line segments as well as The right half of the curve ends in the point (2, 2.7622),
the slope there having the value m = 3.6269. Using again
to circles and ovals.
equation (*), we can calculate the intermediate control
points. They turn out to be (1.2384, 0) and (1.2384, 0).
The crosses indicate points of the real catenary. The error
7.3.8 Multiple use of predened picture is barely noticeable, being less than one percent. This
example points out the use of the optional argument of
boxes
the \begin{picture} command. The picture is dened in
convenient mathematical coordinates, whereas by the
A picture box can be declared by the command
command
then dened by
its lower left corner (marked by the black disk) is assigned
and nally arbitrarily often be drawn by
the coordinates (2.5,0.25).
The optional position parameter has the eect of dening
the anchor point of the savebox. In the example it is set
to bl which puts the anchor point into the bottom left
corner of the savebox. The other position speciers are 7.3.11 Plotting graphs
top and right.
The name argument refers to a LaTeX storage bin and
therefore is of a command nature (which accounts for the
backslashes in the current example). Boxed pictures can
be nested: In this example, \foldera is used within the
denition of \folderb. The \oval command had to be used
as the \line command does not work if the segment length
is less than about 3 mm.

The control points of the two Bzier curves were calculated with formulas (*). The positive branch is determined by P1 = (0, 0) , m1 = 1 and P2 = (2, tanh 2)
, m2 = 1/ cosh2 2 . Again, the picture is dened in
mathematically convenient coordinates, and the lower left
corner is assigned the mathematical coordinates (3,2)
(black disk).

140

7.3.12

CHAPTER 7. CREATING GRAPHICS

The picture environment and gnu- html#pgftikzsection


plot
In the following some basics of TikZ are presented.

The powerful scientic plotting package gnuplot has the


capability to output directly to a LaTeX picture environment. It is often far more convenient to plot directly to
LaTeX, since this saves having to deal with potentially
troublesome postscript les. Plotting scientic data (or,
indeed, mathematical gures) this way gives much greater
control, and of course typesetting ability, than is available
from other means (such as postscript). Such pictures can
then be added to a document by an \include{} command.

7.4.1 Loading Package, Libraries


tikzpicture environment

Using TikZ in a LaTeX document requires loading the


tikz package:
\usepackage{tikz}

N.B. gnuplot is a powerful piece of software with a vast somewhere in the preamble. This will automatically load
array of commands. A full discussion of gnuplot lies be- the pgf package. To load further libraries use
yond the scope of this note. See [] for a tutorial.
\usetikzlibrary{list of libraries separated by commas}

7.4 LaTeX/PGF/TikZ

Examples for libraries are arrows, automata, backgrounds, calendar, chains, matrix, mindmap,
patterns, petri, shadows, [Link],
[Link], spy, trees.
Drawing commands have to be enclosed in an tikzpicture
environment
\begin{tikzpicture}[options]
\end{tikzpicture}

tikz

commands

or alternatively
\tikz[options]{tikz commands}
One possible option useful for inlined graphics is
Example of graphics done with Tikz. Note the slightly translucent
top layer.

One possible solution how to draw graphics directly with


TeX commands is PGF/TikZ. TikZ can produce portable
graphics in both PDF and PostScript formats using either
plain (pdf)TEX, (pdf)Latex or ConTEXt. It comes with
very good documentation and an extensive collection of
examples: [Link]

baseline=dimension
Without that option the lower end of the picture is put on
the baseline of the surrounding text. Using this option,
you can specify that the picture should be raised or lowered such that the height dimension is on the baseline.
Another option to scale the entire picture is
scale=factor

PGF (portable graphics format) is the basic layer, providing a set of basic commands for producing graphics, or dierent for height and width, e.g:
and TikZ (TikZ ist kein Zeichenprogramm) is the fron- xscale=2.5, yscale=0.5
tend layer with a special syntax, making the use of PGF
easier. TikZ commands are prevalently similar to Metafont, the option mechanism is similar to PsTricks syntax.
While the previous systems (picture, epic, pstricks or
metapost) focus on the how to draw, TikZ focuses more
on the what to draw. One could say that TikZ is to drawing in LaTeX as LaTeX is to digital typesetting. Its recommended to use it if your LaTeX distribution includes
it.

7.4.2 Specifying Coordinates


Coordinates are specied in round brackets in an arbitrary TEX dimension either using Cartesian coordinates
(comma separated), e.g. 1cm in the x direction and 2pt
in the y direction

Other packages building on top of TikZ (e.g., (1cm,2pt)


for drawing electrical circuits) can be found here:
[Link] or using polar coordinates (colon separated), e.g. 1cm in

7.4. LATEX/PGF/TIKZ

141

30 degree direction

dotted, densely dotted, loosely dotted, double.

(30:1cm)

Options for lling paths are e.g. ll=<ll color>", pattern=<name>", pattern color=<color>"

Without specifying a unit (1,2), the standard one is cm Straight lines are given by coordinates separated by a dou(1cm,2cm).
ble minus,
Relative coordinates to the previous given point are given
by adding one or two plus signs in front of the coordinate.
With "++" the last point of the path becomes the current
position, with "+" the previous point stays the current path
position. Example: 2 standard units to the right of the last
point used:
++(2,0)

\draw (1,0) -- (0,0) -- (0,1);


The rst coordinate represents a move-to operation. This
is followed by a series of path extension operations, like
"-- (coordinates)".
The same path with some drawing options:
\draw[red, dashed, very thick, rotate=30] (1,0) -- (0,0) -(0,1);

7.4.3

Syntax for Paths

A connected path can be closed using the "--cycle operation:

A path is a series of straight and curved line segments(in


\draw (1,0) -- (0,0) -- (0,1) -- cycle;
a simplied explanation). The instruction has to end with
a semicolon.
A further move-to operation in an existing path starts a
\path[<options>]specication;
new part of the path, which is not connected to the previous part of the path. Here: Move to (0,0) straight line
One instruction can spread over several lines, or several to (2,0), move to (0,1) straight line to (2,1):
instructions can be put on one line.
\draw (0,0) -- (2,0) (0,1) -- (2,1);
Options for path actions are e.g: draw, ll, pattern,
shade (lling, in which its color changes smoothly from
Connecting two points via straight lines that are only horone to another), clip (all subsequent drawings up to the
izontal and vertical, use for rst horizontal then vertial
end of the current scope are clipped against the current
path and the size of subsequent paths will not be impor- \draw (0,0) -| (1,1);
tant for the picture size), use as bounding box.
The "\path command with these options can be com- or for rst vertical then horizontal
bined to: "\draw, "\ll, "\lldraw, "\pattern, "\shade, \draw (0,0) |- (1,1);
"\shadedraw, "\clip, "\useasboundingbox .
Geometric path options:
rotate=<angle in de- Curved paths using a Bezier curve can be created using
gree>", xshift=<length>", yshift=<length>", scal- the "..controls() ..()" command, with one or two control
ing=<factor>", xscale=<factor>", yscale=<factor>".
points.
Color options for drawing paths: color=<color name>", \draw (0,0) .. controls (1,1) .. (4,0) (5,0) .. controls (6,0)
draw=<line color>", opacity=<factor>". Following and (6,1) .. (5,2);
colors are predened: red, green, blue, cyan , magenta,
yellow, black, gray, darkgray, lightgray, brown, lime,
User-dened paths can be created using the to operolive, orange, pink, purple, teal, violet and white.
ation. Without an option it corresponds to a straight
Line width options: line width=<dimension>", and ab- line, exactly like the double minus command. Using the
breviations ultra thin for 0.1pt, very thin for 0.2pt, out and in option a curved path can created. E.g.
thin for 0.4pt (the default width), semithick for 0.6pt, "[out=135,in=45]" causes the path to leave at an angle of
thick for 0.8pt, very thick for 1.2pt, ultra thick for 135 degree at the rst coordinate and arrive at an angle
1.6pt.
of 45 degree at the second coordinate.
Line end, line join options: line cap=<type: round, \draw (0,0) to (3,2); \draw (0,0) to[out=90,in=180]
rect, or butt>", arrows=<start arrow kind>-<end arrow (3,2); \draw (0,0) to[bend right] (3,2);
kind>", rounded corners, rounded corners=<size>",
line join=<type: round, bevel, or miter>".
For rectangles a special syntax exist. Use a move-to operLine pattern options: dash pattern=<dash pattern>" (e.g. ation to one corner and after rectangle the coordinates
dash pattern=on 2pt o 3pt on 4pt o 4pt), dash of the diagonal corner. The last one becomes the new
phase=dash phase", solid, dashed, dotted, dash-

142

CHAPTER 7. CREATING GRAPHICS

current point.
\draw (0,0) rectangle (1,1); \shade[top color=yellow,
bottom color=black] (0,0) rectangle (2,1); \lldraw[ll=green!20!white, draw=green!40!black] (0,0)
rectangle (2,1);

Many functions are possible, here a selection: factorial(\x), sqrt(\x), pow(\x,y), exp(\x), ln(\x), log10(\x),
log2(\x), abs(\x), mod(\x,y), round(\x), oor(\x), ceil(\x),
sin(\x), cos(\x), tan(x), min(\x,y,), max(\x,y). The
trigonometric functions assume that x is in degrees; if x
is expressed in radians use e.g. sin(\x r). Two constants
The ll color green!20!white means 20% green and
can be useful: e, which is equal to 2.718281828, and pi,
80% white mixed together.
which is equal to 3.141592654.
Circles and ellipses paths are dened beginning with their
center then using the circle command either with one An example with two functions:
length as radius of a circle or with two lengths as semi- \draw [help lines] (2,0) grid (2,4); \draw [->] (2.2,0)
axes of an ellipse.
-- (2.2,0); \draw [->] (0,0) -- (0,4.2); \draw [green,
\draw (0,0) circle [radius=1.5]; \draw (0,0) circle (2cm); thick, domain=2:2] plot (\x, {4-\x*\x}); \draw
[domain=2:2, samples=50] plot (\x, {1+cos(pi*\x r});
% old syntax \draw (0,0) circle [x radius=1.5cm, y
radius=10mm]; \draw (0,0) circle (1.2cm and 8mm);
% old syntax \draw (0,0) circle [x radius=1cm, y
radius=5mm, rotate=30]; \draw[rotate=30] (0,0) ellipse
(20pt and 10pt); % old syntax
7.4.4 Nodes
The command arc creates a part of a circle or an ellipse: A node is typically a rectangle or circle or another simple
shape with some text on it. In the simplest case, a node is
\draw (0,0) arc ([Link]mm); \draw (0,0) arc just some text that is placed at some coordinate. Nodes
([Link].75cm and 1cm); \lldraw[ll=cyan, draw=blue] are not part of the path itself, they are added to the picture
(0,0) -- (12mm,0mm) arc ([Link]mm) -- (0,0);
after the path has been drawn.
Or in an alternative syntax:

Inside a path operation use the following syntax after a


given coordinate:

\draw (0,0) arc[radius = 8mm, start angle= 0, end angle= node[<options>](<name>){<text>}


270] \draw (0,0) arc[x radius = 1.75cm, y radius = 1cm,
start angle= 0, end angle= 315]
The "(<name>)" is a name for later reference and it is optional. If you only want to name a certain position without
There are many more predened commands for special writing text there are two possibilities:
paths, like grid, parabola, sin, cos (sine or cosine
node[<options>](<name>){}
coordicurve in the interval [0,/2]).
nate[<options>](<name>)
\draw[help lines] (0,0) grid (2,3); \draw[step=0.5, gray,
very thin] (1.4,1.4) grid (1.4,1.4); \draw (0,0)
parabola (1,1.5) parabola[bend at end] (2,0); \draw (0,0) Writing text along a given path using the node command
is shown as simple example:
sin (1,1) cos (2,0) sin (3,1) cos (4,0) sin (5,1);
\draw[dotted] (0,0) node {1st node} -- (1,1) node {2nd
node} -- (0,2) node {3rd node} -- cycle;
The option help lines denotes ne gray.
To add arrow tips there are simple options for the drawing
Possible options for the node command are e.g. incommand:
ner sep=<dimension>", outer sep=<dimension>",
\draw [->] (0,0) -- (30:20pt); \draw [<->] (1,0) arc minimum
size=<dimension>",
shape
as([Link]pt); \draw [<<->] (2,0) -- ++(0.5,10pt) -- pect=<aspect ratio>",
text=<color>",
font=",
++(0.5,10pt) -- ++(0.5,10pt);
align=<left_right_center>".
A node is centered at the current coordinate by default.
A loop can be realized by "\foreach variable in {list of Often it would be better to have the node to the besides
values} commands".
the actual coordinate: Right (right or anchor=west),
left (left or anchor=east), above (above or an\foreach \x in {0,...,9} \draw (\x,0) circle (0.4);
chor=south), below (below or anchor=north). Combinations are also possible, like anchor=north east or
PGF also has a math engine which enables you to plot
below left.
functions:
\ll[ll=yellow] (0,0) node {1st node} -- (1,1)
\draw [domain=<xmin>:<xmax>] plot (\x, {function});
node[circle,inner sep=0pt,draw] {2nd node} -- (0,2)

7.4. LATEX/PGF/TIKZ
node[ll=red!20,draw,double,rounded
node};

143
corners]

{3rd Once the node x has been dened, you can use anchors
as dened above relative to (x) as "(x.<anchor>)", like
"([Link])".

To place nodes on a line or a curve use the


pos=<fraction>" option, where fraction is a oating point number between 0 representing the previous
coordinate and 1 representing the current coordinate.
\draw (0,0) -- (3,1) node[pos=0]{0} node[pos=0.5]{1/2}
node[pos=0.9]{9/10};
There exist some abbreviations: at start for pos=0,
very near start for pos=0.125, near start for
pos=0.25, midway for pos=0.5, near end for
pos=0.75, very near end for pos=0.875, at end
for pos=1.

7.4.5 Examples
Example 1
\documentclass{article}
\usepackage{tikz}
\begin{document} \begin{tikzpicture} \draw[thick,rounded
corners=8pt] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0)
-- (0,2) -- (2,2) -- (0,0) -- (2,0); \end{tikzpicture}
\end{document}

The sloped option causes the node to be rotated to beExample 2


come a tangent to the curve.
\usepackage{tikz}
\beSince nodes are often the only path operation on paths, \documentclass{article}
gin{document}
\begin{tikzpicture}[scale=3]
there are special commands for creating paths containing
only a node, the rst with text ouput, the second without: \draw[step=.5cm, gray, very thin] (1.2,1.2) grid
(1.2,1.2); \lldraw[ll=green!20,draw=green!50!black]
\node[<options>](<name>) at (<coordinate>){<text>}; (0,0) -- (3mm,0mm) arc ([Link]mm) -- cycle; \draw[->]
\coordinate[<options>](<name>) at (<coordinate>);
(1.25,0) -- (1.25,0) coordinate (x axis); \draw[>] (0,1.25) -- (0,1.25) coordinate (y axis); \draw
One can connect nodes using the nodes labels as coordi- (0,0) circle (1cm); \draw[very thick,red] (30:1cm)
nates. Having "\path(0,0) node(x) {} (3,1) node(y) {};" -- node[left,ll=white] {$\sin \alpha$} (30:1cm
dened, the node at (0,0) got the name "(x)" and the one |- x axis); \draw[very thick,blue] (30:1cm |- x
axis) -- node[below=2pt,ll=white] {$\cos \alpha$}
at (3,1) got a label "(y)".
(0,0); \draw (0,0) -- (30:1cm); \foreach \x/\xtext
\path (0,0) node(x) {} (3,1) node(y) {}; \draw (x) -- (y);
in {1, 0.5/-\frac{1}{2}, 1} \draw (\x cm,1pt)
-(\x
cm,1pt)
node[anchor=north,ll=white]
Equivalent to
{$\xtext$}; \foreach \y/\ytext in {1, 0.5/\coordinate (x) at (0,0); \coordinate (y) at (3,1); \draw \frac{1}{2}, 0.5/\frac{1}{2}, 1} \draw (1pt,\y cm) -(1pt,\y cm) node[anchor=east,ll=white] {$\ytext$};
(x) -- (y);
\end{tikzpicture} \end{document}
Multiline text can be included inside a node. A new
line is indicated by double backslash "\\", but additionally Example 3: A Torus
you have to specify the alignment using the node option \documentclass{article}
\usepackage{tikz}
\bealign=". Here an example:
gin{document} \begin{tikzpicture} \draw (1,0)
\lldraw (0,0) circle (2pt) node[align=left, below] {test to[bend left] (1,0); \draw (1.2,.1) to[bend right]
1\\is aligned left} -- (4,0) circle (2pt) node[align=center, (1.2,.1); \draw[rotate=0] (0,0) ellipse (100pt and 50pt);
below] {test 2\\is centered} -- (8,0) circle (2pt) \end{tikzpicture} \end{document}
node[align=right, below] {test 3\\is right aligned};
Example 4: Some functions
Path construction operations try to be clever, such that the \documentclass{article}
\usepackage{tikz}
\bepath starts at the border of the nodes shape and not from gin{document}
\begin{tikzpicture}[domain=0:4]
the nodes center.
\draw[very thin,color=gray] (0.1,1.1) grid (3.9,3.9);
\path (0,0) node(x) {Hello World!} (3,1) \draw[->] (0.2,0) -- (4.2,0) node[right] {$x$};
node[circle,draw](y) {$\int_1^2 x \mathrm d x$}; \draw[->] (0,1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[->,blue] (x) -- (y); \draw[->,red] (x) -| node[near \draw[color=red] plot (\x,\x) node[right] {$f(x) =x$};
start,below] {label} (y); \draw[->,orange] (x) .. controls \draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x)
+(up:1cm) and +(left:1cm) ..
node[above,sloped] = \sin x$}; \draw[color=orange] plot (\x,{0.05*exp(\x)})
node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
{label} (y);
\end{tikzpicture} \end{document}

144

CHAPTER 7. CREATING GRAPHICS

7.5 LaTeX/PSTricks

\psline[linearc=0.2,->](0,0)(0.5,0.5)(1,1)

PSTricks is a set of extensions. The base package is


pstricks, other packages may be loaded when required.

Rectangles
The xcolor extension gets loaded along PSTricks, so there
is no need to load it manually.
\psframe(x0,y0)(x1,y1) \psframe*(x0,y0)(x1,y1)
PSTricks has one technical specication: it uses
PostScript internally, hence the name. Thus you cannot The starred version prints a lled rectangle. Use the foluse the pdftex or pdatex compilers, you will need to use lowing parameter to get rounded corners:
dvips to get your proper document. It is still possible to
get PDF from PS les thanks to ps2pdf. There is also the \psframe[framearc=0.2](x0,y0)(x1,y1)
possibility to use the PDFTricks extension, which makes
it feasible to use pdatex together with PSTricks commands.
Polygons
However, if you have installed the package xetex-pstricks,
you can use pstricks with xetex or xelatex without modi- Polygons are always closed. The syntax is the same as for
cation of source le.
\psline:

7.5.1

The pspicture environment

\pspolygon(x0,y0)(x1,y1)(x2,y3)...(xn,yn)

As for rectangles, the starred version prints a lled polyPSTricks commands are usually placed in a pspicture engon. And the linearc=0.2 option will print rounded corvironment.
ners.
\begin{pspicture}(x1,y1) % ... \end{pspicture}
The rst argument between parentheses species the co- Circles, arc and ellipses
ordinates of the upper-right corner of the picture. The
bottom-left corner is at (0,0) and is placed at the refer- Starred version lls the shape.
ence point of the next character in the LaTeX document. For circles, you need to provide center coordinates and
It is also possible to specify the coordinates (x0,y0) of the radius:
bottom-left corner:

\pscircle(x,y){r}

\begin{pspicture}(x0,y0)(x1,y1) % ... \end{pspicture}


To restrict the drawing to an arc, append the starting and
Thus the size of the picture is (x1-x0)x(y1-y0). The de- ending angles in trigonometric notation:
fault unit for coordinates is centimeters (cm); this can be \psarc(x,y){r}{angle1}{angle2}
changed with \psset, as in \psset{unit=1bp}. Any TeX
dimension is allowed.
Finally, ellipses:

7.5.2

Fundamental objects

\psellipse(x,y)(horizontal_axis,vertical_axis)

Lines and polylines


A simple line gets printed with

Curves

\psline(x0,y0)(x1,y1)

\psparabola(x0,y0)(x1,y1)

To get a vector, add an arrow as parameter:

will print a symetric parabola with vertical asymptote,


vertex (x1,y1) and ending at (x0,y0).

\psline{->}(x0,y0)(x1,y1)

Use \psbezier to print a Bzier curve with an arbitrary


number of control points. Arcs have at most 4 control
You can add as many points as you want to get a polyline: points. Use the showpoints=true option to print the con\psline(x0,y0)(x1,y1)(x2,y3)(xn,yn)
trol points and the tangents.
To get rounded corners, add the following option:

Use \pscurve to print the interpolation of the given points.


The \psecurve command omits the rst and the last arcs.

7.5. LATEX/PSTRICKS

7.5.3

145

Text

7.5.4 Grids

Use

Without any parameter, the \psgrid command will print


a grid all over the pspicture, with a spacing of 0.2 (i.e.
2mm). You can specify parameters:

\rput(x,y){text}
to print text. Provide an angle to rotate the text.

\psgrid(xmax,ymax): prints a grid from (0,0) to


(xmax,ymax).

\rput{angle}(x,y){text}
You can provide the anchor of the text which will be at
the specied coordinate.
\rput[t]{45}(5,5){text}
Available anchors:

\psgrid(x0,y0)(xmin,ymin)(xmax,ymax): prints a
grid from (xmin,ymin) to (xmax,ymax), one of the
node is at (x0,y0).
griddots=value: the full line of the main graduations
is replaced by a dotted line. The value is the number
of dots per graduation.

B, Bl, Br: baseline center, left and right.


t, tl, tr: top center, left and right.

subgriddots=value: same as griddots but for subgraduations.

b, bl, br: bottom center, left and right.


There is also the \uput command with further options:
\uput{distance}[angle](x,y){text}
The distance parameter is the distance from the coordinate.
PSTricks features several frame style for text.

gridcolor=color,subgridcolor=color: color of graduations and sub-graduations.


gridwidth=value,subgridwidth=value: width of the
lines.
subgriddiv=value: number of subgraduations between two main graduations.
gridlabels=value: size of the label numbers.

\psframebox{text}: rectangle.

ticksize=value: self-explanatory.

\psdblframebox{text}: double rectangle.

ticksize=valueneg valuepos: same as above, but valueneg species the size for negative coordinates, valuepos for positive coordinates.

\psshadowbox{text}: shaded rectangle.


\pstcirclebox{text}: circle.
\psovalbox{text}: oval.

ticklinestyle=value: self-explanatory. value may be


one of solid, dashed, dotted. This is useful for huge
graduations (i.e. ticksize is high).

\psdiabox{text}: diamond.
\pstribox{text}: triangle.

Example

Example:
\rput(5,5){\psdiabox*[llcolor=green]{text}}

\psgrid[griddots=5,
gridlabels=0pt](1,1)(5,5)

Using the pst-text extension, it is possible to draw a text


path.
\pstextpath{shape}{text}

\psgrid(xmin,ymin)(xmax,ymax): prints a grid from


(xmin,ymin) to (xmax,ymax).

subgriddiv=0,

Axis

If you want to add axes, use the pstricks-add extension


To print a text following a path without printing the path, with the following commands:
you need to use \psset{linestyle=none}.
\psaxes(xmin,ymin)(xmax,ymax)
\psaxes(x0,y0)(xmin,ymin)(xmax,ymax)
Example:
\usepackage{pst-text}
%
...
gin{pspicture}(5,5)
\psset{linestyle=none}
textpath{\psline(0,0)(1,1)(2,0)}{triangle
\end{pspicture}

\be\ps- (xmin,ymin) and (xmax,ymax) being the extreme, (x0,y0)


text} being the intersection.
Options

146

CHAPTER 7. CREATING GRAPHICS

Dx=value and Dy=value denes the spacing between graduations.

xunit=value and yunit=value

comma lets you use the comma as decimal separa- value is a number with or without unit. This changes the
scale of the drawings, but will not change the width of
tor.
lines.
As for lines, {->} adds arrows on axes.
Open shapes

Example

You can dene the extreme of an open shape (line, poly\usepackage{pstricks-add}


% line, arc, etc.) with an optional parameter {symbol1...
\begin{pspicture}(1,1)(5,5) symbol2}. There is a decent list of available symbols.
\psaxes[comma,Dx=0.5,Dy=0.5]{->}(0,0)(3,3)
\end{pspicture}
< or >: arrow.
<< or >>: double arrow.

7.5.5

Generic parameters

|: bar.

All shapes

|*: centered bar.

These are to be added between square brackets.

oo: circle.

linewidth=value: if value is without unit, then the


default unit is used.
linecolor=color: color is as dened by the xcolorpackage.
linestyle=value: value is one of dashed,dotted.
doubleline=true.
showpoints=true: highlights points.

o: centered circle.
**: disk.
*: centered disk.
|< or >|: arrow plus bar.
cc: rounded extreme.
c: centered rounded extreme.

dotscale=value species the size of the points. Example:


dotstyle=value where value is among:

\psline{|->>}(x0,y0)(x1,y1)

*: disc
o: circle
Closed shapes
+,x: cross
square, squarre*: starred version is lled.
For closed shape you may dene the llstyle.
diamond, diamond*
triangle, triangle*
llstyle=value: pattern. Possible values: crosshatch,
etc.
crosshatch*, vlines, vlines*, hlines, hlines*, solid.

For example

llcolor=color.

\pscircle[linewidth=0.2,linestyle=dashed,linecolor=blue](0,0){1}
hatchcolor=color.
To apply parameters globally:

hatchwidth=value.

\psset{linewidth=0.2,linestyle=dashed,linecolor=blue}
\pscircle(0,0){1}

hatchsep=value.
hatchangle=value.

This command also lets you change the default unit for
Example:
lengths.
\pscircle[hatchcolor=blue,llstyle=vlines](0,0){1}
unit=value

7.6. LATEX/XY-PIC

7.5.6

147

Object location

\end{pdfpic} % ... \end{document}

The \rput and \uput commands can be used to move any


Another way to use PSTricks with pdatex is the pst-pdf
object.
package.
Example
\begin{pspicture}(5,5)
\psline{->}(0,0)(1,1)
\rput(1,1){\psline{->}(0,0)(1,1)} \end{pspicture}

7.6 LaTeX/Xy-pic

or

xy is a special package for drawing diagrams. To use it,


\begin{pspicture}(5,5) \psline{->}(0,0)(1,1) \psline{- simply add the following line to the preamble of your doc>}(1,1)(2,2) \end{pspicture}
ument:
\usepackage[all]{xy}
You can repeat the operation with \multirput:
\multirput(x0,y0)(xoset, yoset){times}{object}

where all means you want to load a large standard set


of functions from Xy-pic, suitable for developing the kind
of diagrams discussed here.

You can use the same options as for \rput:


\multirput[reference]{angle}(x0,y0)(xoset,
set){times}{object}

yo- The primary way to draw Xy-pic diagrams is over a


matrix-oriented canvas, where each diagram element is
placed in a matrix slot:

With no text but with graphics only, you can use the \mul- The \xymatrix command must be used in math mode.
Here, we specied two lines and two columns. To make
tips command:
this matrix a diagram we just add directed arrows using
\multips(x0,y0)(xoset, yoset){times}{object} \mul- the \ar command.
tips{angle}(x0,y0)(xoset,yoset){times}{object}
The arrow command is placed on the origin cell for the
arrow. The arguments are the direction the arrow should
point to (up, down, right and left).

7.5.7

The PDFTricks extension

To make diagonals, just use more than one direction. In


fact, you can repeat directions to make bigger arrows.

The original PSTricks package does not work with pdatex, but thankfully PDFTricks allows us to bypass this We can draw even more interesting diagrams by adding
labels to the arrows. To do this, we use the common sulimitation.
perscript and subscript operators.
As shown, you use these operators as in math mode. The
only dierence is that that superscript means on top of
the arrow, and subscript means under the arrow. There
Declare the PDFTricks packages in the preamble.
is a third operator, the vertical bar: | It causes text to be
Place all PSTricks extensions in a psinputs environ- placed in the arrow.
ment; place all PSTricks commands in a pdfpic en- To draw an arrow with a hole in it, use \ar[...]|\hole. In
vironment.
some situations, it is important to distinguish between dif-

Usage

Compile with pdatex -shell-escape <le>.

ferent types of arrows. This can be done by putting labels


on them, or changing their appearance

The -shell-escape parameter enables shell command calls. Notice the dierence between the following two diagrams:
It is required for PDFTricks to run.
The modiers between the slashes dene how the curves
are drawn. Xy-pic oers many ways to inuence the
Example
drawing of curves; for more information, check the Xypic
documentation.
\documentclass{article}
\usepackage{pdftricks}
\begin{psinputs} \usepackage{pstricks} \usepackage{multido} \end{psinputs} % ... \begin{document}
% ...
\begin{pdfpic} \psset{unit=\linewidth} \begin{pspicture}(0,0)(10,10) [...]
\end{pspicture}

If you are interested in a more thorough introduction then


consult the Xy-pic Home Page, which contains links to
several other tutorials as well as the reference documentation.

148

7.7 LaTeX/Creating 3D graphics


For creating three-dimensional graphics, there is basic
functionality in the PGF/TikZ package, although drawing
3D graphics with PGF/TikZ is very non-exible, mainly
because it lacks functionality for identifying the surfaces
that are covered by other surfaces and should be excluded
from the rendered image.
A package that can handle this correctly is the pstsolides3d package.
Another way to create 3D graphics is to use Asymptote

CHAPTER 7. CREATING GRAPHICS

Chapter 8

Programming
8.1 LaTeX/Macros

digits cannot be used to name macros invalid characters will error out at compile-time.

Documents produced with the commands you have


learned up to this point will look acceptable to a large
audience. While they are not fancy-looking, they obey
all the established rules of good typesetting, which will
make them easy to read and pleasant to look at. However, there are situations where LaTeX does not provide
a command or environment that matches your needs, or
the output produced by some existing command may not
meet your requirements.

LaTeX will not allow you to create a new command that


would overwrite an existing one. But there is a special
command in case you explicitly want this: \renewcommand. It uses the same syntax as the \newcommand command.
In certain cases you might also want to use the \providecommand command. It works like \newcommand, but if
the command is already dened, LaTeX will silently ignore the new command.

In this chapter, we will try to give some hints on how to


With LaTex2e, it is also possible to add a default paramteach LaTeX new tricks and how to make it produce outeter to a command with the following syntax:
put that looks dierent from what is provided by default.
If the default parameter of \newcommand is present, then
LaTeX is a fairly high-level language compared to Plain
the rst of the number of arguments specied by num is
TeX and thus is more limited. The next chapter will focus
optional with a default value of default; if absent, then all
on Plain TeX and will explain advanced techniques for
of the arguments are required.
programming.

8.1.1

New commands

Note When the command is used with an explicit rst


parameter it is given enclosed with brackets (here
"[lots of users]").

To add your own commands, use the


command. Basically, the command requires two arguments: the name of the command you want to create,
and the denition of the command. Note that the command name can but need not be enclosed in braces, as
you like. The num argument in square brackets is optional
and species the number of arguments the new command
takes (up to 9 are possible). If missing it defaults to 0, i.e.
no argument allowed.

Here is a common example: if you are writing a book


about Mathematics and you have to use vectors, you have
to decide how they will look. There are several dierent
standards, used in many books. If a is a vector, some
people like to add an arrow over it ( a ), other people write
it underlined (a); another common version is to write it
The following two examples should help you to get the bold (a). Let us assume you want to write your vectors
idea. The rst example denes a new command called with an arrow over them; then add the following line in
\wbal that will print The Wikibook about LaTeX. Such your [Link].
a command could come in handy if you had to write the
and write your vectors inside the new \myvec{...} comtitle of this book over and over again.
mand. You can call it as you wish, but you'd better choose
The next example illustrates how to dene a new com- a short name because you will probably write it very ofmand that takes one argument. The #1 tag gets replaced ten. Then, if you change your mind and you want your
by the argument you specify. If you wanted to use more vectors to look dierently you just have to change the
than one argument, use #2 and so on, these arguments are denition of your \myvec{...}. Use this approach whenadded in an extra set of brackets.
ever you can: this will save you a lot of time and increase
Name your new command \wbalTwo and not \wbal2 as the consistency of your document.
149

150

CHAPTER 8. PROGRAMMING

DeclareRobustCommand

Also, if you're still having problems with extra space being appended at the end of your environment when using
Some commands are fragile, that is they fail in some en- the \input for external source, make sure there is no space
vironments. If a macro works in body text but not in (for between the beginning, sourcing, and end of the environexample) a gure caption, its worth trying to replace the ment, such as:
\newcommand{\MyCommand}... declaration with \De- or
clareRobustCommand{\MyCommand}... in the preamble. This is especially true for macros which, when expanded, produce text that is written to a .aux le.

8.1.3 declare commands within newenvironment

8.1.2

New environments

New commands can be declared within newenvironment.


Just as with the \newcommand command, there is a com- Commands declared within the newenvironment refer to
mand to create your own environments. The \newenvi- their arguments by doubling the # character. In the following example, a new environment is declared along
ronment command uses the following syntax:
with a nested command:
Again \newenvironment can have an optional argument.
When the \begin{name} command (which starts the en- If, by mistake, the arguments passed to the \topics macro
vironment) is encountered, the material specied in the are dened with a single # character, the following error
before argument is processed before the text in the en- message will be thrown:
vironment gets processed. The material in the after ar- ! Illegal parameter number in denition of \topics.
gument gets processed when the \end{name} command
(which ends the environment) is encountered.
The num argument is used the same way as in the \newcommand command. LaTeX makes sure that you do not
dene an environment that already exists. If you ever
want to change an existing command, you can use the
\renewenvironment command. It uses the same syntax as
the \newenvironment command.

8.1.4 Extending the number of arguments


The xkeyval packages will let you dene key/value options for commands.

The package is quite complete and documentation is exhaustive. We recommend that package developers read
The example below illustrates the usage of the \newenvi- it.
ronment command:
Lets provide a simple example[1] :
Unmatched braces
Often, part of the motive behind creating an environment
is to surround its body in a grouping of braces. However, this requires unmatched braces to appear in both the
beginning and end portions of the environment declaration, which will prevent the document from compiling.
To solve this issue, use the TeX synonyms \bgroup and
\egroup instead of typing { and } in this case.

Extra space
When creating a new environment you may easily get
bitten by extra spaces creeping in, which can potentially
have fatal eects. For example when you want to create a
title environment which suppresses its own indentation as
well as the one on the following paragraph. The \ignorespaces command in the begin block of the environment
will make it ignore any space after executing the begin
block. The end block is a bit more tricky as special processing occurs at the end of an environment. With the
\ignorespacesafterend LaTeX will issue an \ignorespaces
after the special end processing has occurred.

8.1.5 Arithmetic
LaTeX can manipulate numbers.
The calc package provides the common inx notation.
For high-precision computations, you can use the fp package.

8.1.6 Conditionals
LaTeX can use conditionals thanks to the ifthen package.

8.1.7 Loops
The PGF/TikZ extension provides the \foreach command.
If you are only using \foreach and not drawing graphics,
you may instead use the pgor package directly.
Alternatively you can check out the multido package.

8.2. LATEX/PLAIN TEX

8.1.8

151

8.2 LaTeX/Plain TeX

Strings

xstring provides a lot of features. From CTAN:

While you play with LaTeX macros, you will notice that it
is quite limited. You may wonder how all these packages
you are using every day have been implemented with so
little. In fact, LaTeX is a set of Plain TeX macros and
most packages use Plain TeX code. Plain TeX is much
more low-level, it has much more capabilities at the cost
of a steep learning curve and complex programming.

testing a strings contents


extracting substrings
substitution of substrings
string length

Up to a few exceptions, you can use the full Plain TeX


language within a valid LaTeX document whereas the opposite is false.

position of a substring
number of recurrences of a substring
Examples:

8.2.1 Vocabulary

8.1.9

To avoid confusion it seems necessary to explain some


terms.

LaTeX Hooks

LaTeX provide two hooks:


\AtBeginDocument will let you specify a set
of commands that will be executed when \begin{document} is met.
\AtEndDocument
\end{document}.

does

the

same

For instance, lets replace the page numbers with oldstylenums:

8.1.10

A token is a character, a control sequence, or a


group.

for

This gives you some more exiblity for macros. It can


be useful to override settings that get executed after the
preamble. These hooks can be called several times. The
commands will be executed in the order they were set.

There are also hooks for classes and packages.


Creating Packages.

A group is everything after an opening brace and


before the matching closing brace.

See

Command-line LaTeX

If you work on a Unix-like OS, you might be using Makeles or any kind of script to build your LaTeX projects.
In that connection it might be interesting to produce different versions of the same document by calling LaTeX
with command-line parameters. If you add the following
structure to your document:

A control sequence is anything that begins with a \. It


is not printed as is, it is expanded by the TeX engine
according to its type.
A command (or function or macro) is a control sequence that may expand to text, to (re)denition of
control sequences, etc.
A primitive is a command that is hard coded in the
TeX engine, i.e. it is not written in Plain TeX.
A register is the TeX way to handle variables. They
are limited in numbers (256 for each type of register).
A length is a control sequence that contains a length
(a number followed by a unit). See Lengths.
A font is a control sequence that refers to a font le.
See Fonts.

A box is an object that is made for printing. Anything that ends on the paper is a box: letters, paralatex '\providecommand{\blackandwhite}{true}\input{[Link]}' graphs, pages... See Boxes.
Now you can call LaTeX like this:

First the command \blackandwhite gets dened and then


the actual le is read with input. By setting \blackandwhite to false the color version of the document would be
produced.

8.1.11

Notes and References

[1] [Link]

A glue is a certain amount of space that is put between boxes when they are being concatenated.
A counter is a register containing a number. See
Counters.
There may be more terms, but we hope that it will do it
for now.

152

8.2.2

CHAPTER 8. PROGRAMMING

Catcodes

In TeX some characters have a special meaning that is not


to print the associated glyph. For example, \ is used to introduce a control sequence, and will not print a backslash
by default.

\makeatletter and \makeatother


If you have done a bit of LaTeX hacking, you must
have encountered those two commands, \makeatletter
and \makeatother.

In TeX the '@' characters belongs to catcode 11 letters by


To distinguish between dierent meanings of the charac- default. It means you can use it for macro names. LaTeX
ters, TeX split them into category codes, or catcodes for makes use of the catcode to specify a rule: all non-public,
internal macros that are not supposed to be accessed by
short. There are 16 category codes in TeX.
the end-user contains at least one '@' character in their
A powerful feature of TeX is its ability to redene the
name. In the document, LaTeX changes the catcode of
language itself, since there is a \catcode function that will
'@' to 12, others.
let you change the category code of any characters.
Thats why when you need to access LaTeX internals, you
However this is may be bad practice and lead to unreadmust enclose all the commands accessing private funcable code, especially if you are not working alone on your
tions with \makeatletter and \makeatother. All they do is
document. Should you redene any catcode in a class or
just changing the catcode:
in a style le, make sure to revert it back at the end of
your le.
If you redene catcodes in your document, make sure to 8.2.3 Plain TeX macros
do it after the preamble to prevent clashes with package
\newcommand and \renewcommand are LaTeX-specic
loading.
control sequences. They check that no existing command
gets shadowed by the new denition.
Active characters
In Plain TeX, the primitives for macro denition make no
check on possible shadowing. Its up to you to make sure
Active characters resemble macros: they are single char- you are not breaking anything.
acters that will expand before any other command.
The syntax is
Note that an active character needs to be directly followed
You can use (almost) any sequence of character between
by a denition, otherwise the compilation will fail.
arguments. For instance lets write a simple macro that
will convert the decimal separator from point to comma.
First try:
Examples
This will print (123,4)56. We added the parentheses just
to highlight the issue here. Each parameter is the shortest
possible input sequence that matches the macro deniTexinfo uses a syntax similar to TeX with one major dif- tion, separators included. Thus #1 matches all characters
ference: all functions are introduced with a @ instead of up to the rst point, and #2 matches the rst token only,
a \. This is not by chance: it actually uses TeX to print i.e. the rst character, since there is no separator after it.
the PDF version of the les. What it basically does is in- Solution: add a second separator. A space may seem conputting [Link] which redenes the control sequence venient:
character. Possible implementation:
As a general rule, everytime you expect several parameWith this redenition, the '@' should now introduce ev- ters with specic separators, think out the last separator.
ery command, while the '\' will actually print a backslash If you do not want to play with separators, then Plain TeX
character.
macros are used just as LaTeX macros (without default
parameter):
Itemize
Texinfo

Expanded denitions
Some may nd the LaTeX syntax of list environments a
bit cumbersome. Here is a quick way to dene a wiki-like TeX has another denition command: \edef, which stands
itemize:
for expanded def. The syntax remains the same:
The content gets expanded (but not executed, i.e. printed)
at the point where \edef is used, instead of where the dened macro is used. Macro expansion is not always obIf you have many 'dollar' symbols to print, you may be vious...
better o to change the math shift character.
Example:
Dollar and math

8.2. LATEX/PLAIN TEX

153

Here the redenition of \intro will have no eect on \ex- \futurelet<csname><token1><token2>... works a bit difample.
ferently. token2 is assigned to csname; after that TeX
processes the <token1><token2>... sequence. So \futurelet allows you to assign a token while using it right
Global denitions
after.
Denitions are limited to their scope. However it might
be convenient sometimes to dene a macro inside a group Special control sequence name
that remain valid outside the group, and until the end of
Some macros may have a name that is not directly
the document. This is what we call global denitions.
writable as is. This is the case of macros whose name
You can also use the \global command with \edef.
is made up of macro names. Example:
Both commands have a shortcut:
The last line will print a sentence depending on the \status.
\gdef for \global\def

This command actually does the opposite of \string which


prints a control sequence name without expanding it:

\xdef for \global\edef


Controlling expansion
Long denitions

\expandafter{token1}{token2} will expand token2 beThe previous denition commands would not allow you fore token1. It is sometimes needed when token2 expanto use them over multiple paragraphs, i.e. text containing sion is desired but cannot happen because of token1.
the \par command -- or double line breaks.
\noexpand is useful to have ne grained control over what
You can prex the denition with the \long command to gets expanded in an \edef. Example:
allow multi-paragraph arguments.
Example:
Outer denitions

\the control sequence will let you see the content of various TeX types:
catcodes
chardef

This prex macro prevent denitions from being used in


some context. It is useful to consolidate macros and make
them less error-prone because of bad contexts. Outer
macros are meant to be used outside of any context, hence
the name.

font parameters

For instance the following code will fail:

registers

Outer macros are not allowed to appear in:

...

macro parameters

internal parameters
lengths

Example:

skipped conditional
...
let and futurelet

8.2.4 Registers
Registers are kind of typed variables. They are limited
in numbers, ranging from 0 to 255. There are 6 dierent
types:

\let<csname><token> is the same as \ex- TeX uses some registers internally, so you would be better
pandafter\def\expandafter<csname>\expandafter{<content>}.
o not using them.
It denes a new control sequence name which is equivalent to the specied token. The token is usually another List of reserved registers:
control sequence.
\box255 is used for the contents of a page
Note that \let will expand the token one time only, contrary to \edef which will expand recursively until no fur \count0-\count9 are used for page numbering
ther expansion is possible.
Example[1] :

Scratch registers (freely available):

154

CHAPTER 8. PROGRAMMING

\box0-\box254
\count255
\dimen0-\dimen9
\muskip0-\muskip9

depending on which value we want to set in our conditional.


3. Now we can use our conditional anywhere after in an
if control structure.
A full example is:

\skip0-\skip9
Case statement
Assign register using the '=' control character. For box
registers, use the \setbox command instead.
The
syntax
is
\ifcase
<numYou may use one of the following reservation macro to ber><case0>\or<case1>\or...\else<defaultcase>\.
If number is equal to the case number, its content will be
prevent any clash:
printed. Note that it starts at 0.
These macros use the following syntax: \new*<csname>.
\else is used to specify the default case (whenever none of
Example:
the previous cases have matched).
These commands can not be used inside macros, otherwise every call to the macro would reserve another register.
You can print a register using the \the command. For 8.2.7 Loops
counters use the \number command instead. For boxes
The base syntax is
use the \box command.
As always, content and true action are arbitrary TeX contents. \if* refers to any of the conditionals. Note that
8.2.5 Arithmetic
there is no false action, you cannot put an \else between
\if* and \repeat. In some case this will be the opposite
The arithmetic capabilities of TeX are very limited, alof what you want; you have to change the condition or to
though this base suce to extend it to some interesting
dene a new conditional using \newif. Example:
features. The three main functions:
The above code will print TeX ten times.
register may be of type count, dimen, muskip or skip. It
does not make sense for box nor toks.

8.2.6

Conditionals

8.2.8 Doing nothing

where \if* is one command among the following.

Sometimes it may be useful to tell TeX that you want to


do nothing. There is two commands for that: \relax and
\empty.

Example:

Classic example:

Self dened conditionals

The \relax prevents undesired behaviour if a plus or a minus is encounter after the command.

The base syntax is

The dierence between \empty and \relax lies in the exYou can create new conditionals (as a kind of boolean pansion: \empty disappears after macro expansion.
variables) with the \newif command. With this self dened conditionals you can control the output of your code
in an elegant way. The best way to illustrate the use of
8.2.9 TeX characters
conditionals is through an example.
Two versions of a document must be generated. One version for group A the other one for the rest of people (i.e. char
not belonging to group A):
We can print all characters using the \char {charcode}
1. We use \newif to dene our conditional (i.e. boolean command. The charcode is actually the byte value. For
variable).
example
2. In the following way we set a value (true or false) for Most characters correspond to the ASCII value (e.g. Aour conditional
Za-z), some replace the non-printable characters from
that is:

ASCII.

8.3. LATEX/CREATING PACKAGES

155

chardef and mathchardef

Another problem arises: how to dene a command whose


name is a variable? In most programming languages thats
You can dene control sequence to expand to a not possible at all. What we could be tempted to write is
specic char.
The syntax is \chardef<control seIt will fail for two reasons.
quence>=<charcode>. The following sequences do the
same thing.
1. The two last '#1' are supposed to refer to the arguExample:
ments of the new macro, but they get expanded to
the \localedef macro rst argument because they are
in the body of that macro.
Font encoding map
2. \#1 gets expanded to two tokens: '#' and '1', and the
We can use the above primitive to print the font encoding
\def command will fail as it requires a valid control
map.
sequence name.
Another version, with dierent fonts, one entry per line:

8.2.10

Verbatim lines and spaces

8.2.11

Macros dening macros

The solution to problem 1 is simple: use '##1', which will


expand to '#1' when the macro is executed.

For problem 2, it is a little bit tricky. It is possible to


tell tex that a specic token is a control sequence. This is
It is rather confusing to discover (La)TeX treats all what the \csname...\endcsname is used for. However
whitespace as the same type of spacing glue. Plain TeX
provides some commands to preserve the spacing and will fail because it will redene \csname to '#1', which is
not what we want, then tex will encounter \endcsname,
newlines as you wrote it:
which will result in an error.
which means that you will probably need to combine your
We need to delay the expansion of \def, i.e. to
own verbatim environment, and your command:
tell tex to expand the \csname stu rst, then to apand then in your tex le:
ply \def on it. There is a command for that: \expandafter{token1}{token2}. It will expand {token2} before {token1}.
Finally if we want to set language from command line, we
This is useful in some case, for example to dene lan- must be able to set the \locale variable so that the one in
guage commands as explained in Multilingual versions, the source code is the default value that can be overridden
by the one in the command line. This can be done with
where the end user can write
\provdecommand:
and make sure it switches to the appropriate Babel lanThe nal code is
guage.
Lets dene a macros that will dene language commands And you can compile with
for instance. These commands are simple: if the argu- latex '\providecommand\locale{en}\input{[Link]}'
ment is the value of the \locale variable, then the corresponding macro prints its content directly. Otherwise, it
does nothing.
8.2.12 Notes and References
Basicly, what we want to do is extremely simple: dene a
bunch of macros like this:

[1] From [Link]: What is the dierence between \let and \edef?

In the previous snippet of code, only the \de command in


going to output its content, \en and \fr will print nothing Further reading
at all. Thats what we want. The problem arises when
you want to automate the task, or if you have a lot of
The TeXbook, Donald Knuth
languages, and you want to change the language selection.
TeX by Topic, Victor Eijkhout
You just have to move the #1, but thats not convenient
and it makes it impossible to choose the Babel language
TeX for the Impatient, Paul W. Abrahams, Karl
from command line. Think this out...
Berry and Kathryn A. Hargreaves
What we are going to do is to dene the language commands dynamically following the value of the \locale variable (or any variable of your choice). Hence the use of 8.3 LaTeX/Creating Packages
the \equal command from the ifthen package.
Since it is hardly possible to write it in LaTeX, we will If you dene a lot of new environments and commands,
the preamble of your document will get quite long. In
use some Plain TeX.

156

CHAPTER 8. PROGRAMMING

this situation, it is a good idea to create a LaTeX package


or class containing all your command and environment
denitions. It can be made dynamic enough to t to all
your future documents.

Write whatever you want in it using all the LaTeX


commands you know. Normally you should dene
new commands or import other packages.

By default, LaTeX will allow the use of the '@' characters


for control sequences from within package and class les,
but not from within an end-user document. This way it is
possible to protect commands, i.e. to make them accessible from packages only.

For a more convenient use, it is possible to place the


package within $TEXMFHOME (which is ~/texmf by
default) accoding to the TeX Directory Structure (TDS).
That would be

Your package can be made available in your document


just like any other package: using the \usepackage command. Writing a package basically consists of copying
the contents of your document preamble into a separate
le with a name ending in .sty.

8.3.3 Creating your own class

\endinput: this must be the last command.


Classes are .cls les, package are stored in .sty les. They
are very similar, the main dierence being that you can
Once your package is ready, we can use it in any docload only one class per document.
ument. Import your new package with the known command \usepackage{mypack}. The le [Link] and the
LaTeX source you are compiling must be in the same di8.3.1 makeatletter and makeatother
rectory.

$TEXMFHOME/tex/latex/custom/[Link]
However it is possible to override this security with the On Windows '~' is often C:\Users\username.
duo \makeatletter and \makeatother. These commands
only make sense in a regular document, they are not You may have to run texhash (or equivalent) to make your
TeX distribution index the new le, thus making it availneeded in package or class les.
able for use for any document. It will allow you to use
your package as detailed above, but without it needing to
be in the same directory as your document.
8.3.2 Creating your own package

Lets write a rst [Link] le as an example package:

It is also possible to create your own class le. The process is similar to the creation of your own package, you
can call your own style le in the preamble of any document by the command:

The name of the class le is then [Link]. Lets write


\NeedsTeXFormat{...} species which version of a simple example:
TeX or LaTeX is required at least to run your package. The optional date may be used to specify the
\ProvidesClass is the counterpart of \ProvidesPackversion more precisely.
age.
\ProvidesPackage has to have the same name of the
le without the extension. It tells LaTeX the name
of the package and will allow it to issue a sensible
error message when you try to include a package
twice. The date is important since it can be used
by other package to specify the minimum version
requirement they need to use your package.
Next you may write some TeX or LaTeX code like
loading package, but write only the bare minimum
needed for the package options set below.
\RequirePackage is equivalent to \usepackage.

\PassOptionsToClass and \PassOptionsToPackage


are used to automatically invoke the corresponding
options when the class or the package is loaded.
\DeclareOption*: the starred version lets you handle
non-implemented options.
\ClassWarning will show the corresponding message
in the TeX compiler output.
\LoadClass species the unique parent class, if any.

8.3.4 Hooks

\DeclareOptions are end-user parameters. Each op- There are also hooks for classes and packages.
tion is declared by one such command.
\AtEndOfPackage
\ExecuteOptions{...} tells which are the default.
\AtEndOfClass
\ProcessOptions\relax terminates the option processing.
They behave as the document hooks. See LaTeX Hooks.

8.4. LATEX/THEMES

157

8.4 LaTeX/Themes

8.4.5 Sectioning

Newcomers to LaTeX often feel disappointed by the lack


of visual customization oered by the system. Actually
this is done on purpose: the LaTeX philosophy takes a
point at doing the formatting while the writer focuses on
the content.

This is denitely the most complex part. It is not that hard


since the code is almost the same for \section, \subsection
and \subsubsection.

We use \needspace to make sure there is no line break


right after a sectioning command. We enclose the comIn this chapter, we will show what we can achieve with mand in a group where we set a font size since the space
we need is \baselineskip which depends on the font size.
some eorts.
Starred commands will not set the counters (LaTeX detault behaviour). You can choose to handle starred com8.4.1 Introduction
mand dierently by resetting the counters for instance.
We preceed the section printing by a \noindent. We make
In the following we will write the theme, a package that
sure to end the section printing by a \par command to
will only change the appearance of the document, so that
make sure following text gets printed properly.
our document will work with or without the theme.
For \subsection we make use of the mirrors option to
Note that if it may look eye-candy, this is absolutely not a
change the appearance accordingly.
model of typography. You should not use such theme for
serious publications. This is more a technogical example To handle the PDF bookmarks properly we need the following lines at the end of the denitions.
to exhibit LaTeX capabilities.
Custom theme (TOC)
Custom theme
Custom theme (red)

8.4.2

Package conguration

Nothing much to say here. This is a direct application of


the Creating Packages chapter.
We load the required packages.
needspace is used to prevent page break right after
a sectioning command.
tikz is used to draw the fancy material.
We dene a color option, you may use as much as you
want. Dening colors with specic names makes it very
exible. We also use an option to toggle the fancy reection eect which might be a little too much!

8.4.3

Header and footer

We use TikZ to draw a lled semicircle.


fancyhdr is used to set header and footer. We take care of
using the fancy style and to start from scratch by erasing
the previous header and footer with \fancyhf{}.

8.4.4

Table of contents

We redene commands used by \tableofcontents.

Finally, for \section only, we want it to print in the header,


so we call the \sectionmark command. Here we changed
the behaviour of the starred command over the original
LaTeX version, since we dene and use the \sectionmarkstar command.

8.4.6 Notes and References

Chapter 9

Miscellaneous
9.1 LaTeX/Modular Documents

book. In such cases it is good practice to split your work


into several les. For example, if you are writing a book,
During this guide we have seen what is possible to do and it makes a lot of sense to write each chapter in a sepahow this can be achieved, but the question is: I want to rate .tex le. LaTeX makes this very easy thanks to two
write a proper text with LaTeX, what to do then? Where commands:
should I start from? This is a short step-by-step guide \input{lename}
about how to start a document properly, keeping a good
high-level structure. This is all about organizing your les
and
using the modular capabilities of LaTeX. This way it will
be very easy to make modications even when the doc- \include{lename}
ument is almost nished. These are all just suggestions,
but you might take inspiration from that to create your The dierences between these two ways to include les
own document.
will be explained below. What they have in common is

9.1.1

Project structure

Create a clear structure of the whole project this way:


1. create a directory only for the project. We'll refer to
that in the following parts as the root directory
2. create two other directories inside the root, one for
LaTeX documents, the other one for images. Since
you'll have to write their name quite often, choose
short names. A suggestion would be simply tex and
img.

that they process the contents of [Link] before continuing with the rest of the base le. When the compiler
processes your base le (the le that contains these statements) and reaches the command \input or \include, it
reads [Link] and processes its content in accordance
with the formatting commands specied in the base le.
This way you can put all the formatting options in your
base le and then \input or \include the les which contain the actual content of your work. This means that the
important part of your working process, i.e. writing, is
kept largely separate from formatting choices (which is
one of the main reasons why LaTeX is so good for serious writing!). You will thus be dealing solely with text
and very basic commands such as \section, \emph etc.
Your document will be uncluttered and much easier to
work with.

3. create your document (we'll call it [Link],


but you can use the name you prefer) and your own
package (for example [Link]); this second le
The second method of including a le, \inwill help you to keep the code cleaner.
clude{lename}, diers from the rst in some important
ways. You cannot nest \include statements within a le
If you followed all those steps, these les should be in added via \include, whereas \input, on the other hand,
your root directory, using "/" for each directory:
allows you to call les which themselves call other les,
ad innitum (well, nearly!). You can, however, \include
./[Link] ./[Link] ./tex/ ./img/
a le which contains one or more \input commands.
nothing else.
Please resist the temptation to nest les in this way
simply because the system can do it: you will end up
with just another kind of complexity!

9.1.2

Getting LaTeX to process multiple


Another important dierence is that using \include will
les

force a page break (which makes it ideal for a books


As your work grows, your LaTeX le can become un- chapters), whereas the \input command does not (which
wieldy and confusing, especially if you are writing a long in turn makes it ideal for, say, a long article with discrete
article with substantial, discrete sections, or a full-length sections, which of course are not normally set on a new
158

9.1. LATEX/MODULAR DOCUMENTS

159

page).

will have exactly the same eect as writing

In either case the .tex lename extension is optional.

\input{[Link]}

Working on discrete parts of your documents has consequences for how the base le is compiled; these will be but if you found it more convenient to put all your les in
dealt with below.
a sub-directory of your current directory, called myles,
you would refer to that le by specifying
Using dierent paths

\input{./myles/[Link]}

When the LaTeX compiler nds a reference to an external Indeed, in our example of the absolute path above, you
le in the base le, it will look for it in the same directory. could refer to that le relatively, too:
However, you can in principle refer to any le on your \input{../../documents/useful/[Link]}
system, using both absolute and relative paths.
An absolute path is a full path- and lename with every Of course, all commonly used le systems Linux, Mac
element specied. So, [Link] might have the full OS X and Windows also feature the UNIX ./, ../ facilpath,
ity outlined above. Do note, however, that LaTeX uses
forward slashes / even on Microsoft Windows platforms,
\input{/home/user/texles/[Link]}
which use backslashes \ in pathnames. LaTeX implementations for Windows systems perform this conversion
If you had created the directory myles for your writing
for you, which ensures that your document will be valid
project, in your texles directory, its full path would be,
across all installations.
\input{/home/user/texles/myles/[Link]}
This exibility, inherent in the way in which LaTeX is
integrated with modern le systems, lets you input les in
Obviously, using absolute paths is inecient if you are a way which suits your particular set-up.
referring to a le in the current directory. If, however,
When using relative paths within a LaTeX le imported
you need to include a le which is always kept at a specic
by \input or \include, it is important to note that the paths
place in your system, you may refer to it with an absolute
are relative to the directory in which the main .tex le repath, for example,
sides, not to the directory in which the included (or input)
\input{/home/user/documents/useful/[Link]}
le is found. This is likely to be an issue if using a folder
per chapter, with the gures in each chapters folder, and
In practice, an absolute le path is generally used when using \include to read the chapter source into a main Laone has to refer to a le which is quite some way away TeX le in a parent folder.
in the le system (or perhaps even on a dierent server!).
One word of warning: do not leave empty spaces in the
lenames, they can cause ambiguous behaviour. Either Compiling the base le
leave no spaces or use underscores _ instead.
When you compile your document, page references and
You may, however, need to make your source portable
(to another computer or to a dierent location of your the like will change according to your use of the \input
and \include commands. Normally LaTeX users only run
harddisk), in which case relative paths should be used if
you wish to avoid unnecessary rewriting of path names. the compiler on parts of the document to check that an
individual chapter is syntactically correct and looks as the
Or, a relative path may simply be a more ecient and
elegant way of referring to a le. A relative path is one writer intended. A full run is generally only performed for
which is dened in relation to the current directory, in our producing a full draft or the nal version. In such cases,
case the one which contains the base le. LaTeX uses the it is invariably necessary to run LaTeX twice or more to
standard UNIX notation: with a simple dot . you refer to resolve all the page numbers, references, etc. (especially
the current directory, and by two dots .. you refer to the if you are using bibliographic software such as BiBTeX,
previous directory, that is the one above the current direc- too).
tory in the le system tree. The slash / is used to separate
the dierent components of a pathname: directories and
lenames. So by ./ you refer to the current directory, by
../ you refer to the previous directory, by ../../ you refer to
a directory which is two steps upwards in the lesystem
tree. Writing
\input{./[Link]}

The simplest way to check that one or more of the various components of your work is syntactically robust, is
to comment out the command with a percentage sign, for
example:
\documentclass{article}
\begin{document}
%\input{Section_1}
%\input{Section_2}
%\input{Section_3} \input{Section_4} %\input{Section_5}
\end{document}

160

CHAPTER 9. MISCELLANEOUS

Instead of using \input and \include, child documents


This code will process your base le with the article con- must be loaded as follows:
ventions but only the material in the le Section_4.tex will \suble{lename}
be processed. If that was, say, the last thing you needed
to check before sending o to that major journal, you
The child documents must start with the following statewould then simply remove all the percentage signs and ments:
rerun LaTeX, repeating the compiling process as neces\documentclass[[Link]]{subles} \begin{document}
sary to resolve all references, page numbers and so on.
Using \includeonly

and end with:

\end{document}
Using this command provides more complex, and hence
more useful possibilities. If you include the follow- In summary, the base document ([Link]) looks like:
ing command in your preamble, i.e. before \be\documentclass{book}
\usepackage{subles}
\begin{document},
gin{document} %% my document content \sub\includeonly{lename1,lename2,...}
le{chapter1} %% more of my document content
\end{document}
only the les specied between the curly braces will be
included. Note that you can have one or more les as the and Chapter 1 ([Link]) looks like:
argument to this command: separate them with a comma,
\documentclass[[Link]]{subles} \begin{document}
no spaces.
%% my chapter 1 content %% %% more of my chapter
This requires that there are \include commands in the 1 content \end{document}
document which specify these les. The lename should
be written without the .tex le extension:
Some linux distributions don't have subles package in
\documentclass{book}
\in- their latex distributions, since it was not included until
cludeonly{Chapter_1,Chapter_4} % compile just TeXLive 2012. You can download [Link] from
chapters 1 and 4, space characters not permitted \be- CTAN. This package will contain two les [Link]
gin{document} \include{Chapter_1} % omit the '.tex' and [Link]. Move these les to a directory under
extension \include{Chapter_2} \include{Chapter_3} the name subles in the path /usr/share/texmf/tex/latex.
\include{Chapter_4} \end{document}
This still won't make the package available; the texhash
program must be executed rst. Now you are good to go!
This code would process the base le but only include the
content of the authors rst and fourth chapters (Chapter_1.tex and Chapter_4.tex). Importantly, this alterna- Standalone The standalone package is designed for
tive retains as much of the .aux information as possible moving more of the opposite direction than subles. It
from the previous run, so messes up your cross-references provides a means for importing the preamble of child
much less than the makeshift suggestion above.
documents into the main document, allowing for a exiSeparate compilation of child documents

ble way to include text or images in multiple documents


(e.g. an article and a presentation).
In the main document, the package must be loaded as:

A disadvantage of solely using \input and \include is that


only the base document can be compiled. However, you
may decide that you work better on individual sections of
text and wish to edit and compile those separate from the
main le. There are a few packages available to address
this problem.

\usepackage{standalone}
Child documents are loaded using \input or \include.
The child documents contain, for example, the following
statements:

\documentclass{standalone} % Load any packages


Subles The subles package provides a way to com- needed for this document \begin{document} % Your
pile sections of a document using the same preamble as document or picture \end{document}
the main document.
In the main document, the package must be loaded as:

In summary, the base document ([Link]) looks like:

\usepackage{subles}

\documentclass{book}
\usepackage{standalone}
\begin{document} %% my document content \in-

9.1. LATEX/MODULAR DOCUMENTS

161

put{chapter1} %% more of my document content pasted within your document.


\end{document}
While writing, whenever you have to take a decision about
formatting, dene your own command for it and add it to
and Chapter 1 ([Link]) looks like:
your [Link]:let LaTeX work for you. If you do so, it
will be very easy to change it if you change your mind.
\documentclass{standalone}
%
Preamble
\begin{document} %% my chapter 1 content %% %% This is actually the beginning of the process of writing a
more of my chapter 1 content \end{document}
package. See LaTeX/Macros for more details.
For a list of several packages you can use, see the List of
Packages section.
Inserting PDF les
If you need to insert an existing, possibly multi-page,
PDF le into your LaTeX document, whether or not the
included PDF was compiled with LaTeX or another tool,
consider using the pdfpages package. In the preamble,
include the package:
\usepackage[nal]{pdfpages}

9.1.4 The main document [Link]


Then create a le called [Link]; this will be the
main le, the one you will compile, even if you shouldn't
need to edit it very often because you will be working on
other les. It should look like this (its the sample code
for a report, but you might easily change it to article or
whatever else):

This package also allows you to specify which pages you \documentclass[12pt,a4paper]{report}
\usepackwish to include: for example, to insert pages 3 to 6 from age{graphicx} \usepackage{ifpdf} \ifpdf % put here
some le [Link], use:
packages only for the PDF: \DeclareGraphicsExtensions{.pdf,.png,.jpg,.mps}
\usepackage{hyperref}
\includepdf[pages=3-6]{[Link]}
\else % put here packages only for the DVI: \ % put
all the other packages here: \usepackage{mystyle}
To insert the whole of [Link]:
\begin{document} \input{./tex/[Link]} %\maketi\includepdf[pages=-]{[Link]}
tle \tableofcontents \listogures \listoftables \input{./tex/[Link]}
\input{./tex/main_part.tex}
\input{./tex/[Link]}
\appendix
\inFor full functionality, compile the output with pdatex.
put{./tex/[Link]} % Bibliography: \clearpage
Additional information can be found in the chapter \addcontentsline{toc}{chapter}{Bibliography}
\inExport To Other Formats.
put{./tex/[Link]} \end{document}

9.1.3

The le [Link]

Instead of putting all the packages you need at the beginning of your document as you could, the best way is
to load all the packages you need inside another dummy
package called mystyle you will create just for your document. The good point of doing this is that you will just
have to add one single \usepackage in your document,
keeping your code much cleaner. Moreover, all the info
about your style will be within one le, so when you will
start another document you'll just have to copy that le
and include it properly, so you'll have exactly the same
style you have used.
Creating your own style is very simple: create a le called
[Link] (you could name it as you wish, but it has to
end with ".sty). Write at the beginning:
\ProvidesPackage{mystyle}

Here a lot of code expressed in previous sections has been


used. At the beginning there is the header discussed in the
Tips & Tricks section, so you will be able to compile in
both DVI and PDF. Then you import the only package
you need, that is your [Link] (note that in the code
it has to be imported without the extension), then your
document starts. Then it inserts the title: we don't like
the output of \maketitle so we created our own, the code
for it will be in a le called [Link] in the folder called
tex we created before. How to write it is explained in the
Title Creation section. Then tables of contents, gure and
tables are inserted. If you don't want them, just comment
out those lines. Then the main part of the document in
inserted. As you can see, there is no text in [Link]:
everything is in other les in the tex directory so that you
can easily edit them. We are separating our text from the
structural code, so we are improving the What You See is
What You Mean nature of LaTeX. Then we can see the
appendix and nally the Bibliography. It is in a separate
le and it is manually added to the table of contents using
a tip suggested in the Tips & Tricks.

Then add all the packages you want with the standard
command \usepackage{...} as you would do normally,
change the value of all the variables you want, etc. It Once you have created your [Link] you won't need
will work like the code you put here would be copied and to edit it anymore, unless you want to add other les in the

162

CHAPTER 9. MISCELLANEOUS

tex directory, but this is not going to happen very often.


Now you can write your document, separating it into as
many les as you want and adding many pictures without
getting confused: thanks to the rigid structure you gave
to the project, you will be able to keep track of all your
edits clearly.
A suggestion: do not give your les names like chapter_01.tex or gure_03.png, i.e. try to avoid using
numbers in le-names: if the numbering LaTeX gives
them automatically, is dierent from the one you gave
(and this will likely happen) you will get really confused.
When naming a le, stop for a second, think about a short
name that can fully explain what is inside the le without
being ambiguous, it will let you save a lot of time as soon
as the document gets larger.

9.1.5

External Links

Subles package documentation


Standalone package documentation
pdfpages package documentation

9.2 LaTeX/Collaborative Writing


of LaTeX Documents
Note: This Wikibook is based on the article Tools for
Collaborative Writing of Scientic LaTeX Documents by
Arne Henningsen that is published in The PracTeX Journal 2007, number 3 ([Link]

9.2.1

Abstract

such it does not allow you to roll the article back to


previous versions.
You can use an online collaborative tool built on top
of a versioning control system, such as Authorea.
Authorea performs most of the actions described in
this document, but in the background (it is built on
Git). It allows authors to enter LaTeX or Markdown
via a GUI with mathematical notation, gures, [Link]
plots, IPython notebooks, data, and tables. All content is rendered to HTML5. Authorea also features
a commenting system and article-based chat to ease
collaboration and review.
As the LaTeX system uses plain text, you can use
synchronous collaborative editors like Gobby. In
Gobby you can write your documents in collaboration with anyone in real time. It is strongly recommended that you use utf8 encoding (especially if
there are users on multiple operating systems collaborating) and a stable network (typically wired networks).
TitanPad (or other clones of EtherPad). To compile
use the command:
wget -O [Link] "[Link]
pad/export/xxxx/latest?format=txt" && (latex
[Link])
where 'xxxx' should be replaced by the pad number
(something like 'z7rSrfrYcH').
With a dedicated Linux box with LaTeX & Dropbox
its possible to use Google docs and some scripting to
get automatically generated PDFs on Dropbox from
updates on Google Docs.

You can use a distributed version control system


Collaborative writing of documents requires a strong synsuch as Mercurial or Git. This is the denitive soluchronisation among authors. This Wikibook describes
tion for users looking for control and advanced feaa possible way to organise the collaborative preparation
tures like branch and merge. The learning curve will
of LaTeX documents. The presented solution is primarbe steeper than that for a web-based solution.
ily based on the version control system Subversion (http:
//[Link]/). The Wikibook describes how
Subversion can be used together with several other soft- 9.2.2 Introduction
ware tools and LaTeX packages to organise the collaborative preparation of LaTeX documents.
The collaborative preparation of documents requires a
considerable amount of coordination among the authors.
This coordination can be organised in many dierent
Other Methods
ways, where the best way depends on the specic circum You can use one of the online solutions listed in the stances.
Installation chapter. Most of them have collabora- In this Wikibook, I describe how the collaborative writtion features.
ing of LaTeX documents is organised at our department
(Division of Agricultural Policy, Department of Agricul Another option for collaboration is dropbox. It has 2 tural Economics, University of Kiel, Germany). I present
GB free storage and versioning system. Works like our software tools, and describe how we use them. Thus,
SVN, but more automated and therefore especially this Wikibook provides some ideas and hints that will be
useful for beginning LaTeX users. However, Drop- useful for other LaTeX users who prepare documents tobox is not a true versioning control system, and as gether with their co-authors.

9.2. LATEX/COLLABORATIVE WRITING OF LATEX DOCUMENTS

9.2.3

Interchanging Documents

There are many ways to interchange documents among


authors. One possibility is to compose documents by interchanging e-mail messages. This method has the advantage that common users generally do not have to install
and learn the usage of any extra software, because virtually all authors have an e-mail account. Furthermore, the
author who has modied the document can easily attach
the document and explain the changes by e-mail as well.
Unfortunately, there is a problem when two or more authors are working at the same time on the same document.
So, how can authors synchronise these les?
A second possibility is to provide the document on a common le server, which is available in most departments.
The risk of overwriting each others modications can be
eliminated by locking les that are currently edited. However, generally the le server can be only accessed from
within a department. Hence, authors who are out of the
building cannot use this method to update/commit their
changes. In this case, they will have to use another way to
overcome this problem. So, how can authors access these
les?
A third possibility is to use a version control system.
A comprehensive list of version control systems can be
found at Wikipedia. Version control systems keep track
of all changes in les in a project. If many authors modify
a document at the same time, the version control system
tries to merge all modications automatically. However,
if multiple authors have modied the same line, the modications cannot be merged automatically, and the user
has to resolve the conict by deciding manually which
of the changes should be kept. Authors can also comment their modications so that the co-authors can easily understand the workow of this le. As version control systems generally communicate over the internet (e.g.
through TCP/IP connections), they can be used from different computers with internet connections. A restrictive
rewall policy might prevent the version control system
from connecting to the internet. In this case, the network administrator has to be asked to open the appropriate port. The internet is only used for synchronising
the les. Hence, a permanent internet connection is not
required. The only drawback of a version control system
could be that it has to be installed and congured.
Moreover, a version control system is useful even if a single user is working on a project. First, the user can track
(and possibly revoke) all previous modications. Second, this is a convenient way to have a backup of the les
on other computers (e.g. on the version control server).
Third, this allows the user to easily switch between different computers (e.g. oce, laptop, home).

163

9.2.4 The Version Control System Subversion


Subversion (SVN) comes as a successor to the popular
version control system CVS. SVN operates on a clientserver model in which a central server hosts a project
repository that users copy and modify locally. A repository functions similarly to a library in that it permits
users to check out the current project, make changes, and
then check it back in. The server records all changes a
user checks in (usually with a message summarizing what
changes the user made) so that other users can easily apply those changes to their own local les.
Each user has a local working copy of a remote repository. For instance, users can update changes from the
repository to their working copy, commit changes from
their own working copy to the repository, or (re)view the
dierences between working copy and repository.
To set up a SVN version control system, the SVN server
software has to be installed on a (single) computer with
permanent internet access. (If this computer has no static
IP address, one can use a service like DynDNS to be able
to access the server with a static hostname.) It can run
on many Unix, modern MS Windows, and Mac OS X
platforms.
Users do not have to install the SVN server software, but
a SVN client software. This is the unique way to access the repositories on the server. Besides the basic SVN
command-line client, there are several Graphical User Interface Tools (GUIs) and plug-ins for accessing the SVN
server (see [Link] Additionally, there are very good manuals about SVN freely
available on the internet (e.g. [Link]
com).
At our department, we run the SVN server on a GNULinux system, because most Linux distributions include
it. In this sense, installing, conguring, and maintaining
SVN is a very simple task.
Most MS Windows users access the SVN server by the
TortoiseSVN client, because it provides the most usual
interface for common users. Linux users usually use
SVN utilities from the command-line, or eSvn--a GUI
frontend--with KDi3 for showing complex dierences.

9.2.5 Hosting LaTeX les in Subversion


On our Subversion server, we have one repository for
a common texmf tree. Its structure complies with the
TeX Directory Structure guidelines (TDS, [Link]
[Link]/tds/[Link], see gure 1). This repository provides LaTeX classes, LaTeX styles, and BibTeX styles
that are not available in the LaTeX distributions of the
users, e.g. because they were bought or developed for the
internal use at our department. All users have a working copy of this repository and have congured LaTeX to

164

CHAPTER 9. MISCELLANEOUS
information about the same history of these documents.

Figure 1: Common texmf tree shown in eSvn's Repository


Browser

use this as their personal texmf tree. For instance, teTeX


([Link] users can edit their TeX conguration le (e.g. /etc/texmf/web2c/[Link]) and set
the variable TEXMFHOME to the path of the working
copy of the common texmf tree (e.g. by TEXMFHOME
= $HOME/texmf); MiKTeX ([Link]
users can add the path of the working copy of the common texmf tree in the 'Roots tab of the MiKTeX Options.

Often the question arises, which les should be put under


version control. Generally, all les that are directly modied by the user and that are necessary for compiling the
document should be included in the version control system. Typically, these are the LaTeX source code (*.tex)
les (the main document and possibly some subdocuments) and all pictures that are inserted in the document
(*.eps, *.jpg, *.png, and *.pdf les). All LaTeX classes
(*.cls), LaTeX styles (*.sty), BibTeX data bases (*.bib),
and BibTeX styles (*.bst) generally should be hosted in
the repository of the common texmf tree, but they could
be included in the respective repository, if some (external) co-authors do not have access to the common texmf
tree. On the other hand, all les that are automatically
created or modied during the compilation process (e.g.
*.aut, *.aux, *.bbl, *.bix, *.blg, *.dvi, *.glo, *.gls, *.idx,
*.ilg, *.ind, *.ist, *.lof, *.log, *.lot, *.nav, *.nlo, *.out,
*.pdf, *.ps, *.snm, and *.toc les) or by the (LaTeX or
BibTeX) editor (e.g. *.bak, *.bib~, *.kilepr, *.prj, *.sav,
*.tcp, *.tmp, *.tps, and *.tex~ les) generally should be
not under version control, because these les are not necessary for compilation and generally do not include additional information. Furthermore, these les are regularly
modied so that conicts are very likely.

If a new class or style le has been added (but not if these


les have been modied), the users have to update their
'le name data base' (FNDB) before they can use these
classes and styles. For instance, teTeX users have to execute texhash; MiKTeX users have to click on the button
9.2.6
'Refresh FNDB' in the 'General' tab of the MiKTeX Options.

Subversion
dierence

really

makes

the

Furthermore, the repository contains manuals explaining A great feature of a version control system is that all authe specic LaTeX software solution at our department thors can easily trace the workow of a project by view(e.g. this document).
ing the dierences between arbitrary versions of the les.
The Subversion server hosts a separate repository for each Authors are primarily interested in 'eective' modicaproject of our department. Although branching, merging, tions of the source code that change the compiled docuand tagging is less important for writing text documents ment, but not in 'ineective' modications that have no
than for writing source code for software, our repository impact on the compiled document (e.g. the position of
layouts follow the recommendations of the 'Subversion line breaks). Software tools for comparing text docubook' ([Link] In this sense, each ments ('di tools) generally cannot dierentiate between
repository has the three directories /trunk, /branches, and 'eective' and 'ineective' modications; they highlight
/tags.
both types of modications. This considerably increases
The most important directory is /trunk. If a single text the eort to nd and review the 'eective' modications.
document belongs to the project, all les and subdirec- Therefore, 'ineective' modications should be avoided.
tories of this text document are in /trunk. If the project
yields two or more dierent text documents, /trunk contains a subdirectory for each text document. A slightly
dierent version (a branch) of a text document (e.g. for
presentation at a conference) can be prepared either in
an additional subdirectory of /trunk or in a new subdirectory of /branches. When a text document is submitted to
a journal or a conference, we create a tag in the directory
/tags so that it is easy to identify the submitted version
of the document at a later date. This feature has been
proven very useful. When creating branches and tags, it
is important always to use the Subversion client (and not
the tools of the local le system) for these actions, because this saves disk space on the server and it preserves

In this sense, it is very important not to change the positions of line breaks without cause. Hence, automatic line
wrapping of the users LaTeX editors should be turned
o and line breaks should be added manually. Otherwise, if a single word in the beginning of a paragraph is
added or removed, all line breaks of this paragraph might
change so that most di tools indicate the entire paragraph as modied, because they compare the les line by
line. The di tools wdi ([Link]
wdiff/) and dwdi ([Link] are
not aected by the positions of line breaks, because they
compare documents word by word. However, their output is less clear so that modications are more dicult
to track. Moreover, these tools cannot be used directly

9.2. LATEX/COLLABORATIVE WRITING OF LATEX DOCUMENTS

165

with the Subversion command-line switch --di-cmd, but


a small wrapper script has to be used ([Link]
com/posts/show/1033).
A reasonable convention is to add a line break after each
sentence and start each new sentence in a new line. Note
that this has an advantage also beyond version control: if
you want to nd a sentence in your LaTeX code that you
have seen in a compiled (DVI, PS, or PDF) le or on a
printout, you can easily identify the rst few words of this
sentence and screen for these words on the left border of
your editor window.
Furthermore, we split long sentences into several lines
so that each line has at most 80 characters, because it is
rather inconvenient to search for (small) dierences in
long lines. (Note: For instance, the LaTeX editor Kile
([Link] can assist the user in this
task when it is congured to add a vertical line that marks
the 80th column.) We nd it very useful to introduce the
additional line breaks at logical breaks of the sentence,
e.g. before a relative clause or a new part of the sentence
starts. An example LaTeX code that is formatted according to these guidelines is the source code of the article
Tools for Collaborative Writing of Scientic LaTeX Documents by Arne Henningsen that is published (including
the source code) in The PracTeX Journal 2007, Number
3 ([Link]
If the authors work on dierent operating systems, their LaTeX editors will probably save the
les with dierent newline (end-of-line) characters
([Link] To avoid this
type of 'ineective' modications, all users can agree on
a specic newline character and congure their editor
to use this newline character. Another alternative is
to add the subversion property 'svn:eol-style' and set
it to 'native'. In this case, Subversion automatically
converts all newline characters of this le to the native
newline character of the authors operating system
([Link]
[Link]#[Link].
eol-style).
There is also another important reason for reducing the
number of 'ineective' modications: if several authors
work on the same le, the probability that the same line
is modied by two or more authors at the same time increases with the number of modied lines. Hence, 'ineffective' modications unnecessarily increase the risk of
conicts (see section Interchanging Documents).
Furthermore, version control systems allow a very eective quality assurance measure: all authors should critically review their own modications before they commit them to the repository (see gure 2). The dierences
between the users working copy and the repository can
be easily inspected with a single Subversion command or
with one or two clicks in a graphical Subversion client.
Furthermore, authors should verify that their code can be
compiled awlessly before they commit their modica-

Figure 2: Reviewing modications in KDi3

tions to the repository. Otherwise, the co-authors have


to pay for these mistakes when they want to compile the
document. However, this directive is not only reasonable
for version control systems but also for all other ways to
interchange documents among authors.
Subversion has a feature called 'Keyword Substitution' that includes dynamic version information
about a le (e.g. the revision number or the last
author) into the contents of the le itself (see e.g.
[Link] chapter 3). Sometimes,
it is useful to include these information not only as
a comment in the LaTeX source code, but also in
the (compiled) DVI, PS, or PDF document. This
can be achieved with the LaTeX packages svn (http:
//[Link]/tex-archive/macros/latex/contrib/svn/),
svninfo ([Link]
contrib/svninfo/), or (preferably) svn-multi ([Link]
[Link]/tex-archive/macros/latex/contrib/svn-multi/).
The most important directives for collaborative writing of
LaTeX documents with version control systems are summarised in the following box.
Directives for using LaTeX with version control systems
1. Avoid 'ineective' modications.
2. Do not change line breaks without good reason.
3. Turn o automatic line wrapping of your LaTeX editor.
4. Start each new sentence in a new line.
5. Split long sentences into several lines so that each
line has at most 80 characters.
6. Put only those les under version control that are
directly modied by the user.
7. Verify that your code can be compiled awlessly before committing your modications to the repository.

166

CHAPTER 9. MISCELLANEOUS

8. Use Subversion's di feature to critically review styles can be found on CTAN ([Link] and
your modications before committing them to the on the LaTeX Bibliography Styles Database ([Link]
repository.
[Link]/bstdatabase/). If no suitable BibTeX style
can be found, most desired styles can be conveniently as9. Add a meaningful and descriptive comment when sembled with custombib/makebst ([Link]
committing your modications to the repository.
tex-archive/macros/latex/contrib/custom-bib/).
Furthermore,
BibTeX
style
les
can
be
created
or
modied
10. Use the Subversion client for copying, moving, or renaming les and folders that are under revision con- manually; however this action requires knowledge of the
(unnamed) postx stack language that is used in BibTeX
trol.
style les (Patashnik 1988).
If the users are willing to let go of the built-in di utility
of SVN and use di tools that are local on their workstations, they can put to use such tools that are more tailored
to text documents. The di tool that comes with SVN was
designed with source code in mind. As such, it is built to
be more useful for les of short lines. Other tools, such
as Compare It! allows to conveniently compare text les
where each line can span hundreds of characters (such as
when each line represents a paragraph). When using a
di tool that allows convenient views of les with long
lines, the users can author the TeX les without a strict
line-breaking policy.
Visualizing dis in LaTeX: latexdi and changebar
The tools latexdi and changebar can visualize dierences of two LaTeX les inside a generated document.
This makes it easier to see impact of certain changes
or discuss changes with people not custom to LaTeX.
Changebar comes with a script [Link] which inserts a
bar in the margin indicating parts that have changed. Latexdi allows dierent styles of visualization. The default is that discarded text is marked as red and added
text is marked as blue. It also supports a mode similar
to Changebar which adds a bar in the margin. Latexdi comes with a script latexrevise which can be used to
accept or decline changes. It also has a wrapper script
to support version control systems such as the discussed
Subversion.

At our department, we have a common bibliographic data


base in the BibTeX format (.bib le). It resides in our
common texmf tree (see section 'Hosting LaTeX les in
Subversion') in the subdirectory /bibtex/bib/ (see gure
1). Hence, all users can specify this bibliography by only
using the le name (without the full path) --- no matter
where the users working copy of the common texmf tree
is located.
All users edit our bibliographic data base with the graphical BibTeX editor JabRef ([Link]
net/). As JabRef is written in Java, it runs on all major
operating systems. As dierent versions of JabRef generally save les in a slightly dierent way (e.g. by introducing line breaks at dierent positions), all users should use
the same (e.g. last stable) version of JabRef. Otherwise,
there would be many dierences between dierent versions of .bib les that solely originate from using dierent
version of JabRef. Hence, it would be hard to nd the real
dierences between the compared documents. Furthermore, the probability of conicts would be much higher
(see section 'Subversion really makes the dierence'). As
JabRef saves the BibTeX data base with the native newline character of the authors operating system, it is recommended to add the Subversion property 'svn:eol-style'
and set it to 'native' (see section 'Subversion really makes
the dierence').

An example on how to use Latexdi in the Terminal.


latexdi [Link] [Link] > [Link] # Files [Link] and
[Link] are compared and the le visualizing the changes
is written to [Link] pdatex [Link] # Create a PDF
showing the changes
The program DiPDF can be used to compare two existing PDFs visually. There is also a command line tool
comparepdf based on DiPDF.
Figure 3: Specify default key pattern in JabRef

9.2.7

Managing collaborative bibliogra- JabRef is highly exible and can be congured in many
details. We make the following changes to the default
phies

Writing of scientic articles, reports, and books requires


the citation of all relevant sources. BibTeX is an excellent tool for citing references and creating bibliographies
(Markey 2005, Fenn 2006). Many dierent BibTeX

conguration of JabRef to simplify our work. First,


we specify the default pattern for BibTeX keys so that
JabRef can automatically generate keys in our desired
format. This can be done by selecting Options Preferences Key pattern and modifying the desired pat-

9.2. LATEX/COLLABORATIVE WRITING OF LATEX DOCUMENTS

167

tern in the eld Default pattern. For instance, we use 9.2.8 Conclusion
[auth:lower{]}{[}shortyear] to get the last name of the
rst author in lower case and the last two digits of the This wikibook describes a possible way to eciently
year of the publication (see gure 3).
organise the collaborative preparation of LaTeX documents. The presented solution is based on the Subversion
version control system and several other software tools
and LaTeX packages. However, there are still a few issues that can be improved.

Figure 4: Set up general elds in JabRef

Second, we add the BibTeX eld location for information about the location, where the publication is available
as hard copy (e.g. a book or a copy of an article). This
eld can contain the name of the user who has the hard
copy and where he has it or the name of a library and the
shelf-mark. This eld can be added in JabRef by selecting Options Set up general elds and adding the word
location (using the semicolon (;) as delimiter) somewhere
in the line that starts with General: (see gure 4).

First, we plan that all users install the same LaTeX distribution. As the TeX Live distribution ([Link]
texlive/) is available both for Unix and MS Windows operating systems, we might recommend our users to switch
to this LaTeX distribution in the future. (Currently, our
users have dierent LaTeX distributions that provide a
dierent selection of LaTeX packages and dierent versions of some packages. We solve this problem by providing some packages on our common texmf tree.)

Second, we consider to simplify the solution for a common bibliographic data base. Currently it is based on
the version control system Subversion, the graphical BibTeX editor JabRef, and a le server for the PDF les of
publications in the data base. The usage of three different tools for one task is rather challenging for infrequent users and users that are not familiar with these tools.
Furthermore, the le server can be only accessed by local users. Therefore, we consider to implement an integrated server solution like WIKINDX ([Link]
[Link]/), Aigaion ([Link] or
refBASE ([Link] Using this solution only requires a computer with internet access and
a web browser, which makes the usage of our data base
considerably easier for infrequent users. Moreover, the
stored PDF les are available not only from within the
department, but throughout the world. (Depending on
the copy rights of the stored PDF les, the access to
the server --- or least the access to the PDF les --- has
to be restricted to members of the department.) Even
Non-LaTeX users of our department might benet from
Figure 5: Specify 'Main PDF directory' in JabRef
a server-based solution, because it should be easier to use
this bibliographic data base in (other) word processing
Third, we put all PDF les of publications in a specic software packages, because these servers provide the data
subdirectory in our le server, where we use the BibTeX not only in BibTeX format, but also in other formats.
key as le name. We inform JabRef about this subdi- All readers are encouraged to contribute to this wikibook
rectory by selecting Options Preferences External by adding further hints or ideas or by providing further soprograms and adding the path of the this subdirectory in lutions to the problem of collaborative writing of LaTeX
the eld Main PDF directory (see gure 5). If a PDF le documents.
of a publication is available, the user can push the Auto
button left of JabRef's Pdf eld to automatically add the
le name of the PDF le. Now, all users who have access 9.2.9 Acknowledgements
to the le server can open the PDF le of a publication
by simply clicking on JabRef's PDF icon.
Arne Henningsen thanks Francisco Reinaldo and GralIf we send the LaTeX source code of a project to a journal, publisher, or somebody else who has no access to our
common texmf tree, we do not include our entire bibliographic data base, but extract the relevant entries with
the Perl script aux2bib ([Link]
biblio/bibtex/utils/bibtools/aux2bib).

dine Henningsen for comments and suggestions that


helped him to improve and clarify this paper, Karsten
Heymann for many hints and advices regarding LaTeX,
BibTeX, and Subversion, and Christian Henning as well
as his colleagues for supporting his intention to establish
LaTeX and Subversion at their department.

168

9.2.10

CHAPTER 9. MISCELLANEOUS

References

Some tools are Unix-specic (*BSD, GNU/Linux and


Mac OS X), but it may be possible to make them work on
Fenn, Jrgen (2006): Managing citations and your Windows. If you have the choice, it is often easier with
bibliography with BibTeX. The PracTEX Journal, Unix systems for command line tools.
4. [Link]
Some tools may already be installed. For instance, you
can check if dvipng is installed and ready to use (Unix
Markey, Nicolas (2005): Tame the BeaST. The B only):
to X of BibTeX. [Link]
info/bibtex/tamethebeast/ttb_en.pdf. Version 1.3. which dvipng
You get a directory if it is OK. [[w Most of these tools
Oren Patashnik.
Designing BibTeX styles. are installable using your package manager or portage tree
[Link]
(Unix only).
bibtex/contrib/doc/[Link].
Tools for collaborative paper-writing

9.3.2 Preview mode

This section describes how to generate a screenshot of a


9.3 LaTeX/Export To Other For- LaTeX page or of a specic part of the page using the
LaTeX package preview. Screenshots are useful, for exmats
ample, if you want to include a LaTeX generated formula
on a presentation using you favorite slideware like PowStrictly speaking, LaTeX source can be used to directly erpoint, Keynote or LibreOce Impress. First, start by
making sure you have preview. See Installing Extra Packgenerate two formats:
ages.
DVI using latex, the rst one to be supported;

Say you want to take a screenshot of

PDF using pdatex, more recent.


Using other software freely available on Internet, you can
easily convert DVI and PDF to other document formats.
In particular, you can obtain the PostScript version using
software which is included in your LaTeX distribution.
Some LaTeX IDE will give you the possibility to generate the PostScript version directly (even if it uses internally a DVI mid-step, e.g. LaTeX DVI PS). It is
also possible to create PDF from DVI and vice versa. It
doesn't seem logical to create a le with two steps when
you can create it straight away, but some users might need
it because, as you remember from the rst chapters, the
format you can generate depends upon the formats of the
images you want to include (EPS for DVI, PNG and JPG
for PDF). Here you will nd sections about dierent formats with description about how to get it.


(3)k
12
.
2k + 1
k=0

Write this formula in the preview environment:


Note the active option in the package declaration and the
preview environment around the equations code. Without any of these two, you won't get any output.
This package is also very useful to export specic parts
to other format, or to produce graphics (e.g. using
PGF/TikZ) and then including them in other documents.
You can also automate the previewing of specic environments:
This will produce a PDF containing only the listing content, the page layout will depend on the shape of the
source code.

Other formats can be produced, such as RTF (which can


be used in Microsoft Word) and HTML. However, these
documents are produced from software that parses and
9.3.3 Convert to PDF
interprets the LaTeX les, and do not implement all the
features available for the primary DVI and PDF outputs.
Directly
Nonetheless, they do work, and can be crucial tools for
collaboration with colleagues who do not edit documents
pdatex my_le
with LaTeX.

9.3.1

Tools installation

DVI to PDF

This chapter features a lot of third-party tools; most of dvipdfm my_le.dvi


them are installed independently of your TeX distribu- will create my_le.pdf. Another way is to pass through
PS generation:
tion.

9.3. LATEX/EXPORT TO OTHER FORMATS


dvi2ps [Link] ps2pdf [Link]

169

9.3.4 Convert to PostScript

you will get also a le called my_le.ps that you can


from PDF
delete.
pdf2ps my_le.pdf
Merging PDF
from DVI
If you have created dierent PDF documents and you
want to merge them into one single PDF le you can use dvi2ps my_le.dvi
the following command-line command. You need to have
Ghostscript installed:

9.3.5 Convert to RTF

Using
Windows gswin32
-dNOPAUSE
- LaTeX can be converted into an RTF le, which in turn
sDEVICE=pdfwrite
-sOUTPUTFILE=[Link] can be opened by a word processor such as LibreOce
Writer or Microsoft Word. This conversion is done
-dBATCH [Link] [Link] [Link]
through latex2rtf, which may run on any computer platform, however is only actively supported on Windows,
Using Linux gs -dNOPAUSE -sDEVICE=pdfwrite Linux and BSD, with the last mac update being from
-sOUTPUTFILE=[Link] -dBATCH [Link] [Link] 2001. The program operates by reading the LaTeX
source, and mimicking the behaviour of the LaTeX [Link]
gram. latex2rtf supports most of the standard implemenAlternatively, PDF-Shuer is a small python-gtk applica- tations of LaTeX, such as standard formatting, some math
tion, which helps the user to merge or split pdf documents typesetting, inclusion of EPS, PNG or JPG graphics, and
and rotate, crop and rearrange their pages using an in- tables. As well, it has some limited support for packages,
teractive and intuitive graphical interface. This program such as varioref, and natbib. However, many other packmay be avaliable in your Linux distributions repository. ages are not supported.
Another option to check out is pdftk (or PDF toolkit), latex2rtf is simple to use. The Windows version has a
which is a command-line tool that can manipulate PDFs GUI ([Link]), which is straightforward to use. The
in many ways. To merge one or more les, use:
command-line version is oered for all platforms, and can
be used on an example [Link] le:
pdftk [Link] [Link] [Link] cat output [Link]
latex mypaper bibtex mypaper # if you use bibtex latex2rtf mypaper
Using pdfLaTeX Note: If you are merging external
Both latex and (if needed) bibtex commands need to be
PDF documents into a LaTeX document which is comrun before latex2rtf, because the .aux and .bbl les are
piled with pdatex, a much simpler option is to use the
needed to produce the proper output. The result of this
pdfpages package, e.g.:
conversion will create [Link], which you may open in
Three simple shell scripts using the pdfpages package are many word processors such as Microsoft Word or Libreprovided in the pdfjam bundle by D. Firth. They include Oce.
options to merge several pdf les (pdfjoin), put several
pages in one physical sheet (pdfnup) and rotate pages
(pdf90).
9.3.6 Convert to HTML
See also Modular Documents

There are many converters to HTML.

XeTeX

HEVEA

You can also use XeTeX (or, more precisely, XeLaTeX),


which works in the same way as pdatex: it creates a
PDF le directly from LaTeX source. One advantage of
XeTeX over standard LaTeX is support for Unicode and
modern typography. See its Wikipedia entry for more
details.

hevea mylatexle
latex2html

latex2html -html_version 4.0,latin1,unicode -split 1 nonavigation -noinfo -title MyDocument MyDocuCustomization of PDF output in XeTeX (setting docu- [Link]
ment title, author, keywords etc.) is done using the conTeX4ht
guration of hyperref package.

170

CHAPTER 9. MISCELLANEOUS

TeX4ht is a very powerful conversion program, but its Vector graphics


conguration is not straightforward. Basically a conguration le has to be prepared, and then the program is pdf2svg
called.
Direct conversion from PDF to SVG can be done using
the command line tool pdf2svg.
bibtex2html
pdf2svg [Link] [Link]
For BibTeX.
ps2svg
bibtex2html mybibtexle
Alternatively DVI or PDF can be converted to PS as described before, then the bash script [Link] can be used
9.3.7 Convert to image formats
(as all the software used by this script is multiplatform,
It is sometimes useful to convert LaTeX output to image this is also possible in Windows, a step-by-step guide
formats for use in systems that do not support DVI nor could be written).
PDF les, such as Wikipedia.
dvisvgm
There is two family of graphics:
One can also use dvisvgm, an open source utility that con Vector graphics can be scaled to any size, thus do
verts from DVI to SVG.
not suer from quality loss. SVG is a vector format.
dvisvgm -n [Link]
Raster graphics dene every pixel explicitly. PNG
is a raster format.
Inkscape
So vector graphics are usually preferred. There is still Inkscape is able to convert to SVG, PDF, EPS, and other
vector graphic formats.
some cases where raster graphics are used:
inkscape --export-area-drawing --export-ps=OUTPUT
The target system does not handle vector graphics, INPUT inkscape --export-area-page --export-plainonly raster graphics are supported.
svg=OUTPUT INPUT
SVG can not embed fonts. So either the font will
be rendered using a local .ttf or .otf font (which will
mostly change the output), or all characters must be
turned to vector graphics. This last method makes
the SVG big and slow. If the input LaTeX le contains a lot of text which formatting must be preserved, SVG is not that great.

Raster graphics
GIMP

Open your le with GIMP. It will ask you which page


you want to convert, whether you want to use anti-aliasing
(choose strong if you want to get something similar to
So SVG is great for drawings and a small amount of text. what you see on the screen). Try dierent resolutions to
JPG is a well known raster formats, however it is usually t your needs, but 100 dpi should be enough. Once you
have the image within GIMP, you can post-process it as
not as good as PNG for text.
you like and save it to any format supported by GIMP, as
In some cases it may be sucient to simply copy a region
PNG for example.
of a PDF (or PS) le using the tools available in a PDF
viewer (for example using LaTeX to typeset a formula for
pasting into a presentation). This however will not gen- dvipng
erally have sucient resolution for whole pages or large
A method for DVI les is dvipng. Usage is the same as
areas.
dvipdfm.

pdftocairo -svg [Link] [Link]

Run latex as usual to generate the dvi le. Now, we want


an X font size formula, where X is measure in pixels. You
need to convert this, to dots per inch (dpi). The formula
is: <dpi> = <font_px>*72.27/10. If you want, for instance, X = 32, then the size in dpi corresponds to 231.26.
This value will be passed to dvipng using the ag -D. To
generate the desired png le run the command as follows:

pdftocairo also supports various raster graphic formats.

dvipng -T tight -D 231.26 -o [Link] [Link]

Multiple formats
pdftocairo
There is pdftocairo featured in the poppler toolset.

9.3. LATEX/EXPORT TO OTHER FORMATS


The ag -T sets the size of the image. The option tight
will only include all ink put on the page. The option -o
sends the output to the le name [Link].
ImageMagick
The convert command from the ImageMagick suite can
convert both DVI and PDF les to PNG.
convert [Link] [Link]
optipng
You can optimize the resulting image using optipng so
that it will take up less space.

9.3.8

Convert to plain text

If you are thinking of converting to plain text for spellchecking or to count words, there may be an easier way
-- read Tips and Tricks rst.
Most LaTeX distributions come with detex program,
which strips LaTeX commands. It can handle multi-le
projects, so all you need is to give one command:
detex yourle
(note the omission of .tex extension). This will output
result to standard output. If you want the plain text go to
a le, use
detex yourle > [Link]
If the output from detex does not satisfy you, you can try
a newer version available on Google Code, or use HTML
conversion rst and then copy text from your browser.
If you want to keep the formating, you can use a DVI-toplain text converter, like catdvi. Example:
catdvi [Link] | fmt -u
The use of fmt -u (available on most Unices) will remove
the justication.

171

Chapter 10

Help and Recommendations


10.1 LaTeX/FAQ
10.1.1

you add the \usepackage[utf8]{inputenc} line in the


preamble.

Margins are too wide


Avoid using latin1. See Special Characters.

LaTeXs default margins may seem too large. In most


cases, this is a preferred default and improves readability.
If you still disagree, you can easily change them with
See Page Layout.

10.1.2

10.1.4 Writing the euro symbol directly


Add the following lines in your preamble:

Avoid excessive double line breaks


10.1.5 LaTeX paragraph headings have tiin source code
tle and content on the same line

Too many paragraphs of one line or two do not look very


Some people do not like the way \paragraph{...} writes
good.
the title on the same line as the content. This is actually
Remember the TeX rule:
fairly common in a lot of documents and not as weird as
it may seem at rst.
If two or more consecutive line breaks are found,
There are ways to get around the default behavior, howTeX starts a new paragraph.
ever; see \paragraph line break for more information.
If only one linebreak is found, TeX inserts a space
if there is no space directly before or after it.

10.1.6 Fonts are ugly/jagged/bitmaps or

You might be tempted to put blank lines all the time to


PDF search fails or Copy/paste from
improve the readability of your source code, but this will
PDF is messy
have an impact on formatting. The solution is simple:
put a comment at the very beginning of the blank lines.
You must be using diacritics (e.g. accents) with OT1 enThis will prevent TeX from seeing another line break
coding (the default). Switch to T1 encoding:
all characters up to and including the next line break after
If you have ugly jagged fonts after the font encoding
a comment are ignored.
change, then you have no Type1 compatible fonts availExample:
able. Install Computer Modern Super or Latin Modern
(package name may be lm). To use Latin Modern you
need to include the package:
10.1.3 Simplied special character input
See Fonts for an explanation.
So long as your computing environment supports UTF-8,
you can enter special characters directly rather than entering the TeX commands for diacritics and other extended 10.1.7 Manual formatting:
characters. E.g.,

use of line
breaks and page breaks

This requires that:


You should really avoid breaking lines and pages manu your text editor supports and is set to save your le ally. The TeX engine is in charge of that. The big probin UTF-8;
lem with manual formatting is that it is not dynamic. Even
172

10.1. LATEX/FAQ

173

if it looks right the rst time, the content is likely to ren- not have more weight than normal characters, so they are
der really badly if you change anything before the point usually a better choice for emphasizing small amounts of
you manually formatted.
text.
The only place where page breaks are recommended is at
the upper level of sectioning in your documents, e.g. parts
or chapters (although when you start a new part or chapter, LaTeX will ordinarily do this for you). When you do
manually insert a page break, you should use \clearpage
or \cleardoublepage which print currently oating gures
before starting a new page.

The original and more appropriate use of bold and underline is for special parts, such as headers, the index, glossaries, and so on. (Actually, underlining is rarely used in
professional environments.)

LaTeX has a macro \emph{...} for emphasizing text using italics. It should be preferred to \textit{...} because
\emph{...} will correctly print emphasized text inside
If you absolutely have to insert line or page breaks man- other italic text in the regular font.
ually, you should do it after you are sure you have completed your document otherwise, so that you don't later
10.1.10 The proper way to use gures
have to come back and update it.

10.1.8

Always nish commands with {}

TeX has an unintuitive rule that if a control sequence (a


command) is not followed by a pair of braces (with a parameter in between or not), then the following space character(s) are ignored. LaTeX will not print any space, and
the command (say, the TeX or LaTeX logos) are run together with the following word.

Users used to WYSIWYG document processors like Microsoft Word or LibreOce often get frustrated with gures. The answer is simple: a gure is not a picture!
If you use \includegraphics without enclosing it in a gure
environment, it will behave just as in a word processor,
placing the picture right at the spot where it was placed
in the source.

Figures are a type of oat, which is a virtual object that


LaTeX
can put in places other than the exact location it
To x this, use a pair of braces after the command, even
was
created,
which helps to prevent cluttering your text
if there are no parameters. Example:
with pictures and tables.
(Technical explanation: a control sequence name can only
be composed of characters with catcode 11, that is A- See Importing Graphics and Floats, Figures and Captions
Z and a-z by default. TeX knows where the control se- for more details.
quence name start thanks to the backslash, and it knows
where it ends when it encounters the rst token which is
not of catcode 11. This character is then skipped. Since 10.1.11 Text stops justifying
consecutive spaces have been concatenated into one sinMost likely you have used \raggedleft, \raggedright or
gle space, no space is taken into account.)
\centering at some point and forgotten to switch it o.
It is possible to dene macros that will insert a space dy- These commands are switchesthey remain active until
namically by using the xspace package.
the end of the scope, or until the end of the document
if there is no scope. See Paragraph Alignment for more
If there is no brace and a space following the com- information.
mand, an extra space will be appended.
If there are braces, no extra space will be printed.

10.1.12 Rules of punctuation and spacing

Example:

LaTeX does some work for you, but not everything. Especially regarding punctuation, you are pretty free to do
what you want. Punctuation rules are dierent for each
10.1.9 Avoid bold and underline
language. In English there is no space before a punctuaTypographically speaking, it is usually poor practice to tion mark and one space after it.
use bold or underline formats in the middle of a para- There are a lot of rules, but you can have a quick look at
graph. This has become a common habit for users of tra- Wikipedia.
ditional word processors because these two functions are
very easily accessible (along with italics).
However, bold and underline tend to overweight the text 10.1.13 Compilation fails after a Babel
language change
and distract the reader. When you start reading a paragraph with a bold word in the middle, you often read the
emphasized part rst, thus spoiling the content and break- This is a limitation of Babel. Delete the .aux le (or clean
ing the order of the ideas. Italics are less obvious and do the project), then try compiling again.

174

10.1.14

CHAPTER 10. HELP AND RECOMMENDATIONS

Learning LaTeX quickly or cor- 10.1.17 Use vector graphics rather than
rectly
raster images

Nowadays it is very common to learn on the web by using a search engine and copying and pasting things here
and there. As with every programming language, this is
generally a poor method which will lead to lack of control,
unexpected results, and a lot of frustration. Really learning LaTeX is not that dicult and does not take that long.
Most chapters in this book are dedicated to a specic usage, so the basics are actually covered very quickly.

Raster (bitmap) graphics scale poorly and often create


jagged or low-quality results which clash with the document quality, particularly when printed.

Using vector (line-oriented) graphics instead, either


through LaTeXs native diagramming tools or by exporting vector formats from your drawing or diagramming
tools, will produce much higher quality results. When
possible, you should prefer PDF, EPS, or SVG graphics
If you are getting frustrated with a specic package, make over PNG or JPG.
sure you read its ocial documentation, which is usually
the best source of information. Content found on the web,
even in this book, is rarely as accurate as the ocial documentation. Inaccurate information might result in causing 10.1.18 Stretching tables
mistakes without you understanding why.
The time you spend learning is worth it, and it quickly Trying to stretch tables with the default tabular environmakes up for the time you would lose if you don't learn ment will often lead to unexpected results. The nice tabu
package will do what you want and even much more. Althings properly and end up stuck all the time.
ternatively if you cannot use the tabu package you may
try tabularx or tabulary packages See Tables.

10.1.15

Non-breaking spaces

This useful feature is unknown to most newcomers, although it is available on most WYSIWYG document processors. A non-breaking space between two tokens (e.g.
words, punctuation marks) prevents processors from inserting a line break between them. It is very important
for consistent reading. LaTeX uses the '~' symbol as a
non-breaking space.

10.1.19 Tables are easier than you think


Even though the Tables chapter is quite long, it is worth
reading. In the end, you only need to know a few things
about the environment of your choice.

Some LaTeX editors feature table assistants. Also, many


You usually use non-breaking spaces for punctuation spreadsheet applications have a LaTeX export feature (or
marks in some languages, for units and currencies, for plugin). Again, see Tables for more details.
initials, etc.
For example, in French typography, you put a nonbreaking space before all two-parts punctuation marks. 10.1.20
Example:
Note that writing French like this might get really painful.
Thankfully, Babel with the frenchb option will take care
of the non-breaking spaces for all punctuation marks. In
the above example, only the non-breaking space for the
euro symbol must remain.

10.1.16

Smart mathematics

Relieving cumbersome code (lists


and long command names)

LaTeX is sometimes cumbersome to write, especially if


you are not using an adequate editor. See Editors for
some interesting choices.
You can dene aliases to shorten some commands:
Here the xspace package comes in handy to avoid swallowed spaces.

For lists you may want to try the easylist package. Now
All virtual objects designated by letters, variables or oth- writing a list is as simple as
ers should use a dedicated formatting. For math and a lot
of other elds, the LaTeX math formatting is perfect. For
instance, if you want to refer to an object A, write
If you want to refer to several objects in a sentence, it is
the same.

10.1.21 Reducing the size of your LaTeX


installation

If you refer to a set of objects, you can still use the math The Installation article explains in detail how to manunotation.
ally install a fully functional TeX environment, including
LaTeX and other features, in under 100 MB.
Note that this is dierent from usual text parentheses.

10.2. LATEX/TIPS AND TRICKS

175

10.2 LaTeX/Tips and Tricks


10.2.1

within{equation}{section}
within{gure}{section}

\number-

Always writing LaTeX in roman

The same can be done with similar counter types and docIf you insert the \LaTeX command in an area with a ument units such as subsection.
non-default font, it will be formatted accordingly. If you
want to keep LaTeX written in Computer Modern roman shape, you must redene the function. However, the 10.2.4 Generic header
naive
As explained in the previous sections, a LaTeX source
\renewcommand{\LaTeX}{{\rm \LaTeX}}
can be used to generate both a DVI and a PDF le. For
very basic documents the source is the same but, if the
documents gets more complicated, it could be necessary
will output:
to make some changes in the source so that it will work
TeX capacity exceeded , sorry [ grouping levels =255].
for a format but it will not for the other. For example,
all that is related to graphics has to be adapted accordSo you need to create a temporary variable.
ing to the nal format. As discussed in the section about
oating objects, even if you should use dierent pictures
Sadly,
according to the nal format, you can override this limit
\newcommand{\LaTeXtemp}{\LaTeX}
\renewcom- putting in the same folder pictures in dierent formats
mand{\LaTeX}{{\rm \LaTeXtemp}}
(e.g., EPS and PNG) with the same name and link them
without writing the extension. There is a simple way to
solve this problem:
does not work as well.
\usepackage{ifpdf}

We must use the TeX primitive \let instead.


\let\LaTeXtemp\LaTeX
mand{\LaTeX}{{\rm \LaTeXtemp }}

\renewcomor, if you don't have this package, you can add the following text just after \documentclass[...]{...} :

10.2.2 id est and exempli gratia (i.e. and


e.g.)

\newif\ifpdf \ifx\pdfoutput\undened \pdalse \else


\ifnum\pdfoutput=1 \pdftrue \else \pdalse \ \
this is plain TeX code. The ifpdf package and this code,
both dene a new if-else you can use to change your code
according to the compiler you are using. After you have
used this code, you can use whenever you want in your
document the following syntax:

If you simply use the forms i.e. or e.g., LaTeX will


treat the periods as end of sentence periods (i.e. full stop)
since they are followed by a space, and add more space before the next sentence. To prevent LaTeX from adding
space after the last period, the correct syntax is either \ifpdf % we are running pdatex \else % we are running
i.e.\ " or e.g.\ ".
latex \
Depending on style (e.g., The Chicago Manual of Style),
a comma can be used afterwards, which is interpreted by
LaTeX as part of a sentence, since the period is not followed by any space. In this case, i.e., and e.g., do not
need any special attention.

place after \ifpdf the code you want to insert if you are
compiling with pdatex, place after \else the code you
want to insert if you are compiling with latex. For example, you can use this syntax to load dierent packages or
If the command \frenchspacing is used in the preamble, dierent graphic le formats according to the compiler.
the space between sentences is always consistent.

10.2.5 Graphics and Graph editors


10.2.3

Grouping Figure/Equation NumVector image editors with LaTeX support


bering by Section
It is often preferable to use the same font and font size
in your images as in the document. Moreover, for scientic images, you may need mathematical formulae or
special characters (such as Greek letters). Both things
can be achieved easily if the image editor allows you to
use LaTeX code in your image. Most vector image edi\number- tors do not oer this option. There are, however, a few

For long documents the numbering can become cumbersome as the numbers reach into double and triple digits.
To reset the counters at the start of each section and prex
the numbers by the section number, include the following
in the preamble.
\usepackage{amsmath}

176

CHAPTER 10. HELP AND RECOMMENDATIONS

exceptions.
In early days, LaTeX users used Xg for their drawings.
The editor is still used by quite a few people nowadays
because it has special 'export to LaTeX' features. It also
gives you some very basic ways of encapsulating LaTeX
text and math in the image (setting the texts 'special ag'
to 'special' instead of 'normal'). When exporting, all LaTeX text will be put in a .tex-le, separately from the rest
of the image (which is put in a .ps le).
A newer and easier-to-use vector image editor specially
tailored to LaTeX use is IPE. It allows any LaTeX command, including but not limited to mathematical formulae in the image. The program saves its les as editable
.eps or .pdf les, which eliminates the need of exporting
your image each time you have edited it.

3
2.5
2
-1.5

1.5
1

-1
-0.5

0.5

0 0
A very versatile vector image editor is Inkscape. It does
0.5
not support LaTeX text by itself, but you can use the plu1
1.5
gin Textext for that. This allows you to put any block of
LaTeX code in your image. Additionally since version
gnuplot can plot various numerical data, functions, error distri0.48 you can export to vectorgraphics with texts sepa- bution as well as 3D graphs and surfaces
rated in a .tex le. Using this way text is rendered by the
latex compiler itself.

LaTeXDraw is a free and open source graphical PSTricks


generator and editor. It allows you to draw basic geometric objects and save the result in a variety of formats including .jpg, .png, .eps, .bmp as well as .tex. In the last
case the saved le contains PSTricks/LaTeX code only.
Owing to that you can include any possible LaTeX code
in the picture, since the le is rendered by your LaTeX
environment directly.

set format "$%g$" set title Graph 3: Dependence


of $V_p$ on $R_0$" set xlabel Resistance $R_0$
[$\Omega$]" set ylabel Voltage $V_p$ [V]" set border 3
set xtics nomirror set ytics nomirror set terminal epslatex
set output [Link] plot [Link] using 1:3 #Plot
the data

Now gnuplot produces two les: the graph drawing in


[Link] and the text in [Link]. The second includes
Another way to generate vectorgraphics is using the the EPS image, so that we only need to include the le
Asymptote language. It is a programming language [Link] in our document:
which produces vector images in encapsulated postscript
\input{[Link]}
format and supports LaTeX syntax in any textlabels.
The above steps can be automated by the package gnuplottex. By placing gnuplot commands inside \beGraphs with gnuplot
gin{gnuplot}\end{gnuplot}, and compiling with latex shell-escape, the graphs are created and added into your
A simple method to include graphs and charts in LaTeX document.
documents is to create it within a common spreadsheet
software (OpenOce Calc or MS Oce Excel etc.) and Failure to access gnuplot from latex for Windows can be
include it in the document as a cropped screenshot. How- solved by making le title only in one word. Don't type
ever, this produces poor quality rasterized images. Calc my [Link] for your title le, but do [Link] .
also allows you to copy-paste the charts into OpenOce When you are using gnuplottex it is also possible to diDraw and save them as PDF les.
rectly pass the terminal settings as an argument to the enUsing Microsoft Excel 2010, charts can be copied di- vironment
rectly to Microsoft Expression Design 4, where they can \begin{gnuplot}[terminal=epslatex,
terminalopbe saved as PDF les. These PDF les can be included tions=color, scale=0.9, linewidth=2 ] ... \end{gnuplot}
in LaTeX. This method produces high quality vectorized
Using gnuplottex can cause fraudulent text-highlighting in
images.
some editors when using algebraic functions on imported
An excellent method to render graphs is through gnuplot, data, such as:
a free and versatile plotting software, that has a special
output lter directly for exporting les to LaTeX. We as- (2*($1)):2
sume, that the data is in a CSV le (comma separated Some editors will think of all following text as part of a
text) in the rst and third column. A simple gnuplot script formula and highlight it as such (because of the '$' that is
interpreted as part of the latex code). This can be avoided
to plot the data can look like this:

10.2. LATEX/TIPS AND TRICKS


by ending with:

177

10.2.7 New even page

#$ \end{gnuplot}

In the twoside-mode you have the ability to get a new oddAs it uncomments the dollar sign for the gnuplot inter- side page by:
preter, but is not aecting the interpretation of the .tex
\cleardoublepage
by the editor.
When using pdfLaTeX instead of simple LaTeX, we must
However, LaTeX doesn't give you the ability to get a new
convert the EPS image to PDF and to substitute the name
even-side page. The following method opens up this;
in the [Link] le. If we are working with a Unix-like
The following must be put in your document preamble:
shell, it is simply done using:
\usepackage{ifthen}
\newcommand{\newevenside}{
\ifthenelse{\isodd{\thepage}}{\newpage}{
\newpage
With the included tex le we can work as with an ordinary
\phantom{placeholder} % doesn't appear on page \thisimage.
pagestyle{empty} % if want no header/footer \newpage
Instead of calling eps2pdf directly, we can also include } }
the epstopdf package that automates the process. If we
include a graphics now and leave out the le extension,
To active the new even-side page, type the following
epstopdf will automatically transform the .eps-le to PDF
where you want the new even-side:
and insert it in the text.
\newevenside
\includegraphics{graph1}
eps2pdf [Link] sed -i s/".eps"/".pdf"/g [Link]

This way, if we choose to output to PS or DVI, the EPS


If the given page is an odd-side page, the next new page is
version is used and if we output to PDF directly, the consubsequently an even-side page, and LaTeX will do nothverted PDF graphics is used. Please note that usage of
ing more than a regular \newpage. However, if the given
epstopdf requires compiling with latex -shell-escape.
page is an even page, LaTeX will make a new (odd) page,
Note: Emacs AucTex users might want to check out put in a placeholder, and make another new (even) page.
Gnuplot-mode.
A crude but eective method.

Generate png screenshots


See Export To Other Formats.

10.2.8 Sidebar with information


If you want to put a sidebar with information like copyright and author, you might want to use the eso-pic package. Example:

\usepackage{eso-pic} ...
\AddToShipoutPic\AtPageLowerLeft{%
\rotatebox{90}{%
\begin{minipage}{\paperheight}
\centerIf you want to spell-check your document, you can use ing\textcopyright~\today{} Humble me \end{minipage}
the command-line aspell, hunspell (preferably), or ispell % } } % }%
programs.

10.2.6

Spell-checking and Word Counting ture{%

ispell [Link] aspell --mode=tex -c [Link] hun- If you want it on one page only, use the starred version of
spell -l -t -i utf-8 [Link]
the AddToShipoutPicture command at the page you want
Both understand LaTeX and will skip LaTeX commands. it. (\AddToShipoutPicture*{...})
You can also use a LaTeX editor with built-in spell checking, such as LyX, Kile, or Emacs. Last another option is
10.2.9 Hide auxiliary les
to convert LaTeX source to plain text and open resulting
le in a word processor like [Link] or KOce. If you're using pdatex you can create a folder in which
If you want to count words you can, again, use LyX or all the output les will be stored, so your top directory
convert your LaTeX source to plain text and use, for ex- looks cleaner.
ample, UNIX wc command:
pdatex -output-directory tmp
detex yourle | wc
An alternative to the detex command is the pdftotext Please note that the folder tmp should exist. However if
command which extracts an ASCII text le from PDF:
you're using a Unix-based system you can do something
1. pdatex [Link] 2. pdftotext [Link] 3. wc like this:
[Link]

alias pdatex='mkdir -p tmp; pdatex -output-directory

178
tmp'
Or for vim modify your .vimrc:
" use pdatex let g:Tex_DefaultTargetFormat='pdf'
let
g:Tex_MultipleCompileFormats='pdf,dvi'
let
g:Tex_CompileRule_pdf = 'mkdir -p tmp; pdatex
-output-directory tmp -interaction=nonstopmode $*; cp
tmp/*.pdf .'

CHAPTER 10. HELP AND RECOMMENDATIONS

Chapter 11

Appendix
11.1 LaTeX/Authors
11.1.1

Peter Flynns Formatting information, a beginners


guide to typesetting with LaTeX. We have contacted him by email asking for permission to use
his work. The original book is released under the
GNU Free Documentation License, the same as Wikibooks. For more information, his personal website
is [Link]

Included books

The following books have been included in this wikibook


(or we are working on it!), with permission of the author:
Andy Roberts Getting to grips with Latex.

11.1.2 Wiki users

Not So Short Introduction to LaTex2e by Tobias


Oetiker, Hubert Partl and Irene Hyna. We have Major contributors to the book on Wikibooks are:
contacted the authors by email asking for permission: they allowed us to use their material, but they
Alessio Damato
never edited directly this wikibook. That book is
Jtwdog
released under the GPL, that is not compatible with
the GFDL used here in Wikibooks. Anyway, we
Pierre Neidhardt
have the permission of the authors to use their work.
You can freely copy text from that guide to here.
If you nd text on both the original book and here
11.2 LaTeX/Links
on Wikibooks, then that text is double licensed under GPL and GFDL. For more information about
Tobias Oetiker and Hubert Partl, their websites Here are some other online resources available:
are [Link] and [Link]
[Link]/partl/ respectively.
Community
LaTeX Primer from the Indian TeX Users Group.
Their document is released under the GNU Free
Documentation License, the same as Wikibooks, so
we can include parts of their document as we wish.
In any case, we have contacted Indian TeX Users
Group and they allowed us to do it.

The TeX Users Group Includes links to free versions


of (La)TeX for many kinds of computers.
UK-TUG The UK TeX Users Group
TUGIndia The Indian TeX Users Group

[Link] Newsgroup for (La)TeX related ques David Wilkins Getting started with LaTeX. The
tions
book is not released under any free license, but we
CTAN hundreds of add-on packages and programs
have contacted the author asking him for the permission to use parts of his book on Wikibooks. He
agreed: his work is still protected but you are alTutorials/FAQs
lowed to copy the parts you want on this Wikibook.
If you see text on both the original work and here,
Tobias Oetikers Not So Short Introduction to
then that part (and only that part) is released under
LaTex2e:
the terms of GFDL, like any other text here on Wik[Link]
ibooks.
english/[Link] also at
[Link]
In progress
//[Link]/~{}oetiker/lshort/[Link]
179

180
Vels introduction to LaTeX: What is it, why should
you use it, who should use it and how to get started:
[Link]
11/4_LaTeX_Document_Preparation_System.
html
Peter Flynns beginners guide (formatting):
[Link]
[Link]
The AMS Short Math Guide for LaTeX, a concise
summary of math formula typesetting features
[Link]
amsmath users guide (PDF) and related les:
[Link]
required/amslatex/math/
LaTeX Primer from the Indian TeX Users Group:
[Link]
LaTeX Primer
[Link]
LaTeXPrimer/
PSTricks--fancy graphics exploiting PDF capabilities
[Link]
PDFScreen--create LaTeX PDF les that have navigation buttons used for presentations:
[Link]

CHAPTER 11. APPENDIX


The Comprehensive LaTeX Symbol List (in PDF)
[Link]
comprehensive/[Link]
Getting to Grips with LaTeX (HTML) Collection
of Latex tutorials taking you from the very basics
towards more advanced topics
[Link]
Chapter 8 (about typesetting mathematics) of the
LaTeX companion
[Link]
[Link]
Reference
LaTeX Project Site
The Comprehensive TeX Archive Network Latest
(La)TeX-related packages and software
TeX Directory Structure, used by many (La)TeX
distributions
Natural Math converts natural language math formulas to LaTeX representation
Obsolete packages and commands
Lamports book LaTeX: A Document Preparation
System

David Bausums list of TeX primitives (these are the


Templates
fundamental commands used in TeX):
[Link]
A resource for free high quality LaTeX templates
Leslie Lamports manual for the commands that
for a variety of applications
are unique to LaTeX (commands not used in plain
LaTeX template for writing PhD thesis, 2007
TeX):
[Link]
UCL computer department thesis template
The UK TeX FAQ List of questions and answers that
UT thesis template, 2006
are frequently posted at [Link]
[Link]
A template that supports an easy conversion to *.odt
(*.doc), *.pdf and *.html in one run, 2009
TeX on Mac OS X: Guide to using TeX and LaTeX
on a Mac
[Link]
Text Processing using LaTeX
[Link]
textprocessing/

11.3 LaTeX/Package Reference

This is an incomplete list of useful packages that can be


used for a wide range of dierent kind of documents.
Each package has a short description next to it and, when
The (La)TeX encyclopaedia
available, there is a link to a section describing such pack[Link]
age in detail. All of them (unless stated) should be in Hypertext Help with LaTeX
cluded in your LaTeX distribution as package_name.sty.
[Link]
For more information, refer to the documentation of the
EpsLatex: a very comprehensive guide to images, single packages, as described in Installing Extra Packages.
gures and graphics
[Link] The list is in alphabetical order.

11.5. LATEX/INDEX

181

11.4 LaTeX/Sample LaTeX docu- 11.5.2 B


ments
babel
The easiest way to learn how to use latex is to look at
how other people use it. Here is a list of real world latex sources that are freely available on the internet. The
information here is sorted by application area, so that it
is grouped by the scientic communities that use similar
notation and LaTeX constructs.

Basics
beamer package
Bibliography Management
BibTeX
Bold

11.4.1

General examples

Tutorial examples, books, and real world uses of LaTeX.


[Link], [Link], [Link]
[Link] and [Link]. The ocial sample
documents...

Bullets
Bullet points

11.5.3 C
Captions

A short example of how to use LaTeX for scientic


reports by Stephen J. Eglen.

Collaborative Writing of LaTeX Documents

The not so Short Introduction to LaTeX by Tobias


Oetiker is distributed with full latex sources.

color package

Color

Columns, see Multi-column Pages

11.4.2

Semantics of Programming Languages

Cross-referencing
Customizing LaTeX

Articles on programming language research, from syntax


to semantics, including source code listings, type rules,
proof trees, and even some category theory. A good 11.5.4 D
place to start is Mitchell Wands Latex Resources, includ Dashes
ing a sample le that also demonstrates Didier Remys
mathpartir package. The following are latex sources of
description environment
some articles, books, or presentations from this eld:
Diactrical marks
Pugs: Bootstrapping Perl 6 with Haskell. This paper
Document Classes
by Audrey Tang contains nice examples on conguring the listings package to format source code.
Document Structure
Drawings

11.5 LaTeX/Index
11.5.5 E
This is an alphabetical index of the book.
e.g. (exempli gratia)

11.5.1

Ellipsis

Absolute Beginners

em-dash

Abstract

en-dash

Accents

enumerate

Algorithms

Errors and Warnings

Arrays

Euro currency symbol

Authors

Export To Other Formats

182

CHAPTER 11. APPENDIX

11.5.6

11.5.10 L

Figures

Labels

Floats

Letters

Fonts

Links

Footer, Page

Lists

Footnotes
Formatting

11.5.11 M
makeidx package

11.5.7

\maketitle

General Guidelines

Margin Notes

Graphics

Creating Graphics

Creating

Mathematics

Embedding

Matrices

Importing
graphicx package

11.5.8

Header, Page
HTML output
Hyperlinks
hyperref package
hyphen
Hyphenation

11.5.9

i.e. (id est)


Images
Importing Graphics
Indexing

Minipage environment example


Multi-column Pages

11.5.12 P
Packages
Creating 1
Page Layout
PDF output
picture
Pictures
PNG output
Presentations
Pseudocode

11.5.13 Q
LaTeX/Paragraph Formatting#Quoting_text

Internationalization
Introduction

11.5.14 R

Italics

References

itemize

RTF output

11.6. LATEX/COMMAND GLOSSARY

11.5.15

183

11.6.1 #

Small Capitals

/ see slash marks

Source Code Listings

\@ following period ends sentence

Space Between Words

\\[*][extra-space] new line

Spell-checking

\, thin space, math and text mode

Superscript and subscript: powers and indices

\; thick space, math mode

Superscript and subscript: text mode


SVG output

11.5.16

Table of contents
Tables

\: medium space, math mode


\! negative thin space, math mode
\- hyphenation; tabbing
\= set tab, see tabbing
\> tab, see tabbing
\< back tab, see tabbing
\+ see tabbing

Teletype text

\' accent or tabbing

Text Size

\` accent or tabbing

Theorems

\| double vertical lines, math mode

Tips and Tricks

\( start math environment

Title Creation

\) end math environment


\[ begin displaymath environment

11.5.17

\] end displaymath environment

URLs

11.6.2 A
11.5.18

Verbatim Text

11.5.19

Word Counting

11.5.20

\addcontentsline{le}{sec_unit}{entry} adds an entry


to the specied list or table
\addtocontents{le}{text} adds text (or formatting
commands) directly to the le that generates the
specied list or table
\addtocounter{counter}{value} increments
counter

the

\address{Return address}

XeTeX

\addtolength{len-cmd}{len} increments a length command, see Length

XY-pic package

\addvspace adds a vertical space of a specied height

xy package

\alph causes the current value of a specied counter to


be printed in alphabetic characters

11.6 LaTeX/Command Glossary

\appendix changes the way sectional units are numbered so that information after the command is considered part of the appendix

This is a glossary of LaTeX commandsan alphabetical


\arabic causes the current value of a specied counter
listing of LaTeX commands with the summaries of their
to be printed in Arabic numbers
eects. (Brackets "[]" are optional arguments and braces
\author declares the author(s). See Document Structure
"{}" are required arguments.)

184

11.6.3

CHAPTER 11. APPENDIX

11.6.6 E

\backslash prints a backslash

\em Toggles italics on/o for the text inside curly braces
with the command. Such as {\em This is in italics
\baselineskip a length command (see Lengths), which
\em but this isn't \em and this is again}. This comspecies the minimum space between the bottom of
mand allows nesting.
two successive lines in a paragraph
\emph Toggles italics on/o for the text in curly braces
\baselinestretch scales the value of \baselineskip
following the command e.g. \emph{This is in italics
\bf Boldface typeface
\emph{but this isn't} and this is again}.
\bibitem generates a labeled entry for the bibliography
\bigskipamount
\bigskip equivalent to \vspace{\bigskipamount}
\boldmath bold font in math mode

\ensuremath (LaTeX2e) Treats everything inside the


curly braces as if it were in a math environment.
Useful when creating commands in the preamble as
they will work inside or out of math environments.

\boldsymbol bold font for symbols

\epigraph Adds an epigraph. Requires epigraph package.

11.6.4

\euro Prints euro symbol. Requires eurosym package.

\cal Calligraphic style in math mode


\caption generate caption for gures and tables
\cdots Centered dots
\centering Used to center align LaTeX environments

11.6.7 F
\fbox
\ushbottom

\chapter Starts a new chapter. See Document Structure. \fnsymbol


\footnote Creates a footnote.

\circle

\cite Used to make citations from the provided bibliog- \footnotemark


raphy
\footnotesize Sets font size. See Text Formatting.
\cleardoublepage
\footnotetext
\clearpage Ends the current page and causes any oats
\frac inserts a fraction in mathematics mode. The usage
to be printed. See Page Layout.
is \frac{numerator}{denominator}.
\cline Adds horizontal line in a table that spans only to
a range of cells. See \hline and Tables chapter.
\frame
\closing Inserts a closing phrase (e.g. \closing{yours \framebox Like \makebox but creates a frame around
sincerely}), leaves space for a handwritten signathe box. See Boxes.
ture and inserts a signature specied by \signature{}.
\frenchspacing Instructs LaTex to abstain from insertUsed in the Letter class.
ing more space after a period (.) than is the case for
\color Species color of the text. LaTeX/Colors
an ordinary character. In order to untoggle this functionality resort to the command \nonfrenchspacing.
\copyright makes sign. See Formatting.

11.6.5
\dashbox

11.6.8 G
11.6.9 H

\date

\hll Abbreviation for \hspace{\ll}.


\ddots Inserts a diagonal ellipsis (3 diagonal dots) in
\hline adds a horizontal line in a tabular environment.
math mode
See also \cline, Tables chapter.
\documentclass[options]{style} Used to begin a latex
\href Add a link, or an anchor. See Hyperlinks
document
\dotll

\hrulell

11.6. LATEX/COMMAND GLOSSARY

185

\hspace Produces horizontal space.

\linethickness

\huge Sets font size. See Text Formatting.

\linewidth

\Huge Sets font size. See Text Formatting.

\listogures Inserts a list of the gures in the document. Similar to TOC

\hyphenation{word list} Overrides default hyphenation


\listoftables Inserts a list of the tables in the document.
algorithm for specied words. See Hyphenation
Similar to TOC

11.6.10

\location

\include This command is dierent from \input in that


11.6.13 M
its the output that is added instead of the commands
from the other les. For more see LaTex/Basics
\makebox Denes a box that has a specied width, independent from its content. See Boxes.
\includegraphics Inserts an image. Requires graphicx
package.

\maketitle Causes the title page to be typeset, using information provided by commands such as \title{}
and \author{}.

\includeonly
\indent

\markboth \markright

\input Used to read in LaTex les.


LaTex/Basics.

For more see

\mathcal

\mathop
\it Italicizes the text which is inside curly braces with
the command. Such as {\it This is in italics}. \em is \mbox Write a text in roman font inside a math part
generally preferred since this allows nesting.
\medskip
\item Creates an item in a list. Used in list structures.
\multicolumn

11.6.11

\multiput

\kill Prevent a line in the tabbing environment from be- 11.6.14


ing printed.

11.6.12

\newcommand Denes a new command.


Commands.

\label Used to create label which can be later referenced


with \ref. See Labels and Cross-referencing.
\large Sets font size. See Text Formatting.

See New

\newcolumntype Denes a new type of column to be


used with tables. See Tables.
\newcounter

\Large Sets font size. See Text Formatting.

\newenvironment Denes a new environment.


New Environments.

\LARGE Sets font size. See Text Formatting.

\newfont

\LaTeX Prints LaTeX logo. See Formatting.

\newlength

\LaTeXe Prints current LaTeX version logo.


Formatting.

See

\ldots Prints sequence of three dots. See Formatting.


\left
\lefteqn
\line
\linebreak Suggests LaTeX to break line in this place.
See Page Layout.

See

\newline Ends current line and starts a new one. See


Page Layout.
\newpage Ends current page and starts a new one. See
Page Layout.
\newsavebox
\newtheorem
\nocite Adds a reference to the bibliography without an
inline citation. \nocite{*} causes all entries in a bibtex database to be added to the bibliography.

186

CHAPTER 11. APPENDIX

11.6.17 R

\noindent
\nolinebreak

\raggedbottom Command used for top justied within


other environments.
\nonfrenchspacing Setting the command untoggles the
command \frenchspacing and activates LaTeX stan\raggedleft Command used for right justied within
dards to insert more space after a period (.) than
other environments.
after an ordinary character.
\raggedright Command used for left justied within
\normalsize Sets default font size. See Text Formatting.
other environments.
\nopagebreak Suggests LaTeX not to break page in this
\raisebox Creates a box and raises its content. See
place. See Page Layout.
LaTeX/Boxes.
\not
\ref Used to reference to number of previously declared
\label. See Labels and Cross-referencing.

11.6.15

\renewcommand

\onecolumn

\right
\opening Inserts an opening phrase when using the letter
\rm
class, for example \opening{Dear Sir}
\roman
\oval
\overbrace Draws a brace over the argument. Can be \rule Creates a line of specied width and height. See
LaTeX/Rules and Struts.
used in displaystyle with superscript to label formulae. See Advanced Mathematics.
\overline Draws a line over the argument.

11.6.18 S

11.6.16

\savebox Makes a box and saves it in a named storage


bin.

\pagebreak Suggests LaTeX breaking page in this \sbox The short form of \savebox with no optional arguments.
place. See Page Layout.
\pagenumbering Denes the type of characters used
for the page numbers. Options : arabic, roman, Roman, alph, Alph, gobble (invisible).

\sc Small caps.


\scriptsize Sets font size. See Text Formatting.

\pageref Used to reference to number of page where \section Starts a new section. See Document Structure.
a previously declared \label is located. See Floats, \setcounter
Figures and Captions.
\setlength
\pagestyle See Page Layout.
\settowidth
\par Starts a new paragraph
\paragraph Starts a new paragraph. See Document \sf Sans serif.
Structure.

\shortstack
\parbox Denes a box whose contents are created in \signature In the Letter class, species a signature for
paragraph mode. See Boxes.
later insertion by \closing.
\parindent Normal paragraph indentation.
See
\sl Slanted.
Lengths.
\slash See slash marks
\parskip
\part Starts a new part of a book. See Document Struc- \small Sets font size. See Text Formatting.
ture.
\smallskip
\protect
\sout Strikes out text. Requires ulem package. See Text
Formatting.
\providecommand (LaTeX2e) See Macros.
\put

\space force ordinary space

11.6. LATEX/COMMAND GLOSSARY

187

\sqrt Creates a root (default square, but magnitude can \title


be given as an optional parameter).
\today Writes current day. See Text Formatting.
\stackrel Takes two arguments and stacks the rst on
\tt
top of the second.
\twocolumn

\stepcounter Increase the counter.


\subparagraph Starts a new subparagraph.
Document Structure.

See \typeout
\typein

\subsection Starts a new subsection. See Document


Structure.
11.6.20
\subsubsection Starts a new sub-subsection.
Document Structure.

11.6.19

See

\uline Underlines text. Requires ulem package. See


Formatting.
\underbrace

\underline
\tableofcontents Inserts a table of contents (based on
section headings) at the point where the command \unitlength
appears.
\usebox
\telephone In the letter class, species the senders tele\usecounter
phone number.
\uwave Creates wavy underline. Requires ulem pack\TeX Prints TeX logo. See Text Formatting.
age. See Formatting.
\textbf{} Sets bold font style. See Text Formatting.
\textcolor{}{} Creates colored text. See Entering col- 11.6.21 V
ored text.
\value
\textit{} Sets italic font style. See Text Formatting.
\vbox{text} Encloses a paragraphs text to prevent it
\textmd{} Sets medium weight of a font. See Text Forfrom running over a page break
matting.
\vcenter
\textnormal{} Sets normal font. See Text Formatting.
\vdots Creates vertical dots. See Mathematics.
\textrm{} Sets roman font family. See Text Formatting.
\vector
\textsc{} Sets font style to small caps. See Text Format\verb Creates inline verbatim text. See Formatting.
ting.
\textsf{} Sets sans serif font family. See Text Format- \vll
ting.
\vline
\textsl{} Sets slanted font style. See Text Formatting.

\vphantom

\texttt{} Sets typewriter font family. See Text Format- \vspace


ting.
\textup{} Sets upright shape of a font. See Text For- This page uses material from Dr.
Hypertext Help with LaTeX.
matting.
\textwidth
\textheight
\thanks
\thispagestyle
\tiny Sets font size. See Text Formatting.

Sheldon Greens

Chapter 12

Text and image sources, contributors, and


licenses
12.1 Text
LaTeX/Introduction Source: [Link] Contributors: var Arnfjr Bjarmason,
Tualha, Iamunknown, 3mta3, Jraregris, Goodgerster, Derbeth, Graemeg, Elwikipedista, Withinfocus, Pdelong, Orderud, Whiteknight,
Kernigh, Latexing, Sgenier, Igjimh, Alejo2083, Chazz, Gronau, Xania, Rehoot, Sjlegg, [Link], Urhixidur, Nbrouard, Vadik wiki,
Pi zero, Dan Polansky, Waldir, QuiteUnusual, Piksi, Kri, Mckay, Tom Morris, [Link], Nobelium, Ambrevar, Martinkunev, PAC2,
Anarchyboy, Tomato86, Staticshakedown, E.lewis1, InverseHypercube, Polytropos Technikos, TinyTimZamboni, AllenZh, Ppadmapriya,
Benson Muite, Steelangel, Reddraggone9 and Anonymous: 75
LaTeX/Installation Source: [Link] Contributors: 3mta3, Koavf, MichaelBillington, Mwtoews, Pi zero, Marcus Cyron, Gyro Copter, Kazkaskazkasako, Nobelium, Ambrevar, PAC2, Jason barrington, Mfwitten,
Tomato86, Benregn, LlamaAl, Hahc21, RainCity471 and Anonymous: 34
LaTeX/Installing Extra Packages Source: [Link] Contributors: Alejo2083, Xania, Pi zero, Zylorian, Ollydbg, Mabdul, Ambrevar, Lotus noir, Netheril96, DarkSheep and Anonymous: 20
LaTeX/Basics Source: [Link] Contributors: Krischik, Chuckhomann, 3mta3,
ABCD, Derbeth, Jonathan Webley, Withinfocus, Snaxe920, Jtwdog, Tpr, Jguk, Bilbo1507, Igjimh, Dilaudid, Alejo2083, Mwtoews,
Thenub314, Rehoot, Vadik wiki, Qeny, Atallcostsky, Pi zero, Waldir, MER-C, TomyDuby, CrazyTerabyte, Kri, Adrignola, Constantine, Ambrevar, PAC2, Chisophugis, Immae, Janskalicky, Tomato86, Robbiemorrison, E.lewis1, BrettMontgomery, Guyrobbie, Patuck,
ATC2, DragonLord, Guzo, Wickedjargon, Pater Christophorus, Reddraggone9 and Anonymous: 79
LaTeX/Document Structure Source: [Link] Contributors: Derbeth, Withinfocus, Orderud, Stephan Schneider, Snaxe920, Jtwdog, Jomegat, Nkour, Igjimh, Dilaudid, Alejo2083, JECompton, Mwtoews, BiT, Thenub314, ConditionalZenith, Xania, FlashSheridan, Spelemann, Kovianyo, Recent Runes, Astrophizz, Spag85, Pi zero,
Tully, Waldir, Nux, Jan Winnicki, QuiteUnusual, Neet, Kri, Lovibond, Adrignola, Hosszuka, Wdcf, Ambrevar, Lucasreddinger, Keplerspeed, Dirk Hnniger, Frap, Tomato86, Derwaldrandfoerster, Echeban, LlamaAl, Ntypanski, Wickedjargon, Genethecist, Reddraggone9,
Kurlovitsch, Kw [Link] and Anonymous: 76
LaTeX/Text Formatting Source: [Link] Contributors: Derbeth, Withinfocus, Igjimh, Thenub314, Pi zero, ChrisHodgesUK, Adrignola, Ambrevar, Dirk Hnniger, Robbiemorrison, Fishix, Bgeron, RubensMatos, Kurlovitsch, Lindhea and Anonymous: 15
LaTeX/Paragraph Formatting Source: [Link] Contributors:
Ish ishwar, ABCD, Derbeth, QuantumEleven, Jonathan Webley, Withinfocus, Orderud, Jtwdog, Andyr, Igjimh, Alejo2083, Mwtoews,
Thenub314, ConditionalZenith, Mcld, Kovianyo, MartinSpacek, Crasshopper, Recent Runes, Pi zero, Tully, Ffangs, Hjsb, Yez, Waldir,
CarsracBot, Hannes Rst, Rror, Adrianwn, ChrisHodgesUK, Pstar, QuiteUnusual, Neet, LR, Adrignola, Nixphoeni, PatrickDevlin21,
Ambrevar, Zzo38, Cdecoro, Keplerspeed, Zrisher, GPHemsley, Henrybissonnette, TorfusPolymorphus, Smobbl Bobbl, ToematoeAdmn,
Dirk Hnniger, Mouselb, EvanKroske, Tomato86, Fishpi, Robbiemorrison, Tazquebec, Brammers, Listdata, Neoriddle, Xonqnopp, C3l,
Harrikoo, Gmh04, InverseHypercube, Halilsen, RealSebix, Akim Demaille, Dlituiev, SamuelLB, CD-Stevens, Incognito668, Gmacar and
Anonymous: 139
LaTeX/Colors Source: [Link] Contributors: Alejo2083, Xania, Pi zero, Dan Polansky, Daniel Mietchen, Waldir, Gms, JackPotte, White gecko, ChrisHodgesUK, Kazkaskazkasako, Trace, Kri, Adrignola, Benjaminevans82,
ChristianGruen, Sanderd17, Scorwin, Ambrevar, PAC2, Velociostrich, Dirk Hnniger, Tomato86, Conighion, Qzxpqbp, SamuelLB, Henry
Tallboys, Tisep, Tpapastylianou, Honza889 and Anonymous: 49
LaTeX/Fonts Source: [Link] Contributors: Ish ishwar, Derbeth, Xania, Jacho, Mihai
Capot, Joaospam, Pi zero, Waldir, ChrisHodgesUK, Dreaven3, Ambrevar, Wikieditoroftoday, Crissov, InverseHypercube, Flamenco108,
SamuelLB, BYIST, TortoiseWrath, Abramsky, Ben9243 and Anonymous: 26
LaTeX/List Structures Source: [Link] Contributors: Panic2k4, Selfworm, Xania, ChrisHodgesUK, Ambrevar, Arunib, OlivierMehani, Arthurchy, Henrybissonnette, Dirk Hnniger, Cerniagigante, Scientic29, Kejia, SamuelLB, Michael M Hackett, Lanoxx, Stefantauner, Vog2 and Anonymous: 27

188

12.1. TEXT

189

LaTeX/Special Characters Source: [Link] Contributors: Mwtoews, Ysangkok, Pi zero, Waldir, Zvika, Gms, ChrisHodgesUK, Drevicko, Steindani, Silverpie, Chbarts, Ambrevar, [Link],
Robbiemorrison, Wikieditoroftoday, Zwiebelleder, Zxx117, SamuelLB, Yeshua Saves and Anonymous: 40
LaTeX/Internationalization Source: [Link] Contributors: Derbeth,
Jomegat, Alejo2083, Mwtoews, BiT, Hroobjartr, Kovianyo, Skarakoleva, Pi zero, Eudoxos, Louabill, Louisix, ChrisHodgesUK, Drevicko,
Piksi, Adrignola, Chaojoker, Mijikenda, Ambrevar, Tomato86, Jlrn, Harrikoo, Alzahrawi, Gelbukh, ILubeMyCucumbers20, RealSebix,
Saippuakauppias, SamuelLB, Lobaluna, Waylesange, Rotlink, Abalenkm, Hdankowski, RTPK and Anonymous: 55
LaTeX/Rotations Source: [Link] Contributors: Alejo2083, Ysnikraz, Pi zero,
Ambrevar, Erp and Anonymous: 4
LaTeX/Tables Source: [Link] Contributors: Marozols, Ish ishwar, Jotomicron, Derbeth, Jonathan Webley, Fredmaranhao, Withinfocus, Orderud, Jtwdog, Selfworm, HenrikMidtiby, Igjimh, Dilaudid, Alejo2083, Mwtoews,
Thenub314, Dporter, Fmccown, Drewbie, Mcld, Vesal, Collinpark, Ysnikraz, Tweenk, Rogal, Pi zero, Abonnema, Klusinyan, Petter Strandmark, SteveM82, ChrisHodgesUK, QuiteUnusual, PsyberS, Kri, Adrignola, Benjaminevans82, Byassine52, Skou, Rdg nz, Hosszuka, Emreg00, Zyqqh, Sargas, Maratonda, SciYann, [Link], Grenouille, Erylaos, Ambrevar, Bumbulski, PAC2, Quaristice, Yanuzz, Chuaprap,
Canageek, Helptry, Arided, Topodelapradera, Dirk Hnniger, Robbiemorrison, Sandrobt, Tomxlawson, Crissov, GorillaWarfare, Gallen01,
Dubbaluga, Xonqnopp, [Link], Jevon, JV, Bro4, Gelbukh, Willy james, RealSebix, Ricordisamoa, SamuelLB, Sandbergja, Bianbum, Gibravo, Olaf3142, Squigish, ColeLoki, Tia sng mt tri, AndreKR and Anonymous: 168
LaTeX/Title Creation Source: [Link] Contributors: Derbeth, Cfailde,
Jonathan Webley, Withinfocus, Jomegat, Alejo2083, JECompton, Mwtoews, Thenub314, Recent Runes, He7d3r, Pi zero, Adrignola,
Sargas, Ambrevar, Infenwe, Spirosdenaxas, Dirk Hnniger, Anarchyboy, Ftravers, Neoriddle, Ediahist, SamuelLB, Jluttine, ZimbiX,
Colonel486 and Anonymous: 31
LaTeX/Page Layout Source: [Link] Contributors: Panic2k4, Derbeth,
Withinfocus, Orderud, Mecanismo, Jtwdog, Jomegat, Igjimh, Alejo2083, Mwtoews, Xania, Herbythyme, Drewbie, Rajkiran g, Ojan,
Pi zero, Sabalka, Waldir, QuiteUnusual, Neet, Adrignola, Vaelkake, LQST, Ambrevar, Infenwe, Jafeluv, JenVan, Adouglass, Tomato86,
Scientic29, Computermacgyver, Spook, Halilsen, Harp, RealSebix, SamuelLB, Anthony Deschamps, Bibi6, Daveturnr, Tisep, Lindhe94
and Anonymous: 87
LaTeX/Importing Graphics Source: [Link] Contributors: ZeroOne, Insaneinside, 3mta3, Derbeth, Withinfocus, Orderud, Jtwdog, NavarroJ, Igjimh, Dilaudid, Alejo2083, Mwtoews, Hankwang, Tuka,
ConditionalZenith, TWiStErRob, Matthias M., Hippasus, Spag85, Pi zero, Dan Polansky, Ffangs, Bsander, Waldir, ChrisHodgesUK,
Mathieu Perrin, Martin scharrer, QuiteUnusual, Piksi, Kri, Adrignola, Cengique, KlausFoehl, Wn202, Bcmpinc, Ambrevar, Snoopy67,
Danielstrong52, Dirk Hnniger, Wysinwygaa, Jycn, Tomato86, Robbiemorrison, MarSraM, Harrywt, Mikhail Ryazanov, Xonqnopp,
Jstein, Crasic, Nemoniac, RealSebix, QUBot, SamuelLB, Maschen, MQ978, [Link] and Anonymous: 104
LaTeX/Floats, Figures and Captions Source: [Link]
2694618 Contributors: Derbeth, Withinfocus, Orderud, Jtwdog, Robin, Hansfn, HenrikMidtiby, Igjimh, Dilaudid, Alejo2083, Basenga,
Mwtoews, Qwertyus, DavidMcKenzie, Mcld, Spag85, Pi zero, Tully, Borgg, Icc97, Waldir, ChrisHodgesUK, Whym, Robert Borkowski,
Tosha, Joe Schmedley, Neet, Svick, Hello71, Adrignola, Hosszuka, Rhalah, Ypey, Wdcf, Martin von Wittich, Ambrevar, Gryllida, Rafopar,
Janltx, Je ne dtiens pas la vrit universelle, Caesura, Syockit, Tomato86, Robbiemorrison, Wikieditoroftoday, Karper, Jer789, Wxm29,
Anubhab91, SamuelLB, Konteki, [Link], Linzhongpeng and Anonymous: 112
LaTeX/Hyperlinks Source: [Link] Contributors: Derbeth, Jomegat, Alejo2083,
Qwertyus, Urhixidur, LaTeX, MartinSpacek, Recent Runes, Pi zero, Dan Polansky, Blacktrumpeter, Waldir, Pamputt, ChrisHodgesUK,
SiriusB, Neet, Adrignola, Calimo, Wdcf, Juliabackhausen, Ambrevar, Modest Genius, Roarbakk, Belteshazzar, Bytecrook, Tomato86,
Robbiemorrison, Gwpl, Courcelles, Teles, Neoriddle, Xonqnopp, Jwchong, Prawojazdy, Kevinesta, PeterAllen, Thietkeweb, Joeyboi,
Lnkbuildingservices4u, Mimo, Bajrangkhichi96, Deltasun, Ghoti, Froskoy, SamuelLB, Shahbaz Yousse, Niy, BlackMagic1943 and
Anonymous: 52
LaTeX/Labels and Cross-referencing Source: [Link]
2673141 Contributors: Derbeth, Jomegat, NavarroJ, Alejo2083, Mwtoews, DavidMcKenzie, Mcld, Kovianyo, MartinSpacek, Hulten, Recent Runes, Pi zero, Waldir, TomyDuby, Adrignola, Sargas, Ambrevar, Dirk Hnniger, Robbiemorrison, InverseHypercube, SamuelLB,
Otec Stochastik, Escalator and Anonymous: 52
LaTeX/Errors and Warnings Source: [Link] Contributors:
Darklama, Alejo2083, Mwtoews, Chazz, Thenub314, Xania, Pi zero, Waldir, Rogerbrent, ChrisHodgesUK, Wkdurfee, LR, Kri, Adrignola,
Ambrevar, Nothing1212, Bro4, SamuelLB, AlanBarrett and Anonymous: 19
LaTeX/Lengths Source: [Link] Contributors: Panic2k4, Derbeth, Withinfocus,
Hokiehead, Igjimh, Alejo2083, Pi zero, Scruss, Waldir, Ollydbg, Kri, Adrignola, Ambrevar, Dendik, Xonqnopp, Ediahist, Strpeter and
Anonymous: 15
LaTeX/Counters Source: [Link] Contributors: Ambrevar and Anonymous: 2
LaTeX/Boxes Source: [Link] Contributors: Selfworm, LivingShadow, Kri, Ambrevar, Kundor, AthanasiusOfAlex, Goldenburg111 and Anonymous: 8
LaTeX/Rules and Struts Source: [Link] Contributors: Ollydbg,
Ambrevar and Anonymous: 1
LaTeX/Mathematics Source: [Link] Contributors: Insaneinside, 3mta3,
Juliusross, Atiq ur Rehman, Derbeth, Jonathan Webley, Withinfocus, Orderud, Mecanismo, Ans, Jtwdog, Jomegat, Krishnavedala, Robin,
Cameronc, Nigels, Pirround, Hagindaz, Igjimh, Dilaudid, Ms2ger, Alejo2083, Basenga, Mwtoews, Swift, BiT, DavidMcKenzie, [Link], Dncarley, Elliptic1, Unco, Mcld, Recent Runes, Bonuama, Adam majewski, Pi zero, Waldir, Marra, Mhue, TomyDuby, Geminatea, ChrisHodgesUK, Whym, Germanzs, Ccero, QuiteUnusual, Winfree, Joe Schmedley, Neet, Asmeurer, Kri, Adrignola, Kwetal,
Tork73, Prispartlow, Sargas, Gtz, YuryKirienko, [Link], Karcih, Ambrevar, Lucasreddinger, Keplerspeed, Kwpolska, Xnn, Merciadriluca, Wmheric, Kubieziel, Dirk Hnniger, [Link], Justin W Smith, [Link], Tomato86, , Robbiemorrison,
Netheril96, Kejia, Karper, Clebell, InverseHypercube, Krst, Greenbreen, Karthicknainar, Fsart, Chafe66, Tgwizard, DmitriyZotikov, McSaks, SamuelLB, Jluttine, Comput2h, Wp4bl0, Volvens, Mandriver, Anthony Deschamps, Ntypanski, Hahc21, Franklin Yu, Unlikelyuser,
Briancricks, Strpeter, Komputerwiz, Hapli, Bigwyrm, Yotann and Anonymous: 191

190

CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

LaTeX/Advanced Mathematics Source: [Link] Contributors:


Sbeyer, 3mta3, Jonathan Webley, Ynhockey, Inductiveload, BiT, Thenub314, Ojan, Pi zero, Leyo, ChrisHodgesUK, QuiteUnusual, [Link], Adrignola, Nixphoeni, Silca678, LinuxChristian, [Link], TorfusPolymorphus, Simonjtyler, Tomato86, Kcho, Geetha nitc,
MagnusPI, Codairem, Krst, Arthurvogel, SamuelLB, Escalator, Volvens, Paul2520, Goldenburg111 and Anonymous: 44
LaTeX/Theorems Source: [Link] Contributors: 3mta3, Derbeth, Raylu,
Alejo2083, Mwtoews, Kovianyo, Pi zero, Mhue, Tosha, Juliabackhausen, Ambrevar, Tomato86, SamuelLB, Ajmath62, CtrlAltCarrot
and Anonymous: 24
LaTeX/Chemical Graphics Source: [Link] Contributors: CommonsDelinker, Ambrevar, Dirk Hnniger, Wickedjargon, Banwol, Daviewales and Anonymous: 4
LaTeX/Algorithms Source: [Link] Contributors: ZeroOne, Derbeth,
Alejo2083, Mwtoews, Mcld, Webinn, Pi zero, Dan Polansky, Thefrankinator, Lavaka, Nemti, Whym, Tauriel-1, Adrignola, ,
Maartenweyn, Gkc, Sanderd17, Sargas, Saehrimnir, Ambrevar, JenVan, Debejyo, Mrt doulaty, Brevity, Writalnaie, Tomato86, Fishpi,
Pandora85, Bhanuvrat, Nsda, SamuelLB, Glad, Karategeek6, Szellmann, Jimmaykeepsitreal, Harish victory and Anonymous: 84
LaTeX/Source Code Listings Source: [Link] Contributors:
Panic2k4, Jomegat, Alejo2083, Pi zero, Vaucouleur, Drevicko, Hosszuka, Bunyk, Gladiool, Ambrevar, Arthurchy, Helptry, Evin,
Tomato86, Robbiemorrison, Wenzeslaus, Tau Lambda, Sonic the goliath, Yeshua Saves, RasmusWriedtLarsen and Anonymous: 45
LaTeX/Linguistics Source: [Link] Contributors: Neatnate, Xania, Matj
Grabovsk, ChrisHodgesUK, Joe Schmedley, Ambrevar, Dirk Hnniger, DmitriyZotikov, Ghoti, PhilJohnG, Obelyaev, Olesh,
[Link], Hankjones, SamuelLB, Masterpiga and Anonymous: 12
LaTeX/Indexing Source: [Link] Contributors: Itai, Derbeth, Mecanismo, Stephan
Schneider, Alejo2083, Mwtoews, Kovianyo, Uluboz, He7d3r, Pi zero, Neoptolemus, Dan Polansky, Tully, Morelight, Petter Strandmark,
Neet, Kri, Adrignola, Sargas, WardMuylaert, Dirk Hnniger, Tomato86, Semperos, Nsuwan, SamuelLB, PaulVanDerWalt, Bombcar and
Anonymous: 14
LaTeX/Glossary Source: [Link] Contributors: Panic2k4, Recent Runes, Dan
Polansky, Redirect xer, QuiteUnusual, Speravir, Pmlineditor, Ambrevar, Topodelapradera, Dirk Hnniger, Tomato86, Robbiemorrison,
Bro4, RealSebix, SamuelLB, MoMaT, Hendiadyon, Jessevanassen, Berettag, Tlinnet, Ffavela, Tanzaho, Gmacar, Tonda, Donok11 and
Anonymous: 30
LaTeX/Bibliography Management Source: [Link] Contributors: ZeroOne, Derbeth, Withinfocus, Orderud, Stephan Schneider, Jtwdog, Igjimh, Alejo2083, Mwtoews, Braindrain0000, Qwertyus, Rondenaranja, Thenub314, Drewbie, Oderbolz, Spelemann, Amamory, Kovianyo, Nbrouard, MartinSpacek, Blaisorblade, He7d3r,
Spag85, Pi zero, Kevang, Waldir, Mhue, MichaelSchoenitzer, ChrisHodgesUK, Kazkaskazkasako, Kroolik, Arbitrarily0, QuiteUnusual,
Kri, Vermiculus, Silca678, Rafaelgr, Rbonvall, Eyliu, StevenJohnston, Sandman10000, Sargas, Nobelium, Ambrevar, Tdomhan, Lucasreddinger, John1923, TorfusPolymorphus, MichaelBueker, Topodelapradera, Dirk Hnniger, Lbailey45, Robbiemorrison, Rossdub, Crissov,
Xonqnopp, Jevon, [Link], Bro4, RealSebix, Gillespie09, Literaturgenerator, QUBot, PatrickGalyon, SamuelLB, Jluttine, Austinmohr, Ch605852, Gmacar, Kurlovitsch, Jpoosterhuis and Anonymous: 152
LaTeX/More Bibliographies Source: [Link] Contributors:
Adrignola, Ambrevar, Jimbotyson, Billy the Goat II, Wootery and Anonymous: 14
LaTeX/Letters Source: [Link] Contributors: Derbeth, Edudobay, Mwtoews, Xania,
Jld, Garoth, Pi zero, Neoptolemus, CarsracBot, Gms, ChrisHodgesUK, QuiteUnusual, Ambrevar, GavinMcGimpsey, Tomato86, E.lewis1,
SamuelLB, Empirical bayesian, TheAnarcat and Anonymous: 25
LaTeX/Presentations Source: [Link] Contributors: Ish ishwar, 3mta3, Derbeth, Xania, Kovianyo, Pi zero, Ramac, Dan Polansky, Flal, Jayk, ChrisHodgesUK, FredrikMeyer, Eyliu, Dreaven3, PAC, Sanderd17,
Sargas, [Link], Ambrevar, Stuples, PAC2, NqpZ, Helptry, Grj23, Mezzaluna, Flip, Robbiemorrison, Neoriddle, Xonqnopp, SamuelLB,
Dr0pi, Espinozahg, Goldkatze, Hapli and Anonymous: 47
LaTeX/Teachers Corner Source: [Link] Contributors: PAC, Ambrevar, PAC2, Tomato86, SamuelLB and Anonymous: 9
LaTeX/Curriculum Vitae Source: [Link] Contributors: Jomegat,
QuiteUnusual, Ambrevar, Reyk, Mariafenrinha, Jianhui67, CallumPoole and Anonymous: 9
LaTeX/Introducing Procedural Graphics Source: [Link]
oldid=2711314 Contributors: 3mta3, Kenyon, Jonathan Webley, Jomegat, Alejo2083, Mwtoews, Qwertyus, Rajkiran g, Pi zero, Dan
Polansky, Thefrankinator, Jacobrothstein, [Link], Simeon, ChrisHodgesUK, Tosha, Kri, , Adrignola, Ambrevar, Keplerspeed, Unbitwise, Rnddim, Dirk Hnniger, Jdgilbey, Jycn, Krisrose, Tomato86, Wikieditoroftoday, Pmillerrhodes, Atulya1988, Franzl
aus tirol, Wxm29, SamuelLB and Anonymous: 23
LaTeX/MetaPost Source: [Link] Contributors: Ambrevar
LaTeX/Picture Source: [Link] Contributors: Svick, Ambrevar, Wxm29, Tentotwo
and Anonymous: 7
LaTeX/PGF/TikZ Source: [Link] Contributors: JonnyJD, QuiteUnusual, Kri,
Ambrevar, Franzl aus tirol, Dlituiev and Anonymous: 7
LaTeX/PSTricks Source: [Link] Contributors: ChrisHodgesUK, Ambrevar,
Netheril96, Karlberry and Anonymous: 1
LaTeX/Xy-pic Source: [Link] Contributors: ChrisHodgesUK, Kri, Ambrevar and
Dirk Hnniger
LaTeX/Creating 3D graphics Source: [Link] Contributors:
Kri, Nobelium and Ambrevar

12.2. IMAGES

191

LaTeX/Macros Source: [Link] Contributors: Risk, Mecanismo, Alejo2083, Mwtoews, Pi zero, Tully, Hsmyers, Waldir, ChrisHodgesUK, LR, Kri, Adrignola, Hosszuka, Ambrevar, [Link]., Dirk Hnniger, Robbiemorrison, Aadornellesf, SamuelLB, Funkenstern, AsphyxiateDrake, Yeshua Saves and Anonymous: 35
LaTeX/Plain TeX Source: [Link] Contributors: Blaisorblade, Ambrevar,
Yeshua Saves and Anonymous: 7
LaTeX/Creating Packages Source: [Link] Contributors: Ambrevar
and Anonymous: 4
LaTeX/Themes Source: [Link] Contributors: Ambrevar and Anonymous: 1
LaTeX/Modular Documents Source: [Link] Contributors: Derbeth, Alejo2083, Mwtoews, [Link], Pi zero, ChrisHodgesUK, Neet, Adrignola, Nixphoeni, Liiiii, Frakturfreund, Zyqqh, Ambrevar,
Robbiemorrison, Neoriddle, Ediahist, MaBoehm, SamuelLB, CD-Stevens, Vinaisundaram, [Link], Wgjbeek and Anonymous: 19
LaTeX/Collaborative Writing of LaTeX Documents Source: [Link]
20LaTeX%20Documents?oldid=2602612 Contributors: Derbeth, Arnehe, Pi zero, Madskaddie, Schaber, Waldir, ChrisHodgesUK, QuiteUnusual, Tosha, Kpym, Tim Parenti, Ambrevar, Keplerspeed, Jason barrington, Dirk Hnniger, Bamgooly, Robbiemorrison, [Link],
Wikieditoroftoday, Jmcdon10, Hermine potter, SamuelLB, Jbsnyder and Anonymous: 36
LaTeX/Export To Other Formats Source: [Link]
Contributors: Derbeth, Jomegat, Alejo2083, Mwtoews, Pi zero, ChrisHodgesUK, Bpsullivan, Bakken, Ambrevar, Keplerspeed, SamuelLB,
Wenzeslaus, Migueldvb, Xin-Xin W., [Link] and Anonymous: 20
LaTeX/FAQ Source: [Link] Contributors: Xania, Kayau, Ambrevar, Ghostofkendo,
Dredmorbius, Sobjornstad and Anonymous: 11
LaTeX/Tips and Tricks Source: [Link] Contributors: Derbeth,
Withinfocus, Jguk, Alejo2083, Basenga, Mwtoews, Filip Dominec, Pi zero, Towsonu2003, Brendanarnold, ChrisHodgesUK, Winniehell,
Limpato, Vaelkake, Sargas, Ambrevar, Bumbulski, Tomato86, Robbiemorrison, Wikieditoroftoday, Jamoroch, Russell208, SamuelLB
and Anonymous: 43
LaTeX/Authors Source: [Link] Contributors: Derbeth, Alejo2083, Pi zero, Ambrevar and Anonymous: 1
LaTeX/Links Source: [Link] Contributors: Derbeth, Jonathan Webley, Withinfocus,
Orderud, Dmb, Alejo2083, Jasu, Pi zero, Ambrevar, RaymondSutanto, Rotlink, Eselmeister and Anonymous: 7
LaTeX/Package Reference Source: [Link] Contributors: Dan
Polansky, Ambrevar, Wickedjargon and Dredmorbius
LaTeX/Sample LaTeX documents Source: [Link]
Contributors: Thenub314, Vesal, Pi zero, Ambrevar and Anonymous: 2
LaTeX/Index Source: [Link] Contributors: Derbeth, Jonathan Webley, Pi zero, Ramac, Dan Polansky, Ffangs, TomyDuby, [Link], Ambrevar, Dirk Hnniger and Anonymous: 1
LaTeX/Command Glossary Source: [Link] Contributors: Robert
Horning, Derbeth, Withinfocus, Orderud, Naught101, Dmb, Igjimh, IrfanAli, Spelemann, Paxinum, Pi zero, Dan Polansky, TomyDuby,
ChrisHodgesUK, Pstar, Adrignola, Tuetschek, Kpym, Royote, Stoettner, Dirk Hnniger, Robbiemorrison, Xeracles and Anonymous: 29

12.2 Images
File:50_percents.svg Source: [Link] License: CC0 Contributors: File:
50%.svg Original artist: Ftiercel
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Pmillerrhodes
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Pmillerrhodes
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Dirk Hnniger
File:Ammonium_sulphate_mhchem.png Source: [Link]
License: Cc-by-3.0 Contributors: ? Original artist: ?
File:[Link] Source: [Link] License:
Public domain Contributors:
own work
Original artist:
Mij
File:[Link] Source: [Link] License: Public domain Contributors: My computer Original artist: Myself
File:Blocks_beamer_example.png Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Israel Buitron
File:Book_important2.svg Source: [Link] License: CC-BY-SA3.0 Contributors: Own work Original artist: darklama

192

CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

File:[Link] Source: [Link] License: Public domain Contributors: Own work Original artist: Winfree
File:[Link] Source: [Link] License: Public domain
Contributors: self-made in ChemDraw Original artist: Ben Mills
File:Carbon_Lewis_Structure_PNG.png Source: [Link]
[Link] License: CC-BY-SA-4.0 Contributors: Own work Original artist: Daviewales
File:[Link] Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Olesh
File:Chemfig_angles.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:Chemfig_bonds.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Transferred from [Link]; transferred to Commons by User:Sanderd17 using CommonsHelper. Original artist: Original uploader
was Jtwdog at [Link]
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Transferred from [Link]; transferred to Commons by User:Sanderd17 using CommonsHelper. Original artist: Original uploader
was Jtwdog at [Link]
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Transferred from [Link]; transferred to Commons by User:Sanderd17 using CommonsHelper. Original artist: Original uploader was
Jtwdog at [Link]
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Transferred from [Link]; transferred to Commons by User:Sanderd17 using CommonsHelper. Original artist: Original uploader
was Jtwdog at [Link]
File:[Link] Source: [Link] License: GPL Contributors: Self-made.
Based on Image:[Link], which was released into the public domain by its creator AzaToth. Original artist: Tkgd2007
File:Corticosterone_(1).png Source: [Link] License:
Public domain Contributors: Transferred from [Link]; transferred to Commons by User:Sfan00_IMG using CommonsHelper. Original artist: Original uploader was Iorsh at [Link]
File:[Link] Source: [Link] License: ? Contributors: ? Original artist: ?
File:[Link] Source:
[Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: GPL Contributors:
Transferred from [Link]; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original uploader
was Arnehe at [Link]
File:[Link] Source: [Link] License: ? Contributors: ? Original artist: ?
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Lanoxx
File:[Link] Source: [Link] License: Public domain Contributors: ? Original
artist: ?
File:Example_of_French_quotation_marks.png Source: [Link]
quotation_marks.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Karl Scheel
File:Example_of_German_quotation_marks.png Source:
[Link]
German_quotation_marks.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Karl Scheel
File:Frametitle_keyword_example.png Source: [Link]
png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Israel Buitron
File:[Link] Source: [Link] License: CC0 Contributors: Own work Original artist: jeg
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Hankjones
File:Gummi_0.6.1_screenshot.png Source: [Link] License: MIT Contributors: Transferred from [Link]; transferred to Commons by User:FSII using CommonsHelper on Labs.
Original artist: Gummi team. Original uploader was Sanderd17 at [Link]
File:H2O_Lewis_Structure_PNG.png Source: [Link]
png License: CC-BY-SA-4.0 Contributors: Own work Original artist: Daviewales

12.2. IMAGES

193

File:Information_icon4.svg Source: [Link] License: Public domain Contributors: modied versions from below, which were modies of [Link] Original artist: penubag (color adjustments)
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: ? Original artist: ?
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work
Original artist: Hankjones
File:[Link] Source: [Link] License: CC0 Contributors: Own work Original
artist: ChrisHodgesUK
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: GPL Contributors: Transferred from [Link]; transferred to Commons by User:Adrignola using CommonsHelper. Original
artist: Original uploader was Arnehe at [Link]
File:[Link] Source: [Link] License:
GPL Contributors: Transferred from [Link]; transferred to Commons by User:Adrignola using CommonsHelper. Original artist:
Original uploader was Arnehe at [Link]
File:[Link] Source: [Link] License: GPL
Contributors: Transferred from [Link]; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original
uploader was Arnehe at [Link]
File:[Link] Source: [Link] License: CCBY-SA-3.0 Contributors: ? Original artist: ?
File:[Link] Source: [Link] License: GPL
Contributors: Transferred from [Link]; transferred to Commons by User:Adrignola using CommonsHelper. Original artist: Original
uploader was Arnehe at [Link]
File:Kile_1.[Link] Source: [Link] License: GPL Contributors: ? Original
artist: ?
File:Koma_env.png Source: [Link] License: Cc-by-sa-3.0 Contributors:
own work, basing on Formal - Another proposition from Wikipedia:Example requests for permission under GFDL license
Original artist:
gms
File:[Link] Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link]
Source:
[Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link] License: ? Contributors:
[Link] Original artist:
Andrew Roberts
File:[Link] Source: [Link]
png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link] License: ? Contributors:
own work, basing on Formal - Another proposition from Wikipedia:Example requests for permission under GFDL license Original artist:
Derbeth
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86

194

CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

File:[Link] Source: [Link] License: CC-BYSA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Tomato86
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_-_Indented_Equations.png Source: [Link]
png License: Public domain Contributors: Own work Original artist: Inductiveload
File:LaTeX_Dotsb.png Source: [Link] License: Public domain Contributors: Own work Original artist: Neet
File:LaTeX_Dotsc.png Source: [Link] License: Public domain Contributors: Own work Original artist: Neet
File:LaTeX_Dotsi.png Source: [Link] License: Public domain Contributors: Own work Original artist: Neet
File:LaTeX_Dotsm.png Source: [Link] License: Public domain Contributors: Own work Original artist: Neet
File:LaTeX_Dotso.png Source: [Link] License: Public domain Contributors: Own work Original artist: Neet
File:LaTeX_TabWidth1.svg Source: [Link] License: CC-BYSA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_TabWidth2.svg Source: [Link] License: CC-BYSA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_TabXWidth1.svg Source: [Link] License: CCBY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_TabXWidth2.svg Source: [Link] License: CCBY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_animal_table.svg Source: [Link] License: CCBY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_animal_table_with_booktabs.svg Source: [Link]
with_booktabs.svg License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_bibliography_abbrv.svg Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_bibliography_alpha.svg Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_bibliography_plain.svg Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_colour_demo_1.png Source: [Link] License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_desc-[Link] Source: [Link] License: CCBY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:LaTeX_diagram.svg Source: [Link] License: CC-BY-SA-3.0
Contributors: This vector image was created with Inkscape. Original artist: Alessio Damato
File:LaTeX_example_dcolumn.png Source: [Link] License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_example_dcolumn_bold.png Source: [Link]
[Link] License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_example_split_gather.png Source: [Link]
png License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_example_sqrt.png Source: [Link] License: CC0
Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_figure_caption_with_lof_entry.png Source:
[Link]
caption_with_lof_entry.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Mwtoews
File:LaTeX_font_example.png Source: [Link] License: CC0
Contributors: Own work Original artist: ChrisHodgesUK
File:LaTeX_logo.svg Source: [Link] License: Public domain Contributors: ? Original artist: ?
File:LaTeX_program_package_example01.png
Source:
[Link]
program_package_example01.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: MyName (Gkc (<a
href='//[Link]/wiki/User_talk:Gkc' title='User talk:Gkc'>talk</a>))
File:LaTeX_sloppypar.png Source: [Link] License: Public domain Contributors:
own work
Original artist:
Derbeth

12.2. IMAGES

195

File:LaTeX_tabularx_multi.svg Source: [Link] License:


CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Lavaka
File:[Link] Source: [Link] License: Public domain Contributors: Own work Original artist: Nemti
File:[Link] Source: [Link]
[Link] License: GFDL Contributors: Own work Original artist: Daniele Pighin
File:[Link] Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Tomato86
File:[Link]
Source:
[Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: Public domain Contributors: Own work Original artist: Matj Korvas
File:[Link] Source: [Link]
png License: CC0 Contributors: Own work Original artist: [Link]
File:[Link]
Source:
[Link]
[Link] License: CC0 Contributors: Own work Original artist: [Link]
File:[Link] Source: [Link] License: CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:Latex_Beamer_-_Columns_Example_2.png Source: [Link]
Columns_Example_2.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Flip
File:Latex_Pascal_Listing.png Source: [Link] License: CCBY-3.0 Contributors: LaTeX / GIMP Original artist: LaTeX / GIMP
File:Latex_caption_example.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: own work, but the image of the gull thats from commons Image:Gull portrait ca [Link] Original artist:
Alessio Damato
File:Latex_dashes_example.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: its from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permission of
the author Original artist: Tobias Oetiker
File:Latex_example_arrows.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: part of "the not so short introduction to LaTeX", used with permission of the author Original artist: Alessio
Damato
File:Latex_example_bezier.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio
Damato
File:Latex_example_box_test.png Source: [Link] License: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='[Link]
tex-archive/info/lshort/english/[Link]'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist:
Alessio Damato
File:Latex_example_box_test_2.png Source: [Link]
License: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='[Link]
tex-archive/info/lshort/english/[Link]'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist:
Alessio Damato
File:Latex_example_catenary.png Source: [Link] License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist:
Alessio Damato
File:Latex_example_circles.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio
Damato
File:Latex_example_defining_multiple_columns.svg Source: [Link]
defining_multiple_columns.svg License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Latex_example_enumitem_inline_list.svg Source:
[Link]
enumitem_inline_list.svg License: CC-BY-SA-3.0 Contributors: Own work Original artist: Arthurchy
File:Latex_example_figure_referencing.png Source: [Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato 13:31, 12 January 2007 (UTC)
File:Latex_example_ligatures.png Source: [Link] License: CC-BY-SA-3.0 Contributors: its from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permission of the author Original artist: Tobias Oetiker
File:Latex_example_line_segments.png Source:
[Link]
[Link] License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author
Original artist: Alessio Damato

196

CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

File:Latex_example_math_referencing.png Source: [Link]


[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_example_middle.png Source: [Link] License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:Latex_example_multiple_pics.png Source: [Link]
png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original
artist: Alessio Damato
File:Latex_example_multiput.png Source: [Link] License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist:
Alessio Damato
File:Latex_example_newenvironment.png
Source:
[Link]
[Link] License: CC-BY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text'
href='[Link] not so short introduction to LaTeX</a>, used with permission
of the authors Original artist: Alessio Damato
File:Latex_example_ovals.png Source: [Link] License: CCBY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio
Damato
File:Latex_example_paralist.svg Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Latex_example_rapidity.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio
Damato
File:Latex_example_referencing_section.png Source:
[Link]
referencing_section.png License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_example_rule.png Source: [Link] License: CCBY-SA-3.0 Contributors: taken as a screenshot of <a data-x-rel='nofollow' class='external text' href='[Link]
lshort/english/[Link]'>The not so short introduction to LaTeX</a>, used with permission of the authors Original artist: Alessio Damato
File:Latex_example_sidecap.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: User:Mwtoews
File:Latex_example_subfig.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_example_tabular_cline.svg Source: [Link]
svg License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Latex_example_text_dots.png Source: [Link] License: CC-BY-SA-3.0 Contributors: its from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permission of the author Original artist: Tobias Oetiker
File:Latex_example_text_formulas.png Source: [Link]
png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original
artist: Alessio Damato
File:Latex_example_wrapfig.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_example_wrapfig_vspace.png Source: [Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_example_wrapped_table.svg Source: [Link]
[Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Latex_example_xypics_arrow_list.png Source: [Link]
arrow_list.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author
Original artist: Alessio Damato
File:Latex_example_xypics_arrows_1.png Source: [Link]
arrows_1.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio Damato
File:Latex_example_xypics_arrows_2.png Source: [Link]
arrows_2.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio Damato
File:Latex_example_xypics_arrows_3.png Source: [Link]
arrows_3.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio Damato
File:Latex_example_xypics_arrows_labels.png Source:
[Link]
xypics_arrows_labels.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission
of the author Original artist: Alessio Damato
File:Latex_example_xypics_basic.png Source: [Link]
png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission of the author Original artist: Alessio Damato

12.2. IMAGES

197

File:Latex_example_xypics_curved_arrow.png Source:
[Link]
xypics_curved_arrow.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission
of the author Original artist: Alessio Damato
File:Latex_example_xypics_inarrow_labels.png Source:
[Link]
xypics_inarrow_labels.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission
of the author Original artist: Alessio Damato
File:Latex_example_xypics_standard_arrow.png Source: [Link]
xypics_standard_arrow.png License: CC-BY-SA-3.0 Contributors: part of the not so short introduction to LaTeX, used with permission
of the author Original artist: Alessio Damato
File:Latex_layout.svg Source: [Link] License: CC-BY-SA-3.0 Contributors: the [Link] LaTeX package, heavily post-processed by myself Original artist: Alessio Damato
File:Latex_new_squareroot.png Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_picture_example.png Source: [Link] License:
CC0 Contributors: Own work Original artist: ChrisHodgesUK
File:Latex_qtree_simple_tree.png Source: [Link] License: CC0 Contributors: Own work Original artist: Philip John Gorinski
File:Latex_quote_3.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Thenub314
File:Latex_quote_4.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Tomato86
File:Latex_ready-made_strings.png Source: [Link] License: CC-BY-SA-3.0 Contributors: its from The not so short introduction to LaTeX, a GPLed book by Tobias Oetiker, used with permission of the author Original artist: Tobias Oetiker
File:Latex_showkeys_example.png Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Alessio Damato
File:Latex_sizes_table.png Source: [Link] License: CC-BY-SA3.0 Contributors: Own work Original artist: Jtwdog at [Link]
File:Latex_wikibook_test_title.svg Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Listings_Example.svg Source: [Link] License: CC-BY-SA3.0 Contributors: Own work Original artist: Ambrevar
File:[Link] Source: [Link] License: CC-BY3.0 Contributors: Own work Original artist: Literaturgenerator
File:[Link] Source: [Link] License: Public domain Contributors:
Screenshot taken by myself. Original artist: LyX developer team (see [Link])
File:Mathscr_(A-F).png Source: [Link] License: CC-BYSA-3.0 Contributors: File:[Link] Original artist: Waldir
File:[Link] Source: [Link] License: Public domain Contributors: ? Original artist: ?
File:Methane_chemfig.png Source: [Link] License: CC-BY-SA3.0 Contributors: Own work Original artist: Pmillerrhodes
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:Neighbourhood_definition2.svg Source: [Link]
License: CC-BY-SA-3.0 Contributors:
Neighbourhood_denition2.png Original artist: Neighbourhood_denition2.png: Wegmann
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Dirk Hnniger
File:Nuvola_apps_important_yellow.svg
Source:
[Link]
LGPL Contributors:
An icon from [Link].bz2 (specically
important_yellow.svg License:
Nuvola/icons/scalable/emblems/[Link]) by David Vignoni. Original artist: Modied to look more like the PNG
le by Bastique. Recolored by amurai.
File:[Link] Source: [Link] License:
CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link]
License: CC-BY-SA-3.0 Contributors: Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own work Original artist: Jimbotyson

198

CHAPTER 12. TEXT AND IMAGE SOURCES, CONTRIBUTORS, AND LICENSES

File:[Link] Source: [Link] License: ? Contributors: ? Original artist: ?


File:[Link] Source: [Link] License: ? Contributors: ? Original artist: ?
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors: Own
work Original artist: Tomato86
File:Ring2_chemfig.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:Ring3_chemfig.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:Ring4_chemfig.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:Ring_chemfig.png Source: [Link] License: CC-BY-SA-3.0
Contributors: Own work Original artist: Pmillerrhodes
File:Simple_sideways_tree.png Source: [Link] License:
CC0 Contributors: Own work Original artist: Philip John Gorinski
File:[Link] Source: [Link] License: CC-BY-SA3.0 Contributors: Own work Original artist: Pmillerrhodes
File:Soliton_2nd_order.svg Source:
[Link] License:
CC-BY-SA-3.0 Contributors:
This image was created with gnu<a data-x-rel='nofollow' class='external text' href='http:
//[Link]/check?uri=http%3A%2F%[Link]%2Fwiki%2FSpecial%3AFilepath%2FSoliton_2nd_order.
svg,<span>,&,</span>,ss=1#source'>plot</a>. Original artist: Alessio Damato
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: ? Contributors: ? Original artist: ?
File:[Link] Source: [Link] License: GPL Contributors: Screenshot Original artist: PAC2
File:[Link] Source: [Link] License: CC0 Contributors: Own
work Original artist: Ambrevar
File:[Link] Source: [Link] License: CC-BY-SA-3.0 Contributors:
Own work Original artist: Dirk Hnniger
File:[Link] Source: [Link] License: GFDL Contributors: based on the rst version of the Wikipedia logo, by Nohat. Original artist: version 1 by Nohat (concept by Paullusmagnus);

12.3 Content license


Creative Commons Attribution-Share Alike 3.0

Common questions

Powered by AI

The spacing and alignment in LaTeX, particularly for mathematical equations, can be controlled using several commands. For instance, horizontal and vertical spacing can be managed with commands like \hspace{} and \vspace{}, respectively . For mathematical equations, specific spacing between elements can be adjusted using commands such as \qquad, \quad, \;, and \,. Additionally, the command \ensuremath ensures consistent treatment of expressions within or outside math environments . These commands help maintain the visual structure and readability of documents.

Online LaTeX editors like Authorea provide several advantages over traditional installations. They enable collaboration in real-time, allowing multiple users to edit and access the same document simultaneously, which is convenient for group projects and shared research . Additionally, online editors eliminate the need for complicated installation processes and are accessible from any device with internet access, ensuring consistency across user experiences. These platforms also often include features such as automatic version control and backup, reducing the risk of losing work and simplifying document management .

The AMS math package, known as amsmath, is crucial in LaTeX for its enhanced capability to handle complex mathematical formulas beyond the basic constructs provided by LaTeX. It introduces numerous powerful and flexible commands specifically designed for advanced mathematical typesetting, which are essential for scientific documents loaded with complex equations . The package also includes features for better equation management, such as improved alignment and automatic numbering of equations . A key component in professional-quality typesetting of mathematics, the amsmath package also enables the use of additional packages like mathtools, which further extend its capabilities by fixing quirks and introducing new settings and symbols .

To use LaTeX on a personal computer, the primary components required include: a TeX distribution, a text editor, and a file viewer. The TeX distribution provides the necessary tools for typesetting documents, including a TeX compiler to generate output files from source LaTeX . The text editor is essential for writing the source document and should be one where the user will spend most of their time . Lastly, a file viewer like a PDF viewer is needed to view the final output after compilation, as LaTeX usually outputs to formats such as PDF or DVI .

Bibliography management in LaTeX can be simplified by using a dedicated bibliography management tool. Tools like JabRef or BibDesk allow users to create and manage bibliography files (*.bib) easily. They provide graphical interfaces for entering and organizing reference data, which can then be directly used by BibTeX in the LaTeX document . These tools automate the citation process and help manage large sets of references efficiently, reducing manual error and ensuring consistency in bibliographic styles.

TeX Live is a major TeX distribution that is compatible with a wide range of operating systems, including *BSD, GNU/Linux, Mac OS X, and Windows, making it highly versatile . MiKTeX, on the other hand, is a distribution specifically designed for Windows . MacTeX is tailored for Mac OS, and it is based on the TeX Live distribution, but specifically packaged for Mac users . This makes TeX Live the most universally applicable across different operating systems.

Subfloats in LaTeX are used to organize multiple figures within a single float environment, which is useful for maintaining alignment and uniformity in documentation. Using the 'subcaption' package, subfloats allow each subfigure to have its own caption and optionally a global caption for the entire set . When using subfloats, the layout of figures is managed automatically, either in a side-by-side arrangement when space allows or shifting the layout to fit the page dimensions. This feature helps maintain a clean and cohesive presentation of related figures .

The \ command in LaTeX is used to create a line break within environments that require it, such as in a table or within certain environments like \multicolumn or \array, where pressing "Enter" does not automatically cause a new line . It’s important to use \ judiciously as unnecessary line breaks can affect the visual representation of the content and are usually associated with formatting text within LaTeX environments .

Web-based collaborative platforms offer significant advantages for managing large bibliographic databases compared to traditional installations. They provide centralized access to bibliographic data, making it easier to share and update information within a team . Such platforms can offer seamless integration with various citation styles and formats, facilitating the use of references across different word-processing software. They eliminate the need for manually merging bibliographic data from disparate sources, reducing the potential for errors and increasing efficiency in maintaining consistent, up-to-date citation libraries .

TeX systems such as MiKTeX simplify the exportation of LaTeX documents to other markup languages by providing built-in macros and tools to compile and convert source files. These systems can directly compile LaTeX documents into DVI, PDF, or PS formats, which can then be exported to markup languages such as HTML or XML . The integration of these features within TeX systems allows for consistent formatting and ease of conversion, streamlining the process of generating web-compatible documents from LaTeX sources .

You might also like