@drghaliasri/butex 7.3.3 → 7.3.5

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.
Files changed (44) hide show
  1. package/README.md +2 -0
  2. package/dist/document.d.mts +2 -0
  3. package/dist/document.d.ts +2 -0
  4. package/dist/document.js +36 -3
  5. package/dist/document.js.map +1 -1
  6. package/dist/document.mjs +36 -3
  7. package/dist/document.mjs.map +1 -1
  8. package/dist/document2-cli.js +70 -7
  9. package/dist/document2-cli.js.map +1 -1
  10. package/dist/document2.d.mts +2 -0
  11. package/dist/document2.d.ts +2 -0
  12. package/dist/document2.js +70 -7
  13. package/dist/document2.js.map +1 -1
  14. package/dist/document2.mjs +70 -7
  15. package/dist/document2.mjs.map +1 -1
  16. package/dist/index.d.mts +2 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.global.js +36 -2
  19. package/dist/index.global.js.map +1 -1
  20. package/dist/index.js +36 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +36 -2
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/react-document.js +71 -7
  25. package/dist/react-document.js.map +1 -1
  26. package/dist/react-document.mjs +71 -7
  27. package/dist/react-document.mjs.map +1 -1
  28. package/dist/react-document2-preview.js +65 -6
  29. package/dist/react-document2-preview.js.map +1 -1
  30. package/dist/react-document2-preview.mjs +65 -6
  31. package/dist/react-document2-preview.mjs.map +1 -1
  32. package/dist/react-document2.d.mts +2 -0
  33. package/dist/react-document2.d.ts +2 -0
  34. package/dist/react-document2.js +71 -7
  35. package/dist/react-document2.js.map +1 -1
  36. package/dist/react-document2.mjs +71 -7
  37. package/dist/react-document2.mjs.map +1 -1
  38. package/dist/react.d.mts +2 -0
  39. package/dist/react.d.ts +2 -0
  40. package/dist/react.js +71 -7
  41. package/dist/react.js.map +1 -1
  42. package/dist/react.mjs +71 -7
  43. package/dist/react.mjs.map +1 -1
  44. package/package.json +1 -1
package/dist/react.mjs CHANGED
@@ -1539,6 +1539,31 @@ function formatDigits(value, digitForm = "western") {
1539
1539
  }).join("");
1540
1540
  }
1541
1541
 
1542
+ // src/editor/indexSequence.ts
1543
+ function isIndexComma(node) {
1544
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
1545
+ }
1546
+ function isValidIndexSequence(chain) {
1547
+ let count = 0;
1548
+ let afterComma = false;
1549
+ for (const node of chain.nodes) {
1550
+ if (node.superscript || node.subscript) return false;
1551
+ if (isIndexComma(node)) {
1552
+ if (count === 0 || afterComma) return false;
1553
+ afterComma = true;
1554
+ continue;
1555
+ }
1556
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
1557
+ const identity = node.sourceLatex ?? node.expr;
1558
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
1559
+ if (!isDigit && !isLetter) return false;
1560
+ count += 1;
1561
+ afterComma = false;
1562
+ if (count > 64) return false;
1563
+ }
1564
+ return count >= 2 && !afterComma;
1565
+ }
1566
+
1542
1567
  // src/editor/render.ts
