Skip to main content

Module bibliography

Module bibliography 

Source
Expand description

Lower #bibliography(...) directives into a semantic node.

This is the source boundary only (manifest ยง4, MVP 4): the directive declares one bibliography database path, which is resolved relative to the current .mos source file and stashed on a [NodeKind::Bibliography] node. After lowering, citation keys are checked against the parsed BibTeX records from those declared sources, resolved citations get numeric [N] markers, and the first bibliography node receives one rendered entry child per cited key in first-use order (numeric slice only; CSL styles are a later slice).

Diagnostics:

  • MOS0040: #bibliography(...) called without a (non-empty) path.
  • MOS0042: #bibliography(...) declared more than one path; first wins.
  • MOS0020: the path argument is present but not a string.
  • MOS0015: an unknown keyword argument was supplied.
  • MOS0041: the resolved path does not point to a file on disk, or is not valid UTF-8 (a warning; the node is still emitted, with resolved_path only in the first case, so an unloadable source counts as incomplete).
  • MOS0045: a citation key does not exist in a complete parsed bibliography set.
  • MOS0046: a citation key appears in more than one declared bibliography source.

Structsยง

BibliographyOrigin ๐Ÿ”’
LoadedBibliography ๐Ÿ”’

Constantsยง

BIBLIOGRAPHY_KEYS ๐Ÿ”’
Named keys accepted by bibliography_path; the MOS0015 nearest-match candidate set. Keep in sync with the match arms.

Functionsยง

append_bibliography_entries ๐Ÿ”’
Append one rendered entry per cited key as children of the first [NodeKind::Bibliography] node, ordered by first-use citation number.
bibliography_path ๐Ÿ”’
Pull the single source path out of the directive arguments. A leading positional string (#bibliography("refs.bib")) or the named path:/src: forms are accepted, mirroring #image(...). Returns None (after emitting a diagnostic) when the path is missing, empty, or not a string.
citation_key_span ๐Ÿ”’
clean_field ๐Ÿ”’
Strip BibTeX brace protection and collapse runs of whitespace, so field values like {The {TeX}book} render as The TeXbook.
format_entry ๐Ÿ”’
Render one BibTeX entry as plain text for the bibliography list.
is_citation_key ๐Ÿ”’
load_bibliography ๐Ÿ”’
lower_bibliography_directive ๐Ÿ”’
Lower #bibliography("refs.bib") into a bibliography node.
nearest_citation_key ๐Ÿ”’
The single loaded citation key that is a conservative near-miss for unknown, if any. Candidate filtering stays here (is_citation_key); the selection rule (length floor, len / 3 bound, ties suggest nothing) lives in crate::suggest::nearest_match.
resolve_citations ๐Ÿ”’
Resolve citation keys against the already-loaded bibliography sources.