3.2 Presentation and Content

 < Day Day Up > 



3.2 Presentation and Content

The appearance of mathematical notation and its conceptual meaning have a complex relationship. The same notation can express two completely different mathematical meanings, depending on the context. For example, the expression f(x + y) can be interpreted in two ways:

  • The value of a function f with the arguments x and y

  • The variable f multiplied by the sum of x and y

Conversely, a given mathematical concept can be expressed by more than one notation. For example, the notations and f(x) both have the same mathematical meaning; that is, the derivative of the function f with respect to x. Yet the two notations are distinct in their visual appearance. Similarly, the operation of dividing a by b can be represented in at least three different ways: a / b, , or ab1.

Due to such ambiguity, it is important to have some way of independently specifying the appearance and meaning of a given type of mathematical notation. The solution adopted in MathML is to use two separate sets of tags for these two purposes. Presentation tags are used to encode the appearance of mathematical notation-that is, its visual two-dimensional structure. Content tags, on the other hand, are used to encode the symbolic meaning conveyed by the notation.

Hence, any mathematical expression can be represented in several different ways in MathML:

  • Using only presentation tags. This type of markup is called presentation markup. It is useful in situations where the primary goal is to display mathematical notation, without regard to its meaning. This is the case, for example, when you include equations in a document that is intended only for display on the Web.

  • Using only content tags. This type of markup is called content markup. It is useful in situations where it is important to encode mathematical meaning; for example, if you want to post an equation on a Web page that readers can copy and paste into Mathematica for evaluation.

  • Using a combination of presentation and content tags. This type of markup is called combined markup and is used when you want to encode both the appearance and meaning of equations. For example, you can use combined markup to specify a nonstandard notation for a common mathematical construct or to associate a specific mathematical meaning with a certain type of notation that usually has a different meaning.

Presentation Markup

MathML presentation markup consists of about 30 elements and 50 attributes. The most important presentation elements are the so-called token elements-mo, mn, and mi-which are used to represent operators (such as + or ), numbers (such as 3.14 or -27), and identifiers (that is, variables like x or y), respectively.

Token elements are the only presentation elements that can directly contain character data. All other elements can only contain other MathML elements. The reason for using separate elements to represent operators, numbers, and identifiers is so that each type of item can be rendered according to its own typesetting conventions. For example, operators have extra spacing around them, numbers are usually shown in an upright font, and identifiers are typically italicized.

This simple example of presentation markup encodes the expression x + y :

x + y

    <math>      <mrow>        <mi>x</mi>        <mo>+</mo>        <mi>y</mi>      </mrow>    </math> 

The outermost element of the expression is a math element, as required for any piece of MathML markup. The rest of the markup consists of two mi elements for representing the identifiers x and y and an mo element representing the operator +. These are all enclosed in an mrow element, which causes its child elements to be displayed in a horizontal row.

Here is the presentation markup for a slightly more complicated expression:

(x + y)2.

    <math>      <msup>        <mrow>           <mo>(</mo>           <mrow>              <mi>x</mi>              <mo>+</mo>              <mi>y</mi>           </mrow>        <mo>)</mo>     </mrow>     <mn>2</mn>    </msup>    </math> 

The first element in the markup after the math element is msup, which reflects the fact that the encoded expression consists of a base with a superscript. The msup element has two arguments, which represent the base expression and the superscript, respectively. That is, it has the syntax: <msup> base index </msup>. The base and index terms can either be token elements or more complicated expressions consisting of other MathML elements.

In the above example, the base consists of a single mrow element that is used to encode the expression x + y. The superscript (that is, the second argument of the msup element) is the number 2 enclosed in an mn element to indicate that it is a number.

This example indicates some general principles that you can use to determine the presentation markup for any mathematical expression. Each expression is decomposed into its constituent subexpressions, and the process is continued recursively until one reaches the fundamental or atomic units of the expression, namely numbers, operators, or identifiers. The atomic units are represented by the appropriate token elements. All other subexpressions are then represented by the corresponding MathML presentation elements, so that the recursive structure of the MathML tree exactly duplicates the recursive structure of the original expression.

Here is the presentation markup for a simple quadratic polynomial:

x2 2x + 1

    <math>      <mrow>        <msup>          <mi>x</mi>          <mn>2</mn>        </msup>        <mo>-</mo>        <mrow>          <mn>2</mn>          <mo>&InvisibleTimes;</mo>          <mi>x</mi>        </mrow>        <mo>+</mo>        <mn>1</mn>      </mrow>    </math> 

