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