2

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?

  • I need new tags. Current one (latexml) seems to be a different program altogether, but I have no idea what I should change it to. – TRiG Aug 23 '17 at 18:39
  • How complex is the user input? Is generating markdown and piping it through pandoc an option? Also learning TeXML isn't that hard . . . – DG' Aug 23 '17 at 18:58
  • 2
    Another option is to use ConTeXt to process XML. ConTeXt has a really good support for XML: see the manual, an example with TEI documents and details about processing the XML tree in lua – Aditya Aug 23 '17 at 19:23
  • 1
    I think texml is essentially unused, it really didn't help much with the use case you describe. Just write out the latex directly. – David Carlisle Aug 24 '17 at 6:34
  • 1
    @MichaelPalmer. It is a web interface, yes, but these PDF documents are being attached to emails, not rendered to the browser. – TRiG Sep 14 '17 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.