diff options
| -rw-r--r-- | crates/typst/src/math/ctx.rs | 10 | ||||
| -rw-r--r-- | crates/typst/src/math/fragment.rs | 3 | ||||
| -rw-r--r-- | crates/typst/src/math/style.rs | 15 | ||||
| -rw-r--r-- | tests/ref/bugs/3650-italic-equation.png | bin | 0 -> 3958 bytes | |||
| -rw-r--r-- | tests/typ/bugs/3650-italic-equation.typ | 4 |
5 files changed, 19 insertions, 13 deletions
diff --git a/crates/typst/src/math/ctx.rs b/crates/typst/src/math/ctx.rs index 70de8a8e..6af17bb4 100644 --- a/crates/typst/src/math/ctx.rs +++ b/crates/typst/src/math/ctx.rs @@ -11,7 +11,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::diag::SourceResult; use crate::engine::Engine; -use crate::foundations::{Content, Packed, Smart, StyleChain}; +use crate::foundations::{Content, Packed, StyleChain}; use crate::layout::{Abs, Axes, BoxElem, Em, Frame, LayoutMultiple, Regions, Size}; use crate::math::{ scaled_font_size, styled_char, EquationElem, FrameFragment, GlyphFragment, @@ -202,7 +202,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { let fragment = if let Some(mut glyph) = chars .next() .filter(|_| chars.next().is_none()) - .map(|c| styled_char(styles, c)) + .map(|c| styled_char(styles, c, true)) .and_then(|c| GlyphFragment::try_new(self, styles, c, span)) { // A single letter that is available in the math font. @@ -234,7 +234,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { // Numbers aren't that difficult. let mut fragments = vec![]; for c in text.chars() { - let c = styled_char(styles, c); + let c = styled_char(styles, c, false); fragments.push(GlyphFragment::new(self, styles, c, span).into()); } let frame = MathRun::new(fragments).into_frame(self, styles); @@ -244,13 +244,13 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { TextElem::set_top_edge(TopEdge::Metric(TopEdgeMetric::Bounds)), TextElem::set_bottom_edge(BottomEdge::Metric(BottomEdgeMetric::Bounds)), TextElem::set_size(TextSize(scaled_font_size(self, styles).into())), - EquationElem::set_italic(Smart::Custom(false)), ] .map(|p| p.wrap()); // Anything else is handled by Typst's standard text layout. let styles = styles.chain(&local); - let text: EcoString = text.chars().map(|c| styled_char(styles, c)).collect(); + let text: EcoString = + text.chars().map(|c| styled_char(styles, c, false)).collect(); if text.contains(is_newline) { let mut fragments = vec![]; for (i, piece) in text.split(is_newline).enumerate() { diff --git a/crates/typst/src/math/fragment.rs b/crates/typst/src/math/fragment.rs index e78cd95a..c5396654 100644 --- a/crates/typst/src/math/fragment.rs +++ b/crates/typst/src/math/fragment.rs @@ -9,7 +9,7 @@ use crate::foundations::StyleChain; use crate::introspection::{Meta, MetaElem}; use crate::layout::{Abs, Corner, Em, Frame, FrameItem, Point, Size}; use crate::math::{ - scaled_font_size, styled_char, EquationElem, Limits, MathContext, MathSize, Scaled, + scaled_font_size, EquationElem, Limits, MathContext, MathSize, Scaled, }; use crate::syntax::Span; use crate::text::{Font, Glyph, Lang, TextElem, TextItem}; @@ -234,7 +234,6 @@ impl GlyphFragment { c: char, span: Span, ) -> Option<Self> { - let c = styled_char(styles, c); let id = ctx.ttf.glyph_index(c)?; let id = Self::adjust_glyph_index(ctx, id); Some(Self::with_id(ctx, styles, c, id, span)) diff --git a/crates/typst/src/math/style.rs b/crates/typst/src/math/style.rs index 717b23c3..bd910a79 100644 --- a/crates/typst/src/math/style.rs +++ b/crates/typst/src/math/style.rs @@ -289,16 +289,19 @@ pub fn style_for_denominator(styles: StyleChain) -> [LazyHash<Style>; 2] { /// /// <https://www.w3.org/TR/mathml-core/#new-text-transform-mappings> /// <https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols> -pub fn styled_char(styles: StyleChain, c: char) -> char { +pub fn styled_char(styles: StyleChain, c: char, auto_italic: bool) -> char { use MathVariant::*; let variant = EquationElem::variant_in(styles); let bold = EquationElem::bold_in(styles); - let italic = EquationElem::italic_in(styles).unwrap_or(matches!( - c, - 'a'..='z' | 'ı' | 'ȷ' | 'A'..='Z' | 'α'..='ω' | - '∂' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ' - )); + let italic = EquationElem::italic_in(styles).unwrap_or( + auto_italic + && matches!( + c, + 'a'..='z' | 'ı' | 'ȷ' | 'A'..='Z' | 'α'..='ω' | + '∂' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ' + ), + ); if let Some(c) = basic_exception(c) { return c; diff --git a/tests/ref/bugs/3650-italic-equation.png b/tests/ref/bugs/3650-italic-equation.png Binary files differnew file mode 100644 index 00000000..41f071ab --- /dev/null +++ b/tests/ref/bugs/3650-italic-equation.png diff --git a/tests/typ/bugs/3650-italic-equation.typ b/tests/typ/bugs/3650-italic-equation.typ new file mode 100644 index 00000000..c9b47543 --- /dev/null +++ b/tests/typ/bugs/3650-italic-equation.typ @@ -0,0 +1,4 @@ +_abc $sin(x) "abc"$_ \ +$italic(sin(x) "abc" #box[abc])$ \ +*abc $sin(x) "abc"$* \ +$bold(sin(x) "abc" #box[abc])$ \ |
