diff options
| author | Alex Saveau <saveau.alexandre@gmail.com> | 2023-04-24 02:04:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-24 11:04:04 +0200 |
| commit | 5ccc6876194a3f9329021bf22e7c8d0ed6bf74a1 (patch) | |
| tree | 672bc2785e52ef643bd7ab20a172af8dfe96ff8e | |
| parent | e5ea3ecbbb2cebe1f602996dff911d07e2f7741d (diff) | |
Obey alignment in matrices (#892)
| -rw-r--r-- | library/src/math/matrix.rs | 6 | ||||
| -rw-r--r-- | tests/ref/math/alignment.png | bin | 9752 -> 23935 bytes | |||
| -rw-r--r-- | tests/typ/math/alignment.typ | 79 |
3 files changed, 76 insertions, 9 deletions
diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs index 2243eb38..956c7f8a 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<Content>]) -> 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 Binary files differindex 45b0cd86..2e3c3d5d 100644 --- a/tests/ref/math/alignment.png +++ b/tests/ref/math/alignment.png diff --git a/tests/typ/math/alignment.typ b/tests/typ/math/alignment.typ index 8482d89e..70c52d37 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) $ |
