This is material for a small tutorial on LaTeX and reproducible document generation.
For full productivity, install LaTeX and an editor, for which I suggest TexMaker.
To avoid installations, sign up at sharelatex or overleaf. Sharelatex seems to be slightly better and is open source.
For reprodicible research, automated report generation and syntax-higlighted code inclusion, use rmarkdown. To couple that with the power of LaTeX, you do have to install LaTeX locally.
Install a recent version of R and Rstudio.
In R, run install.packages("rmarkdown")
, which will also install knitr.
In Rstudio, go to tools -> global options -> Sweave
and set "weave Rnw files using" to knitr
.
To check whether everything is running, download and unzip the example presentation.
Open rdwd_pres.Rnw
and click "compile PDF" (CTRL+SHIFT+K).
If LaTeX produces errors because no figures are created, try the following:
- install the
rdwd
package manually withinstall.packages("rdwd")
in R - remove the
cache
folder - compile again
For my presentations, I am now using a template:
install.packages("berryFunctions")
berryFunctions::instGit("brry/berryFunctions") # createPres is not on CRAN yet
library(berryFunctions)
?createPres
Part 1 (Berry, 1 hour)
- 05 min: general LaTeX intro
- 10: doc structure, document class beamer
- 10: compiling
- 05: sectioning
- 10: including figures
- 05: onslide, pause, <+->
- 05: knitr intro
- 10: real life example
10 min break
Part 2 (Irene, 45 min)
- 05: document class
- 10: subsections, Table of contents (TOC)
- 10: tables (Website tex table generator)
- 10: equations
- 10: templates
For literature management, I recommend to use zotero as a Firefox addon.
On journal article pages, simply save references into zotero, then export as BibLaTex file, e.g. myreferences.bib
.
If (instead of just bibtex) you want to use the modern biblatex with biber, set the following:
- In
TexMaker - Options - configure TexMaker - Commands
change the Bibtex entry from "bibtex %.aux" to "biber %" or "biber %.bcf". - In
TexMaker - Options - configure TexMaker - Quick build
select "PdfLaTeX + Bib(la)tex + PdfLaTeX (x2) + View pdf" - In the document itself, use
\usepackage[backend=biber]{biblatex}
,\bibliography{myreferences}
and\printbibliography{}
.
Here is a complete example (included as tex file along with myreferences.bib in the example folder):
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,
citestyle=authoryear,
natbib=true, % for \citet etc
maxcitenames=2]{biblatex}
\bibliography{myreferences} % filename without file extension!
\begin{document}
This is random sample text, so go ahead and read our paper \citet{boessenkool_effects_2016} and maybe also
\citet{allan_anticipated_2010}.
\printbibliography{}
\end{document}