Search code examples
character-encodinggnuplot

How to use greek letters, Angstrom symbol and degree symbol in Gnuplot qt terminal


There are a lot of Q&A about this topic, but I have totally confused about the different encodings; if I try to merge the sub-solutions I have found, they conflict to each others.

So, I am using gnuplot version 5.4.4 with qt terminal, and I want to use greek letters (alpha), Angstrom symbol and degree symbol simultaneously. The farest I have reached is:

set encoding iso_8859_1
set xlabel 'T [{\260}C]'
set ylabel 'a_{\225} [\305]'
plot sin(x)

enter image description here

I.e. degree and Angstrom symbols are OK, but alpha is missing. UTF encoding kills everything. IMPORTANT: assume, that I cannot type directly "Å", "α" nor "°"

Thank you for your advice!


Solution

  • Is it possible that the problem is simply that you have chosen a font that doesn't contain greek character glyphs? I would check that first. Note that iso_8859_1 encoding does not provide either α or Å, so I think the combination you are looking for is not possible without either mixing fonts or switching to a different encoding.

    Assuming you have a suitable font, the preferred method really is utf8. In gnuplot version 5.4 you can provide any unicode character as a unicode code point via an escape sequence. Here is the relevant section from the manual and help unicode.

     You can specify a character by its Unicode code point as \U+hhhh, where hhhh
     is the 4 or 5 character hexadecimal code point. For example the code point for
     the infinity symbol is \U+221E.  This will be converted to a UTF-8 byte
     sequence on output if appropriate.  In a UTF-8 environment this mechanism
     is not needed for printable special characters since they are handled in a
     text string like any other character. However it is useful for combining forms
     or supplemental diacritical marks (e.g. an arrow over a letter to represent
     a vector).  See `set encoding`, `utf8`, and the online unicode demo.
    

    So for your example you could use

    set terminal qt font "ArnoPro,20"
    set encoding utf8
    set xlabel 'T [{\U+00B0}C]'
    set ylabel 'a_{\U+03B1} [\U+212B]'
    plot sin(x)
    

    enter image description here

    I realize that you said "utf8 kills everything", but that description is not sufficient to attempt a diagnosis. If the suggested solution does not work, please edit your question to describe exactly what it is that went wrong.