blob: f47fa42aa8755bd75de3cc86983bb0a011a79c2b [file] [log] [blame]
.de PS \" start picture
. \" $1 is height, $2 is width, both in inches
.if \\$1>0 .sp .35
.ie \\$1>0 .nr $1 \\$1
.el .nr $1 0
.in (\\n(.lu-\\$2)/2u
.ne \\$1
.de PE \" end of picture
.if \\n($1>0 .sp .65
pic, tpic \- troff and tex preprocessors for drawing pictures
.B pic
.I files
.B tpic
.I files
.I Pic
is a
.IR troff (1)
preprocessor for drawing figures on a typesetter.
.I Pic
code is contained between
.B .PS
.B .PE
\&.PS \f2optional-width\fP \f2optional-height\fP
or in a file mentioned in a
.B .PS
.BI .PS " " < file
.IR optional-width
is present, the picture is made that many inches wide,
regardless of any dimensions used internally.
The height is scaled in the same proportion unless
.IR optional-height
is present.
.B .PF
is used instead of
.BR .PE ,
the typesetting position after printing is restored to what it was
upon entry.
.IR element-list
is a list of elements:
\f2primitive attribute-list\fP
\f2placename\fP : \f2element\fP
\f2placename\fP : \f2position\fP
\f2var\fP = \f2expr\fP
{ \f2element-list\fP }
[ \f2element-list\fP ]
for \f2var\fP = \f2expr\fP to \f2expr\fP by \f2expr\fP do { \f2anything\fP }
if \f2expr\fP then { \f2anything\fP } else { \f2anything\fP }
copy \f2file,\fP copy thru \f2macro,\fP copy \f2file\fP thru \fPmacro\fP
sh { \f2commandline\fP }
print \f2expr\fP
reset \f2optional var-list\fP
Elements are separated by newlines or semicolons;
a long element may be continued by ending the line with a backslash.
Comments are introduced by a
.BI #
and terminated by a newline.
Variable names begin with a lower case letter;
place names begin with upper case.
Place and variable names retain their values
from one picture to the next.
After each primitive
the current position moves in the current direction
.RB ( up , down ,
.BR left , right
(default)) by the size of the primitive.
The current position and direction are saved upon entry
to a
.BR { ... }
block and restored upon exit.
Elements within a block enclosed in
.BR [ ... ]
are treated as a unit;
the dimensions are determined by the extreme points
of the contained objects.
Names, variables, and direction of motion within a block are local to that block.
.IR Troff-command
is any line that begins with a period.
Such a line is assumed to make sense in the context where it appears;
generally, this means only size and font changes.
.I primitive
objects are:
box circle ellipse arc line arrow spline move \f2text-list\fP
.L arrow
is a synonym for
.LR "line ->" .
.IR attribute-list
is a sequence of zero or more attributes;
each attribute consists of a keyword, perhaps followed by a value.
.ta .5i 2.5i
h(eigh)t \f2expr\fP wid(th) \f2expr\fP
rad(ius) \f2expr\fP diam(eter) \f2expr\fP
up \f2opt-expr\fP down \f2opt-expr\fP
right \f2opt-expr\fP left \f2opt-expr\fP
from \f2position\fP to \f2position\fP
at \f2position\fP with \f2corner\fP
by \f2expr, expr\fP then
dotted \f2opt-expr\fP dashed \f2opt-expr\fP
chop \f2opt-expr\fP -> <- <->
invis same
fill \f2opt-expr\fP
\f2text-list\fP \f2expr\fP
Missing attributes and values are filled in from defaults.
Not all attributes make sense for all primitives;
irrelevant ones are silently ignored.
The attribute
.L at
causes the geometrical center to be put at the specified place;
.L with
causes the position on the object to be put at the specified place.
For lines, splines and arcs,
.L height
.L width
refer to arrowhead size.
A bare
.I expr
implies motion in the current direction.
Text is normally an attribute of some primitive;
by default it is placed at the geometrical center of the object.
Stand-alone text is also permitted.
A text list
is a list of text items:
\f2 text-item\fP:
"..." \f2positioning ...\fP
sprintf("\f2format\fP", \f2expr\fP, \f2...\fP) \f2positioning ...\fP
\f2 positioning\fP:
center ljust rjust above below
If there are multiple text items for some primitive,
they are arranged vertically and centered except as qualified.
Positioning requests apply to each item independently.
Text items may contain
.I troff
commands for size and font changes, local motions, etc.,
but make sure that these are balanced
so that the entering state is restored before exiting.
A position is ultimately an
.I x,y
coordinate pair, but it may be specified in other ways.
\f2 position\fP:
\f2expr, expr\fP
\f2place\fP ± \f2expr, expr\fP
\f2place\fP ± ( \f2expr, expr\fP )
( \f2position\fP,\f2 position\fP ) \f2x\fP\fR from one, \f2y\fP\fR the other\fP
\f2expr\fP [\fLof the way\fP] between \f2position\fP and \f2position\fP
\f2expr\fP < \f2position\fP , \f2position\fP >
( \f2position\fP )
\f2 place\fP:
\f2placename\fP \f2optional-corner\fP
\f2corner\fP of \f2placename\fP
\f2nth\fP \f2primitive\fP \f2optional-corner\fP
\f2corner\fP of \f2nth\fP \f2primitive\fP
.IR optional-corner
is one of the eight compass points
or the center or the start or end of a primitive.
\f2 optional-corner\fP:
.n .e .w .s .ne .se .nw .sw .c .start .end
\f2 corner\fP:
top bot left right start end
Each object in a picture has an ordinal number;
.IR nth
refers to this.
\f2 nth\fP:
\f2n\fPth\f2, n\fPth last
The built-in variables and their default values are:
.ta .5i 2.5i
boxwid 0.75 boxht 0.5
circlerad 0.25 arcrad 0.25
ellipsewid 0.75 ellipseht 0.5
linewid 0.5 lineht 0.5
movewid 0.5 moveht 0.5
textwid 0 textht 0
arrowwid 0.05 arrowht 0.1
dashwid 0.1 arrowhead 2
scale 1
These may be changed at any time,
and the new values remain in force from picture to picture until changed again
or reset by a
.L reset
Variables changed within
.B [
.B ]
revert to their previous value upon exit from the block.
Dimensions are divided by
.B scale
during output.
Expressions in
.I pic
are evaluated in floating point.
All numbers representing dimensions are taken to be in inches.
\f2 expr\fP:
\f2expr\fP \f2op\fP \f2expr\fP
- \f2expr\fP
! \f2expr\fP
( \f2expr\fP )
\f2place\fP .x \f2place\fP .y \f2place\fP .ht \f2place\fP .wid \f2place\fP .rad
sin(\f2expr\fP) cos(\f2expr\fP) atan2(\f2expr,expr\fP) log(\f2expr\fP) exp(\f2expr\fP)
sqrt(\f2expr\fP) max(\f2expr,expr\fP) min(\f2expr,expr\fP) int(\f2expr\fP) rand()
\f2 op\fP:
+ - * / % < <= > >= == != && ||
.B define
.B undef
statements are not part of the grammar.
define \f2name\fP { \f2replacement text\fP }
undef \f2name\fP
Occurrences of
.BR $1 ,
.BR $2 ,
in the replacement text
will be replaced by the corresponding arguments if
.I name
is invoked as
\f2name\fP(\f2arg1\fP, \f2arg2\fP, ...)
Non-existent arguments are replaced by null strings.
Replacement text
may contain newlines.
.B undef
statement removes the definition of a macro.
.I Tpic
is a
.IR tex (1)
preprocessor that accepts
.IR pic
It produces Tex commands that define a box called
.BR \egraph ,
which contains the picture.
The box may be output this way:
arrow "input" above; box "process"; arrow "output" above
A: ellipse
circle rad .1 with .w at A.e
circle rad .05 at 0.5 <A.c,>
circle rad .065 at 0.5 <A.c,>
spline from last circle.nw left .25 then left .05 down .05
arc from A.c to rad 0.5
for i = 1 to 10 do { line from A.s+.025*i,.01*i down i/50 }
arrow "input" above; box "process"; arrow "output" above
A: ellipse
circle rad .1 with .w at A.e
circle rad .05 at 0.5 <A.c,>
circle rad .065 at 0.5 <A.c,>
spline from last circle.nw left .25 then left .05 down .05
arc from A.c to rad 0.5
for i = 1 to 10 do { line from A.s+.025*i,.01*i down i/50 }
.B \*9/src/cmd/pic
.IR grap (1),
.IR doctype (1),
.IR troff (1)
B. W. Kernighan,
``PIC\(ema Graphics Language for Typesetting'',
Unix Research System Programmer's Manual,
Tenth Edition, Volume 2