Compare commits

...

6 Commits

7 changed files with 46 additions and 14 deletions

View File

@ -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;

View File

@ -20,7 +20,7 @@ use crate::foundations::{
/// ///
/// You can call a function by writing a comma-separated list of function /// You can call a function by writing a comma-separated list of function
/// _arguments_ enclosed in parentheses directly after the function name. /// _arguments_ enclosed in parentheses directly after the function name.
/// Additionally, you can pass any number of trailing content blocks arguments /// Additionally, you can pass any number of trailing content block arguments
/// to a function _after_ the normal argument list. If the normal argument list /// to a function _after_ the normal argument list. If the normal argument list
/// would become empty, it can be omitted. Typst supports positional and named /// would become empty, it can be omitted. Typst supports positional and named
/// arguments. The former are identified by position and type, while the latter /// arguments. The former are identified by position and type, while the latter

View File

@ -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

View File

@ -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,
}

View File

@ -205,7 +205,7 @@
single or double quotes. single or double quotes.
The value is always of type [string]($str). More complex data The value is always of type [string]($str). More complex data
may be parsed manually using functions like [`json.decode`]($json.decode). may be parsed manually using functions like [`json`]($json).
- name: sym - name: sym
title: General title: General

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. // 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 ---