Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers

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

share|improve this answer
add comment

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.

share|improve this answer
    
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 '11 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`? –  Schweinebacke Nov 14 '11 at 6:51
    
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 '11 at 10:56
add comment

I would organize the project like this:

/project/files/....
        /texmf/tex/latex/myclass/... 

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.

share|improve this answer
add comment

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

/Volumes/Dropbox/texmf/tex/latex/myproject

(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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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