@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/dist/react.d.mts CHANGED
@@ -3,7 +3,7 @@ import * as react from 'react';
3
3
  type EditorSide = 'english' | 'arabic';
4
4
  type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'boxed' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
5
5
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
6
- type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
6
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned' | 'cases';
7
7
  type EnvColumnAlignment = 'l' | 'c' | 'r';
8
8
  type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
9
9
  type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
@@ -19,10 +19,10 @@ type EditorNode = {
19
19
  kind: EditorNodeKind;
20
20
  expr: string;
21
21
  characterFont?: CharacterFontId;
22
- /** Minimal upstream source identity used only while the node remains unchanged. */
22
+ /** Canonical source identity; atomic Arabic-label edits preserve it, canonical-side edits invalidate it. */
23
23
  sourceLatex?: string;
24
24
  /** Existing editor node reused for wrapper commands that need editable content. */
25
- wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
25
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\operatorname' | '\\text' | '\\mathbf' | '\\boldarabic';
26
26
  superscript: EditorChain | null;
27
27
  subscript: EditorChain | null;
28
28
  leftDelimExpr: string;
@@ -1163,6 +1163,7 @@ type EditorRuntimeApi = {
1163
1163
  insertMatrixEnv: (style: MatrixEnvStyle, rows: number, columns: number) => void;
1164
1164
  insertArrayEnv: (rows: number, columns: number) => void;
1165
1165
  insertAlignedEnv: (rows: number, columns: number) => void;
1166
+ insertCasesEnv: (rows: number) => void;
1166
1167
  insertSqrt: () => void;
1167
1168
  insertOverset: () => void;
1168
1169
  insertUnderset: () => void;
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as react from 'react';
3
3
  type EditorSide = 'english' | 'arabic';
4
4
  type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'boxed' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
5
5
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
6
- type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
6
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned' | 'cases';
7
7
  type EnvColumnAlignment = 'l' | 'c' | 'r';
8
8
  type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
9
9
  type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
@@ -19,10 +19,10 @@ type EditorNode = {
19
19
  kind: EditorNodeKind;
20
20
  expr: string;
21
21
  characterFont?: CharacterFontId;
22
- /** Minimal upstream source identity used only while the node remains unchanged. */
22
+ /** Canonical source identity; atomic Arabic-label edits preserve it, canonical-side edits invalidate it. */
23
23
  sourceLatex?: string;
24
24
  /** Existing editor node reused for wrapper commands that need editable content. */
25
- wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
25
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\operatorname' | '\\text' | '\\mathbf' | '\\boldarabic';
26
26
  superscript: EditorChain | null;
27
27
  subscript: EditorChain | null;
28
28
  leftDelimExpr: string;
@@ -1163,6 +1163,7 @@ type EditorRuntimeApi = {
1163
1163
  insertMatrixEnv: (style: MatrixEnvStyle, rows: number, columns: number) => void;
1164
1164
  insertArrayEnv: (rows: number, columns: number) => void;
1165
1165
  insertAlignedEnv: (rows: number, columns: number) => void;
1166
+ insertCasesEnv: (rows: number) => void;
1166
1167
  insertSqrt: () => void;
1167
1168
  insertOverset: () => void;
1168
1169
  insertUnderset: () => void;
package/dist/react.js CHANGED
@@ -114,7 +114,7 @@ function createAccentNode(accentId) {
114
114
  }
115
115
  function createGridEnvNode(envName, rows, columns, columnAlignments) {
116
116
  const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
117
- const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns)));
117
+ const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
118
118
  const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
119
119
  const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
120
120
  return {
@@ -1666,6 +1666,9 @@ function renderMatrixRowsArabic(node, options) {
1666
1666
  const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
1667
1667
  return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
1668
1668
  }
1669
+ if (envName === "cases" && options?.casesPresentation) {
1670
+ return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
1671
+ }
1669
1672
  return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
1670
1673
  }
1671
1674
  function renderAccentEnglish(command, accent, base, options) {
@@ -1687,6 +1690,10 @@ function renderAccentArabic(command, accent, base, options) {
1687
1690
  function escapeText(s) {
1688
1691
  return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
1689
1692
  }
1693
+ function escapeAtomicLiteral(text) {
1694
+ const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
1695
+ return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
1696
+ }
1690
1697
  function renderCharContent(node, options) {
1691
1698
  const expr = formatDigits(node.expr, selectedDigitForm(options));
1692
1699
  const font = node.characterFont ?? "default";
@@ -1733,7 +1740,7 @@ function renderNodeEnglish(node, options) {
1733
1740
  return `${body}${latinScripts(node, options)}`;
1734
1741
  }
1735
1742
  if (node.kind === "atomicOperatorCommand") {
1736
- const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
1743
+ const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
1737
1744
  return `${body}${latinScripts(node, options)}`;
1738
1745
  }
1739
1746
  if (node.kind === "standardCommand") {
@@ -1750,7 +1757,8 @@ function renderNodeEnglish(node, options) {
1750
1757
  if (node.wrapperCommand) {
1751
1758
  const expr = formatDigits(node.expr, selectedDigitForm(options));
1752
1759
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
1753
- return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
1760
+ const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
1761
+ return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
1754
1762
  }
1755
1763
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
1756
1764
  }
@@ -1811,7 +1819,8 @@ function renderNodeArabic(node, options) {
1811
1819
  const content = renderCharContent(node, options);
1812
1820
  if (node.wrapperCommand) {
1813
1821
  const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
1814
- return arabicScripts(node, `${wrapper}{${content}}`, options);
1822
+ const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
1823
+ return arabicScripts(node, `${wrapper}{${literal}}`, options);
1815
1824
  }
1816
1825
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
1817
1826
  }
@@ -1840,6 +1849,9 @@ function renderEnglishLatexFromSession(session) {
1840
1849
  function renderArabicLatexFromSession(session) {
1841
1850
  return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
1842
1851
  }
1852
+ function renderArabicPreviewLatexFromSession(session) {
1853
+ return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
1854
+ }
1843
1855
 
1844
1856
  // src/editor/caretOrder.ts
1845
1857
  function collectCaretPositions(chain) {
@@ -2165,6 +2177,9 @@ function findNodeById(root, nodeId) {
2165
2177
  function activeTreeKey(side) {
2166
2178
  return side === "english" ? "englishTree" : "arabicTree";
2167
2179
  }
2180
+ function passiveTreeKey(side) {
2181
+ return side === "english" ? "arabicTree" : "englishTree";
2182
+ }
2168
2183
 
2169
2184
  // src/editor/selection.ts
2170
2185
  function nodeChildChains(node) {
@@ -2793,6 +2808,7 @@ var EQUATION_EDITOR_MESSAGES = {
2793
2808
  matrix: "\u0645\u0635\u0641\u0648\u0641\u0629",
2794
2809
  array: "\u062C\u062F\u0648\u0644",
2795
2810
  aligned: "\u0645\u062D\u0627\u0630\u0627\u0629",
2811
+ piecewise: "\u062F\u0627\u0644\u0629 \u0645\u062A\u0639\u062F\u062F\u0629 \u0627\u0644\u062A\u0639\u0631\u064A\u0641",
2796
2812
  matrixType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629",
2797
2813
  chooseEnvironmentSize: "\u0627\u062E\u062A\u064A\u0627\u0631 \u062D\u062C\u0645 \u0627\u0644\u0628\u064A\u0626\u0629",
2798
2814
  rows: "\u0635\u0641\u0648\u0641",
@@ -2920,6 +2936,7 @@ var EQUATION_EDITOR_MESSAGES = {
2920
2936
  matrix: "Matrix",
2921
2937
  array: "Array",
2922
2938
  aligned: "Aligned",
2939
+ piecewise: "Piecewise (cases)",
2923
2940
  matrixType: "Matrix type",
2924
2941
  chooseEnvironmentSize: "Choose environment size",
2925
2942
  rows: "Rows",
@@ -3053,6 +3070,9 @@ function markExprSync(session, nodeId) {
3053
3070
  function clearSourceIdentity(session, nodeId) {
3054
3071
  const english = findNodeById(session.englishTree, nodeId);
3055
3072
  const arabic = findNodeById(session.arabicTree, nodeId);
3073
+ if (session.activeSide === "arabic" && english?.node.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(english.node.wrapperCommand ?? "") && english.node.sourceLatex) {
3074
+ return;
3075
+ }
3056
3076
  if (english) {
3057
3077
  delete english.node.sourceLatex;
3058
3078
  }
@@ -4053,6 +4073,9 @@ function insertArrayEnv(session, rows, columns, columnAlignments) {
4053
4073
  function insertAlignedEnv(session, rows, columns) {
4054
4074
  return insertGridEnv(session, "aligned", rows, columns);
4055
4075
  }
4076
+ function insertCasesEnv(session, rows) {
4077
+ return insertGridEnv(session, "cases", rows, 2);
4078
+ }
4056
4079
  function insertGridEnv(session, envName, rows, columns, columnAlignments) {
4057
4080
  const base = replaceSelectionFirst(session);
4058
4081
  const next = cloneEditorSession(base);
@@ -4073,7 +4096,7 @@ function insertGridEnv(session, envName, rows, columns, columnAlignments) {
4073
4096
  function setMatrixEnvStyle(session, style) {
4074
4097
  const next = cloneEditorSession(session);
4075
4098
  const pair = findSelectedMatrixPair(next);
4076
- if (!pair) {
4099
+ if (!pair || pair.english.envName === "cases") {
4077
4100
  return session;
4078
4101
  }
4079
4102
  pair.english.envName = style;
@@ -4137,7 +4160,7 @@ function removeMatrixRow(session) {
4137
4160
  function addMatrixColumn(session) {
4138
4161
  const next = cloneEditorSession(session);
4139
4162
  const pair = findSelectedMatrixPair(next);
4140
- if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
4163
+ if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
4141
4164
  return session;
4142
4165
  }
4143
4166
  const columnCount = pair.english.matrixRows[0]?.length ?? 0;
@@ -4159,7 +4182,7 @@ function addMatrixColumn(session) {
4159
4182
  function removeMatrixColumn(session) {
4160
4183
  const next = cloneEditorSession(session);
4161
4184
  const pair = findSelectedMatrixPair(next);
4162
- if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
4185
+ if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
4163
4186
  return session;
4164
4187
  }
4165
4188
  const columnCount = pair.english.matrixRows[0]?.length ?? 0;
@@ -4376,6 +4399,24 @@ function deleteForward(session) {
4376
4399
  appendDebug(next, "deleteForward", "removed node");
4377
4400
  return next;
4378
4401
  }
4402
+ function setExpr(session, nodeId, expr) {
4403
+ const next = cloneEditorSession(session);
4404
+ const activeKey = activeTreeKey(next.activeSide);
4405
+ const passiveKey = passiveTreeKey(next.activeSide);
4406
+ const activeNode = findNodeById(next[activeKey], nodeId);
4407
+ const passiveNode = findNodeById(next[passiveKey], nodeId);
4408
+ if (!activeNode || !passiveNode) {
4409
+ return session;
4410
+ }
4411
+ activeNode.node.expr = expr;
4412
+ if (["\\mathtt", "\\operatorname", "\\text"].includes(activeNode.node.wrapperCommand ?? "")) {
4413
+ passiveNode.node.expr = expr;
4414
+ }
4415
+ clearSourceIdentity(next, nodeId);
4416
+ markExprSync(next, nodeId);
4417
+ appendDebug(next, "setExpr", nodeId);
4418
+ return next;
4419
+ }
4379
4420
  function createStarterSession() {
4380
4421
  const englishRoot = createEditorChain([createEditorNode("char", "x")]);
4381
4422
  const arabicRoot = createEditorChain([createEditorNode("char", "\u0633")]);
@@ -4459,6 +4500,14 @@ function pasteText(session, text) {
4459
4500
  if (!text) {
4460
4501
  return session;
4461
4502
  }
4503
+ const selection = session.selection;
4504
+ if (selection && Math.abs(selection.anchorIndex - selection.focusIndex) === 1) {
4505
+ const selectedChain = findChainById(session[activeTreeKey(session.activeSide)], selection.chainId);
4506
+ const selected = selectedChain?.chain.nodes[Math.min(selection.anchorIndex, selection.focusIndex)];
4507
+ if (selected?.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(selected.wrapperCommand ?? "")) {
4508
+ return setExpr(session, selected.id, text);
4509
+ }
4510
+ }
4462
4511
  let s = session;
4463
4512
  let i = 0;
4464
4513
  while (i < text.length) {
@@ -4518,6 +4567,8 @@ function buildBaseNodeBody(node, digitForm = "western", side = "english") {
4518
4567
  if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
4519
4568
  value.classList.add("node-value--bold");
4520
4569
  }
4570
+ if (node.wrapperCommand === "\\text") value.dir = "auto";
4571
+ if (node.wrapperCommand === "\\operatorname") value.classList.add("node-value--operator-name");
4521
4572
  if (node.wrapperCommand === "\\unit") {
4522
4573
  value.classList.add("node-value--unit");
4523
4574
  value.title = "\u0648\u062D\u062F\u0629 (unit)";
@@ -5024,6 +5075,11 @@ var MATRIX_ENV_CSS = `
5024
5075
  transform-origin: center;
5025
5076
  }
5026
5077
 
5078
+ .matrix-env--cases .matrix-env__wrapper:empty {
5079
+ min-width: 0;
5080
+ padding: 0;
5081
+ }
5082
+
5027
5083
  .matrix-env__grid {
5028
5084
  display: inline-grid;
5029
5085
  direction: ltr;
@@ -5068,9 +5124,10 @@ function applyMatrixDelimiterScale(wrap, grid) {
5068
5124
  }
5069
5125
  function buildMatrixEnvNodeBody(node, buildChain, side) {
5070
5126
  const wrap = document.createElement("span");
5071
- wrap.className = `matrix-env matrix-env--${side}`;
5127
+ wrap.className = `matrix-env matrix-env--${side}${node.envName === "cases" ? " matrix-env--cases" : ""}`;
5128
+ if (node.envName === "cases") wrap.dir = "ltr";
5072
5129
  const style = node.envName ?? node.matrixStyle ?? "matrix";
5073
- const glyphs = style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
5130
+ const glyphs = style === "cases" ? side === "arabic" ? { left: "", right: "}" } : { left: "{", right: "" } : style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
5074
5131
  const left = document.createElement("span");
5075
5132
  left.className = "matrix-env__wrapper matrix-env__wrapper--left";
5076
5133
  left.textContent = glyphs?.left ?? "";
@@ -6520,6 +6577,10 @@ function createEditorRuntime(options) {
6520
6577
  applyStructural((prev) => insertAlignedEnv(prev, rows, columns));
6521
6578
  focusInput();
6522
6579
  },
6580
+ insertCasesEnv: (rows) => {
6581
+ applyStructural((prev) => insertCasesEnv(prev, rows));
6582
+ focusInput();
6583
+ },
6523
6584
  insertSqrt: () => {
6524
6585
  applyStructural((prev) => insertSqrt(prev));
6525
6586
  focusInput();
@@ -8640,7 +8701,9 @@ ${this.closing}` + this.latexScripts();
8640
8701
  }
8641
8702
  const formattedLines = this.lines.map((line) => ` ${line.arabicLatex()}`);
8642
8703
  const content = formattedLines.join(" \\\\\n");
8643
- const fullContent = `${this.opening}
8704
+ const fullContent = this.opening === "\\begin{cases}" && this.closing === "\\end{cases}" ? `\\left.\\begin{array}{rl}
8705
+ ${content}
8706
+ \\end{array}\\right\\}` : `${this.opening}
8644
8707
  ${content}
8645
8708
  ${this.closing}`;
8646
8709
  return this.arabicLatexScripts(sup, sub, fullContent);
@@ -8921,11 +8984,17 @@ var COMMAND_FONT_MAP = Object.fromEntries([
8921
8984
  var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
8922
8985
  NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
8923
8986
  );
8987
+ function hasBareBoldCharSource(node) {
8988
+ return node.kind === "char" && (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") && typeof node.sourceLatex === "string" && node.sourceLatex.length > 0 && !node.sourceLatex.startsWith("\\mathbf{");
8989
+ }
8924
8990
  function charEditorNodeToAstNode(node) {
8925
8991
  const font = node.characterFont ?? "default";
8926
8992
  const charNode = new CharNode(node.expr);
8927
8993
  if (node.wrapperCommand) {
8928
8994
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
8995
+ if (hasBareBoldCharSource(node)) {
8996
+ charNode.sourceLatex = node.sourceLatex;
8997
+ }
8929
8998
  return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
8930
8999
  }
8931
9000
  if (font === "default") {
@@ -8943,8 +9012,9 @@ function commandIdForTex(tex) {
8943
9012
  return null;
8944
9013
  }
8945
9014
  function operatorCommandIdForTex(tex) {
9015
+ const normalized = tex === "\\le" ? "\\leq" : tex === "\\ge" ? "\\geq" : tex;
8946
9016
  for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
8947
- if (spec.Tex === tex) {
9017
+ if (spec.Tex === normalized) {
8948
9018
  return spec.id;
8949
9019
  }
8950
9020
  }
@@ -8975,7 +9045,7 @@ function attachScripts(astNode, editorNode) {
8975
9045
  }
8976
9046
  var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
8977
9047
  function isGridEnvName(value) {
8978
- return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned";
9048
+ return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned" || value === "cases";
8979
9049
  }
8980
9050
  function isMatrixEnvName(value) {
8981
9051
  return MATRIX_ENV_NAMES.has(value);
@@ -9022,6 +9092,9 @@ function envToEditorNode(node) {
9022
9092
  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}` };
9023
9093
  }
9024
9094
  const rowCells = node.lines.map(splitEnvLine);
9095
+ if (parsed.envName === "cases" && (rowCells.length === 0 || rowCells.length > 12 || rowCells.some((row) => row.length !== 2))) {
9096
+ 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)" };
9097
+ }
9025
9098
  const rows = Math.max(1, rowCells.length);
9026
9099
  const columns = Math.max(1, ...rowCells.map((row) => row.length));
9027
9100
  const env = createGridEnvNode(parsed.envName, rows, columns, parsed.alignments);
@@ -9104,14 +9177,19 @@ function wrappedAtomicCommandId(node) {
9104
9177
  return commandIdForTex(`${node.name}{${child.expr}}`);
9105
9178
  }
9106
9179
  function editableWrapperCommand(node) {
9107
- if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
9180
+ if (node.name !== "\\mathtt" && node.name !== "\\operatorname" && node.name !== "\\text" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
9181
+ return null;
9182
+ }
9183
+ if (node.name === "\\text" && node.sourceLatex && !node.sourceLatex.startsWith("\\text{")) {
9108
9184
  return null;
9109
9185
  }
9110
9186
  const child = singleCommandChar(node);
9187
+ if (node.name === "\\text" && child?.sourceLatex && !node.sourceLatex) return null;
9111
9188
  let editorNode;
9112
9189
  if (child) {
9113
9190
  const normalized = normalizeCharImportExpr(child.expr);
9114
9191
  editorNode = createEditorNode("char", normalized.expr);
9192
+ if (child.sourceLatex) editorNode.sourceLatex = child.sourceLatex;
9115
9193
  if (normalized.characterFont !== "default") {
9116
9194
  editorNode.characterFont = normalized.characterFont;
9117
9195
  }
@@ -9123,7 +9201,7 @@ function editableWrapperCommand(node) {
9123
9201
  if (!nested?.editable) return null;
9124
9202
  editorNode = nested.node;
9125
9203
  }
9126
- editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
9204
+ editorNode.wrapperCommand = node.name === "\\mathsf" ? "\\unit" : node.name;
9127
9205
  const scripts = attachScripts(node, editorNode);
9128
9206
  if (scripts) {
9129
9207
  return scripts;
@@ -9257,6 +9335,7 @@ function commandToEditorNode(node) {
9257
9335
  const operatorId = operatorCommandIdForTex(node.name);
9258
9336
  if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
9259
9337
  const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
9338
+ if (node.name === "\\le" || node.name === "\\ge") atomicOperator.sourceLatex = node.name;
9260
9339
  const scripts = attachScripts(node, atomicOperator);
9261
9340
  if (scripts) {
9262
9341
  return scripts;
@@ -9568,7 +9647,7 @@ function editorNodeToAstNode(node) {
9568
9647
  if (!tex) {
9569
9648
  return { ok: false, reason: `\u0631\u0645\u0632 \u0631\u064A\u0627\u0636\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
9570
9649
  }
9571
- astNode = new CommandNode(tex);
9650
+ astNode = new CommandNode(node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : tex);
9572
9651
  } else if (node.kind === "standardCommand") {
9573
9652
  if (!isStandardCommandTex(node.expr)) {
9574
9653
  return { ok: false, reason: `\u0623\u0645\u0631 \u0631\u064A\u0627\u0636\u064A \u0642\u064A\u0627\u0633\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645 \u062D\u0627\u0644\u064A\u0627: ${node.expr}` };
@@ -9579,7 +9658,7 @@ function editorNodeToAstNode(node) {
9579
9658
  } else {
9580
9659
  return { ok: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.kind}` };
9581
9660
  }
9582
- if (node.sourceLatex) {
9661
+ if (node.sourceLatex && !hasBareBoldCharSource(node)) {
9583
9662
  astNode.sourceLatex = node.sourceLatex;
9584
9663
  }
9585
9664
  const scripts = attachAstScripts(node, astNode);
@@ -9927,7 +10006,7 @@ function EquationMobileToolbar({
9927
10006
  if (kind === "rows") {
9928
10007
  setMatrixRows(next);
9929
10008
  } else {
9930
- setMatrixColumns(envMode === "aligned" ? 2 : next);
10009
+ setMatrixColumns(envMode === "aligned" || envMode === "cases" ? 2 : next);
9931
10010
  }
9932
10011
  }
9933
10012
  function insertEnvironment() {
@@ -9936,6 +10015,8 @@ function EquationMobileToolbar({
9936
10015
  runtime.insertArrayEnv(matrixRows, matrixColumns);
9937
10016
  } else if (envMode === "aligned") {
9938
10017
  runtime.insertAlignedEnv(matrixRows, 2);
10018
+ } else if (envMode === "cases") {
10019
+ runtime.insertCasesEnv(matrixRows);
9939
10020
  } else {
9940
10021
  runtime.insertMatrixEnv(matrixStyle, matrixRows, matrixColumns);
9941
10022
  }
@@ -10103,7 +10184,8 @@ function EquationMobileToolbar({
10103
10184
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "butex-widget__sheet-choice-row", role: "group", "aria-label": messages.environmentType, children: [
10104
10185
  { id: "matrix", label: messages.matrix },
10105
10186
  { id: "array", label: messages.array },
10106
- { id: "aligned", label: messages.aligned }
10187
+ { id: "aligned", label: messages.aligned },
10188
+ { id: "cases", label: messages.piecewise }
10107
10189
  ].map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
10108
10190
  "button",
10109
10191
  {
@@ -10111,7 +10193,7 @@ function EquationMobileToolbar({
10111
10193
  "aria-pressed": envMode === option.id,
10112
10194
  onClick: () => {
10113
10195
  setEnvMode(option.id);
10114
- if (option.id === "aligned") setMatrixColumns(2);
10196
+ if (option.id === "aligned" || option.id === "cases") setMatrixColumns(2);
10115
10197
  },
10116
10198
  children: option.label
10117
10199
  },
@@ -10120,19 +10202,19 @@ function EquationMobileToolbar({
10120
10202
  envMode === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "butex-widget__sheet-choice-row", role: "group", "aria-label": messages.matrixType, children: MATRIX_STYLES.map((style) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", title: matrixStyleTitle(style.id, messages), "aria-label": matrixStyleTitle(style.id, messages), "aria-pressed": matrixStyle === style.id, onClick: () => setMatrixStyle(style.id), children: style.label }, style.id)) }) : null,
10121
10203
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "butex-widget__sheet-section", children: [
10122
10204
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: messages.commonMatrixSizes }),
10123
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "butex-widget__matrix-presets", children: (envMode === "aligned" ? MATRIX_PRESETS.filter((preset) => preset.columns === 2) : MATRIX_PRESETS).map((preset) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
10205
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "butex-widget__matrix-presets", children: (envMode === "aligned" || envMode === "cases" ? MATRIX_PRESETS.filter((preset) => preset.columns === 2) : MATRIX_PRESETS).map((preset) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
10124
10206
  "button",
10125
10207
  {
10126
10208
  type: "button",
10127
10209
  "aria-pressed": matrixRows === preset.rows && matrixColumns === preset.columns,
10128
10210
  onClick: () => {
10129
10211
  setMatrixRows(preset.rows);
10130
- setMatrixColumns(envMode === "aligned" ? 2 : preset.columns);
10212
+ setMatrixColumns(envMode === "aligned" || envMode === "cases" ? 2 : preset.columns);
10131
10213
  },
10132
10214
  children: [
10133
10215
  preset.rows,
10134
10216
  "\xD7",
10135
- envMode === "aligned" ? 2 : preset.columns
10217
+ envMode === "aligned" || envMode === "cases" ? 2 : preset.columns
10136
10218
  ]
10137
10219
  },
10138
10220
  `${String(preset.rows)}-${String(preset.columns)}`
@@ -10149,12 +10231,12 @@ function EquationMobileToolbar({
10149
10231
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "butex-widget__matrix-stepper-row", children: [
10150
10232
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: messages.columns }),
10151
10233
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "butex-widget__matrix-stepper", children: [
10152
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: matrixColumns <= 1 || envMode === "aligned", "aria-label": messages.decreaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns - 1), children: "\u2212" }),
10153
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { "aria-live": "polite", children: envMode === "aligned" ? 2 : matrixColumns }),
10154
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: matrixColumns >= 12 || envMode === "aligned", "aria-label": messages.increaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns + 1), children: "+" })
10234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: matrixColumns <= 1 || envMode === "aligned" || envMode === "cases", "aria-label": messages.decreaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns - 1), children: "\u2212" }),
10235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("output", { "aria-live": "polite", children: envMode === "aligned" || envMode === "cases" ? 2 : matrixColumns }),
10236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: matrixColumns >= 12 || envMode === "aligned" || envMode === "cases", "aria-label": messages.increaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns + 1), children: "+" })
10155
10237
  ] })
10156
10238
  ] }),
10157
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "butex-widget__matrix-size-summary", "aria-live": "polite", children: matrixSizeLabel(matrixRows, envMode === "aligned" ? 2 : matrixColumns, messages) }),
10239
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "butex-widget__matrix-size-summary", "aria-live": "polite", children: matrixSizeLabel(matrixRows, envMode === "aligned" || envMode === "cases" ? 2 : matrixColumns, messages) }),
10158
10240
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "butex-widget__matrix-insert", onClick: insertEnvironment, children: messages.insert }),
10159
10241
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "butex-widget__sheet-section", children: [
10160
10242
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: messages.editSelectedEnvironment }),
@@ -10175,11 +10257,11 @@ function EquationMobileToolbar({
10175
10257
  "\u2212",
10176
10258
  messages.row
10177
10259
  ] }),
10178
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", onClick: () => getRuntime()?.addMatrixColumn(), children: [
10260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", disabled: envMode === "cases", onClick: () => getRuntime()?.addMatrixColumn(), children: [
10179
10261
  "+",
10180
10262
  messages.column
10181
10263
  ] }),
10182
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", onClick: () => getRuntime()?.removeMatrixColumn(), children: [
10264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", disabled: envMode === "cases", onClick: () => getRuntime()?.removeMatrixColumn(), children: [
10183
10265
  "\u2212",
10184
10266
  messages.column
10185
10267
  ] })
@@ -10710,7 +10792,7 @@ var ButexEditor = (0, import_react4.forwardRef)(
10710
10792
  const debugLogEl = debugLogRef.current;
10711
10793
  const english = renderEnglishLatexFromSession(session);
10712
10794
  const arabic = renderArabicLatexFromSession(session);
10713
- const activeLatex = session.activeSide === "arabic" ? arabic : english;
10795
+ const activeLatex = session.activeSide === "arabic" ? renderArabicPreviewLatexFromSession(session) : english;
10714
10796
  if (debugRef.current && latexLinesEl) {
10715
10797
  const currentMessages = equationEditorMessages(uiLocaleRef.current);
10716
10798
  latexLinesEl.textContent = `${currentMessages.englishLatex}:
@@ -10910,6 +10992,8 @@ ${arabic || currentMessages.empty}`;
10910
10992
  runtimeRef.current?.insertArrayEnv(rows, columns);
10911
10993
  } else if (envPaletteMode === "aligned") {
10912
10994
  runtimeRef.current?.insertAlignedEnv(rows, columns);
10995
+ } else if (envPaletteMode === "cases") {
10996
+ runtimeRef.current?.insertCasesEnv(rows);
10913
10997
  } else {
10914
10998
  runtimeRef.current?.insertMatrixEnv(matrixStyle, rows, columns);
10915
10999
  }
@@ -11205,7 +11289,8 @@ ${arabic || currentMessages.empty}`;
11205
11289
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.environmentType, children: [
11206
11290
  { id: "matrix", label: messages.matrix },
11207
11291
  { id: "array", label: messages.array },
11208
- { id: "aligned", label: messages.aligned }
11292
+ { id: "aligned", label: messages.aligned },
11293
+ { id: "cases", label: messages.piecewise }
11209
11294
  ].map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
11210
11295
  "button",
11211
11296
  {
@@ -11216,7 +11301,7 @@ ${arabic || currentMessages.empty}`;
11216
11301
  onMouseDown: (event) => event.preventDefault(),
11217
11302
  onClick: () => {
11218
11303
  setEnvPaletteMode(option.id);
11219
- if (option.id === "aligned") {
11304
+ if (option.id === "aligned" || option.id === "cases") {
11220
11305
  setMatrixColumns(2);
11221
11306
  }
11222
11307
  },
@@ -11241,7 +11326,7 @@ ${arabic || currentMessages.empty}`;
11241
11326
  style.id
11242
11327
  )) }) : null,
11243
11328
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "matrix-size-readout", children: matrixHover ? matrixSizeLabel2(matrixHover.rows, matrixHover.columns, messages) : matrixSizeLabel2(matrixRows, matrixColumns, messages) }),
11244
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
11329
+ envPaletteMode !== "cases" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
11245
11330
  { length: 8 },
11246
11331
  (_, rowIndex) => Array.from({ length: 8 }, (_2, columnIndex) => {
11247
11332
  const rows = rowIndex + 1;
@@ -11269,7 +11354,7 @@ ${arabic || currentMessages.empty}`;
11269
11354
  `${rows}-${columns}`
11270
11355
  );
11271
11356
  })
11272
- ) }),
11357
+ ) }) : null,
11273
11358
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "matrix-custom-size", children: [
11274
11359
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
11275
11360
  messages.row,
@@ -11292,7 +11377,8 @@ ${arabic || currentMessages.empty}`;
11292
11377
  type: "number",
11293
11378
  min: 1,
11294
11379
  max: 12,
11295
- value: matrixColumns,
11380
+ value: envPaletteMode === "cases" || envPaletteMode === "aligned" ? 2 : matrixColumns,
11381
+ disabled: envPaletteMode === "cases" || envPaletteMode === "aligned",
11296
11382
  onChange: (event) => setMatrixColumns(clampMatrixSize2(Number(event.currentTarget.value) || 1))
11297
11383
  }
11298
11384
  )
@@ -11305,7 +11391,7 @@ ${arabic || currentMessages.empty}`;
11305
11391
  onMouseDown: (event) => event.preventDefault(),
11306
11392
  onClick: () => {
11307
11393
  const rows = clampMatrixSize2(matrixRows);
11308
- const columns = clampMatrixSize2(matrixColumns);
11394
+ const columns = envPaletteMode === "cases" || envPaletteMode === "aligned" ? 2 : clampMatrixSize2(matrixColumns);
11309
11395
  insertSelectedEnvironment(rows, columns);
11310
11396
  setMatrixMenuOpen(false);
11311
11397
  setMatrixHover(null);
@@ -11351,11 +11437,11 @@ ${arabic || currentMessages.empty}`;
11351
11437
  "-",
11352
11438
  messages.row
11353
11439
  ] }),
11354
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", title: messages.addColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
11440
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", title: messages.addColumn, disabled: envPaletteMode === "cases", onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
11355
11441
  "+",
11356
11442
  messages.column
11357
11443
  ] }),
11358
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", title: messages.removeColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
11444
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", title: messages.removeColumn, disabled: envPaletteMode === "cases", onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
11359
11445
  "-",
11360
11446
  messages.column
11361
11447
  ] })