@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
@@ -137,7 +137,7 @@ var DelimiterNode = class extends BaseAstNode {
137
137
  this.rightDelimExpr = rightDelimExpr2;
138
138
  }
139
139
  latex() {
140
- return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
140
+ return this.leftDelimExpr + " " + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
141
141
  }
142
142
  arabicLatex() {
143
143
  const sup = this.superscript !== null ? this.superscript.arabicLatex() : "";
@@ -2868,6 +2868,31 @@ function renderRawOperatorLatex(expr, side) {
2868
2868
  return expr;
2869
2869
  }
2870
2870
 
2871
+ // src/editor/indexSequence.ts
2872
+ function isIndexComma(node) {
2873
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
2874
+ }
2875
+ function isValidIndexSequence(chain) {
2876
+ let count = 0;
2877
+ let afterComma = false;
2878
+ for (const node of chain.nodes) {
2879
+ if (node.superscript || node.subscript) return false;
2880
+ if (isIndexComma(node)) {
2881
+ if (count === 0 || afterComma) return false;
2882
+ afterComma = true;
2883
+ continue;
2884
+ }
2885
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
2886
+ const identity = node.sourceLatex ?? node.expr;
2887
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
2888
+ if (!isDigit && !isLetter) return false;
2889
+ count += 1;
2890
+ afterComma = false;
2891
+ if (count > 64) return false;
2892
+ }
2893
+ return count >= 2 && !afterComma;
2894
+ }
2895
+
2871
2896
  // src/editor/render.ts
2872
2897
  function selectedDigitForm(options) {
2873
2898
  return options?.digitForm ?? "western";
@@ -2975,7 +3000,7 @@ function renderCharContent(node, options) {
2975
3000
  }
2976
3001
  function renderNodeEnglish(node, options) {
2977
3002
  if (node.kind === "delimiter" && node.innerExpr) {
2978
- return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
3003
+ return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
2979
3004
  }
2980
3005
  if (node.kind === "boxed" && node.innerExpr) {
2981
3006
  const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
@@ -3094,10 +3119,18 @@ function renderNodeArabic(node, options) {
3094
3119
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
3095
3120
  }
3096
3121
  function renderChainEnglish(chain, options) {
3122
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3123
+ const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
3124
+ return "\\mathnormal{" + atoms.join("") + "}";
3125
+ }
3097
3126
  return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
3098
3127
  }
3099
3128
  function renderChainArabic(chain, options) {
3100
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
3129
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
3130
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3131
+ return "\\mathnormal{" + rendered.join("") + "}";
3132
+ }
3133
+ return rendered.join(" ");
3101
3134
  }
3102
3135
  function renderEnglishLatexFromSession(session) {
3103
3136
  return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -3985,14 +4018,14 @@ function attachScripts(astNode, editorNode) {
3985
4018
  editorNode.sourceLatex = astNode.sourceLatex;
3986
4019
  }
3987
4020
  if (astNode.superscript) {
3988
- const sup = chainToEditorChain(astNode.superscript);
4021
+ const sup = chainToEditorChain(astNode.superscript, true);
3989
4022
  if (!sup.editable) {
3990
4023
  return sup;
3991
4024
  }
3992
4025
  editorNode.superscript = sup.chain;
3993
4026
  }
3994
4027
  if (astNode.subscript) {
3995
- const sub = chainToEditorChain(astNode.subscript);
4028
+ const sub = chainToEditorChain(astNode.subscript, true);
3996
4029
  if (!sub.editable) {
3997
4030
  return sub;
3998
4031
  }
@@ -4380,7 +4413,33 @@ function normalizeVerticalDelimiterCommands(chain) {
4380
4413
  }
4381
4414
  return new ChainNode(normalized);
4382
4415
  }
4383
- function chainToEditorChain(chain) {
4416
+ function chainToEditorChain(chain, script = false) {
4417
+ if (script && chain.chain.length === 1) {
4418
+ const wrapper = chain.chain[0];
4419
+ if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
4420
+ if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
4421
+ 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" };
4422
+ }
4423
+ const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
4424
+ if (!imported.editable) return imported;
4425
+ const atoms = [];
4426
+ for (const node of imported.chain.nodes) {
4427
+ if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
4428
+ atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
4429
+ } else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
4430
+ atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
4431
+ } else {
4432
+ atoms.push(node);
4433
+ }
4434
+ }
4435
+ imported.chain.nodes = atoms;
4436
+ if (!isValidIndexSequence(imported.chain)) {
4437
+ 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" };
4438
+ }
4439
+ imported.chain.indexSequence = true;
4440
+ return imported;
4441
+ }
4442
+ }
4384
4443
  const nodes = [];
4385
4444
  for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
4386
4445
  const converted = astNodeToEditorNode(astNode);