Reserve title footnote space on the first page

This commit is contained in:
gloamxun committed 2026-10-19 18:32:10 +08:00
1 parent 09781d40e9
commit 9dc1f59f8e
4 files changed
+84 -3

No files matched your search

+2 -1
View File
@@ -343,7 +343,8 @@ space on the page where the paragraph ends, and paints the notes with a
separator rule at the bottom of the page. Footnote lines are painted in body
coordinates so they stay below the text block rather than overlapping it.
`\thanks{...}` is a footnote in the title or author block and is painted at
the bottom of the first page. Footnotes inside captions, floats, or arbitrary
the bottom of the first page. Its measured height is reserved before body
placement, so the last body line stays above the footnote area. Footnotes inside captions, floats, or arbitrary
boxes are not collected yet.
Basic `\input{file}` imports are read relative to the main `.tex` file. Imported
+2 -1
View File
@@ -76,7 +76,8 @@ the source changes; the SVG preview is refreshed per page.
- Pagination: the positioned renderer reserves a 3 mm descent guard at the page
bottom (TeX `\maxdepth`) so the last baseline and its descender stay inside
the page frame.
- Preprint title blocks use the arxiv class's 11 pt leading and reference title
- Preprint title blocks reserve the title/author `\thanks` footnote height on
page one, use the arxiv class's 11 pt leading and reference title
gaps; table cells get a 1 mm render-area tolerance so bottom floats at the page
goal do not trip the frame check.
- Live preview: paragraph cache, page-hash diffing, warm rebuilds in the low
+73 -1
View File
@@ -1184,6 +1184,62 @@ fn footnote_reserve(
.saturating_add(i64::from(scaled_points(1.0).0))
}
/// Height reserved for footnotes that are not attached to a body block.
///
/// Title/author `\thanks` notes fall into this category: they are painted at
/// the bottom of page one, so the body on that page must stop above them.
fn title_footnote_reserve(
model: &DocumentModel,
content_width_mm: f64,
metrics: &BoxFontMetrics,
font_cache: &fonts::FontCache,
cjk_family: Option<FontFamily<fonts::Font>>,
mono_family: Option<FontFamily<fonts::Font>>,
sans_family: Option<FontFamily<fonts::Font>>,
math_metrics: &math_font::MathFontMetrics,
math_layout: &MathLayoutEnvironment,
cache: &mut ParagraphLayoutCache,
) -> i64 {
let mut referenced = Vec::new();
for block in 0..model.blocks.len() {
for number in footnote_numbers_for_block(model, block) {
if !referenced.contains(&number) {
referenced.push(number);
}
}
}
let footnote_font_size = ((f32::from(model.base_font_size) * 0.82).round() as u8).max(1);
let width_mm = (content_width_mm - 8.0).max(20.0);
let mut height = 0_i64;
for note in &model.footnotes {
if referenced.contains(&note.number) {
continue;
}
for line in measure_positioned_lines(
&note.runs,
footnote_font_size,
width_mm,
metrics,
font_cache,
cjk_family,
mono_family,
sans_family,
math_metrics,
math_layout,
cache,
) {
height = height.saturating_add(line.height);
}
}
if height == 0 {
0
} else {
height
.saturating_add(i64::from(scaled_points(2.0).0))
.saturating_add(i64::from(scaled_points(1.0).0))
}
}
fn measure_positioned_lines(
runs: &[Run],
font_size: u8,
@@ -1639,7 +1695,7 @@ pub(super) fn build_positioned_pages(
let heading_gap = (normal_line_height as f64 * 0.65).round() as i64;
// Leave a small descent guard so the last baseline and its descender stay
// inside the page frame; TeX's \maxdepth plays the same role.
let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64
let mut page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64
- millimeters_to_scaled(3.0);
let mut pages = vec![PositionedPage::default()];
set_body_line_factor(if model.title_style == TitleStyle::Preprint {
@@ -1647,6 +1703,22 @@ pub(super) fn build_positioned_pages(
} else {
1.2
});
// Reserve the bottom of page one for `\thanks` notes in the title block.
// They are painted after pagination, so without this the last body line can
// run into the footnote area.
let title_reserve = title_footnote_reserve(
model,
content_width_mm,
metrics,
font_cache,
cjk_family,
mono_family,
sans_family,
math_metrics,
math_layout,
cache,
);
page_goal = page_goal.saturating_sub(title_reserve);
let mut deferred: Vec<DeferredFloat> = Vec::new();
let mut block_end_pages: HashMap<usize, usize> = HashMap::new();
let mut block_start_pages: HashMap<usize, usize> = HashMap::new();
+7
View File
@@ -76,6 +76,7 @@ fn hello_compiles_to_pdf() {
}
#[test]
fn arxiv_fixture_is_three_letter_pages() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures")
@@ -98,6 +99,12 @@ fn arxiv_fixture_is_three_letter_pages() {
assert!(first_page.contains("REPRINT"), "missing undertitle");
assert!(first_page.contains("Hippocampus"), "missing author column");
assert!(first_page.contains("October"), "missing date");
let body_y = text_y(&first_page, "See");
let note_y = text_y(&first_page, "Use");
assert!(
note_y > body_y + 4.0,
"title footnote must reserve space below the body: {body_y} vs {note_y}"
);
let third_page = page_svg(&value, 2);
let entry_x = text_x(&third_page, "Geor");
let continuation_x = text_x(&third_page, "Recognition");