Next: 2.3 Exercises Up: 2. SESSION TWO Previous: 2.1.3 More exercises Contents Index

# 2.2 Plotting text strings

In many situations we need to annotate plots or maps with text strings; in GMT this is done using pstext. Apart from the common switches, there are 7 options that are particularly useful (Table 2.4).

Table 2.4: Some of the most frequently used options in pstext.

Option | Purpose
-C dx/dy | Spacing between text and the text box (see -W)
-D dx/dy | Offsets the projected location of the strings
-G fill | Sets the color of the text
-L | Lists the font ids and exits
-N | Deactivates clipping at the borders
-S pen | Selects outline font and sets pen attributes
-W[fill][o[pen]] | Paint the text box; draw the outline if o is appended (also see -C)

Figure 2.1: Relationship between the text box and the extra clearance.

The input data to pstext is expected to contain the following information:

x y size angle fontno justify text

The size argument is the font size in points, the angle is the angle (measured counterclockwise) between the text's baseline and the horizontal, justify indicates which point on the text-string should correspond to the given x, y location, and text is the text string or sentence to plot. Figure 2.2 illustrates these concepts and shows the relevant two-character codes used for justification.

Figure 2.2: Justification (and corresponding character codes) for text strings.

The text string can be one or several words and may include octal codes for special characters and escape-sequences used to select subscripts or symbol fonts. The escape sequences that are recognized by GMT are given in Tables 2.5 and 2.6.

Table: GMT text escape sequences.

Code | Effect
@~ | Turns symbol font on or off
@+ | Turns superscript on or off
@- | Turns subscript on or off
@# | Turns small caps on or off
@_ | Turns underline on or off
@%fontno% | Switches to another font; @%% resets to previous font
@:size: | Switches to another font size; @:: resets to previous size
@;color; | Switches to another font color; @;; resets to previous color
@! | Creates one composite character of the next two characters
@@ | Prints the @ sign itself

Note that these escape sequences (as well as octal codes) can be used anywhere in GMT including in arguments to the -B option. A chart of octal codes can be found in Appendix F in the GMT technical reference book. For accented European characters you must set CHAR_ENCODING to ISOLatin1 in your .gmtdefaults4 file.

We will demonstrate pstext with the following script:

    cat << EOF | pstext -R0/7/0/5 -Jx1i -P -B1g1 -GDarkOrange | ghostview -
    1  1  30  0  4  BL It's P@al, not Pal!
    1  2  30  0  4  BL Try @%33%ZapfChancery@%% today
    1  3  30  0  4  BL @~D@~g@-b@- = 2@~pr@~G@~D@~h.
    1  4  30  0  4  BL University of Hawaii at M@!a\225noa
    EOF

Here we have used the ``here document'' notation in UNIX: The EOF will treat the following lines as the input file until it detects the word EOF. We pipe the PostScript directly through ghostview (the - tells ghostview that piping is happening).

Table 2.6: Shortcuts for some European characters.

Code | Effect | Code | Effect
@E | Æ | @e | æ
@O | Ø | @o | ø
@A | Å | @a | å
@C | Ç | @c | ç
@N | Ñ | @n | ñ
@U | Ü | @u | ü
@s | ß |  |

Next: 2.3 Exercises Up: 2. SESSION TWO Previous: 2.1.3 More exercises Contents Index