Skip to content Skip to navigation Skip to collection information

OpenStax_CNX

You are here: Home » Content » Connexions Guide to MathML » Content MathML Tags

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

Content MathML Tags

Module by: Connexions, Kyle Barnhart. E-mail the authors

Summary: A comprehensive explanation of the most commonly-used Content MathML tags. Provides an basic, step-by-step explanation as to how Content MathML expressions are built using these tags.

Let's take a close look at 2+2=4 2 2 4 expressed in Content MathML. From it, we can identify the most common tags used in C-MML expressions.

Example 1: Writing 2+2=4 2 2 4 in Content MathML

<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.

Tokens: cn, ci, and csymbol

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 11, 50005000, and 3.141593.14159 are all marked up with cn tags.

In our simple example, 2+2=4 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 XX, FF, or P2P2, is contained in a ci element.

If we wished to change our example expression into an algebraic relation, say x+2=4 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.

Apply

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 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 2 ) ( 4 ) = ( + 2 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."

Relations and Operators

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 a b )
  • neq ( ab a b )
  • gt ( a>b a b )
  • lt ( a<b a b )
  • geq ( ab a b )
  • leq ( ab a 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 a b c )
  • minus ( ab=c a b c )
  • divide ( ab=c a b c )
  • times ( ab=c a b c )
  • power ( ab=c a b c )
  • root ( ab=c a b c )

Collection Navigation

Content actions

Download:

Collection as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks