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 CHANGED
@@ -117,12 +117,20 @@ astral-plane Mathematical Alphanumeric Symbols are handled correctly):
117
117
  `U+1D400–U+1D7FF` → ASCII (`𝐴→A`, `𝑥→x`), Greek (`π→\pi`, both plain `U+03B1..` and
118
118
  math-italic `U+1D6FC..`), relation/operator symbols (`≤→\leq`, `≥→\geq`, `≠→\ne`,
119
119
  `·→\cdot`, `×→\times`, `∞→\infty`, `→→\rightarrow`, …).
120
- 2. **pylatexenc's builtin map** (`src/uni2latex.generated.ts`, internalized from
121
- pylatexenc 2.x, MIT) everything else with a known LaTeX escape.
120
+ 2. **Verbatim Unicode** — everything else is kept as-is (`světlo` `světlo`,
121
+ `€` `€`). OMML is Unicode-native and math renderers (MathLive, KaTeX,
122
+ unicode-math) accept Unicode identifiers/symbols in math mode, whereas
123
+ text-mode escapes (`\v{e}`, `\ss`, `\textendash`, `\ensuremath{…}`) are invalid
124
+ inside an equation and lossy on the way back to OMML. A literal `\` becomes
125
+ `{\backslash}`.
122
126
 
123
127
  LaTeX-special characters in runs (`%`, `&`, `_`, `{`, `}`, `#`, `$`, `~`, `^`) are escaped
124
128
  via dwml's `escape_latex` (`a%` → `a\%`).
125
129
 
130
+ `unicodeToLatex()` (the pylatexenc-derived *text-mode* encoder,
131
+ `src/uni2latex.generated.ts`) is still exported for consumers that need it, but is
132
+ no longer used for run text.
133
+
126
134
  ## Examples
127
135
 
128
136
  | OMML input | LaTeX output |
package/dist/index.cjs CHANGED
@@ -35,9 +35,11 @@ __webpack_require__.d(__webpack_exports__, {
35
35
  ommlNodeToLatex: ()=>ommlNodeToLatex,
36
36
  ommlToLatex: ()=>ommlToLatex,
37
37
  textContent: ()=>textContent,
38
- unicodeToLatex: ()=>unicodeToLatex
38
+ unicodeToLatex: ()=>unicodeToLatex,
39
+ unicodeToMathLatex: ()=>unicodeToMathLatex
39
40
  });
40
41
  const txml_namespaceObject = require("txml/txml");
42
+ const external_entities_namespaceObject = require("entities");
41
43
  const UNI2LATEX = {
42
44
  34: "''",
43
45
  35: "\\#",
@@ -1562,6 +1564,18 @@ function unicodeToLatex(input) {
1562
1564
  }
1563
1565
  return out;
1564
1566
  }
1567
+ const ASCII_MATH = {
1568
+ 0x5c: '{\\backslash}'
1569
+ };
1570
+ function unicodeToMathLatex(input) {
1571
+ const s = String(input).normalize('NFC');
1572
+ let out = '';
1573
+ for (const ch of s){
1574
+ const cp = ch.codePointAt(0);
1575
+ out += ASCII_MATH[cp] ?? ch;
1576
+ }
1577
+ return out;
1578
+ }
1565
1579
  const CHARS = [
1566
1580
  '{',
1567
1581
  '}',
@@ -1731,6 +1745,7 @@ const T = {
1731
1745
  '∗': '\\ast ',
1732
1746
  '∘': '\\circ ',
1733
1747
  '∙': '\\bullet ',
1748
+ '•': '\\bullet ',
1734
1749
  '−': '-',
1735
1750
  '<': '<',
1736
1751
  '>': '>',
@@ -1985,7 +2000,7 @@ function isElement(node) {
1985
2000
  }
1986
2001
  function textContent(node) {
1987
2002
  let out = '';
1988
- for (const child of node.children)out += 'string' == typeof child ? child : textContent(child);
2003
+ for (const child of node.children)out += 'string' == typeof child ? (0, external_entities_namespaceObject.decodeXML)(child) : textContent(child);
1989
2004
  return out;
1990
2005
  }
1991
2006
  function pyFormat(template, positional = [], named = {}) {
@@ -2399,7 +2414,7 @@ class Converter {
2399
2414
  const mapped = T[ch];
2400
2415
  if (void 0 !== mapped) out += mapped;
2401
2416
  else if (CHARS.includes(ch)) out += ch;
2402
- else out += unicodeToLatex(ch);
2417
+ else out += unicodeToMathLatex(ch);
2403
2418
  }
2404
2419
  return out;
2405
2420
  }
@@ -2490,6 +2505,7 @@ exports.ommlNodeToLatex = __webpack_exports__.ommlNodeToLatex;
2490
2505
  exports.ommlToLatex = __webpack_exports__.ommlToLatex;
2491
2506
  exports.textContent = __webpack_exports__.textContent;
2492
2507
  exports.unicodeToLatex = __webpack_exports__.unicodeToLatex;
2508
+ exports.unicodeToMathLatex = __webpack_exports__.unicodeToMathLatex;
2493
2509
  for(var __rspack_i in __webpack_exports__)if (-1 === [
2494
2510
  "elementChildren",
2495
2511
  "escapeLatex",
@@ -2498,7 +2514,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
2498
2514
  "ommlNodeToLatex",
2499
2515
  "ommlToLatex",
2500
2516
  "textContent",
2501
- "unicodeToLatex"
2517
+ "unicodeToLatex",
2518
+ "unicodeToMathLatex"
2502
2519
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
2503
2520
  Object.defineProperty(exports, '__esModule', {
2504
2521
  value: true