diff --git a/crates/typst-layout/src/math/attach.rs b/crates/typst-layout/src/math/attach.rs index 0f9090f77..cda033159 100644 --- a/crates/typst-layout/src/math/attach.rs +++ b/crates/typst-layout/src/math/attach.rs @@ -161,7 +161,7 @@ fn stretch_size( ) -> Option>> { // Extract from an EquationElem. let mut base = elem.base(); - if let Some(equation) = base.to_packed::() { + while let Some(equation) = base.to_packed::() { base = equation.body(); } diff --git a/crates/typst-library/src/math/attach.rs b/crates/typst-library/src/math/attach.rs index 74eabd101..f3c7ea99f 100644 --- a/crates/typst-library/src/math/attach.rs +++ b/crates/typst-library/src/math/attach.rs @@ -48,7 +48,7 @@ impl Packed { pub fn merge_base(&self) -> Option { // Extract from an EquationElem. let mut base = self.base(); - if let Some(equation) = base.to_packed::() { + while let Some(equation) = base.to_packed::() { base = equation.body(); } diff --git a/tests/ref/math-attach-nested-base.png b/tests/ref/math-attach-nested-base.png index 54c623872..4b8126e74 100644 Binary files a/tests/ref/math-attach-nested-base.png and b/tests/ref/math-attach-nested-base.png differ diff --git a/tests/ref/math-attach-nested-deep-base.png b/tests/ref/math-attach-nested-deep-base.png new file mode 100644 index 000000000..e745e6b67 Binary files /dev/null and b/tests/ref/math-attach-nested-deep-base.png differ diff --git a/tests/ref/math-stretch-attach-nested-equation.png b/tests/ref/math-stretch-attach-nested-equation.png index 5ab4fbb51..3ddb0d00d 100644 Binary files a/tests/ref/math-stretch-attach-nested-equation.png and b/tests/ref/math-stretch-attach-nested-equation.png differ diff --git a/tests/suite/math/attach.typ b/tests/suite/math/attach.typ index 56fa47c58..cedc3a4ab 100644 --- a/tests/suite/math/attach.typ +++ b/tests/suite/math/attach.typ @@ -167,9 +167,22 @@ $ attach(a^b, b: c) quad #let a0 = math.attach(math.alpha, b: [0]) #let a1 = $alpha^1$ +#let a2 = $attach(a1, bl: 3)$ $ a0 + a1 + a0_2 \ - a1_2 + a0^2 + a1^2 $ + a1_2 + a0^2 + a1^2 \ + a2 + a2_2 + a2^2 $ + +--- math-attach-nested-deep-base --- +// Test attachments when the base has attachments and is nested arbitrarily +// deep. +#{ + let var = $x^1$ + for i in range(24) { + var = $var$ + } + $var_2$ +} --- math-attach-scripts-extended-shapes --- // Test script attachments positioning if the base is an extended shape (or a diff --git a/tests/suite/math/stretch.typ b/tests/suite/math/stretch.typ index 6bf13e255..1377f4d21 100644 --- a/tests/suite/math/stretch.typ +++ b/tests/suite/math/stretch.typ @@ -83,3 +83,11 @@ $ stretch(base, size: #50%) $ // Test stretching with attachments when nested in an equation. #let body = $stretch(=)$ $ body^"text" $ + +#{ + let body = $stretch(=)$ + for i in range(24) { + body = $body$ + } + $body^"long text"$ +}