December 26th, 2020

MathML and OMML User Selection Attributes

Murray Sargent
Principal Software Engineer

Some assistive technology (AT) programs use MathML or OMML as conduits for generating math speech and braille from math-enabled apps. In addition, they would like to use these formats for editing math text as well as speaking it and displaying it on refreshable braille displays. To this end, the formats need selection attributes that identify where the user selection is or should be within the MathML or OMML. These selection attributes are intended for accessibility purposes; MathML/OMML in copy, paste, and files ordinarily wouldn’t contain such attributes.

User Selection

A user selection can be degenerate, that is, an insertion point, or nondegenerate in which case it selects one or more ranges of characters. Multiple disjoint selections (multiple ranges) can be made by using the Ctrl key and clicking appropriately. For math editing, multiple selections aren’t generally very useful, and this post doesn’t treat them. A nondegenerate selection has an active end, the end that moves when you enter Shift + an arrow key, and an anchor end. The two ends coincide for an insertion point.

Selection attributes

To specify the locations of the selection ends in any MathML/OMML content, we define the attribute names selActiveEnd, selAnchorEnd, and selIP (insertion point). The values for these attributes are given in the table

“before” Before math zone
“after” After math zone
n At offset n into an element

The most common attribute is selIP with the value “0”, i.e., an insertion point at the start of the element, such as the MathML <mi selIP=”0″>a</mi> or the OMML <m:t selIP=”0”>𝑎</m:t>.

With elements containing more than one character like the MathML <mi>sin</mi>, the insertion point might be in between the ‘s’ and the ‘i’, in which case one has <mi selIP=”1″>sin</mi> and the OMML <m:t selIP=“1”>sin</m:t>. If the user then enters Shift+→ to select the ‘i’, the MathML is <mi selAnchorEnd=”1″ selActiveEnd=”2″>sin></mi> and the OMML is <m:t selAnchorEnd=”1″ selActiveEnd=”2″>sin</m:t>.

Another case is for an IP at the end of an object argument. For example, in the MathML fraction <mfrac><mn>1</mn><mn>2</mn></mfrac>, if the IP follows the ‘2’ in the denominator, the selIP attribute appears in MathML as <mn selIP=”1″>2</mn>. This IP is at the end of the denominator, not at the end of the fraction, and entering a character puts the character in the denominator following the ‘2’. The corresponding OMML is <m:t selIP=”1″>2</m:t>.

The offset n is given in code units of the Unicode encoding in use. Microsoft Office apps use UTF-16 for which most math alphanumerics are surrogate pairs, that is, 2 code units. If a fraction denominator is 𝑥, an IP following the 𝑥 is specified for a UTF-16 implementation by the MathML as <mi selIP=”2″>x</mi> even though MathML uses the single-unit ASCII letter x to represent the surrogate-pair math-alphabetic 𝑥 (U+1D465). This choice is synchronized with the selection in memory. In OMML, math alphanumerics aren’t translated to ASCII, so this size difference doesn’t occur.

Nested objects

An IP or selection end can follow the last element of a parent element such as being after the parenthesized expression in (𝑎 + 𝑏)² but still in the base of the superscript object. For an IP, this is given in MathML by an empty <mrow selIP=”0″/>:

<msup>
   <mrow>
      <mrow><mo>(</mo><mi>a</mi><mo>+</mo><mi>b</mi><mo>)</mo></mrow>
      <mrow selIP="0"/></mrow>
   <mn>2</mn></msup>

In OMML, it’s given by an empty run <m:r selIP=”0″/>. The empty <mrow> or empty <m:r> is also used for an IP at the end of the math zone, but still in the math zone.

Selection end at start of math object

If an IP is at the start of a math object, such as a fraction, but before the first argument, the selection attribute goes in the math-object element. For example, for the fraction “1 over 2”, an IP at the start of the fraction is indicated by <mfrac selIP=”0″> in MathML and by <m:f selIP=”0″> in OMML.

Selection extending outside of math zone

A selection may start before a math zone and select part or all of the math zone. Similarly, it can start inside the math zone and extend beyond it. The attribute values “before” and “after” are used for such cases, respectively. For example, the math in the statement (selection is highlighted) “the Pythagorean Theorem is 𝑎² + 𝑏² = 𝑐²” is represented by the MathML

<math selAnchorEnd="before">
   <msup><mi>a</mi><mn>2</mn></msup>
   <mo selActiveEnd="0">+</mo>
   <msup><mi>b</mi><mn>2</mn></msup>
   <mo>=</mo>
   <msup><mi>c</mi><mn>2</mn></msup>
</math>

where the active end follows the 𝑎². If the whole math zone is embedded in a selection with the active end at the selection end, <math selAnchorEnd=”before” selActiveEnd=”after”> is used. A selected empty math-zone place holder can be represented in MathML by <math selIP=”0″/>.

Elements that take selection attributes

Although it would be possible to allow selection attributes on most any element, it’s simpler to process and nevertheless general enough to restrict the elements that take selection attributes to

  • Character elements: MathML <mi>, <mn>, <mo>, <mtext> and OMML <m:t>
  • MathML <mrow> and OMML <m:r>
  • Math object elements like MathML <mfrac> and OMML <m:f>
  • Math zone element: MathML <math> and OMML <oMath>

Author

Murray Sargent
Principal Software Engineer

Yale BS, MS, PhD in theoretical physics. Worked 22 years in laser theory & applications first at Bell Labs and then Professor of Optical Sciences, University of Arizona. Worked on technical word processing, writing the first math display program (1969) and the technical word processor PS (1980s). Developed the SST debugger we used to get Windows 2.0 running in protected mode thereby eliminating the 640KB DOS barrier (1988). Have more than 100 refereed publications, 3 laser-physics books, 4 ...

More about author

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Mayank Talapda

    selection extending outside of math zone it’s amazing explain
    Thanks and regard,
    Dosti ke upar shayari