Place the page body below geometry's top margin
The geometry package's top/bottom margins were only used to derive a text height; the laid-out body still started at the very top of the sheet, so the arXiv template's 1in top margin was ignored and text sat on the paper edge. Record top/bottom margins on PageGeometry and add the top margin to the page body's vertical offset, which both the SVG preview and the PDF writer honour; the page number and footer baseline move with the body. An explicit textheight still wins over the margin-derived one. The arXiv template's first baseline now sits at 1in + 12pt, still with zero warnings in two pages. Unit tests cover the margin parse/derive and a preview whose first baseline shifts by exactly one inch.
This commit is contained in:
1 parent
21d48866de
commit
7a615a8639
3 files changed
+50
-4
No files matched your search
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
|
|||||||
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
|
||||||
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
|
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
|
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
|
||||||
PDF opt-in with `?engine=route-d`). 975 workspace tests are green and no oracle
|
PDF opt-in with `?engine=route-d`). 977 workspace tests are green and no oracle
|
||||||
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
fixture is ignored. Preview JSON also carries a `warnings` array naming
|
||||||
environments route-D cannot lay out and control words that survived layout, so
|
environments route-D cannot lay out and control words that survived layout, so
|
||||||
unsupported source is reported instead of being silently typeset.
|
unsupported source is reported instead of being silently typeset.
|
||||||
@@ -387,7 +387,9 @@ commands are kept for the native section parser instead of expanding their class
|
|||||||
redefinitions, `\keywords` becomes a plain paragraph, `\lipsum[n]` expands to
|
redefinitions, `\keywords` becomes a plain paragraph, `\lipsum[n]` expands to
|
||||||
filler text, comments and external `\bibliography` commands are dropped, and a
|
filler text, comments and external `\bibliography` commands are dropped, and a
|
||||||
`center`/`flushleft`/`flushright` environment that follows text starts its own
|
`center`/`flushleft`/`flushright` environment that follows text starts its own
|
||||||
block. Class files are still mapped semantically rather than executed by a VM.
|
block, and `geometry`'s `top`/`bottom` margins offset the page body (the arXiv
|
||||||
|
first baseline is at 1in + 12pt) while an explicit `textheight` wins over the
|
||||||
|
margins. Class files are still mapped semantically rather than executed by a VM.
|
||||||
|
|
||||||
### P7 — Service and incrementality
|
### P7 — Service and incrementality
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -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.
|
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 434 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 975 tests (434 route-D unit, 353 engine binary unit, 10 route-D integration, 42 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-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 977 tests (434 route-D unit, 355 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 60 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
@@ -491,6 +491,9 @@ deliberately open rather than approximated:
|
|||||||
`\keywords` becomes a plain paragraph, `\lipsum[n]` expands to filler text,
|
`\keywords` becomes a plain paragraph, `\lipsum[n]` expands to filler text,
|
||||||
comments and external `\bibliography` commands are dropped, and
|
comments and external `\bibliography` commands are dropped, and
|
||||||
`center`/flush environments that follow text start their own block.
|
`center`/flush environments that follow text start their own block.
|
||||||
|
`geometry`'s `top`/`bottom` options shift the page body below the sheet edge
|
||||||
|
(the arXiv template's first baseline now sits at 1in + 12pt instead of the
|
||||||
|
page edge), while an explicit `textheight` still wins over margins.
|
||||||
- Page hashes cover rendered items/insertions/marks/floats, not source-dependency
|
- Page hashes cover rendered items/insertions/marks/floats, not source-dependency
|
||||||
metadata, so replaying an earlier page cannot change its hash merely by
|
metadata, so replaying an earlier page cannot change its hash merely by
|
||||||
re-attaching source hashes.
|
re-attaching source hashes.
|
||||||
|
|||||||
+42
-1
@@ -148,6 +148,10 @@ struct PageGeometry {
|
|||||||
paper_height: Option<i64>,
|
paper_height: Option<i64>,
|
||||||
vsize: Option<i64>,
|
vsize: Option<i64>,
|
||||||
textheight: Option<i64>,
|
textheight: Option<i64>,
|
||||||
|
/// `geometry`'s `top`/`bottom`: the page body starts this far below the
|
||||||
|
/// sheet edge, and the footer margin stays clear below it.
|
||||||
|
top_margin: Option<i64>,
|
||||||
|
bottom_margin: Option<i64>,
|
||||||
/// `\textwidth` / `\hsize` / `\linewidth`, in scaled points.
|
/// `\textwidth` / `\hsize` / `\linewidth`, in scaled points.
|
||||||
line_width: Option<i64>,
|
line_width: Option<i64>,
|
||||||
par_indent: Option<i64>,
|
par_indent: Option<i64>,
|
||||||
@@ -1552,6 +1556,8 @@ fn apply_geometry_package(geometry: &mut PageGeometry, options: &str) {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
geometry.top_margin = top;
|
||||||
|
geometry.bottom_margin = bottom;
|
||||||
let explicit_width = geometry.line_width;
|
let explicit_width = geometry.line_width;
|
||||||
let explicit_height = geometry.textheight;
|
let explicit_height = geometry.textheight;
|
||||||
if left.is_some() || right.is_some() || top.is_some() || bottom.is_some() {
|
if left.is_some() || right.is_some() || top.is_some() || bottom.is_some() {
|
||||||
@@ -4895,7 +4901,9 @@ fn resolve_citations(paragraphs: &mut [SourceParagraph], bibliography: &[(String
|
|||||||
|
|
||||||
fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
fn apply_geometry(document: &mut Document, geometry: &PageGeometry) {
|
||||||
document.h_offset = geometry.origin.h_offset;
|
document.h_offset = geometry.origin.h_offset;
|
||||||
document.v_offset = geometry.origin.v_offset;
|
// 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);
|
||||||
if let Some(width) = geometry.paper_width {
|
if let Some(width) = geometry.paper_width {
|
||||||
document.paper_width = width;
|
document.paper_width = width;
|
||||||
}
|
}
|
||||||
@@ -14083,6 +14091,39 @@ A definition.
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn geometry_reads_vertical_margins() {
|
||||||
|
let source = "\\documentclass{article}\n\\usepackage[top=1in,bottom=1.5in,left=1in,right=1in]{geometry}\n\\begin{document}\n\nText.\n\n\\end{document}\n";
|
||||||
|
let (_body, geometry) = geometry_and_body(source);
|
||||||
|
assert_eq!(geometry.top_margin, parse_dimension("1in"));
|
||||||
|
assert_eq!(geometry.bottom_margin, parse_dimension("1.5in"));
|
||||||
|
assert_eq!(
|
||||||
|
geometry.textheight,
|
||||||
|
Some(792 * SCALE - parse_dimension("1in").unwrap() - parse_dimension("1.5in").unwrap())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn geometry_top_margin_offsets_the_page_body() {
|
||||||
|
let first_y = |json: &str| -> f64 {
|
||||||
|
let value: serde_json::Value = serde_json::from_str(json).expect("JSON");
|
||||||
|
let svg = value["pages"][0]["svg"].as_str().expect("svg");
|
||||||
|
let index = svg.find("y=\"").expect("text y");
|
||||||
|
let rest = &svg[index + 3..];
|
||||||
|
let end = rest.find('"').expect("y end");
|
||||||
|
rest[..end].parse().expect("numeric y")
|
||||||
|
};
|
||||||
|
let plain = preview_json("Hello").expect("plain preview");
|
||||||
|
let shifted =
|
||||||
|
preview_json("\\usepackage[top=1in]{geometry}\n\nHello").expect("shifted preview");
|
||||||
|
let delta = first_y(&shifted) - first_y(&plain);
|
||||||
|
let inch = parse_dimension("1in").unwrap() as f64 / SCALE as f64;
|
||||||
|
assert!(
|
||||||
|
(delta - inch).abs() < 0.2,
|
||||||
|
"top margin shifted text by {delta}pt, expected {inch}pt"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lipsum_expands_to_filler_paragraphs() {
|
fn lipsum_expands_to_filler_paragraphs() {
|
||||||
let source = "\\documentclass{article}\n\\begin{document}\n\n\\lipsum[1]\n\n\\lipsum[2-3]\n\n\\lipsum\n\n\\end{document}\n";
|
let source = "\\documentclass{article}\n\\begin{document}\n\n\\lipsum[1]\n\n\\lipsum[2-3]\n\n\\lipsum\n\n\\end{document}\n";
|
||||||
|
|||||||
Reference in new issue
Block a user