@drghaliasri/butex 8.0.3 → 8.1.0

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.
@@ -162,12 +162,14 @@ type MathObject2Json = {
162
162
  source_owner?: 'imported-structured' | 'editor';
163
163
  label_enabled?: boolean;
164
164
  label?: string;
165
+ numbered?: boolean;
165
166
  };
166
167
  /** Positional metadata for a raw-only span that has no structured equation AST. */
167
168
  type RawMathObject2Json = {
168
169
  node_type: 'RawMathObject';
169
170
  label_enabled?: boolean;
170
171
  label?: string;
172
+ numbered?: boolean;
171
173
  };
172
174
  type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
173
175
  type ReferenceFieldSeparator = ',' | '،';
@@ -299,6 +301,8 @@ type MathToken2 = {
299
301
  /** When true on display math, export as equation env with \\label. */
300
302
  labelEnabled?: boolean;
301
303
  label?: string;
304
+ /** Independent display-equation numbering override; absent means legacy semantics. */
305
+ numbered?: boolean;
302
306
  };
303
307
  type CiteToken2 = {
304
308
  id: string;
@@ -400,6 +404,7 @@ type PreviewInline2 = {
400
404
  display: boolean;
401
405
  output: DocumentMathOutput;
402
406
  editable: boolean;
407
+ numberLabel?: string;
403
408
  } | {
404
409
  kind: 'cite';
405
410
  id: string;
@@ -682,6 +687,8 @@ type EquationDrawerProps = {
682
687
  responsiveMode?: ButexResponsiveMode;
683
688
  labelEnabled?: boolean;
684
689
  label?: string;
690
+ numbered?: boolean;
691
+ onNumberedChange?: (numbered: boolean) => void;
685
692
  labels?: DocumentLabelEntry[];
686
693
  references?: Reference2[];
687
694
  ownerId?: string;
@@ -692,7 +699,7 @@ type EquationDrawerProps = {
692
699
  onSave: (session: EditorSession) => void;
693
700
  onDelete?: () => void;
694
701
  };
695
- declare function EquationDrawer({ debug, session, reason, mathMode, canDelete, equationSide, uiLocale, responsiveMode, labelEnabled, label, labels, references, ownerId, onLabelEnabledChange, onLabelChange, onMathModeChange, onClose, onSave, onDelete, }: EquationDrawerProps): react_jsx_runtime.JSX.Element;
702
+ declare function EquationDrawer({ debug, session, reason, mathMode, canDelete, equationSide, uiLocale, responsiveMode, labelEnabled, label, numbered, onNumberedChange, labels, references, ownerId, onLabelEnabledChange, onLabelChange, onMathModeChange, onClose, onSave, onDelete, }: EquationDrawerProps): react_jsx_runtime.JSX.Element;
696
703
 
697
704
  type InlineFieldProps = {
698
705
  field: InlineField2;
@@ -162,12 +162,14 @@ type MathObject2Json = {
162
162
  source_owner?: 'imported-structured' | 'editor';
163
163
  label_enabled?: boolean;
164
164
  label?: string;
165
+ numbered?: boolean;
165
166
  };
166
167
  /** Positional metadata for a raw-only span that has no structured equation AST. */
167
168
  type RawMathObject2Json = {
168
169
  node_type: 'RawMathObject';
169
170
  label_enabled?: boolean;
170
171
  label?: string;
172
+ numbered?: boolean;
171
173
  };
172
174
  type DocumentMathObjectJson = MathObject2Json | RawMathObject2Json;
173
175
  type ReferenceFieldSeparator = ',' | '،';
@@ -299,6 +301,8 @@ type MathToken2 = {
299
301
  /** When true on display math, export as equation env with \\label. */
300
302
  labelEnabled?: boolean;
301
303
  label?: string;
304
+ /** Independent display-equation numbering override; absent means legacy semantics. */
305
+ numbered?: boolean;
302
306
  };
303
307
  type CiteToken2 = {
304
308
  id: string;
@@ -400,6 +404,7 @@ type PreviewInline2 = {
400
404
  display: boolean;
401
405
  output: DocumentMathOutput;
402
406
  editable: boolean;
407
+ numberLabel?: string;
403
408
  } | {
404
409
  kind: 'cite';
405
410
  id: string;
@@ -682,6 +687,8 @@ type EquationDrawerProps = {
682
687
  responsiveMode?: ButexResponsiveMode;
683
688
  labelEnabled?: boolean;
684
689
  label?: string;
690
+ numbered?: boolean;
691
+ onNumberedChange?: (numbered: boolean) => void;
685
692
  labels?: DocumentLabelEntry[];
686
693
  references?: Reference2[];
687
694
  ownerId?: string;
@@ -692,7 +699,7 @@ type EquationDrawerProps = {
692
699
  onSave: (session: EditorSession) => void;
693
700
  onDelete?: () => void;
694
701
  };
695
- declare function EquationDrawer({ debug, session, reason, mathMode, canDelete, equationSide, uiLocale, responsiveMode, labelEnabled, label, labels, references, ownerId, onLabelEnabledChange, onLabelChange, onMathModeChange, onClose, onSave, onDelete, }: EquationDrawerProps): react_jsx_runtime.JSX.Element;
702
+ declare function EquationDrawer({ debug, session, reason, mathMode, canDelete, equationSide, uiLocale, responsiveMode, labelEnabled, label, numbered, onNumberedChange, labels, references, ownerId, onLabelEnabledChange, onLabelChange, onMathModeChange, onClose, onSave, onDelete, }: EquationDrawerProps): react_jsx_runtime.JSX.Element;
696
703
 
697
704
  type InlineFieldProps = {
698
705
  field: InlineField2;
@@ -875,82 +875,79 @@ function refTokenLatex(keys, refCommand) {
875
875
  const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
876
876
  return `${command}{${keys.join(",")}}`;
877
877
  }
878
- function collectDocumentLabels(document2) {
879
- const entries = [];
878
+ function implicitReferenceKey(kind, ownerId, unitId) {
879
+ const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
880
+ const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
881
+ return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
882
+ }
883
+ function supportsSingleEquationNumbering(token) {
884
+ return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
885
+ }
886
+ function isNumberedEquation(token) {
887
+ if (!supportsSingleEquationNumbering(token)) return false;
888
+ if (typeof token.numbered === "boolean") return token.numbered;
889
+ return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
890
+ }
891
+ function isNumberedFloat(block) {
892
+ return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
893
+ }
894
+ function collectDocumentReferenceTargets(document2) {
895
+ const targets = [];
880
896
  const counters = { fig: 0, tab: 0, eq: 0 };
881
- function pushEqFromField(tokens) {
882
- for (const token of tokens) {
883
- if (token.kind !== "math") {
884
- continue;
885
- }
886
- if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
887
- counters.eq += 1;
888
- entries.push({
889
- key: token.label.trim(),
890
- kind: "eq",
891
- caption: "",
892
- ownerId: token.id,
893
- number: counters.eq
894
- });
897
+ function append(kind, ownerId, caption, numbered, manualKey = "") {
898
+ if (numbered) counters[kind] += 1;
899
+ targets.push({
900
+ key: implicitReferenceKey(kind, ownerId),
901
+ kind,
902
+ ownerId,
903
+ caption,
904
+ number: numbered ? counters[kind] : null,
905
+ ...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
906
+ });
907
+ }
908
+ function visitField(field) {
909
+ for (const token of field.tokens) {
910
+ if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
911
+ append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
895
912
  }
896
913
  }
897
914
  }
898
915
  function walk(blocks) {
899
916
  for (const block of blocks) {
900
- if (block.kind === "image") {
901
- if (block.labelEnabled && block.label.trim().length > 0) {
902
- counters.fig += 1;
903
- entries.push({
904
- key: block.label.trim(),
905
- kind: "fig",
906
- caption: block.captionEnabled ? block.caption : "",
907
- ownerId: block.id,
908
- number: counters.fig
909
- });
910
- }
911
- if (block.captionEnabled) {
912
- pushEqFromField(block.captionField.tokens);
913
- }
914
- }
915
- if (block.kind === "table") {
916
- if (block.labelEnabled && block.label.trim().length > 0) {
917
- counters.tab += 1;
918
- entries.push({
919
- key: block.label.trim(),
920
- kind: "tab",
921
- caption: block.captionEnabled ? block.caption : "",
922
- ownerId: block.id,
923
- number: counters.tab
924
- });
925
- }
926
- if (block.captionEnabled) {
927
- pushEqFromField(block.captionField.tokens);
928
- }
929
- for (const row of block.rows) {
930
- for (const cell of row) {
931
- pushEqFromField(cell.tokens);
932
- }
917
+ if (block.kind === "image" || block.kind === "table") {
918
+ append(
919
+ block.kind === "image" ? "fig" : "tab",
920
+ block.id,
921
+ block.captionEnabled ? block.caption : "",
922
+ isNumberedFloat(block),
923
+ block.labelEnabled ? block.label : ""
924
+ );
925
+ if (block.captionEnabled) visitField(block.captionField);
926
+ if (block.kind === "table") {
927
+ for (const row of block.rows) for (const cell of row) visitField(cell);
933
928
  }
934
- }
935
- if (block.kind === "textBlock") {
936
- pushEqFromField(block.field.tokens);
937
- }
938
- if (block.kind === "list") {
929
+ } else if (block.kind === "textBlock") {
930
+ visitField(block.field);
931
+ } else if (block.kind === "list") {
939
932
  for (const item of block.items) {
940
- pushEqFromField(item.field.tokens);
933
+ visitField(item.field);
941
934
  walk(item.blocks);
942
935
  }
943
936
  }
944
937
  }
945
938
  }
946
939
  walk(document2.blocks);
947
- return entries;
940
+ return targets;
941
+ }
942
+ function collectDocumentLabels(document2) {
943
+ return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
948
944
  }
949
945
  function labelNumberMap(document2) {
950
946
  const map = /* @__PURE__ */ new Map();
951
- for (const entry of collectDocumentLabels(document2)) {
952
- if (!map.has(entry.key)) {
953
- map.set(entry.key, { kind: entry.kind, number: entry.number });
947
+ for (const target of collectDocumentReferenceTargets(document2)) {
948
+ if (target.number === null) continue;
949
+ for (const key of [target.key, target.manualKey]) {
950
+ if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
954
951
  }
955
952
  }
956
953
  return map;
@@ -1004,8 +1001,12 @@ function stripDisplayMathDelimiters(source) {
1004
1001
  if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
1005
1002
  return trimmed.slice(2, -2).trim();
1006
1003
  }
1007
- if (trimmed.startsWith("\\begin{equation}") && trimmed.endsWith("\\end{equation}")) {
1008
- return trimmed.slice("\\begin{equation}".length, -"\\end{equation}".length).trim();
1004
+ for (const environment of ["equation", "equation*"]) {
1005
+ const opening = `\\begin{${environment}}`;
1006
+ const closing = `\\end{${environment}}`;
1007
+ if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
1008
+ return trimmed.slice(opening.length, -closing.length).trim();
1009
+ }
1009
1010
  }
1010
1011
  return trimmed;
1011
1012
  }
@@ -1398,7 +1399,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
1398
1399
  editable: true,
1399
1400
  sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
1400
1401
  ...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
1401
- ...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
1402
+ ...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
1403
+ ...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
1402
1404
  });
1403
1405
  } else {
1404
1406
  tokens.push({
@@ -1413,7 +1415,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
1413
1415
  reason: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u062D\u0641\u0648\u0638\u0629 \u0643\u0646\u0635 \u062E\u0627\u0645 \u0641\u0642\u0637 \u062D\u0627\u0644\u064A\u0627",
1414
1416
  sourceOwner: "raw",
1415
1417
  ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
1416
- ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
1418
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
1419
+ ...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
1417
1420
  });
1418
1421
  }
1419
1422
  index = span.end;
@@ -9489,6 +9492,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
9489
9492
  if (current.label !== void 0) {
9490
9493
  replaced.label = current.label;
9491
9494
  }
9495
+ if (current.numbered !== void 0) {
9496
+ replaced.numbered = current.numbered;
9497
+ }
9492
9498
  field.tokens[index] = replaced;
9493
9499
  return true;
9494
9500
  });
@@ -9708,6 +9714,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
9708
9714
  if (typeof patch.label === "string") {
9709
9715
  token.label = patch.label;
9710
9716
  }
9717
+ if (typeof patch.numbered === "boolean") {
9718
+ token.numbered = patch.numbered;
9719
+ }
9711
9720
  return true;
9712
9721
  });
9713
9722
  return next;
@@ -10025,12 +10034,13 @@ function serializeField(field) {
10025
10034
  }
10026
10035
  value += token.source;
10027
10036
  if (!token.math || token.sourceOwner === "raw") {
10028
- if (token.labelEnabled !== void 0 || token.label !== void 0) {
10037
+ if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
10029
10038
  hasPersistedMath = true;
10030
10039
  mathObjects.push({
10031
10040
  node_type: "RawMathObject",
10032
10041
  ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
10033
- ...token.label !== void 0 ? { label: token.label } : {}
10042
+ ...token.label !== void 0 ? { label: token.label } : {},
10043
+ ...token.numbered !== void 0 ? { numbered: token.numbered } : {}
10034
10044
  });
10035
10045
  } else {
10036
10046
  mathObjects.push(null);
@@ -10043,7 +10053,8 @@ function serializeField(field) {
10043
10053
  ...token.sourceSide ? { source_side: token.sourceSide } : {},
10044
10054
  source_owner: token.sourceOwner,
10045
10055
  ...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
10046
- ...token.label !== void 0 ? { label: token.label } : {}
10056
+ ...token.label !== void 0 ? { label: token.label } : {},
10057
+ ...token.numbered !== void 0 ? { numbered: token.numbered } : {}
10047
10058
  });
10048
10059
  }
10049
10060
  return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
@@ -10484,12 +10495,15 @@ function tokenLatex(token, labelKinds, previousToken) {
10484
10495
  if (token.kind === "ref") {
10485
10496
  return refTokenLatexForDocument(token, labelKinds, previousToken);
10486
10497
  }
10487
- if (token.display && token.labelEnabled && token.label && token.label.trim().length > 0) {
10498
+ if (isNumberedEquation(token)) {
10488
10499
  const body = mathBodyLatex(token);
10489
- return `\\begin{equation}
10490
- ${body}
10491
- \\label{${token.label.trim()}}
10492
- \\end{equation}`;
10500
+ const autoKey = implicitReferenceKey("eq", token.id);
10501
+ const aliases = [autoKey];
10502
+ if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
10503
+ return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
10504
+ }
10505
+ if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
10506
+ return "\\[" + mathBodyLatex(token) + "\\]";
10493
10507
  }
10494
10508
  if (token.sourceOwner === "editor") {
10495
10509
  return editorMathLatexForCompile(token);
@@ -10556,11 +10570,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
10556
10570
  if (hasCaption) {
10557
10571
  lines.push(` \\caption{${caption}}`);
10558
10572
  }
10559
- if (block.labelEnabled && block.label.trim().length > 0) {
10560
- if (!hasCaption) {
10561
- lines.push(` \\refstepcounter{${counter}}`);
10562
- }
10563
- lines.push(` \\label{${block.label.trim()}}`);
10573
+ const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
10574
+ if (hasCaption || hasManualLabel) {
10575
+ if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
10576
+ const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
10577
+ lines.push(" \\label{" + autoKey + "}");
10578
+ if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
10564
10579
  }
10565
10580
  return lines;
10566
10581
  }
@@ -10656,10 +10671,8 @@ ${meta.abstract.trim()}
10656
10671
  }
10657
10672
  function documentLabelKindMap(document2) {
10658
10673
  const map = /* @__PURE__ */ new Map();
10659
- for (const entry of collectDocumentLabels(document2)) {
10660
- if (!map.has(entry.key)) {
10661
- map.set(entry.key, entry.kind);
10662
- }
10674
+ for (const [key, entry] of labelNumberMap(document2)) {
10675
+ map.set(key, entry.kind);
10663
10676
  }
10664
10677
  return map;
10665
10678
  }
@@ -10758,10 +10771,17 @@ function validateToken(context, token, path, blockId) {
10758
10771
  return;
10759
10772
  }
10760
10773
  validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
10774
+ if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
10775
+ addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
10776
+ }
10761
10777
  if (!token.labelEnabled) {
10762
10778
  return;
10763
10779
  }
10764
- if (!token.display) {
10780
+ if (!supportsSingleEquationNumbering(token)) {
10781
+ addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
10782
+ return;
10783
+ }
10784
+ if (!isNumberedEquation(token)) {
10765
10785
  addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
10766
10786
  return;
10767
10787
  }
@@ -10859,7 +10879,7 @@ function validatePendingReferences(context) {
10859
10879
  for (const pending of context.pendingReferences) {
10860
10880
  for (const key of pending.token.keys) {
10861
10881
  const normalized = normalizeDocumentKey(key);
10862
- if (!isValidDocumentKey(normalized)) {
10882
+ if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
10863
10883
  addIssue(
10864
10884
  context,
10865
10885
  "missing_reference",
@@ -10958,6 +10978,18 @@ function validateDocument(document2) {
10958
10978
  resolved.blocks.forEach((block, index) => {
10959
10979
  validateBlock(context, block, `$.blocks[${String(index)}]`);
10960
10980
  });
10981
+ for (const target of collectDocumentReferenceTargets(resolved)) {
10982
+ if (target.number !== null && target.manualKey !== target.key) {
10983
+ registerKey(
10984
+ context,
10985
+ target.key,
10986
+ "$.automatic_labels",
10987
+ target.kind,
10988
+ target.kind === "eq" ? void 0 : target.ownerId,
10989
+ target.kind === "eq" ? target.ownerId : void 0
10990
+ );
10991
+ }
10992
+ }
10961
10993
  for (const diagnostic of resolved.diagnostics) {
10962
10994
  addIssue(context, "parser_diagnostic", diagnostic.path);
10963
10995
  }
@@ -11098,6 +11130,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
11098
11130
  })
11099
11131
  };
11100
11132
  }
11133
+ const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
11101
11134
  const island = {
11102
11135
  id: token.id,
11103
11136
  tex: mathTex(token, equationSide, previewOptions.digitForm),
@@ -11105,8 +11138,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
11105
11138
  output,
11106
11139
  editable: token.editable
11107
11140
  };
11141
+ const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
11142
+ documentDirection: previewOptions.documentDirection,
11143
+ digitForm: previewOptions.digitForm
11144
+ });
11108
11145
  islands.push(island);
11109
- return { kind: "math", ...island };
11146
+ return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
11110
11147
  });
11111
11148
  }
11112
11149
  function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
@@ -11129,12 +11166,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
11129
11166
  ...block.centered ? { centered: true } : {}
11130
11167
  };
11131
11168
  }
11132
- function floatNumberLabel(document2, key, previewOptions) {
11133
- if (!key || key.trim().length === 0) {
11134
- return void 0;
11135
- }
11136
- const hit = labelNumberMap(document2).get(key.trim());
11137
- if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
11169
+ function floatNumberLabel(document2, ownerId, previewOptions) {
11170
+ const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
11171
+ if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
11138
11172
  return void 0;
11139
11173
  }
11140
11174
  return formatFloatCaptionTitle(hit.kind, hit.number, {
@@ -11176,7 +11210,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
11176
11210
  id: block.id,
11177
11211
  rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
11178
11212
  ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
11179
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
11213
+ ...label.length > 0 ? { label } : {},
11214
+ ...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
11180
11215
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
11181
11216
  };
11182
11217
  }
@@ -11190,7 +11225,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
11190
11225
  options: block.options,
11191
11226
  centered: block.centered,
11192
11227
  ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
11193
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
11228
+ ...label.length > 0 ? { label } : {},
11229
+ ...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
11194
11230
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
11195
11231
  };
11196
11232
  }
@@ -14412,7 +14448,14 @@ function PreviewInlines({ inlines, output }) {
14412
14448
  if (inline.kind === "ref") {
14413
14449
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "butex-document-widget__preview-cite butex-document-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
14414
14450
  }
14415
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }, inline.id);
14451
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "butex-document-widget__preview-math-numbered", children: [
14452
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }),
14453
+ inline.numberLabel ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "butex-document-widget__preview-equation-number", children: [
14454
+ "(",
14455
+ inline.numberLabel,
14456
+ ")"
14457
+ ] }) : null
14458
+ ] }, inline.id);
14416
14459
  }) });
