MarcG
MarcG

Reputation: 103

knitr losts accentuated characters when compiled in pdf

I read "all" demands concerning knitr and encoding but I cannot find solution... My problem seems very simple: Here is my Try.Rnw file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\section{Essai de données}   
<<>>=
a <- "éssaié"
print(a)
@
\end{document}

It is saved in UTF-8. When I compile it in Rstudio or directly in R with

knit2pdf("Try.Rnw", encoding = "UTF-8")

I get this pdf:

1 Essai de donnes
a <- "ssai"
print(a)

All the accentuated characters are lost. Same happened if I save it in LATIN1.

Thanks a lot

Marc

> sessionInfo()
R version 3.0.1 Patched (2013-06-10 r62935)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.1



Information sur le package ‘knitr’

Description :

Package:            knitr
Type:               Package
Title:              A general-purpose package for dynamic report generation in R
Version:            1.2
Date:               2013-04-10

Rstudio

> versionInfo()
$version
[1] ‘0.98.156’

$mode
[1] "desktop"

Upvotes: 1

Views: 202

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30184

The problem may come from three possible sources: knitr, the encoding, or LaTeX. To diagnose the problem comes from knitr, you need to call knit() instead of knit2pdf() to see if the tex output is correct:

library(knitr)
knit("Try.Rnw", encoding = "UTF-8")
# open Try.tex and see if the accentuated characters are there

To make sure the encoding is really UTF-8, check the menu File --> Save with Encoding.

Upvotes: 2

Related Questions