4.2 Token Elements

 < Day Day Up > 



4.2 Token Elements

There are three different types of token elements in presentation markup: mi, mn, and mo. This section discusses these elements in more detail.

Style Attributes

A set of style attributes controls the precise way in which the content of token elements is rendered There are nine style attributes that all token elements accept. These attributes can be divided into two groups, depending on which version of MathML they were introduced in (Tables 4.4 and 4.5).

Table 4.4: Style Attributes Introduced in MathML 2.0

Name

Property Specified

Allowed Value

mathbackground

Background color

#rgb | #rrggbb | html-colorname

mathcolor

Text color

#rgb | #rrggbb | html-colorname

mathsize

Font size

small | normal | big | number v-unit

mathvariant

Style variant

normal | bold | italic | script | bold-script | double-struck | fraktur | bold-fraktur | sans-serif | bold-sans-serif | sans-serif-italic | monospace

html-color-name refers to one of the named color keywords defined in HTML 4 (that is, aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow).

Table 4.5: Style Attributes Introduced in MathML 1.0

Name

Property Specified

Allowed Value

color

Text color

#rgb | #rrggbb | html-colorname

fontfamily

Font family

string | css-fontfamily

fontsize

Font size

number v-unit

fontstyle

Font style

normal | italic

fontweight

Font weight

normal | bold

The use of the second set of attributes is deprecated in MathML 2.0 since they conflict with properties of the same name defined in CSS. Having the same attribute names in MathML and CSS can lead to problems. For example, the meaning of an equation may be altered by system-wide style changes applied using a CSS stylesheet. These attributes are still supported for backward compatibility and because they provide a simple way to directly specify common style properties. For some examples of how these attributes can be used in a CSS stylesheet, to control the rendering of MathML equations, see Section 8.2.

There is some overlap between the style attributes introduced in MathML 2.0 and the older ones from MathML 1.0. For example, you can specify the color of an equation using either the color or mathcolor attributes. Similarly, you can cause an equation to be displayed in bold font using either fontweight or mathvariant. In case of a conflict between the new attributes (from MathML 2.0) and the deprecated attributes (MathML 1.0), the former take precedence. For example, the following expression should render in a bold font.

ABC

    <mi fontweight="normal" mathvariant="bold">ABC</mi> 

The following expression should render in an italic sans-serif font.

ABC

    <mi fontweight='bold' mathvariant= 'sans-serif-italic'>        ABC</mi> 

In practice, most MathML expressions are likely to be embedded in another XML data format such as XHTML. In such cases, it is desirable for the displayed equations to have the same style attributes as the surrounding text, so that the font styles and sizes, for example, are compatible with the environment. For this reason, the default values of most of the above style attributes are inherited from the environment.

The meaning and usage of most of the style attributes listed above are evident from their names. However, the mathvariant attribute requires some further explanation. This attribute specifies that a character should be displayed in a particular font variant, such as Fraktur, Bold, Italic, Script, Bold-Script, Double-struck, and so on. In mathematical notation, each of these style variants often has a specific meaning associated with it. For example, an italic g might indicate a function name, a bold g might indicate a vector, and a Fraktur g might indicate a Lie algebra. Hence, you should not use the mathvariant style attribute to specify styles unless the meaning implied by that style is specifically intended.

The MathML DTD includes a set of character entities that directly represent styled characters described by different values of the mathvariant attribute. However, these characters are in plane 1 of Unicode and plane 1 characters cannot be displayed in current browsers. Hence, in many cases it is preferable to use the mathvariant attribute in combination with a plane 0 character instead of the corresponding plane 1 character. (The meaning of plane 0 and plane 1 characters was explained in Section 3.4.)

For example, if you want to include a Fraktur g in a mathematical expression, you can do so using the character entity reference to the plane 1 Unicode character for this symbol, as shown here:

     g    <mi>&gfr;</mi>     <mi>&1D524;</mi> 

