Preamble: I am using LaTex on Linux (Ubuntu 10.4.1)

I want to export equations generated in LaTeX to either a high-res bitmap or vector image format for use in a desktop publishing program. However, the target document has a coloured background, so I cannot simply use the GIMP (it seems) as it renders PDFs on a white background.

Is there a command I can put in a LaTeX document to generate a PDF with a transparent background, or another way of extracting these equations?


Use dvipng for a transparent-background PNG, as such:

dvipng -D 1000 -bg Transparent -pp pagenumber document.dvi

where -pp is the page number to make an image of, and -D is the DPI, set to a huge number for a high-resolution image.

Result is a large alpha-channel PNG which can then be cropped down to to extract the equation, and indeed any other latex-rendered objects.


I'm not aware of any way of doing this using LaTeX itself, though you could just ImageMagick on the result. He's a script.

pdflatex -interaction=batchmode "$texfile"
pdfcrop "$pdffile" "${pdffile%.pdf}-cropped.pdf"
pdftoppm -png -f 1 -l 1 "${pdffile%.pdf}-cropped.pdf" > "$pngfile" 
convert "$pngfile" -transparent white "${pngfile%.png}-transparent.png"

You could use regular latex rather than pdflatex in the first command with dvipng. If you want a higher resolution, add the appropriate option to pdftoppm (e.g., -r 300 for 300 dpi; the default is 150 dpi if I'm not mistaken).

If you wanted a vector graphic instead, you could try Inkscape or dvisvgm, but I don't have a lot of experience with those.

  • The problem with this are the inevitable white halos that come from changing the background colour of anti-aliased text after conversion to a raster. – sargant Sep 4 '10 at 15:05
  • Look at man pdftoppm -- it has lots of options for turning off font anti-aliasing, vector anti-aliasing, freetype effects; you can even set it to monochrome if you like. It's hard to know what will give the best effects though without access to your equations. – frabjous Sep 4 '10 at 20:13

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.