[Tex/LaTex] Gnuplot output encoding

epslatexgnuplotinput-encodings

I have this gnuplot script and works fine:

set term png
set output 'test.png'

plot sin(x) ti "Eñe"

Note de 'ñ' in the label. This produces an image and you can read the 'ñ'.
Now I try to change the term to epslatex:

set term epslatex color
set output 'test.tex'

plot sin(x) ti "Eñe"

Run gnuplot, and it generates test.tex and test.eps. Then I have a master file:

% master.tex
\documentclass{report}
\usepackage[spanish]{babel}
\usepackage[latin1]{inputenc}

\begin{document}
\input{test.tex}
\end{document}

When I compile master.tex (either with texmaker or from console with pdflatex) I get an error. If I open test.tex with texmaker, instead of 'eñe' I have 'Eñe'. But if I open it with gvim, I have 'ñ'. When I fix it from textmaker, everything works just fine.

There is a workaround that I don't want to use:
In the gnuplot script, instead of 'eñe' I can write 'e\\~ne'. That works, but I really don't want to do it that way.

I've tried using set encoding to utf8 and iso_8859_1 in the gnuplot script with no luck.

Any ideas?

Best Answer

If you want to do

set encoding iso_8859_1

in the Gnuplot file, you must ensure it is Latin-1 encoded to begin with. I made my test with Emacs, adding the line

# -*- coding: latin-1 -*-

at the start, which is the incantation for setting the desired file encoding. Other editors have their own methods.


I recommend you to switch to UTF-8 for the LaTeX files. The [utf8] option to inputenc has proved very robust and it's possible to extend the known characters (inputenc doesn't load a definition for each Unicode character, as it would mean defining scores of useless fonts) with \DeclareUnicodeCharacter commands or with the newunicodechar package, in case of need.