latex basics
DESCRIPTION
An introduction to LaTeX, system for typesetting technical and scientific documents.TRANSCRIPT
. . . . . .
LATEX Basics
Kristen Sauby, Rosana Zenil-Lopez, Gabriela Blohm
Department of BiologyUniversity of Florida
April 1, 2011
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 1 / 29
. . . . . .
What is LATEX?
a programming language used to create attractive andconsistently formatted documents
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 2 / 29
. . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types ofdocuments
automatic numbering of sections, figures, tables, andformulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
. . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types ofdocuments
automatic numbering of sections, figures, tables, andformulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
. . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types ofdocuments
automatic numbering of sections, figures, tables, andformulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
. . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types ofdocuments
automatic numbering of sections, figures, tables, andformulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
. . . . . .
Why would you want to use LATEX?
consistent formatting
fancy fonts
make posters, presentations, and other types ofdocuments
automatic numbering of sections, figures, tables, andformulas
creation of a bibliography and index
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 3 / 29
. . . . . .
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
. . . . . .
Why would you want to use LATEX?
include, align, and number attractive mathematicalformulas
n!
k !(n − k)!=
(n
k
)(1)
limx→∞
exp(−x) = 0 (2)
Am,n =
a1,1 a1,2 · · · a1,na2,1 a2,2 · · · a2,n...
... . . . ...am,1 am,2 · · · am,n
(3)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 5 / 29
. . . . . .
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
. . . . . .
Why would you want to use LATEX?
Embed R code and objects
> 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)))
treatment outcome counts1 1 1 18.002 1 2 17.003 1 3 15.004 2 1 20.005 2 2 10.006 2 3 20.007 3 1 25.008 3 2 13.009 3 3 12.00
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 7 / 29
. . . . . .
We’ll Work Through an Example Together
Go to latexlab.org or open the example .tex file on yourcomputer.
We’ll use this example document to understand better thestructure of LATEX documents.
In LATEX lab, select“split” (near the bottom left of thepage)
this lets us see the .tex document and the ouputdocument (the compiled document) in the samewindow.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
. . . . . .
We’ll Work Through an Example Together
Go to latexlab.org or open the example .tex file on yourcomputer.
We’ll use this example document to understand better thestructure of LATEX documents.
In LATEX lab, select“split” (near the bottom left of thepage)
this lets us see the .tex document and the ouputdocument (the compiled document) in the samewindow.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
. . . . . .
We’ll Work Through an Example Together
Go to latexlab.org or open the example .tex file on yourcomputer.
We’ll use this example document to understand better thestructure of LATEX documents.
In LATEX lab, select“split” (near the bottom left of thepage)
this lets us see the .tex document and the ouputdocument (the compiled document) in the samewindow.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 8 / 29
. . . . . .
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
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
preamble (commands that affect 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 thefinal document)
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 10 / 29
. . . . . .
LATEX Document Structure
Begin your document using the following command:\documentstyle[options]{class}
where options include such specifications as
font size
number of columns
paper size
and the class is the type of document that you want tomake
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 11 / 29
. . . . . .
LATEX Document Structure
Next list the packages to be used:\usepackage[options]{package}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 12 / 29
. . . . . .
LATEX Document Structure
The preamble can also include:
title and author information
date
font specification
and more
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 13 / 29
. . . . . .
LATEX Document Structure
After completing the preamble begin the document:
\begin{document}
At the end of the document you must include thecommand:
\end{document}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 14 / 29
. . . . . .
Compiling Your LATEX
Once you have the document set up, you can then addtext, figures, formulas, tables, etc. to the document.
When you are ready to create a PDF, you“compile” thedocument.
In LATEX lab, go to the“Compiler”drop-down menu andselect“Compile”.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 15 / 29
. . . . . .
Types of Functions in LATEX
Ways to organize or include data:
verbatim
itemize
enumerate
figure
table
tabular
Try adding a bulleted list to the example .tex file.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 16 / 29
. . . . . .
Types of Functions in LATEX
Ways to organize or include data:
verbatim
itemize
enumerate
figure
table
tabular
Try adding a bulleted list to the example .tex file.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 16 / 29
. . . . . .
Types of Functions
You can also include comments (that don’t appear in thefinal, compiled document) by using the % symbol.
Anything after the % symbol will not be evaluated byLATEX when compiling the document.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 17 / 29
. . . . . .
Including Math in LATEX
Note that our example .tex file includes\usepackage{amsmath} in the preamble.
This package lets us include mathematical formulas in ourLATEX document.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 18 / 29
. . . . . .
Including Math in LATEX
The example .tex file includes this formula:\begin{align}E &= mcˆ2 \\m &= \frac{m 0}{\sqrt{1-\frac{vˆ2}{cˆ2}}}\end{align}The“align”command is specific to mathematical formulasand allows you to align the“=”symbol of multipleformulas.
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 19 / 29
. . . . . .
Using R and LATEX
Unfortunately, LATEX lab doesn’t support Sweave...
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 20 / 29
. . . . . .
Using R and LATEX
To include R objects/code in a LATEX document:
In the preamble include:
\usepackage{Sweave}
After \begin{document} include:
<<include Sweave options here>>=include R data here@
Save your file with the“.Rnw”extension instead of“.tex”
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
. . . . . .
Using R and LATEX
To include R objects/code in a LATEX document:
In the preamble include:
\usepackage{Sweave}
After \begin{document} include:
<<include Sweave options here>>=include R data here@
Save your file with the“.Rnw”extension instead of“.tex”
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
. . . . . .
Using R and LATEX
To include R objects/code in a LATEX document:
In the preamble include:
\usepackage{Sweave}
After \begin{document} include:
<<include Sweave options here>>=include R data here@
Save your file with the“.Rnw”extension instead of“.tex”
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 21 / 29
. . . . . .
Using R and LATEX
To include R objects/code in a LATEX document:
Execute the“.Rnw”fileI using your text editorI using R
This produces a“.tex”file which you can then compile
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 22 / 29
. . . . . .
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
. . . . . .
Using R and LATEX
Use the function xtable from library xtable to includetables:<<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
. . . . . .
Using R and LATEX
Use the function xtable from library xtable to includetables
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 25 / 29
. . . . . .
Using R and LATEX
print(xtable(data.frame(treatment, outcome, counts)))produces this table:
treatment outcome counts
1 1 1 18.002 1 2 17.003 1 3 15.004 2 1 20.005 2 2 10.006 2 3 20.007 3 1 25.008 3 2 13.009 3 3 12.00
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 26 / 29
. . . . . .
Use as a Reference Manager
make a“.bib”file containing reference information
include \usepackage{cite} in your preamble
use commands such as \citep{your-ref-name} in thebody of your document where you want to include acitationinclude the following commands at the end of thedocument to compile the reference list:
I \bibliography{name-of-your-bib-file}I \bibliographystyle{name-of-ref-style}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
. . . . . .
Use as a Reference Manager
make a“.bib”file containing reference information
include \usepackage{cite} in your preamble
use commands such as \citep{your-ref-name} in thebody of your document where you want to include acitationinclude the following commands at the end of thedocument to compile the reference list:
I \bibliography{name-of-your-bib-file}I \bibliographystyle{name-of-ref-style}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
. . . . . .
Use as a Reference Manager
make a“.bib”file containing reference information
include \usepackage{cite} in your preamble
use commands such as \citep{your-ref-name} in thebody of your document where you want to include acitation
include the following commands at the end of thedocument to compile the reference list:
I \bibliography{name-of-your-bib-file}I \bibliographystyle{name-of-ref-style}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
. . . . . .
Use as a Reference Manager
make a“.bib”file containing reference information
include \usepackage{cite} in your preamble
use commands such as \citep{your-ref-name} in thebody of your document where you want to include acitationinclude the following commands at the end of thedocument to compile the reference list:
I \bibliography{name-of-your-bib-file}I \bibliographystyle{name-of-ref-style}
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 27 / 29
. . . . . .
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
. . . . . .
This is a very brief overview of LATEX but we hope that youhave learned something useful!
Questions?
Sauby, Zenil, Blohm (U of Fl) LATEXBasics April 1, 2011 29 / 29