Problem
VerbatimOut
from the “fancyvrb” package doesn’t play nicely with UTF-8 characters.
Minimal working example:
\documentclass{minimal}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\begin{document}
\begin{VerbatimOut}{\jobname.test}
é
\end{VerbatimOut}
\input{\jobname.test}
\end{document}
Error message
When compiled using pdflatex mini
, this gives the error
File ended while scanning use of
\UTFviii@three@octets
.
A different error occurs when the sole occurrence of é
above is replaced by something else, e.g. é */
:
Package inputenc Error: Unicode char
\u8:###
not set up for use with LaTeX.
– indicating that in this case, LaTeX succeeds in reading a multi-byte UTF-8 character, but not knowing what to do with it (i.e. it’s the wrong character).
In fact, when I open the produced .test
file manually, it contains the character é
, but in Latin-1 encoding!
Proof: when I open the files in a hex editor, I get the following:
- Original file:
C3 A9
(corresponds to LATIN SMALL LETTER E WITH ACUTE in UTF-8) - Written file:
E9
(corresponds toé
in Latin-1)
Question
How to set VerbatimOut
up correctly?
filecontents*
(from “filecontents”) shows that it can work. Unfortunately, I don’t understand either code so I cannot fix fancyvrb’s code by replicating the logic from filecontents manually.
I also cannot use filecontents*
instead of VerbatimOut
because the former doesn’t work within a \newenvironment
, while the latter does.
(Oh, by the way: vanilla Verbatim
instead of VerbatimOut
also works as expected. The error seems to occur when writing the file, not when reading the verbatim input)