/// <summary> /// Parse the math ML xml data. /// </summary> /// <param name="mathML">The math ML xml data.</param> /// <returns>The math expression; else null;</returns> public static string Parse(string mathML) { // try parsing the root XElement root; string s = null; try { root = XElement.Parse(mathML); BuildContextOptions buildOptions = new BuildContextOptions(); var m = Parser.Parse(root); var sb = new StringBuilder(); m.Visit(sb, new BuildContext(buildOptions)); s = sb.ToString(); bool useHacks = true; if (useHacks) { // hack: evil hacks until problems are resolved s = s.Replace("(*", "(") .Replace(")Math", ")*Math") .Replace(")(", ")*(") .Replace("**", "*"); // hack: even nastier hack here Regex re = new Regex(@"(\d)(\()"); foreach (Match match in re.Matches(s)) { string toReplace = match.Value; string toReplaceWith = match.Groups[1].Value + "*" + match.Groups[2].Value; s = s.Replace(toReplace, toReplaceWith); } } } catch { s = null; } return(s); }
/// <summary> /// Initializes a new instance of the <see cref="BuildContext"/> class. /// </summary> /// <param name="options">Build options.</param> internal BuildContext(BuildContextOptions options) { Options = options; }