home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / psfig / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-09-22  |  50.2 KB

  1. Subject:  v11i074:  Including PostScript figures in ditroff, Part03/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: trevor@linc.cis.upenn.edu (Trevor Darrell)
  7. Posting-number: Volume 11, Issue 74
  8. Archive-name: psfig/Part03
  9.  
  10. # This is a shell archive.  Remove anything before this line,
  11. # then unpack it by saving it in a file and typing "sh file".
  12. #
  13. # Contents:  trf/doc/ trf/doc/figs/ trf/doc/Makefile trf/doc/dopaper
  14. #    trf/doc/getpages trf/doc/paper.ms trf/doc/paper.tmac
  15.  
  16. echo mkdir - trf/doc
  17. mkdir trf/doc
  18. chmod u=rwx,g=rx,o=rx trf/doc
  19.  
  20. echo x - trf/doc/Makefile
  21. sed 's/^@//' > "trf/doc/Makefile" <<'@//E*O*F trf/doc/Makefile//'
  22. # A sample Makefile for psfig stuff
  23.  
  24. P    = paper
  25. Draft    =
  26.  
  27. # Change these to reflect your installation
  28. Ditroff    = ditroff
  29. Eqn    = eqn
  30.  
  31. Macros    = -ms
  32. MyMacs    = paper.tmac ../lib/psfig.tmac
  33.  
  34. # This should be the *modified* psdit
  35. Psdit    = psdit
  36.  
  37. Psfig    = psfig $(Draft) -Dfigs
  38. Docs    = $P.ps eqn.ps pro.ps
  39.  
  40. whattodo:
  41.     @echo "Make what?"
  42.  
  43. pages: $P.ps
  44.     getpages $P.ps
  45.  
  46. $P.pr: $P.ps
  47.     psprint -e -r $P.ps
  48.  
  49. $P.ps: $P.pfg
  50.     $(Ditroff) -Tpsc $(Macros) $(MyMacs) $P.pfg > $P.dtrf
  51.     $(Psdit) $P.dtrf > $P.ps
  52.  
  53. $P.tek: $P.pfg
  54.     $(Ditroff) -Ttc $(Macros) $(MyMacs) $P.pfg > $P.tc
  55.     tc $P.tc
  56.     
  57. $P.pfg: $P.eqn
  58.     $(Psfig) <$P.eqn >$P.pfg
  59.  
  60. $P.eqn: $P.tbl
  61.     $(Eqn) -Tpsc <$P.tbl >$P.eqn
  62.  
  63. $P.tbl: $P.pic
  64.     tbl <$P.pic >$P.tbl
  65.  
  66. $P.pic: $P.ms
  67.     pic <$P.ms >$P.pic
  68.     
  69. count: $P.ms
  70.     deroff $P.ms | wc -w
  71.  
  72. spell: #spell
  73. #spell: $P.ms
  74.     spell $P.ms >'#'spell
  75.  
  76. tidy:
  77.     -rm -f *.BAK *.CKP core a.out
  78. clean: tidy
  79.     -rm -f *.tc *.dtrf *.pfg *.eqn *.tbl *.pic '#'* $P.ps.* $P.ps *.out
  80. @//E*O*F trf/doc/Makefile//
  81. chmod u=rw,g=r,o=r trf/doc/Makefile
  82.  
  83. echo x - trf/doc/dopaper
  84. sed 's/^@//' > "trf/doc/dopaper" <<'@//E*O*F trf/doc/dopaper//'
  85. #! /bin/csh -f
  86. #
  87. #   How to make the psfig paper (it's tricky).
  88. #
  89. set P=paper
  90. date
  91. setenv PSLIBDIR ../patches
  92. if (! -e $PSLIBDIR/psdit.pro) then
  93.     echo You must patch psdit.pro first!
  94.     exit -1
  95. endif
  96.  
  97.     # Make a real version (the little pages will be empty)
  98.     # *ignore* warnings about missing paper.ps.[1-8]
  99.  
  100. touch $P.ms
  101. echo Ignore warnings.....
  102. make Draft=-d150 $P.ps
  103. getpages $P.ps
  104. ls -l $P.ps
  105.  
  106.     # Make a super version (the little pages are level 151)
  107.  
  108. touch $P.eqn
  109. make Draft=-d200 $P.ps
  110. ls -l $P.ps
  111.  
  112. date
  113. @//E*O*F trf/doc/dopaper//
  114. chmod u=rwx,g=rx,o=rx trf/doc/dopaper
  115.  
  116. echo mkdir - trf/doc/figs
  117. mkdir trf/doc/figs
  118. chmod u=rwx,g=rx,o=rx trf/doc/figs
  119.  
  120. echo x - trf/doc/getpages
  121. sed 's/^@//' > "trf/doc/getpages" <<'@//E*O*F trf/doc/getpages//'
  122. #! /bin/csh -f
  123. #
  124. #    getpages:
  125. #
  126. #    Takes a .ps file and creates a new .ps file for each page
  127. #    in the original.
  128. #
  129. #    N.Batchelder, 3/8/86.
  130. #
  131.  
  132. set File=$1
  133. set Pages=`grep -c '^%%Page[: ]' $File`
  134. set Page=1
  135. while ($Page <= $Pages)
  136.     echo $File.$Page
  137.     psrev -s$Page -R <$File >$File.$Page
  138.     @ Page++
  139. end
  140. @//E*O*F trf/doc/getpages//
  141. chmod u=rwx,g=rx,o=rx trf/doc/getpages
  142.  
  143. echo x - trf/doc/paper.ms
  144. sed 's/^@//' > "trf/doc/paper.ms" <<'@//E*O*F trf/doc/paper.ms//'
  145. @.\" psfig documentation and users guide
  146. @.nr Ns 0i
  147. @.de Ip
  148. @.IP \&\s8\z\(ui\H'10'\f(CB\\$1\s0\z\(ui\H'0'\fP\fI\\$2\fP
  149. @..
  150. @.F+
  151. delim ##
  152. define "ht"        | height |
  153. define "wd"        | width |
  154. define "pretzel"    | pretzel.ps wd 1.3n |
  155. define "rosette"    | rosette.ps |
  156.  
  157. define "nedface"    | figure ned.ps height 1i reserve level 101 |
  158. define "trevorface"    | figure trevor.ps height 1i reserve level 101 |
  159. @.F-
  160. @.LP        \" Initialize -ms
  161. @.rs
  162. @.sp .5i
  163. @.in +.5i \" **
  164. @.nf
  165. @.ce 99
  166. @.ps 12
  167. @.vs 15p
  168. @.B
  169. Psfig \*- A \*(Dt Preprocessor for \*(Ps Figures
  170. @.ps
  171. @.vs
  172. @.ce 0
  173. @.sp
  174. @.ta 2.0iC 3.6iC
  175. @.I
  176.     Ned Batchelder\(dg    Trevor Darrell
  177. @.R
  178. @.sp .1i
  179.     #nedface#    #trevorface#
  180. @.sp .8
  181. @.ce 99
  182. Computer and Information Science Department
  183. University of Pennsylvania
  184. 200 South 33\s-2\urd\d\s0 Street
  185. Philadelphia, PA  19104
  186. @.sp .3i
  187. @.I ABSTRACT
  188. @.sp
  189. @.ce 0
  190. @.fi
  191. @.in +.5i
  192. @.ll -.5i
  193. @.ti +\n(PIu
  194. @.I Psfig
  195. is a new preprocessor for \*(Tr.
  196. It implements a general figure inclusion, where a figure is any
  197. \*(Ps file.
  198. For example:
  199. @.F+
  200. rosette height 1.25i
  201. @.F-
  202. Figures are automatically scaled and positioned, with all sizes under user
  203. control.
  204. @.I Psfig
  205. can be used not only for actual figures, but also to provide special effects
  206. in standard text, like
  207. \v'2.7p'# black.ps height \n(.vu width "\w'white\ on\ black'u+1n" reserve 0 0 #\v'-2.7p'\c
  208. # literal /1 setgray/ #\h'.5n'white\ on\ black# literal /0 setgray/ #,
  209. or custom special characters, like `#pretzel#'.
  210. For speed and for compatibility with non-\*(Ps systems, a draft
  211. mode is available that simply shows the name of the \*(Ps file and the
  212. extent of the figure.
  213. @.ll
  214. @.in
  215. @.in -.5i
  216. @.sp 2
  217. @.2C
  218. @.FS \(dg
  219. Author's current address:
  220. Digital Equipment Corporation,
  221. 129 Parker Street, PKO3-1/K90
  222. Maynard, MA  01754
  223. @.FE
  224. @.NH 1
  225. Introduction
  226. @.PP
  227. The \*(Ps language is a powerful page description tool that is rapidly becoming
  228. @.I
  229. de facto
  230. @.R
  231. standard, and is available in printers with a wide range of price and
  232. performance from several manufacturers. Since \*(Tr has a long
  233. history of preprocessors that provide new functions (\c
  234. @.I
  235. eqn, tbl, pic,
  236. @.R
  237. and
  238. @.I grap 
  239. provide equations, tables, line drawings, and graphs respectively),
  240. we wanted to write a preprocessor that would provide the capability
  241. to include arbitrary \*(Ps figures into a document. 
  242. @.I Psfig
  243. is the result.
  244. @.NH 2
  245. Simple Use
  246. @.PP
  247. The simplest 
  248. @.I psfig
  249. command is simply the word
  250. @.Ex figure
  251. followed by the name of a file.
  252. If we have a file called `rosette.ps' which contains the
  253. \*(Ps code to draw the rosette in the abstract,
  254. we would use the 
  255. @.I psfig
  256. command
  257. @.Ex
  258. figure rosette.ps
  259. @.En
  260. to include it as a figure.
  261. (We'll explain how to combine 
  262. @.I psfig
  263. commands with the rest of a \*(Tr document in a little while.)
  264. @.I Psfig
  265. will automatically position the figure to the proper place on the page,
  266. regardless of its `natural' position.
  267. It will also instruct \*(Tr to reserve the space occupied by the figure so that
  268. it doesn't overlap with anything else on the page.
  269. @.PP
  270. Because no mention of size was made, 
  271. @.I psfig
  272. draws the figure at its natural size.
  273. The rosette's natural size is about 4 inches across, which is a little
  274. large; the rosette in the abstract was produced with:
  275. @.Ex
  276. figure rosette.ps height 1.25i
  277. @.En
  278. The 
  279. @.Ex height
  280. clause specifies how high the figure should be.
  281. We've asked for it to be 1\(14 inches high.
  282. The word
  283. @.Ex 1.25i
  284. is interpreted by \*(Tr, so any expression that \*(Tr can evaluate
  285. is acceptable.
  286. For explicit measurements, the units
  287. @.Ex i ,
  288. @.Ex c ,
  289. and
  290. @.Ex p
  291. for inches, centimeters and printer's points (1/72 inch) are
  292. available (among others) for absolute distances, and 
  293. @.Ex m ,
  294. @.Ex n ,
  295. and
  296. @.Ex v
  297. for the current point size, half the current point size, and the current 
  298. line spacing are available for distances that vary according 
  299. to their environment.
  300. @.PP
  301. Since the width of the figure wasn't specified, it was scaled equally so
  302. that the shape of the figure is maintained.
  303. Of course, if desired, both dimensions can be explicitly specified.
  304. The command
  305. @.Ex
  306. figure rosette.ps
  307.            height .5i
  308.            width \en(.lu
  309. @.En
  310. produces:
  311. @.F+
  312. figure rosette.ps height .5i width \n(.lu
  313. @.F-
  314. (The width expression
  315. @.Ex \en(.lu
  316. is a \*(Tr incantation that means the current line length.
  317. It stretches the rosette across the column exactly.)
  318. @.PP
  319. Multiple
  320. @.Ex figure
  321. commands place figures side-by-side across the page, and space between such
  322. figures is specified with a 
  323. @.Ex space
  324. command.
  325. @.Ex
  326. figure rosette.ps height .5i width .2i
  327. space .5i
  328. figure rosette.ps height .5i width .8i
  329. @.En
  330. produces:
  331. @.F+
  332. figure rosette.ps height .5i width .2i
  333. space .5i
  334. figure rosette.ps height .5i width .8i
  335. @.F-
  336. @.PP
  337. Figure 1 is an overview of all of the components in the system, and by the way,
  338. a fairly complex example of what can be done with
  339. @.I psfig .
  340. @.\"
  341. @.F+
  342. define "page" /figure ht 1.1i wd .85i bounds 0 0 612 792 level 151/
  343. define "erase" /figure white.ps ht 1.1i wd .85i reserve 0 0/
  344. define "epg" /erase; page/
  345. @.F-
  346. @.KW
  347. @.PS
  348. boxht = 1.1; boxwid = .85
  349. linewid = .35
  350. Source: box "\*(Tr" "Source"
  351. arrow
  352. box "\fIeqn, tbl, \fPetc." "(optional)" ht .5 wid .8
  353. arrow
  354. Pf: box "\fIpsfig\fP" ht .5 wid .8
  355. arrow
  356. box "\*(Dt" ht .5 wid .8
  357. arrow
  358. Psdit: box "\fIpsdit\fP" ht .5 wid .8
  359.  
  360. define spread | with .e at last box.e + (-.6, .1) |
  361. @.ds Pv "\v'.55i-.2m'
  362. @.ds P^ "\v'-.55i-.2m'
  363. Output: [
  364. P8: box "\*(Pv# epg paper.ps.12 #\*(P^"
  365. P7: box "\*(Pv# epg paper.ps.11 #\*(P^" with .e at last box.e + (-.6, .1)
  366. P6: box "\*(Pv# epg paper.ps.10 #\*(P^" with .e at last box.e + (-.6, .1)
  367. P5: box "\*(Pv# epg paper.ps.9  #\*(P^" with .e at last box.e + (-.6, .1)
  368. P4: box invis "..."  with .e at last box.e + (-.6, .1)
  369. P3: box "\*(Pv# epg paper.ps.3 #\*(P^" with .e at last box.e + (-.6, .1)
  370. P2: box "\*(Pv# epg paper.ps.2 #\*(P^" with .e at last box.e + (-.6, .1)
  371. P1: box "\*(Pv# epg paper.ps.1 #\*(P^" with .e at last box.e + (-.6, .1)
  372. Handle: (P6.ne, P3.ne)
  373. ] with .n at Pf.s - (0, .4)
  374. "\*(Ps output" at last [].s below
  375. spline -> from Psdit.e \
  376.     then right .5 \
  377.     then down .5 \
  378.     then to Output.Handle
  379. right
  380. Figs: [
  381.     Rosette: box "\*(Pv#page rosette.ps #\*(P^"
  382.     move right .1
  383.     Face: box "\*(Pv#page ned.ps #\*(P^"
  384.     move same
  385.     Pretzel: box "\*(Pv#page pretzel.ps #\*(P^"
  386. ] with .s at Pf.n + (0, .4)
  387. "\*(Ps Figures" at Figs.n + (0, .05) above
  388.  
  389. spline from Figs.sw - (0, .05) \
  390.     then down .15 \
  391.     then to Pf.n + (0, .35) \
  392.     then down .15
  393. arrow to Pf.n
  394. spline from Figs.se - (0, .05) \
  395.     then down .15 \
  396.     then to Pf.n + (0, .35) \
  397.     then down .15
  398. @.PE
  399. @.sp 
  400. @.ce
  401. @.B "Figure 1. " " How the components fit together."
  402. @.sp
  403. @.WE    \" End the wide keep.
  404. @.NH 1
  405. Design Overview
  406. @.PP
  407. In designing
  408. @.I psfig ,
  409. our first goal was to serve the average \*(Tr user who
  410. desires to include figures in a document with the
  411. power and generality of \*(Ps. The existing \*(Tr preprocessors do a
  412. fine job in each of their specialized tasks, but none of them approach
  413. the generality or descriptive power of \*(Ps.
  414. We saw 
  415. @.I psfig
  416. as being the base for a broad range of uses, so in addition to being easy to 
  417. use, it had to be powerful.
  418. We wanted the capability to include anything from a full
  419. page high resolution image down to a special mathematical symbol, as well as
  420. also to provide an ability to pass through literal \*(Ps for
  421. special effects. 
  422. @.NH 2
  423. Interface Design
  424. @.PP
  425. Good user interfaces are as simple as possible in the base case,
  426. yet retain full generality for more sophisticated use.
  427. Our goal for 
  428. @.I psfig
  429. was to design a user interface that is extremely simple for the simplest case
  430. of including a \*(Ps file as a figure, but that has the power necessary to 
  431. describe more complex operations that sophisticated users might want.
  432. @.PP
  433. We also set out to make sure that it was a familiar interface. We explicitly
  434. tried to make
  435. @.I psfig
  436. as much like
  437. @.I eqn
  438. as possible. We saw
  439. @.I eqn
  440. as a good example of a powerful yet easy to use preprocessor which solved most
  441. of the problems of interface design that we were going to face.
  442. @.PP
  443. Lastly, we wanted to make sure that 
  444. @.I psfig
  445. was as powerful as possible. In the spirit of the other \*(Tr translators, as
  446. much information as possible is simply passed through the preprocessor. 
  447. For example, we chose not to define our own units for the specification of
  448. figure dimensions. Rather, we assume that the expression used will be 
  449. interpretable by \*(Tr, and pass it through. This provides a powerful link
  450. between 
  451. @.I psfig
  452. and \*(Tr, and allows for uses that would have been impossible had 
  453. @.I psfig
  454. interpreted all dimensions itself.
  455. @.NH 2
  456. Figure Placement
  457. @.PP
  458. To most users, the operation of including a figure into a document seems a natural one, and the behavior that should result from simple figure inclusion 
  459. commands seems obvious. We wanted to make sure that 
  460. @.I psfig
  461. would conform to these expectations that people had about figure placement.
  462. @.PP
  463. There are eight values that govern how
  464. @.I psfig
  465. manipulates a figure to position it properly:
  466. four for where the figure lies in its natural \*(Ps coordinate system,
  467. and four for where the figure is desired to fall on the page.
  468. We use the term ``natural'' position
  469. to refer to the size and location of the figure would have if it were printed
  470. alone, and we adopt Adobe's convention
  471. of describing a figure's natural size with a bounding box, specifying
  472. the x and y coordinates for both the lower left and upper right 
  473. corners.
  474. @.PP
  475. To avoid confronting this collection of numbers for every figure,
  476. we developed some defaults to use when positioning a figure. We assume the
  477. desired position of the figure is at the current \*(Tr 
  478. pen position, and that the figure should keep its natural height and width. 
  479. If the figure conforms to 
  480. the \*(Ps Document Structuring Convention as defined by Adobe Systems, 
  481. the figure's natural size (and position) will be declared in a \*(Ps comment
  482. which
  483. @.I psfig
  484. can read.
  485. More often than not, though, one does not want the figure at its natural size.
  486. We designed 
  487. @.I psfig 's
  488. figure manipulations to take into account not just a translation to move the
  489. figure to the proper place on the page, but also a scaling to resize
  490. the figure.
  491. @.I Psfig
  492. allows you to specify a height and/or width for the figure.
  493. If only one is given, the user's expectation is that the other will be 
  494. calculated to maintain the figure's original aspect ratio, so this is what
  495. @.I psfig
  496. does.
  497. @.PP
  498. Because users will find varied purposes for
  499. @.I psfig ,
  500. it understands about two different types of figures.
  501. Broken out figures are similar to 
  502. @.I eqn 's
  503. display equations: they reserve space across an entire column so that they 
  504. occupy space like paragraphs. They are used for actual figures in documents.
  505. The pie chart in Figure 2 is an example of a broken out figure.
  506. @.KF
  507. @.F+
  508. piechart.ps width \n(.lu
  509. @.F-
  510. @.br
  511. @.ce 99
  512. @.sp .1i
  513. @.B "Figure 2. " " A Broken out figure"
  514. @.br
  515. @.KE
  516. In-line figures are similar to 
  517. @.I eqn 's 
  518. in-line equations: they occupy space within the current line of text, and are 
  519. used to provide special characters for unusual applications. Examples include 
  520. the pretzel (#pretzel#) from the abstract.
  521. @.PP
  522. Because these two types of figure have different uses, 
  523. they have different defaults for 
  524. positioning. Broken out figures have their upper left corner placed on the 
  525. \*(Tr baseline, so that they will extend down from the current position.
  526. In-line figures have their lower left corners place on the baseline, so that 
  527. they will behave similarly to other characters. Note that the baseline will in 
  528. general be modified in some way prior to invoking the figure, so that the 
  529. positioning will be correct.
  530. @.NH 2
  531. Interactions With Other Components
  532. @.PP
  533. One of the elegant aspects of \*(Tr's preprocessor system is that
  534. there seem to be no restrictions on their use with each other. Any or
  535. all of them can operate on different or even the same parts of the
  536. document without any ill effects.  We worked hard to maintain this
  537. standard of compatibility in creating
  538. @.I psfig .
  539. It has been successfully used with the standard preprocessors
  540. @.I tbl ,
  541. @.I eqn ,
  542. and
  543. @.I pic ,
  544. just as \*(Tr users would expect (uses with
  545. @.I eqn
  546. and
  547. @.I pic
  548. are included in this paper).
  549. @.PP
  550. Finally, we sought to make 
  551. @.I psfig
  552. interact well
  553. with other variants of \*(Tr. 
  554. To be able to pass commands through to the output file, 
  555. @.I psfig
  556. requires full \*(Dt, to which many people do not have access. It also obviously
  557. presupposes a \*(Ps output device.
  558. In order that source files using 
  559. @.I psfig
  560. can be processed with 
  561. other systems (for example, \*(Nr or vanilla \*(Tr without special
  562. postprocessors or \*(Ps), a draft mode feature has been included 
  563. which uses no unusual features of either the formatter or the output device.
  564. Of course, none of the \*(Ps figures are included in the output, but 
  565. indications of them are given, and the formatting of the \*(Tr output around 
  566. them is the same. 
  567. @.NH 2
  568. \*(Ps Environments
  569. @.PP
  570. @.I Psfig 
  571. is possible because the \*(Ps imaging model 
  572. allows the creation of nested, protected environments by transforming the
  573. coordinate system and redefining certain system operators.
  574. For example, it is very easy to take a figure that filled an
  575. entire 8\(12" by 11" page and cause it to instead be printed in a
  576. box one inch square in the lower right hand corner of the
  577. page. \*(Ps can do this because all graphical operations are performed
  578. relative to the current transformation matrix (CTM), a homogeneous
  579. transform that establishes the scale, position and orientation of the
  580. coordinate system relative to the physical page. 
  581. Using the eight parameters mentioned we can calculate the translation and
  582. scaling of the coordinate system needed to move a figure from its natural 
  583. position to its desired position.
  584. @.\"
  585. @.PP
  586. Given the bounding box and the desired location and size for a figure, the 
  587. translation and scaling needed to cause the figure to be printed at the
  588. desired location is done in three steps:
  589. @.IP \(bu
  590. scale horizontally by desired
  591. width divided by old width
  592. @.IP \(bu
  593. scale vertically by desired
  594. height divided by old height
  595. @.IP \(bu
  596. translate the upper left hand
  597. corner of the figure's bounding 
  598. box to the current point.
  599. @.PP
  600. \*(Ps also gives us the tools necessary to insure that any side effects of a 
  601. figure do not affect the rest of the document. The \*(Ps operators 
  602. @.Ex save
  603. and
  604. @.Ex restore
  605. effectively undo the side effects of any code executed between them.
  606. @.I Psfig
  607. brackets all figures with these operators to protect the document.
  608. The environment in which the \*(Ps code for a figure is executed places
  609. no restrictions on the commands which may be used, so any well formed
  610. (and non-hostile) \*(Ps file can be included as a figure. 
  611. The \*(Ps operators 
  612. @.Ex showpage ,
  613. @.Ex initgraphics ,
  614. @.Ex initmatrix ,
  615. and
  616. @.Ex defaultmatrix
  617. are locally redefined for the figure so they behave in a rational
  618. way. For example 
  619. @.Ex initgraphics
  620. first performs a `regular' initgraphics, but then restores the current
  621. transformation matrix (CTM) to the one we created for the figure.
  622. The redefinition of
  623. @.Ex showpage
  624. is simply to do nothing. It is expected that no multi-page \*(Ps files will be 
  625. included as figures, so this redefinition really amounts to ignoring any 
  626. @.Ex showpage
  627. that may appear at the end of the figure.
  628. @.NH 1
  629. The Preprocessor
  630. @.PP
  631. The
  632. @.I psfig
  633. preprocessor is responsible for the interface seen by the user. Essentially
  634. it translates a higher-level syntax into file inclusion and 
  635. literal \*(Ps calls which are passed though \*(Dt and interpreted by the 
  636. postprocessor.
  637. Like the other \*(Tr preprocessors, 
  638. @.I psfig
  639. interprets those portions of the file that are marked as its input. This input 
  640. it translates into raw \*(Tr code. All other portions of the file are passed 
  641. directly through to the output, to be interpreted further down the line.
  642. @.PP
  643. The basic 
  644. @.I psfig
  645. command to include a figure is the optional keyword
  646. @.Ex figure ,
  647. followed by the name of a file containing a \*(Ps program, followed by
  648. any number of optional clauses. Some common clauses are:
  649. @.DS I \n(PIu        \" Indent by the standard amount
  650. @.Ex "height " \c
  651. @.I " h"
  652. @.Ex "width " \c
  653. @.I " w"
  654. @.Ex "bounds " \c
  655. @.I " llx lly urx ury"
  656. @.DE
  657. which specify the size of the desired figure, and the bounding box of the
  658. original figure. 
  659. As promised, if there is no
  660. @.Ex bounds 
  661. clause for a figure, 
  662. @.I psfig
  663. scans the \*(Ps file for the bounding box comment, and will also
  664. compute the height and width using the defaults discussed earlier.
  665. @.PP
  666. @.I Psfig
  667. also provides an lower level interface with the
  668. @.Ex file
  669. and 
  670. @.Ex literal
  671. commands, which provide direct file and literal \*(Ps inclusion, respectively.
  672. Finally, a 
  673. @.Ex global
  674. option is available on 
  675. @.Ex file
  676. and
  677. @.Ex literal
  678. to download code that will remain present across the 
  679. @.Ex save
  680. and 
  681. @.Ex restore
  682. context normally surrounding each \*(Dt page.
  683. @.PP
  684. In the simplest usage then, one need only specify the name of a 
  685. file containing \*(Ps to include a figure, and 
  686. @.I psfig 
  687. will perform a default set of ``reasonable'' actions.
  688. @.PP
  689. The full input syntax is included in Appendix A.
  690. @.NH 1
  691. \*(Dt and Postprocessor Hooks
  692. @.PP
  693. The preprocessor bears the brunt of making things look and act in a
  694. well behaved manner, but the real work is done in the postprocessor
  695. and its \*(Ps prolog files.
  696. @.PP
  697. @.I Psfig
  698. uses the \*(Dt 
  699. @.Ex \eX
  700. command to pass commands through to the postprocessor. An input sequence of 
  701. @.Ex
  702. \eX'test'
  703. @.En
  704. will come through \*(Dt as
  705. @.Ex
  706. x X test
  707. @.En
  708. We used 
  709. @.I psdit ,
  710. the \*(Dt to \*(Ps translator supplied with TranScript from Adobe Systems as
  711. our postprocessor. We added two primitives that we call through
  712. @.Ex \eX :
  713. @.DS I \n(PIu
  714. @.Ex \eX'f \c
  715. @.I " filename" \c
  716. @.Ex '
  717. @.Ex \eX'p \c
  718. @.I " literal \*(Ps" \c
  719. @.Ex '
  720. @.DE
  721. The former interpolates the contents of
  722. @.I filename
  723. into the \*(Ps output
  724. @.I psdit ,
  725. while the latter injects 
  726. @.I "literal \*(Ps" .
  727. In passing literal arguments, we trick \*(Dt into
  728. evaluating dimension expressions for us
  729. by enclosing our expression in 
  730. @.Ex \ew'\eh' \c
  731. @.I expr \c
  732. @.Ex '' .\(dg
  733. @.FS \(dg
  734. This \*(Tr incantation asks for the
  735. overall width of a string that is nothing but a relative horizontal motion by
  736. @.I expr .
  737. @.FE
  738. This will evaluate to the value of 
  739. @.I expr
  740. in device units.
  741. All scaling computation is done in this way, since the
  742. preprocessor can not know the value of \*(Tr variables, which
  743. may well be used in expressions. This also means the preprocessor
  744. need not know anything about \*(Tr dimensions, and users can specify dimensions
  745. in the same ways they always have.
  746. Inside
  747. @.I psfig ,
  748. the computation is manipulated in an algebraic manner, and is finally
  749. evaluated when it passes through 
  750. @.Ex \eX .
  751. @.NH 1
  752. Putting it all Together
  753. @.PP
  754. Now we can examine exactly how we create the nested and protected 
  755. environment.
  756. We perform a simple figure inclusion in three steps:
  757. @.IP \(bu
  758. Using 
  759. @.I psdit 's
  760. new literal pass through command, construct a call to a `startFig'
  761. \*(Ps function that we 
  762. have included in the prolog prepended to all \*(Ps files from 
  763. @.I psdit .
  764. The startFig
  765. function takes the desired height and width, and natural bounding
  766. box as arguments, issues a 
  767. @.Ex save ,
  768. performs the necessary transformations of
  769. the graphics state, then redefines system operators as needed.
  770. @.IP \(bu
  771. Using 
  772. @.I psdit 's
  773. file inclusion command, copy the figure file into the output stream.
  774. @.IP \(bu
  775. Using literal, call our `endFig' \*(Ps function that undoes the effects
  776. of `startFig'. EndFig needs no arguments.
  777. @.PP
  778. So, to show a small example, if we had a \*(Ps figure in a file
  779. @.Ex smiley.ps
  780. that contained the code:
  781. @.\"
  782. @.Ex
  783. %!
  784. %%BoundingBox: 0 0 36 36
  785. newpath 18 18 10 0 360 arc stroke % head
  786. newpath 18 18 6 180 360 arc stroke% mouth
  787. newpath 22 22 .5 0 360 arc stroke % eyes
  788. newpath 14 22 .5 0 360 arc stroke
  789. showpage
  790. @.En
  791. and 
  792. @.I psfig
  793. was processing the \*(Tr source fragment:
  794. @.Ex
  795. for a happy document!
  796. \&.F+
  797. figure smiley.ps 
  798. \&.F-
  799. \&.NH 1
  800. What is a Figure?
  801. @.En
  802. @.I psfig
  803. would translate `
  804. @.Ex "figure smiley.ps" '
  805. into a series of
  806. @.Ex \eX
  807. calls which would cause the following \*(Ps output from 
  808. @.I psdit :
  809. @.DS I \n(PIu        \" Indent by the standard amount
  810. @.Ex "760 4512(happy)N 976(document!)X"
  811. @.Ex "1422 4560 MXY"
  812. @.Ex "288 288 0.00 0.00 36.00 36.00 startFig"
  813. @.I "...contents of smiley.ps..."
  814. @.Ex "endFig"
  815. @.Ex "3 f 760 5040(6.)N"
  816. @.Ex "860(What)X 1071(Is)X 1153(A)X"
  817. @.Ex "1231(Figure?)X
  818. @.DE
  819. The height and width are the first arguments to 
  820. @.Ex startFig ,
  821. and are in \*(Dt device units, followed by the natural bounding box
  822. of the figure in points.
  823. @.Ex startFig
  824. will convert the height and width into points, then
  825. perform the computation outlined above.
  826. And all this makes for a happy document!
  827. @.F+
  828. smiley.ps
  829. @.F-
  830. @.NH 1
  831. What Is A Figure?
  832. @.PP
  833. Since figures are simply \*(Ps files, 
  834. @.I psfig
  835. allows dozens of utilities to be figure tools. Most graphical tools
  836. either directly produce \*(Ps, or produce an output language (such as
  837. Tektronix 4014, and Unix plot) that
  838. can be translated into \*(Ps using available filters. 
  839. @.NH 2
  840. Figure Requirements
  841. @.PP
  842. Of course, in addition to the \*(Ps information about the appearance of the 
  843. figure, 
  844. @.I psfig
  845. will need some information about the figure that it can use for computing the
  846. size of the figure.
  847. The only requirement on a figure is that it produce valid \*(Ps code, 
  848. and that it contain a
  849. @.Ex %%BoundingBox
  850. comment as described in Adobe's Document Structuring Conventions.
  851. @.I Psfig
  852. insures that a figure is actually \*(Ps by checking that the first two 
  853. characters in the file are `%!'.
  854. @.PP
  855. Note that the mere presence of the proper identifying characters and a
  856. bounding box comment will not insure a figure will behave properly.
  857. There are many ways a \*(Ps program could fail in a
  858. @.I psfig
  859. environment, from having an erroneous bounding box, to causing a \*(Ps error
  860. when executed, to circumventing
  861. @.I psfig 's
  862. redefinition of system operators, to using operators that haven't
  863. been protected by 
  864. @.I psfig ,
  865. such as
  866. @.Ex exitserver .
  867. As with most trap door mechanisms that allow arbitrary information to pass 
  868. through a processor, 
  869. @.I psfig
  870. has little choice but to trust the figures it deals with. It makes some minimal
  871. checks that catch the most blatant problems, but it cannot do more than that.
  872. @.NH 2
  873. Encapsulated \*(Ps
  874. @.PP
  875. Recently Adobe has addressed the issue of \*(Ps programs that 
  876. are designed explicitly for use as included figures, and have established an 
  877. @.I "Encapsulated \*(Ps File Format" .
  878. Part of 
  879. this standard deals with file formats for dual bitmap/\*(Ps representations,
  880. primarily for Macintosh and MS-DOS applications, and
  881. is not important for this discussion. Other parts, however, present
  882. guidelines for safe \*(Ps code that can be imported into documents,
  883. and they outline some of the techniques that are used by 
  884. @.I psfig
  885. to set up a nested environment. The standard does not assume any operator
  886. redefinition other than 
  887. @.Ex showpage ,
  888. and it provides a list of operators that seriously disturb the state
  889. of the interpreter, and are forbidden in conforming EPSF programs:
  890. @.F+
  891. delim
  892. @.F-
  893. @.sp .1i
  894. @.TS
  895. center box;
  896. cfB s 
  897. cfB s
  898. _ _
  899. l l.
  900. Operators to avoid in 
  901. imported files (EPSF 1.3)
  902.  
  903. exitserver    initgraphics
  904. initmatrix    initclip
  905. erasepage    copypage
  906. grestoreall    framedevice
  907. setpageparams    banddevice
  908. nulldevice    renderbands
  909. note
  910. @.TE
  911. @.sp .1i
  912. @.F+
  913. delim ##
  914. @.F-
  915. In particular, only operators documented in the body (that is, not an 
  916. appendix) of
  917. @.I "\*(Ps Language Reference Manual" 
  918. (commonly known as the Red Book) should be used since the availability of any
  919. others cannot be guaranteed in all \*(Ps implementations.
  920. In general, any \*(Ps file used with
  921. @.I psfig
  922. should conform as closely as possible to the EPSF specification.
  923. Note that even though
  924. @.Ex initgraphics
  925. and
  926. @.Ex initmatrix
  927. are redefined for
  928. @.I psfig
  929. figures, their use is discouraged.
  930. @.\"
  931. @.\" We don't need this editorial: It's off our point.
  932. @.\"
  933. @.\".NH 2
  934. @.\"Macintosh Woes
  935. @.\".PP
  936. @.\"For better or worse, the Apple Macintosh is one of the most popular
  937. @.\"vehicles for creating \*(Ps drawings and diagrams.
  938. @.\"Unfortunately, Apple has chosen to make getting the \*(Ps from
  939. @.\"applications such as MacDraw no easy task.
  940. @.\"MacDraw doesn't produce pure \*(Ps, relying on a collection
  941. @.\"of procedures defined in a prolog which, in an AppleTalk environment,
  942. @.\"is always loaded into the printer.
  943. @.\"Since we use our printers for more than Macintosh applications, we must
  944. @.\"download the prolog file with each job that requires it.
  945. @.\"Methods for dealing with Mac figures are given in \(sc 7.7.
  946. @.\"Note that Apple seems to change the contents of this prolog with
  947. @.\"each new LaserWriter driver, so in general a file captured from one
  948. @.\"Mac will not print using a prolog captured from another Mac.
  949. @.\"Worse, certain recent version of the LaserWriter driver produce
  950. @.\"\*(Ps that causes problems with operator redefinition. Thumbs
  951. @.\"down to Apple for for yet another closed system.
  952. @.\"
  953. @.NH 1
  954. Tutorial
  955. @.\ This section to be taken largely verbatim from existing paper
  956. @.NH 2
  957. \*(Tr Interface
  958. @.PP
  959. Like the other \*(Tr preprocessors, 
  960. @.I psfig
  961. passes most of its input through to its output untouched.
  962. Only text that is marked as a 
  963. @.I psfig
  964. command is interpreted.
  965. @.PP
  966. There are a number of ways to mark
  967. @.I psfig
  968. commands in your \*(Tr document.
  969. The first is to enclose them between
  970. @.Ex .F+
  971. and
  972. @.Ex .F- :
  973. @.DS I \n(PIu
  974. @.Ex ".F+"
  975. @.I "psfig commands"
  976. @.Ex ".F-"
  977. @.DE
  978. This is precisely equivalent to 
  979. @.I eqn 's
  980. @.Ex .EQ
  981. and
  982. @.Ex .EN :
  983. The 
  984. @.Ex .F+
  985. and
  986. @.Ex .F-
  987. lines are copied through to the output so that macro packages can do
  988. some action before or after figures.
  989. Any arguments to 
  990. @.Ex .F+
  991. or
  992. @.Ex .F-
  993. are copied through to the output but are otherwise ignored.
  994. In our definitions of these macros, 
  995. @.Ex .F+
  996. and
  997. @.Ex .F-
  998. provide a displayed figure centered in the line, and giving
  999. @.Ex .F+
  1000. an argument of
  1001. @.Ex L
  1002. will leave the figure left flush.
  1003. @.PP
  1004. Like
  1005. @.I eqn ,
  1006. @.I psfig
  1007. has the ability to read commands from within a \*(Tr line.
  1008. The
  1009. @.Ex delim
  1010. command specifies two characters that will delimit
  1011. @.I psfig
  1012. commands:
  1013. @.Ex
  1014. \&.F+
  1015. delim @@
  1016. \&.F-
  1017. @.En
  1018. Any text that falls between the two characters specified will be
  1019. interpreted as commands by 
  1020. @.I psfig .
  1021. In-line commands are most useful for generating special characters like the
  1022. pretzel in the abstract, because they don't cause a break in the text.
  1023. One restriction: an in-line command must not be broken across two lines.
  1024. @.PP
  1025. @.NH 2
  1026. Command Structure
  1027. @.PP
  1028. @.I Psfig
  1029. commands consist of words separated by white space (spaces, tabs, or
  1030. newlines).
  1031. Some words, like
  1032. @.Ex figure
  1033. and
  1034. @.Ex space
  1035. are reserved words, and mean something to 
  1036. @.I psfig ,
  1037. while others, like
  1038. @.Ex rosette.ps
  1039. and
  1040. @.Ex \en(.lu
  1041. are assumed to mean something to someone else. (In this case, the file system
  1042. and \*(Tr).
  1043. @.PP
  1044. A command that starts with a non-reserved word is assumed to be a 
  1045. @.Ex figure
  1046. command, so the word
  1047. @.Ex figure
  1048. can usually be omitted.
  1049. Semicolons are taken as command separators and can be used to avoid
  1050. ambiguities caused by the omission of a reserved word.
  1051. @.PP
  1052. Because non-reserved words aren't interpreted, they must be quoted if they
  1053. contain any characters that
  1054. @.I psfig
  1055. interprets specially.
  1056. Either single or double quotes may be used.
  1057. One exception: it is impossible for an in-line command to contain the closing
  1058. delimiter character, even if it is quoted.
  1059. @.NH 2
  1060. In-line Figures
  1061. @.PP
  1062. Figures that result from in-line 
  1063. commands are slightly different from figures created the other two ways.
  1064. First, whereas broken out figures have their top edge on
  1065. the current baseline and extend down,
  1066. in-line figures sit with their lower edge on the current
  1067. baseline, and extend up.
  1068. This facilitates the use of in-line figures to create custom characters like
  1069. the pretzel (#pretzel#).
  1070. For example, the last sentence ended with:
  1071. @.Ex
  1072. pretzel (@ pretzel.ps width 1.3n @).
  1073. @.En
  1074. The width here is specified in the \*(Tr unit 
  1075. @.Ex n ,
  1076. which is the width of a lower case `n' in the current point size.
  1077. Specifying a width this way makes the character the right size regardless of
  1078. the current text size:
  1079. @.DS I \n(PIu
  1080. @.ps 18
  1081. A larger pretzel: `# pretzel #'.
  1082. @.ps 10
  1083. @.DE
  1084. @.PP
  1085. Characters designed this way can be used anywhere a standard character can
  1086. be used:
  1087. @.EQ
  1088. sum from {i = 0 } to "# pretzel #" ^x sup "# pretzel #"
  1089. ^=^ 2 sin("#pretzel#")
  1090. @.EN
  1091. One hint for use with 
  1092. @.I eqn :
  1093. always enclose
  1094. @.I psfig
  1095. commands with quotes when inside
  1096. @.I eqn
  1097. commands.
  1098. For example, part of the above equation was created with
  1099. @.Ex
  1100. x sup "@ pretzel width 1.3n @"
  1101. @.En
  1102. @.sp \n(Nsu
  1103. @.PP
  1104. Another difference between in-line and broken out figures is that by default,
  1105. in-line figures don't reserve any vertical space, under the assumption that they
  1106. will fit within the current line anyway.
  1107. If your in-line figure is higher than anything else on the line, and you want
  1108. the space to be reserved, then add the word
  1109. @.Ex reserve
  1110. to your command.
  1111. If your figure isn't higher and you use
  1112. @.Ex reserve ,
  1113. the spacing will be wrong, so only use it if you need it.
  1114. @.NH 2
  1115. Macros
  1116. @.PP
  1117. @.I Psfig
  1118. provides a macro facility that is similar to
  1119. @.I eqn 's.
  1120. A command of the form:
  1121. @.Ex
  1122. define foo /bar/
  1123. @.En
  1124. will define a macro named 
  1125. @.Ex foo .
  1126. Any occurrence of the word
  1127. @.Ex foo
  1128. will now be replaced by the word
  1129. @.Ex bar .
  1130. The text of the macro is delimited by any character not included in the text
  1131. itself, and may be any sequence of characters, including any of the
  1132. characters that
  1133. @.I psfig
  1134. interprets specially.
  1135. @.PP
  1136. Macros can be useful for commonly used figures like in-line characters.
  1137. For example, this manual begins with the following lines:
  1138. @.Ex
  1139. \&.F+
  1140. delim @@
  1141. define wd /width/
  1142. define pretzel /pretzel.ps wd 1.3n/
  1143. \&.F-
  1144. @.En
  1145. and all the pretzels in the text were created with:
  1146. @.Ex
  1147. @@pretzel@
  1148. @.En
  1149. Remember that using a width specified in 
  1150. @.Ex n 's
  1151. gives us size independence, so that this macro will work in any environment
  1152. to give us the right size pretzel.
  1153. @.PP
  1154. Macro expansion is attempted for every word that 
  1155. @.I psfig
  1156. sees, unless it is quoted.
  1157. In particular, the name of a macro in a
  1158. @.Ex define
  1159. command is expanded if possible, so be careful about redefinitions.
  1160. The best policy is to always enclose the name in quotes:
  1161. @.Ex
  1162. define "wd" /width/
  1163. @.En
  1164. Macros in the text of a macro are expanded when the macro is expanded, not
  1165. when it is defined.
  1166. @.NH 2
  1167. Special Effects
  1168. @.PP
  1169. @.I Psfig
  1170. can also be used to provide interesting graphical effects.
  1171. @.PP
  1172. @.di Gb        \" Divert the Gray Box.
  1173. @.ll -2n
  1174. For example, this paragraph has been printed on a gray background.
  1175. We diverted the text of the paragraph, scaled a gray box to fit
  1176. around it, and then printed the text on top of the gray.
  1177. @.br
  1178. @.di
  1179. @.ll
  1180. @.F+ L
  1181. figure gray.ps
  1182.    height \n(dnu+1n
  1183.    width \n(.lu
  1184.    reserve 0 0
  1185. @.F-
  1186. @.nf    \" read diversions in no-fill.
  1187. @.sp -2p
  1188. @.in 1n
  1189. @.Gb    \" Get the text.
  1190. @.in
  1191. @.fi    \" back to fill mode.
  1192. @.PP
  1193. The command used to create the gray box on which the text sits was:
  1194. @.Ex
  1195. \&.F+ L
  1196. figure gray.ps
  1197.    height \\n(dnu+1n
  1198.    width \\n(.lu
  1199.    reserve 0 0
  1200. \&.F-
  1201. @.En
  1202. The file `gray.ps' draws a unit square filled with a light gray.
  1203. We specified the height to be a little bit more than the height of the
  1204. last diversion (the paragraph), and the width to be the same as the
  1205. width of a line.
  1206. @.PP
  1207. The
  1208. @.Ex reserve
  1209. clause tells \*(Tr how much space to reserve, here, none.
  1210. Normally, 
  1211. @.I psfig
  1212. has \*(Tr reserve the space taken by the figure so that it won't overlap
  1213. with anything else.
  1214. Here we want it to overlap, so we override the default, and have
  1215. \*(Tr reserve no space.
  1216. The
  1217. @.Ex L
  1218. on the line with
  1219. @.Ex .F+
  1220. overrides the default centering, so that the box is flush left.
  1221. @.NH 2
  1222. Raw \*(Ps
  1223. @.PP
  1224. In addition to specifying files to include into the \*(Dt output, you can
  1225. also specify literal \*(Ps text to be output.
  1226. The basic command is 
  1227. @.Ex
  1228. literal /text to be output/
  1229. @.En
  1230. The text (which is delimited by any character, just like the
  1231. text of
  1232. @.Ex define 
  1233. commands) will be inserted into the \*(Ps output without any
  1234. protection around it.
  1235. No macros are expanded in the literal text, but interpretation of \*(Tr
  1236. constructs is performed.
  1237. @.PP
  1238. Because there is no protection, you must be careful when writing
  1239. @.Ex literal s.
  1240. Any modifications you make to the state of the \*(Ps interpreter will linger
  1241. into the rest of your document.
  1242. Also keep in mind that the \*(Ps text is interpreted in the environment of your
  1243. document, not a special figure environment, so any output generated will
  1244. probably be wrong.
  1245. @.PP
  1246. Because of this,
  1247. literal text is really designed to be used as a way to output small amounts
  1248. of \*(Ps code to modify the way something else will work, rather than
  1249. generating output itself.
  1250. For example, the white on black effect in the abstract was produced in part by
  1251. bracketing the words `white on black' with some
  1252. @.Ex literal s
  1253. that change the color to white and then back to black:
  1254. @.Ex
  1255. @@ literal /1 setgray/ @
  1256. white on black
  1257. @@ literal /0 setgray/ @
  1258. @.En
  1259. @.sp \n(Nsu
  1260. @.PP
  1261. Another example of the use of 
  1262. @.Ex literal
  1263. is to modify the way lines are drawn by
  1264. @.I pic .
  1265. Normally, 
  1266. @.I pic 
  1267. allows simple dashed or dotted lines, but not complex dash patterns or
  1268. dashed splines.
  1269. By using 
  1270. @.Ex literal s
  1271. to change \*(Ps's dash parameter, you can achieve these effects:
  1272. @.Ex
  1273. \&.PS
  1274. define ps | box invis ht 0 wid 0 |
  1275. ps "@literal /[25 15] 0 setdash/@"
  1276. circle
  1277. ps "@literal /[20 15 40 15] 0 setdash/@"
  1278. spline right .5 \\
  1279.     then down .5 left .5 \\
  1280.     then right .5
  1281. ps "@literal /[] 0 setdash/@"
  1282. circle
  1283. \&.PE
  1284. @.En
  1285. produces
  1286. @.PS
  1287. define ps | box invis ht 0 wid 0 |
  1288. ps "#literal /[25 15] 0 setdash/#"
  1289. circle
  1290. ps "#literal /[20 15 40 15] 0 setdash/#"
  1291. spline right .5 \
  1292.     then down .5 left .5 \
  1293.     then right .5
  1294. ps "#literal /[] 0 setdash/#"
  1295. circle
  1296. @.PE
  1297. Notice that we used a 
  1298. @.I pic
  1299. macro called 
  1300. @.Ex ps
  1301. to hide the 
  1302. @.I psfig
  1303. commands.
  1304. @.PP
  1305. Another form of raw \*(Ps output is the
  1306. @.Ex file
  1307. command, which takes the named file and outputs it at the current point with
  1308. no protection.
  1309. No scaling or positioning is done, so in general, the file should not
  1310. produce any output, since it will not be able to predict its position on the
  1311. page.
  1312. @.NH 2 
  1313. Preludes And Postludes
  1314. @.PP
  1315. The main use for the raw output forms discussed in the last section is to
  1316. provide auxiliary information for a figure.
  1317. For example, let's suppose that you have a file named `fig.mac'
  1318. which contains some \*(Ps output from MacDraw.
  1319. Since Macintosh applications assume that the \*(Ps they generate will be
  1320. preceded by a header file (`mac.pro')
  1321. full of function definitions that the application
  1322. can make use of, fig.mac will not work properly without
  1323. the header.
  1324. One solution would simply be to modify fig.mac by copying the header file
  1325. into the beginning of it.
  1326. @.PP
  1327. Rather than force you to do that,
  1328. @.I psfig
  1329. provides you with a way to specify the relationship between fig.mac and
  1330. mac.pro.
  1331. Our current example would be specified like this:
  1332. @.Ex
  1333. figure fig.mac {
  1334.     file mac.pro
  1335.     figure
  1336. }
  1337. @.En
  1338. The braces enclose a list of things to be output in the order they should
  1339. appear.
  1340. We name the file `mac.pro' first, so it is output first.
  1341. Then the word
  1342. @.Ex figure
  1343. by itself means the figure named at the beginning of the command.
  1344. Both of these are enclosed in one environment.
  1345. An example of MacDraw output is at the top of the next page.
  1346. @.KW
  1347. @.F+
  1348. figure lab.ps {
  1349.     file /usr/lib/ps/mac.pro
  1350. } width 4.5i
  1351. @.F-
  1352. @.sp 
  1353. @.ce 99
  1354. @.B "Figure 2. " "Some sample MacDraw output."
  1355. @.ce 0
  1356. @.sp 
  1357. @.WE
  1358. @.PP
  1359. The list of things to output can be placed anywhere in the 
  1360. @.Ex figure 
  1361. command, even before the file name of the figure, and may contain any number
  1362. of entries, although the figure must be referred back to (by the word
  1363. @.Ex figure )
  1364. at most once.
  1365. The entries (aside from the
  1366. @.Ex figure )
  1367. can be either
  1368. @.Ex file s
  1369. or 
  1370. @.Ex literal s, 
  1371. and may appear either before or after the
  1372. @.Ex figure .
  1373. If the word
  1374. @.Ex figure
  1375. doesn't appear it is assumed to be the last item in the list.
  1376. @.PP
  1377. This mechanism provides a general way to modify the behavior of figures.
  1378. For example, a figure could be designed so that it reads arguments off
  1379. the \*(Ps stack, with a
  1380. @.Ex literal
  1381. providing them at run time:
  1382. @.Ex
  1383. figure takesargs.ps {
  1384.     literal /arg1 arg2/
  1385.     figure
  1386. }
  1387. @.En
  1388. Or perhaps you have a shape that you want outlined sometimes and filled
  1389. sometimes.
  1390. You can put the commands to create the path into a file called `logo.ps' and
  1391. then make use of a
  1392. @.Ex literal
  1393. after the figure to draw it:
  1394. @.Ex
  1395. figure logo.ps {
  1396.     figure
  1397.     literal /stroke/
  1398. }
  1399. @.En
  1400. @.sp \n(Nsu
  1401. @.PP
  1402. This feature can be coupled with the macro definition feature in a clever way.
  1403. If you are going to be dealing with many MacDraw figures, you could define a
  1404. macro:
  1405. @.Ex
  1406. define "macfig" /
  1407. figure {
  1408.         file mac.pro
  1409.         figure
  1410. }
  1411. /
  1412. @.En
  1413. and then simply say
  1414. @.Ex
  1415. macfig fig.mac
  1416. @.En
  1417. to include the figure.
  1418. @.NH 2
  1419. Global Data
  1420. @.PP
  1421. The above technique for including MacDraw documents points up a problem:
  1422. the header file will be downloaded for each figure that needs it.
  1423. Since the header file can be quite large (mac.pro is more than 25K bytes),
  1424. this could get quite wasteful.
  1425. @.PP 
  1426. One solution would be to download the header once, and then to just download
  1427. each figure separately.
  1428. This will work except that each \*(Dt page is an isolated environment, and
  1429. each page begins with the environment that the entire document began in.
  1430. The header file will be available to every figure on the page in which it was
  1431. downloaded, but will be lost when another page is started.
  1432. @.PP
  1433. @.I Psfig
  1434. provides a solution to this by allowing the user to modify the environment
  1435. in which pages are started.
  1436. The word 
  1437. @.Ex global
  1438. can be used to modify the
  1439. @.Ex file
  1440. or
  1441. @.Ex literal
  1442. commands, and they will be executed in such a way that their effects are
  1443. seen throughout the rest of the document.
  1444. @.PP
  1445. We can use
  1446. @.Ex global
  1447. to create a macro that does the work of loading the header for us:
  1448. @.Ex
  1449. define "macfig" |
  1450.     file mac.pro global;
  1451.     define "macfig" / figure /;
  1452.     figure
  1453. |
  1454. @.En
  1455. The first use of the macro downloads the header file, redefines
  1456. @.Ex macfig ,
  1457. and begins a figure command.
  1458. Other uses are then simply 
  1459. @.Ex figure
  1460. commands.
  1461. @.PP
  1462. Careful use of 
  1463. @.Ex global s
  1464. can produce interesting results, but care must be taken.
  1465. For example, because successive pages depend on
  1466. @.Ex global s
  1467. on previous pages, the pages of the document cannot be reversed and still
  1468. print properly.
  1469. @.NH 2
  1470. Clipping
  1471. @.PP
  1472. Normally, no clipping is done on figures; they are trusted to print only
  1473. within their declared bounding box.
  1474. If clipping is desired, the word
  1475. @.Ex clip
  1476. can be added to a
  1477. @.Ex figure
  1478. command, and the figure will be clipped to its bounding box.
  1479. @.NH 2
  1480. Draft Levels
  1481. @.PP
  1482. Because some \*(Ps figures can be expensive to print (half-toned
  1483. pictures, for example), and because documents designed to be printed on
  1484. \*(Ps printers may have to be printed on less capable printers, 
  1485. @.I psfig
  1486. allows the user to control the extent of the inclusion of figures.
  1487. Every figure has associated with it a `level', which should
  1488. correspond roughly to the cost of printing it.
  1489. When 
  1490. @.I psfig
  1491. processes a file, it runs at a certain level, and figures whose cost is less
  1492. than the current level get printed.
  1493. Broken out figures whose cost is more than the current level are omitted,
  1494. and a box is drawn around where they would be:
  1495. @.F+
  1496. rosette.ps height 1i level 9999
  1497. @.F-
  1498. The box has the name of the file in it for identification.
  1499. In-line figures are simply omitted, but the space they occupy is still
  1500. reserved by \*(Tr.
  1501. Here is a draft pretzel: `#pretzel level 9999#'.
  1502. Since a box takes less time to draw than a complicated figure, the careful
  1503. use of draft levels can speed up the printing of your document.
  1504. Also, the box is drawn with standard \*(Tr commands, so by setting
  1505. @.I psfig 
  1506. to run at the lowest level (so that it decides that all the figures are
  1507. too expensive), you'll get output that can be formatted by a generic \*(Tr
  1508. (not even \*(Dt is required!).
  1509. Of course, you won't have the figures, but the layout will be the same,
  1510. because the space has been reserved.
  1511. @.PP
  1512. The default level that 
  1513. @.I psfig 
  1514. runs at is 100.
  1515. In-line figures get a cost of 5 by default, and broken out figures get a cost
  1516. of 10.
  1517. To set the cost of a figure, simply tack on a
  1518. @.Ex level
  1519. clause.
  1520. The box above was made by:
  1521. @.Ex
  1522. rosette.ps height 1i level 9999
  1523. @.En
  1524. @.sp \n(Nsu
  1525. @.NH 1
  1526. Using Psfig
  1527. @.PP
  1528. Since 
  1529. @.I psfig
  1530. is a \*(Tr preprocessor in the classic style, it operates as a pure filter.
  1531. It can be used anywhere in the pipeline of preprocessors, but it is safest
  1532. if you run it last (just before \*(Tr).
  1533. The macro definitions of 
  1534. @.Ex .F+
  1535. and 
  1536. @.Ex .F-
  1537. must be included with the 
  1538. @.Ex -mpsfig
  1539. option on the \*(Dt command line.
  1540. For example, this paper was produced with the equivalent of:
  1541. @.Ex
  1542. pic | tbl | eqn | psfig | 
  1543. @.br
  1544. \ \ \ \ \ ditroff -mpsfig | psdit
  1545. @.En
  1546. @.sp \n(Nsu
  1547. @.PP
  1548. There are a few options that can be specified on the command line.
  1549. @.PP
  1550. @.Ex -d <level>
  1551. specifies the draft level to run at.
  1552. If <level> is omitted, then zero is assumed, causing all figures to be
  1553. omitted.
  1554. @.PP
  1555. @.Ex -f
  1556. specifies that \*(Dt codes should be output that work around a bug in \*(Dt
  1557. that was discovered during the development of
  1558. @.I psfig .
  1559. Broken out figures won't center properly with unfixed \*(Dt's without this
  1560. flag.
  1561. Also, special characters in
  1562. @.I eqn
  1563. won't work on these unfixed \*(Dt's, even with 
  1564. @.Ex -f .
  1565. @.PP
  1566. @.Ex -D <dir>
  1567. specifies a directory in which to search for files.
  1568. Any number of these can be specified, and they will be searched in turn.
  1569. The current directory is always searched first.
  1570. @.NH 1
  1571. Psfig/\*(Tx
  1572. @.PP
  1573. We have a package of similar functionality available for the \*(Tx
  1574. document preparation system. 
  1575. @.I Psfig/\*(Tx
  1576. uses no preprocessor, and is implemented entirely in \*(Tx macros,
  1577. using the
  1578. @.I dvips
  1579. postprocessor from ArborText. Files 
  1580. @.I are
  1581. scanned for the
  1582. @.Ex %%BoundingBox
  1583. comment,
  1584. but they are not checked to see that they conform to the structuring
  1585. convention (for example, the bounding box could be in the middle of the file,
  1586. rather than in the header or trailer as required by the convention).
  1587. The 
  1588. @.I psfig/\*(Tx
  1589. command
  1590. @.DS I \n(PIu
  1591. @.Ex "\epsfig{file=" \c
  1592. @.I "name, clause, clause,... " \c
  1593. @.Ex "}"
  1594. @.DE
  1595. is the equivalent of the
  1596. @.I psfig
  1597. command
  1598. @.DS I \n(PIu
  1599. @.Ex "figure " \c
  1600. @.I " name clause clause ..."
  1601. @.DE
  1602. The \*(Ps implementation of 
  1603. @.I psfig
  1604. and
  1605. @.I psfig/\*(Tx
  1606. are very similar, differing only in the scaling factors used to convert
  1607. \*(Dt or \*(Tx units into points, and in the code to implement
  1608. @.Ex global
  1609. (each post-processor has different variables that must be restored when
  1610. we return to the current save context.)
  1611. @.\ no in-line figures
  1612. @.NH 1
  1613. Getting Psfig
  1614. @.PP
  1615. Inquiries about 
  1616. @.I psfig
  1617. may be directed to trevor@linc.cis.upenn.edu, or
  1618. the U.S. mail address listed above.
  1619. @.I Psfig
  1620. will be available as part of future releases of the T\s-2RAN\s0S\s-2CRIPT\s0
  1621. package from Adobe, as well as through uucp/ftp distributions.
  1622. @.PP
  1623. @.NH 1
  1624. Acknowledgments
  1625. @.PP
  1626. We would like to thank: the University of Pennsylvania and in particular
  1627. Ira Winston for supporting and encouraging this work;
  1628. Brian Kernighan for helping gracefully with the internals of \*(Dt and 
  1629. for having written
  1630. @.I eqn
  1631. to guide us through the darkness; 
  1632. and Adobe Systems for having designed and implemented \*(Ps, which made it
  1633. all possible.
  1634. @.PP 
  1635. @.SH
  1636. A. Language Syntax
  1637. @.PP
  1638. @.I Psfig
  1639. recognizes these commands found between
  1640. @.Ex ".F+"
  1641. and 
  1642. @.Ex ".F-"
  1643. or in-line delimiters:
  1644. @.de Ds
  1645. @.sp
  1646. @.nf
  1647. @.in .5i
  1648. @..
  1649. @.de De
  1650. @.fi
  1651. @.sp
  1652. @.in -.5i
  1653. @..
  1654. @.Ds
  1655. [\c
  1656. @.Ex "figure" \c
  1657. ]\c
  1658. @.I " path " \c
  1659. [\c
  1660. @.I "clauses" \c
  1661. ] [\c
  1662. @.I "modifiers" \c
  1663. ]
  1664. @.\"
  1665. @.Ex "file " \c
  1666. @.I path \c
  1667. [\c
  1668. @.I "modifiers" \c
  1669. ]
  1670. @.\"
  1671. @.Ex "literal " \c
  1672. @.I "text " [\c
  1673. @.I "modifiers" ]
  1674. @.\"
  1675. @.Ex "space " \c
  1676. @.I dimen
  1677. @.\"
  1678. @.Ex "define " \c
  1679. @.I "word text"
  1680. @.\"
  1681. @.Ex "delim " \c
  1682. @.I "char" \c
  1683. [\c
  1684. @.I char ]
  1685. @.De
  1686. @.I Modifier 
  1687. is one or more of:
  1688. @.Ds
  1689. @.Ex "level " \c
  1690. @.I num 
  1691. @.Ex "global"
  1692. @.De
  1693. @.I Clauses
  1694. is one or more of:
  1695. @.Ds 
  1696. @.Ex "height " \c 
  1697. @.I "dimen"
  1698. @.Ex "width " \c
  1699. @.I "dimen"
  1700. @.Ex "bounds " \c
  1701. @.I "int int int int"
  1702. @.Ex "reserve " \c
  1703. @.I "dimen dimen" 
  1704. @.Ex "clip " 
  1705. { \c
  1706. @.I environment \c
  1707. }
  1708. @.De
  1709. @.LP
  1710. @.I Environment 
  1711. is a series of 
  1712. @.Ex file
  1713. and/or 
  1714. @.Ex literal
  1715. commands, and the keyword
  1716. @.Ex figure .
  1717. @.LP
  1718. @.I Path 
  1719. is a valid Unix file path.
  1720. @.LP
  1721. @.I Dimen 
  1722. is a \*(Tr expression that will evaluate to a length.
  1723. @.LP
  1724. @.I Text
  1725. is any string of characters which is delimited by a single character, and
  1726. does not contain that character.
  1727. @.PP
  1728. The path, clauses, and modifiers of a figure command may be present in
  1729. any order.  Whitespace is ignored (except that in-line commands may not
  1730. cross lines), and semicolons optionally separate commands.
  1731. @.sp
  1732. @.F+
  1733. delim
  1734. @.F-
  1735. @//E*O*F trf/doc/paper.ms//
  1736. chmod u=rw,g=r,o=r trf/doc/paper.ms
  1737.  
  1738. echo x - trf/doc/paper.tmac
  1739. echo YOU WILL HAVE TO CHANGE 30 ^G\'s TO REAL BELL\'s IN THIS FILE!
  1740. sed 's/^@//' > "trf/doc/paper.tmac" <<'@//E*O*F trf/doc/paper.tmac//'
  1741. @.\" myms --
  1742. @.\" Modifications to the -ms macros.
  1743. @.\" N.Batchelder
  1744. @.\"
  1745. @.    \" UX - UNIX macro
  1746. @.de UX
  1747. @.ie \\n(UX \s-1UNIX\s0\\$1
  1748. @.el \{\
  1749. \s-1UNIX\s0\\$1\**
  1750. @.FS
  1751. \s-1UNIX\s0 is a trademark of AT&T Bell Laboratories.
  1752. @.FE
  1753. @.nr UX 1
  1754. @.\}
  1755. @..
  1756. @.    \" I - italic font
  1757. @.de I
  1758. @.nr PQ \\n(.f
  1759. @.if t .ft 2
  1760. @.ie ^G\\$1^G^G .if n .ul 999
  1761. @.el .if n .ul 1
  1762. @.if t .if !^G\\$1^G^G \&\\$1\^\f\\n(PQ\\$2
  1763. @.if n .if \\n(.$=1 \&\\$1
  1764. @.if n .if \\n(.$>1 \&\\$1\c
  1765. @.if n .if \\n(.$>1 \&\\$2
  1766. @..
  1767. @.    \" TY - typewriter font
  1768. @.de TY
  1769. @.nr PQ \\n(.f
  1770. @.if t .if ^G\\$1^G^G .ft CB
  1771. @.if t .if !^G\\$1^G^G \&\f(CB\\$1\f\\n(PQ\\$2
  1772. @.if n .if !^G\\$1^G^G \&\\$1\\$2
  1773. @..
  1774. @.    \" SC - a little smaller (for Small Caps)
  1775. @.de SC
  1776. @.nr PQ \\n(.s
  1777. @.if t .ps -1
  1778. @.if t .if !^G\\$1^G^G \&\\$1\s\\n(PQ\\$2
  1779. @.if n .if \\n(.$=1 \&\\$1
  1780. @.if n .if \\n(.$>1 \&\\$1\c
  1781. @.if n .if \\n(.$>1 \&\\$2
  1782. @..
  1783. @.    \" PS & PE -- the default macros that came with the source.
  1784. @.de PS    \" start picture
  1785. @.    \" $1 is height, $2 is width, both in inches
  1786. @.if t .sp .3
  1787. @.in (\\n(.lu-\\$2)/2u
  1788. @.ne \\$1
  1789. @..
  1790. @.de PE    \" end of picture
  1791. @.in
  1792. @.if t .sp .6
  1793. @..
  1794. @.lg off        \" they don't work right
  1795. @.nr PO 1.32i    \" center it.
  1796. @.\"    An attempt to add full width floating keeps to -ms two column mode.
  1797. @.de HD
  1798. @.if \\n(W? \{\
  1799. @.    rn NP @@
  1800. @.    ev 1
  1801. @.    nf
  1802. @.    ls 1
  1803. @.    in 0
  1804. @.    W>
  1805. @.    rm W>
  1806. @.    nr W? 0
  1807. @.    br
  1808. @.    in
  1809. @.    ls
  1810. @.    fi
  1811. @.    ev
  1812. @.    rn @@ NP \}
  1813. @..
  1814. @.de KW        \" Wide keep. Floats to the top of the next page.
  1815. @.nr KN \\n(.u
  1816. @.if !\\n(IK .if \\n(NX>1 .W!
  1817. @.if !\\n(IK .if \\n(NX<=1 .FQ
  1818. @.nr IK +1
  1819. @..
  1820. @.    \" W! - process wide keeps (modified from FQ).
  1821. @.de W!
  1822. @.nr KI \\n(.i            \" Save the indent
  1823. @.ev 2
  1824. @.TA
  1825. @.br
  1826. @.in \\n(KIu
  1827. @.ps \\n(PS
  1828. @.if \\n(VS>=40 .vs \\n(VSu
  1829. @.if \\n(VS<=39 .vs \\n(VSp
  1830. @.ll \\n(LLu
  1831. @.lt \\n(LTu
  1832. @.di W>        \" Get the real thing into W>
  1833. @.nr W? 1
  1834. @.. \" end of WQ
  1835. @.nr W? 0
  1836. @.\"    WE - end wide keep.
  1837. @.de WE
  1838. @.if \\n(IK .if !\\n(IK-1 .if !\\n(IF .W.
  1839. @.if \\n(IK .nr IK -1
  1840. @..
  1841. @.    \" W. - real wide release
  1842. @.de W.
  1843. @.br
  1844. @.di
  1845. @.nf
  1846. @.rs
  1847. @.ce 0
  1848. @.if \\n(KN .fi            \" Restore fill state.
  1849. @.ev
  1850. @..
  1851. @.\" psfig.mac -- definitions for the psfig paper.
  1852. @.tr \(ui 
  1853. @.if t .ds Ps "P\s-2OST\%\s0S\s-2CRIPT\s0
  1854. @.if t .ds Tr "T\s-2ROFF\s0
  1855. @.if t .ds Dt "D\s-2ITROFF\s0
  1856. @.if n .ds Ps "Post\%Script
  1857. @.if n .ds Tr "Troff
  1858. @.if n .ds Dt "Ditroff
  1859. @.if t .ds Nr "N\s-2ROFF\s0
  1860. @.if n .ds Nr "Nroff
  1861. @.if t .ds Tx "T\h'-.2m'\v'.5n'E\v'-.5n'\h'-.06m'X
  1862. @.if n .ds Tx "TeX
  1863. @.\"
  1864. @.de Ex        \" Start an example
  1865. @.if !^G\\$1^G^G .if t \&\s8\z\(ui\H'10'\f(CB\\$1\s0\z\(ui\H'0'\fP\\$2
  1866. @.if !^G\\$1^G^G .if n \&`\\$1'\\$2
  1867. @.if ^G\\$1^G^G \{\
  1868. @.    DS I \\n(PIu
  1869. @.    ft CB
  1870. @.    ps 8
  1871. @.    nf
  1872. \z\(ui\H'10'\c
  1873. @.    eo\}
  1874. @..
  1875. @.de En        \" End an example
  1876. @.ec
  1877. @.fi
  1878. @.ps 10
  1879. @.R
  1880. @.DE
  1881. \z\(ui\H'0'\c
  1882. @..
  1883. @.if t .nr PI .2i
  1884. @.if n .nr PI 5n
  1885. @.\" psfig macros. An argument will turn off centering.
  1886. @.de F+
  1887. @.br
  1888. @.nr F, \\n(.u
  1889. @.nf
  1890. @.if ^G\\n(.z^G^G .sp -.5
  1891. @.if \\n(.$=0 .ce 9999
  1892. @..
  1893. @.de F-
  1894. @.ce 0
  1895. @.if \\n(F, .fi
  1896. @.br
  1897. @..
  1898.  
  1899. @//E*O*F trf/doc/paper.tmac//
  1900. chmod u=rw,g=r,o=r trf/doc/paper.tmac
  1901.  
  1902. echo Inspecting for damage in transit...
  1903. temp=/tmp/shar$$; dtemp=/tmp/.shar$$
  1904. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  1905. cat > $temp <<\!!!
  1906.       58     146     930 Makefile
  1907.       28      84     507 dopaper
  1908.       18      54     296 getpages
  1909.     1591    7823   44021 paper.ms
  1910.      158     567    2712 paper.tmac
  1911.     1853    8674   48466 total
  1912. !!!
  1913. wc  trf/doc/Makefile trf/doc/dopaper trf/doc/getpages trf/doc/paper.ms trf/doc/paper.tmac | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  1914. if [ -s $dtemp ]
  1915. then echo "Ouch [diff of wc output]:" ; cat $dtemp
  1916. else echo "No problems found."
  1917. fi
  1918. exit 0
  1919.