Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .