Access Keys:
Skip to content (Access Key - 0)

How do I include Postscript graphics in a LaTeX file?

On this page:

Overview

Postscript files can easily be included and scaled in LaTeX documents. For encapsulated postscript files (.eps, .epsi), the easiest method uses the epsf style, and is described below.

On the other hand, if your postscript file is not encapsulated, and does not contain a bounding box, you have two choices:

  • you may convert it to an .eps file using the ps2epsi converter in the gnu locker. This command
    athena% add gnu
    athena% ps2epsi file.ps 

    will create file.epsi

  • you may use the PSbox macros in the consult locker, and follow the second set of directions below.

Using epsf

  1. Add the line
    	\usepackage{epsf} 

    to the beginning of your document, after the \documentclass line.

  2. When you want to include the .eps file, use the
    \epsfbox{filename.eps}

    command. You can scale the postscript file by using either \epsfxsize=width or \epsfysize=height to specify a width or height; the other dimension will be scaled accordingly. You must include the \epsfxsize or \epsfysize command before the \epsfbox; otherwise you'll be scaling the next figure.

  3. If you need to center the file and are getting error messages, enclose it in an \mbox:
       
    \begin{center}
    \mbox{\epsfbox{filename.eps}}
    \end{center}
    

Using psbox

  1. First, you need to copy two "style files" into the same directory as your latex files. To do this, change into the same directory as your latex files, and then type:
    	attach consult
    	cp /mit/consult/lib/tex/macros/ps*.sty .
    

    Alternately, you can add the path /mit/consult/lib/tex/macros/ to your TEXINPUTS; a line in your .environment file such as

    setenv TEXINPUTS .:/mit/sipb/share/tex/macros:/mit/consult/lib/tex/macros/:
    

    will include the LaTeX styles in both the consult and sipb lockers, in addition to the default styles (don't forget the ":" at the end!). Note that sipb and consult must be attached in order for these paths to work.

  2. Under Latex2e (the default), add the following line after your \documentclass line:
       
          \usepackage{psbox}	
    
  3. If possible, generate the postscript file such that the picture is flush against the lower-left-hand corner. (For example, if idraw is being used, group the entire picture and move it to the lower-left-hand corner of the page. If it is a raw postscript file, add an appropriate translate command, if you know how.) When you do this, the left most 1/4" of the document may not be printed, since although (0,0) is at the lower-left hand corner of the page, on some printers the left most 1/4" part of the page isn't part of the image area. Don't worry about it.
  4. 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 graphic. Also, if the graphic is not located in the lower-left-hand corner, measure the (x,y) distance from the lower-left-hand corder of the page to lower-left-hand corner of the graphic IN INCHES.
    NOTE If your postscript file was created in Xfig, make sure that it does not use "fills", as these do not come out correctly when used with dvips on the Athena printers (they come out as solid colors as opposed to shades or cross-hatched patterns).
  5. Include the Postscript file
    1. 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 centered, included in a figure, or anything else you want!

    2. If you were unfortunate enough as to be unable to get the graphic in the lower-left-hand corner, all is not lost. However, 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 form 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}
      
  6. You can also shrink and scale your postscript figures. For example, if you wanted to include your figure shrunk by half in each direction, you would used:
    	\PSbox{/mit/username/filename.PS hscale=50 vscale=50}{2.5in}{2in}
    

    (with the dimensions being the size of the figure once it has been scaled to half size in each direction). Scale values are in percent. Note that it's possible to shrink your figure in one direction and not the other; in most cases, though, you want to scale it equally both horizontally and vertically.

IS&T Contributions

Documentation and information provided by IS&T staff members


Last Modified:

December 16, 2010

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
Labels:
olc-athena olc-athena Delete
olc-latex olc-latex Delete
ps ps Delete
postscript postscript Delete
latex latex Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
Feedback
This product/service is:
Easy to use
Average
Difficult to use

This article is:
Helpful
Inaccurate
Obsolete
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki