Using TeXShop, LaTeX and ConTeXt Simultaneously

Use this folder if you have upgraded to TeX Live 2023 or MacTeX-2023. The version of ConTeXt in TeX Live 2023 and MacTeX-2023 changed considerably from past years, so new Engines are provided. The situation is still in flux as the pretest period ends, but the suggestions below should continue to hold even if there are later updates.

ConTeXt is part of TeX Live 2023. That version is updated once a year, but ConTeXt is under active development and changes more frequently. It is possible to get the latest ConTeXt by going to the ConTeXt Garden Wiki and installing the version available there. This is a small download and can be done quickly, The process is clearly described on the Wiki, and very easy. The distribution can be installed anywhere you like; a natural place is in your home directory at ~/bin/context. Then it does not interfere with TeX Live.

If you install ConTeXt this way, go to TeXShop Preferences under the "Engine" tab and change the third item at the top, which is labeled "Alternate Path", to the path for ConTeXt binaries. If the binaries were installed in ~/bin/context, this path might be ~/bin/context/tex/texmf-osx-arm64/bin.

The remaining instructions work with both the ConTeXt in TeX Live and this alternate ConTeXt installation. Move the engine file ConTeXt2023 from ~/Library/TeXShop/Engines/Inactive/ConTeXt-2023 to ~/Library/TeXShop/Engines.

At the top of each ConTeXt source file, add the magic lines

     % !TEX TS-program = ConTeXt-2023
     % !TEX useAlternatePath
     % !TEX useConTeXtSyncParser

Omit the middle line if you use the ConTeXt in TeX Live. In all cases add to the header of the ConTeXt document the command

     \setupsynctex[state=start,method=min] 

After these steps, typesetting with TeX, LaTeX, XeTeX, and other engines will work as usual, but typesetting with ConTeXt will also work as usual. The ConTeXt typesetting job will use the appropriate distribution and syncTeX will use new routines in ConTeXt rather than the usual syncTeX code. For more details on this final point, see the TeXShop changes for version 4.66,

Note: In some earlier versions of the pretest, it was necessary to run the following command just once before using ConTeXt. In case of trouble, try this fix.

    mtxrun --generate

An Alternate Engine, Just In Case

Until March 12, 2023, ConTeXt had problems with paths which contain symbolic links. These problems are now fixed, but this section is provided in case these problems resurface. In that case, use the alternate engine ConTeXt2023-Temp.

The problems occurred because the standard path /Library/TeX/texbin used by MacTeX is a symbolic link. There was no problem calling a binary from such a path, but ConTeXt analyzed this path to find other directories in TeX Live. There is a programming routine a program can use to find the call which started it running. Thus if I type /Users/koch/usr/local/texlive/2023/bin/universal-darwin/luametatex, then luametatex can go up a level and find universal-darwin, or up two levels and find bin, or up three levels and find 2023. From there, it can find 2023/texmf-dist. But if this same program is called using /Library/TeX/texbin/luametatex, then going up a level gives texbin, two levels gives TeX, and three levels gives /Library, and there is no /Library/texmf-dist.

On March 12 this problem was fixed in ConTeXt. Until then, we provided the engine ConTeXt2023-Temp, included here. In Monterey and Ventura there is a shell command named "readlink" which understands a flag "-f", and the following command reads a path which may contain symbolic links and outputs a similar path without any such links:

     readlink -f path

When TeXShop calls an engine, it provides the path used by the call in $3. So ConTeXt-2023-Temp calls "readlink -f $3" to find the full path, and calls context using this full path.

If you use an earlier version of macOS, either you have no readlink or else your readlink does not understand this flag. The solution is to add a full path to your binaries to the start of your PATH before calling context. This can be hard coded into the engine. The disadvantage is that in a future year the engine must be changed.

Using TeXShop, LaTeX, and ConTeXt with an External Editor.

These ConTeXt changes also work with an external editor, but the configuration steps are a little more difficult. These steps are clearly described in the Changes document for TeXShop 4.66 available in the TeXShop Help menu, so read that document for details.

Richard Koch
2740 Washington St
Eugene, Oregon 97405