@drghaliasri/butex 8.0.2 → 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.
- package/README.md +7 -7
- package/dist/document-cli.js +231 -88
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +35 -2
- package/dist/document.d.ts +35 -2
- package/dist/document.js +187 -100
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +182 -100
- package/dist/document.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +4 -0
- package/dist/react-document-preview.d.ts +4 -0
- package/dist/react-document-preview.js +78 -71
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +78 -71
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +8 -1
- package/dist/react-document.d.ts +8 -1
- package/dist/react-document.js +177 -115
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +177 -115
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document.mjs
CHANGED
|
@@ -851,82 +851,85 @@ function refTokenLatex(keys, refCommand) {
|
|
|
851
851
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
852
852
|
return `${command}{${keys.join(",")}}`;
|
|
853
853
|
}
|
|
854
|
-
function
|
|
855
|
-
const
|
|
854
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
855
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
856
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
857
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
858
|
+
}
|
|
859
|
+
function supportsSingleEquationNumbering(token) {
|
|
860
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
861
|
+
}
|
|
862
|
+
function isNumberedEquation(token) {
|
|
863
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
864
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
865
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
866
|
+
}
|
|
867
|
+
function isNumberedFloat(block) {
|
|
868
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
869
|
+
}
|
|
870
|
+
function collectDocumentReferenceTargets(document2) {
|
|
871
|
+
const targets = [];
|
|
856
872
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
857
|
-
function
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
873
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
874
|
+
if (numbered) counters[kind] += 1;
|
|
875
|
+
targets.push({
|
|
876
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
877
|
+
kind,
|
|
878
|
+
ownerId,
|
|
879
|
+
caption,
|
|
880
|
+
number: numbered ? counters[kind] : null,
|
|
881
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
function visitField(field) {
|
|
885
|
+
for (const token of field.tokens) {
|
|
886
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
887
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
871
888
|
}
|
|
872
889
|
}
|
|
873
890
|
}
|
|
874
891
|
function walk(blocks) {
|
|
875
892
|
for (const block of blocks) {
|
|
876
|
-
if (block.kind === "image") {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
if (block.captionEnabled) {
|
|
888
|
-
pushEqFromField(block.captionField.tokens);
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
if (block.kind === "table") {
|
|
892
|
-
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
893
|
-
counters.tab += 1;
|
|
894
|
-
entries.push({
|
|
895
|
-
key: block.label.trim(),
|
|
896
|
-
kind: "tab",
|
|
897
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
898
|
-
ownerId: block.id,
|
|
899
|
-
number: counters.tab
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
if (block.captionEnabled) {
|
|
903
|
-
pushEqFromField(block.captionField.tokens);
|
|
904
|
-
}
|
|
905
|
-
for (const row of block.rows) {
|
|
906
|
-
for (const cell of row) {
|
|
907
|
-
pushEqFromField(cell.tokens);
|
|
908
|
-
}
|
|
893
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
894
|
+
append(
|
|
895
|
+
block.kind === "image" ? "fig" : "tab",
|
|
896
|
+
block.id,
|
|
897
|
+
block.captionEnabled ? block.caption : "",
|
|
898
|
+
isNumberedFloat(block),
|
|
899
|
+
block.labelEnabled ? block.label : ""
|
|
900
|
+
);
|
|
901
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
902
|
+
if (block.kind === "table") {
|
|
903
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
909
904
|
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
}
|
|
914
|
-
if (block.kind === "list") {
|
|
905
|
+
} else if (block.kind === "textBlock") {
|
|
906
|
+
visitField(block.field);
|
|
907
|
+
} else if (block.kind === "list") {
|
|
915
908
|
for (const item of block.items) {
|
|
916
|
-
|
|
909
|
+
visitField(item.field);
|
|
917
910
|
walk(item.blocks);
|
|
918
911
|
}
|
|
919
912
|
}
|
|
920
913
|
}
|
|
921
914
|
}
|
|
922
915
|
walk(document2.blocks);
|
|
923
|
-
return
|
|
916
|
+
return targets;
|
|
917
|
+
}
|
|
918
|
+
function collectDocumentLabels(document2) {
|
|
919
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
|
|
920
|
+
}
|
|
921
|
+
function collectDocumentKeyLabels(document2) {
|
|
922
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null).flatMap((target) => [
|
|
923
|
+
{ key: target.key, ownerId: target.ownerId },
|
|
924
|
+
...target.manualKey && target.manualKey !== target.key ? [{ key: target.manualKey, ownerId: target.ownerId }] : []
|
|
925
|
+
]);
|
|
924
926
|
}
|
|
925
927
|
function labelNumberMap(document2) {
|
|
926
928
|
const map = /* @__PURE__ */ new Map();
|
|
927
|
-
for (const
|
|
928
|
-
if (
|
|
929
|
-
|
|
929
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
930
|
+
if (target.number === null) continue;
|
|
931
|
+
for (const key of [target.key, target.manualKey]) {
|
|
932
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
930
933
|
}
|
|
931
934
|
}
|
|
932
935
|
return map;
|
|
@@ -980,8 +983,12 @@ function stripDisplayMathDelimiters(source) {
|
|
|
980
983
|
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
981
984
|
return trimmed.slice(2, -2).trim();
|
|
982
985
|
}
|
|
983
|
-
|
|
984
|
-
|
|
986
|
+
for (const environment of ["equation", "equation*"]) {
|
|
987
|
+
const opening = `\\begin{${environment}}`;
|
|
988
|
+
const closing = `\\end{${environment}}`;
|
|
989
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
990
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
991
|
+
}
|
|
985
992
|
}
|
|
986
993
|
return trimmed;
|
|
987
994
|
}
|
|
@@ -1374,7 +1381,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1374
1381
|
editable: true,
|
|
1375
1382
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1376
1383
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1377
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1384
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1385
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1378
1386
|
});
|
|
1379
1387
|
} else {
|
|
1380
1388
|
tokens.push({
|
|
@@ -1389,7 +1397,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1389
1397
|
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",
|
|
1390
1398
|
sourceOwner: "raw",
|
|
1391
1399
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1392
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1400
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1401
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1393
1402
|
});
|
|
1394
1403
|
}
|
|
1395
1404
|
index = span.end;
|
|
@@ -5443,6 +5452,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
|
|
|
5443
5452
|
if (current.label !== void 0) {
|
|
5444
5453
|
replaced.label = current.label;
|
|
5445
5454
|
}
|
|
5455
|
+
if (current.numbered !== void 0) {
|
|
5456
|
+
replaced.numbered = current.numbered;
|
|
5457
|
+
}
|
|
5446
5458
|
field.tokens[index] = replaced;
|
|
5447
5459
|
return true;
|
|
5448
5460
|
});
|
|
@@ -5667,6 +5679,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
|
|
|
5667
5679
|
if (typeof patch.label === "string") {
|
|
5668
5680
|
token.label = patch.label;
|
|
5669
5681
|
}
|
|
5682
|
+
if (typeof patch.numbered === "boolean") {
|
|
5683
|
+
token.numbered = patch.numbered;
|
|
5684
|
+
}
|
|
5670
5685
|
return true;
|
|
5671
5686
|
});
|
|
5672
5687
|
return next;
|
|
@@ -5975,7 +5990,7 @@ function normalizedNewFloatLabel(document2, label) {
|
|
|
5975
5990
|
if (!normalized) return "";
|
|
5976
5991
|
const error = documentKeyError(normalized, {
|
|
5977
5992
|
references: document2.references,
|
|
5978
|
-
labels:
|
|
5993
|
+
labels: collectDocumentKeyLabels(document2)
|
|
5979
5994
|
});
|
|
5980
5995
|
if (error === "duplicate") {
|
|
5981
5996
|
throw new DocumentCommandError("duplicate_key", "Float label is already in use");
|
|
@@ -6419,7 +6434,7 @@ function validateReferenceKey(document2, key, excludeReferenceId) {
|
|
|
6419
6434
|
const normalized = normalizeDocumentKey(key);
|
|
6420
6435
|
const error = documentKeyError(normalized, {
|
|
6421
6436
|
references: document2.references,
|
|
6422
|
-
labels:
|
|
6437
|
+
labels: collectDocumentKeyLabels(document2),
|
|
6423
6438
|
...excludeReferenceId ? { excludeReferenceId } : {}
|
|
6424
6439
|
});
|
|
6425
6440
|
if (error === "duplicate") {
|
|
@@ -6641,6 +6656,17 @@ function parseToken(value) {
|
|
|
6641
6656
|
throw new DocumentCommandError("invalid_inline_token", "Unsupported inline token kind");
|
|
6642
6657
|
}
|
|
6643
6658
|
function parseInlineCommand(value) {
|
|
6659
|
+
if (value.op === "set_equation_numbering") {
|
|
6660
|
+
if (typeof value.numbered !== "boolean") {
|
|
6661
|
+
throw new DocumentCommandError("invalid_command", "numbered must be boolean");
|
|
6662
|
+
}
|
|
6663
|
+
return {
|
|
6664
|
+
op: "set_equation_numbering",
|
|
6665
|
+
field_id: requireString2(value.field_id, "field_id", false).trim(),
|
|
6666
|
+
token_id: requireString2(value.token_id, "token_id", false).trim(),
|
|
6667
|
+
numbered: value.numbered
|
|
6668
|
+
};
|
|
6669
|
+
}
|
|
6644
6670
|
if (value.op === "insert_inline_token") {
|
|
6645
6671
|
return {
|
|
6646
6672
|
op: value.op,
|
|
@@ -6694,7 +6720,8 @@ function liveToken(input, id) {
|
|
|
6694
6720
|
editable: true,
|
|
6695
6721
|
sourceOwner: mathObject.source_owner === "editor" ? "editor" : "imported-structured",
|
|
6696
6722
|
...mathObject.label_enabled !== void 0 ? { labelEnabled: mathObject.label_enabled } : {},
|
|
6697
|
-
...mathObject.label !== void 0 ? { label: mathObject.label } : {}
|
|
6723
|
+
...mathObject.label !== void 0 ? { label: mathObject.label } : {},
|
|
6724
|
+
...mathObject.numbered !== void 0 ? { numbered: mathObject.numbered } : {}
|
|
6698
6725
|
};
|
|
6699
6726
|
}
|
|
6700
6727
|
function insertionIndex(tokens, anchor) {
|
|
@@ -6716,6 +6743,17 @@ function applyInlineCommand(document2, command) {
|
|
|
6716
6743
|
if (!field) {
|
|
6717
6744
|
throw new DocumentCommandError("field_not_found", "Inline field was not found");
|
|
6718
6745
|
}
|
|
6746
|
+
if (command.op === "set_equation_numbering") {
|
|
6747
|
+
const token = field.tokens.find((entry) => entry.id === command.token_id);
|
|
6748
|
+
if (!token || token.kind !== "math") {
|
|
6749
|
+
throw new DocumentCommandError("token_not_found", "Equation token was not found");
|
|
6750
|
+
}
|
|
6751
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
6752
|
+
throw new DocumentCommandError("invalid_inline_token", "Only a single display equation can be numbered");
|
|
6753
|
+
}
|
|
6754
|
+
token.numbered = command.numbered;
|
|
6755
|
+
return;
|
|
6756
|
+
}
|
|
6719
6757
|
if (command.op === "insert_inline_token") {
|
|
6720
6758
|
const index2 = insertionIndex(field.tokens, command.anchor);
|
|
6721
6759
|
field.tokens.splice(index2, 0, liveToken(command.token, newTokenId(document2, command.token.kind)));
|
|
@@ -7068,12 +7106,13 @@ function serializeField(field) {
|
|
|
7068
7106
|
}
|
|
7069
7107
|
value += token.source;
|
|
7070
7108
|
if (!token.math || token.sourceOwner === "raw") {
|
|
7071
|
-
if (token.labelEnabled !== void 0 || token.label !== void 0) {
|
|
7109
|
+
if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
|
|
7072
7110
|
hasPersistedMath = true;
|
|
7073
7111
|
mathObjects.push({
|
|
7074
7112
|
node_type: "RawMathObject",
|
|
7075
7113
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
7076
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
7114
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
7115
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
7077
7116
|
});
|
|
7078
7117
|
} else {
|
|
7079
7118
|
mathObjects.push(null);
|
|
@@ -7086,7 +7125,8 @@ function serializeField(field) {
|
|
|
7086
7125
|
...token.sourceSide ? { source_side: token.sourceSide } : {},
|
|
7087
7126
|
source_owner: token.sourceOwner,
|
|
7088
7127
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
7089
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
7128
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
7129
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
7090
7130
|
});
|
|
7091
7131
|
}
|
|
7092
7132
|
return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
|
|
@@ -7219,7 +7259,7 @@ function toDocumentJson(document2) {
|
|
|
7219
7259
|
|
|
7220
7260
|
// src/document/jsonCommands.ts
|
|
7221
7261
|
function isInlineCommand(command) {
|
|
7222
|
-
return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token";
|
|
7262
|
+
return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token" || command.op === "set_equation_numbering";
|
|
7223
7263
|
}
|
|
7224
7264
|
function isListCommand(command) {
|
|
7225
7265
|
return command.op === "insert_list" || command.op === "insert_list_item" || command.op === "replace_list_item" || command.op === "remove_list_item" || command.op === "move_list_item";
|
|
@@ -7334,7 +7374,7 @@ function parseCommand2(value) {
|
|
|
7334
7374
|
if (!isObject3(value) || typeof value.op !== "string") {
|
|
7335
7375
|
throw new DocumentCommandError("invalid_command", "command requires an op");
|
|
7336
7376
|
}
|
|
7337
|
-
if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token") {
|
|
7377
|
+
if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token" || value.op === "set_equation_numbering") {
|
|
7338
7378
|
return parseInlineCommand(value);
|
|
7339
7379
|
}
|
|
7340
7380
|
if (value.op === "insert_list" || value.op === "insert_list_item" || value.op === "replace_list_item" || value.op === "remove_list_item" || value.op === "move_list_item") {
|
|
@@ -7468,7 +7508,7 @@ function applyBasicCommand(document2, command) {
|
|
|
7468
7508
|
if (label2 !== void 0 && label2.length > 0) {
|
|
7469
7509
|
const keyError = documentKeyError(label2, {
|
|
7470
7510
|
references: document2.references,
|
|
7471
|
-
labels:
|
|
7511
|
+
labels: collectDocumentKeyLabels(document2),
|
|
7472
7512
|
excludeOwnerId: block2.id
|
|
7473
7513
|
});
|
|
7474
7514
|
if (keyError === "duplicate") {
|
|
@@ -7723,7 +7763,7 @@ function getDocumentReferences(document2) {
|
|
|
7723
7763
|
function getDocumentReferenceIndex(document2) {
|
|
7724
7764
|
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
7725
7765
|
const labelEntries = collectDocumentLabels(document2);
|
|
7726
|
-
const labelKeys = new Set(
|
|
7766
|
+
const labelKeys = new Set(labelNumberMap(document2).keys());
|
|
7727
7767
|
const citations = [];
|
|
7728
7768
|
const crossReferences = [];
|
|
7729
7769
|
const tokenLocations = /* @__PURE__ */ new Map();
|
|
@@ -7806,6 +7846,14 @@ function getDocumentReferenceIndex(document2) {
|
|
|
7806
7846
|
citations,
|
|
7807
7847
|
cross_references: crossReferences,
|
|
7808
7848
|
labels,
|
|
7849
|
+
reference_targets: collectDocumentReferenceTargets(document2).map((target) => ({
|
|
7850
|
+
key: target.key,
|
|
7851
|
+
kind: target.kind,
|
|
7852
|
+
caption: target.caption,
|
|
7853
|
+
number: target.number,
|
|
7854
|
+
...target.kind === "eq" ? { token_id: target.ownerId } : { block_id: target.ownerId },
|
|
7855
|
+
...target.manualKey ? { manual_key: target.manualKey } : {}
|
|
7856
|
+
})),
|
|
7809
7857
|
unresolved: {
|
|
7810
7858
|
citation_keys: unresolvedCitationKeys,
|
|
7811
7859
|
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
@@ -8047,9 +8095,13 @@ function digitsMappingFromDigitForm(digitForm) {
|
|
|
8047
8095
|
}
|
|
8048
8096
|
return "arabicdigits";
|
|
8049
8097
|
}
|
|
8098
|
+
function editorMathLatexForCompile(token) {
|
|
8099
|
+
const source = token.math && token.sourceSide === "arabic" && token.source.includes("\\begin{cases}") ? mathTokenSourceForSide(token, "arabic", void 0, true) : token.source;
|
|
8100
|
+
return mirrorBuTeXOperatorsInTex(source, { target: "compile" });
|
|
8101
|
+
}
|
|
8050
8102
|
function mathBodyLatex(token) {
|
|
8051
8103
|
if (token.sourceOwner === "editor") {
|
|
8052
|
-
return stripDisplayMathDelimiters(
|
|
8104
|
+
return stripDisplayMathDelimiters(editorMathLatexForCompile(token));
|
|
8053
8105
|
}
|
|
8054
8106
|
if (!token.math || token.sourceOwner === "raw") {
|
|
8055
8107
|
return stripDisplayMathDelimiters(token.source);
|
|
@@ -8116,15 +8168,18 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
8116
8168
|
if (token.kind === "ref") {
|
|
8117
8169
|
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
8118
8170
|
}
|
|
8119
|
-
if (token
|
|
8171
|
+
if (isNumberedEquation(token)) {
|
|
8120
8172
|
const body = mathBodyLatex(token);
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
\\end{equation}
|
|
8173
|
+
const autoKey = implicitReferenceKey("eq", token.id);
|
|
8174
|
+
const aliases = [autoKey];
|
|
8175
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
8176
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
8177
|
+
}
|
|
8178
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
8179
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
8125
8180
|
}
|
|
8126
8181
|
if (token.sourceOwner === "editor") {
|
|
8127
|
-
return
|
|
8182
|
+
return editorMathLatexForCompile(token);
|
|
8128
8183
|
}
|
|
8129
8184
|
if (!token.math || token.sourceOwner === "raw") {
|
|
8130
8185
|
return token.source;
|
|
@@ -8191,11 +8246,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
8191
8246
|
if (hasCaption) {
|
|
8192
8247
|
lines.push(` \\caption{${caption}}`);
|
|
8193
8248
|
}
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
lines.push(
|
|
8249
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
8250
|
+
if (hasCaption || hasManualLabel) {
|
|
8251
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
8252
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
8253
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
8254
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
8199
8255
|
}
|
|
8200
8256
|
return lines;
|
|
8201
8257
|
}
|
|
@@ -8291,10 +8347,8 @@ ${meta.abstract.trim()}
|
|
|
8291
8347
|
}
|
|
8292
8348
|
function documentLabelKindMap(document2) {
|
|
8293
8349
|
const map = /* @__PURE__ */ new Map();
|
|
8294
|
-
for (const entry of
|
|
8295
|
-
|
|
8296
|
-
map.set(entry.key, entry.kind);
|
|
8297
|
-
}
|
|
8350
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
8351
|
+
map.set(key, entry.kind);
|
|
8298
8352
|
}
|
|
8299
8353
|
return map;
|
|
8300
8354
|
}
|
|
@@ -8393,10 +8447,17 @@ function validateToken(context, token, path, blockId) {
|
|
|
8393
8447
|
return;
|
|
8394
8448
|
}
|
|
8395
8449
|
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
8450
|
+
if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
|
|
8451
|
+
addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
|
|
8452
|
+
}
|
|
8396
8453
|
if (!token.labelEnabled) {
|
|
8397
8454
|
return;
|
|
8398
8455
|
}
|
|
8399
|
-
if (!token
|
|
8456
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
8457
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
8458
|
+
return;
|
|
8459
|
+
}
|
|
8460
|
+
if (!isNumberedEquation(token)) {
|
|
8400
8461
|
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
8401
8462
|
return;
|
|
8402
8463
|
}
|
|
@@ -8494,7 +8555,7 @@ function validatePendingReferences(context) {
|
|
|
8494
8555
|
for (const pending of context.pendingReferences) {
|
|
8495
8556
|
for (const key of pending.token.keys) {
|
|
8496
8557
|
const normalized = normalizeDocumentKey(key);
|
|
8497
|
-
if (!isValidDocumentKey(normalized)) {
|
|
8558
|
+
if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
|
|
8498
8559
|
addIssue(
|
|
8499
8560
|
context,
|
|
8500
8561
|
"missing_reference",
|
|
@@ -8593,6 +8654,18 @@ function validateDocument(document2) {
|
|
|
8593
8654
|
resolved.blocks.forEach((block, index) => {
|
|
8594
8655
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
8595
8656
|
});
|
|
8657
|
+
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
8658
|
+
if (target.number !== null && target.manualKey !== target.key) {
|
|
8659
|
+
registerKey(
|
|
8660
|
+
context,
|
|
8661
|
+
target.key,
|
|
8662
|
+
"$.automatic_labels",
|
|
8663
|
+
target.kind,
|
|
8664
|
+
target.kind === "eq" ? void 0 : target.ownerId,
|
|
8665
|
+
target.kind === "eq" ? target.ownerId : void 0
|
|
8666
|
+
);
|
|
8667
|
+
}
|
|
8668
|
+
}
|
|
8596
8669
|
for (const diagnostic of resolved.diagnostics) {
|
|
8597
8670
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
8598
8671
|
}
|
|
@@ -8741,6 +8814,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
8741
8814
|
})
|
|
8742
8815
|
};
|
|
8743
8816
|
}
|
|
8817
|
+
const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
|
|
8744
8818
|
const island = {
|
|
8745
8819
|
id: token.id,
|
|
8746
8820
|
tex: mathTex(token, equationSide, previewOptions.digitForm),
|
|
@@ -8748,8 +8822,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
8748
8822
|
output,
|
|
8749
8823
|
editable: token.editable
|
|
8750
8824
|
};
|
|
8825
|
+
const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
|
|
8826
|
+
documentDirection: previewOptions.documentDirection,
|
|
8827
|
+
digitForm: previewOptions.digitForm
|
|
8828
|
+
});
|
|
8751
8829
|
islands.push(island);
|
|
8752
|
-
return { kind: "math", ...island };
|
|
8830
|
+
return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
|
|
8753
8831
|
});
|
|
8754
8832
|
}
|
|
8755
8833
|
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
@@ -8772,12 +8850,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
|
|
|
8772
8850
|
...block.centered ? { centered: true } : {}
|
|
8773
8851
|
};
|
|
8774
8852
|
}
|
|
8775
|
-
function floatNumberLabel(document2,
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
}
|
|
8779
|
-
const hit = labelNumberMap(document2).get(key.trim());
|
|
8780
|
-
if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
8853
|
+
function floatNumberLabel(document2, ownerId, previewOptions) {
|
|
8854
|
+
const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
|
|
8855
|
+
if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
8781
8856
|
return void 0;
|
|
8782
8857
|
}
|
|
8783
8858
|
return formatFloatCaptionTitle(hit.kind, hit.number, {
|
|
@@ -8819,7 +8894,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8819
8894
|
id: block.id,
|
|
8820
8895
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
8821
8896
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8822
|
-
...label.length > 0 ? { label
|
|
8897
|
+
...label.length > 0 ? { label } : {},
|
|
8898
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
8823
8899
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8824
8900
|
};
|
|
8825
8901
|
}
|
|
@@ -8833,7 +8909,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
8833
8909
|
options: block.options,
|
|
8834
8910
|
centered: block.centered,
|
|
8835
8911
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
8836
|
-
...label.length > 0 ? { label
|
|
8912
|
+
...label.length > 0 ? { label } : {},
|
|
8913
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
8837
8914
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
8838
8915
|
};
|
|
8839
8916
|
}
|
|
@@ -8948,7 +9025,9 @@ export {
|
|
|
8948
9025
|
clearDocumentImageAsset,
|
|
8949
9026
|
cloneDocumentMeta,
|
|
8950
9027
|
cloneDocumentNode,
|
|
9028
|
+
collectDocumentKeyLabels,
|
|
8951
9029
|
collectDocumentLabels,
|
|
9030
|
+
collectDocumentReferenceTargets,
|
|
8952
9031
|
createDocumentHistory,
|
|
8953
9032
|
createEmptyArabicEquationSession,
|
|
8954
9033
|
createEmptyDocument,
|
|
@@ -8986,6 +9065,7 @@ export {
|
|
|
8986
9065
|
getDocumentReferences,
|
|
8987
9066
|
hasXeLatexUnsupportedEmoji,
|
|
8988
9067
|
hijriMonthLabel,
|
|
9068
|
+
implicitReferenceKey,
|
|
8989
9069
|
inlineFieldLatex,
|
|
8990
9070
|
insertCiteTokenAtCaret,
|
|
8991
9071
|
insertDocumentBlockAfter,
|
|
@@ -8994,6 +9074,8 @@ export {
|
|
|
8994
9074
|
insertRefTokenAtCaret,
|
|
8995
9075
|
isDocumentValid,
|
|
8996
9076
|
isDuplicateDocumentKey,
|
|
9077
|
+
isNumberedEquation,
|
|
9078
|
+
isNumberedFloat,
|
|
8997
9079
|
isValidDocumentKey,
|
|
8998
9080
|
labelNumberMap,
|
|
8999
9081
|
mathNodeFromArabicSession,
|