blob: a78d1152ca3abbb99f1c80e124174f999b7f9460 [file] [log] [blame]
JJ Allaire5dc9fe02016-01-30 18:44:51 -05001---
2title: "R Markdown Format for reveal.js Presentations"
3output:
christophe dervieux42886a12021-09-16 11:36:01 +02004 github_document: default
JJ Allaire5dc9fe02016-01-30 18:44:51 -05005---
6
christophe dervieux42886a12021-09-16 11:36:01 +02007<!-- badges: start -->
8[![CRAN status](https://www.r-pkg.org/badges/version/revealjs)](https://CRAN.R-project.org/package=revealjs)
9[![R-CMD-check](https://github.com/rstudio/revealjs/workflows/R-CMD-check/badge.svg)](https://github.com/rstudio/revealjs/actions)
10<!-- badges: end -->
11
JJ Allaire5dc9fe02016-01-30 18:44:51 -050012## Overview
13
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +090014This repository provides an [R Markdown](http://rmarkdown.rstudio.com) custom format for [reveal.js](https://revealjs.com/) HTML presentations.
JJ Allaire5dc9fe02016-01-30 18:44:51 -050015
16You can use this format in R Markdown documents by installing this package as follows:
17
18```r
JJ Allaired9f38d22016-01-31 14:15:59 -050019install.packages("revealjs", type = "source")
JJ Allaire5dc9fe02016-01-30 18:44:51 -050020```
21
22
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +090023To create a [reveal.js](https://revealjs.com/) 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:
JJ Allaire5dc9fe02016-01-30 18:44:51 -050024
25 ---
26 title: "Habits"
27 author: John Doe
28 date: March 22, 2005
29 output: revealjs::revealjs_presentation
30 ---
31
32 # In the morning
33
34 ## Getting up
35
36 - Turn off alarm
37 - Get out of bed
38
39 ## Breakfast
40
41 - Eat eggs
42 - Drink coffee
43
44 # In the evening
45
46 ## Dinner
47
48 - Eat spaghetti
49 - Drink wine
50
51 ## Going to sleep
52
53 - Get in bed
54 - Count sheep
55
Daniel Chen46087c32016-03-21 17:58:14 -040056## Rendering
57
Daniel Chen81a14342016-03-21 18:00:56 -040058Depending on your use case, there are 3 ways you can render the presentation.
Daniel Chen46087c32016-03-21 17:58:14 -040059
601. RStudio
612. R console
623. Terminal (e.g., bash)
63
64### RStudio
65
66When creating the presentation in RStudio, there will be a `Knit` button
67right below the source tabs.
68By 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.
69
Daniel Chen81a14342016-03-21 18:00:56 -040070Note: Unlike the the other slideshow outputs, the slideshow viewer popup from RStudio will be blank,
Daniel Chen46087c32016-03-21 17:58:14 -040071to view the slide show click the `open in browser` button,
72and the slide show will render in your default web browser.
73
74### R Console
75
76The `Knit` button is actually calling the `rmarkdown::render()` function.
Daniel Chen81a14342016-03-21 18:00:56 -040077So, to render the document within the R console:
Daniel Chen46087c32016-03-21 17:58:14 -040078
79```r
80rmarkdown::render('my_reveal_presentation.Rmd')
81```
82
83There are many other output tweaks you can use by directly calling `render`.
84You can read up on the [documentation](https://cran.r-project.org/web/packages/rmarkdown/rmarkdown.pdf) for more details.
85
86### Command Line
87
88When you need the presentation to be rendered from the command line:
89
90```bash
91Rscript -e "rmarkdown::render('my_reveal_presentation.Rmd')"
92```
93
JJ Allaire5dc9fe02016-01-30 18:44:51 -050094## Display Modes
95
96The following single character keyboard shortcuts enable alternate
97display modes:
98
99- `'f'` enable fullscreen mode
100
101- `'o'` enable overview mode
102
103Pressing `Esc` exits all of these modes.
104
105## Incremental Bullets
106
107You can render bullets incrementally by adding the `incremental` option:
108
109 ---
110 output:
111 revealjs::revealjs_presentation:
112 incremental: true
113 ---
114
115If you want to render bullets incrementally for some slides but not
116others you can use this syntax:
117
118 > - Eat eggs
119 > - Drink coffee
120
121## Appearance and Style
122
123There are several options that control the appearance of revealjs presentations:
124
125* `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").
126
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500127* `highlight` specifies the syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass null to prevent syntax highlighting.
128
129* `center` specifies whether you want to vertically center content on slides (this defaults to false).
130
131* `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.
132
133For example:
134
135 ---
136 output:
137 revealjs::revealjs_presentation:
138 theme: sky
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500139 highlight: pygments
140 center: true
141 ---
142
JJ Allaire41921d32016-01-30 19:11:43 -0500143## Slide Transitions
144
Jon Caldera35857d2017-04-11 16:38:58 +0200145You can use the `transition` and `background_transition` options to specify the global default slide transition style:
JJ Allaire41921d32016-01-30 19:11:43 -0500146
147* `transition` specifies the visual effect when moving between slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
148
149* `background_transition` specifies the background transition effect when moving between full page slides. Available transitions are "default", "fade", "slide", "convex", "concave", "zoom" or "none".
150
151For example:
152
153 ---
154 output:
155 revealjs::revealjs_presentation:
156 transition: fade
157 ---
158
159
160You can override the global transition for a specific slide by using the data-transition attribute, for example:
161
162 ## Use a zoom transition {data-transition="zoom"}
163
164 ## Use a faster speed {data-transition-speed="fast"}
165
166You can also use different in and out transitions for the same slide, for example:
167
168 ## Fade in, Slide out {data-transition="slide-in fade-out"}
169
170 ## Slide in, Fade out {data-transition="fade-in slide-out"}
171
172
JJ Allaire8382c3e2016-01-30 19:04:31 -0500173## Slide Backgrounds
174
175Slides 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.
176
177 ## CSS color background {data-background=#ff0000}
178
179 ## Full size image background {data-background="background.jpeg"}
180
181 ## Video background {data-background-video="background.mp4"}
182
183 ## Embed a web page as a background {data-background-iframe="https://example.com"}
184
185Backgrounds 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.
186
Jon Caldera35857d2017-04-11 16:38:58 +0200187## 2-D Presentations
JJ Allairede1ed652016-01-30 19:41:18 -0500188
189You 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:
190
191 # Horizontal Slide 1
192
193 ## Vertical Slide 1
194
195 ## Vertical Slide 2
196
197 # Horizontal Slide 2
198
199With 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".
200
201
202
JJ Allaire5f514242016-07-12 10:28:23 -0400203## Reveal Options
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500204
JJ Allaire064552c2017-02-10 10:28:41 -0500205Reveal.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 -0500206
207 ---
208 title: "Habits"
209 output:
210 revealjs::revealjs_presentation:
211 self_contained: false
212 reveal_options:
213 slideNumber: true
214 previewLinks: true
215 ---
216
217You can find documentation on the various available Reveal.js options here: <https://github.com/hakimel/reveal.js#configuration>.
218
219
220## Figure Options
221
222There are a number of options that affect the output of figures within reveal.js presentations:
223
224* `fig_width` and `fig_height` can be used to control the default figure width and height (7x5 is used by default)
225
226* `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.
227
228* `fig_caption` controls whether figures are rendered with captions
229
230For example:
231
232 ---
233 title: "Habits"
234 output:
235 revealjs::revealjs_presentation:
236 fig_width: 7
237 fig_height: 6
238 fig_caption: true
239 ---
240
241
242## MathJax Equations
243
244By 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:
245
246* Specify "default" to use an https URL from the official MathJax CDN.
247
248* 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.
249
250* Specify an alternate URL to load MathJax from another location.
251
252* Specify null to exclude MathJax entirely.
253
254For example, to use a local copy of MathJax:
255
256 ---
257 title: "Habits"
258 output:
259 revealjs::revealjs_presentation:
260 mathjax: local
261 self_contained: false
262 ---
263
264To use a self-hosted copy of MathJax:
265
266 ---
267 title: "Habits"
268 output:
269 revealjs::revealjs_presentation:
270 mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
271 ---
272
273To exclude MathJax entirely:
274
275 ---
276 title: "Habits"
277 output:
278 revealjs::revealjs_presentation:
279 mathjax: null
280 ---
281
282## Document Dependencies
283
Jon Caldera35857d2017-04-11 16:38:58 +0200284By 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 keep dependencies in external files you can specify `self_contained: false`. For example:
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500285
286 ---
287 title: "Habits"
288 output:
289 revealjs::revealjs_presentation:
290 self_contained: false
291 ---
292
293Note 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`.
294
295One 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:
296
297 ---
298 title: "Habits"
299 output:
300 revealjs::revealjs_presentation:
301 self_contained: false
302 lib_dir: libs
303 ---
304
JJ Allaire5f514242016-07-12 10:28:23 -0400305## Reveal Plugins
JJ Allaire82a8dee2016-07-12 10:25:36 -0400306
307You can enable various reveal.js plugins using the `reveal_plugins` option. Plugins currently supported include:
308
309| Plugin | Description |
310|----------------------------|---------------------------------------------|
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +0900311| [notes](https://revealjs.com/speaker-view/) | Present per-slide notes in a separate browser window. |
JJ Allaire82a8dee2016-07-12 10:25:36 -0400312| [zoom](http://lab.hakim.se/zoom-js/) | Zoom in and out of selected content with Alt+Click. |
313| [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 -0500314| [chalkboard](https://github.com/rajgoel/reveal.js-plugins/tree/master/chalkboard) | Include handwritten notes within a presentation. |
JJ Allaire064552c2017-02-10 10:28:41 -0500315| [menu](https://github.com/denehyg/reveal.js-menu) | Include a navigation menu within a presentation. |
JJ Allaire82a8dee2016-07-12 10:25:36 -0400316
317Note 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:
318
319 ---
320 title: "Habits"
321 output:
322 revealjs::revealjs_presentation:
323 self_contained: false
324 reveal_plugins: ["notes", "search"]
325 ---
326
JJ Allaire064552c2017-02-10 10:28:41 -0500327You can specify additional options for the `chalkboard` and `menu` plugins using `reveal_options`, for example:
JJ Allaire375805c2016-11-15 08:56:43 -0500328
329 ---
330 title: "Habits"
331 output:
332 revealjs::revealjs_presentation:
333 self_contained: false
JJ Allaire064552c2017-02-10 10:28:41 -0500334 reveal_plugins: ["chalkboard", "menu"]
JJ Allaire375805c2016-11-15 08:56:43 -0500335 reveal_options:
336 chalkboard:
337 theme: whiteboard
338 toggleNotesButton: false
JJ Allaire064552c2017-02-10 10:28:41 -0500339 menu:
340 side: right
JJ Allaire375805c2016-11-15 08:56:43 -0500341 ---
342
343
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500344## Advanced Customization
345
346### Includes
347
348You 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:
349
350 ---
351 title: "Habits"
352 output:
353 revealjs::revealjs_presentation:
354 includes:
355 in_header: header.html
356 before_body: doc_prefix.html
357 after_body: doc_suffix.html
358 ---
359
360
361### Pandoc Arguments
362
Jon Caldera35857d2017-04-11 16:38:58 +0200363If there are pandoc features you want to use that lack equivalents in the YAML options described above you can still use them by passing custom `pandoc_args`. For example:
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500364
365 ---
366 title: "Habits"
367 output:
368 revealjs::revealjs_presentation:
369 pandoc_args: [
370 "--title-prefix", "Foo",
371 "--id-prefix", "Bar"
372 ]
373 ---
374
Atsushi Yasumotoe734cd82020-08-10 21:48:18 +0900375Documentation on all available pandoc arguments can be found in the [pandoc user guide](https://pandoc.org/MANUAL.html#options).
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500376
377## Shared Options
378
Jon Caldera35857d2017-04-11 16:38:58 +0200379If 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 delimiters or enclosing output object are used in this file. For example:
JJ Allaire5dc9fe02016-01-30 18:44:51 -0500380
381**\_output.yaml**
382
383```yaml
384revealjs::revealjs_presentation:
385 theme: sky
386 transition: fade
387 highlight: pygments
388```
389
390All 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.
Christophe Dervieux7f1add52021-09-15 15:42:07 +0200391
392## Code of Conduct
393
394Please note that the revealjs project is released with a [Contributor Code of Conduct](https://pkgs.rstudio.com/revealjs/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.