Add abstract quotations, unnumbered paragraphs, and author-year citations

This commit is contained in:
gloamxun committed 2026-10-19 15:39:02 +08:00
1 parent 3406f84e86
commit 7f1f202de1
11 files changed
+366 -60

No files matched your search

+32 -4
View File
@@ -501,6 +501,7 @@ struct Parser {
suppress_indent: bool,
paragraph_alignment: ParagraphAlignment,
alignment_saves: Vec<ParagraphAlignment>,
in_abstract: bool,
}
impl Parser {
@@ -551,6 +552,7 @@ impl Parser {
suppress_indent: false,
paragraph_alignment: ParagraphAlignment::Justified,
alignment_saves: Vec::new(),
in_abstract: false,
}
}
@@ -945,6 +947,7 @@ impl Parser {
expanded::FrontendEventKind::PackageLoaded(package) => {
if package == "arxiv" {
self.document.title_style = TitleStyle::Preprint;
self.document.author_year_citations = true;
if self.document.undertitle.is_none() {
self.document.undertitle = Some("A Preprint".to_string());
}
@@ -1263,13 +1266,29 @@ impl Parser {
self.append_reference(UnresolvedReference::Label(key.clone()))
}
expanded::FrontendEventKind::Citation(keys) => {
self.append_reference(UnresolvedReference::Citation(
keys.split(',').map(str::trim).map(str::to_string).collect(),
))
let (keys, textual) = match keys.strip_prefix("@text:") {
Some(keys) => (keys, true),
None => (keys.as_str(), false),
};
let keys = keys.split(',').map(str::trim).map(str::to_string).collect();
self.append_reference(if textual {
UnresolvedReference::TextualCitation(keys)
} else {
UnresolvedReference::Citation(keys)
})
}
expanded::FrontendEventKind::BibliographyItem(key) => {
self.start_bibliography_item(key.clone())
}
expanded::FrontendEventKind::BibliographyMetadata { key, author, year } => {
self.document.citation_metadata.insert(
key.clone(),
crate::document::CitationMetadata {
author: author.clone(),
year: year.clone(),
},
);
}
expanded::FrontendEventKind::IncludeGraphics { options, path } => {
self.add_image(path.clone(), options.clone())
}
@@ -1864,6 +1883,11 @@ impl Parser {
&& let Some(first) = runs.first_mut()
{
first.alignment = Some(self.paragraph_alignment);
} else if self.in_abstract
&& runs.first().is_some_and(|run| run.alignment.is_none())
&& let Some(first) = runs.first_mut()
{
first.alignment = Some(ParagraphAlignment::Quote);
}
prepend_paragraph_indent(&mut runs, indent);
let source = self.paragraph_source.take();
@@ -1962,8 +1986,12 @@ impl Parser {
self.push_block(Block::Centered {
runs: vec![heading],
});
self.in_abstract = true;
}
(false, "abstract") => {
self.flush_paragraph();
self.in_abstract = false;
}
(false, "abstract") => self.flush_paragraph(),
(true, "raggedright") => {
self.flush_paragraph();
self.alignment_saves.push(self.paragraph_alignment);