@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.
- package/README.md +7 -7
- package/dist/document-cli.js +158 -86
- 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 +181 -98
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +176 -98
- 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 +171 -113
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +171 -113
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Node.js **20+** is required for tooling/worker usage. MathJax `^4.1.0` is a peer
|
|
|
25
25
|
| `@drghaliasri/butex/react-document-preview` | Lightweight read-only `ButexDocumentPreview` |
|
|
26
26
|
| `butex-document` | Stateless stdin / authenticated HTTP worker |
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
The completed **Document2 → Document** migration retired the first-generation editor and promoted the maintained model, worker and React editor to the unversioned names above. These are the current **8.0.3** package interfaces, not pending migration-branch APIs. See the [post-fix verification](docs/development/document-migration-postfix-20261108.md) for evidence and release qualifications.
|
|
29
29
|
|
|
30
30
|
## MathJax setup
|
|
31
31
|
|
|
@@ -47,20 +47,20 @@ See [math/rendering architecture](docs/architecture/equations.md) for initializa
|
|
|
47
47
|
```ts
|
|
48
48
|
import {
|
|
49
49
|
createEmptyDocument,
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
fromDocumentJson,
|
|
51
|
+
toDocumentJson,
|
|
52
52
|
validateDocument,
|
|
53
53
|
} from '@drghaliasri/butex/document';
|
|
54
54
|
|
|
55
55
|
const document = createEmptyDocument();
|
|
56
56
|
const validation = validateDocument(document);
|
|
57
|
-
const saved =
|
|
58
|
-
const restored =
|
|
57
|
+
const saved = toDocumentJson(document);
|
|
58
|
+
const restored = fromDocumentJson(saved);
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
Use `ButexDocumentEditor` from `@drghaliasri/butex/react-document` for the interactive editor; use `ButexDocumentPreview` from `@drghaliasri/butex/react-document-preview` to show read-only snapshots.
|
|
62
62
|
|
|
63
|
-
Renaming an enabled figure/table label with `update_float_meta` also updates matching
|
|
63
|
+
Renaming an enabled figure/table label with `update_float_meta` also updates matching `\ref`/`\eqref` tokens throughout the document in the same edit; disabling or clearing a label leaves references unchanged.
|
|
64
64
|
|
|
65
65
|
**Host responsibility:** authentication, article permissions, immutable revisions, image uploads/storage, compilation and publishing. BuTeX supplies pure Document transformations and editing UI, never an article database or MCP authorization bypass. See [Document](docs/architecture/document.md), [React integration](docs/architecture/react-editor.md), and [the worker](docs/architecture/worker.md).
|
|
66
66
|
|
|
@@ -84,7 +84,7 @@ The [BuTeX book design](docs/proposals/book-editor.md) and [Al-Bayan integration
|
|
|
84
84
|
|
|
85
85
|
- [Architecture](docs/architecture/README.md) — implemented package and host contracts
|
|
86
86
|
- [Development](docs/development/README.md) — building, browser testing and releases
|
|
87
|
-
- [Proposals](docs/proposals/README.md) — book authoring and
|
|
87
|
+
- [Proposals](docs/proposals/README.md) — book authoring and completed Document migration evidence
|
|
88
88
|
- [Archive](docs/archive/README.md) — historical design records
|
|
89
89
|
|
|
90
90
|
The npm tarball includes `dist/` and this README; `docs/` live in the [GitLab repository](https://gitlab.com/drghaliasri/butex).
|
package/dist/document-cli.js
CHANGED
|
@@ -754,76 +754,88 @@ function refTokenLatex(keys, refCommand) {
|
|
|
754
754
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
755
755
|
return `${command}{${keys.join(",")}}`;
|
|
756
756
|
}
|
|
757
|
-
function
|
|
758
|
-
const
|
|
757
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
758
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
759
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
760
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
761
|
+
}
|
|
762
|
+
function supportsSingleEquationNumbering(token) {
|
|
763
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
764
|
+
}
|
|
765
|
+
function isNumberedEquation(token) {
|
|
766
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
767
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
768
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
769
|
+
}
|
|
770
|
+
function isNumberedFloat(block) {
|
|
771
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
772
|
+
}
|
|
773
|
+
function collectDocumentReferenceTargets(document2) {
|
|
774
|
+
const targets = [];
|
|
759
775
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
760
|
-
function
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
776
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
777
|
+
if (numbered) counters[kind] += 1;
|
|
778
|
+
targets.push({
|
|
779
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
780
|
+
kind,
|
|
781
|
+
ownerId,
|
|
782
|
+
caption,
|
|
783
|
+
number: numbered ? counters[kind] : null,
|
|
784
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
function visitField(field) {
|
|
788
|
+
for (const token of field.tokens) {
|
|
789
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
790
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
774
791
|
}
|
|
775
792
|
}
|
|
776
793
|
}
|
|
777
794
|
function walk(blocks) {
|
|
778
795
|
for (const block of blocks) {
|
|
779
|
-
if (block.kind === "image") {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
if (block.captionEnabled) {
|
|
791
|
-
pushEqFromField(block.captionField.tokens);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
if (block.kind === "table") {
|
|
795
|
-
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
796
|
-
counters.tab += 1;
|
|
797
|
-
entries.push({
|
|
798
|
-
key: block.label.trim(),
|
|
799
|
-
kind: "tab",
|
|
800
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
801
|
-
ownerId: block.id,
|
|
802
|
-
number: counters.tab
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
if (block.captionEnabled) {
|
|
806
|
-
pushEqFromField(block.captionField.tokens);
|
|
807
|
-
}
|
|
808
|
-
for (const row of block.rows) {
|
|
809
|
-
for (const cell of row) {
|
|
810
|
-
pushEqFromField(cell.tokens);
|
|
811
|
-
}
|
|
796
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
797
|
+
append(
|
|
798
|
+
block.kind === "image" ? "fig" : "tab",
|
|
799
|
+
block.id,
|
|
800
|
+
block.captionEnabled ? block.caption : "",
|
|
801
|
+
isNumberedFloat(block),
|
|
802
|
+
block.labelEnabled ? block.label : ""
|
|
803
|
+
);
|
|
804
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
805
|
+
if (block.kind === "table") {
|
|
806
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
812
807
|
}
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
if (block.kind === "list") {
|
|
808
|
+
} else if (block.kind === "textBlock") {
|
|
809
|
+
visitField(block.field);
|
|
810
|
+
} else if (block.kind === "list") {
|
|
818
811
|
for (const item of block.items) {
|
|
819
|
-
|
|
812
|
+
visitField(item.field);
|
|
820
813
|
walk(item.blocks);
|
|
821
814
|
}
|
|
822
815
|
}
|
|
823
816
|
}
|
|
824
817
|
}
|
|
825
818
|
walk(document2.blocks);
|
|
826
|
-
return
|
|
819
|
+
return targets;
|
|
820
|
+
}
|
|
821
|
+
function collectDocumentLabels(document2) {
|
|
822
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
|
|
823
|
+
}
|
|
824
|
+
function collectDocumentKeyLabels(document2) {
|
|
825
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null).flatMap((target) => [
|
|
826
|
+
{ key: target.key, ownerId: target.ownerId },
|
|
827
|
+
...target.manualKey && target.manualKey !== target.key ? [{ key: target.manualKey, ownerId: target.ownerId }] : []
|
|
828
|
+
]);
|
|
829
|
+
}
|
|
830
|
+
function labelNumberMap(document2) {
|
|
831
|
+
const map = /* @__PURE__ */ new Map();
|
|
832
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
833
|
+
if (target.number === null) continue;
|
|
834
|
+
for (const key of [target.key, target.manualKey]) {
|
|
835
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return map;
|
|
827
839
|
}
|
|
828
840
|
function stripDisplayMathDelimiters(source) {
|
|
829
841
|
const trimmed = source.trim();
|
|
@@ -833,8 +845,12 @@ function stripDisplayMathDelimiters(source) {
|
|
|
833
845
|
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
834
846
|
return trimmed.slice(2, -2).trim();
|
|
835
847
|
}
|
|
836
|
-
|
|
837
|
-
|
|
848
|
+
for (const environment of ["equation", "equation*"]) {
|
|
849
|
+
const opening = `\\begin{${environment}}`;
|
|
850
|
+
const closing = `\\end{${environment}}`;
|
|
851
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
852
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
853
|
+
}
|
|
838
854
|
}
|
|
839
855
|
return trimmed;
|
|
840
856
|
}
|
|
@@ -1227,7 +1243,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1227
1243
|
editable: true,
|
|
1228
1244
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1229
1245
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1230
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1246
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1247
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1231
1248
|
});
|
|
1232
1249
|
} else {
|
|
1233
1250
|
tokens.push({
|
|
@@ -1242,7 +1259,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1242
1259
|
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",
|
|
1243
1260
|
sourceOwner: "raw",
|
|
1244
1261
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1245
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1262
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1263
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1246
1264
|
});
|
|
1247
1265
|
}
|
|
1248
1266
|
index = span.end;
|
|
@@ -4944,7 +4962,7 @@ function normalizedNewFloatLabel(document2, label) {
|
|
|
4944
4962
|
if (!normalized) return "";
|
|
4945
4963
|
const error = documentKeyError(normalized, {
|
|
4946
4964
|
references: document2.references,
|
|
4947
|
-
labels:
|
|
4965
|
+
labels: collectDocumentKeyLabels(document2)
|
|
4948
4966
|
});
|
|
4949
4967
|
if (error === "duplicate") {
|
|
4950
4968
|
throw new DocumentCommandError("duplicate_key", "Float label is already in use");
|
|
@@ -5388,7 +5406,7 @@ function validateReferenceKey(document2, key, excludeReferenceId) {
|
|
|
5388
5406
|
const normalized = normalizeDocumentKey(key);
|
|
5389
5407
|
const error = documentKeyError(normalized, {
|
|
5390
5408
|
references: document2.references,
|
|
5391
|
-
labels:
|
|
5409
|
+
labels: collectDocumentKeyLabels(document2),
|
|
5392
5410
|
...excludeReferenceId ? { excludeReferenceId } : {}
|
|
5393
5411
|
});
|
|
5394
5412
|
if (error === "duplicate") {
|
|
@@ -5610,6 +5628,17 @@ function parseToken(value) {
|
|
|
5610
5628
|
throw new DocumentCommandError("invalid_inline_token", "Unsupported inline token kind");
|
|
5611
5629
|
}
|
|
5612
5630
|
function parseInlineCommand(value) {
|
|
5631
|
+
if (value.op === "set_equation_numbering") {
|
|
5632
|
+
if (typeof value.numbered !== "boolean") {
|
|
5633
|
+
throw new DocumentCommandError("invalid_command", "numbered must be boolean");
|
|
5634
|
+
}
|
|
5635
|
+
return {
|
|
5636
|
+
op: "set_equation_numbering",
|
|
5637
|
+
field_id: requireString2(value.field_id, "field_id", false).trim(),
|
|
5638
|
+
token_id: requireString2(value.token_id, "token_id", false).trim(),
|
|
5639
|
+
numbered: value.numbered
|
|
5640
|
+
};
|
|
5641
|
+
}
|
|
5613
5642
|
if (value.op === "insert_inline_token") {
|
|
5614
5643
|
return {
|
|
5615
5644
|
op: value.op,
|
|
@@ -5663,7 +5692,8 @@ function liveToken(input, id) {
|
|
|
5663
5692
|
editable: true,
|
|
5664
5693
|
sourceOwner: mathObject.source_owner === "editor" ? "editor" : "imported-structured",
|
|
5665
5694
|
...mathObject.label_enabled !== void 0 ? { labelEnabled: mathObject.label_enabled } : {},
|
|
5666
|
-
...mathObject.label !== void 0 ? { label: mathObject.label } : {}
|
|
5695
|
+
...mathObject.label !== void 0 ? { label: mathObject.label } : {},
|
|
5696
|
+
...mathObject.numbered !== void 0 ? { numbered: mathObject.numbered } : {}
|
|
5667
5697
|
};
|
|
5668
5698
|
}
|
|
5669
5699
|
function insertionIndex(tokens, anchor) {
|
|
@@ -5685,6 +5715,17 @@ function applyInlineCommand(document2, command) {
|
|
|
5685
5715
|
if (!field) {
|
|
5686
5716
|
throw new DocumentCommandError("field_not_found", "Inline field was not found");
|
|
5687
5717
|
}
|
|
5718
|
+
if (command.op === "set_equation_numbering") {
|
|
5719
|
+
const token = field.tokens.find((entry) => entry.id === command.token_id);
|
|
5720
|
+
if (!token || token.kind !== "math") {
|
|
5721
|
+
throw new DocumentCommandError("token_not_found", "Equation token was not found");
|
|
5722
|
+
}
|
|
5723
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
5724
|
+
throw new DocumentCommandError("invalid_inline_token", "Only a single display equation can be numbered");
|
|
5725
|
+
}
|
|
5726
|
+
token.numbered = command.numbered;
|
|
5727
|
+
return;
|
|
5728
|
+
}
|
|
5688
5729
|
if (command.op === "insert_inline_token") {
|
|
5689
5730
|
const index2 = insertionIndex(field.tokens, command.anchor);
|
|
5690
5731
|
field.tokens.splice(index2, 0, liveToken(command.token, newTokenId(document2, command.token.kind)));
|
|
@@ -6037,12 +6078,13 @@ function serializeField(field) {
|
|
|
6037
6078
|
}
|
|
6038
6079
|
value += token.source;
|
|
6039
6080
|
if (!token.math || token.sourceOwner === "raw") {
|
|
6040
|
-
if (token.labelEnabled !== void 0 || token.label !== void 0) {
|
|
6081
|
+
if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
|
|
6041
6082
|
hasPersistedMath = true;
|
|
6042
6083
|
mathObjects.push({
|
|
6043
6084
|
node_type: "RawMathObject",
|
|
6044
6085
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
6045
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
6086
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
6087
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
6046
6088
|
});
|
|
6047
6089
|
} else {
|
|
6048
6090
|
mathObjects.push(null);
|
|
@@ -6055,7 +6097,8 @@ function serializeField(field) {
|
|
|
6055
6097
|
...token.sourceSide ? { source_side: token.sourceSide } : {},
|
|
6056
6098
|
source_owner: token.sourceOwner,
|
|
6057
6099
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
6058
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
6100
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
6101
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
6059
6102
|
});
|
|
6060
6103
|
}
|
|
6061
6104
|
return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
|
|
@@ -6188,7 +6231,7 @@ function toDocumentJson(document2) {
|
|
|
6188
6231
|
|
|
6189
6232
|
// src/document/jsonCommands.ts
|
|
6190
6233
|
function isInlineCommand(command) {
|
|
6191
|
-
return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token";
|
|
6234
|
+
return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token" || command.op === "set_equation_numbering";
|
|
6192
6235
|
}
|
|
6193
6236
|
function isListCommand(command) {
|
|
6194
6237
|
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";
|
|
@@ -6303,7 +6346,7 @@ function parseCommand2(value) {
|
|
|
6303
6346
|
if (!isObject3(value) || typeof value.op !== "string") {
|
|
6304
6347
|
throw new DocumentCommandError("invalid_command", "command requires an op");
|
|
6305
6348
|
}
|
|
6306
|
-
if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token") {
|
|
6349
|
+
if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token" || value.op === "set_equation_numbering") {
|
|
6307
6350
|
return parseInlineCommand(value);
|
|
6308
6351
|
}
|
|
6309
6352
|
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") {
|
|
@@ -6437,7 +6480,7 @@ function applyBasicCommand(document2, command) {
|
|
|
6437
6480
|
if (label2 !== void 0 && label2.length > 0) {
|
|
6438
6481
|
const keyError = documentKeyError(label2, {
|
|
6439
6482
|
references: document2.references,
|
|
6440
|
-
labels:
|
|
6483
|
+
labels: collectDocumentKeyLabels(document2),
|
|
6441
6484
|
excludeOwnerId: block2.id
|
|
6442
6485
|
});
|
|
6443
6486
|
if (keyError === "duplicate") {
|
|
@@ -6692,7 +6735,7 @@ function getDocumentReferences(document2) {
|
|
|
6692
6735
|
function getDocumentReferenceIndex(document2) {
|
|
6693
6736
|
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
6694
6737
|
const labelEntries = collectDocumentLabels(document2);
|
|
6695
|
-
const labelKeys = new Set(
|
|
6738
|
+
const labelKeys = new Set(labelNumberMap(document2).keys());
|
|
6696
6739
|
const citations = [];
|
|
6697
6740
|
const crossReferences = [];
|
|
6698
6741
|
const tokenLocations = /* @__PURE__ */ new Map();
|
|
@@ -6775,6 +6818,14 @@ function getDocumentReferenceIndex(document2) {
|
|
|
6775
6818
|
citations,
|
|
6776
6819
|
cross_references: crossReferences,
|
|
6777
6820
|
labels,
|
|
6821
|
+
reference_targets: collectDocumentReferenceTargets(document2).map((target) => ({
|
|
6822
|
+
key: target.key,
|
|
6823
|
+
kind: target.kind,
|
|
6824
|
+
caption: target.caption,
|
|
6825
|
+
number: target.number,
|
|
6826
|
+
...target.kind === "eq" ? { token_id: target.ownerId } : { block_id: target.ownerId },
|
|
6827
|
+
...target.manualKey ? { manual_key: target.manualKey } : {}
|
|
6828
|
+
})),
|
|
6778
6829
|
unresolved: {
|
|
6779
6830
|
citation_keys: unresolvedCitationKeys,
|
|
6780
6831
|
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
@@ -7089,12 +7140,15 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
7089
7140
|
if (token.kind === "ref") {
|
|
7090
7141
|
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
7091
7142
|
}
|
|
7092
|
-
if (token
|
|
7143
|
+
if (isNumberedEquation(token)) {
|
|
7093
7144
|
const body = mathBodyLatex(token);
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
\\end{equation}
|
|
7145
|
+
const autoKey = implicitReferenceKey("eq", token.id);
|
|
7146
|
+
const aliases = [autoKey];
|
|
7147
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
7148
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
7149
|
+
}
|
|
7150
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
7151
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
7098
7152
|
}
|
|
7099
7153
|
if (token.sourceOwner === "editor") {
|
|
7100
7154
|
return editorMathLatexForCompile(token);
|
|
@@ -7161,11 +7215,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
7161
7215
|
if (hasCaption) {
|
|
7162
7216
|
lines.push(` \\caption{${caption}}`);
|
|
7163
7217
|
}
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
lines.push(
|
|
7218
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
7219
|
+
if (hasCaption || hasManualLabel) {
|
|
7220
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
7221
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
7222
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
7223
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
7169
7224
|
}
|
|
7170
7225
|
return lines;
|
|
7171
7226
|
}
|
|
@@ -7261,10 +7316,8 @@ ${meta.abstract.trim()}
|
|
|
7261
7316
|
}
|
|
7262
7317
|
function documentLabelKindMap(document2) {
|
|
7263
7318
|
const map = /* @__PURE__ */ new Map();
|
|
7264
|
-
for (const entry of
|
|
7265
|
-
|
|
7266
|
-
map.set(entry.key, entry.kind);
|
|
7267
|
-
}
|
|
7319
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
7320
|
+
map.set(key, entry.kind);
|
|
7268
7321
|
}
|
|
7269
7322
|
return map;
|
|
7270
7323
|
}
|
|
@@ -7363,10 +7416,17 @@ function validateToken(context, token, path, blockId) {
|
|
|
7363
7416
|
return;
|
|
7364
7417
|
}
|
|
7365
7418
|
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
7419
|
+
if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
|
|
7420
|
+
addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
|
|
7421
|
+
}
|
|
7366
7422
|
if (!token.labelEnabled) {
|
|
7367
7423
|
return;
|
|
7368
7424
|
}
|
|
7369
|
-
if (!token
|
|
7425
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
7426
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
7427
|
+
return;
|
|
7428
|
+
}
|
|
7429
|
+
if (!isNumberedEquation(token)) {
|
|
7370
7430
|
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
7371
7431
|
return;
|
|
7372
7432
|
}
|
|
@@ -7464,7 +7524,7 @@ function validatePendingReferences(context) {
|
|
|
7464
7524
|
for (const pending of context.pendingReferences) {
|
|
7465
7525
|
for (const key of pending.token.keys) {
|
|
7466
7526
|
const normalized = normalizeDocumentKey(key);
|
|
7467
|
-
if (!isValidDocumentKey(normalized)) {
|
|
7527
|
+
if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
|
|
7468
7528
|
addIssue(
|
|
7469
7529
|
context,
|
|
7470
7530
|
"missing_reference",
|
|
@@ -7563,6 +7623,18 @@ function validateDocument(document2) {
|
|
|
7563
7623
|
resolved.blocks.forEach((block, index) => {
|
|
7564
7624
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
7565
7625
|
});
|
|
7626
|
+
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
7627
|
+
if (target.number !== null && target.manualKey !== target.key) {
|
|
7628
|
+
registerKey(
|
|
7629
|
+
context,
|
|
7630
|
+
target.key,
|
|
7631
|
+
"$.automatic_labels",
|
|
7632
|
+
target.kind,
|
|
7633
|
+
target.kind === "eq" ? void 0 : target.ownerId,
|
|
7634
|
+
target.kind === "eq" ? target.ownerId : void 0
|
|
7635
|
+
);
|
|
7636
|
+
}
|
|
7637
|
+
}
|
|
7566
7638
|
for (const diagnostic of resolved.diagnostics) {
|
|
7567
7639
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
7568
7640
|
}
|