@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.
@@ -1,7 +1,7 @@
1
1
  type EditorSide = 'english' | 'arabic';
2
2
  type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'boxed' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
3
3
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
4
- type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
4
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned' | 'cases';
5
5
  type EnvColumnAlignment = 'l' | 'c' | 'r';
6
6
  type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
7
7
  type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
@@ -17,10 +17,10 @@ type EditorNode = {
17
17
  kind: EditorNodeKind;
18
18
  expr: string;
19
19
  characterFont?: CharacterFontId;
20
- /** Minimal upstream source identity used only while the node remains unchanged. */
20
+ /** Canonical source identity; atomic Arabic-label edits preserve it, canonical-side edits invalidate it. */
21
21
  sourceLatex?: string;
22
22
  /** Existing editor node reused for wrapper commands that need editable content. */
23
- wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
23
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\operatorname' | '\\text' | '\\mathbf' | '\\boldarabic';
24
24
  superscript: EditorChain | null;
25
25
  subscript: EditorChain | null;
26
26
  leftDelimExpr: string;
@@ -1134,11 +1134,11 @@ declare function createEmptyEquationSession(side?: EditorSide): EditorSession;
1134
1134
  declare function createEmptyArabicEquationSession(): EditorSession;
1135
1135
  declare function mathTokenToEditorSession(math: MathNode | null, side?: EditorSide): DocumentMathBridgeResult;
1136
1136
  declare function mathTokenToArabicEditorSession(math: MathNode | null): DocumentMathBridgeResult;
1137
- declare function mathSourceFromSession(session: EditorSession, side: EditorSide, opening?: string, closing?: string): string;
1137
+ declare function mathSourceFromSession(session: EditorSession, side: EditorSide, opening?: string, closing?: string, presentation?: boolean): string;
1138
1138
  declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
1139
1139
  declare function mathNodeFromSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1140
1140
  declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1141
- declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId): string;
1141
+ declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId, presentation?: boolean): string;
1142
1142
 