Alternatively, you can use the mathvariant attribute applied to the ordinary letter g, as shown below:

    g    <mi mathvariant="fraktur">g</mi> 

The fact that the same character can be represented in two different ways can cause problems for applications where the semantic meaning of the markup is important, such as when you are searching or indexing mathematical content. To avoid such problems, the MathML specification requires that processing applications treat plane 0 characters with the mathvariant attribute specified as equivalent to the corresponding plane 1 characters.

Numbers

The mn element is used to represent numbers, or more precisely numeric literals. A numeric literal is any sequence of characters that represents an unsigned integer or real number. Here are some examples:

     <mn>1</mn>    <mn>6.67</mn>    <mn>2002</mn>    <mn>1.6e-19</mn>    <mn>0xAEFF</mn>     <mn>1100101</mn> 

Negative numbers can be represented by including a "-" sign before the numeric literal in the same <mn> element, as shown below:

    <mn>-1</mn> 

However, it is preferable to place the minus sign in a separate mo element so that you provide additional information about the meaning of the markup for use by processing applications, as shown here:

    <mo>-</mo><mn>1</mn> 

An mn element is rendered as the characters in its content with no extra spacing around them. By default, the content is rendered in an unslanted font. However, you can specify a different rendering using the style attributes available for token elements.

Not all numbers should be represented using mn. For example, fractions are represented using the mfrac element, as shown here:

    <mfrac><mn>1</mn><mn>2</mn></mfrac> 

A named symbolic constant, such as π, is represented by an entity reference enclosed in an mi element, as shown below.:

    <mi>&pi;</mi> 

Complex numbers are represented as an mrow element, which contains separate arguments for the real part, the imaginary part, and the operator between them, as shown here (note the use of the entity reference &InvisibleTimes; to denote multiplication between the imaginary part and the symbolic number i):

3.4 + 5i

      <mrow>        <mn>3.4</mn>        <mo>+</mo>        <mrow>          <mn>5</mn>          <mo>&InvisibleTimes;</mo>          <mi>&ImaginaryI;</mi>        </mrow>      </mrow> 

Identifiers

The mi element is used to represent identifiers; that is, names of variables and functions. Examples are:

     <mi>x</mi>    <mi>sin</mi>     <mi>F</mi> 

Symbolic constants such as π, e, and i are also represented using an mi element, as shown here:

     <mi>&pi;</mi>    <mi>&ExponentialE;</mi>     <mi>&ImaginaryI;</mi> 

Not every identifier is represented using an mi element. For example, subscripted or primed variables are represented using an msub or msup element, respectively. Conversely, you can include any text in an mi element, if it is to be rendered as an identifier. A typical example is an ellipsis that represents a term in a series, as shown below:

1 + 2 ++ n

    <mrow>      <mn>1</mn>      <mo>+</mo>      <mn>2</mn>      <mo>+</mo>      <mi>&ctdot;</mi>      <mo>+</mo>      <mi>n</mi>     </mrow> 

The mi element accepts all the common style attributes defined for token elements. However, the mathvariant and fontstyle attributes have a different default value for mi elements. The default value is italic if the content of the mi element is a single character, and normal otherwise. This reflects the convention that variables and functions represented by single letters are typeset in an italic font.

Operators

The mo element is used for representing operators as well as other symbols that should render as operators. This includes fence characters (such as braces, parentheses, or absolute value bars), separators (such as commas or semicolons), and accents (such as a bar or tilde over a character). Here are some examples:

 <mo>+</mo>    <mo>&lt;</mo>    <mo>=</mo>    <mo>&int;</mo>    <mo>and</mo>    <mo>(</mo>    <mo>}</mo> 

Invisible Operators

As discussed in Section 3.2, some operators that are invisible in traditional notation should be specified using explicit named entity references in an mo element. These include &InvisibleTimes;, &InvisibleComma;, and &ApplyFunction;. The advantage of using these entity references is that they provide semantic information about the markup. This information can then be used by rendering applications to achieve better results in visual and audio rendering or by computer algebra systems to evaluate an equation. Some examples of expressions involving invisible operators follow.

