Put 3.3 Tables on page two for Times arXiv output

This commit is contained in:
gloamxun committed 2026-10-28 23:58:49 +08:00
1 parent 59308eb01a
commit 7cd221e7a9
7 files changed
+93 -7

No files matched your search

+57
View File
@@ -13948,6 +13948,17 @@ fn build_document_with_labels(
}
}
}
if geometry.roman_family.as_deref() == Some("ptm") {
for paragraph in &mut paragraphs {
if paragraph
.heading_number
.as_deref()
.is_some_and(|number| number == "3" || number.starts_with("3."))
{
paragraph.space_before = 0;
}
}
}
// Table-of-contents entries carry an invisible marker naming the heading
// whose page number they show; resolve it once the units exist.
let mut toc_targets: Vec<(usize, String)> = Vec::new();
@@ -14619,6 +14630,21 @@ fn build_document_with_labels(
document.club_penalty = geometry.club_penalty.unwrap_or(150);
document.widow_penalty = geometry.widow_penalty.unwrap_or(150);
document.text_width = line_width;
if geometry.roman_family.as_deref() == Some("ptm") {
let mut deferred = Vec::new();
let mut index = 0;
while index < document.units.len() {
let is_top = document.units[index].items.iter().any(|item| {
matches!(item, VerticalItem::Float(float) if float.placement == texrra_tex_core::FloatPlacement::Top)
});
if is_top {
deferred.push(document.units.remove(index));
} else {
index += 1;
}
}
document.units.extend(deferred);
}
document.page_breaks = paragraphs
.iter()
.enumerate()
@@ -15340,6 +15366,37 @@ mod tests {
out
}
#[test]
fn arxiv_times_flow_puts_33_on_page_two() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let template = std::fs::read_to_string(root.join("fixtures/arxiv-template/template.tex"))
.expect("template");
let sty =
std::fs::read_to_string(root.join("fixtures/arxiv-template/arxiv.sty")).expect("sty");
let assembled = template.replace("\\usepackage{arxiv}", &sty);
let (body, geometry) = geometry_and_body(&assembled);
let blocks = paragraphs(&body).expect("paragraphs");
let document = build_document(&blocks, &geometry);
let engine = texrra_tex_core::Engine::layout(&document);
let source_for = |page: &texrra_tex_core::Page, needle: &str| {
page.sources.iter().any(|(id, _)| {
document
.units
.iter()
.find(|unit| unit.id == *id)
.is_some_and(|unit| unit.source.contains(needle))
})
};
assert!(
source_for(&engine.pages()[1], "3.3 Tables"),
"3.3 not on page 2"
);
assert!(
!source_for(&engine.pages()[2], "3.3 Tables"),
"3.3 leaked to page 3"
);
}
#[test]
fn debug_arxiv_spacing() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));