Creating XML String or DOM Outputs

The simplest outputs that SnuggleTeX can create are XML String and XML DOM-based outputs.


  • Call one of the SnuggleSession.buildXMLString() methods create an XML String fragment (or, more formally, a “well-formed external general parsed entity”) representing everything that has been parsed so far. This type of output can be useful for demonstrating results, or if you need to pass or transmit the resulting XML to other software components. (See the Minimal and XML String Output examples to demonstrate this.)
  • Call one of the snuggleSession.buildDOMSubtree() methods to append the resulting XML to an existing DOM Element’s children. This might be useful if you are integrating SnuggleTeX into some other activity that builds a DOM.
  • Call one of the snuggleSession.buildDOMSubtree() methods to create a new Document and return a NodeList representing your converted LaTeX inputs. (Note that SnuggleTeX will wrap these Nodes within a special root Element within the Document.)

Output Configuration

You can configure exactly how this works using a DOMOutputOptions Object for DOM outputs or its subclass XMLStringOutputOptions Object for XML String outputs. These are both simple JavaBeans that let you control details such as:

  • Prefixing of XHTML, MathML (and SnuggleTeX) XML elements;
  • Whether to annotate MathML with the LaTeX input;
  • Whether and how to report any LaTeX errors discovered during processing inside the resulting XML output;
  • What to do with any URLs encountered (e.g. those specified with the \href command);
  • Whether to inline CSS using style attributes; (This can be useful if your XML is going to end up inside some kind of XML application that doesn’t support user-specified CSS stylesheets. See CSS Stylesheet Notes for more discussion of these points.)
  • Whether you want to “post-process” the newly created DOM Nodes before they get added to the final DOM tree;
  • (For XMLStringOutputOptions) How the resulting XML string should be serialized, such as control over indentation, encoding, XML declaration, DOCTYPE delcaration and whether to use named entities instead of numeric character references. (Note that you will need an XSLT 2.0 processor, such as the version of Saxon 9.1 bundled with the full SnuggleTeX distribution, if you want to output named entities.)

Have a look at the API documentation for DOMOutputOptions and XMLStringOutputOptions for more information.