Controlling alignment

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

MathML provides a sophisticated mechanism for controlling the alignment of expressions that appear in a table. You can align the content of any cell with that of other cells in the same column. Each cell can contain any number of subexpressions that can be aligned independently, along the right, left, or center, or along a decimal point.

To specify the alignment, you must take the following steps:

  1. Create alignment groups within each expression that you want to align. An alignment group is defined as any content between the start of one maligngroup element and the next maligngroup element or the end of the cell, whichever comes first.
  2. Specify a point of alignment for each alignment group. You can do this either by inserting a malignmark element or using the groupalign attribute. This attribute can be specified for an entire table or for a specific row or cell.

Let’s look at a simple example. Suppose you want to display a pair of simultaneous equations so that the following items in one equation are each aligned with the corresponding items in the other equation:

  • The variables "x" and "y"
  • The operators "+" or "-"
  • The "=" sign
  • The number on the right-hand side

Here is the markup for this example:

Controlling alignment: equation 1

<mtable>
  <mtr>
    <mtd>
      <mrow>
        <mn>2</mn>
        <mo>&InvisibleTimes;</mo>
        <maligngroup/><mi><malignmark/>x</mi>
        <maligngroup/><mo><malignmark/>+</mo>
        <maligngroup/><mi><malignmark/>y</mi>
        <maligngroup/><mo><malignmark/>=</mo>
        <mo>-</mo>
        <maligngroup/><mn><malignmark/>5</mn>
      </mrow>
    </mtd>
  </mtr>
  <mtr>
    <mtd>
      <mrow>
        <maligngroup/><mi><malignmark/>x</mi>
        <maligngroup/><mo><malignmark/>-</mo>
        <mn>2</mn>
        <mo>&InvisibleTimes;</mo>
        <maligngroup/><mi><malignmark/>y</mi>
        <maligngroup/><mo><malignmark/>=</mo>
        <maligngroup/><mn><malignmark/>1</mn>
      </mrow>
    </mtd>
  </mtr>
</mtable>

Notice that each equation is placed in a separate cell of a table that consists of two rows and one column. In each equation, five different parts must be aligned independently. Hence, each equation contains five alignment groups, each defined using a single maligngroup element.

For each alignment group, you specify the alignment point by inserting a malignmark element in the content of the token element that contains the character to be aligned. Recall that malignmark is one of only two elements that can occur as the content of a token element (the other is mglyph).

The malignmark element takes a single attribute called edge, which defines the position of the alignment point. With the default setting edge="left", the alignment point is the left edge of the character immediately to the right of the malignmark element. With the setting edge="right", the alignment point is the right edge of the character immediately to the left of the malignmark element.

For complex expressions with a large number of alignment points, it is verbose to specify each alignment point using an explicit malignmark element. As an alternative, you can use the groupalign attribute to specify the alignment point for each alignment group.

The following markup represents the same set of equations as above but with the alignment specified using the groupalign attribute on the top-level mtable element:

<mtable>
  <mtr groupalign="{left}">
    <mtd>
      <mrow>
        <mn>2</mn>
        <mo>&InvisibleTimes;</mo>
        <maligngroup/><mi>x</mi>
        <maligngroup/><mo>+</mo>
        <maligngroup/><mi>y</mi>
        <maligngroup/><mo>=</mo>
        <mo>-</mo>
        <maligngroup/><mn>5</mn>
      </mrow>
    </mtd>
  </mtr>
  <mtr>
    <mtd>
      <mrow>
        <maligngroup/><mi>x</mi>
        <maligngroup/><mo>-</mo>
        <mn>2</mn>
        <mo>&InvisibleTimes;</mo>
        <maligngroup/><mi>y</mi>
        <maligngroup/><mo>=</mo>
        <maligngroup/><mn>1</mn>
      </mrow>
    </mtd>
  </mtr>
</mtable>

You can specify the groupalign attribute on an mtable element (for the entire table), on an mtr or mlabeledtr element (for a single row), or on an mtd element (for a single cell). If this attribute is not specified explicitly, it is inherited from the environment. Note that an alignment point specified by a malignmark element overrides the automatic specification defined by the groupalign attribute.

The alignment position for each alignment group can be specified as one of four values: left, right, center, and decimalpoint. Since each cell can contain multiple alignment groups, the groupalign attribute on an mtd element is set to a list of alignment values, each value applying to a specific alignment group. If there are more alignment groups than alignment values in the list, the last element in the list is applied to all the remaining groups. Here is an example:

<mtd groupalign="right decimalpoint left">

When you specify groupalign on an mtr, mlabeledtr, or mtable element, the attribute is set to a list of list of alignment values. Each list is enclosed in curly braces to separate it from other lists. Here is an example:

<mtr groupalign="{right decimalpoint left} {right left}">

The mtable element also takes an attribute called alignmentscope. If you set this to false, all maligngroup and malignmark elements in the table are ignored. This attribute is useful when you are representing nested tables. For example, you can use it to prevent alignment information intended for the outer table from being applied to the inner table.

In general, alignmentscope is specified as a list of Boolean values, each applying to one column of the table. For example, with the following markup, alignment elements would be recognized in the first two columns of the table but ignored in the last column:

<mtable alignmentscope="true true false">

   

<< back next >>

 

 

 

Tipp der data2type-Redaktion:
Zum Thema MathML bieten wir auch folgende Schulungen zur Vertiefung und professionellen Fortbildung an:

 

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