Monday 17 December 2007

Installing LaTeX packages

This post is going to change a lot as I try this new feat. I'm writing as I go, and this may not even work. Worse, I might break my current LaTeX distribution. Wish me luck.

I'm using several very helpful pages. One is the readme file for the package I'm installing, and the other is here.

I download the package I want: it happens to be REVTeX4. It's saved as revtex4.tar.gz somewhere temporary. My path $TEXMFLOCAL happens to correspond to /usr/local/share/texmf. This is where all my updates will be stored- in a nice local file, so I can find them again. In this path, I created some handy directories...
mkdir /usr/local/share/texmf/tex
mkdir /usr/local/share/texmf/tex/latex

I changed directories here:
cd /usr/local/share/texmf/tex/latex
next moved the tar file into this location...
cp /temporarylocation/revtex4.tar.gz .
the full-stop is not a typo. I un-tarred it like so:
tar -zxvf revtex4.tar.gz
I had to be acting as a superuser, of course, to wield such fantastic powers. I now have a lovely directory named revtex4. The readme suggests I put the *.bst files in $TEXMFLOCAL/bibtex/bst/revtex4, so I do the following:
cd /usr/local/share/texmf/
mkdir bibtex
mkdir bibtex/bst
mkdir bibtex/bst/revtex4
cd bibtext/bst/revtex4
cp /usr/local/share/texmf/tex/latex/revtex4/*.bst .
I think I shall also delete them from their current home in /tex/latex/revtex4 for good measure. It is now time to instruct my TeX system where to find it all. I altered a cunning file:
kwrite /usr/share/texmf/web2c/texmf.cnf
From here on, I (almost) quote verbatim from this page.

I had already defined a directory for local material, and stuck everything there. This was /usr/local/share/texmf.

If your configuration file has a line that says something like:
TEXMFLOCAL=$SELFAUTOPARENT/share/texmf
...then you are fine; leave it alone. Some older distributions instead have a line like
TEXMFLOCAL=/usr/local/share/texmf
...commented out (it starts with a percent sign). If yours is commented out, then below it put the non-commented $SELFAUTOPARENT line (and date the change in the file; sometimes that's helpful).
Mine had the "older distribution" option, but it wasn't commented out, so I left it as it was.

Turn on searching of that local directory. A bit further down I found this line
TEXMF = {$HOMETEXMF,!!$TEXMFLOCAL,!!$TEXMFMAIN}
I commented this line out by prefixing a percent sign to the line. Below it I added a new line:
TEXMF={$HOMETEXMF,$TEXMFLOCAL,!!$TEXMFMAIN}
...in which I've deleted the twin exclamation points. The twin exclamation points tell the system that if it does not find a file in the main tree's ls-R database then it should not go on to search the disk. That's OK because your main tree will never change since you will put new things into the local tree. So the rehashing done [later] will be up to date forever. (Older versions have a TEXMF=!!$TEXMFMAIN line which you can comment out and replace with what's above.)


The page also offers wisdom on what I'm actually doing. The re-hashing I do at the end.

Your TeX system can precompute the position of [certain] files so that, instead of scanning the directory tree on your physical disk, your system finds where a file is in a database file called 'ls-R', which lists that directory tree. Then your TeX goes straight to that spot in the directory structure on the disk to get the file's contents. (The software libraries that do this work are called `kpath'.) Point One: If you make any changes to a precomputed portion of your setup then you must rebuild (or `rehash') the database of files, or your changes won't be found.

I continue:

Insure that searching of that local directory is done on disk. For certain kinds of files (such as .vf files), if the system finds a filename database in the directory tree then it will look for that file only in the database -- it will not go on to search the disk (whether there are twin exclamation points or not). Thus, for those files, forgetting to rehash results in your system saying that it cannot find files that you know are in the right place. To avoid that puzzlement, we will omit creation of that database for the local tree... I found this line
TEXMFDBS=$TEXMF;$VARTEXFONTS
...commented it out with a percent sign, and added this just below it:
TEXMFDBS=$TEXMFMAIN;$VARTEXFONTS
The version with TEXMF would have caused TEXMFDBS to expand to include the local tree, but now with TEXMFMAIN it will only include the distribution's tree.

And now for the hashing of the database:

Run the command to remake the ls-R filename database. I first checked that there was no ls-R file in the local directory /usr/local/share/texmf and then I did this.
texhash
The system responded by telling me that it had made /usr/share/texmf/ls-R (and also a /var/lib/texmf/ls-R file that has to do with user-created fonts that I will not discuss). The main point is that the system did not make /usr/local/share/texmf/ls-R. Consequently, searches of the local material will be made on disk.

Et voila. Thank you, oh great author of handy page (and sorry for stealing your text- I reproduce it here in case it disappears, or I can't find it again!)

LATER: Ok, this appears to have broken my LaTeX as predicted. I'm having problems with finding Metafont. Will sort this out and post in a later post about it, if I can fix it.

No comments: