diff --git a/crates/typst-library/src/math/equation.rs b/crates/typst-library/src/math/equation.rs index 32be216a4..145f45095 100644 --- a/crates/typst-library/src/math/equation.rs +++ b/crates/typst-library/src/math/equation.rs @@ -235,7 +235,10 @@ impl Outlinable for Packed { self.block(StyleChain::default()) && self.numbering().is_some() } - fn prefix(&self, numbers: Content) -> Content { + fn prefix(&self, numbers: Content, add_supplement: Smart) -> Content { + if add_supplement == Smart::Custom(false) { + return numbers; + } let supplement = self.supplement(); if !supplement.is_empty() { supplement + TextElem::packed('\u{a0}') + numbers diff --git a/crates/typst-library/src/model/figure.rs b/crates/typst-library/src/model/figure.rs index 78a79a8e2..ad7cbf9ff 100644 --- a/crates/typst-library/src/model/figure.rs +++ b/crates/typst-library/src/model/figure.rs @@ -436,7 +436,10 @@ impl Outlinable for Packed { || self.numbering().is_some()) } - fn prefix(&self, numbers: Content) -> Content { + fn prefix(&self, numbers: Content, add_supplement: Smart) -> Content { + if add_supplement == Smart::Custom(false) { + return numbers; + } let supplement = self.supplement(); if !supplement.is_empty() { supplement + TextElem::packed('\u{a0}') + numbers diff --git a/crates/typst-library/src/model/heading.rs b/crates/typst-library/src/model/heading.rs index 00931c815..f436d962d 100644 --- a/crates/typst-library/src/model/heading.rs +++ b/crates/typst-library/src/model/heading.rs @@ -364,8 +364,17 @@ impl Outlinable for Packed { (**self).resolve_level(StyleChain::default()) } - fn prefix(&self, numbers: Content) -> Content { - numbers + fn prefix(&self, numbers: Content, add_supplement: Smart) -> Content { + if add_supplement == Smart::Custom(true) { + let supplement = self.supplement(); + if !supplement.is_empty() { + supplement + TextElem::packed('\u{a0}') + numbers + } else { + numbers + } + } else { + numbers + } } fn body(&self) -> Content { diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs index 489c375e6..93c895663 100644 --- a/crates/typst-library/src/model/outline.rs +++ b/crates/typst-library/src/model/outline.rs @@ -357,7 +357,7 @@ pub trait Outlinable: Refable { } /// Constructs the default prefix given the formatted numbering. - fn prefix(&self, numbers: Content) -> Content; + fn prefix(&self, numbers: Content, add_supplement: Smart) -> Content; /// The body of the entry. fn body(&self) -> Content; @@ -421,7 +421,7 @@ impl Show for Packed { let context = Context::new(None, Some(styles)); let context = context.track(); - let prefix = self.prefix(engine, context, span)?; + let prefix = self.prefix(engine, context, span, Smart::Auto)?; let inner = self.inner(engine, context, span)?; let block = if self.element.is::() { let body = prefix.unwrap_or_default() + inner; @@ -542,16 +542,21 @@ impl OutlineEntry { } /// Formats the element's numbering (if any). - /// - /// This also appends the element's supplement in case of figures or - /// equations. For instance, it would output `1.1` for a heading, but - /// `Figure 1` for a figure, as is usual for outlines. #[func(contextual)] pub fn prefix( &self, engine: &mut Engine, context: Tracked, span: Span, + /// Whether to add the element's supplement if it has one. + /// + /// If set to `{auto}`, the supplement is added for figures and + /// equations that have one. For instance, it would output `[1.1]` + /// for a heading, but `[Figure 1]` for a figure, as is usual for + /// outlines. + #[named] + #[default] + add_supplement: Smart, ) -> SourceResult> { let outlinable = self.outlinable().at(span)?; let Some(numbering) = outlinable.numbering() else { return Ok(None) }; @@ -559,7 +564,7 @@ impl OutlineEntry { let styles = context.styles().at(span)?; let numbers = outlinable.counter().display_at_loc(engine, loc, styles, numbering)?; - Ok(Some(outlinable.prefix(numbers))) + Ok(Some(outlinable.prefix(numbers, add_supplement))) } /// Creates the default inner content of the entry.