TeXML is an XML serialization of LaTeX. The getfo program can convert TeXML to LaTeX. Is there any way to convert LaTeX to XML?
Unnecessarily Detailed Background
I want to programmatically generate PDF documents using user input. There are various ways I could go about this, each with various levels of pain.
Use TCPDF, a library for writing PDF directly in PHP. This is what I'm currently doing, but it's a bit of a pain and certainly doesn't produce nice looking documents.
Write TeX or LaTeX (or similar) directly from PHP. I experimented with this, but escaping all special characters looks very very tricky. I'm nervous of introducing subtle security bugs and/or creating an unmaintainable mess.
Use SILE instead of LaTeX. SILE has two formats — one similar to LaTeX, intended for handwritten documents, and one in XML, intended for programmatically generated documents. This could work, but it's harder to find help with SILE documents.
Use TeXML. If I'd known about this sooner, I probably would have skipped most of the previous steps. TeXML is an XML dialect which can represent everything in LaTeX. Any LaTeX document has an equivalent TeXML document, and vice versa. Since TeXML is XML, it is easy to generate from a PHP program. The TeXML document can then be processed by getfo to produce LaTeX, and then that document can be processed to produce PDF.
Beautiful. But does this mean that I now need to learn TeXML? It would be far simpler to handwrite a sample document in LaTeX, and then automatically convert that to TeXML, which I can then use as a template for future documents. Can getfo run backwards to convert LaTeX to TeXML?