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)); } }
/** * Creates a {@link SnuggleSnapshot} Object holding the current state of this session that can * be later used to recreate a session having exactly the same state. */ public SnuggleSnapshot createSnapshot() { return new SnuggleSnapshot(engine, packages, (SessionConfiguration) configuration.clone(), (DOMOutputOptions) defaultDOMOutputOptions.clone(), /* (No real need to clone as this is immutable here, but we'll do it for consistency) */ (XMLStringOutputOptions) defaultXMLStringOutputOptions.clone(), /* (Ditto) */ new ArrayList<InputError>(errors), new HashMap<String, UserDefinedCommand>(userCommandMap), new HashMap<String, UserDefinedEnvironment>(userEnvironmentMap), new ArrayList<FlowToken>(parsedTokens)); }
private static String serializeAndDumpDocument(final String title, final Document document) { final XMLStringOutputOptions outputOptions = new XMLStringOutputOptions(); outputOptions.setIndenting(true); final String serialized = XMLUtilities.serializeNode(document, outputOptions); System.out.println(title + " => " + serialized); return serialized; }
/** * Creates a new {@link SnuggleEngine} using the given {@link StylesheetManager} * for managing stylesheets. Use this if you want to integrate XSLT caching * with your own code, want more control over how things get cached or want to control * the selection of XSLT implementations. */ public SnuggleEngine(StylesheetManager stylesheetManager) { this.packages = Collections.synchronizedList(new ArrayList<SnugglePackage>()); this.defaultSessionConfiguration = new SessionConfiguration(); this.defaultDOMOutputOptions = new DOMOutputOptions(); this.defaultXMLStringOutputOptions = new XMLStringOutputOptions(); /* Create manager for XSLT stylesheets using the given cache */ this.stylesheetManager = stylesheetManager; /* Add in core package */ packages.add(CorePackageDefinitions.getPackage()); }
/** * Creates a new {@link SnuggleEngine} using the given {@link StylesheetManager} * for managing stylesheets. Use this if you want to integrate XSLT caching * with your own code, want more control over how things get cached or want to control * the selection of XSLT implementations. */ public SnuggleEngine(StylesheetManager stylesheetManager) { this.packages = new ArrayList<SnugglePackage>(); this.defaultSessionConfiguration = new SessionConfiguration(); this.defaultDOMOutputOptions = new DOMOutputOptions(); this.defaultXMLStringOutputOptions = new XMLStringOutputOptions(); /* Create manager for XSLT stlyesheets using the given cache */ this.stylesheetManager = stylesheetManager; /* Add in core package */ packages.add(CorePackageDefinitions.getPackage()); }
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)); } }
/** * Creates a new {@link SnuggleEngine} using the given {@link StylesheetManager} * for managing stylesheets. Use this if you want to integrate XSLT caching * with your own code, want more control over how things get cached or want to control * the selection of XSLT implementations. */ public SnuggleEngine(StylesheetManager stylesheetManager) { this.packages = new ArrayList<SnugglePackage>(); this.defaultSessionConfiguration = new SessionConfiguration(); this.defaultDOMOutputOptions = new DOMOutputOptions(); this.defaultXMLStringOutputOptions = new XMLStringOutputOptions(); /* Create manager for XSLT stlyesheets using the given cache */ this.stylesheetManager = stylesheetManager; /* Add in core package */ packages.add(CorePackageDefinitions.getPackage()); }
this.defaultXMLStringOutputOptions = (XMLStringOutputOptions) engine.getDefaultXMLStringOutputOptions().clone();
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)); } }