netlify / build-image

This is the build image used for running automated builds
MIT License
496 stars 197 forks source link

Add Tectonic (LaTeX engine, PDF typesetting) #527

Open kwshi opened 3 years ago

kwshi commented 3 years ago

Proposal

It would be nice if the Netlify build image included Tectonic. Tectonic is a modern, well-behaved implementation of the LaTeX engine, which is universally regarded as the industry standard for typesetting publication-quality PDFs. Here is an example of such a document made with Tectonic, by one of my close friends.

Motivation

I acknowledge that PDF typesetting is probably a niche interest in the CS industry world. But in the STEM-related academic world, and especially CS academia, LaTeX is probably the single most widely-used piece of software. CS academics like me like to use Git/GitHub to manage our LaTeX source code, but lack a convenient means to provide easy-to-access pre-built PDFs:

If Netlify were to support a tectonic builder, it would fit our use-case perfectly & quite easily. A sample usage flow may look like this:

  1. Make a GitHub repo containing LaTeX source files,
  2. Make a Netlify project with the build command tectonic <document>.tex & output directory / (project root). When the LaTeX source is modified & pushed, Netlify will build the PDF & host the output on somethingsomething.netlify.app/<document>.pdf.
  3. Link to the PDF URL in the GitHub README.

This is quite analogous to, e.g., a Webpack building flow generating bundled HTML/CSS/JS output from SCSS/TS source, except we are generating downloadable/viewable PDF output from LaTeX source.

Existing solutions

I am not the only one who wishes to use Netlify to build LaTeX files; many others have run into the same need & have come up with various workarounds to doing so:

All of these solutions are sort of suboptimal, as they require writing complex scripts/configurations or invoking an additional CI runner to set up correctly.

Steps

The basic installation of Tectonic is quite straightforward & documented here: install some system libraries (libfontconfig1-dev libgraphite2-dev libharfbuzz-dev libicu-dev libssl-dev zlib1g-dev), then install Tectonic via cargo install tectonic (since Cargo already exists in the build image, this is trivially possible).

In addition to installing Tectonic, one additional thing that would be helpful is to cache downloaded packages (the same way, e.g., npm dependencies are cached between successive builds). Tectonic auto-detects dependencies from the LaTeX source code & downloads them on-demand, removing the need to explicitly specify dependencies in configs/lockfiles; all that would need to be done here is to (1) copy the Tectonic cache from Netlify cache to wherever Tectonic expects it (by default, ~/.cache/Tectonic) before building, then (2) save the new Tectonic cache back into the Netlify cache after building.

Conclusion

I'm starting this discussion to see if enough other people share my wish to build PDFs via Tectonic with Netlify. Personally, I believe that it would be a huge blessing to the academic CS community if Netlify did add support for Tectonic. If others are also interested in this idea, & Netlify maintainers would also be willing to incorporate such a feature, I would be happy to work on a PR & offer my help making this possible.

cole-wilson commented 3 years ago

I would also like to see this natively added!