Editing Mathematics

The possibility to include mathematical expressions is really important for scientists. Some computer formats, such as LaTeX, already allows it for documents whose purpose is being visually rendered, especially printed. Nevertheless, including mathematical formulae in web pages is much more difficult. People generally use images generated from LaTeX sources: they get a longer loading time, a layout not adapted with the rounded text, a bad print quality... Moreover, Internet is supposed to be a universal way to share informations and a more powerful mathematical language than LaTeX is required in order to make the formulae understandable by speech synthesizers (for visually impaired), mathematical softwares, search engines...

For all these reasons, the W3C created the MathML (Mathematical Markup Language) and indicates that, because of its complexity, it should not be edited by hand. Consequently, Amaya proposes a Wysiwyg interface where 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. In addition, there are some other controls for entering mathematical constructs. Note that the different browsers don't behave in the same way with MathML: see the browsers compatibility section for more informations.

Creating mathematical formulae

New Formula

Generally, mathematical formulae are not alone but included in a document with text, table, images... to do this, you have to create a XHTML document. Otherwise, you can create a MathML document (mml) for instance to use the formulae in other softwares.

To create a new mathematical expression in a document, move the insertion point to the position where you want to insert an expression, and then click the Math button (the first) from the Math palette, or choose New formula from the XML menu. Here are examples with a formula inserted directly in the XHTML document or inside a SVG image :

Γ ( x ) = 0 + t x 1 t t

Γ ( x ) = 0 + t x 1 t t

The XML Menu

The XML/Basic math Elements menu contains elements which are not available from the palette. The first items create new elements of a given type in a mathematical expression : Plain text (mtext), Identifier (mi), Number (mn), Operator (moĹ). These commands can also change the type of a single element or a sequence of elements.

The next command, Space (mspace), allows you to add space in a formula. To change its size, you have to modify its attribute. See .

The next item, Character (&xxx;), enables you to enter a character that is not available on the keyboard. It displays a dialog where you have to enter the character name (for instance alpha for the Greek character α).

The two last commands InvisibleTimes and ApplyFunction are used to enter the corresponding invisible characters. See the Special Characters section.

The XML/Math Constructions menu enables you to create new constructs within a formula. If the insertion point is not in a formula, Amaya first creates a math element to accept the new construct. The available constructs are:

Finally, the XML/Matrices menu allows you to create and edit MathML tables: a b c d

You must then choose the number of lines and columns in the new table through a dialog that pops up. You can manipulate it like a HTML table through the commands available from the XML/Matrices menu.

The Math Palette

Clicking on a button in the Math palette inserts the mathematical construction represented on its icon. Parts in black are really inserted, parts in red represent placeholder, parts in blue are asked thanks to a dialog. Green parts are simply additional informations that are not inserted.

