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