math-core 0.6.4 → 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 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.convert_with_local_counter("x^2 + y^2 = z^2", false);
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.convert_with_local_counter("\\frac{1}{2}", true);
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.convert_with_local_counter("\\sqrt{x^2 + 1}", false);
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.convert_with_local_counter("\\d x", false);
72
+ const mathml = converter.convert_with_local_state("\\d x", false);
73
73
  ```
74
74
 
75
- ### Numbered Equations with Global Counter
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.convert_with_global_counter(
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.convert_with_global_counter(
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.reset_global_counter();
95
+ converter.reset_global_state();
96
96
 
97
97
  // This equation gets (1) again
98
- const eq3 = converter.convert_with_global_counter(
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.convert_with_local_counter(
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.convert_with_local_counter(
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.convert_with_local_counter("\\begin{foobar}", false);
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.convert_with_local_counter("\\invalid", false);
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
- - `convert_with_global_counter(latex: string, displaystyle: boolean): string` — Convert LaTeX to MathML using a global equation counter.
175
- - `convert_with_local_counter(latex: string, displaystyle: boolean): string` — Convert LaTeX to MathML using a local equation counter.
176
- - `reset_global_counter(): void` — Reset the global equation counter to zero.
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
 
@@ -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
 
@@ -35,8 +36,8 @@ export class LatexError {
35
36
  export class LatexToMathML {
36
37
  free(): void;
37
38
  [Symbol.dispose](): void;
38
- convert_with_global_counter(content: string, displaystyle: boolean): string;
39
- convert_with_local_counter(content: string, displaystyle: boolean): string;
39
+ convert_with_global_state(content: string, displaystyle: boolean): string;
40
+ convert_with_local_state(content: string, displaystyle: boolean): string;
40
41
  constructor(js_config: MathCoreOptions);
41
- reset_global_counter(): void;
42
+ reset_global_state(): void;
42
43
  }
package/dist/math_core.js CHANGED
@@ -119,10 +119,10 @@ export class LatexToMathML {
119
119
  * @param {boolean} displaystyle
120
120
  * @returns {string}
121
121
  */
122
- convert_with_global_counter(content, displaystyle) {
122
+ convert_with_global_state(content, displaystyle) {
123
123
  const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
124
124
  const len0 = WASM_VECTOR_LEN;
125
- const ret = wasm.latextomathml_convert_with_global_counter(this.__wbg_ptr, ptr0, len0, displaystyle);
125
+ const ret = wasm.latextomathml_convert_with_global_state(this.__wbg_ptr, ptr0, len0, displaystyle);
126
126
  if (ret[2]) {
127
127
  throw takeFromExternrefTable0(ret[1]);
128
128
  }
@@ -133,10 +133,10 @@ export class LatexToMathML {
133
133
  * @param {boolean} displaystyle
134
134
  * @returns {string}
135
135
  */
136
- convert_with_local_counter(content, displaystyle) {
136
+ convert_with_local_state(content, displaystyle) {
137
137
  const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
138
  const len0 = WASM_VECTOR_LEN;
139
- const ret = wasm.latextomathml_convert_with_local_counter(this.__wbg_ptr, ptr0, len0, displaystyle);
139
+ const ret = wasm.latextomathml_convert_with_local_state(this.__wbg_ptr, ptr0, len0, displaystyle);
140
140
  if (ret[2]) {
141
141
  throw takeFromExternrefTable0(ret[1]);
142
142
  }
@@ -154,15 +154,15 @@ export class LatexToMathML {
154
154
  LatexToMathMLFinalization.register(this, this.__wbg_ptr, this);
155
155
  return this;
156
156
  }
157
- reset_global_counter() {
158
- wasm.latextomathml_reset_global_counter(this.__wbg_ptr);
157
+ reset_global_state() {
158
+ wasm.latextomathml_reset_global_state(this.__wbg_ptr);
159
159
  }
160
160
  }
161
161
  if (Symbol.dispose) LatexToMathML.prototype[Symbol.dispose] = LatexToMathML.prototype.free;
162
162
  function __wbg_get_imports() {
163
163
  const import0 = {
164
164
  __proto__: null,
165
- __wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
165
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
166
166
  const obj = arg1;
167
167
  const ret = typeof(obj) === 'string' ? obj : undefined;
168
168
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -170,14 +170,14 @@ function __wbg_get_imports() {
170
170
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
171
171
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
172
172
  },
173
- __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
173
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
174
174
  throw new Error(getStringFromWasm0(arg0, arg1));
175
175
  },
176
- __wbg_allowUnreliableRendering_85799e8d6aea3b13: function(arg0) {
176
+ __wbg_allowUnreliableRendering_09ef135275eede85: function(arg0) {
177
177
  const ret = arg0.allowUnreliableRendering;
178
178
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
179
179
  },
180
- __wbg_annotation_787a5a6d7b450089: function(arg0) {
180
+ __wbg_annotation_363d3c8394162f0f: function(arg0) {
181
181
  const ret = arg0.annotation;
182
182
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
183
183
  },
@@ -185,23 +185,23 @@ function __wbg_get_imports() {
185
185
  const ret = ConfigParseError.__wrap(arg0);
186
186
  return ret;
187
187
  },
188
- __wbg_done_60cf307fcc680536: function(arg0) {
188
+ __wbg_done_89b2b13e91a60321: function(arg0) {
189
189
  const ret = arg0.done;
190
190
  return ret;
191
191
  },
192
- __wbg_entries_206899f1a3dd30a8: function(arg0) {
192
+ __wbg_entries_00d7283394649868: function(arg0) {
193
193
  const ret = arg0.entries();
194
194
  return ret;
195
195
  },
196
- __wbg_get_2b48c7d0d006a781: function(arg0, arg1) {
196
+ __wbg_get_507a50627bffa49b: function(arg0, arg1) {
197
197
  const ret = arg0[arg1 >>> 0];
198
198
  return ret;
199
199
  },
200
- __wbg_ignoreUnknownCommands_2e5f9e0782e159a4: function(arg0) {
200
+ __wbg_ignoreUnknownCommands_fbafb7b34d6e9764: function(arg0) {
201
201
  const ret = arg0.ignoreUnknownCommands;
202
202
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
203
203
  },
204
- __wbg_isArray_67c2c9c4313f4448: function(arg0) {
204
+ __wbg_isArray_0677c962b281d01a: function(arg0) {
205
205
  const ret = Array.isArray(arg0);
206
206
  return ret;
207
207
  },
@@ -209,34 +209,41 @@ function __wbg_get_imports() {
209
209
  const ret = LatexError.__wrap(arg0);
210
210
  return ret;
211
211
  },
212
- __wbg_macros_b577b47d3bca5e4c: function(arg0) {
212
+ __wbg_macros_03715a0e353a948d: function(arg0) {
213
213
  const ret = arg0.macros;
214
214
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
215
215
  },
216
- __wbg_next_eb8ca7351fa27906: function() { return handleError(function (arg0) {
216
+ __wbg_next_71f2aa1cb3d1e37e: function() { return handleError(function (arg0) {
217
217
  const ret = arg0.next();
218
218
  return ret;
219
219
  }, arguments); },
220
- __wbg_prettyPrint_3bde870ba3a210c7: function(arg0, arg1) {
220
+ __wbg_prettyPrint_53b1abd5bf18c3d9: function(arg0, arg1) {
221
221
  const ret = arg1.prettyPrint;
222
222
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
223
223
  var len1 = WASM_VECTOR_LEN;
224
224
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
225
225
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
226
226
  },
227
- __wbg_size_5ef6bbbc4b6332a9: function(arg0) {
227
+ __wbg_size_56cb46b36f9b2664: function(arg0) {
228
228
  const ret = arg0.size;
229
229
  return ret;
230
230
  },
231
- __wbg_throwOnError_f0f4b6c0a179492b: function(arg0) {
231
+ __wbg_throwOnError_b6c73f7b5c7ff297: function(arg0) {
232
232
  const ret = arg0.throwOnError;
233
233
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
234
234
  },
235
- __wbg_value_f3625092ee4b37f4: function(arg0) {
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) {
236
243
  const ret = arg0.value;
237
244
  return ret;
238
245
  },
239
- __wbg_xmlNamespace_64127331da9c1367: function(arg0) {
246
+ __wbg_xmlNamespace_28171b05853d5a2e: function(arg0) {
240
247
  const ret = arg0.xmlNamespace;
241
248
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
242
249
  },
Binary file
@@ -13,10 +13,10 @@ export const latexerror_context: (a: number) => any;
13
13
  export const latexerror_label: (a: number) => any;
14
14
  export const latexerror_message: (a: number) => any;
15
15
  export const latexerror_report: (a: number) => any;
16
- export const latextomathml_convert_with_global_counter: (a: number, b: number, c: number, d: number) => [number, number, number];
17
- export const latextomathml_convert_with_local_counter: (a: number, b: number, c: number, d: number) => [number, number, number];
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];
18
18
  export const latextomathml_new: (a: any) => [number, number, number];
19
- export const latextomathml_reset_global_counter: (a: number) => void;
19
+ export const latextomathml_reset_global_state: (a: number) => void;
20
20
  export const __wbindgen_malloc: (a: number, b: number) => number;
21
21
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
22
22
  export const __externref_table_alloc: () => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-core",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "description": "Convert LaTeX to MathML Core",
5
5
  "homepage": "https://github.com/tmke8/math-core#readme",
6
6
  "bugs": {