LaTeX math renderer API

Render LaTeX formulas (fractions, roots, sums, integrals, matrices, \ce chemistry) to SVG, PNG or MathML for web pages, e-mails, PDFs and quizzes.

GETPOSThttps://apibox.io.vn/v1/math-render
Images & Codes▶ Try it online

Send a LaTeX formula in tex and choose the output: svg (default, self-contained: glyphs are vector paths, no font needed), png (transparent or background, scale 2 by default for sharp text), mathml (native MathML that current browsers display) or json (MathML, an HTML snippet, the SVG, a PNG as base64, the size and the vertical_align offset to line the image up with surrounding text). display=false gives inline style (smaller fractions, limits beside ∑).

The LaTeX is parsed by temml (MIT), which covers the usual math of KaTeX: fractions, binomials, roots, scripts, sums and integrals with limits, \left…\right delimiters, matrices, cases, aligned, accents, \mathbb / \mathcal / \mathbf, \text{} (Vietnamese works), colours and mhchem \ce{} for chemistry. The MathML is then laid out by our own TeX-like box engine and drawn with the STIX Two Math font (SIL OFL); no MathJax or browser runs on the server. Set size (font size in px, default 24), color and padding.

The SVG / PNG layout is an approximation of TeX: spacing and stretchy delimiters (which are scaled, not assembled from pieces) can differ slightly from KaTeX or MathJax, and line breaks (\\ outside environments) are ignored. Errors in the LaTeX return 400 with the parser message.

Parameters

NameInTypeRequiredDefault
texquery|bodystringyesLaTeX formula, without $ delimiters (max 5000 characters).
formatquery|bodystringnosvgsvg, png, mathml or json.
displayquery|bodybooleannotruefalse for inline style.
sizequery|bodynumberno24Font size in px (8–200).
colorquery|bodystringno#000000Formula colour.
backgroundquery|bodystringnoBackground colour (transparent by default).
paddingquery|bodynumbernoMargin in px (default: a quarter of size).
scalequery|bodynumberno2PNG pixel ratio (1–8).

Example

curl "https://apibox.io.vn/v1/math-render?tex=E%20%3D%20mc%5E2&format=json" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "tex": "E = mc^2",
  "display": true,
  "mathml": "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" class=\"tml-display\" style=\"display:block math;\"><mrow><mi>E</mi><mo>=</mo><mi>m</mi><msup><mi>c</mi><mn class=\"tml-sml-pad\">2</mn></msup></mrow></math>",
  "html": "<div style=\"text-align:center\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" …</math></div>",
  "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"99\" height=\"34\" viewBox=\"0 0 99 34\" role=\"img\">…</svg>",
  "width": 99,
  "height": 34,
  "vertical_align": "-6.29px",
  "png_base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMYAAABECAYAAADa40qO…",
  "png_scale": 2,
  "engine": "temml (LaTeX to MathML) + own box layout with STIX Two Math outlines"
}

Use cases

  • Formulas in exam papers, quizzes and e-learning content
  • Math in e-mails and chat messages as PNG
  • Formulas inside generated PDFs and slide decks
  • Previewing LaTeX typed by students or teachers

FAQ

Which LaTeX commands are supported?

Those of temml, similar to KaTeX: standard math, environments (matrix, pmatrix, cases, aligned, array), \text, \operatorname, \color, \boxed, \cancel and \ce for chemistry. Unknown commands return a 400 error.

How do I align the image with text?

Use format=json: vertical_align (for example -6.29px) is the distance from the baseline to the bottom of the image; set it as CSS vertical-align on the <img>.

Is the SVG accessible?

The SVG is a drawing. For screen readers, use the MathML output (format=mathml or the html field of json), which browsers read as math.

Related APIs

Start with 1,000 free requests every month. Get free API key →