The following markup could be spoken as "x times y" instead of just "x y":

xy

    <mrow>      <mi>x</mi>      <mo>&InvisibleTimes;</mo>      <mi>y</mi>     </mrow> 

The following markup could be spoken as "A sub one, two" instead of "A sub twelve":

A12

    <msub>      <mi>A</mi>      <mrow>        <mn>1</mn>        <mo>&InvisibleComma;</mo>        <mn>2</mn>      </mrow>     </msub> 

The following markup could be spoken as "f of x" instead of "f times x":

f(x)

    <mrow>      <mi>f</mi>      <mo>&ApplyFunction;</mo>      <mrow>        <mo>(</mo>        <mi>x</mi>        <mo>)</mo>      </mrow>     </mrow> 

Attributes

The attributes of the mo element determine the precise details of how individual operators and symbols are rendered. The mo element has the unique property that the default values of its attributes are determined based on its content, using an operator dictionary (described in the "Operator Dictionary" section later in this chapter).

Table 4.6 summarizes the various attributes of the mo element and their default values. Each default value is shown with an asterisk to indicate that it is a generic default, which is used only if no match is found for that attribute in the operator dictionary.

Table 4.6: Attributes of the mo Element

Attribute

Values

Default

fence

true | false

false*

separator

true | false

false*

accent

true | false

false*

form

prefix | infix | postfix

Determined by position in mrow

lspace

number h-unit | namedspace thickmathspace*

rspace

number h-unit | namedspace thickmathspace*

stretchy

true | false

false*

symmetric

true | false

true*

maxsize

number [v-unit | h-unit] | namedspace | infinity infinity*

minsize

number | namedspace

1*

largeop

true | false

false*

movablelimits

true | false

false*

The meaning of these attributes is given here:

  • fence, separator, and accent: specify if the content of the mo element should be interpreted as a fence, separator, or accent, respectively. If any of these attributes is set to true, the rendering conventions relevant to that type of object are applied to the operator.

  • form: specifies the position in which an operator occurs.

  • lspace and rspace: determine the amount of space that should be inserted to the left or right of an operator, respectively.

  • stretchy: specifies if an operator should expand or shrink to accommodate the elements it encloses.

  • symmetric: specifies if a stretchy operator should stretch in such a way that its height above and depth below the baseline is always the same.

  • maxsize: specifies the maximum size to which a stretchy operator can grow.

  • minsize: specifies the minimum size to which a stretchy operator can shrink.

The MathML specification defines detailed rules for how stretchy operators should grow in size both vertically and horizontally, based on the context in which the mo element occurs. Here is an example of an operator that stretches vertically:

    <mrow>      <mo>(</mo>      <mfrac>        <mi>x</mi>        <mi>y</mi>       </mfrac>       <mo>)</mo>     </mrow> 

Compare this example to the case where the parentheses are prevented from stretching if you set the attribute maxsize to 1 (this forces the operators to stay at their default size):

    <mrow>      <mo maxsize="1">(</mo>      <mfrac>        <mi>a</mi>        <mi>b</mi>      </mfrac>      <mo maxsize="1">)</mo>     </mrow> 

Here is an example of an operator that stretches horizontally:

    <mrow>      <mi>x</mi>      <mover>        <mo>&RightArrow;</mo>        <mtext>tends to</mtext>      </mover>      <mi>a</mi>     </mrow> 

The following two attributes affect the rendering of an operator based on the value of the displaystyle attribute of the mstyle element:

  • largeop: specifies if an operator should be drawn larger than normal when displaystyle="true" is in its environment.

  • movablelimits: specifies if the limits of an operator should be moved to the subscript and superscript positions when displaystyle="false" is in its environment

