math-core 0.6.3 → 0.7.0
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 +16 -16
- package/dist/math_core.d.ts +5 -3
- package/dist/math_core.js +36 -22
- package/dist/math_core_bg.wasm +0 -0
- package/dist/math_core_bg.wasm.d.ts +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ import { LatexToMathML } from "math-core";
|
|
|
31
31
|
const converter = new LatexToMathML({});
|
|
32
32
|
|
|
33
33
|
// Convert inline math
|
|
34
|
-
const inline = converter.
|
|
34
|
+
const inline = converter.convert_with_local_state("x^2 + y^2 = z^2", false);
|
|
35
35
|
console.log(inline);
|
|
36
36
|
// Output: <math><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msup><mi>y</mi><mn>2</mn></msup><mo>=</mo><msup><mi>z</mi><mn>2</mn></msup></math>
|
|
37
37
|
|
|
38
38
|
// Convert display math
|
|
39
|
-
const display = converter.
|
|
39
|
+
const display = converter.convert_with_local_state("\\frac{1}{2}", true);
|
|
40
40
|
console.log(display);
|
|
41
41
|
// Output: <math display="block"><mfrac><mn>1</mn><mn>2</mn></mfrac></math>
|
|
42
42
|
```
|
|
@@ -51,7 +51,7 @@ import { LatexToMathML } from "math-core";
|
|
|
51
51
|
const converter = new LatexToMathML({ prettyPrint: "always" });
|
|
52
52
|
|
|
53
53
|
try {
|
|
54
|
-
const mathml = converter.
|
|
54
|
+
const mathml = converter.convert_with_local_state("\\sqrt{x^2 + 1}", false);
|
|
55
55
|
console.log(mathml);
|
|
56
56
|
} catch (e) {
|
|
57
57
|
console.error(`Conversion error: ${e.message}`);
|
|
@@ -69,10 +69,10 @@ macros.set("R", "\\mathbb{R}"); // Real numbers
|
|
|
69
69
|
macros.set("vec", "\\mathbf{#1}"); // Vector notation
|
|
70
70
|
|
|
71
71
|
const converter = new LatexToMathML({ macros });
|
|
72
|
-
const mathml = converter.
|
|
72
|
+
const mathml = converter.convert_with_local_state("\\d x", false);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
### Numbered Equations with Global
|
|
75
|
+
### Numbered Equations with Global State
|
|
76
76
|
|
|
77
77
|
For documents with multiple numbered equations:
|
|
78
78
|
|
|
@@ -80,22 +80,22 @@ For documents with multiple numbered equations:
|
|
|
80
80
|
const converter = new LatexToMathML({});
|
|
81
81
|
|
|
82
82
|
// First equation gets (1)
|
|
83
|
-
const eq1 = converter.
|
|
83
|
+
const eq1 = converter.convert_with_global_state(
|
|
84
84
|
"\\begin{align}E = mc^2\\end{align}",
|
|
85
85
|
true,
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
// Second equation gets (2)
|
|
89
|
-
const eq2 = converter.
|
|
89
|
+
const eq2 = converter.convert_with_global_state(
|
|
90
90
|
"\\begin{align}F = ma\\end{align}",
|
|
91
91
|
true,
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
// Reset counter when starting a new chapter/section
|
|
95
|
-
converter.
|
|
95
|
+
converter.reset_global_state();
|
|
96
96
|
|
|
97
97
|
// This equation gets (1) again
|
|
98
|
-
const eq3 = converter.
|
|
98
|
+
const eq3 = converter.convert_with_global_state(
|
|
99
99
|
"\\begin{align}p = mv\\end{align}",
|
|
100
100
|
true,
|
|
101
101
|
);
|
|
@@ -109,12 +109,12 @@ Use local counters when equation numbers should restart within each conversion:
|
|
|
109
109
|
const converter = new LatexToMathML({});
|
|
110
110
|
|
|
111
111
|
// Each conversion has independent numbering
|
|
112
|
-
const doc1 = converter.
|
|
112
|
+
const doc1 = converter.convert_with_local_state(
|
|
113
113
|
"\\begin{align}a &= b\\\\c &= d\\end{align}",
|
|
114
114
|
true,
|
|
115
115
|
); // Contains (1) and (2)
|
|
116
116
|
|
|
117
|
-
const doc2 = converter.
|
|
117
|
+
const doc2 = converter.convert_with_local_state(
|
|
118
118
|
"\\begin{align}x &= y\\\\z &= w\\end{align}",
|
|
119
119
|
true,
|
|
120
120
|
); // Also contains (1) and (2)
|
|
@@ -128,7 +128,7 @@ By default, conversion errors throw a `LatexError` with detailed diagnostics:
|
|
|
128
128
|
const converter = new LatexToMathML({});
|
|
129
129
|
|
|
130
130
|
try {
|
|
131
|
-
converter.
|
|
131
|
+
converter.convert_with_local_state("\\begin{foobar}", false);
|
|
132
132
|
} catch (e) {
|
|
133
133
|
console.log(e.message); // 'Unknown environment "foobar".'
|
|
134
134
|
console.log(e.report); // Formatted diagnostic with source spans
|
|
@@ -142,7 +142,7 @@ Set `throwOnError: false` to return an HTML error snippet instead of throwing:
|
|
|
142
142
|
|
|
143
143
|
```javascript
|
|
144
144
|
const converter = new LatexToMathML({ throwOnError: false });
|
|
145
|
-
const result = converter.
|
|
145
|
+
const result = converter.convert_with_local_state("\\invalid", false);
|
|
146
146
|
// Returns: <span class="math-core-error" title="..."><code>\invalid</code></span>
|
|
147
147
|
```
|
|
148
148
|
|
|
@@ -171,9 +171,9 @@ new LatexToMathML(options: MathCoreOptions)
|
|
|
171
171
|
|
|
172
172
|
**Methods:**
|
|
173
173
|
|
|
174
|
-
- `
|
|
175
|
-
- `
|
|
176
|
-
- `
|
|
174
|
+
- `convert_with_global_state(latex: string, displaystyle: boolean): string` — Convert LaTeX to MathML using global state.
|
|
175
|
+
- `convert_with_local_state(latex: string, displaystyle: boolean): string` — Convert LaTeX to MathML using local state.
|
|
176
|
+
- `reset_global_state(): void` — Reset the global state (e.g., set the equation counter to zero).
|
|
177
177
|
|
|
178
178
|
### `LatexError`
|
|
179
179
|
|
package/dist/math_core.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface MathCoreOptions {
|
|
|
9
9
|
ignoreUnknownCommands?: boolean;
|
|
10
10
|
annotation?: boolean;
|
|
11
11
|
allowUnreliableRendering?: boolean;
|
|
12
|
+
unicodeSubstitution?: "never" | "conventional";
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
|
|
@@ -27,6 +28,7 @@ export class LatexError {
|
|
|
27
28
|
end: number;
|
|
28
29
|
start: number;
|
|
29
30
|
readonly context: string | undefined;
|
|
31
|
+
readonly label: string;
|
|
30
32
|
readonly message: string;
|
|
31
33
|
readonly report: string | undefined;
|
|
32
34
|
}
|
|
@@ -34,8 +36,8 @@ export class LatexError {
|
|
|
34
36
|
export class LatexToMathML {
|
|
35
37
|
free(): void;
|
|
36
38
|
[Symbol.dispose](): void;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
convert_with_global_state(content: string, displaystyle: boolean): string;
|
|
40
|
+
convert_with_local_state(content: string, displaystyle: boolean): string;
|
|
39
41
|
constructor(js_config: MathCoreOptions);
|
|
40
|
-
|
|
42
|
+
reset_global_state(): void;
|
|
41
43
|
}
|
package/dist/math_core.js
CHANGED
|
@@ -67,6 +67,13 @@ export class LatexError {
|
|
|
67
67
|
const ret = wasm.latexerror_context(this.__wbg_ptr);
|
|
68
68
|
return ret;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* @returns {string}
|
|
72
|
+
*/
|
|
73
|
+
get label() {
|
|
74
|
+
const ret = wasm.latexerror_label(this.__wbg_ptr);
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
70
77
|
/**
|
|
71
78
|
* @returns {string}
|
|
72
79
|
*/
|
|
@@ -112,10 +119,10 @@ export class LatexToMathML {
|
|
|
112
119
|
* @param {boolean} displaystyle
|
|
113
120
|
* @returns {string}
|
|
114
121
|
*/
|
|
115
|
-
|
|
122
|
+
convert_with_global_state(content, displaystyle) {
|
|
116
123
|
const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
117
124
|
const len0 = WASM_VECTOR_LEN;
|
|
118
|
-
const ret = wasm.
|
|
125
|
+
const ret = wasm.latextomathml_convert_with_global_state(this.__wbg_ptr, ptr0, len0, displaystyle);
|
|
119
126
|
if (ret[2]) {
|
|
120
127
|
throw takeFromExternrefTable0(ret[1]);
|
|
121
128
|
}
|
|
@@ -126,10 +133,10 @@ export class LatexToMathML {
|
|
|
126
133
|
* @param {boolean} displaystyle
|
|
127
134
|
* @returns {string}
|
|
128
135
|
*/
|
|
129
|
-
|
|
136
|
+
convert_with_local_state(content, displaystyle) {
|
|
130
137
|
const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
131
138
|
const len0 = WASM_VECTOR_LEN;
|
|
132
|
-
const ret = wasm.
|
|
139
|
+
const ret = wasm.latextomathml_convert_with_local_state(this.__wbg_ptr, ptr0, len0, displaystyle);
|
|
133
140
|
if (ret[2]) {
|
|
134
141
|
throw takeFromExternrefTable0(ret[1]);
|
|
135
142
|
}
|
|
@@ -147,15 +154,15 @@ export class LatexToMathML {
|
|
|
147
154
|
LatexToMathMLFinalization.register(this, this.__wbg_ptr, this);
|
|
148
155
|
return this;
|
|
149
156
|
}
|
|
150
|
-
|
|
151
|
-
wasm.
|
|
157
|
+
reset_global_state() {
|
|
158
|
+
wasm.latextomathml_reset_global_state(this.__wbg_ptr);
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
if (Symbol.dispose) LatexToMathML.prototype[Symbol.dispose] = LatexToMathML.prototype.free;
|
|
155
162
|
function __wbg_get_imports() {
|
|
156
163
|
const import0 = {
|
|
157
164
|
__proto__: null,
|
|
158
|
-
|
|
165
|
+
__wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
|
|
159
166
|
const obj = arg1;
|
|
160
167
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
161
168
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -163,14 +170,14 @@ function __wbg_get_imports() {
|
|
|
163
170
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
164
171
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
165
172
|
},
|
|
166
|
-
|
|
173
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
167
174
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
168
175
|
},
|
|
169
|
-
|
|
176
|
+
__wbg_allowUnreliableRendering_09ef135275eede85: function(arg0) {
|
|
170
177
|
const ret = arg0.allowUnreliableRendering;
|
|
171
178
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
172
179
|
},
|
|
173
|
-
|
|
180
|
+
__wbg_annotation_363d3c8394162f0f: function(arg0) {
|
|
174
181
|
const ret = arg0.annotation;
|
|
175
182
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
176
183
|
},
|
|
@@ -178,23 +185,23 @@ function __wbg_get_imports() {
|
|
|
178
185
|
const ret = ConfigParseError.__wrap(arg0);
|
|
179
186
|
return ret;
|
|
180
187
|
},
|
|
181
|
-
|
|
188
|
+
__wbg_done_89b2b13e91a60321: function(arg0) {
|
|
182
189
|
const ret = arg0.done;
|
|
183
190
|
return ret;
|
|
184
191
|
},
|
|
185
|
-
|
|
192
|
+
__wbg_entries_00d7283394649868: function(arg0) {
|
|
186
193
|
const ret = arg0.entries();
|
|
187
194
|
return ret;
|
|
188
195
|
},
|
|
189
|
-
|
|
196
|
+
__wbg_get_507a50627bffa49b: function(arg0, arg1) {
|
|
190
197
|
const ret = arg0[arg1 >>> 0];
|
|
191
198
|
return ret;
|
|
192
199
|
},
|
|
193
|
-
|
|
200
|
+
__wbg_ignoreUnknownCommands_fbafb7b34d6e9764: function(arg0) {
|
|
194
201
|
const ret = arg0.ignoreUnknownCommands;
|
|
195
202
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
196
203
|
},
|
|
197
|
-
|
|
204
|
+
__wbg_isArray_0677c962b281d01a: function(arg0) {
|
|
198
205
|
const ret = Array.isArray(arg0);
|
|
199
206
|
return ret;
|
|
200
207
|
},
|
|
@@ -202,34 +209,41 @@ function __wbg_get_imports() {
|
|
|
202
209
|
const ret = LatexError.__wrap(arg0);
|
|
203
210
|
return ret;
|
|
204
211
|
},
|
|
205
|
-
|
|
212
|
+
__wbg_macros_03715a0e353a948d: function(arg0) {
|
|
206
213
|
const ret = arg0.macros;
|
|
207
214
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
208
215
|
},
|
|
209
|
-
|
|
216
|
+
__wbg_next_71f2aa1cb3d1e37e: function() { return handleError(function (arg0) {
|
|
210
217
|
const ret = arg0.next();
|
|
211
218
|
return ret;
|
|
212
219
|
}, arguments); },
|
|
213
|
-
|
|
220
|
+
__wbg_prettyPrint_53b1abd5bf18c3d9: function(arg0, arg1) {
|
|
214
221
|
const ret = arg1.prettyPrint;
|
|
215
222
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
216
223
|
var len1 = WASM_VECTOR_LEN;
|
|
217
224
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
218
225
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
219
226
|
},
|
|
220
|
-
|
|
227
|
+
__wbg_size_56cb46b36f9b2664: function(arg0) {
|
|
221
228
|
const ret = arg0.size;
|
|
222
229
|
return ret;
|
|
223
230
|
},
|
|
224
|
-
|
|
231
|
+
__wbg_throwOnError_b6c73f7b5c7ff297: function(arg0) {
|
|
225
232
|
const ret = arg0.throwOnError;
|
|
226
233
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
227
234
|
},
|
|
228
|
-
|
|
235
|
+
__wbg_unicodeSubstitution_0308f153a7409367: function(arg0, arg1) {
|
|
236
|
+
const ret = arg1.unicodeSubstitution;
|
|
237
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
238
|
+
var len1 = WASM_VECTOR_LEN;
|
|
239
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
240
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
241
|
+
},
|
|
242
|
+
__wbg_value_a5d5488a9589444a: function(arg0) {
|
|
229
243
|
const ret = arg0.value;
|
|
230
244
|
return ret;
|
|
231
245
|
},
|
|
232
|
-
|
|
246
|
+
__wbg_xmlNamespace_28171b05853d5a2e: function(arg0) {
|
|
233
247
|
const ret = arg0.xmlNamespace;
|
|
234
248
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
235
249
|
},
|
package/dist/math_core_bg.wasm
CHANGED
|
Binary file
|
|
@@ -10,12 +10,13 @@ export const __wbg_set_latexerror_end: (a: number, b: number) => void;
|
|
|
10
10
|
export const __wbg_set_latexerror_start: (a: number, b: number) => void;
|
|
11
11
|
export const configparseerror_message: (a: number) => any;
|
|
12
12
|
export const latexerror_context: (a: number) => any;
|
|
13
|
+
export const latexerror_label: (a: number) => any;
|
|
13
14
|
export const latexerror_message: (a: number) => any;
|
|
14
15
|
export const latexerror_report: (a: number) => any;
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
16
|
+
export const latextomathml_convert_with_global_state: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
17
|
+
export const latextomathml_convert_with_local_state: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
17
18
|
export const latextomathml_new: (a: any) => [number, number, number];
|
|
18
|
-
export const
|
|
19
|
+
export const latextomathml_reset_global_state: (a: number) => void;
|
|
19
20
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
20
21
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
21
22
|
export const __externref_table_alloc: () => number;
|