Repository: typst/typst
File: crates/typst-layout/src/math/frac.rs (Rust)

Code before:

// Lays out a horizontal fraction
fn layout_horizontal_frac(
    ctx: &mut MathContext,
    styles: StyleChain,
    num: &Content,
    denom: &Content,
    span: Span,
    num_deparen: bool,
    denom_deparen: bool,
) -> SourceResult<()> {
    let num = if num_deparen {
        &LrElem::new(Content::sequence(vec![
            SymbolElem::packed('('),
            num.clone(),
            SymbolElem::packed(')'),
        ]))
        .pack()
    } else {
        num
    };
    let num_frame = ctx.layout_into_fragment(num, styles)?;
    ctx.push(num_frame);

    // AI
    let mut slash =
        ctx.layout_into_fragment(&SymbolElem::packed('/').spanned(span), styles)?;
    slash.center_on_axis();
    ctx.push(slash);

    let denom = if denom_deparen {
        &LrElem::new(Content::sequence(vec![
            SymbolElem::packed('('),
            denom.clone(),
            SymbolElem::packed(')'),
        ]))
        .pack()
    } else {
        denom
    };
    let denom_frame = ctx.layout_into_fragment(denom, styles)?;
    ctx.push(denom_frame);

    Ok(())
}

/// Lay out a skewed fraction.
fn layout_skewed_frac(
    ctx: &mut MathContext,
    styles: StyleChain,
    num: &Content,

Review comment (suggestion):
I do wonder whether the "better" (as in, more semantically correct) glyph to use here is the division slash U+2215. Though given every font displays it slightly differently (see below) to the solidus U+002F and the solidus is what unicode-math uses (`\mathslash`), it doesn't make much sense.

<details>

<summary>solidus vs division slash</summary>

```typ
#set page(width: auto, height: auto, margin: 1em)

#let div = math.class("normal", symbol("\u{2215}"))
#let test = $ a div b quad "vs" quad a \/ b \ E div QQ quad "vs" quad E \/ QQ $

#let fonts = (
  "Cambria Math",
  "Latin Modern Math",
  "New Computer Modern Math",
  "Noto Sans Math",
  "STIX Two Math",
  "Euler Math",
)

#for font in fonts {
  [#font]
  show math.equation: set text(font: font)
  test
}
```

<img width="2590" height="6324" alt="test" src="https://github.com/user-attachments/assets/3640a85b-0513-439d-8816-1d5df572e1d1" />

</details>

Code after:

// Lays out a horizontal fraction
fn layout_horizontal_frac(
    ctx: &mut MathContext,
    styles: StyleChain,
    num: &Content,
    denom: &Content,
    span: Span,
    num_deparen: bool,
    denom_deparen: bool,
) -> SourceResult<()> {
    let num = if num_deparen {
        &LrElem::new(Content::sequence(vec![
            SymbolElem::packed('('),
            num.clone(),
            SymbolElem::packed(')'),
        ]))
        .pack()
    } else {
        num
    };
    let num_frame = ctx.layout_into_fragment(num, styles)?;
    ctx.push(num_frame);

    let mut slash =
        ctx.layout_into_fragment(&SymbolElem::packed('/').spanned(span), styles)?;
    slash.center_on_axis();
    ctx.push(slash);

    let denom = if denom_deparen {
        &LrElem::new(Content::sequence(vec![
            SymbolElem::packed('('),
            denom.clone(),
            SymbolElem::packed(')'),
        ]))
        .pack()
    } else {
        denom
    };
    let denom_frame = ctx.layout_into_fragment(denom, styles)?;
    ctx.push(denom_frame);

    Ok(())
}

/// Lay out a skewed fraction.
fn layout_skewed_frac(
    ctx: &mut MathContext,
    styles: StyleChain,
    num: &Content,
    denom: &Content,