(Excerpt from "The MathML Handbook" by Pavi Sandhu)
Each MathML element has a number of attributes. The attribute for an element is specified after the element name in the start tag of the element, using the syntax: attribute-name="value". The value of the attribute must be enclosed in either single quotation marks or double quotation marks. The following six attributes are accepted by all MathML elements:
- class, style, and id: to facilitate use of CSS and XSL stylesheets
- xlink:href: used for setting up links
- xref: for use in parallel markup
- other: used for specifying nonstandard attributes that are not defined in MathML but may be supported by specific processing applications
In addition, each content or presentation element may have other attributes based on its specific role. For example, the mfrac element has an attribute called linethickness, as shown here:
The linethickness attribute determines the thickness of the line that separates the numerator and denominator of the fraction. The default value of this attribute is 1, which corresponds to a line of normal thickness. In the above example, linethickness is set to 0, which corresponds to the line being invisible.
MathML attributes can be set in two ways:
- They can be explicitly set in the start tag of an element, as in the above example.
- They can take the default value if not specified explicitly. The default value can be specified in the DTD, or it can be automatic (specified by the MathML rendering software) or inherited (from the surrounding environment).
An example of an inherited value that overrides a default value is shown here:
x + y
<math> <mrow> <mstyle mathsize="18 pt"> <mi>x</mi> <mo>+</mo> </mstyle> <mi>y</mi> </mrow> </math>
The example uses the presentation element mstyle, which you use to set style attributes for presentation markup. The value of all this element’s attributes is automatically inherited by all its child elements. Here, the mi element containing the x and the mo element containing the + both inherit the value of the mathsize attribute, even though this attribute is not specified explicitly on either of the two elements.
MathML restricts the types of values certain attributes can take. These restrictions may be specified in the MathML DTD or may be additional rules that are enforced by MathML processors even if they are not explicitly described in the DTD. The allowed values for each type of attribute are described in the discussion of individual elements under Presentation markup and Content markup. The following syntax is used to specify the possible values an attribute can take:
attribute-name value1 |value2... | valueN
The allowed values are separated by a vertical bar indicating that any one of them can be used as a value for attribute-name. For example, the form attribute of the <mo> element can take three possible values:
Certain attribute values may be indicated with a + (which means the value can occur 1 or more times) or with a * (which means the value can occur 0 or more times). Here is an example:
This means that the columnalign attribute of the mtable element can take a set of values, each controlling the alignment of a specific column of the table. If fewer values than the number of columns are specified, the last value is repeated as many times as necessary. If there are more values than the number of columns, the extra values are ignored.
The notation used to indicate allowed values of attributes in the MathML specification is summarized in the following table. For compactness, the same notation is used later in the book when we describe the attributes in the discussion of individual elements.
Table: Notation used to indicate allowed values of MathML attributes.
|x|y||Either x or y is allowed.|
|x*||x can occur zero or more times.|
|x+||x can occur one or more times.|
|(x|y)+||Either x or y can occur one or more times.|
|[x]||x is optional.|
|h-unit||Unit of horizontal distance.|
|v-unit||Unit of vertical distance.|
|%||Percentage of the default value.|
|#rgb||Color in Red Green Blue (RGB) units with one digit for each color component.|
|#rrggbb||Color in RGB units with two digits for each color component.|
Some attributes are specified with a unit in addition to a numerical value. In this case, the attribute value typically consists of a number followed by a unit. For example, the allowed values of the mathsize attribute are specified as:
mathsize small|normal|big|number v-unit
Here, v-unit denotes a unit of vertical length. The example below shows the use of an attribute value that includes a unit (it causes the identifier x to be displayed in a 24-point font size):
<mi mathsize="24 pt">x</mi>
Possible units in attribute values are listed in the following table.
Table: Possible units in attribute values.
|em||Width of the letter "m" in the font being used.|
|ex||Height of the letter "x" in the font being used.|
If an attribute value is specified as a percentage, it is usually a percentage of the default value of that attribute. For example:
is equivalent to
<mfrac linethickness="200 %"><mi>x</mi><mi>y</mi></mfrac>
|<< back||next >>|
Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.
CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America