@drghaliasri/butex 8.0.1 → 8.0.3
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-cli.js +123 -16
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +5 -5
- package/dist/document.d.ts +5 -5
- package/dist/document.js +65 -22
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +65 -22
- package/dist/document.mjs.map +1 -1
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.global.js +54 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +54 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -9
- package/dist/index.mjs.map +1 -1
- package/dist/react-document-preview.js +44 -15
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +44 -15
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +3 -3
- package/dist/react-document.d.ts +3 -3
- package/dist/react-document.js +136 -46
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +136 -46
- package/dist/react-document.mjs.map +1 -1
- package/dist/react.d.mts +4 -3
- package/dist/react.d.ts +4 -3
- package/dist/react.js +123 -37
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +123 -37
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -208,7 +208,9 @@ ${this.closing}` + this.latexScripts();
|
|
|
208
208
|
}
|
|
209
209
|
const formattedLines = this.lines.map((line) => ` ${line.arabicLatex()}`);
|
|
210
210
|
const content = formattedLines.join(" \\\\\n");
|
|
211
|
-
const fullContent =
|
|
211
|
+
const fullContent = this.opening === "\\begin{cases}" && this.closing === "\\end{cases}" ? `\\left.\\begin{array}{rl}
|
|
212
|
+
${content}
|
|
213
|
+
\\end{array}\\right\\}` : `${this.opening}
|
|
212
214
|
${content}
|
|
213
215
|
${this.closing}`;
|
|
214
216
|
return this.arabicLatexScripts(sup, sub, fullContent);
|
|
@@ -2673,7 +2675,7 @@ function createAccentNode(accentId) {
|
|
|
2673
2675
|
}
|
|
2674
2676
|
function createGridEnvNode(envName, rows, columns, columnAlignments) {
|
|
2675
2677
|
const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
|
|
2676
|
-
const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
2678
|
+
const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
|
|
2677
2679
|
const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
2678
2680
|
const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
|
|
2679
2681
|
return {
|
|
@@ -2977,6 +2979,9 @@ function renderMatrixRowsArabic(node, options) {
|
|
|
2977
2979
|
const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
|
|
2978
2980
|
return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
|
|
2979
2981
|
}
|
|
2982
|
+
if (envName === "cases" && options?.casesPresentation) {
|
|
2983
|
+
return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
|
|
2984
|
+
}
|
|
2980
2985
|
return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
|
|
2981
2986
|
}
|
|
2982
2987
|
function renderAccentEnglish(command, accent, base, options) {
|
|
@@ -2998,6 +3003,10 @@ function renderAccentArabic(command, accent, base, options) {
|
|
|
2998
3003
|
function escapeText(s) {
|
|
2999
3004
|
return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
|
|
3000
3005
|
}
|
|
3006
|
+
function escapeAtomicLiteral(text) {
|
|
3007
|
+
const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
|
|
3008
|
+
return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
|
|
3009
|
+
}
|
|
3001
3010
|
function renderCharContent(node, options) {
|
|
3002
3011
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3003
3012
|
const font = node.characterFont ?? "default";
|
|
@@ -3044,7 +3053,7 @@ function renderNodeEnglish(node, options) {
|
|
|
3044
3053
|
return `${body}${latinScripts(node, options)}`;
|
|
3045
3054
|
}
|
|
3046
3055
|
if (node.kind === "atomicOperatorCommand") {
|
|
3047
|
-
const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3056
|
+
const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
|
|
3048
3057
|
return `${body}${latinScripts(node, options)}`;
|
|
3049
3058
|
}
|
|
3050
3059
|
if (node.kind === "standardCommand") {
|
|
@@ -3061,7 +3070,8 @@ function renderNodeEnglish(node, options) {
|
|
|
3061
3070
|
if (node.wrapperCommand) {
|
|
3062
3071
|
const expr = formatDigits(node.expr, selectedDigitForm(options));
|
|
3063
3072
|
const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
|
|
3064
|
-
|
|
3073
|
+
const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
|
|
3074
|
+
return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
|
|
3065
3075
|
}
|
|
3066
3076
|
return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
|
|
3067
3077
|
}
|
|
@@ -3122,7 +3132,8 @@ function renderNodeArabic(node, options) {
|
|
|
3122
3132
|
const content = renderCharContent(node, options);
|
|
3123
3133
|
if (node.wrapperCommand) {
|
|
3124
3134
|
const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
|
|
3125
|
-
|
|
3135
|
+
const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
|
|
3136
|
+
return arabicScripts(node, `${wrapper}{${literal}}`, options);
|
|
3126
3137
|
}
|
|
3127
3138
|
return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
|
|
3128
3139
|
}
|
|
@@ -3151,6 +3162,9 @@ function renderEnglishLatexFromSession(session) {
|
|
|
3151
3162
|
function renderArabicLatexFromSession(session) {
|
|
3152
3163
|
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
|
|
3153
3164
|
}
|
|
3165
|
+
function renderArabicPreviewLatexFromSession(session) {
|
|
3166
|
+
return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
|
|
3167
|
+
}
|
|
3154
3168
|
|
|
3155
3169
|
// src/editor/state.ts
|
|
3156
3170
|
function appendDebug(session, command, note) {
|
|
@@ -3500,6 +3514,11 @@ var MATRIX_ENV_CSS = `
|
|
|
3500
3514
|
transform-origin: center;
|
|
3501
3515
|
}
|
|
3502
3516
|
|
|
3517
|
+
.matrix-env--cases .matrix-env__wrapper:empty {
|
|
3518
|
+
min-width: 0;
|
|
3519
|
+
padding: 0;
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3503
3522
|
.matrix-env__grid {
|
|
3504
3523
|
display: inline-grid;
|
|
3505
3524
|
direction: ltr;
|
|
@@ -4016,8 +4035,9 @@ function commandIdForTex(tex) {
|
|
|
4016
4035
|
return null;
|
|
4017
4036
|
}
|
|
4018
4037
|
function operatorCommandIdForTex(tex) {
|
|
4038
|
+
const normalized = tex === "\\le" ? "\\leq" : tex === "\\ge" ? "\\geq" : tex;
|
|
4019
4039
|
for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
|
|
4020
|
-
if (spec.Tex ===
|
|
4040
|
+
if (spec.Tex === normalized) {
|
|
4021
4041
|
return spec.id;
|
|
4022
4042
|
}
|
|
4023
4043
|
}
|
|
@@ -4048,7 +4068,7 @@ function attachScripts(astNode, editorNode) {
|
|
|
4048
4068
|
}
|
|
4049
4069
|
var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
|
|
4050
4070
|
function isGridEnvName(value) {
|
|
4051
|
-
return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned";
|
|
4071
|
+
return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned" || value === "cases";
|
|
4052
4072
|
}
|
|
4053
4073
|
function isMatrixEnvName(value) {
|
|
4054
4074
|
return MATRIX_ENV_NAMES.has(value);
|
|
@@ -4095,6 +4115,9 @@ function envToEditorNode(node) {
|
|
|
4095
4115
|
return { editable: false, reason: `\u0625\u063A\u0644\u0627\u0642 \u0628\u064A\u0626\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.closing}` };
|
|
4096
4116
|
}
|
|
4097
4117
|
const rowCells = node.lines.map(splitEnvLine);
|
|
4118
|
+
if (parsed.envName === "cases" && (rowCells.length === 0 || rowCells.length > 12 || rowCells.some((row) => row.length !== 2))) {
|
|
4119
|
+
return { editable: false, reason: "\u0628\u064A\u0626\u0629 cases \u062A\u062A\u0637\u0644\u0628 \u062A\u0639\u0628\u064A\u0631\u0627 \u0648\u0634\u0631\u0637\u0627 \u0641\u064A \u0643\u0644 \u0635\u0641 (\u0639\u0645\u0648\u062F\u0627\u0646)" };
|
|
4120
|
+
}
|
|
4098
4121
|
const rows = Math.max(1, rowCells.length);
|
|
4099
4122
|
const columns = Math.max(1, ...rowCells.map((row) => row.length));
|
|
4100
4123
|
const env = createGridEnvNode(parsed.envName, rows, columns, parsed.alignments);
|
|
@@ -4177,14 +4200,19 @@ function wrappedAtomicCommandId(node) {
|
|
|
4177
4200
|
return commandIdForTex(`${node.name}{${child.expr}}`);
|
|
4178
4201
|
}
|
|
4179
4202
|
function editableWrapperCommand(node) {
|
|
4180
|
-
if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
|
|
4203
|
+
if (node.name !== "\\mathtt" && node.name !== "\\operatorname" && node.name !== "\\text" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
|
|
4204
|
+
return null;
|
|
4205
|
+
}
|
|
4206
|
+
if (node.name === "\\text" && node.sourceLatex && !node.sourceLatex.startsWith("\\text{")) {
|
|
4181
4207
|
return null;
|
|
4182
4208
|
}
|
|
4183
4209
|
const child = singleCommandChar(node);
|
|
4210
|
+
if (node.name === "\\text" && child?.sourceLatex && !node.sourceLatex) return null;
|
|
4184
4211
|
let editorNode;
|
|
4185
4212
|
if (child) {
|
|
4186
4213
|
const normalized = normalizeCharImportExpr(child.expr);
|
|
4187
4214
|
editorNode = createEditorNode("char", normalized.expr);
|
|
4215
|
+
if (child.sourceLatex) editorNode.sourceLatex = child.sourceLatex;
|
|
4188
4216
|
if (normalized.characterFont !== "default") {
|
|
4189
4217
|
editorNode.characterFont = normalized.characterFont;
|
|
4190
4218
|
}
|
|
@@ -4196,7 +4224,7 @@ function editableWrapperCommand(node) {
|
|
|
4196
4224
|
if (!nested?.editable) return null;
|
|
4197
4225
|
editorNode = nested.node;
|
|
4198
4226
|
}
|
|
4199
|
-
editorNode.wrapperCommand = node.name === "\\
|
|
4227
|
+
editorNode.wrapperCommand = node.name === "\\mathsf" ? "\\unit" : node.name;
|
|
4200
4228
|
const scripts = attachScripts(node, editorNode);
|
|
4201
4229
|
if (scripts) {
|
|
4202
4230
|
return scripts;
|
|
@@ -4330,6 +4358,7 @@ function commandToEditorNode(node) {
|
|
|
4330
4358
|
const operatorId = operatorCommandIdForTex(node.name);
|
|
4331
4359
|
if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
|
|
4332
4360
|
const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
|
|
4361
|
+
if (node.name === "\\le" || node.name === "\\ge") atomicOperator.sourceLatex = node.name;
|
|
4333
4362
|
const scripts = attachScripts(node, atomicOperator);
|
|
4334
4363
|
if (scripts) {
|
|
4335
4364
|
return scripts;
|
|
@@ -4497,8 +4526,8 @@ function mathTokenToEditorSession(math, side = "arabic") {
|
|
|
4497
4526
|
result.session.sync = buildInitialSyncMap(result.session.englishTree, result.session.arabicTree);
|
|
4498
4527
|
return result;
|
|
4499
4528
|
}
|
|
4500
|
-
function mathSourceFromSession(session, side, opening = "$", closing = "$") {
|
|
4501
|
-
const inner = side === "english" ? renderEnglishLatexFromSession(session) : renderArabicLatexFromSession(session);
|
|
4529
|
+
function mathSourceFromSession(session, side, opening = "$", closing = "$", presentation = false) {
|
|
4530
|
+
const inner = side === "english" ? renderEnglishLatexFromSession(session) : presentation ? renderArabicPreviewLatexFromSession(session) : renderArabicLatexFromSession(session);
|
|
4502
4531
|
if (opening === "$" || opening === "\\(") {
|
|
4503
4532
|
return opening + inner + closing;
|
|
4504
4533
|
}
|
|
@@ -4511,11 +4540,11 @@ ${closing}`;
|
|
|
4511
4540
|
${inner}
|
|
4512
4541
|
${closing}`;
|
|
4513
4542
|
}
|
|
4514
|
-
function mathTokenSourceForSide(token, side, digitForm) {
|
|
4543
|
+
function mathTokenSourceForSide(token, side, digitForm, presentation = false) {
|
|
4515
4544
|
if (!token.math || token.sourceOwner === "raw") {
|
|
4516
4545
|
return token.source;
|
|
4517
4546
|
}
|
|
4518
|
-
if (token.sourceSide === side && digitForm === void 0) {
|
|
4547
|
+
if (!presentation && token.sourceSide === side && digitForm === void 0) {
|
|
4519
4548
|
return token.source;
|
|
4520
4549
|
}
|
|
4521
4550
|
const result = mathTokenToEditorSession(token.math, side);
|
|
@@ -4523,12 +4552,12 @@ function mathTokenSourceForSide(token, side, digitForm) {
|
|
|
4523
4552
|
return token.source;
|
|
4524
4553
|
}
|
|
4525
4554
|
const session = digitForm === void 0 ? result.session : setCurrentDigitForm(result.session, digitForm);
|
|
4526
|
-
return mathSourceFromSession(session, side, token.opening, token.closing);
|
|
4555
|
+
return mathSourceFromSession(session, side, token.opening, token.closing, presentation);
|
|
4527
4556
|
}
|
|
4528
4557
|
|
|
4529
4558
|
// src/document/previewModel.ts
|
|
4530
4559
|
function mathTex(token, equationSide, digitForm) {
|
|
4531
|
-
return mathTokenSourceForSide(token, equationSide, digitForm);
|
|
4560
|
+
return mathTokenSourceForSide(token, equationSide, digitForm, true);
|
|
4532
4561
|
}
|
|
4533
4562
|
function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
|
|
4534
4563
|
return field.tokens.map((token) => {
|