@webc.site/math 0.1.2 → 0.1.4

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 CHANGED
@@ -21,22 +21,22 @@ 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 & Calling Process](#design--calling-process)
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 & Background](#history--background)
28
+ - [History and Background](#history-and-background)
29
29
 
30
30
  ## Usage
31
31
 
32
32
  ### JavaScript Example
33
33
 
34
- #### 1. Replace Formulas in Markdown (using `@webc.site/math/md`)
34
+ #### 1. Replace Formulas in Markdown (using `@webc.site/math/md.js`)
35
35
 
36
36
  Parses Markdown text, automatically identifying and replacing inline/block equations with MathML.
37
37
 
38
38
  ```javascript
39
- import mdMath from "@webc.site/math/md";
39
+ import mdMath from "@webc.site/math/md.js";
40
40
 
41
41
  const markdown = "Euler's identity: $$e^{i\\pi} + 1 = 0$$";
42
42
  const html = mdMath(markdown);
@@ -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 & Math Font Configuration
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
 
@@ -208,9 +208,9 @@ Currently, the following LaTeX extensions, macro definitions, or custom styling
208
208
  8. **Equation Numbering & Custom Tags**: `\tag`, `\newtagform`, `\usetagform`, etc.
209
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.
210
210
 
211
- ## Error Handling & Fault Tolerance
211
+ ## Error Handling and Fault Tolerance
212
212
 
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.
213
+ When parsing Markdown text using `@webc.site/math/md.js`, 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.
214
214
 
215
215
  Note that calling `@webc.site/math` (the TeX compiler core) directly with invalid LaTeX syntax will throw an array containing an error code (see the internal error codes table below). If you are using the core TeX compiler directly, it is recommended to wrap the call in a `try...catch` block.
216
216
 
@@ -252,7 +252,7 @@ Our compiler acts as a translator that turns TeX into standard MathML tags on th
252
252
 
253
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.
254
254
 
255
- #### 4. Unified Frontend & SSR Capabilities
255
+ #### 4. Unified Frontend and SSR Capabilities
256
256
 
257
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.
258
258
 
@@ -280,7 +280,7 @@ Based on compiling standard test equations (measured using [sh/benchmark.js](htt
280
280
 
281
281
  ![](demo/speed.svg)
282
282
 
283
- ## Design & Calling Process
283
+ ## Design and Calling Process
284
284
 
285
285
  The parser processes input Markdown string, isolates TeX expressions, and translates them to MathML structures.
286
286
 
@@ -378,7 +378,7 @@ The `SHOW_MAP` dictionary converts AST nodes into standard MathML markup strings
378
378
  └── test.sh # Formatter, linter, and compiler test runner
379
379
  ```
380
380
 
381
- ## History & Background
381
+ ## History and Background
382
382
 
383
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.
384
384
 
@@ -404,8 +404,8 @@ The `18s` project provides a optimized math font `m` (Latin Modern Math, derived
404
404
  - [使用方法](#使用方法)
405
405
  - [功能特性](#功能特性)
406
406
  - [支持的语法清单](#支持的语法清单)
407
- - [什么是 MathML?](#什么是-mathml)
408
- - [为什么需要 TeX 公式转 MathML?](#为什么需要-tex-公式转-mathml)
407
+ - [什么是 MathML?](#什么是-mathml)
408
+ - [为什么需要 TeX 公式转 MathML?](#为什么需要-tex-公式转-mathml)
409
409
  - [性能对比](#性能对比)
410
410
  - [设计思路与调用流程](#设计思路与调用流程)
411
411
  - [如何添加新的语法支持](#如何添加新的语法支持)
@@ -417,12 +417,12 @@ The `18s` project provides a optimized math font `m` (Latin Modern Math, derived
417
417
 
418
418
  ### JavaScript 示例
419
419
 
420
- #### 1. 替换 Markdown 中的公式(使用 `@webc.site/math/md`)
420
+ #### 1. 替换 Markdown 中的公式(使用 `@webc.site/math/md.js`)
421
421
 
422
422
  输入 Markdown 文本,自动识别其中的行内/块级公式并替换为 MathML。
423
423
 
424
424
  ```javascript
425
- import mdMath from "@webc.site/math/md";
425
+ import mdMath from "@webc.site/math/md.js";
426
426
 
427
427
  const markdown = "欧拉恒等式:$$e^{i\\pi} + 1 = 0$$";
428
428
  const html = mdMath(markdown);
@@ -596,7 +596,7 @@ math {
596
596
 
597
597
  ## 错误处理与容错机制
598
598
 
599
- 在使用 `@webc.site/math/md` 解析 Markdown 文本时,如果数学公式中包含非法的 LaTeX 语法(例如未闭合的 `\left`),内部会自动捕获该语法错误,并优雅地退化为显示原始的公式文本(如 `$$x + \left( y$$`),而不会抛出 JavaScript 异常或导致网页/应用渲染崩溃。因此,调用该函数时**无需**使用 `try...catch` 块包裹。
599
+ 在使用 `@webc.site/math/md.js` 解析 Markdown 文本时,如果数学公式中包含非法的 LaTeX 语法(例如未闭合的 `\left`),内部会自动捕获该语法错误,并优雅地退化为显示原始的公式文本(如 `$$x + \left( y$$`),而不会抛出 JavaScript 异常或导致网页/应用渲染崩溃。因此,调用该函数时**无需**使用 `try...catch` 块包裹。
600
600
 
601
601
  但需要注意的是,如果直接使用 `@webc.site/math` 的默认导出(TeX 编译器核心)来渲染非法的 LaTeX 语法,它会抛出包含错误码的数组(详见下文错误码表)。因此,直接调用 TeX 编译器时建议使用 `try...catch` 进行包裹。
602
602
 
package/mathml.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function mathml(tex: string, block?: boolean): string;
package/md.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function mdMath(md: string): string;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@webc.site/math","version":"0.1.2","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"}}
1
+ {"name":"@webc.site/math","version":"0.1.4","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":{".":{"types":"./mathml.d.ts","default":"./mathml.js"},"./md.js":{"types":"./md.d.ts","default":"./md.js"},"./*":"./*"},"dependencies":{}}