diff --git a/Cargo.lock b/Cargo.lock index 1472a2a01..fef4b8449 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -862,7 +862,7 @@ dependencies = [ [[package]] name = "rex" version = "0.1.2" -source = "git+https://github.com/laurmaedje/ReX#b44e59bfa68cc4b0288bd2be80e093ed3b279af5" +source = "git+https://github.com/laurmaedje/ReX#7362b0cbb229211d6206198d80382a9b23eda993" dependencies = [ "font", "unicode-math", diff --git a/NOTICE b/NOTICE index 05f361899..4444cccd0 100644 --- a/NOTICE +++ b/NOTICE @@ -460,6 +460,8 @@ The GUST Font License Version 1.0 applies to: * Latin Modern fonts in fonts/LatinModern*.otf (http://www.gust.org.pl/projects/e-foundry/lm-math) +* NewComputerModern fonts in fonts/NewCM*.otf + % This is version 1.0, dated 22 June 2009, of the GUST Font License. % (GUST is the Polish TeX Users Group, http://www.gust.org.pl) % diff --git a/fonts/LatinModernMath.otf b/fonts/LatinModernMath.otf deleted file mode 100644 index 0e4642e91..000000000 Binary files a/fonts/LatinModernMath.otf and /dev/null differ diff --git a/fonts/NewCMMath-Regular.otf b/fonts/NewCMMath-Regular.otf new file mode 100644 index 000000000..82221fb81 Binary files /dev/null and b/fonts/NewCMMath-Regular.otf differ diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index ce41bd49a..b1dabbe5e 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -20,7 +20,7 @@ pub struct MathNode { impl MathNode { /// The math font family. #[property(referenced)] - pub const FAMILY: FontFamily = FontFamily::new("Latin Modern Math"); + pub const FAMILY: FontFamily = FontFamily::new("NewComputerModernMath"); /// The spacing above display math. #[property(resolve, shorthand(around))] pub const ABOVE: Option = Some(Ratio::one().into()); diff --git a/src/library/math/rex.rs b/src/library/math/rex.rs index 43e2c015c..addf56b6b 100644 --- a/src/library/math/rex.rs +++ b/src/library/math/rex.rs @@ -1,8 +1,8 @@ +use rex::error::{Error, LayoutError}; use rex::font::{FontContext, MathFont}; use rex::layout::{LayoutSettings, Style}; use rex::parser::color::RGBA; use rex::render::{Backend, Cursor, Renderer}; -use rex::error::{Error, LayoutError}; use crate::font::FaceId; use crate::library::prelude::*; @@ -27,30 +27,33 @@ impl Layout for RexNode { styles: StyleChain, ) -> TypResult>> { // Load the font. - let face_id = match ctx.fonts.select(self.family.as_str(), variant(styles)) { - Some(id) => id, - None => return Ok(vec![]), - }; + let span = self.tex.span; + let face_id = ctx + .fonts + .select(self.family.as_str(), variant(styles)) + .ok_or("failed to find math font") + .at(span)?; // Prepare the font. let data = ctx.fonts.get(face_id).buffer(); - let font = match MathFont::parse(data) { - Ok(font) => font, - Err(_) => return Ok(vec![]), - }; + let font = MathFont::parse(data) + .map_err(|_| "failed to parse math font") + .at(span)?; + + let ctx = FontContext::new(&font).ok_or("failed to parse math font").at(span)?; // Layout the formula. - let ctx = FontContext::new(&font); let em = styles.get(TextNode::SIZE); let style = if self.display { Style::Display } else { Style::Text }; let settings = LayoutSettings::new(&ctx, em.to_pt(), style); let renderer = Renderer::new(); - let layout = renderer.layout(&self.tex.v, settings) + let layout = renderer + .layout(&self.tex.v, settings) .map_err(|err| match err { Error::Parse(err) => err.to_string(), Error::Layout(LayoutError::Font(err)) => err.to_string(), }) - .at(self.tex.span)?; + .at(span)?; // Determine the metrics. let (x0, y0, x1, y1) = renderer.size(&layout); diff --git a/tests/ref/graphics/transform.png b/tests/ref/graphics/transform.png index 65d947584..1cb8efcd4 100644 Binary files a/tests/ref/graphics/transform.png and b/tests/ref/graphics/transform.png differ diff --git a/tests/ref/math/basic.png b/tests/ref/math/basic.png index 42723bc51..ce9596620 100644 Binary files a/tests/ref/math/basic.png and b/tests/ref/math/basic.png differ diff --git a/tests/ref/text/font.png b/tests/ref/text/font.png index cce4897b2..65badc0ac 100644 Binary files a/tests/ref/text/font.png and b/tests/ref/text/font.png differ diff --git a/tests/typ/graphics/transform.typ b/tests/typ/graphics/transform.typ index 5d2a1729a..2dde626b1 100644 --- a/tests/typ/graphics/transform.typ +++ b/tests/typ/graphics/transform.typ @@ -23,7 +23,7 @@ [X] } -#set text("Latin Modern Math", size) +#set text("Latin Modern Roman", size) Neither #tex, \ nor #xetex! diff --git a/tests/typ/math/basic.typ b/tests/typ/math/basic.typ index 33246261d..051dbaf32 100644 --- a/tests/typ/math/basic.typ +++ b/tests/typ/math/basic.typ @@ -11,6 +11,10 @@ $[ a^2 + b^2 = c^2 ]$ Prove by induction: $[ \sum_{k=0}^n k = \frac{n(n+1)}{2} ]$ +--- +// Test that blackboard style looks nice. +$[ f: \mathbb{N} \rightarrow \mathbb{R} ]$ + --- // Error: 1-10 expected '}' found EOF $\sqrt{x$ diff --git a/tests/typ/text/font.typ b/tests/typ/text/font.typ index bfec3e1ce..e57fedbd4 100644 --- a/tests/typ/text/font.typ +++ b/tests/typ/text/font.typ @@ -24,9 +24,6 @@ // Emoji. Emoji: 🐪, 🌋, 🏞 -// Math. -#text("Latin Modern Math")[∫ 𝛼 + 3𝛽 d𝑡] - // Colors. [ #set text(fill: eastern) @@ -34,7 +31,7 @@ Emoji: 🐪, 🌋, 🏞 ] // Disable font fallback beyond the user-specified list. -// Without disabling, Latin Modern Math would come to the rescue. +// Without disabling, NewComputerModernMath would come to the rescue. #set text("PT Sans", "Twitter Color Emoji", fallback: false) 2π = 𝛼 + 𝛽. ✅