Debian Codegraph @

man/html_document.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/html_document.R
3 \name{html_document}
4 \alias{html_document}
5 \title{Convert to an HTML document}
6 \usage{
7 html_document(
8 toc = FALSE,
9 toc_depth = 3,
10 toc_float = FALSE,
11 number_sections = FALSE,
12 anchor_sections = FALSE,
13 section_divs = TRUE,
14 fig_width = 7,
15 fig_height = 5,
16 fig_retina = 2,
17 fig_caption = TRUE,
18 dev = "png",
19 df_print = "default",
20 code_folding = c("none", "show", "hide"),
21 code_download = FALSE,
22 self_contained = TRUE,
23 theme = "default",
24 highlight = "default",
25 highlight_downlit = FALSE,
26 math_method = "default",
27 mathjax = "default",
28 template = "default",
29 extra_dependencies = NULL,
30 css = NULL,
31 includes = NULL,
32 keep_md = FALSE,
33 lib_dir = NULL,
34 md_extensions = NULL,
35 pandoc_args = NULL,
36 ...
37 )
38 }
39 \arguments{
40 \item{toc}{\code{TRUE} to include a table of contents in the output}
41
42 \item{toc_depth}{Depth of headers to include in table of contents}
43
44 \item{toc_float}{\code{TRUE} to float the table of contents to the left of the
45 main document content. Rather than \code{TRUE} you may also pass a list of
46 options that control the behavior of the floating table of contents. See the
47 \emph{Floating Table of Contents} section below for details.}
48
49 \item{number_sections}{\code{TRUE} to number section headings}
50
51 \item{anchor_sections}{\code{TRUE} to show section anchors when mouse hovers
52 for all headers. A list can also be passed with \code{style} and/or
53 \code{depth} to customize the behavior. See
54 \link[rmarkdown:html_document]{Anchor Sections Customization section}.}
55
56 \item{section_divs}{Wrap sections in \verb{<div>} tags, and attach identifiers to the
57 enclosing \verb{<div>} rather than the header itself.}
58
59 \item{fig_width}{Default width (in inches) for figures}
60
61 \item{fig_height}{Default height (in inches) for figures}
62
63 \item{fig_retina}{Scaling to perform for retina displays (defaults to 2, which
64 currently works for all widely used retina displays). Set to \code{NULL} to
65 prevent retina scaling. Note that this will always be \code{NULL} when
66 \code{keep_md} is specified (this is because \code{fig_retina} relies on
67 outputting HTML directly into the markdown document).}
68
69 \item{fig_caption}{\code{TRUE} to render figures with captions}
70
71 \item{dev}{Graphics device to use for figure output (defaults to png)}
72
73 \item{df_print}{Method to be used for printing data frames. Valid values
74 include "default", "kable", "tibble", and "paged". The "default" method
75 uses a corresponding S3 method of \code{print}, typically
76 \code{print.data.frame}. The "kable" method uses the
77 \code{\link[knitr:kable]{knitr::kable}} function. The "tibble" method uses
78 the \pkg{tibble} package to print a summary of the data frame. The "paged"
79 method creates a paginated HTML table (note that this method is only valid
80 for formats that produce HTML). In addition to the named methods you can
81 also pass an arbitrary function to be used for printing data frames. You
82 can disable the \code{df_print} behavior entirely by setting the option
83 \code{rmarkdown.df_print} to \code{FALSE}. See
84 \href{https://yihui.org/rmarkdown/html-document.html#data-frame-printing}{Data
85 frame printing section} in bookdown book for examples.}
86
87 \item{code_folding}{Enable document readers to toggle the display of R code
88 chunks. Specify \code{"none"} to display all code chunks. Specify
89 \code{"hide"} or \code{"show"} to hide or show all R code chunks by
90 default, and let readers toggle the states on browsers. See the
91 \emph{Code folding}}
92
93 \item{code_download}{Embed the Rmd source code within the document and provide
94 a link that can be used by readers to download the code.}
95
96 \item{self_contained}{Produce a standalone HTML file with no external
97 dependencies, using data: URIs to incorporate the contents of linked
98 scripts, stylesheets, images, and videos. Note that even for self contained
99 documents MathJax is still loaded externally (this is necessary because of
100 its size).}
101
102 \item{theme}{One of the following:
103 \itemize{
104 \item A \code{\link[bslib:bs_theme]{bslib::bs_theme()}} object (or a list of \code{\link[bslib:bs_theme]{bslib::bs_theme()}} argument values)
105 \itemize{
106 \item Use this option for custom themes using Bootstrap 4 or 3.
107 \item In this case, any \code{.scss}/\code{.sass} files provided to the \code{css}
108 parameter may utilize the \code{theme}'s underlying Sass utilities
109 (e.g., variables, mixins, etc).
110 }
111 \item \code{NULL} for no theme (i.e., no \code{\link[=html_dependency_bootstrap]{html_dependency_bootstrap()}}).
112 \item A character string specifying a \href{https://bootswatch.com/3/}{Bootswatch 3}
113 theme name (for backwards-compatibility).
114 }}
115
116 \item{highlight}{Syntax highlight engine and style. See the
117 \emph{Highlighting} section below for details.
118
119 "default" (and "textmate") will use highlightjs as syntax highlighting
120 engine instead of Pandoc.
121
122 Any other value will be passed as Pandoc's highlighting style. Pandoc's
123 built-in styles include "tango", "pygments", "kate", "monochrome",
124 "espresso", "zenburn", "haddock" and "breezedark".
125
126 Two custom styles are also included, "arrow", an accessible color scheme,
127 and "rstudio", which mimics the default IDE theme. Alternatively, supply a
128 path to a \samp{.theme} to use
129 \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{a custom Pandoc style}. Note that custom theme requires Pandoc 2.0+.
130
131 Pass \code{NULL} to prevent syntax highlighting.}
132
133 \item{highlight_downlit}{\code{TRUE} to use the \pkg{downlit} package as
134 syntax highlight engine to highlight inline code and R code chunks
135 (including providing hyperlinks to function documentation). The package
136 needs to be installed to use this feature.
137
138 Only Pandoc color schemes are supported with this engine. With
139 \code{highlight = "default"}, it will use the accessible theme called
140 "arrow". To learn more about \pkg{downlit} highlighting engine, see
141 \url{https://downlit.r-lib.org/}.}
142
143 \item{math_method}{Math rendering engine to use. This will define the math method to use with Pandoc.
144 \itemize{
145 \item It can be a string for the engine, one of "mathjax", "mathml", "webtex", "katex", "gladtex", or "r-katex"
146 or "default" for \code{mathjax}.
147 \item It can be a list of
148 \itemize{
149 \item \code{engine}: one of
150 "mathjax", "mathml", "webtex", "katex", or "gladtex".
151 \item \code{url}: A specific url to use with \code{mathjax}, \code{katex} or \code{webtex}.
152 Note that for \code{engine = "mathjax"}, \code{url = "local"} will use a local version of MathJax (which is
153 copied into the output directory).
154 }
155 }
156
157 For example,
158
159 \if{html}{\out{<div class="sourceCode yaml">}}\preformatted{output:
160 html_document:
161 math_method:
162 engine: katex
163 url: https://cdn.jsdelivr.net/npm/[email protected]/dist/
164 }\if{html}{\out{</div>}}
165
166 See \href{https://pandoc.org/MANUAL.html#math-rendering-in-html}{Pandoc's Manual about Math in HTML} for the details
167 about Pandoc supported methods.
168
169 Using \code{math_method = "r-katex"} will opt-in server side rendering using
170 KaTeX thanks to \href{https://docs.ropensci.org/katex/}{katex} R package. This is
171 useful compared to \code{math_method = "katex"} to have no JS dependency, only a
172 CSS dependency for styling equation.}
173
174 \item{mathjax}{Include mathjax. The "default" option uses an https URL from a
175 MathJax CDN. The "local" option uses a local version of MathJax (which is
176 copied into the output directory). You can pass an alternate URL or pass
177 \code{NULL} to exclude MathJax entirely.}
178
179 \item{template}{Pandoc template to use for rendering. Pass "default" to use
180 the rmarkdown package default template; pass \code{NULL} to use pandoc's
181 built-in template; pass a path to use a custom template that you've created.
182 Note that if you don't use the "default" template then some features of
183 \code{html_document} won't be available (see the Templates section below for
184 more details).}
185
186 \item{extra_dependencies}{Extra dependencies as a list of the
187 \code{html_dependency} class objects typically generated by
188 \code{\link[htmltools:htmlDependency]{htmltools::htmlDependency()}}.}
189
190 \item{css}{CSS and/or Sass files to include. Files with an extension of .sass
191 or .scss are compiled to CSS via \code{sass::sass()}. Also, if \code{theme} is a
192 \code{\link[bslib:bs_theme]{bslib::bs_theme()}} object, Sass code may reference the relevant Bootstrap
193 Sass variables, functions, mixins, etc.}
194
195 \item{includes}{Named list of additional content to include within the
196 document (typically created using the \code{\link{includes}} function).}
197
198 \item{keep_md}{Keep the markdown file generated by knitting.}
199
200 \item{lib_dir}{Directory to copy dependent HTML libraries (e.g. jquery,
201 bootstrap, etc.) into. By default this will be the name of the document with
202 \verb{_files} appended to it.}
203
204 \item{md_extensions}{Markdown extensions to be added or removed from the
205 default definition of R Markdown. See the \code{\link{rmarkdown_format}} for
206 additional details.}
207
208 \item{pandoc_args}{Additional command line options to pass to pandoc}
209
210 \item{...}{Additional function arguments to pass to the base R Markdown HTML
211 output formatter \code{\link{html_document_base}}}
212 }
213 \value{
214 R Markdown output format to pass to \code{\link{render}}
215 }
216 \description{
217 Format for converting from R Markdown to an HTML document.
218 }
219 \details{
220 See the \href{https://yihui.org/rmarkdown/html-document.html}{online documentation} for additional details on using the \code{html_document}
221 format.
222
223 R Markdown documents can have optional metadata that is used to generate a
224 document header that includes the title, author, and date. For more details
225 see the documentation on R Markdown \link[=rmd_metadata]{metadata}.
226
227 R Markdown documents also support citations. You can find more information on
228 the markdown syntax for citations in the
229 \href{https://pandoc.org/MANUAL.html#citations}{Bibliographies and Citations} article in the online documentation.
230 }
231 \section{Highlighting}{
232
233
234 There are three highlighting engines available to HTML documents:
235
236 \describe{
237 \item{highlightjs}{It does highlighting in the browser, using javascript It
238 can only be used with the default template (i.e \code{template = "default"})
239 and it has two styles ("default" and "textmate"). When activated, it adds
240 two additional dependencies to the output file: a JS script and a CSS file.
241 For now, this is the default engine for the default template - this could
242 change in the future.}
243
244 \item{Pandoc}{Pandoc's built-in highlighting.engine works with any template,
245 default or custom, and style can be chosen among the built-in ones ("tango",
246 "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and
247 "breezedark") or a path to a custom theme ".theme" file (see Details in the
248 \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}).
249 \pkg{rmarkdown} includes two custom themes to select with \code{highlight}
250 parameter:
251 \itemize{
252 \item "arrow", an accessible style using colors \href{https://www.a11yproject.com/}{optimized for accessibility and color contrast}
253 \item "rstudio", a color scheme close to RStudio's default highlighting and
254 highglightjs's textmate.
255 }
256
257 Custom themes are only available for Pandoc 2.0 and above.}
258
259 \item{downlit}{\href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that
260 provides a syntax highlighting engine in R. It will also do automatic
261 linking of R code (requires internet connectivity). It is activated only if
262 \code{highlight_downlit = TRUE} and only affects R code, leaving
263 highlighting for other languages unchanged. The default color scheme is
264 the accessible theme "arrow".
265
266 It requires some CSS in the template to correctly style links. This is included
267 in the default template, but if you want to use with a custom template, you will
268 need to add this to your template:
269
270 \if{html}{\out{<div class="sourceCode">}}\preformatted{$if(highlight-downlit)$
271 <style type="text/css">
272 code a:any-link \{
273 color: inherit; /* use colour from syntax highlighting */
274 text-decoration: underline;
275 text-decoration-color: #ccc;
276 \}
277 </style>
278 $endif$
279 }\if{html}{\out{</div>}}
280
281 }}
282 }
283
284 \section{Anchor Sections Customization}{
285
286
287 This will be the default to activate anchor sections link on header
288
289 \if{html}{\out{<div class="sourceCode yaml">}}\preformatted{output:
290 html_document:
291 anchor_sections: TRUE
292 }\if{html}{\out{</div>}}
293
294 There are currently two options to modify the default behavior
295
296 \describe{
297 \item{\code{style}}{Select a predefined visual style:
298 \itemize{
299 \item \code{style = "dash"}, the default, uses \samp{#}, a minimalist choice that evokes the id selector from HTML and CSS.
300 \item \code{style = "symbol"} will use a \href{https://codepoints.net/U+1F517}{link symbol} \if{html}{\out{(&#x1F517;&#xFE0E;)}}
301 \item \code{style = "icon"} will use an svg icon. \if{html}{(\figure{link-black-18dp.svg}{options: alt="icon link"})}
302 }
303
304 You can also customize using a css rule in your
305 document. For example, to get a pictogram \if{html}{\out{(&#x1F517;)}}:
306
307 \if{html}{\out{<div class="sourceCode css">}}\preformatted{a.anchor-section::before \{
308 content: '\\\\01F517';
309 \}
310 }\if{html}{\out{</div>}}
311
312 About how to apply custom CSS in R Markdown document, see
313 \url{https://yihui.org/rmarkdown-cookbook/html-css.html}
314 }
315 \item{\code{depth}}{Select the maximum header level to add the
316 anchor link to. For example, this yaml will use the symbol style and
317 only with level 1 and 2 headings:
318
319 \if{html}{\out{<div class="sourceCode yaml">}}\preformatted{output:
320 html_document:
321 anchor_sections:
322 style: icon
323 depth: 2
324 }\if{html}{\out{</div>}}
325
326 If omitted, anchor will be added to all headers (equivalent of
327 \code{depth=6}). You can also set anchors manually with \code{depth = 0} using this syntax
328
329 \if{html}{\out{<div class="sourceCode markdown">}}\preformatted{# my header \{.hasAnchor\}
330 }\if{html}{\out{</div>}}
331
332 }
333
334 Using anchor sections will add some CSS to your document output for the
335 styling, and a JS script if \code{section_divs = TRUE}. The anchor link itself
336 is added using a Lua filter, and hence requires Pandoc 2.0+
337 }
338 }
339
340 \section{Navigation Bars}{
341
342
343 If you have a set of html documents which you'd like to provide a common
344 global navigation bar for, you can include a "_navbar.yml" or "_navbar.html"
345 file within the same directory as your html document and it will automatically
346 be included at the top of the document.
347
348 The "_navbar.yml" file includes \code{title}, \code{type}, \code{left}, and
349 \code{right} fields (to define menu items for the left and right of the navbar
350 respectively). Menu items include \code{text} and \code{href} fields. For example:
351
352 \if{html}{\out{<div class="sourceCode yaml">}}\preformatted{title: "My Website"
353 type: default
354 left:
355 - text: "Home"
356 href: index.html
357 - text: "Other"
358 href: other.html
359 right:
360 - text: GitHub
361 href: https://github.com
362 }\if{html}{\out{</div>}}
363
364 The \code{type} field is optional and can take the value "default" or "inverse" (which
365 provides a different color scheme for the navigation bar).
366
367 Alternatively, you can include a "_navbar.html" file which is a full HTML definition
368 of a bootstrap navigation bar. For a simple example of including a navigation bar see
369 \url{https://github.com/rstudio/rmarkdown-website/blob/master/_navbar.html}.
370 For additional documentation on creating Bootstrap navigation bars see
371 \url{https://getbootstrap.com/docs/4.5/components/navbar/}.
372 }
373
374 \section{Floating Table of Contents}{
375
376
377 You may specify a list of options for the \code{toc_float} parameter which
378 control the behavior of the floating table of contents. Options include:
379 \itemize{
380 \item \code{collapsed} (defaults to \code{TRUE}) controls whether the table of contents appears with only the top-level (H2) headers. When collapsed the table of contents is automatically expanded inline when necessary.
381 \item \code{smooth_scroll} (defaults to \code{TRUE}) controls whether page scrolls are animated when table of contents items are navigated to via mouse clicks.
382 \item \code{print} (defaults to \code{TRUE}) controls whether the table of contents appears when user prints out the HTML page.
383 }
384 }
385
386 \section{Code folding}{
387
388
389 Code blocks become foldable by specifying "show" or "hide" to the
390 \code{code_folding} parameter. The state can be toggled individually on
391 browsers. The document-wide toggle button is also provided for
392 \code{html_document} and some of its extensions such as
393 \code{html_notebook}. Note that this feature applies not only to source
394 codes of chunks, but also markdown code blocks.
395
396 Supported languages are R, Python, Bash, SQL, C++, Stan, and Julia. To
397 support code blocks with other languages, add \code{foldable} class to them
398 (i.e., \code{class.source = "foldable"} as a chunk option).
399
400 The default initial state of code folding respects the value given to the
401 \code{code_folding} parameter. To override the behavior individually, add
402 \code{fold-none} to disable, \code{fold-hide} to initially hide,
403 \code{fold-show} to initially show.
404 }
405
406 \section{Tabbed Sections}{
407
408
409 You can organize content using tabs by applying the \code{.tabset} class
410 attribute to headers within a document. This will cause all sub-headers of
411 the header with the \code{.tabset} attribute to appear within tabs rather
412 than as standalone sections. For example:
413
414 \if{html}{\out{<div class="sourceCode markdown">}}\preformatted{## Quarterly Results \{.tabset\}
415
416 ### By Product
417
418 ### By Region
419 }\if{html}{\out{</div>}}
420
421 With \code{\link[=html_document]{html_document()}}, you can also specify two additional attributes to
422 control the appearance and behavior of the tabs. The \code{.tabset-fade}
423 attributes causes the tabs to fade in and out when switching. The
424 \code{.tabset-pills} attribute causes the visual appearance of the tabs to
425 be "pill" rather than traditional tabs. For example:
426
427 \if{html}{\out{<div class="sourceCode markdown">}}\preformatted{## Quarterly Results \{.tabset .tabset-fade .tabset-pills\}
428 }\if{html}{\out{</div>}}
429
430 If tabbed sections relies on \code{\link[=html_dependency_tabset]{html_dependency_tabset()}}, for example by
431 \code{\link[=html_vignette]{html_vignette()}}, these two attributes are not supported.
432 }
433
434 \section{Templates}{
435
436
437 You can provide a custom HTML template to be used for rendering. The syntax
438 for templates is described in the
439 \href{https://pandoc.org/MANUAL.html}{pandoc documentation}. You can also use
440 the basic pandoc template by passing \code{template = NULL}.
441
442 Note however that if you choose not to use the "default" HTML template then
443 several aspects of HTML document rendering will behave differently:
444 \itemize{
445 \item The \code{theme} parameter does not work (you can still provide styles using the \code{css} parameter).
446 \item For the \code{highlight} parameter, the default highlighting engine will resolve to Pandoc instead of highlightjs and highlighting style will default to "pygments". "textmate" style is not available as related to highlightjs
447 \item The \code{toc_float} parameter will not work.
448 \item The \code{code_folding} parameter will not work.
449 \item Tabbed sections (as described above) will not work.
450 \item Navigation bars (as described above) will not work.
451 \item MathJax will not work if \code{self_contained} is \code{TRUE} (these two options can't be used together in normal pandoc templates).
452 }
453
454 Due to the above restrictions, you might consider using the \code{includes}
455 parameter as an alternative to providing a fully custom template.
456 }
457
458 \examples{
459 \dontrun{
460 library(rmarkdown)
461
462 render("input.Rmd", html_document())
463
464 render("input.Rmd", html_document(toc = TRUE))
465 }
466 }