Knitr and R markdown doc with diacritics

2019-07-23 18:58发布

问题:

Has someone experience with R packages Knitr and markdown and working with diacritics? Is it possible to write in another language and still have the output in pdf?

The knitr Html converter knit2html won't let me to convert the R markdown document and consequently convert it into pdf with pandoc.

回答1:

I had no problem with the following file:

Test rmd with diacritical marks
=============

Hello: Dvořak, müsli, éèô


```{r}
exp(pi)
```

From the command line:

Rscript -e "library('knitr'); knit('tmp.rmd')"
pandoc -o tmp.pdf tmp.md

The key point may be that you need to knit (to convert rmd to md), then run pandoc: don't try to convert to HTML and thence to PDF ...



回答2:

So this is just a follow up on Ben answer:

All is needed basically is to save the R markdown editor with encoding. By changing the default saving from ISO-8859-1 to UTF-8.

The rest is as Ben described, so from rmd > md > pdf.



回答3:

Markdown is the simplest of the input languages for knitr and while it is great for basic things it quickly falls short when you want to go beyond the basics. It is probably better to use a template based on LaTeX if you want to use the diacritics or other more advanced features.