Mathematical expressions (formulas) in MathML

Topics:

Expressions

Two TeX variants, two compilers

Character groups

Names

Numbers

Symbols

Fixed TeX words

Table with TeX words

Own table

MathML code

Blanks

Superscript and subscript

Examples of mathematical expressions

Mathematical expressions written directly in MathML

This page can only be displayed properly with a browser capable of displaying formulas in MathML, for example Mozilla Firefox.

Mathematical expressions may be written directly in MathML as described below.

Mathematical expressions may also be written in a format borrowed from TeX (LaTeX), and placed between a pair of dollar signs, as in the circle equation:
$ cos ^2 x + sin ^ 2 x = 1 $
Each expression must end on the same line on which it started. This rule has been made to prevent confusion due to forgotten $ characters, among other reasons.
Expressions written in TeX are translated into MathML. The MathML expressions can as usual be viewed in the source code for the quizzes produced. Notice that quiz files with MathML have a suffix .xml and that they follow the standard XML, which rquires strict adherence to all rules of syntax.

On every server with QuizComposer the TeX to MathML compiler, the TeX variant ITeX, to which references can be found on this Mozilla/MathML page is installed, if possible. Please notice on that page the posibility of having sample formulas displayed, and of trying out your own formulas. Expressions written between a pair of dollar signs (one before and one after) are translated using this compiler, when installed.

On servers where the ITeX compiler is not installed formulas enclosed between single dollar signs are translated using a built-in compiler, denoted QCTeX. The possibilities with this compiler, QCTeX, are described below. If the expression $ \QC $ is translated into the word QuizComposer the ITeX compiler is not installed on the server, accordingly QCTeX will be used for all formulas between $-signs.

The ITeX compiler gives you more possibilities for writing formulas than the built-in compiler does. You may, for example, write tables ("\array") according to the guide to ITeX. Incidentally, for tables especially, notice the possibility in QuizComposer of indicating, in question fields, line continuation with a \ at the very end of a line (e.g. for tables, after space after \\).

A possible advantage with the built-in compiler, QCTeX, is the possibility of associating a conversion table from TeX commands to MathML character sequences as described below. By writing a triple $$$ rather than a single $ before a formula you indicate that the formula should be translated using QCTeX.

The rest of this guide specifies the formulas that can be translated with the built-in formula compiler in QuizComposer.

An expression is composed of character groups separated by blanks (spaces). There are five categories of character groups, viz. names, numbers and symbols, plus so-called TeX words and MathML tags. TeX words start with the sign \. MathML tags start with < and end with >.

begin with a letter. A name with only one letter will be displayed in italics. Otherwise names are displayed in a normal font (Roman). Please note, that function names which in TeX are written starting with a \ sign, e.g. \log, are displayed without this \ sign.

are written with digits, decimal point and minus sign where applicable.

may be written either as they are, e.g. with / for division, with \TeX words,with MathML tags or with an & symbol, as described in the following section.

As mentioned above, TeX words begin with the sign \. The following six words have special significance:
\sqrt specifies the square root of the subsequent argument \root specifies the nth root of the subsequent argument, with n as the second argument
\frac specifies a fraction of the 2 subsequent arguments in the expression (numerator and denominator),
\munder specifies that the subsequent argument will have the next subsequent argument beneath it, as often used in summation,
\mover specifies likewise, a superscript,
\munderover specifies a subscript and a superscript.

All the other TeX words are looked up in a built-in table associated with the translator. If the TeX word is at the start of a line, it will be replaced in the expression by the rest of the table line (which is expected to be a MathML construct). For example, \infty shows the symbol for infinity, as in the table. If a TeX word does not appear in the table the \ sign will be replaced by & and a semicolon (;) will be appended to the word. Hopefully, this creates a "MathML Character Name", that will be displayed as a mathematical symbol. For example, \alpha displays Greek alpha.

The built-in table contains most of TeX's mathematical symbols but if you can't find what your looking for you may define your own table using this form.
You can also directly write MathML Character Names starting with an & sign and ending with a semicolon (;).

The table illustrates the format of MathML code. A MathML element is normally written with both start and end tags of which the simplest are <mi> for "identifiers", <mn> for numbers and <mo> for operators. The latter type cover, generally speaking, all other symbols including brackets (parentheses).
Round brackets (( )) and square brackets ([ ]) may be written straight in. They will be displayed as they are, although you should be aware that they will be stretched vertically to surround their contents e.g. fractions and tables. However, curly brackets ({ }) have a special significance and as in TeX, enclose arguments to the special TeX words mentioned above. For example, the expression $ \sqrt{a^2+b^{-2}} $ displays the square root of the sum of a to the power of 2 and b to the power of minus 2.

MathML tags are not translated. With MathML tags, you just write direct MathML code, e.g. the start tag <mi>. In principle, you'll need to put in an end tag for every start tag. But if one or more end tags are missing in relation to the number of start tags, then end tags will be generated so that MathML's requirements for a bracket structure are kept.
In the end markers which you write yourself, you may add "options", although quotation marks must not be used, only apostrophes ('). (This requirement will probably be lifted some time in the future).

When writing a mathematical expression, you should be aware of how blanks (spaces) are used to separate groups of characters. The translator creates MathML code for each separate group of characters. Apart from blanks that you yourself have placed (e.g. between a function name like sin and an argument like x), the translator inserts blanks (spaces) as follows:
In front of the following 4 signs: - \ & <
After the following 4 signs: = ; , :
Enclosing the following (groups of) characters: _ + ^( { [ ) } ] <> >= <=
After a minus sign (-), unless it's followed by a digit or a decimal point.
In front of an equals sign (=), unless it's with a < or >
After greater than (>), unless this is followed by =
In front of a slash(/), unless this follows a <
After a slash (/), unless this is followed by a >

Please note, that the symbol ^ for power of , or superscript, and the symbol _ for subscript are treated differently from the other symbols written directly, e.g. + and /. From the _ and ^ signs, MathML code is created with start tags <msub>, <msup> or <msubsup> followed by the "base" (that which is indexed) and an index or two indices. See the examplesbelow.

Examples of mathematical expressions
To view these mathematical formulas, you need a special browser that can display them, such as Mozilla Firefox.

$ a sin^2 x + cos^-2 x = 1.5 $         is displayed         a sin 2 x + cos -2 x = 1.5

$ \frac {-b \pm \sqrt { b^2 - 4 a c }}{2 a} $         is displayed as         - b ± b 2 - 4 a c 2 a

$ \frac { \sqrt { 4 + \sqrt { 12 + 13 } } } { \root 64 3 } $         is displayed as         4 + 12 + 13 64 3

$ \int _ 0 ^ \pi f(x)dx = \munderover \sum {i=1} {i=n} y _ j ^ m $         is displayed as         0 π f ( x ) dx = i = 1 i = n y j m

$ \frac {d ln x^4 } { d x} $         is displayed as         d ln x 4 d x

Mathematical expressions written directly in MathML
You can write MathML codes directly into a definition form's fields. For example, the codestring:
<math xmlns='&mathml;'> <mi>sin</mi><mo>(</mo><mi>x</mi><mo>)</mo><math>
displays
sin(x).
Obviously, MathML is really quite verbious.

An option worth considering is to use a MathML composer to write MathML code. Amaya is a combined browser and composer/editor, a so-called WYSIWYG composer (What You See Is What You Get), where formulas can be constructed graphically by pointing and clicking. Amaya is able to display MathML codes in a separate window from which you can copy the code to the field in the definition form. Also, look into the Mozilla MathML project for a composer of MathML pages.