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 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,7 +35,8 @@ __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");
41
42
  const external_entities_namespaceObject = require("entities");
@@ -1563,6 +1564,18 @@ function unicodeToLatex(input) {
1563
1564
  }
1564
1565
  return out;
1565
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
+ }
1566
1579
  const CHARS = [
1567
1580
  '{',
1568
1581
  '}',
@@ -1732,6 +1745,7 @@ const T = {
1732
1745
  '∗': '\\ast ',
1733
1746
  '∘': '\\circ ',
1734
1747
  '∙': '\\bullet ',
1748
+ '•': '\\bullet ',
1735
1749
  '−': '-',
1736
1750
  '<': '<',
1737
1751
  '>': '>',
@@ -2400,7 +2414,7 @@ class Converter {
2400
2414
  const mapped = T[ch];
2401
2415
  if (void 0 !== mapped) out += mapped;
2402
2416
  else if (CHARS.includes(ch)) out += ch;
2403
- else out += unicodeToLatex(ch);
2417
+ else out += unicodeToMathLatex(ch);
2404
2418
  }
2405
2419
  return out;
2406
2420
  }
@@ -2491,6 +2505,7 @@ exports.ommlNodeToLatex = __webpack_exports__.ommlNodeToLatex;
2491
2505
  exports.ommlToLatex = __webpack_exports__.ommlToLatex;
2492
2506
  exports.textContent = __webpack_exports__.textContent;
2493
2507
  exports.unicodeToLatex = __webpack_exports__.unicodeToLatex;
2508
+ exports.unicodeToMathLatex = __webpack_exports__.unicodeToMathLatex;
2494
2509
  for(var __rspack_i in __webpack_exports__)if (-1 === [
2495
2510
  "elementChildren",
2496
2511
  "escapeLatex",
@@ -2499,7 +2514,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
2499
2514
  "ommlNodeToLatex",
2500
2515
  "ommlToLatex",
2501
2516
  "textContent",
2502
- "unicodeToLatex"
2517
+ "unicodeToLatex",
2518
+ "unicodeToMathLatex"
2503
2519
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
2504
2520
  Object.defineProperty(exports, '__esModule', {
2505
2521
  value: true