Render arxiv-style preprint title blocks

This commit is contained in:
gloamxun committed 2026-10-19 15:23:13 +08:00
1 parent 8d5cbc69ba
commit 4991bdfcfc
12 files changed
+559 -77

No files matched your search

+16
View File
@@ -55,6 +55,16 @@ impl Default for PageSize {
}
}
/// Layout style for the document title block.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum TitleStyle {
/// The generic article title: title, author, date, no rules.
#[default]
Article,
/// Preprint-style title block with rules, an undertitle, and author columns.
Preprint,
}
#[derive(Clone)]
pub struct Footnote {
pub number: u32,
@@ -66,6 +76,10 @@ pub struct DocumentModel {
pub title: String,
pub author: String,
pub date: String,
/// Style selected by the document's class/package layer.
pub title_style: TitleStyle,
/// Optional line printed under the title rules, e.g. "A Preprint".
pub undertitle: Option<String>,
pub page: PageSize,
pub parindent: common::Scaled,
/// Base font size selected by the document class (10, 11, or 12pt).
@@ -87,6 +101,8 @@ impl Default for DocumentModel {
title: String::new(),
author: String::new(),
date: String::new(),
title_style: TitleStyle::default(),
undertitle: None,
page: PageSize::default(),
// article's default \parindent for 10/11pt text.
parindent: common::Scaled(17 * 65_536),
+46 -3
View File
@@ -4,8 +4,8 @@ use crate::{
TeXGlue, TeXGlueOrder,
document::{
Block, ColumnAlignment, DocumentModel, EquationNumber, InlineBox, InlineBoxAlign,
ListBlock, ListItem, PageMargins, PageSize, PageStyleOverride, ParagraphAlignment,
ParsedDocument, RuleBox, Run, UnresolvedReference,
ListBlock, ListItem, PageMargins, PageSize, PageStyleKind, PageStyleOverride,
ParagraphAlignment, ParsedDocument, RuleBox, Run, TitleStyle, UnresolvedReference,
},
expanded,
math_expr::*,
@@ -942,6 +942,30 @@ impl Parser {
expanded::FrontendEventKind::MetadataEnd(field) => {
self.finish_metadata(*field);
}
expanded::FrontendEventKind::PackageLoaded(package) => {
if package == "arxiv" {
self.document.title_style = TitleStyle::Preprint;
if self.document.undertitle.is_none() {
self.document.undertitle = Some("A Preprint".to_string());
}
if !self
.document
.page_style_overrides
.iter()
.any(|override_| override_.anchor == 0)
{
self.document.page_style_overrides.push(PageStyleOverride {
anchor: 0,
kind: PageStyleKind::Empty,
});
}
}
}
expanded::FrontendEventKind::MetadataSeparator => {
if self.metadata_capture.is_some() {
self.append_text("\u{F7001}");
}
}
expanded::FrontendEventKind::Geometry(settings) => {
apply_class_font_size(&mut self.document, settings);
apply_geometry(&mut self.document, settings);
@@ -1067,10 +1091,18 @@ impl Parser {
expanded::FrontendEventKind::LiteralCharacter(character) => {
self.append_text(&character.to_string())
}
expanded::FrontendEventKind::LineBreak => self.append_text(" "),
expanded::FrontendEventKind::LineBreak => {
if self.metadata_capture.is_some() {
self.append_metadata_line_break();
} else {
self.append_text(" ");
}
}
expanded::FrontendEventKind::RowBreak => {
if self.table.is_some() {
self.finish_table_row();
} else if self.metadata_capture.is_some() {
self.append_metadata_line_break();
} else {
self.append_text(" ");
}
@@ -1339,6 +1371,17 @@ impl Parser {
}
}
fn append_metadata_line_break(&mut self) {
let Some((_, runs)) = &mut self.metadata_capture else {
return;
};
if let Some(last) = runs.last_mut() {
last.text.push('\n');
} else {
runs.push(Run::plain("\n".to_string()));
}
}
fn append_text(&mut self, text: &str) {
if normalize_whitespace(text).is_empty() {
return;
+4
View File
@@ -248,6 +248,10 @@ pub enum FrontendEventKind {
header: bool,
},
PageNumber,
/// A package or class was loaded from a local file.
PackageLoaded(String),
/// A separator between author blocks (LaTeX's \And).
MetadataSeparator,
ParagraphAlignment(crate::document::ParagraphAlignment),
TableOfContents,
ListOfFigures,