mathml_core/blocks/
mod.rs

1use crate::{MathElement, MathIdentifier, MathML};
2use std::{
3    collections::BTreeMap,
4    fmt::{Debug, Display, Formatter},
5};
6mod constructors;
7mod display;
8
9/// The [`<math>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math) element is the top-level MathML element,
10/// used to write a single mathematical formula.
11///
12/// It can be placed in HTML content where flow content is permitted.
13#[derive(Debug, Clone, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct MathRoot {
16    children: Vec<MathML>,
17    attributes: BTreeMap<String, String>,
18}
19
20/// Mark a function with arguments.
21#[derive(Debug, Clone, PartialEq)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct MathFunction {
24    name: String,
25    body: Vec<MathML>,
26}
27
28/// The [`<mrow>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mrow) element is used to group sub-expressions,
29/// which usually contain one or more operators with their respective operands, such as `<mi>` and `<mn>`.
30///
31/// This element renders as a horizontal row containing its arguments.
32///
33/// When writing a MathML expression, you should group elements within an `<mrow>` in the same way as they are grouped in the mathematical interpretation of the expression.
34///
35/// Proper grouping helps the rendering of the expression in several ways:
36///
37/// - It can improve the display by possibly affecting spacing and preventing line breaks.
38/// - It simplifies the interpretation of the expression by automated systems such as computer algebra systems and audio renderers.
39#[derive(Debug, Clone, PartialEq)]
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41pub struct MathRow {
42    grouped: bool,
43    children: Vec<MathML>,
44}
45
46/// The [`<mphantom>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mphantom) element is rendered invisibly,
47/// but dimensions such as height, width, and baseline position, are still kept.
48#[derive(Debug, Clone, PartialEq)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50pub struct MathPhantom {
51    inner: MathML,
52}
53
54/// The [`<mspace>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace) element is used to insert space characters into a mathematical formula.
55#[derive(Debug, Clone, PartialEq)]
56#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
57pub struct MathStyle {
58    base: MathML,
59    attributes: BTreeMap<String, String>,
60}
61
62/// The [`<mtable>`](https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtable) element allows you to create tables or matrices.
63///
64/// Its children are `<mtr>` elements, representing rows.
65///
66/// Each of them having `<mtd>` elements as its children, representing cells.
67///
68/// These elements are similar to `<table>`, `<tr>` and `<td>` elements of HTML.
69#[derive(Debug, Clone, PartialEq)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
71pub struct MathTable {
72    stream: Vec<MathML>,
73    attributes: BTreeMap<String, String>,
74}