diff options
| author | damaxwell <damaxwell@alaska.edu> | 2023-08-02 14:27:33 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-03 00:27:33 +0200 |
| commit | cd163868f5a93f84a9185d14407a66d051e29dad (patch) | |
| tree | 1ed42606bda5c7c9ab6af1f9a29446e67954d39c | |
| parent | 3c94e05cedcb308d83028bfb42e19b29c1201ac1 (diff) | |
large operators have limits in displays; relations have limits always (#1748)
| -rw-r--r-- | crates/typst-library/src/math/attach.rs | 31 | ||||
| -rw-r--r-- | tests/ref/math/attach-p3.png | bin | 5860 -> 15600 bytes | |||
| -rw-r--r-- | tests/typ/math/attach-p3.typ | 18 |
3 files changed, 33 insertions, 16 deletions
diff --git a/crates/typst-library/src/math/attach.rs b/crates/typst-library/src/math/attach.rs index ee65b657..d74beafe 100644 --- a/crates/typst-library/src/math/attach.rs +++ b/crates/typst-library/src/math/attach.rs @@ -216,10 +216,16 @@ pub enum Limits { impl Limits { /// The default limit configuration if the given character is the base. pub fn for_char(c: char) -> Self { - if Self::DEFAULT_TO_LIMITS.contains(&c) { - Limits::Display - } else { - Limits::Never + match unicode_math_class::class(c) { + Some(MathClass::Large) => { + if is_integral_char(c) { + Limits::Never + } else { + Limits::Display + } + } + Some(MathClass::Relation) => Limits::Always, + _ => Limits::Never, } } @@ -231,18 +237,6 @@ impl Limits { Self::Never => false, } } - - /// Unicode codepoints that should show attachments as limits in display - /// mode. - #[rustfmt::skip] - const DEFAULT_TO_LIMITS: &[char] = &[ - /* ∏ */ '\u{220F}', /* ∐ */ '\u{2210}', /* ∑ */ '\u{2211}', - /* ⋀ */ '\u{22C0}', /* ⋁ */ '\u{22C1}', - /* ⋂ */ '\u{22C2}', /* ⋃ */ '\u{22C3}', - /* ⨀ */ '\u{2A00}', /* ⨁ */ '\u{2A01}', /* ⨂ */ '\u{2A02}', - /* ⨃ */ '\u{2A03}', /* ⨄ */ '\u{2A04}', - /* ⨅ */ '\u{2A05}', /* ⨆ */ '\u{2A06}', - ]; } macro_rules! measure { @@ -444,6 +438,11 @@ fn compute_shifts_up_and_down( (shift_up, shift_down) } +/// Determines if the character is one of a variety of integral signs +fn is_integral_char(c: char) -> bool { + ('∫'..='∳').contains(&c) || ('⨋'..='⨜').contains(&c) +} + /// Whether the fragment consists of a single character or atomic piece of text. fn is_character_box(fragment: &MathFragment) -> bool { match fragment { diff --git a/tests/ref/math/attach-p3.png b/tests/ref/math/attach-p3.png Binary files differindex ac3c3895..104534b7 100644 --- a/tests/ref/math/attach-p3.png +++ b/tests/ref/math/attach-p3.png diff --git a/tests/typ/math/attach-p3.typ b/tests/typ/math/attach-p3.typ index 0fc25d63..c681af2a 100644 --- a/tests/typ/math/attach-p3.typ +++ b/tests/typ/math/attach-p3.typ @@ -22,3 +22,21 @@ $ attach(A, t: #locate(it => oops)) $ #show math.iota: math.limits.with(inline: false) #eq $iota_a^b$ + +--- +// Test default of limit attachments on relations at all sizes +#set page(width: auto) +$ a =^"def" b quad a lt.eq_"really" b quad a arrow.r.long.squiggly^"slowly" b $ +$a =^"def" b quad a lt.eq_"really" b quad a arrow.r.long.squiggly^"slowly" b$ + +$a scripts(=)^"def" b quad a scripts(lt.eq)_"really" b quad a scripts(arrow.r.long.squiggly)^"slowly" b$ + +--- +// Test default of scripts attachments on integrals at display size +$ integral.sect_a^b quad \u{2a1b}_a^b quad limits(\u{2a1b})_a^b $ +$integral.sect_a^b quad \u{2a1b}_a^b quad limits(\u{2a1b})_a^b$ + +--- +// Test default of limit attachments on large operators at display size only +$ tack.t.big_0^1 quad \u{02A0A}_0^1 quad join_0^1 $ +$tack.t.big_0^1 quad \u{02A0A}_0^1 quad join_0^1$ |