1143
1143
  type DocumentPreviewOptions = {
1144
1144
  documentDirection?: DocumentDirection;
@@ -1,7 +1,7 @@
1
1
  type EditorSide = 'english' | 'arabic';
2
2
  type EditorNodeKind = 'char' | 'number' | 'operator' | 'delimiter' | 'boxed' | 'frac' | 'sqrt' | 'overset' | 'underset' | 'accent' | 'env' | 'atomicCommand' | 'atomicOperatorCommand' | 'standardCommand';
3
3
  type MatrixEnvStyle = 'matrix' | 'pmatrix' | 'bmatrix' | 'Bmatrix' | 'vmatrix' | 'Vmatrix';
4
- type GridEnvName = MatrixEnvStyle | 'array' | 'aligned';
4
+ type GridEnvName = MatrixEnvStyle | 'array' | 'aligned' | 'cases';
5
5
  type EnvColumnAlignment = 'l' | 'c' | 'r';
6
6
  type CharacterFontId = 'default' | 'takween' | 'diwani' | 'diwaniOutline' | 'maghribi';
7
7
  type DigitFormId = 'western' | 'arabicIndic' | 'persianIndic';
@@ -17,10 +17,10 @@ type EditorNode = {
17
17
  kind: EditorNodeKind;
18
18
  expr: string;
19
19
  characterFont?: CharacterFontId;
20
- /** Minimal upstream source identity used only while the node remains unchanged. */
20
+ /** Canonical source identity; atomic Arabic-label edits preserve it, canonical-side edits invalidate it. */
21
21
  sourceLatex?: string;
22
22
  /** Existing editor node reused for wrapper commands that need editable content. */
23
- wrapperCommand?: '\\unit' | '\\mathtt' | '\\mathbf' | '\\boldarabic';
23
+ wrapperCommand?: '\\unit' | '\\mathtt' | '\\operatorname' | '\\text' | '\\mathbf' | '\\boldarabic';
24
24
  superscript: EditorChain | null;
25
25
  subscript: EditorChain | null;
26
26
  leftDelimExpr: string;
@@ -1134,11 +1134,11 @@ declare function createEmptyEquationSession(side?: EditorSide): EditorSession;
1134
1134
  declare function createEmptyArabicEquationSession(): EditorSession;
1135
1135
  declare function mathTokenToEditorSession(math: MathNode | null, side?: EditorSide): DocumentMathBridgeResult;
1136
1136
  declare function mathTokenToArabicEditorSession(math: MathNode | null): DocumentMathBridgeResult;
1137
- declare function mathSourceFromSession(session: EditorSession, side: EditorSide, opening?: string, closing?: string): string;
1137
+ declare function mathSourceFromSession(session: EditorSession, side: EditorSide, opening?: string, closing?: string, presentation?: boolean): string;
1138
1138
  declare function mathSourceFromArabicSession(session: EditorSession, opening?: string, closing?: string): string;
1139
1139
  declare function mathNodeFromSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1140
1140
  declare function mathNodeFromArabicSession(session: EditorSession, opening?: string, closing?: string): MathNode;
1141
- declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId): string;
1141
+ declare function mathTokenSourceForSide(token: MathToken2, side: EditorSide, digitForm?: DigitFormId, presentation?: boolean): string;
1142
1142
 
1143
1143
  type DocumentPreviewOptions = {
1144
1144
  documentDirection?: DocumentDirection;
package/dist/document.js CHANGED
@@ -741,7 +741,9 @@ ${this.closing}` + this.latexScripts();
741
741
  }
742
742
  const formattedLines = this.lines.map((line) => ` ${line.arabicLatex()}`);
743
743
  const content = formattedLines.join(" \\\\\n");
744
- const fullContent = `${this.opening}
744
+ const fullContent = this.opening === "\\begin{cases}" && this.closing === "\\end{cases}" ? `\\left.\\begin{array}{rl}
745
+ ${content}
746
+ \\end{array}\\right\\}` : `${this.opening}
745
747
  ${content}
746
748
  ${this.closing}`;
747
749
  return this.arabicLatexScripts(sup, sub, fullContent);
@@ -3096,7 +3098,7 @@ function createAccentNode(accentId) {
3096
3098
  }
3097
3099
  function createGridEnvNode(envName, rows, columns2, columnAlignments) {
3098
3100
  const safeRows = Math.max(1, Math.min(12, Math.trunc(rows)));
3099
- const safeColumns = Math.max(1, Math.min(12, Math.trunc(columns2)));
3101
+ const safeColumns = envName === "cases" ? 2 : Math.max(1, Math.min(12, Math.trunc(columns2)));
3100
3102
  const matrixStyles = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
3101
3103
  const isMatrix = matrixStyles.has(envName) && envName !== "array" && envName !== "aligned";
3102
3104
  return {
@@ -3400,6 +3402,9 @@ function renderMatrixRowsArabic(node, options) {
3400
3402
  const spec = (node.columnAlignments ?? []).slice(0, node.matrixRows[0]?.length ?? 0).reverse().map(reverseAlignmentForArabic).join("");
3401
3403
  return `\\begin{array}{${spec || "c"}}${rows.join(" \\\\\n")}\\end{array}`;
3402
3404
  }
3405
+ if (envName === "cases" && options?.casesPresentation) {
3406
+ return `\\left.\\begin{array}{rl}${rows.join(" \\\\\n")}\\end{array}\\right\\}`;
3407
+ }
3403
3408
  return `\\begin{${envName}}${rows.join(" \\\\\n")}\\end{${envName}}`;
3404
3409
  }
3405
3410
  function renderAccentEnglish(command, accent, base, options) {
@@ -3421,6 +3426,10 @@ function renderAccentArabic(command, accent, base, options) {
3421
3426
  function escapeText(s) {
3422
3427
  return s.replace(/\\/g, "\\textbackslash{}").replace(/[{}]/g, "\\$&");
3423
3428
  }
3429
+ function escapeAtomicLiteral(text) {
3430
+ const unescaped = text.replace(/\\([%_&#{}$])/g, "$1");
3431
+ return escapeText(unescaped).replace(/[%_&#$]/g, "\\$&");
3432
+ }
3424
3433
  function renderCharContent(node, options) {
3425
3434
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3426
3435
  const font = node.characterFont ?? "default";
@@ -3467,7 +3476,7 @@ function renderNodeEnglish(node, options) {
3467
3476
  return `${body}${latinScripts(node, options)}`;
3468
3477
  }
3469
3478
  if (node.kind === "atomicOperatorCommand") {
3470
- const body = atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
3479
+ const body = node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : atomicOperatorCommandSpec(node.expr)?.Tex ?? node.expr;
3471
3480
  return `${body}${latinScripts(node, options)}`;
3472
3481
  }
3473
3482
  if (node.kind === "standardCommand") {
@@ -3484,7 +3493,8 @@ function renderNodeEnglish(node, options) {
3484
3493
  if (node.wrapperCommand) {
3485
3494
  const expr = formatDigits(node.expr, selectedDigitForm(options));
3486
3495
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
3487
- return `${wrapper}{${escapeText(expr)}}${latinScripts(node, options)}`;
3496
+ const escaped = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : escapeText(expr);
3497
+ return `${wrapper}{${escaped}}${latinScripts(node, options)}`;
3488
3498
  }
3489
3499
  return `${renderCharContent(node, options)}${latinScripts(node, options)}`;
3490
3500
  }
@@ -3545,7 +3555,8 @@ function renderNodeArabic(node, options) {
3545
3555
  const content = renderCharContent(node, options);
3546
3556
  if (node.wrapperCommand) {
3547
3557
  const wrapper = node.wrapperCommand === "\\mathbf" ? "\\boldarabic" : node.wrapperCommand;
3548
- return arabicScripts(node, `${wrapper}{${content}}`, options);
3558
+ const literal = wrapper === "\\operatorname" || wrapper === "\\text" ? escapeAtomicLiteral(expr) : content;
3559
+ return arabicScripts(node, `${wrapper}{${literal}}`, options);
3549
3560
  }
3550
3561
  return arabicScripts(node, (node.characterFont ?? "default") === "default" ? `\\text{${escapeText(expr)}}` : content, options);
3551
3562
  }
@@ -3574,6 +3585,9 @@ function renderEnglishLatexFromSession(session) {
3574
3585
  function renderArabicLatexFromSession(session) {
3575
3586
  return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western" });
3576
3587
  }
3588
+ function renderArabicPreviewLatexFromSession(session) {
3589
+ return renderChainArabic(session.arabicTree, { digitForm: session.currentDigitForm ?? "western", casesPresentation: true });
3590
+ }
3577
3591
 
3578
3592
  // src/editor/state.ts
3579
3593
  function appendDebug(session, command, note) {
@@ -3923,6 +3937,11 @@ var MATRIX_ENV_CSS = `
3923
3937
  transform-origin: center;
3924
3938
  }
3925
3939
 
3940
+ .matrix-env--cases .matrix-env__wrapper:empty {
3941
+ min-width: 0;
3942
+ padding: 0;
3943
+ }
3944
+
3926
3945
  .matrix-env__grid {
3927
3946
  display: inline-grid;
3928
3947
  direction: ltr;
@@ -4429,11 +4448,17 @@ var COMMAND_FONT_MAP = Object.fromEntries([
4429
4448
  var CHAR_FONT_EXPORT_TEX = Object.fromEntries(
4430
4449
  NON_DEFAULT_CHARACTER_FONT_SPECS.map((font) => [font.id, font.macro])
4431
4450
  );
4451
+ function hasBareBoldCharSource(node) {
4452
+ return node.kind === "char" && (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") && typeof node.sourceLatex === "string" && node.sourceLatex.length > 0 && !node.sourceLatex.startsWith("\\mathbf{");
4453
+ }
4432
4454
  function charEditorNodeToAstNode(node) {
4433
4455
  const font = node.characterFont ?? "default";
4434
4456
  const charNode = new CharNode(node.expr);
4435
4457
  if (node.wrapperCommand) {
4436
4458
  const wrapper = node.wrapperCommand === "\\boldarabic" ? "\\mathbf" : node.wrapperCommand;
4459
+ if (hasBareBoldCharSource(node)) {
4460
+ charNode.sourceLatex = node.sourceLatex;
4461
+ }
4437
4462
  return new CommandNode(wrapper, [], [new ChainNode([charNode])]);
4438
4463
  }
4439
4464
  if (font === "default") {
@@ -4451,8 +4476,9 @@ function commandIdForTex(tex) {
4451
4476
  return null;
4452
4477
  }
4453
4478
  function operatorCommandIdForTex(tex) {
4479
+ const normalized = tex === "\\le" ? "\\leq" : tex === "\\ge" ? "\\geq" : tex;
4454
4480
  for (const spec of Object.values(ATOMIC_OPERATOR_COMMANDS)) {
4455
- if (spec.Tex === tex) {
4481
+ if (spec.Tex === normalized) {
4456
4482
  return spec.id;
4457
4483
  }
4458
4484
  }
@@ -4483,7 +4509,7 @@ function attachScripts(astNode, editorNode) {
4483
4509
  }
4484
4510
  var MATRIX_ENV_NAMES = /* @__PURE__ */ new Set(["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix"]);
4485
4511
  function isGridEnvName(value) {
4486
- return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned";
4512
+ return MATRIX_ENV_NAMES.has(value) || value === "array" || value === "aligned" || value === "cases";
4487
4513
  }
4488
4514
  function isMatrixEnvName(value) {
4489
4515
  return MATRIX_ENV_NAMES.has(value);
@@ -4530,6 +4556,9 @@ function envToEditorNode(node) {
4530
4556
  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}` };
4531
4557
  }
4532
4558
  const rowCells = node.lines.map(splitEnvLine);
4559
+ if (parsed.envName === "cases" && (rowCells.length === 0 || rowCells.length > 12 || rowCells.some((row) => row.length !== 2))) {
4560
+ 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)" };
4561
+ }
4533
4562
  const rows = Math.max(1, rowCells.length);
4534
4563
  const columns2 = Math.max(1, ...rowCells.map((row) => row.length));
4535
4564
  const env = createGridEnvNode(parsed.envName, rows, columns2, parsed.alignments);
@@ -4612,14 +4641,19 @@ function wrappedAtomicCommandId(node) {
4612
4641
  return commandIdForTex(`${node.name}{${child.expr}}`);
4613
4642
  }
4614
4643
  function editableWrapperCommand(node) {
4615
- if (node.name !== "\\mathtt" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4644
+ if (node.name !== "\\mathtt" && node.name !== "\\operatorname" && node.name !== "\\text" && node.name !== "\\mathsf" && node.name !== "\\unit" && node.name !== "\\mathbf" && node.name !== "\\boldarabic") {
4645
+ return null;
4646
+ }
4647
+ if (node.name === "\\text" && node.sourceLatex && !node.sourceLatex.startsWith("\\text{")) {
4616
4648
  return null;
4617
4649
  }
4618
4650
  const child = singleCommandChar(node);
4651
+ if (node.name === "\\text" && child?.sourceLatex && !node.sourceLatex) return null;
4619
4652
  let editorNode;
4620
4653
  if (child) {
4621
4654
  const normalized = normalizeCharImportExpr(child.expr);
4622
4655
  editorNode = createEditorNode("char", normalized.expr);
4656
+ if (child.sourceLatex) editorNode.sourceLatex = child.sourceLatex;
4623
4657
  if (normalized.characterFont !== "default") {
4624
4658
  editorNode.characterFont = normalized.characterFont;
4625
4659
  }
@@ -4631,7 +4665,7 @@ function editableWrapperCommand(node) {
4631
4665
  if (!nested?.editable) return null;
4632
4666
  editorNode = nested.node;
4633
4667
  }
4634
- editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4668
+ editorNode.wrapperCommand = node.name === "\\mathsf" ? "\\unit" : node.name;
4635
4669
  const scripts = attachScripts(node, editorNode);
4636
4670
  if (scripts) {
4637
4671
  return scripts;
@@ -4765,6 +4799,7 @@ function commandToEditorNode(node) {
4765
4799
  const operatorId = operatorCommandIdForTex(node.name);
4766
4800
  if (operatorId && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0) {
4767
4801
  const atomicOperator = createEditorNode("atomicOperatorCommand", operatorId);
4802
+ if (node.name === "\\le" || node.name === "\\ge") atomicOperator.sourceLatex = node.name;
4768
4803
  const scripts = attachScripts(node, atomicOperator);
4769
4804
  if (scripts) {
4770
4805
  return scripts;
@@ -5076,7 +5111,7 @@ function editorNodeToAstNode(node) {
5076
5111
  if (!tex) {
5077
5112
  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}` };
5078
5113
  }
5079
- astNode = new CommandNode(tex);
5114
+ astNode = new CommandNode(node.sourceLatex === "\\le" || node.sourceLatex === "\\ge" ? node.sourceLatex : tex);
5080
5115
  } else if (node.kind === "standardCommand") {
5081
5116
  if (!isStandardCommandTex(node.expr)) {
5082
5117
  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}` };
@@ -5087,7 +5122,7 @@ function editorNodeToAstNode(node) {
5087
5122
  } else {
5088
5123
  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}` };
5089
5124
  }
5090
- if (node.sourceLatex) {
5125
+ if (node.sourceLatex && !hasBareBoldCharSource(node)) {
5091
5126
  astNode.sourceLatex = node.sourceLatex;
5092
5127
  }
5093
5128
  const scripts = attachAstScripts(node, astNode);
@@ -5151,8 +5186,8 @@ function mathTokenToEditorSession(math, side = "arabic") {
5151
5186
  function mathTokenToArabicEditorSession(math) {
5152
5187
  return mathTokenToEditorSession(math, "arabic");
5153
5188
  }
5154
- function mathSourceFromSession(session, side, opening = "$", closing = "$") {
5155
- const inner = side === "english" ? renderEnglishLatexFromSession(session) : renderArabicLatexFromSession(session);
5189
+ function mathSourceFromSession(session, side, opening = "$", closing = "$", presentation = false) {
5190
+ const inner = side === "english" ? renderEnglishLatexFromSession(session) : presentation ? renderArabicPreviewLatexFromSession(session) : renderArabicLatexFromSession(session);
5156
5191
  if (opening === "$" || opening === "\\(") {
5157
5192
  return opening + inner + closing;
5158
5193
  }
@@ -5178,11 +5213,11 @@ function mathNodeFromSession(session, opening = "$", closing = "$") {
5178
5213
  function mathNodeFromArabicSession(session, opening = "$", closing = "$") {
5179
5214
  return mathNodeFromSession(session, opening, closing);
5180
5215
  }
5181
- function mathTokenSourceForSide(token, side, digitForm) {
5216
+ function mathTokenSourceForSide(token, side, digitForm, presentation = false) {
5182
5217
  if (!token.math || token.sourceOwner === "raw") {
5183
5218
  return token.source;
5184
5219
  }
5185
- if (token.sourceSide === side && digitForm === void 0) {
5220
+ if (!presentation && token.sourceSide === side && digitForm === void 0) {
5186
5221
  return token.source;
5187
5222
  }
5188
5223
  const result = mathTokenToEditorSession(token.math, side);
@@ -5190,7 +5225,7 @@ function mathTokenSourceForSide(token, side, digitForm) {
5190
5225
  return token.source;
5191
5226
  }
5192
5227
  const session = digitForm === void 0 ? result.session : setCurrentDigitForm(result.session, digitForm);
5193
- return mathSourceFromSession(session, side, token.opening, token.closing);
5228
+ return mathSourceFromSession(session, side, token.opening, token.closing, presentation);
5194
5229
  }
5195
5230
 
5196
5231
  // src/document/commands.ts
@@ -6584,10 +6619,10 @@ function applyReferenceFields(reference, command) {
6584
6619
  reference.fieldSeparator = command.field_separator;
6585
6620
  }
6586
6621
  }
6587
- function replaceCitationKey(document2, previousKey, nextKey) {
6622
+ function replaceInlineKey(document2, kind, previousKey, nextKey) {
6588
6623
  function replaceInField(field) {
6589
6624
  for (const token of field.tokens) {
6590
- if (token.kind === "cite") {
6625
+ if (token.kind === kind) {
6591
6626
  token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
6592
6627
  }
6593
6628
  }
@@ -6646,7 +6681,7 @@ function applyArticleCommand(document2, command) {
6646
6681
  const previousKey = target.key;
6647
6682
  const nextKey = validateReferenceKey(document2, command.key, target.id);
6648
6683
  target.key = nextKey;
6649
- replaceCitationKey(document2, previousKey, nextKey);
6684
+ replaceInlineKey(document2, "cite", previousKey, nextKey);
6650
6685
  }
6651
6686
  applyReferenceFields(target, command);
6652
6687
  return;
@@ -7607,6 +7642,7 @@ function applyBasicCommand(document2, command) {
7607
7642
  throw new DocumentCommandError("invalid_key", "Float label is invalid");
7608
7643
  }
7609
7644
  }
7645
+ const previousLabel = block2.labelEnabled ? block2.label : "";
7610
7646
  applyFloatMetaPatch(block2, {
7611
7647
  ...command.centered !== void 0 ? { centered: command.centered } : {},
7612
7648
  ...command.caption_enabled !== void 0 ? { captionEnabled: command.caption_enabled } : {},
@@ -7614,6 +7650,9 @@ function applyBasicCommand(document2, command) {
7614
7650
  ...command.label_enabled !== void 0 ? { labelEnabled: command.label_enabled } : {},
7615
7651
  ...label2 !== void 0 ? { label: label2 } : {}
7616
7652
  });
7653
+ if (previousLabel && block2.labelEnabled && block2.label && previousLabel !== block2.label) {
7654
+ replaceInlineKey(document2, "ref", previousLabel, block2.label);
7655
+ }
7617
7656
  return;
7618
7657
  }
7619
7658
  const label = normalizedNewFloatLabel(document2, command.label);
@@ -8172,9 +8211,13 @@ function digitsMappingFromDigitForm(digitForm) {
8172
8211
  }
8173
8212
  return "arabicdigits";
8174
8213
  }
8214
+ function editorMathLatexForCompile(token) {
8215
+ const source = token.math && token.sourceSide === "arabic" && token.source.includes("\\begin{cases}") ? mathTokenSourceForSide(token, "arabic", void 0, true) : token.source;
8216
+ return mirrorBuTeXOperatorsInTex(source, { target: "compile" });
8217
+ }
8175
8218
  function mathBodyLatex(token) {
8176
8219
  if (token.sourceOwner === "editor") {
8177
- return stripDisplayMathDelimiters(mirrorBuTeXOperatorsInTex(token.source, { target: "compile" }));
8220
+ return stripDisplayMathDelimiters(editorMathLatexForCompile(token));
8178
8221
  }
8179
8222
  if (!token.math || token.sourceOwner === "raw") {
8180
8223
  return stripDisplayMathDelimiters(token.source);
@@ -8249,7 +8292,7 @@ ${body}
8249
8292
  \\end{equation}`;
8250
8293
  }
8251
8294
  if (token.sourceOwner === "editor") {
8252
- return mirrorBuTeXOperatorsInTex(token.source, { target: "compile" });
8295
+ return editorMathLatexForCompile(token);
8253
8296
  }
8254
8297
  if (!token.math || token.sourceOwner === "raw") {
8255
8298
  return token.source;
@@ -8836,7 +8879,7 @@ function remapSelectionAfterRangeMove(selection, direction) {
8836
8879
 
8837
8880
  // src/document/previewModel.ts
8838
8881
  function mathTex(token, equationSide, digitForm) {
8839
- return mathTokenSourceForSide(token, equationSide, digitForm);
8882
+ return mathTokenSourceForSide(token, equationSide, digitForm, true);
8840
8883
  }
8841
8884
  function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
8842
8885
  return field.tokens.map((token) => {