## Editing mathematics

Amaya allows you to include mathematical expressions in web pages, following the Mathematical Markup Language (MathML) specification. Mathematical expressions are handled as structured components, exactly in the same way as HTML elements. Therefore, you can manipulate math expressions in the same way you manipulate other parts of HTML documents. All editing commands provided by Amaya for handling text are also available for math, and there are some additional controls to enter mathematical constructs.

### Creating a math expression

#### The Math palette and the Types/Math menu

To create a mathematical expression in a document, just move the insertion point (the caret) to the position where you want to insert that expression, and click the Math button (the rightmost button), or select the last entry (Math) from the Types menu. The Math button displays a palette that stays on the screen until you click the Done button. Item Math from the Types menu displays a popup menu. Just choose the most convenient tool. Both allow you to select the mathematical construct to be inserted.

In the Math palette (or menu) the first item allows you to create a new formula when the caret is in some HTML element (but the caret should not be within a MathML element):

The next items of the Math menu (or palette) allow you to create new constructs within a formula. If the caret is not in a formula, a `Math` element is created first to accept the new construct. The available constructs are, from top to bottom:

- Root with index, `mroot` in MathML: x + 1 3
- Square root, `msqrt`: x + 1
- Fraction, `mfrac`: 1 x + 1
- Expression with subscript and superscript, `msubsup`: x i + 1 n or ∫ 0 ∞
- Expression with a subscript, `msub`: x i
- Expression with a superscript, `msup`: x n
- Expression with under- and overscript, `munderover`: ∑ i = 1 n
- Expression with underscript, `munder`: x -
- Expression with overscript, `mover`: x → maps to y
- Expression within parentheses, `mrow`: ( a + b )
- Expression with prescripts and tensor indices, `mmultiscripts`: X i j k l
- Matrix or table, `mtable`: a b c d

The last item of the Math palette ( αβγ ) displays another palette from which you can insert mathematical symbols and greek characters.

#### Entering constructs from the keyboard

You are not obliged to use a menu or a palette to create and edit mathematical expressions. You can enter mathematical constructs directly from the keyboard, as each item in the Math menu has a keyboard equivalent (all shortcuts are listed in the menu). This allows you to type faster. To type even faster, you may also use the keyboard to move the caret from a construct to another, with the arrow keys.

### Entering characters

When you type a character string in a MathML element, Amaya parses that string and generates elements `mo` (operator), `mn` (number), `mi` (identifier), and `mtext` automatically. For instance, to enter

x = 2 a + b

just type `x=2a+b`, (don't forget to first click on the Math item of the Math menu, if you are not in a mathematical expression) and you will get the following structure (you can check in the Math_Structure view):

    <mi>x</mi><mo>=</mo><mn>2</mn><mi>a</mi><mo>+</mo><mi>b</mi>

### Structure editing

Amaya provides the same method to create and edit matrices as to edit HTML tables. Like for tables there is a specific command (Delete matrix column) to delete a column in a matrix, even if it's not empty. This command is located at the end of submenu Math of menu Types.

You may want to change the structure of an existing expression, e.g. appending a superscript or puting parentheses around an expression. To do that, just select the expression and enter the new construct with the palette, the Math menu or the keyboard.

You can also use the Transform command from the Edit menu. Select the expression you want to transform and the Transform command will display a menu with all possible changes.

### Math_Structure view

Whenever a document contains some MathML elements, choosing the Show Structure item from the Views menu actually opens two views:

- the Structure view shows the main structure of the HTML document. In this view, MathML elements are only represented by a `MATH` tag and their actual contents is not shown.
- the Math_Structure view shows only MathML elements, but here, all their components are visible.

You can edit math expressions either in the main view or in the Math_Structure view. The Math_Structure view is especially helpful to avoid ambiguity. Consider the following example:

x = a + b + 1

When moving the caret after character b, it is not clear whether you want to add something within the square root or after it. Selecting (or checking) in the Math_Structure view avoids any ambiguity.

### Links in MathML

You can create and use links in mathematical expressions. These links are represented in the XML Linking Language (XLink). Only the simple unidirectional hyperlinks are available, but you can associate a link with any part of a formula. For example, the fraction in the formula below is a link to the W3C home page:

y = 1 x 2 + 1

Double-clicking any character within the fraction fetches the W3C home page. In the XML file, the fraction is represented by:

    <mfrac xml:link="simple" href="http://www.w3.org/">...</mfrac>

To create such a link, just select an expression (the fraction in the above example), click on the Link button (or select "createLink" from the Links menu) and click on the desired target. If the target is an expression in a formula, you first have to turn that expression into a target. Just select the expression and select "create Target" from the Links menu. This creates an `id` attribute for the target expression.

### Current limitations

Amaya implements only the Presentation Tags from MathML, not the Content Markup. All presentation elements and attributes are available, but only some attributes have an impact on the formatted view (`fontsize`, `fontweight`, `fontstyle`, `fontfamily`, `color`). The `class`, `id` and `style` attributes are available, with the same semantics as in HTML: you can associate CSS style with MathML elements (`class` and `style` attributes) and a MathML element can be the target of a link (`id` attribute).

Due to the lack of mathematical fonts, only a limited set of entities representing math symbols are recognized, mainly those available in the Symbol font. The current version supports: Therefore, SuchThat, DownTee, Or, And, Not, Exists, ForAll, Element, NotElement, NotSubset, Subset, SubsetEqual, Superset, SupersetEqual, DoubleLeftArrow, DoubleLeftRightArrow, DoubleRightArrow, LeftArrow, LeftRightArrow, RightArrow, Congruent, GreaterEqual, le, NotEqual, Proportional, VerticalBar, Union, Intersection, PlusMinus, CirclePlus, Sum, Integral, CircleTimes, Product, CenterDot, Diamond, PartialD, DoubleDownArrow, DoubleUpArrow, DownArrow, UpArrow, ApplyFunction, TripleDot.