Bounding boxes in EPS files...

Hi all,

I'm enjoying the new toy (real LaTeX support), and after running the examples/tex_demo, I noticed the bounding boxes aren't quite right. I know that Darren and John have struggled a lot with this issue, and I don't know what the true solution should be. But I've seen similar problems in the past with Gnuplot (when making square aspect ratio plots), and I had this lying around:

def eps_fix_bbox(fname):
     """Fix the bounding box of an eps file by running ps2eps on it.

     If its name ends in .eps, the original file is removed.

     This is particularly useful for plots made by Gnuplot with square aspect
     ratio: there is a bug in Gnuplot which makes it generate a bounding box
     which is far wider than the actual plot.

     This function assumes that ps2eps is installed in your system."""

     # note: ps2ps and eps2eps do NOT work, ONLY ps2eps works correctly. The
     # others make output with bitmapped fonts, which looks horrible.
     print 'Fixing eps file: <%s>' % fname
     xsys('ps2eps -f -q -l %s' % fname)
     if fname.endswith('.eps'):
         os.rename(fname+'.eps',fname)

those of you running IPython can get it simply via:

from IPython.Gnuplot2 import eps_fix_bbox

I don't claim that it does the right thing everywhere, but a few tests seemed to give reasonable results. I don't know if it will help others, but it works for me, so here it goes.

Cheers,

f

Hi Fernando,

Which version of ghostscript are you using? We had trouble with bboxes using a
version older than ghostscript-8.16.

I use ghostscript's epswrite device to convert a latex-generated postscript to
eps. It converts the fonts to bitmaps, as you pointed out, but you can
increase the resolution in rc with ps.distiller.res: I have it set to 6000,
and the files are not too big.

Would you send me a copies of the bad eps and the fixed version, and also a
copy of ps2eps? I don't have that program on my system, and was not able to
find it on the web.

Thanks,
Darren

···

On Wednesday 08 June 2005 1:29 am, Fernando Perez wrote:

Hi all,

I'm enjoying the new toy (real LaTeX support), and after running the
examples/tex_demo, I noticed the bounding boxes aren't quite right.

Darren, Fernando,

I'm sorry I haven't had a chance to try out the new tex/latex
support, and am really looking forward to it. Thanks!!

I've used scripts to convert gnuplot/ps-latex to eps and png for
too many years (and will be thrilled to replace them with
matplotlib scripts). For the EPS bbox problem from dvips, I've
had good luck running
   gs -q -dBATCH -dNOPAUSE -sDEVICE=bbox my.eps
on the eps file generated from
   dvips -E ... -o my.eps my.dvi
The bbox output from 'gs -sDEVICE=bbox' can then be used to
rewrite the eps file. It's definitely a kludge and involves
temporary files (this might be unavoidable, and tex/latex uses
lots of these anyway), but the results seem good, even with
relatively old versions of ghostscript.

I don't know if that's better than Fernando's suggestion or not,
but since the PS backend already uses gs (I think), it might be
worth considering.

Thanks!

--Matt

PS: For eps->png, I've been quite happy running
     convert -antialias -density 300 my.eps my.png
Maybe that's a reasonable alternative to dvipng??

Darren Dale wrote:

Hi all,

I'm enjoying the new toy (real LaTeX support), and after running the
examples/tex_demo, I noticed the bounding boxes aren't quite right.

Which version of ghostscript are you using? We had trouble with bboxes using a version older than ghostscript-8.16.

Ah, that could be it. Fedora 3 comes stock with:

[~]> rpm -qa | grep ghost
ghostscript-fonts-5.50-13
ghostscript-7.07-33

I use ghostscript's epswrite device to convert a latex-generated postscript to eps. It converts the fonts to bitmaps, as you pointed out, but you can increase the resolution in rc with ps.distiller.res: I have it set to 6000, and the files are not too big.

Mh, I dind't point that out: I didn't even know you could do it :slight_smile:

Would you send me a copies of the bad eps and the fixed version, and also a copy of ps2eps? I don't have that program on my system, and was not able to find it on the web.

Here goes. As it turns out, ps2eps is a simple perl script which I got god knows when. So people won't actually have it on their systems, it's something that lives in /usr/local/bin on my box, sorry.

But no worries. I can lie with using ps2eps for now, until I can upgrade to a moer current ghostscript.

Cheers,

f

bboxes.tgz (38.3 KB)

···

On Wednesday 08 June 2005 1:29 am, Fernando Perez wrote: