summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-07-15 05:54:54 -0400
committerGitHub <noreply@github.com>2024-07-15 09:54:54 +0000
commitf0407d4949cce8014e2a4fdef8c00c955d870127 (patch)
treea5cc7754e76ea8f342a7873c796f81b2a69cf041
parentac322e342b4736bea189f5e7ac39561c0e5a3127 (diff)
Wrapping with parens should not push superscripts higher (#4545)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
-rw-r--r--crates/typst/src/math/row.rs15
-rw-r--r--tests/ref/math-attach-horizontal-align.pngbin2001 -> 1900 bytes
-rw-r--r--tests/ref/math-attach-to-group.pngbin651 -> 649 bytes
-rw-r--r--tests/ref/math-root-large-body.pngbin1614 -> 1549 bytes
-rw-r--r--tests/suite/math/attach.typ4
5 files changed, 14 insertions, 5 deletions
diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs
index 5234ca2c..60afe64e 100644
--- a/crates/typst/src/math/row.rs
+++ b/crates/typst/src/math/row.rs
@@ -159,10 +159,19 @@ impl MathRun {
pub fn into_fragment(self, ctx: &MathContext, styles: StyleChain) -> MathFragment {
if self.0.len() == 1 {
- self.0.into_iter().next().unwrap()
- } else {
- FrameFragment::new(ctx, styles, self.into_frame(ctx, styles)).into()
+ return self.0.into_iter().next().unwrap();
}
+
+ // Fragments without a math_size are ignored: the notion of size do not
+ // apply to them, so their text-likeness is meaningless.
+ let text_like = self
+ .iter()
+ .filter(|e| e.math_size().is_some())
+ .all(|e| e.is_text_like());
+
+ FrameFragment::new(ctx, styles, self.into_frame(ctx, styles))
+ .with_text_like(text_like)
+ .into()
}
/// Returns a builder that lays out the [`MathFragment`]s into a possibly
diff --git a/tests/ref/math-attach-horizontal-align.png b/tests/ref/math-attach-horizontal-align.png
index 507cb0ff..8aa2a376 100644
--- a/tests/ref/math-attach-horizontal-align.png
+++ b/tests/ref/math-attach-horizontal-align.png
Binary files differ
diff --git a/tests/ref/math-attach-to-group.png b/tests/ref/math-attach-to-group.png
index a3d1923e..ea4115fc 100644
--- a/tests/ref/math-attach-to-group.png
+++ b/tests/ref/math-attach-to-group.png
Binary files differ
diff --git a/tests/ref/math-root-large-body.png b/tests/ref/math-root-large-body.png
index 3dd4d848..b8d9edfb 100644
--- a/tests/ref/math-root-large-body.png
+++ b/tests/ref/math-root-large-body.png
Binary files differ
diff --git a/tests/suite/math/attach.typ b/tests/suite/math/attach.typ
index c9510c6a..c5ca5735 100644
--- a/tests/suite/math/attach.typ
+++ b/tests/suite/math/attach.typ
@@ -84,9 +84,9 @@ $ (-1)^n + (1/2 + 3)^(-1/2) $
// Test that the attachments are aligned horizontally.
$ x_1 p_1 frak(p)_1 2_1 dot_1 lg_1 !_1 \\_1 ]_1 "ip"_1 op("iq")_1 \
x^1 b^1 frak(b)^1 2^1 dot^1 lg^1 !^1 \\^1 ]^1 "ib"^1 op("id")^1 \
- x_1 y_1 "_"_1 x^1 l^1 "`"^1 attach(I,tl:1,bl:1,tr:1,br:1)
+ "_"_1 "`"^1 x_1 y_1 x^1 l^1 attach(I,tl:1,bl:1,tr:1,br:1)
scripts(sum)_1^1 integral_1^1 abs(1/2)_1^1 \
- x^1_1, "("b y")"^1_1 != (b y)^1_1, "[∫]"_1 [integral]_1 $
+ x^1_1, ")"^1_1 (b y)^1_1, "[∫]"_1 [integral]_1 $
--- math-attach-limit ---
// Test limit.