diff --git a/crates/typst/src/model/footnote.rs b/crates/typst/src/model/footnote.rs index f8f36eb23..2aeaad1a7 100644 --- a/crates/typst/src/model/footnote.rs +++ b/crates/typst/src/model/footnote.rs @@ -93,6 +93,15 @@ impl FootnoteElem { Self::new(FootnoteBody::Reference(label)) } + /// Creates a new footnote referencing the footnote with the specified label, + /// with the other fields from the current footnote cloned. + pub fn into_ref(&self, label: Label) -> Self { + Self { + body: FootnoteBody::Reference(label), + ..self.clone() + } + } + /// Tests if this footnote is a reference to another footnote. pub fn is_ref(&self) -> bool { matches!(self.body(), FootnoteBody::Reference(_)) diff --git a/crates/typst/src/model/reference.rs b/crates/typst/src/model/reference.rs index 511ca3d9a..8194eec53 100644 --- a/crates/typst/src/model/reference.rs +++ b/crates/typst/src/model/reference.rs @@ -177,8 +177,8 @@ impl Show for Packed { let elem = elem.at(span)?; - if elem.func() == FootnoteElem::elem() { - return Ok(FootnoteElem::with_label(target).pack().spanned(span)); + if let Some(footnote) = elem.to_packed::() { + return Ok(footnote.into_ref(target).pack().spanned(span)); } let elem = elem.clone(); diff --git a/tests/ref/issue-4454-footnote-ref-numbering.png b/tests/ref/issue-4454-footnote-ref-numbering.png new file mode 100644 index 000000000..0e89dbd91 Binary files /dev/null and b/tests/ref/issue-4454-footnote-ref-numbering.png differ diff --git a/tests/suite/model/footnote.typ b/tests/suite/model/footnote.typ index 34450ca4c..d72ca25a0 100644 --- a/tests/suite/model/footnote.typ +++ b/tests/suite/model/footnote.typ @@ -187,3 +187,7 @@ B #footnote[b] #set page(height: 50pt) #footnote[A] #footnote[B] + +--- issue-4454-footnote-ref-numbering --- +// Test that footnote references are numbered correctly. +A #footnote(numbering: "*")[B], C @fn, D @fn, E @fn.