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

Code before:
    pub num: Content,

    /// The fraction's denominator.
    #[required]
    pub denom: Content,

    /// The style of the fraction.
    /// - `"vertical"`: stacked numerator and denominator with a bar.
    /// - `"diagonal"`: numerator and denominator separated by a slash.
    /// - `"horizontal"`: numerator and denominator placed inline and
    ///   parentheses are not absorbed
    ///
    /// The default style is "vertical"
    pub style: Option<FracStyle>,

    /// Whether the numerator was originally surrounded by parentheses
    /// that were stripped by the parser.
    #[internal]
    #[synthesized]
    pub num_deparenthesized: bool,

    /// Whether the denominator was originally surrounded by parentheses
    /// that were stripped by the parser.
    #[internal]
    #[synthesized]
    pub denom_deparenthesized: bool,
}

/// A binomial expression.
///
/// # Example
/// ```example
/// $ binom(n, k) $
/// $ binom(n, k_1, k_2, k_3, ..., k_m) $
/// ```
#[elem(title = "Binomial", Mathy)]
pub struct BinomElem {
    /// The binomial's upper index.
    #[required]
    pub upper: Content,

    /// The binomial's lower index.
    #[required]
    #[variadic]
    #[parse(
        let values = args.all::<Spanned<Value>>()?;
        if values.is_empty() {
            // Prevents one element binomials
            bail!(args.span, "missing argument: lower");
        }
        values.into_iter().map(|spanned| spanned.v.display()).collect()

Review comment (suggestion):
```suggestion
    #[internal]
    #[parse(None)]
    #[default(false)]
    pub denom_deparenthesized: bool,
```
I'm pretty sure `#[synthesized]` should only be used if the `Synthesize` trait is being used. I've copied what's in `crates/typst-library/src/layout/page.rs` for the `boundary` field (no idea why the parse thing is needed...).

Code after:
    /// ```example
    /// #set math.frac(style: "skewed")
    /// $ a / b $
    /// $ frac(x, y, style: "vertical") $
    /// ```
    #[default(FracStyle::Vertical)]
    pub style: FracStyle,

    /// Whether the numerator was originally surrounded by parentheses
    /// that were stripped by the parser.
    #[internal]
    #[parse(None)]
    #[default(false)]
    pub num_deparenthesized: bool,

    /// Whether the denominator was originally surrounded by parentheses
    /// that were stripped by the parser.
    #[internal]
    #[parse(None)]
    #[default(false)]
    pub denom_deparenthesized: bool,
}

/// Fraction style
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum FracStyle {
    /// Stacked numerator and denominator with a bar.
    #[default]
    Vertical,
    /// Numerator and denominator separated by a slash.
    Skewed,
    /// Numerator and denominator placed inline and parentheses are not
    /// absorbed.
    Horizontal,
}

/// A binomial expression.
///
/// # Example
/// ```example
/// $ binom(n, k) $
/// $ binom(n, k_1, k_2, k_3, ..., k_m) $
/// ```
#[elem(title = "Binomial", Mathy)]
pub struct BinomElem {
    /// The binomial's upper index.
    #[required]
    pub upper: Content,

    /// The binomial's lower index.
    #[required]