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
//! The two structural lowering rules ([`LoweringRule`]) of the
//! `latex-recomposed` backend, for the paragraph break and the paragraph:
//! the only lowering rules that the
//! backend's feature registers itself ([`rules`]).
//!
//! Both rules write a blank line, which LaTeX reads as a paragraph break, and
//! both require the raw tree:
//!
//! | element | rule | writes |
//! |---|---|---|
//! | `flm.parbreak` | [`PARBREAK_RULE`] ([`ParbreakRule`]) | one blank line, however many blank lines the author wrote at that place |
//! | `flm.paragraph` | [`PARAGRAPH_RULE`] ([`ParagraphRule`]) | the paragraph's content, lowered, then one blank line |
//!
//! # The raw tree
//!
//! The recomposed LaTeX keeps the document as the author typed it, so it is
//! written from the *raw* tree: the [frozen
//! tree](crate::guide::concepts_overview#frozen-trees-and-computed-data) that
//! the [block-structure pass](crate::lang::rewrites::blocks) has not
//! processed, in which no paragraphs were built, no typographic
//! substitution was made, the text is as parsed, and the paragraph-break
//! markers (`flm.parbreak`) are still in place. A backend states the tree
//! state it needs through the requirements of its lowering rules, not through
//! a setting: both rules here require the capability `flm.blocks.raw`
//! ([`RAW`]), which the [`blocks`](crate::stdlib::features::blocks) feature
//! provides through a stage that does nothing and only marks this tree
//! state. The lowering stage of a backend requires
//! every capability that the backend's selected rules require
//! ([`rules_needs`](crate::stdlib::backends::lowering::rules_needs)), so
//! every plan for this backend keeps its trees raw, regardless of what the
//! document holds.
//!
//! The paragraph rule never applies on the raw tree, where no paragraph group
//! exists. It is registered because `flm.paragraph` is a structural element
//! present in every registry, and building a plan for a backend fails
//! ([`PlanError::Incomplete`](crate::core::plan::PlanError::Incomplete)) when
//! some element that a document may contain has neither a native emission
//! nor a rule on that backend. Both rules stage (build into the lowered
//! tree; see [`Lowerer`]) a `flm.pres.latex.raw` node holding the blank line
//! ([`LatexRawPayload`]): a blank line is LaTeX syntax that no other construct
//! element expresses.
//!
//! Both rules are marked as the default on this backend only
//! ([`DefaultMark::OnBackends`]), so that they do not affect the `text`
//! backend, which writes `flm.parbreak` natively and lowers `flm.paragraph`
//! through the general rule of the `lowering` feature
//! ([`PARAGRAPH_RULE`](crate::stdlib::backends::lowering::PARAGRAPH_RULE)).
//!
//! # Where the other recomposition rules are registered
//!
//! Each standard feature registers the lowering rule that writes its own
//! elements back as LaTeX (its *recomposition rule*), in a `latex` module of
//! its own, beside the feature's general rule. Such a rule refers to things
//! the feature does not register: this backend, in its default mark; the
//! LaTeX construct elements, in what it produces; and for some features a
//! table another feature owns, such as the references feature's table of
//! safe labels. The feature makes a peer declaration ([`PeerName`](crate::core::registry::PeerName)) of each:
//! a forward declaration that the registry build resolves once every feature
//! has registered. When a peer declaration resolves to nothing, the rule is
//! set aside (excluded from rule selection) and the build records one Note.
//! A host that registers the `textstyles` feature without the `latex`
//! feature and this backend therefore still builds its registry; a host that
//! registers this backend gets every feature's recomposition rule selected
//! like any other rule. This backend's feature declares no content feature as
//! a dependency: a registry that holds it needs only the `latex`, `lowering`
//! and `check` features.
use Arc;
use NodeRef;
use crate;
use crate;
use crateFlm;
use crateElementName;
use crateLatexRawPayload;
use crateRAW as LATEX_RAW;
use crateRAW;
use BACKEND;
/// The registered name of the paragraph-break rule ([`ParbreakRule`]),
/// `flm.parbreak.lower.latex-recomposed`.
pub const PARBREAK_RULE: &str = "flm.parbreak.lower.latex-recomposed";
/// The registered name of the paragraph rule ([`ParagraphRule`]),
/// `flm.paragraph.lower.latex-recomposed`.
pub const PARAGRAPH_RULE: &str = "flm.paragraph.lower.latex-recomposed";
/// The text of the `flm.pres.latex.raw` node that both rules stage: two
/// newlines, which LaTeX reads as one paragraph break.
pub const BLANK_LINE: &str = "\n\n";
/// Stages a `flm.pres.latex.raw` node holding one blank line ([`BLANK_LINE`])
/// and returns its identifier in the tree being built.
/// The lowering rule registered as [`PARBREAK_RULE`]: it lowers a
/// paragraph-break marker (`flm.parbreak`) to one blank line.
///
/// The author may have written several blank lines at that place; LaTeX reads
/// any number of them as one paragraph break, and the recomposed LaTeX writes
/// one.
;
/// The lowering rule registered as [`PARAGRAPH_RULE`]: it lowers a paragraph
/// group (`flm.paragraph`) to its content, lowered, followed by one blank
/// line.
///
/// The rule never applies on the raw tree that this backend requires; it
/// exists so that the plan's completeness check
/// ([`PlanError::Incomplete`](crate::core::plan::PlanError::Incomplete)) finds
/// a rule for `flm.paragraph` (see the module documentation).
;
/// The two structural lowering rules of this backend, [`PARBREAK_RULE`] then
/// [`PARAGRAPH_RULE`], ready to be registered; the [`LatexRecomposed`] feature
/// registers them.
///
/// Each rule requires the capability [`RAW`] (`flm.blocks.raw`), produces
/// `flm.pres.latex.raw` nodes, and is marked as the default on the
/// `latex-recomposed` backend only ([`DefaultMark::OnBackends`]).
///
/// [`LatexRecomposed`]: super::LatexRecomposed
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::latex_recomposed::rules::{PARBREAK_RULE, rules};
///
/// let names: Vec<String> = rules().iter().map(|rule| rule.name.to_string()).collect();
/// assert_eq!(names[0], PARBREAK_RULE);
/// assert!(rules().iter().all(|rule| rule.decl.requires[0].as_str() == "flm.blocks.raw"));
/// ```