latex2unicode
v0.1.0
Published
Convert LaTeX math expressions to readable Unicode text
Readme
latex2unicode
Convert LaTeX math expressions to readable Unicode text. Zero dependencies, works in Node and browsers.
�?LaTeX 数学公式转换成可读的 Unicode 文本。零依赖,Node 和浏览器通用�?
Install
npm install latex2unicode
# or
bun add latex2unicodeUsage
import { latexToUnicode } from "latex2unicode"
latexToUnicode("y = \\beta_0 + \\beta_1 x + \\varepsilon")
// �?"𝑦 = β₀ + β₁�?+ ε"
latexToUnicode("\\hat{\\beta} = (X'X)^{-1}X'y")
// �?"β̂ = (𝑋′�?⁻¹𝑋′�?
latexToUnicode("\\frac{x^2+1}{x-1}")
// �?"(𝑥² + 1)/(𝑥 �?1)"
latexToUnicode("\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}")
// �?"[1 0; 0 1]"
latexToUnicode("\\sum_{i=1}^{n} x_i")
// �?"∑ᵢ₌₁ⁿ𝑥ᵢ"Options
latexToUnicode(input, { italic: false }) // 输出普通字母而非数学斜体字符What it supports
- 希腊字母与变�?α β γ �?ε φ)
- 上下�?𝑥ᵢ²、β₀、𝑒⁻ᵝ�?
- 分式:
\frac{1}{2}�?½;\frac{a}{b}�?ᵃ⁄b;复杂分式回退�?(a)/(b) - 根号:
\sqrt{x}�?√�?- 运算符与关系�?�?�?�?�?�?�?�?�?�?�?�?�? - 显示偏好符号(�?�?�?�?全系)
- 数学字母样式(�?�?𝔼 �?
- 矩阵�?cases 环境(bmatrix/pmatrix/vmatrix/cases)
- 组合重音(β̂、𝑥̄、𝑎⃗)
- 数学斜体变量(𝑥𝑦𝑧、𝐴𝐵�?
符号表数据驱�? �?LaTeX 官方 unicode-math 符号�?2469 个符�?+ KaTeX 符号�?(传统 LaTeX 命令�?自动生成(bun run generate),不手写白名单,杜绝遗漏�?
回退策略: 无法识别的命令原样输�?去掉反斜�?,保证信息不丢失�?
Test
bun testLicense
MIT
