diff --git a/crates/typst-library/src/math/cancel.rs b/crates/typst-library/src/math/cancel.rs index 16e4067a7..455750f7a 100644 --- a/crates/typst-library/src/math/cancel.rs +++ b/crates/typst-library/src/math/cancel.rs @@ -108,7 +108,7 @@ impl LayoutMath for CancelElem { let length = self.length(styles).resolve(styles); let stroke = self.stroke(styles).unwrap_or(FixedStroke { - paint: TextElem::fill_in(styles), + paint: TextElem::fill_in(styles).as_decoration(), ..Default::default() }); diff --git a/crates/typst-library/src/math/frac.rs b/crates/typst-library/src/math/frac.rs index bd8d86bf0..c30141786 100644 --- a/crates/typst-library/src/math/frac.rs +++ b/crates/typst-library/src/math/frac.rs @@ -143,7 +143,7 @@ fn layout( line_pos, FrameItem::Shape( Geometry::Line(Point::with_x(line_width)).stroked(FixedStroke { - paint: TextElem::fill_in(ctx.styles()), + paint: TextElem::fill_in(ctx.styles()).as_decoration(), thickness, ..FixedStroke::default() }), diff --git a/crates/typst-library/src/math/fragment.rs b/crates/typst-library/src/math/fragment.rs index a40ed2bfe..76ee2512f 100644 --- a/crates/typst-library/src/math/fragment.rs +++ b/crates/typst-library/src/math/fragment.rs @@ -225,7 +225,7 @@ impl GlyphFragment { c, font: ctx.font.clone(), lang: TextElem::lang_in(ctx.styles()), - fill: TextElem::fill_in(ctx.styles()), + fill: TextElem::fill_in(ctx.styles()).as_decoration(), shift: TextElem::baseline_in(ctx.styles()), style: ctx.style, font_size: ctx.size, diff --git a/crates/typst-library/src/math/matrix.rs b/crates/typst-library/src/math/matrix.rs index b54da5d60..4142d2357 100644 --- a/crates/typst-library/src/math/matrix.rs +++ b/crates/typst-library/src/math/matrix.rs @@ -397,7 +397,7 @@ fn layout_mat_body( let default_stroke_thickness = DEFAULT_STROKE_THICKNESS.scaled(ctx); let default_stroke = FixedStroke { thickness: default_stroke_thickness, - paint: TextElem::fill_in(ctx.styles()), + paint: TextElem::fill_in(ctx.styles()).as_decoration(), line_cap: LineCap::Square, ..Default::default() }; diff --git a/crates/typst-library/src/math/root.rs b/crates/typst-library/src/math/root.rs index 13c5c1478..ba918ea94 100644 --- a/crates/typst-library/src/math/root.rs +++ b/crates/typst-library/src/math/root.rs @@ -122,7 +122,7 @@ fn layout( line_pos, FrameItem::Shape( Geometry::Line(Point::with_x(radicand.width())).stroked(FixedStroke { - paint: TextElem::fill_in(ctx.styles()), + paint: TextElem::fill_in(ctx.styles()).as_decoration(), thickness, ..FixedStroke::default() }), diff --git a/crates/typst-library/src/math/underover.rs b/crates/typst-library/src/math/underover.rs index aeb83061f..6fc768300 100644 --- a/crates/typst-library/src/math/underover.rs +++ b/crates/typst-library/src/math/underover.rs @@ -96,7 +96,7 @@ fn layout_underoverline( line_pos, FrameItem::Shape( Geometry::Line(Point::with_x(width)).stroked(FixedStroke { - paint: TextElem::fill_in(ctx.styles()), + paint: TextElem::fill_in(ctx.styles()).as_decoration(), thickness: bar_height, ..FixedStroke::default() }), diff --git a/tests/ref/visualize/gradient-math.png b/tests/ref/visualize/gradient-math.png new file mode 100644 index 000000000..13185bec7 Binary files /dev/null and b/tests/ref/visualize/gradient-math.png differ diff --git a/tests/typ/visualize/gradient-math.typ b/tests/typ/visualize/gradient-math.typ new file mode 100644 index 000000000..2030ecbbb --- /dev/null +++ b/tests/typ/visualize/gradient-math.typ @@ -0,0 +1,68 @@ +// Test that gradients are applied correctly on equations. + +--- +// Test on cancel +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ a dot cancel(5) = cancel(25) 5 x + cancel(5) 1 $ + +--- +// Test on frac +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ nabla dot bold(E) = frac(rho, epsilon_0) $ + +--- +// Test on root +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ x_"1,2" = frac(-b +- sqrt(b^2 - 4 a c), 2 a) $ + +--- +// Test on matrix +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ A = mat( + 1, 2, 3; + 4, 5, 6; + 7, 8, 9 +) $ + +--- +// Test on underover +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ underline(X^2) $ +$ overline("hello, world!") $ + +--- +// Test a different direction +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow, dir: ttb)) +#show math.equation: box + +$ A = mat( + 1, 2, 3; + 4, 5, 6; + 7, 8, 9 +) $ + +$ x_"1,2" = frac(-b +- sqrt(b^2 - 4 a c), 2 a) $ + +--- +// Test miscelaneous + +#show math.equation: set text(fill: gradient.linear(..color.map.rainbow)) +#show math.equation: box + +$ hat(x) = bar x bar = vec(x, y, z) = tilde(x) = dot(x) $ +$ x prime = vec(1, 2, delim: "[") $ +$ sum_(i in NN) 1 + i $ +$ attach( + Pi, t: alpha, b: beta, + tl: 1, tr: 2+3, bl: 4+5, br: 6, +) $