rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 978 forks source link

Activate graphics for Pandoc also for custom template when `md` source contains only LaTeX figures. #2387

Open cderv opened 2 years ago

cderv commented 2 years ago

Related to https://github.com/rstudio/bookdown/issues/1350#issuecomment-1163595061

\includegraphics in LaTeX requires the graphics package, which Pandoc only adds after a variable graphics https://github.com/jgm/pandoc/blob/e0dea96d6c1e7d6f19040cafd9ffde432de330d8/data/templates/default.latex#L258-L259

I think Pandoc activate the variable if images are detected in the document (Img in AST ?) but if the figure in the markdown file is inserting using LaTeX directly (which knitr can do), and not markdown syntax then Pandoc won't activate the variable probably.

In rmarkdown we do activate by default when the default template is used https://github.com/rstudio/rmarkdown/blob/7eb75a81c7e8ea124b224842c63c19fcaddb8802/R/pdf_document.R#L148-L149

Maybe we could detect a LaTeX figure and activate it also in a non default template so that it does not suprise user ? https://github.com/rstudio/bookdown/issues/1350#issuecomment-1163413321

Just noting the idea here. Need to see what it means to do that

yihui commented 2 years ago

I'm okay with always activating it, regardless of the template.