Skip to content

Commit

Permalink
add a vignette engine litedown::book to build vignettes into a book
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 1, 2024
1 parent e1d45e5 commit a6caa3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Set `options(bitmapType = 'cairo')` in `fuse()` if `capabilities('cairo')` is TRUE, which will generate smaller bitmap plot files (e.g., `.png`) than using `quartz` or `Xlib`, and is also a safer option for `fuse()` to be executed in parallel (rstudio/rmarkdown#2561).

- Added a new vignette engine `litedown::book` to make it possible to build multiple vignettes into a book. To use this engine, declare `\VignetteEngine{litedown::book}` only in the book index file (e.g., `index.Rmd`) but not in other book chapter files.

# CHANGES IN litedown VERSION 0.2

- A data frame (or matrix/tibble) wrapped in `I()` is fully printed to a table now by default. Without `I()`, data objects are truncated to 10 rows by default when printing to tables.
Expand Down
19 changes: 16 additions & 3 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ record_print.knitr_kable = function(x, ...) {

# register vignette engines
.onLoad = function(lib, pkg) {
vig_add('vignette', vig_fun(TRUE), vig_fun(FALSE))
vig_add('book', vig_fun(TRUE), vig_fun(FALSE))
}

vig_add = function(name, weave, tangle) {
tools::vignetteEngine(
'vignette', vig_fun(TRUE), vig_fun(FALSE), '[.]R?md$',
aspell = list(filter = vig_filter)
name, weave, tangle, '[.]R?md$', aspell = list(filter = vig_filter)
)
}

# weave or tangle?
vig_fun = function(weave = TRUE) {
vig_fun = function(weave = TRUE, book = FALSE) {
function(file, quiet = FALSE, ...) {
empty_file = function() write_utf8(character(), with_ext(file, '.R'))

# call fuse_book() to build multiple input files into a book
if (book) return(if (weave) {
if (quiet) {
opt = options(litedown.progress.delay = Inf); on.exit(options(opt))
}
fuse_book(dirname(file), envir = globalenv())
} else empty_file())

# fuse() .Rmd and mark() .md
if (grepl('[.]Rmd$', file)) {
if (weave) fuse(file, quiet = quiet, envir = globalenv()) else {
Expand Down

0 comments on commit a6caa3f

Please sign in to comment.