@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.
- package/dist/document.d.mts +2 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +35 -2
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +35 -2
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +68 -5
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +2 -0
- package/dist/document2.d.ts +2 -0
- package/dist/document2.js +68 -5
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +68 -5
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.global.js +35 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +69 -5
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +69 -5
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +63 -4
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +63 -4
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.d.mts +2 -0
- package/dist/react-document2.d.ts +2 -0
- package/dist/react-document2.js +69 -5
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +69 -5
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +2 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +69 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +69 -5
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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";
|
|
@@ -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
|
-
|
|
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);
|