Applying styles

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

The mstyle element is used to apply style changes throughout a given piece of presentation markup. If an attribute is specified explicitly on an mstyle element, the value of that attribute is inherited by all elements contained within that mstyle element, either directly or indirectly. The net effect is to reset the default value of that attribute everywhere in the environment defined by that mstyle element. The mstyle element therefore provides a general mechanism for applying style changes selectively to specific parts of an expression.

Imagine, then, that you want an attribute to have a particular value everywhere in a given piece of markup. Instead of specifying that attribute explicitly on each element, you can just specify the attribute once on an mstyle element that encloses the markup where you want the changes to apply. Of course, you can still override the default setting applied by the mstyle element by explicitly specifying an attribute on any element in the environment.

For example, if you want a certain subexpression within a larger expression to be rendered in a 24-point font size, you can use the following markup:

x + 1

  <mi mathsize="24 pt">x</mi>
  <mo mathsize="24 pt">+</mo>
  <mn mathsize="24 pt">1</mn>

A simpler way to achieve the same result is shown here (this markup is equivalent to the markup in the above example):

<mstyle mathsize="24 pt">

Each mstyle element can accept any attribute for any presentation element that does not have a required value. This means that any attribute with either a default value or a value that is inherited or computed can be specified using the mstyle element. In addition, several style attributes are specifically defined for use with the mstyle element. Each of these attributes has a default value that is inherited by every presentation element, even if the elementis not explicitly enclosed in an mstyle element.

Script size attributes

Many common notational structures require characters to be displayed in a reduced size relative to the surrounding text. For example, the numerator and denominator of a fraction that appears in a line of text are typically shown in a reduced size. Similarly, subscripts and superscripts are typically shown in a smaller size than the base to which they are attached. The reduction in size of characters that occur in such special positions is controlled by two attributes of the mstyle element: scriptlevel and scriptsizemultiplier.

The scriptlevel attribute takes integer values. It has a value of 0 for normal text, 1 for subscripts, 2 for subscripts of subscripts, and so on. Each increase in the value of scriptlevel leads to a corresponding decrease in the font size, according to the following algorithm. The current font size is multiplied by the value of scriptsizemultiplier raised to the power of the change in the value of scriptlevel. The default value of scriptsizemultiplier is 0.71. This value, as well as the algorithm for calculating the reduction in font size, is based on typesetting conventions chosen because they produce acceptable-looking results in practice. There is also an additional attribute called scriptminsize, which specifies a minimum value below which the font size cannot be reduced, regardless of the value of scriptsizemultiplier.

Another important attribute of the mstyle element is displaystyle. This attribute specifies whether an expression should be rendered in display mode or inline mode. It achieves this by affecting the rendering of the mo element, based on the values of its largeop and movablelimits, as explained in the discussion of the mo element under Presentation markup: Introduction.

A setting of displaystyle="false" is used for inline mathematical expressions, which typically appear embedded in a paragraph of text. Such expressions are typically rendered in a smaller size and with underscripts and overscripts moved to the subscript and superscript position, respectively. This causes the mathematical expression to be vertically compressed so that it does not disrupt the spacing between lines.

A setting of displaystyle="true" is used for mathematical expressions that are to be rendered in display mode; that is, in a line by themselves. Such expressions are typically rendered in a larger size and with any underscripts and overscripts in their normal positions.

Certain presentation elements, such as mfrac, mroot, msub, msup, and so on, automatically change the values of scriptlevel and displaysize in one or more of their arguments. Details of this behavior are provided in the discussion of these individual elements in this chapter.

Color and background attributes

The mstyle attribute also accepts the color and background attributes, which determine the color of the font and background, respectively. These attributes can be set directly on token elements only. Hence, the mstyle element provides a way to specify the color and background of elements other than token elements.

The color and background attributes can both be specified in either RGB notation or as an HTML color name, as shown in the examples below.

This markup displays some text in a red color with a yellow background:

<mstyle mathcolor="red" mathbackground="yellow">
  <mtext>Here is some colored text.</mtext>

This displays an expression in red color with a white background:

<mstyle mathcolor="#FF0000" mathbackground="#FFFFFF">

Spacing attributes

The following seven attributes of the mstyle element set the size of the various named spaces defined in MathML:

  • veryverythinmathspace
  • verythinmathspace
  • thinmathspace
  • mediummathspace
  • thickmathspace
  • verythickmathspace
  • veryverythickmathspace

Each of these attributes defines a fixed horizontal space, with the default value ranging between 1/18 em and 7/18 em. Since the spacing between operators in the operator dictionary is defined in terms of these values, setting these values to a larger or smaller value can make the spacing between all operators looser or tighter.


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