@drghaliasri/butex 7.3.4 → 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 (43) hide show
  1. package/dist/document.d.mts +2 -0
  2. package/dist/document.d.ts +2 -0
  3. package/dist/document.js +35 -2
  4. package/dist/document.js.map +1 -1
  5. package/dist/document.mjs +35 -2
  6. package/dist/document.mjs.map +1 -1
  7. package/dist/document2-cli.js +68 -5
  8. package/dist/document2-cli.js.map +1 -1
  9. package/dist/document2.d.mts +2 -0
  10. package/dist/document2.d.ts +2 -0
  11. package/dist/document2.js +68 -5
  12. package/dist/document2.js.map +1 -1
  13. package/dist/document2.mjs +68 -5
  14. package/dist/document2.mjs.map +1 -1
  15. package/dist/index.d.mts +2 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.global.js +35 -1
  18. package/dist/index.global.js.map +1 -1
  19. package/dist/index.js +35 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +35 -1
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/react-document.js +69 -5
  24. package/dist/react-document.js.map +1 -1
  25. package/dist/react-document.mjs +69 -5
  26. package/dist/react-document.mjs.map +1 -1
  27. package/dist/react-document2-preview.js +63 -4
  28. package/dist/react-document2-preview.js.map +1 -1
  29. package/dist/react-document2-preview.mjs +63 -4
  30. package/dist/react-document2-preview.mjs.map +1 -1
  31. package/dist/react-document2.d.mts +2 -0
  32. package/dist/react-document2.d.ts +2 -0
  33. package/dist/react-document2.js +69 -5
  34. package/dist/react-document2.js.map +1 -1
  35. package/dist/react-document2.mjs +69 -5
  36. package/dist/react-document2.mjs.map +1 -1
  37. package/dist/react.d.mts +2 -0
  38. package/dist/react.d.ts +2 -0
  39. package/dist/react.js +69 -5
  40. package/dist/react.js.map +1 -1
  41. package/dist/react.mjs +69 -5
  42. package/dist/react.mjs.map +1 -1
  43. package/package.json +1 -1
@@ -173,6 +173,8 @@ type EditorSyncState = 'synced' | 'diverged';
173
173
  type EditorChain = {
174
174
  id: string;
175
175
  nodes: EditorNode[];
176
+ /** Complete script authored as \\mathnormal{ordered,index,atoms}. */
177
+ indexSequence?: boolean;
176
178
  };
177
179
  type EditorNode = {
178
180
  id: string;
@@ -173,6 +173,8 @@ type EditorSyncState = 'synced' | 'diverged';
173
173
  type EditorChain = {
174
174
  id: string;
175
175
  nodes: EditorNode[];
176
+ /** Complete script authored as \\mathnormal{ordered,index,atoms}. */
177
+ indexSequence?: boolean;
176
178
  };
177
179
  type EditorNode = {
178
180
  id: string;
package/dist/document.js CHANGED
@@ -2052,6 +2052,31 @@ function formatDigits(value, digitForm = "western") {
2052
2052
  }).join("");
2053
2053
  }
2054
2054
 
2055
+ // src/editor/indexSequence.ts
2056
+ function isIndexComma(node) {
2057
+ return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
2058
+ }
2059
+ function isValidIndexSequence(chain) {
2060
+ let count = 0;
2061
+ let afterComma = false;
2062
+ for (const node of chain.nodes) {
2063
+ if (node.superscript || node.subscript) return false;
2064
+ if (isIndexComma(node)) {
2065
+ if (count === 0 || afterComma) return false;
2066
+ afterComma = true;
2067
+ continue;
2068
+ }
2069
+ const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
2070
+ const identity = node.sourceLatex ?? node.expr;
2071
+ const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
2072
+ if (!isDigit && !isLetter) return false;
2073
+ count += 1;
2074
+ afterComma = false;
2075
+ if (count > 64) return false;
2076
+ }
2077
+ return count >= 2 && !afterComma;
2078
+ }
2079
+
2055
2080
  // src/editor/render.ts
2056
2081
  function selectedDigitForm(options) {
2057
2082
  return options?.digitForm ?? "western";
@@ -2179,7 +2204,11 @@ function renderNodeArabic(node, options) {
2179
2204
  return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
2180
2205
  }
2181
2206
  function renderChainArabic(chain, options) {
2182
- return chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options)).join(" ");
2207
+ const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
2208
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
2209
+ return "\\mathnormal{" + rendered.join("") + "}";
2210
+ }
2211
+ return rendered.join(" ");
2183
2212
  }
2184
2213
  function renderArabicLatexFromSession(session) {
2185
2214
  return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
@@ -3158,7 +3187,11 @@ function editorChainToAstChain(chain) {
3158
3187
  }
3159
3188
  nodes.push(converted.node);
3160
3189
  }
3161
- return { ok: true, chain: new ChainNode(nodes) };
3190
+ const content = new ChainNode(nodes);
3191
+ if (chain.indexSequence && isValidIndexSequence(chain)) {
3192
+ return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
3193
+ }
3194
+ return { ok: true, chain: content };
3162
3195
  }
3163
3196
  function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
3164
3197
  const converted = editorChainToAstChain(session.englishTree);