This example uses the mrow and msup elements introduced in the previous example, along with the token elements mi, mn, and mo. The additional feature here is the use of the entity reference &InvisibleTimes; to indicate that the 2 and the x are being multiplied together. The use of this entity reference is not required, since the visual display of the equation is unaffected if the <mo>&InvisibleTimes;</mo> element is omitted altogether.

However, if you explicitly include the entity reference, the markup gives additional information about the meaning of the equation. This information is useful, for example, when you are evaluating the markup in a computer algebra system or converting it to an audio rendering. Hence, the use of such entities is strongly encouraged in presentation MathML. Note that for applications in which interpreting the meaning of an equation is important, the use of content MathML would be preferable.

The following example illustrates how you can use presentation markup to represent fractions and square roots:

    <math>      <mrow>        <mfrac>          <mrow>            <mn>1</mn>            <mo>+</mo>            <msqrt>              <mn>5</mn>            </msqrt>          </mrow>            <mn>2</mn>        </mfrac>      </mrow>    </math> 

The mfrac and msqrt elements are used to represent fractions and square roots, respectively. The mfrac element has the syntax: <mfrac> num denom </mfrac>, where the first argument is the numerator and the second argument is the denominator.

Here is the presentation markup for the solution of a general quadratic equation:

    <math>      <mrow>        <mi>x</mi>        <mo>=</mo>        <mfrac>          <mrow>            <mo>-</mo>            <mi>b</mi>            <mo>&PlusMinus;</mo>            <msqrt>              <mrow>                <msup>                  <mi>b</mi>                  <mn>2</mn>                </msup>                <mo>-</mo>                <mrow>                  <mn>4</mn>                  <mo>&InvisibleTimes;</mo>                  <mi>a</mi>                  <mo>&InvisibleTimes;</mo>                  <mi>c</mi>                </mrow>              </mrow>            </msqrt>          </mrow>          <mrow>            <mn>2</mn>            <mo>&InvisibleTimes;</mo>            <mi>a</mi>          </mrow>        </mfrac>      </mrow>    </math> 

This example uses several of the presentation elements introduced so far: mrow, msqrt, msup, and mfrac. It differs from the previous example only in the complexity of the nesting: the markup has a larger number of elements that reflect the complexity of the layout tree from which the expression is composed. Note the use of the entity reference &InvisibleTimes; to explicitly indicate multiplication. The example also uses the entity reference &PlusMinus; to represent the ± symbol.

Here is the presentation markup for a simple matrix:

    <math>      <mrow>        <mo>(</mo>        <mtable>          <mtr>            <mtd><mi>a</mi></mtd>            <mtd><mi>b</mi></mtd>          </mtr>          <mtr>            <mtd><mi>c</mi></mtd>            <mtd><mi>d</mi></mtd>          </mtr>        </mtable>        <mo>)</mo>      </mrow>    </math> 

The outermost element of the matrix is an mtable element, which is used to represent any type of table or array. Each row of the table is enclosed in an mtr element, and each entry or cell in a row is enclosed in an mtd element. The parentheses surrounding the matrix are indicated explicitly using mo elements.

Here is the presentation markup for an equation involving an integral:

    <math>      <mrow>        <mrow>          <msubsup>            <mo>&int;</mo>            <mn>0</mn>            <mi>&infin;</mi>          </msubsup>          <mrow>            <msup>              <mi>&ExponentialE;</mi>              <mrow>                <mo>-</mo>                <mi>x</mi>              </mrow>            </msup>            <mo>&InvisibleTimes;</mo>            <mrow>              <mo>&DifferentialD;</mo>              <mi>x</mi>            </mrow>          </mrow>        </mrow>        <mo>=</mo>        <mn>1</mn>      </mrow>    </math> 

The only new element introduced in this example is msubsup, which has the syntax: <msubsup> base subscript superscript</msup>. This element is used to position a subscript and superscript symmetrically about a base expression. Note the use of the named entity references &int;, &ExponentialE;, and &DifferentialD; to represent the integral, exponential, and differential d symbols, respectively. As with the use of &InvisibleTimes;, the use of these named character references provides useful information about the meaning of the expression.

Content Markup

MathML content markup consists of about 150 elements and 12 attributes. The majority of content elements are empty elements that represent a specific operator, function, or relation. Examples of such elements are plus, power, log, and sin.

Content markup also contains three different token elements, cn, ci, and csymbol, which are used to encode numbers, identifiers, and user-defined symbols, respectively. Content token elements are the only content elements that can directly contain character data. All other content elements are either empty elements or can contain only other content elements.

