Math

Struct Math 

Source
pub struct Math;
Expand description

The <math> element - embeds MathML (Mathematical Markup Language) content.

§Purpose

The <math> element is the top-level element for MathML content, used to embed mathematical expressions and equations in HTML documents. MathML provides semantic markup for mathematical notation, enabling proper rendering, accessibility, and computational manipulation of mathematical expressions.

§Content Categories

  • Flow Content
  • Phrasing Content
  • Embedded Content
  • Palpable Content

§Permitted Content Model

  • MathML elements (follows MathML specification, not HTML)

§Common Use Cases

  • Displaying mathematical equations and formulas
  • Scientific and technical documentation
  • Educational materials with math content
  • Research papers and academic publications
  • Interactive math applications

§Key Attributes

  • display: “block” or “inline” (controls display mode)
  • xmlns: XML namespace (usually "http://www.w3.org/1998/Math/MathML")
  • Plus all MathML-specific attributes

§Example

<!-- Inline math: Pythagorean theorem -->
<p>The Pythagorean theorem states that
<math>
  <msup><mi>a</mi><mn>2</mn></msup>
  <mo>+</mo>
  <msup><mi>b</mi><mn>2</mn></msup>
  <mo>=</mo>
  <msup><mi>c</mi><mn>2</mn></msup>
</math>
</p>

<!-- Block math: Quadratic formula -->
<math display="block">
  <mi>x</mi>
  <mo>=</mo>
  <mfrac>
    <mrow>
      <mo>−</mo><mi>b</mi>
      <mo>±</mo>
      <msqrt>
        <msup><mi>b</mi><mn>2</mn></msup>
        <mo>−</mo>
        <mn>4</mn><mi>a</mi><mi>c</mi>
      </msqrt>
    </mrow>
    <mrow>
      <mn>2</mn><mi>a</mi>
    </mrow>
  </mfrac>
</math>

<!-- Fraction notation -->
<math>
  <mfrac>
    <mn>1</mn>
    <mn>2</mn>
  </mfrac>
</math>

<!-- Complex expression with matrix -->
<math display="block">
  <mrow>
    <mo>[</mo>
    <mtable>
      <mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd></mtr>
      <mtr><mtd><mn>3</mn></mtd><mtd><mn>4</mn></mtd></mtr>
    </mtable>
    <mo>]</mo>
  </mrow>
</math>

§Accessibility

  • MathML provides built-in semantic accessibility
  • Screen readers can navigate and speak mathematical expressions
  • Consider providing text alternatives for complex equations
  • Ensure proper use of MathML semantic elements
  • Test with assistive technologies that support MathML

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Math

Source§

const TAG: &'static str = "math"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl EmbeddedContent for Math

Source§

impl FlowContent for Math

Source§

impl PalpableContent for Math

Source§

impl PhrasingContent for Math

Auto Trait Implementations§

§

impl Freeze for Math

§

impl RefUnwindSafe for Math

§

impl Send for Math

§

impl Sync for Math

§

impl Unpin for Math

§

impl UnwindSafe for Math

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.