Tiny TeX Distribution Based on Web2C and LuaTeX

An Attempt on Minifying TeX

Published on 20 December 2024 by Jing Huang.

1. Why Build a New TeX Distribution

Finally I decided to build my own TeX distribution1, as the current TeXLive (even the minimal installation) is too bloated for me. All I need is a basic TeX compiler and a compact directory containing the files TeX reads in. I use Type1 fonts, but I certainly don’t need a command line tool to generate font maps for me. ls-R database is unnecessary unless there are many files under the directory Kpathsea searches2. Strictly speaking, I also don’t need LaTeX2e.

2. My Choice

I chose LuaTeX as the TeX engine. While it doesn’t come with many fancy features out of the box, its functionality can be greatly extended using the embedded Lua scripting language. As the successor to Omega/Aleph, LuaTeX greatly enhances vanilla TeX’s multilingual typesetting capabilities. A build-in graphic library mplib is included, which eliminates the need for TikZ and such.

The default format is plainTeX, which I found much easier to work with compared to LaTeX2e. It does not involve many high-level abstractions (i.e., NFSS2 for font selection), making it more straightforward. It also doesn’t attempt to separate format and content, which is really useless when doing non-trivial typesetting. There are some drawbacks though, such as a less active community.

3. Construction

3.1. Web2C (Kpathsea)

The main focus here is on optimizing compile-time and runtime path configuration. This is where I modified the standard TDS. In addition to optimizing file scanning, I removed support for engines other than LuaTeX and eliminated support for most helper scripts.

3.2. Engine (LuaTeX)

Nothing special here. I simply compiled LuaTeX inside TeXLive’s source tree (and its banner remains) with HarfBuzz. I had tried embedding LuaJIT, but seems like it is incompatible with so many Lua-based macro-packages (like luaotfload).

3.3. Fonts and Format

The basic installation includes only the Type1 and TFM for Computer Modern and all fonts included in the AMSFonts bundle. You can use them with the good old ways. In further versions, the Concrete Math font might be included.

To use OpenType or TrueType fonts, you will need luaotfload, a font loader adapted from ConTeXt for plainTeX. This is bundled in the dist.tar.gz which is released with aplTeX.

The default format is plainTeX, which has been patched in a way to utilize the extensions of eTeX, pdfTeX, and LuaTeX. It is also Unicode-aware. Additionally, I’ve added an \everyjob hook so that LuaTeX will read luatex.map3.

4. Dist Release

The poor man’s version doesn’t come with any macro-packages — only plainTeX. I believe external macro-packages are generally unnecessary for plainTeX, except in a few cases.

For these rare cases, I’ve packaged a few macro-packages. These are mainly for demonstration purposes (showing how the modified TDS works), and to handle some of the complex dependencies (many of which weren’t even documented). The packaged ones include: