diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index ce70f1de3..785e027ad 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -102,24 +102,24 @@ impl MathNode { } impl Show for MathNode { - fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult { - let mut map = StyleMap::new(); - map.set_family(FontFamily::new("NewComputerModernMath"), styles); - - let mut realized = self - .clone() - .pack() - .guarded(Guard::Base(NodeId::of::())) - .styled_with_map(map); - + fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult { + let mut realized = self.clone().pack().guarded(Guard::Base(NodeId::of::())); if self.block { realized = realized.aligned(Axes::with_x(Some(Align::Center.into()))) } - Ok(realized) } } +impl Finalize for MathNode { + fn finalize(&self, realized: Content) -> Content { + realized.styled( + TextNode::FAMILY, + FallbackList(vec![FontFamily::new("New Computer Modern Math")]), + ) + } +} + impl Layout for MathNode { fn layout( &self, diff --git a/src/font/book.rs b/src/font/book.rs index dfc6140c6..25b1fc850 100644 --- a/src/font/book.rs +++ b/src/font/book.rs @@ -299,7 +299,7 @@ fn decode_mac_roman(coded: &[u8]) -> String { coded.iter().copied().map(char_from_mac_roman).collect() } -/// Trim style naming from a family name. +/// Trim style naming from a family name and fix bad names. fn typographic_family(mut family: &str) -> &str { // Separators between names, modifiers and styles. const SEPARATORS: [char; 3] = [' ', '-', '_']; @@ -349,7 +349,11 @@ fn typographic_family(mut family: &str) -> &str { } } - &family[..len] + // Fix bad names. + match &family[..len] { + "NewComputerModernMath" => "New Computer Modern Math", + other => other, + } } /// How many words the two strings share in their prefix. diff --git a/tests/typ/text/font.typ b/tests/typ/text/font.typ index 170703c78..0889a0f36 100644 --- a/tests/typ/text/font.typ +++ b/tests/typ/text/font.typ @@ -31,7 +31,7 @@ Emoji: 🐪, 🌋, 🏞 ] // Disable font fallback beyond the user-specified list. -// Without disabling, NewComputerModernMath would come to the rescue. +// Without disabling, New Computer Modern Math would come to the rescue. #set text("PT Sans", "Twitter Color Emoji", fallback: false) 2π = 𝛼 + 𝛽. ✅ diff --git a/tests/typ/text/symbol.typ b/tests/typ/text/symbol.typ index 4dcef58b1..f758c7793 100644 --- a/tests/typ/text/symbol.typ +++ b/tests/typ/text/symbol.typ @@ -6,7 +6,7 @@ :woman:old: :turtle: -#set text("NewComputerModernMath") +#set text("New Computer Modern Math") :arrow: :arrow:l: :arrow:r:squiggly: