/**
* Convert the Expression to MathML.
*
* @return {string}
*/
toMathML() : string {
if (this.subtype === 'assignment') {
return this.content.map(MathLib.toMathML).join(':=') + ':=' + MathLib.toMathML(this.value);
}
if (this.subtype === 'binaryOperator') {
if (this.value === '-') {
return this.content[0].toMathML() + '-' + this.content[1].toMathML();
}
if (this.value === '/') {
return '' + this.content[0].toMathML() + this.content[1].toMathML() + '';
}
if (this.value === '^') {
return '' + this.content[0].toMathML() + this.content[1].toMathML() + '';
}
}
if (this.subtype === 'brackets') {
return '(' + this.content.toMathML() + ')';
}
if (this.subtype === 'complexNumber') {
if (this.mode === 'cartesian') {
return '' + this.value[0].toMathML() + '+' + this.value[1].toMathML() + 'i';
}
else if (this.mode === 'polar') {
return this.value[0].toMathML() + 'e'
+ this.value[1].toMathML() + 'i';
}
}
if (this.subtype === 'constant') {
if (this.value === 'pi') {
return 'π';
}
}
if (this.subtype === 'number') {
return '' + this.value + '';
}
if (this.subtype === 'variable') {
return '' + this.value + '';
}
if (this.subtype === 'naryOperator') {
return '' + this.content.map(expr => expr.toMathML()).join('' +
(this.value === '*'
? '·'
: this.value) +
'') + '';
}
if (this.subtype === 'unaryOperator') {
if (this.value === '-') {
return '-' + this.content.toMathML();
}
return this.content.toMathML();
}
if (this.subtype === 'functionCall') {
return '' + this.value + '⁡(' +
( this.content.length
? this.content.map(expr => expr.toMathML()).join(',')
: 'x') +
')';
}
if (this.subtype === 'functionDefinition') {
return '' +
(this.args.length === 1
? '' + this.args[0] + ''
: '(' + this.args.join(',') + ')') +
'⟼' +
(this.content.length === 1
? this.content[0].toMathML()
: '(' + this.content.map(expr => expr.toMathML()) + ')') +
'';
}
}