[Tex/LaTex] Mac – styles apparently not installed, yet working

natbib

New to LaTeX, running Mountain Lion on Mac. I have seen plenty of posts which all suggest that to use packages, they should be included in the ~/Library/texmf/tex/latex/ folder, such as on this question: Installing new style packages on a Mac

However, I have been using various packages and they've been working fine, such as natbib and the apalike style, even though I didn't have a texmf folder until just a moment ago when I created it. My bibliography was working, but as far as I can tell, I didn't have the apalike style on my Mac anywhere (including hidden files), so it shouldn't have been?

Firstly, how can LaTeX use natbib's apalike style if, apparently, it's not on my Mac?

Secondly, how can I go about locating, and editing, whichever apalike style I'm actually using?

I'm struggling a little with some of the logic around LaTeX, like its use of a style file which is apparently not on my Mac.

Edit: The reason this is bugging me is because I'd actually like to edit the apalike style, but all of the instructional guides I can find talk about editing the existing file (which also makes more sense than a newbie like me trying to write it from scratch).

Best Answer

TeX Live (including MacTeX) uses several distinct hierarchies of files ('texmf trees'). The contents of the trees is managed and searched differently.

Although this can be customised differently, the chances are that you are using the default. In that case, the main 3 trees you have to think about will be the following.

  • The main distribution tree installed and updated by MacTeX/TeX Live Utility, usually at /usr/local/texlive/YYYY/texmf-dist/ where YYYY is the year of the version of TeX Live you are using e.g. 2015.

    • You should not alter the contents of the files in this tree. Nor should you add or remove files manually.
    • The tree is managed by the tools provided to administer your installation of TeX. (TeX Live Utility or tlmgr etc.)
  • The local tree which contains files installed locally and available to all users of the system, usually at /usr/local/texlive/texmf-local/.

    • This is probably best used for packages you download because TeX Live doesn't provide them, especially if you want them to be available for a while and generally or don't want to accidentally edit them, for example.
    • When you install packages here, you need to update the file name database so that TeX can find them.
  • Your personal tree which contains files you install or write for your personal use, at ~/Library/texmf/ in your case.

    • This is best used for cases where you make a renamed copy of a file to edit it or create your own files.
    • The exception would be if you install a font package, when it would be better to use the local tree even for your own idiosyncratic creations. However, you don't need to worry about this if you are new to LaTeX because the creation of custom font packages is not something you are likely to tackle any time soon ;).

The styles you have been using are not in your personal tree because they are supplied by your TeX distribution and installed into the main, distribution tree.

To discover the location of a file or to determine which file TeX is using:

kpsewhich <filename>.<extension>

For example, on my system

kpsewhich apalike.bst

returns

/usr/local/texlive/2015/texmf-dist/bibtex/bst/base/apalike.bst

which shows the file is in the main, distribution tree, whereas

kpsewhich splncs03.bst 

returns

/home/<username>/texmf/bibtex/bst/journals/llncs2e/splncs03.bst

where <username> is my user name, which shows that the file is in my personal tree.

To discover the location of a tree, you can ask kpsewhich for the value of the relevant variable.

For example,

kpsewhich -var TEXMFDIST ; kpsewhich -var TEXMFLOCAL ; kpsewhich -var TEXMFHOME  

returns

/usr/local/texlive/2015/texmf-dist
/usr/local/texlive/texmf-local
/home/<username>/texmf

on my system. On yours, the final result will presumably give something equivalent to ~/Library/texmf.