[R] Sweave (R?) font encoding problems

Luís Torgo ltorgo at liacc.up.pt
Mon Oct 31 16:46:24 CET 2005


Dear R list,

I'm having some problems with font encodings when using R+Sweave+Latex in my 
native language: Portuguese.

My environment:
Kubuntu 5.10 Linux
$> uname -a
Linux nassa 2.6.12-9-686 #1 Mon Oct 10 13:25:32 BST 2005 i686 GNU/Linux

R> R.version
         _                
platform i486-pc-linux-gnu
arch     i486             
os       linux-gnu        
system   i486, linux-gnu  
status                    
major    2                
minor    1.1              
year     2005             
month    06               
day      20               
language R  
R> Sys.getlocale()
[1] 
"LC_CTYPE=pt_PT.utf-8;LC_NUMERIC=C;LC_TIME=pt_PT.utf-8;LC_COLLATE=pt_PT.utf-8;LC_MONETARY=pt_PT.utf-8;LC_MESSAGES=pt_PT.utf-8;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
R> localeToCharset()
[1] "ISO8859-1"


Here is a small example trying to replicate my problems:

File:exp.Rnw
================================
\documentclass[10pt,twoside]{article}
\usepackage[dvips]{graphicx}
\usepackage[portuges]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\section{Introdução}

Isto é uma experiência.

\begin{figure}[b]
\centering
<<echo=false,fig=true,width=10,height=10>>=
barras(1)
@
\caption{Distribuição dos valores percentuais.}
\label{fig:idade}
\end{figure}

\end{document}
=================================

The problem occurs when I Sweave this file using the command:
R> Sweave('exp.Rnw')

The generated exp.tex file gets these contents:
=================================
\documentclass[10pt,twoside]{article}
\usepackage[dvips]{graphicx}
\usepackage[portuges]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{/usr/lib/R/share/texmf/Sweave}
\begin{document}

\section{IntroduÃ§Ã£o}

Isto Ã© uma experiÃªncia.

\begin{figure}[b]
\centering
\includegraphics{exp-001}
\caption{DistribuiÃ§Ã£o dos valores percentuais.}
\label{fig:idade}
\end{figure}

\end{document}
=================================

All Portuguese  characters were "spoiled".  So apparently the Sweave function 
is "translating" my original font encoding

I suspect that this is a problem related to the recent internationalization 
changes in R, as this same file/process was previously (around a year ago I 
think) working correctly for me.

I've read several documentation on these internationalization issues in R and 
browsed the mailing list. As a result, because initially I didn't have R 
working with the pt_PT.utf-8 locale, I've installed the PT language support 
package for my OS, expecting that this would solve the "problem".  Apparently 
I'm missing something else, so I wonder if someone could give me a hint on 
how to solve this.

Thanks,
Luis Torgo

-- 
Luis Torgo
    FEP/LIACC, University of Porto   Phone : (+351) 22 339 20 93
    Machine Learning Group           Fax   : (+351) 22 339 20 99
    R. de Ceuta, 118, 6o             email : ltorgo at liacc.up.pt
    4050-190 PORTO - PORTUGAL        WWW   : http://www.liacc.up.pt/~ltorgo




More information about the R-help mailing list