Fix PDF page origin and add the fidelity/latency roadmap

The PDF writer received the raw geometry origin instead of the document's
effective offsets, so PDFs started at x=0 and clipped running headers above the
page even though the preview looked shifted. PDF output now uses the same
h_offset/v_offset as the preview.

For a geometry document with a 6.5in measure this restores the 1in text block;
the arXiv template's page-2/3 headers ("arXiv Template", "A Preprint") now
appear. A regression test checks the centred text block.

Add docs/TEX_FIDELITY_ROADMAP.md: page-frame/class/font/citation/math
fidelity workstreams, incremental revision/patch protocol, milestones and the
<100ms warm preview target. Test count is 1070 (433 engine).
This commit is contained in:
gloamxun committed 2026-10-27 20:55:51 +08:00
1 parent 7407d4ed42
commit 30f1df03ca
6 files changed
+197 -10

No files matched your search

+23 -1
View File
@@ -156,6 +156,9 @@ struct PageGeometry {
bottom_margin: Option<i64>,
/// `\textwidth` / `\hsize` / `\linewidth`, in scaled points.
line_width: Option<i64>,
/// The source uses the `geometry` package, so a text block with no explicit
/// `\hoffset` is centred between the paper edges.
geometry_package: bool,
par_indent: Option<i64>,
par_skip: Option<i64>,
par_skip_stretch: Option<i64>,
@@ -2325,6 +2328,7 @@ fn geometry_package_options(line: &str) -> Option<String> {
/// Apply the subset of the `geometry` package that route-D can honour.
fn apply_geometry_package(geometry: &mut PageGeometry, options: &str) {
geometry.geometry_package = true;
let paper_width = geometry.paper_width.unwrap_or(612 * SCALE);
let paper_height = geometry.paper_height.unwrap_or(792 * SCALE);
let mut left = None;
@@ -7138,6 +7142,11 @@ fn renewcommand_length(line: &str, name: &str) -> Option<i64> {
fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
document.h_offset = geometry.origin.h_offset;
if geometry.geometry_package && document.h_offset == 0 {
let paper_width = geometry.paper_width.unwrap_or(612 * SCALE);
let line_width = geometry.line_width.unwrap_or(480 * SCALE);
document.h_offset = ((paper_width - line_width) / 2).max(0);
}
// geometry's `top` places the text block below the sheet edge; the
// display list and the PDF writer both honour the offset.
document.v_offset = geometry.origin.v_offset + geometry.top_margin.unwrap_or(0);
@@ -7629,11 +7638,15 @@ pub fn pdf_bytes_with_images(
.and_then(|name| color_spec(name, &geometry.colors))
},
};
let origin = PageOrigin {
h_offset: document.h_offset,
v_offset: document.v_offset,
};
Ok(display_lists_to_pdf_with_cm_type1_and_metadata(
&pages,
document.paper_width,
document.paper_height,
geometry.origin,
origin,
&metadata,
))
}
@@ -19358,6 +19371,15 @@ left & right \\
);
}
#[test]
fn geometry_centers_the_text_block_horizontally() {
let source = "\\documentclass{article}\n\\usepackage[letterpaper,textwidth=6.5in]{geometry}\n\\begin{document}\n\nText.\n\n\\end{document}\n";
let json = preview_json(source).expect("preview");
let texts = svg_texts(&json);
let (_, x, _) = texts.iter().find(|(text, _, _)| text == "T").expect("text");
assert!((*x - 72.0).abs() < 1.0, "text starts at {x}pt");
}
#[test]
fn geometry_top_margin_offsets_the_page_body() {
let first_y = |json: &str| -> f64 {