@drghaliasri/butex 7.0.2 → 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.
- package/dist/document2-cli.js +1351 -27
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +63 -3
- package/dist/document2.d.ts +63 -3
- package/dist/document2.js +299 -37
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +297 -37
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2-preview.d.mts +336 -0
- package/dist/react-document2-preview.d.ts +336 -0
- package/dist/react-document2-preview.js +7767 -0
- package/dist/react-document2-preview.js.map +1 -0
- package/dist/react-document2-preview.mjs +7737 -0
- package/dist/react-document2-preview.mjs.map +1 -0
- package/dist/react-document2.d.mts +53 -14
- package/dist/react-document2.d.ts +53 -14
- package/dist/react-document2.js +281 -42
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +278 -41
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +6 -1
package/dist/document2.js
CHANGED
|
@@ -92,6 +92,8 @@ __export(public_exports, {
|
|
|
92
92
|
formatRefLabel: () => formatRefLabel,
|
|
93
93
|
fromDocumentJson2: () => fromDocumentJson2,
|
|
94
94
|
getArabicXeLatexPreamble: () => getArabicXeLatexPreamble,
|
|
95
|
+
getDocument2ReferenceIndex: () => getDocument2ReferenceIndex,
|
|
96
|
+
getDocument2References: () => getDocument2References,
|
|
95
97
|
hasXeLatexUnsupportedEmoji: () => hasXeLatexUnsupportedEmoji,
|
|
96
98
|
hijriMonthLabel: () => hijriMonthLabel,
|
|
97
99
|
inlineFieldLatex: () => inlineFieldLatex,
|
|
@@ -966,6 +968,10 @@ function defaultFloatMeta() {
|
|
|
966
968
|
centered: true,
|
|
967
969
|
captionEnabled: false,
|
|
968
970
|
caption: "",
|
|
971
|
+
captionField: {
|
|
972
|
+
id: document2Id("field"),
|
|
973
|
+
tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
|
|
974
|
+
},
|
|
969
975
|
labelEnabled: false,
|
|
970
976
|
label: ""
|
|
971
977
|
};
|
|
@@ -1024,15 +1030,20 @@ function collectDocument2Labels(document2) {
|
|
|
1024
1030
|
}
|
|
1025
1031
|
function walk(blocks) {
|
|
1026
1032
|
for (const block of blocks) {
|
|
1027
|
-
if (block.kind === "image"
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1033
|
+
if (block.kind === "image") {
|
|
1034
|
+
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
1035
|
+
counters.fig += 1;
|
|
1036
|
+
entries.push({
|
|
1037
|
+
key: block.label.trim(),
|
|
1038
|
+
kind: "fig",
|
|
1039
|
+
caption: block.captionEnabled ? block.caption : "",
|
|
1040
|
+
ownerId: block.id,
|
|
1041
|
+
number: counters.fig
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
if (block.captionEnabled) {
|
|
1045
|
+
pushEqFromField(block.captionField.tokens);
|
|
1046
|
+
}
|
|
1036
1047
|
}
|
|
1037
1048
|
if (block.kind === "table") {
|
|
1038
1049
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
@@ -1045,6 +1056,9 @@ function collectDocument2Labels(document2) {
|
|
|
1045
1056
|
number: counters.tab
|
|
1046
1057
|
});
|
|
1047
1058
|
}
|
|
1059
|
+
if (block.captionEnabled) {
|
|
1060
|
+
pushEqFromField(block.captionField.tokens);
|
|
1061
|
+
}
|
|
1048
1062
|
for (const row of block.rows) {
|
|
1049
1063
|
for (const cell of row) {
|
|
1050
1064
|
pushEqFromField(cell.tokens);
|
|
@@ -1137,6 +1151,14 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
1137
1151
|
}
|
|
1138
1152
|
if (typeof patch.caption === "string") {
|
|
1139
1153
|
block.caption = patch.caption;
|
|
1154
|
+
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
1155
|
+
block.captionField.tokens = [
|
|
1156
|
+
{
|
|
1157
|
+
id: existingText?.id ?? document2Id("text"),
|
|
1158
|
+
kind: "text",
|
|
1159
|
+
text: patch.caption
|
|
1160
|
+
}
|
|
1161
|
+
];
|
|
1140
1162
|
}
|
|
1141
1163
|
if (typeof patch.labelEnabled === "boolean") {
|
|
1142
1164
|
block.labelEnabled = patch.labelEnabled;
|
|
@@ -1656,6 +1678,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1656
1678
|
...metadataFromJson(json.metadata)
|
|
1657
1679
|
};
|
|
1658
1680
|
}
|
|
1681
|
+
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1682
|
+
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1683
|
+
return applyImportedInlineIds(
|
|
1684
|
+
createInlineField2(
|
|
1685
|
+
caption,
|
|
1686
|
+
json.caption_math_objects ?? [],
|
|
1687
|
+
options,
|
|
1688
|
+
`${path}.caption`,
|
|
1689
|
+
diagnostics,
|
|
1690
|
+
json.caption_formats ?? []
|
|
1691
|
+
),
|
|
1692
|
+
json.caption_inline_ids,
|
|
1693
|
+
identities
|
|
1694
|
+
);
|
|
1695
|
+
}
|
|
1659
1696
|
function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
1660
1697
|
if (!Array.isArray(json.rows)) {
|
|
1661
1698
|
throw new Error("\\begin{tabular} requires rows array");
|
|
@@ -1682,6 +1719,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1682
1719
|
if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
|
|
1683
1720
|
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
|
|
1684
1721
|
}
|
|
1722
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1685
1723
|
return {
|
|
1686
1724
|
id: blockIdFromJson(json, identities),
|
|
1687
1725
|
kind: "table",
|
|
@@ -1689,13 +1727,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1689
1727
|
closing: "\\end{tabular}",
|
|
1690
1728
|
columns: typeof json.columns === "string" ? json.columns : "",
|
|
1691
1729
|
rows,
|
|
1692
|
-
...
|
|
1730
|
+
...floatMeta,
|
|
1731
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1693
1732
|
...metadataFromJson(json.metadata)
|
|
1694
1733
|
};
|
|
1695
1734
|
}
|
|
1696
|
-
function parseImageBlock(json, identities) {
|
|
1735
|
+
function parseImageBlock(json, options, path, diagnostics, identities) {
|
|
1697
1736
|
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
1698
1737
|
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
1738
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1699
1739
|
return {
|
|
1700
1740
|
id: blockIdFromJson(json, identities),
|
|
1701
1741
|
kind: "image",
|
|
@@ -1703,7 +1743,8 @@ function parseImageBlock(json, identities) {
|
|
|
1703
1743
|
value,
|
|
1704
1744
|
...assetId !== void 0 ? { assetId } : {},
|
|
1705
1745
|
options: isRecordOfStrings(json.options) ? json.options : {},
|
|
1706
|
-
...
|
|
1746
|
+
...floatMeta,
|
|
1747
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1707
1748
|
...metadataFromJson(json.metadata)
|
|
1708
1749
|
};
|
|
1709
1750
|
}
|
|
@@ -1736,7 +1777,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1736
1777
|
return parseTableBlock(json, options, path, diagnostics, identities);
|
|
1737
1778
|
}
|
|
1738
1779
|
if (json.command === "\\includegraphics") {
|
|
1739
|
-
return parseImageBlock(json, identities);
|
|
1780
|
+
return parseImageBlock(json, options, path, diagnostics, identities);
|
|
1740
1781
|
}
|
|
1741
1782
|
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
1742
1783
|
return parseBibliographyBlock(json, identities);
|
|
@@ -4763,6 +4804,20 @@ function cloneToken(token) {
|
|
|
4763
4804
|
function cloneField(field) {
|
|
4764
4805
|
return { id: field.id, tokens: field.tokens.map(cloneToken) };
|
|
4765
4806
|
}
|
|
4807
|
+
function inlineFieldSource(field) {
|
|
4808
|
+
return field.tokens.map((token) => {
|
|
4809
|
+
if (token.kind === "text") {
|
|
4810
|
+
return token.text;
|
|
4811
|
+
}
|
|
4812
|
+
if (token.kind === "cite") {
|
|
4813
|
+
return citeTokenLatex(token.keys);
|
|
4814
|
+
}
|
|
4815
|
+
if (token.kind === "ref") {
|
|
4816
|
+
return refTokenLatex(token.keys, token.refCommand);
|
|
4817
|
+
}
|
|
4818
|
+
return token.source;
|
|
4819
|
+
}).join("");
|
|
4820
|
+
}
|
|
4766
4821
|
function cloneBlock(block) {
|
|
4767
4822
|
const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
|
|
4768
4823
|
if (block.kind === "textBlock") {
|
|
@@ -4780,10 +4835,20 @@ function cloneBlock(block) {
|
|
|
4780
4835
|
};
|
|
4781
4836
|
}
|
|
4782
4837
|
if (block.kind === "table") {
|
|
4783
|
-
return {
|
|
4838
|
+
return {
|
|
4839
|
+
...block,
|
|
4840
|
+
...metadata,
|
|
4841
|
+
rows: block.rows.map((row) => row.map(cloneField)),
|
|
4842
|
+
captionField: cloneField(block.captionField)
|
|
4843
|
+
};
|
|
4784
4844
|
}
|
|
4785
4845
|
if (block.kind === "image") {
|
|
4786
|
-
return {
|
|
4846
|
+
return {
|
|
4847
|
+
...block,
|
|
4848
|
+
...metadata,
|
|
4849
|
+
options: { ...block.options },
|
|
4850
|
+
captionField: cloneField(block.captionField)
|
|
4851
|
+
};
|
|
4787
4852
|
}
|
|
4788
4853
|
return { ...block, ...metadata };
|
|
4789
4854
|
}
|
|
@@ -4796,6 +4861,13 @@ function cloneDocument(document2) {
|
|
|
4796
4861
|
diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
|
|
4797
4862
|
};
|
|
4798
4863
|
}
|
|
4864
|
+
function visitCaptionField(block, visitor) {
|
|
4865
|
+
if (!visitor(block.captionField)) {
|
|
4866
|
+
return false;
|
|
4867
|
+
}
|
|
4868
|
+
block.caption = inlineFieldSource(block.captionField);
|
|
4869
|
+
return true;
|
|
4870
|
+
}
|
|
4799
4871
|
function visitFields(blocks, visitor) {
|
|
4800
4872
|
for (const block of blocks) {
|
|
4801
4873
|
if (block.kind === "textBlock") {
|
|
@@ -4816,6 +4888,11 @@ function visitFields(blocks, visitor) {
|
|
|
4816
4888
|
}
|
|
4817
4889
|
}
|
|
4818
4890
|
}
|
|
4891
|
+
if (visitCaptionField(block, visitor)) {
|
|
4892
|
+
return true;
|
|
4893
|
+
}
|
|
4894
|
+
} else if (block.kind === "image" && visitCaptionField(block, visitor)) {
|
|
4895
|
+
return true;
|
|
4819
4896
|
}
|
|
4820
4897
|
}
|
|
4821
4898
|
return false;
|
|
@@ -5693,6 +5770,9 @@ function findField(blocks, fieldId) {
|
|
|
5693
5770
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
5694
5771
|
return block.field;
|
|
5695
5772
|
}
|
|
5773
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
5774
|
+
return block.captionField;
|
|
5775
|
+
}
|
|
5696
5776
|
if (block.kind === "list") {
|
|
5697
5777
|
for (const item of block.items) {
|
|
5698
5778
|
if (item.field.id === fieldId) {
|
|
@@ -5731,26 +5811,30 @@ function findBlock(blocks, blockId) {
|
|
|
5731
5811
|
}
|
|
5732
5812
|
return null;
|
|
5733
5813
|
}
|
|
5814
|
+
function collectFieldIdentity(field, sets) {
|
|
5815
|
+
sets.fields.add(field.id);
|
|
5816
|
+
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5817
|
+
}
|
|
5734
5818
|
function collectIdentitySets(blocks, sets) {
|
|
5735
5819
|
for (const block of blocks) {
|
|
5736
5820
|
sets.blocks.add(block.id);
|
|
5737
5821
|
if (block.kind === "textBlock") {
|
|
5738
|
-
|
|
5739
|
-
block.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5822
|
+
collectFieldIdentity(block.field, sets);
|
|
5740
5823
|
} else if (block.kind === "list") {
|
|
5741
5824
|
for (const item of block.items) {
|
|
5742
5825
|
sets.items.add(item.id);
|
|
5743
|
-
|
|
5744
|
-
item.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5826
|
+
collectFieldIdentity(item.field, sets);
|
|
5745
5827
|
collectIdentitySets(item.blocks, sets);
|
|
5746
5828
|
}
|
|
5747
5829
|
} else if (block.kind === "table") {
|
|
5830
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5748
5831
|
for (const row of block.rows) {
|
|
5749
5832
|
for (const field of row) {
|
|
5750
|
-
|
|
5751
|
-
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
5833
|
+
collectFieldIdentity(field, sets);
|
|
5752
5834
|
}
|
|
5753
5835
|
}
|
|
5836
|
+
} else if (block.kind === "image") {
|
|
5837
|
+
collectFieldIdentity(block.captionField, sets);
|
|
5754
5838
|
}
|
|
5755
5839
|
}
|
|
5756
5840
|
}
|
|
@@ -6085,6 +6169,37 @@ function applyReferenceFields(reference, command) {
|
|
|
6085
6169
|
reference.fieldSeparator = command.field_separator;
|
|
6086
6170
|
}
|
|
6087
6171
|
}
|
|
6172
|
+
function replaceCitationKey(document2, previousKey, nextKey) {
|
|
6173
|
+
function replaceInField(field) {
|
|
6174
|
+
for (const token of field.tokens) {
|
|
6175
|
+
if (token.kind === "cite") {
|
|
6176
|
+
token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6179
|
+
}
|
|
6180
|
+
function visitBlocks(blocks) {
|
|
6181
|
+
for (const block of blocks) {
|
|
6182
|
+
if (block.kind === "textBlock") {
|
|
6183
|
+
replaceInField(block.field);
|
|
6184
|
+
} else if (block.kind === "table") {
|
|
6185
|
+
replaceInField(block.captionField);
|
|
6186
|
+
for (const row of block.rows) {
|
|
6187
|
+
for (const cell of row) {
|
|
6188
|
+
replaceInField(cell);
|
|
6189
|
+
}
|
|
6190
|
+
}
|
|
6191
|
+
} else if (block.kind === "image") {
|
|
6192
|
+
replaceInField(block.captionField);
|
|
6193
|
+
} else if (block.kind === "list") {
|
|
6194
|
+
for (const item of block.items) {
|
|
6195
|
+
replaceInField(item.field);
|
|
6196
|
+
visitBlocks(item.blocks);
|
|
6197
|
+
}
|
|
6198
|
+
}
|
|
6199
|
+
}
|
|
6200
|
+
}
|
|
6201
|
+
visitBlocks(document2.blocks);
|
|
6202
|
+
}
|
|
6088
6203
|
function applyArticleCommand(document2, command) {
|
|
6089
6204
|
if (command.op === "update_document_meta") {
|
|
6090
6205
|
document2.meta = {
|
|
@@ -6113,7 +6228,10 @@ function applyArticleCommand(document2, command) {
|
|
|
6113
6228
|
const target = document2.references[targetIndex];
|
|
6114
6229
|
if (command.op === "update_reference") {
|
|
6115
6230
|
if (command.key !== void 0) {
|
|
6116
|
-
|
|
6231
|
+
const previousKey = target.key;
|
|
6232
|
+
const nextKey = validateReferenceKey(document2, command.key, target.id);
|
|
6233
|
+
target.key = nextKey;
|
|
6234
|
+
replaceCitationKey(document2, previousKey, nextKey);
|
|
6117
6235
|
}
|
|
6118
6236
|
applyReferenceFields(target, command);
|
|
6119
6237
|
return;
|
|
@@ -6542,10 +6660,15 @@ function insertTable(document2, command) {
|
|
|
6542
6660
|
columns: command.columns,
|
|
6543
6661
|
rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
|
|
6544
6662
|
...defaultFloatMeta(),
|
|
6545
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
6546
6663
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
6547
6664
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
6548
6665
|
};
|
|
6666
|
+
if (command.caption !== void 0) {
|
|
6667
|
+
applyFloatMetaPatch(block, {
|
|
6668
|
+
caption: command.caption,
|
|
6669
|
+
captionEnabled: command.caption.trim().length > 0
|
|
6670
|
+
});
|
|
6671
|
+
}
|
|
6549
6672
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
6550
6673
|
}
|
|
6551
6674
|
function checkCell(table, rowIndex, columnIndex) {
|
|
@@ -6690,6 +6813,15 @@ function fieldJson(field) {
|
|
|
6690
6813
|
...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
|
|
6691
6814
|
};
|
|
6692
6815
|
}
|
|
6816
|
+
function captionJson(field) {
|
|
6817
|
+
const serialized = serializeField(field);
|
|
6818
|
+
return {
|
|
6819
|
+
caption: serialized.value,
|
|
6820
|
+
caption_inline_ids: serialized.inlineIds,
|
|
6821
|
+
...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
|
|
6822
|
+
...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
|
|
6823
|
+
};
|
|
6824
|
+
}
|
|
6693
6825
|
function listItemJson(item) {
|
|
6694
6826
|
const field = fieldJson(item.field);
|
|
6695
6827
|
return {
|
|
@@ -6734,7 +6866,7 @@ function blockJson(block) {
|
|
|
6734
6866
|
...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
|
|
6735
6867
|
centered: block.centered,
|
|
6736
6868
|
caption_enabled: block.captionEnabled,
|
|
6737
|
-
|
|
6869
|
+
...captionJson(block.captionField),
|
|
6738
6870
|
label_enabled: block.labelEnabled,
|
|
6739
6871
|
label: block.label,
|
|
6740
6872
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -6749,7 +6881,7 @@ function blockJson(block) {
|
|
|
6749
6881
|
options: { ...block.options },
|
|
6750
6882
|
centered: block.centered,
|
|
6751
6883
|
caption_enabled: block.captionEnabled,
|
|
6752
|
-
|
|
6884
|
+
...captionJson(block.captionField),
|
|
6753
6885
|
label_enabled: block.labelEnabled,
|
|
6754
6886
|
label: block.label,
|
|
6755
6887
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -7076,10 +7208,15 @@ function applyBasicCommand(document2, command) {
|
|
|
7076
7208
|
assetId: command.asset_id,
|
|
7077
7209
|
options: { width: "0.8\\columnwidth" },
|
|
7078
7210
|
...defaultFloatMeta(),
|
|
7079
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
7080
7211
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
7081
7212
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
7082
7213
|
};
|
|
7214
|
+
if (command.caption !== void 0) {
|
|
7215
|
+
applyFloatMetaPatch(block, {
|
|
7216
|
+
caption: command.caption,
|
|
7217
|
+
captionEnabled: command.caption.trim().length > 0
|
|
7218
|
+
});
|
|
7219
|
+
}
|
|
7083
7220
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
7084
7221
|
}
|
|
7085
7222
|
function applyDocument2Command(json, commandInput) {
|
|
@@ -7173,6 +7310,119 @@ function document2Outline(json) {
|
|
|
7173
7310
|
});
|
|
7174
7311
|
}
|
|
7175
7312
|
|
|
7313
|
+
// src/document2/introspection.ts
|
|
7314
|
+
function appendUnique(target, seen, values) {
|
|
7315
|
+
for (const value of values) {
|
|
7316
|
+
if (!seen.has(value)) {
|
|
7317
|
+
seen.add(value);
|
|
7318
|
+
target.push(value);
|
|
7319
|
+
}
|
|
7320
|
+
}
|
|
7321
|
+
}
|
|
7322
|
+
function getDocument2References(document2) {
|
|
7323
|
+
return document2.references.map((reference) => ({
|
|
7324
|
+
key: reference.key,
|
|
7325
|
+
authors: reference.authors,
|
|
7326
|
+
title: reference.title,
|
|
7327
|
+
year: reference.year,
|
|
7328
|
+
venue: reference.venue,
|
|
7329
|
+
url: reference.url,
|
|
7330
|
+
field_separator: reference.fieldSeparator
|
|
7331
|
+
}));
|
|
7332
|
+
}
|
|
7333
|
+
function getDocument2ReferenceIndex(document2) {
|
|
7334
|
+
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
7335
|
+
const labelEntries = collectDocument2Labels(document2);
|
|
7336
|
+
const labelKeys = new Set(labelEntries.map((entry) => entry.key));
|
|
7337
|
+
const citations = [];
|
|
7338
|
+
const crossReferences = [];
|
|
7339
|
+
const tokenLocations = /* @__PURE__ */ new Map();
|
|
7340
|
+
const unresolvedCitationKeys = [];
|
|
7341
|
+
const unresolvedCrossReferenceKeys = [];
|
|
7342
|
+
const seenCitationKeys = /* @__PURE__ */ new Set();
|
|
7343
|
+
const seenCrossReferenceKeys = /* @__PURE__ */ new Set();
|
|
7344
|
+
function visitField(blockId, field) {
|
|
7345
|
+
for (const token of field.tokens) {
|
|
7346
|
+
tokenLocations.set(token.id, { block_id: blockId, field_id: field.id });
|
|
7347
|
+
if (token.kind === "cite") {
|
|
7348
|
+
const unresolvedKeys = token.keys.filter((key) => !referenceKeys.has(key));
|
|
7349
|
+
citations.push({
|
|
7350
|
+
kind: "cite",
|
|
7351
|
+
block_id: blockId,
|
|
7352
|
+
field_id: field.id,
|
|
7353
|
+
token_id: token.id,
|
|
7354
|
+
keys: [...token.keys],
|
|
7355
|
+
unresolved_keys: unresolvedKeys
|
|
7356
|
+
});
|
|
7357
|
+
appendUnique(unresolvedCitationKeys, seenCitationKeys, unresolvedKeys);
|
|
7358
|
+
} else if (token.kind === "ref") {
|
|
7359
|
+
const unresolvedKeys = token.keys.filter((key) => !labelKeys.has(key));
|
|
7360
|
+
crossReferences.push({
|
|
7361
|
+
kind: "ref",
|
|
7362
|
+
ref_command: token.refCommand,
|
|
7363
|
+
block_id: blockId,
|
|
7364
|
+
field_id: field.id,
|
|
7365
|
+
token_id: token.id,
|
|
7366
|
+
keys: [...token.keys],
|
|
7367
|
+
unresolved_keys: unresolvedKeys
|
|
7368
|
+
});
|
|
7369
|
+
appendUnique(unresolvedCrossReferenceKeys, seenCrossReferenceKeys, unresolvedKeys);
|
|
7370
|
+
}
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
function visitBlocks(blocks) {
|
|
7374
|
+
for (const block of blocks) {
|
|
7375
|
+
if (block.kind === "textBlock") {
|
|
7376
|
+
visitField(block.id, block.field);
|
|
7377
|
+
} else if (block.kind === "table") {
|
|
7378
|
+
visitField(block.id, block.captionField);
|
|
7379
|
+
for (const row of block.rows) {
|
|
7380
|
+
for (const cell of row) {
|
|
7381
|
+
visitField(block.id, cell);
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
} else if (block.kind === "image") {
|
|
7385
|
+
visitField(block.id, block.captionField);
|
|
7386
|
+
} else if (block.kind === "list") {
|
|
7387
|
+
for (const item of block.items) {
|
|
7388
|
+
visitField(block.id, item.field);
|
|
7389
|
+
visitBlocks(item.blocks);
|
|
7390
|
+
}
|
|
7391
|
+
}
|
|
7392
|
+
}
|
|
7393
|
+
}
|
|
7394
|
+
visitBlocks(document2.blocks);
|
|
7395
|
+
const labels = labelEntries.map((entry) => {
|
|
7396
|
+
if (entry.kind !== "eq") {
|
|
7397
|
+
return {
|
|
7398
|
+
key: entry.key,
|
|
7399
|
+
kind: entry.kind,
|
|
7400
|
+
caption: entry.caption,
|
|
7401
|
+
number: entry.number,
|
|
7402
|
+
block_id: entry.ownerId
|
|
7403
|
+
};
|
|
7404
|
+
}
|
|
7405
|
+
const location = tokenLocations.get(entry.ownerId);
|
|
7406
|
+
return {
|
|
7407
|
+
key: entry.key,
|
|
7408
|
+
kind: entry.kind,
|
|
7409
|
+
caption: entry.caption,
|
|
7410
|
+
number: entry.number,
|
|
7411
|
+
...location ? { block_id: location.block_id, field_id: location.field_id } : {},
|
|
7412
|
+
token_id: entry.ownerId
|
|
7413
|
+
};
|
|
7414
|
+
});
|
|
7415
|
+
return {
|
|
7416
|
+
citations,
|
|
7417
|
+
cross_references: crossReferences,
|
|
7418
|
+
labels,
|
|
7419
|
+
unresolved: {
|
|
7420
|
+
citation_keys: unresolvedCitationKeys,
|
|
7421
|
+
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
7422
|
+
}
|
|
7423
|
+
};
|
|
7424
|
+
}
|
|
7425
|
+
|
|
7176
7426
|
// src/document2/arabicPreamble.ts
|
|
7177
7427
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
7178
7428
|
const parts = [];
|
|
@@ -7543,11 +7793,12 @@ ${block.closing}`;
|
|
|
7543
7793
|
${rows.join(" \\\\\n")}
|
|
7544
7794
|
${block.closing}`;
|
|
7545
7795
|
}
|
|
7546
|
-
function floatCaptionLabelLines(block, counter) {
|
|
7796
|
+
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
7547
7797
|
const lines = [];
|
|
7548
|
-
const
|
|
7798
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
7799
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
7549
7800
|
if (hasCaption) {
|
|
7550
|
-
lines.push(` \\caption{${
|
|
7801
|
+
lines.push(` \\caption{${caption}}`);
|
|
7551
7802
|
}
|
|
7552
7803
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
7553
7804
|
if (!hasCaption) {
|
|
@@ -7563,7 +7814,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
|
7563
7814
|
if (block.centered) {
|
|
7564
7815
|
lines.push(" \\centering");
|
|
7565
7816
|
}
|
|
7566
|
-
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
7817
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
7567
7818
|
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
7568
7819
|
lines.push("\\end{table}");
|
|
7569
7820
|
return lines.join("\n");
|
|
@@ -7583,14 +7834,14 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
7583
7834
|
}
|
|
7584
7835
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
7585
7836
|
}
|
|
7586
|
-
function imageBlockLatex(block, fixedFloats) {
|
|
7837
|
+
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
7587
7838
|
const placement = fixedFloats ? "H" : "htbp";
|
|
7588
7839
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
7589
7840
|
if (block.centered) {
|
|
7590
7841
|
lines.push(" \\centering");
|
|
7591
7842
|
}
|
|
7592
7843
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
7593
|
-
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
7844
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
7594
7845
|
lines.push("\\end{figure}");
|
|
7595
7846
|
return lines.join("\n");
|
|
7596
7847
|
}
|
|
@@ -7605,7 +7856,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
|
7605
7856
|
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
7606
7857
|
}
|
|
7607
7858
|
if (block.kind === "image") {
|
|
7608
|
-
return imageBlockLatex(block, fixedFloats);
|
|
7859
|
+
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
7609
7860
|
}
|
|
7610
7861
|
if (block.kind === "bibliography") {
|
|
7611
7862
|
const width = String(Math.max(references.length, 9));
|
|
@@ -7798,7 +8049,7 @@ function validateBlock(context, block, path) {
|
|
|
7798
8049
|
);
|
|
7799
8050
|
});
|
|
7800
8051
|
});
|
|
7801
|
-
|
|
8052
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7802
8053
|
if (block.labelEnabled) {
|
|
7803
8054
|
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
7804
8055
|
}
|
|
@@ -7811,7 +8062,7 @@ function validateBlock(context, block, path) {
|
|
|
7811
8062
|
addIssue(context, "empty_image", path, block.id);
|
|
7812
8063
|
}
|
|
7813
8064
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
7814
|
-
|
|
8065
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
7815
8066
|
if (block.labelEnabled) {
|
|
7816
8067
|
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
7817
8068
|
}
|
|
@@ -8144,6 +8395,15 @@ function floatNumberLabel(document2, key, previewOptions) {
|
|
|
8144
8395
|
digitForm: previewOptions.digitForm
|
|
8145
8396
|
});
|
|
8146
8397
|
}
|
|
8398
|
+
function captionPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
8399
|
+
if (!block.captionEnabled || block.caption.trim().length === 0) {
|
|
8400
|
+
return {};
|
|
8401
|
+
}
|
|
8402
|
+
return {
|
|
8403
|
+
caption: block.caption.trim(),
|
|
8404
|
+
captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
|
|
8405
|
+
};
|
|
8406
|
+
}
|
|
8147
8407
|
function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
8148
8408
|
if (block.kind === "textBlock") {
|
|
8149
8409
|
return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
|
|
@@ -8167,7 +8427,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8167
8427
|
kind: "table",
|
|
8168
8428
|
id: block.id,
|
|
8169
8429
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
8170
|
-
...block
|
|
8430
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8171
8431
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8172
8432
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8173
8433
|
};
|
|
@@ -8181,7 +8441,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8181
8441
|
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
8182
8442
|
options: block.options,
|
|
8183
8443
|
centered: block.centered,
|
|
8184
|
-
...block
|
|
8444
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8185
8445
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
8186
8446
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8187
8447
|
};
|
|
@@ -8331,6 +8591,8 @@ function document2Latex2(document2, options = {}) {
|
|
|
8331
8591
|
formatRefLabel,
|
|
8332
8592
|
fromDocumentJson2,
|
|
8333
8593
|
getArabicXeLatexPreamble,
|
|
8594
|
+
getDocument2ReferenceIndex,
|
|
8595
|
+
getDocument2References,
|
|
8334
8596
|
hasXeLatexUnsupportedEmoji,
|
|
8335
8597
|
hijriMonthLabel,
|
|
8336
8598
|
inlineFieldLatex,
|