Programming Gri

1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index

5.9: Text Strings

Any text can be drawn in any size; Gri does not limit font size to a list, e.g. 10 point, 12 points, etc. Several fonts are available in Gri, e.g. Times, Helvetica, etc.; these are all standard PostScript fonts. Support for some non-English languages (e.g. French) is also provided. And, finally, Gri supports inclusion of simple mathematical expressions (Greek letters, superscripts, etc.) in text, using a LaTeX-style syntax.

5.9.1: Embedding synonyms in quoted text strings

Outside math strings, you can embed your synonyms at will. For example, you can include the name of a data file in the title of your plot as follows
query \filename "File to read from?" ("data.file")
open \filename
read columns x y
draw curve
draw title "data from \filename"
Within math strings (ie, between matched dollar-signs), these synonyms are disabled, and only the mathematical symbols and Greek letters work.

5.9.2: Mathematical text

5.9.2.1: Subscripts

As in TeX and LaTeX, you must be in math-mode to use subscripts; in other words, you must enclose the string or substring in dollar-signs. For single-character subscripts, insert an underline prior to the character to be subscripted:
draw title "$a_2$"

For multiple-character subscripts, insert braces before and after the item to be subscripted:
draw title "$a_{22}$"

5.9.2.2: Superscripts

As in TeX and LaTeX, you must be in math-mode to use superscripts; in other words, you must enclose the string or substring in dollar-signs. For single-character superscripts, insert a carat prior to the character to be superscripted:
draw title "$a^2$"

For multiple-character superscripts, insert braces before and after the item to be superscripted:
draw title "$a^{22}$"

5.9.2.3: Mathematical symbols

As in TeX and LaTeX, you indicate mathematical symbols and Greek letters with backslash sequences. The following LaTeX symbols are defined in math mode in Gri (cf tables in Lamport's section 3):

\Delta \Downarrow \Gamma \Im \Lambda \Leftarrow
\Leftrightarrow \Omega \Pi \Phi \Psi \Re
\Rightarrow \Sigma \Theta \Uparrow \Upsilon \Xi
\alpha \approx \ast \beta \bullet \chi \circ
\cong \delta \div \downarrow \epsilon \equiv
\eta \exists \forall \gamma \geq \gg \in \infty
\iota \kappa \lambda \langle \leftarrow
\leftrightarrow \leq \ll \mu \nabla \neq \nu
\omega \partial \phi \pi \pm \prod \propto \psi
\rangle \rho \rightarrow \sigma \sim \subset
\subseteq \sum \supset \supseteq \surd \sqrt
\tau \theta \times \uparrow \upsilon \varpi
\wedge \xi \zeta \vartheta \varsigma \varphi
\aleph \oplus \otimes \wp \prime \emptyset
\angle \neg \clubsuit \diamondsuit \spadesuit
\cdot \lfloor \lceil \rceil \rfloor

Click here to see the symbols and their names. For example, you might use these as follows:
draw title "$\alpha$ = thermal expansion coefficient"

Sometimes you'll want a mathematical symbol to be adjacent to a normal text string, with no space between. You can do this by enclosing in braces, as in LaTeX.

TeX and LaTeX handle combinations of superscripts and subscripts very cleanly, putting one above the other. Presently, Gri does not do this; for example `set x name "$A_1^2$"' will have the 2 appearing to the right of the 1 instead of above it. Proper positioning will be added to a later version of Gri, but in the meantime you can achieve the desired effect with the TeX ``negative thinspace'' psuedo-character in math-mode. Using this feature will not hurt you when the new Gri becomes available. The symbol for a negative thinspace is `\!' in math-mode. It has no meaning in nonmath mode. A thinspace is 1/6 of an ``em-space'' (a TeX term, normally equal to the width of the character ``M'' in the current font). In most fonts, numbers are half the width of the letter ``M'', so that 3 negative thinspaces will move leftward over a single number. Thus, if the example above becomes `set x name "$A_1\!\!\!^2"', the 2 will be positioned above the 1. (Equivalently, you could write `set x name "$A^2\!\!_1$"'.) Depending on the actual characters you have in the super/subscripts, you might need more or less thinspaces; some experimentation might be required. Also, note that the symbol `\,' in math mode is a positive thinspace (which moves the next character a little bit to the right). Thus, you can add a little extra spaces between characters by doing something like `set x name "A$\,$B"'.

To get a hat over a single character, do something like the following (which draws a hat over the character "h"):
draw label "h${\!\!\!^{^\wedge}}$" at 10 12 cm

To get an overbar on a rho, do this:
draw label "$\rho\!\!\!\!^-$" at 3 3 cm

5.9.3: Non-English characters

Gri supports both English and other European-derived languages. In particular, it permits text with accents on letters. (It does not support other Oriental and other languages at this time.) Gri uses the ISO-Latin-1 font-encodings by default, although the so-called `standard' font-encoding may also be selected with the `Set Font Encoding' command see Set Font Encoding. For more on font encodings see any book on PostScript fonts ... although the bottom line is that if you are using accented characters in your work, then you probably already know about encodings, and if you don't use accents then you needn't learn about this topic except for the pleasure of learning about other languages.

The method of handling accented characters is very simple. If you can type it, Gri can draw it! It's up to you to determine how to enter the accents. Most text editors permit this. Since many users will prefer the Emacs editor, a few words about that are in order.

Consider the task of inserting French text, with the Emacs text-editor. There are several ways of doing this (and you may wish to consult your emacs info manual). A method that works in emacs-19 up to current emacs-20 versions uses the emacs `iso-transl.el' package by putting the following in your `~/.emacs' file:
(require 'iso-transl)
(iso-transl-set-language "French")
(standard-display-european t)
Loading this package defines three ways of entering the non-ASCII printable characters with codes above 127: the prefix `C-x 8', or the `Alt' key, or a dead accent key. For example, you can enter uppercase A-umlaut as `C-x 8 " A' or `Alt-" A' (if you have an Alt key) or `umlaut A' (if you have an umlaut/diaeresis key).

A more recently introduced method is to enter the mode which allows quick insertion of iso-latin-1 characters. Do the Emacs command `M-x iso-accents-mode' (either manually, or in a hook that's done automatically). Now, suppose the x-axis is to represent temperature. All you'd have to do is type in the command
set x name "Temp'erature"
As you type, the quote mark will dissappear, and reappear as an accent on the `e'. And then, Gri will recognize this accented `e', and it will draw the accent on the axis label.

5.9.4: Adjustment Of Character Position

Micro-positioning is available within math-mode, via the symbols `\!' (which means go left one thin-space) and `\,' (which means go right on thin-space). (A thin-space is 1/6 the width of the letter ``M'').