I am struggling to produce an exam sheet in French using exams2nops
. There are accents in the text provided in the intro
and title
argument of this function and also in the Rnw
files containing the function. The formers are correctly displayed in the resulting PDF, but not the later, for example é
from a Rnw
file is displayed as <U+00E9>
.
The call to exams2nops
looks like this:
exams2nops(file=myexam, n = N.students, dir = '.',
name = paste0('exam-', exam.date),
title = "Examen écrit",
course = course.id,
institution = "",
logo = paste(exams.dir, 'input/logo.jpg', sep='/'),
date = exam.date,
replacement = TRUE,
intro = intro,
blank=round(length(myexam)/4),
duplex = TRUE, pages = NULL,
usepackage = NULL,
language = "fr",
encoding = "UTF-8",
startid = 1,
points = c(1), showpoints = TRUE,
samepage = TRUE,
twocolumn = FALSE,
reglength = 9,
header=NULL)
Note that "Examen écrit" is correctly displayed in the final PDF, the problem is with the accent in the Rnw files. The function call yields no error.
The *.tex
files by generated by exams2nops
, already have the problem. For example, the sentense 'Quarante patients ont été inscrits' in the original Rnw
file, becomes 'Quarante patients ont <U+00E9>t<U+00E9> inscrits' in the tex
file.
I use exams_2.4-0
with R 4.2.2
with TeXShop 4.70
on OSX 11.6
.
I checked that Rnw
are utf-8 encoded, for example:
$ file -I question1.Rnw
question1.Rnw: text/x-tex; charset=utf-8
It seems they are utf-8
-encoded, indeed. These files were translated with deepl or google translate, then edited in emacs.
I tried setting the encoding
parameter of exams2nops
to latin-1
. It did not help.
Any Idea?
The problem disapeared after setting R 'locales' properly. A recurrent problem with OSX R installs. The symptome is:
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_MONETARY failed, using "C"
at start up. This thread explains how to fix it: Installing R on Mac - Warning messages: Setting LC_CTYPE failed, using "C".