4

Some hack here.

In ?RweaveLatex manual, I found only paragraph about encoding in UTF-8 but considering Windows users:

 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.

Currently running ubuntu, how can I make the SweaveInput aware of the UTF-8 encoding?

lockstep
  • 250,273
hhh
  • 8,743

1 Answers1

7

I have had the same problem when working with Russian input in Sweave. After some experimentation I understood that you need to pass the encoding to Sweave and Stangle before they start processing the file. When they read \usepackage, it is too late.

The following entries in my Makefile work for me

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

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

You need to change koi8-r for utf8. Also, if you do not use Makefiles, the following shell lines should work

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

By the way, it seems that older versions of R did not have this problem; I started to get them starting from 2.14.10. Before this version they've happily read the encoding from \usepackage[...]{inputenc}...

Boris
  • 38,129