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.
|
||||
|
||||
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
||||
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||
PDF opt-in with `?engine=route-d`). 458 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 459 workspace tests are green and no oracle
|
||||
fixture is ignored.
|
||||
|
||||
Known gaps, in dependency order:
|
||||
@@ -249,6 +249,12 @@ breaks; at `\tolerance=10000` the wide-measure fixture now matches pdfLaTeX at
|
||||
breaks because the demerits optimum differs; that stays documented as a
|
||||
known approximation.
|
||||
|
||||
Bottom floats now have their own page fixture: when the float fits, the
|
||||
body break matches pdfLaTeX. When it does not fit the remaining body space,
|
||||
the paged builder ends the current page and defers the float, while TeX
|
||||
keeps filling the page before placing the float on the next one; that
|
||||
deferral-fill case stays documented as a known approximation.
|
||||
|
||||
### P2 — Vertical list, page builder, `\output` (L2)
|
||||
|
||||
Scope:
|
||||
|
||||
+4
-2
@@ -267,7 +267,9 @@ oracle fixture is ignored.
|
||||
change page goals. The paged builder places top `Float` material at the top
|
||||
of a page and bottom `Float` material at the page bottom: a late top float
|
||||
starts the next page, a bottom float that cannot fit the remaining body
|
||||
space is deferred, stacked bottom floats reserve `\floatsep`, and
|
||||
space ends the current page and is deferred to the next page's bottom
|
||||
(TeX instead keeps filling the current page before deferring the float,
|
||||
which remains a documented approximation), stacked bottom floats reserve `\floatsep`, and
|
||||
`\bottomfraction` caps the bottom float share, and a page whose top floats reach `\floatpagefraction` ships without body material. Route-D preview/PDF draw
|
||||
pages through `display_list_with_layout` so the body clears
|
||||
`\textfloatsep` / the bottom float area; the scrolling builder still
|
||||
@@ -361,7 +363,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
|
||||
|
||||
Paragraph units carry a `ParagraphFont`; `Unit::paragraph_with_face` and `Unit::paragraph_with_style_and_face` select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (`cmr10`, `cmbx10`, `cmti10`, `cmbxti10`, `cmtt10`, `cmss10`) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 304 unit tests plus seven route-D integration tests and thirty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 458 tests (304 route-D unit, 7 route-D integration, 32 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 13 binary units), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 304 unit tests plus seven route-D integration tests and thirty-three oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 459 tests (304 route-D unit, 7 route-D integration, 33 oracle, 71 v1 integration, 26 server, 4 v1 unit, 1 core unit, 13 binary units), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
Reference in new issue
Block a user