Skip to content

Warn that cropping is disabled if pdfcrop or ghostscript are not found.#2017

Merged
yihui merged 4 commits intomasterfrom
warn-pdf-crop
Jan 21, 2021
Merged

Warn that cropping is disabled if pdfcrop or ghostscript are not found.#2017
yihui merged 4 commits intomasterfrom
warn-pdf-crop

Conversation

@cderv
Copy link
Collaborator

@cderv cderv commented Jan 21, 2021

here is a proposal to do that on rmarkdown side.

It is oriented specifically toward cropping tools for which we want the warning. I had the idea to make it more generic but we don't need it for now so I stop myself from doing it.

Other solutions could be by adapting find_program() so that it warns, or using (exporting ?) knitr:::has_utility() but the logic is not exactly the same as find_program() (which deals with OSX a specific way). Opportunity to refactor ?

Anyway, here is a PR to have you thoughts before merging.

@cderv cderv linked an issue Jan 21, 2021 that may be closed by this pull request
3 tasks
@cderv cderv requested a review from yihui January 21, 2021 20:45
Copy link
Contributor

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good enough to me. Thanks!

I'm not sure if the peculiarity of which on macOS is still there. Someday we might be able to get rid of the hack

rmarkdown/R/util.R

Lines 293 to 309 in dbc4a68

# Find a program within the PATH. On OSX we need to explictly call
# /usr/bin/which with a forwarded PATH since OSX Yosemite strips
# the PATH from the environment of child processes
find_program <- function(program) {
if (is_osx()) {
res <- suppressWarnings({
# Quote the path (so it can contain spaces, etc.) and escape any quotes
# and escapes in the path itself
sanitized_path <- gsub("\\", "\\\\", Sys.getenv("PATH"), fixed = TRUE)
sanitized_path <- gsub("\"", "\\\"", sanitized_path, fixed = TRUE)
system(paste0("PATH=\"", sanitized_path, "\" /usr/bin/which ", program),
intern = TRUE)
})
if (length(res) == 0)
""
else
res

I've been using Sys.which() myself and haven't run into this problem. My guess is that we originally had this hack mainly because of the nonstandard path of MacTeX (which is something like /usr/texbin). TinyTeX's binaries are symlinked to the standard /usr/local/bin so it won't suffer from this problem.

@yihui yihui merged commit 5c3e3f5 into master Jan 21, 2021
@yihui yihui deleted the warn-pdf-crop branch January 21, 2021 21:33
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Jan 25, 2021
Merge branch 'master' of https://github.com/rstudio/rmarkdown

* 'master' of https://github.com/rstudio/rmarkdown: (111 commits)
  get rid of names, otherwise the returned vector will have names like this:
  Only run testrmd if pandoc is available
  Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017)
  Add shiny to remotes (rstudio#2014)
  file.path.ci is too loose with file matching (rstudio#2012)
  improve error messages for the new theme argument behavior
  Add Bootstrap 4 support (rstudio#1706)
  amend rstudio#1965: 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
  htmltools 0.5.1 is on CRAN now
  remove download stats
  use on.exit to remove file (rstudio#2001)
  use only the TinyTeX-1 version in CI (rstudio#1998)
  Cache should work on Windows with recent version of R (rstudio#1997)
  exclude renv folder from render_site() copied resources (rstudio#1996)
  Update CI to last Pandoc 2.11.3.1 (rstudio#1992)
  Revert "return div not nil for non-qualifying latex div"
  Add missing NEWS item for v2.6 release
  return div not nil for non-qualifying latex div
  Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989)
  Improvements to latex-div (rstudio#1984)
  ...

# Conflicts:
#	NEWS.md
#	R/render.R
#	man/render.Rd
jonathan-g added a commit to jonathan-g/rmarkdown that referenced this pull request Jan 25, 2021
* master: (111 commits)
  get rid of names, otherwise the returned vector will have names like this:
  Only run testrmd if pandoc is available
  Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017)
  Add shiny to remotes (rstudio#2014)
  file.path.ci is too loose with file matching (rstudio#2012)
  improve error messages for the new theme argument behavior
  Add Bootstrap 4 support (rstudio#1706)
  amend rstudio#1965: 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
  htmltools 0.5.1 is on CRAN now
  remove download stats
  use on.exit to remove file (rstudio#2001)
  use only the TinyTeX-1 version in CI (rstudio#1998)
  Cache should work on Windows with recent version of R (rstudio#1997)
  exclude renv folder from render_site() copied resources (rstudio#1996)
  Update CI to last Pandoc 2.11.3.1 (rstudio#1992)
  Revert "return div not nil for non-qualifying latex div"
  Add missing NEWS item for v2.6 release
  return div not nil for non-qualifying latex div
  Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989)
  Improvements to latex-div (rstudio#1984)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No warning when Ghostsript cannot be find and fig_crop = TRUE

2 participants