1543
1568
  function selectedDigitForm(options) {
1544
1569
  return options?.digitForm ?? "western";
@@ -1646,7 +1671,7 @@ function renderCharContent(node, options) {
1646
1671
  }
1647
1672
  function renderNodeEnglish(node, options) {
1648
1673
  if (node.kind === "delimiter" && node.innerExpr) {
1649
- return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
1674
+ return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
1650
1675
  }
1651
1676
  if (node.kind === "boxed" && node.innerExpr) {
1652
1677
  const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
@@ -1765,10 +1790,18 @@ function renderNodeArabic(node, options) {
1765
1790
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
1766
1791
  }
1767
1792
  function renderChainEnglish(chain, options) {
1793
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
1794
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
1795
+ return "\\mathnormal{" + atoms.join("") + "}";
1796
+ }
1768
1797
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
1769
1798
  }
1770
1799
  function renderChainArabic(chain, options) {
1771
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
1800
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
1801
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
1802
+ return "\\mathnormal{" + rendered.join("") + "}";
1803
+ }
1804
+ return rendered.join(" ");
1772
1805
  }
1773
1806
  function renderEnglishLatexFromSession(session) {
1774
1807
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -3608,6 +3641,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
3608
3641
  if (!engLocated) {
3609
3642
  return false;
3610
3643
  }
3644
+ if (engLocated.chain.indexSequence) return false;
3611
3645
  const nodes = engLocated.chain.nodes;
3612
3646
  const i = session.caret.index;
3613
3647
  let targetId = null;
@@ -8500,7 +8534,7 @@ var DelimiterNode = class extends BaseAstNode {
8500
8534
  this.rightDelimExpr = rightDelimExpr2;
8501
8535
  }
8502
8536
  latex() {
8503
- return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
8537
+ return this.leftDelimExpr + " " + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
8504
8538
  }
8505
8539
  arabicLatex() {
8506
8540
  const sup = this.superscript !== null ? this.superscript.arabicLatex() : "";
@@ -8889,14 +8923,14 @@ function attachScripts(astNode, editorNode) {
8889
8923
  editorNode.sourceLatex = astNode.sourceLatex;
8890
8924
  }
8891
8925
  if (astNode.superscript) {
8892
- const sup = chainToEditorChain(astNode.superscript);
8926
+ const sup = chainToEditorChain(astNode.superscript, true);
8893
8927
  if (!sup.editable) {
8894
8928
  return sup;
8895
8929
  }
8896
8930
  editorNode.superscript = sup.chain;
8897
8931
  }
8898
8932
  if (astNode.subscript) {
8899
- const sub = chainToEditorChain(astNode.subscript);
8933
+ const sub = chainToEditorChain(astNode.subscript, true);
8900
8934
  if (!sub.editable) {
8901
8935
  return sub;
8902
8936
  }
@@ -9284,7 +9318,33 @@ function normalizeVerticalDelimiterCommands(chain) {
9284
9318
  }
9285
9319
  return new ChainNode(normalized);
9286
9320
  }
9287
- function chainToEditorChain(chain) {
9321
+ function chainToEditorChain(chain, script = false) {
9322
+ if (script && chain.chain.length === 1) {
9323
+ const wrapper = chain.chain[0];
9324
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
9325
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
9326
+ return { editable: false, reason: "\u0635\u064A\u063A\u0629 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629" };
9327
+ }
9328
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
9329
+ if (!imported.editable) return imported;
9330
+ const atoms = [];
9331
+ for (const node of imported.chain.nodes) {
9332
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
9333
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
9334
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
9335
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
9336
+ } else {
9337
+ atoms.push(node);
9338
+ }
9339
+ }
9340
+ imported.chain.nodes = atoms;
9341
+ if (!isValidIndexSequence(imported.chain)) {
9342
+ return { editable: false, reason: "\u0645\u062D\u062A\u0648\u0649 \u0645\u062C\u0645\u0648\u0639\u0629 \u0627\u0644\u0641\u0647\u0627\u0631\u0633 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645" };
9343
+ }
9344
+ imported.chain.indexSequence = true;
9345
+ return imported;
9346
+ }
9347
+ }
9288
9348
  const nodes = [];
9289
9349
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
9290
9350
  const converted = astNodeToEditorNode(astNode);
@@ -9492,7 +9552,11 @@ function editorChainToAstChain(chain) {
9492
9552
  }
9493
9553
  nodes.push(converted.node);
9494
9554
  }
9495
- return { ok: true, chain: new ChainNode(nodes) };
9555
+ const content = new ChainNode(nodes);
9556
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
9557
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
9558
+ }
9559
+ return { ok: true, chain: content };
9496
9560
  }
9497
9561
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
9498
9562
  const converted = editorChainToAstChain(session.englishTree);