![]() |
![]()
| ![]() |
![]()
NAMEgrap —
Kernighan and Bentley's language for typesetting graphs
SYNOPSIS
DESCRIPTIONgrap is an implementation of Kernighan and Bentley's
language for typesetting graphs, as described in ``Grap-A Language for
Typesetting Graphs, Tutorial and User Manual,'' by Jon L. Bentley and Brian W.
Kernighan, revised May 1991, which is the primary source for information on
how to use grap . As of this writing, it is available
electronically at
http://www.kohala.com/start/troff/cstr114.ps .
Additional documentation and examples, packaged with
grap , may have been installed locally as well. If
available, paths to them can be displayed using grap
-h or grap
-v (or grap
--help / grap
--version )
This version is a black box implementation of
Because The
All numbers used internally by To be precise, the value by which two numbers must differ for
All The It is possible for someone to cause The New versions of
groff(1)
will invoke CommandsCommands are separated from one another by newlines or semicolons (;).
This describes how the axes for the graph are
drawn. A line_description is a
pic line
description, e.g.,
dashed 0.5 ,
or the literal solid . It may also include a
color keyword followed by the color to draw the string
in double quotes. Any color understood by the underlying groff system can be
used. Color can only be used under GNU pic, and is not available in
compatibility mode. Similarly, for pic implementations that understand
thickness , that attribute may be used with a real
valued parameter. Thickness is not available in
compatibility mode.
If the first line_description is given, the
frame is drawn with that style. The default is
If no plotting commands have been given before the
The
coord command specifies
a new coordinate system or sets limits on the default system. It defines the
largest and smallest values that can be plotted, and therefore the scale of
the data in the frame. The limits for the x and y coordinate systems can be
given separately. If a name is given, that coordinate
system is defined, if not the default system is modified.
A coordinate system created by one This command also determines if a scale is plotted
logarithmically.
The
draw command defines
the style with which a given line will be plotted. If
line_name is given, the style is associated with that
name, otherwise the default style is set.
line_description is a
pic line
description, and the optional plot_string is a string to
be centered at each point. The default line description is
invis , and the default plotting string is a centered
bullet, so by default each point is a filled circle, and they are unconnected.
If points are being connected, each draw command ends
any current line and begins a new one.
When defining a line style, that is the first
The plot string can have its format changed through several
string_modifiers. String_modifiers are described in the description of the
The standard defines file includes several macros useful as plot
strings, including
The
next command plots the
given point using the line style given by line_name, or
the default if none is given. If line_name is given, it
should have been defined by an earlier draw command,
if not a new line style with that name is created, initialized the same way as
the default style. The two expressions give the point's x and y values,
relative to the optional coordinate system. That system should have been
defined by an earlier coord command, if not, grap will
exit. If the optional line_description is given, it
overrides the style's default line description. You cannot over-ride the
plotting string. To use a different plotting string use the
plot command.
The coordinates may optionally be enclosed in parentheses: (expr, expr) quoted_string
[string_modifiers] [,
quoted_string
[string_modifiers]] ...
These commands both plot a string at the given
point. In the first case the literal strings are stacked above each other. The
string_modifiers include the
pic
justification modifiers (
ljust ,
rjust , above , and
below ), and absolute and
relative size modifiers. See the
pic
documentation for the description of the justification modifiers.
grap also supports the aligned
and unaligned modifiers which are briefly noted in the
description of the label command.
The standard defines file includes several macros useful as plot
strings, including Strings placed by either format of the
If In the second version, the expr is converted
to a string and placed on the graph. format_string is
a
printf(3)
format string. Only formatting escapes for printing floating point numbers
make sense. The format string is only respected if the
Points are specified the same way as for
The second form of this command is because the first form can be
used with a
This command controls the placement of ticks on the
frame. By default, ticks are automatically generated on the left and bottom
sides of the frame.
The first version of this command turns on the automatic tick
generation for a given side. The The second version of the If The labels on the ticks may be shifted by specifying a direction
and the distance in inches to offset the label. That is the optional
direction and expression immediately preceding the
The third format of the ticks left out from 2 to 32 by *2 will put ticks at 2, 4, 8, 16, and 32. If format_string is specified, all ticks are formatted using it. The parameters preceding the The ticks left out from 2 to 32 by *2 ticks left in 3, 5, 7 will put ticks on the left side of the frame pointing out at 2, 4, 8, 16, and 32 and in at 3, 5, and 7. The final form of
The
grid command is similar
to the ticks command except that
grid specifies the placement of lines in the frame.
The syntax is similar to ticks as well.
By specifying Instead of a direction for ticks, Grids are labelled by default. To omit labels, specify the format string as “”. If
The
label command places a
label on the given axis. It is possible to specify several labels, which will
be stacked over each other as in
pic. The
final argument, if present, specifies how many inches the label is shifted
from the axis.
By default the labels on the left and right labels run parallel to
the frame. You can cancel this by specifying
This draws an circle at the point indicated. By
default, the circle is small, 0.025 inches. This can be over-ridden by
specifying a radius. The coordinates of the point are relative to the named
coordinate system, or the default system if none is specified.
This command has been extended to take a line description, e.g.,
This draws a line or arrow from the first point to
the second using the given style. The default line style is
solid . The line_description can
be given either before the from or after the
to clause. If both are given the second is used. It is
possible to specify one point in one coordinate system and one in another,
note that if both points are in a named coordinate system (even if they are in
the same named coordinate system), both points must have
coordinate_name given.
The
copy command imports
data from another file into the current graph. The form with only a filename
given is a simple file inclusion; the included file is simply read into the
input stream and can contain arbitrary grap commands.
The more common case is that it is a number list; see
Number Lists below.
The second form takes lines from the file, splits them into words delimited by one or more spaces, and calls the given macro with those words as parameters. The macro may either be defined here, or be a macro defined earlier. See Macros for more information on macros. The filename may be omitted if the
print (expr|string)
Prints its argument to the standard error.
This passes block to
sh(1). Unlike
K&B
grap no macro or variable expansion is done. I
believe that this is also true for GNU
pic version
1.10. See the Macros section for information
on defining blocks.
This issues the given
pic
statements in the enclosing
.PS and
.PE at the point where the command is issued.
Statements that begin with a period are considered to be
troff(statements)
and are output in the enclosing For the purposes of relative placement of
pic or
troff
commands, the frame is output immediately before the first plotted object,
or the
This command is used to position graphs with
respect to each other. The current graph is given the
pic name
Name (names used by
pic begin
with capital letters). Any
pic commands
following the graph are used to position the next graph. The frame of the
graph is available for use with
pic name
Frame. The following places a second graph below the
first:
graph Linear [ graph description ] graph Exponential with .Frame.n at \ Linear.Frame.s - (0, .05) [ graph description ] name = expr This assigns expr to the
variable name.
grap has only
numeric (double) variables.
Assignment creates a variable if it does not exist. Variables
persist across graphs. Assignments can cascade;
The
bar command facilitates
drawing bar graphs. The first form of the command describes the bar somewhat
generally and has grap place it. The bar may extend up
or to the right, is centered on offset and extends up or
right height units (in the given coordinate system). For
example
bar up 3 ht 2 draws a 2 unit high bar sitting on the x axis, centered on x=3. By
default bars are 1 unit wide, but this can be changed with the
The line description has been extended to include a
The second form of the command draws a box with the two points as corners. This can be used to draw boxes highlighting certain data as well as bar graphs. Note that filled bars will cover data drawn under them. Control Flowif expr
then block
[else block]
The
if statement provides
simple conditional execution. If expr is non-zero, the
block after the then statement
is executed. If not the block after the
else is executed, if present. See
Macros for the definition of blocks. Early
versions of this implementation of grap treated the
blocks as macros that were defined and expanded in place. This led to
unnecessary confusion because explicit separators were sometimes called for.
Now, grap inserts a separator (;) after the last
character in block, so constructs like
if (x == 3) { y = y + 1 } x = x + 1 for block.
This command executes block
iteratively. The variable name is set to
from_expr and incremented by
by_expr until it exceeds to_expr.
The iteration has the semantics defined in the
ticks
command. The definition of block is discussed in
Macros. See also the note about implicit
separators in the description of the if command.
An Expressionsgrap supports most standard arithmetic operators: + - /
* ^. The carat (^) is exponentiation. In an if
statement grap also supports the C logical operators
==, !=, &&, || and unary !. Also in an if , ==
and != are overloaded for the comparison of quoted strings. Parentheses are
used for grouping.
Assignment is not allowed in an expression in any context, except
for simple cascading of assignments.
The Other than string comparison, no expressions can use strings. One
string valued function exists:
Macrosgrap has a simple but powerful macro facility. Macros
are defined using the define command :
Every occurrence of name in
the program text is replaced by the contents of block.
block is defined by a series of statements in nested {
}'s, or a series of statements surrounded by the same letter. An example of
the latter is
define foo X coord x 1,3 X foo appears in the text, it will be replaced
by coord x 1,3 . Macros are literal, and can contain
newlines. If a macro does not span multiple lines, it should end in a
semicolon to avoid parsing errors.
Macros can take parameters, too. If a macro call is followed by a parenthesized, comma-separated list the values starting with $1 will be replaced in the macro with the elements of the list. A $ not followed by a digit is left unchanged. This parsing is very rudimentary; no nesting or parentheses or escaping of commas is allowed. Also, there is no way to say argument 1 followed by a digit (${1}0 in sh(1)). The following will draw a line with slope 1. define foo { next at $1, $2 } for i from 1 to 5 { foo(i,i) } undefine
command deletes a macro.
See the directory
/usr/local/share/examples/grap for more examples of
macros. Confirm the location of the examples directory using the
Number ListsA whitespace-separated list of numbers is treated specially. The list is taken to be points to be plotted using the default line style on the default coordinate system. If more than two numbers are given, the extra numbers are taken to be additional y values to plot at the first x value. Number lists in DWBgrap can be comma-separated, and this
grap supports that as well. More precisely, numbers in
number lists can be separated by either whitespace, commas, or both.
1 2 3 4 5 6 Will plot points using the default line style at (1,2), (1,3),(4,5) and (4,6). A simple way to plot a set of numbers in a file named ./data is: .G1 copy "./data" .G2 Pic Macrosgrap defines pic macros that can be used in embedded pic
code to place elements in the graph. The macros are
x_gg , y_gg , and
xy_gg . These macros define pic distances that
correspond to the given argument. They can be used to size boxes or to plot
pic constructs on the graph. To place a given construct on the graph, you
should add Frame.Origin to it. Other coordinate spaces can be used by
replacing gg with the name of the coordinate space. A
coordinate space named gg cannot be reliably accessed
by these macros.
The macros are emitted immediately before the frame is drawn. DWB ENVIRONMENT VARIABLESIf the environment variableGRAP_DEFINES is defined,
grap will look for its defines file there. If that
value is a relative path name the path specified in the
-M option will be searched for it.
GRAP_DEFINES overrides the compiled in location of the
defines file, but may be overridden by the -d or
-D flags.
If FILES/usr/local/share/grap/grap.definesSEE ALSOatan2(3), groff(1), pic(1), printf(3), sh(1), sprintf(3), troff(1)If documentation and examples have been installed,
BUGSThere are several small incompatibilities with K&Rgrap . They include the sh
command not expanding variables and macros, and a more strict adherence to
parameter order in the internal commands.
Although much improved, the error reporting code can still be confused. Notably, an error in a macro is not detected until the macro is used, and it produces unusual output in the error message. Iterating many times over a macro with no newlines can run
AUTHORThis implementation was done by Ted Faber ⟨faber@lunabase.org⟩. Bruce Lilly ⟨bruce.lilly@gmail.com⟩ contributed many bug fixes, including a considerable revamp of the error reporting code. If you can actually find an error in yourgrap code, you can probably thank him.
grap was designed and specified by
Brian Kernighan and Jon
Bentley.
|