@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/document2.mjs
CHANGED
|
@@ -506,7 +506,7 @@ var DelimiterNode = class extends BaseAstNode {
|
|
|
506
506
|
this.rightDelimExpr = rightDelimExpr2;
|
|
507
507
|
}
|
|
508
508
|
latex() {
|
|
509
|
-
return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
|
|
509
|
+
return this.leftDelimExpr + " " + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
|
|
510
510
|
}
|
|
511
511
|
arabicLatex() {
|
|
512
512
|
const sup = this.superscript !== null ? this.superscript.arabicLatex() : "";
|
|
@@ -3127,6 +3127,31 @@ function renderRawOperatorLatex(expr, side) {
|
|
|
3127
3127
|
return expr;
|
|
3128
3128
|
}
|
|
3129
3129
|
|
|
3130
|
+
// src/editor/indexSequence.ts
|
|
3131
|
+
function isIndexComma(node) {
|
|
3132
|
+
return node.kind === "operator" && (node.expr === "," || node.expr === "\u060C");
|
|
3133
|
+
}
|
|
3134
|
+
function isValidIndexSequence(chain) {
|
|
3135
|
+
let count = 0;
|
|
3136
|
+
let afterComma = false;
|
|
3137
|
+
for (const node of chain.nodes) {
|
|
3138
|
+
if (node.superscript || node.subscript) return false;
|
|
3139
|
+
if (isIndexComma(node)) {
|
|
3140
|
+
if (count === 0 || afterComma) return false;
|
|
3141
|
+
afterComma = true;
|
|
3142
|
+
continue;
|
|
3143
|
+
}
|
|
3144
|
+
const isDigit = node.kind === "number" && /^[0-9]$/.test(node.expr);
|
|
3145
|
+
const identity = node.sourceLatex ?? node.expr;
|
|
3146
|
+
const isLetter = node.kind === "char" && (/^[A-Za-z]$/.test(identity) || Array.from(identity).length === 1 && /^\p{L}$/u.test(identity));
|
|
3147
|
+
if (!isDigit && !isLetter) return false;
|
|
3148
|
+
count += 1;
|
|
3149
|
+
afterComma = false;
|
|
3150
|
+
if (count > 64) return false;
|
|
3151
|
+
}
|
|
3152
|
+
return count >= 2 && !afterComma;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3130
3155
|
// src/editor/render.ts
|
|
3131
3156
|
function selectedDigitForm(options) {
|
|
3132
3157
|
return options?.digitForm ?? "western";
|
|
@@ -3234,7 +3259,7 @@ function renderCharContent(node, options) {
|
|
|
3234
3259
|
}
|
|
3235
3260
|
function renderNodeEnglish(node, options) {
|
|
3236
3261
|
if (node.kind === "delimiter" && node.innerExpr) {
|
|
3237
|
-
return `${node.leftDelimExpr}${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
3262
|
+
return `${node.leftDelimExpr} ${renderChainEnglish(node.innerExpr, options)}${node.rightDelimExpr}${latinScripts(node, options)}`;
|
|
3238
3263
|
}
|
|
3239
3264
|
if (node.kind === "boxed" && node.innerExpr) {
|
|
3240
3265
|
const body = `\\boxed{${renderChainEnglish(node.innerExpr, options)}}`;
|
|
@@ -3353,10 +3378,18 @@ function renderNodeArabic(node, options) {
|
|
|
3353
3378
|
return arabicScripts(node, formatDigits(node.expr, selectedDigitForm(options)), options);
|
|
3354
3379
|
}
|
|
3355
3380
|
function renderChainEnglish(chain, options) {
|
|
3381
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3382
|
+
const atoms = chain.nodes.map((node) => isIndexComma(node) ? "," : renderNodeEnglish(node, options));
|
|
3383
|
+
return "\\mathnormal{" + atoms.join("") + "}";
|
|
3384
|
+
}
|
|
3356
3385
|
return chain.nodes.map((node) => renderNodeEnglish(node, options)).join(" ");
|
|
3357
3386
|
}
|
|
3358
3387
|
function renderChainArabic(chain, options) {
|
|
3359
|
-
|
|
3388
|
+
const rendered = chain.nodes.slice().reverse().map((node) => renderNodeArabic(node, options));
|
|
3389
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
3390
|
+
return "\\mathnormal{" + rendered.join("") + "}";
|
|
3391
|
+
}
|
|
3392
|
+
return rendered.join(" ");
|
|
3360
3393
|
}
|
|
3361
3394
|
function renderEnglishLatexFromSession(session) {
|
|
3362
3395
|
return renderChainEnglish(session.englishTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
@@ -4256,14 +4289,14 @@ function attachScripts(astNode, editorNode) {
|
|
|
4256
4289
|
editorNode.sourceLatex = astNode.sourceLatex;
|
|
4257
4290
|
}
|
|
4258
4291
|
if (astNode.superscript) {
|
|
4259
|
-
const sup = chainToEditorChain(astNode.superscript);
|
|
4292
|
+
const sup = chainToEditorChain(astNode.superscript, true);
|
|
4260
4293
|
if (!sup.editable) {
|
|
4261
4294
|
return sup;
|
|
4262
4295
|
}
|
|
4263
4296
|
editorNode.superscript = sup.chain;
|
|
4264
4297
|
}
|
|
4265
4298
|
if (astNode.subscript) {
|
|
4266
|
-
const sub = chainToEditorChain(astNode.subscript);
|
|
4299
|
+
const sub = chainToEditorChain(astNode.subscript, true);
|
|
4267
4300
|
if (!sub.editable) {
|
|
4268
4301
|
return sub;
|
|
4269
4302
|
}
|
|
@@ -4651,7 +4684,33 @@ function normalizeVerticalDelimiterCommands(chain) {
|
|
|
4651
4684
|
}
|
|
4652
4685
|
return new ChainNode(normalized);
|
|
4653
4686
|
}
|
|
4654
|
-
function chainToEditorChain(chain) {
|
|
4687
|
+
function chainToEditorChain(chain, script = false) {
|
|
4688
|
+
if (script && chain.chain.length === 1) {
|
|
4689
|
+
const wrapper = chain.chain[0];
|
|
4690
|
+
if (wrapper instanceof CommandNode && wrapper.name === "\\mathnormal") {
|
|
4691
|
+
if (wrapper.optionalArgs.length || wrapper.mandatoryArgs.length !== 1) {
|
|
4692
|
+
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" };
|
|
4693
|
+
}
|
|
4694
|
+
const imported = chainToEditorChain(wrapper.mandatoryArgs[0]);
|
|
4695
|
+
if (!imported.editable) return imported;
|
|
4696
|
+
const atoms = [];
|
|
4697
|
+
for (const node of imported.chain.nodes) {
|
|
4698
|
+
if (node.kind === "number" && /^[0-9]{2,}$/.test(node.expr)) {
|
|
4699
|
+
atoms.push(...node.expr.split("").map((digit) => createEditorNode("number", digit)));
|
|
4700
|
+
} else if (node.kind === "char" && !node.sourceLatex && /^[A-Za-z]{2,}$/.test(node.expr)) {
|
|
4701
|
+
atoms.push(...node.expr.split("").map((letter) => createEditorNode("char", letter)));
|
|
4702
|
+
} else {
|
|
4703
|
+
atoms.push(node);
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
imported.chain.nodes = atoms;
|
|
4707
|
+
if (!isValidIndexSequence(imported.chain)) {
|
|
4708
|
+
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" };
|
|
4709
|
+
}
|
|
4710
|
+
imported.chain.indexSequence = true;
|
|
4711
|
+
return imported;
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4655
4714
|
const nodes = [];
|
|
4656
4715
|
for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
|
|
4657
4716
|
const converted = astNodeToEditorNode(astNode);
|
|
@@ -4859,7 +4918,11 @@ function editorChainToAstChain(chain) {
|
|
|
4859
4918
|
}
|
|
4860
4919
|
nodes.push(converted.node);
|
|
4861
4920
|
}
|
|
4862
|
-
|
|
4921
|
+
const content = new ChainNode(nodes);
|
|
4922
|
+
if (chain.indexSequence && isValidIndexSequence(chain)) {
|
|
4923
|
+
return { ok: true, chain: new ChainNode([new CommandNode("\\mathnormal", [], [content])]) };
|
|
4924
|
+
}
|
|
4925
|
+
return { ok: true, chain: content };
|
|
4863
4926
|
}
|
|
4864
4927
|
function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
4865
4928
|
const converted = editorChainToAstChain(session.englishTree);
|