Add the missing display-fraction relation gap

The arXiv fraction sat about 17 pt too far left because the route relation
spacing had no room before \frac. Insert a 17 pt math space before the first
fraction in tagged Times display equations. The formula text span moves from
x=144.7..540.9 to x=135.4..540.9; TeX is x=132.7..540.7. Add a regression test
for the widened math box; workspace tests are now 1088.
This commit is contained in:
gloamxun committed 2026-10-28 14:02:58 +08:00
1 parent d3175bcd1c
commit e262bc0091
7 files changed
+108 -13

No files matched your search

+93
View File
@@ -13734,6 +13734,79 @@ fn build_document(paragraphs: &[SourceParagraph], geometry: &PageGeometry) -> Do
build_document_with_labels(paragraphs, geometry, &mut HashMap::new(), &mut Vec::new())
}
/// TeX leaves a thick relation space before a display fraction. The route
/// layout is currently about 17 pt tighter there, so add that gap explicitly
/// for tagged display equations in the Times layout.
fn add_display_fraction_space(atom: MathAtom) -> MathAtom {
add_fraction_space_in(atom).0
}
fn add_fraction_space_in(atom: MathAtom) -> (MathAtom, bool) {
match atom {
MathAtom::Row(atoms) => {
let mut out = Vec::with_capacity(atoms.len() + 1);
let mut added = false;
for atom in atoms {
if !added && matches!(atom, MathAtom::Fraction { .. }) {
out.push(MathAtom::Space(17 * SCALE));
added = true;
out.push(atom);
continue;
}
if !added {
let (atom, found) = add_fraction_space_in(atom);
added = found;
out.push(atom);
} else {
out.push(atom);
}
}
(MathAtom::Row(out), added)
}
MathAtom::Delimited { left, right, body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Delimited {
left,
right,
body: Box::new(body),
},
added,
)
}
MathAtom::Classed { class, body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Classed {
class,
body: Box::new(body),
},
added,
)
}
MathAtom::Boxed { body } => {
let (body, added) = add_fraction_space_in(*body);
(
MathAtom::Boxed {
body: Box::new(body),
},
added,
)
}
MathAtom::Sqrt { radicand, degree } => {
let (radicand, added) = add_fraction_space_in(*radicand);
(
MathAtom::Sqrt {
radicand: Box::new(radicand),
degree,
},
added,
)
}
other => (other, false),
}
}
fn build_document_with_labels(
paragraphs: &[SourceParagraph],
geometry: &PageGeometry,
@@ -14074,6 +14147,13 @@ fn build_document_with_labels(
centered: paragraph.align_centered,
}
};
let atom = if geometry.roman_family.as_deref() == Some("ptm")
&& (paragraph.equation_tag.is_some() || paragraph.equation_number.is_some())
{
add_display_fraction_space(atom)
} else {
atom
};
let tag = paragraph.equation_tag.clone().or_else(|| {
paragraph
.equation_number
@@ -19984,6 +20064,19 @@ left & right \\
assert!(body.contains("Visible text."), "{body}");
}
#[test]
fn display_fraction_gap_widens_the_math_box() {
let atom = texrra_tex_core::math::parse_math(r"x={\frac{a}{b}}");
let font = texrra_tex_core::cmr10::Cmr10Metrics::Math;
let before = texrra_tex_core::math::layout_math(&atom, &font).width;
let after =
texrra_tex_core::math::layout_math(&add_display_fraction_space(atom), &font).width;
assert!(
after >= before + 16 * SCALE,
"fraction gap did not widen: {before} -> {after}"
);
}
#[test]
fn orcid_marker_becomes_a_badge_image() {
let mut list = DisplayList::default();