Mathematical Markup Language (MathML)
MohammadTaghi Hajiaghayi,
Department of Computer Science,
University of Waterloo,
mhajiaghayi@math.uwateroo.ca
Available On-line at:
http://www.cs.uwaterloo.ca/~mhajiaghayi/mathml/mathml.html
Slides
of this presentation
Another Slides
Abstract
This presentation defines the Mathematical Markup Language,
or MathML. MathML is an XML application for describing mathematical notation
and capturing both its structure and content. The goal of MathML
is to enable mathematics to be served, received, and processed on
the World Wide Web, just as HTML has enabled this functionality for text.
This paper is only a brief description of MathML and begins
with background information on mathematical notation, the problems it poses,
and the philosophy underlying the solutions MathML proposes. Additional
sections discuss about the MathML content and presentation elements,
what is the structure of MathML and finally how MathML renderers
might be implemented and should interact with browsers.
1. Introduction
MathML(Mathematical Markup Language) like HTML
is an appllication for defining and expressing Mathematics documents in
the WEB.
It's final goal is to provide a standard notation
on the Web that other softwares and application are be capable of reading
and expressing mathematical formulas on the internet.
The current method for defining the text documents
is using the GIF or other types of images but they are not appropriate
at all, because now there isn't any standard notaiton for representing
the mathematics on the web. So for example if you want to copy and
paste a formula, there would be so much problem, because you must copy
the actual image file, However, using the MathML you are be able to copy
and paste the mathematics formula like the other HTML text. Another
property of MathML is that, people with visual diabilities also can understand
the Mathematics formula, because the MathML documents can be easily converted
into alternative media such as speech and Braille. Also Mathml
Provide an standard mehtod for transfering data on
the web. However this capability can also be provided by sending Image
files, but it is not as easy as sending MathML documents because the MathML
documents are acutually only text documents and sending text is both easier
and less expensive (in the sense of the size of the files that must be
transfered on the web).
So far W3C the sponser of MathML has released two recommendation of
MathML. One is W3C MathML 1.0 Recommendation released on 7th April
1998 [1] and the other is MathML 1.01 Recommendation which was release
on 7 July 1999 [2].
At present, several vendors offers plug-ins appletes that can
render the MathML encoding, however Translatos and equation editor which
are capable of generating HTML pages with images of the mathematical expression
from HTML with embeded MathML codes are few.
1. Introduction to
MathML
MathML which stands for Mathematical
Markup Language, like HTML, is yet another, newly released,
markup language for expressing mathematical and scientific content over
the World Wide Web. It's meant to be a low-level language implemented by
applications, not by hand due to the fact that MathML markup is strict
when it comes to tag usage. MathML 1.01, a revised version of the W3C MathML
1.0 Recommendation (7th April 1998), was released on 7 July 1999.
1. 1. Why MathML?
Why bother creating a markup language
especially for math? Well, the current methods used to express mathematical
equations and scientific formulas, are by no means good enough. In most
cases a GIF image has to made to show math notation because such a format
can't be accomplished with standard HTML coding. For Example, E=MC^2 can't
be copied as an actual formula because it's an image. With MathML you'll
be able to copy and paste math expressions from and to other places, keeping
the integrity of the expression. People with visual disabilities will also
be able to read and use mathematical data since it can be interpreted into
alternative media such as speech or Braille. Another purpose of MathML
was to provide a way for machines to transfer mathematical content on the
Web that can be presented in a standard notation. The other purpose is
that, using MathML software actually utilize the expression or formula
to solve a problem in real time.
1. 2. Features
The cool thing about MathML is that
it's actual mathematical data that can be used in other computing areas.
By embedding MathML into a web page, external software can then use it
and process formulas, expressions, and scientific calculations, opening
the WWW to the world of mathematics. It increases the type of media that
can be presented and used on the Internet. It also relinquishes the use
of images to present mathematical concepts in a standard notation because
MathML interpreters will render the MathML in standard notation on the
document.
1. 3. MathML Software
Combined
with a style sheet to specify other aspects of layout, MathML should eventually
be used by browsers without the use of plug-ins. At present, several vendors
offer applet and plug-ins which can render MathML in place in a browser.
Translators and equation editors which can generate HTML pages with images
of the mathematical expression from HTML with embedded MathML code are
few currently. So far, W3C's Amaya browser supports MathML as does E-Lite
by ICEsoft. Netscape's new unreleased browser, titled Gecko, is planning
on fully supporting MathML, and maybe including a WYSIWYG editor
for mathematical equations. It is hoped that MathML will be also available
through the use of plug-ins for browsers that can't fully implement
it yet.
Another indicator of the importance of
MathML is the list of organizations that have expressed support for MathML.
It includes IBM, makers of the Techexplorer Scientific Browser; Wolfram
Research, makers of Mathematica 3.0; Waterloo Maple, makers of Maple V;
Hewlett-Packard, makers of the EzMath plug-in; the American Mathematical
Society, developers of a LaTeX to MathML translator; Design Science,
makers of the MathType equation editor; and yours truly, Design Science,
makers of the WebEQ suite of MathML tools.
2. MathML Overview
2. 1. Presentation and
Content
Think about trying to help a student with a math problem over the phone.
Your first challenge is to make sure you are both talking about the same
thing, and there are two natural approaches. You can say things like "use
the chain rule to write down the derivative of f composed with g", or,
if the student is really at sea, you can say "write f prime, open paren,
g of x, close paren, g prime of x". The first method tries to communicate
the sense or meaning, and leaves the notation up to the student. The second
method tries to convey the notation, so that by looking at it, the student
can grasp the sense.
In
MathML, these two styles of encoding are called content encodings and presentation
encodings. Which kind of encoding is most appropriate for a given task
will depend on the situation. MathML allows an author to use either kind
of encoding, or mix them in a hybrid.
There
are 28 MathML presentation elements, with about 50 attributes. These elements
are for encoding mathematical notation. Most elements represent
templates or patterns for laying out subexpressions. For example, there
is an mfrac element, which as you would expect, is used for forming
a fraction from two expressions by putting one over the other with a line
in between. Using presentation elements, you can precisely control how
an expression will look when displayed in a browser, or printed on paper.
Unfortunately, as with any layout-based mark-up language, it is all
too easy to get it to look right, without taking care to get the underlying
structure right. In some cases this won't matter, but it is less likely
a badly encoded expression could be spoken properly by a voice synthesizer,
evaluated in a computer algebra system, or used by other applications which
need to know something of the sense of an expression, rather than just
its appearance.
For
content markup, there are around 75 elements, with about a dozen attributes.
Many of these elements come in families, and represent mathematical operations
and functions, such as plus and sin. Others represent mathematical
objects like set and vector. Content markup is intended for
facilitating applications other than display, like computer algebra, and
speech synthesis. As a consequence, when using content mark-up, it is harder
to directly control how an expression will be displayed.
2.
2. Examples and Expression Trees
If
you look at a lot of math notation, you will soon notice that although
there are a lot of math symbols, there are only a few ways of arranging
them -- a row, subscript and superscripts, fractions, matrices and a few
others. Of course, these notational patterns or schemata often appear nested
inside one another, such as a square root of a fraction, and they generally
have a number of parameters which depend on the context, such as the amount
to shift a superscript for inline math vs. displayed math. The important
point is that even complicated, nested expressions are built-up from a
handful of simple schemata.
MathML
presentation elements encode the way an expression is built-up from of
the nested layout schemata. The best way to understand how this works is
to look at an example:
(a + b)^2
This
expression naturally breaks into a "base," the (a + b), and a "script,"
which is the single character '2' in this case. The base decomposes further
into a sequence of two characters and three symbols. Of course, the decomposition
process terminates with indivisible expressions such as digits, letters,
or other symbol characters. The MathML presentation encoding of this expression
is:
<msup>
<mfenced>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
</mfenced>
<mn>2</mn>
</msup>
The top-level structure is an expression with a superscript. This is
encoded by the fact that the outermost tags in the MathML mark-up are the
<msup>
and </msup> tags. The mark-up in between the start tag and the
end tag defines the base and the superscript. The first subexpression is
an mfenced element, which displays its contents surrounded by parentheses.
The second expression is the character 2, enclosed in <mn> tags,
which tell a renderer to display it like a number. Similarly, the subexpressions
contained in the mfenced element are all individual characters, wrapped
in tags to indiciate that they should be displayed as identifiers (<mi>)
and operators (<mo>) respectively.
Though
we won't go into this until later, the content markup for the same example
might be:
<apply>
<power/>
<apply>
<plus/>
<ci>a</ci>
<ci>b</ci>
</apply>
<cn>2</cn>
</apply>
As you see, content mark-up uses the same kind of syntax as presentation
markup. Each layout schemata or content construction corresponds to a pair
of start and end tags (except for so-called empty elements like
<plus/>,
which we will encounter later). The mark-up for subexpressions is enclosed
between the start and end tags, and the order they appear in determines
what roles they play, e.g. the first child is the base and the second shild
is the superscript in an msup schema.
As
the indentation of the MathML examples suggests, it is natural to think
about MathML expressions as tree structures. Each node in the tree corresponds
to a particular layout schema, and its "branches" or child nodes correspond
to its subexpressions. This abstract expression tree is a handy thing to
have in the back of your mind. It also describes how the MathML tags should
be nested to encode the expression, and how typesetting "boxes" should
be nested on the screen to display the notation. You can see one mathematical
notaion and its tree structure in figure below:
3. Elements and Attributes
Many
people are somewhat familiar with HTML-style syntax. In HTML, one mixes
keywords in angle brackets with the text to indicate logical sections like
paragraphs and titles. Different kinds of logical blocks display in different
styles. Often, one can specify variants on a theme by adding attributes
in the start tags of a particular block. For example, in HTML, the start
and end tags <table> and </table> mark a table section, and you can
specify variations by adding attributes like <table width="85%">.
MathML
uses a very similar style of mark-up. In MathML, because of the nature
of the subject matter, the ratio of tags to text is much higher than in
HTML, but the start tag/end tag syntax and the use of attributes is the
same. In MathML there are two kinds of elements. Most elements have start
and end tags of the form:
<element_name>
... </element_name>
These
elements can have other data in between the start and end tag, such as
text, extended characters, or other elements. The remaining MathML elements
are empty elements of the form:
<element_name/>
These
elements have just one tag, which looks like a hybrid between a start and
an end tag.
All
MathML elements accept a few attributes, and some accept a dozen or more.
Attributes generally specify additional information about the element.
Each attribute has a name and a value. When used with an element that has
both start and end tags, the attributes go in the start tag between the
element name and the final '>'. In empty elements, attributes go
in between the element name and the final '/>'.
Attribute
values must always be enclosed in quotes. In XML, either double or single
quotes are permitted. A couple of templates illustrate the general
format for attributes:
<element_name
attrib_name1='val1' attrib_name2='val2' ... >
and
<element_name
attrib_name='value'/>
Most
MathML attribute values are required to be in a particular format, such
as a positive integer, or one of a short list of keywords like "true"
and "false".
The
final thing you need to know about MathML syntax is how the actual text
and symbol characters needed for mathematical formulas are encoded. First
of all, characters and symbols can only appear inside a handful of special
MathML elements called token elements. Consider an example:
<mrow>
<mi>a</mi>
<mo>+</mo>
<mi>b</mi>
</mrow>
Most MathML elements, like the outer mrow element, expect to
only find other MathML elements in their content. By contrast, the mi
and
mo
elements are tokens, and their content consists of characters and
symbols.
Within
token elements, one can have plain text characters, which display as themselves,
or special entity refereneces. Entity references are just keywords in a
special format, which represent extended characters. Examples of character
references are α and ∩ which stand for
a lower case Greek alpha, and the intersection sign, respectively. MathML
renderers, with access to symbol fonts, will display the actual extended
character glyph in the place of the entity reference.
The
format for an entity reference is a keyword preceded by an ampersand (&)
and followed by a semicolon (;). That is, a generic entity reference looks
like: &entity_name;.
Most
of the MathML entities names are nearly identical to LaTeX symbol names:
To write a LaTeX symbol such as \alpha in a form used by MathML,
remove the initial backslash and add an ampersand to the beginning and
a semi-colon to the end of the word. Thus, \alpha becomes α
.
The
complete list of MathML entity references is very long and comprehensive
with more than 1800 symbols and therefore is not included here. you
may find them in the references.
4.
Boxes
MathML
presentation mark-up is based around the idea of a layout box. You
can think of a layout box as a sort of abstract bounding box for a particular
kind of mathematical notation. Layout boxes naturally fall into categories
based on their contents. Simple layout boxes just contain individual characters,
and their dimensions depend only on the font being used. More complicated
layout boxes arrange their "child boxes" according to some algorithm.
For example, a fraction box arranges two child boxes to be vertically stacked
with a line between, and centered horizontally.

For
these cases, the actual dimensions of a layout box depend recursively on
the sizes of the child boxes. If you think about trying to typeset a mathematical
expression by hand, it is clear why layout boxes are a good idea. The first
time you typeset a fraction, you have to work out the algorithm for computing
the horizontal and vertical positions for the numerator and denominator
expressions. Once that is done, you can teach it to your assistant, and
he or she can do all the calculation without knowing anything but the dimensions
of the subexpressions. Or more likely, these days you create a digital
assistant to do it.