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

Code before:
                SymbolElem::packed(')'),
            ]))),
            styles,
        )?
    } else {
        ctx.layout_into_frame(num, styles)?
    };
    ctx.push(FrameFragment::new(styles, num_frame));

    let mut slash = GlyphFragment::new_char(ctx.font, styles, '/', span)?;
    slash.center_on_axis();
    ctx.push(slash);

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

    Ok(())
}

/// Lay out a skewed fraction.
fn layout_skewed_frac(
    ctx: &mut MathContext,
    styles: StyleChain,
    num: &Content,
    denom: &Content,
    span: Span,
) -> SourceResult<()> {
    // Font-derived constants
    let vgap = scaled!(ctx, styles, skewed_fraction_vertical_gap);
    let hgap = scaled!(ctx, styles, skewed_fraction_horizontal_gap);
    let axis = scaled!(ctx, styles, axis_height);
    // let vgap = vgap + axis / 2.0; // LuaTeX behavior

    let num_style = style_for_numerator(styles);
    let num_frame = ctx.layout_into_frame(num, styles.chain(&num_style))?;
    let num_size = num_frame.size();
    let denom_style = style_for_denominator(styles);
    let denom_frame = ctx.layout_into_frame(denom, styles.chain(&denom_style))?;
    let denom_size = denom_frame.size();


Review comment (suggestion):
```suggestion
    let denom = if denom_deparen {
        &LrElem::new(Content::sequence(vec![
            SymbolElem::packed('('),
            denom.clone(),
            SymbolElem::packed(')'),
        ]))
        .pack()
    } else {
        denom
    };
    let denom = ctx.layout_into_fragment(denom, styles)?;
    ctx.push(denom);
```
Probably better to just lay it out into a fragment directly.

Code after:
    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,
    span: Span,
) -> SourceResult<()> {
    // Font-derived constants
    let constants = ctx.font().math();
    let vgap = constants.skewed_fraction_vertical_gap.resolve(styles);