mirror of
https://github.com/typst/typst
synced 2025-08-19 17:38:32 +08:00
Compare commits
4 Commits
838c1b9194
...
2ae6429531
Author | SHA1 | Date | |
---|---|---|---|
|
2ae6429531 | ||
|
3dc9acf4b3 | ||
|
bb8b7a66ba | ||
|
1df33f72b4 |
@ -4,7 +4,7 @@ use ecow::EcoString;
|
|||||||
use typst_library::diag::SourceResult;
|
use typst_library::diag::SourceResult;
|
||||||
use typst_library::foundations::{Packed, StyleChain, SymbolElem};
|
use typst_library::foundations::{Packed, StyleChain, SymbolElem};
|
||||||
use typst_library::layout::{Abs, Size};
|
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::{
|
use typst_library::text::{
|
||||||
BottomEdge, BottomEdgeMetric, TextElem, TopEdge, TopEdgeMetric,
|
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 variant = EquationElem::variant_in(styles);
|
||||||
let bold = EquationElem::bold_in(styles);
|
let bold = EquationElem::bold_in(styles);
|
||||||
let italic = EquationElem::italic_in(styles).unwrap_or(
|
let default_style = EquationElem::default_style_in(styles);
|
||||||
auto_italic
|
let default_italic = match c {
|
||||||
&& matches!(
|
'a'..='z' | 'ħ' | 'ı' | 'ȷ' | 'α'..='ω' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ' =>
|
||||||
c,
|
{
|
||||||
'a'..='z' | 'ħ' | 'ı' | 'ȷ' | 'A'..='Z' |
|
matches!(default_style, MathStyle::Iso | MathStyle::Tex | MathStyle::French)
|
||||||
'α'..='ω' | '∂' | 'ϵ' | 'ϑ' | 'ϰ' | 'ϕ' | 'ϱ' | 'ϖ'
|
}
|
||||||
)
|
'A'..='Z' => matches!(default_style, MathStyle::Iso | MathStyle::Tex),
|
||||||
&& matches!(variant, Sans | Serif),
|
'Α'..='Ω' => 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) {
|
if let Some(c) = basic_exception(c) {
|
||||||
return c;
|
return c;
|
||||||
|
@ -14,7 +14,7 @@ use crate::layout::{
|
|||||||
AlignElem, Alignment, BlockElem, InlineElem, OuterHAlignment, SpecificAlignment,
|
AlignElem, Alignment, BlockElem, InlineElem, OuterHAlignment, SpecificAlignment,
|
||||||
VAlignment,
|
VAlignment,
|
||||||
};
|
};
|
||||||
use crate::math::{MathSize, MathVariant};
|
use crate::math::{MathSize, MathStyle, MathVariant};
|
||||||
use crate::model::{Numbering, Outlinable, ParLine, Refable, Supplement};
|
use crate::model::{Numbering, Outlinable, ParLine, Refable, Supplement};
|
||||||
use crate::text::{FontFamily, FontList, FontWeight, LocalName, TextElem};
|
use crate::text::{FontFamily, FontList, FontWeight, LocalName, TextElem};
|
||||||
|
|
||||||
@ -52,6 +52,10 @@ pub struct EquationElem {
|
|||||||
#[default(false)]
|
#[default(false)]
|
||||||
pub block: bool,
|
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.
|
/// How to [number]($numbering) block-level equations.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
|
@ -252,3 +252,18 @@ pub enum MathVariant {
|
|||||||
Mono,
|
Mono,
|
||||||
Bb,
|
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.
|
// Test text styling in math.
|
||||||
|
|
||||||
--- math-style-italic-default ---
|
--- 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, ϴ$
|
$a, A, delta, ϵ, partial, Delta, ϴ$
|
||||||
|
|
||||||
--- math-style ---
|
--- math-style ---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user