Converting a LaTeX package to MathJax – TeX
There is no mechanical step-by-step process to convert a LaTeX package into a MathJax extension, because MathJax does not execute TeX: it only reimplements a subset of the language in JavaScript.
The first step is to understand what the package actually does. Purely symbolic or notational macros (\newcommand, operators, abbreviations) can usually be implemented directly via tex.macros in MathJax, without creating an extension.
However, macros that:
- alter parsing,
- use conditional logic,
- introduce new syntax,
may require a JavaScript extension, using the MathJax (v3) CommandMap and Configuration system. In this case, the macro needs to be rewritten in terms of MathJax’s internal model, not “converted” from LaTeX code.
Packages that depend on TikZ, boxes, dimensions, counters, or page layout are not portable to MathJax.
In short: porting a LaTeX package to MathJax usually means reimplementing the desired behavior, not translating the code. The best practical guide is to study the code of the official MathJax extensions (e.g., ams or physics).
Yes, there are good resources, but they are not gathered in a single “from scratch” tutorial, and that’s part of the difficulty.
The most useful resources are:
Especially the sections on:
-
the TeX parser
-
CommandMap -
Configuration
They explain what an extension needs to register and at what stage of parsing it acts.
- The source code of the official MathJax extensions
This is, in practice, the best teaching material. Extensions such as:
show real-world examples of:
- argument reading
- macro redefinition
- equivalent TeX injection into the parser
It contains complete examples of well-structured and up-to-date extensions for the MathJax v3 model, which is much more useful than isolated documentation.
- The canonical answers on MathJax/TeX StackExchange
Several answers from MathJax developers themselves explain why certain things are possible or not, which helps to understand the correct mental model.
In short: there is no single guide, but the combination of TeX input jax documentation with reading the code of the official extensions is, today, the most effective way to learn exactly what a MathJax extension needs to do.
Read more here: Source link
