Before we start I want to make clear by “your own local repository” I am not suggesting installing all packages manually. That would make things harder, not easier! Instead I am suggesting a local repository for your own files. Do you have a .bib file you use for most of your work? A version you are forever copying into new folders and modifying (or perhaps it is output from a reference manager such as Mendeley). Not to mention custom .bib and .cls files provided by journals, and other .sty files which are not packaged and available via MiKTeX or TeXlive.
The bad way to handle this is to keep copying these files to new folders each time you need them. The difficult method is to start modifying the folders maintained by TeXlive and MiKTeX. The best method is to make a folder for these files on your computer and tell TeXlive or MiKTeX to always check this folder. This way you can put it in a Dropbox folder (or other cloud synchronised folder) and have these files update on any machine you use.
So how do we do this? First we need to make a directory, called whatever you want, I will call this ‘MyTeX’. In side this we need a specific file structure. Make the following directories:
Now put any .bib files in the MyTeX/bibtex/bib directory, any .bst files in the MyTeX/bibtex/bst directory, and any .sty or .cls files in MyTeX/tex/latex (For packages which have a whole directory of files you can just copy the directory into MyTeX/tex/latex).
Now we have our local repository we need to tell LaTeX about it. This needs to be done differently in Windows and Linux
It is very easy to do this in Windows with MiKTeX. Simply go Start -> All Programs -> MiKTeX -> Maintainance (Admin) -> Settings (Admin). Which brings up this window (switch to the Roots tab):
Click “Add…” and navigate to the MyTeX folder (or whatever you called it) and add it. It should now be listed in that big white box. Switch to the General tab:
And here we want to refresh the file name database (I think that is what it stands for), so we click “Refresh FNDB”. Once that is finished click OK.
That was it! You can check by putting a .bib in the bib directory (or a .bst in the bst directory, or a .sty in the latex directory) and check that when you run LaTeX in a nother directory it can find them.
I have to say that while in I think Linux is much better than Windows on most things. I am surprised to have to say that its support for TeX repositories (at least on Ubuntu) is shockingly bad. On an operating system where from command line you can automatically install and update most software it is a bit pathetic that the version of TeXlive available on Ubuntu does not have the ability to install missing packages on the fly (especially when Windows can). Doing a TeXlive full install get’s around this, but I don’t see why I should need to waste so much space on packages I don’t need just so I have access to ones which I do which aren’t in the basic TeXlive.
I am sorry also to say that setting up your own TeX repository is also a lot less hassle on Windows. But once it is done there is no more hassle. So rant over, let’s do this!
- First we need to locate some TeX config files. Open the terminal and run:
to locate the texmf config file. Open this in gedit (no need to open with sudo) by running:
gedit %FILENAME% &
(the & is optional but it stops the terminal waiting for gedit to close)
- The file ask you not to edit it. But tells you the directory where it is generated from.
go to this directory by running:
- Let’s look at the files in the directory by running:
- You could edit one of these files or (should end with .cnf), but let’s create our own with the touch command. I think (but I am not sure) they are included alphabetically and I have had some problems using an arbitrary name, so I find it is best to put it first by having a file name which begins with 00. For example: 00JulianRepos.cnf
So you should run:
sudo touch %name_you_chose%.cnf
Then run (to edit file):
gksu gedit %name_you_chose%.cnf
gksu is like sudo but has a GUI window asking for permission before the program opens and it sets the permissions correctly for the GUI. There is no & on the line so we can’t accidentally forget to save and close the file.
- Add the following line to the file:
- Save file and exit gedit.
- We now need to update texmf.cnf by running:
- Now we update the LaTeX’s map of where things are by running:
- Now let’s check it worked. Run:
kpsepath tex | tr : '\n'
You should see a list of directories. Your local repository followed by: /tex///
should be in this list. This means it is checking the tex folder of your archive
and all its subdirectories for tex files (and .sty and .cls files)
- As a final check we can look for a file in the repository. Pick a file which is in one of the sub folders of the repository and add the filename (with no extension) into the following command:
If everything is working it should give you the full path to that file when you run the command.
That was it! You are now done.