Check browser compatibility for Temml
mainTemml relies on native MathML support. It is compatible with:
- Chrome
- Edge
- Firefox
- Safari
Note: Temml will not work in Internet Explorer.
repository·main·Indexed 43 days ago
https://github.com/ronkok/temmlA lightweight JavaScript utility for converting LaTeX math notation into MathML Core. Designed as a compact alternative to MathJax and KaTeX, Temml version 0.13.5 supports browser and server-side (Node.js) rendering. It includes extensions for chemical equations (mhchem), physics syntax, MediaWiki-specific functions (texvc), and a Copy-tex extension for copying MathML as LaTeX.
Temml relies on native MathML support. It is compatible with:
Note: Temml will not work in Internet Explorer.
While Temml-generated HTML is generally safe from <script> injection, you can use specific options to provide finer security control when processing untrusted inputs:
maxSize: Prevents large width/height visual disruptions.maxExpand: Prevents infinite macro loop attacks.trust: Use with caution. Allows commands that may load external resources or modify HTML attributes (e.g., \includegraphics or \class).Temml supports subscripts and superscripts using standard LaTeX notation (e.g., A^{2+3}).
Additionally, Temml supports Math-mode Unicode subscript and superscript characters. If you use these Unicode characters directly in your input, they will render as if they were written in a subscript or superscript position.
Example:
A²⁺³ will render identically to A^{2+3}.
Temml allows you to define macros that can either be local to a single render call or persist across multiple calls.
To define document-wide macros or colors, use temml.definePreamble. This returns a macros object that you can pass into subsequent render calls.
const macros = temml.definePreamble(`
\\newcommand\\d[0]{\\operatorname{d}\\!}
\\def\\foo{x^2}
\\definecolor{sortaGreen}{RGB}{128,128,0}
`);temml.render without passing a macros object, macros defined via \gdef or \global\let in the TeX string will not be available in the next render call.macros object and pass it into the options of every render call.const macros = {}; // Or from definePreamble
for (let aSpan of [...mathSpans]) {
const tex = aSpan.textContent;
const displayMode = aSpan.classList.contains("display");
// Pass the macros object to ensure persistence
temml.render(tex, aSpan, { macros, displayMode });
}const macros = temml.definePreamble(
`\\newcommand\\d[0]{\\operatorname{d}\\!}
\\def\\foo{x^2}
\\definecolor{sortaGreen}{RGB}{128,128,0}`
);The extension enables chemical equation and unit syntax using \ce and \pu commands.
\ce.\pu.Note on Deprecated Commands: This extension supports \ce but does not support the deprecated \cf command. If your source content uses \cf, you must define a macro that maps \cf to \ce to maintain compatibility.
For a full list of supported syntax and examples, refer to the mhchem Manual.
Temml supports several LaTeX commands for applying color to mathematical expressions. You can use standard color names, hex codes, or define custom colors using \definecolor.
\color{color_name} content or {\color{color_name} content}: Sets the color for the following content.\textcolor{color_name}{content}: Sets the color for the specified content.\colorbox{color_name}{content}: Places content in a colored box.\fcolorbox{border_color}{background_color}{content}: Places content in a box with a specific border color and background color.Most color functions allow an optional argument to specify a color model (similar to the xcolor package). Supported models are:
HTML (e.g., \color[HTML]{ff00ff})RGB (e.g., \color[RGB]{255,0,255})rgb (e.g., \color[rgb]{1,0,1})Note: For \definecolor, the model argument is required.
You can define custom colors using \definecolor. To make these colors available throughout your entire document, include the definitions in your preamble.
Example of defining and using a custom color:
\definecolor{sortaGreen}{RGB}{128,128,0}
{\color{sortaGreen} F=ma}Temml uses CSS counters for automatic equation numbering in certain AMS environments. The default numbering is controlled by the .tml-eqn::before class and a tmlEqnNo counter.
You can customize the numbering format (e.g., adding a chapter prefix) by overwriting the content rule in your CSS:
/* Example: Prefixing numbers with '3.' to get (3.1), (3.2), etc. */
.tml-eqn::before { content: "(3." counter(tmlEqnNo) ")"; }Troubleshooting: If numbering is not working, ensure your own CSS has not overwritten the counter-reset on the body element.
.tml-eqn::before { content: "(3." counter(tmlEqnNo) ")"; }The mhchem extension adds support for \ce (chemical equations) and \pu (units) functions to Temml. Because it is an extension, it must be included separately from the core library.
Include the mhchem.min.js script in your HTML <head> immediately after the temml.min.js script.
If you are working in a server-side environment, use temml.cjs. The mhchem functionality is already bundled within the CommonJS version of Temml.
<script src="./temml.min.js"></script>
<script src="./mhchem.min.js"></script>To render arbitrary Unicode characters (including Mathematical Alphanumeric Symbols like Bold, Fraktur, or Script) in Temml, use one of the following two methods:
Using \char with a hex code:
\char"263a renders ☺.
Using \text{...}:
\text{☺} renders ☺.
Note on Mathematical Script:
For the Unicode range U+1D49C - U+1D4B5 (Mathematical Script), Temml defaults to chancery glyphs (matching \mathcal{...}). To force roundhand glyphs (per Unicode 14+), append the \ufe01 character to the symbol.
\char"263a
\text{☺}physics extension, ams, stix, statmath, texvc, actuarialangle, or LaTeX 2ε), it will only be available if the corresponding extension is included in your project. Some functions may be explicitly marked as (Not supported).To use Temml in a browser, download the release zip from the releases page. A minimum installation requires the following files to be placed in the same folder:
temml.min.jsTemml-Local.cssTemml.woff2 (The CSS and font files must reside in the same directory).For Node.js or server-side environments, install via npm or yarn:
npm install temml
# or
yarn add temmlWhen using Temml on the server, import temml.cjs or temml.mjs instead of temml.min.js.
npm install temmlTemml requires the HTML5 doctype. To set up a basic environment, include the Temml-Local.css stylesheet and the temml.min.js script in your <head> section. Ensure the CSS and font files are correctly linked in the same directory.
<!DOCTYPE html>
<!-- Temml requires the use of the HTML5 doctype. -->
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./Temml-Local.css">
<script src="./temml.min.js"></script>
</head>
<body>
<!-- MathML content goes here -->
</body>
</html>