@drghaliasri/butex 8.1.3 → 8.2.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/dist/book.mjs CHANGED
@@ -5493,6 +5493,7 @@ function bookContextForUnit(snapshot, unitId) {
5493
5493
  kind: t.kind,
5494
5494
  ...t.caption !== void 0 ? { caption: t.caption } : {},
5495
5495
  ...t.displayLabel !== void 0 ? { displayLabel: t.displayLabel } : {},
5496
+ ...t.ordinal !== void 0 ? { ordinal: t.ordinal } : {},
5496
5497
  ...t.manualKey !== void 0 ? { manualKey: t.manualKey } : {}
5497
5498
  })) };
5498
5499
  }
@@ -5599,6 +5600,21 @@ function bookPreamble(snapshot) {
5599
5600
  "\\renewcommand{\\contentsname}{\u0627\u0644\u0645\u062D\u062A\u0648\u064A\u0627\u062A}"
5600
5601
  ].join("\n");
5601
5602
  }
5603
+ function normalizeBookEquationLabels(content, unitId, projection) {
5604
+ const aliases = /* @__PURE__ */ new Map();
5605
+ let latex = content;
5606
+ for (const target of projection.targets) {
5607
+ if (target.kind !== "eq" || !target.manualKey || target.manualKey === target.key) continue;
5608
+ aliases.set(target.manualKey, target.key);
5609
+ if (target.unitId === unitId) {
5610
+ const automatic = "\\label{" + target.key + "}";
5611
+ const manual = "\\label{" + target.manualKey + "}";
5612
+ latex = latex.replace(automatic + "\n" + manual, automatic);
5613
+ }
5614
+ }
5615
+ if (!aliases.size) return latex;
5616
+ return latex.replace(/\\(eqref|ref)\{([^}]*)\}/g, (_whole, command, keys) => "\\" + command + "{" + keys.split(",").map((key) => aliases.get(key.trim()) ?? key).join(",") + "}");
5617
+ }
5602
5618
  function book2Latex(raw, _options = {}) {
5603
5619
  const snapshot = normalizeBookSnapshot(raw);
5604
5620
  const projection = resolveBookSnapshot(snapshot);
@@ -5666,7 +5682,7 @@ function book2Latex(raw, _options = {}) {
5666
5682
  references: snapshot.references.references,
5667
5683
  targets: projection.targets
5668
5684
  };
5669
- const content = documentContentLatex(fromDocumentJson(doc), context);
5685
+ const content = normalizeBookEquationLabels(documentContentLatex(fromDocumentJson(doc), context), entry.id, projection);
5670
5686
  files[unitPath] = [unitBoundary(entry, projection, unnumbered), content, ""].join("\n\n");
5671
5687
  main.push("\\input{" + unitPath + "}");
5672
5688
  if (!((entry.type === "chapter" || entry.type === "appendix") && entry.numbered)) {