@sciexpr/math 0.1.0 → 0.1.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ # @sciexpr/math
2
+
3
+ > Scientific Expression Engine — Math utilities
4
+
5
+ ## Features
6
+
7
+ - Greek letter & math symbol library
8
+ - Matrix utilities (creation, operations, LaTeX templates)
9
+ - Symbol & function catalogs
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { GREEK_LETTERS, MatrixUtils, identityMatrix, latexMatrixTemplate } from '@sciexpr/math';
15
+ ```
package/dist/index.cjs CHANGED
@@ -22,12 +22,16 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ALL_SYMBOLS: () => ALL_SYMBOLS,
24
24
  ARROWS: () => ARROWS,
25
+ FUNCTIONS: () => FUNCTIONS,
25
26
  GREEK_LOWERCASE: () => GREEK_LOWERCASE,
26
27
  GREEK_UPPERCASE: () => GREEK_UPPERCASE,
28
+ HYPERBOLIC_TRIG: () => HYPERBOLIC_TRIG,
29
+ MATH_PALETTE_CATEGORIES: () => MATH_PALETTE_CATEGORIES,
27
30
  MISC_SYMBOLS: () => MISC_SYMBOLS,
28
31
  MatrixUtils: () => MatrixUtils,
29
32
  OPERATORS: () => OPERATORS,
30
33
  RELATIONS: () => RELATIONS,
34
+ getPaletteSymbols: () => getPaletteSymbols,
31
35
  getSymbolsByCategory: () => getSymbolsByCategory,
32
36
  identityMatrix: () => identityMatrix,
33
37
  latexMatrixTemplate: () => latexMatrixTemplate,
@@ -52,10 +56,12 @@ var GREEK_LOWERCASE = [
52
56
  { latex: "\\mu", unicode: "\u03BC", name: "mu", category: "greek-lower", description: "Mu" },
53
57
  { latex: "\\nu", unicode: "\u03BD", name: "nu", category: "greek-lower", description: "Nu" },
54
58
  { latex: "\\xi", unicode: "\u03BE", name: "xi", category: "greek-lower", description: "Xi" },
59
+ { latex: "\\omicron", unicode: "\u03BF", name: "omicron", category: "greek-lower", description: "Omicron" },
55
60
  { latex: "\\pi", unicode: "\u03C0", name: "pi", category: "greek-lower", description: "Pi" },
56
61
  { latex: "\\rho", unicode: "\u03C1", name: "rho", category: "greek-lower", description: "Rho" },
57
62
  { latex: "\\sigma", unicode: "\u03C3", name: "sigma", category: "greek-lower", description: "Sigma" },
58
63
  { latex: "\\tau", unicode: "\u03C4", name: "tau", category: "greek-lower", description: "Tau" },
64
+ { latex: "\\upsilon", unicode: "\u03C5", name: "upsilon", category: "greek-lower", description: "Upsilon" },
59
65
  { latex: "\\phi", unicode: "\u03C6", name: "phi", category: "greek-lower", description: "Phi" },
60
66
  { latex: "\\chi", unicode: "\u03C7", name: "chi", category: "greek-lower", description: "Chi" },
61
67
  { latex: "\\psi", unicode: "\u03C8", name: "psi", category: "greek-lower", description: "Psi" },
@@ -153,6 +159,158 @@ function searchSymbols(query) {
153
159
  function getSymbolsByCategory(category) {
154
160
  return ALL_SYMBOLS.filter((s) => s.category === category);
155
161
  }
162
+ var FUNCTIONS = [
163
+ { latex: "\\sin", unicode: "sin", name: "sin", category: "function" },
164
+ { latex: "\\cos", unicode: "cos", name: "cos", category: "function" },
165
+ { latex: "\\tan", unicode: "tan", name: "tan", category: "function" },
166
+ { latex: "\\csc", unicode: "csc", name: "csc", category: "function" },
167
+ { latex: "\\sec", unicode: "sec", name: "sec", category: "function" },
168
+ { latex: "\\cot", unicode: "cot", name: "cot", category: "function" },
169
+ { latex: "\\ln", unicode: "ln", name: "natural log", category: "function", description: "\u81EA\u7136\u5BF9\u6570" },
170
+ { latex: "\\log", unicode: "log", name: "logarithm", category: "function" },
171
+ { latex: "\\exp", unicode: "exp", name: "exponential", category: "function", description: "\u6307\u6570\u51FD\u6570" },
172
+ { latex: "\\arg", unicode: "arg", name: "argument", category: "function" },
173
+ { latex: "\\det", unicode: "det", name: "determinant", category: "function" },
174
+ { latex: "\\gcd", unicode: "gcd", name: "gcd", category: "function", description: "\u6700\u5927\u516C\u7EA6\u6570" },
175
+ { latex: "\\lcm", unicode: "lcm", name: "lcm", category: "function", description: "\u6700\u5C0F\u516C\u500D\u6570" },
176
+ { latex: "\\dim", unicode: "dim", name: "dimension", category: "function" },
177
+ { latex: "\\ker", unicode: "ker", name: "kernel", category: "function" },
178
+ { latex: "\\hom", unicode: "hom", name: "homomorphism", category: "function" },
179
+ { latex: "\\deg", unicode: "deg", name: "degree", category: "function" },
180
+ { latex: "\\mod", unicode: "mod", name: "modulo", category: "function" },
181
+ { latex: "\\Pr", unicode: "Pr", name: "probability", category: "function", description: "\u6982\u7387\u51FD\u6570" },
182
+ { latex: "\\min", unicode: "min", name: "minimum", category: "function" },
183
+ { latex: "\\max", unicode: "max", name: "maximum", category: "function" },
184
+ { latex: "\\inf", unicode: "inf", name: "infimum", category: "function", description: "\u4E0B\u786E\u754C" },
185
+ { latex: "\\sup", unicode: "sup", name: "supremum", category: "function", description: "\u4E0A\u786E\u754C" }
186
+ ];
187
+ var HYPERBOLIC_TRIG = [
188
+ { latex: "\\sinh", unicode: "sinh", name: "sinh", category: "hyperbolic", description: "\u53CC\u66F2\u6B63\u5F26" },
189
+ { latex: "\\cosh", unicode: "cosh", name: "cosh", category: "hyperbolic", description: "\u53CC\u66F2\u4F59\u5F26" },
190
+ { latex: "\\tanh", unicode: "tanh", name: "tanh", category: "hyperbolic", description: "\u53CC\u66F2\u6B63\u5207" },
191
+ { latex: "\\coth", unicode: "coth", name: "coth", category: "hyperbolic", description: "\u53CC\u66F2\u4F59\u5207" },
192
+ { latex: "\\arcsin", unicode: "arcsin", name: "arcsin", category: "hyperbolic", description: "\u53CD\u6B63\u5F26" },
193
+ { latex: "\\arccos", unicode: "arccos", name: "arccos", category: "hyperbolic", description: "\u53CD\u4F59\u5F26" },
194
+ { latex: "\\arctan", unicode: "arctan", name: "arctan", category: "hyperbolic", description: "\u53CD\u6B63\u5207" }
195
+ ];
196
+ function toPaletteEntry(s, isCommon) {
197
+ return { ...s, isCommon };
198
+ }
199
+ function toPaletteEntries(items, isCommon) {
200
+ return items.map((s) => toPaletteEntry(s, isCommon));
201
+ }
202
+ var COMMON_GREEK_LOWERCASE = /* @__PURE__ */ new Set([
203
+ "\\alpha",
204
+ "\\beta",
205
+ "\\gamma",
206
+ "\\delta",
207
+ "\\epsilon",
208
+ "\\theta",
209
+ "\\lambda",
210
+ "\\mu",
211
+ "\\pi",
212
+ "\\sigma",
213
+ "\\phi",
214
+ "\\omega"
215
+ ]);
216
+ var COMMON_GREEK_UPPERCASE = /* @__PURE__ */ new Set([
217
+ "\\Gamma",
218
+ "\\Delta",
219
+ "\\Theta",
220
+ "\\Lambda",
221
+ "\\Sigma",
222
+ "\\Pi",
223
+ "\\Phi",
224
+ "\\Omega"
225
+ ]);
226
+ var MATH_PALETTE_CATEGORIES = [
227
+ {
228
+ id: "operations",
229
+ label: "\u8FD0\u7B97",
230
+ symbols: toPaletteEntries(OPERATORS, true)
231
+ },
232
+ {
233
+ id: "relations",
234
+ label: "\u5173\u7CFB",
235
+ symbols: toPaletteEntries(RELATIONS, true)
236
+ },
237
+ {
238
+ id: "arrows",
239
+ label: "\u7BAD\u5934",
240
+ symbols: toPaletteEntries(ARROWS, true)
241
+ },
242
+ {
243
+ id: "greek",
244
+ label: "\u5E0C\u814A\u5B57\u6BCD",
245
+ symbols: [
246
+ ...GREEK_LOWERCASE.filter((s) => COMMON_GREEK_LOWERCASE.has(s.latex)).map((s) => toPaletteEntry(s, true)),
247
+ ...GREEK_UPPERCASE.filter((s) => COMMON_GREEK_UPPERCASE.has(s.latex)).map((s) => toPaletteEntry(s, true))
248
+ ]
249
+ },
250
+ {
251
+ id: "matrix",
252
+ label: "\u77E9\u9635",
253
+ symbols: [
254
+ { latex: "\\begin{pmatrix} & \\\\ & \\end{pmatrix}", unicode: "\u25A6", name: "pmatrix", category: "matrix", isCommon: true },
255
+ { latex: "\\begin{bmatrix} & \\\\ & \\end{bmatrix}", unicode: "\u25A6", name: "bmatrix", category: "matrix", isCommon: true },
256
+ { latex: "\\begin{vmatrix} & \\\\ & \\end{vmatrix}", unicode: "\u25A6", name: "vmatrix", category: "matrix", isCommon: false },
257
+ { latex: "\\begin{Vmatrix} & \\\\ & \\end{Vmatrix}", unicode: "\u25A6", name: "Vmatrix", category: "matrix", isCommon: false },
258
+ { latex: "\\begin{matrix} & \\\\ & \\end{matrix}", unicode: "\u25A6", name: "matrix", category: "matrix", isCommon: false },
259
+ { latex: "\\begin{Bmatrix} & \\\\ & \\end{Bmatrix}", unicode: "\u25A6", name: "Bmatrix", category: "matrix", isCommon: false }
260
+ ]
261
+ },
262
+ {
263
+ id: "scripts",
264
+ label: "\u4E0A\u4E0B\u6807",
265
+ symbols: [
266
+ { latex: "^{}", unicode: "\u02E3", name: "superscript", category: "script", isCommon: true },
267
+ { latex: "_{}", unicode: "\u2093", name: "subscript", category: "script", isCommon: true },
268
+ { latex: "_{}^{}", unicode: "\u2093\u02E3", name: "sub-superscript", category: "script", isCommon: true },
269
+ { latex: "\\overline{}", unicode: "x\u0304", name: "overline", category: "script", isCommon: false, description: "\u4E0A\u5212\u7EBF" },
270
+ { latex: "\\underline{}", unicode: "x\u0332", name: "underline", category: "script", isCommon: false, description: "\u4E0B\u5212\u7EBF" },
271
+ { latex: "\\hat{}", unicode: "x\u0302", name: "hat", category: "script", isCommon: false, description: "\u5E3D\u5B50\u7B26\u53F7" },
272
+ { latex: "\\bar{}", unicode: "x\u0304", name: "bar", category: "script", isCommon: false, description: "\u4E0A\u6A2A\u7EBF" },
273
+ { latex: "\\vec{}", unicode: "x\u20D7", name: "vector", category: "script", isCommon: false, description: "\u5411\u91CF\u7BAD\u5934" },
274
+ { latex: "\\dot{}", unicode: "x\u0307", name: "dot", category: "script", isCommon: false, description: "\u70B9\u5BFC\u6570" },
275
+ { latex: "\\ddot{}", unicode: "x\u0308", name: "ddot", category: "script", isCommon: false, description: "\u53CC\u70B9\u5BFC\u6570" }
276
+ ]
277
+ },
278
+ {
279
+ id: "large-ops",
280
+ label: "\u5927\u578B\u8FD0\u7B97",
281
+ symbols: [
282
+ { latex: "\\sum_{}^{}", unicode: "\u2211", name: "sum", category: "large-op", isCommon: true },
283
+ { latex: "\\prod_{}^{}", unicode: "\u220F", name: "product", category: "large-op", isCommon: true },
284
+ { latex: "\\int_{}^{}", unicode: "\u222B", name: "integral", category: "large-op", isCommon: true },
285
+ { latex: "\\iint_{}^{}", unicode: "\u222C", name: "double integral", category: "large-op", isCommon: false },
286
+ { latex: "\\iiint_{}^{}", unicode: "\u222D", name: "triple integral", category: "large-op", isCommon: false },
287
+ { latex: "\\oint_{}^{}", unicode: "\u222E", name: "contour integral", category: "large-op", isCommon: false },
288
+ { latex: "\\lim_{}", unicode: "lim", name: "limit", category: "large-op", isCommon: true },
289
+ { latex: "\\lim_{x \\to }{}", unicode: "lim", name: "limit x\u2192", category: "large-op", isCommon: false, description: "\u53D8\u91CF\u8D8B\u5411\u7684\u6781\u9650" },
290
+ { latex: "\\max", unicode: "max", name: "max", category: "large-op", isCommon: true },
291
+ { latex: "\\min", unicode: "min", name: "min", category: "large-op", isCommon: true }
292
+ ]
293
+ },
294
+ {
295
+ id: "functions",
296
+ label: "\u51FD\u6570",
297
+ symbols: toPaletteEntries(FUNCTIONS, true)
298
+ },
299
+ {
300
+ id: "hyperbolic-trig",
301
+ label: "\u53CC\u66F2/\u53CD\u4E09\u89D2",
302
+ symbols: toPaletteEntries(HYPERBOLIC_TRIG, true)
303
+ },
304
+ {
305
+ id: "misc",
306
+ label: "\u5176\u4ED6\u7B26\u53F7",
307
+ symbols: toPaletteEntries(MISC_SYMBOLS, true)
308
+ }
309
+ ];
310
+ function getPaletteSymbols(categoryId) {
311
+ const cat = MATH_PALETTE_CATEGORIES.find((c) => c.id === categoryId);
312
+ return cat?.symbols ?? [];
313
+ }
156
314
 
157
315
  // src/matrix.ts
158
316
  var MatrixUtils = class {
@@ -197,9 +355,9 @@ var MatrixUtils = class {
197
355
  }
198
356
  /**
199
357
  * 格式化矩阵为 LaTeX
200
- * @param matrix 矩阵数据(字符串数组)
201
- * @param matrixType 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
202
- * @param columnAlign 列对齐 (l/c/r)
358
+ * @param matrix - 矩阵数据(字符串数组)
359
+ * @param options.matrixType - 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
360
+ * @param options.columnAlign - 列对齐 (l/c/r)
203
361
  */
204
362
  toLaTeX(matrix, options) {
205
363
  const type = options?.matrixType ?? "pmatrix";
@@ -291,12 +449,16 @@ ${body}
291
449
  0 && (module.exports = {
292
450
  ALL_SYMBOLS,
293
451
  ARROWS,
452
+ FUNCTIONS,
294
453
  GREEK_LOWERCASE,
295
454
  GREEK_UPPERCASE,
455
+ HYPERBOLIC_TRIG,
456
+ MATH_PALETTE_CATEGORIES,
296
457
  MISC_SYMBOLS,
297
458
  MatrixUtils,
298
459
  OPERATORS,
299
460
  RELATIONS,
461
+ getPaletteSymbols,
300
462
  getSymbolsByCategory,
301
463
  identityMatrix,
302
464
  latexMatrixTemplate,
package/dist/index.d.cts CHANGED
@@ -23,6 +23,26 @@ declare const ALL_SYMBOLS: SymbolEntry[];
23
23
  declare function searchSymbols(query: string): SymbolEntry[];
24
24
  /** 按分类获取符号 */
25
25
  declare function getSymbolsByCategory(category: string): SymbolEntry[];
26
+ declare const FUNCTIONS: SymbolEntry[];
27
+ declare const HYPERBOLIC_TRIG: SymbolEntry[];
28
+ /** Palette 符号条目(扩展自 SymbolEntry,增加 isCommon 标记) */
29
+ interface PaletteSymbolEntry extends SymbolEntry {
30
+ /** 是否为该分类中的常用符号 */
31
+ isCommon?: boolean;
32
+ }
33
+ /** 子分类 palette 数据 */
34
+ interface SubCategoryPalette {
35
+ /** 子分类 ID */
36
+ id: string;
37
+ /** 子分类标签(中文) */
38
+ label: string;
39
+ /** 符号列表 */
40
+ symbols: PaletteSymbolEntry[];
41
+ }
42
+ /** 数学分类的 palette 子分类数据 */
43
+ declare const MATH_PALETTE_CATEGORIES: SubCategoryPalette[];
44
+ /** 根据子分类 ID 获取 palette 符号 */
45
+ declare function getPaletteSymbols(categoryId: string): PaletteSymbolEntry[];
26
46
 
27
47
  /**
28
48
  * 矩阵工具
@@ -46,9 +66,9 @@ declare class MatrixUtils {
46
66
  transpose<T>(matrix: T[][]): T[][];
47
67
  /**
48
68
  * 格式化矩阵为 LaTeX
49
- * @param matrix 矩阵数据(字符串数组)
50
- * @param matrixType 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
51
- * @param columnAlign 列对齐 (l/c/r)
69
+ * @param matrix - 矩阵数据(字符串数组)
70
+ * @param options.matrixType - 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
71
+ * @param options.columnAlign - 列对齐 (l/c/r)
52
72
  */
53
73
  toLaTeX(matrix: string[][], options?: {
54
74
  matrixType?: 'matrix' | 'pmatrix' | 'bmatrix' | 'vmatrix' | 'Bmatrix' | 'Vmatrix';
@@ -89,4 +109,4 @@ declare function identityMatrix(n: number): number[][];
89
109
  /** 创建 LaTeX 矩阵模板字符串 */
90
110
  declare function latexMatrixTemplate(rows: number, cols: number): string;
91
111
 
92
- export { ALL_SYMBOLS, ARROWS, GREEK_LOWERCASE, GREEK_UPPERCASE, MISC_SYMBOLS, MatrixUtils, OPERATORS, RELATIONS, type SymbolEntry, getSymbolsByCategory, identityMatrix, latexMatrixTemplate, searchSymbols, zeroMatrix };
112
+ export { ALL_SYMBOLS, ARROWS, FUNCTIONS, GREEK_LOWERCASE, GREEK_UPPERCASE, HYPERBOLIC_TRIG, MATH_PALETTE_CATEGORIES, MISC_SYMBOLS, MatrixUtils, OPERATORS, type PaletteSymbolEntry, RELATIONS, type SubCategoryPalette, type SymbolEntry, getPaletteSymbols, getSymbolsByCategory, identityMatrix, latexMatrixTemplate, searchSymbols, zeroMatrix };
package/dist/index.d.ts CHANGED
@@ -23,6 +23,26 @@ declare const ALL_SYMBOLS: SymbolEntry[];
23
23
  declare function searchSymbols(query: string): SymbolEntry[];
24
24
  /** 按分类获取符号 */
25
25
  declare function getSymbolsByCategory(category: string): SymbolEntry[];
26
+ declare const FUNCTIONS: SymbolEntry[];
27
+ declare const HYPERBOLIC_TRIG: SymbolEntry[];
28
+ /** Palette 符号条目(扩展自 SymbolEntry,增加 isCommon 标记) */
29
+ interface PaletteSymbolEntry extends SymbolEntry {
30
+ /** 是否为该分类中的常用符号 */
31
+ isCommon?: boolean;
32
+ }
33
+ /** 子分类 palette 数据 */
34
+ interface SubCategoryPalette {
35
+ /** 子分类 ID */
36
+ id: string;
37
+ /** 子分类标签(中文) */
38
+ label: string;
39
+ /** 符号列表 */
40
+ symbols: PaletteSymbolEntry[];
41
+ }
42
+ /** 数学分类的 palette 子分类数据 */
43
+ declare const MATH_PALETTE_CATEGORIES: SubCategoryPalette[];
44
+ /** 根据子分类 ID 获取 palette 符号 */
45
+ declare function getPaletteSymbols(categoryId: string): PaletteSymbolEntry[];
26
46
 
27
47
  /**
28
48
  * 矩阵工具
@@ -46,9 +66,9 @@ declare class MatrixUtils {
46
66
  transpose<T>(matrix: T[][]): T[][];
47
67
  /**
48
68
  * 格式化矩阵为 LaTeX
49
- * @param matrix 矩阵数据(字符串数组)
50
- * @param matrixType 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
51
- * @param columnAlign 列对齐 (l/c/r)
69
+ * @param matrix - 矩阵数据(字符串数组)
70
+ * @param options.matrixType - 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
71
+ * @param options.columnAlign - 列对齐 (l/c/r)
52
72
  */
53
73
  toLaTeX(matrix: string[][], options?: {
54
74
  matrixType?: 'matrix' | 'pmatrix' | 'bmatrix' | 'vmatrix' | 'Bmatrix' | 'Vmatrix';
@@ -89,4 +109,4 @@ declare function identityMatrix(n: number): number[][];
89
109
  /** 创建 LaTeX 矩阵模板字符串 */
90
110
  declare function latexMatrixTemplate(rows: number, cols: number): string;
91
111
 
92
- export { ALL_SYMBOLS, ARROWS, GREEK_LOWERCASE, GREEK_UPPERCASE, MISC_SYMBOLS, MatrixUtils, OPERATORS, RELATIONS, type SymbolEntry, getSymbolsByCategory, identityMatrix, latexMatrixTemplate, searchSymbols, zeroMatrix };
112
+ export { ALL_SYMBOLS, ARROWS, FUNCTIONS, GREEK_LOWERCASE, GREEK_UPPERCASE, HYPERBOLIC_TRIG, MATH_PALETTE_CATEGORIES, MISC_SYMBOLS, MatrixUtils, OPERATORS, type PaletteSymbolEntry, RELATIONS, type SubCategoryPalette, type SymbolEntry, getPaletteSymbols, getSymbolsByCategory, identityMatrix, latexMatrixTemplate, searchSymbols, zeroMatrix };
package/dist/index.js CHANGED
@@ -14,10 +14,12 @@ var GREEK_LOWERCASE = [
14
14
  { latex: "\\mu", unicode: "\u03BC", name: "mu", category: "greek-lower", description: "Mu" },
15
15
  { latex: "\\nu", unicode: "\u03BD", name: "nu", category: "greek-lower", description: "Nu" },
16
16
  { latex: "\\xi", unicode: "\u03BE", name: "xi", category: "greek-lower", description: "Xi" },
17
+ { latex: "\\omicron", unicode: "\u03BF", name: "omicron", category: "greek-lower", description: "Omicron" },
17
18
  { latex: "\\pi", unicode: "\u03C0", name: "pi", category: "greek-lower", description: "Pi" },
18
19
  { latex: "\\rho", unicode: "\u03C1", name: "rho", category: "greek-lower", description: "Rho" },
19
20
  { latex: "\\sigma", unicode: "\u03C3", name: "sigma", category: "greek-lower", description: "Sigma" },
20
21
  { latex: "\\tau", unicode: "\u03C4", name: "tau", category: "greek-lower", description: "Tau" },
22
+ { latex: "\\upsilon", unicode: "\u03C5", name: "upsilon", category: "greek-lower", description: "Upsilon" },
21
23
  { latex: "\\phi", unicode: "\u03C6", name: "phi", category: "greek-lower", description: "Phi" },
22
24
  { latex: "\\chi", unicode: "\u03C7", name: "chi", category: "greek-lower", description: "Chi" },
23
25
  { latex: "\\psi", unicode: "\u03C8", name: "psi", category: "greek-lower", description: "Psi" },
@@ -115,6 +117,158 @@ function searchSymbols(query) {
115
117
  function getSymbolsByCategory(category) {
116
118
  return ALL_SYMBOLS.filter((s) => s.category === category);
117
119
  }
120
+ var FUNCTIONS = [
121
+ { latex: "\\sin", unicode: "sin", name: "sin", category: "function" },
122
+ { latex: "\\cos", unicode: "cos", name: "cos", category: "function" },
123
+ { latex: "\\tan", unicode: "tan", name: "tan", category: "function" },
124
+ { latex: "\\csc", unicode: "csc", name: "csc", category: "function" },
125
+ { latex: "\\sec", unicode: "sec", name: "sec", category: "function" },
126
+ { latex: "\\cot", unicode: "cot", name: "cot", category: "function" },
127
+ { latex: "\\ln", unicode: "ln", name: "natural log", category: "function", description: "\u81EA\u7136\u5BF9\u6570" },
128
+ { latex: "\\log", unicode: "log", name: "logarithm", category: "function" },
129
+ { latex: "\\exp", unicode: "exp", name: "exponential", category: "function", description: "\u6307\u6570\u51FD\u6570" },
130
+ { latex: "\\arg", unicode: "arg", name: "argument", category: "function" },
131
+ { latex: "\\det", unicode: "det", name: "determinant", category: "function" },
132
+ { latex: "\\gcd", unicode: "gcd", name: "gcd", category: "function", description: "\u6700\u5927\u516C\u7EA6\u6570" },
133
+ { latex: "\\lcm", unicode: "lcm", name: "lcm", category: "function", description: "\u6700\u5C0F\u516C\u500D\u6570" },
134
+ { latex: "\\dim", unicode: "dim", name: "dimension", category: "function" },
135
+ { latex: "\\ker", unicode: "ker", name: "kernel", category: "function" },
136
+ { latex: "\\hom", unicode: "hom", name: "homomorphism", category: "function" },
137
+ { latex: "\\deg", unicode: "deg", name: "degree", category: "function" },
138
+ { latex: "\\mod", unicode: "mod", name: "modulo", category: "function" },
139
+ { latex: "\\Pr", unicode: "Pr", name: "probability", category: "function", description: "\u6982\u7387\u51FD\u6570" },
140
+ { latex: "\\min", unicode: "min", name: "minimum", category: "function" },
141
+ { latex: "\\max", unicode: "max", name: "maximum", category: "function" },
142
+ { latex: "\\inf", unicode: "inf", name: "infimum", category: "function", description: "\u4E0B\u786E\u754C" },
143
+ { latex: "\\sup", unicode: "sup", name: "supremum", category: "function", description: "\u4E0A\u786E\u754C" }
144
+ ];
145
+ var HYPERBOLIC_TRIG = [
146
+ { latex: "\\sinh", unicode: "sinh", name: "sinh", category: "hyperbolic", description: "\u53CC\u66F2\u6B63\u5F26" },
147
+ { latex: "\\cosh", unicode: "cosh", name: "cosh", category: "hyperbolic", description: "\u53CC\u66F2\u4F59\u5F26" },
148
+ { latex: "\\tanh", unicode: "tanh", name: "tanh", category: "hyperbolic", description: "\u53CC\u66F2\u6B63\u5207" },
149
+ { latex: "\\coth", unicode: "coth", name: "coth", category: "hyperbolic", description: "\u53CC\u66F2\u4F59\u5207" },
150
+ { latex: "\\arcsin", unicode: "arcsin", name: "arcsin", category: "hyperbolic", description: "\u53CD\u6B63\u5F26" },
151
+ { latex: "\\arccos", unicode: "arccos", name: "arccos", category: "hyperbolic", description: "\u53CD\u4F59\u5F26" },
152
+ { latex: "\\arctan", unicode: "arctan", name: "arctan", category: "hyperbolic", description: "\u53CD\u6B63\u5207" }
153
+ ];
154
+ function toPaletteEntry(s, isCommon) {
155
+ return { ...s, isCommon };
156
+ }
157
+ function toPaletteEntries(items, isCommon) {
158
+ return items.map((s) => toPaletteEntry(s, isCommon));
159
+ }
160
+ var COMMON_GREEK_LOWERCASE = /* @__PURE__ */ new Set([
161
+ "\\alpha",
162
+ "\\beta",
163
+ "\\gamma",
164
+ "\\delta",
165
+ "\\epsilon",
166
+ "\\theta",
167
+ "\\lambda",
168
+ "\\mu",
169
+ "\\pi",
170
+ "\\sigma",
171
+ "\\phi",
172
+ "\\omega"
173
+ ]);
174
+ var COMMON_GREEK_UPPERCASE = /* @__PURE__ */ new Set([
175
+ "\\Gamma",
176
+ "\\Delta",
177
+ "\\Theta",
178
+ "\\Lambda",
179
+ "\\Sigma",
180
+ "\\Pi",
181
+ "\\Phi",
182
+ "\\Omega"
183
+ ]);
184
+ var MATH_PALETTE_CATEGORIES = [
185
+ {
186
+ id: "operations",
187
+ label: "\u8FD0\u7B97",
188
+ symbols: toPaletteEntries(OPERATORS, true)
189
+ },
190
+ {
191
+ id: "relations",
192
+ label: "\u5173\u7CFB",
193
+ symbols: toPaletteEntries(RELATIONS, true)
194
+ },
195
+ {
196
+ id: "arrows",
197
+ label: "\u7BAD\u5934",
198
+ symbols: toPaletteEntries(ARROWS, true)
199
+ },
200
+ {
201
+ id: "greek",
202
+ label: "\u5E0C\u814A\u5B57\u6BCD",
203
+ symbols: [
204
+ ...GREEK_LOWERCASE.filter((s) => COMMON_GREEK_LOWERCASE.has(s.latex)).map((s) => toPaletteEntry(s, true)),
205
+ ...GREEK_UPPERCASE.filter((s) => COMMON_GREEK_UPPERCASE.has(s.latex)).map((s) => toPaletteEntry(s, true))
206
+ ]
207
+ },
208
+ {
209
+ id: "matrix",
210
+ label: "\u77E9\u9635",
211
+ symbols: [
212
+ { latex: "\\begin{pmatrix} & \\\\ & \\end{pmatrix}", unicode: "\u25A6", name: "pmatrix", category: "matrix", isCommon: true },
213
+ { latex: "\\begin{bmatrix} & \\\\ & \\end{bmatrix}", unicode: "\u25A6", name: "bmatrix", category: "matrix", isCommon: true },
214
+ { latex: "\\begin{vmatrix} & \\\\ & \\end{vmatrix}", unicode: "\u25A6", name: "vmatrix", category: "matrix", isCommon: false },
215
+ { latex: "\\begin{Vmatrix} & \\\\ & \\end{Vmatrix}", unicode: "\u25A6", name: "Vmatrix", category: "matrix", isCommon: false },
216
+ { latex: "\\begin{matrix} & \\\\ & \\end{matrix}", unicode: "\u25A6", name: "matrix", category: "matrix", isCommon: false },
217
+ { latex: "\\begin{Bmatrix} & \\\\ & \\end{Bmatrix}", unicode: "\u25A6", name: "Bmatrix", category: "matrix", isCommon: false }
218
+ ]
219
+ },
220
+ {
221
+ id: "scripts",
222
+ label: "\u4E0A\u4E0B\u6807",
223
+ symbols: [
224
+ { latex: "^{}", unicode: "\u02E3", name: "superscript", category: "script", isCommon: true },
225
+ { latex: "_{}", unicode: "\u2093", name: "subscript", category: "script", isCommon: true },
226
+ { latex: "_{}^{}", unicode: "\u2093\u02E3", name: "sub-superscript", category: "script", isCommon: true },
227
+ { latex: "\\overline{}", unicode: "x\u0304", name: "overline", category: "script", isCommon: false, description: "\u4E0A\u5212\u7EBF" },
228
+ { latex: "\\underline{}", unicode: "x\u0332", name: "underline", category: "script", isCommon: false, description: "\u4E0B\u5212\u7EBF" },
229
+ { latex: "\\hat{}", unicode: "x\u0302", name: "hat", category: "script", isCommon: false, description: "\u5E3D\u5B50\u7B26\u53F7" },
230
+ { latex: "\\bar{}", unicode: "x\u0304", name: "bar", category: "script", isCommon: false, description: "\u4E0A\u6A2A\u7EBF" },
231
+ { latex: "\\vec{}", unicode: "x\u20D7", name: "vector", category: "script", isCommon: false, description: "\u5411\u91CF\u7BAD\u5934" },
232
+ { latex: "\\dot{}", unicode: "x\u0307", name: "dot", category: "script", isCommon: false, description: "\u70B9\u5BFC\u6570" },
233
+ { latex: "\\ddot{}", unicode: "x\u0308", name: "ddot", category: "script", isCommon: false, description: "\u53CC\u70B9\u5BFC\u6570" }
234
+ ]
235
+ },
236
+ {
237
+ id: "large-ops",
238
+ label: "\u5927\u578B\u8FD0\u7B97",
239
+ symbols: [
240
+ { latex: "\\sum_{}^{}", unicode: "\u2211", name: "sum", category: "large-op", isCommon: true },
241
+ { latex: "\\prod_{}^{}", unicode: "\u220F", name: "product", category: "large-op", isCommon: true },
242
+ { latex: "\\int_{}^{}", unicode: "\u222B", name: "integral", category: "large-op", isCommon: true },
243
+ { latex: "\\iint_{}^{}", unicode: "\u222C", name: "double integral", category: "large-op", isCommon: false },
244
+ { latex: "\\iiint_{}^{}", unicode: "\u222D", name: "triple integral", category: "large-op", isCommon: false },
245
+ { latex: "\\oint_{}^{}", unicode: "\u222E", name: "contour integral", category: "large-op", isCommon: false },
246
+ { latex: "\\lim_{}", unicode: "lim", name: "limit", category: "large-op", isCommon: true },
247
+ { latex: "\\lim_{x \\to }{}", unicode: "lim", name: "limit x\u2192", category: "large-op", isCommon: false, description: "\u53D8\u91CF\u8D8B\u5411\u7684\u6781\u9650" },
248
+ { latex: "\\max", unicode: "max", name: "max", category: "large-op", isCommon: true },
249
+ { latex: "\\min", unicode: "min", name: "min", category: "large-op", isCommon: true }
250
+ ]
251
+ },
252
+ {
253
+ id: "functions",
254
+ label: "\u51FD\u6570",
255
+ symbols: toPaletteEntries(FUNCTIONS, true)
256
+ },
257
+ {
258
+ id: "hyperbolic-trig",
259
+ label: "\u53CC\u66F2/\u53CD\u4E09\u89D2",
260
+ symbols: toPaletteEntries(HYPERBOLIC_TRIG, true)
261
+ },
262
+ {
263
+ id: "misc",
264
+ label: "\u5176\u4ED6\u7B26\u53F7",
265
+ symbols: toPaletteEntries(MISC_SYMBOLS, true)
266
+ }
267
+ ];
268
+ function getPaletteSymbols(categoryId) {
269
+ const cat = MATH_PALETTE_CATEGORIES.find((c) => c.id === categoryId);
270
+ return cat?.symbols ?? [];
271
+ }
118
272
 
119
273
  // src/matrix.ts
120
274
  var MatrixUtils = class {
@@ -159,9 +313,9 @@ var MatrixUtils = class {
159
313
  }
160
314
  /**
161
315
  * 格式化矩阵为 LaTeX
162
- * @param matrix 矩阵数据(字符串数组)
163
- * @param matrixType 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
164
- * @param columnAlign 列对齐 (l/c/r)
316
+ * @param matrix - 矩阵数据(字符串数组)
317
+ * @param options.matrixType - 矩阵类型 (matrix/pmatrix/bmatrix/vmatrix)
318
+ * @param options.columnAlign - 列对齐 (l/c/r)
165
319
  */
166
320
  toLaTeX(matrix, options) {
167
321
  const type = options?.matrixType ?? "pmatrix";
@@ -252,12 +406,16 @@ ${body}
252
406
  export {
253
407
  ALL_SYMBOLS,
254
408
  ARROWS,
409
+ FUNCTIONS,
255
410
  GREEK_LOWERCASE,
256
411
  GREEK_UPPERCASE,
412
+ HYPERBOLIC_TRIG,
413
+ MATH_PALETTE_CATEGORIES,
257
414
  MISC_SYMBOLS,
258
415
  MatrixUtils,
259
416
  OPERATORS,
260
417
  RELATIONS,
418
+ getPaletteSymbols,
261
419
  getSymbolsByCategory,
262
420
  identityMatrix,
263
421
  latexMatrixTemplate,
package/package.json CHANGED
@@ -1,52 +1,61 @@
1
- {
2
- "name": "@sciexpr/math",
3
- "version": "0.1.0",
4
- "description": "Scientific Expression Engine - Math utilities (symbol library, matrix tools)",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "sideEffects": false,
17
- "files": ["dist"],
18
- "scripts": {
19
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
20
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
- "lint": "tsc --noEmit",
22
- "clean": "rimraf dist",
23
- "test": "vitest run"
24
- },
25
- "keywords": ["scientific", "expression", "math", "matrix", "symbols"],
26
- "license": "MIT",
27
- "author": {
28
- "name": "haoguodong09-svg",
29
- "email": "haoguodong09@gmail.com"
30
- },
31
- "homepage": "https://github.com/haoguodong09-svg/scientific-expression-engine#readme",
32
- "bugs": {
33
- "url": "https://github.com/haoguodong09-svg/scientific-expression-engine/issues"
34
- },
35
- "repository": {
36
- "type": "git",
37
- "url": "https://github.com/haoguodong09-svg/scientific-expression-engine",
38
- "directory": "packages/math"
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "dependencies": {
44
- "@sciexpr/core": "workspace:*"
45
- },
46
- "devDependencies": {
47
- "tsup": "^8.0.0",
48
- "typescript": "^5.5.0",
49
- "vitest": "^2.0.0",
50
- "rimraf": "^5.0.0"
51
- }
52
- }
1
+ {
2
+ "name": "@sciexpr/math",
3
+ "version": "0.1.1",
4
+ "description": "Scientific Expression Engine - Math utilities (symbol library, matrix tools)",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "keywords": [
22
+ "scientific",
23
+ "expression",
24
+ "math",
25
+ "matrix",
26
+ "symbols"
27
+ ],
28
+ "license": "MIT",
29
+ "author": {
30
+ "name": "haoguodong09-svg",
31
+ "email": "haoguodong09@gmail.com"
32
+ },
33
+ "homepage": "https://github.com/haoguodong09-svg/scientific-expression-engine#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/haoguodong09-svg/scientific-expression-engine/issues"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/haoguodong09-svg/scientific-expression-engine",
40
+ "directory": "packages/math"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "@sciexpr/core": "0.1.1"
47
+ },
48
+ "devDependencies": {
49
+ "tsup": "^8.0.0",
50
+ "typescript": "^5.5.0",
51
+ "vitest": "^2.0.0",
52
+ "rimraf": "^5.0.0"
53
+ },
54
+ "scripts": {
55
+ "build": "tsup",
56
+ "dev": "tsup --watch",
57
+ "lint": "tsc --noEmit",
58
+ "clean": "rimraf dist",
59
+ "test": "vitest run"
60
+ }
61
+ }