@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
package/dist/react-document.js
CHANGED
|
@@ -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() : "";
|
|
@@ -2288,6 +2288,31 @@ function formatDigits(value, digitForm = "western") {
|
|
|
2288
2288
|
}).join("");
|
|
2289
2289
|
}
|
|
2290
2290
|
|
|
2291
|
+
// src/editor/indexSequence.ts
|
|
2292
|
+
function isIndexComma(node) {
|
|
2293
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
2294
|
+
}
|
|
2295
|
+
function isValidIndexSequence(chain) {
|
|
2296
|
+
let count = 0;
|
|
2297
|
+
let afterComma = false;
|
|
2298
|
+
for (const node of chain.nodes) {
|
|
2299
|
+
if (node.superscript || node.subscript) return false;
|
|
2300
|
+
if (isIndexComma(node)) {
|
|
2301
|
+
if (count === 0 || afterComma) return false;
|
|
2302
|
+
afterComma = true;
|
|
2303
|
+
continue;
|
|
2304
|
+
}
|
|
2305
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
2306
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
2307
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
2308
|
+
if (!isDigit && !isLetter) return false;
|
|
2309
|
+
count += 1;
|
|
2310
|
+
afterComma = false;
|
|
2311
|
+
if (count > 64) return false;
|
|
2312
|
+
}
|
|
2313
|
+
return count >= 2 && !afterComma;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2291
2316
|
// src/editor/render.ts
|
|
2292
2317
|
function selectedDigitForm(options) {
|
|
2293
2318
|
return options?.digitForm ?? "western";
|
|
@@ -2395,7 +2420,7 @@ function renderCharContent(node, options) {
|
|
|
2395
2420
|
}
|
|
2396
2421
|
function renderNodeEnglish(node, options) {
|
|
2397
2422
|
if (node.kind === "delimiter" && node.innerExpr) {
|
|
2398
|
-
return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
2423
|
+
return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
2399
2424
|
}
|
|
2400
2425
|
if (node.kind === "boxed" && node.innerExpr) {
|
|
2401
2426
|
const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
|
|
@@ -2514,10 +2539,18 @@ function renderNodeArabic(node, options) {
|
|
|
2514
2539
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
2515
2540
|
}
|
|
2516
2541
|
function renderChainEnglish(chain, options) {
|
|
2542
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
2543
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
2544
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
2545
|
+
}
|
|
2517
2546
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
2518
2547
|
}
|
|
2519
2548
|
function renderChainArabic(chain, options) {
|
|
2520
|
-
|
|
2549
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
2550
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
2551
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
2552
|
+
}
|
|
2553
|
+
return rendered.join(" ");
|
|
2521
2554
|
}
|
|
2522
2555
|
function renderEnglishLatexFromSession(session) {
|
|
2523
2556
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -4357,6 +4390,7 @@ function tryMergeLeafTyping(session, kind, fragment) {
|
|
|
4357
4390
|
if (!engLocated) {
|
|
4358
4391
|
return false;
|
|
4359
4392
|
}
|
|
4393
|
+
if (engLocated.chain.indexSequence) return false;
|
|
4360
4394
|
const nodes = engLocated.chain.nodes;
|
|
4361
4395
|
const i = session.caret.index;
|
|
4362
4396
|
let targetId = null;
|
|
@@ -7387,14 +7421,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
7387
7421
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
7388
7422
|
}
|
|
7389
7423
|
if (astNode.superscript) {
|
|
7390
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
7424
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
7391
7425
|
if (!sup.editable) {
|
|
7392
7426
|
return sup;
|
|
7393
7427
|
}
|
|
7394
7428
|
editorNode.superscript = sup.chain;
|
|
7395
7429
|
}
|
|
7396
7430
|
if (astNode.subscript) {
|
|
7397
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
7431
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
7398
7432
|
if (!sub.editable) {
|
|
7399
7433
|
return sub;
|
|
7400
7434
|
}
|
|
@@ -7782,7 +7816,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
7782
7816
|
}
|
|
7783
7817
|
return new ChainNode(normalized);
|
|
7784
7818
|
}
|
|
7785
|
-
function chainToEditorChain(chain) {
|
|
7819
|
+
function chainToEditorChain(chain, script = false) {
|
|
7820
|
+
if (script && chain.chain.length === 1) {
|
|
7821
|
+
const wrapper = chain.chain[0];
|
|
7822
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
7823
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
7824
|
+
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" };
|
|
7825
|
+
}
|
|
7826
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
7827
|
+
if (!imported.editable) return imported;
|
|
7828
|
+
const atoms = [];
|
|
7829
|
+
for (const node of imported.chain.nodes) {
|
|
7830
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
7831
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
7832
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
7833
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
7834
|
+
} else {
|
|
7835
|
+
atoms.push(node);
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7838
|
+
imported.chain.nodes = atoms;
|
|
7839
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
7840
|
+
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" };
|
|
7841
|
+
}
|
|
7842
|
+
imported.chain.indexSequence = true;
|
|
7843
|
+
return imported;
|
|
7844
|
+
}
|
|
7845
|
+
}
|
|
7786
7846
|
const nodes = [];
|
|
7787
7847
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
7788
7848
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -7990,7 +8050,11 @@ function editorChainToAstChain(chain) {
|
|
|
7990
8050
|
}
|
|
7991
8051
|
nodes.push(converted.node);
|
|
7992
8052
|
}
|
|
7993
|
-
|
|
8053
|
+
const content = new ChainNode(nodes);
|
|
8054
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
8055
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
8056
|
+
}
|
|
8057
|
+
return { ok: true, chain: content };
|
|
7994
8058
|
}
|
|
7995
8059
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
7996
8060
|
const converted = editorChainToAstChain(session.englishTree);
|