[Tex/LaTex] Why does kpsewhich fail to find this file


I'm trying to compile a file with context, and I get an error:

I couldn't open style file cont-no.bst
---line 2 of file dissertation.aux
 : \bibstyle{cont-no
 :                  }

I thought I would debug this by trying to figure out where kpsewhich seeks this file, but it wasn't found:

$ kpsewhich cont-no.bst

So I tried to use the --debug switch to find out what's going on, and to my surprise I find that it is searching all the listings it should be searching:

$ kpsewhich --debug=2 cont-no.bst
kdebug:/nix/store/msb4kcxagy3xkqx02wl25qdid1qgpnww-TeXLive-linkdir/texmf-config/ls-R: 10799 entries in 10172 directories (0 hidden).
kdebug:ls-R hash table:32003 buckets, 3564 nonempty (11%); 10799 entries, average chain 3.0.
kdebug:/nix/store/msb4kcxagy3xkqx02wl25qdid1qgpnww-TeXLive-linkdir/texmf-var/ls-R: 80 entries in 13 directories (0 hidden).
kdebug:ls-R hash table:32003 buckets, 3564 nonempty (11%); 10879 entries, average chain 3.1.
kdebug:/nix/store/msb4kcxagy3xkqx02wl25qdid1qgpnww-TeXLive-linkdir/texmf-dist/ls-R: 135626 entries in 9902 directories (0 hidden).
kdebug:ls-R hash table:32003 buckets, 30360 nonempty (94%); 146505 entries, average chain 4.8.

texmf-dist/ls-R indeed lists the necessary file:

$ cat /nix/store/msb4kcxagy3xkqx02wl25qdid1qgpnww-TeXLive-linkdir/texmf-dist/ls-R

which exists:

$ ls /nix/store/msb4kcxagy3xkqx02wl25qdid1qgpnww-TeXLive-linkdir/texmf-dist/texmf-dist/bibtex/bst/context/cont-no.bst

So my question is, why doesn't kpsewhich return the path to this file? As far as I can see, it should have all the information it needs.

Best Answer

The file is included under texmf-dist/texmf-dist/.. but kpsewhich is searching under texmf-dist/ and the relevant ls-R is in texmf-dist/. So the file is not found because the file is one directory layer deeper than normal, but your TeX Live is not configured accordingly.

Note that the hierarchical structure of the file system matters. It is not sufficient that a file's location be correctly listed in the relevant ls-R. Rather, the file must be located on a path which is appropriate to its file type.

By way of illustration, consider this example:

kpsewhich -show-path=bst

On my system, this returns


These directories are searched in order. If preceded by !!, then the relevant ls-R will be used and the search will not examine the contents of the actual directory on disk. Otherwise, the search will examine everything under the relevant directory.

What this means is that a .bst file will not be found if it is located under, say, /usr/local/texlive/2015/texmf-dist/tex/latex/<some package>/ even if the location of the file is included correctly in the ls-R /usr/local/texlive/2015/texmf-dist/ls-R. Likewise, it will not be found under /usr/local/texlive/2015/texmf-dist/texmf-dist/bibtex/bst/ even if it is included in /usr/local/texlive/2015/texmf-dist/ls-R.

The best solution, I think, will involve eliminating the additional layer so that you return to a TDS compliant configuration.

Related Question