From c38d55614af0226be8eb3f3e1500da8b7be2fec8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 9 Dec 2022 21:22:23 +0100 Subject: A few math fixes --- library/src/math/mod.rs | 3 ++- library/src/math/tex.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'library/src/math') 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 { 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 { +) -> Result { // 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. -- cgit v1.2.3