Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

latex-math

tiny-md11.6kMPL-2.00.0.2TypeScript support: included

Parses LaTeX math strings—typically extracted from Markdown—and converts them into an abstract syntax tree (AST).

LaTeX, LaTeX parser, Math, Math-mode, Parser, AST, Abstract Syntax Tree, Parse LaTeX, Latex AST, unified, remark-math, Markdown, Vite, Frontend, Frontend tooling, Typescript, Web development, Modern, Lightweight, Compatibility, Seamless integration, Customizable, Cutting-edge, Progressive

readme

LaTeX Math to AST

test Maintainability codecov Version Downloads npm bundle size Gitpod ready-to-code

Convert LaTeX math strings into structured abstract syntax trees (ASTs) — lightweight, Vite-compatible, and built for modern tooling.


✨ Overview

This utility parses LaTeX math strings and transforms them into LaTeX ASTs for further processing, analysis, or transformation.

It is a trimmed-down version of @unified-latex/unified-latex-util-parse, built specifically to address compatibility issues with Vite and modern build tools.


🚀 Features

  • 🧠 Converts LaTeX math strings to ASTs
  • ⚡️ Lightweight & minimal dependencies
  • 🛠 Vite-compatible (unlike @unified-latex/unified-latex-util-parse)
  • 🔌 Easy to integrate with remark-math pipelines
  • 📦 Suitable for client-side or server-side rendering

Installation

pnpm add latex-math

or

npm install latex-math

or

yarn add latex-math

🔧 Usage

import { parseMath } from "latex-math";

const latex = "\\frac{a}{b}";
const ast = parseMath(latex);

console.log(ast);

📚 Why this exists

The original package @unified-latex/unified-latex-util-parse is robust, but includes many dependencies and causes issues in Vite-based or modern ESM projects.

This package solves that by providing only what's necessary to parse math-mode LaTeX, with modern compatibility and minimal footprint.


Star this repository and share it with your friends.

📄 License

This library is licensed under the MPL-2.0 open-source license.

Please enroll in our courses or sponsor our work.


with 💖 by Mayank Kumar Chaudhari

````