@dskripchenko/math 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/index.cjs +1875 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.mjs +1868 -0
- package/package.json +70 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Denis Skripchenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dskripchenko/math
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/dskripchenko/math/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@dskripchenko/math)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
TeX math to MathML — with **no runtime dependencies**, **no fonts to ship**
|
|
8
|
+
and **no DOM**. A string goes in, a `<math>` element comes out, and the
|
|
9
|
+
browser's own MathML draws it: in Chromium, Firefox and Safari, on screen, on
|
|
10
|
+
paper and in a PDF.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { checkMath, MATH_CSS, parseMath, renderMath, texOf } from '@dskripchenko/math'
|
|
14
|
+
|
|
15
|
+
element.innerHTML = renderMath('x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}')
|
|
16
|
+
element.innerHTML = renderMath('\\sum_{i=1}^n i = \\frac{n(n+1)}{2}', { display: true })
|
|
17
|
+
|
|
18
|
+
// A math font, so that fences and roots stretch; the look of an error.
|
|
19
|
+
style.textContent = MATH_CSS
|
|
20
|
+
|
|
21
|
+
// Your own commands, with arguments.
|
|
22
|
+
renderMath('\\norm{\\R^n}', { macros: { R: '\\mathbb{R}', norm: '\\left\\|#1\\right\\|' } })
|
|
23
|
+
|
|
24
|
+
// TeX that cannot be read: shown as written, the reason in its title — or a MathError.
|
|
25
|
+
renderMath('\\frac{1}') // <span class="dsk-math-error" title="An argument is missing">\frac{1}</span>
|
|
26
|
+
checkMath('a + \\nope') // MathError { message: 'Unknown command \\nope', position: 4 }
|
|
27
|
+
|
|
28
|
+
// The TeX back from a drawn formula (it is kept in an annotation).
|
|
29
|
+
texOf(document.querySelector('math')!) // 'x = \\frac{-b …'
|
|
30
|
+
|
|
31
|
+
// The formula as a tree, for a renderer of your own.
|
|
32
|
+
parseMath('x^2') // { type: 'scripts', base: { type: 'ident', text: 'x' }, sup: { type: 'number', text: '2' }, over: false }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**What it reads** — the LaTeX math people write in notes, papers and docs:
|
|
36
|
+
letters and numbers, sub- and superscripts and primes; `\frac`, `\dfrac`,
|
|
37
|
+
`\binom`, `\sqrt[n]`; Greek, operators, relations, arrows, `\not`; big
|
|
38
|
+
operators with limits (`\sum`, `\prod`, `\int`, `\limits`); function names
|
|
39
|
+
(`\sin`, `\lim`, `\max`, `\operatorname`); stretching fences (`\left`,
|
|
40
|
+
`\middle`, `\right`, `\big`…); accents and braces (`\hat`, `\vec`,
|
|
41
|
+
`\overline`, `\overbrace`, `\underbrace`, `\overset`); letter styles
|
|
42
|
+
(`\mathbb`, `\mathbf`, `\mathcal`, `\mathfrak`, `\mathsf`, `\mathtt`,
|
|
43
|
+
`\boldsymbol`); `\text`; spaces; colours; `\boxed`; matrices, `cases`,
|
|
44
|
+
`aligned`, `gathered`, `array`; macros of your own.
|
|
45
|
+
|
|
46
|
+
## What it promises
|
|
47
|
+
|
|
48
|
+
- **MathML Core.** Only what every engine with MathML draws: letter styles
|
|
49
|
+
as Unicode's mathematical letters, alignment and lines in the cells' style.
|
|
50
|
+
- **Errors, not guesses.** An unknown command or an unclosed group is an
|
|
51
|
+
error with its place in the TeX.
|
|
52
|
+
- **Escaped output.** Nothing in the TeX becomes markup; a colour is a name
|
|
53
|
+
or a hex value, nothing else.
|
|
54
|
+
- **Bounded work.** Nesting, length and macro expansion are limited:
|
|
55
|
+
pathological input fails fast.
|
|
56
|
+
- **Small.** About 14 KB gzipped (before your bundler minifies it).
|
|
57
|
+
|
|
58
|
+
Fences, roots and big operators stretch only in a font with an OpenType MATH
|
|
59
|
+
table: `MATH_CSS` names STIX Two Math (macOS), Cambria Math (Windows), Latin
|
|
60
|
+
Modern Math and Noto Sans Math. Where none is installed, the page provides one.
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
| | | | | |
|
|
65
|
+
|---|---|---|---|---|
|
|
66
|
+
| Getting started: API, what is supported, fonts, errors | [en](docs/en/getting-started.md) | [ru](docs/ru/getting-started.md) | [de](docs/de/getting-started.md) | [zh](docs/zh/getting-started.md) |
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install @dskripchenko/math
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[MIT](LICENSE)
|