Each presentation element inherits a default value of displaystyle from its environment. This attribute specifies if a given expression should be rendered in inline mode or display mode. Inline expressions are typically rendered in a smaller size and with underscripts and overscripts drawn in the subscript and superscript position. Display expressions are typically rendered in a larger size and with any underscripts and overscripts shown in their normal position.

The largeop and movablelimits attributes are used in MathML to control the two key properties that distinguish the inline and display mode of an operator, namely its size and the position of its limits.

Some typical examples of operators for which largeop and movablelimits are both true by default are the integral, summation, and product symbols. Here is an example of an expression for which displaystyle="true":

    <mstyle displaystyle="true">      <munderover>        <mo>&sum;</mo>        <mi>a</mi>        <mi>b</mi>     </munderover>     <mrow>       <mi>f</mi>       <mi>&ApplyFunction;</mi>       <mrow>         <mi>(</mi>         <mo>x</mo>         <mo>)</mo>       </mrow>     </mrow>    </mstyle> 

Here is how the same expression might look if rendered with displaystyle="false":

Notice that the summation symbol is shown in a smaller size and the underscripts and overscript have moved to the subscript and overscript position. These changes are a consequence of the fact that the largeop and movablelimits are both true by default for the mo element that contains the &sum; operator.

Operator Dictionary

Most mathematical operators and symbols have special rendering properties that must be handled on a case-by-case basis. For example, prefix operators are typically rendered with extra space on the left, postfix operators have extra space on the right, and infix operators have extra space on both sides. The mechanism used in presentation markup to respect such rendering conventions is to determine the default attribute values for each operator from an operator dictionary.

The operator dictionary is a table that lists attribute values for a large collection of common operators and symbols. When displaying an <mo> element containing a particular operator, the renderer first checks to see if that operator is listed in the operator dictionary. If so, the default attribute values for that <mo> element are taken from the entry for that operator in the dictionary. If the operator is not listed in the dictionary (or if it is listed but all of its attributes are not assigned explicit values), then the values of all unmatched attributes are determined from their generic defaults.

For example, the entry in the operator dictionary for the "=" operator is shown below:

    "="  form="infix"  lspace = "thickmathspace" rspace =    "thickmathspace" 

This entry specifies default values for the form, lspace, and rspace attributes in an mo element that contains the "=" operator as its content. All other attributes of this <mo> element take their generic default values, since these attributes are not specified explicitly in the operator dictionary entry. In other words, the following markup:

    <mo>=</mo> 

is automatically interpreted as the following:

    <mo form="infix" lspace = "thickmathspace" rspace =    "thickmathspace">=</mo> 

This operator dictionary entry applies the typesetting convention that the "=" operator is typically used in the infix position and that it should be rendered with extra space on either side.

Here is the operator dictionary entry for the "(" operator:

    "("  form="prefix"  fence = "true" stretchy = "true"         lspace = "0em" rspace = "0em" 

This entry reflects the fact that the "(" character is typically used in an expression as a fence, it is normally stretched to accommodate its contents, and it does not have extra space around it.

The operator dictionary thus provides a way to automatically apply the typesetting conventions associated with each type of operator that might occur inside an <mo> element. Of course, you can always override the default behavior and change the rendering properties of any operator by explicitly specifying one or more attributes.

Text

The mtext element is used to represent ordinary text that appears inside a mathematical expression. This element is useful for mixing text and mathematical notation, as in the following example:

Theorem 1: If x > 0 and y > 0, then xy > 0

    <mrow>      <mtext>Theorem 1:If</mtext>      <mi>x</mi><mo>&gt;</mo><mn>0</mn>      <mtext>and</mtext>      <mi>y</mi><mo>&gt;</mo><mn>0</mn>      <mtext>then</mtext><mi>,</mi>      <mi>x</mi><mo>&InvisibleTimes;</mo><mi>y</mi>      <mo>&gt;</mo><mn>0</mn>     </mrow> 

