public List<InputError> getLastErrors() { return session.getErrors(); } }
public Element doMathInput(String mathModeInput, DOMOutputOptions domOutputOptions) { ConstraintUtilities.ensureNotNull(mathModeInput, "Math Mode Input"); String latexInput = "\\[" + mathModeInput + "\\]"; session.reset(); try { session.parseInput(new SnuggleInput(latexInput, "Math Mode Input")); } catch (IOException e) { throw new SnuggleLogicException("Unexpected IOException"); } NodeList nodeList = session.buildDOMSubtree(domOutputOptions); if (!session.getErrors().isEmpty()) { return null; } /* Extract and check <math> element */ Element result = null; if (nodeList.getLength()==1) { result = (Element) nodeList.item(0); if (!MathMLUtilities.isMathMLElement(result, "math")) { throw new IllegalArgumentException("Input did not yield exactly 1 <math> element"); } } else { throw new IllegalArgumentException("Input did not yield exactly 1 result element"); } return result; }
for (InputError error : session.getErrors()) { System.err.println(MessageFormatter.formatErrorAsString(error));
for (InputError error : session.getErrors()) { System.err.println(MessageFormatter.formatErrorAsString(error));
for (InputError error : session.getErrors()) { System.err.println(MessageFormatter.formatErrorAsString(error));
/** * Convert a tex math formula into a Symja expression. The SnuggleTeX engine first converts the TeX expression in a * MathML expression. This MathML expression is then converted to Symja. * * @param texStr * the tex math formula * @return */ public IExpr toExpression(String texStr) { SnuggleEngine engine = new SnuggleEngine(); SnuggleSession session = engine.createSession(); session.getConfiguration().setFailingFast(true); SnuggleInput input = new SnuggleInput("$$ " + texStr + " $$"); try { if (session.parseInput(input)) { NodeList nodes = session.buildDOMSubtree(); int[] position = new int[] { 0 }; return convert(nodes, position, null, 0); } List<InputError> errors = session.getErrors(); for (int i = 0; i < errors.size(); i++) { fEngine.printMessage(errors.get(i).toString()); } } catch (Exception e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } return F.$Aborted; }