mathml_core/operators/
mod.rs

1use crate::{
2    helpers::{safe_html_char, safe_html_str},
3    traits::{write_tag_close, write_tag_self_close, write_tag_start},
4    MathElement, MathML,
5};
6use std::{
7    collections::BTreeMap,
8    fmt::{Display, Formatter},
9    iter::repeat,
10};
11mod constructors;
12mod display;
13
14/// The [`<mo>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo) element represents an operator in a broad sense.
15///
16/// Besides operators in strict mathematical meaning, this element also includes "operators" like parentheses, separators like comma and semicolon, or "absolute value" bars.
17#[derive(Clone, Debug, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct MathOperator {
20    operator: String,
21    attributes: BTreeMap<String, String>,
22}
23
24/// The [`<mspace>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace) element is used to display a blank space, whose size is set by its attributes.
25#[derive(Clone, Debug, PartialEq)]
26#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27pub struct MathSpace {
28    attributes: BTreeMap<String, String>,
29}
30
31/// The [`<mroot>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mroot) or [`<msqrt>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt) element is used to display roots with an explicit index.
32#[derive(Clone, Debug, PartialEq)]
33#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
34pub struct MathSqrt {
35    base: MathML,
36    surd: Option<MathML>,
37}
38
39/// The [`<mmultiscripts>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mmultiscripts) element is used to attach an arbitrary number of subscripts and superscripts to an expression at once
40#[derive(Clone, Debug, PartialEq)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub struct MathMultiScript {
43    base: MathML,
44    ru: Vec<MathML>,
45    rd: Vec<MathML>,
46    lu: Vec<MathML>,
47    ld: Vec<MathML>,
48    attributes: BTreeMap<String, String>,
49}
50
51/// The [`<munderover>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover) element is used to attach accents or limits both under and over an expression.
52#[derive(Clone, Debug, PartialEq)]
53#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
54pub struct MathUnderOver {
55    base: MathML,
56    under: Option<MathML>,
57    over: Option<MathML>,
58    attributes: BTreeMap<String, String>,
59}
60
61/// The [`<mfenced>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfenced) element provides the possibility to add custom opening and closing parentheses and separators to an expression.
62///
63/// ## Polyfill
64///
65/// Since it is deprecated by the MathML standard, we provide a polyfill to `<mrow>` for this element.
66#[derive(Clone, Debug, PartialEq)]
67#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
68pub struct MathFenced {
69    base: Vec<MathML>,
70    open: char,
71    close: char,
72    separators: String,
73}