graphic with four colored squares
Cover page images (keys)

MathML

12 Aug 2005

Ivan Herman, W3C

MathML

These slides are in XHTML, and follow the approach described on a separate page for presentation. That page describes the minimum environment you should have to display these slides with the proper MathML content.

Table of Content:

  1. Why MathML?
  2. Why MathML? (cont.)
  3. What is MathML?
  4. Who developed MathML?
  5. A Flavour of MathML: Quadratic formula in MathML
  6. A Bit of History
  7. MathML structure
  8. Same Formula in Different Markups
  9. Why two markups?
  10. Presentation Elements
  11. Main Token Presentation Elements
  12. Controlling the Rendering
  13. Controlling the Rendering (cont.)
  14. General Layout
  15. General Layout (cont.)
  16. Script and Limits
  17. Tables and Matrices
  18. Tables and Matrices (cont.)
  19. Enlivening Expressions
  20. Content Markup
  21. Content Markup Details
  22. Content Markup
  23. Fundamental Content Elements
  24. Fundamental Content Elements (cont.)
  25. Fundamental Content Elements
  26. Fundamental Content Elements
  27. Content Operators and Functions
  28. Content Operators and Functions
  29. Mixing Content and Presentation Markups
  30. Semantics of Content Elements
  31. Adding semantics to an expression
  32. Using MathML with Other Markups
  33. Embedding MathML
  34. Using “object”
  35. Full XML Based Usage: Namespaces
  36. Full XML Based Usage: Common Approach
  37. Further Information

Why MathML?

Current solutions to display math on the Web:

Use HTML
eg: ai (a<sub>i</sub>))
  • HTML is not rich enough
  • typesetting mathematical formulae is hard!
Use embedded images
eg: quadratic formula
  • requires specialized editors
  • difficult to position/size the image properly
  • not searchable
  • accessibility problems (what should a voice browser do?)

Why MathML? (cont.)

What is MathML?

Who developed MathML?

A Flavour of MathML: Quadratic formula in MathML

<mrow>
  <mi>x</mi> <mo>=</mo>
  <mfrac>
    <mrow>
      <mrow><mo>-</mo><mi>b</mi></mrow>
      <mo>±</mo>
      <msqrt>
        <mrow>
          <msup><mi>b</mi><mn>2</mn></msup>
          <mo>-</mo>
          <mrow>
            <mi>c</mi>
          </mrow>
        </mrow>
      </msqrt>
    </mrow>
    <mrow>
      <mi>a</mi>
    </mrow>
  </mfrac>
</mrow>

A Bit of History

MathML structure

XML Elements in MathML are:

Presentation markup elements:
Describing the notation directly (see previous example): rows, fractions, operators, etc. It captures the notational structure.
Content markup elements:
Explicit encoding of the mathematical content. It captures the mathematical structure.
The (only) interface element:
math element, which binds a formula to the surrounding XML (eg., XHTML)

Note: earlier versions relied on XML Entities for special signs (integrals, greek letters, etc), but Unicode has taken over…

Same Formula in Different Markups

Presentation Markup Content Markup
<msup>
  <mfenced>
    <mrow>
      <mi>a</mi>
      <mo>+</mo>
      <mi>b</mi>
    </mrow>
  </mfenced>
  <mn>2</mn>
</msup>    
<apply>
  <power/>
  <apply>
    <plus/>
    <ci>a</ci>
    <ci>b</ci>
  </apply>
  <cn>2</cn>
</apply>

Why two markups?

Presentation Elements

Presentation elements fall in two categories:

Token elements
Individual symbols, names, numbers, alignment control, ...
Layout elements
Rows, fractions, square roots, superscripts, tables, ...

Main Token Presentation Elements

identifier, number
<mi>a</mi> <mn>2</mn>
operator, separator, or accent
<mi>a</mi><mo>→</mo><mi>b</mi>
text
<mtext>Theorem 1:</mtext>

Controlling the Rendering

Attributes to control the precise rendering, eg,

