dwml-ts 0.5.2 → 0.5.3
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 +10 -2
- package/dist/index.cjs +19 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -74,4 +74,20 @@ export { TNode }
|
|
|
74
74
|
*/
|
|
75
75
|
export declare function unicodeToLatex(input: string): string;
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Math-mode encoder for OMML run text (`m:t`).
|
|
79
|
+
*
|
|
80
|
+
* pylatexenc's map targets *text* mode: accented letters become `\v{e}` /
|
|
81
|
+
* `\'e` / `\ss`, symbols become `\textendash` / `\texteuro`, and math symbols
|
|
82
|
+
* are wrapped in `\ensuremath{}`. None of that is valid inside an equation —
|
|
83
|
+
* MathLive renders `\v{e}` as an error box and drops the accent when the
|
|
84
|
+
* LaTeX is converted back to MathML/OMML, so "světlo" round-trips as "svetlo".
|
|
85
|
+
*
|
|
86
|
+
* OMML is Unicode-native and every math renderer downstream (MathLive, KaTeX,
|
|
87
|
+
* unicode-math TeX, Office itself) accepts Unicode letters and symbols in
|
|
88
|
+
* math mode, so anything outside ASCII that dwml's curated `T` table did not
|
|
89
|
+
* already map is kept verbatim. Only `\` needs a control sequence.
|
|
90
|
+
*/
|
|
91
|
+
export declare function unicodeToMathLatex(input: string): string;
|
|
92
|
+
|
|
77
93
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1524,6 +1524,18 @@ function unicodeToLatex(input) {
|
|
|
1524
1524
|
}
|
|
1525
1525
|
return out;
|
|
1526
1526
|
}
|
|
1527
|
+
const ASCII_MATH = {
|
|
1528
|
+
0x5c: '{\\backslash}'
|
|
1529
|
+
};
|
|
1530
|
+
function unicodeToMathLatex(input) {
|
|
1531
|
+
const s = String(input).normalize('NFC');
|
|
1532
|
+
let out = '';
|
|
1533
|
+
for (const ch of s){
|
|
1534
|
+
const cp = ch.codePointAt(0);
|
|
1535
|
+
out += ASCII_MATH[cp] ?? ch;
|
|
1536
|
+
}
|
|
1537
|
+
return out;
|
|
1538
|
+
}
|
|
1527
1539
|
const CHARS = [
|
|
1528
1540
|
'{',
|
|
1529
1541
|
'}',
|
|
@@ -1693,6 +1705,7 @@ const T = {
|
|
|
1693
1705
|
'∗': '\\ast ',
|
|
1694
1706
|
'∘': '\\circ ',
|
|
1695
1707
|
'∙': '\\bullet ',
|
|
1708
|
+
'•': '\\bullet ',
|
|
1696
1709
|
'−': '-',
|
|
1697
1710
|
'<': '<',
|
|
1698
1711
|
'>': '>',
|
|
@@ -2361,7 +2374,7 @@ class Converter {
|
|
|
2361
2374
|
const mapped = T[ch];
|
|
2362
2375
|
if (void 0 !== mapped) out += mapped;
|
|
2363
2376
|
else if (CHARS.includes(ch)) out += ch;
|
|
2364
|
-
else out +=
|
|
2377
|
+
else out += unicodeToMathLatex(ch);
|
|
2365
2378
|
}
|
|
2366
2379
|
return out;
|
|
2367
2380
|
}
|
|
@@ -2444,6 +2457,6 @@ function extractOmmlLatex(xml, options = {}) {
|
|
|
2444
2457
|
});
|
|
2445
2458
|
return findAll(nodes, 'oMath').map((omath)=>ommlNodeToLatex(omath, options).trim());
|
|
2446
2459
|
}
|
|
2447
|
-
export { elementChildren, escapeLatex, extractOmmlLatex, localName, ommlNodeToLatex, ommlToLatex, textContent, unicodeToLatex };
|
|
2460
|
+
export { elementChildren, escapeLatex, extractOmmlLatex, localName, ommlNodeToLatex, ommlToLatex, textContent, unicodeToLatex, unicodeToMathLatex };
|
|
2448
2461
|
|
|
2449
2462
|
//# sourceMappingURL=index.js.map
|