Honour club and widow penalties on paragraph lines
Route-D expanded a paragraph into one node per line without TeX's \clubpenalty/\widowpenalty, so a page break could orphan the first line or widow the last. Insert the penalties between line nodes (150 by default, read from the source registers) and make the page builder reject any penalty of 10000 or more as a breakpoint. Forced -10000 values now break exactly where pdfLaTeX does; two page oracle fixtures compare per-page text, and unit tests cover the node order and the forbidden breakpoint.
This commit is contained in:
1 parent
1bb28cf141
commit
8ac2e828df
6 files changed
+210
-4
No files matched your search
@@ -1720,6 +1720,12 @@ pub struct Document {
|
||||
/// material moves into the page height, as in TeX's page builder.
|
||||
#[serde(default)]
|
||||
pub max_depth: i64,
|
||||
/// TeX `\clubpenalty`: discouraged break after a paragraph's first line.
|
||||
#[serde(default = "default_club_penalty")]
|
||||
pub club_penalty: i64,
|
||||
/// TeX `\widowpenalty`: discouraged break before a paragraph's last line.
|
||||
#[serde(default = "default_widow_penalty")]
|
||||
pub widow_penalty: i64,
|
||||
/// Minimum percentage of the page that text must occupy before a bottom
|
||||
/// float is allowed onto the page (TeX's `\textfraction`, in percent).
|
||||
#[serde(default = "default_text_fraction")]
|
||||
@@ -1824,6 +1830,14 @@ fn default_split_max_depth() -> i64 {
|
||||
i64::MAX
|
||||
}
|
||||
|
||||
fn default_club_penalty() -> i64 {
|
||||
150
|
||||
}
|
||||
|
||||
fn default_widow_penalty() -> i64 {
|
||||
150
|
||||
}
|
||||
|
||||
fn default_split_top_skip() -> i64 {
|
||||
10 * 65_536
|
||||
}
|
||||
@@ -1875,6 +1889,8 @@ impl Document {
|
||||
text_width: default_text_width(),
|
||||
top_skip: 0,
|
||||
max_depth: 0,
|
||||
club_penalty: default_club_penalty(),
|
||||
widow_penalty: default_widow_penalty(),
|
||||
text_fraction_percent: default_text_fraction(),
|
||||
float_page_fraction_percent: 50,
|
||||
bottom_fraction_percent: default_bottom_fraction(),
|
||||
@@ -2039,6 +2055,8 @@ fn document_nodes(
|
||||
// one node per line so the page builder is free to break
|
||||
// inside it; each slice renders as its own single-line
|
||||
// paragraph and keeps the baselines of its own line.
|
||||
let total_lines = paragraph.lines.len();
|
||||
let mut line_index = 0_usize;
|
||||
let mut remaining = paragraph.clone();
|
||||
loop {
|
||||
let tail = if remaining.lines.len() > 1 {
|
||||
@@ -2062,13 +2080,29 @@ fn document_nodes(
|
||||
items.push(VerticalItem::Paragraph(remaining.clone()));
|
||||
match tail {
|
||||
Some(tail) => {
|
||||
// TeX inserts \clubpenalty after the first line
|
||||
// and \widowpenalty before the last, so a page
|
||||
// break that would leave a single line behind
|
||||
// pays the paragraph's penalty.
|
||||
if line_index == 0 && document.club_penalty != 0 {
|
||||
nodes.push(VerticalNode::Penalty(document.club_penalty));
|
||||
owners.push(index);
|
||||
items.push(VerticalItem::Penalty(document.club_penalty));
|
||||
}
|
||||
// TeX puts interline glue between lines; a
|
||||
// zero-width glue node is the legal breakpoint
|
||||
// the page builder needs to split here.
|
||||
nodes.push(VerticalNode::Glue(VerticalGlue::new(0, 0, 0)));
|
||||
owners.push(index);
|
||||
items.push(VerticalItem::Glue(0));
|
||||
if line_index + 1 == total_lines - 1 && document.widow_penalty != 0
|
||||
{
|
||||
nodes.push(VerticalNode::Penalty(document.widow_penalty));
|
||||
owners.push(index);
|
||||
items.push(VerticalItem::Penalty(document.widow_penalty));
|
||||
}
|
||||
remaining = tail;
|
||||
line_index += 1;
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
@@ -4452,6 +4486,28 @@ mod tests {
|
||||
assert_eq!(document.paper_height, 792 * 65_536);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_lines_carry_club_and_widow_penalties() {
|
||||
let style = crate::paragraph::ParagraphStyle {
|
||||
line_width: 120 * 65_536,
|
||||
..Default::default()
|
||||
};
|
||||
let text = "alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu ".repeat(8);
|
||||
let unit = Unit::paragraph_with_style(1, text, style);
|
||||
let mut document = Document::new(700 * 65_536, vec![unit]);
|
||||
document.club_penalty = 77;
|
||||
document.widow_penalty = 88;
|
||||
let (nodes, _, _) = document_nodes(&document).expect("page-builder nodes");
|
||||
let penalties: Vec<i64> = nodes
|
||||
.iter()
|
||||
.filter_map(|node| match node {
|
||||
VerticalNode::Penalty(value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(penalties, vec![77, 88]);
|
||||
}
|
||||
|
||||
fn document() -> Document {
|
||||
Document::new(
|
||||
50,
|
||||
|
||||
@@ -587,7 +587,9 @@ impl PageBuilder {
|
||||
deferred_floats.clone(),
|
||||
));
|
||||
}
|
||||
if index > start {
|
||||
// TeX treats a penalty of 10000 or more as no break at
|
||||
// all; only the forced (<= -10000) case above is stronger.
|
||||
if index > start && *penalty < 10_000 {
|
||||
candidates.push(self.candidate(
|
||||
height,
|
||||
depth,
|
||||
@@ -928,6 +930,14 @@ mod tests {
|
||||
assert_eq!(pages[1].penalty, 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infinite_penalty_forbids_the_break() {
|
||||
let builder = PageBuilder::new(100);
|
||||
let nodes = vec![box_(60, 0), VerticalNode::Penalty(10_000), box_(60, 0)];
|
||||
let pages = builder.build(&nodes);
|
||||
assert_eq!(pages.len(), 1, "a 10000 penalty must not be a breakpoint");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glue_breaks_report_a_ten_thousand_penalty() {
|
||||
let builder = PageBuilder::new(100);
|
||||
|
||||
@@ -323,6 +323,17 @@ fn route_pages_text_with(
|
||||
page_goal_pt: i64,
|
||||
top_skip_pt: i64,
|
||||
) -> Vec<String> {
|
||||
route_pages_text_with_penalties(paragraphs, par_skip, page_goal_pt, top_skip_pt, 150, 150)
|
||||
}
|
||||
|
||||
fn route_document_with_penalties(
|
||||
paragraphs: &[String],
|
||||
par_skip: i64,
|
||||
page_goal_pt: i64,
|
||||
top_skip_pt: i64,
|
||||
club_penalty: i64,
|
||||
widow_penalty: i64,
|
||||
) -> Document {
|
||||
let mut units = Vec::new();
|
||||
let mut page_breaks = Vec::new();
|
||||
for text in paragraphs {
|
||||
@@ -346,9 +357,30 @@ fn route_pages_text_with(
|
||||
document.page_breaks = page_breaks;
|
||||
document.top_skip = top_skip_pt * PT;
|
||||
document.par_skip = par_skip * PT;
|
||||
document.club_penalty = club_penalty;
|
||||
document.widow_penalty = widow_penalty;
|
||||
document.text_float_sep = 0;
|
||||
// LaTeX's default \maxdepth keeps descents out of the page height.
|
||||
document.max_depth = 5 * PT;
|
||||
document
|
||||
}
|
||||
|
||||
fn route_pages_text_with_penalties(
|
||||
paragraphs: &[String],
|
||||
par_skip: i64,
|
||||
page_goal_pt: i64,
|
||||
top_skip_pt: i64,
|
||||
club_penalty: i64,
|
||||
widow_penalty: i64,
|
||||
) -> Vec<String> {
|
||||
let document = route_document_with_penalties(
|
||||
paragraphs,
|
||||
par_skip,
|
||||
page_goal_pt,
|
||||
top_skip_pt,
|
||||
club_penalty,
|
||||
widow_penalty,
|
||||
);
|
||||
Engine::layout(&document)
|
||||
.pages()
|
||||
.iter()
|
||||
@@ -356,6 +388,32 @@ fn route_pages_text_with(
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Lay out through the TeX page builder (`document_nodes`), the path route-D
|
||||
/// previews and PDFs use; club/widow penalties are inserted between lines.
|
||||
fn route_paged_text_with_penalties(
|
||||
paragraphs: &[String],
|
||||
par_skip: i64,
|
||||
page_goal_pt: i64,
|
||||
top_skip_pt: i64,
|
||||
club_penalty: i64,
|
||||
widow_penalty: i64,
|
||||
) -> Vec<String> {
|
||||
let document = route_document_with_penalties(
|
||||
paragraphs,
|
||||
par_skip,
|
||||
page_goal_pt,
|
||||
top_skip_pt,
|
||||
club_penalty,
|
||||
widow_penalty,
|
||||
);
|
||||
Engine::layout_paged(&document)
|
||||
.expect("paged layout")
|
||||
.pages()
|
||||
.iter()
|
||||
.map(page_alnum_text)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn assert_lines_match(label: &str, ours: &[Line], reference: &[Line]) {
|
||||
assert_eq!(
|
||||
ours.len(),
|
||||
@@ -760,6 +818,62 @@ fn newpage_matches_pdftex_page_breaks() {
|
||||
assert_eq!(ours, reference, "newpage page text");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn club_penalty_forces_a_break_after_the_first_line() {
|
||||
let text = format!("{WORDS} {WORDS} {WORDS}");
|
||||
let source = format!(
|
||||
"\\documentclass[10pt]{{article}}\n\
|
||||
\\pdfpagewidth=612bp \\pdfpageheight=792bp\n\
|
||||
\\pagestyle{{empty}}\n\
|
||||
\\begin{{document}}\n\
|
||||
\\hsize=345pt \\parindent=15pt \\topskip=12pt \\vsize=550pt \\clubpenalty=-10000 \\widowpenalty=0\n\
|
||||
{text}\\par\n\\end{{document}}\n"
|
||||
);
|
||||
let Some(reference) = pdftex_pages(&source) else {
|
||||
eprintln!("skipping: pdflatex/pdftotext are not installed");
|
||||
return;
|
||||
};
|
||||
let ours = route_paged_text_with_penalties(&[text], 0, 550, 12, -10_000, 0);
|
||||
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, "text on page {}", index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn widow_penalty_forces_a_break_before_the_last_line() {
|
||||
let text = format!("{WORDS} {WORDS} {WORDS}");
|
||||
let source = format!(
|
||||
"\\documentclass[10pt]{{article}}\n\
|
||||
\\pdfpagewidth=612bp \\pdfpageheight=792bp\n\
|
||||
\\pagestyle{{empty}}\n\
|
||||
\\begin{{document}}\n\
|
||||
\\hsize=345pt \\parindent=15pt \\topskip=12pt \\vsize=550pt \\clubpenalty=0 \\widowpenalty=-10000\n\
|
||||
{text}\\par\n\\end{{document}}\n"
|
||||
);
|
||||
let Some(reference) = pdftex_pages(&source) else {
|
||||
eprintln!("skipping: pdflatex/pdftotext are not installed");
|
||||
return;
|
||||
};
|
||||
let ours = route_paged_text_with_penalties(&[text], 0, 550, 12, 0, -10_000);
|
||||
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, "text on page {}", index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pages_break_like_pdftex_for_single_line_paragraphs() {
|
||||
let paragraphs: Vec<String> = (0..100)
|
||||
|
||||
@@ -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`). 958 workspace tests are green and no oracle
|
||||
PDF opt-in with `?engine=route-d`). 963 workspace tests are green and no oracle
|
||||
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
||||
environments route-D cannot lay out and control words that survived layout, so
|
||||
unsupported source is reported instead of being silently typeset.
|
||||
@@ -304,6 +304,11 @@ and `[b]` floats that fit or defer to the next page); each
|
||||
asserts the same page count and the same per-page body text as pdfLaTeX, with
|
||||
footnote text excluded from the body comparison. Route-D's source mapping still
|
||||
does not raise LaTeX floats, so the float fixture drives `Engine` directly.
|
||||
Two more fixtures pin TeX's orphan and widow controls: `\clubpenalty=-10000`
|
||||
forces a break after a paragraph's first line and `\widowpenalty=-10000` forces
|
||||
one before its last, page for page against pdfLaTeX. The paged builder inserts
|
||||
both penalties between line nodes (150 by default) and refuses any penalty of
|
||||
10000 or more as a breakpoint.
|
||||
|
||||
### P3 — `\halign` / `\valign` (L2)
|
||||
|
||||
|
||||
+2
-2
@@ -360,7 +360,7 @@ M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic
|
||||
|
||||
M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
|
||||
|
||||
M2 (partial): `Page::display_list_with_goal(page_goal)` places insertion material at `page_goal - insertion_height`, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical `content` at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect `text_fraction_percent`, respect `top_fraction_percent` (TeX `\topfraction`, default 70%) and `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page. The incremental edit path applies the same float fractions, float number limits, insertion-class limits and per-class `skip` rules as full layout. `Document::float_sep` (TeX `\floatsep`, default 12pt) reserves a gap between stacked floats of the same placement in both paths. `Document::text_float_sep` (TeX `\textfloatsep`, default 20pt) reserves exactly one gap between the float block and the body text on a page that has both, again in both paths; `Page::display_list_with_layout(page_goal, text_float_sep)` applies the same gap when rendering, while `display_list_with_goal` stays gap-free for callers that do not know the document settings. Float material at the top of a page starts at the top margin: `\topskip` is consumed only by body text, matching TeX float pages. A `[t]` float seen while a page is already being filled is installed at the top of that same page, exactly as TeX's `\@toplist` does: the page height gains the float plus one `\textfloatsep` (or `\floatsep` between stacked floats), so the body stops earlier instead of the float waiting for the next page; only a break before the float moves it forward. `FloatPlacement::Here` models `[h]` floats: they keep their place in the body flow with `Document::in_text_sep` (TeX `\intextsep`, default 12pt) above and below, move to the next page when they do not fit, and count against `\totalnumber`. The page stores the float's `gap_after` so the display list advances the flow by the same amount the builder reserved. A standalone `page::PageBuilder` implements TeX's candidate-breakpoint cost model (page badness from accumulated glue stretch/shrink plus break penalties, `\topskip` for the first box, `\maxdepth` depth shifting) with unit tests covering overfull avoidance, exact glue filling, forced and costed breaks, `\topskip`, `\maxdepth`, marks, insertion limits and top-float placement; every fragment records the penalty that broke it. `Engine::layout_paged` now builds pages through it for documents whose units are single vertical items (boxes, rules, paragraphs, math, haligns, glue, penalties, marks and insertion classes, including per-class limits and held-over material; held-over material starts with `Document::split_top_skip` (TeX `\splittopskip`, default 10pt) when the class capacity can also hold its first item, and `Document::split_max_depth` (TeX `\splitmaxdepth`, `\maxdimen` by default) clamps the first held box's depth while moving the excess into its height); `Document::max_depth` feeds TeX's `\maxdepth` into the builder, and among equal-cost breakpoints the later candidate wins, matching the page builder's `least_page_cost` update with `<=`, so a page can take a later break even when it overfills the goal slightly; when no break fits within the glue shrink, the least overfull break is used instead. Paragraphs also split across pages at line boundaries, so body material no longer overflows a page as one box. Paragraph boxes carry TeX depth: each node reports its last line's descent, so `\pagedepth` sees it, and the builder adds every box descent beyond `\maxdepth` to the page height while keeping the rest as page depth (TeX's per-box rule); route-D sources default `\maxdepth` to LaTeX's 5pt (0.5\topskip), and the page fixtures set it explicitly. A standalone `\smallskip`, `\medskip`, `\bigskip`, `\vskip` or `\vspace{...}` line between paragraphs becomes the following unit's `space_before` glue, carrying TeX's width plus its `plus`/`minus` parts (`\smallskip` is 3pt plus 1pt minus 1pt, and so on). Both page builders reserve it, the paged builder gets a real breakpoint with the glue's stretch and shrink, and edits preserve all three components; the command no longer leaks into the paragraph text. `Document::h_offset` and `v_offset` (TeX `\hoffset`/`\voffset`, default zero) feed `pdf::PageOrigin`, and `display_lists_to_pdf_with_paper` translates the page body without moving the sheet; a route-D fixture checks a 10pt/20pt shift against `pdftotext -bbox`, and
|
||||
M2 (partial): `Page::display_list_with_goal(page_goal)` places insertion material at `page_goal - insertion_height`, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical `content` at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect `text_fraction_percent`, respect `top_fraction_percent` (TeX `\topfraction`, default 70%) and `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page. The incremental edit path applies the same float fractions, float number limits, insertion-class limits and per-class `skip` rules as full layout. `Document::float_sep` (TeX `\floatsep`, default 12pt) reserves a gap between stacked floats of the same placement in both paths. `Document::text_float_sep` (TeX `\textfloatsep`, default 20pt) reserves exactly one gap between the float block and the body text on a page that has both, again in both paths; `Page::display_list_with_layout(page_goal, text_float_sep)` applies the same gap when rendering, while `display_list_with_goal` stays gap-free for callers that do not know the document settings. Float material at the top of a page starts at the top margin: `\topskip` is consumed only by body text, matching TeX float pages. A `[t]` float seen while a page is already being filled is installed at the top of that same page, exactly as TeX's `\@toplist` does: the page height gains the float plus one `\textfloatsep` (or `\floatsep` between stacked floats), so the body stops earlier instead of the float waiting for the next page; only a break before the float moves it forward. `FloatPlacement::Here` models `[h]` floats: they keep their place in the body flow with `Document::in_text_sep` (TeX `\intextsep`, default 12pt) above and below, move to the next page when they do not fit, and count against `\totalnumber`. The page stores the float's `gap_after` so the display list advances the flow by the same amount the builder reserved. A standalone `page::PageBuilder` implements TeX's candidate-breakpoint cost model (page badness from accumulated glue stretch/shrink plus break penalties, `\topskip` for the first box, `\maxdepth` depth shifting) with unit tests covering overfull avoidance, exact glue filling, forced and costed breaks, `\topskip`, `\maxdepth`, marks, insertion limits and top-float placement; every fragment records the penalty that broke it. `Engine::layout_paged` now builds pages through it for documents whose units are single vertical items (boxes, rules, paragraphs, math, haligns, glue, penalties, marks and insertion classes, including per-class limits and held-over material; held-over material starts with `Document::split_top_skip` (TeX `\splittopskip`, default 10pt) when the class capacity can also hold its first item, and `Document::split_max_depth` (TeX `\splitmaxdepth`, `\maxdimen` by default) clamps the first held box's depth while moving the excess into its height); `Document::max_depth` feeds TeX's `\maxdepth` into the builder, and among equal-cost breakpoints the later candidate wins, matching the page builder's `least_page_cost` update with `<=`, so a page can take a later break even when it overfills the goal slightly; when no break fits within the glue shrink, the least overfull break is used instead. Paragraphs also split across pages at line boundaries, so body material no longer overflows a page as one box. Each multi-line paragraph inserts TeX's `\clubpenalty` after its first line and `\widowpenalty` before its last (150 in LaTeX, overridable through `\clubpenalty`/`\widowpenalty`); a page penalty of 10000 or more is not a legal breakpoint, and forcing either register to -10000 breaks exactly where pdfLaTeX does (two page oracle fixtures). Paragraph boxes carry TeX depth: each node reports its last line's descent, so `\pagedepth` sees it, and the builder adds every box descent beyond `\maxdepth` to the page height while keeping the rest as page depth (TeX's per-box rule); route-D sources default `\maxdepth` to LaTeX's 5pt (0.5\topskip), and the page fixtures set it explicitly. A standalone `\smallskip`, `\medskip`, `\bigskip`, `\vskip` or `\vspace{...}` line between paragraphs becomes the following unit's `space_before` glue, carrying TeX's width plus its `plus`/`minus` parts (`\smallskip` is 3pt plus 1pt minus 1pt, and so on). Both page builders reserve it, the paged builder gets a real breakpoint with the glue's stretch and shrink, and edits preserve all three components; the command no longer leaks into the paragraph text. `Document::h_offset` and `v_offset` (TeX `\hoffset`/`\voffset`, default zero) feed `pdf::PageOrigin`, and `display_lists_to_pdf_with_paper` translates the page body without moving the sheet; a route-D fixture checks a 10pt/20pt shift against `pdftotext -bbox`, and
|
||||
preview pages apply the same offsets to their display list so the editor and
|
||||
PDF agree. `Document::paper_width` and `paper_height` (TeX `\paperwidth`/`\paperheight`, default US Letter) set the PDF MediaBox and the preview page box, and both route-D endpoints strip leading `\hoffset`/`\voffset`/`\paperwidth`/`\paperheight`/`\vsize`/`\textheight` dimension assignments from the source (preamble included) and apply them, and the same pass reads `\parindent`, `\parskip`, `\baselineskip`, `\leftskip`, `\rightskip`, `\emergencystretch`, `\tolerance`, `\pretolerance`, `\hangindent`/`\hangafter`, `\spaceskip`/`\xspaceskip` and `\frenchspacing` into the paragraph styles; `\textwidth`/`\hsize` (including `\setlength{\textwidth}{...}`) set the paragraph measure, and `\setlength` also applies to the supported layout lengths with `\parskip` keeping its plus/minus glue; body paragraphs are measured with CMR10/per-face TFM advances rather than fixed cells; `\textheight` wins over `\vsize` because LaTeX resets `\vsize` from `\textheight` on every page, and project previews reuse the same geometry parsing. `Engine::top_mark`, `first_mark` and `bot_mark` implement TeX's carried mark registers per class. `Document::output_routine` runs an interpreted `\output` program over the paged fragments (`output::OutputProgram`: `\shipout\box255`, `\relax`, `\message`, `\ifdim`, `\ifnum`, `\ifodd` and `\ifcase` over the page registers, now including `\pageno`, `\outputpenalty`, `\deadcycles` and `\maxdeadcycles`), dropping pages the routine does not ship. A `\mark{...}` or classed `\marks<n>{...}` write inside the routine is recorded by the interpreter and placed at the front of the next page's marks, so the carried marks TeX exposes to the following page are reproduced. Assignments such as `\pageno=10`, `\deadcycles=0`, `\count2=2000`, `\dimen2=30pt`, `\skip2=6pt` and `\vsize=300pt` mutate the per-page context; `\advance`, `\multiply` and `\divide` adjust those registers in place (`\advance\pageno by 2`, `\divide\deadcycles by 2`, `\advance\dimen2 by 5pt`), and an arithmetic `\vsize` change retargets later pages exactly like an assignment; `\pageno` and the insertion registers keep their assigned values for later pages, since TeX's output registers are global; Route-D sources map a standalone `\newpage` or `\clearpage` onto `Document::page_breaks`, so the next paragraph starts on a fresh page (the paged builder turns each break into a `-10000` penalty node); the paged builder runs the routine after each page, so an assigned `\vsize` sets the goal of the pages the routine has not seen yet: the remaining fragments are rebuilt from the next node index with the new goal, which works with insertion material because class limits apply while the page is assembled; a deferred bottom float disables the retarget because the carried queue cannot be rebuilt. The `\pagegoal` register handed to the output routine is reduced by the insertion space reserved on that page. `\vbadness` carries the page's break badness and `\insertpenalties` counts insertion items the class limits held over, so an output routine can react to overfull breaks or split insertions. Paged layouts record the node index that starts each page, so `Engine::edit` on a paged layout reuses the sealed prefix and rebuilds only from the edited unit's page onward; an interpreted `\output` routine still forces a full rebuild, and an edit whose replay would begin before the first insertion does too, because held-over material and dropped pages move page boundaries. A document that contains a bottom float likewise rebuilds in full: a deferred float is carried on the page fragment, and a suffix replay starting at a page boundary cannot recover that queue. The scrolling builder's float path remains to be ported. The oracle harness also compares whole pages: ten page fixtures (single-line paragraphs, `\parskip=6pt`, multi-line paragraphs split across pages, a 300pt `\textheight`, a 30pt `\topskip`, a forced `\newpage`, stretchy `\vskip` glue between paragraphs, footnotes raised with `\footnotetext`, and a `[t]` float that reserves its height plus `\textfloatsep` on the page it appears, and `[b]` floats that fit or defer to the next page) assert the same page count and the same per-page alphanumeric text as pdfLaTeX at 345pt measure, 550pt `\vsize`, 12pt `\topskip` and 15pt `\parindent`.
|
||||
|
||||
@@ -370,7 +370,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`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
|
||||
|
||||
The crate currently has 432 unit tests plus ten route-D integration tests and thirty-nine oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 958 tests (432 route-D unit, 341 engine binary unit, 10 route-D integration, 39 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
The crate currently has 434 unit tests plus ten route-D integration tests and forty-one oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 963 tests (434 route-D unit, 342 engine binary unit, 10 route-D integration, 41 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
@@ -229,6 +229,8 @@ struct PageGeometry {
|
||||
par_fillskip: Option<(i64, i64, bool)>,
|
||||
top_skip: Option<i64>,
|
||||
max_depth: Option<i64>,
|
||||
club_penalty: Option<i64>,
|
||||
widow_penalty: Option<i64>,
|
||||
split_top_skip: Option<i64>,
|
||||
split_max_depth: Option<i64>,
|
||||
hyphen_penalty: Option<i64>,
|
||||
@@ -2667,6 +2669,10 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
geometry.line_penalty = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "adjdemerits") {
|
||||
geometry.adj_demerits = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "clubpenalty") {
|
||||
geometry.club_penalty = Some(value);
|
||||
} else if let Some(value) = integer_assignment(trimmed, "widowpenalty") {
|
||||
geometry.widow_penalty = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "topskip") {
|
||||
geometry.top_skip = Some(value);
|
||||
} else if let Some(value) = dimension_assignment(trimmed, "maxdepth") {
|
||||
@@ -10079,6 +10085,8 @@ fn build_document_with_labels(
|
||||
}
|
||||
// LaTeX sets \maxdepth=.5\topskip; sources may override it later.
|
||||
document.max_depth = 5 * SCALE;
|
||||
document.club_penalty = geometry.club_penalty.unwrap_or(150);
|
||||
document.widow_penalty = geometry.widow_penalty.unwrap_or(150);
|
||||
document.text_width = line_width;
|
||||
document.page_breaks = paragraphs
|
||||
.iter()
|
||||
@@ -13430,6 +13438,19 @@ A definition.
|
||||
assert_eq!(document.max_depth, 5 * SCALE);
|
||||
assert_eq!(document.split_top_skip, 3 * SCALE);
|
||||
}
|
||||
#[test]
|
||||
fn geometry_reads_club_and_widow_penalties() {
|
||||
let source = "\\documentclass{article}\n\\clubpenalty=77\n\\widowpenalty=88\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||
let (body, geometry) = geometry_and_body(source);
|
||||
assert_eq!(geometry.club_penalty, Some(77));
|
||||
assert_eq!(geometry.widow_penalty, Some(88));
|
||||
assert!(!body.contains("clubpenalty"));
|
||||
let paragraphs = paragraphs(&body).expect("paragraphs");
|
||||
let document = build_document(¶graphs, &geometry);
|
||||
assert_eq!(document.club_penalty, 77);
|
||||
assert_eq!(document.widow_penalty, 88);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn geometry_reads_demerit_registers() {
|
||||
let source = "\\documentclass{article}\n\\hyphenpenalty=77\n\\exhyphenpenalty=88\n\\doublehyphendemerits=1234\n\\finalhyphendemerits=4321\n\\linepenalty=20\n\\adjdemerits=999\n\\begin{document}\n\nSome words here.\n\n\\end{document}\n";
|
||||
|
||||
Reference in new issue
Block a user