The palette contains all constructions described in Content MathML (but the produced code is an equivalent in Presentation MathML, see the known issues section) and even more. You can also save your own contructions in a mml file in order to use them latter. The 6 tabs are :

    • Various constructs
      • new formula
      • mrow: used to group elements. See the section about the row construction
      • mphantom: hide a piece of formula, can be used for alignment. The hidden parts can be viewed if you select the formula :

        { + 5 x + 3 y + 0 z = + 0 2 x + 0 y + 7 z = + 11 3 x + 2 y 6 z = 7

      • parenthesis: ( x )
      • interval: The open, separator and close symbols are asked. [ a ; b ]
      • fence: Same, but the number of element is asked. [ 1 , c , Y , , }
      • mtable: a b c d
      • menclose: a or b
      • selector: The number of coordonnates is asked. a i j
      • piecewise or vertical brace : x = { x  if  x 0 x  otherwise
    • Presentation MathML constructs: msup, msub, msubsup, mover, munder, munderover, multiscripts.
    • Sets of numbers: naturals, integers, rationals, reals, complexes, quaternions, primes.
    • Accents and underscript
    • relations of equivalence and orders
      • equalities, approx, congru, isomorphic
      • inequalities
      • inf, sup, max and min
    • logic
      • True and False
      • equivalence
      • universal and existential quantifiers
      • not, and, or, xor, implies, equivalent to
    • set theory
      • set/list built by extension/separation, nuple
      • element, subset
      • empty set, powerset
      • complement, difference, symetric difference
      • intersection, union, cartesian product
      • cardinal, omega, aleph, diagonal intersection
    • functions and maps
      • lambda construct
      • map definition, arrows
      • domain, image (range), codomain
      • identity, compose, inverse
    • arithmetic
      • sum, prod
      • factorial, combination, cardinal
      • factor of
      • lcm, gcd
      • reminder, quotient
    • operations
      • elementary operations: plus, minus, times, divide, fraction
      • power, root
      • floor, ceiling
    • complexes
      • abs, arg, conjugate
      • cartesian, polar
      • real and imaginary part
    • constants: , , π , γ , NaN (not a number)
    • analysis
      • differential, partial differential
      • integrals: simple/double/triple, normal/contour, msub/msupsub
      • equivalence
      • limit, tends to
      • supminus ( 1 - ) or supplus ( 0 + )
      • infinity
      • o and O
    • linear algebra
      • direct sum
      • vectorrow, vectorcolumn, matrix
      • transpose, determinant
      • curl, div, grad, laplacian
      • vector product, scalar product, outerproduct
      • orthogonal, parallel, orthogonal complement, norm
    • statistic : mean, sdev, variance, median, mode, moment
  1. classical elementary functions (trigonometric, inverse...)

Entering Math Constructs using the Keyboard

You are not required to use the menus or the Math palette to create and edit mathematical expressions. You can enter mathematical constructs directly from the keyboard because each item in the Math menus has a keyboard equivalent. These shortcuts are listed on the menu. See the list of current Linux, Mac OS X, and Windows shortcuts. You can enter greek letters with the following shortcuts : (Ctrl) g (Ctrl) [letter] and (Ctrl + Shift) G (Ctrl + Shift) [letter].

You can also use the keyboard arrow keys to move the insertion point from one math construct to another. The right and left arrows move the insertion point according to the structure of the mathematical expression. For example, in a fraction when the insertion point is at the end of a numerator, the right arrow key moves the insertion point to the beginning of the denominator. Moreover if you use the right arrow in a not already completed construction, the insertion point is directly moved to the nearest placeholder.

Advanced Editing Features

Entering Math Characters

When you type a character string in a MathML element, Amaya parses the string and automatically generates the elements mo (operator), mn (number), mi (identifier), and mtext.

For example, to enter the formula x = 2 a + b

  1. If you are not in a mathematical expression, choose XML/New formula (math).
  2. Type this sequence of 6 characters: x=2a+b

Use the Structure or Source view to display the following structure generated by Amaya:

<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, select the characters that were misinterpreted and change their type with one of the commands such as Plain text (mtext), Identifier (mi), Number (mn), Operator (mo) or Space (mspace) from the Basic math elements submenu of the XML menu.

The row construction

The row construction from the palette is the equivalent of the braces in LaTeX: it allows you to give informations about how the different part of a formula are grouped together. It does not appear on the screen but have an indirect effect on the rendering.

For instance, when entering brackets as in the following expression:

f ( x ) = 1 x

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

f ( x ) = 1 x

Here, the (x) must be contained in a mrow element. You can correct the problem by selecting this part of the formula and then clicking on the row construction. You can also directly get the expected mrow if you choose Math Constructs/Parentheses from the XML menu or select the Parentheses button on the Maths palette.

Spacing

Amaya takes care of spacing within math expressions, but in some cases you may need to add some additional space. Move the cursor to the position where you want to insert space and choose Basic math elements/Space (mspace) from the XML menu. This creates a default horizontal space. You can then change its width attribute to adjust its size or you can add other attributes (height, depth, linebreak) to change vertical spacing. Refer to the MathML specification for more details.

Special Characters

You can use the Character command from the XML/Basic math Elements menu to enter mathematical characters and symbols that are not available on the keyboard. Type in the name of the character, as defined in the MathML specification. You may choose to type the Unicode value of the character instead. For entering this value in decimal, start with a '#'. For entering the value in hexadecimal, start with '#x'. To type faster, you can also enter the hexadecimal value without any leading '#x', but note that this may be ambiguous (like 'af', for instance). In case of ambiguity, the string is interpreted as a character name.

You can also use the Special characters palette. The first two rows of buttons allow you to choose a group of characters, which are then available in the pull down below. Choose a character in the list and insert it in the formula by clicking the insertion button

Also, the MathML specification says to add invisible characters in order to make easier the reading of formula by speech synthesizers. They are automatically inserted in constructions from the palette but sometimes you have to do it by yourself. You can use the XML menu or shortcuts. The three invisible characters are :

  1. invisible times: a b
  2. apply function: f ( x )
  3. invisible comma: a i j

Changing the Expression Structure

You may want to change the structure of an existing expression, such as appending a superscript, putting parentheses around an expression, or turning an expression into the numerator of a fraction. To do that, select the expression and enter the new construct with the palette, the XML/Math Constructs menu or the keyboard. You can also use Transform on the Edit menu. Select the expression you want to transform and Transform will display a menu with all possible changes. For constructs that are not part of the Presentation MathML markup - i.e. only available from the palette - clicking on the button will move the selected expression in the more natural placeholder.

Changing an expression structure is useful to keep a recursive structure even when you enter a formula linearly. For instance to enter x 2 9 25 x 3 5 you can,

Generally, you will use both methods.

Viewing Structure in MathML

MathML structure in a document can be viewed by choosing Show Structure from the Views menu. Choosing this option opens the Structure view, which reveals the main structure of the document, the math elements, and their contents.

Math expressions can be edited in the main view or in the Structure view.

The Structure view is especially helpful to avoid ambiguity. For example, in the equation below, placing the cursor after character b , it is not clear whether you wish to add something within the square root or after it.

x = a + b + 1

Selecting (or checking) in the Structure view avoids any misselections. You can also check the status line at the bottom of the main window.

Linking in MathML

You can create and use links in mathematical expressions. These links are represented using the XML Linking Language (XLink). Only simple unidirectional hyperlinks are available in Amaya, 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 or right-clicking any character within the fraction loads the W3C home page.

To create such a link, select a math expression (the fraction in the above example, for instance by clicking on the fraction bar), click the Link button from the XHTML palette (or choose Create or change link from the Links menu), and click the desired target.

If the target is an expression in a formula, you must first turn the expression into a target. Select the expression and choose Create target from the Links menu to create an id attribute for the target expression.

More about MathML

Browsers Compatibility

Firefox or other Gecko-based browsers support MathML wheras Internet Explorer needs a plugin.

It is necessary to use the .xml suffix to make sure that XHTML document are managed as an XML format. Without this suffix some browsers don't display included mathematical expressions correctly.

It's also recommended to use the utf-8 charset for all XML documents.

By default Amaya adds the XHTML 1.1 plus MathML 2.0 doctype at the beginning of the document. This doctype is not mandatory but it is useful:

Unfortunately, this doctype is not supported by many browsers. So it could be necessary to remove this doctype with the Amaya command: File>Change the Document Type>Remove the doctype.

IE uses the pmathml.xsl transformation style sheet and a plugin to display the MathML code included in XHTML documents. Amaya adds automatically a link to that transformation style sheet, but the author must think to store a copy of this style sheet (pmathml.xsl) in the local directory of the document.

Known Issues