Look at the MinimalExample.java. (The source for this is available in the full SnuggleTeX distribution if you want to compile this yourself.) This demonstrates a very simple example of calling up SnuggleTeX:
/* 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);
This block of code converts the LaTeX input $$ x+2=3 $$ to a simple XML String fragment, which is printed to the standard output. For this particular input, the resulting XML fragment consists of a single MathML math element.
You can run this on the command line with:
java -classpath snuggletex-core-n.n.n.jar uk.ac.ed.ph.snuggletex.samples.MinimalExample
(This assumes that snuggletex-core-n.n.n.jar is in the current directory; you will of course need to provide a path if it is not. You should also substitute n.n.n for the actual version number attached to your SnuggleTeX JAR.)
When run, you should get an output like:
Input $$ x+2=3 $$ was converted to: <math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> <mi>x</mi><mo>+</mo><mn>2</mn><mo>=</mo><mn>3</mn></math>
(The newline before the <mi> in the sample output above has been added to prevent the text being too wide. You should find that your XML is output as a single line if you run the example yourself. Note that SnuggleTeX can also be instructed to indent the output, if asked.)
The XML fragment output in the above example is great for showing off the outputs from SnuggleTeX but is not usually much use if you want to do anything else with it. SnuggleTeX supports a number of alternative outputs that can be more useful to programmers.