Another common use of mtext elements is for including literal whitespace, since MathML automatically removes whitespace that is included directly. You can include whitespace of varying widths using the named character entities such as &VeryThinSpace;, &ThinSpace;, &MediumSpace;, or &ThickSpace;, as shown here:

    <mtext>&ThinSpace;</mtext>    <mtext>&ThickSpace;&ThickSpace;</mtext>Alternatively, you can insert whitespace of arbitrary width, height, and depth, using the mspace element, as discussed below. 

Blank Space

The empty element mspace is used to explicitly insert a blank space of any desired size. The size and position of the space inserted depends on the value of the following three attributes:

  • width: specifies the width of the bounding box that contains the mspace element

  • height: specifies the distance from the baseline of the text to the top edge of the bounding box

  • depth: specifies the distance from the baseline of the text to the bottom edge of the bounding box

The default values of all these attributes are chosen to make the mspace element have no effect on visual rendering. Hence, if you want to include a visible blank space, you must explicitly specify one or more attributes, as shown here:

    <mspace width="5 em" height="2 ex" depth="2 ex"/> 

The mspace element also takes an attribute called linebreak, which can be used to provide suggestions for linebreaking to a visual renderer. Possible values of this attribute and their meaning are given in Table 4.8.

Table 4.8: Possible Values of the linebreak Attribute

Value

Meaning

auto

There is no effect on linebreaking; the renderer uses its default linebreaking behavior.

newline

This is a new line and do not indent.

indentingnewline

This is a new line and do indent.

nobreak

A linebreak is not allowed here.

goodbreak

A linebreak is needed on the line; here is a good spot.

badbreak

A linebreak is needed on the line; try to avoid breaking here.

Strings

Most programming languages include strings as a fundamental data type for representing sequences of characters. In order to communicate with other programming applications such as computer algebra systems, MathML provides the ms element for representing strings.

The content of an ms element is typically rendered with a quotation mark character at the beginning and end. By default, the left and right quotation mark characters are the standard double quotation mark character, &quot;, but using the attributes lquote and rquote you can substitute either of these with a different character, as shown here:

    "This is a string"    <ms>This is a string</ms>    'This is a string'    <ms lquote="&apos;" rquote="&apos;">This is a            string</ms> 

As with any other token element, whitespace that occurs within the content of an ms element is automatically trimmed from the ends and collapsed. Hence, any whitespace that you must include when representing a string should be explicitly encoded using one of the named space characters such as &nbsp; or &ThinSpace;.

Character Glyphs

A MathML expression can contain any character included in the Unicode character set. In particular, technical symbols and other extended characters can be included either using a named entity reference defined in the MathML DTD or, more generally, using the numeric character entity reference defined in Unicode.

However, in special cases, you might need to use a character that is not available in Unicode. Alternatively, you might wish to use a Unicode character but represent it using a variant of the standard glyph associated with the character. MathML provides the mglyph element specifically for use in such situations. It allows you insert a particular glyph from a particular font family at any place in your document.

The mglyph element accepts the following three attributes:

  • fontfamily: specifies the font family that contains the glyph.

  • index: is a number that specifies the position of the glyph in a particular font family.

  • alt: provides an alternate name for the glyph. This name can be used by an audio renderer or by a visual renderer if it cannot find the specified font family for rendering the glyph. If using this, you should choose a descriptive name for it.

These are all required attributes; that is, they do not have a default value and must be explicitly specified in every mglyph element.

Here is an example that shows the use of the mglyph element:

R = A + B

    <mrow>      <mi><mglyph fontfamily="Mathematica 6" index="82"        alt="GothicCapitalR"/></mi>      <mo>=</mo>      <mi><mglyph fontfamily="Mathematica 6" index="65"        alt="GothicCapitalA"/></mi>      <mo>+</mo>      <mi><mglyph fontfamily="Mathematica 6" index="66"        alt="GothicCapitalB"/></mi>     </mrow> 

This explicitly specifies that the characters in positions R, A, and B from the Mathematica 6 font family should be used to display certain capital letters in a Gothic script.



 < 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