utf8在使用knitr的情节标签中

Roa*_*oah 5 plot r knitr

无法使用knitr将以下Rnw文档编译成pdf

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<>>=
hist(rnorm(100),main="???????????")
@

\end{document}
Run Code Online (Sandbox Code Playgroud)

有了英文标签,一切都还可以.


编辑1:现在我有两个版本的pdf.在第一个字母被点替换.

第二个中,所有字母都重叠.第二个是使用addtional code chunk生成的

<<>>=
pdf.options(encoding = "CP1251")
@
Run Code Online (Sandbox Code Playgroud)

我使用的是Ubuntu 12.04 + R 2.14 + Texlive.


编辑2:

目前我发现了以下部分解决方案:

<<>>=
cairo_pdf("figure.pdf")
hist(rnorm(100),main="???????????")
dev.off()
@
\includegraphics{figure.pdf}
Run Code Online (Sandbox Code Playgroud)

编辑3:

使用以下代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<dev='cairo_pdf'>>=
hist(rnorm(100),main="???????????")
@

\end{document}
Run Code Online (Sandbox Code Playgroud)

我获得了一个CORRECT直方图,有很多警告.如何避免或至少抑制它们?


最后!乌拉!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\begin{document}

<<dev='cairo_pdf',warning=FALSE>>=
hist(rnorm(100),main="???????????")
@

\end{document}
Run Code Online (Sandbox Code Playgroud)

我可以避免警告吗?有人可以用编码和警告向我解释所有这些东西吗?

Yih*_*Xie 4

您可能需要设置pdf.options(encoding = 'your_encoding');请参阅https://github.com/yihui/knitr/issues/172我不完全确定这里的编码到底应该是什么。