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
//! The `defterm` feature: defined terms. An author defines a term where it is
//! explained, with the `defterm` environment, and links to that term
//! definition from anywhere in the document with `\term`.
//!
//! # What an author writes
//!
//! ```text
//! \begin{defterm}{Markov chain}\label{topic:markov}\aliasterm{Markov chains}
//! A random process whose next state depends on its present state alone.
//! \end{defterm}
//!
//! Every \term{Markov chain} forgets its past, as \term{Markov chains} do;
//! \term[Markov chain]{such a process} does too. See \ref{topic:markov}.
//! ```
//!
//! A **term definition** is the environment `defterm`. Its one argument is
//! the **term** being defined, inline content (`\(\alpha\)-decay`,
//! `\emph{Markov} chain`), and its body holds the explanation's paragraphs.
//! After the term, the environment accepts two repeatable fields, in any
//! order:
//!
//! - `\label{…}`, a label by which `\ref` and `\hyperref` refer to the term
//! definition, of the label type `term` or `topic` ([`LABEL_TYPES`]); a
//! reference to a term definition shows its term;
//! - `\aliasterm{…}`, an **alias**: another way of writing the term (a
//! plural, an inflected form), under which a term link finds the same term
//! definition.
//!
//! A **term link** is `\term[ref]{shown}`: a link to the definition of the
//! term `ref`, or of the term `shown` where the bracket is left out or blank,
//! showing the text `shown`. Terms are matched by their **identity**: the source text
//! they are written as, with whitespace collapsed
//! ([`spelling_identity`](crate::stdlib::backends::pres::spelling_identity)).
//! The match is exact, case and markup included, so `\term{Entropy}` finds no
//! definition of `entropy`. A term's other forms are declared with
//! `\aliasterm`; nothing else matches a term to a term definition. The
//! language guide describes these commands for authors under [Defined
//! terms](crate::guide::language_syntax#defined-terms).
//!
//! # A term link is a reference
//!
//! A term definition declares one [reference
//! point](crate::model::aspects::RefPoint) and a term link declares one
//! [reference site](crate::model::aspects::RefSite) ([`elements`] gives the
//! labels; see [reference points, labels and
//! anchors](crate::guide::concepts_overview#reference-points-labels-and-anchors)).
//! The [references](crate::stdlib::features::refs) feature resolves the site
//! against the point through its stages and tables, as it resolves `\ref`;
//! no code of this feature looks a term definition up. A term definition's
//! reference point carries a label computed from its term, one computed from
//! each alias, then the labels the author wrote ([`elements`]). Therefore:
//!
//! - a term link that nothing resolves is reported by the references feature
//! as `flm.refs.unresolved`, an Error by default;
//! - two term definitions of one term carry the same computed label, which
//! the references feature reports as `flm.refs.duplicate-label`, and every
//! term link finds the first one;
//! - a term definition's anchor is the one that feature computes from the
//! point's first label: the label computed from the term, where the term is
//! not empty.
//!
//! # How they are written
//!
//! A term definition is written as a block holding its body, whose first
//! paragraph opens with the **lead-in**: the configured lead-in template
//! ([`DeftermConfig`]), `#{term}: ` by default, so that the term definition
//! reads `Markov chain: A random process …`. The lead-in is set as a run-in
//! heading is, and shows the term where the term definition writes it, never
//! a copy ([`lead_in`]). A term link is a link of the kind `term` around the
//! text written for it, except inside the definition of its own term, where
//! it is the term being defined: a span of role `flm.defterm.term`, linked to
//! nothing ([`rules`]).
//!
//! On the text and `html` backends the lead-in is followed by the backend's
//! run-in stop (the render option `run_in_stop`, a period by default) only
//! where it ends without punctuation.
//!
//! - On the **text backend**, the lead-in is printed before the first
//! paragraph's words, and a term link is its text.
//! - On the **`html` backend**, a term definition is a block carrying its
//! anchor and a term link is a link of kind `term`; the term being defined
//! is a span that the feature's stylesheet sets in italics ([`html`]).
//! - On the **`latex-recomposed` backend**, a term definition is written back
//! as the environment `defterm`, its labels made to refer to it with the
//! term as their display text, and the style file defines the environment
//! from the configured lead-in. A term link is the LaTeX hook
//! `\flmTerm{<label>}{<shown>}`, and, inside the definition of its own
//! term, `\flmTermInDefterm{<shown>}`; an author redefines either
//! ([`latex`]).
//!
//! The rendering guide describes the outputs under [Defined
//! terms](crate::guide::rendering#defined-terms), [Defined terms in
//! HTML](crate::guide::rendering#defined-terms-in-html) and [Defined terms in
//! the recomposed LaTeX](crate::guide::rendering#defined-terms-in-the-recomposed-latex).
//!
//! # What the feature provides to the pipeline
//!
//! - **Elements.** [`DEFTERM`] (`flm.defterm`), the environment `defterm`,
//! and [`TERM`] (`flm.term`), the command `\term`, both available in text
//! mode; and the synthesized element [`TERM_POINTER`], which shows the term
//! inside a lead-in ([`lead_in`]); no document can write it.
//! - **Two argument roles**, each stating what an argument holds
//! ([`ArgDef::role`](crate::lang::mint::ArgDef::role)).
//! [`DEFINED_TERM_ARG_ROLE`] (`flm.defterm.defined-term`) is the role of
//! the term a `defterm` environment defines and of its `\aliasterm`
//! field's argument; [`TARGET_ARG_ROLE`] (`flm.defterm.target`) is the role
//! of the term a `\term` points to.
//! - **The general lowering rules**, [`DEFINITION_RULE`], [`TERM_RULE`] and
//! [`POINTER_RULE`], each the default on every backend ([`rules`],
//! [`lead_in`]).
//! The term definition's general rule requires the feature's style
//! identifier `flm.defterm.style` ([`html::STYLE`]) at every definition it
//! stages, and the term link's where it writes the term inside its own
//! definition.
//! - **On the `html` backend**, the feature's stylesheet,
//! `flm.defterm.style` ([`html`]).
//! - **On the `latex-rendered` backend**, the definition piece
//! `flm.latex.def.flmx.defterm` ([`latex_rendered`]), which the same
//! requirement brings into the style file.
//! - **On the `latex-recomposed` backend**, the rules of the three elements
//! and the feature's definition piece `flm.latex.def.defterm` ([`latex`]).
//! - **A configuration**, [`DeftermConfig`], whose one field, the lead-in
//! template, is the feature's settings key. It is fixed when the registry is
//! built (see [settings, options and
//! configuration](crate::guide::concepts_overview#settings-options-and-configuration)),
//! and a build hook ([`LateInit`](crate::core::registry::LateInit))
//! compiles the template once the language is built.
//!
//! # Interactions with other features
//!
//! The feature reads the references feature's anchors and resolutions tables
//! optionally, and declares them through peer declarations
//! ([`PeerName`](crate::core::registry::PeerName)); it declares the same way
//! the argument role that the references feature gives the argument of the
//! `\label` field ([`DEFINED_LABEL_ARG_ROLE`](refs::DEFINED_LABEL_ARG_ROLE)).
//! It therefore builds and renders in a registry without the references
//! feature: a term definition declares its reference point, which nothing
//! reads, and is written with no anchor, and a term link is its text. The rules of the `latex-recomposed`
//! backend are registered under peer declarations of their backend and of
//! the LaTeX family's elements; in a registry without them, those rules are
//! set aside (excluded from rule selection; see
//! [`PeerName`](crate::core::registry::PeerName)).
//!
//! # Map of the items
//!
//! - The feature: [`Defterm`], [`feature`], [`FEATURE`].
//! - The configuration: [`DeftermConfig`], [`DEFAULT_LEAD_IN`].
//! - The elements, their arguments and the identity of a term: [`elements`]
//! ([`DEFTERM`], [`TERM`], [`term_target`], [`in_own_definition`]).
//! - The lead-in and the term pointer: [`lead_in`].
//! - The general rules: [`rules`].
//! - The conditions: [`EmptyTerm`], [`PointerRefused`].
//! - The stylesheet: [`html`]. The `latex-recomposed` backend's own rules:
//! [`latex`].
// A term link is resolved by the references feature, with no lookup of this
// feature's own: that feature already resolves every reference site under one
// set of conditions and one severity rule, which a second lookup would repeat
// and could contradict.
use Arc;
use crateSettingsDecl;
use crate;
use crate;
use craterefs;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// The feature's registered name, `defterm`.
pub const FEATURE: &str = "defterm";
/// The declaration of the feature's settings: the fields of [`DeftermConfig`] are its keys, and
/// the lead-in template is FLM markup. See [`crate::core::settings`].
/// The `defterm` feature ([`FlmFeature`]): under a [`DeftermConfig`], it
/// registers the environment `defterm` and the command `\term`, the term
/// pointer, their lowering rules on every backend, and the build hook that
/// compiles the lead-in template. See the [module documentation](self).
///
/// Construct it with [`Defterm::new`], or use [`feature`] for the default
/// configuration. The registry build fails when the lead-in template does
/// not compile.
/// The [`Defterm`] feature under the default configuration (the lead-in
/// [`DEFAULT_LEAD_IN`]), ready to be listed in a package entry
/// ([`PackageEntry`](crate::core::registry::PackageEntry)).
///
/// Use `Arc::new(Defterm::new(config))` to list the feature under a
/// [`DeftermConfig`] of your own.