ECN No Name Newsletter: September, 1989

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

Using PSFIG to Display PostScript in Troff text

Stan Harlow

Psfig is a preprocessor to troff on the ECN that allows scaling and positioning of postscript within troff text. Postscript is a powerful page description language used to talk to the several laser printers, such as the Apple LaserWriter. Postscript may be produced by AutoCAD, psraster, ECN plot programs and a number of personal computer programs. I have used psfig to display photographs digitized by a laser scanner connected to a PC and converted to Postscript.

Psfig works like other troff preprocessors (eqn, tbl, pic and grap) in which commands are enbedded between delimiters in the troff text file. The delimiters for psfig are ".F+" and ".F-". The simplest psfig command is "figure" followed by the name of a postscript file. Psfig is described completely in a paper entitled Psfig - A DITROFF Preprocessor for POSTSCRIPT Figures by Ned Batchelder and Trevor Darrell. This paper is available from your site specialist.

Psfig passes only the size of the figure and the path to the figure to troff. Troff does not read the postscript file. An lpr filter called psdit does the work of converting the troff output to postscript, combining it with the user's postscript file and sending it all to the laser printer.

As an example, if a troff text file called "myfile" contains the psfig command "figure myfig", the following command line will send "myfile" through psfig and troff to be printed on the "aa" Apple LaserWriter:

            psfig myfile | troff -Tpsc | lpr -Paa -n

The "-n" flag tells lpr to use the psdit filter. Psdit is executed by the lpr daemon and must have world read permission on the user's postscript file "myfig". This example will fail if the postscript file "myfig" is locked (mode 600) or if any directories leading to "myfig" are locked (mode 700).

To get around the problem of a locked file or directory, the user can pipe the troff output through psdit before piping it to lpr:

          psfig myfile | troff -Tpsc | psdit |lpr -Paa

In this case, psdit is executed by the user's id and thus has read permission on the postscript file "myfig". Note that the '-n' flag is not used on lpr if psdit precedes it.

A POSTSCRIPT file "smiley.ps"

  %!
  %%BoundingBox:  0 0 36 36
  newpath 18 18 10 0 360 arc stroke % head
  newpath 18 18 6 180 360 arc stroke % mouth
  newpath 22 22 .5 0 360 arc stroke % eyes
  newpath 14 22 .5 0 360 arc stroke
  showpage

A fragment of troff code including psfig delimiters.

   To get a happy document
   .F+
   figure smiley.ps
   .F-
   Put on a happy face!

Output:

  To get a happy document

                       happy face drawn here

  Put on a happy face!


The POSTSCRIPT file, "rosette.ps", has a natural size of about 4 inches across. This file can be manipulated to fit various spaces using psfig as was shown at this point in the newsletter.

  figure rosette.ps height 1.25i

  figure rossette.ps height .5i width \n(.lu
     (the width notation is troff for "current line length")

  figure rossette.ps height .5i width .2i
  space .5i
  figure rossette.ps height .5i width .8i


webmaster@ecn.purdue.edu
Last modified: Wednesday, 29-Oct-97 16:39:21 EST

[HTML Check] HTML