@drghaliasri/butex 7.0.3 → 7.0.4

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.
@@ -805,6 +805,10 @@ function defaultFloatMeta() {
805
805
  centered: true,
806
806
  captionEnabled: false,
807
807
  caption: "",
808
+ captionField: {
809
+ id: document2Id("field"),
810
+ tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
811
+ },
808
812
  labelEnabled: false,
809
813
  label: ""
810
814
  };
@@ -863,15 +867,20 @@ function collectDocument2Labels(document2) {
863
867
  }
864
868
  function walk(blocks) {
865
869
  for (const block of blocks) {
866
- if (block.kind === "image" && block.labelEnabled && block.label.trim().length > 0) {
867
- counters.fig += 1;
868
- entries.push({
869
- key: block.label.trim(),
870
- kind: "fig",
871
- caption: block.captionEnabled ? block.caption : "",
872
- ownerId: block.id,
873
- number: counters.fig
874
- });
870
+ if (block.kind === "image") {
871
+ if (block.labelEnabled && block.label.trim().length > 0) {
872
+ counters.fig += 1;
873
+ entries.push({
874
+ key: block.label.trim(),
875
+ kind: "fig",
876
+ caption: block.captionEnabled ? block.caption : "",
877
+ ownerId: block.id,
878
+ number: counters.fig
879
+ });
880
+ }
881
+ if (block.captionEnabled) {
882
+ pushEqFromField(block.captionField.tokens);
883
+ }
875
884
  }
876
885
  if (block.kind === "table") {
877
886
  if (block.labelEnabled && block.label.trim().length > 0) {
@@ -884,6 +893,9 @@ function collectDocument2Labels(document2) {
884
893
  number: counters.tab
885
894
  });
886
895
  }
896
+ if (block.captionEnabled) {
897
+ pushEqFromField(block.captionField.tokens);
898
+ }
887
899
  for (const row of block.rows) {
888
900
  for (const cell of row) {
889
901
  pushEqFromField(cell.tokens);
@@ -976,6 +988,14 @@ function applyFloatMetaPatch(block, patch) {
976
988
  }
977
989
  if (typeof patch.caption === "string") {
978
990
  block.caption = patch.caption;
991
+ const existingText = block.captionField.tokens.find((token) => token.kind === "text");
992
+ block.captionField.tokens = [
993
+ {
994
+ id: existingText?.id ?? document2Id("text"),
995
+ kind: "text",
996
+ text: patch.caption
997
+ }
998
+ ];
979
999
  }
980
1000
  if (typeof patch.labelEnabled === "boolean") {
981
1001
  block.labelEnabled = patch.labelEnabled;
@@ -1495,6 +1515,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
1495
1515
  ...metadataFromJson(json.metadata)
1496
1516
  };
1497
1517
  }
1518
+ function captionFieldFromJson(json, options, path, diagnostics, identities) {
1519
+ const caption = typeof json.caption === "string" ? json.caption : "";
1520
+ return applyImportedInlineIds(
1521
+ createInlineField2(
1522
+ caption,
1523
+ json.caption_math_objects ?? [],
1524
+ options,
1525
+ `${path}.caption`,
1526
+ diagnostics,
1527
+ json.caption_formats ?? []
1528
+ ),
1529
+ json.caption_inline_ids,
1530
+ identities
1531
+ );
1532
+ }
1498
1533
  function parseTableBlock(json, options, path, diagnostics, identities) {
1499
1534
  if (!Array.isArray(json.rows)) {
1500
1535
  throw new Error("\\begin{tabular} requires rows array");
@@ -1521,6 +1556,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
1521
1556
  if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
1522
1557
  pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
1523
1558
  }
1559
+ const floatMeta = parseFloatMetaFromJson(json);
1524
1560
  return {
1525
1561
  id: blockIdFromJson(json, identities),
1526
1562
  kind: "table",
@@ -1528,13 +1564,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
1528
1564
  closing: "\\end{tabular}",
1529
1565
  columns: typeof json.columns === "string" ? json.columns : "",
1530
1566
  rows,
1531
- ...parseFloatMetaFromJson(json),
1567
+ ...floatMeta,
1568
+ captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
1532
1569
  ...metadataFromJson(json.metadata)
1533
1570
  };
1534
1571
  }
1535
- function parseImageBlock(json, identities) {
1572
+ function parseImageBlock(json, options, path, diagnostics, identities) {
1536
1573
  const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
1537
1574
  const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
1575
+ const floatMeta = parseFloatMetaFromJson(json);
1538
1576
  return {
1539
1577
  id: blockIdFromJson(json, identities),
1540
1578
  kind: "image",
@@ -1542,7 +1580,8 @@ function parseImageBlock(json, identities) {
1542
1580
  value,
1543
1581
  ...assetId !== void 0 ? { assetId } : {},
1544
1582
  options: isRecordOfStrings(json.options) ? json.options : {},
1545
- ...parseFloatMetaFromJson(json),
1583
+ ...floatMeta,
1584
+ captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
1546
1585
  ...metadataFromJson(json.metadata)
1547
1586
  };
1548
1587
  }
@@ -1575,7 +1614,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
1575
1614
  return parseTableBlock(json, options, path, diagnostics, identities);
1576
1615
  }
1577
1616
  if (json.command === "\\includegraphics") {
1578
- return parseImageBlock(json, identities);
1617
+ return parseImageBlock(json, options, path, diagnostics, identities);
1579
1618
  }
1580
1619
  if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
1581
1620
  return parseBibliographyBlock(json, identities);
@@ -4602,6 +4641,20 @@ function cloneToken(token) {
4602
4641
  function cloneField(field) {
4603
4642
  return { id: field.id, tokens: field.tokens.map(cloneToken) };
4604
4643
  }
4644
+ function inlineFieldSource(field) {
4645
+ return field.tokens.map((token) => {
4646
+ if (token.kind === "text") {
4647
+ return token.text;
4648
+ }
4649
+ if (token.kind === "cite") {
4650
+ return citeTokenLatex(token.keys);
4651
+ }
4652
+ if (token.kind === "ref") {
4653
+ return refTokenLatex(token.keys, token.refCommand);
4654
+ }
4655
+ return token.source;
4656
+ }).join("");
4657
+ }
4605
4658
  function cloneBlock(block) {
4606
4659
  const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
4607
4660
  if (block.kind === "textBlock") {
@@ -4619,10 +4672,20 @@ function cloneBlock(block) {
4619
4672
  };
4620
4673
  }
4621
4674
  if (block.kind === "table") {
4622
- return { ...block, ...metadata, rows: block.rows.map((row) => row.map(cloneField)) };
4675
+ return {
4676
+ ...block,
4677
+ ...metadata,
4678
+ rows: block.rows.map((row) => row.map(cloneField)),
4679
+ captionField: cloneField(block.captionField)
4680
+ };
4623
4681
  }
4624
4682
  if (block.kind === "image") {
4625
- return { ...block, ...metadata, options: { ...block.options } };
4683
+ return {
4684
+ ...block,
4685
+ ...metadata,
4686
+ options: { ...block.options },
4687
+ captionField: cloneField(block.captionField)
4688
+ };
4626
4689
  }
4627
4690
  return { ...block, ...metadata };
4628
4691
  }
@@ -4635,6 +4698,13 @@ function cloneDocument(document2) {
4635
4698
  diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
4636
4699
  };
4637
4700
  }
4701
+ function visitCaptionField(block, visitor) {
4702
+ if (!visitor(block.captionField)) {
4703
+ return false;
4704
+ }
4705
+ block.caption = inlineFieldSource(block.captionField);
4706
+ return true;
4707
+ }
4638
4708
  function visitFields(blocks, visitor) {
4639
4709
  for (const block of blocks) {
4640
4710
  if (block.kind === "textBlock") {
@@ -4655,6 +4725,11 @@ function visitFields(blocks, visitor) {
4655
4725
  }
4656
4726
  }
4657
4727
  }
4728
+ if (visitCaptionField(block, visitor)) {
4729
+ return true;
4730
+ }
4731
+ } else if (block.kind === "image" && visitCaptionField(block, visitor)) {
4732
+ return true;
4658
4733
  }
4659
4734
  }
4660
4735
  return false;
@@ -5532,6 +5607,9 @@ function findField(blocks, fieldId) {
5532
5607
  if (block.kind === "textBlock" && block.field.id === fieldId) {
5533
5608
  return block.field;
5534
5609
  }
5610
+ if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
5611
+ return block.captionField;
5612
+ }
5535
5613
  if (block.kind === "list") {
5536
5614
  for (const item of block.items) {
5537
5615
  if (item.field.id === fieldId) {
@@ -5570,26 +5648,30 @@ function findBlock(blocks, blockId) {
5570
5648
  }
5571
5649
  return null;
5572
5650
  }
5651
+ function collectFieldIdentity(field, sets) {
5652
+ sets.fields.add(field.id);
5653
+ field.tokens.forEach((token) => sets.tokens.add(token.id));
5654
+ }
5573
5655
  function collectIdentitySets(blocks, sets) {
5574
5656
  for (const block of blocks) {
5575
5657
  sets.blocks.add(block.id);
5576
5658
  if (block.kind === "textBlock") {
5577
- sets.fields.add(block.field.id);
5578
- block.field.tokens.forEach((token) => sets.tokens.add(token.id));
5659
+ collectFieldIdentity(block.field, sets);
5579
5660
  } else if (block.kind === "list") {
5580
5661
  for (const item of block.items) {
5581
5662
  sets.items.add(item.id);
5582
- sets.fields.add(item.field.id);
5583
- item.field.tokens.forEach((token) => sets.tokens.add(token.id));
5663
+ collectFieldIdentity(item.field, sets);
5584
5664
  collectIdentitySets(item.blocks, sets);
5585
5665
  }
5586
5666
  } else if (block.kind === "table") {
5667
+ collectFieldIdentity(block.captionField, sets);
5587
5668
  for (const row of block.rows) {
5588
5669
  for (const field of row) {
5589
- sets.fields.add(field.id);
5590
- field.tokens.forEach((token) => sets.tokens.add(token.id));
5670
+ collectFieldIdentity(field, sets);
5591
5671
  }
5592
5672
  }
5673
+ } else if (block.kind === "image") {
5674
+ collectFieldIdentity(block.captionField, sets);
5593
5675
  }
5594
5676
  }
5595
5677
  }
@@ -5924,6 +6006,37 @@ function applyReferenceFields(reference, command) {
5924
6006
  reference.fieldSeparator = command.field_separator;
5925
6007
  }
5926
6008
  }
6009
+ function replaceCitationKey(document2, previousKey, nextKey) {
6010
+ function replaceInField(field) {
6011
+ for (const token of field.tokens) {
6012
+ if (token.kind === "cite") {
6013
+ token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
6014
+ }
6015
+ }
6016
+ }
6017
+ function visitBlocks(blocks) {
6018
+ for (const block of blocks) {
6019
+ if (block.kind === "textBlock") {
6020
+ replaceInField(block.field);
6021
+ } else if (block.kind === "table") {
6022
+ replaceInField(block.captionField);
6023
+ for (const row of block.rows) {
6024
+ for (const cell of row) {
6025
+ replaceInField(cell);
6026
+ }
6027
+ }
6028
+ } else if (block.kind === "image") {
6029
+ replaceInField(block.captionField);
6030
+ } else if (block.kind === "list") {
6031
+ for (const item of block.items) {
6032
+ replaceInField(item.field);
6033
+ visitBlocks(item.blocks);
6034
+ }
6035
+ }
6036
+ }
6037
+ }
6038
+ visitBlocks(document2.blocks);
6039
+ }
5927
6040
  function applyArticleCommand(document2, command) {
5928
6041
  if (command.op === "update_document_meta") {
5929
6042
  document2.meta = {
@@ -5952,7 +6065,10 @@ function applyArticleCommand(document2, command) {
5952
6065
  const target = document2.references[targetIndex];
5953
6066
  if (command.op === "update_reference") {
5954
6067
  if (command.key !== void 0) {
5955
- target.key = validateReferenceKey(document2, command.key, target.id);
6068
+ const previousKey = target.key;
6069
+ const nextKey = validateReferenceKey(document2, command.key, target.id);
6070
+ target.key = nextKey;
6071
+ replaceCitationKey(document2, previousKey, nextKey);
5956
6072
  }
5957
6073
  applyReferenceFields(target, command);
5958
6074
  return;
@@ -6381,10 +6497,15 @@ function insertTable(document2, command) {
6381
6497
  columns: command.columns,
6382
6498
  rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
6383
6499
  ...defaultFloatMeta(),
6384
- ...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
6385
6500
  ...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
6386
6501
  ...command.metadata ? { metadata: { ...command.metadata } } : {}
6387
6502
  };
6503
+ if (command.caption !== void 0) {
6504
+ applyFloatMetaPatch(block, {
6505
+ caption: command.caption,
6506
+ captionEnabled: command.caption.trim().length > 0
6507
+ });
6508
+ }
6388
6509
  document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
6389
6510
  }
6390
6511
  function checkCell(table, rowIndex, columnIndex) {
@@ -6529,6 +6650,15 @@ function fieldJson(field) {
6529
6650
  ...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
6530
6651
  };
6531
6652
  }
6653
+ function captionJson(field) {
6654
+ const serialized = serializeField(field);
6655
+ return {
6656
+ caption: serialized.value,
6657
+ caption_inline_ids: serialized.inlineIds,
6658
+ ...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
6659
+ ...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
6660
+ };
6661
+ }
6532
6662
  function listItemJson(item) {
6533
6663
  const field = fieldJson(item.field);
6534
6664
  return {
@@ -6573,7 +6703,7 @@ function blockJson(block) {
6573
6703
  ...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
6574
6704
  centered: block.centered,
6575
6705
  caption_enabled: block.captionEnabled,
6576
- caption: block.caption,
6706
+ ...captionJson(block.captionField),
6577
6707
  label_enabled: block.labelEnabled,
6578
6708
  label: block.label,
6579
6709
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
@@ -6588,7 +6718,7 @@ function blockJson(block) {
6588
6718
  options: { ...block.options },
6589
6719
  centered: block.centered,
6590
6720
  caption_enabled: block.captionEnabled,
6591
- caption: block.caption,
6721
+ ...captionJson(block.captionField),
6592
6722
  label_enabled: block.labelEnabled,
6593
6723
  label: block.label,
6594
6724
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
@@ -6915,10 +7045,15 @@ function applyBasicCommand(document2, command) {
6915
7045
  assetId: command.asset_id,
6916
7046
  options: { width: "0.8\\columnwidth" },
6917
7047
  ...defaultFloatMeta(),
6918
- ...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
6919
7048
  ...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
6920
7049
  ...command.metadata ? { metadata: { ...command.metadata } } : {}
6921
7050
  };
7051
+ if (command.caption !== void 0) {
7052
+ applyFloatMetaPatch(block, {
7053
+ caption: command.caption,
7054
+ captionEnabled: command.caption.trim().length > 0
7055
+ });
7056
+ }
6922
7057
  document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
6923
7058
  }
6924
7059
  function applyDocument2Command(json, commandInput) {
@@ -7012,6 +7147,119 @@ function document2Outline(json) {
7012
7147
  });
7013
7148
  }
7014
7149
 
7150
+ // src/document2/introspection.ts
7151
+ function appendUnique(target, seen, values) {
7152
+ for (const value of values) {
7153
+ if (!seen.has(value)) {
7154
+ seen.add(value);
7155
+ target.push(value);
7156
+ }
7157
+ }
7158
+ }
7159
+ function getDocument2References(document2) {
7160
+ return document2.references.map((reference) => ({
7161
+ key: reference.key,
7162
+ authors: reference.authors,
7163
+ title: reference.title,
7164
+ year: reference.year,
7165
+ venue: reference.venue,
7166
+ url: reference.url,
7167
+ field_separator: reference.fieldSeparator
7168
+ }));
7169
+ }
7170
+ function getDocument2ReferenceIndex(document2) {
7171
+ const referenceKeys = new Set(document2.references.map((reference) => reference.key));
7172
+ const labelEntries = collectDocument2Labels(document2);
7173
+ const labelKeys = new Set(labelEntries.map((entry) => entry.key));
7174
+ const citations = [];
7175
+ const crossReferences = [];
7176
+ const tokenLocations = /* @__PURE__ */ new Map();
7177
+ const unresolvedCitationKeys = [];
7178
+ const unresolvedCrossReferenceKeys = [];
7179
+ const seenCitationKeys = /* @__PURE__ */ new Set();
7180
+ const seenCrossReferenceKeys = /* @__PURE__ */ new Set();
7181
+ function visitField(blockId, field) {
7182
+ for (const token of field.tokens) {
7183
+ tokenLocations.set(token.id, { block_id: blockId, field_id: field.id });
7184
+ if (token.kind === "cite") {
7185
+ const unresolvedKeys = token.keys.filter((key) => !referenceKeys.has(key));
7186
+ citations.push({
7187
+ kind: "cite",
7188
+ block_id: blockId,
7189
+ field_id: field.id,
7190
+ token_id: token.id,
7191
+ keys: [...token.keys],
7192
+ unresolved_keys: unresolvedKeys
7193
+ });
7194
+ appendUnique(unresolvedCitationKeys, seenCitationKeys, unresolvedKeys);
7195
+ } else if (token.kind === "ref") {
7196
+ const unresolvedKeys = token.keys.filter((key) => !labelKeys.has(key));
7197
+ crossReferences.push({
7198
+ kind: "ref",
7199
+ ref_command: token.refCommand,
7200
+ block_id: blockId,
7201
+ field_id: field.id,
7202
+ token_id: token.id,
7203
+ keys: [...token.keys],
7204
+ unresolved_keys: unresolvedKeys
7205
+ });
7206
+ appendUnique(unresolvedCrossReferenceKeys, seenCrossReferenceKeys, unresolvedKeys);
7207
+ }
7208
+ }
7209
+ }
7210
+ function visitBlocks(blocks) {
7211
+ for (const block of blocks) {
7212
+ if (block.kind === "textBlock") {
7213
+ visitField(block.id, block.field);
7214
+ } else if (block.kind === "table") {
7215
+ visitField(block.id, block.captionField);
7216
+ for (const row of block.rows) {
7217
+ for (const cell of row) {
7218
+ visitField(block.id, cell);
7219
+ }
7220
+ }
7221
+ } else if (block.kind === "image") {
7222
+ visitField(block.id, block.captionField);
7223
+ } else if (block.kind === "list") {
7224
+ for (const item of block.items) {
7225
+ visitField(block.id, item.field);
7226
+ visitBlocks(item.blocks);
7227
+ }
7228
+ }
7229
+ }
7230
+ }
7231
+ visitBlocks(document2.blocks);
7232
+ const labels = labelEntries.map((entry) => {
7233
+ if (entry.kind !== "eq") {
7234
+ return {
7235
+ key: entry.key,
7236
+ kind: entry.kind,
7237
+ caption: entry.caption,
7238
+ number: entry.number,
7239
+ block_id: entry.ownerId
7240
+ };
7241
+ }
7242
+ const location = tokenLocations.get(entry.ownerId);
7243
+ return {
7244
+ key: entry.key,
7245
+ kind: entry.kind,
7246
+ caption: entry.caption,
7247
+ number: entry.number,
7248
+ ...location ? { block_id: location.block_id, field_id: location.field_id } : {},
7249
+ token_id: entry.ownerId
7250
+ };
7251
+ });
7252
+ return {
7253
+ citations,
7254
+ cross_references: crossReferences,
7255
+ labels,
7256
+ unresolved: {
7257
+ citation_keys: unresolvedCitationKeys,
7258
+ cross_reference_keys: unresolvedCrossReferenceKeys
7259
+ }
7260
+ };
7261
+ }
7262
+
7015
7263
  // src/document2/arabicPreamble.ts
7016
7264
  function fontOptions(digitsMapping, includeScript = true) {
7017
7265
  const parts = [];
@@ -7382,11 +7630,12 @@ ${block.closing}`;
7382
7630
  ${rows.join(" \\\\\n")}
7383
7631
  ${block.closing}`;
7384
7632
  }
7385
- function floatCaptionLabelLines(block, counter) {
7633
+ function floatCaptionLabelLines(block, counter, labelKinds) {
7386
7634
  const lines = [];
7387
- const hasCaption = block.captionEnabled && block.caption.trim().length > 0;
7635
+ const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
7636
+ const hasCaption = block.captionEnabled && caption.length > 0;
7388
7637
  if (hasCaption) {
7389
- lines.push(` \\caption{${block.caption.trim()}}`);
7638
+ lines.push(` \\caption{${caption}}`);
7390
7639
  }
7391
7640
  if (block.labelEnabled && block.label.trim().length > 0) {
7392
7641
  if (!hasCaption) {
@@ -7402,7 +7651,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
7402
7651
  if (block.centered) {
7403
7652
  lines.push(" \\centering");
7404
7653
  }
7405
- lines.push(...floatCaptionLabelLines(block, "table"));
7654
+ lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
7406
7655
  lines.push(indent(tabularInnerLatex(block, labelKinds)));
7407
7656
  lines.push("\\end{table}");
7408
7657
  return lines.join("\n");
@@ -7422,14 +7671,14 @@ function imageOptionsLatex(block, constrainToColumn) {
7422
7671
  }
7423
7672
  return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
7424
7673
  }
7425
- function imageBlockLatex(block, fixedFloats) {
7674
+ function imageBlockLatex(block, labelKinds, fixedFloats) {
7426
7675
  const placement = fixedFloats ? "H" : "htbp";
7427
7676
  const lines = [`\\begin{figure}[${placement}]`];
7428
7677
  if (block.centered) {
7429
7678
  lines.push(" \\centering");
7430
7679
  }
7431
7680
  lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
7432
- lines.push(...floatCaptionLabelLines(block, "figure"));
7681
+ lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
7433
7682
  lines.push("\\end{figure}");
7434
7683
  return lines.join("\n");
7435
7684
  }
@@ -7444,7 +7693,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
7444
7693
  return tableBlockLatex(block, labelKinds, fixedFloats);
7445
7694
  }
7446
7695
  if (block.kind === "image") {
7447
- return imageBlockLatex(block, fixedFloats);
7696
+ return imageBlockLatex(block, labelKinds, fixedFloats);
7448
7697
  }
7449
7698
  if (block.kind === "bibliography") {
7450
7699
  const width = String(Math.max(references.length, 9));
@@ -7637,7 +7886,7 @@ function validateBlock(context, block, path) {
7637
7886
  );
7638
7887
  });
7639
7888
  });
7640
- validateTextValue(context, block.caption, `${path}.caption`, block.id);
7889
+ validateInlineField(context, block.captionField, `${path}.caption`, block.id);
7641
7890
  if (block.labelEnabled) {
7642
7891
  registerKey(context, block.label, `${path}.label`, "tab", block.id);
7643
7892
  }
@@ -7650,7 +7899,7 @@ function validateBlock(context, block, path) {
7650
7899
  addIssue(context, "empty_image", path, block.id);
7651
7900
  }
7652
7901
  validateTextValue(context, block.value, `${path}.value`, block.id);
7653
- validateTextValue(context, block.caption, `${path}.caption`, block.id);
7902
+ validateInlineField(context, block.captionField, `${path}.caption`, block.id);
7654
7903
  if (block.labelEnabled) {
7655
7904
  registerKey(context, block.label, `${path}.label`, "fig", block.id);
7656
7905
  }
@@ -7983,6 +8232,15 @@ function floatNumberLabel(document2, key, previewOptions) {
7983
8232
  digitForm: previewOptions.digitForm
7984
8233
  });
7985
8234
  }
8235
+ function captionPreview(block, islands, output, equationSide, document2, previewOptions) {
8236
+ if (!block.captionEnabled || block.caption.trim().length === 0) {
8237
+ return {};
8238
+ }
8239
+ return {
8240
+ caption: block.caption.trim(),
8241
+ captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
8242
+ };
8243
+ }
7986
8244
  function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
7987
8245
  if (block.kind === "textBlock") {
7988
8246
  return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
@@ -8006,7 +8264,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
8006
8264
  kind: "table",
8007
8265
  id: block.id,
8008
8266
  rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
8009
- ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
8267
+ ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
8010
8268
  ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
8011
8269
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
8012
8270
  };
@@ -8020,7 +8278,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
8020
8278
  ...block.assetId !== void 0 ? { assetId: block.assetId } : {},
8021
8279
  options: block.options,
8022
8280
  centered: block.centered,
8023
- ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
8281
+ ...captionPreview(block, islands, output, equationSide, document2, previewOptions),
8024
8282
  ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
8025
8283
  ...block.metadata ? { metadata: { ...block.metadata } } : {}
8026
8284
  };
@@ -8169,6 +8427,8 @@ export {
8169
8427
  formatRefLabel,
8170
8428
  fromDocumentJson2,
8171
8429
  getArabicXeLatexPreamble,
8430
+ getDocument2ReferenceIndex,
8431
+ getDocument2References,
8172
8432
  hasXeLatexUnsupportedEmoji,
8173
8433
  hijriMonthLabel,
8174
8434
  inlineFieldLatex,