Adding an output format

The formats supplied are Maple, Latex, MathML and Maxima, with the corresponding files found in the \formats folder. These files can be edited to reflect the syntax you prefer. These files can also be used as templates for creating files for different formats. There are a number of rules and options that you need to be aware of to successfully create an XML file for a new format.

Each math object has its own element in the XML document, with a familiar name describing it, for example “Add”. Within this element there are a number of sub-elements depending upon how many arguments the object has.
N-ary operators have a single ‘output’ element e.g. for addition this is
<Add>
<output>+</output>
</Add>
Binary Operators have 3 ‘output’ elements e.g. for fraction in Latex this is
<Divide brackets="false">
<output1>\frac{</output1>
<output2>}{</output2>
<output3>}</output3>
</Divide>
Functions have 2 ‘output’ elements e.g. for square root in Latex this is
<SquareRoot brackets="false">
<output1>\sqrt{</output1>
<output2>}</output2>
</SquareRoot>
N-ary functions have 'n' output elements e.g. for definite integral in Latex it has 5
<DefiniteIntegral reverse="true">
<output1> \int_{</output1>
<output2>}^{</output2>
<output3>}</output3>
<output4>\,\mathrm{d</output4>
<output5>}</output5>
</DefiniteIntegral>
Symbols have 1 ‘output’ element e.g. for Infinity in Latex this is
<Infinity>
<output>\infty</output>
</Infinity>
Groupings have 2 ‘output’ elements e.g. for square brackets in Latex this is
<BracketsSq>
<output1>\left[</output1>
<output2>\right]</output2>
</BracketsSq>
Matrix in Latex is as follows:
<Matrix>
<matrixStart>\left( \begin{array}{ccc}</matrixStart>
<rowStart />
<elementStart />
<elementEnd />
<elementSeparator><![CDATA[ & ]]></elementSeparator>
<rowEnd> \\ </rowEnd>
<rowSeparator />
<matrixEnd>\end{array} \right)</matrixEnd>
</Matrix>
The syntax within these tags is used when converting an expression to that particular format. The actual arguments of the objects appear in the syntax between each pair of tags. For example consider ½ in Latex format. It has 3 ‘output’ elements. So the first part will be ‘\frac{‘, then the first argument will be appended to the string giving us, ‘\frac{1’, then the 2nd output will be appended, ‘\frac{1}{‘, then the 2nd argment, \frac{1}{2’ and then the final output, ‘\frac{1}{2}’. A similar process takes place with all the object types of objects, with the argument being appended between each pair of output elements.
There are various options that can be set to allow more control over the output.
Reverse
If you find the arguments of a binary operator being output in the wrong order for a format, you can reverse the order of them by setting, reverse=”true”. An example of this is with the N-th root in Latex,
<NthRoot reverse="true" brackets="false">
<output1>\sqrt[ </output1>
<output2>]{</output2>
<output3>}</output3>
</NthRoot>
Argument Order
If you find the arguments of an N-ary Function being output in the wrong order for a format, you can re-arrange the order of them by setting, order=”#1,#2,#3,...,#n”. An example of this is with the Sum in Latex. Obviously, the default order for this is 0,1,2,3, and it is being changed to 1,2,3,0.
<Sum order="1,2,3,0">
<output1> \sum_{{</output1>
<output2>}={</output2>
<output3>}}^{</output3>
<output4>}</output4>
<output5></output5>
</Sum>
AutoBrackets
By default, round brackets are placed around n-ary operators and binary operators where necessary to ensure operator precedence is preserved. For presentational formats, such as Latex this is often unnecessary, so there is the option to turn automatic placing of brackets on/off. This is set in the element that specifies the name of the format. An example of this is shown for Latex,
<name AutoBrackets="false">Latex</name>
Brackets on Functions
Brackets are added by default around the argument of a function. For example Sine in Latex is,
<Sine>
<output1>\sin </output1>
<output2 />
</Sine>
Brackets are automatically added after the ‘\sin’ and after the 2nd output, resulting in "\sin(arg)". This is often the desired result but if you need to turn the brackets off, they can be set for each individual function. An example of turning them off is shown here for Square root in Latex,
<SquareRoot brackets="false">
<output1>\sqrt{</output1>
<output2>}</output2>
</SquareRoot>
Initial
As well as the structured number of output elements for each type of object, there is the option of having an ‘initial’ element. The data in this element is added to the string before any other output element is. An example of its use for describing multiplication in MathML Content is shown below.
<Add>
<initial><times/></initial>
<output</output>
</Add>
‘a x b x c’ would then be converted to,
<times/>
<ci>a</ci>
<ci>b</ci>
<ci>c</ci>
Final
N-ary operators can also have an optional 'final' element for adding data after everything else. An example of this is with Union in Maxima.
<Union>
<initial>union(</initial>
<output>,</output>
<final>)</final>
</Union>