next up previous contents
Next: Other Tricks Up: Pretty Pictures Previous: LATEX picture Environment

Including PostScript Files

In general you are better off using a drawing program designed for the device you will be printing on, and then using the \special command (or the \PSbox macro below) to include a file.22

If you are using a program which generates Encapsulated PostScript Files, you can simply use the epsf package, and then say

\epsfbox{filename.eps}
at the place where you want the figure. This automatically reserves space for the PostScript picture based on the size stored in it. See the dvips man page or one of the LATEX books for more details.

To include a non-Encapsulated PostScript file (i.e. one written by hand or by certain drawing programs):

1.
Include the following line before the \begin{document}. Most of the magic is needed so that LaTeX knows how big the document is, so that it can reserve space for the PostScript figure for proper placement and spacing.

\newcommand{\PSbox}[3]{\mbox{\special{psfile=#1}\hspace{#2}\rule{0pt}{#3}}}

2.
If possible, generate the PostScript file such that the picture is flush against the bottom-left corner. When you do this, the left-most $\frac{1}{4}$ inch of the picture may not be printed, since although (0,0) is at the lower-left hand corner of the page, on some printers the left most $\frac{1}{4}$ inch part of the page isn't part of the image area. Don't worry about it--the missing part should be visible when LATEX moves it back onto the page.

3.
Print out the PostScript file. There are two reasons for doing this. The first is to make sure that there aren't any errors in the PostScript. The second reason is to get the dimensions of the picture and where it is located on the page. Measure the height and the width of the picture. Also, if the picture is not located in the lower-left-hand corner, measure the (x,y) distance from the lower-left-hand corner of the page to lower-left-hand corner of the graphic in inches. The psbb program in the gnu locker can also be useful for determining the size and offset of a postscript picture.

4.
To do the actual inclusion, do step (a) if the image is in the lower left corner of the page. Otherwise do step (b).

(a)
If the PostScript file has the image in the lower-left-hand corner of the page, it's really easy. At the point where you want the picture to be included, just use the following command:

\PSbox{/mit/username/filename.PS}{1.7in}{0.25in}

Where the first argument is the filename of the PostScript file, the second is the width of the graphic, and the third argument is the height of the graphic. The dimensions can be specified in any format that LaTeX accepts. So, for example, a dimension such as ``4cm'' will also work.

This ``PSbox'' can be included in a figure, or anything else you want!

(b)
If you were unfortunate enough as to be unable to get the graphic in the lower-left-hand corner, you will need to do a bit more work. Take the distance from the left-hand side of the page (which you measured in inches, right?) and multiply by -72. Call this number the ``hoffset''. Take the distance from the bottom of the page to the bottom of the graphic (also measured inches), multiply it by -72, and call it the ``voffset''. Then the PSbox command should be modified to be:
\PSbox{/mit/username/filename hoffset=hoffset voffset=voffset}{width}{length}

For example, to include a file which is 4 inches high and 5 inches wide, which is located 3 inches from the bottom of the page and 2 inches from the left side of the page, the PSbox would be:

\PSbox{/mit/username/filename.PS hoffset=-144 voffset=-216}{5in}{4in}

NOTE: xdvi cannot show included PostScript figures; instead, it leaves a blank space of the correct size. Xdvi will also print a warning that says `xdvi: special ``filename'' not implemented' every time you preview a page with a PostScript figure on it. This is nothing to worry about--it's just reminding you that it can't preview the PostScript figure--it should still print out without any problems. The version of xdvi currently installed in the sipb and newtex lockers can preview PostScript figures, either using the native Display PostScriptfeatures (default), or by rendering the image through another program first (the ``-nodps'' option). This feature still has some problems, and in some circumstances X server bugs could caused you to be logged out without warning. As always, we recommend that you save your files early and often.

If you want to see where the PostScript picture will appear, you can change the \mbox in the definition of \PSbox to \fbox. In other words, you'd change the line

\newcommand{\PSbox}[3]{\mbox{\special{psfile=#1}\hspace{#2}\rule{0pt}{#3}}}

in your document to be:

\newcommand{\PSbox}[3]{\fbox{\special{psfile=#1}\hspace{#2}\rule{0pt}{#3}}}
Assuming that you have specified the arguments to \PSbox correctly, this will result in a box being drawn around the area where the PostScript image will appear. However, when you print your LATEX document, the box will appear on the printed output as well. You will need to change the \fbox back to \mbox and run LATEX again on your file to make the box go away when you want to print your final copy.



 
next up previous contents
Next: Other Tricks Up: Pretty Pictures Previous: LATEX picture Environment
Alex Rolfe
1999-10-29