Seamlessly switching between different context versions

Posted on April 11, 2019

Recently, Hans announced the prerelease of a new version of ConTeXt called LuaMetapostTeX or LMTX for short. LMTX is supposed to a streamlined and stripped down version of LuaTeX where most of the backend code for writing PDF and images has been removed from the engine and is handled by macro package using Lua code. Some of the rationale for the change in discussed in this post and more details including the source code and documentation will be available when LMTX will be formally released in this year’s ConTeXt meeting. Currently just the binary is available for testing from Pragma Ade’s website. There is no change in user-facing code, so in principle, one can simply switch from ConTeXt MkIV to LMTX without making any change in the tex file.

In my tests so far, I could compile all my documents using LMTX without any noticeable difference. Nonetheless, I want to keep ConTeXt MkIV around for some critical projects like typesetting material for courses that I teach. In this post, I’ll explain my setup for using ConTeXt MkIV and LMTX in parallel.

ConTeXt standalone distribution is a portable distribution (i.e., it can be “installed” in any directory) that works by $PATH munging. In particular, if the installation has been downloaded in say <install-dir>, then all one needs to do (on linux) is set the $PATH variable to


Then simply call context filename to compile a file, and ConTeXt figures out the location of rest of the $TEXMF tree based on the locaiton of the luatex (or luametatex) binary. ConTeXt comes with a helper script called setuptex to help with the PATH munging. So, to use ConTeXt standalone, one simply calls

source <install-dir>/tex/setuptex

and then just call context filename. Currently LMTX does’t come with a setuptex file but it is straight forward to simply copy the setuptex file that comes with ConTeXt standalone and change the path so that it points at the LMTX bin directory.

So far so good. However, when I started using MKIV and LMTX in parallel, it was easy to forget which setuptex file I had sourced and which version of ConTeXt I was using. To avoid this confusion, I came up with the following variation of the setuptex file:

export TEXMFOS


export PATH

PS1="(ctx) $PS1"
export PS1

resettex () {
    export PATH
    unset _OLD_PATH
    export PS1
    unset _OLD_PS1
    unset -f resettex

This has the following additional features.

  1. It adds a tag (I use ctx for MKIV and lmtx for LMTX) before the terminal prompt). So, it is easy to see which which version of ConTeXt I am using.

  2. It defines a function resettex that resets the value of PATH to its original value (before setuptex was called).

Both these features are inspired by the virtualenv setup for Python.

Here is a screencast showing this feature in action.

PS: If you use Archlinux that you can install context-minimals-git and luametatex packages (which I maintain) from AUR and these packages automatically create the above setuptex file.

This entry was posted in Installation and tagged setuptex, context standalone, luametatex.