diff --git a/crates/typst-layout/src/math/mat.rs b/crates/typst-layout/src/math/mat.rs index 6c8b04553..24104f4ee 100644 --- a/crates/typst-layout/src/math/mat.rs +++ b/crates/typst-layout/src/math/mat.rs @@ -127,7 +127,9 @@ fn layout_vec_body( let denom_style = style_for_denominator(styles); let mut flat = vec![]; for child in column { - flat.push(ctx.layout_into_run(child, styles.chain(&denom_style))?); + // We allow linebreaks in cases and vectors, which are functionally + // identical to commas. + flat.extend(ctx.layout_into_run(child, styles.chain(&denom_style))?.rows()); } // We pad ascent and descent with the ascent and descent of the paren // to ensure that normal vectors are aligned with others unless they are diff --git a/crates/typst-layout/src/math/shared.rs b/crates/typst-layout/src/math/shared.rs index 13477c10b..74e62e8f0 100644 --- a/crates/typst-layout/src/math/shared.rs +++ b/crates/typst-layout/src/math/shared.rs @@ -121,7 +121,6 @@ pub fn stack( alternator: LeftRightAlternator, minimum_ascent_descent: Option<(Abs, Abs)>, ) -> Frame { - let rows: Vec<_> = rows.into_iter().flat_map(|r| r.rows()).collect(); let AlignmentResult { points, width } = alignments(&rows); let rows: Vec<_> = rows .into_iter() diff --git a/crates/typst-layout/src/math/underover.rs b/crates/typst-layout/src/math/underover.rs index b1d4825b6..1a2c8db66 100644 --- a/crates/typst-layout/src/math/underover.rs +++ b/crates/typst-layout/src/math/underover.rs @@ -297,7 +297,7 @@ fn layout_underoverspreader( if let Some(annotation) = annotation { let under_style = style_for_subscript(styles); let annotation_styles = styles.chain(&under_style); - rows.push(ctx.layout_into_run(annotation, annotation_styles)?); + rows.extend(ctx.layout_into_run(annotation, annotation_styles)?.rows()); } 0 } @@ -305,7 +305,7 @@ fn layout_underoverspreader( if let Some(annotation) = annotation { let over_style = style_for_superscript(styles); let annotation_styles = styles.chain(&over_style); - rows.push(ctx.layout_into_run(annotation, annotation_styles)?); + rows.extend(ctx.layout_into_run(annotation, annotation_styles)?.rows()); } rows.push(stretched.into()); rows.push(MathRun::new(vec![body])); diff --git a/tests/ref/math-cases-linebreaks.png b/tests/ref/math-cases-linebreaks.png new file mode 100644 index 000000000..543d5384c Binary files /dev/null and b/tests/ref/math-cases-linebreaks.png differ diff --git a/tests/ref/math-mat-linebreaks.png b/tests/ref/math-mat-linebreaks.png new file mode 100644 index 000000000..52ff0a8bb Binary files /dev/null and b/tests/ref/math-mat-linebreaks.png differ diff --git a/tests/ref/math-underover-multiline-annotation.png b/tests/ref/math-underover-multiline-annotation.png new file mode 100644 index 000000000..ad8f0c802 Binary files /dev/null and b/tests/ref/math-underover-multiline-annotation.png differ diff --git a/tests/ref/math-vec-linebreaks.png b/tests/ref/math-vec-linebreaks.png new file mode 100644 index 000000000..6eeed42b8 Binary files /dev/null and b/tests/ref/math-vec-linebreaks.png differ diff --git a/tests/suite/math/cases.typ b/tests/suite/math/cases.typ index 2cf48e6f7..1c7b4a6b4 100644 --- a/tests/suite/math/cases.typ +++ b/tests/suite/math/cases.typ @@ -15,3 +15,8 @@ $ x = cases(1, 2) $ --- math-cases-delim --- #set math.cases(delim: sym.angle.l) $ cases(a, b, c) $ + +--- math-cases-linebreaks --- +// Currently linebreaks are equivalent to commas, though this behaviour may +// change in the future. +$ cases(a, b, c) cases(reverse: #true, a \ b \ c) $ diff --git a/tests/suite/math/mat.typ b/tests/suite/math/mat.typ index baec53eee..391ff1677 100644 --- a/tests/suite/math/mat.typ +++ b/tests/suite/math/mat.typ @@ -229,6 +229,11 @@ $ mat(delim: angle.r, 1, 2; 3, 4) $ $ mat(delim: #(none, "["), 1, 2; 3, 4) $ $ mat(delim: #(sym.angle.r, sym.bracket.double.r), 1, 2; 3, 4) $ +--- math-mat-linebreaks --- +// Unlike cases and vectors, linebreaks are discarded in matrices. This +// behaviour may change in the future. +$ mat(a; b; c) mat(a \ b \ c) $ + --- issue-1617-mat-align --- #set page(width: auto) $ mat(a, b; c, d) mat(x; y) $ diff --git a/tests/suite/math/underover.typ b/tests/suite/math/underover.typ index 5eca70b3a..600ccf7c6 100644 --- a/tests/suite/math/underover.typ +++ b/tests/suite/math/underover.typ @@ -45,3 +45,10 @@ $A_2 != overline(A)_2 != underline(A)_2 != underline(overline(A))_2 \ $J^b != overline(J)^b != underline(J)^b != underline(overline(J))^b \ K^3 != overline(K)^3 != underline(K)^3 != underline(overline(K))^3 \ T^i != overline(T)^i != underline(T)^i != underline(overline(T))^i$ + +--- math-underover-multiline-annotation --- +// Test that multiline annotations do not change the baseline. +$ S = overbrace(beta (alpha) S I, "one line") + - overbrace(mu (N), "two" \ "line") $ +$ S = underbrace(beta (alpha) S I, "one line") + - underbrace(mu (N), "two" \ "line") $ diff --git a/tests/suite/math/vec.typ b/tests/suite/math/vec.typ index cf7057f33..5de7eca94 100644 --- a/tests/suite/math/vec.typ +++ b/tests/suite/math/vec.typ @@ -49,3 +49,8 @@ $ vec(1, 2) $ --- math-vec-delim-invalid-closing --- // Error: 22-33 invalid delimiter: "%" #set math.vec(delim: (none, "%")) + +--- math-vec-linebreaks --- +// Currently linebreaks are equivalent to commas, though this behaviour may +// change in the future. +$ vec(a, b, c) vec(a \ b \ c) $