Consider including pdfcrop in TinyTeX
riccardoporreca opened this issue · 4 comments
TL;DR
- It would be great to make
pdfcrop
available as part ofTinyTeX
. - Otherwise, one could advise to use
tinytex::tlmgr_install("pdfcrop")
and make sureghostscript
is availablenot to rely on.pdfcrop
when developing R Markdown PDF reports that could be rendered using a TinyTeX installation, by forcingfig_crop: false
in the YAML header
This is a suggestion to address the following situation.
- R Markdown enables cropping images by default for PDF output documents using
pdfcrop
(if installed). pdfcrop
is a very sensible way of achieving nicely-sized figures generated from R w/o explicitly playing withfig.width
/fig.height
chunk options.pdfcrop
is available (on Linux) as part of the TeX Live installation (intexlive-extra-utils
, requiring an additional ~200MB for the installation1).- TinyTeX is a great asset and a natural choice for a light-weight LaTeX installation, especially in containerized environments (see e.g.
rocker/verse
). However, the lack ofpdfcrop
may cause extra effort and hiccups, especially when developing a PDF report based on a local TeX Live installation (affordable in terms of size), with the figures not being cropped once deployed. Having a mixed TinyTeX +texlive-extra-utils
is of course possible (and better than a full TeX Live installation in terms of total size), but the extra 200MB are a big overkill for just havingpdfcrop
.- Update: TinyTeX is such a great tool: one can install
pdfcrop
viatinytex::tlmgr_install("pdfcrop")
(or directly viatlmgr install
) ! (Requiresghostscript
to work.)
__
docker run --rm rocker/r-ver:3.5.3 sh -c 'apt-get update && apt-get install --no-install-recommends texlive-extra-utils'
=> `After this operation, 233 MB of additional disk space will be used
Thanks for the suggestion! I could include pdfcrop
in the default installation, but as you mentioned, the real tricky thing is how to install Ghostscript on different platforms. It is relatively easy for a specific platform, such as in rocker/verse---you can install any additional packages after the default installation of TinyTeX: https://github.com/rocker-org/rocker-versioned/blob/08ca130eaf2f517452b4d4fa65ac34842eaaafd0/verse/Dockerfile#L50
There are other packages that also require Ghostscript, such as epstopdf
. I have tried to install it on macOS if Homebrew is available: https://github.com/yihui/tinytex/blob/45612516660c187b3e11bfee7d78ce2096ac454c/R/tlmgr.R#L111-L116
In short, having pdfcrop
in the default installation is still a little far away from a complete working solution for cropping PDF figures automatically in R Markdown.
BTW, I don't use Linux now, but I'm surprised that you have to install texlive-extra-utils
in order to obtain Ghostscript. Isn't there a standalone package for Ghostscript? https://packages.ubuntu.com/ghostscript
Thanks a lot @yihui for your reply and the very useful hints / pointers. The more I look into TinyTeX the more I like it!
Indeed, the dependency on Ghostscript is something you probably don't want to handle as part of the default installation. The nice things is that e.g. pdfcrop
itself crashes with a clear message about Ghostscript not being found, so if a user installed pdfcrop
via tlmgr
and try to use it, it would be clear what is missing.
Apologies for the confusion around texlive-extra-utils
, I mentioned it as an alternative for the whole pdfcrop
installation before realizing tlmgr
could be used for this, and should have stroked it out as part of the Update (will do it now to keep things clear).
Would you think of a good place where the manual installation of pdfcrop
on top of TinyTeX could be mentioned / documented (maybe the R Markdown guide)? I think expecting figures to be cropped is pretty standard when using R Markdown with PDF (hence the default img_crop: true
), but with the default TinyTeX install this is silently ignored and can puzzle users. I am basically wondering how to help other users facing or preventing the sort of hiccups I encountered with it. Of course I hope at least this issue can help as a reference.
I will also follow up on your suggestion and propose to add pdfcrop
to rocker/verse in the existing tlmgr install
line.
Yes, we should absolutely document it more clearly in the R Markdown book you mentioned. Please feel free to hit the Edit button at the top and submit a pull request. Thank you!