Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
\usepackage[utf8]{inputenc} doesn't work for you? I've used this on Windows and Linux and it worked both times. I must wonder, though, what is your real problem with encoding (image text not using localized characters?)? –  Roman Luštrik Dec 29 '11 at 16:45
    
@RomanLuštrik I have master.Rnw that SweaveInputs small.Rnw, the encoding specified by master.Rnw with \usepackage[utf8]{inputenc} works but not for the part samll.Rnw. Clear now? –  hhh Dec 29 '11 at 16:56
    
Related question: Sweave generating invalid LaTeX. –  Alan Munn Dec 29 '11 at 19:33

1 Answer 1

up vote 6 down vote accepted

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}...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.