summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-06-19 09:29:38 +0200
committerGitHub <noreply@github.com>2025-06-19 07:29:38 +0000
commit0bc68df2a9a87ca7e36e34dab56b07c666d64760 (patch)
treebf42ac0e1785465035d4611235bc0991ee3af27e
parentf32cd5b3e1e9b5c81f8fe72042212a7c7d3a43a7 (diff)
Hint for label in both document and bibliography (#6457)
-rw-r--r--crates/typst-library/src/model/reference.rs13
-rw-r--r--tests/suite/model/ref.typ3
2 files changed, 12 insertions, 4 deletions
diff --git a/crates/typst-library/src/model/reference.rs b/crates/typst-library/src/model/reference.rs
index 7d44cccc..f22d70b3 100644
--- a/crates/typst-library/src/model/reference.rs
+++ b/crates/typst-library/src/model/reference.rs
@@ -5,7 +5,7 @@ use crate::diag::{bail, At, Hint, SourceResult};
use crate::engine::Engine;
use crate::foundations::{
cast, elem, Cast, Content, Context, Func, IntoValue, Label, NativeElement, Packed,
- Show, Smart, StyleChain, Synthesize,
+ Repr, Show, Smart, StyleChain, Synthesize,
};
use crate::introspection::{Counter, CounterKey, Locatable};
use crate::math::EquationElem;
@@ -229,8 +229,15 @@ impl Show for Packed<RefElem> {
// RefForm::Normal
if BibliographyElem::has(engine, self.target) {
- if elem.is_ok() {
- bail!(span, "label occurs in the document and its bibliography");
+ if let Ok(elem) = elem {
+ bail!(
+ span,
+ "label `{}` occurs both in the document and its bibliography",
+ self.target.repr();
+ hint: "change either the {}'s label or the \
+ bibliography key to resolve the ambiguity",
+ elem.func().name(),
+ );
}
return Ok(to_citation(self, engine, styles)?.pack().spanned(span));
diff --git a/tests/suite/model/ref.typ b/tests/suite/model/ref.typ
index 2f8e2fa2..87b1c409 100644
--- a/tests/suite/model/ref.typ
+++ b/tests/suite/model/ref.typ
@@ -51,7 +51,8 @@ $ A = 1 $ <eq2>
// Test ambiguous reference.
= Introduction <arrgh>
-// Error: 1-7 label occurs in the document and its bibliography
+// Error: 1-7 label `<arrgh>` occurs both in the document and its bibliography
+// Hint: 1-7 change either the heading's label or the bibliography key to resolve the ambiguity
@arrgh
#bibliography("/assets/bib/works.bib")