Minimal TeX Live installation for MediaWiki

From Edifying Fellowship
Jump to: navigation, search

MS: I wanted to set up this Wiki to support math rendering with the MediaWiki Math extension. That extension can operate in several different ways, but I wanted (for compatibility with my other systems) to use a TeX Live installation on the Web server. But a full installation of TeX Live requires 5.2G, and the cloud instance serving this Wiki only has a 4.0G drive, already more than three quarters full, intended to hold all of the operating system and server software. There's a larger volume for "data to be served" but I didn't want to try to shift TeX onto that with symlinks and burn 5.2G storing packages nearly all of which will never be used, just to have a few math expressions in this Wiki. I wanted a minimal TeX Live installation sufficient to support MediaWiki's math rendering, which I would hope would be much smaller. It's surprisingly hard to determine what parts of TeX Live are actually used by MediaWiki. This article is meant to note what I did for my own future reference and in case it's of use to others.

Things out of scope of this note: general system administration; anything Windows-related; general MediaWiki configuration; general TeX Live installation; MediaWiki math rendering methods other than through LaTeX and texvc; installation of OCaml and texvc. It is assumed that readers know how to install TeX Live as such and just need to know how to install a minimal configuration of TeX Live to support MediaWiki.

MediaWiki invokes texvc, which invokes the command-line "latex" program to generate a .dvi file and then renders it with dvipng. So you need TeX Live's "basic" configuration scheme for command-line LaTeX, plus the "dvipng" package which is not part of that scheme. The LaTeX packages loaded when texvc invokes LaTeX can be found by searching for "usepackage" in the file extensions/Math/math/ They are (though maybe not all used every time): ucs, inputenc, amsmath, amsfonts, color, babel, teubner, eurosym, and cancel. Most of these are automatically-included in the "basic" installation.

Switching from "full" to "basic" drops the space requirement estimate for TeX Live from 5.2G to 161M (97%), though it will increase a little bit later when we add the needed packages that are not included in the "basic" installation scheme. Of that, a significant fraction is the documentation and source files, which are not really needed in a server environment. Under O for "options" from the main screen of the TeX Live installer, turn off D "install font/macro doc tree" and S for "install font/macro source tree"; these changes save 78M and 14M respectively, bringing the installer's estimate down to 69M.

While in the "options" screen, be sure to also turn on L "create symlinks in standard directories": texvc needs to find LaTeX in the path, and it may not be easy to add TeX directories to the path seen by scripts running on the Web server, even if you think it makes sense to add application-specific directories to the system-wide path at all (I don't). You will need to create a symlink for dvipng manually after installing it.

After doing the initial menu-driven install of the basic configuration, use "tlmgr install" from the command line to install dvipng, ucs, teubner, eurosym, and cancel. The "cancel" package is especially important because it is used unconditionally, and its absence will produce an unhelpful message implying there may be a configuration problem with Ghostcript, when Ghostscript is not even used in a texvc/dvipng configuration! The other packages used by texvc should have come automatically with the TeX Live "basic" configuration. Then create the manual symlink from dvipng to a directory in the path with a command like "ln -s /usr/local/texlive/2017/bin/x86_64-linux/dvipng /usr/local/bin/".

Total real disk space consumption from this installation (as measured on my server by comparing before-and-after free space) seems to be almost exactly 100M. That's significantly more than the sum of the size estimates from the TeX Live installer (roughly 70M). I think maybe the installer doesn't count the space consumed by the "formats," which are precompiled images of the TeX engine after loading core macros. It is probably not safe to try to do without those; I think in the best case, TeX would be doing a lot of extra work to recompile all its core macros on every invocation.

Note that the installation will probably grow a little beyond this size with use as it lazily generates and caches bitmap fonts.

Sample math expression:

 \int u \, \mathrm{d}v = uv - \int v \, \mathrm du

\sin \phi = 5\cos \theta