knitr在用pdf编译时失去了突出的字符

时间:2013-06-13 10:32:07

标签: r utf-8 character-encoding knitr

我读了关于编织和编码的“所有”要求,但我找不到解决方案......我的问题似乎很简单: 这是我的Try.Rnw文件:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\section{Essai de données}   
<<>>=
a <- "éssaié"
print(a)
@
\end{document}

以UTF-8保存。当我在Rstudio中编译它或直接在R中编译

knit2pdf("Try.Rnw", encoding = "UTF-8")

我得到这个pdf:

1 Essai de donnes
a <- "ssai"
print(a)

所有突出的字符都会丢失。 如果我将它保存在LATIN1中也是如此。

非常感谢

马克

> sessionInfo()
R version 3.0.1 Patched (2013-06-10 r62935)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.1



Information sur le package ‘knitr’

Description :

Package:            knitr
Type:               Package
Title:              A general-purpose package for dynamic report generation in R
Version:            1.2
Date:               2013-04-10

Rstudio

> versionInfo()
$version
[1] ‘0.98.156’

$mode
[1] "desktop"

1 个答案:

答案 0 :(得分:2)

问题可能来自三个可能的来源:knitr,编码或LaTeX。要从knitr诊断问题,您需要拨打knit()而不是knit2pdf()来查看tex输出是否正确:

library(knitr)
knit("Try.Rnw", encoding = "UTF-8")
# open Try.tex and see if the accentuated characters are there

要确保编码真的是UTF-8,请检查菜单File --> Save with Encoding