Export to image (TeX2img/dvisvgm/ImageMagick)

Sometimes you need a LaTeX formula or figure as an image — PNG for a slide, SVG for the web. The recipe: typeset just that piece, crop it tight, then rasterize or vectorize. The tools: TeX2img (all-in-one), dvisvgm (→SVG), ImageMagick + Ghostscript (→PNG), and pdfcrop (trim margins).

All-in-one — TeX2img

TeX2img compiles your LaTeX source to PDF and then to a tightly cropped image (PNG, SVG, JPEG, …), with transparency and anti-aliasing. The easiest route for equation and figure images, and especially popular in Japan.

The manual pipeline

First typeset just the piece — the standalone class auto-crops to the content (for a normal PDF, use pdfcrop to trim margins). Then, for vector (SVG) use dvisvgm (crisp at any zoom; great for the web and math); for raster (PNG) use ImageMagick (magick -density 300 in.pdf out.png). ImageMagick renders the PDF via Ghostscript, so raise -density for resolution and add transparency as needed. Ghostscript can also rasterize directly (-sDEVICE=pngalpha).

terminal
pdfcrop eq.pdf eq-crop.pdf              # 余白を切り詰め / trim margins
magick -density 300 eq-crop.pdf eq.png  # PDF → PNG(300dpi, Ghostscript 経由)
dvisvgm --pdf eq-crop.pdf               # PDF → SVG(ベクタ)

Which path

  • Quick equation/figure images → TeX2img.
  • Lossless vectors for the web → dvisvgm (SVG).
  • When you need PNG/JPEG → pdfcropImageMagick (Ghostscript); raise -density for resolution.
  • For a standalone figure file, the standalone class auto-crops.