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--libgsor theLIBGSenvironment variable. - PDF input (
--pdf) is processed with Ghostscript (versions below 10.01.0) or withmutool, selected through theDVISVGM_PDF_PROCenvironment 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
- Put the formula in a small stand-alone LaTeX document (for example
eq.tex) that contains only the content you want in the SVG. - Compile it to DVI:
latex eq.tex. This produceseq.dvi. - Convert it:
dvisvgm eq.dvi. Per the manual page, the default output name is%f.svgfor a single-page DVI (the input file name with.svg) and%f-%p.svgwhen the DVI has several pages. Set a name with--output(-o). - 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 as1-5, where%Pstands for the last page. - For an EPS file, run
dvisvgm --eps figure.eps(requires Ghostscript). - 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
- Load MathJax in your page or script as described in its documentation.
- Call
MathJax.tex2svgPromise(math, options). The MathJax documentation recommends the promise version in version 4, because fonts may load asynchronously; the synchronousMathJax.tex2svg(math, options)also exists and returns a DOM element directly. - Serialise the returned element, for example:
const svg = await MathJax.tex2svgPromise('sqrt{x^2+1}', {display: false}); const text = svg.outerHTML; - If you want stand-alone SVG files, set
fontCachein thesvgsection 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. - 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
- dvisvgm manual page, https://dvisvgm.de/Manpage/ (read 2026-11-08).
- MathJax documentation, converting to other formats, https://docs.mathjax.org/en/latest/web/convert.html (read 2026-11-08).







