1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use crate::MathML;
use std::fmt::{Display, Formatter};
mod display;
/// The [`<mfrac>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfrac) element is used to display fractions.
///
/// It can also be used to mark up fraction-like objects such as binomial coefficients and Legendre symbols.
#[derive(Clone, Debug, PartialEq)]
pub struct MathFraction {
numerator: MathML,
denominator: MathML,
line_thickness: LineThickness,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineThickness {
Thin,
Medium,
Thick,
Length(u8),
}
impl Default for LineThickness {
fn default() -> Self {
LineThickness::Medium
}
}
impl From<MathFraction> for MathML {
fn from(value: MathFraction) -> Self {
MathML::Frac(Box::new(value))
}
}
impl MathFraction {
pub fn new(numerator: MathML, denominator: MathML) -> Self {
Self { numerator, denominator, line_thickness: Default::default() }
}
pub fn with_thickness<T>(mut self, line_thickness: T) -> Self
where
T: Into<LineThickness>,
{
self.line_thickness = line_thickness.into();
self
}
}
impl MathML {
pub fn fraction(numerator: MathML, denominator: MathML) -> Self {
MathFraction::new(numerator, denominator).into()
}
// binomial coefficients and Legendre symbols
// <mrow>
// <mo>(</mo>
// <mfrac linethickness="0">
// <mi>n</mi>
// <mi>k</mi>
// </mfrac>
// <mo>)</mo>
// </mrow>
// pub fn binomial(numerator: MathML, denominator: MathML) -> Self {
// let mut row = vec![];
// row.push(MathML::Op("("));
// row.push(MathML::fraction(numerator, denominator).with_thickness(LineThickness::Length(0)));
// row.push(MathML::mo(")"));
// row
// }
}