From 02b16bf9cfd2f0dc095055487434a94a63485eeb Mon Sep 17 00:00:00 2001 From: Malo <57839069+MDLC01@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:14:12 +0100 Subject: [PATCH] Make `math.class` affect the limit configuration (#3231) --- crates/typst/src/math/attach.rs | 9 +++++++++ crates/typst/src/math/class.rs | 8 ++++++-- tests/ref/math/class.png | Bin 6460 -> 7599 bytes 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 ff66a3867..09541d1ca 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 9f430ad70..1b6c638ca 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 { 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 index 27844ebe1410d073e4d759be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gnwmF#@Q$*oh$I@Q%ZoSb(CQ*{8BLkJi8D$ zEKL2!rsD04g=Om|!YT1eRSGJ{yw`zhB^ltE8r(*s57yToE=xhnm7q$fQ$Dh-Cw&L7 zqy?ziIE5>?6po1^`&wW~jgYqp9IHdvd-}Z62HBy&RQf@nas5SbX1q675r~@?-hYM1 zX9>U0bQtfw4A>UgaeG3z?M2hRH5WeE8CAUfXQK0g`-*`C(F=u-nm>6pW`9nTH^R`e zx^rp!7j~yWvlCJu1kQ^U!1JO8Ok(+*MW|O2xvFc+lSw5Gfbxx~st>uD(AJWB9Ls@r zxU&dY^%^kz3qV_L14D&vcq1@e_J6LG#-a%T`sW`9XdeV@tuEm7z??;J#h*dLW6cD{ zSOl!h!Jj9BztL6S>HgY0V000fxIEyVlIx5xx~79py+_F3Nr3jO1N(gQ^+g!jFn}vf z?-8Q92#_tdb#g~88jilBy!8#fCL;|u8bpfTBb*^%|J3C+prx_t#E;+OYfAj+f4b!Y zC1*GpK}L`fWCR&OMvxI?1Q|g_kP&1A89_#n5o81zK}L{o$0SLTBuSE_|Al`6V_9bo Tv-?p>00000NkvXXu0mjf-zU}{ diff --git a/tests/typ/math/class.typ b/tests/typ/math/class.typ index 0c9fa32b4..a5901b31d 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 $