The single most important content element is the apply element, which is used to apply operators or functions to expressions. The first argument of the apply element is typically an element that represents an operator or function. The remaining arguments represent one or more expressions to which the first argument is applied.

Content markup is based on the concept of prefix notation, a convention for writing mathematical expressions that is used in programming languages like LISP. In prefix notation, any expression is written as an operator followed by the objects it operates on, namely its operands. For example, to represent x + y in prefix notation, you would write something like + x y. Similarly, to represent x2, you would write Power x 2. You can represent more complicated expressions in prefix notation by nesting and combining smaller subexpressions.

To get the content markup for an expressions, you first write the expression in prefix notation; then you replace each operator and operand by the corresponding content elements. Here is a simple example of content markup:

x2

    <math>      <apply>        <power/>        <ci>x</ci>        <cn>2</cn>      </apply>    </math> 

The markup consists of a single apply element, followed by three elements that each represent an argument of the apply element. The first element is the empty element power, which represents the function to be applied. The next two elements, ci and cn, represent the arguments to which the power function is applied. The ci element represents the base and the cn element the power.

Here is the content markup for the expression: x + y:

x + y

    <math>      <apply>        <plus/>        <ci>x</ci>        <ci>y</ci>      </apply>    </math> 

The markup consists of a single apply element followed by a plus element (which represents the function to be applied) and two ci elements (which represent the arguments to which the plus function is applied).

Here is the content markup for a slightly more complicated expression:

(x + y)2

    <math>      <apply>        <power/>        <apply>          <plus/>          <ci>x</ci>          <ci>y</ci>        </apply>        <cn>2</cn>      </apply>    </math> 

This markup combines elements of both the previous examples. It uses two nested apply elements. The inner apply element is used to encode the sum x + y, and the outer apply element is used to raise the summed expression to the power of two.

Here is the content markup for a simple algebraic expression:

x2 2x + 1

    <math>      <apply>        <plus/>        <apply>          <minus/>          <apply>            <power/>            <ci>x</ci>            <cn>2</cn>          </apply>          <apply>            <times/>            <cn>2</cn>            <ci>x</ci>          </apply>        </apply>        <cn>1</cn>      </apply>    </math> 

This example uses the apply, plus, and power elements that we saw in combination with the minus and times elements. The last two elements represent subtraction and multiplication, respectively.

The following example illustrates how to represent fractions and square roots using content markup:

    <math>      <apply>        <divide/>        <apply>          <plus/>          <cn>1</cn>          <apply>            <root/>            <cn>5</cn>          </apply>        </apply>        <cn>2</cn>      </apply>    </math> 

The square root is encoded using the root element. You can also use this element to represent radicals by specifying the degree of the radical as the second argument. As you can see, more complicated expressions are built up in a straightforward way by combining and nesting smaller subexpressions, as required.

Here is the content markup for a simple matrix:

    <math>      <matrix>        <matrixrow>          <ci>a</ci>          <ci>b</ci>        </matrixrow>        <matrixrow >          <ci>c</ci>          <ci>d</ci>        </matrixrow >      </matrix>    </math> 

Here is the content markup for an equation involving an integral:

    <math>      <apply>        <eq/>        <apply>          <int/>          <bvar><ci>x</ci></bvar>          <lowlimit><cn>0</cn></lowlimit>          <uplimit><infinity/></uplimit>          <apply>            <power/>            <exponentiale/>            <apply>              <minus/>              <ci>x</ci>            </apply>          </apply>        </apply>        <cn>1</cn>      </apply>    </math> 

In the above example, the int element is used to represent an integral. The lowlimit, uplimit, and bvar elements are used to represent the upper limit, lower limit, and variable of integration, respectively. The constants and e are represented using the content elements infinity and exponentiale, respectively.

Handling Whitespace

MathML ignores all whitespace (spaces, tabs, new lines, or carriage returns) that occurs outside of token elements. Whitespace occurring within token elements is trimmed from the ends; that is, all whitespace at the beginning and end of the content is removed Whitespace internal to MathML elements is collapsed so that each sequence of one or more spaces is replaced by exactly one blank space.

If you need to explicitly encode whitespace characters at the start or end of the content of a token element or in sequences other than a single space, you can do so by using the &nbsp; entity reference or the whitespace character entities (such as &ThinSpace;, &MediumSpace;, and &ThickSpace;). For whitespace that occurs outside of token elements, you should use an mspace element instead of an mtext element that contains whitespace entities.



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net