@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.
- package/README.md +2 -0
- package/dist/document.d.mts +2 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +36 -3
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +36 -3
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +70 -7
- 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 +70 -7
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +70 -7
- 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 +36 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +36 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +71 -7
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +71 -7
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +65 -6
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +65 -6
- 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 +71 -7
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +71 -7
- 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 +71 -7
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +71 -7
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -166,7 +166,7 @@ var DelimiterNode = class extends BaseAstNode {
|
|
|
166
166
|
this.rightDelimExpr = rightDelimExpr2;
|
|
167
167
|
}
|
|
168
168
|
latex() {
|
|
169
|
-
return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
|
|
169
|
+
return this.leftDelimExpr + " " + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
|
|
170
170
|
}
|
|
171
171
|
arabicLatex() {
|
|
172
172
|
const sup = this.superscript !== null ? this.superscript.arabicLatex() : "";
|
|
@@ -2897,6 +2897,31 @@ function renderRawOperatorLatex(expr, side) {
|
|
|
2897
2897
|
return expr;
|
|
2898
2898
|
}
|
|
2899
2899
|
|
|
2900
|
+
// src/editor/indexSequence.ts
|
|
2901
|
+
function isIndexComma(node) {
|
|
2902
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
2903
|
+
}
|
|
2904
|
+
function isValidIndexSequence(chain) {
|
|
2905
|
+
let count = 0;
|
|
2906
|
+
let afterComma = false;
|
|
2907
|
+
for (const node of chain.nodes) {
|
|
2908
|
+
if (node.superscript || node.subscript) return false;
|
|
2909
|
+
if (isIndexComma(node)) {
|
|
2910
|
+
if (count === 0 || afterComma) return false;
|
|
2911
|
+
afterComma = true;
|
|
2912
|
+
continue;
|
|
2913
|
+
}
|
|
2914
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
2915
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
2916
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
2917
|
+
if (!isDigit && !isLetter) return false;
|
|
2918
|
+
count += 1;
|
|
2919
|
+
afterComma = false;
|
|
2920
|
+
if (count > 64) return false;
|
|
2921
|
+
}
|
|
2922
|
+
return count >= 2 && !afterComma;
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2900
2925
|
// src/editor/render.ts
|
|
2901
2926
|
function selectedDigitForm(options) {
|
|
2902
2927
|
return options?.digitForm ?? "western";
|
|
@@ -3004,7 +3029,7 @@ function renderCharContent(node, options) {
|
|
|
3004
3029
|
}
|
|
3005
3030
|
function renderNodeEnglish(node, options) {
|
|
3006
3031
|
if (node.kind === "delimiter" && node.innerExpr) {
|
|
3007
|
-
return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
3032
|
+
return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
3008
3033
|
}
|
|
3009
3034
|
if (node.kind === "boxed" && node.innerExpr) {
|
|
3010
3035
|
const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
|
|
@@ -3123,10 +3148,18 @@ function renderNodeArabic(node, options) {
|
|
|
3123
3148
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3124
3149
|
}
|
|
3125
3150
|
function renderChainEnglish(chain, options) {
|
|
3151
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3152
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
3153
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
3154
|
+
}
|
|
3126
3155
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3127
3156
|
}
|
|
3128
3157
|
function renderChainArabic(chain, options) {
|
|
3129
|
-
|
|
3158
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
3159
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3160
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
3161
|
+
}
|
|
3162
|
+
return rendered.join(" ");
|
|
3130
3163
|
}
|
|
3131
3164
|
function renderEnglishLatexFromSession(session) {
|
|
3132
3165
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -4014,14 +4047,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
4014
4047
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
4015
4048
|
}
|
|
4016
4049
|
if (astNode.superscript) {
|
|
4017
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
4050
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
4018
4051
|
if (!sup.editable) {
|
|
4019
4052
|
return sup;
|
|
4020
4053
|
}
|
|
4021
4054
|
editorNode.superscript = sup.chain;
|
|
4022
4055
|
}
|
|
4023
4056
|
if (astNode.subscript) {
|
|
4024
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
4057
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
4025
4058
|
if (!sub.editable) {
|
|
4026
4059
|
return sub;
|
|
4027
4060
|
}
|
|
@@ -4409,7 +4442,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
4409
4442
|
}
|
|
4410
4443
|
return new ChainNode(normalized);
|
|
4411
4444
|
}
|
|
4412
|
-
function chainToEditorChain(chain) {
|
|
4445
|
+
function chainToEditorChain(chain, script = false) {
|
|
4446
|
+
if (script && chain.chain.length === 1) {
|
|
4447
|
+
const wrapper = chain.chain[0];
|
|
4448
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
4449
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
4450
|
+
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" };
|
|
4451
|
+
}
|
|
4452
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
4453
|
+
if (!imported.editable) return imported;
|
|
4454
|
+
const atoms = [];
|
|
4455
|
+
for (const node of imported.chain.nodes) {
|
|
4456
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
4457
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
4458
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
4459
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
4460
|
+
} else {
|
|
4461
|
+
atoms.push(node);
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
imported.chain.nodes = atoms;
|
|
4465
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
4466
|
+
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" };
|
|
4467
|
+
}
|
|
4468
|
+
imported.chain.indexSequence = true;
|
|
4469
|
+
return imported;
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4413
4472
|
const nodes = [];
|
|
4414
4473
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
4415
4474
|
const converted = astNodeToEditorNode(astNode);
|