dwml-ts 0.5.1 → 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 +21 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parse } from "txml/txml";
|
|
2
|
+
import { decodeXML } from "entities";
|
|
2
3
|
const UNI2LATEX = {
|
|
3
4
|
34: "''",
|
|
4
5
|
35: "\\#",
|
|
@@ -1523,6 +1524,18 @@ function unicodeToLatex(input) {
|
|
|
1523
1524
|
}
|
|
1524
1525
|
return out;
|
|
1525
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
|
+
}
|
|
1526
1539
|
const CHARS = [
|
|
1527
1540
|
'{',
|
|
1528
1541
|
'}',
|
|
@@ -1692,6 +1705,7 @@ const T = {
|
|
|
1692
1705
|
'∗': '\\ast ',
|
|
1693
1706
|
'∘': '\\circ ',
|
|
1694
1707
|
'∙': '\\bullet ',
|
|
1708
|
+
'•': '\\bullet ',
|
|
1695
1709
|
'−': '-',
|
|
1696
1710
|
'<': '<',
|
|
1697
1711
|
'>': '>',
|
|
@@ -1946,7 +1960,7 @@ function isElement(node) {
|
|
|
1946
1960
|
}
|
|
1947
1961
|
function textContent(node) {
|
|
1948
1962
|
let out = '';
|
|
1949
|
-
for (const child of node.children)out += 'string' == typeof child ? child : textContent(child);
|
|
1963
|
+
for (const child of node.children)out += 'string' == typeof child ? decodeXML(child) : textContent(child);
|
|
1950
1964
|
return out;
|
|
1951
1965
|
}
|
|
1952
1966
|
function pyFormat(template, positional = [], named = {}) {
|
|
@@ -2360,7 +2374,7 @@ class Converter {
|
|
|
2360
2374
|
const mapped = T[ch];
|
|
2361
2375
|
if (void 0 !== mapped) out += mapped;
|
|
2362
2376
|
else if (CHARS.includes(ch)) out += ch;
|
|
2363
|
-
else out +=
|
|
2377
|
+
else out += unicodeToMathLatex(ch);
|
|
2364
2378
|
}
|
|
2365
2379
|
return out;
|
|
2366
2380
|
}
|
|
@@ -2443,6 +2457,6 @@ function extractOmmlLatex(xml, options = {}) {
|
|
|
2443
2457
|
});
|
|
2444
2458
|
return findAll(nodes, 'oMath').map((omath)=>ommlNodeToLatex(omath, options).trim());
|
|
2445
2459
|
}
|
|
2446
|
-
export { elementChildren, escapeLatex, extractOmmlLatex, localName, ommlNodeToLatex, ommlToLatex, textContent, unicodeToLatex };
|
|
2460
|
+
export { elementChildren, escapeLatex, extractOmmlLatex, localName, ommlNodeToLatex, ommlToLatex, textContent, unicodeToLatex, unicodeToMathLatex };
|
|
2447
2461
|
|
|
2448
2462
|
//# sourceMappingURL=index.js.map
|