Making LaTeX easier: Maintaining your own local repository

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

In Windows

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:
    kpsewhich texmf.cnf
    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:
    cd %path_in_file%
  • 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:
    sudo update-texmf
  • Now we update the LaTeX’s map of where things are by running:
    sudo updmap
  • 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:
    kpsewhich %FILENAME%
    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.

4 thoughts on “Making LaTeX easier: Maintaining your own local repository

  1. I just ran across this, so I haven’t had a chance to try, but putting a repository in Dropbox is exactly what I want to do. Thanks!

  2. Any chance you could write a similar guide for Mac systems? We don’t get the fancy “update-texmf” tool, and “texhash” doesn’t work. Everything else I have been able to workaround, just using sudo for gksu and emacs (or any editor) for gedit.
    And just one point of clarification, does %FULL_PATH_TO_MyTeX_DIRECTORY_YOU_MADE% explicitly include “My_TeX” at the end? In my case I’m uncertain whether /u/Dropbox/My_TeX or /u/Dropbox is the correct path.

    • Hi. I have never tried this on a mac and also don’t have a mac I could try it on. I have some idea on how to proceed.

      First point is “/u/Dropbox/My_TeX” is the correct path, not just “/u/Dropbox”.

      Second is my linux explanation should probably be edited to say, it is only for the Ubuntu and similar deb packages. The process is slightly different for plain tex live. I guess mac may work similar to plain tex live. In this case (if I remember correctly)
      kpsewhich texmf.cnf
      should return a config file which is not generated from another directory and is the actual config file to edit. You can just add the line
      directly to this file, and then move to the
      sudo update-texmf

      I would be very interested to know if this helps. Sorry about the delay for your comment to go live, I have a ratio of about 1000:1 spam to real comments, so the spam filter is pretty aggressive.

Leave a Reply

Your email address will not be published. Required fields are marked *