math=MathJax.Hub.getAllJax("mathid")[0];
str1=math.root.toMathML("");
str2=math.root.toMathMLquote(str1);
Here "mathid" is a CSS ID of an HTML element (like a <span>) that contains the LaTeX, and "[0]" indicates to get the first LaTeX expression inside that element. Then the toMathML("") method (yes, with an empty string for input) returns the MathML equivalent expression, as a string, and the toMathMLquote(str) method takes a MathML string and applies ampersand-escaping, so that "<" becomes "<" and so forth -- for HTML display inside a <pre> environment, this is the version you need. All of this has to happen *after* the math has been processed, so you have to use the MathJax queue, as described in the documentation page "Modifying Math on the Page" (my favorite bit of MathJax documentation), at