@sciexpr/presets
预设模板库 — 常用数学公式、化学模板、希腊字母预设。
安装
bash
npm install @sciexpr/presets数学模板 (30+)
六类数学公式模板,按分类/标签/ID 快速检索。
typescript
import {
ALL_MATH_TEMPLATES,
getTemplatesByCategory, searchTemplates, getTemplateById,
} from '@sciexpr/presets'分类
| 分类 | 模板数 | 示例 |
|---|---|---|
calculus | 8 | 导数定义、链式法则、泰勒展开 |
algebra | 7 | 求根公式、二项式定理、等比数列 |
trigonometry | 8 | 和角公式、倍角公式、欧拉公式 |
linear-algebra | 6 | 矩阵乘法、特征值、克拉默法则 |
statistics | 4 | 正态分布、贝叶斯定理 |
physics | 5 | 质能方程、牛顿定律、薛定谔方程 |
检索
typescript
// 按分类
getTemplatesByCategory('calculus')
// → [{ id:'derivative-def', name:'导数定义', latex:'f\'(x)=...', ... }, ...]
// 按关键词搜索
searchTemplates('积分')
// → [{ id:'integral-def', ... }, { id:'integration-by-parts', ... }]
// 按标签搜索
searchTemplates('derivative')
// → [{ id:'derivative-def', ... }, { id:'power-rule', ... }]
// 按 ID 获取
getTemplateById('quadratic-formula')
// → { id:'quadratic-formula', name:'求根公式', latex:'x = \\frac{-b \\pm ...}', ... }模板结构
typescript
interface FormulaTemplate {
id: string // 唯一标识
name: string // 名称
latex: string // LaTeX 源码
category: string // 分类:calculus/algebra/trigonometry/...
description: string // 描述
tags: string[] // 标签
}化学模板 (20+)
常见化合物、经典反应、电化学公式。
typescript
import {
COMPOUND_TEMPLATES, REACTION_TEMPLATES,
searchCompounds, getAcids, getBases,
} from '@sciexpr/presets'常见化合物 (19)
typescript
// 按名称搜索
searchCompounds('硫酸')
// → [{ id:'h2so4', name:'硫酸', latex:'\\ce{H2SO4}', ... }]
// 获取所有酸
getAcids()
// → [{ id:'h2so4', ... }, { id:'hcl', ... }, { id:'hno3', ... }, ...]
// 获取所有碱
getBases()
// → [{ id:'naoh', ... }, { id:'caoh2', ... }]经典反应 (8)
typescript
REACTION_TEMPLATES.map(t => t.name)
// → ['中和反应','甲烷燃烧','光合作用','细胞呼吸','铁生锈','电解水','哈柏法','化学平衡']希腊字母预设
typescript
import { GREEK_LOWERCASE_GROUP, GREEK_UPPERCASE_GROUP, searchGreek } from '@sciexpr/presets'
// 24 个小写字母 (含变体)
GREEK_LOWERCASE_GROUP.letters
// → [{ latex:'\\alpha', unicode:'α', name:'Alpha', ... }, ...]
// 11 个大写字母
GREEK_UPPERCASE_GROUP.letters
// → [{ latex:'\\Gamma', unicode:'Γ', name:'Gamma' }, ...]
// 搜索
searchGreek('alpha')
// → [{ latex:'\\alpha', unicode:'α', ... }]字母结构
typescript
interface GreekLetter {
latex: string // '\\alpha'
unicode: string // 'α'
name: string // 'Alpha'
englishName: string // 'alpha'
variants?: { // 变体(如 \\varepsilon, \\varphi 等)
latex: string
unicode: string
name: string
}[]
}