diff --git a/NAMESPACE b/NAMESPACE index a146ac080..8648e882b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,8 +10,11 @@ export(html_book) export(html_chapters) export(html_document2) export(kindlegen) +export(markdown_document2) +export(odt_document2) export(pdf_book) export(pdf_document2) +export(powerpoint_presentation2) export(preview_chapter) export(publish_book) export(render_book) diff --git a/NEWS.md b/NEWS.md index ba1f11b96..c63905a87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ # CHANGES IN bookdown VERSION 0.13 +## NEW FEATURES + +- Added `odt_document2` and `powerpoint_presentation2` (thanks, @atusy, #742). +- Added `markdown_document2` which enables to use cross references in an arbitrary format specified in `base_format` argument (e.g., `markdown_document2(base_format = prettydoc::html_pretty)`) (thanks, @atusy, #742). # CHANGES IN bookdown VERSION 0.12 diff --git a/R/html.R b/R/html.R index d3c537964..811d18c9f 100644 --- a/R/html.R +++ b/R/html.R @@ -99,7 +99,9 @@ tufte_html_book = function(...) { #' \code{rmarkdown::\link{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. +#' their ID's using the same syntax when sections are numbered. In case you want +#' to enable cross reference in other formats, use \code{markdown_document2} with +#' \code{base_format} argument. #' @param ...,fig_caption,md_extensions,pandoc_args Arguments to be passed to a #' specific output format function. For a function \code{foo2()}, its #' arguments are passed to \code{foo()}, e.g. \code{...} of diff --git a/R/word.R b/R/word.R index 898fda8a2..4a456d54c 100644 --- a/R/word.R +++ b/R/word.R @@ -1,9 +1,12 @@ #' @rdname html_document2 #' @export -word_document2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { +markdown_document2 = function( + fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ..., base_format +) { from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) - config = rmarkdown::word_document( + base_format = get_base_format(base_format) + config = base_format( fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... ) pre = config$pre_processor @@ -18,7 +21,25 @@ word_document2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args if (is.function(post)) output = post(metadata, input, output, clean, verbose) move_output(output) } - config$bookdown_output_format = 'docx' + config$bookdown_output_format = config$pandoc$to config = set_opts_knit(config) config } + +#' @rdname html_document2 +#' @export +word_document2 = function(...) { + markdown_document2(..., base_format = rmarkdown::word_document) +} + +#' @rdname html_document2 +#' @export +odt_document2 = function(...) { + markdown_document2(..., base_format = rmarkdown::odt_document) +} + +#' @rdname html_document2 +#' @export +powerpoint_presentation2 = function(...) { + markdown_document2(..., base_format = rmarkdown::powerpoint_presentation) +} diff --git a/man/bookdown-package.Rd b/man/bookdown-package.Rd index ba6178e8c..8dc9ae598 100644 --- a/man/bookdown-package.Rd +++ b/man/bookdown-package.Rd @@ -26,6 +26,7 @@ Other contributors: \item Albert Kim [contributor] \item Alessandro Samuel-Rosa [contributor] \item Andrzej Oles [contributor] + \item Atsushi Yasumoto (0000-0002-8335-495X) [contributor] \item Aust Frederik (0000-0003-4900-788X) [contributor] \item Bastiaan Quast [contributor] \item Ben Marwick [contributor] diff --git a/man/html_document2.Rd b/man/html_document2.Rd index a4c2c9e9a..8e84b2661 100644 --- a/man/html_document2.Rd +++ b/man/html_document2.Rd @@ -6,12 +6,15 @@ \alias{pdf_document2} \alias{tufte_handout2} \alias{tufte_book2} +\alias{markdown_document2} \alias{word_document2} +\alias{odt_document2} +\alias{powerpoint_presentation2} \title{Output formats that allow numbering and cross-referencing figures/tables/equations} \usage{ -html_document2(..., number_sections = TRUE, pandoc_args = NULL, - base_format = rmarkdown::html_document) +html_document2(..., number_sections = TRUE, pandoc_args = NULL, + base_format = rmarkdown::html_document) tufte_html2(..., number_sections = FALSE) @@ -21,8 +24,14 @@ tufte_handout2(...) tufte_book2(...) -word_document2(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, - ...) +markdown_document2(fig_caption = TRUE, md_extensions = NULL, + pandoc_args = NULL, ..., base_format) + +word_document2(...) + +odt_document2(...) + +powerpoint_presentation2(...) } \arguments{ \item{..., fig_caption, md_extensions, pandoc_args}{Arguments to be passed to a @@ -48,7 +57,9 @@ These are simple wrappers of the output format functions like \code{rmarkdown::\link{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. +their ID's using the same syntax when sections are numbered. In case you want +to enable cross reference in other formats, use \code{markdown_document2} with +\code{base_format} argument. } \note{ These function are expected to work with a single R Markdown document