Skip to main content
v2026.11,858 entries · CC-BY 4.0

LaTeX to SVG: Convert Equations with dvisvgm and MathJax

Free ways to convert LaTeX to SVG: dvisvgm for DVI, PDF and EPS, MathJax tex2svgPromise for web equations, plus font and portability fixes.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: to turn LaTeX into SVG without a commercial tool, compile the formula or figure with LaTeX and convert the result with dvisvgm, or, for equations shown on the web, call MathJax’s tex2svgPromise function. This guide gives the commands and options for both routes, taken from the dvisvgm manual page and the MathJax documentation (both read 2026-11-08).

What LaTeX-to-SVG conversion is used for in research

SVG is a vector format, so equations and figures stay sharp at any size and can be edited in vector tools or embedded in web pages and slides. Researchers typically need it to put a typeset equation on a lab web page or in a presentation, to hand a vector figure to a collaborator who does not use PDF, or to build a web page that renders formulas without screenshots. Two free routes cover most cases: dvisvgm converts the output of a LaTeX run (DVI, PDF or EPS) to SVG, and MathJax renders a TeX string to SVG in a browser or JavaScript environment. The opposite direction, placing an SVG into a LaTeX document, is covered in including graphics in LaTeX.

Install or access (official source only)

dvisvgm is documented at dvisvgm.de. The manual page states these requirements for the features used below:

  • EPS input (--eps) and PostScript specials require Ghostscript; the library location can be given with --libgs or the LIBGS environment variable.
  • PDF input (--pdf) is processed with Ghostscript (versions below 10.01.0) or with mutool, selected through the DVISVGM_PDF_PROC environment variable.
  • On Windows, the manual page names MiKTeX 2.9 or later; portable MiKTeX is not supported.

MathJax is documented at docs.mathjax.org; the conversion functions below are described on its page about converting to other formats. For background on using MathJax with LaTeX, see MathJax and LaTeX.

Step by step: convert an equation with dvisvgm

  1. Put the formula in a small stand-alone LaTeX document (for example eq.tex) that contains only the content you want in the SVG.
  2. Compile it to DVI: latex eq.tex. This produces eq.dvi.
  3. Convert it: dvisvgm eq.dvi. Per the manual page, the default output name is %f.svg for a single-page DVI (the input file name with .svg) and %f-%p.svg when the DVI has several pages. Set a name with --output (-o).
  4. If you compiled with pdfLaTeX and have a PDF instead, run dvisvgm --pdf eq.pdf. By default only the first page is converted; choose pages with --page (-p), which accepts ranges such as 1-5, where %P stands for the last page.
  5. For an EPS file, run dvisvgm --eps figure.eps (requires Ghostscript).
  6. For maximum portability, add --no-fonts (-n) so text is written as plain paths (see the next section).

The three synopses given by the manual page are dvisvgm [options] file[.dvi], dvisvgm --eps [options] file.eps and dvisvgm --pdf [options] file[.pdf].

Step by step: convert an equation with MathJax

  1. Load MathJax in your page or script as described in its documentation.
  2. Call MathJax.tex2svgPromise(math, options). The MathJax documentation recommends the promise version in version 4, because fonts may load asynchronously; the synchronous MathJax.tex2svg(math, options) also exists and returns a DOM element directly.
  3. Serialise the returned element, for example: const svg = await MathJax.tex2svgPromise('sqrt{x^2+1}', {display: false}); const text = svg.outerHTML;
  4. If you want stand-alone SVG files, set fontCache in the svg section of the configuration to "local" or "none"; the documentation names these values for stand-alone files, and the global setting shares font data across expressions.
  5. The documentation also provides a getSvgImage() helper that embeds CSS into the serialised SVG.

The conversion options listed in the documentation are display (default true), em (16), ex (8), containerWidth, scale and family.

Output and how to read it

By default dvisvgm embeds SVG font elements for the text; the manual page notes that few renderers support them. --no-fonts replaces them with paths: variant 0 writes paths plus use elements, variant 1 writes paths only. --font-format (-f) selects the font format when fonts are kept; the default is SVG, with TTF, WOFF and WOFF2 also available. --exact-bbox (-e) computes a tight bounding box from each glyph; the manual page notes it applies to DVI input only. Bitmaps are embedded as JPEG by default, and --bitmap-format=png changes that. MathJax returns an SVG DOM element, scaled by its em, ex and scale options.

Troubleshooting

Symptom Cause and fix (from the documentation)
Text missing or wrong in a browser, editor or converter The renderer may not support SVG font elements, the dvisvgm default. Re-run with --no-fonts.
Only one page of a PDF converted PDF input converts page 1 by default. Use --page with a range.
EPS or PostScript content fails These need Ghostscript; point dvisvgm to it with --libgs or LIBGS.
PDF input fails PDF processing uses Ghostscript (below 10.01.0) or mutool via DVISVGM_PDF_PROC.
Windows install not working The manual page names MiKTeX 2.9 or later and states portable MiKTeX is not supported.
Saved MathJax SVG does not stand alone Set fontCache to "local" or "none", and see the documentation’s getSvgImage() helper for embedding CSS.
Formula SVG generated before fonts load Use tex2svgPromise, the version the MathJax documentation recommends in v4.

Free alternatives compared

Route Input Needs Documented use
dvisvgm DVI, PDF, EPS A LaTeX installation; Ghostscript for EPS and PostScript specials Formulas and figures compiled by LaTeX
MathJax tex2svgPromise A TeX math string MathJax in a browser or JavaScript environment Equations converted without a LaTeX run

FAQ

How do I convert a LaTeX equation to SVG for free?

Compile it to DVI with latex and run dvisvgm file.dvi, or use MathJax’s tex2svgPromise for a TeX string. Both are free tools documented by their projects.

Can dvisvgm convert a PDF to SVG?

Yes: dvisvgm --pdf file.pdf. Only the first page is converted unless you set --page.

Why does my SVG show missing text in some programs?

dvisvgm embeds SVG font elements by default and few renderers support them. Use --no-fonts.

How do I go the other way and use an SVG in LaTeX?

See including graphics in LaTeX, which covers the includesvg command.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about LaTeX to SVG: Convert Equations with dvisvgm and MathJax

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →