Cover bottom float page placement with pdfLaTeX
This commit is contained in:
1 parent
a09b1d1d36
commit
fd9790cf28
3 files changed
+82
-3
No files matched your search
@@ -1005,6 +1005,77 @@ fn top_floats_reserve_page_space_like_pdftex() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A `[b]` float reserves its height plus `\textfloatsep` at the page bottom;
|
||||
/// the body must stop earlier on exactly the pages pdfLaTeX chooses.
|
||||
#[test]
|
||||
fn bottom_floats_reserve_page_space_like_pdftex() {
|
||||
let paragraphs: Vec<String> = (0..80)
|
||||
.map(|index| format!("p{index} alpha beta gamma"))
|
||||
.collect();
|
||||
let float_at = 2_usize;
|
||||
let mut body = String::new();
|
||||
for (index, paragraph) in paragraphs.iter().enumerate() {
|
||||
body.push_str(paragraph);
|
||||
body.push_str("\\par\n");
|
||||
if index == float_at {
|
||||
body.push_str("\\begin{figure}[b]\\rule{100pt}{60pt}\\end{figure}\n");
|
||||
}
|
||||
}
|
||||
let source = format!(
|
||||
"\\documentclass[10pt]{{article}}\n\
|
||||
\\pdfpagewidth=612bp \\pdfpageheight=792bp\n\
|
||||
\\pagestyle{{empty}}\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 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 index == float_at {
|
||||
units.push(Unit::float(
|
||||
next_id,
|
||||
FloatPlacement::Bottom,
|
||||
100 * PT,
|
||||
60 * PT,
|
||||
));
|
||||
next_id += 1;
|
||||
}
|
||||
}
|
||||
let mut document = Document::new(550 * PT, units);
|
||||
document.top_skip = 12 * PT;
|
||||
document.text_float_sep = 20 * PT;
|
||||
document.max_depth = 5 * PT;
|
||||
let engine = Engine::layout_paged(&document).expect("bottom floats 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, reference)) in ours.iter().zip(&reference).enumerate() {
|
||||
assert_eq!(ours, reference, "body text on page {}", index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// `\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.
|
||||
|
||||
Reference in new issue
Block a user