Creating Legacy Web Pages
In some scenarios, it might not be viable to use the MathML-based web pages that SnuggleTeX generates by default. However, all is not lost! The full distribution of SnuggleTeX ships with an extension that converts MathML to images using components of the JEuclid software.
(SnuggleTeX can also attempt to convert very simple MathML expressions into XHTML+CSS using the DownConvertingPostProcessor class that you can easily attach to your WebPageOutputOptions.)
Using this extension requires a bit of programming on your part as you must decide how you are going to store and serve the resulting images along with your web pages. (You might be able to get some ideas by poking around inside the snuggletex-webapp module, which is part of the full distribution and is used to serve up these documentation pages and the various online demos.)
Getting Started with the JEuclid Extension
- In order to use the JEuclid Extension, you will have to download the full distribution of SnuggleTeX.
- You need to have snuggletex-core.jar and snuggletex-jeuclid.jar in your ClassPath, as well as jeuclid-core.jar, batik-dom.jar, batik-ext.jar, batik-util.jar, batik-xml.jar, commons-io.jar, commons-logging.jar, xml-apis.jar (not needed for Java 6 and above), xml-apis-ext.jar and xmlgraphics-commons.jar. (The JARs in the distribution ZIP file contain version numbers in their names; it should be obvious what we mean here.)
The JEuclidUtilities.createWebPageOptions() method creates a suitably configured instance of WebPageOutputOptions that will convert MathML to images (trying XHTML+CSS first if requested) and produce a legacy HTML web page as a result.
In order to make this work correctly, you need to pass this method an instance of an interface called MathMLImageSavingCallback that tells SnuggleTeX what to do with each image it creates. (There is an abstract implementation of this called SimpleMathMLImageSavingCallback that you might find a useful starting point here.)
You can then use this WebPageOutputOptions to generate SnuggleTeX web page outputs in the usual way.
Technical Implementation Notes
The resulting WebPageType in this case is actually PROCESSED_HTML, which has been configured with one or both of the following DOMPostProcessors:
- DownConvertingPostProcessor: This will optionally attempt to convert simple MathML expressions to XHTML + CSS. Expressions that are too complex are left as MathML.
- JEuclidMathMLPostProcessor: This hunts out any (remaining) MathML elements, converts them to images using JEuclid, calls back on your MathMLImageSavingCallback to let you save them or store them, and then replaces the MathML with XHTML <img/> elements that you control using your callback.