I have an SVG file and would like to turn that into EPS for embedding into a latex file to be eventually used by dvips. I can use rsvg-convert to turn my SVG into PS. I then can use ps2eps to turn that into EPS. But ps2eps does adjust the bounding box, which means that the resulting EPS will not show the whitespace as instructed by the SVG file.

Is there a way to prevent this, i.e. to convert PS to EPS while maintaining the BoundingBox of the original PS file?

The best I could come up with so far is this:

rsvg-convert -f ps -d 600 -p 600 --background-color=white -o foo.ps foo.svg
ps2eps -f -H foo.ps
sed -i~ "s/^%%BoundingBox:.*/`grep ^%%BoundingBox: foo.ps`/" foo.eps

But I consider this approach pretty hackish.

  • Why don't you use the PS produced by rsvg-convert as is? Or just say mv foo.ps foo.eps if you want. Be aware that rsvg-convert produces raster images from its input. – AlexG Nov 26 '13 at 9:11
  • @AlexG: The PS generated by rsvg-convert isn't denoted as EPS, according to the file header. I'm not sure if it is safe to embed, if it cleans up the stack and state properly. It might be, though. Good idea, will try that. I'm pretty sure that the generated file is a vector graphic. I zoomed in very far, it still looks smooth, and the file is pretty small. The code too looks like reasonable vector operations. – MvG Nov 26 '13 at 9:47
  • @AlexG: I tried directly embedding the PS into my latex file, and see no ill effects. Would you please post that solution as an answer? – MvG Nov 26 '13 at 9:52
  • As for rasterization, I was only reproducing what the man page tells. – AlexG Nov 26 '13 at 11:12

For the purpose of embedding with latex+dvips, a one-page Postscript file with a %%BoundingBox entry can be safely regarded as encapsulated Postscript and doesn't require further processing. Thus, the output of rsvg-convert can be used directly.

  • The spec includes more requirements for an EPS file, in particular it must not use restricted commands (2.4), must clean up after itself (2.5 and 2.6), must contain a file type comment mentioning EPSF (2.1), and so on. That last condition is definitely not satisfied in my case, but apparently latex+dvips can cope with that well enough. – MvG Nov 26 '13 at 10:11
  • @MvG Thanks for the information. I'll modify the answer. – AlexG Nov 26 '13 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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