14417
14460
  }
14418
14461
  function isBodyPreviewBlock(block) {
@@ -18468,6 +18511,8 @@ function EquationDrawer({
18468
18511
  responsiveMode = "auto",
18469
18512
  labelEnabled = false,
18470
18513
  label = "",
18514
+ numbered = false,
18515
+ onNumberedChange,
18471
18516
  labels = [],
18472
18517
  references = [],
18473
18518
  ownerId = "",
@@ -18557,6 +18602,10 @@ function EquationDrawer({
18557
18602
  ] })
18558
18603
  ] }),
18559
18604
  mathMode === "display" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "butex-document-widget__float-meta", children: [
18605
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "butex-document-widget__float-meta-toggle", children: [
18606
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("input", { type: "checkbox", checked: numbered, onChange: (event) => onNumberedChange?.(event.currentTarget.checked) }),
18607
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: uiLocale === "ar" ? "\u062A\u0631\u0642\u064A\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Number equation" })
18608
+ ] }),
18560
18609
  /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "butex-document-widget__float-meta-toggle", children: [
18561
18610
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
18562
18611
  "input",
@@ -19080,13 +19129,14 @@ var import_react16 = require("react");
19080
19129
  var import_jsx_runtime18 = require("react/jsx-runtime");
19081
19130
  function RefPickerPopover({
19082
19131
  open,
19083
- labels,
19132
+ targets,
19084
19133
  initialKeys = [],
19085
19134
  initialRefCommand = "ref",
19086
19135
  uiLocale = "ar",
19087
19136
  digitForm = "arabicIndic",
19088
19137
  onClose,
19089
19138
  onConfirm,
19139
+ onNumberEquation,
19090
19140
  onManageLabels
19091
19141
  }) {
19092
19142
  const messages = documentMessages(uiLocale);
@@ -19123,22 +19173,19 @@ function RefPickerPopover({
19123
19173
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("strong", { children: messages.refPickerTitle }),
19124
19174
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", "data-dialog-initial-focus": true, className: "butex-document-widget__icon-btn", title: messages.close, "aria-label": messages.close, onClick: onClose, children: "\xD7" })
19125
19175
  ] }),
19126
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "butex-document-widget__dialog-body", children: labels.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("ul", { className: "butex-document-widget__cite-picker-list", children: labels.map((entry) => {
19127
- const checked = selected.includes(entry.key);
19128
- const title = formatFloatCaptionTitle(entry.kind, entry.number, {
19176
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "butex-document-widget__dialog-body", children: targets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("ul", { className: "butex-document-widget__cite-picker-list", children: targets.filter((entry) => entry.number !== null || entry.kind === "eq").map((entry) => {
19177
+ const checked = selected.includes(entry.key) || Boolean(entry.manualKey && selected.includes(entry.manualKey));
19178
+ const title = entry.number === null ? uiLocale === "ar" ? "\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u0631\u0642\u0645\u0629" : "Unnumbered equation" : formatFloatCaptionTitle(entry.kind, entry.number, {
19129
19179
  uiLocale,
19130
19180
  digitForm,
19131
19181
  documentDirection
19132
19182
  });
19133
19183
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("label", { className: "butex-document-widget__cite-picker-item", children: [
19134
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("input", { type: "radio", name: "butex-ref-key", checked, onChange: () => selectKey(entry.key, entry.kind) }),
19184
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null, onChange: () => selectKey(entry.key, entry.kind) }),
19135
19185
  /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("span", { children: [
19136
- /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("strong", { children: [
19137
- title,
19138
- " ",
19139
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__refs-item-key", children: entry.key })
19140
- ] }),
19141
- entry.caption ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null
19186
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("strong", { children: entry.kind === "eq" && entry.number !== null ? title.replace(/(\d+|[٠-٩]+)$/, "($1)") : title }),
19187
+ entry.caption ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null,
19188
+ entry.kind === "eq" && entry.number === null && onNumberEquation ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", onClick: () => onNumberEquation(entry.ownerId), children: uiLocale === "ar" ? "\u0631\u0642\u0651\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0623\u0648\u0644\u0627\u064B" : "Number equation first" }) : null
19142
19189
  ] })
19143
19190
  ] }) }, `${entry.kind}:${entry.ownerId}`);
19144
19191
  }) }) }),
@@ -21858,6 +21905,7 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
21858
21905
  const latex = documentLatex(documentNode, { digitForm });
21859
21906
  const documentJson = (0, import_react17.useMemo)(() => toDocumentJson(documentNode), [documentNode]);
21860
21907
  const documentLabels = (0, import_react17.useMemo)(() => collectDocumentLabels(documentNode), [documentNode]);
21908
+ const referenceTargets = (0, import_react17.useMemo)(() => collectDocumentReferenceTargets(documentNode), [documentNode]);
21861
21909
  const preview = (0, import_react17.useMemo)(
21862
21910
  () => documentPreview(documentNode, mathOutput, equationSide, {
21863
21911
  documentDirection,
@@ -22193,7 +22241,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22193
22241
  session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
22194
22242
  reason: null,
22195
22243
  labelEnabled: false,
22196
- label: ""
22244
+ label: "",
22245
+ numbered: false
22197
22246
  });
22198
22247
  }
22199
22248
  function openMath(token, origin) {
@@ -22218,7 +22267,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22218
22267
  session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
22219
22268
  reason: result.reason,
22220
22269
  labelEnabled: Boolean(token.labelEnabled),
22221
- label: token.label ?? ""
22270
+ label: token.label ?? "",
22271
+ numbered: isNumberedEquation(token)
22222
22272
  });
