flm_core/stdlib/features/quote/latex.rs
1//! The recomposition rule of the [`quote`](super) feature on the
2//! `latex-recomposed` backend: a quotation is written back as the environment
3//! the author wrote, each quotation section through a LaTeX hook. A LaTeX
4//! hook is a macro that the recomposed LaTeX writes and the [style
5//! file](crate::stdlib::backends::latex::style) defines with a plain
6//! default, which a user redefines in the document's preamble to change what
7//! the recomposed LaTeX does at that point
8//! ([LaTeX hooks](crate::stdlib::backends::latex::preamble)).
9//!
10//! | written | LaTeX |
11//! |---|---|
12//! | `\begin{quote}\text{To be.}\attributed{Shakespeare}\end{quote}` | `\begin{quote}\flmQuoteText{To be.}\flmQuoteAttributed{Shakespeare}\end{quote}` |
13//! | `\lines{First\\ \indent Second}` | `\flmQuoteLines{First\\\relax`, then on the next line `\flmIndent{1\flmTabWidth}Second}` |
14//! | `\block{One.⏎⏎Two.}` | `\flmQuoteBlock{One.⏎⏎Two.}` |
15//! | `\begin{blockquote}One.⏎⏎Two.\end{blockquote}` | `\begin{blockquote}\flmQuoteBlock{One.⏎⏎Two.}\end{blockquote}` |
16//! | `\begin{address}123 Main St\\ City\end{address}` | `\begin{address}\flmQuoteLines{123 Main St\\\relax`, then `City}\end{address}` |
17//!
18//! The rendering guide describes the same output for readers of the
19//! recomposed LaTeX
20//! ([Quotations in the recomposed LaTeX](crate::guide::rendering#quotations-in-the-recomposed-latex)).
21//!
22//! # The environment and its quotation sections
23//!
24//! The rule [`LATEX_RULE`] ([`QuoteLatexRule`]) writes a quotation as the
25//! environment of its name. Inside the environment, it writes the body as the
26//! author wrote it (the whitespace, blank lines and source comments between
27//! the quotation sections unchanged, the nodes that are whitespace, such as
28//! `~` and `\ `, left out), and each quotation section through the LaTeX hook
29//! of its kind ([`hook_of`]):
30//!
31//! - `\flmQuoteText{<passage>}`, `\flmQuoteAttributed{<attribution>}` and
32//! `\flmQuoteBlock{<paragraphs>}`, over the argument of the
33//! quotation-section command, lowered through the ordinary rules;
34//! - `\flmQuoteLines{<lines>}`, over the lines: the argument is split at
35//! every `\\`, the whitespace at both ends of each line is trimmed, and the
36//! lines are joined by `\\\relax` and a line break. A line's indentation
37//! (its leading `\indent` commands, a length of as many tabs) is written as
38//! `\flmIndent{<length>}` before its content, the length written as the
39//! [LaTeX family](crate::stdlib::backends::latex) writes every length ([`stage_length`]):
40//! `\flmIndent{1\flmTabWidth}` for one tab, `\flmIndent{2\flmTabWidth}` for
41//! two. The `\relax` after every `\\` ends that command, so that a line
42//! beginning with `[` or `*` is read as the line's text and not as an
43//! argument or a star of `\\`, regardless of what begins the line (a
44//! source comment included). The line break after `\relax` is ignored, as
45//! a space after a command name is, so no space follows.
46//!
47//! The rule reads the body as every backend reads it (see the [feature's
48//! documentation](super)): a quotation-section command opens a quotation
49//! section where it is in *section position*, written directly in the body
50//! of an environment that accepts it, and each maximal run of other content
51//! between two quotation sections is a run of **bare content**. The
52//! whitespace, blank lines and source comments at the edges of a run are
53//! written unchanged, outside any LaTeX hook, except the nodes that are
54//! whitespace, such as `~` and `\ `, which are left out there, as every other
55//! backend leaves them out. The rest of the run, with the
56//! whitespace at both of its ends trimmed, is written through the LaTeX hook
57//! of the environment's bare-content kind (a `blockquote`'s content inside
58//! `\flmQuoteBlock`, an `address`'s inside `\flmQuoteLines`). Where the
59//! environment reads no bare content, the run is reported
60//! ([`BareContent`](super::BareContent)) and written in place, inside the
61//! environment and outside any LaTeX hook. The two other errors are reported
62//! as on every other backend: an `\indent` after the first content of its
63//! line ([`IndentMidLine`](super::IndentMidLine)), which is left out, and a
64//! quotation-section command written anywhere other than directly in a quote
65//! environment's body ([`NestedSection`](super::NestedSection)), reported by the rule of the
66//! command ([`SectionRule`](super::SectionRule)), which writes its content.
67//!
68//! # The definitions in the style file
69//!
70//! The feature's definition piece ([`definition_piece`],
71//! `flm.latex.def.quote`; a unit of LaTeX definitions a feature registers,
72//! [`LatexPreambleDef`]) defines the LaTeX hooks of the four kinds of
73//! quotation section and `\flmIndent`,
74//! each with `\ProvideDocumentCommand`, so that a definition that the user's
75//! document class or preamble made first is kept; the user redefines any of
76//! them after loading the style file. The rule requires the definition piece
77//! at every quotation. The length `\flmTabWidth`, the width of one tab,
78//! belongs to the LaTeX family
79//! ([`TAB_WIDTH`](crate::stdlib::backends::latex::preamble::TAB_WIDTH));
80//! [`stage_length`] requires the definition piece that declares it wherever
81//! a line's indentation is written in tabs.
82//!
83//! `quote` is an environment of standard LaTeX. The environments `blockquote`
84//! and `address`, which standard LaTeX does not define, are defined by the
85//! same definition piece, each with `\ProvideDocumentEnvironment`, so that an
86//! environment of that name defined first by the document class, a package or
87//! the author's preamble is kept: `blockquote` as the one item of a list
88//! indented `4em`, as `\flmQuoteBlock` sets its paragraphs, and `address` as a
89//! group set in `\small`. Their text does not depend on the configuration, so
90//! it belongs in a definition piece; the family's definition construct
91//! ([`DEFINITION`](crate::stdlib::backends::latex::construct::DEFINITION))
92//! is for text a feature builds from its configuration. An environment of any
93//! other name that a host configures is written under its name, and the
94//! author's LaTeX must define it.
95
96use std::sync::Arc;
97
98use techy::core::node::{BuildId, NodeRef};
99use techy::error::Diagnostic;
100
101use crate::core::lowering::{
102 DefaultMark, Lower, LowerCx, LowerError, Lowerer, Lowering, LoweringDecl, LoweringRule,
103};
104use crate::core::registry::{BuildError, FeatureBuilder};
105use crate::lang::Flm;
106use crate::lang::structural::PARBREAK;
107use crate::model::aspects::is_whitespace_of;
108use crate::model::element::{element_of, element_value};
109use crate::model::names::{ElementName, Name};
110use crate::stdlib::backends::latex::construct::{
111 ARG_SLOT, ENVIRONMENT as ENVIRONMENT_CONSTRUCT, MACRO, RAW,
112};
113use crate::stdlib::backends::latex::preamble::stage_length;
114use crate::stdlib::backends::latex::{
115 LatexArgShape, LatexEnvironmentPayload, LatexMacroPayload, LatexPreambleDef, LatexRawPayload,
116 preamble,
117};
118use crate::stdlib::backends::latex_recomposed::BACKEND;
119use crate::stdlib::backends::lowering::{is_blank, lower_run, stage_trimmed_runs};
120use crate::stdlib::backends::pres::BODY_SLOT;
121
122use super::config::QuoteSection;
123use super::elements::{QuoteElement, section_position};
124use super::lower::{bare_content, is_content, is_line_command, is_linebreak, read_line};
125use super::QUOTE;
126
127/// The name of the lowering rule of a quotation on the `latex-recomposed`
128/// backend, `flm.quote.lower.latex-recomposed` ([`QuoteLatexRule`]).
129pub const LATEX_RULE: &str = "flm.quote.lower.latex-recomposed";
130
131/// The name of the feature's definition piece, `quote`; its identifier, under
132/// which a rule requires it, is `flm.latex.def.quote` ([`PIECE`]).
133pub const PIECE_NAME: &str = "quote";
134
135/// The identifier of the feature's definition piece, `flm.latex.def.quote`
136/// ([`definition_piece`]).
137pub const PIECE: &str = "flm.latex.def.quote";
138
139/// The name of the LaTeX hook a text section (a quoted passage) is written
140/// through, `flmQuoteText`.
141pub const TEXT_HOOK: &str = "flmQuoteText";
142
143/// The name of the LaTeX hook a lines section is written through,
144/// `flmQuoteLines`.
145pub const LINES_HOOK: &str = "flmQuoteLines";
146
147/// The name of the LaTeX hook an attribution is written through,
148/// `flmQuoteAttributed`.
149pub const ATTRIBUTED_HOOK: &str = "flmQuoteAttributed";
150
151/// The name of the LaTeX hook a block section is written through,
152/// `flmQuoteBlock`.
153pub const BLOCK_HOOK: &str = "flmQuoteBlock";
154
155/// The name of the LaTeX hook a line's indentation is written through,
156/// `flmIndent`, before the line's content: `\flmIndent{<length>}`.
157pub const INDENT_HOOK: &str = "flmIndent";
158
159/// Returns the name of the LaTeX hook a quotation section of the kind
160/// `section` is written through: [`TEXT_HOOK`], [`LINES_HOOK`],
161/// [`ATTRIBUTED_HOOK`] or [`BLOCK_HOOK`].
162pub fn hook_of(section: QuoteSection) -> &'static str {
163 match section {
164 QuoteSection::Text => TEXT_HOOK,
165 QuoteSection::Lines => LINES_HOOK,
166 QuoteSection::Attributed => ATTRIBUTED_HOOK,
167 QuoteSection::Block => BLOCK_HOOK,
168 }
169}
170
171/// Returns the feature's definition piece, `flm.latex.def.quote`: the LaTeX
172/// hooks of the four kinds of quotation section and the LaTeX hook
173/// `\flmIndent`, each defined with
174/// `\ProvideDocumentCommand`, and the two environments of the feature's
175/// default configuration that standard LaTeX does not define:
176///
177/// - `\flmQuoteText{<passage>}` — the passage, ending a paragraph:
178/// `#1\par`;
179/// - `\flmQuoteLines{<lines>}` — the lines, each ended by `\\\relax`, set
180/// with no paragraph indentation, in a group of their own, the paragraph
181/// started before the first line, so that an empty first line has a line
182/// to end:
183/// `\par\begingroup\setlength{\parindent}{0pt}\leavevmode#1\par\endgroup`;
184/// - `\flmQuoteAttributed{<attribution>}` — the attribution, on a line of
185/// its own set to the right after a dash:
186/// `\par\begingroup\raggedleft---~#1\par\endgroup`;
187/// - `\flmQuoteBlock{<paragraphs>}` — paragraphs and blocks, indented as the
188/// one item of a list with no label, its left margin `4em` and its first
189/// line indented as a paragraph: `\par\list{}{\itemindent\parindent
190/// \leftmargin=4em\relax}\item\relax #1\endlist`;
191/// - `\flmIndent{<length>}` — space of that length at the start of a line
192/// that no line break removes: `\hspace*{#1}`;
193/// - the environments `blockquote` and `address`, defined with
194/// `\ProvideDocumentEnvironment`: `blockquote` as the list that
195/// `\flmQuoteBlock` sets,
196/// `address` as a group set `\small`
197/// (`\ProvideDocumentEnvironment{address}{}{\par\begingroup\small}{\par\endgroup}`).
198///
199/// The environments' text does not depend on the configuration, so it
200/// belongs to the definition piece, which is written into the style file of every
201/// document holding a quotation; the family's definition construct is for
202/// text a feature builds from its configuration. A definition of the same
203/// name made before the style file is loaded is kept.
204///
205/// The LaTeX hooks of the four kinds of quotation section take a long
206/// argument (`+m`), so that content holding a paragraph break is still read
207/// as the argument instead of stopping the compilation. Redefine a LaTeX
208/// hook, before loading the style file
209/// or after it, to set that quotation section differently. See the [module
210/// documentation](self).
211pub fn definition_piece() -> LatexPreambleDef {
212 // The definitions of `blockquote` and `address` are the two of the Python
213 // implementation's recomposer.
214 LatexPreambleDef::new(
215 PIECE_NAME,
216 "\
217% Quotations: one command for each kind of quotation section (a passage,
218% lines, an attribution, a block), written between the environment's \\begin
219% and \\end lines.
220% \\flmQuoteText{<passage>}: a quoted passage, ending a paragraph.
221% \\flmQuoteLines{<lines>}: lines set as written, each ended by \\\\\\relax, with no
222% paragraph indentation; a line's indentation is \\flmIndent{<length>} at
223% its start, a tab being \\flmTabWidth.
224% \\flmQuoteAttributed{<attribution>}: the attribution, on a line of its own
225% set to the right, after a dash.
226% \\flmQuoteBlock{<paragraphs>}: paragraphs and blocks, indented as the one
227% item of a list with no label, its left margin 4em.
228% \\flmIndent{<length>}: space of <length> at the start of a line.
229% Redefine one of these commands to set that kind of quotation section
230% differently.
231% The environments blockquote (set as \\flmQuoteBlock sets its paragraphs) and
232% address (a group set in \\small), which standard LaTeX does not define, are
233% defined below; a definition made before this file is loaded is kept.
234\\ProvideDocumentCommand\\flmQuoteText{+m}{#1\\par}
235\\ProvideDocumentCommand\\flmQuoteLines{+m}{\\par\\begingroup\\setlength{\\parindent}{0pt}\\leavevmode#1\\par\\endgroup}
236\\ProvideDocumentCommand\\flmQuoteAttributed{+m}{\\par\\begingroup\\raggedleft---~#1\\par\\endgroup}
237\\ProvideDocumentCommand\\flmQuoteBlock{+m}{\\par\\list{}{\\itemindent\\parindent\\leftmargin=4em\\relax}\\item\\relax #1\\endlist}
238\\ProvideDocumentCommand\\flmIndent{m}{\\hspace*{#1}}
239\\ProvideDocumentEnvironment{blockquote}{}{\\par\\list{}{\\itemindent\\parindent\\leftmargin=4em\\relax}\\item\\relax}{\\endlist}
240\\ProvideDocumentEnvironment{address}{}{\\par\\begingroup\\small}{\\par\\endgroup}
241",
242 "`\\flmQuoteText`, `\\flmQuoteLines`, `\\flmQuoteAttributed`, `\\flmQuoteBlock`: the \
243 LaTeX hooks of the four kinds of quotation section; `\\flmIndent{length}`: a line's \
244 indentation; the environments `blockquote` and `address`",
245 )
246}
247
248/// The implementation of the lowering rule [`LATEX_RULE`], the default on the
249/// `latex-recomposed` backend: it requires the definition piece [`PIECE`]
250/// and stages the environment of the quotation's name around its body, each
251/// quotation section through its LaTeX hook. See the [module
252/// documentation](self).
253///
254/// # Errors
255///
256/// [`LowerError`] when the node carries no [`QuoteElement`], and any error from lowering the
257/// content.
258#[derive(Debug, Default, Clone, Copy)]
259pub struct QuoteLatexRule;
260
261impl Lower for QuoteLatexRule {
262 fn lower(
263 &self,
264 node: NodeRef<'_, Flm>,
265 cx: &mut LowerCx<'_>,
266 lw: &mut dyn Lowerer,
267 ) -> Result<Lowering, LowerError> {
268 let value = element_value::<QuoteElement>(&node)
269 .ok_or_else(|| LowerError::structure("a quotation without its value"))?;
270 lw.require(&Name::from(PIECE));
271 // The body read as the general rule reads it: sections in section
272 // position, and the maximal runs of other content between them.
273 let body: Vec<NodeRef<'_, Flm>> =
274 node.body().map(|body| body.iter().collect()).unwrap_or_default();
275 let mut content = Vec::new();
276 let mut start = 0;
277 for (at, child) in body.iter().enumerate() {
278 if let Some(position) = section_position(child) {
279 bare_run(cx, lw, value, &body[start..at], &mut content)?;
280 let section = match position.section {
281 QuoteSection::Lines => {
282 let nodes: Vec<NodeRef<'_, Flm>> = child
283 .argument_content_nodes(0)
284 .map(|nodes| nodes.iter().collect())
285 .unwrap_or_default();
286 stage_lines(cx, lw, &nodes)?
287 }
288 _ => lw.lower_arg(cx, child, 0)?,
289 };
290 content.push(hook(cx, lw, position.section, section)?);
291 start = at + 1;
292 }
293 }
294 bare_run(cx, lw, value, &body[start..], &mut content)?;
295 let environment = lw.pres_slots_with(
296 cx,
297 &ElementName::from(ENVIRONMENT_CONSTRUCT),
298 LatexEnvironmentPayload::new(value.name.as_str(), Vec::new()),
299 vec![(String::from(BODY_SLOT), content)],
300 )?;
301 Ok(Lowering::Emit(vec![environment]))
302 }
303}
304
305/// Stages `run`, a maximal run of bare content between two quotation
306/// sections of the quotation `value`: the whitespace, blank lines and source
307/// comments at its edges unchanged, the nodes that are whitespace there left
308/// out ([`lower_edge`]), and the rest through the LaTeX hook of
309/// the environment's bare-content kind, with the whitespace at both of its
310/// ends trimmed as a quotation section's content is; or, where the
311/// environment reads no bare content, reported once and written in place.
312fn bare_run(
313 cx: &mut LowerCx<'_>,
314 lw: &mut dyn Lowerer,
315 value: &QuoteElement,
316 run: &[NodeRef<'_, Flm>],
317 out: &mut Vec<BuildId>,
318) -> Result<(), LowerError> {
319 let Some(first) = run.iter().position(|node| !is_edge(node)) else {
320 out.extend(lower_edge(cx, lw, run)?);
321 return Ok(());
322 };
323 let last = run.iter().rposition(|node| !is_edge(node)).unwrap_or(first);
324 out.extend(lower_edge(cx, lw, &run[..first])?);
325 let core = &run[first..=last];
326 match value.environment.bare {
327 Some(QuoteSection::Lines) => {
328 let lines = stage_lines(cx, lw, core)?;
329 out.push(hook(cx, lw, QuoteSection::Lines, lines)?);
330 }
331 Some(kind) => {
332 let content = stage_trimmed_runs(cx, lw, &[core], is_line_command)?;
333 out.push(hook(cx, lw, kind, content)?);
334 }
335 None => {
336 lw.diagnose(Diagnostic::error(bare_content(value), core[0].span().clone()));
337 out.extend(lower_run(cx, lw, core)?);
338 }
339 }
340 out.extend(lower_edge(cx, lw, &run[last + 1..])?);
341 Ok(())
342}
343
344/// Returns whether `node`, at the edge of a bare run, stands outside any
345/// LaTeX hook: whitespace (`~` and `\ ` included, [`is_blank`]), a source
346/// comment, or the paragraph-break node that a blank line leaves in the tree
347/// this backend lowers, which has not been through the block-structure pass.
348fn is_edge(node: &NodeRef<'_, Flm>) -> bool {
349 node.is_comment() || is_blank(node) || element_of(node).name.as_str() == PARBREAK
350}
351
352/// Lowers `edge`, nodes at the edge of a bare run ([`is_edge`]), as written,
353/// except the nodes that are whitespace, such as `~` and `\ `
354/// ([`is_whitespace_of`]), which are left out: LaTeX would typeset them
355/// there, and every other backend removes them.
356fn lower_edge(
357 cx: &mut LowerCx<'_>,
358 lw: &mut dyn Lowerer,
359 edge: &[NodeRef<'_, Flm>],
360) -> Result<Vec<BuildId>, LowerError> {
361 let mut out = Vec::new();
362 for run in edge.split(is_whitespace_of) {
363 out.extend(lower_run(cx, lw, run)?);
364 }
365 Ok(out)
366}
367
368/// Stages the lines of a lines section over `content`: split at every `\\`,
369/// each line's indentation as `\flmIndent{<length>}` before its content, the
370/// whitespace at both ends of the line trimmed, the lines joined by
371/// `\\\relax` and a line break. A lines section that holds neither content
372/// nor a `\\` has no line.
373fn stage_lines(
374 cx: &mut LowerCx<'_>,
375 lw: &mut dyn Lowerer,
376 content: &[NodeRef<'_, Flm>],
377) -> Result<Vec<BuildId>, LowerError> {
378 let mut out = Vec::new();
379 if !content.iter().any(|node| is_content(node) || is_linebreak(node)) {
380 return Ok(out);
381 }
382 for (index, line) in content.split(is_linebreak).enumerate() {
383 if index > 0 {
384 out.push(raw(cx, lw, "\\\\\\relax\n")?);
385 }
386 let (indent, runs) = read_line(lw, line);
387 if !indent.is_zero() {
388 let length = stage_length(cx, lw, &indent)?;
389 out.push(lw.pres_slots_with(
390 cx,
391 &ElementName::from(MACRO),
392 LatexMacroPayload::new(INDENT_HOOK, [LatexArgShape::Mandatory]),
393 vec![(String::from(ARG_SLOT), vec![length])],
394 )?);
395 }
396 out.extend(stage_trimmed_runs(cx, lw, &runs, is_line_command)?);
397 }
398 Ok(out)
399}
400
401/// Stages a call of the LaTeX hook of the kind `section` with `content` as
402/// its argument.
403fn hook(
404 cx: &mut LowerCx<'_>,
405 lw: &mut dyn Lowerer,
406 section: QuoteSection,
407 content: Vec<BuildId>,
408) -> Result<BuildId, LowerError> {
409 lw.pres_slots_with(
410 cx,
411 &ElementName::from(MACRO),
412 LatexMacroPayload::new(hook_of(section), [LatexArgShape::Mandatory]),
413 vec![(String::from(ARG_SLOT), content)],
414 )
415}
416
417/// Stages a raw node (`flm.pres.latex.raw`): LaTeX text written byte for
418/// byte.
419fn raw(cx: &mut LowerCx<'_>, lw: &mut dyn Lowerer, text: &str) -> Result<BuildId, LowerError> {
420 lw.pres_with(cx, &ElementName::from(RAW), LatexRawPayload::new(text), Vec::new())
421}
422
423/// Returns the lowering rule [`LATEX_RULE`], ready to be registered: the
424/// default on the `latex-recomposed` backend only.
425pub fn latex_rule() -> LoweringRule {
426 LoweringRule::new(
427 LATEX_RULE,
428 QUOTE,
429 LoweringDecl::new()
430 .produces(ENVIRONMENT_CONSTRUCT)
431 .produces(MACRO)
432 .produces(RAW),
433 Arc::new(QuoteLatexRule),
434 DefaultMark::OnBackends(vec![BACKEND.into()]),
435 )
436 .docs(
437 "a quotation lowers to the environment of its name, each quotation section through the \
438 LaTeX hook of its kind, and a line's indentation through `\\flmIndent`",
439 )
440}
441
442/// Registers what the feature contributes to the `latex-recomposed` backend:
443/// a peer declaration ([`PeerName`](crate::core::registry::PeerName)) of the
444/// backend and of each construct element the rule stages, the definition
445/// piece ([`definition_piece`]) as a contribution to the service slot of
446/// definition pieces ([`preamble::SLOT`]), then [`latex_rule`]. A registry
447/// without the LaTeX features still builds, with the rule set aside (excluded
448/// from rule selection; see [`PeerName`](crate::core::registry::PeerName)).
449///
450/// # Errors
451///
452/// The [`BuildError`] of the registry builder.
453pub(super) fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
454 b.peer_backend(
455 BACKEND,
456 "the latex-recomposed backend, on which the quotation's rule \
457 `flm.quote.lower.latex-recomposed` is the default",
458 )?;
459 b.peer_element::<LatexEnvironmentPayload>(
460 ENVIRONMENT_CONSTRUCT,
461 "the LaTeX family's environment construct, which the recomposition rule stages",
462 )?;
463 b.peer_element::<LatexMacroPayload>(
464 MACRO,
465 "the LaTeX family's macro-call construct, which the recomposition rule stages for the \
466 LaTeX hooks of the quotation sections and of a line's indentation",
467 )?;
468 b.peer_element::<LatexRawPayload>(
469 RAW,
470 "the LaTeX family's raw node construct, in which the recomposition rule writes the \
471 line breaks between lines and the length of a line's indentation",
472 )?;
473 b.peer_slot::<LatexPreambleDef>(preamble::SLOT, Arc::new(definition_piece()))?;
474 b.lowering_rule(latex_rule())
475}
476
477#[cfg(test)]
478mod tests {
479 use super::*;
480
481 #[test]
482 fn the_piece_provides_the_four_hooks_and_the_indentation() {
483 let piece = definition_piece();
484 assert_eq!(piece.id.as_str(), PIECE);
485 for hook in [TEXT_HOOK, LINES_HOOK, ATTRIBUTED_HOOK, BLOCK_HOOK, INDENT_HOOK] {
486 assert!(
487 piece.content.contains(&format!("\\ProvideDocumentCommand\\{hook}{{")),
488 "{hook}"
489 );
490 }
491 assert!(piece.requires.is_empty());
492 }
493
494 #[test]
495 fn the_piece_provides_only_the_two_environments_latex_lacks() {
496 let piece = definition_piece();
497 for name in ["blockquote", "address"] {
498 let definition = format!("\\ProvideDocumentEnvironment{{{name}}}{{}}");
499 assert_eq!(piece.content.matches(&definition).count(), 1, "{name}");
500 }
501 assert!(!piece.content.contains("Environment{quote}"));
502 }
503}