public static String getHTMLEval(String input) { String workingInput = cleanInput(input); Expression expressionToEval = MathEngine.getExpressionFromString(workingInput); if (expressionToEval == null) { return(HTMLizer.prepareForHTML(input)); } else { Expression evaluated = expressionToEval.cloneAndSubstitute(MathEngine.Table).evaluate(); return(@"\(" + evaluated.toHTML() + @"\)"); } }
public static String getHTMLPlot(String input) { String workingInput = cleanInput(input); String[] partsOfCommand = workingInput.Split(new Char[] { ',' }); if (partsOfCommand.Length != 4) { return(HTMLizer.prepareForHTML(input)); } try { Double lowerLimit = Double.Parse(partsOfCommand[1]); Double upperLimit = Double.Parse(partsOfCommand[2]); int numberOfPoints = int.Parse(partsOfCommand[3]); if (lowerLimit > upperLimit || numberOfPoints <= 0) { return(HTMLizer.prepareForHTML(input)); } Expression expr = MathEngine.getExpressionFromString(partsOfCommand[0]); List <Symbol> symbolsInExpr = new List <Symbol>(); if (expr == null || (symbolsInExpr = expr.symbolsInExpression(symbolsInExpr)).Count != 1 || !expr.canEvaluateIfSymbolsConst(symbolsInExpr.ToArray())) { return(HTMLizer.prepareForHTML(input)); } List <KeyValuePair <Double, Double> > points = new List <KeyValuePair <Double, Double> >(); loadPoints(ref points, expr, symbolsInExpr[0], lowerLimit, upperLimit, numberOfPoints); return(generateHTMLPlot(points)); } catch (Exception) { return(HTMLizer.prepareForHTML(input)); } }