Knitr compiling a document with Chinese

I am trying to compile a YiHui BIG5 example (knitr with Chinese content). I used a Mac OSX snow blower, the latest RStudio, pdfLatex (same result with XeLatex). This is an excerpt from raw.Rnw

\begin{document}
\title{knitr與繁體中文文檔}
\author{謝益輝}

測試,咳咳。以下代碼靠譜嗎?

<<test>>=
1+1 # 太簡單了
'引號能用嗎?'
rnorm(5)
(function(){
paste('這裡是字符串')
})()
@

Using the standard encoding system "UTF-8", the resulting pdf file

1+1 #
## [1] 2
''
## [1] ""
rnorm(5)
## [1] -0.4290 1.8835 -0.7045 -0.9232 1.5433
(function(){ paste('') })()
## [1] ""

since you can see that the Chinese are just an empty place. Then I saved .Rnw with BIG5 encoding and compile again. The resulting pdf file will look like this:

AyyCHUNXaH
1+1 # F
## [1] 2
'H'
## [1] "H"
rnorm(5)
## [1] -0.27859 -0.79428 -0.76903 0.40313 -0.07851
(function(){ paste('oOr') })()
## [1] "oOr"

This time, the Chinese become random letters.

What else can I do? Totally new to wrt Coding / national_version.

+4
source share
2

XeLaTeX, , , , , , . xeCJK.

+3

, .

Sys.setlocale(category="LC_ALL",locale="en_US.UTF-8") 

, , , R. . , MAC. , .

0

All Articles