diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs index 2243eb386..956c7f8af 100644 --- a/library/src/math/matrix.rs +++ b/library/src/math/matrix.rs @@ -272,8 +272,10 @@ fn layout_mat_body(ctx: &mut MathContext, rows: &[Vec]) -> SourceResult let mut y = Abs::zero(); for ((cell, &ascent), &descent) in col.into_iter().zip(&ascents).zip(&descents) { let cell = cell.into_aligned_frame(ctx, &points, Align::Center); - let pos = - Point::new(x + (rcol - cell.width()) / 2.0, y + ascent - cell.ascent()); + let pos = Point::new( + if points.is_empty() { x + (rcol - cell.width()) / 2.0 } else { x }, + y + ascent - cell.ascent(), + ); frame.push_frame(pos, cell); y += ascent + descent + row_gap; } diff --git a/tests/ref/math/alignment.png b/tests/ref/math/alignment.png index 45b0cd862..2e3c3d5dd 100644 Binary files a/tests/ref/math/alignment.png and b/tests/ref/math/alignment.png differ diff --git a/tests/typ/math/alignment.typ b/tests/typ/math/alignment.typ index 8482d89ee..70c52d376 100644 --- a/tests/typ/math/alignment.typ +++ b/tests/typ/math/alignment.typ @@ -2,9 +2,8 @@ --- // Test alignment step functions. -#set page(width: 300pt) $ -"abc" &= c \ +"a" &= c \ &= c + 1 & "By definition" \ &= d + 100 + 1000 \ &= x && "Even longer" \ @@ -12,17 +11,83 @@ $ --- // Test post-fix alignment. -#set page(width: 300pt) $ & "right" \ "a very long line" \ +"left" \ +$ + +--- +// Test no alignment. +$ +"right" \ +"a very long line" \ +"left" \ $ --- // Test alternating alignment. -#set page(width: 300pt) $ -"abc" & "abc abc abc" & "abc abc" \ -"abc abc" & "abc abc" & "abc" \ -"abc abc abc" & "abc" & "abc abc abc" \ +"a" & "a a a" & "a a" \ +"a a" & "a a" & "a" \ +"a a a" & "a" & "a a a" \ $ + +--- +// Test alternating alignment in a vector. +$ vec( + "a" & "a a a" & "a a", + "a a" & "a a" & "a", + "a a a" & "a" & "a a a", +) $ + +--- +// Test alternating explicit alignment in a matrix. +$ mat( + "a" & "a a a" & "a a"; + "a a" & "a a" & "a"; + "a a a" & "a" & "a a a"; +) $ + +--- +// Test alignment in a matrix. +$ mat( + "a", "a a a", "a a"; + "a a", "a a", "a"; + "a a a", "a", "a a a"; +) $ + +--- +// Test explicit left alignment in a matrix. +$ mat( + &"a", &"a a a", &"a a"; + &"a a", &"a a", &"a"; + &"a a a", &"a", &"a a a"; +) $ + +--- +// Test explicit right alignment in a matrix. +$ mat( + "a"&, "a a a"&, "a a"&; + "a a"&, "a a"&, "a"&; + "a a a"&, "a"&, "a a a"&; +) $ + +--- +// Test #460 equations. +$ +a &=b & quad c&=d \ +e &=f & g&=h +$ + +$ mat(&a+b,c;&d, e) $ +$ mat(&a+b&,c;&d&, e) $ +$ mat(&&&a+b,c;&&&d, e) $ +$ mat(.&a+b&.,c;.....&d&....., e) $ + +--- +// Test #454 equations. +$ mat(-1, 1, 1; 1, -1, 1; 1, 1, -1) $ +$ mat(-1&, 1&, 1&; 1&, -1&, 1&; 1&, 1&, -1&) $ +$ mat(-1&, 1&, 1&; 1, -1, 1; 1, 1, -1) $ +$ mat(&-1, &1, &1; 1, -1, 1; 1, 1, -1) $