Compare footnote insertions with pdfLaTeX page breaks
This commit is contained in:
1 parent
6b3145fd09
commit
a78e0c1d0d
3 files changed
+96
-8
No files matched your search
@@ -10,7 +10,7 @@ use std::process::Command;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use texrra_tex_core::paragraph::{HorizontalItem, ParagraphStyle};
|
||||
use texrra_tex_core::{Document, Engine, Unit, VerticalItem};
|
||||
use texrra_tex_core::{Document, Engine, Unit, VerticalItem, layout_paragraph};
|
||||
|
||||
/// Scaled points per TeX point.
|
||||
const PT: i64 = 65_536;
|
||||
@@ -935,6 +935,91 @@ fn pages_split_paragraphs_like_pdftex() {
|
||||
}
|
||||
}
|
||||
|
||||
/// `\footnotetext` raises insertion material that is reserved at the page
|
||||
/// bottom. With slack on each page, the body breaks and per-page body text
|
||||
/// must stay in step with pdfLaTeX even though the note text is not compared.
|
||||
#[test]
|
||||
fn footnotes_reserve_page_space_like_pdftex() {
|
||||
let paragraphs: Vec<String> = (0..80)
|
||||
.map(|index| format!("p{index} alpha beta gamma"))
|
||||
.collect();
|
||||
let notes: Vec<usize> = (0..8).map(|index| index * 10 + 9).collect();
|
||||
let mut body = String::new();
|
||||
for (index, paragraph) in paragraphs.iter().enumerate() {
|
||||
body.push_str(paragraph);
|
||||
body.push_str("\\par\n");
|
||||
if let Some(number) = notes.iter().position(|at| *at == index) {
|
||||
body.push_str(&format!("\\footnotetext{{note number {number}}}\n"));
|
||||
}
|
||||
}
|
||||
let source = format!(
|
||||
"\\documentclass[10pt]{{article}}\n\
|
||||
\\pdfpagewidth=612bp \\pdfpageheight=792bp\n\
|
||||
\\pagestyle{{empty}}\n\
|
||||
\\renewcommand{{\\thefootnote}}{{}}\n\
|
||||
\\begin{{document}}\n\
|
||||
\\hsize=345pt \\parindent=15pt \\parskip=0pt \\topskip=12pt \\vsize=550pt\n\
|
||||
{body}\\end{{document}}\n"
|
||||
);
|
||||
let Some(reference) = pdftex_pages(&source) else {
|
||||
eprintln!("skipping: pdflatex/pdftotext are not installed");
|
||||
return;
|
||||
};
|
||||
let style = ParagraphStyle {
|
||||
line_width: 345 * PT,
|
||||
par_indent: 15 * PT,
|
||||
line_height: 12 * PT,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let note_style = ParagraphStyle {
|
||||
line_width: 345 * PT,
|
||||
par_indent: 0,
|
||||
line_height: 11 * PT,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let mut units = Vec::new();
|
||||
let mut next_id = 1_u64;
|
||||
for (index, paragraph) in paragraphs.iter().enumerate() {
|
||||
units.push(Unit::paragraph_with_style(
|
||||
next_id,
|
||||
paragraph.clone(),
|
||||
style.clone(),
|
||||
));
|
||||
next_id += 1;
|
||||
if let Some(number) = notes.iter().position(|at| *at == index) {
|
||||
let note = layout_paragraph(&format!("note number {number}"), ¬e_style);
|
||||
units.push(Unit::insertion(
|
||||
next_id,
|
||||
0,
|
||||
note.height,
|
||||
vec![VerticalItem::Paragraph(note)],
|
||||
));
|
||||
next_id += 1;
|
||||
}
|
||||
}
|
||||
let mut document = Document::new(550 * PT, units);
|
||||
document.top_skip = 12 * PT;
|
||||
document.text_float_sep = 0;
|
||||
document.insertion_skip = 12 * PT;
|
||||
let engine = Engine::layout_paged(&document).expect("insertions are page-buildable");
|
||||
let ours: Vec<String> = engine.pages().iter().map(page_alnum_text).collect();
|
||||
assert_eq!(
|
||||
ours.len(),
|
||||
reference.len(),
|
||||
"route-D produced {} pages, pdfLaTeX {}",
|
||||
ours.len(),
|
||||
reference.len()
|
||||
);
|
||||
for (index, (ours, page)) in ours.iter().zip(&reference).enumerate() {
|
||||
// pdftotext puts each note at the bottom of its page; dropping the
|
||||
// note text leaves the body words route-D also reports.
|
||||
let expected = (0..notes.len()).fold(page.clone(), |text, number| {
|
||||
text.replace(&format!("notenumber{number}"), "")
|
||||
});
|
||||
assert_eq!(ours, &expected, "body text on page {}", index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_breaks_match_pdftex_at_150pt() {
|
||||
compare_fixture(WORDS, 150);
|
||||
|
||||
Reference in new issue
Block a user