blob: 399c6896373bbec90dc355a9339c6fc9e96fe8eb [file] [log] [blame]
JJ Allaire5dc9fe02016-01-30 18:44:51 -05001---
2title: "R Markdown Format for reveal.js Presentations"
3output:
4 github_document:
5 toc: true
JJ Allaireb9873562016-01-30 19:26:11 -05006 toc_depth: 2
JJ Allaire5dc9fe02016-01-30 18:44:51 -05007---
8
9## Overview
10
11This repository provides an [R Markdown](http://rmarkdown.rstudio.com) custom format for [reveal.js](http://lab.hakim.se/reveal-js/#/) HTML presentations.
12
13You can use this format in R Markdown documents by installing this package as follows:
14
15```r
JJ Allaired9f38d22016-01-31 14:15:59 -050016install.packages("revealjs", type = "source")
JJ Allaire5dc9fe02016-01-30 18:44:51 -050017```
18
19
20To create a [reveal.js](http://lab.hakim.se/reveal-js/#/) presentation from R Markdown you specify the `revealjs_presentation` output format in the front-matter of your document. You can create a slide show broken up into sections by using the `#` and `##` heading tags (you can also create a new slide without a header using a horizontal rule (`----`). For example here's a simple slide show:
21
22 ---
23 title: "Habits"
24 author: John Doe
25 date: March 22, 2005
26 output: revealjs::revealjs_presentation
27 ---
28
29 # In the morning
30
31 ## Getting up
32
33 - Turn off alarm
34 - Get out of bed
35
36 ## Breakfast
37
38 - Eat eggs
39 - Drink coffee
40
41 # In the evening
42
43 ## Dinner
44
45 - Eat spaghetti
46 - Drink wine
47
48 ## Going to sleep
49
50 - Get in bed
51 - Count sheep
52
Daniel Chen46087c32016-03-21 17:58:14 -040053## Rendering
54
Daniel Chen81a14342016-03-21 18:00:56 -040055Depending on your use case, there are 3 ways you can render the presentation.
Daniel Chen46087c32016-03-21 17:58:14 -040056
571. RStudio
582. R console
593. Terminal (e.g., bash)
60
61### RStudio
62
63When creating the presentation in RStudio, there will be a `Knit` button
64right below the source tabs.
65By default, it will render the current document and place the rendered `HTML` file in the same directory as the source file, with the same name.
66
Daniel Chen81a14342016-03-21 18:00:56 -040067Note: Unlike the the other slideshow outputs, the slideshow viewer popup from RStudio will be blank,
Daniel Chen46087c32016-03-21 17:58:14 -040068to view the slide show click the `open in browser` button,
69and the slide show will render in your default web browser.
70
71### R Console
72
73The `Knit` button is actually calling the `rmarkdown::render()` function.
Daniel Chen81a14342016-03-21 18:00:56 -040074So, to render the document within the R console:
Daniel Chen46087c32016-03-21 17:58:14 -040075
76```r
77rmarkdown::render('my_reveal_presentation.Rmd')
78```
79
80There are many other output tweaks you can use by directly calling `render`.
81You can read up on the [documentation](https://cran.r-project.org/web/packages/rmarkdown/rmarkdown.pdf) for more details.
82
83### Command Line
84
85When you need the presentation to be rendered from the command line:
86
87```bash
88Rscript -e "rmarkdown::render('my_reveal_presentation.Rmd')"
89```
90
JJ Allaire5dc9fe02016-01-30 18:44:51 -050091## Display Modes
92
93The following single character keyboard shortcuts enable alternate
94display modes:
95
96- `'f'` enable fullscreen mode
97
98- `'o'` enable overview mode
99
100Pressing `Esc` exits all of these modes.
101
102## Incremental Bullets
103
104You can render bullets incrementally by adding the `incremental` option:
105
106 ---
107 output:
108 revealjs::revealjs_presentation:
109 incremental: true
110 ---
111
112If you want to render bullets incrementally for some slides but not
113others you can use this syntax:
114
115 > - Eat eggs
116 > - Drink coffee
117
118## Appearance and Style
119
120There are several options that control the appearance of revealjs presentations:
121
122* `theme` specifies the theme to use for the presentation (available themes are "default", "simple", "sky", "beige", "serif", "solarized", "blood", "moon", "night", "black", "league" or "white").
123
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500124* `highlight` specifies the syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass null to prevent syntax highlighting.
125
126* `center` specifies whether you want to vertically center content on slides (this defaults to false).
127
128* `smart` indicates whether to produce typographically correct output, converting straight quotes to curly quotes, `---` to em-dashes, `--` to en-dashes, and `...` to ellipses. Note that `smart` is enabled by default.
129
130For example:
131
132 ---
133 output:
134 revealjs::revealjs_presentation:
135 theme: sky
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500136 highlight: pygments
137 center: true
138 ---
139
JJ Allaire41921d32016-01-30 19:11:43 -0500140## Slide Transitions
141
142You can use the `transition` and `background_transition` optoins to specify the global default slide transition style:
143
144* `transition` specifies the visual effect when moving between slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
145
146* `background_transition` specifies the background transition effect when moving between full page slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
147
148For example:
149
150 ---
151 output:
152 revealjs::revealjs_presentation:
153 transition: fade
154 ---
155
156
157You can override the global transition for a specific slide by using the data-transition attribute, for example:
158
159 ## Use a zoom transition {data-transition="zoom"}
160
161 ## Use a faster speed {data-transition-speed="fast"}
162
163You can also use different in and out transitions for the same slide, for example:
164
165 ## Fade in, Slide out {data-transition="slide-in fade-out"}
166
167 ## Slide in, Fade out {data-transition="fade-in slide-out"}
168
169
JJ Allaire8382c3e2016-01-30 19:04:31 -0500170## Slide Backgrounds
171
172Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a data-background attribute to your slide header element. Four different types of backgrounds are supported: color, image, video and iframe. Below are a few examples.
173
174 ## CSS color background {data-background=#ff0000}
175
176 ## Full size image background {data-background="background.jpeg"}
177
178 ## Video background {data-background-video="background.mp4"}
179
180 ## Embed a web page as a background {data-background-iframe="https://example.com"}
181
182Backgrounds transition using a fade animation by default. This can be changed to a linear sliding transition by specifying the `background-transition: slide`. Alternatively you can set data-background-transition on any slide with a background to override that specific transition.
183
JJ Allairede1ed652016-01-30 19:41:18 -0500184## 2-D Presenations
185
186You can use the `slide_level` option to specify which level of heading will be used to denote individual slides. If `slide_level` is 2 (the default), a two-dimensional layout will be produced, with level 1 headers building horizontally and level 2 headers building vertically. For example:
187
188 # Horizontal Slide 1
189
190 ## Vertical Slide 1
191
192 ## Vertical Slide 2
193
194 # Horizontal Slide 2
195
196With this layout horizontal navigation will proceed directly from "Horizontal Slide 1" to "Horizontal Slide 2", with vertical navigation to "Vertical Slide 1", etc. presented as an option on "Horizontal Slide 1".
197
198
199
JJ Allaire5f514242016-07-12 10:28:23 -0400200## Reveal Options
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500201
JJ Allaire064552c2017-02-10 10:28:41 -0500202Reveal.js has many additional options to configure it's behavior. You can specify any of these options using `reveal_options`, for example:
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500203
204 ---
205 title: "Habits"
206 output:
207 revealjs::revealjs_presentation:
208 self_contained: false
209 reveal_options:
210 slideNumber: true
211 previewLinks: true
212 ---
213
214You can find documentation on the various available Reveal.js options here: <https://github.com/hakimel/reveal.js#configuration>.
215
216
217## Figure Options
218
219There are a number of options that affect the output of figures within reveal.js presentations:
220
221* `fig_width` and `fig_height` can be used to control the default figure width and height (7x5 is used by default)
222
223* `fig_retina` Specifies the scaling to perform for retina displays (defaults to 2, which currently works for all widely used retina displays). Note that this only takes effect if you are using knitr >= 1.5.21. Set to `null` to prevent retina scaling.
224
225* `fig_caption` controls whether figures are rendered with captions
226
227For example:
228
229 ---
230 title: "Habits"
231 output:
232 revealjs::revealjs_presentation:
233 fig_width: 7
234 fig_height: 6
235 fig_caption: true
236 ---
237
238
239## MathJax Equations
240
241By default [MathJax](http://www.mathjax.org/) scripts are included in reveal.js presentations for rendering LaTeX and MathML equations. You can use the `mathjax` option to control how MathJax is included:
242
243* Specify "default" to use an https URL from the official MathJax CDN.
244
245* Specify "local" to use a local version of MathJax (which is copied into the output directory). Note that when using "local" you also need to set the `self_contained` option to false.
246
247* Specify an alternate URL to load MathJax from another location.
248
249* Specify null to exclude MathJax entirely.
250
251For example, to use a local copy of MathJax:
252
253 ---
254 title: "Habits"
255 output:
256 revealjs::revealjs_presentation:
257 mathjax: local
258 self_contained: false
259 ---
260
261To use a self-hosted copy of MathJax:
262
263 ---
264 title: "Habits"
265 output:
266 revealjs::revealjs_presentation:
267 mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
268 ---
269
270To exclude MathJax entirely:
271
272 ---
273 title: "Habits"
274 output:
275 revealjs::revealjs_presentation:
276 mathjax: null
277 ---
278
279## Document Dependencies
280
281By default R Markdown produces standalone HTML files with no external dependencies, using data: URIs to incorporate the contents of linked scripts, stylesheets, images, and videos. This means you can share or publish the file just like you share Office documents or PDFs. If you'd rather have keep depenencies in external files you can specify `self_contained: false`. For example:
282
283 ---
284 title: "Habits"
285 output:
286 revealjs::revealjs_presentation:
287 self_contained: false
288 ---
289
290Note that even for self contained documents MathJax is still loaded externally (this is necessary because of it's size). If you want to serve MathJax locally then you should specify `mathjax: local` and `self_contained: false`.
291
292One common reason keep dependencies external is for serving R Markdown documents from a website (external dependencies can be cached separately by browsers leading to faster page load times). In the case of serving multiple R Markdown documents you may also want to consolidate dependent library files (e.g. Bootstrap, MathJax, etc.) into a single directory shared by multiple documents. You can use the `lib_dir` option to do this, for example:
293
294 ---
295 title: "Habits"
296 output:
297 revealjs::revealjs_presentation:
298 self_contained: false
299 lib_dir: libs
300 ---
301
JJ Allaire5f514242016-07-12 10:28:23 -0400302## Reveal Plugins
JJ Allaire82a8dee2016-07-12 10:25:36 -0400303
304You can enable various reveal.js plugins using the `reveal_plugins` option. Plugins currently supported include:
305
306| Plugin | Description |
307|----------------------------|---------------------------------------------|
308| [notes](https://github.com/hakimel/reveal.js/#speaker-notes) | Present per-slide notes in a separate browser window. |
309| [zoom](http://lab.hakim.se/zoom-js/) | Zoom in and out of selected content with Alt+Click. |
310| [search](https://github.com/hakimel/reveal.js/blob/master/plugin/search/search.js) | Find a text string anywhere in the slides and show the next occurrence to the user. |
JJ Allaire375805c2016-11-15 08:56:43 -0500311| [chalkboard](https://github.com/rajgoel/reveal.js-plugins/tree/master/chalkboard) | Include handwritten notes within a presentation. |
JJ Allaire064552c2017-02-10 10:28:41 -0500312| [menu](https://github.com/denehyg/reveal.js-menu) | Include a navigation menu within a presentation. |
JJ Allaire82a8dee2016-07-12 10:25:36 -0400313
314Note that the use of plugins requires that the `self_contained` option be set to false. For example, this presentation includes both the "notes" and "search" plugins:
315
316 ---
317 title: "Habits"
318 output:
319 revealjs::revealjs_presentation:
320 self_contained: false
321 reveal_plugins: ["notes", "search"]
322 ---
323
JJ Allaire064552c2017-02-10 10:28:41 -0500324You can specify additional options for the `chalkboard` and `menu` plugins using `reveal_options`, for example:
JJ Allaire375805c2016-11-15 08:56:43 -0500325
326 ---
327 title: "Habits"
328 output:
329 revealjs::revealjs_presentation:
330 self_contained: false
JJ Allaire064552c2017-02-10 10:28:41 -0500331 reveal_plugins: ["chalkboard", "menu"]
JJ Allaire375805c2016-11-15 08:56:43 -0500332 reveal_options:
333 chalkboard:
334 theme: whiteboard
335 toggleNotesButton: false
JJ Allaire064552c2017-02-10 10:28:41 -0500336 menu:
337 side: right
JJ Allaire375805c2016-11-15 08:56:43 -0500338 ---
339
340
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500341## Advanced Customization
342
343### Includes
344
345You can do more advanced customization of output by including additional HTML content or by replacing the core pandoc template entirely. To include content in the document header or before/after the document body you use the `includes` option as follows:
346
347 ---
348 title: "Habits"
349 output:
350 revealjs::revealjs_presentation:
351 includes:
352 in_header: header.html
353 before_body: doc_prefix.html
354 after_body: doc_suffix.html
355 ---
356
357
358### Pandoc Arguments
359
360If there are pandoc features you want to use that lack equivilants in the YAML options described above you can still use them by passing custom `pandoc_args`. For example:
361
362 ---
363 title: "Habits"
364 output:
365 revealjs::revealjs_presentation:
366 pandoc_args: [
367 "--title-prefix", "Foo",
368 "--id-prefix", "Bar"
369 ]
370 ---
371
372Documentation on all available pandoc arguments can be found in the [pandoc user guide](http://johnmacfarlane.net/pandoc/README.html#options).
373
374## Shared Options
375
376If you want to specify a set of default options to be shared by multiple documents within a directory you can include a file named `_output.yaml` within the directory. Note that no YAML delimeters or enclosing output object are used in this file. For example:
377
378**\_output.yaml**
379
380```yaml
381revealjs::revealjs_presentation:
382 theme: sky
383 transition: fade
384 highlight: pygments
385```
386
387All documents located in the same directory as `_output.yaml` will inherit it's options. Options defined explicitly within documents will override those specified in the shared options file.
388
389
390
391
392
393
394
395
396
397
398