Repository: typst/typst
File: crates/typst-library/src/math/style.rs (Rust)

Code before:
    /// The content to style.
    body: Content,
) -> Content {
    body.styled(EquationElem::set_variant(Some(MathVariant::Plain)))
}

/// Sans-serif font style in math.
///
/// ```example
/// $ sans(A B C) $
/// ```
#[func(title = "Sans Serif", keywords = ["mathsf"])]
pub fn sans(
    /// The content to style.
    body: Content,
) -> Content {
    body.styled(EquationElem::set_variant(Some(MathVariant::SansSerif)))
}

/// Script (roundhand) font style in math.
///
/// ```example
/// $ scr(S) $
/// ```
///
/// This is the default calligraphic/script style for most math fonts. See
/// [`cal`]($math.cal) for more on how to get the other style (chancery).
///
/// For the default math font, the chancery style is the default. But the
/// roundhand style is available through the `ss01` feature. Therefore, you
/// could define your own version of `\mathscr` like this:
///
/// ```example
/// #let scr(it) = text(
///   features: ("ss01",),
///   box($cal(it)$),
/// )
///
/// We establish $cal(P) != scr(P)$.
/// ```
///
/// (The box is not conceptually necessary, but unfortunately currently needed
/// due to limitations in Typst's text style handling in math.)
#[func(title = "Script", keywords = ["mathscr", "roundhand"])]
pub fn scr(
    /// The content to style.
    body: Content,
) -> Content {
    body.styled(EquationElem::set_variant(Some(MathVariant::Roundhand)))
}


Review comment (suggestion):
Maybe this statement isn't quite true? Unicode uses it as the default and mentions that it was used more often. Another thing to consider: this might just be making things unnecessarily confusing for users as the default math font _doesn't_ do this.

Code after:
    /// The content to style.
    body: Content,
) -> Content {
    body.set(EquationElem::variant, Some(MathVariant::Plain))
}

/// Sans-serif font style in math.
///
/// ```example
/// $ sans(A B C) $
/// ```
#[func(title = "Sans Serif", keywords = ["mathsf"])]
pub fn sans(
    /// The content to style.
    body: Content,
) -> Content {
    body.set(EquationElem::variant, Some(MathVariant::SansSerif))
}

/// Calligraphic (chancery) font style in math.
///
/// ```example
/// Let $cal(P)$ be the set of ...
/// ```
///
/// This is the default calligraphic/script style for most math fonts. See
/// [`scr`]($math.scr) for more on how to get the other style (roundhand).
#[func(title = "Calligraphic", keywords = ["mathcal", "chancery"])]
pub fn cal(
    /// The content to style.
    body: Content,
) -> Content {
    body.set(EquationElem::variant, Some(MathVariant::Chancery))
}

/// Script (roundhand) font style in math.
///
/// ```example
/// $ scr(S) $
/// ```
///
/// There are two ways that fonts can support differentiating `cal` and `scr`.
/// The first is using Unicode variation sequences. This works out of the box
/// in Typst, however only a few math fonts currently support this.
///
/// The other way is using [font features]($text.features). For example, the
/// roundhand style might be available in a font through the `ss01` feature.
/// To use it in Typst, you could then define your own version of `scr` like
/// this:
///
/// ```example