Below is my experimental RMarkdown document (named tikz-cyrillic.Rmd):
---
title: "TikZ cyrillic test"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
dev: tikz
html_document: default
word_document: default
---
```{r,engine='tikz', fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg'}
\begin{tikzpicture}
\path (0,0) node
(x) {Hello World!}
(3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
\draw[->,blue]
(x) -- (y);
\draw[->,red]
(x) -| node[near start,below] {мир!} (y);
\draw[->,orange] (x) .. controls +(up:1cm) and +(left:1cm) .. node[above,sloped] {Привет} (y);
\end{tikzpicture}
```
It is based on example from 17.11 of pgfmanual.pdf.
Gummi using TeXLive with XeTeX with simple preamble
\usepackage[main=russian,english]{babel}
\usepackage{fontspec}
\setmainfont[Ligatures={TeX,Historic}]{Times New Roman}
gives me the following output:
You can test it in OverLeaf.
But in RStudio I can't understand where should I enter preamble for TikZ device, so I have wrong output (HTML as example):
What should I change in RMarkdown document to get correct output in TikZ diagram?
I need the same image appearance for HTML, PDF and Word document (docx).
Note: I'm using Gummi and RStudio 1.1.456 on Ubuntu 16.04 LTS with TeXLive 2015 if it matters.