/** * 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); }
/** * 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); }
/** * 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); }
public SnuggleSimpleMathRunner createSimpleMathRunner() { return new SnuggleSimpleMathRunner(createSession()); }
public SnuggleSimpleMathRunner createSimpleMathRunner(SessionConfiguration sessionConfiguration) { return new SnuggleSimpleMathRunner(createSession(sessionConfiguration)); }
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); } }
void convert(Element latexElement) throws IOException { String rawInputLaTeX = latexElement.getTextContent(); String inputLaTeX = rawInputLaTeX.replaceAll("(\r\n|\r|\n)", "\n"); SnuggleEngine engine = createSnuggleEngine(); SnuggleSession session = engine.createSession(); SnuggleInput input = new SnuggleInput(inputLaTeX, "LaTeX Element"); try { session.parseInput(input); } catch (Exception e) { throw new IOException("Error while parsing: " + rawInputLaTeX + ": " + e.getMessage(), e); } while (latexElement.getChildNodes().getLength() != 0) latexElement.removeChild(latexElement.getFirstChild()); DOMOutputOptions options = new DOMOutputOptions(); options.setErrorOutputOptions(DOMOutputOptions.ErrorOutputOptions.XHTML); try { session.buildDOMSubtree(latexElement, options); } catch (Exception e) { throw new IOException("Error while building DOM for: " + rawInputLaTeX + ": " + e.getMessage(), e); } }
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 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); } }
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); } }
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); } }
SnuggleSession session = engine.createSession(); try {
SnuggleSession session = engine.createSession(); try {
/** * 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; }
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); options.setUsingNamedEntities(true); /* (Only used if caller has an XSLT 2.0 processor) */ /* 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)); } }
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)); } }
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)); } }
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("$$ e^{i\\pi} = -1 $$"); session.parseInput(input); /* Create "options" Object to SnuggleTeX what kind of web page we want. We're going * to generate one that will work fine with MOZILLA and tweak a few options, just for * fun! */ WebPageOutputOptions options = WebPageOutputOptionsTemplates.createWebPageOptions(WebPageType.MOZILLA); options.setTitle("My Web Page"); options.setAddingTitleHeading(true); options.setIndenting(true); options.setAddingMathSourceAnnotations(true); options.setIncludingStyleElement(false); /* Now ask SnuggleTeX to write the resulting output to the console. * (You would normally send the output somewhere more interesting, though!) */ session.writeWebPage(options, System.out); } }
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("$$ a^2 = b^2 + c^2 $$"); session.parseInput(input); /* Create "options" Object to SnuggleTeX what kind of web page we want. We're going * to generate one that will work fine with MOZILLA and tweak a few options, just for * fun! */ WebPageOutputOptions options = WebPageOutputOptionsBuilder.createHTML5MathJaxOptions(); options.setTitle("My Web Page"); options.setAddingTitleHeading(true); options.setIndenting(true); options.setAddingMathSourceAnnotations(true); options.setIncludingStyleElement(false); /* Now ask SnuggleTeX to write the resulting output to the console. * (You would normally send the output somewhere more interesting, though!) */ session.writeWebPage(options, System.out); } }
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("$$ e^{i\\pi} = -1 $$"); session.parseInput(input); /* Create "options" Object to SnuggleTeX what kind of web page we want. We're going * to generate one that will work fine with MOZILLA and tweak a few options, just for * fun! */ WebPageOutputOptions options = WebPageOutputOptionsTemplates.createWebPageOptions(WebPageType.MOZILLA); options.setTitle("My Web Page"); options.setAddingTitleHeading(true); options.setIndenting(true); options.setAddingMathSourceAnnotations(true); options.setIncludingStyleElement(false); /* Now ask SnuggleTeX to write the resulting output to the console. * (You would normally send the output somewhere more interesting, though!) */ session.writeWebPage(options, System.out); } }