MathXyJax3
MathJax3 with XyJaX-v3 for server-side rendering of mathematical expressions and xy-pic diagrams.
Features
- MathJax 3 Integration: MathJax for high-quality mathematical typesetting
- XyJax-v3 Support: Full support for xy-pic diagrams and commutative diagrams
- Server-Side Rendering: Optimized for Node.js server environments
- ESM Module: Modern ES module support
- SVG Output: Clean, scalable vector graphics output
Installation
npm install mathxyjax3
Quick Start
import mathjax from 'mathxyjax3';
// Render a simple math expression
const mathSvg = mathjax.tex2svgHtml('E = mc^2');
console.log(mathSvg.outerHTML);
// Render xy-pic diagram
const xyDiagram = mathjax.tex2svgHtml('\\xymatrix{A \\ar[r] & B}');
console.log(xyDiagram.outerHTML);
API Reference
tex2svgHtml(input, options)
Converts TeX/LaTeX input to SVG output wrapped in HTML.
Parameters:
input
(string): The TeX/LaTeX expression to renderoptions
(object, optional): Rendering options
Returns:
- HTML string containing SVG
Example:
const svg = mathjax.tex2svgHtml('\\frac{1}{2}', {
display: true,
em: 16,
ex: 8
});
Supported Formats
Mathematical Expressions
- Standard LaTeX math commands
- AMS math extensions
- Complex equations and formulas
- Matrices and arrays
XY-pic Diagrams
- Commutative diagrams
- Category theory diagrams
- Graph theory visualizations
- Custom arrow styles and labels
Examples
Basic Mathematics
// Fractions
mathjax.tex2svgHtml('\\frac{a}{b}');
// Integrals
mathjax.tex2svgHtml('\\int_{-\\infty}^{\\infty} e^{-x^2} dx');
// Matrices
mathjax.tex2svgHtml('\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}');
XY-pic Diagrams
// Simple commutative diagram
mathjax.tex2svgHtml('\\xymatrix{A \\ar[r]^f \\ar[d]_g & B \\ar[d]^h \\\\ C \\ar[r]_k & D}');
// Category theory
mathjax.tex2svgHtml('\\xymatrix@1{\\bullet \\ar@/^/[rr]^{f} \\ar@/_/[rr]_{g} && \\bullet}');
Dependencies
- MathJax 3: Core mathematical rendering engine
- XyJax-v3: XY-pic extension for diagram rendering
- esbuild: Fast JavaScript bundler
- xmldom-sre: XML DOM implementation
- wicked-good-xpath: XPath support
Related Projects
License
MIT License - see LICENSE file for details.
Support
Author
TANIGUCHI Masaya