Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rmarkdown 2.7

- Do not force `options(htmltools.preserve.raw = TRUE)` when this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293.

- `knitr_options_pdf()` will now throw a warning when `fig_crop = TRUE` but is disabled because required tools `pdfcrop` and/or `ghostscript` are missing (thanks, @netique, #2016).

rmarkdown 2.6
================================================================================
Expand Down
2 changes: 1 addition & 1 deletion R/output_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ knitr_options_pdf <- function(fig_width,
knit_hooks <- NULL

# apply cropping if requested and we have pdfcrop and ghostscript
crop <- fig_crop && find_program("pdfcrop") != '' && tools::find_gs_cmd() != ''
crop <- fig_crop && has_crop_tools()
if (crop) {
knit_hooks = list(crop = knitr::hook_pdfcrop)
opts_chunk$crop = TRUE
Expand Down
15 changes: 15 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ find_program <- function(program) {
}
}

has_crop_tools <- function() {
tools <- c(
pdfcrop = find_program("pdfcrop"),
ghostcript = tools::find_gs_cmd()
)
missing <- tools[tools == ""]
if (length(missing) == 0) return(TRUE)
x <- paste0(names(missing), collapse = ", ")
warning(
sprintf("\nTool(s) not installed or not in PATH: %s", x),
"\n-> As a result, figure cropping will be disabled."
)
FALSE
}

# given a string, escape the regex metacharacters it contains:
# regex metas are these,
# . \ | ( ) [ { ^ $ * + ?
Expand Down