Extending pic with PostScript

Last-Updated: 2024-09-05

Sources

PostScript with pic

pic is a wonderful preprocessor which can do many things, please refer to the documentation which came with groff (/usr/share/doc/groff/pic.ps.gz for Debian, mirrored here for convenience).

If one wants to go beyond the current capabilities of pic, it is possible to use the PostScript output device and to include PostScript code in the groff input file.

Tadziu Hoffmann did just that with the following example, drawing a 10-pointed star filled with yellow and with a dashed outline.

.\" pic
.\" ----------------------------------------------------------------
.po 2.5c
.ll 21c-5c
.sp 2c
.\" ----------------------------------------------------------------
.de XX
ps: mdef 2
/blam!
{ 0 -25 moveto
  10
  { 18 rotate 0 -15 lineto 18 rotate 0 -25 lineto }
  repeat
  closepath
  gsave 1 1 0 setrgbcolor fill grestore
  [ 6 2.5 1.6922 2.5 4 2.5 1.6922 2.5 ] 3 setdash
  stroke }
def
/shift
{ currentpoint 2.2 sub translate }
def
..
.devicem XX
.PS
define blam { [
box width 0.5 invis "\X'ps: exec gsave shift blam! grestore'"
] }
box "foo"
arrow right
blam "bar"
arrow right
circle "baz"
.PE

The resulting file pictest.pdf is linked at the top of the page. It was obtained with:

groff -Tps input.ro | ps2pdf - pictest.pdf
← Go back