@danielsimonjr/mathts-expression 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +20 -0
  2. package/dist/index.d.ts +2111 -2398
  3. package/dist/index.js +452 -170
  4. package/package.json +59 -59
package/README.md CHANGED
@@ -15,8 +15,28 @@ npm install @danielsimonjr/mathts-expression
15
15
  - `createParse` / `createParserClass` / `createParser` — parse to an AST.
16
16
  - 16 AST node constructors (`createConstantNode`, `createOperatorNode`, …).
17
17
  - `compile` / `createEvaluate` / `compileExpression` — evaluate expressions.
18
+ - AST serializers on every node: `toString()`, `toTex()` (LaTeX), `toHTML()`, and `toMathML()` (MathML).
18
19
  - Focused re-exports are also published: `@danielsimonjr/mathts-{parser,ast,evaluator}`.
19
20
 
21
+ ## Serializing an AST
22
+
23
+ Every node serializes to several formats. `toMathML()` returns a MathML
24
+ **fragment** (like `toTex()` returns a LaTeX fragment, without delimiters);
25
+ wrap it in a `<math>` element with `mathMLDocument(node)` to render. MathML is
26
+ typeset natively by modern browsers — no external dependencies.
27
+
28
+ ```ts
29
+ import { mathMLDocument, mathMLError } from '@danielsimonjr/mathts-expression';
30
+
31
+ const node = parse('c = 1 / sqrt(eps0 * mu0)'); // parse from the functions package
32
+ node.toString(); // 'c = 1 / sqrt(eps0 * mu0)'
33
+ node.toTex(); // 'c=\\frac{1}{\\sqrt{ eps0\\cdot mu0}}'
34
+ node.toMathML(); // '<mrow><mi>c</mi><mo>=</mo><mfrac>…</mfrac></mrow>'
35
+ mathMLDocument(node); // '<math xmlns="…" display="block">…</math>' (renderable)
36
+ ```
37
+
38
+ `mathMLError(src)` produces a `<math><merror>` element for a parse failure.
39
+
20
40
  ## License
21
41
 
22
42
  MIT (c) Daniel Simon Jr.