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
//! This module defines the diagnostic conditions of the [`floats`](super)
//! feature. Their identifiers have the form `flm.floats.<condition>`. The
//! conditions [`NonumberWithoutEffect`], [`LabelWithoutRefs`] and
//! [`MissingHandler`] are notes, and the other conditions are errors.
//!
//! Every lowering rule of a float reads the float with
//! [`read_float`](super::read_float), which reports the problems of the float.
//! A document therefore gets the same reports on every backend. These
//! conditions are reported only when a float is lowered. The `check` workflow
//! ([`CHECK_WORKFLOW`](crate::stdlib::CHECK_WORKFLOW)) lowers no float, and
//! therefore does not report them. They concern the following problems:
//!
//! - a repeated `\caption`, or a mistake in the optional argument of
//! `\caption` ([`CaptionRepeated`], [`CaptionUnknownKey`],
//! [`CaptionMissingValue`], [`CaptionRepeatedKey`]);
//! - a `\nonumber` that has no effect ([`NonumberWithoutEffect`]);
//! - a `\label` in a registry without the references feature
//! ([`LabelWithoutRefs`]);
//! - a float to be numbered in a registry without the numbering feature
//! ([`NoNumbering`]);
//! - content that the float type does not accept ([`ContentRefused`]).
//!
//! The check stage [`CHECK_HANDLERS`](super::CHECK_HANDLERS) reports
//! [`MissingHandler`], also under the `check` workflow. The check stage
//! reports [`StageFailed`] when it fails to read a table. A document cannot
//! cause this error.
use DiagnosticInfo;
/// The error that is reported when the body of a float contains more than one
/// `\caption` (`flm.floats.caption-repeated`).
///
/// Reported by the lowering rule of the float, on every backend, at each
/// `\caption` after the first. The first `\caption` gives the caption of the
/// float. The other `\caption` commands are left out of the output.
/// The error that is reported when the optional argument of `\caption`
/// contains a key other than `alt` (`flm.floats.caption-unknown-key`).
///
/// The optional argument of `\caption` contains key-value pairs. Its only key
/// is `alt`, which gives the alternative text of the caption, as in
/// `\caption[alt=A plot]{A plot of the data, before and after.}`. A reference
/// to an unnumbered float shows the alternative text in place of the caption.
/// Unlike in LaTeX, the optional argument does not give a short caption.
///
/// Reported by the lowering rule of the float, on every backend, at the
/// `\caption`. The unknown key is ignored. A valid `alt` key in the same
/// argument is still used.
/// The error that is reported when the key `alt` in the optional argument of
/// `\caption` is written without `=` (`flm.floats.caption-missing-value`).
///
/// The key `alt` must be followed by `=` and the alternative text of the
/// caption, as in `\caption[alt=A plot]{A plot of the data, before and
/// after.}`.
///
/// Reported by the lowering rule of the float, on every backend, at the
/// `\caption`. The key is ignored.
;
/// The error that is reported when the optional argument of `\caption`
/// contains `alt=…` more than once (`flm.floats.caption-repeated-key`).
///
/// Reported by the lowering rule of the float, on every backend, at the
/// `\caption`. The first value of `alt` is used, and the others are ignored.
;
/// The note that is reported when a `\nonumber` in the body of a float has no
/// effect (`flm.floats.nonumber-without-effect`).
///
/// The numbering policy of the float type
/// ([`FloatNumbering`](super::FloatNumbering)) determines whether a float is
/// numbered. A `\nonumber` has no effect in the following cases:
///
/// - The float type is never numbered
/// ([`Unnumbered`](super::FloatNumbering::Unnumbered)).
/// - The float type is numbered only when the float has a `\label`
/// ([`AutoNumbered`](super::FloatNumbering::AutoNumbered), the default), and
/// the float has no `\label`.
/// - The float contains an earlier `\nonumber`.
///
/// Reported by the lowering rule of the float, on every backend, at each such
/// `\nonumber`. The float is not numbered.
/// The note that is reported when a float has a `\label` and the registry does
/// not contain the [`refs`](crate::stdlib::features::refs) feature (id
/// `flm.floats.label-without-refs`).
///
/// Without the references feature, `\ref` is not available, and nothing can
/// refer to the float. The label still counts for the numbering policy of the
/// float type: a float of a type that is numbered only when it has a `\label`
/// ([`AutoNumbered`](super::FloatNumbering::AutoNumbered)) is numbered.
///
/// Reported by the lowering rule of the float, on every backend, at the first
/// `\label` of the float. The float is otherwise lowered as usual.
/// The error that is reported when a float is to be numbered and the registry
/// does not contain the [`numbering`](crate::stdlib::features::numbering)
/// feature (id `flm.floats.no-numbering`).
///
/// The numbering policy of the float type
/// ([`FloatNumbering`](super::FloatNumbering)) determines whether a float is
/// numbered. In the default configuration, a `figure` or a `table` is
/// numbered when it has a `\label` and no `\nonumber`. Only the numbering
/// feature computes the numbers of floats.
///
/// Reported by the lowering rule of the float, on every backend, at the float.
/// On every backend except `latex-recomposed`, the float is written as an
/// unnumbered float: the line under its content contains only its caption, or
/// is left out when the float has no caption. On the `latex-recomposed`
/// backend, the float is written as numbered, and LaTeX numbers it.
/// The error that is reported when the content of a float is not accepted by
/// its float type (`flm.floats.content-refused`).
///
/// A float type lists the content handlers that it accepts
/// ([`FloatType::handlers`](super::FloatType::handlers)). A content handler
/// ([`FloatContentHandler`](super::FloatContentHandler)) checks the content of
/// a float, and accepts it or refuses it. The content of a float is accepted
/// when one of the content handlers of its type accepts it. In the default
/// configuration, a `figure` must contain exactly one image, as in
/// `\begin{figure}\includegraphics{plot.png}\caption{A plot}\end{figure}`. A
/// `table` must contain exactly one table of cells or exactly one image. The
/// commands `\caption`, `\label` and `\nonumber`, whitespace and comments do
/// not count as content.
///
/// The message lists the content that each available content handler of the
/// type accepts. A content handler that is not available in the registry
/// accepts no content, and is reported as [`MissingHandler`]. When none of the
/// content handlers of the type is available, no content can be accepted, and
/// the message lists the missing content handlers instead.
///
/// Reported by the lowering rule of the float, on every backend, at the float.
/// The content is lowered as usual, as if the float type accepted any
/// content.
/// The note that is reported when a float type that is used in the document
/// lists a content handler that is not available in the registry (id
/// `flm.floats.missing-handler`).
///
/// A float type lists the content handlers that it accepts
/// ([`FloatType::handlers`](super::FloatType::handlers)). Each content handler
/// is contributed to the service slot [`CONTENT_SLOT`](super::CONTENT_SLOT) by
/// the feature that provides its kind of content: the `graphics` feature
/// contributes `includegraphics`, and the `cells` feature contributes `cells`.
/// A content handler is missing, for instance, when the registry does not
/// contain the feature that contributes it.
///
/// Reported by the check stage [`CHECK_HANDLERS`](super::CHECK_HANDLERS), also
/// under the `check` workflow, once for each float type and each missing
/// content handler of the type, at the first float of the type in the
/// document. The missing content handler accepts no content, and the other
/// content handlers of the type are tried. When none of the content handlers
/// of a float type is available, every float of the type is reported as
/// [`ContentRefused`].
/// Error raised when the check stage of the floats feature fails to read a
/// table (id `flm.floats.stage-failed`).
///
/// The check stage [`CHECK_HANDLERS`](super::CHECK_HANDLERS) reads the element
/// index ([`ELEMENT_INDEX`](crate::stdlib::features::index::ELEMENT_INDEX)).
/// A table read fails only when the code of a feature is faulty, for instance
/// when the value type of the table differs from the declared one (see
/// [`AccessError`](crate::core::data::store::AccessError)). A document cannot
/// cause this error.
///
/// Reported with no position in the source. The check stage then stops, and
/// reports no [`MissingHandler`] for the document.