mirror of
https://github.com/typst/typst
synced 2025-07-27 06:17:53 +08:00
Document that a where
selector is needed to update figure counters
Resolves #6641 It was documented in `figure.counter`, but that field is synthesized and not visible in docs. https://docs.rs/typst-library/0.13.1/typst_library/model/struct.FigureElem.html#method.counter
This commit is contained in:
parent
2bbee17978
commit
77db88eb98
@ -415,6 +415,8 @@ impl Counter {
|
|||||||
/// - If it is a [selector], counts through elements that matches with the
|
/// - If it is a [selector], counts through elements that matches with the
|
||||||
/// selector. For example,
|
/// selector. For example,
|
||||||
/// - provide an element function: counts elements of that type,
|
/// - provide an element function: counts elements of that type,
|
||||||
|
/// - provide a [`where`]($function.where) selector:
|
||||||
|
/// counts a type of elements with specific fields,
|
||||||
/// - provide a [`{<label>}`]($label): counts elements with that label.
|
/// - provide a [`{<label>}`]($label): counts elements with that label.
|
||||||
key: CounterKey,
|
key: CounterKey,
|
||||||
) -> Counter {
|
) -> Counter {
|
||||||
|
@ -189,6 +189,37 @@ pub struct FigureElem {
|
|||||||
/// supplement: [Atom],
|
/// supplement: [Atom],
|
||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// If you want to modify a counter to skip a number or reset the counter,
|
||||||
|
/// you can access the [counter] of each kind of figures from
|
||||||
|
/// a [`where`]($function.where) selector:
|
||||||
|
///
|
||||||
|
/// - For [tables]($table): `{counter(figure.where(kind: table))}`
|
||||||
|
/// - For [images]($image): `{counter(figure.where(kind: image))}`
|
||||||
|
/// - For a custom kind: `{counter(figure.where(kind: kind))}`
|
||||||
|
///
|
||||||
|
/// ```example
|
||||||
|
/// #figure(
|
||||||
|
/// table(columns: 2, $n$, $1$),
|
||||||
|
/// caption: [The first table.],
|
||||||
|
/// )
|
||||||
|
///
|
||||||
|
/// #counter(figure.where(kind: table)).update(41)
|
||||||
|
///
|
||||||
|
/// #figure(
|
||||||
|
/// table(columns: 2, $n$, $42$),
|
||||||
|
/// caption: [Jumped to the 42nd table.],
|
||||||
|
/// )
|
||||||
|
///
|
||||||
|
/// #figure(
|
||||||
|
/// rect[Image],
|
||||||
|
/// caption: [And it doesn't affect images.],
|
||||||
|
/// )
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// There is also a convenience field called `counter` to simplify general
|
||||||
|
/// [show rules]($styling/#show-rules). There is an example
|
||||||
|
/// [show rule that customizes `figure.caption`]($figure.caption.body) below.
|
||||||
pub kind: Smart<FigureKind>,
|
pub kind: Smart<FigureKind>,
|
||||||
|
|
||||||
/// The figure's supplement.
|
/// The figure's supplement.
|
||||||
@ -228,8 +259,8 @@ pub struct FigureElem {
|
|||||||
/// Convenience field to get access to the counter for this figure.
|
/// Convenience field to get access to the counter for this figure.
|
||||||
///
|
///
|
||||||
/// The counter only depends on the `kind`:
|
/// The counter only depends on the `kind`:
|
||||||
/// - For (tables)[@table]: `{counter(figure.where(kind: table))}`
|
/// - For [tables]($table): `{counter(figure.where(kind: table))}`
|
||||||
/// - For (images)[@image]: `{counter(figure.where(kind: image))}`
|
/// - For [images]($image): `{counter(figure.where(kind: image))}`
|
||||||
/// - For a custom kind: `{counter(figure.where(kind: kind))}`
|
/// - For a custom kind: `{counter(figure.where(kind: kind))}`
|
||||||
///
|
///
|
||||||
/// These are the counters you'll need to modify if you want to skip a
|
/// These are the counters you'll need to modify if you want to skip a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user