TeX Live relies on the kpse
library and MacTeX is based on TeX Live.
Basically, all TeX related programs are linked to the library, whose primary job is to set up several environment variables starting from the location the program sits in.
So, for example, if you run pdflatex
and the binary resides in /usr/local/texlive/2018/bin/x86_64-darwin/
(usually the location is determined via a soft link), the main variables that are set are (from texmf.cnf
% SELFAUTOLOC (directory of the binary=/usr/local/texlive/YYYY/bin/i386-linux),
% SELFAUTODIR (its parent = /usr/local/texlive/YYYY/bin),
% SELFAUTOPARENT (its grandparent = /usr/local/texlive/YYYY), and
% SELFAUTOGRANDPARENT (its great-grandparent = /usr/local/texlive).
These four variables are set based on the location of the binary and used for locating the relevant texmf.cnf
files (see the documentation of the library, texdoc kpathsea
) which will set all the other necessary variables.
A program for querying the setup is kpsewhich
; among other options, it can report the value of environment variables, including those that are set at program launch by kpse
; so
kpsewhich -var-value=SELFAUTOPARENT
will return, on my machine,
/usr/local/texlive/2018
from which you can easily extract the year, if needed.
Just for information, when I want to test a document with different versions of TeX Live, instead of changing the distribution via the panel I just directly call the binary:
/usr/local/texlive/2017/bin/x86_64-darwin pdflatex
because the SELFAUTOLOC
feature will set the environment to what results from reading the texmf.cnf
files from the 2017 distribution.
kpsewhich -var-value=SELFAUTOPARENT
returns/usr/local/texlive/2018
(or whatever year the installed distribution refers to).kpsewhich
uses the system one.env SELFAUTOPARENT='/usr/local/texlive/2017' kpsewhich -var-value=SELFAUTOPARENT
, the terminal returns/usr/local/texlive/2018
. Differently from otherkpse
variables, theSELF...
ones are not looked at when program linked tolibkpse
are launched.