@webc.site/math 0.1.1 → 0.1.3
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/README.md +26 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,11 +21,11 @@ The world's smallest and fastest web Markdown formula renderer designed to parse
|
|
|
21
21
|
- [What is MathML?](#what-is-mathml)
|
|
22
22
|
- [Why Compile TeX Formulas to MathML?](#why-compile-tex-formulas-to-mathml)
|
|
23
23
|
- [Benchmark](#benchmark)
|
|
24
|
-
- [Design
|
|
24
|
+
- [Design and Calling Process](#design-and-calling-process)
|
|
25
25
|
- [How to Add Syntax Support](#how-to-add-syntax-support)
|
|
26
26
|
- [Tech Stack](#tech-stack)
|
|
27
27
|
- [Directory Structure](#directory-structure)
|
|
28
|
-
- [History
|
|
28
|
+
- [History and Background](#history-and-background)
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
@@ -56,7 +56,7 @@ const tex = "e^{i\\pi} + 1 = 0";
|
|
|
56
56
|
const html = mathml(tex, true); // true for block math, false/empty for inline math
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
### CSS
|
|
59
|
+
### CSS and Math Font Configuration
|
|
60
60
|
|
|
61
61
|
For browser mathematical layout engines to present beautifully typeset math equations, we highly recommend using a math font. The **Latin Modern Math** font provided in the `18s` package is recommended (derived from Knuth's classical Computer Modern typeface, with a complete mathematical symbol set and OpenType MATH table support).
|
|
62
62
|
|
|
@@ -90,8 +90,11 @@ Depending on your project setup, choose one of the following methods to import t
|
|
|
90
90
|
```javascript
|
|
91
91
|
// Import the bundle (includes Source Han Sans t, monospace c, and math font m)
|
|
92
92
|
import "18s/_.css";
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or import math font `m` only:
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
```javascript
|
|
95
98
|
import "18s/m.css";
|
|
96
99
|
```
|
|
97
100
|
|
|
@@ -100,8 +103,11 @@ import "18s/m.css";
|
|
|
100
103
|
```css
|
|
101
104
|
/* Import the bundle (includes Source Han Sans t, monospace c, and math font m) */
|
|
102
105
|
@import "18s/_.css";
|
|
106
|
+
```
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
Or import math font `m` only:
|
|
109
|
+
|
|
110
|
+
```css
|
|
105
111
|
@import "18s/m.css";
|
|
106
112
|
```
|
|
107
113
|
|
|
@@ -185,7 +191,7 @@ Designed to be extremely lightweight, this library supports the most commonly us
|
|
|
185
191
|
- **Matrices & Multi-line Layouts**:
|
|
186
192
|
- Matrix environments: `matrix`, `pmatrix`, `bmatrix`, `vmatrix`, `Vmatrix` (e.g., `\begin{pmatrix} a & b \\ c & d \end{pmatrix}`)
|
|
187
193
|
- Systems of equations & conditional branches: `cases` (e.g., `\begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}`)
|
|
188
|
-
-
|
|
194
|
+
- General-purpose array layouts: `array`
|
|
189
195
|
- Line breaks & alignments: use `\\`, `\\*`, or `\\[width]` (for custom row spacing, e.g. `\\[10px]`) for line breaks, and `&` for column alignments
|
|
190
196
|
|
|
191
197
|
### Unsupported Syntax (Non-Goals)
|
|
@@ -202,7 +208,7 @@ Currently, the following LaTeX extensions, macro definitions, or custom styling
|
|
|
202
208
|
8. **Equation Numbering & Custom Tags**: `\tag`, `\newtagform`, `\usetagform`, etc.
|
|
203
209
|
9. **Arbitrary Operator Limits**: Except for predefined big operators (`\sum`, `\int`) and limit-like operators (`\lim`), using `\limits` on arbitrary commands or structures (e.g., `\operatorname{sn}\limits_{...}`) is not supported.
|
|
204
210
|
|
|
205
|
-
## Error Handling
|
|
211
|
+
## Error Handling and Fault Tolerance
|
|
206
212
|
|
|
207
213
|
When parsing Markdown text using `@webc.site/math/md`, if a mathematical formula contains invalid LaTeX syntax (such as an unclosed `\left`), the parser automatically catches the compilation error internally and gracefully falls back to displaying the raw formula text (e.g., `$$x + \left( y$$`). This ensures that a single syntax error in a formula won't throw JavaScript exceptions or crash your application. Therefore, you **do not** need to wrap it in a `try...catch` block when calling this function.
|
|
208
214
|
|
|
@@ -246,7 +252,7 @@ Our compiler acts as a translator that turns TeX into standard MathML tags on th
|
|
|
246
252
|
|
|
247
253
|
Because the compilation is purely a fast tag-mapping step and layout is handled natively, CPU usage is minimal. This makes it ideal for **WYSIWYG editors, live markdown previewers, and interactive apps** where formulas need to be rendered dynamically on every keystroke without lag—even on low-end mobile devices.
|
|
248
254
|
|
|
249
|
-
#### 4. Unified Frontend
|
|
255
|
+
#### 4. Unified Frontend and SSR Capabilities
|
|
250
256
|
|
|
251
257
|
Since the output is standard HTML with MathML elements, the same compiler works seamlessly for dynamic client-side rendering (CSR), server-side rendering (SSR), and static site generation (SSG) alike.
|
|
252
258
|
|
|
@@ -274,7 +280,7 @@ Based on compiling standard test equations (measured using [sh/benchmark.js](htt
|
|
|
274
280
|
|
|
275
281
|

|
|
276
282
|
|
|
277
|
-
## Design
|
|
283
|
+
## Design and Calling Process
|
|
278
284
|
|
|
279
285
|
The parser processes input Markdown string, isolates TeX expressions, and translates them to MathML structures.
|
|
280
286
|
|
|
@@ -372,7 +378,7 @@ The `SHOW_MAP` dictionary converts AST nodes into standard MathML markup strings
|
|
|
372
378
|
└── test.sh # Formatter, linter, and compiler test runner
|
|
373
379
|
```
|
|
374
380
|
|
|
375
|
-
## History
|
|
381
|
+
## History and Background
|
|
376
382
|
|
|
377
383
|
Mathematical typesetting on the web has historically relied on heavy libraries like MathJax or KaTeX. These libraries fetch large bundles and execute extensive CSS and layout calculations, causing page loading latencies.
|
|
378
384
|
|
|
@@ -398,7 +404,8 @@ The `18s` project provides a optimized math font `m` (Latin Modern Math, derived
|
|
|
398
404
|
- [使用方法](#使用方法)
|
|
399
405
|
- [功能特性](#功能特性)
|
|
400
406
|
- [支持的语法清单](#支持的语法清单)
|
|
401
|
-
- [什么是 MathML?](#什么是-mathml
|
|
407
|
+
- [什么是 MathML?](#什么是-mathml)
|
|
408
|
+
- [为什么需要 TeX 公式转 MathML?](#为什么需要-tex-公式转-mathml)
|
|
402
409
|
- [性能对比](#性能对比)
|
|
403
410
|
- [设计思路与调用流程](#设计思路与调用流程)
|
|
404
411
|
- [如何添加新的语法支持](#如何添加新的语法支持)
|
|
@@ -469,8 +476,11 @@ npm install 18s
|
|
|
469
476
|
```javascript
|
|
470
477
|
// 引入合并后的字体 CSS(包含思源黑体 t、代码字体 c 及数学字体 m)
|
|
471
478
|
import "18s/_.css";
|
|
479
|
+
```
|
|
472
480
|
|
|
473
|
-
|
|
481
|
+
或者仅按需引入数学字体 `m`:
|
|
482
|
+
|
|
483
|
+
```javascript
|
|
474
484
|
import "18s/m.css";
|
|
475
485
|
```
|
|
476
486
|
|
|
@@ -479,8 +489,11 @@ import "18s/m.css";
|
|
|
479
489
|
```css
|
|
480
490
|
/* 引入合并后的字体 CSS(包含思源黑体 t、代码字体 c 及数学字体 m) */
|
|
481
491
|
@import "18s/_.css";
|
|
492
|
+
```
|
|
482
493
|
|
|
483
|
-
|
|
494
|
+
或者仅按需引入数学字体 `m`:
|
|
495
|
+
|
|
496
|
+
```css
|
|
484
497
|
@import "18s/m.css";
|
|
485
498
|
```
|
|
486
499
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@webc.site/math","version":"0.1.
|
|
1
|
+
{"name":"@webc.site/math","version":"0.1.3","description":"The world's smallest and fastest web Markdown formula renderer / 全球最小最快的网页Markdown公式渲染器","keywords":["markdown","math","mathml","render","tex"],"homepage":"https://math.webc.site","license":"MulanPSL-2.0","author":"i18n.site@gmail.com","repository":{"type":"git","url":"git+https://github.com/webc-site/math.git"},"type":"module","exports":{".":"./mathml.js","./*":"./*"},"scripts":{"prepare":"husky"},"dependencies":{},"lint-staged":{"**/*.svg":"bun sh/hook/svg.js","**/*.styl":"bun sh/hook/styl.js"}}
|