The upcoming version 0.1.6 of Tectonic has a new engine extension, \TectonicCodaTokens, that makes it possible to write LaTeX documents that contain no boilerplate initialization code. This post demonstrates the technique.
First, the motivation. It’s, uh, a little vague. You can achieve the same effects by creating wrapper files and/or using \input
commands. I can’t quite put my finger on why, but I think that the technique that I’m about to describe will open up new possibilities that would be significantly more annoying to achieve with wrapper files. I’m pretty sure that being able to process input “files” directly, without having to wrap them, and without the user needing to write the boilerplate themselves, is powerful. But I’ll confess that at this point this is more of a feeling than a concrete use case.
The basic approach is to create your own “format” file of a pre-initialized LaTeX environment. By using the \everyjob
token list, which is inserted at the beginning of every job, and the new \TectonicCodaTokens
, you can sandwich an arbitrary input file in arbitrary commands.
Here’s a minimal format template:
% note: requires Tectonic 0.1.6 or later
\let\therealdump=\dump
\let\dump=\relax
\input latex.ltx
\let\dump=\therealdump
\let\therealdump=\relax % better way to undefine \therealdump?
\documentclass{letter}
\usepackage[colorlinks, allcolors=blue]{hyperref}
% etc.
\everyjob={\begin{document}}
% could schedule late-time init with \AtBeginDocument
\TectonicCodaTokens={\end{document}}
% NB: Initialization of system fonts needs to go into \everyjob since they cannot
% be saved in format files.
\dump
If you called this file myformat.tex
, you’d process it this way to generate myformat.fmt.gz
:
tectonic --outfmt=format myformat.tex
You could then write a LaTeX file that looked exactly like this:
Hello, world! I'm a LaTeX file that has no boilerplate.
Look: $y = x^2$ and \url{https://tectonic.newton.cx/}.
And compile it thusly:
tectonic --format=myformat.fmt.gz mydemo.tex
And boom, you get a PDF!
My initial hope was that this technique would speed up compilation for large documents, but in my experience that’s actually not the case. If you had a whole lot of packages to load, maybe it would.
Again, in a certain sense this doesn’t add any new capabilities to a TeX system, but I really like the idea of being able to process boilerplate-free files that (can) look just like plain text.