Want a TeX to XML or MathML converter

Is there a TeX engine that converts a TeX document to MathML or XML directly the way PDFTeX converts text input to PDF?

I am familiar with some converters that transform a subset of TeX into something that can be viewed on a browser, but they all leave out many of the packages I used, particularly `hyperref` and `xypic`. I want a converter that passes Knuth's test for genuine TeX.

-
As far as I know, it doesn't exist. tex4ht does a good job in many cases, though, with hand-written support for many packages. –  Bruno Le Floch May 24 '11 at 0:11
ConTeXt supports an xml backend (that can be used to export to xhtml or epub as well). But, I guess, that you are interested in a LaTeX to XML. –  Aditya May 24 '11 at 0:31
@Aditya: true, I keep forgetting that you ConTeXt guys are much further along on this than LaTeX. I think that SixWingedSeraph's question is about TeX itself, though. –  Bruno Le Floch May 24 '11 at 2:56
@Bruno: Although ConTeXt is able to process plain TeX input, I really doubt that it will generate any useful XML from that. To generate XML, all ConTeXt commands are use "tags" that are then translated into XML. (The standard ConTeXt command for defining new macros, `\define` and `\definestartstop` automatically insert these tags). Unless the macros used by plain TeX are redefined in terms of these tags, ConTeXt won't be able to give useful XML output. –  Aditya May 24 '11 at 4:57
I doubt very much that you will ever get a genuine TeX to XML converter because TeX can do things with its output that XML can't - in particular, it can measure the size of various bits of its output and take action accordingly. Since an XML document doesn't know how it will be rendered, this would be extremely difficult to implement. That's why the converters in existence tend to work on a subset and build outwards. –  Andrew Stacey May 24 '11 at 7:17

`tex4ht` can convert to XHTML and MathML. See my answer to this question.

-

There's plasTeX and LaTeXML, written in Python and Perl respectively.

The KWARC group are a major user of LaTeXML.

-

TeX4h. It is a part of MiKTeX bundle and, perhaps, TeX Live.

-

You could give a try to Illumino. It can manage LaTeX files and output several output formats as:

• Custom XML
• Native PDF
• PS
• Custom HTML
• others
-

I'm not sure if this TeX/LaTeX to MathML Online Translator is part of what you're looking for. It generates clunky but acceptable MathML from (La)TeX input.

-

As XML is just a syntax it is trivial to convert any LaTeX into XML just by creatimg a file of the form `<latex>...` text of latex document with `<` `&` and `>` replaced by `&lt;` `&amp;` `&gt;` `....</latex>` The result is XML but perhaps not what you meant. This isn't just a silly example though, people do such translations to store blobs of TeX in XML databases.

Another conversion to XML can be got by running `latex` to get dvi then using `dvisvgm` to convert the result to SVG. Again this is XML but perhaps not the kind of XML you intended as it is positioning every character by fixed coordinate positions. It does however cope with a very wide range of TeX inputs.

If you need a conversion to something not unlike HTML. Say, XHTML for text, MathML for maths and SVG for any vector images included, then the issues relate to the nature of the HTML format: that it is expected to reflow in the client and use reader- rather than author-specified fonts in many cases, and that the rendering environment (even with javascript enabled) isn't as tightly bound to the programming structures as happens in TeX. The fact that that system uses an XML (or HTML) syntax rather than a backslash-and-brace syntax is the least of the issues involved in a translation.

If you do want to translate to XHTML+MathML, then LaTeXML is a good place to start,

-
With Tex4ht supplied in MikTeX, you can use `mzlatex filname` (without extension) for creating the xml extension file. You can clean with some scripts according to your requirements.