POSTS
Lighter TeX Runs Faster
Summary
This post is making TeX working better on the cloud. It does this by making a custom TeX Live that contains only the resource your document needs. It's preparation for the TeX Hour tomorrow (Thursday 25 March). There's a proof-of-concept at the URLs at the foot of this page.
In case you didn't know, every Thursday (18:30 to 19:30 UK time) there's a zoom TeX Hour. The zoom URL and other details are here.
Introduction
Github provides free continuous integration (CI). This means for example that tests are run whenever there's a commit. And it doesn't have to be tests. We could run LaTeX whenever one of our source files is changed. This tests run quicker when we they install only the necessary resouces. Before about 2 minutes. After about 20 seconds. This is satisfactory for occasional use and, but construction, is fully integrated into Github. I expect the same to be true for Gitlab.
An example
The source file for Don Knuth's The TeXbook is, roughly, 20,000 lines occupying 1.4 MB. A TeX-Live distribution when installed occupies several gigabytes. In other words, perhaps 3,000 times the size. Most of this mass of files is not needed to typeset The TeXbook.
I've developed a semi-automated method that discovers exactly which
files are needed to typeset a TeX or LaTeX document. Chapter 6 of The
TeXbook uses a short file story.tex
as an example. Here it is.
\hrule
\vskip 1in
\centerline{\bf A SHORT STORY}
\vskip 6pt
\centerline{\sl by A. U. Thor} % !`?`?! (modified)
\vskip .5cm
Once upon a time, in a distant
galaxy called \"O\"o\c c,
there lived a computer
named R.~J. Drofnats.
Mr.~Drofnats---or ``R. J.,'' as
he preferred to be called---% error has been fixed!
was happiest when he was at work
typesetting beautiful documents.
\vskip 1in
\hrule
\vfill\eject
To typeset this file to PDF requires 5 additional files, that occupy about 6MB in total. (When compressed, they're less than 2.5MB.)
# bytes name
34811 cmbx10.pfb
35752 cmr10.pfb
35022 cmsl10.pfb
2219712 pdftex
3899591 pdftex.fmt
A comparison
First before. We use this LaTeX file
\documentclass{article}
\begin{document}
Hello world.
\end{document}
Running the typesetting this document takes over 2 minutes. For evidence see the actions record page.
Now after. Running the typesetting story.tex
using the lighter TeX
takes about 20 seconds. For evidence see the actions record
page.
Why the difference?
For both the TeX and LaTeX examples the typesetting task is in the queue for about 15 seconds before being started. The typesetting itself takes no more than a second in both cases. The big difference is in setting up the typesetting environment. In the CI system this is done from scratch every time. That helps ensure reproducible results.
For LaTeX we used a generic install from TeX-Live. For TeX we used a custom install that provided only the 5 files listed above, together with configuration and utitity scripts. For LaTeX this took almost 2 minutes. For TeX it took no time at all.
Isn't this unfair to LaTeX?
I chose to optimise Don Knuth's story.tex
because it was small
enough to be done by hand. I then chose to semi-automate it to avoid
errors and ensure reproducibility.
Repeating this process for LaTeX might require more work on the automation tools. After that, I fully expect the LaTeX results to be within 5 seconds of the TeX results. And in both cases I expect more complex documents to add only a few seconds.
Of course, if you're typesetting a font catalog or a comprehensive symbol list then you'll have to install a lot of fonts. This might take a few seconds.
The future
To learn more go to the pages
and explore. Soon, probably tomorrow, I provide proof-of-concept instructions on how use these Social TeX repositories to typeset suitable content of your own.
Hint: Fork the repository, enable Actions in the fork, and modify the source files
- https://github.com/social-tex/explore-tex-action/blob/y2021p005/finish/story.tex
- https://github.com/social-tex/explore-latex-action/blob/main/hello.tex
but in your clone of the Social TeX repository.
When you go to your Actions tab and click on the TeX / LaTeX action in the workflows column, you'll see a Run workflow button. Press it!
Apologies
This is all proof-of-concept at present. My focus has been on understanding and solving the technical problems. So usability and documentation isn't quite there yet. A thorough reworking is needed.
Acknowledgement
Xu Cheng's https://github.com/xu-cheng/latex-action gave me a great help in getting my own work started. It provided something out of the box that worked, that I could tinker with. I'm most grateful. Altogether 68 people have forked his work.