Accents in paragraphs work perfectly. Text in figures is correct in the plot viewer, but once I compile the pdf the accents disappear from the figures.
Here's an example that reproduces the issue.
---
title: 'Some title'
author: 'This be me'
date: '`r format(Sys.Date(), "%B %Y")`'
lang: es
header-includes:
- \usepackage{tikz}
output:
pdf_document:
fig_caption: yes
---
```{r global options, echo = F, message=F}
library(knitr)
opts_chunk$set(fig.width=6, fig.height=3.5, dev = 'tikz')
```
I have some paragraphs that include cool accents like áspid.
If I run the next chunk in the R console I see the accent on the figure it generated. But the accent is missing in the pdf.
```{r}
plot(pressure, main= "áspid")
```
This looks like a bug in the R
tikzDevicepackage. It generates a.tikzfile using the UTF-8 encoding, but doesn't include something likein it to declare the encoding. There are a number of references in its documentation to the "Unicode" section of the
?tikzDevicehelp topic, but there is no such section. You might want to report an issue on the Github page for the package, https://github.com/yihui/tikzDevice.Edited to add:
After some experimentation, I can't see a way to add that line to the
.tikzfile, but requestingxelatexinstead of the default LaTeX engine does seem to work. You can do that by adding the R codeinto your early code chunk. That will use
xelatexfor the figures,pdflatexfor the rest. ("xetex"is not a typo; that's how you requestxelatex.)If you want, you can switch to
xelatexfor the rest usinglatex_engine: xelatexin the YAML header, but the figures will still usepdflatexunless you also add the option setting.