---
title: "A Quick Demo of Mixing LaTeX with R Markdown"
output:
  pdf_document:
    citation_package: "natbib"
    keep_tex: true
    includes: 
      in_header: header.tex
documentclass: "article"
fontsize: 11pt
geometry: margin=1in
bibliography: paper.bib
---

# Using LaTeX in R Markdown

As this document will be compiled to PDF, we can mix ***markdown*** markup with
LaTeX markup, as in this citation: \citet{Zeil09}.

R chunks are added using the usual R markdown syntax. If we add a figure caption
to a chunk that produces a plot, the graphic will be put in a figure 
environment in the generated LaTeX code and this will float by default. To place
the graphic at the point in the text where the chunk is in the `.Rmd` file, 
we can use `fig.pos = "H"`; this requires the LaTeX **float** package, 
which we load in a custom `header.tex`, see the YAML header in the `.Rmd` file 
and the accompanying `header.tex` file.

```{r, fig.align = "center", fig.cap = "A Figure", fig.pos = "H"}
library(colorspace)
# from ?rainbow_hcl
wheel <- function(col, radius = 1, ...)
  pie(rep(1, length(col)), col = col, radius = radius, ...) 
wheel(rainbow_hcl(12))
```

With the `keep_tex: true` option in the YAML header, the `.tex` file that is 
generated when converting the `.Rmd` to PDF is kept, so you can see how the
R code and markdown has been converted to LaTeX code.

# References
