I want to use my own .sty and .cls file in a project. I know of the following two possibilities of placing them:

  • in my local tex tree (or the general tex tree, which is worse)

  • in the same directory as the .tex file

Both of these I find unsatisfactory for the following reasons:

The local tex tree is unsatisfactory since the .sty file is specific for the project, so I want it to be close to the project, so I easily remember where it is etc. Also, I am using dropbox to synchronize the project files between different computers automatically, so the .sty file should be in the dropbox folder.

The 'same directory' is unsatisfactory since the project is in a directory with many subdirectories. The .tex files in all these subdirectories should be able to access the same .sty file.

What I would like to do is: create a subdirectory 'style files' in the project directory, where I put style and class files (there are several for the project), then tell tex somehow where to find them.

How can I do this?

I am using a recent TexLive on Mac OS X.6

I know there have been questions about placement of .sty files, but I did not find an answer to this question.


6 Answers 6


there is a third possibility and for projects the best one: put all in a texmf directory which is located inside your documents directory. Then do a export TEXMFHOME=texmf before running pdflatex or something else and the texmf tree will be searched first.

Inside this local texmf you must have the same TeX Directory Structure as usual: http://tug.org/tds For a local texmf tree you do not need to run texhash because files are searched recursively in that tree

  • This helped me. I now place copies of some LaTeX class files in a texmf/tex/latex local subdirectory of a document project, and then use env TEXMFHOME=texmf pdflatex ... to run pdflatex and produce the document.
    – mhucka
    Sep 14, 2017 at 19:38
  • Is there any possibility to set this texmfhome variable inside the latex document so that latex knows it, while it is independent of the executing shell? In my case I'm collaborating with other people on the same latex project, while it would be hard to convince/teach all of them to set an environment variable first. Sep 30, 2017 at 13:43
  • In general yes, but then you have to run LaTeX with --shell-escape which not all users like. It is a kind of risk. It makes more sense to create a shell script / batch file which first set TEXMFHOME=texmf
    – user2478
    Oct 1, 2017 at 7:59

Modern file systems know symbolic links. So you may have the class and package files at a subfolder of your project and link this subfolder to a tex/latex/ subfolder at the local (or private) TEXMF tree. With such a symbolic link you needn't change any configurations or environment variables.

  • 1
    Thanks. Using symbolic links like that seems the best solution to me. However, it doesn't work. I get a 'Missing \begin{document}' error message where tex starts to read the .sty file. I put a link to the actual style file inside $HOME/Library/texmf/tex/latex. How can I make it work?
    – Daniel
    Nov 13, 2011 at 20:01
  • If files at $HOME/Library/texmf/tex/latex work, symbolic links should also. Note: You should use subdirectories at $HOME/Library/texmf/tex/latex, e.g. $HOME/Library/texmf/tex/latex/myproject/myclass.cls. Using files like $HOME/Library/texmf/tex/latex/myclass.cls is not recommended (but should nevertheless work). Does kpsewhich -var-value=TEXMFHOME list $HOME/Library/texmf/tex/latex? Does kpsewhich <yourfile> find the file`? Nov 14, 2011 at 6:51
  • 1
    Thanks again, Schweinebacke. If I put the .cls or .sty file at $HOME/Library/texmf/tex/latex , it works. Also, if I put the .cls file somewhere else and a link into $HOME/Library/texmf/tex/latex then it's ok. However, if I put the .sty file somewhere else and a link in $HOME/Library/texmf/tex/latex , then latex says: Invalid character book^^@^^@^ etc., so apparently it cannot deal with the link correctly. kpsewhich does find the files. Any ideas? Merry Christmas!
    – Daniel
    Dec 24, 2011 at 10:56

At the top level of the TeX Live distribution there is a texmf.cnf file that you can edit, if you don't want to set environment variables; the usual value for TEXMFHOME is, with an vanilla TeX Live

TEXMFHOME = ~/texmf

which stands for a texmf folder in your home. With the MacTeX installed TeX Live it is

TEXMFHOME = ~/Library/texmf

This kpathsea variable can be set to whatever you prefer:

TEXMFHOME = {~/Library/texmf,/Volumes/Dropbox/texmf}

would make TeX programs search also the texmf folder (which should be organized as a TeX tree) in the disk called Dropbox. You should know the precise path to give. Assuming this, you can put your classes and packages inside


(choose a better name) and all users that modify accordingly the texmf.cnf file on their machines will be able to access the tree.

Launching TeX programs as, say,

TEXMFHOME=:/Volumes/Dropbox/texmf// pdflatex filename

would be equivalent (notice the initial colon that means "append" the new tree after the value stated in texmf.cnf and the trailing // to mean "search recursively). Such a setting of TEXMFHOME can be of course stated in the overall environment. The texmf.cnf way is safer, as it doesn't depend on shell setup; the extra tree will be ignored if not found on the system.

  • Should I be concerned that TEXMFHOME=:/foo// kpsewhich --var-value=TEXMFHOME yields just ':/foo//', without the normal value of TEXMFHOME? That is, does the leading colon still (this answer is six years old) cause the path in the environment to be appended to the normal value from texmf.cnf? MacTeX 2016 here. Thanks!
    – dsedivec
    May 4, 2017 at 18:00

I would organize the project like this:


And then I would register /project/texmf as a new local texmf tree.

In miktex registering such a new root can be done either with miktex-settings or on the command line with initexmf --register-root=path\to\project\texmf.

In TeXLive you could e.g. add it to the TEXMFLOCAL variable in your texmf.cnf.


Yes, ~/texmf is a convinient solution for me after a deep searching of this topic. Here is my solution to use a single copy of preamble file, templates, and bib files:


  • broken link....
    – cronburg
    Feb 11, 2016 at 18:18

Probably the easiest trick to do is to create aliases of every .sty and .cls file (located in your 'style files' directory) and put them wherever you need them. This is not (only) for saving space, but for unity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.