## 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, 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 for entering mathematical constructs.

### Creating a mathematical 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 an expression, and then click the Math button , or select the Math entry from the Types menu. The Math button displays a palette that stays on the screen until you click its Done button. The item Math from the Types menu displays a popup menu. Just choose the most convenient tool for you. 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 or SVG element (but the caret should not be within a MathML element).

In the Math menu, the next items allow you to create new basic elements (not available in the palette): Plain text (`mtext`), Identifier (`mi`), Number (`mn`), Operator (`mo`). You can also use these commands to change the type of a single element or a sequence of elements.

These items in the Math menu are followed by the Character (`&xxx;`) item. This command allows you to enter a character that is not available on the keyboard. It displays a dialogue box where you have to enter the character name (for instance alpha for the Greek character α).

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:

- Root with index, `mroot` in MathML: x + 1 3
- Square root, `msqrt`: x + 1
- Enclose, `menclose`: 1234
- 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 required 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. The right and left arrows move the caret according to the structure of the mathematical expression. For instance, in a fraction, when the caret is at the end of a numerator, key → moves it to the beginning of the denominator.

### 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 this sequence of 6 characters: `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 Structure view):

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

If the result is not exactly what you want, just select the characters that have been misinterpreted and change their type with one of the commands Plain text (mtext), Identifier (mi), Number (mn), Operator (mo) from the Types/Math menu.

Note: when entering brackets, like in the following expression:

f ( x ) = 1 x

simply typing the sequence `f(x)=` would lead to:

f ( x ) = 1 x

Use the Prentheses command from menu Types/Math or from the palette instead.

### Structure editing

Amaya provides the same method to create and edit matrices as to edit HTML tables. Similar to 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 putting 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.

### Structure view

Whenever a document contains some MathML elements, choosing the Show Structure item from the Views menu actually opens the Structure view which shows the main structure of the HTML document. In this view, the `math` tag and their actual contents is shown.

You can edit math expressions either in the main view or in the Structure view. The 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 Structure view avoids any ambiguity. You can also check the status line, at the bottom of the main window.

### Links in MathML

You can create and use links in mathematical expressions. These links are represented using a draft version of 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.

To create such a link, just select an expression (the fraction in the above example), click on the Link button (or select "Create or change link" 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 2.0, not the Content Markup. All presentation elements and attributes are available, but only the following attributes are rendered on the screen: `alttext`, `mathvariant`, `mathsize`, `mathcolor`, `mathbackground`, `fontsize`, `fontweight`, `fontstyle`, `fontfamily`, `color`, `linethickness`, `numalign`, `denomalign`, `bevelled`, `notation`, `lquote`, `rquote`, `lspace`, `rspace`, `subscriptshift`, `superscriptshift`, `form`, `width` (`mspace` only), `height` (`mspace` only), `depth` (`mspace` only), `align`, `rowalign`, `columnalign`, `frame`, `rowspan`, `columnspan`.

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 in the current version, 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, DifferentialD, ImaginaryI, ExponentialE, InvisibleComma, UnderBar, OverBar, ThinSpace, ThickSpace, Hat, OverBar, UnderBar, prime, Prime.