From 4f0fbfb7e003f6ae88c1b210fdb7b38f795fc9e4 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 31 Mar 2025 09:17:49 +0000 Subject: [PATCH] Add dotless parameter to `math.accent` (#5939) Co-authored-by: Laurenz --- crates/typst-layout/src/math/accent.rs | 6 +++-- crates/typst-library/src/math/accent.rs | 26 +++++++++++++++++++-- tests/ref/math-accent-dotless-disabled.png | Bin 0 -> 311 bytes tests/ref/math-accent-dotless-set-rule.png | Bin 0 -> 147 bytes tests/suite/math/accent.typ | 8 +++++++ 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/ref/math-accent-dotless-disabled.png create mode 100644 tests/ref/math-accent-dotless-set-rule.png diff --git a/crates/typst-layout/src/math/accent.rs b/crates/typst-layout/src/math/accent.rs index f2dfa2c45..73d821019 100644 --- a/crates/typst-layout/src/math/accent.rs +++ b/crates/typst-layout/src/math/accent.rs @@ -19,8 +19,10 @@ pub fn layout_accent( let mut base = ctx.layout_into_fragment(&elem.base, styles.chain(&cramped))?; // Try to replace a glyph with its dotless variant. - if let MathFragment::Glyph(glyph) = &mut base { - glyph.make_dotless_form(ctx); + if elem.dotless(styles) { + if let MathFragment::Glyph(glyph) = &mut base { + glyph.make_dotless_form(ctx); + } } // Preserve class to preserve automatic spacing. diff --git a/crates/typst-library/src/math/accent.rs b/crates/typst-library/src/math/accent.rs index b162c52b1..e62b63872 100644 --- a/crates/typst-library/src/math/accent.rs +++ b/crates/typst-library/src/math/accent.rs @@ -13,8 +13,8 @@ use crate::math::Mathy; /// ``` #[elem(Mathy)] pub struct AccentElem { - /// The base to which the accent is applied. - /// May consist of multiple letters. + /// The base to which the accent is applied. May consist of multiple + /// letters. /// /// ```example /// $arrow(A B C)$ @@ -51,9 +51,24 @@ pub struct AccentElem { pub accent: Accent, /// The size of the accent, relative to the width of the base. + /// + /// ```example + /// $dash(A, size: #150%)$ + /// ``` #[resolve] #[default(Rel::one())] pub size: Rel, + + /// Whether to remove the dot on top of lowercase i and j when adding a top + /// accent. + /// + /// This enables the `dtls` OpenType feature. + /// + /// ```example + /// $hat(dotless: #false, i)$ + /// ``` + #[default(true)] + pub dotless: bool, } /// An accent character. @@ -103,11 +118,18 @@ macro_rules! accents { /// The size of the accent, relative to the width of the base. #[named] size: Option>, + /// Whether to remove the dot on top of lowercase i and j when + /// adding a top accent. + #[named] + dotless: Option, ) -> Content { let mut accent = AccentElem::new(base, Accent::new($primary)); if let Some(size) = size { accent = accent.with_size(size); } + if let Some(dotless) = dotless { + accent = accent.with_dotless(dotless); + } accent.pack() } )+ diff --git a/tests/ref/math-accent-dotless-disabled.png b/tests/ref/math-accent-dotless-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..d75ec4580253f4b791384ba7e98bf209eab338c6 GIT binary patch literal 311 zcmV-70m%M|P)w)T5`r&Y`IJ`TyHLT3Y-rdKZLobSId4 z-n?iFMBq;YO@n&RpTm$K{`C_~z5IXo4^-+iO)dUB?-`iB2#e6G3nBF5`HyI7@rvb3 z!1T(HZ(#cNiR{N<#{B)gG`09&$Qwvp2SE6L|GPmMt$S%|@rU3O|6hPSxa1g+1_^}z ze+5p?KHq6-@tdMO{{yf7|G%c^;eX3_K!Ht@{x^X_|F+?005R4eF=Tc4^998002ov JPDHLkV1kDTnQ{OC literal 0 HcmV?d00001 diff --git a/tests/ref/math-accent-dotless-set-rule.png b/tests/ref/math-accent-dotless-set-rule.png new file mode 100644 index 0000000000000000000000000000000000000000..ae5ef017aaedc711d30182cd57d05de08e9f9397 GIT binary patch literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^6+kS@0VEh)%)UPdQc<2Rjv*Ddl7HAcG$dYm6xi*q zE4Q^mLFeDx!h{5!dmrnL|8C@bb+w*NqtBl|Kt{gaz(6eCR>a;wY=5+2azm5Vk88gh oH(J#EV)*&v_4zopr0MHjU3IG5A literal 0 HcmV?d00001 diff --git a/tests/suite/math/accent.typ b/tests/suite/math/accent.typ index 5be4f576f..ab0078a5f 100644 --- a/tests/suite/math/accent.typ +++ b/tests/suite/math/accent.typ @@ -42,3 +42,11 @@ $tilde(U, size: #1.1em), x^tilde(U, size: #1.1em), sscript(tilde(U, size: #1.1em macron(bb(#c)), dot(cal(#c)), diaer(upright(#c)), breve(bold(#c)), circle(bold(upright(#c))), caron(upright(sans(#c))), arrow(bold(frak(#c)))$ $test(i) \ test(j)$ + +--- math-accent-dotless-disabled --- +// Test disabling the dotless glyph variants. +$hat(i), hat(i, dotless: #false), accent(j, tilde), accent(j, tilde, dotless: #false)$ + +--- math-accent-dotless-set-rule --- +#set math.accent(dotless: false) +$ hat(i) $