diff options
| author | Malo <57839069+MDLC01@users.noreply.github.com> | 2024-01-25 16:14:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-25 15:14:12 +0000 |
| commit | 02b16bf9cfd2f0dc095055487434a94a63485eeb (patch) | |
| tree | 78ef8485278d1e59aa9726740831bb8361aebd10 | |
| parent | 11abc1f1e34153d2c89589ca89bf84ef2c358817 (diff) | |
Make `math.class` affect the limit configuration (#3231)
| -rw-r--r-- | crates/typst/src/math/attach.rs | 9 | ||||
| -rw-r--r-- | crates/typst/src/math/class.rs | 8 | ||||
| -rw-r--r-- | tests/ref/math/class.png | bin | 6460 -> 7599 bytes | |||
| -rw-r--r-- | tests/typ/math/class.typ | 12 |
4 files changed, 26 insertions, 3 deletions
diff --git a/crates/typst/src/math/attach.rs b/crates/typst/src/math/attach.rs index ff66a386..09541d1c 100644 --- a/crates/typst/src/math/attach.rs +++ b/crates/typst/src/math/attach.rs @@ -212,6 +212,15 @@ impl Limits { } } + /// The default limit configuration for a math class. + pub fn for_class(class: MathClass) -> Self { + match class { + MathClass::Large => Self::Display, + MathClass::Relation => Self::Always, + _ => Self::Never, + } + } + /// Whether limits should be displayed in this context pub fn active(&self, ctx: &MathContext) -> bool { match self { diff --git a/crates/typst/src/math/class.rs b/crates/typst/src/math/class.rs index 9f430ad7..1b6c638c 100644 --- a/crates/typst/src/math/class.rs +++ b/crates/typst/src/math/class.rs @@ -2,12 +2,15 @@ use unicode_math_class::MathClass; use crate::diag::SourceResult; use crate::foundations::{elem, Content, Packed}; -use crate::math::{LayoutMath, MathContext}; +use crate::math::{LayoutMath, Limits, MathContext}; /// Forced use of a certain math class. /// /// This is useful to treat certain symbols as if they were of a different -/// class, e.g. to make a symbol behave like a relation. +/// class, e.g. to make a symbol behave like a relation. The class of a symbol +/// defines the way it is laid out, including spacing around it, and how its +/// scripts are attached by default. Note that the latter can always be +/// overridden using [`{limits}`](math.limits) and [`{scripts}`](math.scripts). /// /// # Example /// ```example @@ -37,6 +40,7 @@ impl LayoutMath for Packed<ClassElem> { ctx.unstyle(); fragment.set_class(*self.class()); + fragment.set_limits(Limits::for_class(*self.class())); ctx.push(fragment); Ok(()) } diff --git a/tests/ref/math/class.png b/tests/ref/math/class.png Binary files differindex 27844ebe..a54dbd67 100644 --- a/tests/ref/math/class.png +++ b/tests/ref/math/class.png diff --git a/tests/typ/math/class.typ b/tests/typ/math/class.typ index 0c9fa32b..a5901b31 100644 --- a/tests/typ/math/class.typ +++ b/tests/typ/math/class.typ @@ -34,4 +34,14 @@ $ a pluseq 5 $ --- // Test exceptions. -$ sqrt(3)\/2 quad d_0.d_1d_2 dots $
\ No newline at end of file +$ sqrt(3)\/2 quad d_0.d_1d_2 dots $ + +--- +// Test if the math class changes the limit configuration. +$ class("normal", ->)_a $ +$class("relation", x)_a$ +$ class("large", x)_a $ +$class("large", ->)_a$ + +$limits(class("normal", ->))_a$ +$ scripts(class("relation", x))_a $ |
