This document provides an introduction to LaTeX, covering what LaTeX is, why you would want to use it, its document structure, and how to include math, R code/objects, and references. LaTeX is a programming language used to create consistently formatted documents across different document types. It allows for fancy fonts, automatic numbering, and embedding of other objects like figures, tables, and R code/outputs. The document structure in LaTeX includes the preamble, top matter, main text, appendices, bibliography, and comments.
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
LaTeX Basics
1. . . . . . .
LATEX Basics
Kristen Sauby, Rosana Zenil-Lopez, Gabriela Blohm
Department of Biology
University of Florida
April 1, 2011
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 1 / 29
2. . . . . . .
What is LATEX?
a programming language used to create attractive and
consistently formatted documents
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 2 / 29
3. . . . . . .
Why would you want to use LATEX?
consistent formatting
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
4. . . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
5. . . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types of
documents
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
6. . . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types of
documents
automatic numbering of sections,
7. gures, tables, and
formulas
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
8. . . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types of
documents
automatic numbering of sections,
9. gures, tables, and
formulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
10. . . . . . .
Why would you want to use LATEX?
!"##$ %"##& '"##( )"##g
*"##+ ,"##- ."##g /"##g
D. Taraborelli !2008", The Beauty of LATEX
Some rights reserved. ##$%&$'(
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 4 / 29
11. . . . . . .
Why would you want to use LATEX?
include, align, and number attractive mathematical
formulas
n!
k!(n k)!
=
(
n
k
)
(1)
lim
x!1
exp(x) = 0 (2)
Am;n =
a1;1 a1;2 a1;n
a2;1 a2;2 a2;n
...
...
. . . ...
am;1 am;2 am;n
(3)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 5 / 29
12. . . . . . .
Why would you want to use LATEX?
Embed R code and objects
sample(100, 5)
[1] 85 79 82 62 73
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 6 / 29
14. We'll Work Through an Example Together
Go to latexlab.org or open the example .tex
15. le on your
computer.
. . . . . .
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
16. We'll Work Through an Example Together
Go to latexlab.org or open the example .tex
17. le on your
computer.
We'll use this example document to understand better the
structure of LATEX documents.
. . . . . .
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
18. We'll Work Through an Example Together
Go to latexlab.org or open the example .tex
19. le on your
computer.
We'll use this example document to understand better the
structure of LATEX documents.
In LATEX lab, select split (near the bottom left of the
page)
this lets us see the .tex document and the ouput
document (the compiled document) in the same
window.
. . . . . .
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
20. What types of documents can you make in LATEX?
. . . . . .
Classes of LATEX documents include:
article
book
beamer (for presentations)
and more
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 9 / 29
21. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
22. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
23. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
the written document (abstract, sections, etc.)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
24. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
the written document (abstract, sections, etc.)
appendices
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
25. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
the written document (abstract, sections, etc.)
appendices
table of contents
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
26. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
the written document (abstract, sections, etc.)
appendices
table of contents
bibliography
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
27. . . . . . .
LATEX Document Structure
preamble (commands that aect the entire document)
top matter (title, date, authors, etc.)
the written document (abstract, sections, etc.)
appendices
table of contents
bibliography
comments (i.e., text that does not show up in the
29. . . . . . .
LATEX Document Structure
Begin your document using the following command:
ndocumentstyle[options]fclassg
where options include such speci
30. cations as
font size
number of columns
paper size
and the class is the type of document that you want to
make
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 11 / 29
31. . . . . . .
LATEX Document Structure
Next list the packages to be used:
nusepackage[options]fpackageg
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 12 / 29
32. . . . . . .
LATEX Document Structure
The preamble can also include:
title and author information
date
font speci
33. cation
and more
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 13 / 29
34. . . . . . .
LATEX Document Structure
After completing the preamble begin the document:
nbeginfdocumentg
At the end of the document you must include the
command:
nendfdocumentg
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 14 / 29
35. . . . . . .
Compiling Your LATEX
Once you have the document set up, you can then add
text,
36. gures, formulas, tables, etc. to the document.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 15 / 29
37. . . . . . .
Types of Functions in LATEX
Ways to organize or include data:
verbatim
itemize
enumerate
38. gure
table
tabular
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 16 / 29
39. . . . . . .
Types of Functions in LATEX
Ways to organize or include data:
verbatim
itemize
enumerate
42. . . . . . .
Types of Functions
You can also include comments (that don't appear in the
43. nal, compiled document) by using the % symbol.
Anything after the % symbol will not be evaluated by
LATEX when compiling the document.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 17 / 29
44. . . . . . .
Including Math in LATEX
Note that our example .tex
45. le includes
nusepackagefamsmathg in the preamble.
This package lets us include mathematical formulas in our
LATEX document.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 18 / 29
46. . . . . . .
Including Math in LATEX
The example .tex
47. le includes this formula:
nbeginfaligng
E = mc^2 nn
m = nfracfm 0gfnsqrtf1-nfracfv^2gfc^2ggg
nendfaligng
The aligncommand is speci
48. c to mathematical formulas
and allows you to align the=symbol of multiple
formulas.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 19 / 29
49. . . . . . .
Using R and LATEX
Unfortunately, LATEX lab doesn't support Sweave...
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 20 / 29
50. Using R and LATEX
To include R objects/code in a LATEX document:
. . . . . .
In the preamble include:
nusepackagefSweaveg
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
51. Using R and LATEX
To include R objects/code in a LATEX document:
. . . . . .
In the preamble include:
nusepackagefSweaveg
After nbeginfdocumentg include:
include Sweave options here=
include R data here
@
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
52. Using R and LATEX
To include R objects/code in a LATEX document:
. . . . . .
In the preamble include:
nusepackagefSweaveg
After nbeginfdocumentg include:
include Sweave options here=
include R data here
@
Save your
53. le with the .Rnwextension instead of
.tex
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
54. . . . . . .
Using R and LATEX
To include R objects/code in a LATEX document:
Execute the .Rnw
55. le
I using your text editor
I using R
This produces a .tex
56. le which you can then compile
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 22 / 29
57. . . . . . .
Using R and LATEX
Example:
=
sample(100,5)
@
Will produce:
sample(100, 5)
[1] 72 67 41 24 83
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 23 / 29
58. . . . . . .
Using R and LATEX
Use the function xtable from library xtable to include
tables:
Results=TEX=
library(xtable)
counts - c(18,17,15,20,10,20,25,13,12)
outcome - gl(3,1,9)
treatment - gl(3,3)
print(xtable(data.frame(treatment, outcome, counts)))
@
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 24 / 29
59. . . . . . .
Using R and LATEX
Use the function xtable from library xtable to include
tables
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 25 / 29
60. Using R and LATEX
print(xtable(data.frame(treatment, outcome, counts)))
produces this table:
treatment outcome counts
1 1 1 18.00
2 1 2 17.00
3 1 3 15.00
4 2 1 20.00
5 2 2 10.00
6 2 3 20.00
7 3 1 25.00
8 3 2 13.00
9 3 3 12.00
. . . . . .
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 26 / 29
61. . . . . . .
Use as a Reference Manager
make a .bib
62. le containing reference information
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
63. . . . . . .
Use as a Reference Manager
make a .bib
64. le containing reference information
include nusepackagefciteg in your preamble
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
65. . . . . . .
Use as a Reference Manager
make a .bib
66. le containing reference information
include nusepackagefciteg in your preamble
use commands such as ncitepfyour-ref-nameg in the
body of your document where you want to include a
citation
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
67. . . . . . .
Use as a Reference Manager
make a .bib
68. le containing reference information
include nusepackagefciteg in your preamble
use commands such as ncitepfyour-ref-nameg in the
body of your document where you want to include a
citation
include the following commands at the end of the
document to compile the reference list:
I nbibliographyfname-of-your-bib-
70. . . . . . .
Good Resources for LATEX
LATEX Wikibook
Online LATEX Equation Editor
Sweave User Manual
A Beamer Quickstart
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 28 / 29
71. This is a very brief overview of LATEX but we hope that you
have learned something useful!
. . . . . .
Questions?
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 29 / 29