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
//! This module defines the diagnostic conditions of the `lists` feature. Their
//! identifiers have the form `flm.lists.<condition>`. Every condition is an
//! error, except [`RefIgnored`], which is a note.
//!
//! The conditions are reported by the lowering rules of the feature:
//!
//! - The rule that lowers a list reports the mistakes in the optional
//! arguments of the list and of its items ([`UnknownKey`],
//! [`MissingValue`], [`BadLabelForm`], [`RefIgnored`]), the mistakes in the
//! body of the list ([`ContentBeforeItem`], [`MissingTag`]), and the
//! problems with the labels beside the items ([`BadLabel`],
//! [`LabelNamesNumber`], [`NoNumbering`]). Both the general rule
//! [`ListRule`](super::ListRule) and the rule
//! [`ListLatexRule`](super::latex::ListLatexRule) of the `latex-recomposed`
//! backend report these conditions, so a document gets the same reports on
//! every backend.
//! - [`ListLatexRule`](super::latex::ListLatexRule) also reports
//! [`NoEnumitemFormat`] and [`NumberReadAsCharacters`]. These conditions
//! concern the way in which the recomposed LaTeX writes the label template
//! and the reference template of a list.
//! - The rule [`ItemRule`](super::ItemRule) of `\item` reports
//! [`ItemOutsideList`], on every backend.
use DiagnosticInfo;
/// The error that is reported when the optional argument of a list or of an
/// `\item` contains an unknown key (`flm.lists.unknown-key`).
///
/// The optional argument of a list accepts the keys `label` and `ref`, as in
/// `\begin{enumerate}[label=(#{alph}), ref=#{alph}]`. Instead of key-value
/// pairs, it also accepts a short label form, as in `\begin{enumerate}[(a)]`.
/// A short label form consists only of the characters `[]().:-+*aAiI1`. A
/// label with other characters is given with the `label` key, as in
/// `\begin{enumerate}[label={Step~#{arabic}:}]`. An optional argument of a
/// list that contains no `=` and is not a short label form is reported as a
/// whole as an unknown key.
///
/// The optional argument of an `\item` accepts the key `tag`, as in
/// `\item[tag={a=b}]`. An argument that contains no `=` is the tag itself, as
/// in `\item[Term]`.
///
/// Reported by the lowering rule of the list, on every backend. The unknown
/// key is ignored, and the other keys of the argument are used.
/// The error that is reported when a key in the optional argument of a list
/// or of an `\item` is written without `=` (`flm.lists.missing-value`).
///
/// Each key must be followed by `=` and its value, as in
/// `\begin{enumerate}[label=(#{alph}), ref=#{alph}]` or `\item[tag={Term}]`.
///
/// Reported by the lowering rule of the list, on every backend. The key is
/// ignored.
/// The error that is reported when a short label form contains more than one
/// of the characters `a`, `A`, `i`, `I` and `1` (`flm.lists.bad-label-form`).
///
/// In a short label form, one of these characters stands for the number of the
/// item, written in the style of the character: `\begin{enumerate}[(a)]` gives
/// the labels `(a)`, `(b)`, …, and `\begin{enumerate}[i.]` gives `i.`, `ii.`,
/// … A short label form may therefore contain at most one of these
/// characters. A short label form without any of them is a fixed label, as in
/// `\begin{itemize}[-]`. A label that contains more of these characters is
/// given with the `label` key, where `#{…}` marks the number, as in
/// `\begin{enumerate}[label=#{roman}.a]`.
///
/// Reported by the lowering rule of the list, on every backend. The list then
/// uses the label template of its [list kind](super#lists-and-list-kinds) for
/// its nesting depth.
/// The error that is reported when a label template or a reference template
/// in the optional argument of a list is not valid (`flm.lists.bad-label`).
///
/// These templates are written in the language of the number templates of the
/// [`numbering`](crate::stdlib::features::numbering) feature. Each `#{name}`
/// stands for the number of the item in the number format `name`, and the
/// rest of the template is FLM content, as in `label=(#{alph})` or
/// `label={\textbf{#{arabic}}.}`. A template is not valid if it contains a
/// placeholder that is not a number format, or content that is not valid FLM.
///
/// Reported by the lowering rule of the list, on every backend. If the label
/// template is not valid, the list uses the label template of its
/// [list kind](super#lists-and-list-kinds) for its nesting depth. On the
/// `latex-recomposed` backend, the key of the template is left out of the
/// recomposed LaTeX, and LaTeX uses its default instead.
///
/// Each template that is not valid is reported once. The reference template of
/// a numbered list is compiled by the numbering feature, which reports a
/// reference template that is not valid as `flm.numbering.bad-number-format`.
/// This also holds for a template given with `label=` alone, which sets both
/// the label template and the reference template. This condition therefore
/// reports a reference template only in a registry without the numbering
/// feature.
/// The error that is reported when the label template of an unnumbered list
/// contains a number format (`flm.lists.label-names-number`).
///
/// The [list kind](super#lists-and-list-kinds) of a list environment
/// determines whether the items of its lists are numbered
/// ([`ListKind::numbered`](super::ListKind::numbered)). The label template of
/// a list cannot change this. The items of an unnumbered list, such as
/// `itemize`, have no number. The label template of such a list must
/// therefore be a fixed label, as in `\begin{itemize}[label={--}]` or
/// `\begin{itemize}[*]`. A number format is written as `#{…}` in a label
/// template, and as one of the characters `a`, `A`, `i`, `I` and `1` in a
/// short label form.
///
/// Reported by the lowering rule of the list, on every backend. The list then
/// uses the label template of its list kind for its nesting depth. On the
/// `latex-recomposed` backend, the key `label` is left out of the recomposed
/// LaTeX, and LaTeX uses its default label.
/// The note that is reported when the optional argument of an unnumbered list
/// contains the key `ref` (`flm.lists.ref-ignored`).
///
/// The items of an unnumbered list have no number, so the reference template
/// given with `ref` is not used. A reference to an item of such a list is
/// written as the label beside the item. The value of `ref` is ignored, and
/// it is not checked.
///
/// This condition is a note and not an error so that you can change the
/// environment of a list between a numbered and an unnumbered one, for
/// instance from `enumerate` to `itemize`, without removing the key `ref`.
///
/// Reported by the lowering rule of the list, on every backend, once for each
/// such list.
/// The error that is reported when the body of a list contains content before
/// its first `\item` (`flm.lists.content-before-item`). Whitespace, blank
/// lines and comments do not count as content here.
///
/// Reported by the lowering rule of the list, on every backend. On every
/// backend except `latex-recomposed`, the content is written as an additional
/// first item, which has no label and no number. On the `latex-recomposed`
/// backend, the content is written before the first `\item`, as in the
/// source.
/// The error that is reported when an item has no tag in a list that has no
/// label template (`flm.lists.missing-tag`).
///
/// A list has a label template if its [list kind](super#lists-and-list-kinds)
/// has one for the nesting depth of the list, or if the optional argument of
/// the list gives one. In the default configuration, the list kind of the
/// `description` environment has no label template. Each item of a
/// `description` list must therefore have a tag, as in `\item[Term]` or
/// `\item[tag={Term}]`.
///
/// Reported by the lowering rule of the list, on every backend, once for each
/// item without a tag. The item is written without a label.
/// The error that is reported when the items of a numbered list need a number
/// and the registry does not contain the
/// [`numbering`](crate::stdlib::features::numbering) feature (id
/// `flm.lists.no-numbering`).
///
/// Only the numbering feature computes the numbers of list items. The items of
/// a numbered list need a number if the label template of the list contains a
/// number format and at least one item has no tag. A list with a fixed label,
/// as in `\begin{enumerate}[label={*}]`, needs no number, and neither does an
/// item with a tag.
///
/// Reported by the lowering rule of the list, on every backend, once for each
/// such list. On every backend except `latex-recomposed`, the items without a
/// tag are written without a label. On the `latex-recomposed` backend, the list
/// is written as usual, and LaTeX numbers its items.
/// The error that is reported when an `\item` inside a list is not placed
/// directly in the body of the list (`flm.lists.item-outside-list`).
///
/// An `\item` begins an item only if it is placed directly in the body of a
/// list, as in `\begin{itemize}\item First \item Second\end{itemize}`.
/// Outside of a list, `\item` is not defined at all.
///
/// Reported by the lowering rule [`ItemRule`](super::ItemRule) of `\item`, on
/// every backend. The `\item` expands to nothing. The content that follows it
/// is written as usual.
;
/// The error that is reported on the `latex-recomposed` backend when the label
/// template or the reference template of a list contains a number format that
/// LaTeX's `enumitem` package does not support (id
/// `flm.lists.no-enumitem-format`).
///
/// The recomposed LaTeX writes the label template and the reference template
/// given in the optional argument of a list as the `label` and `ref` keys of
/// the `enumitem` package. It writes each number format as the `enumitem`
/// command for this format. Such commands exist only for the number formats
/// `#{arabic}`, `#{alph}`, `#{Alph}`, `#{roman}` and `#{Roman}`, as in
/// `\begin{enumerate}[label=(#{alph})]`. The other backends write the number
/// themselves and accept every number format of the
/// [`numbering`](crate::stdlib::features::numbering) feature.
///
/// Reported by the rule [`ListLatexRule`](super::latex::ListLatexRule), once
/// for each key. The key is left out of the recomposed LaTeX. Without
/// `label`, LaTeX uses its default label. Without `ref`, references to the
/// items use the label template.
/// The error that is reported on the `latex-recomposed` backend when the label
/// template or the reference template of a list contains a number format
/// inside content that is read as characters, such as verbatim content (id
/// `flm.lists.number-read-as-characters`).
///
/// A command reads its content as characters when it uses the characters as
/// they are written instead of typesetting them. This is the case, for
/// instance, for verbatim content, for the address of a link and for the label
/// in a `\ref`. The recomposed LaTeX writes a number format as a command of
/// LaTeX's `enumitem` package, which LaTeX expands each time it sets a label.
/// The characters of such content, however, are needed when the recomposed
/// LaTeX is generated, before any number exists. The other backends write the
/// number themselves and report nothing.
///
/// Reported by the rule [`ListLatexRule`](super::latex::ListLatexRule), once
/// for each key. The key is left out of the recomposed LaTeX, as for
/// [`NoEnumitemFormat`].