summaryrefslogtreecommitdiff
path: root/src/library/math
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-19 12:59:39 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-19 12:59:39 +0200
commit5a7c901f2195a746e0982723b959c07431844077 (patch)
tree02058fb875cb87979fa930b5dc97a94b309459be /src/library/math
parent3965e10281ea3c8754a1877c9f7e71c1930bf4c3 (diff)
Switch to New Computer Modern Math
Diffstat (limited to 'src/library/math')
-rw-r--r--src/library/math/mod.rs2
-rw-r--r--src/library/math/rex.rs27
2 files changed, 16 insertions, 13 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index ce41bd49..b1dabbe5 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<BlockSpacing> = Some(Ratio::one().into());
diff --git a/src/library/math/rex.rs b/src/library/math/rex.rs
index 43e2c015..addf56b6 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<Vec<Arc<Frame>>> {
// 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);