mirror of
https://github.com/typst/typst
synced 2025-08-20 01:48:34 +08:00
Merge 3dc9acf4b39127ab399ea3e8a292ff83c6dcd48e into d1deb80bb8b4d5fad348c23a3e079e4854aa57e4
This commit is contained in:
commit
2ae6429531
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 |
@ -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 ---
|
||||
|
Loading…
x
Reference in New Issue
Block a user