@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
package/dist/document2-cli.js
CHANGED
|
@@ -2971,6 +2971,31 @@ function renderRawOperatorLatex(expr, side) {
|
|
|
2971
2971
|
return expr;
|
|
2972
2972
|
}
|
|
2973
2973
|
|
|
2974
|
+
// src/editor/indexSequence.ts
|
|
2975
|
+
function isIndexComma(node) {
|
|
2976
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
2977
|
+
}
|
|
2978
|
+
function isValidIndexSequence(chain) {
|
|
2979
|
+
let count = 0;
|
|
2980
|
+
let afterComma = false;
|
|
2981
|
+
for (const node of chain.nodes) {
|
|
2982
|
+
if (node.superscript || node.subscript) return false;
|
|
2983
|
+
if (isIndexComma(node)) {
|
|
2984
|
+
if (count === 0 || afterComma) return false;
|
|
2985
|
+
afterComma = true;
|
|
2986
|
+
continue;
|
|
2987
|
+
}
|
|
2988
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
2989
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
2990
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && new RegExp("^\\p{L}$", "u").test(identity));
|
|
2991
|
+
if (!isDigit && !isLetter) return false;
|
|
2992
|
+
count += 1;
|
|
2993
|
+
afterComma = false;
|
|
2994
|
+
if (count > 64) return false;
|
|
2995
|
+
}
|
|
2996
|
+
return count >= 2 && !afterComma;
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2974
2999
|
// src/editor/render.ts
|
|
2975
3000
|
function selectedDigitForm(options) {
|
|
2976
3001
|
return options?.digitForm ?? "western";
|
|
@@ -3197,10 +3222,18 @@ function renderNodeArabic(node, options) {
|
|
|
3197
3222
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3198
3223
|
}
|
|
3199
3224
|
function renderChainEnglish(chain, options) {
|
|
3225
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3226
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
3227
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
3228
|
+
}
|
|
3200
3229
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3201
3230
|
}
|
|
3202
3231
|
function renderChainArabic(chain, options) {
|
|
3203
|
-
|
|
3232
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
3233
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3234
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
3235
|
+
}
|
|
3236
|
+
return rendered.join(" ");
|
|
3204
3237
|
}
|
|
3205
3238
|
function renderEnglishLatexFromSession(session) {
|
|
3206
3239
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -4078,14 +4111,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
4078
4111
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
4079
4112
|
}
|
|
4080
4113
|
if (astNode.superscript) {
|
|
4081
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
4114
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
4082
4115
|
if (!sup.editable) {
|
|
4083
4116
|
return sup;
|
|
4084
4117
|
}
|
|
4085
4118
|
editorNode.superscript = sup.chain;
|
|
4086
4119
|
}
|
|
4087
4120
|
if (astNode.subscript) {
|
|
4088
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
4121
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
4089
4122
|
if (!sub.editable) {
|
|
4090
4123
|
return sub;
|
|
4091
4124
|
}
|
|
@@ -4473,7 +4506,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
4473
4506
|
}
|
|
4474
4507
|
return new ChainNode(normalized);
|
|
4475
4508
|
}
|
|
4476
|
-
function chainToEditorChain(chain) {
|
|
4509
|
+
function chainToEditorChain(chain, script = false) {
|
|
4510
|
+
if (script && chain.chain.length === 1) {
|
|
4511
|
+
const wrapper = chain.chain[0];
|
|
4512
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
4513
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
4514
|
+
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" };
|
|
4515
|
+
}
|
|
4516
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
4517
|
+
if (!imported.editable) return imported;
|
|
4518
|
+
const atoms = [];
|
|
4519
|
+
for (const node of imported.chain.nodes) {
|
|
4520
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
4521
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
4522
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
4523
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
4524
|
+
} else {
|
|
4525
|
+
atoms.push(node);
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
imported.chain.nodes = atoms;
|
|
4529
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
4530
|
+
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" };
|
|
4531
|
+
}
|
|
4532
|
+
imported.chain.indexSequence = true;
|
|
4533
|
+
return imported;
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4477
4536
|
const nodes = [];
|
|
4478
4537
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
4479
4538
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -4681,7 +4740,11 @@ function editorChainToAstChain(chain) {
|
|
|
4681
4740
|
}
|
|
4682
4741
|
nodes.push(converted.node);
|
|
4683
4742
|
}
|
|
4684
|
-
|
|
4743
|
+
const content = new ChainNode(nodes);
|
|
4744
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
4745
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
4746
|
+
}
|
|
4747
|
+
return { ok: true, chain: content };
|
|
4685
4748
|
}
|
|
4686
4749
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
4687
4750
|
const converted = editorChainToAstChain(session.englishTree);
|