22223
22273
  return;
22224
22274
  }
@@ -22231,7 +22281,8 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22231
22281
  session: equationSessionWithDocumentDigits(result.session),
22232
22282
  reason: null,
22233
22283
  labelEnabled: Boolean(token.labelEnabled),
22234
- label: token.label ?? ""
22284
+ label: token.label ?? "",
22285
+ numbered: isNumberedEquation(token)
22235
22286
  });
22236
22287
  }
22237
22288
  function selectMobileView(view) {
@@ -22322,10 +22373,11 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22322
22373
  if (selectedMath.mathMode === "display") {
22323
22374
  next2 = updateMathTokenLabel(next2, selectedMath.tokenId, {
22324
22375
  labelEnabled: selectedMath.labelEnabled,
22325
- label: selectedMath.label
22376
+ label: selectedMath.label,
22377
+ numbered: selectedMath.numbered
22326
22378
  });
22327
22379
  } else {
22328
- next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "" });
22380
+ next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "", numbered: false });
22329
22381
  }
22330
22382
  pendingFocusRef.current = { kind: "math", tokenId: selectedMath.tokenId };
22331
22383
  applyDocument(next2, "immediate");
@@ -22370,10 +22422,11 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22370
22422
  0,
22371
22423
  fieldAfter.tokens.findIndex((token) => token.id === trailingTextTokenId) - 1
