Written and maintained by CASRAI Editorial Board
Last updated
This guide provides researchers, data analysts, and academic developers with practical instructions for configuring MathJax to render LaTeX mathematical expressions inside web applications, online documentation, and digital preprints.
What it is used for in research
Modern scientific communication increasingly occurs on the web, through open-access repositories, interactive project websites, lab blogs, and computational notebooks. However, standard web browsers cannot natively typeset complex mathematical notation written in LaTeX. Researchers use MathJax to bridge this gap, rendering publication-quality equations across digital platforms without forcing readers to download compiled PDF documents.
In academic workflows, MathJax is embedded into tools such as Jupyter Notebooks, Quarto documents, R Markdown, and Sphinx documentation. It allows research groups to publish interactive data analyses, technical reports, and preprints while maintaining identical mathematical syntax across their computational code and published papers. For projects submitting computational tools to venues such as the Journal of Open Source Software (JOSS), MathJax ensures documentation websites display the underlying algorithms with typographic precision.
What is MathJax vs LaTeX?
LaTeX is a comprehensive document preparation system and markup language created by Leslie Lamport on top of Donald Knuth’s TeX typesetting engine. A standalone LaTeX distribution—such as TeX Live or MiKTeX—compiles full manuscript files into printable output (typically PDF or DVI), handling page margins, bibliographic citations, figure placement, and indentation in LaTeX across entire documents.
In contrast, MathJax is an open-source JavaScript display engine managed under NumFOCUS sponsorship. MathJax does not compile complete documents or manage page layout. Instead, it operates strictly within the web browser, parsing mathematical markup written in LaTeX, MathML, or AsciiMath and dynamically rendering those expressions into HTML/CSS or SVG.
Can MathJax render LaTeX?
Yes, MathJax renders LaTeX mathematical syntax directly inside web browsers. It includes built-in support for standard mathematical macros, superscripts, subscripts, fractions, matrices, and American Mathematical Society (AMS) environments such as align and gather. However, MathJax does not parse text-mode LaTeX structural commands such as documentclass, usepackage, or document body wrappers like begin{document}.
Does anyone use LaTeX anymore?
LaTeX remains the dominant standard for manuscript preparation and typesetting across mathematics, physics, computer science, quantitative finance, and engineering disciplines. Major publishers, conference proceedings, and preprint platforms (such as arXiv) require or encourage LaTeX source files. Researchers use reference managers suited to TeX workflows—often evaluated when choosing between Zotero vs JabRef for LaTeX-based writing—and rely on MathJax to translate their paper equations seamlessly into online project portals.
Install or access
MathJax requires no installation for readers visiting a web page; it executes client-side within modern browsers. For researchers and developers building web pages, documentation, or portals, MathJax is available through official content delivery networks (CDNs) or installed locally via npm.
The official, recommended access route for web pages is loading the combined component from jsDelivr via an asynchronous script tag:
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script>
For Node.js environments, static site generators, or local web applications requiring self-hosted assets, MathJax is available as an open-source package published on npm:
npm install mathjax@3
The library is open-source under the Apache 2.0 License, allowing unrestricted deployment on academic, institutional, and commercial sites.
Step-by-step task
Follow these five steps to configure and deploy MathJax for LaTeX rendering on an academic web page or documentation site.
-
Define the global configuration object: Declare the
window.MathJaxconfiguration block before loading the MathJax script. Specify the delimiters for inline and displayed equations. By default, MathJax does not enable single dollar signs for inline math to prevent conflict with currency amounts. Enable them explicitly if your workflow relies on standard TeX inline delimiters:<script> window.MathJax = { tex: { inlineMath: [['$', '$'], ['\(', '\)']], displayMath: [['$$', '$$'], ['\[', '\]']], processEscapes: true } }; </script> -
Load the MathJax script: Place the official script reference immediately after your configuration script block inside the document
<head>or at the end of the<body>:<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script> -
Embed LaTeX equations into HTML content: Author mathematical formulas directly in your web page prose using the configured delimiters.
-
Configure custom research macros: If your manuscript or lab uses custom TeX macros, add them directly to the
tex.macrosconfiguration object. This avoids repetitive typing across research articles:<script> window.MathJax = { tex: { macros: { RR: '{\mathbb{R}}', norm: ['\left\|#1\right\|', 1] } } }; </script> -
Typeset dynamic content asynchronously: When using single-page applications (such as React, Vue, or dynamic dashboards) that insert equations after the initial page load, call the Promise-based typesetting API:
MathJax.typesetPromise().then(() => { // Equations successfully rendered }).catch((err) => console.error('MathJax typeset error:', err));
How to write a math formula in LaTeX for web rendering
When drafting formulas for MathJax, format mathematical expressions using standard TeX syntax. The table below illustrates common mathematical patterns supported out of the box:
| Mathematical Pattern | LaTeX Input Syntax | Rendered Notation Description |
|---|---|---|
| Inline Equation | $E = mc^2$ |
Inline mass-energy equivalence with superscript |
| Fractions & Roots | $$frac{-b pm sqrt{b^2 - 4ac}}{2a}$$ |
Display fraction with square root and plus-minus sign |
| Summation & Limits | $$sum_{i=1}^{n} X_i = mu$$ |
Summation operator with lower and upper limits and Greek mu |
| Aligned Multi-line | $$begin{align} a &= b + c \ d &= e - f end{align}$$ |
Two-line equation aligned at equals signs using AMS align |
| Matrix Notation | $$begin{pmatrix} 1 & 0 \ 0 & 1 end{pmatrix}$$ |
2×2 identity matrix enclosed in parentheses via pmatrix |
For authoring complex journal articles and managing figure numbering, review guidance on LaTeX ref commands and manuscript authoring with AASTeX.
Output and how to read it
MathJax processes the TeX source on page load and transforms each equation into scalable, accessible visual output. Depending on the loaded component, the rendered output uses one of two primary formats:
- CommonHTML (
tex-chtml.js): Generates standard HTML elements styled with modern CSS and web fonts. This format provides fast rendering, sharp rendering on high-DPI displays, and clean integration with browser zoom. - SVG (
tex-svg.js): Generates self-contained scalable vector graphic paths for each equation. SVG output ensures identical visual reproduction regardless of locally installed fonts and avoids font-loading delays on mobile devices.
Every equation rendered by MathJax is interactive. Readers can right-click any rendered expression to open the MathJax contextual menu. This menu allows researchers to:
- Inspect and copy the original LaTeX source code for re-use.
- Copy the expression as MathML markup for import into word processors or computational software.
- Trigger accessibility features, including screen reader exploration and high-contrast equation zoom.
Troubleshooting
When LaTeX math fails to render properly in a browser, use this troubleshooting matrix to resolve the most frequent configuration and syntax issues:
| Observed Symptom | Probable Cause | Corrective Action |
|---|---|---|
Literal LaTeX code appears on page (e.g., $x + y$ visible) |
Single dollar delimiters not configured, or script failed to load | Verify inlineMath array includes ['$', '$'], and confirm the CDN script tag loads without Content Security Policy (CSP) blocking. |
| Currency amounts trigger unintended math mode | Prose contains unescaped dollar signs (e.g., $50 and $100) | Enable processEscapes: true in configuration, and escape literal dollar symbols as $ in HTML source text. |
Equation breaks near relational operators (< or >) |
Browser HTML parser interprets operators as HTML tags | Use LaTeX macros lt and gt instead of raw angle brackets, or leave spaces around the operators. |
| Formulas do not render after dynamic AJAX / SPA page updates | MathJax only scans the DOM once during initial window load | Call MathJax.typesetPromise() in your JavaScript component update lifecycle after inserting new DOM elements. |
Unknown environment error for advanced AMS packages |
Required extension not loaded in minimal configurations | Load the standard tex-chtml.js component, which bundles the ams package by default. |
Free alternatives
Several free and open-source rendering tools exist for displaying mathematics on the web. The table below compares the primary alternatives used in research and academic publishing:
| Tool / Technology | Primary Architecture | Performance Profile | Key Research Advantage | Primary Limitation |
|---|---|---|---|---|
| MathJax | Client-side & Node.js JavaScript engine | Full feature set; moderate load footprint (~300 KB combined) | Unmatched TeX macro and AMS environment coverage; built-in accessibility menu and MathML export | Slower initial render time on pages containing hundreds of complex formulas |
| KaTeX | Lightweight JavaScript engine (client or server) | High speed; synchronous rendering with minimal footprint (~80 KB) | Instant page load without layout shift; ideal for high-traffic documentation and blogs | Supports a smaller subset of LaTeX environments and macros than MathJax |
| Native MathML | Direct browser rendering engine (W3C standard) | Zero JavaScript overhead; instant native rendering | Zero external dependencies; fully native accessibility support in modern browsers | Requires authoring or converting TeX into verbose MathML XML syntax before publishing |
FAQ
Can MathJax render LaTeX?
Yes. MathJax renders LaTeX mathematical markup directly into web browsers using HTML/CSS or SVG. It fully supports standard math syntax and AMS environments such as align, gather, and matrices. It does not compile full document structures like documentclass or text-mode commands.
What is MathJax vs LaTeX?
LaTeX is a complete document typesetting system that compiles raw source code into printable documents like PDFs. MathJax is a JavaScript library that runs inside a web browser to display mathematical expressions on web pages. LaTeX typesets entire papers; MathJax displays math equations on the web.
Does anyone use LaTeX anymore?
Yes. LaTeX remains the gold standard for writing and typesetting academic papers in STEM disciplines, including mathematics, physics, computer science, and engineering. Major journals, arXiv, and university presses rely heavily on LaTeX source files.
How to write a math formula in LaTeX?
To write a math formula in LaTeX, wrap inline expressions between delimiters like $x = y$ or (x = y). For standalone display equations, use $$ ... $$ or [ ... ]. Inside the delimiters, express relationships using standard TeX macros, such as frac{numerator}{denominator} for fractions and sqrt{x} for roots.
Sources
- MathJax Documentation: TeX and LaTeX Support. Official documentation, https://docs.mathjax.org/en/latest/input/tex/index.html (checked 2026-11-07).
- MathJax Documentation: Getting Started with Components. Official documentation, https://docs.mathjax.org/en/latest/web/start.html (checked 2026-11-07).
- MathJax Documentation: Differences from Actual TeX. Official documentation, https://docs.mathjax.org/en/latest/input/tex/differences.html (checked 2026-11-07).
- The LaTeX Project: An introduction to LaTeX. Official documentation, https://www.latex-project.org/about/ (checked 2026-11-07).







