Is it possible to include an SVG image in a pdf provided by rmarkdown?

I want the svg image to be embedded in the PDF document that I rendered with rmarkdown. Does this not seem possible, or am I missing something? If this is not possible, is there a way to convert the .svg image to .png first before embedding it?

In my rmarkdown file, it looks like this (note the two different types of image insertion):

```{r results="asis",eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA,fig.height=10}

cat("![](svg_file.svg)")

```

![](svg_file.svg)
+4
source share
1 answer

I found a solution that works for me. It is based on using the svgLaTeX package and some LaTeX code inside your Rmarkdown file.

:

  • svg LaTeX. Rmarkdown.
  • , LaTeX --shell-escape. , Rmarkdown.
  • SVG \includesvg{svg-image} Rmarkdown. , .

pdflatex LaTeX. , , , ...

, SVG- svg-image.svg .

---
output: 
  pdf_document:
    latex_engine: pdflatex
    pandoc_args: "--latex-engine-opt=--shell-escape"
header-includes:
   - \usepackage{svg}
---

\includesvg{svg-image}

, !

0

Source: https://habr.com/ru/post/1618413/


All Articles