Polish preprint title details and plainnat bibliography formatting
This commit is contained in:
1 parent
7f1f202de1
commit
d211889e93
8 files changed
+120
-11
No files matched your search
@@ -377,8 +377,9 @@ author/editor, title, journal, booktitle, volume, number, pages, publisher,
|
|||||||
institution, school, organization, edition, address, month, note, and year fields.
|
institution, school, organization, edition, address, month, note, and year fields.
|
||||||
BibTeX `@string` macros and single-level `crossref` inheritance are supported.
|
BibTeX `@string` macros and single-level `crossref` inheritance are supported.
|
||||||
Manual `thebibliography` entries also work. Documents loading `natbib` or
|
Manual `thebibliography` entries also work. Documents loading `natbib` or
|
||||||
`arxiv.sty` render `\citet`/`\citep` as author-year citations and omit numeric
|
`arxiv.sty` render `\citet`/`\citep` as author-year citations, format `.bib`
|
||||||
bibliography labels; other documents keep numeric citations. Custom `.bst`
|
entries in plainnat order (`First Last`, `In ...`, `pages`, publisher/year),
|
||||||
|
and omit numeric bibliography labels; other documents keep numeric citations. Custom `.bst`
|
||||||
sorting/formatting and page-number references (`\pageref`) are not implemented.
|
sorting/formatting and page-number references (`\pageref`) are not implemented.
|
||||||
|
|
||||||
A paragraph starts with the current `\parindent` (17pt by default); the
|
A paragraph starts with the current `\parindent` (17pt by default); the
|
||||||
|
|||||||
@@ -1983,6 +1983,7 @@ impl Parser {
|
|||||||
self.flush_paragraph();
|
self.flush_paragraph();
|
||||||
let mut heading = Run::plain("Abstract".to_string());
|
let mut heading = Run::plain("Abstract".to_string());
|
||||||
heading.bold = true;
|
heading.bold = true;
|
||||||
|
heading.small_caps = true;
|
||||||
self.push_block(Block::Centered {
|
self.push_block(Block::Centered {
|
||||||
runs: vec![heading],
|
runs: vec![heading],
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ contents and figure/table lists with dotted leaders; native PDF rectangles; unif
|
|||||||
chapter headings with chapter-prefixed section numbering and page breaks;
|
chapter headings with chapter-prefixed section numbering and page breaks;
|
||||||
deferred top-float queue for figures; document-level custom `\maketitle`;
|
deferred top-float queue for figures; document-level custom `\maketitle`;
|
||||||
abstract quotation formatting, unnumbered `\paragraph` headings, natbib-style
|
abstract quotation formatting, unnumbered `\paragraph` headings, natbib-style
|
||||||
author-year citations;
|
author-year citations and plainnat bibliography formatting;
|
||||||
`\vbox`/`\vtop` vertical-material capture with inline splicing
|
`\vbox`/`\vtop` vertical-material capture with inline splicing
|
||||||
(`build_positioned_pages` is the only page builder and no separate break
|
(`build_positioned_pages` is the only page builder and no separate break
|
||||||
planner remains).
|
planner remains).
|
||||||
|
|||||||
+7
-1
@@ -66,7 +66,9 @@ the source changes; the SVG preview is refreshed per page.
|
|||||||
`\hspace*`, skips), text symbols/letters/punctuation, break advisories,
|
`\hspace*`, skips), text symbols/letters/punctuation, break advisories,
|
||||||
metadata, `\paragraph` run-in headings, citations/references, tables/lists/images.
|
metadata, `\paragraph` run-in headings, citations/references, tables/lists/images.
|
||||||
- Citations: numeric citations by default; `natbib`/`arxiv.sty` selects author-year
|
- Citations: numeric citations by default; `natbib`/`arxiv.sty` selects author-year
|
||||||
`\citet`/`\citep` from `.bib` metadata and drops numeric bibliography labels.
|
`\citet`/`\citep` from `.bib` metadata, formats bibliography entries in
|
||||||
|
plainnat order (`First Last`, `In ...`, `pages`, publisher/year), and drops
|
||||||
|
numeric bibliography labels.
|
||||||
- Live preview: paragraph cache, page-hash diffing, warm rebuilds in the low
|
- Live preview: paragraph cache, page-hash diffing, warm rebuilds in the low
|
||||||
milliseconds for small edits.
|
milliseconds for small edits.
|
||||||
|
|
||||||
@@ -90,6 +92,10 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
|||||||
the next page.
|
the next page.
|
||||||
- Contents: chapter headings are listed with chapter-prefixed section
|
- Contents: chapter headings are listed with chapter-prefixed section
|
||||||
numbers, but contents are not split per chapter.
|
numbers, but contents are not split per chapter.
|
||||||
|
- Preprint title blocks: ORCID icons embedded in `\author` are dropped because
|
||||||
|
metadata does not carry PDF images, and links/URLs remain plain black text
|
||||||
|
instead of colored hyperref links. Title-block vertical spacing is tighter
|
||||||
|
than the reference class.
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
|
|||||||
+87
-1
@@ -889,6 +889,25 @@ fn source_directory(file_name: &str) -> &Path {
|
|||||||
.unwrap_or_else(|| Path::new("."))
|
.unwrap_or_else(|| Path::new("."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn natbib_author_list(author: &str) -> String {
|
||||||
|
let names = author
|
||||||
|
.split(" and ")
|
||||||
|
.map(|name| {
|
||||||
|
let name = name.trim();
|
||||||
|
match name.split_once(',') {
|
||||||
|
Some((last, first)) => format!("{} {}", first.trim(), last.trim()),
|
||||||
|
None => name.to_string(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
match names.as_slice() {
|
||||||
|
[] => String::new(),
|
||||||
|
[only] => only.clone(),
|
||||||
|
[first, second] => format!("{first} and {second}"),
|
||||||
|
[rest @ .., last] => format!("{}, and {last}", rest.join(", ")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct BibEntry {
|
struct BibEntry {
|
||||||
kind: String,
|
kind: String,
|
||||||
key: String,
|
key: String,
|
||||||
@@ -896,7 +915,10 @@ struct BibEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BibEntry {
|
impl BibEntry {
|
||||||
fn to_latex(&self) -> String {
|
fn to_latex(&self, author_year: bool) -> String {
|
||||||
|
if author_year {
|
||||||
|
return self.natbib_latex();
|
||||||
|
}
|
||||||
let field = |name: &str| self.fields.get(name).map(String::as_str).unwrap_or("");
|
let field = |name: &str| self.fields.get(name).map(String::as_str).unwrap_or("");
|
||||||
let mut parts = Vec::new();
|
let mut parts = Vec::new();
|
||||||
let author = field("author");
|
let author = field("author");
|
||||||
@@ -964,6 +986,70 @@ impl BibEntry {
|
|||||||
}
|
}
|
||||||
escape_bib_text(&parts.join(" "))
|
escape_bib_text(&parts.join(" "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// plainnat/author-year layout used by `natbib` and the arXiv class.
|
||||||
|
fn natbib_latex(&self) -> String {
|
||||||
|
let field = |name: &str| self.fields.get(name).map(String::as_str).unwrap_or("");
|
||||||
|
let authors = if !field("author").is_empty() {
|
||||||
|
natbib_author_list(field("author"))
|
||||||
|
} else if !field("editor").is_empty() {
|
||||||
|
format!("{} (ed.)", field("editor"))
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
let mut output = String::new();
|
||||||
|
if !authors.is_empty() {
|
||||||
|
output.push_str(&authors);
|
||||||
|
output.push_str(". ");
|
||||||
|
}
|
||||||
|
let title = field("title");
|
||||||
|
if !title.is_empty() {
|
||||||
|
output.push_str(title);
|
||||||
|
output.push_str(". ");
|
||||||
|
}
|
||||||
|
let mut tail = Vec::new();
|
||||||
|
let booktitle = field("booktitle");
|
||||||
|
if !booktitle.is_empty() {
|
||||||
|
tail.push(format!("In \\emph{{{booktitle}}}"));
|
||||||
|
} else if !field("journal").is_empty() {
|
||||||
|
tail.push(format!("\\emph{{{}}}", field("journal")));
|
||||||
|
}
|
||||||
|
if !field("volume").is_empty() {
|
||||||
|
let mut volume = field("volume").to_string();
|
||||||
|
if !field("number").is_empty() {
|
||||||
|
volume.push_str(&format!("({})", field("number")));
|
||||||
|
}
|
||||||
|
tail.push(volume);
|
||||||
|
}
|
||||||
|
if !field("pages").is_empty() {
|
||||||
|
tail.push(format!(
|
||||||
|
"pages {}",
|
||||||
|
field("pages").replace("--", "\u{2013}")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if !tail.is_empty() {
|
||||||
|
output.push_str(&tail.join(", "));
|
||||||
|
output.push_str(", ");
|
||||||
|
}
|
||||||
|
let publisher = if field("publisher").is_empty() {
|
||||||
|
field("organization")
|
||||||
|
} else {
|
||||||
|
field("publisher")
|
||||||
|
};
|
||||||
|
let year = field("year");
|
||||||
|
match (publisher.is_empty(), year.is_empty()) {
|
||||||
|
(false, false) => output.push_str(&format!("{publisher}, {year}.")),
|
||||||
|
(false, true) => output.push_str(&format!("{publisher}.")),
|
||||||
|
(true, false) => output.push_str(&format!("{year}.")),
|
||||||
|
(true, true) => {
|
||||||
|
if output.ends_with(", ") {
|
||||||
|
output.truncate(output.len() - 2);
|
||||||
|
output.push('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
escape_bib_text(output.trim())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape_bib_text(source: &str) -> String {
|
fn escape_bib_text(source: &str) -> String {
|
||||||
|
|||||||
@@ -453,8 +453,8 @@ const PRELUDE: &str = r#"
|
|||||||
\def\And{\texrraauthorseparator}
|
\def\And{\texrraauthorseparator}
|
||||||
\def\AND{\texrraauthorseparator}
|
\def\AND{\texrraauthorseparator}
|
||||||
\def\ifhmode{\iftrue}
|
\def\ifhmode{\iftrue}
|
||||||
\def\paragraph#1{\par\texrraunnumberedheadingstart{3}#1\texrraheadingend\par}
|
\def\paragraph#1{\par\noindent{\bfseries #1}\hspace{1em}}
|
||||||
\def\subparagraph#1{\par\texrraunnumberedheadingstart{3}#1\texrraheadingend\par}
|
\def\subparagraph#1{\par\noindent{\itshape #1}\hspace{1em}}
|
||||||
\def\@startsection#1#2#3#4#5#6#7{\par\texrraheadingstart{#2}#7\texrraheadingend\par}
|
\def\@startsection#1#2#3#4#5#6#7{\par\texrraheadingstart{#2}#7\texrraheadingend\par}
|
||||||
\def\setlength#1#2{#1=#2\relax}
|
\def\setlength#1#2{#1=#2\relax}
|
||||||
\def\addtolength#1#2{\advance#1#2\relax}
|
\def\addtolength#1#2{\advance#1#2\relax}
|
||||||
|
|||||||
@@ -530,6 +530,10 @@ struct CompilerState {
|
|||||||
pending_page_decorations: Vec<PendingPageDecoration>,
|
pending_page_decorations: Vec<PendingPageDecoration>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
document_started: bool,
|
document_started: bool,
|
||||||
|
/// True when `natbib` (or a class that loads it) is active; controls
|
||||||
|
/// author-year bibliography formatting and citations.
|
||||||
|
#[serde(default)]
|
||||||
|
author_year_bibliography: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PendingPageDecoration {
|
struct PendingPageDecoration {
|
||||||
@@ -4352,6 +4356,7 @@ fn load_document_class(
|
|||||||
token,
|
token,
|
||||||
FrontendEventKind::PackageLoaded(class.clone()),
|
FrontendEventKind::PackageLoaded(class.clone()),
|
||||||
);
|
);
|
||||||
|
input.state_mut().author_year_bibliography |= matches!(class.as_str(), "natbib" | "arxiv");
|
||||||
SourceDependency::record(
|
SourceDependency::record(
|
||||||
&mut input.state_mut().dependencies.borrow_mut(),
|
&mut input.state_mut().dependencies.borrow_mut(),
|
||||||
&path,
|
&path,
|
||||||
@@ -4647,6 +4652,7 @@ fn use_package(
|
|||||||
token,
|
token,
|
||||||
FrontendEventKind::PackageLoaded(package.clone()),
|
FrontendEventKind::PackageLoaded(package.clone()),
|
||||||
);
|
);
|
||||||
|
input.state_mut().author_year_bibliography |= matches!(package.as_str(), "natbib" | "arxiv");
|
||||||
SourceDependency::record(
|
SourceDependency::record(
|
||||||
&mut input.state_mut().dependencies.borrow_mut(),
|
&mut input.state_mut().dependencies.borrow_mut(),
|
||||||
&path,
|
&path,
|
||||||
@@ -6215,6 +6221,7 @@ fn bibliography_primitive(
|
|||||||
}
|
}
|
||||||
.map_err(|message| input.fatal_error(error::SimpleTokenError::new(token, message)))?;
|
.map_err(|message| input.fatal_error(error::SimpleTokenError::new(token, message)))?;
|
||||||
|
|
||||||
|
let author_year = input.state().author_year_bibliography;
|
||||||
let mut source = String::from("\\begin{thebibliography}{9}");
|
let mut source = String::from("\\begin{thebibliography}{9}");
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
source.push_str("\\texrrabibmeta{");
|
source.push_str("\\texrrabibmeta{");
|
||||||
@@ -6226,7 +6233,7 @@ fn bibliography_primitive(
|
|||||||
source.push_str("}\\bibitem{");
|
source.push_str("}\\bibitem{");
|
||||||
source.push_str(&entry.key);
|
source.push_str(&entry.key);
|
||||||
source.push('}');
|
source.push('}');
|
||||||
source.push_str(&entry.to_latex());
|
source.push_str(&entry.to_latex(author_year));
|
||||||
}
|
}
|
||||||
source.push_str("\\end{thebibliography}");
|
source.push_str("\\end{thebibliography}");
|
||||||
let generated = lex_generated_tex(input, &source, token)?;
|
let generated = lex_generated_tex(input, &source, token)?;
|
||||||
|
|||||||
+11
-3
@@ -999,7 +999,7 @@ Body.
|
|||||||
let value: serde_json::Value = serde_json::from_str(&preview).expect("preview JSON");
|
let value: serde_json::Value = serde_json::from_str(&preview).expect("preview JSON");
|
||||||
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||||
assert!(
|
assert!(
|
||||||
svg.contains(">Abstract</text>"),
|
svg.contains(">BSTRACT</text>"),
|
||||||
"missing abstract heading: {svg}"
|
"missing abstract heading: {svg}"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1218,8 +1218,16 @@ fn natbib_citations_use_author_year() {
|
|||||||
"numeric citation was not replaced: {second}"
|
"numeric citation was not replaced: {second}"
|
||||||
);
|
);
|
||||||
let third = page_svg(&value, 2);
|
let third = page_svg(&value, 2);
|
||||||
|
let george = third.find("Geor").expect("bibliography given name missing");
|
||||||
|
let kour = third
|
||||||
|
.find(">Kour</text>")
|
||||||
|
.expect("bibliography family name missing");
|
||||||
assert!(
|
assert!(
|
||||||
third.contains(">Kour</text>"),
|
george < kour,
|
||||||
"bibliography entry missing: {third}"
|
"bibliography should render given name before family name: {third}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!third.contains(">[1]</text>"),
|
||||||
|
"author-year bibliography should omit numeric labels: {third}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user