@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.mjs CHANGED
@@ -96,7 +96,7 @@ function createAccentNode(accentId) {
96
96
  }
97
97
  function createGridEnvNode(envName, rows, columns, columnAlignments) {
98
98
  const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
99
- const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns)));
99
+ const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns)));
100
100
  const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
101
101
  const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
102
102
  return {
@@ -1648,6 +1648,9 @@ function renderMatrixRowsArabic(node, options) {
1648
1648
  const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
1649
1649
  return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
1650
1650
  }
1651
+ if (envName === "cases" && options?.casesPresentation) {
1652
+ return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
1653
+ }
1651
1654
  return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
1652
1655
  }
1653
1656
  function renderAccentEnglish(command, accent, base, options) {
@@ -1669,6 +1672,10 @@ function renderAccentArabic(command, accent, base, options) {
1669
1672
  function escapeText(s) {
1670
1673
  return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
1671
1674
  }
1675
+ function escapeAtomicLiteral(text) {
1676
+ const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
1677
+ return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
1678
+ }
1672
1679
  function renderCharContent(node, options) {
1673
1680
  const expr = formatDigits(node.expr, selectedDigitForm(options));
1674
1681
  const font = node.characterFont ?? "default";
@@ -1715,7 +1722,7 @@ function renderNodeEnglish(node, options) {
1715
1722
  return `${body}${latinScripts(node, options)}`;
1716
1723
  }
1717
1724
  if (node.kind === "atomicOperatorCommand") {
1718
- const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
1725
+ const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
1719
1726
  return `${body}${latinScripts(node, options)}`;
1720
1727
  }
1721
1728
  if (node.kind === "standardCommand") {
@@ -1732,7 +1739,8 @@ function renderNodeEnglish(node, options) {
1732
1739
  if (node.wrapperCommand) {
1733
1740
  const expr = formatDigits(node.expr, selectedDigitForm(options));
1734
1741
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
1735
- return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
1742
+ const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
1743
+ return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
1736
1744
  }
1737
1745
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
1738
1746
  }
@@ -1793,7 +1801,8 @@ function renderNodeArabic(node, options) {
1793
1801
  const content = renderCharContent(node, options);
1794
1802
  if (node.wrapperCommand) {
1795
1803
  const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
1796
- return arabicScripts(node, `${wrapper}{${content}}`, options);
1804
+ const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
1805
+ return arabicScripts(node, `${wrapper}{${literal}}`, options);
1797
1806
  }
1798
1807
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
1799
1808
  }
@@ -1822,6 +1831,9 @@ function renderEnglishLatexFromSession(session) {
1822
1831
  function renderArabicLatexFromSession(session) {
1823
1832
  return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
1824
1833
  }
1834
+ function renderArabicPreviewLatexFromSession(session) {
1835
+ return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
1836
+ }
1825
1837
 
1826
1838
  // src/editor/caretOrder.ts
1827
1839
  function collectCaretPositions(chain) {
@@ -2147,6 +2159,9 @@ function findNodeById(root, nodeId) {
2147
2159
  function activeTreeKey(side) {
2148
2160
  return side === "english" ? "englishTree" : "arabicTree";
2149
2161
  }
2162
+ function passiveTreeKey(side) {
2163
+ return side === "english" ? "arabicTree" : "englishTree";
2164
+ }
2150
2165
 
2151
2166
  // src/editor/selection.ts
2152
2167
  function nodeChildChains(node) {
@@ -2775,6 +2790,7 @@ var EQUATION_EDITOR_MESSAGES = {
2775
2790
  matrix: "\u0645\u0635\u0641\u0648\u0641\u0629",
2776
2791
  array: "\u062C\u062F\u0648\u0644",
2777
2792
  aligned: "\u0645\u062D\u0627\u0630\u0627\u0629",
2793
+ piecewise: "\u062F\u0627\u0644\u0629 \u0645\u062A\u0639\u062F\u062F\u0629 \u0627\u0644\u062A\u0639\u0631\u064A\u0641",
2778
2794
  matrixType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0635\u0641\u0648\u0641\u0629",
2779
2795
  chooseEnvironmentSize: "\u0627\u062E\u062A\u064A\u0627\u0631 \u062D\u062C\u0645 \u0627\u0644\u0628\u064A\u0626\u0629",
2780
2796
  rows: "\u0635\u0641\u0648\u0641",
@@ -2902,6 +2918,7 @@ var EQUATION_EDITOR_MESSAGES = {
2902
2918
  matrix: "Matrix",
2903
2919
  array: "Array",
2904
2920
  aligned: "Aligned",
2921
+ piecewise: "Piecewise (cases)",
2905
2922
  matrixType: "Matrix type",
2906
2923
  chooseEnvironmentSize: "Choose environment size",
2907
2924
  rows: "Rows",
@@ -3035,6 +3052,9 @@ function markExprSync(session, nodeId) {
3035
3052
  function clearSourceIdentity(session, nodeId) {
3036
3053
  const english = findNodeById(session.englishTree, nodeId);
3037
3054
  const arabic = findNodeById(session.arabicTree, nodeId);
3055
+ if (session.activeSide === "arabic" && english?.node.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(english.node.wrapperCommand ?? "") && english.node.sourceLatex) {
3056
+ return;
3057
+ }
3038
3058
  if (english) {
3039
3059
  delete english.node.sourceLatex;
3040
3060
  }
@@ -4035,6 +4055,9 @@ function insertArrayEnv(session, rows, columns, columnAlignments) {
4035
4055
  function insertAlignedEnv(session, rows, columns) {
4036
4056
  return insertGridEnv(session, "aligned", rows, columns);
4037
4057
  }
4058
+ function insertCasesEnv(session, rows) {
4059
+ return insertGridEnv(session, "cases", rows, 2);
4060
+ }
4038
4061
  function insertGridEnv(session, envName, rows, columns, columnAlignments) {
4039
4062
  const base = replaceSelectionFirst(session);
4040
4063
  const next = cloneEditorSession(base);
@@ -4055,7 +4078,7 @@ function insertGridEnv(session, envName, rows, columns, columnAlignments) {
4055
4078
  function setMatrixEnvStyle(session, style) {
4056
4079
  const next = cloneEditorSession(session);
4057
4080
  const pair = findSelectedMatrixPair(next);
4058
- if (!pair) {
4081
+ if (!pair || pair.english.envName === "cases") {
4059
4082
  return session;
4060
4083
  }
4061
4084
  pair.english.envName = style;
@@ -4119,7 +4142,7 @@ function removeMatrixRow(session) {
4119
4142
  function addMatrixColumn(session) {
4120
4143
  const next = cloneEditorSession(session);
4121
4144
  const pair = findSelectedMatrixPair(next);
4122
- if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
4145
+ if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
4123
4146
  return session;
4124
4147
  }
4125
4148
  const columnCount = pair.english.matrixRows[0]?.length ?? 0;
@@ -4141,7 +4164,7 @@ function addMatrixColumn(session) {
4141
4164
  function removeMatrixColumn(session) {
4142
4165
  const next = cloneEditorSession(session);
4143
4166
  const pair = findSelectedMatrixPair(next);
4144
- if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows) {
4167
+ if (!pair || !pair.english.matrixRows || !pair.arabic.matrixRows || pair.english.envName === "cases") {
4145
4168
  return session;
4146
4169
  }
4147
4170
  const columnCount = pair.english.matrixRows[0]?.length ?? 0;
@@ -4358,6 +4381,24 @@ function deleteForward(session) {
4358
4381
  appendDebug(next, "deleteForward", "removed node");
4359
4382
  return next;
4360
4383
  }
4384
+ function setExpr(session, nodeId, expr) {
4385
+ const next = cloneEditorSession(session);
4386
+ const activeKey = activeTreeKey(next.activeSide);
4387
+ const passiveKey = passiveTreeKey(next.activeSide);
4388
+ const activeNode = findNodeById(next[activeKey], nodeId);
4389
+ const passiveNode = findNodeById(next[passiveKey], nodeId);
4390
+ if (!activeNode || !passiveNode) {
4391
+ return session;
4392
+ }
4393
+ activeNode.node.expr = expr;
4394
+ if (["\\mathtt", "\\operatorname", "\\text"].includes(activeNode.node.wrapperCommand ?? "")) {
4395
+ passiveNode.node.expr = expr;
4396
+ }
4397
+ clearSourceIdentity(next, nodeId);
4398
+ markExprSync(next, nodeId);
4399
+ appendDebug(next, "setExpr", nodeId);
4400
+ return next;
4401
+ }
4361
4402
  function createStarterSession() {
4362
4403
  const englishRoot = createEditorChain([createEditorNode("char", "x")]);
4363
4404
  const arabicRoot = createEditorChain([createEditorNode("char", "\u0633")]);
@@ -4441,6 +4482,14 @@ function pasteText(session, text) {
4441
4482
  if (!text) {
4442
4483
  return session;
4443
4484
  }
4485
+ const selection = session.selection;
4486
+ if (selection && Math.abs(selection.anchorIndex - selection.focusIndex) === 1) {
4487
+ const selectedChain = findChainById(session[activeTreeKey(session.activeSide)], selection.chainId);
4488
+ const selected = selectedChain?.chain.nodes[Math.min(selection.anchorIndex, selection.focusIndex)];
4489
+ if (selected?.kind === "char" && ["\\mathtt", "\\operatorname", "\\text"].includes(selected.wrapperCommand ?? "")) {
4490
+ return setExpr(session, selected.id, text);
4491
+ }
4492
+ }
4444
4493
  let s = session;
4445
4494
  let i = 0;
4446
4495
  while (i < text.length) {
@@ -4500,6 +4549,8 @@ function buildBaseNodeBody(node, digitForm = "western", side = "english") {
4500
4549
  if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
4501
4550
  value.classList.add("node-value--bold");
4502
4551
  }
4552
+ if (node.wrapperCommand === "\\text") value.dir = "auto";
4553
+ if (node.wrapperCommand === "\\operatorname") value.classList.add("node-value--operator-name");
4503
4554
  if (node.wrapperCommand === "\\unit") {
4504
4555
  value.classList.add("node-value--unit");
4505
4556
  value.title = "\u0648\u062D\u062F\u0629 (unit)";
@@ -5006,6 +5057,11 @@ var MATRIX_ENV_CSS = `
5006
5057
  transform-origin: center;
5007
5058
  }
5008
5059
 
5060
+ .matrix-env--cases .matrix-env__wrapper:empty {
5061
+ min-width: 0;
5062
+ padding: 0;
5063
+ }
5064
+
5009
5065
  .matrix-env__grid {
5010
5066
  display: inline-grid;
5011
5067
  direction: ltr;
@@ -5050,9 +5106,10 @@ function applyMatrixDelimiterScale(wrap, grid) {
5050
5106
  }
5051
5107
  function buildMatrixEnvNodeBody(node, buildChain, side) {
5052
5108
  const wrap = document.createElement("span");
5053
- wrap.className = `matrix-env matrix-env--${side}`;
5109
+ wrap.className = `matrix-env matrix-env--${side}${node.envName === "cases" ? " matrix-env--cases" : ""}`;
5110
+ if (node.envName === "cases") wrap.dir = "ltr";
5054
5111
  const style = node.envName ?? node.matrixStyle ?? "matrix";
5055
- const glyphs = style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
5112
+ const glyphs = style === "cases" ? side === "arabic" ? { left: "", right: "}" } : { left: "{", right: "" } : style === "array" || style === "aligned" ? void 0 : WRAPPERS[style];
5056
5113
  const left = document.createElement("span");
5057
5114
  left.className = "matrix-env__wrapper matrix-env__wrapper--left";
5058
5115
  left.textContent = glyphs?.left ?? "";
@@ -6502,6 +6559,10 @@ function createEditorRuntime(options) {
6502
6559
  applyStructural((prev) => insertAlignedEnv(prev, rows, columns));
6503
6560
  focusInput();
6504
6561
  },
6562
+ insertCasesEnv: (rows) => {
6563
+ applyStructural((prev) => insertCasesEnv(prev, rows));
6564
+ focusInput();
6565
+ },
6505
6566
  insertSqrt: () => {
6506
6567
  applyStructural((prev) => insertSqrt(prev));
6507
6568
  focusInput();
@@ -8622,7 +8683,9 @@ ${this.closing}` + this.latexScripts();
8622
8683
  }
8623
8684
  const formattedLines = this.lines.map((line) => ` ${line.arabicLatex()}`);
8624
8685
  const content = formattedLines.join(" \\\\\n");
8625
- const fullContent = `${this.opening}
8686
+ const fullContent = this.opening === "\\begin{cases}" && this.closing === "\\end{cases}" ? `\\left.\\begin{array}{rl}
8687
+ ${content}
8688
+ \\end{array}\\right\\}` : `${this.opening}
8626
8689
  ${content}
8627
8690
  ${this.closing}`;
8628
8691
  return this.arabicLatexScripts(sup, sub, fullContent);
@@ -8903,11 +8966,17 @@ var COMMAND_FONT_MAP = Object.fromEntries([
8903
8966
  var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
8904
8967
  NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
8905
8968
  );
8969
+ function hasBareBoldCharSource(node) {
8970
+ return node.kind === "char" && (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") && typeof node.sourceLatex === "string" && node.sourceLatex.length > 0 && !node.sourceLatex.startsWith("\\mathbf{");
8971
+ }
8906
8972
  function charEditorNodeToAstNode(node) {
8907
8973
  const font = node.characterFont ?? "default";
8908
8974
  const charNode = new CharNode(node.expr);
8909
8975
  if (node.wrapperCommand) {
8910
8976
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
8977
+ if (hasBareBoldCharSource(node)) {
8978
+ charNode.sourceLatex = node.sourceLatex;
8979
+ }
8911
8980
  return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
8912
8981
  }
8913
8982
  if (font === "default") {
@@ -8925,8 +8994,9 @@ function commandIdForTex(tex) {
8925
8994
  return null;
8926
8995
  }
8927
8996
  function operatorCommandIdForTex(tex) {
8997
+ const normalized = tex === "\\le" ? "\\leq" : tex === "\\ge" ? "\\geq" : tex;
8928
8998
  for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
8929
- if (spec.Tex === tex) {
8999
+ if (spec.Tex === normalized) {
8930
9000
  return spec.id;
8931
9001
  }
8932
9002
  }
@@ -8957,7 +9027,7 @@ function attachScripts(astNode, editorNode) {
8957
9027
  }
8958
9028
  var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
8959
9029
  function isGridEnvName(value) {
8960
- return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned";
9030
+ return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned" || value === "cases";
8961
9031
  }
8962
9032
  function isMatrixEnvName(value) {
8963
9033
  return MATRIX_ENV_NAMES.has(value);
@@ -9004,6 +9074,9 @@ function envToEditorNode(node) {
9004
9074
  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}` };
9005
9075
  }
9006
9076
  const rowCells = node.lines.map(splitEnvLine);
9077
+ if (parsed.envName === "cases" && (rowCells.length === 0 || rowCells.length > 12 || rowCells.some((row) => row.length !== 2))) {
9078
+ 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)" };
9079
+ }
9007
9080
  const rows = Math.max(1, rowCells.length);
9008
9081
  const columns = Math.max(1, ...rowCells.map((row) => row.length));
9009
9082
  const env = createGridEnvNode(parsed.envName, rows, columns, parsed.alignments);
@@ -9086,14 +9159,19 @@ function wrappedAtomicCommandId(node) {
9086
9159
  return commandIdForTex(`${node.name}{${child.expr}}`);
9087
9160
  }
9088
9161
  function editableWrapperCommand(node) {
9089
- if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
9162
+ if (node.name !== "\\mathtt" && node.name !== "\\operatorname" && node.name !== "\\text" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
9163
+ return null;
9164
+ }
9165
+ if (node.name === "\\text" && node.sourceLatex && !node.sourceLatex.startsWith("\\text{")) {
9090
9166
  return null;
9091
9167
  }
9092
9168
  const child = singleCommandChar(node);
9169
+ if (node.name === "\\text" && child?.sourceLatex && !node.sourceLatex) return null;
9093
9170
  let editorNode;
9094
9171
  if (child) {
9095
9172
  const normalized = normalizeCharImportExpr(child.expr);
9096
9173
  editorNode = createEditorNode("char", normalized.expr);
9174
+ if (child.sourceLatex) editorNode.sourceLatex = child.sourceLatex;
9097
9175
  if (normalized.characterFont !== "default") {
9098
9176
  editorNode.characterFont = normalized.characterFont;
9099
9177
  }
@@ -9105,7 +9183,7 @@ function editableWrapperCommand(node) {
9105
9183
  if (!nested?.editable) return null;
9106
9184
  editorNode = nested.node;
9107
9185
  }
9108
- editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
9186
+ editorNode.wrapperCommand = node.name === "\\mathsf" ? "\\unit" : node.name;
9109
9187
  const scripts = attachScripts(node, editorNode);
9110
9188
  if (scripts) {
9111
9189
  return scripts;
@@ -9239,6 +9317,7 @@ function commandToEditorNode(node) {
9239
9317
  const operatorId = operatorCommandIdForTex(node.name);
9240
9318
  if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
9241
9319
  const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
9320
+ if (node.name === "\\le" || node.name === "\\ge") atomicOperator.sourceLatex = node.name;
9242
9321
  const scripts = attachScripts(node, atomicOperator);
9243
9322
  if (scripts) {
9244
9323
  return scripts;
@@ -9550,7 +9629,7 @@ function editorNodeToAstNode(node) {
9550
9629
  if (!tex) {
9551
9630
  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}` };
9552
9631
  }
9553
- astNode = new CommandNode(tex);
9632
+ astNode = new CommandNode(node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : tex);
9554
9633
  } else if (node.kind === "standardCommand") {
9555
9634
  if (!isStandardCommandTex(node.expr)) {
9556
9635
  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}` };
@@ -9561,7 +9640,7 @@ function editorNodeToAstNode(node) {
9561
9640
  } else {
9562
9641
  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}` };
9563
9642
  }
9564
- if (node.sourceLatex) {
9643
+ if (node.sourceLatex && !hasBareBoldCharSource(node)) {
9565
9644
  astNode.sourceLatex = node.sourceLatex;
9566
9645
  }
9567
9646
  const scripts = attachAstScripts(node, astNode);
@@ -9909,7 +9988,7 @@ function EquationMobileToolbar({
9909
9988
  if (kind === "rows") {
9910
9989
  setMatrixRows(next);
9911
9990
  } else {
9912
- setMatrixColumns(envMode === "aligned" ? 2 : next);
9991
+ setMatrixColumns(envMode === "aligned" || envMode === "cases" ? 2 : next);
9913
9992
  }
9914
9993
  }
9915
9994
  function insertEnvironment() {
@@ -9918,6 +9997,8 @@ function EquationMobileToolbar({
9918
9997
  runtime.insertArrayEnv(matrixRows, matrixColumns);
9919
9998
  } else if (envMode === "aligned") {
9920
9999
  runtime.insertAlignedEnv(matrixRows, 2);
10000
+ } else if (envMode === "cases") {
10001
+ runtime.insertCasesEnv(matrixRows);
9921
10002
  } else {
9922
10003
  runtime.insertMatrixEnv(matrixStyle, matrixRows, matrixColumns);
9923
10004
  }
@@ -10085,7 +10166,8 @@ function EquationMobileToolbar({
10085
10166
  /* @__PURE__ */ jsx("div", { className: "butex-widget__sheet-choice-row", role: "group", "aria-label": messages.environmentType, children: [
10086
10167
  { id: "matrix", label: messages.matrix },
10087
10168
  { id: "array", label: messages.array },
10088
- { id: "aligned", label: messages.aligned }
10169
+ { id: "aligned", label: messages.aligned },
10170
+ { id: "cases", label: messages.piecewise }
10089
10171
  ].map((option) => /* @__PURE__ */ jsx(
10090
10172
  "button",
10091
10173
  {
@@ -10093,7 +10175,7 @@ function EquationMobileToolbar({
10093
10175
  "aria-pressed": envMode === option.id,
10094
10176
  onClick: () => {
10095
10177
  setEnvMode(option.id);
10096
- if (option.id === "aligned") setMatrixColumns(2);
10178
+ if (option.id === "aligned" || option.id === "cases") setMatrixColumns(2);
10097
10179
  },
10098
10180
  children: option.label
10099
10181
  },
@@ -10102,19 +10184,19 @@ function EquationMobileToolbar({
10102
10184
  envMode === "matrix" ? /* @__PURE__ */ jsx("div", { className: "butex-widget__sheet-choice-row", role: "group", "aria-label": messages.matrixType, children: MATRIX_STYLES.map((style) => /* @__PURE__ */ 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,
10103
10185
  /* @__PURE__ */ jsxs("section", { className: "butex-widget__sheet-section", children: [
10104
10186
  /* @__PURE__ */ jsx("h4", { children: messages.commonMatrixSizes }),
10105
- /* @__PURE__ */ jsx("div", { className: "butex-widget__matrix-presets", children: (envMode === "aligned" ? MATRIX_PRESETS.filter((preset) => preset.columns === 2) : MATRIX_PRESETS).map((preset) => /* @__PURE__ */ jsxs(
10187
+ /* @__PURE__ */ jsx("div", { className: "butex-widget__matrix-presets", children: (envMode === "aligned" || envMode === "cases" ? MATRIX_PRESETS.filter((preset) => preset.columns === 2) : MATRIX_PRESETS).map((preset) => /* @__PURE__ */ jsxs(
10106
10188
  "button",
10107
10189
  {
10108
10190
  type: "button",
10109
10191
  "aria-pressed": matrixRows === preset.rows && matrixColumns === preset.columns,
10110
10192
  onClick: () => {
10111
10193
  setMatrixRows(preset.rows);
10112
- setMatrixColumns(envMode === "aligned" ? 2 : preset.columns);
10194
+ setMatrixColumns(envMode === "aligned" || envMode === "cases" ? 2 : preset.columns);
10113
10195
  },
10114
10196
  children: [
10115
10197
  preset.rows,
10116
10198
  "\xD7",
10117
- envMode === "aligned" ? 2 : preset.columns
10199
+ envMode === "aligned" || envMode === "cases" ? 2 : preset.columns
10118
10200
  ]
10119
10201
  },
10120
10202
  `${String(preset.rows)}-${String(preset.columns)}`
@@ -10131,12 +10213,12 @@ function EquationMobileToolbar({
10131
10213
  /* @__PURE__ */ jsxs("div", { className: "butex-widget__matrix-stepper-row", children: [
10132
10214
  /* @__PURE__ */ jsx("span", { children: messages.columns }),
10133
10215
  /* @__PURE__ */ jsxs("div", { className: "butex-widget__matrix-stepper", children: [
10134
- /* @__PURE__ */ jsx("button", { type: "button", disabled: matrixColumns <= 1 || envMode === "aligned", "aria-label": messages.decreaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns - 1), children: "\u2212" }),
10135
- /* @__PURE__ */ jsx("output", { "aria-live": "polite", children: envMode === "aligned" ? 2 : matrixColumns }),
10136
- /* @__PURE__ */ jsx("button", { type: "button", disabled: matrixColumns >= 12 || envMode === "aligned", "aria-label": messages.increaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns + 1), children: "+" })
10216
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: matrixColumns <= 1 || envMode === "aligned" || envMode === "cases", "aria-label": messages.decreaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns - 1), children: "\u2212" }),
10217
+ /* @__PURE__ */ jsx("output", { "aria-live": "polite", children: envMode === "aligned" || envMode === "cases" ? 2 : matrixColumns }),
10218
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: matrixColumns >= 12 || envMode === "aligned" || envMode === "cases", "aria-label": messages.increaseColumns, onClick: () => setMatrixDimension("columns", matrixColumns + 1), children: "+" })
10137
10219
  ] })
10138
10220
  ] }),
10139
- /* @__PURE__ */ jsx("p", { className: "butex-widget__matrix-size-summary", "aria-live": "polite", children: matrixSizeLabel(matrixRows, envMode === "aligned" ? 2 : matrixColumns, messages) }),
10221
+ /* @__PURE__ */ jsx("p", { className: "butex-widget__matrix-size-summary", "aria-live": "polite", children: matrixSizeLabel(matrixRows, envMode === "aligned" || envMode === "cases" ? 2 : matrixColumns, messages) }),
10140
10222
  /* @__PURE__ */ jsx("button", { type: "button", className: "butex-widget__matrix-insert", onClick: insertEnvironment, children: messages.insert }),
10141
10223
  /* @__PURE__ */ jsxs("section", { className: "butex-widget__sheet-section", children: [
10142
10224
  /* @__PURE__ */ jsx("h4", { children: messages.editSelectedEnvironment }),
@@ -10157,11 +10239,11 @@ function EquationMobileToolbar({
10157
10239
  "\u2212",
10158
10240
  messages.row
10159
10241
  ] }),
10160
- /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => getRuntime()?.addMatrixColumn(), children: [
10242
+ /* @__PURE__ */ jsxs("button", { type: "button", disabled: envMode === "cases", onClick: () => getRuntime()?.addMatrixColumn(), children: [
10161
10243
  "+",
10162
10244
  messages.column
10163
10245
  ] }),
10164
- /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => getRuntime()?.removeMatrixColumn(), children: [
10246
+ /* @__PURE__ */ jsxs("button", { type: "button", disabled: envMode === "cases", onClick: () => getRuntime()?.removeMatrixColumn(), children: [
10165
10247
  "\u2212",
10166
10248
  messages.column
10167
10249
  ] })
@@ -10692,7 +10774,7 @@ var ButexEditor = forwardRef(
10692
10774
  const debugLogEl = debugLogRef.current;
10693
10775
  const english = renderEnglishLatexFromSession(session);
10694
10776
  const arabic = renderArabicLatexFromSession(session);
10695
- const activeLatex = session.activeSide === "arabic" ? arabic : english;
10777
+ const activeLatex = session.activeSide === "arabic" ? renderArabicPreviewLatexFromSession(session) : english;
10696
10778
  if (debugRef.current && latexLinesEl) {
10697
10779
  const currentMessages = equationEditorMessages(uiLocaleRef.current);
10698
10780
  latexLinesEl.textContent = `${currentMessages.englishLatex}:
@@ -10892,6 +10974,8 @@ ${arabic || currentMessages.empty}`;
10892
10974
  runtimeRef.current?.insertArrayEnv(rows, columns);
10893
10975
  } else if (envPaletteMode === "aligned") {
10894
10976
  runtimeRef.current?.insertAlignedEnv(rows, columns);
10977
+ } else if (envPaletteMode === "cases") {
10978
+ runtimeRef.current?.insertCasesEnv(rows);
10895
10979
  } else {
10896
10980
  runtimeRef.current?.insertMatrixEnv(matrixStyle, rows, columns);
10897
10981
  }
@@ -11187,7 +11271,8 @@ ${arabic || currentMessages.empty}`;
11187
11271
  /* @__PURE__ */ jsx2("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.environmentType, children: [
11188
11272
  { id: "matrix", label: messages.matrix },
11189
11273
  { id: "array", label: messages.array },
11190
- { id: "aligned", label: messages.aligned }
11274
+ { id: "aligned", label: messages.aligned },
11275
+ { id: "cases", label: messages.piecewise }
11191
11276
  ].map((option) => /* @__PURE__ */ jsx2(
11192
11277
  "button",
11193
11278
  {
@@ -11198,7 +11283,7 @@ ${arabic || currentMessages.empty}`;
11198
11283
  onMouseDown: (event) => event.preventDefault(),
11199
11284
  onClick: () => {
11200
11285
  setEnvPaletteMode(option.id);
11201
- if (option.id === "aligned") {
11286
+ if (option.id === "aligned" || option.id === "cases") {
11202
11287
  setMatrixColumns(2);
11203
11288
  }
11204
11289
  },
@@ -11223,7 +11308,7 @@ ${arabic || currentMessages.empty}`;
11223
11308
  style.id
11224
11309
  )) }) : null,
11225
11310
  /* @__PURE__ */ jsx2("div", { className: "matrix-size-readout", children: matrixHover ? matrixSizeLabel2(matrixHover.rows, matrixHover.columns, messages) : matrixSizeLabel2(matrixRows, matrixColumns, messages) }),
11226
- /* @__PURE__ */ jsx2("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
11311
+ envPaletteMode !== "cases" ? /* @__PURE__ */ jsx2("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
11227
11312
  { length: 8 },
11228
11313
  (_, rowIndex) => Array.from({ length: 8 }, (_2, columnIndex) => {
11229
11314
  const rows = rowIndex + 1;
@@ -11251,7 +11336,7 @@ ${arabic || currentMessages.empty}`;
11251
11336
  `${rows}-${columns}`
11252
11337
  );
11253
11338
  })
11254
- ) }),
11339
+ ) }) : null,
11255
11340
  /* @__PURE__ */ jsxs2("div", { className: "matrix-custom-size", children: [
11256
11341
  /* @__PURE__ */ jsxs2("label", { children: [
11257
11342
  messages.row,
@@ -11274,7 +11359,8 @@ ${arabic || currentMessages.empty}`;
11274
11359
  type: "number",
11275
11360
  min: 1,
11276
11361
  max: 12,
11277
- value: matrixColumns,
11362
+ value: envPaletteMode === "cases" || envPaletteMode === "aligned" ? 2 : matrixColumns,
11363
+ disabled: envPaletteMode === "cases" || envPaletteMode === "aligned",
11278
11364
  onChange: (event) => setMatrixColumns(clampMatrixSize2(Number(event.currentTarget.value) || 1))
11279
11365
  }
11280
11366
  )
@@ -11287,7 +11373,7 @@ ${arabic || currentMessages.empty}`;
11287
11373
  onMouseDown: (event) => event.preventDefault(),
11288
11374
  onClick: () => {
11289
11375
  const rows = clampMatrixSize2(matrixRows);
11290
- const columns = clampMatrixSize2(matrixColumns);
11376
+ const columns = envPaletteMode === "cases" || envPaletteMode === "aligned" ? 2 : clampMatrixSize2(matrixColumns);
11291
11377
  insertSelectedEnvironment(rows, columns);
11292
11378
  setMatrixMenuOpen(false);
11293
11379
  setMatrixHover(null);
@@ -11333,11 +11419,11 @@ ${arabic || currentMessages.empty}`;
11333
11419
  "-",
11334
11420
  messages.row
11335
11421
  ] }),
11336
- /* @__PURE__ */ jsxs2("button", { type: "button", title: messages.addColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
11422
+ /* @__PURE__ */ jsxs2("button", { type: "button", title: messages.addColumn, disabled: envPaletteMode === "cases", onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
11337
11423
  "+",
11338
11424
  messages.column
11339
11425
  ] }),
11340
- /* @__PURE__ */ jsxs2("button", { type: "button", title: messages.removeColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
11426
+ /* @__PURE__ */ jsxs2("button", { type: "button", title: messages.removeColumn, disabled: envPaletteMode === "cases", onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
11341
11427
  "-",
11342
11428
  messages.column
11343
11429
  ] })