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 want to get a standalone EPS graphic from DVI. This process can be done using the batch file as follows

latex %1
dvips -E %1 -o %1.eps

And the test file is as follows

\documentclass{minimal}
\usepackage{pstricks}


\begin{document}

\begin{pspicture}[showgrid=false](3,3)
\pscircle(1.5,1.5){1}
\end{pspicture}

\end{document}

However the resulting EPS has incorrect bounding box. How to fix the bounding box?


Update: You can also find a more detailed solution in How to produce EPS instead of PS using latex.exe followed by dvips.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

This seems to be because EPS (and PDF) uses PostScript points (=1/72in, called bp (big points) in TeX), not the normal TeX points (1pt=1/72.27in). The EPS contains its size (bounding box) as integers, so rounding the size upwards. You can try and add the hi-resolution bounding box header which contains the size as floating point numbers. However, it depends on the used tool which of the two are used.

You can get these headers calculated by Ghostscript using:

gs -dNOPAUSE -dBATCH -q -sDEVICE=bbox file.eps

which prints the required EPS headers:

%%BoundingBox: 0 0 34 31
%%HiResBoundingBox: 0.000000 0.000000 33.317999 30.005999

You can then simply replace the original headers with the updated one. There might be tools which do this for you (e.g. eps2eps) but these might actually change the font settings etc. I wrote my own Perl script called fixbb once which does nothing else then calling gs like above and replacing the headers. (But I'm just seeing know that it doesn't add the HiResBoundingBox header if it wasn't use before.)

As workaround you could make sure that your diagrams are drawn using bp not pt, at least the outer rectangle.

BTW: I would use \documentclass[border=0pt]{standalone} instead. This saves you some steps (e.g. page style is already set to be empty, ...). However, I still get a white border at the right and top.

share|improve this answer
    
If EPS file also has`%%HiResBoundingBox` header, use \usepackage[hiresbb]{graphicx} to avoid top and right padding. –  xport Jul 2 '11 at 0:15
    
+1 and accepted for informing %%HiResBoundingBox. I use neither fixbb nor eps2eps. Instead, I used epstool. –  xport Jul 2 '11 at 8:25
    
@xport: Ah yes, epstool! I knew there was a tool which made me stop using my own fixbb, but couldn't recall it. I stopped using EPS years ago. –  Martin Scharrer Jul 2 '11 at 8:53
    
I knew epstool by reading the source of your fixbb. :-) –  xport Jul 2 '11 at 9:55
    
@xport: Oh, yeah, it's old code of mine ;-) –  Martin Scharrer Jul 2 '11 at 9:58

Another option is keep the image as it is right now and trim off the excess padding when it's put into your document. If, for example, your picture is called MyPicture.eps then it can be trimmed through \includegraphics[trim= left bottom right top, clip=true]{MyPicture.eps} where you enter how much want to trim the figure on each side. For example, see what happens to your picture with this code:

\documentclass{minimal}
\usepackage{graphicx}
\begin{document}
\pagestyle{empty}
\includegraphics[width=2.50in, trim= 8 1 3 .5, clip=true]{MyPicture.eps}
\end{document}

By adjusting values in trim, you control what the picture looks like. See http://www.andy-roberts.net/misc/latex/latextutorial5.html for more details.

share|improve this answer
    
True, but the OP seems to want to use it as standalone file and not re-include it in a LaTeX document. Also you would need to adjust the trim values for every picture manually. –  Martin Scharrer Jul 1 '11 at 19:29

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.