summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src/math')
-rw-r--r--crates/typst-library/src/math/ctx.rs24
-rw-r--r--crates/typst-library/src/math/mod.rs4
2 files changed, 24 insertions, 4 deletions
diff --git a/crates/typst-library/src/math/ctx.rs b/crates/typst-library/src/math/ctx.rs
index 999a5ccb..e6a84674 100644
--- a/crates/typst-library/src/math/ctx.rs
+++ b/crates/typst-library/src/math/ctx.rs
@@ -5,7 +5,7 @@ use typst::model::realize;
use unicode_segmentation::UnicodeSegmentation;
use super::*;
-use crate::text::tags;
+use crate::text::{tags, BottomEdge, BottomEdgeMetric, TopEdge, TopEdgeMetric};
macro_rules! scaled {
($ctx:expr, text: $text:ident, display: $display:ident $(,)?) => {
@@ -203,7 +203,27 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
style = style.with_italic(false);
}
let text: EcoString = text.chars().map(|c| style.styled_char(c)).collect();
- let frame = self.layout_content(&TextElem::packed(text).spanned(span))?;
+ let text = TextElem::packed(text)
+ .styled(TextElem::set_top_edge(TopEdge::Metric(TopEdgeMetric::Bounds)))
+ .styled(TextElem::set_bottom_edge(BottomEdge::Metric(
+ BottomEdgeMetric::Bounds,
+ )))
+ .spanned(span);
+ let par = ParElem::new(vec![text]);
+
+ // There isn't a natural width for a paragraph in a math environment;
+ // because it will be placed somewhere probably not at the left margin
+ // it will overflow. So emulate an `hbox` instead and allow the paragraph
+ // to extend as far as needed.
+ let frame = par
+ .layout(
+ self.vt,
+ self.outer.chain(&self.local),
+ false,
+ Size::splat(Abs::inf()),
+ false,
+ )?
+ .into_frame();
FrameFragment::new(self, frame)
.with_class(MathClass::Alphabetic)
.with_spaced(spaced)
diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs
index b5410a03..c29ad29b 100644
--- a/crates/typst-library/src/math/mod.rs
+++ b/crates/typst-library/src/math/mod.rs
@@ -292,9 +292,9 @@ impl Layout for EquationElem {
}
} else {
let slack = ParElem::leading_in(styles) * 0.7;
- let top_edge = TextElem::top_edge_in(styles).resolve(styles, font.metrics());
+ let top_edge = TextElem::top_edge_in(styles).resolve(styles, &font, None);
let bottom_edge =
- -TextElem::bottom_edge_in(styles).resolve(styles, font.metrics());
+ -TextElem::bottom_edge_in(styles).resolve(styles, &font, None);
let ascent = top_edge.max(frame.ascent() - slack);
let descent = bottom_edge.max(frame.descent() - slack);