Merge 2a3c6f5ffec7bd7d68bfc57e069653bb3517522e into 9b09146a6b5e936966ed7ee73bce9dd2df3810ae

This commit is contained in:
Malo 2025-05-06 22:55:19 +00:00 committed by GitHub
commit 9d92c401bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 71 additions and 11 deletions

View File

@ -235,7 +235,10 @@ impl Outlinable for Packed<EquationElem> {
self.block(StyleChain::default()) && self.numbering().is_some()
}
fn prefix(&self, numbers: Content) -> Content {
fn prefix(&self, numbers: Content, add_supplement: Smart<bool>) -> Content {
if add_supplement == Smart::Custom(false) {
return numbers;
}
let supplement = self.supplement();
if !supplement.is_empty() {
supplement + TextElem::packed('\u{a0}') + numbers

View File

@ -436,7 +436,10 @@ impl Outlinable for Packed<FigureElem> {
|| self.numbering().is_some())
}
fn prefix(&self, numbers: Content) -> Content {
fn prefix(&self, numbers: Content, add_supplement: Smart<bool>) -> Content {
if add_supplement == Smart::Custom(false) {
return numbers;
}
let supplement = self.supplement();
if !supplement.is_empty() {
supplement + TextElem::packed('\u{a0}') + numbers

View File

@ -364,8 +364,17 @@ impl Outlinable for Packed<HeadingElem> {
(**self).resolve_level(StyleChain::default())
}
fn prefix(&self, numbers: Content) -> Content {
numbers
fn prefix(&self, numbers: Content, add_supplement: Smart<bool>) -> 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 {

View File

@ -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<bool>) -> Content;
/// The body of the entry.
fn body(&self) -> Content;
@ -421,7 +421,7 @@ impl Show for Packed<OutlineEntry> {
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::<EquationElem>() {
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<Context>,
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<bool>,
) -> SourceResult<Option<Content>> {
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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -171,6 +171,46 @@
== Middle heading
=== Lower heading
--- outline-entry-force-supplement ---
#set page(width: 200pt)
#set heading(numbering: "1.", supplement: [Chapter])
#show outline.entry.where(level: 1): it => link(
it.element.location(),
it.indented(
it.prefix(add-supplement: true),
it.inner(),
)
)
#outline()
= Top
== Middle
=== Lower
== Middle Again
= Top again
#set heading(numbering: none)
= Top again again
--- outline-entry-no-supplement ---
#set page(width: 200pt)
#set math.equation(numbering: "(i)", supplement: [Eq])
#show outline.entry.where(level: 1): it => link(
it.element.location(),
it.indented(
it.prefix(add-supplement: false),
it.inner(),
)
)
#outline(target: math.equation)
$ 1 $
#set math.equation(numbering: none)
$ 2 $
--- outline-entry-inner ---
#set heading(numbering: "1.")
#show outline.entry: it => block(it.inner())