# Gnuplot output encoding

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?

• If you want to set encoding iso_8859_1 in the gnuplot file, you must also save it as Latin-1; the output "EÃ±e" is a clear indication of a two byte UTF-8 character interpreted as Latin-1. Why don't you switch to UTF-8 in all cases? – egreg Sep 21 '13 at 22:59
• Setting the encoding with set enconding iso_8859_1 and saving the script as Latin-1 worked. Why I don't switch to UTF-8 in all cases? I don't know, maybe historical reasons, maybe in the future I'll ask myself the same question and change. Thank you very much – Nico Sep 21 '13 at 23:14

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.

• I think that I use latin1 because of Windows defaults (with Argentina settings). I'll have in mind what you said and I'll give it a try to utf8. For future reference, I changed the encoding in vim with set encoding latin1 or set encoding fileencoding latin1 – Nico Sep 22 '13 at 0:02