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?

TRiG
  • 213
  • 1
  • 12
  • I need new tags. Current one ([tag: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
  • I guess that task of learning enough TeXML for a template will be much easier than task of configuration of TeXML suppor in TeX to XML convertors. – michal.h21 Aug 23 '17 at 19:18
  • 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
  • Since you mention PHP, I assume that you are using a web interface. I wonder if programmatic conversion to PDF is really necessary, or if you could get away with putting out HTML and printer-friendly style sheets. If PDF is deemed necessary, maybe have a look at reportlab (a Python library for programmatic PDF generation). – Michael Palmer Aug 23 '17 at 19:30
  • 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 06: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
  • @MichaelPalmer. I've been working on other things in the interim, but hope to get back to this soon. I think I'll do what other comments suggest, and just learn TeXML. There will then be two compilation steps: TeXML to LaTeX, and LaTeX to PDF. – TRiG Sep 14 '17 at 14:10
  • (Tried to edit my previous comment but was too late ...) I haven't used PHP in 10 years, but it seems there are libraries to help with this. You are not limited to LaTeX as the backend - you could for example use this: https://github.com/PHPOffice/PHPWord - which would allow you to produce a variety of document formats. Regarding TeXML vs plain LaTeX: if the structure of the document is always the same, and you just have to insert a couple of strings, I would go with plain LaTeX. Otherwise, if you need more flexibility, XML might indeed be useful. – Michael Palmer Sep 14 '17 at 14:18
  • This page gives an overview of some PDF generation libraries: https://www.davidfischer.name/2015/08/generating-pdfs-with-and-without-python/ – Michael Palmer Sep 14 '17 at 14:22
  • Some interesting reading there. Thanks, @MichaelPalmer. – TRiG Sep 14 '17 at 14:27

0 Answers0