[Tex/LaTex] Embedding LaTeX for PDF generation

embeddingpdf

I'd like to use LaTeX as an document generation backend in my application (mainly because it is well known, feature rich and output is of very high quality). Let's assume the application creates a small set of documents with content generated (or calculated) from user input.

Of course, I could require a working installation of TeX with the (relatively small) set of used packages on the installation target. Another option would be providing this during the installation process of the application itself. This would allow for feeding the generated LaTeX source to the latex command.

This adds a large and perhaps unstable dependency to the (comparatively) small application. As TeX installations can easily exceed several hundred MB in size, I'd rather not like to bother users with this.

What I'm looking for is a way of embedding LaTeX in my application, specifically tailored to the used document class and packages in the generated documents, ideally without the need to kpathsea the required files.

I assume this has been done before, but I haven't managed to find any traces of this.

Best Answer

This is fairly straight-forward:

  • get a minimal (La)TeX distribution such as w32tex (if the license will allow it) or kergis (which should be okay anywhere since it's MIT licensed) http://www.kergis.com/en/kertex.html
  • TeX a sample document which includes every element you plan to support
  • use a utility like http://ctan.org/pkg/snapshot to get a list of the files needed
  • put all of the files in a directory w/in your application and set the TeX binary to look file files there first