Programming

Using the TeX local texmf

4 min.
Status: in progress · Type: log · Importance: 3

The local texmf tree

Each TeX distribution allow the use of a local texmf tree, that is, a folder in the user hard drive where user generated TeX related files are to be put (personal packages, bibtex files,…). The main advantages of the local texmf tree are:

  • It is preserved when upgrading the TeX distribution.
  • All the files located inside (custom packages, bibtex files, images,…) are automatically available for the (La)TeX processor.

The local texmf tree have to comply with the TeX Directory Structure (TDS) hierarchy.

Finding the local texmf folder in your operating system

The location of the local texmf tree depends on the TeX distribution you have installed. The two main ones are TeXLive and MiKTeX.

In MiKTeX (Windows) the location of the texmf folder is selected using the MiKTeX configuration utility so the user can put the folder wherever they like. In TeXLive there is an environment variable named TEXMFHOME that points to the local texmf tree. If you cant to check the value of TEXMFHOME just open a terminal and type

kpsewhich -var-value=TEXMFHOME

The default value of that variable depends on the operating system:

  • On Linux: ~/texmf
  • On Mac OSX: ~/Library/texmf
  • On Windows: C:\Users\<user name>\texmf

From now on I will refer simply by texmf to the local texmf folder.

You can of course use a custom location for the local texmf folder. The only thing you need to do is to link the TEXMFHOME folder to the new location. For instance, in Mac OSX you can create the texmf directory inside Dropbox (or any other syncing utility) and link it to the system location

ln -s ~/Dropbox/texmf $(kpswhich -var-value=TEXMFHOME) 

so you can share the texmf in multiple machines. See Setting up a local texmf tree for more information.

Using the local texmf tree

In the following I will present two useful ways of using the local texmf tree:

  • To share a bibliography
  • To share images in multiples documents (institutional logos, signatures,…)

The best place for your bib files

The best way to add bibliographic references to a LaTeX document is through bibtex (or biblatex) and a bibtex file. It is usually convenient to keep a single (or a few) bibtex file (in our example we will name it library.bib) with all the references we work with. In this sense, we have three alternatives to use the file in any new project:

  1. the file has to be copied (or linked) to any new project in order to use it since (La)TeX will always look for bibtex files at the same folder where the main .tex file is located.
  2. we can specify with the \bibliography{} command the (relative or absolute) path to the bibtex file we want to add. Hence, we can keep the bibliography in a fixed place in our folder structure.
  3. using the local texmf folder: copy the bibtex file into texmf/bibtex/bib/ (in this way the hierarchy of the TDS is complied). Then, we can add the file to any .tex project by simply using \bibliography{library.bib}. We can copy as many bib files we want in the same folder and all of them will be available in our .tex files.

Save your logos for easy access

The second utility of the local texmf folder we are going to discuss is the ability to share images files. For instance, think of a institutional logo that we need to add to any official document we produced with (La)TeX. We can:

  • proceed similarly as in items 1 or 2 in the previous section (using in the latter the ability of the \includegraphics command to indicate relative or absolute path to a image file) or
  • we can copy all the image files (for instance logo.jpg) we want to share through all our .tex files in texmf/tex/images/ (to comply with the TDS hierarchy) in any format (La)TeX can process.

In the second case, we simply add \includegraphics{logo.jpg} to any (La)TeX file to get the image.

Final thoughts

The usefulness of the local texmf tree is not restricted to the two use cases we have presented here. Any kind of file, from packages to fonts, used by the (La)TeX processor can be place in the texmf folder to make it system-available.

Share this article

Cite as: Francisco Torralbo, Using the TeX local texmf [Blog post]. August 7, 2020. Retrieved from: https://www.ugr.es/~ftorralbo/blog/programming/local-texmf/.

Using the TeX local texmf by Francisco Torralbo is licensed under a Creative Commons Attribution-ShareAlike 4.0 International.