typst/typst · error

label `{}` occurs both in the document and a bibliography

Error message

label `{}` occurs both in the document and a bibliography

What it means

Raised in reference realization: the referenced label exists both as an element in the document and as an entry in the bibliography, so Typst cannot decide which to resolve to.

Source

Thrown at crates/typst-library/src/model/reference.rs:265

                ))
                .at(span)?;
            let supplement = engine.introspect(PageSupplementIntrospection(loc, span));

            return realize_reference(
                self,
                engine,
                styles,
                Counter::new(CounterKey::Page),
                numbering,
                supplement,
                elem,
            );
        }
        // RefForm::Normal

        if BibliographyElem::has(engine, self.target, span) {
            if let Ok(elem) = elem {
                bail!(
                    span,
                    "label `{}` occurs both in the document and a 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));
        }

        let elem = elem.at(span)?;

        if let Some(footnote) = elem.to_packed::<FootnoteElem>() {
            return Ok(footnote.into_ref(self.target).pack().spanned(span));
        }

View on GitHub (pinned to 35417aa769)

Solutions

  1. Rename one of the labels so they differ
  2. Remove the bibliography entry or the in-document label
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/typst-library/src/model/reference.rs:265 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of typst/typst@35417aa769 (2026-08-17). Data as JSON: /api/errors/ea323c19d32ccd0f. Report an issue: GitHub.