flm_core/stdlib/features/citations/latex.rs
1//! The lowering rules of the [`citations`](super) feature for the
2//! `latex-recomposed` backend (the recomposed LaTeX): a citation is written
3//! back as the author wrote it, through three LaTeX hooks, and the list of
4//! cited works is left to LaTeX.
5//!
6//! A LaTeX hook is a macro that the recomposed LaTeX writes and the style
7//! file defines with a plain default, which a user redefines in the
8//! document's preamble to change what the recomposed LaTeX does at that point
9//! (see [LaTeX hooks](crate::stdlib::backends::latex::preamble) and the
10//! rendering guide's [LaTeX hooks](crate::guide::rendering#the-latex-hooks)).
11//! The three hooks of a citation are `\flmCite`, `\flmCitePreSpace` and
12//! `\flmRefCite`:
13//!
14//! | written | LaTeX |
15//! |---|---|
16//! | `text~\cite{a,b,c}` | `text~\flmCitePreSpace\flmCite{a,b,c}` |
17//! | `\cite[Thm 4]{a,b}\cite{c}` | `\flmCitePreSpace\flmCite[Thm 4]{a,b}\flmCite{c}` |
18//! | `\cite{arxiv:1234_5}` | `\flmCitePreSpace\flmCite{arxiv:1234_5}` |
19//! | `\R\cite{a,b,c}` | `\flmRefCite{refs.~}{\flmCite{a,b,c}}` |
20//! | `\R[S]\cite{a}\cite{b}` | `\flmRefCite{Refs.~}{\flmCite{a}\flmCite{b}}` |
21//! | `\R[I]\cite{a}` | `\flmRefCite{}{\flmCite{a}}` |
22//!
23//! The rendering guide shows what LaTeX prints for them ([Citations in the
24//! recomposed LaTeX](crate::guide::rendering#citations-in-the-recomposed-latex)).
25//!
26//! # A citation written as the author wrote it
27//!
28//! This backend lowers the tree before its block structure is read, so the
29//! author's whitespace is written to the output unchanged. The rule of
30//! `\cite` ([`CiteLatexRule`]) writes **one** `\flmCitePreSpace` for the
31//! citation chunk, then **one** `\flmCite` per call of the citation chunk:
32//! the first call and each further call, in order, each with its own citation
33//! keys and its own note. Nothing is sorted, merged or compressed: LaTeX
34//! numbers the cited works, and sorts and compresses them (or not) as the
35//! author's bibliography setup says. The rule of `\R` ([`RefCiteLatexRule`])
36//! writes no `\flmCitePreSpace`, because an `\R` is a part of its sentence,
37//! and passes its word and its calls to `\flmRefCite`. The word is the
38//! citation counter style's word: singular when the citation chunk holds one
39//! item and plural otherwise, counting a citation key written twice as two
40//! items (the other backends count the distinct numbers the citation mark
41//! shows; see [`StagedMark::shown`](super::StagedMark::shown)), capitalized
42//! under the flag `S`, and empty under the flag `I`. The configuration's placement and
43//! form change nothing here: LaTeX decides how a citation is shown.
44//!
45//! The **citation keys** of one call are written as a raw node (the LaTeX
46//! family's construct `flm.pres.latex.raw`, written to the output without
47//! escaping), joined by commas: each citation key as
48//! [`read_chunk`](super::read_chunk) reads it, the FLM code written for it
49//! with every run of whitespace made one space and the ends trimmed. No
50//! character is escaped (an underscore in a citation key stays an
51//! underscore) and no safe label is assigned, because a citation key is not
52//! a label of the document but the name of an entry of the author's
53//! bibliography database. A citation key that LaTeX cannot read is the
54//! author's to fix.
55//!
56//! The citation keys are checked for placeholders
57//! ([`spelling_at_lowering`](crate::core::lowering::spelling_at_lowering)), so
58//! a user definition whose template holds a placeholder among the citation
59//! keys of a `\cite` (`\cite{arxiv:#1}`) is not written as a LaTeX
60//! definition: each of its use sites is expanded, and the rule writes the
61//! citation keys that the use site supplies. A `\cite` with no placeholder in
62//! its citation keys, inside a user definition kept as a LaTeX definition, is
63//! written into that definition, and LaTeX numbers it wherever the
64//! definition is used.
65//!
66//! The **note** is content, written as all content is, in the optional
67//! argument; a call whose note is empty writes none.
68//!
69//! A call with no citation key is reported, as on every output
70//! ([`report_mistakes`]), and writes no `\flmCite`.
71//! A citation chunk that writes no `\flmCite` at all, and an `\R` with no
72//! `\cite` directly after it ([`NoCitation`]), are
73//! written as a dropped mark (`flm.pres.dropped`), which this backend writes
74//! as a comment line.
75//!
76//! # The definition piece of the hooks
77//!
78//! The feature's definition piece ([`definition_piece`],
79//! `flm.latex.def.citations`; a definition piece is a unit of LaTeX
80//! definitions that the style file holds when the document requires it, see
81//! [`LatexPreambleDef`]) defines the three LaTeX hooks, each with
82//! `\ProvideDocumentCommand`, so a definition that the author's class or
83//! preamble made first is the one used. It requests no LaTeX package:
84//! loading `natbib` or `biblatex` is the author's choice.
85//!
86//! - `\flmCite[<note>]{<keys>}`, one call: LaTeX's `\cite`, with its
87//! optional argument when there is a note. An author who wants the
88//! citation entries shown in place redefines it, with `biblatex`'s
89//! `\fullcite` for example.
90//! - `\flmCitePreSpace`, before a citation chunk of `\cite` calls:
91//! `\unskip~`, which removes the author's space and writes a space that
92//! does not break. An author of superscript citations redefines it to
93//! `\unskip`.
94//! - `\flmRefCite{<word>}{<citations>}`, for an `\R`: the word, then the
95//! citations. An author of superscript citations who redefines `\flmCite`
96//! with a command that prints bare numbers (`natbib`'s `\citenum`) gets
97//! `refs.~1,2` with this hook unchanged.
98//!
99//! **A citation in a heading whose case LaTeX changes** (a class that sets
100//! its running heads in capitals with `\MakeUppercase`): the definition piece
101//! adds `\flmCite` to the LaTeX kernel's list of commands whose argument a
102//! change of case leaves unchanged (`\l_text_case_exclude_arg_tl`, where the
103//! kernel lists `\cite`), unless `\flmCite` is on it already. The kernel
104//! protects the first brace group after the command. Where the note holds no
105//! brace group, that group is the mandatory argument, so the citation keys
106//! still refer to the author's entries, and the note is uppercased like the
107//! text around it (`RESULTS [1, THM 4]`). As with LaTeX's own `\cite`, a note
108//! that holds a brace group (a command's argument, as in `\emph{p.}`) takes
109//! that protection instead, and the citation keys are then uppercased too.
110//!
111//! The definition piece also makes a citation contribute nothing to a PDF
112//! bookmark where `hyperref` is loaded, before the style file or after it
113//! (the word of `\flmRefCite` included), so a heading's title that holds a
114//! citation gives its bookmark the title's own words.
115//!
116//! # The list of cited works
117//!
118//! No bibliography is written: the list of cited works and its entries lower
119//! to nothing on this backend ([`ListNotWritten`]), and no citation entry is
120//! written anywhere. LaTeX writes its own list (`thebibliography`, BibTeX,
121//! `biblatex`) from the author's database. The check that every cited key has
122//! a citation entry still runs, because its result belongs to the document,
123//! regardless of the backend that renders it.
124//!
125//! # Registration
126//!
127//! The feature declares the `latex-recomposed` backend and the LaTeX family's
128//! macro and raw constructs through peer declarations
129//! ([`PeerName`](crate::core::registry::PeerName)), and contributes its
130//! definition piece to the style file's service slot
131//! ([`preamble::SLOT`]) as a peer contribution. A registry without the LaTeX
132//! features therefore still builds, with these rules set aside (excluded from
133//! rule selection; see [`PeerName`](crate::core::registry::PeerName)).
134
135use std::sync::Arc;
136
137use techy::core::node::{BuildId, NodeRef};
138
139use crate::core::lowering::{
140 DefaultMark, Lower, LowerCx, LowerError, Lowerer, Lowering, LoweringDecl, LoweringRule,
141};
142use crate::core::registry::{BuildError, FeatureBuilder};
143use crate::lang::Flm;
144use crate::model::names::{ElementName, Name};
145use crate::stdlib::backends::latex::construct::{ARG_SLOT, MACRO, RAW};
146use crate::stdlib::backends::latex::preamble::{self, LatexPreambleDef};
147use crate::stdlib::backends::latex::{LatexArgShape, LatexMacroPayload, LatexRawPayload};
148use crate::stdlib::backends::latex_recomposed::BACKEND;
149use crate::stdlib::backends::lowering::lower_run;
150use crate::stdlib::backends::pres;
151
152use super::bibliography::{BIBLIOGRAPHY, BIBLIOGRAPHY_ENTRY};
153use super::config::CAPITAL_VARIANT;
154use super::diagnostics::NoCitation;
155use super::elements::{calls, leading_call, read_call, Chunk, Reading, CITE, NOTE_ARG, REFCITE};
156use super::mark::{read_flags, report_mistakes, stage_dropped, MarkSettings};
157
158/// The name of the lowering rule of `\cite` on the recomposed LaTeX,
159/// `flm.citations.cite.lower.latex-recomposed`, whose body is
160/// [`CiteLatexRule`].
161pub const CITE_LATEX_RULE: &str = "flm.citations.cite.lower.latex-recomposed";
162
163/// The name of the lowering rule of `\R` on the recomposed LaTeX,
164/// `flm.citations.refcite.lower.latex-recomposed`, whose body is
165/// [`RefCiteLatexRule`].
166pub const REFCITE_LATEX_RULE: &str = "flm.citations.refcite.lower.latex-recomposed";
167
168/// The name of the feature's definition piece, `citations`, from which its
169/// identifier `flm.latex.def.citations` ([`PIECE`]) is derived.
170pub const PIECE_NAME: &str = "citations";
171
172/// The identifier of the feature's definition piece,
173/// `flm.latex.def.citations` ([`definition_piece`]), which the rules require
174/// when they write a hook.
175pub const PIECE: &str = "flm.latex.def.citations";
176
177/// The name of the LaTeX hook that each call of a citation chunk is written
178/// as, `flmCite`: `\flmCite[<note>]{<keys>}`.
179pub const CITE_COMMAND: &str = "flmCite";
180
181/// The name of the LaTeX hook written once before a citation chunk of
182/// `\cite` calls, `flmCitePreSpace`, which takes no argument.
183pub const PRE_SPACE_COMMAND: &str = "flmCitePreSpace";
184
185/// The name of the LaTeX hook that an `\R` is written as, `flmRefCite`:
186/// `\flmRefCite{<word>}{<citations>}`.
187pub const REF_CITE_COMMAND: &str = "flmRefCite";
188
189/// Returns the feature's definition piece, `flm.latex.def.citations`
190/// ([`LatexPreambleDef`]). It defines the three LaTeX hooks, each with
191/// `\ProvideDocumentCommand`: `\flmCite[<note>]{<keys>}` as LaTeX's `\cite`,
192/// `\flmCitePreSpace` as `\unskip~`, and `\flmRefCite{<word>}{<citations>}`
193/// as the word followed by the citations. It adds `\flmCite` to the LaTeX
194/// kernel's list of commands whose argument a change of case leaves
195/// unchanged, and makes a citation contribute nothing to a PDF bookmark. It
196/// requests no LaTeX package.
197///
198/// An author redefines a hook, before loading the style file or after it, to
199/// cite another way. See the [module
200/// documentation](self#the-definition-piece-of-the-hooks).
201pub fn definition_piece() -> LatexPreambleDef {
202 LatexPreambleDef::new(
203 PIECE_NAME,
204 "\
205% Citations, written as the document wrote them. The list of the cited works
206% is LaTeX's own (thebibliography, BibTeX, biblatex), built from your
207% database.
208% \\flmCite[<note>]{<keys>}: one citation, its keys as written, separated by
209% commas, and its note where it has one; by default LaTeX's \\cite. To show
210% the entries in place, redefine it, with biblatex's \\fullcite for instance.
211% \\flmCitePreSpace: written before citations attached to the text before
212% them; by default \\unskip~, a space that does not break. For superscript
213% citations, redefine it to \\unskip.
214% \\flmRefCite{<word>}{<citations>}: citations used as a noun of the sentence,
215% with the word written before them (refs.~, Refs.~, or nothing); by
216% default the word, then the citations.
217% A change of case (\\MakeUppercase) leaves the keys of \\flmCite unchanged and
218% changes its note, as it does for \\cite; as for \\cite, it protects the
219% first brace group after the command, so where the note holds one
220% ([{...}], \\emph{...}) the keys are changed too.
221\\ProvideDocumentCommand\\flmCite{o m}{\\IfValueTF{#1}{\\cite[{#1}]{#2}}{\\cite{#2}}}
222\\ProvideDocumentCommand\\flmCitePreSpace{}{\\unskip~}
223\\ProvideDocumentCommand\\flmRefCite{m m}{#1#2}
224% What a citation contributes to a PDF bookmark: nothing. The \\AtBeginDocument
225% block below runs when the document begins, so that it also applies where
226% hyperref is loaded after this file; it does nothing without hyperref.
227% \\flm@cite@bookmark, defined first, reads \\flmCite's optional note, if any,
228% then its keys, and writes nothing.
229\\def\\flm@cite@bookmark#1{\\ifx[#1\\expandafter\\flm@cite@bookmark@note\\fi}
230\\def\\flm@cite@bookmark@note#1]#2{}
231\\AtBeginDocument{\\ifdefined\\pdfstringdefDisableCommands
232 \\pdfstringdefDisableCommands{%
233 \\def\\flmCitePreSpace{}%
234 \\let\\flmCite\\flm@cite@bookmark
235 \\def\\flmRefCite#1#2{}%
236 }\\fi}
237\\ExplSyntaxOn
238\\tl_if_in:NnF \\l_text_case_exclude_arg_tl { \\flmCite } { \\tl_put_right:Nn \\l_text_case_exclude_arg_tl { \\flmCite } }
239\\ExplSyntaxOff
240",
241 "the LaTeX hooks of a citation: `\\flmCite[note]{keys}` (LaTeX's `\\cite` by default), \
242 `\\flmCitePreSpace` and `\\flmRefCite{word}{citations}`; a change of case leaves the \
243 keys of `\\flmCite` unchanged",
244 )
245}
246
247/// Stages the `\flmCite` calls of the citation chunk that `node` carries, one
248/// per call with at least one citation key, in order: the call's citation
249/// keys as a raw node, joined by commas, and its note, where it has content,
250/// as the optional argument. Returns them with the citation chunk as read.
251/// Every call's writing mistakes are reported, and the definition piece
252/// [`PIECE`] is required when at least one `\flmCite` is staged.
253///
254/// # Errors
255///
256/// [`LowerError::PlaceholderCharacters`] for citation keys that hold a
257/// placeholder of a user definition's template being lowered without
258/// expansion, and [`LowerError`] from staging.
259fn stage_calls<'t>(
260 cx: &mut LowerCx<'_>,
261 lw: &mut dyn Lowerer,
262 node: &NodeRef<'t, Flm>,
263) -> Result<(Vec<BuildId>, Chunk<'t>), LowerError> {
264 let mut all = Chunk::default();
265 let mut out = Vec::new();
266 for call in calls(node) {
267 let before = all.items.len();
268 read_call(&call, Reading::AtLowering, &mut all)?;
269 let keys: Vec<&str> = all.items[before..].iter().map(|item| item.key.as_str()).collect();
270 if keys.is_empty() {
271 continue;
272 }
273 let note: Vec<NodeRef<'t, Flm>> = match call.argument_content_nodes_named(NOTE_ARG) {
274 Ok(Some(content)) => content.iter().collect(),
275 _ => Vec::new(),
276 };
277 let mut shapes = Vec::with_capacity(2);
278 let mut slots = Vec::with_capacity(2);
279 if !note.is_empty() {
280 shapes.push(LatexArgShape::Optional);
281 slots.push((ARG_SLOT.to_string(), lower_run(cx, lw, ¬e)?));
282 }
283 let raw = LatexRawPayload::new(keys.join(","));
284 shapes.push(LatexArgShape::Mandatory);
285 slots.push((ARG_SLOT.to_string(), vec![lw.pres_with(cx, &ElementName::from(RAW), raw, Vec::new())?]));
286 out.push(lw.pres_slots_with(
287 cx,
288 &ElementName::from(MACRO),
289 LatexMacroPayload::new(CITE_COMMAND, shapes),
290 slots,
291 )?);
292 }
293 report_mistakes(lw, &all);
294 if !out.is_empty() {
295 lw.require(&Name::from(PIECE));
296 }
297 Ok((out, all))
298}
299
300/// Stages the LaTeX hook `\<name>`, which takes no argument.
301fn bare_hook(cx: &mut LowerCx<'_>, lw: &mut dyn Lowerer, name: &str) -> Result<BuildId, LowerError> {
302 lw.pres_slots_with(cx, &ElementName::from(MACRO), LatexMacroPayload::new(name, []), Vec::new())
303}
304
305/// The body of [`CITE_LATEX_RULE`]: it writes `\flmCitePreSpace`, then one
306/// `\flmCite` per call of the citation chunk; a dropped mark
307/// (`flm.pres.dropped`) where no call has a citation key. See the [module
308/// documentation](self).
309#[derive(Debug, Default, Clone, Copy)]
310pub struct CiteLatexRule;
311
312impl Lower for CiteLatexRule {
313 fn lower(
314 &self,
315 node: NodeRef<'_, Flm>,
316 cx: &mut LowerCx<'_>,
317 lw: &mut dyn Lowerer,
318 ) -> Result<Lowering, LowerError> {
319 let (cites, chunk) = stage_calls(cx, lw, &node)?;
320 if cites.is_empty() {
321 return Ok(Lowering::Emit(vec![stage_dropped(cx, lw, &chunk, false)?]));
322 }
323 let mut out = vec![bare_hook(cx, lw, PRE_SPACE_COMMAND)?];
324 out.extend(cites);
325 Ok(Lowering::Emit(out))
326 }
327}
328
329/// The body of [`REFCITE_LATEX_RULE`]: it writes `\flmRefCite` with the
330/// citation counter style's word (in the variant the flags select, singular
331/// or plural by how many items the citation chunk holds, a citation key
332/// written twice counted twice, empty under the flag `I`) and
333/// one `\flmCite` per call of the citation chunk; it writes no
334/// `\flmCitePreSpace`. An `\R` with no `\cite` directly after it is reported
335/// ([`NoCitation`]) and, like a citation chunk whose calls hold no citation
336/// key, written as a dropped mark (`flm.pres.dropped`). Unknown flags are
337/// reported as on every output ([`UnknownFlag`](super::UnknownFlag)). See the
338/// [module documentation](self).
339#[derive(Debug)]
340pub struct RefCiteLatexRule {
341 settings: Arc<MarkSettings>,
342}
343
344impl Lower for RefCiteLatexRule {
345 fn lower(
346 &self,
347 node: NodeRef<'_, Flm>,
348 cx: &mut LowerCx<'_>,
349 lw: &mut dyn Lowerer,
350 ) -> Result<Lowering, LowerError> {
351 let flags = read_flags(&node, lw)?;
352 if leading_call(&node).is_none() {
353 lw.error(NoCitation, node.span().clone());
354 }
355 let (cites, chunk) = stage_calls(cx, lw, &node)?;
356 if cites.is_empty() {
357 return Ok(Lowering::Emit(vec![stage_dropped(cx, lw, &chunk, false)?]));
358 }
359 let items = chunk.items.len();
360 let mut word = Vec::new();
361 if flags.word {
362 let variant = flags.capital.then_some(CAPITAL_VARIANT);
363 if let Some(text) = self.settings.style()?.word_text(items, variant) {
364 word = lw.splice(cx, text)?;
365 }
366 }
367 let hook = lw.pres_slots_with(
368 cx,
369 &ElementName::from(MACRO),
370 LatexMacroPayload::new(REF_CITE_COMMAND, [LatexArgShape::Mandatory, LatexArgShape::Mandatory]),
371 vec![(ARG_SLOT.to_string(), word), (ARG_SLOT.to_string(), cites)],
372 )?;
373 Ok(Lowering::Emit(vec![hook]))
374 }
375}
376
377/// The declaration of what the two rules of the recomposed LaTeX produce: the
378/// LaTeX family's macro and raw constructs, and the dropped mark.
379fn decl() -> LoweringDecl {
380 LoweringDecl::new().produces(MACRO).produces(RAW).produces(pres::DROPPED)
381}
382
383/// The rules of `\cite` ([`CITE_LATEX_RULE`]) and of `\R`
384/// ([`REFCITE_LATEX_RULE`]) on the recomposed LaTeX, marked as the defaults
385/// on the `latex-recomposed` backend only.
386pub(super) fn latex_rules(settings: &Arc<MarkSettings>) -> Vec<LoweringRule> {
387 vec![
388 LoweringRule::new(
389 CITE_LATEX_RULE,
390 CITE,
391 decl(),
392 Arc::new(CiteLatexRule),
393 DefaultMark::OnBackends(vec![BACKEND.into()]),
394 )
395 .docs(
396 "a citation chunk lowers to `\\flmCitePreSpace` and one `\\flmCite[note]{keys}` per \
397 call, the keys written unescaped",
398 ),
399 LoweringRule::new(
400 REFCITE_LATEX_RULE,
401 REFCITE,
402 decl(),
403 Arc::new(RefCiteLatexRule { settings: Arc::clone(settings) }),
404 DefaultMark::OnBackends(vec![BACKEND.into()]),
405 )
406 .docs(
407 "a citation chunk written with `\\R` lowers to `\\flmRefCite{word}{…}` holding the \
408 citation counter style's word and one `\\flmCite[note]{keys}` per call, with no \
409 `\\flmCitePreSpace`",
410 ),
411 ]
412}
413
414/// Registers the feature's part of the recomposed LaTeX: the peer
415/// declarations of the names the rules use that the LaTeX features own (the
416/// backend, the macro and raw constructs), the definition piece, contributed
417/// to the style file's service slot ([`preamble::SLOT`]), the rules of the
418/// list of cited works ([`ListNotWritten`]) and the rules of `\cite` and
419/// `\R`. The feature therefore builds in a registry without the LaTeX
420/// features, with these rules set aside.
421///
422/// # Errors
423///
424/// The [`BuildError`] of the registry builder when a declaration is made
425/// outside the round that takes it.
426pub(super) fn register(b: &mut FeatureBuilder<'_>, settings: &Arc<MarkSettings>) -> Result<(), BuildError> {
427 b.peer_backend(
428 BACKEND,
429 "the latex-recomposed backend, on which the citations feature's rules of the recomposed \
430 LaTeX are the defaults",
431 )?;
432 b.peer_element::<LatexMacroPayload>(
433 MACRO,
434 "the LaTeX family's macro-call construct, which the citations feature's rules stage for \
435 each LaTeX hook",
436 )?;
437 b.peer_element::<LatexRawPayload>(
438 RAW,
439 "the LaTeX family's raw construct, in which the citation keys of a call are written",
440 )?;
441 b.peer_slot::<LatexPreambleDef>(preamble::SLOT, Arc::new(definition_piece()))?;
442 register_list(b)?;
443 for rule in latex_rules(settings) {
444 b.lowering_rule(rule)?;
445 }
446 Ok(())
447}
448
449/// The body of the rules of the list of cited works and of its entries on the
450/// recomposed LaTeX: it writes nothing, because LaTeX writes its own list
451/// there. See the [module documentation](self#the-list-of-cited-works).
452#[derive(Debug, Default)]
453pub struct ListNotWritten;
454
455impl Lower for ListNotWritten {
456 fn lower(
457 &self,
458 _node: NodeRef<'_, Flm>,
459 _cx: &mut LowerCx<'_>,
460 _lw: &mut dyn Lowerer,
461 ) -> Result<Lowering, LowerError> {
462 Ok(Lowering::Emit(Vec::new()))
463 }
464}
465
466/// Registers [`ListNotWritten`] for the list element and its entry element,
467/// marked as the default on the `latex-recomposed` backend only.
468fn register_list(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
469 let rules = [
470 (BIBLIOGRAPHY, "flm.citations.bibliography.lower.latex-recomposed"),
471 (BIBLIOGRAPHY_ENTRY, "flm.citations.bibliography.entry.lower.latex-recomposed"),
472 ];
473 for (element, rule) in rules {
474 b.lowering_rule(
475 LoweringRule::new(
476 rule,
477 element,
478 LoweringDecl::new(),
479 Arc::new(ListNotWritten),
480 DefaultMark::OnBackends(vec![BACKEND.into()]),
481 )
482 .docs(
483 "on the recomposed LaTeX, nothing is written for the list of the cited works: \
484 LaTeX writes its own",
485 ),
486 )?;
487 }
488 Ok(())
489}
490
491#[cfg(test)]
492mod tests {
493 use super::*;
494 use crate::stdlib::backends::latex::preamble::piece_id;
495
496 #[test]
497 fn the_piece_is_named_as_its_identifier_says_and_requests_no_package() {
498 let piece = definition_piece();
499 assert_eq!(piece.id, piece_id(PIECE_NAME));
500 assert_eq!(piece.id.as_str(), PIECE);
501 assert!(piece.requires.is_empty());
502 for hook in [CITE_COMMAND, PRE_SPACE_COMMAND, REF_CITE_COMMAND] {
503 assert!(piece.content.contains(&format!("\\ProvideDocumentCommand\\{hook}{{")), "{hook}");
504 }
505 assert!(piece.content.contains("\\tl_put_right:Nn \\l_text_case_exclude_arg_tl { \\flmCite }"));
506 // Nothing of a citation stands in a PDF bookmark, the word of
507 // `\flmRefCite` included.
508 for line in ["\\def\\flmCitePreSpace{}%", "\\let\\flmCite\\flm@cite@bookmark", "\\def\\flmRefCite#1#2{}%"] {
509 assert!(piece.content.contains(line), "{line}");
510 }
511 }
512}