Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly check ghostscript for cropping on Windows #2246

Closed
cderv opened this issue Mar 22, 2023 · 7 comments
Closed

Correctly check ghostscript for cropping on Windows #2246

cderv opened this issue Mar 22, 2023 · 7 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Mar 22, 2023

Follows discussions in rstudio/tinytex#391

We need to make knitr::plot_crop() conditional on windows to use the ghotscript internal to TeX Live. The internal ghostscript is not found by our detection because it is not expose in path (which is on purpose by Tex Live)

https://github.com/yihui/knitr/blame/1239f36c5dee8b0e029958a793ae71558902f52c/R/plot.R#L374

This is an adaptation of previous fix #954

But we may also need to reconsider in rmarkdown as we also check for ghostcript using tools::find_gs_cmd()
https://github.com/rstudio/rmarkdown/blob/0e794e35717c3be9637e2b0468bb97010d84b527/R/util.R#L318-L331

My understand is that

  • On windows we can expect (or check in Tex Live directory) that the internal ghostscript will be used - so no need to have it.
  • Otherwise we still need an external program

However, the use of internal ghostcript is conditional to Tex Live version as from rstudio/tinytex#391 this is not working and an external program should be used.

Maybe using grepl("TeX Live 2023", tinytex::tlmgr_version(FALSE)) ?

@remlapmot
Copy link

If helpful, I'm happy to help test proposed changes.

@remlapmot
Copy link

And here is where the existing cropping logic is included in the Quarto CLI:

https://github.com/quarto-dev/quarto-cli/blob/2246187f1aa0c4bee2b68c677b8efa55a0f8c779/src/resources/rmd/execute.R#L272

@cderv
Copy link
Collaborator Author

cderv commented Mar 23, 2023

Oh thanks, they indeed do not use an exported or internal function from knitr ... too bad... 😞

@yihui yihui closed this as completed in 4953bec Apr 21, 2023
@yihui
Copy link
Owner

yihui commented Apr 21, 2023

I've implemented the logic in knitr:::has_crop_tools() in 4953bec. I hope I understood it correctly. If it was correct, we'll need to replace the internal function has_crop_tools() in rmarkdown with this one, and Quarto should use it, too.

Thanks!

@cderv
Copy link
Collaborator Author

cderv commented Apr 21, 2023

Looks good !

If helpful, I'm happy to help test proposed changes.

@remlapmot can you test it to confirm ?

@remlapmot
Copy link

Thanks indeed @yihui. This is now working well for me.

Sorry that I have been slow to reply @cderv, I am a lecturer and I was teaching and then marking.

I have checked this by uninstalling my external Ghostscript, and under the development version of knitr (1.42.10) on Windows, using TinyTeX (tlmgr 66798, TeX Live 2023). My test Rmd file was the following.

---
output: pdf_document
---

```{r include=FALSE}
if (!tinytex::check_installed('pdfcrop')) tinytex::tlmgr_install("pdfcrop")
knitr::knit_hooks$set(crop = knitr::hook_pdfcrop)
```

```{r, crop=TRUE}
plot(1:10)
```

```{r, crop=NULL}
plot(1:10)
```

Which produced the following pdf as expected (i.e., with the first figure cropped and the second figure uncropped).

2023-05-18 23_24_35-test-windows-rmd-fix pdf - SumatraPDF

Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants