<< Chapter < Page | Chapter >> Page > |
Let's take a close look at $2+2=4$ expressed in Content MathML. From it, we can identify the most common tags used in C-MML expressions.
<m:math><m:apply><m:eq/><m:apply><m:plus/><m:cn>2</m:cn><m:cn>2</m:cn></m:apply><m:cn>4</m:cn></m:apply></m:math>
There are a few things you should note immediately about the code above. Every tag (or
element , as they are formally known) is contained in brackets and begins with a "m:" to signify that it is a MathML tag. We say that this "m:" defines the
namespace of the element. Namespaces are used in web markup languages to keep track of which language (such as XHTML or QML) is being "spoken." Also notice that the equation begins with the
math
element, which denotes the beginning of every MathML expression.
Like other web-based markup languages, MathML tags have corresponding end tags which mark the end of a section-- in this case, the end of an operation or modifier. Every end tag is essentially the same as it's start tag, but with a forward slash ("/") character in front of the name.
There are over a hundred different Content MathML tags, but only a few that are used in the majority of expressions. Remember, you can always refer to the W3C's Content MathML page to look up a tag if you can't remember it.
Each number, variable, and symbol has to be explicitly marked up in a given MathML expression. There are three different elements used to mark up these operands.
cn
ci
csymbol
cn
The
cn element is used to denote an explicit number, as opposed to a variable or symbolic representation of a number. Values such as
1 ,
-5000 , and
3.14159 are all marked up with
cn
tags.
In our simple example,
$2+2=4$ , there are three numbers marked up with
cn
tags.
<m:math><m:apply><m:eq/><m:apply><m:plus/>
<m:cn>2</m:cn><m:cn>2</m:cn> </m:apply>
<m:cn>4</m:cn> </m:apply></m:math>
ci
The
ci element is used to markup variables. Any non-explicit representation of a number, such as
X ,
F , or
{P}_{2} , is contained in a
ci
element.
If we wished to change our example expression into an algebraic relation, say $x+2=4$ , then we would only need to make one small change to the Content MathML markup.
<m:math><m:apply><m:eq/><m:apply><m:plus/>
<m:ci>x</m:ci> <m:cn>2</m:cn></m:apply><m:cn>4</m:cn></m:apply></m:math>
While the csymbol is a valid Content MathML construct, its use is fairly uncommon and therefor it will not be discussed in this module.
Now that we understand how to markup operands, we need to know how to relate and operate upon them to form an expression. The most fundamental tag for writing Content MathML is the
apply tag, which governs the way operations and modifiers are placed in the expression. Take another look at the
example above , and you might notice that there are two
apply
tags. The
apply
tag is MathML's way of indicating that an operation or relation should be introduced.
The first child of an
apply
tag is the operation or relation we wish to implement. Colloquially, a
child is any element directly within (or "under") an element.
<m:math><m:apply><m:eq/>
<m:apply>
<m:plus/>
<m:cn>2</m:cn><m:cn>2</m:cn> </m:apply><m:cn>4</m:cn></m:apply></m:math>
In the code block above, the
apply
tag is highlighted in bold and the
apply
tag's first child element is italicized. The
apply
tag will always understand its first child to be the operation or relation. The operation in this case is
plus
(addition).
The second child of the
apply
tag is always the first element being acted upon. There may be even more children depending on what kind of operation is being applied. It wouldn't make any sense to apply sine to two numbers but it
does make sense of apply addition to two numbers. For our example, there are two child elements after the
plus
tag, both of which are
cn
elements containing "2". So the instruction reads "apply addition to two and two," or
$2+2$
It can be difficult to understand the way that
apply
tags work since MathML doesn't "read" like a typical mathematical expression. Again, remember that Content MathML is focused on applying operations in order to convey semantics. If we were to simply transcribe our Content MathML example onto paper as operations and numbers, it would look something like this:
=(+2\text{}2)(4)
Equations written in this way are said to be in prefix notation (or Polish notation ). It's may seem very counter-intuitive, but computers handle this notation a lot faster than "normal" (or infix ) notation.
To expand our understanding of the
apply
tag in Content MathML, let's look at the topmost
apply
tag and its children.
<m:math>
<m:apply>
<m:eq/>
<m:apply> <m:plus/><m:cn>2</m:cn><m:cn>2</m:cn></m:apply>
<m:cn>4</m:cn> </m:apply></m:math>
The first child of
apply
is the
eq
element, which corresponds to equality ("="). The second child, however, is another
apply
tag. This means that
everything inside this second
apply
tag is the first argument . The third direct child of the first apply tag is a
cn
containing the number 4. This means that "whatever is in the second
apply
tag is equal to four."
Mathematical expressions usually involve at least one
relation , such as equality ("=") or one number being greater than the other ("<" or ">"). Content MathML offers an extensive library of relational elements. The
<eq/>
relation is highlighted in our example expression below.
<m:math><m:apply>
<m:eq/> <m:apply><m:plus/><m:cn>2</m:cn><m:cn>2</m:cn></m:apply><m:cn>4</m:cn></m:apply></m:math>
Notice that the
<eq/>
element does not have an end tag. This is because relations and operations are generally declared using an
empty tag . It doesn't "contain" anything, so it simply terminates itself with a forward slash at the end of the element.
There are several commonly-used Content MathML relation elements. These include:
eq
(
a=b )neq
(
a\neq b )gt
(
a> b )lt
(
a< b )geq
(
a\ge b )leq
(
a\le b )Similarly, we usually have at least one operator in a given mathematical expression. Some of the most common operators used in Content MathML include:
plus
(
a+b=c )minus
(
a-b=c )divide
(
\frac{a}{b}=c )times
(
ab=c )power
(
a^{b}=c )root
(
\sqrt{ab}=c )Notification Switch
Would you like to follow the 'Connexions guide to mathml' conversation and receive update notifications?