Skip to main content

flm_core/stdlib/features/floats/
mod.rs

1//! The `floats` feature: figures, tables and other **floats**, blocks of
2//! content shown with an optional caption, labels and a number.
3//!
4//! # What an author writes
5//!
6//! ```text
7//! \begin{figure}
8//!   \includegraphics{plot.png}
9//!   \caption[alt=A plot]{A plot of the data, before and after.}
10//!   \label{figure:plot}
11//! \end{figure}
12//! ```
13//!
14//! prints, on the plain-text output,
15//!
16//! ```text
17//! [image: plot.png]
18//!
19//! Figure 1: A plot of the data, before and after.
20//! ```
21//!
22//! A **float type** is one kind of float, such as `figure` or `table`
23//! ([`FloatType`]). Each float type is an environment of the type's name that
24//! takes no argument. Its body is laid out in paragraphs and blocks, and three
25//! commands may be written in it, anywhere directly in the body and in any
26//! order:
27//!
28//! - `\caption[alt=…]{…}`: the float's **caption**, inline content shown
29//!   under the float's content. Its optional argument holds key-value pairs
30//!   with the only key `alt`, the caption's **alternative text**, which a
31//!   reference to an unnumbered float shows in place of the full caption. A
32//!   float holds at most one caption.
33//! - `\label{type:label}`: a
34//!   [label](crate::guide::concepts_overview#reference-points-labels-and-anchors),
35//!   the text an author writes to refer to the float from elsewhere. Its
36//!   label type (the part before the colon) must be one of the float type's
37//!   accepted label types ([`FloatType::label_types`]), by default the type's
38//!   own name: `\label{figure:plot}`.
39//! - `\nonumber`: the float is not numbered.
40//!
41//! The three commands are the elements of the scoped package
42//! [`FIELDS_PACKAGE`] (`flm.floats.fields`). A scoped package
43//! ([`ScopedPackageDef`](crate::lang::mint::ScopedPackageDef)) is a set of
44//! element declarations that can be written only inside the environment bodies
45//! and arguments whose declarations refer to the package by name ([scoped
46//! packages](crate::guide::concepts_overview#scoped-packages)); every float
47//! body refers to this one, so the three commands can be written in a float's
48//! body and nowhere else. Each is a field, a macro the float reads as data
49//! rather than as content
50//! ([fields](crate::guide::concepts_overview#fields-data-a-construct-reads));
51//! the float reads them from its body ([`body`]). `\label` is the references
52//! feature's own declaration ([`refs::label_package`]), declared here a second
53//! time so that a label can be written in a float's body whether or not that
54//! feature is registered.
55//!
56//! The rest of the body is the float's **content**. What the content may be is
57//! decided by the float type: a type lists the **content handlers** it
58//! accepts ([`FloatType::handlers`]), and a content handler
59//! ([`FloatContentHandler`]) is a value, contributed by the feature that owns
60//! a kind of content, that accepts a float's content or refuses it. The
61//! handlers are tried in the type's order, and the first that accepts the
62//! content decides. The shipped `figure` accepts exactly one image (the
63//! handler `includegraphics`, which the `graphics` feature contributes), the
64//! shipped `table` exactly one table of cells (the handler `cells`, which the
65//! `cells` feature contributes) or exactly one image; this feature contributes
66//! only the handler `any` ([`AnyContent`]), which accepts any content. Content
67//! that no handler of the type accepts is reported, and is shown as written.
68//!
69//! On the plain-text and HTML outputs, a float is shown where it is written:
70//! it is not moved, as LaTeX moves a float. By default, the recomposed LaTeX
71//! sets a numbered float in the LaTeX float environment of the type's name,
72//! which LaTeX places ([`latex`]).
73//!
74//! # Numbers, references and anchors
75//!
76//! Each float type has a **numbering policy** ([`FloatNumbering`]):
77//!
78//! - `AutoNumbered`, the default: a float of the type is numbered when it
79//!   carries a `\label` and no `\nonumber`;
80//! - `Numbered`: every float of the type is numbered unless it carries
81//!   `\nonumber`, as a displayed equation is;
82//! - `Unnumbered`: no float of the type is numbered.
83//!
84//! A `\nonumber` that changes nothing is reported with a Note
85//! ([`NonumberWithoutEffect`]). A numbered float counts in its type's counter,
86//! `flm.floats.<type>` ([`counter_name`]), and its number is shown in its
87//! type's counter style, `flm.floats.style.<type>` ([`style_name`]), whose
88//! words are the float type's: `Fig.~` and, under `\ref[S]{…}`, `Figure~` for
89//! `figure` (`~` is a space at which no line break is made). A counter is a
90//! dotted name under which things are counted in document order, and a counter
91//! style says how a counter value is shown ([counters and counter
92//! styles](crate::guide::concepts_overview#counters-and-counter-styles)). The
93//! feature declares both for each type to the numbering feature, through
94//! [`contribute_type`].
95//!
96//! Every float, numbered or not, is one reference point of the reference kind
97//! of its type's name. A reference point
98//! ([`RefPoint`](crate::model::aspects::RefPoint)) is one place in a document
99//! that can be referred to, numbered, or given an anchor ([reference points,
100//! labels and anchors](crate::guide::concepts_overview#reference-points-labels-and-anchors)).
101//! A reference to a numbered float, `\ref{figure:plot}`, shows `Fig.~1`; a
102//! reference to an unnumbered float shows its caption's alternative text where
103//! one is written, else its caption. A reference to an unnumbered float with
104//! no caption has nothing to show, and the references feature reports it. The
105//! float's anchor, the identifier a link to it points at, is its type and
106//! number (`figure-1`), else the anchor of its first label (`figure-plot` for
107//! `\label{figure:plot}`), else none; the references feature computes it.
108//!
109//! # What the feature provides to the pipeline
110//!
111//! The `floats` feature ([`Floats`], an [`FlmFeature`]) registers, from its
112//! configuration [`FloatsConfig`]:
113//!
114//! - **The element** [`FLOAT`] (`flm.floats.float`), with one element value per
115//!   float type, each a [`FloatElement`] declared as the environment of the
116//!   type's name, in text mode, as a block. [`contribute_type`] makes every
117//!   declaration a float type needs; another feature calls it to declare a
118//!   float type of its own.
119//! - **The scoped package** [`FIELDS_PACKAGE`] (`flm.floats.fields`) of the
120//!   three commands above. A float type may list further scoped packages
121//!   ([`FloatType::scoped_packages`]), which make the commands of its content
122//!   available in its body: `\includegraphics` in a `figure`.
123//! - **Two service slots.** A service slot is the declaration, by the feature
124//!   that owns an interaction, of a dotted name, the type of the values the
125//!   slot takes and its arity; any feature may contribute a value to it
126//!   ([services and service slots](crate::core::services)). [`TYPES_SLOT`]
127//!   (`flm.floats.types`) holds every float type of the registry, and
128//!   [`CONTENT_SLOT`] (`flm.floats.content`) every content handler; the
129//!   feature contributes its configured types and [`AnyContent`].
130//! - **The stage** [`CHECK_HANDLERS`] (`flm.floats.check-handlers`), which
131//!   reports each content handler that a float type used in the document lists
132//!   and that no registered feature contributes ([`MissingHandler`]). Every
133//!   rule that lowers a float requires it, and it is a member of the
134//!   collection [`flm.validated`](crate::stdlib::VALIDATED), so the `check`
135//!   workflow ([`CHECK_WORKFLOW`](crate::stdlib::CHECK_WORKFLOW)), which
136//!   validates a document and writes no output, runs it too.
137//! - **The lowering rules.** A role and its kind tokens are feature-owned
138//!   names on a presentation payload that say what a container is
139//!   ([`pres::payload`](crate::stdlib::backends::pres::payload)). The general
140//!   rule [`FLOAT_RULE`] ([`FloatRule`]), the default on every backend, lowers
141//!   a float to a block of role [`FLOAT_ROLE`] (`flm.floats.float`) whose kind
142//!   tokens are the float type's name and [`NUMBERED_KIND`] or [`UNNUMBERED_KIND`]. The block holds the
143//!   content in a block of role [`CONTENT_ROLE`] and, where the float is
144//!   numbered or has a caption, **the line under the content** in a block of
145//!   role [`CAPTION_ROLE`]: `Figure 1: ` followed by the caption, `Figure 1`
146//!   alone, or the caption alone, the caption name and number in a span of
147//!   role [`NUMBER_ROLE`]. The plain-text output prints the two blocks one
148//!   blank line apart. The rule requires the feature's style identifier
149//!   `flm.floats.style` at every float, which on the `html` backend names the
150//!   feature's stylesheet ([`html`]); the HTML backend writes the float as a
151//!   `<figure>` and the line under its content as a `<figcaption>`. On the
152//!   `latex-recomposed` backend, the rule [`latex::LATEX_RULE`] writes the
153//!   float as the environment `flmFloat`, a LaTeX hook: an environment that
154//!   the recomposed LaTeX writes and the style file defines with a plain
155//!   default, which a user redefines in the document's preamble ([LaTeX
156//!   hooks](crate::stdlib::backends::latex::preamble)). The feature's
157//!   definition piece defines it ([`latex`]).
158//! - **The settings.** The configuration [`FloatsConfig`] holds the float
159//!   types. A feature's configuration is the plain Rust value the feature is
160//!   constructed from; it is fixed when the registry is built and cannot vary
161//!   per document or per render ([settings, options and
162//!   configuration](crate::guide::concepts_overview#settings-options-and-configuration)).
163//!   As settings, the float types are the key `types`, a map from a type's
164//!   name to its fields. When a host combines several sources of settings, a
165//!   source that writes one float type's entry leaves the other types' entries
166//!   as the lower-ranked sources wrote them
167//!   ([`SettingsDecl::merge_entries`](crate::core::settings::SettingsDecl::merge_entries));
168//!   the values of `words` and `number_format` are FLM markup.
169//!
170//! The rendering guide shows what each output writes: [floats on the plain-text
171//! output](crate::guide::rendering#floats), [floats in
172//! HTML](crate::guide::rendering#floats-in-html) and [floats in the recomposed
173//! LaTeX](crate::guide::rendering#floats-in-the-recomposed-latex). The language
174//! guide describes floats for authors ([Floats](crate::guide::language_syntax#floats)).
175//!
176//! # Interactions with other features
177//!
178//! The feature requires no other feature. It makes peer declarations of what
179//! the other features own: a peer declaration
180//! ([`PeerName`](crate::core::registry::PeerName)) of an element, element type,
181//! table, service slot, scoped package, argument role or backend tells the
182//! registry build that another feature owns that name, and the build resolves it after every
183//! feature has registered.
184//!
185//! - **Numbering.** The counter and the counter style of each float type are
186//!   contributed to the numbering feature's service slots as peer
187//!   contributions, and the rules read the counter table
188//!   [`COUNTERS`] (`flm.counters`) optionally. Without the numbering feature, a float that
189//!   its policy numbers is reported ([`NoNumbering`]) and shown unnumbered,
190//!   except on the recomposed LaTeX, where LaTeX numbers it.
191//! - **References.** The rules read the anchors table
192//!   [`ANCHORS`](crate::stdlib::features::refs::ANCHORS) optionally. Without
193//!   the references feature, a float has no anchor and a `\label` in it has no
194//!   effect and is reported with a Note ([`LabelWithoutRefs`]); the label still
195//!   counts for an `AutoNumbered` type. On the recomposed LaTeX, the rule also
196//!   reads the safe-labels table
197//!   ([`SAFE_LABELS`](crate::stdlib::features::refs::SAFE_LABELS)) optionally.
198//!   The argument of the `\label` command in a float's body has the
199//!   references feature's argument role
200//!   [`DEFINED_LABEL_ARG_ROLE`](crate::stdlib::features::refs::DEFINED_LABEL_ARG_ROLE),
201//!   which the feature declares as a peer.
202//! - **Graphics and cells.** The shipped float types refer to the scoped
203//!   packages and content handlers of the `graphics` and `cells` features by
204//!   name only ([`INCLUDEGRAPHICS_PACKAGE`], [`INCLUDEGRAPHICS_HANDLER`],
205//!   [`CELLS_PACKAGE`], [`CELLS_HANDLER`]). Without one of those features, its
206//!   commands cannot be written in a float's body and its handler accepts
207//!   nothing; where the document holds a float of a type that lists the
208//!   handler, the stage reports the handler once per run with a Note
209//!   ([`MissingHandler`]).
210//! - **The element index.** The stage reads the element index
211//!   ([`ElementIndex`](crate::stdlib::features::index::ElementIndex), table
212//!   [`ELEMENT_INDEX`](crate::stdlib::features::index::ELEMENT_INDEX)) to find
213//!   the floats of the document.
214//!
215//! What a float's body gets wrong is reported while the float is lowered, by
216//! the reader that every rule lowering a float calls ([`read_float`]), so
217//! every backend reports the same conditions. The `check` workflow lowers
218//! nothing and does not report them ([`diagnostics`]).
219//!
220//! # Map of the items
221//!
222//! - [`Floats`], [`feature`], [`FEATURE`]: the feature.
223//! - [`FloatsConfig`], [`FloatType`], [`FloatNumbering`]: the configuration.
224//! - [`FLOAT`], [`FloatElement`], [`contribute_type`], [`float_point`]: the
225//!   element, its float types and its reference point.
226//! - [`FIELDS_PACKAGE`], [`CAPTION_FIELD`], [`NONUMBER_FIELD`],
227//!   [`CAPTION_OPTIONS_ARG`], [`CAPTION_TEXT_ARG`], [`ALT_KEY`]: the commands of
228//!   a float's body.
229//! - [`body`]: reading a float's body ([`read_float`], [`float_fields`],
230//!   [`float_body`], [`read_caption`]).
231//! - [`content`]: content handlers ([`FloatContentHandler`], [`AnyContent`],
232//!   [`Handlers`], [`Verdict`]); [`TYPES_SLOT`], [`CONTENT_SLOT`],
233//!   [`ANY_HANDLER`], [`CHECK_HANDLERS`].
234//! - [`FloatRule`], [`FLOAT_RULE`], [`float_decl`], [`float_number`]: the
235//!   general rule; [`FLOAT_ROLE`], [`CONTENT_ROLE`], [`CAPTION_ROLE`],
236//!   [`NUMBER_ROLE`], [`NUMBERED_KIND`], [`UNNUMBERED_KIND`],
237//!   [`RESERVED_KINDS`]: the names it stages.
238//! - [`html`], [`latex`]: the rules of the `html` and `latex-recomposed`
239//!   backends; [`latex_rendered`]: the definition piece of the
240//!   `latex-rendered` backend.
241//! - [`counter_name`], [`style_name`]: the counter and counter style of a
242//!   float type.
243//! - [`diagnostics`]: the conditions the feature reports.
244
245pub mod body;
246mod config;
247pub mod content;
248pub mod diagnostics;
249mod elements;
250pub mod html;
251pub mod latex;
252pub mod latex_rendered;
253mod lower;
254
255use std::sync::Arc;
256
257use crate::core::settings::SettingsDecl;
258use crate::core::registry::{BuildError, CapabilityDef, FeatureBuilder, FeatureInfo, FlmFeature};
259use crate::core::services::Arity;
260use crate::model::names::Name;
261use crate::stdlib::features::numbering::{COUNTERS, Counters};
262use crate::stdlib::features::refs;
263use crate::stdlib::VALIDATED;
264
265pub use body::{
266    Caption, FloatBody, FloatFields, FloatReading, float_body, float_fields, read_caption,
267    read_float,
268};
269pub use config::{
270    CELLS_HANDLER, CELLS_PACKAGE, FloatNumbering, FloatType, FloatsConfig, INCLUDEGRAPHICS_HANDLER,
271    INCLUDEGRAPHICS_PACKAGE,
272};
273pub use content::{AnyContent, FloatContentHandler, Handlers, Verdict};
274pub use diagnostics::{
275    CaptionMissingValue, CaptionRepeated, CaptionRepeatedKey, CaptionUnknownKey, ContentRefused,
276    LabelWithoutRefs, MissingHandler, NoNumbering, NonumberWithoutEffect, StageFailed,
277};
278pub use elements::{FloatElement, contribute_type, float_point};
279pub use lower::{FLOAT_RULE, FloatRule, float_decl, float_number};
280
281/// The feature's registered name, `floats`.
282pub const FEATURE: &str = "floats";
283
284/// Returns the declaration of the feature's settings: the fields of [`FloatsConfig`] are its
285/// keys; `types` is combined entry by entry, and the `words` and `number_format` of every type
286/// are FLM markup. See [`crate::core::settings`].
287fn settings() -> SettingsDecl {
288    SettingsDecl::new(FEATURE)
289        .config::<FloatsConfig>(
290            "The float types, each an environment of the type's name: its caption name, its \
291            numbering policy, its number format, the words a reference writes before its \
292            number, the content handlers it accepts, the scoped packages available in its body \
293            and the label types it accepts. Fixed when the registry is built: it cannot vary \
294            per document or per render.",
295        )
296        .merge_entries("types", || crate::core::settings::named::to_data(&FloatsConfig::default().types, "name"))
297        .remove_false("types")
298        .markup("types.*.words")
299        .markup("types.*.number_format")
300}
301
302/// The name of the element of every float, `flm.floats.float`: one element
303/// value per float type, each carrying a [`FloatElement`].
304pub const FLOAT: &str = "flm.floats.float";
305
306/// The role of the block a float lowers to, `flm.floats.float`, the same
307/// name as the element's. The HTML backend writes a block of this role as a
308/// `<figure>`.
309pub const FLOAT_ROLE: &str = FLOAT;
310
311/// The role of the block holding a float's content,
312/// `flm.floats.float.content`.
313pub const CONTENT_ROLE: &str = "flm.floats.float.content";
314
315/// The role of the block holding the line under a float's content,
316/// `flm.floats.float.caption`. The HTML backend writes a block of this role
317/// as a `<figcaption>`.
318pub const CAPTION_ROLE: &str = "flm.floats.float.caption";
319
320/// The role of the span holding a float's caption name and number in the
321/// line under its content (`Figure 1`), `flm.floats.float.number`.
322pub const NUMBER_ROLE: &str = "flm.floats.float.number";
323
324/// The kind token of a float shown with a number, `numbered`. It is written
325/// on the float's block and on the block of the line under its content, after
326/// the float type's name.
327pub const NUMBERED_KIND: &str = "numbered";
328
329/// The kind token of a float shown without a number, `unnumbered`, written
330/// where [`NUMBERED_KIND`] would be.
331pub const UNNUMBERED_KIND: &str = "unnumbered";
332
333/// The kind tokens that a float's block carries beside its type's name,
334/// [`NUMBERED_KIND`] and [`UNNUMBERED_KIND`]. Because a float type's name is
335/// also a kind token of its floats, no float type may have one of these
336/// names ([`FloatType::validate`]).
337pub const RESERVED_KINDS: [&str; 2] = [NUMBERED_KIND, UNNUMBERED_KIND];
338
339/// The name of the service slot of the float types, `flm.floats.types`. It
340/// takes [`FloatType`] values, any number of them, kept in the order
341/// contributed (`Arity::OrderedMany`). The feature contributes its
342/// configuration's types, and another feature contributes a type of its own
343/// through [`contribute_type`]. Two types of one name in the slot fail the
344/// registry build.
345pub const TYPES_SLOT: &str = "flm.floats.types";
346
347/// The name of the service slot of the content handlers,
348/// `flm.floats.content`. It takes [`FloatContentHandler`] trait objects, any
349/// number of them, kept in the order contributed (`Arity::OrderedMany`). The
350/// feature contributes [`AnyContent`]; the feature that owns a kind of content
351/// contributes its own handler as a peer contribution (see
352/// [`content`]). Two handlers of one name fail the registry build.
353pub const CONTENT_SLOT: &str = "flm.floats.content";
354
355/// The name of the scoped package of the three commands of a float's body,
356/// `flm.floats.fields`: `\caption`, `\label` and `\nonumber`. Every float
357/// body refers to it.
358pub const FIELDS_PACKAGE: &str = "flm.floats.fields";
359
360/// The name of the caption command, `caption`, written `\caption[alt=…]{…}`.
361pub const CAPTION_FIELD: &str = "caption";
362
363/// The name of the command that marks a float unnumbered, `nonumber`.
364pub const NONUMBER_FIELD: &str = "nonumber";
365
366/// The name of a caption's optional argument, `options`, which holds
367/// key-value pairs.
368pub const CAPTION_OPTIONS_ARG: &str = "options";
369
370/// The name of a caption's mandatory argument, `text`.
371pub const CAPTION_TEXT_ARG: &str = "text";
372
373/// The only key of a caption's optional argument, `alt`: the caption's
374/// alternative text, which a reference to an unnumbered float shows.
375pub const ALT_KEY: &str = "alt";
376
377/// The name of the content handler that accepts any content, `any`
378/// ([`AnyContent`]).
379pub const ANY_HANDLER: &str = "any";
380
381/// The name of the feature's stage, and of the capability it provides,
382/// `flm.floats.check-handlers`. The stage reports, once per run, each content
383/// handler that a float type used in the document lists and that no
384/// registered feature contributes ([`MissingHandler`]).
385pub const CHECK_HANDLERS: &str = "flm.floats.check-handlers";
386
387/// Returns the name of the counter in which the floats of the type
388/// `float_type` are counted, `flm.floats.<type>`.
389pub fn counter_name(float_type: &str) -> Name {
390    Name::from(format!("flm.floats.{float_type}"))
391}
392
393/// Returns the name of the counter style in which the number of a float of
394/// the type `float_type` is shown, `flm.floats.style.<type>`.
395pub fn style_name(float_type: &str) -> Name {
396    Name::from(format!("flm.floats.style.{float_type}"))
397}
398
399/// The `floats` feature: from a [`FloatsConfig`], it declares one environment
400/// per configured float type, the scoped package of a float's body, the two
401/// service slots, the lowering rules and the stage. See the [module
402/// documentation](self).
403///
404/// Registering the feature fails with [`BuildError::Feature`] when the
405/// configuration fails [`FloatsConfig::validate`], and when two float types or
406/// two content handlers of one name are contributed. The feature may be
407/// registered at most once in a registry.
408#[derive(Debug, Default, Clone)]
409pub struct Floats {
410    config: FloatsConfig,
411}
412
413impl Floats {
414    /// Returns the feature with the configuration `config`, which is fixed for
415    /// the life of the registry it is built into.
416    pub fn new(config: FloatsConfig) -> Floats {
417        Floats { config }
418    }
419
420    /// Returns the configuration this feature was constructed with.
421    pub fn config(&self) -> &FloatsConfig {
422        &self.config
423    }
424}
425
426impl FlmFeature for Floats {
427    fn info(&self) -> FeatureInfo {
428        FeatureInfo::new(FEATURE, "Floats").docs(
429            "Floats such as figures and tables: one environment per float type, each an element \
430             value of `flm.floats.float`, holding content with an optional caption, labels and a \
431             number given by the type's numbering policy.",
432        )
433    }
434
435    fn settings(&self) -> Option<SettingsDecl> {
436        Some(settings())
437    }
438
439    fn register(&self, b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
440        let owner = b.feature().clone();
441        self.config
442            .validate()
443            .map_err(|detail| BuildError::Feature { feature: owner.clone(), detail })?;
444        b.service_slot::<FloatType>(
445            TYPES_SLOT,
446            Arity::OrderedMany,
447            "The float types; `floats::contribute_type` declares each one, with the environment of \
448             its name.",
449        )?;
450        b.service_slot::<dyn FloatContentHandler>(
451            CONTENT_SLOT,
452            Arity::OrderedMany,
453            "The content handlers that float types list by name: each accepts a float's content \
454             or refuses it.",
455        )?;
456        b.contribute_to::<dyn FloatContentHandler>(CONTENT_SLOT, Arc::new(AnyContent))?;
457        b.element(elements::float_type_def(&owner))?;
458        b.element_type_text(
459            FLOAT,
460            "A float: content of a float type, such as a figure or a table, shown with a line \
461             under it that holds its number and its caption.",
462        )?;
463        // The `\label` command of a float's body is the references feature's,
464        // with that feature's role on its argument; declared as a peer, so
465        // that a registry without that feature still builds.
466        b.peer_argument_role(refs::DEFINED_LABEL_ARG_ROLE)?;
467        b.scoped_package(elements::fields_package(&owner))?;
468        for float_type in &self.config.types {
469            contribute_type(b, Arc::new(float_type.clone()))?;
470        }
471        // The two tables belong to the numbering and the references features,
472        // which may be absent: the rule reads them optionally.
473        b.peer_table::<Counters>(
474            COUNTERS.name(),
475            "the numbering feature's counter table, which the float's rules read for the number \
476             shown in the line under the float's content",
477        )?;
478        b.peer_table::<refs::Anchors>(
479            refs::ANCHORS.name(),
480            "the references feature's anchors table, which the float's rules read for the \
481             float's anchor and to find out whether labels have an effect",
482        )?;
483        let handlers = Arc::new(Handlers::default());
484        b.finalizer(Arc::new(content::CollectHandlers { handlers: Arc::clone(&handlers) }))?;
485        b.lowering_rule(lower::float_rule(Arc::clone(&handlers)))?;
486        html::register(b)?;
487        latex_rendered::register(b)?;
488        latex::register(b, handlers)?;
489        b.capability(CapabilityDef::new(CHECK_HANDLERS).docs(
490            "Each content handler that a float type used in the document lists, and that no \
491             registered feature contributes, has been reported once. A member of \
492             `flm.validated`.",
493        ))?;
494        b.stage(Arc::new(content::CheckHandlers))?;
495        b.collection_member(VALIDATED, CHECK_HANDLERS)?;
496        b.digest_input(&self.config.digest_bytes())?;
497        Ok(())
498    }
499}
500
501/// Returns the [`Floats`] feature with the default configuration (the float
502/// types `figure` and `table`), ready to be listed in a package entry.
503///
504/// Use `Arc::new(Floats::new(config))` to list the feature with a
505/// [`FloatsConfig`] of your own.
506pub fn feature() -> Arc<dyn crate::core::registry::FlmFeature> {
507    Arc::new(Floats::default())
508}