// include generated mathml from right nodes to siblings to their left (because of mrow) virtual public string ChildMathML(string right) { if (this is RelationTreeNode || this is SymbolTreeNode) { throw new Exception("Child classes must re-implement this method"); } if (this.children.Count > 0 && (this.children[0] is RelationTreeNode || this.children[0] is SymbolTreeNode)) { string this_symbol = null; if (this.children.Count == 2) { // one relation string relationship = (this.children[1] as RelationTreeNode).relationType; switch (relationship) { // sqrt case "CONTAINS": this_symbol = String.Format("<msqrt>{0}</msqrt>", this.children[1].ChildMathML(null)); break; // supersscript case "SUPER": this_symbol = String.Format("<msup>{0}{1}</msup>", this.children[0].ChildMathML(null), this.children[1].ChildMathML(null)); break; // subscript case "SUBSC": this_symbol = String.Format("<msub>{0}{1}</msub>", this.children[0].ChildMathML(null), this.children[1].ChildMathML(null)); break; } } else if (this.children.Count == 3) { // frac/sum/etc. string above = null, below = null, this_sym = null; bool is_frac = false; foreach (ParseTreeNode ptn in this.children) { if (ptn is RelationTreeNode) { RelationTreeNode rtn = null; rtn = ptn as RelationTreeNode; if (rtn.relationType == "ABOVE") { above = rtn.ChildMathML(null); } if (rtn.relationType == "BELOW") { below = rtn.ChildMathML(null); } } else if (ptn is SymbolTreeNode) { SymbolTreeNode stn = ptn as SymbolTreeNode; this_sym = stn.ChildMathML(null); if (stn.nodeType.Equals("-")) { is_frac = true; } } } if (is_frac) { this_symbol = String.Format("<mfrac>{0}{1}</mfrac>", above, below); } else { this_symbol = String.Format("<msubsup>{0}{1}{2}</msubsup>", this_sym, below, above); } } else { for (int k = this.children.Count - 1; k >= 0; k--) { right = this.children[k].ChildMathML(right); } } if (right == null) { return(this_symbol); } if (this_symbol == null) { return(right); } // something to our right return(String.Format("<mrow>{0}{1}</mrow>", this_symbol, right)); } else { for (int k = this.children.Count - 1; k >= 0; k--) { right = this.children[k].ChildMathML(right); } return(right); } }