【发布时间】:2018-06-24 16:52:21
【问题描述】:
我使用 Window10 64、R Studio 版本 1.1.383 和 MiKTeX 2.9。 我尝试使用 rmarkdown 使用函数从 html 文本打印 PDF。
# function html -> pdf
write_pdfx <- function(x){
for(i in 1:nrow(x)) {
message(sprintf("Processing %s", x$id[i]))
tf <- tempfile(fileext=".html")
writeLines(x$content[i], tf, useBytes = FALSE)
pandoc_convert(
input = tf,
to = "latex",
output = sprintf("%s.pdf",x$id[i]),
wd = getwd()
)
unlink(tf)
}}
df 包含两列:id 带有 id 和 content 带有 html 文本。编码为 UTF-8
Encoding(df$content) <- "UTF-8"
不幸的是,html 文本包含很多特殊字符。其中大部分(如“ü”或“ä”不会造成任何问题)。但是,有些像“ẗ”会导致错误:
pandoc.exe: Cannot decode byte '\xfc': Data.Text.Internal.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
Error: pandoc document conversion failed with error 1
如果我设置useBytes = TRUE我会得到另一个错误:
! Package inputenc Error: Unicode char ẗ (U+1E97)
(inputenc) not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
...
l.212 ...sene Vergleich, wonach ersterer gestüẗ
Try running pandoc with --latex-engine=xelatex.
pandoc.exe: Error producing PDF
我也试过xelatex,但没有成功。
Package inputenc Error & Error: pandoc document conversion failed with error 43 没有解决问题。
我也找到了这个信息,但是,我无法实现它: How to write Unicode string to text file in R Windows? Hebrew Encoding Hell in R and writing a UTF-8 table in Windows https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16064
在我的情况下,有什么方法可以在 Windows 上使用 writeLines() 编写 UTF-8?
【问题讨论】:
标签: r utf-8 latex r-markdown pdflatex