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; }