diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-06 12:37:08 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-06 12:37:08 +0100 |
| commit | 3ecb0c754bc1777e002a43e4c34b27e676f9a95c (patch) | |
| tree | 49dd299b6671058dd47b7dae84b748f117a962d3 /library/src/math/tex.rs | |
| parent | c2e458a133772a94009733040b39d58e781af977 (diff) | |
More math syntax
Diffstat (limited to 'library/src/math/tex.rs')
| -rw-r--r-- | library/src/math/tex.rs | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/library/src/math/tex.rs b/library/src/math/tex.rs index b2b6486e..da07f1d6 100644 --- a/library/src/math/tex.rs +++ b/library/src/math/tex.rs @@ -6,32 +6,7 @@ use rex::render::{Backend, Cursor, Renderer}; use typst::font::Font; use crate::prelude::*; -use crate::text::{families, variant, LinebreakNode, SpaceNode, TextNode}; - -/// Turn a math node into TeX math code. -#[capability] -pub trait Texify { - /// Perform the conversion. - fn texify(&self) -> EcoString; -} - -impl Texify for Content { - fn texify(&self) -> EcoString { - if self.is::<SpaceNode>() { - return EcoString::new(); - } - - if self.is::<LinebreakNode>() { - return r"\\".into(); - } - - if let Some(node) = self.with::<dyn Texify>() { - return node.texify(); - } - - panic!("{self:?} is not math"); - } -} +use crate::text::{families, variant, TextNode}; /// Layout a TeX formula into a frame. pub fn layout_tex( @@ -63,13 +38,15 @@ pub fn layout_tex( let style = if display { Style::Display } else { Style::Text }; let settings = LayoutSettings::new(&ctx, em.to_pt(), style); let renderer = Renderer::new(); - let layout = renderer + let Ok(layout) = renderer .layout(&tex, settings) .map_err(|err| match err { Error::Parse(err) => err.to_string(), Error::Layout(LayoutError::Font(err)) => err.to_string(), }) - .expect("failed to layout with rex"); + else { + panic!("failed to layout with rex: {tex}"); + }; // Determine the metrics. let (x0, y0, x1, y1) = renderer.size(&layout); |
