Capture corresponding authors and class metadata cleanly
This commit is contained in:
1 parent
5fd5f92bb4
commit
06cc88809e
5 files changed
+40
-8
No files matched your search
@@ -75,6 +75,8 @@ pub struct AuthorBlock {
|
||||
/// One-based affiliation indices attached to this author.
|
||||
pub affiliations: Vec<usize>,
|
||||
pub email: Option<String>,
|
||||
/// Author marked with `*` (corresponding author).
|
||||
pub corresponding: bool,
|
||||
}
|
||||
|
||||
/// One numbered affiliation in a structured front matter.
|
||||
|
||||
@@ -480,6 +480,7 @@ struct Parser {
|
||||
metadata_capture: Option<(expanded::MetadataField, Vec<Run>)>,
|
||||
author_affiliations: Vec<usize>,
|
||||
pending_author_email: Option<String>,
|
||||
pending_author_corresponding: bool,
|
||||
email_capture: Option<Vec<Run>>,
|
||||
affiliation_capture: Option<(usize, Vec<Run>)>,
|
||||
abstract_capture: Option<Vec<Run>>,
|
||||
@@ -598,6 +599,7 @@ impl Parser {
|
||||
metadata_capture: None,
|
||||
author_affiliations: Vec::new(),
|
||||
pending_author_email: None,
|
||||
pending_author_corresponding: false,
|
||||
email_capture: None,
|
||||
affiliation_capture: None,
|
||||
abstract_capture: None,
|
||||
@@ -803,10 +805,12 @@ impl Parser {
|
||||
self.document.author = value;
|
||||
let affiliations = std::mem::take(&mut self.author_affiliations);
|
||||
let email = self.pending_author_email.take();
|
||||
let corresponding = std::mem::take(&mut self.pending_author_corresponding);
|
||||
self.document.authors.push(crate::document::AuthorBlock {
|
||||
runs,
|
||||
affiliations,
|
||||
email,
|
||||
corresponding,
|
||||
});
|
||||
}
|
||||
expanded::MetadataField::Date => self.document.date = value,
|
||||
@@ -1063,11 +1067,18 @@ impl Parser {
|
||||
expanded::FrontendEventKind::MetadataEmailStart => {
|
||||
self.email_capture = Some(Vec::new());
|
||||
}
|
||||
expanded::FrontendEventKind::MetadataAuthorCorresponding => {
|
||||
self.pending_author_corresponding = true;
|
||||
}
|
||||
expanded::FrontendEventKind::MetadataEmailEnd => {
|
||||
if let Some(mut runs) = self.email_capture.take() {
|
||||
trim_run_end(&mut runs);
|
||||
let email = runs.iter().map(|run| run.text.as_str()).collect::<String>();
|
||||
self.pending_author_email = Some(email);
|
||||
if let Some(author) = self.document.authors.last_mut() {
|
||||
author.email = Some(email);
|
||||
} else {
|
||||
self.pending_author_email = Some(email);
|
||||
}
|
||||
}
|
||||
}
|
||||
expanded::FrontendEventKind::AffiliationStart(index) => {
|
||||
|
||||
@@ -292,6 +292,7 @@ pub enum FrontendEventKind {
|
||||
KeywordsEnd,
|
||||
/// Start/end of the e-mail address inside an author block.
|
||||
MetadataEmailStart,
|
||||
MetadataAuthorCorresponding,
|
||||
MetadataEmailEnd,
|
||||
ParagraphAlignment(crate::document::ParagraphAlignment),
|
||||
TableOfContents,
|
||||
|
||||
@@ -1857,12 +1857,15 @@ pub(super) fn build_positioned_pages(
|
||||
let mut author_emails = Vec::new();
|
||||
for author in &model.authors {
|
||||
let mut runs = author.runs.clone();
|
||||
if !author.affiliations.is_empty() {
|
||||
let marks = author
|
||||
if !author.affiliations.is_empty() || author.corresponding {
|
||||
let mut marks = author
|
||||
.affiliations
|
||||
.iter()
|
||||
.map(|index| superscript(*index))
|
||||
.collect::<String>();
|
||||
if author.corresponding {
|
||||
marks.push('*');
|
||||
}
|
||||
runs.push(Run::plain(marks));
|
||||
}
|
||||
for line in measure_positioned_lines(
|
||||
@@ -1928,8 +1931,15 @@ pub(super) fn build_positioned_pages(
|
||||
}
|
||||
|
||||
if !author_emails.is_empty() {
|
||||
let email_runs =
|
||||
vec![Run::plain(format!("E-mail: {}", author_emails.join("; ")))];
|
||||
let corresponding = model.authors.iter().any(|author| author.corresponding);
|
||||
let email_runs = vec![Run::plain(if corresponding {
|
||||
format!(
|
||||
"*Corresponding author(s). E-mail(s): {}",
|
||||
author_emails.join("; ")
|
||||
)
|
||||
} else {
|
||||
format!("E-mail: {}", author_emails.join("; "))
|
||||
})];
|
||||
for line in measure_positioned_lines(
|
||||
&email_runs,
|
||||
base_font_size.saturating_sub(1).max(1),
|
||||
|
||||
@@ -2224,7 +2224,9 @@ fn author_frontmatter_primitive(
|
||||
input: &mut vm::ExecutionInput<CompilerState>,
|
||||
) -> texlang::prelude::Result<()> {
|
||||
if let Some(next) = input.unexpanded().next()? {
|
||||
if !matches!(next.value(), token::Value::Other('*')) {
|
||||
if matches!(next.value(), token::Value::Other('*')) {
|
||||
write_event(input, token, FrontendEventKind::MetadataAuthorCorresponding);
|
||||
} else {
|
||||
input.unexpanded().back(next);
|
||||
}
|
||||
}
|
||||
@@ -2250,8 +2252,14 @@ fn author_frontmatter_primitive(
|
||||
fn skip_optional_bracket(
|
||||
input: &mut vm::ExecutionInput<CompilerState>,
|
||||
) -> texlang::prelude::Result<()> {
|
||||
let Some(first) = input.unexpanded().next()? else {
|
||||
return Ok(());
|
||||
let first = loop {
|
||||
let Some(next) = input.unexpanded().next()? else {
|
||||
return Ok(());
|
||||
};
|
||||
if matches!(next.value(), token::Value::Space(_)) {
|
||||
continue;
|
||||
}
|
||||
break next;
|
||||
};
|
||||
if !matches!(first.value(), token::Value::Other('[')) {
|
||||
input.unexpanded().back(first);
|
||||
|
||||
Reference in new issue
Block a user