diff options
| author | frozolotl <44589151+frozolotl@users.noreply.github.com> | 2023-11-13 12:26:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-13 12:26:58 +0100 |
| commit | 67422e664b9e7089e8eb4de65c5a25b2817a00c0 (patch) | |
| tree | b692e4a91728e7286da38c2fffb2e3a5744f53c4 /crates/typst-library/src/math | |
| parent | 8219ec259511f4f2f03b8921a4f20f3a39c43821 (diff) | |
Allow non-string contents for math operators (#2663)
Diffstat (limited to 'crates/typst-library/src/math')
| -rw-r--r-- | crates/typst-library/src/math/op.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/typst-library/src/math/op.rs b/crates/typst-library/src/math/op.rs index b4c36002..8f44b3e1 100644 --- a/crates/typst-library/src/math/op.rs +++ b/crates/typst-library/src/math/op.rs @@ -21,7 +21,7 @@ use super::*; pub struct OpElem { /// The operator's text. #[required] - pub text: EcoString, + pub text: Content, /// Whether the operator should show attachments as limits in display mode. #[default(false)] @@ -31,8 +31,7 @@ pub struct OpElem { impl LayoutMath for OpElem { #[tracing::instrument(skip(ctx))] fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> { - let fragment = - ctx.layout_text(&TextElem::new(self.text().clone()).spanned(self.span()))?; + let fragment = ctx.layout_fragment(self.text())?; ctx.push( FrameFragment::new(ctx, fragment.into_frame()) .with_class(MathClass::Large) @@ -49,12 +48,15 @@ impl LayoutMath for OpElem { macro_rules! ops { ($($name:ident $(: $value:literal)? $(($tts:tt))?),* $(,)?) => { pub(super) fn define(math: &mut Scope) { - $(math.define( - stringify!($name), - OpElem::new(ops!(@name $name $(: $value)?).into()) - .with_limits(ops!(@limit $($tts)*)) - .pack() - );)* + $({ + let operator = EcoString::from(ops!(@name $name $(: $value)?)); + math.define( + stringify!($name), + OpElem::new(TextElem::new(operator).into()) + .with_limits(ops!(@limit $($tts)*)) + .pack() + ); + })* let dif = |d| { HElem::new(THIN.into()).with_weak(true).pack() |