<mo> ( </mo>
<mo maxsize="1"> ( </mo>

Controlling the Rendering (cont.)

General Layout

subexpressions
<mrow><mi>a</mi><mi>b</mi></mrow>
fraction
<mfrac><mi>a</mi><mi>b</mi></mfrac>
square root
<msqrt><mi>a</mi></msqrt>

General Layout (cont.)

radical
<mroot><mi>a</mi><mi>b</mi></mroot>
surround content
<mfenced open="[" separators=";">
  <mi>a</mi><mi>b</mi>
</mfenced>

Script and Limits

subscript
<msub><mi>x</mi><mi>i</mi></msub>
superscript
<msub><mi>x</mi><mi>i</mi></msub>
tensor indices
<mmultiscripts><mi>R</mi>
  <mi>i</mi><mi>j</mi><mi>k</mi><mi>l</mi>
  <mprescripts/><mi>a</mi><none/><mi>b</mi>
  ...
</mmultiscripts>

Tables and Matrices

table
<mrow><mo> [ </mo> <mtable>
<mtr>
  <mtd><mn>1</mn></mtd>
  <mtd><mn>0</mn></mtd>
  <mtd><mn>0</mn></mtd>
</mtr>
...
</mtable> <mo> ] </mo></mrow>
row
entry

Tables and Matrices (cont.)

align
<mtable 
  groupalign="decimalpoint left ...">
   <mtr><mtd><mrow>
        <maligngroup/>
        <mn> 8.44 </mn>
        <maligngroup/>
        <mi> x </mi>
        ...   
   </mrow></mtd></mtr>
   <mtr><mtd><mrow>
        <maligngroup/>
        <mn> 3.1 </mn>
        <maligngroup/>
        <mi> x </mi>
         ...
   </mrow></mtd></mtr>
</mtable>

Enlivening Expressions

<maction actiontype="toggle" selection="2">
    <mrow>...</mrow>
    <mrow>...</mrow>
</maction>

Other possible action types (depending on the rendering engine)

Content Markup

Content markup reflects the structure of formulae:

schematic view of the structure of an integr120al expression

Content Markup Details

Content markup reflects the structure of formulae:

  <apply><int/>
    <bvar><ci>t</ci></bvar>
    <lowlimit><cn>0</cn></lowlimit>
    <uplimit><cn>1</cn></uplimit>
    <apply><power/>
      <ci>t</ci>
      <cn>2</cn>
    </apply>
  </apply>

MathML does not define the exact mapping from content markup to rendering (only a "Default Rendering" is defined).

Content Markup

Fundamental Content Elements

Number
<cn type="complex-cartesian">
    3<sep/>4
</cn>
Variable
<apply>
  <ci>F</ci>
  <ci>x</ci>
</apply>
Apply construct
Numeric interval
<interval closure="open-closed">
  <cn>3</cn><cn>4</cn>
</interval>

Fundamental Content Elements (cont.)

Functions and operators
<apply><laplacian/>
  <ci>f</ci>
</apply>
Inverse function
<apply>
  <apply><inverse/><sin/></apply>
  <ci>x</ci>
</apply>

Fundamental Content Elements

Condition
<apply>
  <max/>
   <condition>
    <apply><and/>
      <apply><in/>
        <ci>x</ci>
        <ci type="set">B</ci>
      </apply>
      <apply><notin/>
        <ci>x</ci>
        <ci type="set">C</ci>
      </apply>
    </apply>
   </condition>
  <ci>x</ci>
</apply>

Fundamental Content Elements

Matrices
<matrix>
  <matrixrow> 
     <cn> 1 </cn> <cn> 2 </cn>
  </matrixrow>
  <matrixrow>
     <cn> 3 </cn> <cn> 4 </cn>
  </matrixrow>
</matrix>
Piecewise
<piecewise>
  <piece>
    <apply><minus/>
      <ci> x </ci>
    </apply>
    <apply><lt/>
      <ci> x </ci>
      <cn> 0 </cn>
    </apply>
  </piece>
  <piece>...</piece>
</piecewise>

Content Operators and Functions

Arithmetic, Algebra, Logic
quotient, exp, max, min, root, and, xor, forall, exists, floor ...
Relations
eq, neq, equivalent, ...
Calculus
ln, int, partialdiff, diff, limit, laplacian ...
Set theory
list, union, intersect, cartesian product ...

Content Operators and Functions

Sequences and series
sum, product, ...
Statistics
mean, variance, moment ...
Trigonometry
sin, arccos, ...
Linear algebra
vector, matrix, vector product, ...
Constants
integers, reals, pi, infinity, ...

Altogether cca. 100 elements!

Mixing Content and Presentation Markups

  <apply>
    <mrow>
      <msub>
        <mi>F</mi>
        <mi>i</mi>
      </msub>
    </mrow>
    <ci>x</ci>
  </apply>

Semantics of Content Elements

<!-- reference to OpenMath definition of Bessel function -->
<apply>
  <csymbol encoding="OpenMath"
    definitionURL="http://www.openmath.org/...">
    <msub><mi>J</mi><mn>0</mn></msub>
  </csymbol>
  <ci>y</ci>
</apply>

Adding semantics to an expression

<semantics>
  <apply>
  <divide/>
    <cn>123</cn>
    <cn>456</cn>
  </apply>
  <annotation encoding="Mathematica">
       N[123/456, 39]
  </annotation>
  <annotation encoding="Maple">
       evalf(123/456, 39);
  </annotation>
  <annotation-xml encoding="OpenMath">
    <OMA xmlns="http://www.openmath.org/OpenMath">
	  <OMS cd="arith1" name="divide"/>
	  <OMI>123</OMI>
	  <OMI>456</OMI>
    </OMA>
  </annotation-xml>
</semantics>

Using MathML with Other Markups

Embedding MathML

<embed src="mmls/mixExample.mml" height="60" width="110" />

Using “object”

<object type="application/mathml+xml"
   data="mmls/mixExample.mml"
   height="60" width="110"></object>

Full XML Based Usage: Namespaces

Using XHTML, the math content should be directly includable:

<body>
  <p>Bla bla bla</p>
  <m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
    <m:mrow>...<m:mrow>
  </m:math>
</body>

Full XML Based Usage: Common Approach

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <?xml-stylesheet type="text/xsl" href="mathml.xsl"?>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>

Further Information

These slides are at:
http://www.w3.org/Consortium/Offices/Presentations/MathML/
W3C MathML Activity Page:
http://www.w3.org/Math/
The latest release of the Recommendation
http://www.w3.org/TR/MathML2/
More information about W3C:
http://www.w3.org/Consortium/
Contact information:
http://www.w3.org/Consortium/Contact
Mail me:
ivan@w3.org