PostScript native units are "points". 1 inch = 72 points.

Comments are preceeded with %.

Entire Postscript programs are usually signified like this:

    %!PS-Adobe-3.0 EPSF-3.0
    %%BoundingBox: 34 34 578 758
    %%More headers or comments here

Typical text output goes like this:

  /Courier findfont
  36 scalefont
  setfont
  (The text goes here!) show

Useful Commands

abs

float -> int Math operation. Absolute value.

add

# # -> sum# Math operation. Adds two numbers.

and

i t/f t/f -> t/f Logical operation. Logical AND.

arc

cenx ceny radius startang endang -> Generates circular arc section. The very annoying thing about this is that it only works in CCW. You can use moveto arc moveto to jump to the end of the arc (making it the beginning) and then back to the beginning when you’re done. But this has some severe limitations.

atan

0-1 Arctangent, silly.

bitshift
ceiling

float -> int

clear

x x x x .... x ->

cleartomark
clip

This takes the current path and uses it to create a clip mask. Everything rendered outside of this clipmask is ignored. So if you want everything to be within a certain border, you can make a path of that border and execute clip. Note that clip doesn’t lose the path information which means you could do a stroke too. The only way to make your clip region bigger is by undoing back to a previous state with grestore.

closepath

Takes current path and draws a line from the current point to the first point.

copy
cos

ang -> 0-1ang -> 0-1 Math operator. Cosine.

count
counttomark
curveto

x1 y1 x2 y2 x3 y3 -> Constructs a Bezier curve from the current point to point 3 using points 1 and 2 as control points. Point 1 is on a tangent to the curve at the start (current position) and point2 is on a tangent line to the curve where it ends at point 3.

def

/varname value -> Stores the "value" in a variable. This can be a procedure that can be executed later like so: /go { showpage clear (test.ps) run } def

dup

x -> x x Duplicate. Just like the RPN command.

eq

# # -> t/f Logical comparison operation. Equals.

exch

y x -> y x Same as swap in RPN.

exp
fill

Fills in recent path

findfont

/fontname ->

floor
for

start inc end {proc} -> n1 n2 n3 ... Looping construction. This allows for more complicated looping than the similar repeat command. This one leaves the current counter on the stack prior to executing each procedure. So if you don’t need to use this counter, the first command of your procedure might as well be pop.

ge

# # -> t/f Logical comparison operation. Greater-than or equal.

grestore

Restores the properties stored by gsave. Useful to unset temporary modifications.

gsave

Saves current state of the graphics system. This includes gray, width, paths, clippaths and just about everything. It is important to realize that gsave/grestore pairs can be nested preserving various things at various times.

gt

# # -> t/f Logical comparison operation. Greater-than.

idiv

# # -> # Math operator. Integer division.

if

t/f {proc} ->

ifelse

t/f {procT} {procF} ->

in
index
le

# # -> t/f Logical comparison operation. Less-than or equal.

lineto

x y -> Continues a path from the current point to the point specified. Segments generated with this command will become visible with a subsequent stroke command.

log
lt

# # -> t/f Logical comparison operation. Less-than.

mark
mod

# # -> # Math operator. Remainder.

moveto

x y -> Continues a path to a new point. Segments generated with this command will not be rendered with a subsequent stroke command.

mul

# # -> #

ne

# # -> t/f Logical comparison operation. Not equal.

neg

# -> -# Math operator. Negate.

newpath

Initializes the creation of a new path.

not

t/f -> f/t Logical operation. Logical not.

or

t/f t/f -> t/f Logical operation. Logical or.

pop

x -> Same as "drop" in RPN.

rand
repeat

#times {proc} -> Simple looping construction used to repeat a procedure a known # of times.

rlineto

dx dy -> Continue a path using relative coordinates. This is similar to the lineto.

rmoveto

dx dy -> Jump to another position leaving no stroke marks using relative coordinates. This is similar to moveto.

roll
rotate

deg -> Modifies the viewer’s transform matrix. This is used to change the angular layout of everything. Positive angles turn the viewer ccw, not the paper. You are rotating how you look at it, not how it is.

round
rrand
run

(filename) -> Executes the named (in parentheses) file in the PS interpreter.

scale

xfact yfact -> Modifies the transform matrix. Can be used to mirror too with -1 scale factors. All matrix transforms are cumulative so this does nothing: 2 { -1 -1 scale } repeat

scalefont

points -> Sets the current font size in pionts.

setgray

0-1 -> Sets the ink darkness. 0 is totally black and 1 is totally white.

setlinewidth

points -> Sets the width in points for subsequent stroked paths.

show

(text string here) -> Causes the specified text to be rendered in the current font.

showpage

Causes the current program to be rendered. In GS previewer, it cause a clearing of the page. When actually printing, the printer (mine DJ anyway) needs this command to get going. Without a showpage command at the end of the file, nothing will happen.

sin

ang -> 0-1 Math operator. Sine.

sqrt

# -> # Math operator. Square root.

srand
stroke

Causes the renderer to draw the current path at the current linewidth and gray level, etc.

sub

# # -> difference Math function. Subtraction.

translate

dx dy -> Modifies the viewer’s transform matrix. This basically slides the origin (0,0) for subsequent operations to the specified location. All effects are cumulative and the only way to get back to an earlier state is to follow the steps in reverse or grestore from a previous gsave.

truncate
xor

t/f t/f -> t/f Logical operator. Exclusive OR.