summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-09 21:22:23 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-09 21:22:23 +0100
commitc38d55614af0226be8eb3f3e1500da8b7be2fec8 (patch)
tree88ab7d81cbb849d8592baf32a4e5de5a8c9e36ab /library/src
parentcd089b6194c57b2e8dff70efaa7cbd53035f7327 (diff)
A few math fixes
Diffstat (limited to 'library/src')
-rw-r--r--library/src/math/mod.rs3
-rw-r--r--library/src/math/tex.rs12
2 files changed, 9 insertions, 6 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index 62432b12..317bc1d4 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -61,7 +61,8 @@ impl Layout for MathNode {
) -> SourceResult<Fragment> {
let mut t = Texifier::new(styles);
self.texify(&mut t)?;
- layout_tex(vt, &t.finish(), self.display, styles)
+ Ok(layout_tex(vt, &t.finish(), self.display, styles)
+ .unwrap_or(Fragment::frame(Frame::new(Size::zero()))))
}
}
diff --git a/library/src/math/tex.rs b/library/src/math/tex.rs
index f17134b7..60f00249 100644
--- a/library/src/math/tex.rs
+++ b/library/src/math/tex.rs
@@ -14,7 +14,7 @@ pub fn layout_tex(
tex: &str,
display: bool,
styles: StyleChain,
-) -> SourceResult<Fragment> {
+) -> Result<Fragment, &'static str> {
// Load the font.
let variant = variant(styles);
let world = vt.world();
@@ -27,11 +27,13 @@ pub fn layout_tex(
}
// Prepare the font context.
- let font = font.expect("failed to find suitable math font");
- let ctx = font
+ let Some(font) = font else { return Err("failed to find suitable math font") };
+ let Some(ctx) = font
.math()
.map(|math| FontContext::new(font.ttf(), math))
- .expect("failed to create font context");
+ else {
+ return Err("failed to create math font context");
+ };
// Layout the formula.
let em = styles.get(TextNode::SIZE);
@@ -45,7 +47,7 @@ pub fn layout_tex(
Error::Layout(LayoutError::Font(err)) => err.to_string(),
})
else {
- panic!("failed to layout with rex: {tex}");
+ return Err("failed to layout math");
};
// Determine the metrics.