Write math any way. Convert it to anything.

Type math however you like — 3x^2 + sin x, \frac{d}{dx} e^{2x}, Math.pow(x, 2), or x² ≤ √y. MathZetta parses it into a single standard postfix format, then converts it to LaTeX, MathML, spoken English, JavaScript, Python, SQL, Excel, GLSL shaders, exact answers, or live table formulas. Zero dependencies, just a few kilobytes per output, and it runs in both the browser and Node.

Used for variables inside {{…}} blocks (so x^2 = {{x^2}} becomes x² = 4 when x = 2) and for the evaluate and calculate rows. Everywhere else, variables stay symbolic.

How to use it

The API

Parse once, output anywhere. parse turns text into postfix, and every to… function accepts raw text, postfix, or a syntax tree — so you can parse once and pass the result to as many formats as you need.

const p = parse('x^2 + 1');
// p is ['x', '2', '^', '1', '+']
toLaTeX(p);         // 'x^2 + 1'
toSpeech(p);        // 'x squared plus 1'
toJavaScript(p);    // 'Math.pow(x, 2) + 1'
evaluate(p, {x: 3}); // 10

Pass options as the last argument (for example, toSQL(p, { dialect: 'sqlite' }) or toPython(p, { numpy: true })). Invalid input or unsupported outputs (like a derivative in SQL) throw a clear Error, and parseSteps(text) shows every step of the parser.

Explore the full API with editable examples

Script tag

Drop in one CDN script with no build step. Everything is available on window.MathZetta.

<script src="https://cdn.jsdelivr.net/npm/mathzetta@1/build/mathzetta.min.js"></script>
<script>
  const { parse, toLaTeX, toSpeech } = MathZetta;
  toSpeech('(x+1)^2');   // "the quantity x plus 1, squared"
</script>

Import only what you need

The core package is just the parser. Each output format is its own entry point, so you only bundle what you actually use.

import { parse } from 'mathzetta';
import { toLaTeX } from 'mathzetta/latex';
import { calculate } from 'mathzetta/calculate';

parse('2x sin x');            // ['2','x','*','x','sin','*']
toLaTeX('x^2/2');             // '\\frac{x^2}{2}'
calculate('sqrt(8)').text;    // '2*sqrt(2)'

Entry points: /latex /mathml /text /speech /javascript /python /sql /excel /glsl /evaluate /calculate /formulas /all /plain — see them live. Using a CDN without npm? Import https://cdn.jsdelivr.net/npm/mathzetta@1/build/mathzetta.esm.min.js, or customize your bundle on the CDN builder page.

Node

npm install mathzetta
node -e "import('mathzetta/sql').then(m =>
  console.log(m.toSQL('price * qty > 10')))"
// or require('mathzetta') for CommonJS

Works with ES modules and CommonJS in the browser and Node 18+, with full TypeScript types and zero runtime dependencies.

Features

Inline calculations: {{…}}

Wrap an expression in double braces to calculate it automatically — keeping exact fractions and roots where possible. Just import mathzetta/calculate (or use the full script tag).

toText('3 + 4 = {{3 + 4}}')            // '3 + 4 = 7'
toLaTeX('\\sqrt{8} = {{sqrt(8)}}')    // '\\sqrt{8} = 2\\sqrt{2}'
toText('\\pi \\approx {{~4 pi}}')     // 'π ≈ 3.1416'

Display math: Inline Math

A companion library that renders MathZetta trees as plain HTML and CSS — fractions, integrals, piecewise functions, and more. Every part shares the same node IDs as the speech output, so you can highlight, click, or animate individual pieces.

import { render } from '@mathzetta/inlinemath';
const v = render(el, String.raw`\int_0^1 x^2 dx`);
v.highlight('x^2');  v.set(String.raw`\frac{1}{3}`, { animate: true });

Try Inline Math

Table formulas

mathzetta/formulas compiles expressions like H / AB > 0.3 into fast row functions or SQL. tabview uses it to power searchable data tables in the browser, on a tabc server, or on SQLite.

const f = strToFunction(['H', 'AB'], 'H / AB');
createRowEvaluator(f.jsFunction)([30, 100]);  // 0.3
strToSQL(['H', 'AB'], 'H / AB > 0.3', new Map(),
  { dialect: 'sqlite' }).sqlExpression;

Try the table demo

Image filters

mathzetta/glsl compiles math into GPU shaders. qblur builds on it to turn formulas like if gray > 0.5 then (1, 0, 0) or gaussian(3) into shareable WebGL image filters with sliders and masks.

Open the filter editor

Computer algebra: MathZetta CAS

Simplify, factor, solve, differentiate, and integrate with readable step-by-step explanations — driven by YAML rules you can inspect and customize. npm install @mathzetta/cas

import { parse } from 'mathzetta';
import { createCAS } from '@mathzetta/cas';
const cas = createCAS({ read: (text) => parse(text) });

cas.diff('x^2 sin(x)', 'x').text         // x^2·cos(x) + 2x·sin(x)
cas.solve('x^2 - 5x + 6 = 0', 'x').text  // x = 2 or x = 3
cas.integrate('x e^x', 'x').text         // x·e^x - e^x

Try the CAS playground · Inspect the YAML rules

Editable game & app formulas

Two games use MathZetta so every rule — swing chance, fatigue, ticket demand — is a formula players can replace and see rendered as math. If your app has knobs, they can be formulas too.

evaluate('max(0, 1 - fatigue/100) * skill',
         { fatigue: 50, skill: 0.8 });   // 0.4

Built with MathZetta

Live tools and sites powered by MathZetta. You can also jump to any of them from the sidebar.

The postfix format

MathZetta uses standard reverse Polish notation (postfix): fixed-arity operators are bare (x sin, a b ^), variadic functions include an argument count (a b c 3 max), unary minus is neg, derivatives use der, and eu is e u ^. See the full token list in docs/postfix.md and the parsing pipeline in docs/how-it-works.md. Because every node ID is just its postfix index, speech segments, MathML elements, and rendered HTML parts all stay automatically in sync. Want to learn how it works hands-on? Try the interactive postfix quiz.

What it supports

The goal: read any math you'd meet through Calculus II — algebra, functions, trig, exponentials, logarithms, limits, derivatives, integrals, sequences, and series — no matter how it's written, and draw it, say it, and work it out.

Browse every operator with live examples in the operations reference, inspect every parsing stage in the playground, or run the 6,000+ checks yourself in the browser test runner.

When math can be read two ways

Some input has two reasonable readings; MathZetta always takes the same one. Click one to see it read above. All of them, with how to write the other reading, are in When math can be read two ways (each is a test).