Title: | Authoring Books and Technical Documents with R Markdown |
---|---|
Description: | Output formats and utilities for authoring books and technical documents with R Markdown. |
Authors: | Yihui Xie [aut, cre] , Christophe Dervieux [ctb] , JJ Allaire [ctb], Albert Kim [ctb], Alessandro Samuel-Rosa [ctb], Andrzej Oles [ctb], Atsushi Yasumoto [ctb] , Aust Frederik [ctb] , Bastiaan Quast [ctb], Ben Marwick [ctb], Chester Ismay [ctb], Clifton Franklund [ctb], Daniel Emaasit [ctb], David Shuman [ctb], Dean Attali [ctb], Drew Tyre [ctb], Ellis Valentiner [ctb], Frans van Dunne [ctb], Hadley Wickham [ctb], Jeff Allen [ctb], Jennifer Bryan [ctb], Jonathan McPhers [ctb], JooYoung Seo [ctb] , Joyce Robbins [ctb], Junwen Huang [ctb], Kevin Cheung [ctb], Kevin Ushey [ctb], Kim Seonghyun [ctb], Kirill Muller [ctb], Luciano Selzer [ctb], Matthew Lincoln [ctb], Maximilian Held [ctb], Michael Sachs [ctb], Michal Bojanowski [ctb], Nathan Werth [ctb], Noam Ross [ctb], Peter Hickey [ctb], Pedro Rafael D. Marinho [ctb] , Romain Lesur [ctb] , Sahir Bhatnagar [ctb], Shir Dekel [ctb] , Steve Simpson [ctb], Thierry Onkelinx [ctb] , Vincent Fulco [ctb], Yixuan Qiu [ctb], Zhuoer Dong [ctb], Posit Software, PBC [cph, fnd], Bartek Szopka [ctb] (The jQuery Highlight plugin), Zeno Rocha [cph] (clipboard.js library), MathQuill contributors [ctb] (The MathQuill library; authors listed in inst/resources/AUTHORS), FriendCode Inc [cph, ctb] (The gitbook style, with modifications) |
Maintainer: | Yihui Xie <[email protected]> |
License: | GPL-3 |
Version: | 0.41.2 |
Built: | 2024-12-06 17:20:28 UTC |
Source: | https://github.com/rstudio/bookdown |
Implementation of custom R Markdown site generator for bookdown.
bookdown_site(input, ...)
bookdown_site(input, ...)
input |
Website directory (or the name of a file within the directory). |
... |
Currently unused. |
This output format is built with Bootstrap, using carefully crafted features to provide a clean reading experience whether you are on a phone, tablet, or desktop. To read more about this format, see: https://bookdown.org/yihui/bookdown/html.html#bs4-book
bs4_book( theme = bs4_book_theme(), repo = NULL, ..., lib_dir = "libs", pandoc_args = NULL, extra_dependencies = NULL, template = "default", split_bib = FALSE, footnotes_inline = TRUE ) bs4_book_theme(primary = "#0068D9", version = 4, ...)
bs4_book( theme = bs4_book_theme(), repo = NULL, ..., lib_dir = "libs", pandoc_args = NULL, extra_dependencies = NULL, template = "default", split_bib = FALSE, footnotes_inline = TRUE ) bs4_book_theme(primary = "#0068D9", version = 4, ...)
theme |
A named list or |
repo |
Either link to repository where book is hosted, used to generate
view source and edit buttons or a list with repository |
lib_dir , pandoc_args , extra_dependencies , split_bib , ...
|
Passed on to |
template |
Pandoc template to use for rendering. Pass |
footnotes_inline |
By default, footnotes will be set inline and shown on
hover. Set to |
primary |
Primary colour: used for links and background of footer. |
version |
Passed to |
This function calls the command ebook-convert
in Calibre
(https://calibre-ebook.com) to convert e-books.
calibre(input, output, options = "")
calibre(input, output, options = "")
input |
The input filename. |
output |
The output filename or extension (if only an extension is
provided, the output filename will be the input filename with its extension
replaced by |
options |
A character vector of additional options to be passed to
|
The output filename.
After a book is rendered, there will be a series of output files and directories created in the book root directory, typically including ‘*_files/’, ‘*_cache/’, ‘_book/’, and some HTML/LaTeX auxiliary files. These filenames depend on the book configurations. This function identifies these files and directories, and delete them if desired, so you can rebuild the book with a clean source.
clean_book(clean = getOption("bookdown.clean_book", FALSE))
clean_book(clean = getOption("bookdown.clean_book", FALSE))
clean |
Whether to delete the possible output files. If |
Create a bookdown project with multiple book output formats, including HTML. Choose one of two HTML book output formats:
create_gitbook(path) create_bs4_book(path)
create_gitbook(path) create_bs4_book(path)
path |
Absolute path to an empty directory in which to create the bookdown project. In the RStudio IDE, if rstudioapi package available, an RStudio project will be created. |
Use create_gitbook()
to use bookdown::gitbook()
output format
Use create_bs4_book()
to use a bookdown::bs4_book()
output format
The function will create a folder with file structure for a bookdown project, and example files with information on how to start.
Convert a book to the EPUB format, which is is an e-book format supported by many readers, such as Amazon Kindle Fire and iBooks on Apple devices.
epub_book( fig_width = 5, fig_height = 4, dev = "png", fig_caption = TRUE, number_sections = TRUE, toc = FALSE, toc_depth = 3, stylesheet = NULL, cover_image = NULL, metadata = NULL, chapter_level = 1, epub_version = c("epub3", "epub", "epub2"), md_extensions = NULL, global_numbering = !number_sections, pandoc_args = NULL, template = "default" )
epub_book( fig_width = 5, fig_height = 4, dev = "png", fig_caption = TRUE, number_sections = TRUE, toc = FALSE, toc_depth = 3, stylesheet = NULL, cover_image = NULL, metadata = NULL, chapter_level = 1, epub_version = c("epub3", "epub", "epub2"), md_extensions = NULL, global_numbering = !number_sections, pandoc_args = NULL, template = "default" )
fig_width , fig_height , dev , fig_caption
|
Figure options (width, height, the graphical device, and whether to render figure captions). |
number_sections |
Whether to number sections. |
toc , toc_depth
|
Whether to generate a table of contents, and its depth. |
stylesheet |
A character vector of paths to CSS stylesheets to be applied to the eBook. |
cover_image |
The path to a cover image. |
metadata |
The path to the EPUB metadata file. |
chapter_level |
The level by which the e-book is split into separate “chapter” files. |
epub_version |
Whether to use version 3 or 2 of EPUB. This correspond to
Pandoc's supported output format. |
md_extensions |
A character string of Pandoc Markdown extensions. |
global_numbering |
If |
pandoc_args |
A vector of additional Pandoc arguments. |
template |
Pandoc template to use for rendering. Pass |
Figure/table numbers cannot be generated if sections are not numbered
(number_sections = FALSE
).
This function converts the syntax ‘```{theorem, label, ...}’ to ‘::: {.theorem #label ...}’ (Pandoc's fenced Div) for theorem environments.
fence_theorems(input, text = xfun::read_utf8(input), output = NULL)
fence_theorems(input, text = xfun::read_utf8(input), output = NULL)
input |
Path to an Rmd file that contains theorem environments written in the syntax of code blocks. |
text |
A character vector of the Rmd source. When |
output |
The output file to write the converted input content. You can
specify |
If output = NULL
, the converted text is returned, otherwise
the text is written to the output file.
Learn more about theorems and proofs and custom blocks in the bookdown book.
This output format function ported a style provided by GitBook (https://www.gitbook.com) for R Markdown. To read more about this format, see: https://bookdown.org/yihui/bookdown/html.html#gitbook-style
gitbook( fig_caption = TRUE, number_sections = TRUE, self_contained = FALSE, anchor_sections = TRUE, lib_dir = "libs", global_numbering = !number_sections, pandoc_args = NULL, extra_dependencies = list(), ..., template = "default", split_by = c("chapter", "chapter+number", "section", "section+number", "rmd", "none"), split_bib = TRUE, config = list(), table_css = TRUE, code_folding = c("none", "show", "hide") )
gitbook( fig_caption = TRUE, number_sections = TRUE, self_contained = FALSE, anchor_sections = TRUE, lib_dir = "libs", global_numbering = !number_sections, pandoc_args = NULL, extra_dependencies = list(), ..., template = "default", split_by = c("chapter", "chapter+number", "section", "section+number", "rmd", "none"), split_bib = TRUE, config = list(), table_css = TRUE, code_folding = c("none", "show", "hide") )
fig_caption , number_sections , self_contained , anchor_sections , lib_dir , pandoc_args , code_folding , extra_dependencies , ...
|
Arguments to be passed to |
global_numbering |
If |
template |
Pandoc template to use for rendering. Pass |
split_by |
How to name the HTML output files from the book: |
split_bib |
Whether to split the bibliography onto separate pages where the citations are actually used. |
config |
A list of configuration options for the gitbook style, such as the font/theme settings. |
table_css |
|
Split the HTML output into chapters while updating relative links (e.g. links
in TOC, footnotes, citations, figure/table cross-references, and so on).
Functions html_book()
and tufte_html_book()
are simple wrapper
functions of html_chapter()
using a specific base output format.
html_chapters( toc = TRUE, number_sections = TRUE, fig_caption = TRUE, lib_dir = "libs", template = bookdown_file("templates/default.html"), global_numbering = !number_sections, pandoc_args = NULL, ..., base_format = rmarkdown::html_document, split_bib = TRUE, page_builder = build_chapter, split_by = c("section+number", "section", "chapter+number", "chapter", "rmd", "none") ) html_book(...) tufte_html_book(...)
html_chapters( toc = TRUE, number_sections = TRUE, fig_caption = TRUE, lib_dir = "libs", template = bookdown_file("templates/default.html"), global_numbering = !number_sections, pandoc_args = NULL, ..., base_format = rmarkdown::html_document, split_bib = TRUE, page_builder = build_chapter, split_by = c("section+number", "section", "chapter+number", "chapter", "rmd", "none") ) html_book(...) tufte_html_book(...)
toc , number_sections , fig_caption , lib_dir , template , pandoc_args
|
See
|
global_numbering |
If |
... |
Other arguments to be passed to |
base_format |
An output format function to be used as the base format. |
split_bib |
Whether to split the bibliography onto separate pages where the citations are actually used. |
page_builder |
A function to combine different parts of a chapter into a
page (an HTML character vector). See |
split_by |
How to name the HTML output files from the book: |
An R Markdown output format object to be passed to
bookdown::render_book()
.
These functions are expected to be used in conjunction with
render_book()
. It is almost meaningless if they are used with
rmarkdown::render()
. Functions like html_document2
are
designed to work with the latter.
If you want to use a different template, the template must contain three
pairs of HTML comments: ‘<!--bookdown:title:start-->’ and
‘<!--bookdown:title:end-->’ to mark the title section of the book
(this section will be placed only on the first page of the rendered book);
‘<!--bookdown:toc:start-->’ and ‘<!--bookdown:toc:end-->’ to mark
the table of contents section (it will be placed on all chapter pages);
‘<!--bookdown:body:start-->’ and ‘<!--bookdown:body:end-->’ to
mark the HTML body of the book (the HTML body will be split into separate
pages for chapters). You may open the default HTML template
(bookdown:::bookdown_file('templates/default.html')
) to see where
these comments were inserted.
These are simple wrappers of the output format functions like
rmarkdown::html_document()
, and they added the
capability of numbering figures/tables/equations/theorems and
cross-referencing them. See ‘References’ for the syntax. Note you can
also cross-reference sections by their ID's using the same syntax when
sections are numbered. In case you want to enable cross reference in other
formats, use markdown_document2
with base_format
argument.
html_document2( ..., number_sections = TRUE, global_numbering = !number_sections, pandoc_args = NULL, base_format = rmarkdown::html_document ) html_fragment2(..., number_sections = FALSE) html_notebook2(..., number_sections = FALSE) html_vignette2(..., number_sections = FALSE) ioslides_presentation2(..., number_sections = FALSE) slidy_presentation2(..., number_sections = FALSE) tufte_html2(..., number_sections = FALSE) pdf_document2(...) beamer_presentation2(..., number_sections = FALSE) tufte_handout2(...) tufte_book2(...) markdown_document2( number_sections = TRUE, fig_caption = TRUE, md_extensions = NULL, global_numbering = !number_sections, pandoc_args = NULL, ..., base_format = rmarkdown::md_document ) context_document2(...) github_document2(...) odt_document2(...) powerpoint_presentation2(...) rtf_document2(...) word_document2(...)
html_document2( ..., number_sections = TRUE, global_numbering = !number_sections, pandoc_args = NULL, base_format = rmarkdown::html_document ) html_fragment2(..., number_sections = FALSE) html_notebook2(..., number_sections = FALSE) html_vignette2(..., number_sections = FALSE) ioslides_presentation2(..., number_sections = FALSE) slidy_presentation2(..., number_sections = FALSE) tufte_html2(..., number_sections = FALSE) pdf_document2(...) beamer_presentation2(..., number_sections = FALSE) tufte_handout2(...) tufte_book2(...) markdown_document2( number_sections = TRUE, fig_caption = TRUE, md_extensions = NULL, global_numbering = !number_sections, pandoc_args = NULL, ..., base_format = rmarkdown::md_document ) context_document2(...) github_document2(...) odt_document2(...) powerpoint_presentation2(...) rtf_document2(...) word_document2(...)
... , fig_caption , md_extensions , pandoc_args
|
Arguments to be passed to a
specific output format function. For a function |
number_sections |
Whether to number section headers: if |
global_numbering |
If |
base_format |
An output format function to be used as the base format. |
An R Markdown output format object to be passed to
rmarkdown::render()
.
These output formats are used to generate single output files, such as
a single HTML output file (unlike gitbook
, which generates multiple
HTML output files by default).
The functions ‘tufte_*()’ are wrappers of functions in the tufte package.
https://bookdown.org/yihui/bookdown/
Convert R Markdown files to PDF after resolving the special tokens of bookdown (e.g., the tokens for references and labels) to native LaTeX commands.
pdf_book( toc = TRUE, number_sections = TRUE, fig_caption = TRUE, pandoc_args = NULL, ..., base_format = rmarkdown::pdf_document, toc_unnumbered = TRUE, toc_appendix = FALSE, toc_bib = FALSE, quote_footer = NULL, highlight_bw = FALSE )
pdf_book( toc = TRUE, number_sections = TRUE, fig_caption = TRUE, pandoc_args = NULL, ..., base_format = rmarkdown::pdf_document, toc_unnumbered = TRUE, toc_appendix = FALSE, toc_bib = FALSE, quote_footer = NULL, highlight_bw = FALSE )
toc , number_sections , fig_caption , pandoc_args
|
See
|
... |
Other arguments to be passed to |
base_format |
An output format function to be used as the base format. |
toc_unnumbered |
Whether to add unnumbered headers to the table of contents. |
toc_appendix |
Whether to add the appendix to the table of contents. |
toc_bib |
Whether to add the bibliography section to the table of contents. |
quote_footer |
If a character vector of length 2 and the quote footer
starts with three dashes (‘---’), |
highlight_bw |
Whether to convert colors for syntax highlighting to black-and-white (grayscale). |
This function is based on rmarkdown::pdf_document
(by default) with better default arguments. You can also change the default
format to other LaTeX/PDF format functions using the base_format
argument.
The global R option bookdown.post.latex
can be set to a function to
post-process the LaTeX output. This function takes the character vector of
the LaTeX output as its input argument, and should return a character vector
to be written to the ‘.tex’ output file. This gives you full power to
post-process the LaTeX output.
This output format can only be used with render_book()
.
Publish a book to the web. Note that you should be sure to render all
versions of the book before publishing, unless you have specified
render = TRUE
.
publish_book( name = NULL, account = NULL, server = NULL, render = c("none", "local", "server") )
publish_book( name = NULL, account = NULL, server = NULL, render = c("none", "local", "server") )
name |
Name of the book (this will be used in the URL path of the
published book). Defaults to the |
account |
Account name to publish to. Will default to any previously
published to account or any single account already associated with
|
server |
Server to publish to (by default beta.rstudioconnect.com but any RStudio Connect server can be published to). |
render |
Rendering behavior for site:
Note that for |
Render multiple R Markdown files under the current working directory into a
book. It can be used in the RStudio IDE (specifically, the knit
field
in YAML). The preview_chapter()
function is a wrapper of
render_book(preview = TRUE)
.
render_book( input = ".", output_format = NULL, ..., clean = TRUE, envir = parent.frame(), clean_envir = !interactive(), output_dir = NULL, new_session = NA, preview = FALSE, config_file = "_bookdown.yml" ) preview_chapter(..., envir = parent.frame())
render_book( input = ".", output_format = NULL, ..., clean = TRUE, envir = parent.frame(), clean_envir = !interactive(), output_dir = NULL, new_session = NA, preview = FALSE, config_file = "_bookdown.yml" ) preview_chapter(..., envir = parent.frame())
input |
A directory, an input filename or multiple filenames. For a
directory, ‘index.Rmd’ will be used if it exists in this (book)
project directory. For filenames, if |
output_format , ... , clean , envir
|
Arguments to be passed to
|
clean_envir |
This argument has been deprecated and will be removed in future versions of bookdown. |
output_dir |
The output directory. If |
new_session |
Whether to use new R sessions to compile individual Rmd
files (if not provided, the value of the |
preview |
Whether to render and preview the input files specified by the
|
config_file |
The book configuration file. |
There are two ways to render a book from Rmd files. The default way
(new_session = FALSE
) is to merge Rmd files into a single file and
render this file. You can also choose to render each individual Rmd file in a
new R session (new_session = TRUE
).
# see https://bookdown.org/yihui/bookdown for the full documentation if (file.exists("index.Rmd")) bookdown::render_book("index.Rmd") ## Not run: # will use the default format defined in index.Rmd or _output.yml bookdown::render_book("index.Rmd") # will use the options for format defined in YAML metadata bookdown::render_book("index.Rmd", "bookdown::pdf_book") # If you pass an output format object, it must have all the options set bookdown::render_book("index.Rmd", bookdown::pdf_book(toc = FALSE)) # will render the book in the current directory bookdown::render_book() # this is equivalent to bookdown::render_book("index.Rmd") # will render the book living in the specified directory bookdown::render_book("my_book_project") ## End(Not run)
# see https://bookdown.org/yihui/bookdown for the full documentation if (file.exists("index.Rmd")) bookdown::render_book("index.Rmd") ## Not run: # will use the default format defined in index.Rmd or _output.yml bookdown::render_book("index.Rmd") # will use the options for format defined in YAML metadata bookdown::render_book("index.Rmd", "bookdown::pdf_book") # If you pass an output format object, it must have all the options set bookdown::render_book("index.Rmd", bookdown::pdf_book(toc = FALSE)) # will render the book in the current directory bookdown::render_book() # this is equivalent to bookdown::render_book("index.Rmd") # will render the book living in the specified directory bookdown::render_book("my_book_project") ## End(Not run)
When any files are modified or added to the book directory, the book will be
automatically recompiled, and the current HTML page in the browser will be
refreshed. This function is based on servr::httw()
to continuously watch a directory.
serve_book( dir = ".", output_dir = "_book", preview = TRUE, in_session = TRUE, quiet = FALSE, ... )
serve_book( dir = ".", output_dir = "_book", preview = TRUE, in_session = TRUE, quiet = FALSE, ... )
dir |
The root directory of the book (containing the Rmd source files). |
output_dir |
The directory for output files; see
|
preview |
Whether to render the modified/added chapters only, or the
whole book; see |
in_session |
Whether to compile the book using the current R session, or always open a new R session to compile the book whenever changes occur in the book directory. |
quiet |
Whether to suppress output (e.g., the knitting progress) in the console. |
... |
Other arguments passed to |
For in_session = TRUE
, you will have access to all objects created in
the book in the current R session: if you use a daemonized server (via the
argument daemon = TRUE
), you can check the objects at any time when
the current R session is not busy; otherwise you will have to stop the server
before you can check the objects. This can be useful when you need to
interactively explore the R objects in the book. The downside of
in_session = TRUE
is that the output may be different with the book
compiled from a fresh R session, because the state of the current R session
may not be clean.
For in_session = FALSE
, you do not have access to objects in the book
from the current R session, but the output is more likely to be reproducible
since everything is created from new R sessions. Since this function is only
for previewing purposes, the cleanness of the R session may not be a big
concern. You may choose in_session = TRUE
or FALSE
depending on
your specific applications. Eventually, you should run render_book()
from a fresh R session to generate a reliable copy of the book output.