6.3 Parallel Markup

 < Day Day Up > 



6.3 Parallel Markup

In many cases, it is desirable to encode both the presentation and content markup for a mathematical expression. A MathML processing application can then use one type of markup or the other, depending on the context. For example, the presentation markup could be used for displaying the expression in a Web page while the content markup could be used for copying and pasting the expression into a computer algebra system for evaluation. This type of combined markup is called parallel markup because it contains multiple encodings of the same expression, in parallel branches of the main expression tree.

The mechanism used in MathML for providing multiple encodings of the same expression is the semantics element. The syntax of the semantics element was discussed in Section 5.7. The first child of this element is a complete content markup or presentation markup expression. The second child can be an annotation-xml element that contains the same expression encoded in a different form. The form of the annotation is specified using the encoding attribute of the annotation-xml element. This attribute has the value MathML-Content for content markup and MathML-Presentation for presentation markup.

Top-level Parallel Markup

Parallel markup that consists of a single semantics element is called top-level parallel markup. This is because it establishes a correspondence between the content encoding and presentation encoding of the main top-level expression.

To specify a particular rendering for a given piece of content markup, you would specify a content expression as the first argument of the semantics element and the corresponding presentation expression as the second argument. Here is an example:

  • f(x)

    <semantics>      <apply>        <diff/>          <bvar><ci>x</ci></bvar>          <apply>            <ci type="fn">f</ci>            <ci>x</ci>          </apply>        </apply>      <annotation-xml encoding="MathML-Presentation">        <mrow>          <msup>            <mi>f</mi><mo>&prime;</mo>          </msup>          <mo>(</mo><mi>x</mi><mo>)</mo>        </mrow>       </annotation-xml>      </semantics> 

By default, a particular MathML application might render the content expression in the above markup as . By using presentation markup as an annotation, you can specify that the content expression be rendered as f(x) instead.

Alternatively, you can specify the presentation encoding as the first argument and place the content encoding in the second argument. Here is the same example as the one just shown; this time, however, the order of presentation and content markup is reversed:

  • f(x)

    <semantics>        <mrow>          <msup>            <mi>f</mi><mo>&prime;</mo>          </msup>          <mo>(</mo><mi>x</mi><mo>)</mo>       </mrow>      <annotation-xml encoding="MathML-Content">      <apply>        <diff/>          <bvar><ci>x</ci></bvar>          <apply>            <ci type="fn">f</ci>            <ci>x</ci>          </apply>        </apply>      </annotation-xml>     </semantics> 

Notice that the encoding attribute of the annotation-xml element is set to MathML-Content in this case (as opposed to MathML-Presentation in the earlier example).

The type of markup shown in the previous example is useful for applications that are primarily presentation based but that can benefit from additional information provided by the content markup annotation.

Fine-grained Parallel Markup

In top-level parallel markup, the content and presentation markup for the entire expression are each contained in a different branch of a single semantics element. Thus, the correspondence between the presentation and content encodings is for the entire expression as a whole. However, in some contexts, you need to specify the correspondence between presentation and content encodings of subexpressions of the main expression as well. One way to accomplish this is to use nested semantics elements, thereby creating what is called fine-grained parallel markup.

This type of markup can be useful, for example, in an equation editor that allows a user to build up complicated expressions by nesting and combining smaller, simpler subexpressions. Suppose the application internally stores a representation of each expression in MathML form. Since a user might select a particular fragment of a large expression for copying and pasting, it is desirable for both the content and presentation markup of the selected fragment to be included in the content copied to the clipboard.

Consider the following example of top-level parallel markup:

  • x2 + sin(x)

    <semantics>      <mrow>        <msup><mi>x</mi><mn>2</mn></msup>        <mo>+</mo>        <mrow>          <mi>sin</mi><mo>&ApplyFunction;</mo>          <mo>(</mo><mi>x</mi><mo>)</mo>        </mrow>      </mrow>      <annotation-xml encoding='MathML-Content'>        <apply>          <plus/>          <apply><power/><ci>x</ci><cn>2</cn></apply>          <apply><sin/><ci>x</ci></apply>        </apply>      </annotation-xml>     </semantics> 

Here is the same expression represented using fine-grained parallel markup, involving two nested semantics elements:

  • x2 + sin(x)

    <semantics>      <mrow>        <semantics>          <msup><mi>x</mi><mn>2</mn></msup>          <annotation-xml encoding="MathML-Content">            <apply><power/><ci>x</ci><cn>2</cn></apply>          </annotation-xml>        </semantics>        <mo>+</mo>        <semantics>          <mrow>            <mi>sin</mi><mo>&ApplyFunction;</mo>            <mo>(</mo><mi>x</mi><mo>)</mo>          </mrow>          <annotation-xml encoding="MathML-Content">            <apply><sin/><ci>x</ci></apply>          </annotation-xml>        </semantics>s      </mrow>      <annotation-xml encoding="MathML-Content">        <apply>          <plus/>          <apply><power/><ci>x</ci><cn>2</cn></apply>          <apply><sin/><ci>x</ci></apply>        </apply>      </annotation-xml>     </semantics> 

This markup provides separate content and presentation encodings of the two terms x2 and sin(x), as well as for the top-level expression, x2 + sin(x).

Using Cross-References

By using a sufficient number of semantics elements, you can explicitly specify down to as small a level as desired the correspondence between content and presentation encodings of sub-expressions of the main expression. However, the limitation of this approach is that the markup quickly becomes very verbose, which leads to a large increase in the size of the document.

A more efficient way to specify fine-grained markup is to use the id and xref tags, which all MathML elements support. These tags provide a compact way to create cross-references between different parts of the expression tree. You can then use cross-references to associate content elements with the corresponding presentation elements, down to the level of the individual token elements that represent the leaves of the expression tree-namely, numbers, operators, and identifiers.

The id and xref attributes can be set to any arbitrary value, as long as that value is unique within the document. Any element with an id attribute then defines a target, which is referenced by all elements that have an xref attribute with the same value. The following markup uses cross-references to represent the same expression used in the last example:

  • x2 + sin(x)

    <semantics>      <mrow >        <msup >          <mi >x</mi>          <mn >2</mn>        </msup>        <mo >+</mo>        <mrow >          <mi >sin</mi>          <mo >&ApplyFunction;</mo>          <mo >(</mo>          <mi >x</mi>          <mo >)</mo>        </mrow>      </mrow>      <annotation-xml encoding='MathML-Content'>        <apply xref="A">          <plus xref="A.2"/>          <apply xref="A.1">          <power/>           <ci xref="A.1.1">x</ci>           <cn xref="A.1.2">2</cn>         </apply>          <apply xref="A.3.2">         <sin xref="A.3.1"/>        <ci                xref="A.3.4">x</ci>        </apply>        </apply>      </annotation-xml>     </semantics> 

Notice that the content and presentation encodings of the entire expression, x2 + sin(x), are associated using id and xref attributes with the value A. Moving one level down the expression tree, the two encodings of the term x2 are identified using the id and xref pairs having the value A.1. Finally, the token elements in the content and presentation markup, describing the identifier x and the number 2 in the first term, are identified using the values A.1.1 and A.1.2.



 < 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