Compare commits

...

4 Commits

Author SHA1 Message Date
fGolke
2ae6429531
Merge 3dc9acf4b39127ab399ea3e8a292ff83c6dcd48e into d1deb80bb8b4d5fad348c23a3e079e4854aa57e4 2025-07-05 21:57:19 +08:00
fGolke
3dc9acf4b3 Fix formatting v2 2025-04-05 22:13:13 +02:00
fGolke
bb8b7a66ba Fix formatting 2025-04-05 21:58:33 +02:00
fGolke
1df33f72b4 Add default-style parameter to math.equation 2025-04-05 21:49:00 +02:00
5 changed files with 44 additions and 12 deletions

View File

@ -4,7 +4,7 @@ use ecow::EcoString;
use typst_library::diag::SourceResult;
use typst_library::foundations::{Packed, StyleChain, SymbolElem};
use typst_library::layout::{Abs, Size};
use typst_library::math::{EquationElem, MathSize, MathVariant};
use typst_library::math::{EquationElem, MathSize, MathStyle, MathVariant};
use typst_library::text::{
BottomEdge, BottomEdgeMetric, TextElem, TopEdge, TopEdgeMetric,
};
@ -171,15 +171,19 @@ fn styled_char(styles: StyleChain, c: char, auto_italic: bool) -> char {
let variant = EquationElem::variant_in(styles);
let bold = EquationElem::bold_in(styles);
let italic = EquationElem::italic_in(styles).unwrap_or(
auto_italic
&& matches!(
c,
'a'..='z' | 'ħ' | 'ı' | 'ȷ' | 'A'..='Z' |
'α'..='ω' | '∂' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ'
)
&& matches!(variant, Sans | Serif),
);
let default_style = EquationElem::default_style_in(styles);
let default_italic = match c {
'a'..='z' | 'ħ' | 'ı' | 'ȷ' | 'α'..='ω' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ' =>
{
matches!(default_style, MathStyle::Iso | MathStyle::Tex | MathStyle::French)
}
'A'..='Z' => matches!(default_style, MathStyle::Iso | MathStyle::Tex),
'Α'..='Ω' => matches!(default_style, MathStyle::Iso),
'∂' => matches!(default_style, MathStyle::Tex | MathStyle::French),
_ => false,
};
let italic = EquationElem::italic_in(styles)
.unwrap_or(auto_italic && default_italic && matches!(variant, Sans | Serif));
if let Some(c) = basic_exception(c) {
return c;

View File

@ -14,7 +14,7 @@ use crate::layout::{
AlignElem, Alignment, BlockElem, InlineElem, OuterHAlignment, SpecificAlignment,
VAlignment,
};
use crate::math::{MathSize, MathVariant};
use crate::math::{MathSize, MathStyle, MathVariant};
use crate::model::{Numbering, Outlinable, ParLine, Refable, Supplement};
use crate::text::{FontFamily, FontList, FontWeight, LocalName, TextElem};
@ -52,6 +52,10 @@ pub struct EquationElem {
#[default(false)]
pub block: bool,
/// The rule determining which letters and symbols are italic by default.
#[default(MathStyle::Tex)]
pub default_style: MathStyle,
/// How to [number]($numbering) block-level equations.
///
/// ```example

View File

@ -252,3 +252,18 @@ pub enum MathVariant {
Mono,
Bb,
}
/// A rule describing which letters and symbols are italic by default.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Cast, Hash)]
// #[derive(Serialize, Deserialize, Cast)]
// #[serde(rename_all = "kebab-case")]
pub enum MathStyle {
// Every latin or greek letter italic, [partial] upright.
Iso,
// Everything but capital greek letters italic.
Tex,
// Lowercase letters and [partial] italic.
French,
// Everything upright.
Upright,
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 466 B

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,7 +1,16 @@
// Test text styling in math.
--- math-style-italic-default ---
// Test italic defaults.
// Test italic defaults for all `default-style`s.
$a, A, delta, ϵ, partial, Delta, ϴ$
#set math.equation(default-style: "iso")
$a, A, delta, ϵ, partial, Delta, ϴ$
#set math.equation(default-style: "french")
$a, A, delta, ϵ, partial, Delta, ϴ$
#set math.equation(default-style: "upright")
$a, A, delta, ϵ, partial, Delta, ϴ$
--- math-style ---