22372
22424
  )]?.id : null : fieldAfter?.tokens.filter((token) => token.kind === "math").at(-1)?.id ?? null;
22373
- if (insertedMathId && selectedMath.mathMode === "display" && selectedMath.labelEnabled) {
22425
+ if (insertedMathId && selectedMath.mathMode === "display") {
22374
22426
  next = updateMathTokenLabel(next, insertedMathId, {
22375
- labelEnabled: true,
22376
- label: selectedMath.label
22427
+ labelEnabled: selectedMath.labelEnabled,
22428
+ label: selectedMath.label,
22429
+ numbered: selectedMath.numbered
22377
22430
  });
22378
22431
  }
22379
22432
  if (insertedMathId) {
@@ -22825,10 +22878,12 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22825
22878
  responsiveMode,
22826
22879
  labelEnabled: selectedMath.labelEnabled,
22827
22880
  label: selectedMath.label,
22881
+ numbered: selectedMath.numbered,
22882
+ onNumberedChange: (numbered) => setSelectedMath((current) => current ? { ...current, numbered } : current),
22828
22883
  labels: documentLabels,
22829
22884
  references: documentNode.references,
22830
22885
  ownerId: selectedMath.tokenId ?? void 0,
22831
- onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled } : current),
22886
+ onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled, numbered: enabled || current.numbered } : current),
22832
22887
  onLabelChange: (nextLabel) => setSelectedMath((current) => current ? { ...current, label: nextLabel } : current),
22833
22888
  onMathModeChange: (mode) => setSelectedMath((current) => current ? { ...current, mathMode: mode } : current),
22834
22889
  onClose: closeEquationAndRestoreOrigin,
@@ -22856,13 +22911,16 @@ var ButexDocumentEditor = (0, import_react17.forwardRef)(
22856
22911
  RefPickerPopover,
22857
22912
  {
22858
22913
  open: refPicker !== null,
22859
- labels: documentLabels,
22914
+ targets: referenceTargets,
22860
22915
  initialKeys: refPicker?.keys ?? [],
22861
22916
  initialRefCommand: refPicker?.refCommand ?? "ref",
22862
22917
  uiLocale,
22863
22918
  digitForm,
22864
22919
  onClose: () => setRefPicker(null),
22865
22920
  onConfirm: confirmRefKeys,
22921
+ onNumberEquation: (tokenId) => {
22922
+ applyDocument(updateMathTokenLabel(documentRef.current, tokenId, { numbered: true }), "immediate");
22923
+ },
22866
22924
  onManageLabels: () => {
22867
22925
  setRefPicker(null);
22868
22926
  openLabelsManager();