private SnuggleEngine createSnuggleEngine() { return new SnuggleEngine(getStylesheetManager()); } }
/** * Creates a new {@link SnuggleSession} using the default {@link SessionConfiguration} * or a fresh {@link SessionConfiguration} if no default has been set. */ public SnuggleSession createSession() { return createSession(defaultSessionConfiguration); }
/** * Builds a DOM sub-tree based on the currently parsed tokens, appending the results as * children of the given target root Element. This uses the default {@link DOMOutputOptions} * associated with this engine. * * @return true if completed successfully, false if the process was terminated by an error in the * input LaTeX and if the session was configured to fail on the first error. */ public boolean buildDOMSubtree(final Element targetRoot) { return buildDOMSubtree(targetRoot, engine.getDefaultDOMOutputOptions()); }
private Node latexToNode(String latex){ SnuggleEngine engine = new SnuggleEngine(); try { SnuggleSession createSession = engine.createSession(); createSession.parseInput(new SnuggleInput(latex)); NodeList dst = createSession.buildDOMSubtree(); return dst.item(0); } catch (IOException e) { throw new RuntimeException(e); } }
public static void main(String[] args) throws IOException { /* Create vanilla SnuggleEngine and new SnuggleSession */ SnuggleEngine engine = new SnuggleEngine(); SnuggleSession session = engine.createSession(); /* Parse some LaTeX input */ SnuggleInput input = new SnuggleInput("\\section*{The quadratic formula}" + "$$ \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a} $$"); session.parseInput(input); /* Specify how we want the resulting XML */ XMLStringOutputOptions options = new XMLStringOutputOptions(); options.setSerializationMethod(SerializationMethod.XHTML); options.setIndenting(true); options.setEncoding("UTF-8"); options.setAddingMathSourceAnnotations(true); if (engine.getStylesheetManager().supportsXSLT20()) { /* Caller has an XSLT 2.0 processor, so let's output named entities for readability */ options.setUsingNamedEntities(true); } /* Convert the results to an XML String, which in this case will * be a single MathML <math>...</math> element. */ System.out.println(session.buildXMLString(options)); } }
this.packages = engine.getPackages().toArray(new SnugglePackage[engine.getPackages().size()]); this.defaultDOMOutputOptions = (DOMOutputOptions) engine.getDefaultDOMOutputOptions().clone(); this.defaultXMLStringOutputOptions = (XMLStringOutputOptions) engine.getDefaultXMLStringOutputOptions().clone();
/** * Gets the {@link StylesheetManager} being used by the underlying {@link SnuggleEngine} */ public StylesheetManager getStylesheetManager() { return engine.getStylesheetManager(); }
/** * Creates a well-formed external general parsed entity out of the currently parsed tokens. * <p> * The default {@link XMLStringOutputOptions} specified in the {@link SnuggleEngine} will be * used. * * @return resulting XML if the process completed successfully, null if the process was * terminated by an error in the input LaTeX and if the session was configured to fail on * the first error. */ public String buildXMLString() { return buildXMLString(engine.getDefaultXMLStringOutputOptions()); }
/** * Delegates to {@link SnuggleEngine#getBuiltinCommandByTeXName(String)} * * @see SnuggleEngine#getBuiltinCommandByTeXName(String) */ public BuiltinCommand getBuiltinCommandByTeXName(String texName) { return engine.getBuiltinCommandByTeXName(texName); }
/** * Delegates to {@link SnuggleEngine#getBuiltinEnvironmentByTeXName(String)} * * @see SnuggleEngine#getBuiltinEnvironmentByTeXName(String) */ public BuiltinEnvironment getBuiltinEnvironmentByTeXName(String texName) { return engine.getBuiltinEnvironmentByTeXName(texName); }
private Node latexToNode(String latex){ SnuggleEngine engine = new SnuggleEngine(); try { SnuggleSession createSession = engine.createSession(); createSession.parseInput(new SnuggleInput(latex)); NodeList dst = createSession.buildDOMSubtree(); return dst.item(0); } catch (IOException e) { throw new RuntimeException(e); } }
public static void main(String[] args) throws IOException { /* Create vanilla SnuggleEngine and new SnuggleSession */ SnuggleEngine engine = new SnuggleEngine(); SnuggleSession session = engine.createSession(); /* Parse some LaTeX input */ SnuggleInput input = new SnuggleInput("\\section*{The quadratic formula}" + "$$ \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a} $$"); session.parseInput(input); /* Specify how we want the resulting XML */ XMLStringOutputOptions options = new XMLStringOutputOptions(); options.setSerializationMethod(SerializationMethod.XHTML); options.setIndenting(true); options.setEncoding("UTF-8"); options.setAddingMathSourceAnnotations(true); if (engine.getStylesheetManager().supportsXSLT20()) { /* Caller has an XSLT 2.0 processor, so let's output named entities for readability */ options.setUsingNamedEntities(true); } /* Convert the results to an XML String, which in this case will * be a single MathML <math>...</math> element. */ System.out.println(session.buildXMLString(options)); } }
/** * Gets the {@link StylesheetManager} being used by the underlying {@link SnuggleEngine} */ public StylesheetManager getStylesheetManager() { return engine.getStylesheetManager(); }
/** * Creates a well-formed external general parsed entity out of the currently parsed tokens. * <p> * The default {@link XMLStringOutputOptions} specified in the {@link SnuggleEngine} will be * used. * * @return resulting XML if the process completed successfully, null if the process was * terminated by an error in the input LaTeX and if the session was configured to fail on * the first error. */ public String buildXMLString() { return buildXMLString(engine.getDefaultXMLStringOutputOptions()); }
/** * Delegates to {@link SnuggleEngine#getBuiltinCommandByTeXName(String)} * * @see SnuggleEngine#getBuiltinCommandByTeXName(String) */ public BuiltinCommand getBuiltinCommandByTeXName(String texName) { return engine.getBuiltinCommandByTeXName(texName); }
/** * Delegates to {@link SnuggleEngine#getBuiltinEnvironmentByTeXName(String)} * * @see SnuggleEngine#getBuiltinEnvironmentByTeXName(String) */ public BuiltinEnvironment getBuiltinEnvironmentByTeXName(String texName) { return engine.getBuiltinEnvironmentByTeXName(texName); }
public static void main(String[] args) throws IOException { /* Create vanilla SnuggleEngine and new SnuggleSession */ SnuggleEngine engine = new SnuggleEngine(); SnuggleSession session = engine.createSession(); /* Parse some very basic Math Mode input */ SnuggleInput input = new SnuggleInput("$$ x+2=3 $$"); session.parseInput(input); /* Convert the results to an XML String, which in this case will * be a single MathML <math>...</math> element. */ String xmlString = session.buildXMLString(); System.out.println("Input " + input.getString() + " was converted to:\n" + xmlString); } }
/** * Creates a new {@link SnuggleSession} using the default {@link SessionConfiguration} * if se */ public SnuggleSession createSession() { SessionConfiguration sessionConfiguration = defaultSessionConfiguration; if (sessionConfiguration!=null) { sessionConfiguration = new SessionConfiguration(); } return createSession(sessionConfiguration); }
/** * Builds a DOM sub-tree based on the currently parsed tokens, appending the results as * children of the given target root Element. This uses the default {@link DOMOutputOptions} * associated with this engine. * * @return true if completed successfully, false if the process was terminated by an error in the * input LaTeX and if the session was configured to fail on the first error. */ public boolean buildDOMSubtree(final Element targetRoot) { return buildDOMSubtree(targetRoot, engine.getDefaultDOMOutputOptions()); }
/** * Gets the {@link StylesheetManager} being used by the underlying {@link SnuggleEngine} */ public StylesheetManager getStylesheetManager() { return engine.getStylesheetManager(); }