我在Windows上使用Rstudio,在使用Rnw文件中的utf字符时遇到问题:
在Rnw文件上使用knitr时,ut文字\ u20ac(欧元符号)将被\ u0080替换为tex文件。 Rnw文件包含:
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{eurosym}
\DeclareUnicodeCharacter{20AC}{\euro}
\begin{document}
<<print, echo = FALSE>>=
x <- '\U20AC'
Encoding(x)
print(x)
sessionInfo()
@
\end{document}
产生tex文件(仅限最后一行):
\begin{verbatim}
## [1] "UTF-8"
## [1] "<U+0080>"
## R version 3.3.0 (2016-05-03)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
##
## locale:
## [1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252
## [3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
## [5] LC_TIME=Dutch_Netherlands.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.14.1
##
## loaded via a namespace (and not attached):
## [1] magrittr_1.5 formatR_1.4 tools_3.3.0 stringi_1.1.1 stringr_1.1.0
## [6] evaluate_0.9
\end{verbatim}
使用的命令:
knitr('test.Rnw')
乳胶无法处理生成的tex文件:
! Package inputenc Error: Unicode char  (U+80)
(inputenc) not set up for use with LaTeX.
使用sweave而不是knitr工作正常。