21

I often have trouble remembering the name of the kpsewhich command. Maybe it would be easier for me to remember it, if I understand where the name come from, so the question is:

What does the kpse stand for?

23

Karl's Path SEarch Library WHICH

  • Thank you! This will make it much easier to remember! – muxoveji May 22 at 12:29
  • 1
    @david-carlisle what a bold answer ;-) – topskip May 23 at 13:28
18

As info kpathsea says (online manual here), Kpathsea is a library for path searching (e.g., for very quickly locating a given .sty file in a set of potentially large TEXMF trees, without doing a recursive directory tree traversal every time a given file is needed; this is important when compiling LaTeX documents using several packages, themselves requiring other packages, possibly various font files, etc.).

This path search gives the pathse part, abbreviated as pse. The “which“ reminds of the Unix which utility, which tells you the path of the executable run for a given command, according to your PATH environment variable. For instance:

$ which find
/usr/bin/find

I believe the “k” stands for “Karl Berry”. :-)

Complements

The comparison between which and kpsewhich goes further than that. As Unix shells often maintain a cache of executables present in directories of the PATH in order to offer efficient lookup for command completion, the Kpathsea library maintains a filename database (comprised of the ls-R files in each TEXMF tree) in order to offer similar fast lookup to TeX-related programs.

In Unix shells, the cache can often be updated with a hash command (hash -r in Bash, rehash in Zsh) when you've added or removed executables from your PATH and wish to refresh the cache without restarting your shell; for the Kpathsea library, the corresponding operation is done with mktexlsr, also known as texhash.

Finally, which looks up a given executable in the directories listed in PATH1, in some way similarly as kpsewhich for finding a TeX-related file using either on-disk lookup or only the filename database (it depends on whether the TEXMF tree is preceded with !! where it is used in texmf.cnf2). kpsewhich is more sophisticated than a typical which builtin, though, as it can return different results depending on what was given as -progname, has a notion of variables that can be set in texmf.cnf, can look up in-cache-only or on-disk depending on the per-directory-settings in texmf.cnf, etc.


Footnotes

  1. In Bash and Zsh at least, it seems to really search the PATH: if you add a new executable to a directory of your PATH, the which builtin of these shells finds it right away without any need to run hash -r or rehash (this may not be the case for command completion).

  2. See for instance /usr/share/texlive/texmf-dist/web2c/texmf.cnf on Debian.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.