From 89098b4a602580a1ae7cd3e2c792e925a0b0b8ff Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Sun, 14 Jul 2019 10:06:51 +0900 Subject: [PATCH 1/9] add: odt_document2 (close #722) --- R/odt.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 R/odt.R diff --git a/R/odt.R b/R/odt.R new file mode 100644 index 000000000..36d9d5ca4 --- /dev/null +++ b/R/odt.R @@ -0,0 +1,24 @@ +#' @rdname html_document2 +#' @export +odt_document2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { + from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) + + config = rmarkdown::odt_document( + fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... + ) + pre = config$pre_processor + config$pre_processor = function(metadata, input_file, ...) { + # Pandoc does not support numbered sections for Word, so figures/tables have + # to be numbered globally from 1 to n + process_markdown(input_file, from, pandoc_args, TRUE) + if (is.function(pre)) pre(metadata, input_file, ...) + } + post = config$post_processor + config$post_processor = function(metadata, input, output, clean, verbose) { + if (is.function(post)) output = post(metadata, input, output, clean, verbose) + move_output(output) + } + config$bookdown_output_format = 'docx' + config = set_opts_knit(config) + config +} From e715fde2b98bdfb45c820b6d35426b0ce7d84b2c Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Sun, 14 Jul 2019 10:07:34 +0900 Subject: [PATCH 2/9] add: powerpoint_presentation2 (close #741) --- R/powerpoint.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 R/powerpoint.R diff --git a/R/powerpoint.R b/R/powerpoint.R new file mode 100644 index 000000000..38d9f186a --- /dev/null +++ b/R/powerpoint.R @@ -0,0 +1,24 @@ +#' @rdname html_document2 +#' @export +powerpoint_presentation2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { + from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) + + config = rmarkdown::powerpoint_presentation( + fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... + ) + pre = config$pre_processor + config$pre_processor = function(metadata, input_file, ...) { + # Pandoc does not support numbered sections for Word, so figures/tables have + # to be numbered globally from 1 to n + process_markdown(input_file, from, pandoc_args, TRUE) + if (is.function(pre)) pre(metadata, input_file, ...) + } + post = config$post_processor + config$post_processor = function(metadata, input, output, clean, verbose) { + if (is.function(post)) output = post(metadata, input, output, clean, verbose) + move_output(output) + } + config$bookdown_output_format = 'docx' + config = set_opts_knit(config) + config +} From c96fc3dce08f9f3d7b3a9ce9033ca101086fff0c Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Sun, 14 Jul 2019 10:08:15 +0900 Subject: [PATCH 3/9] devtools::document() --- NAMESPACE | 2 ++ man/bookdown-package.Rd | 1 + man/html_document2.Rd | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index a146ac080..db93d4f61 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,8 +10,10 @@ export(html_book) export(html_chapters) export(html_document2) export(kindlegen) +export(odt_document2) export(pdf_book) export(pdf_document2) +export(powerpoint_presentation2) export(preview_chapter) export(publish_book) export(render_book) 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..ff6d30457 100644 --- a/man/html_document2.Rd +++ b/man/html_document2.Rd @@ -1,11 +1,14 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/html.R, R/latex.R, R/word.R +% Please edit documentation in R/html.R, R/latex.R, R/odt.R, R/powerpoint.R, +% R/word.R \name{html_document2} \alias{html_document2} \alias{tufte_html2} \alias{pdf_document2} \alias{tufte_handout2} \alias{tufte_book2} +\alias{odt_document2} +\alias{powerpoint_presentation2} \alias{word_document2} \title{Output formats that allow numbering and cross-referencing figures/tables/equations} @@ -21,6 +24,12 @@ tufte_handout2(...) tufte_book2(...) +odt_document2(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, + ...) + +powerpoint_presentation2(fig_caption = TRUE, md_extensions = NULL, + pandoc_args = NULL, ...) + word_document2(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) } From 6239e3f1b08f0143ebc1e673baa67f5e3fa85359 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Thu, 25 Jul 2019 07:19:29 +0900 Subject: [PATCH 4/9] factor out repeated codes to office_document2_base --- R/odt.R | 24 ------------------- R/powerpoint.R | 24 ------------------- R/word.R | 56 +++++++++++++++++++++++++++---------------- man/html_document2.Rd | 21 ++++++++-------- 4 files changed, 45 insertions(+), 80 deletions(-) delete mode 100644 R/odt.R delete mode 100644 R/powerpoint.R diff --git a/R/odt.R b/R/odt.R deleted file mode 100644 index 36d9d5ca4..000000000 --- a/R/odt.R +++ /dev/null @@ -1,24 +0,0 @@ -#' @rdname html_document2 -#' @export -odt_document2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { - from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) - - config = rmarkdown::odt_document( - fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... - ) - pre = config$pre_processor - config$pre_processor = function(metadata, input_file, ...) { - # Pandoc does not support numbered sections for Word, so figures/tables have - # to be numbered globally from 1 to n - process_markdown(input_file, from, pandoc_args, TRUE) - if (is.function(pre)) pre(metadata, input_file, ...) - } - post = config$post_processor - config$post_processor = function(metadata, input, output, clean, verbose) { - if (is.function(post)) output = post(metadata, input, output, clean, verbose) - move_output(output) - } - config$bookdown_output_format = 'docx' - config = set_opts_knit(config) - config -} diff --git a/R/powerpoint.R b/R/powerpoint.R deleted file mode 100644 index 38d9f186a..000000000 --- a/R/powerpoint.R +++ /dev/null @@ -1,24 +0,0 @@ -#' @rdname html_document2 -#' @export -powerpoint_presentation2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { - from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) - - config = rmarkdown::powerpoint_presentation( - fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... - ) - pre = config$pre_processor - config$pre_processor = function(metadata, input_file, ...) { - # Pandoc does not support numbered sections for Word, so figures/tables have - # to be numbered globally from 1 to n - process_markdown(input_file, from, pandoc_args, TRUE) - if (is.function(pre)) pre(metadata, input_file, ...) - } - post = config$post_processor - config$post_processor = function(metadata, input, output, clean, verbose) { - if (is.function(post)) output = post(metadata, input, output, clean, verbose) - move_output(output) - } - config$bookdown_output_format = 'docx' - config = set_opts_knit(config) - config -} diff --git a/R/word.R b/R/word.R index 898fda8a2..f2c771ed4 100644 --- a/R/word.R +++ b/R/word.R @@ -1,24 +1,38 @@ -#' @rdname html_document2 -#' @export -word_document2 = function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { - from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) +office_document2_base = function(base_format) { + force(base_format) - config = rmarkdown::word_document( - fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... - ) - pre = config$pre_processor - config$pre_processor = function(metadata, input_file, ...) { - # Pandoc does not support numbered sections for Word, so figures/tables have - # to be numbered globally from 1 to n - process_markdown(input_file, from, pandoc_args, TRUE) - if (is.function(pre)) pre(metadata, input_file, ...) - } - post = config$post_processor - config$post_processor = function(metadata, input, output, clean, verbose) { - if (is.function(post)) output = post(metadata, input, output, clean, verbose) - move_output(output) + function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { + from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) + + config = base_format( + fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... + ) + pre = config$pre_processor + config$pre_processor = function(metadata, input_file, ...) { + # Pandoc does not support numbered sections for Word, so figures/tables have + # to be numbered globally from 1 to n + process_markdown(input_file, from, pandoc_args, TRUE) + if (is.function(pre)) pre(metadata, input_file, ...) + } + post = config$post_processor + config$post_processor = function(metadata, input, output, clean, verbose) { + if (is.function(post)) output = post(metadata, input, output, clean, verbose) + move_output(output) + } + config$bookdown_output_format = 'docx' + config = set_opts_knit(config) + config } - config$bookdown_output_format = 'docx' - config = set_opts_knit(config) - config } + +#' @rdname html_document2 +#' @export +word_document2 = office_document2_base(rmarkdown::word_document) + +#' @rdname html_document2 +#' @export +odt_document2 = office_document2_base(rmarkdown::odt_document) + +#' @rdname html_document2 +#' @export +powerpoint_presentation2 = office_document2_base(rmarkdown::powerpoint_presentation) diff --git a/man/html_document2.Rd b/man/html_document2.Rd index ff6d30457..f7c3244d7 100644 --- a/man/html_document2.Rd +++ b/man/html_document2.Rd @@ -1,20 +1,19 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/html.R, R/latex.R, R/odt.R, R/powerpoint.R, -% R/word.R +% Please edit documentation in R/html.R, R/latex.R, R/word.R \name{html_document2} \alias{html_document2} \alias{tufte_html2} \alias{pdf_document2} \alias{tufte_handout2} \alias{tufte_book2} +\alias{word_document2} \alias{odt_document2} \alias{powerpoint_presentation2} -\alias{word_document2} \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) @@ -24,14 +23,14 @@ tufte_handout2(...) tufte_book2(...) -odt_document2(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, - ...) +word_document2(fig_caption = TRUE, md_extensions = NULL, + pandoc_args = NULL, ...) -powerpoint_presentation2(fig_caption = TRUE, md_extensions = NULL, - pandoc_args = NULL, ...) +odt_document2(fig_caption = TRUE, md_extensions = NULL, + pandoc_args = NULL, ...) -word_document2(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, - ...) +powerpoint_presentation2(fig_caption = TRUE, md_extensions = NULL, + pandoc_args = NULL, ...) } \arguments{ \item{..., fig_caption, md_extensions, pandoc_args}{Arguments to be passed to a From 85e2aefe4577f0f68505be59b530aab3fb18d02b Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Thu, 25 Jul 2019 07:41:24 +0900 Subject: [PATCH 5/9] fix: bookdown_output_format being docx which should be conditionally defined --- R/word.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/word.R b/R/word.R index f2c771ed4..625856572 100644 --- a/R/word.R +++ b/R/word.R @@ -19,7 +19,7 @@ office_document2_base = function(base_format) { 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 } From 58b7bb51594f087e3e29d570a0dd28de2683ed00 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 29 Jul 2019 21:14:56 +0900 Subject: [PATCH 6/9] rename office_document2 to markdown_document2 and export it --- NAMESPACE | 1 + R/word.R | 59 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index db93d4f61..8648e882b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(html_book) export(html_chapters) export(html_document2) export(kindlegen) +export(markdown_document2) export(odt_document2) export(pdf_book) export(pdf_document2) diff --git a/R/word.R b/R/word.R index 625856572..4a456d54c 100644 --- a/R/word.R +++ b/R/word.R @@ -1,38 +1,45 @@ -office_document2_base = function(base_format) { - force(base_format) - - function(fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...) { - from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) +#' @rdname html_document2 +#' @export +markdown_document2 = function( + fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ..., base_format +) { + from = rmarkdown::from_rmarkdown(fig_caption, md_extensions) - config = base_format( - fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ... - ) - pre = config$pre_processor - config$pre_processor = function(metadata, input_file, ...) { - # Pandoc does not support numbered sections for Word, so figures/tables have - # to be numbered globally from 1 to n - process_markdown(input_file, from, pandoc_args, TRUE) - if (is.function(pre)) pre(metadata, input_file, ...) - } - post = config$post_processor - config$post_processor = function(metadata, input, output, clean, verbose) { - if (is.function(post)) output = post(metadata, input, output, clean, verbose) - move_output(output) - } - config$bookdown_output_format = config$pandoc$to - config = set_opts_knit(config) - config + 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 + config$pre_processor = function(metadata, input_file, ...) { + # Pandoc does not support numbered sections for Word, so figures/tables have + # to be numbered globally from 1 to n + process_markdown(input_file, from, pandoc_args, TRUE) + if (is.function(pre)) pre(metadata, input_file, ...) + } + post = config$post_processor + config$post_processor = function(metadata, input, output, clean, verbose) { + if (is.function(post)) output = post(metadata, input, output, clean, verbose) + move_output(output) } + config$bookdown_output_format = config$pandoc$to + config = set_opts_knit(config) + config } #' @rdname html_document2 #' @export -word_document2 = office_document2_base(rmarkdown::word_document) +word_document2 = function(...) { + markdown_document2(..., base_format = rmarkdown::word_document) +} #' @rdname html_document2 #' @export -odt_document2 = office_document2_base(rmarkdown::odt_document) +odt_document2 = function(...) { + markdown_document2(..., base_format = rmarkdown::odt_document) +} #' @rdname html_document2 #' @export -powerpoint_presentation2 = office_document2_base(rmarkdown::powerpoint_presentation) +powerpoint_presentation2 = function(...) { + markdown_document2(..., base_format = rmarkdown::powerpoint_presentation) +} From a6943ae705be2d5adb22ed38272e287357f0ad65 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 29 Jul 2019 21:16:33 +0900 Subject: [PATCH 7/9] document markdown_document2 in html_document2 --- R/html.R | 4 +++- man/html_document2.Rd | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) 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/man/html_document2.Rd b/man/html_document2.Rd index f7c3244d7..8e84b2661 100644 --- a/man/html_document2.Rd +++ b/man/html_document2.Rd @@ -6,6 +6,7 @@ \alias{pdf_document2} \alias{tufte_handout2} \alias{tufte_book2} +\alias{markdown_document2} \alias{word_document2} \alias{odt_document2} \alias{powerpoint_presentation2} @@ -23,14 +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) -odt_document2(fig_caption = TRUE, md_extensions = NULL, - pandoc_args = NULL, ...) +word_document2(...) -powerpoint_presentation2(fig_caption = TRUE, md_extensions = NULL, - pandoc_args = NULL, ...) +odt_document2(...) + +powerpoint_presentation2(...) } \arguments{ \item{..., fig_caption, md_extensions, pandoc_args}{Arguments to be passed to a @@ -56,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 From f3817a396e070c3218c014cda7185ce99f177a7e Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 29 Jul 2019 21:16:50 +0900 Subject: [PATCH 8/9] update NEWS --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index ba1f11b96..e64a109d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ # 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 From f2560e36106d8a0276f15a3c0465873503eebfd5 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 9 Aug 2019 10:11:45 -0500 Subject: [PATCH 9/9] unwrap lines in news --- NEWS.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index e64a109d5..c63905a87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,9 +3,8 @@ ## 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). + +- 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