\SweaveInput{...} 使用 UTF-8 编码吗?

\SweaveInput{...} 使用 UTF-8 编码吗?

一些黑客这里

在 ?RweaveLatex 手册中,我只找到有关 UTF-8 编码的段落,但考虑到 Windows 用户:

 The use of fancy quotes (see ‘sQuote’) can cause problems when
 setting R output.  Either set ‘options(useFancyQuotes = FALSE)’ or
 arrange that LaTeX is aware of the encoding used (by a
 ‘\usepackage[utf8]{inputenc}’ declaration: Windows users of
 ‘Sweave’ from ‘Rgui.exe’ will need to replace ‘utf8’ by ‘cp1252’
 or similar) and ensure that typewriter fonts containing
 directional quotes are used.

目前正在运行 ubuntu,如何让 SweaveInput 知道 UTF-8 编码?

答案1

我在 Sweave 中处理俄语输入时也遇到了同样的问题。经过一些实验,我明白你需要将编码传递给 Sweave 和 Stangle他们开始处理文件。当他们读到时\usepackage,已经太晚了。

我的 Makefile 中的以下条目对我有用

%.tex:  %.rnw 
    echo "Sweave ('$<', encoding='koi8-r')" | R --slave

%.R: %.rnw
    echo "Stangle ('$<', encoding='koi8-r')" | R --slave    

您需要将 koi8-r 更改为 utf8。此外,如果您不使用 Makefile,以下 shell 行应该有效

echo "Sweave ('myfile.rnw', encoding='utf8')" | R --slave
echo "Stangle ('myfile.rnw', encoding='utf8')" | R --slave

顺便说一句,旧版本的 R 似乎没有这个问题;我从 2.14.10 开始使用它们。在此版本之前,它们很高兴地读取了来自\usepackage[...]{inputenc}... 的编码

相关内容