diff --git a/crates/typst-layout/src/math/fragment.rs b/crates/typst-layout/src/math/fragment.rs index 3497587c..fce0ca30 100644 --- a/crates/typst-layout/src/math/fragment.rs +++ b/crates/typst-layout/src/math/fragment.rs @@ -739,7 +739,9 @@ fn assemble( } advance -= max_overlap; - growable += max_overlap - min_overlap; + // In case we have that max_overlap < min_overlap, ensure we + // don't decrease the value of growable. + growable += (max_overlap - min_overlap).max(Abs::zero()); } full += advance; diff --git a/tests/ref/math-stretch-min-overlap-exceeds-max.png b/tests/ref/math-stretch-min-overlap-exceeds-max.png new file mode 100644 index 00000000..a75437fd Binary files /dev/null and b/tests/ref/math-stretch-min-overlap-exceeds-max.png differ diff --git a/tests/suite/math/stretch.typ b/tests/suite/math/stretch.typ index d145f72a..80015540 100644 --- a/tests/suite/math/stretch.typ +++ b/tests/suite/math/stretch.typ @@ -91,3 +91,12 @@ $ body^"text" $ } $body^"long text"$ } + +--- math-stretch-min-overlap-exceeds-max --- +// Test that glyph assembly doesn't end up with negative lengths if the max +// overlap calculated is less than the minConnectorOverlap. +#show math.equation: set text(font: "STIX Two Math") +// Warning: glyph has assembly parts with overlap less than minConnectorOverlap +// Hint: its rendering may appear broken - this is probably a font bug +// Hint: please file an issue at https://github.com/typst/typst/issues +$ stretch(->)^"Gauss-Jordan Elimination" $