Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a document containing, among other things, some figures created using the picture environment. Now I need to create a postscript file for each figure, but if I simply copy them into otherwise blank documents, each one will take up an entire page.

For example, if I have

...
\setlength{\unitlength}{1in}
\begin{picture}(3.14,2.71)
  %Draw things
\end{picture}
...

then I would like to create a .PS file that is 3.14x2.71 inches and which contains nothing but this drawing. I should be able to change my picture environment above to an \includegraphics command that loads the new file, and have it make zero change to the document that is output.

What's the best way to create a postscript file from a LaTeX-drawn picture with the same dimensions as the original?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

You should look into the (extremely useful) preview package. You'll probably want the tightpage option, and if you want the generated eps to have exactly the same dimensions as the original you'll need to \setlength\PreviewBorder{0 pt}.

You don't need to copy the picture environments into otherwise blank documents, you just need have a \PreviewEnvironment{picture} line in the preamble, in order to extract only the pictures.

To expand on your example

\documentclass{article}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{0pt}
\PreviewEnvironment{picture}
\begin{document}
\setlength{\unitlength}{1in}
Text before picture
\begin{picture}(3.14,2.71)
 Contents of picture environment
\end{picture}
\begin{picture}(1.00,1.00)
 Contents of picture environment2
\end{picture}
Text after pictures
\end{document}

Gives, when compiled with pdflatex, a pdf which has pages of exactly 3.14in*2.71in and 1.00in*1.00in, and when compiled by latex and dvips gives a ps with the same dimension pages. Either the pdf or the ps can be turned into eps using external tools, but if you want to, you can replace tightpage with psfixbb and then run dvips -E -i on the dvi to get a series of eps files each with the correct dimensions (named jobname.001 jobname.002 etc, which you have to rename as jobname.001.eps etc).

Removing the active option from the usepackage line means the file will compile as if preview was never loaded.

PS: if you want the \includegraphics boxes to be very accurately the same as the original ones then you should also look into the hiresbb option of the graphicx package. Otherwise the dimensions get rounded to 1 bp (big point) accuracy.

share|improve this answer
    
This is a great solution, although it has shown me that not all of my pictures fit exactly within their prescribed areas. This is most commonly due to placing a dot on the boundary, and results in the cutting off of half the dot, but I suppose that's more my fault than the package's... –  Michael Underwood Aug 19 '10 at 22:11
    
Too late to edit my previous comment, but is it possible to create an eps file that has a defined bounding box, but also contains content outside of that? Since that's essentially the case I have with the picture environments it would be the best way to accomplish what I'm after. –  Michael Underwood Aug 19 '10 at 22:23
    
It is possible to have an eps file that extends beyond its bounding box, but I don't think that preview gives you any way to make one: the tightpage option actually changes the page size, not the bounding box; the psfixbb and dvips -E -i route causes the bounding box to be enlarged just enough that it catches the parts of your image that extend past the dimensions of the picture. –  Lev Bishop Aug 20 '10 at 13:39
add comment

Run ps2eps on the postscript file you produce. You'll get an encapsulated postscript that you can view with postscript viewers or embed via \includegraphics.

share|improve this answer
    
Thanks, that works fairly well, but the resulting bounding box is defined by the limits of the drawing, not the original dimensions of the picture. If the drawing goes exactly to all four edges without going over then this will work perfectly, but for other scenarios the resulting eps file isn't quite the same size as the original picture so spacings near the image change... –  Michael Underwood Aug 19 '10 at 21:19
add comment

If you create the images as otherwise empty pdf pages (no page number!) you can then use pdfcrop to trim the whitespace

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.