Temml

raw JSON →
0.13.2 verified Sat Apr 25 auth: no javascript

A lightweight LaTeX-to-MathML Core conversion library for JavaScript, currently at v0.13.2. Released under MIT license, it offers a smaller bundle size (171KB minified) compared to MathJax (338KB) and KaTeX (280KB), with better LaTeX coverage than TeXZilla. It supports system fonts for minimal footprint and includes a comprehensive test suite. Essential for accessibility and SEO-friendly math rendering in modern browsers. Active development with periodic releases aimed at fixing bugs and adding LaTeX functions.

error TypeError: temml is not a function
cause Importing the default export as a named export, e.g., `import { temml } from 'temml'`.
fix
Use default import: import temml from 'temml'.
error Error: Unsupported function: \url
cause Using LaTeX commands removed in v0.11.07.
fix
Replace \url{...} with an HTML anchor element outside math mode.
error Module not found: Error: Can't resolve 'temml'
cause Missing temml package in node_modules or incorrect import path.
fix
Run npm install temml and ensure import path is correct (e.g., import temml from 'temml').
error TypeError: Cannot read properties of undefined (reading 'firstChild')
cause Calling `renderMathInElement` on a DOM element that is not yet mounted or is null.
fix
Ensure the target element exists in the DOM before calling renderMathInElement, e.g., inside DOMContentLoaded event.
breaking Rendering option `wrap` default changed from `'text'` to `'none'` in v0.12.0, breaking rendering behavior for inline math without explicit wrap option.
fix Set `wrap: 'text'` explicitly in options to preserve old behavior, or update styles to handle MathML core wrappers.
breaking Removed support for `\url` and `\href` commands in v0.11.07: these LaTeX commands no longer produce hyperlinks.
fix Replace `\url{...}` and `\href{url}{text}` with manual HTML anchor elements outside math mode.
gotcha Temml requires Node.js >=18.13.0 for server-side usage; older Node versions cause runtime errors or missing features.
fix Upgrade Node.js to version 18.13.0 or later, or use a polyfill/compatibility shim.
gotcha Chromium renders system fonts incorrectly for some MathML constructs; Latin Modern font (380KB) is recommended for best visual quality.
fix Include the Latin Modern Math font via CSS or use a font loading strategy to ensure correct rendering in Chromium-based browsers.
deprecated Temml's `renderMathInElement` function may be deprecated in future in favor of a more streamlined API; current behavior is stable.
fix Monitor changelog for upcoming API changes; consider using the core `temml()` function with custom DOM manipulation instead.
npm install temml
yarn add temml
pnpm add temml

Demonstrates converting LaTeX to MathML string using temml() and auto-rendering math in the document body with renderMathInElement().

import temml, { renderMathInElement } from 'temml';

// Generate MathML string
const mathml = temml('E = mc^2', {
  displayMode: true,
  throwOnError: false
});
console.log(mathml);

// Auto-render all math in a DOM element
document.addEventListener('DOMContentLoaded', () => {
  renderMathInElement(document.body, {
    delimiters: [
      {left: '$$', right: '$$', display: true},
      {left: '$', right: '$', display: false}
    ],
    throwOnError: false
  });
});