% Writing beautiful and reproducible slides quickly % Yihui Xie % 2012/04/30
- after you finished typing
\documentclass{beamer}
and\title{}
, I have finished my first slide with markdown - far fewer commands to remember, e.g. to write bullet points, just begin with a dash "
-
" instead of\begin{itemize}
and\item
; how things can be simpler? - I know you want math to show you are a statistician, e.g.
$f(k)={n \choose k}p^{k}(1-p)^{n-k}$ - you do not need to maintain output -- only maintain a source file
- HTML5/CSS3 is much more fun than LaTeX
head(cars)
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
cor(cars)
## speed dist
## speed 1.0000 0.8069
## dist 0.8069 1.0000
library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
- source editor: RStudio (perfect integration with knitr; one-click compilation); currently you have to use the version >= 0.96.109
- HTML5 slides converter: pandoc; this document was generated by:
pandoc -s -S -i -t dzslides --mathjax knitr-slides.md -o knitr-slides.html
- the file
knitr-slides.md
is the markdown output from its source:library(knitr); knit('knitr-slides.Rmd')
- or simple click the button
Knit HTML
in RStudio
- you should tweak the default style; why not try some Google web fonts? (think how painful it is to wrestle with fonts in LaTeX)
- pandoc provides 3 types of HTML5 slides (dzslides is one of them)
- you can tweak the default template to get better appearances
- if you have come up with a better dzslides template, please let me know or contribute to pandoc directly (e.g.
pre
blocks should havemax-width
andmax-height
)
- pandoc supports conversion to beamer as well. period.
- ...
It is good to include the session info, e.g. this document is produced with knitr. Here is my session info:
print(sessionInfo(), locale = FALSE)
## R version 3.2.3 (2015-12-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 15.04
##
## attached base packages:
## [1] stats graphics grDevices utils datasets base
##
## other attached packages:
## [1] ggplot2_2.0.0 knitr_1.11.24
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.2 codetools_0.2-14 digest_0.6.8 grid_3.2.3
## [5] plyr_1.8.3 gtable_0.1.2 formatR_1.2.2 magrittr_1.5
## [9] evaluate_0.8 scales_0.3.0 stringi_1.0-1 labeling_0.3
## [13] tools_3.2.3 stringr_1.0.0 munsell_0.4.2 colorspace_1.2-6
## [17] methods_3.2.3
- the plots are too wide? use the chunk option
out.width
which will be used in<img width=... />
, e.g.out.width=400px