Enhanced text mode

Many terminal types support an enhanced text mode in which additional formatting information is embedded in the text string. For example, "x^2" will write x-squared as we are used to seeing it, with a superscript 2. This mode is selected by default when you set the terminal, but may be toggled afterward using "set termoption [no]enhanced", or by marking individual strings as in "set label 'x_2' noenhanced".
Enhanced Text Control Codes
Control Example Result Explanation
^ a^x ax superscript
_ a_x ax subscript
@ a@^b_{cd} abcd phantom box (occupies no width)
& d&{space}b db inserts space of specified length
~ ~a{.8-} [IMAGE svg] overprints '-' on 'a', raised by .8
times the current fontsize
{/Times abc} abc print abc in font Times at current size
{/Times*2 abc} abc print abc in font Times at twice current size
{/Times:Italic abc} abc print abc in font Times with style italic
{/Arial:Bold=20 abc} abc print abc in boldface Arial font size 20
\U+ \U+221E Unicode point U+221E INFINITY

The markup control characters act on the following single character or bracketed clause. The bracketed clause may contain a string of characters with no additional markup, e.g. 2^{10}, or it may contain additional markup that changes font properties. Font specifiers MUST be preceded by a '/' character that immediately follows the opening '{'. If a font name contains spaces it must be enclosed in single or double quotes.

Examples: The first example illustrates nesting one bracketed clause inside another to produce a boldface A with an italic subscript i, all in the current font. If the clause introduced by :Normal were omitted the subscript would be both italic and boldface. The second example illustrates the same markup applied to font "Times New Roman" at 20 point size.

{/:Bold A_{/:Normal{/:Italic i}}}
{/"Times New Roman":Bold=20 A_{/:Normal{/:Italic i}}}

The phantom box is useful for a@^b_c to align superscripts and subscripts but does not work well for overwriting an accent on a letter. For the latter, it is much better to use an encoding (e.g. iso_8859_1 or utf8) that contains a large variety of letters with accents or other diacritical marks. See set encoding. Since the box is non-spacing, it is sensible to put the shorter of the subscript or superscript in the box (that is, after the @).

Space equal in length to a string can be inserted using the '&' character. Thus

'abc&{def}ghi'
would produce
'abc   ghi'.

The '˜ ' character causes the next character or bracketed text to be overprinted by the following character or bracketed text. The second text will be horizontally centered on the first. Thus '˜ a/' will result in an 'a' with a slash through it. You can also shift the second text vertically by preceding the second text with a number, which will define the fraction of the current fontsize by which the text will be raised or lowered. In this case the number and text must be enclosed in brackets because more than one character is necessary. If the overprinted text begins with a number, put a space between the vertical offset and the text ('˜ {abc}{.5 000}'); otherwise no space is needed ('˜ {abc}{.5 — }'). You can change the font for one or both strings ('˜ a{.5 /*.2 o}' — an 'a' with a one-fifth-size 'o' on top — and the space between the number and the slash is necessary), but you can't change it after the beginning of the string. Neither can you use any other special syntax within either string. You can, of course, use control characters by escaping them (see below), such as '˜ a{ \^}'

You can escape control characters using \, e.g., \ \, \{, and so on. See escape sequences below.

Note that strings in double-quotes are parsed differently than those enclosed in single-quotes. The major difference is that backslashes may need to be doubled when in double-quoted strings.

The file "ps_guide.ps" in the /docs/psdoc subdirectory of the gnuplot source distribution contains more examples of the enhanced syntax, as does the demo enhanced_utf8.dem

Escape sequences

The backslash character \ is used to escape single byte character codes or Unicode entry points.

The form \ooo (where ooo is a 3 character octal value) can be used to index a known character code in a specific font encoding. For example the Adobe Symbol font uses a custom encoding in which octal 245 represents the infinity symbol. You could embed this in an enhanced text string by giving the font name and the character code "{/Symbol \245}". This is mostly useful for the PostScript terminal, which cannot easily handle UTF-8 encoding.

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.

Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
Distributed under the gnuplot license (rights to distribute modified versions are withheld).