I am building a document class and a set of packages to be used as templates for various documents. I'd like to aviod having to copy those over to another folder every time I use them, but I'd also like to avoid cluttering up the folder containing document classes and packages with tex files (and all the output noise...).

I tried starting a document with \documentclass{../templates/mycls}, but since mycls.cls starts with \ProvidesPackage{mycls}, I get naming problems in macros that use \@currname (for example some macros in the kvoptions package).

Is there any way I can use a document class or package from a different folder, without having to install that folder into the local TeX distribution?

Clarification: There seems to be some confusion on what I'm trying to do here. What I want to accomplish is a folder structure like the following:


The reason for this is that I want to make it very clear which files are related to templates, and which files are just documents using the template, so that when someone comes to get the templates from me, they'll know which files they need. However, with the folder structure above none of the documents in the /documents/ folder can be compiled without copying the template files into /documents/. I don't want duplicate files.

I am not interested in how to install packages under various TeX distributions (I'm working on MiKTeX, and I know how to do that here...) - I just want to make it as easy as possible for people to find the template files.

  • 3
    What operating system? With TeX-Live on Linux, you should be able to do what you want by setting the TEXINPUTS environmental variable. I am not sure how this would work on the various Windows/Mac TeX distributions. – Willie Wong Nov 23 '10 at 22:24
  • It'd be identical with Mac OS X. – TH. Nov 24 '10 at 1:16

I think the easiest way, one that doesn't involve playing with environment variables (which can be tricky to get right when you're using graphical programs not launched from the command line) would be to put your document class in ~/texmf/tex/latex/mycls/mycls.cls.

With MiKTeX, you need to register a local additions directory. I have no experience we this, but this page looks like it has all of the information you need to do that.

  • 1
    The corresponding folder on Mac OS X is ~/Library/texmf, the rest being identical. That would be my recommendation, too; it is what the home tree is intended for, after all, and doesn't require playing around with environment variables. – Philipp Nov 24 '10 at 10:17
  • @Philipp: I use TeX Live on Mac OS X and it is definitely ~/texmf. Perhaps Mac TeX is different. At any rate, kpsewhich -expand-var '$TEXINPUTS' will list the possible locations. – TH. Nov 25 '10 at 11:15
  • that is possible, I haven't checked. BTW, you can also say kpsewhich --var-value=TEXMFHOME to get the home TEXMF tree. – Philipp Nov 25 '10 at 13:18
  • 3
    It is very surprising though that in all of these answers and similar posts, nobody could mention a way to locally include a documentclass file by relative path. I have seen people do that before, but I have been out of practise for quite some time and now I cannot figure out how to do it :( – Subhamoy S. Jan 18 '13 at 11:04

Well I don't think that it is a good idea to put a class or packages in a subfolder relative to the document: It could be tricky to get the pathes for subsequent \inputs right. Some ideas are here: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=docotherdir

But concerning your problem with \@currname: As it is your own class, why don't you simply reset \@currname at the start of the class?


By default (i.e., this behaviour is disabled in "paranoid" mode), Web2c Texs (basically, all Tex implementations) will look in parent directories for things they are not configured to look for.

So creating a hard link in the parent directory from templates/mycls.cls to mycls.cls should solve your problem.

  • Hard or soft link, in fact. (I think using the local texmf tree is probably better, though.) – Will Robertson Nov 24 '10 at 8:06
  • 2
    I disagree on two points: (a) MiKTeX is not based on Web2c and is widely used, so Web2c is not "basically all TeX implementations". (b) the (symbolic or hard) link will work regardless of whether openin_any=p or not, so it seems irrelevant (and potentially confusing) to mention it here. – mpg Nov 24 '10 at 12:52
  • @mpg: (a) I understood that Miktex's default engine is now Pdftex, which is based on Web2C: is that not right? (b) Really? If openin_any=p will allow inputting a file in the parent directory, then I don't understand what paranoid mode is for. – Charles Stewart Nov 24 '10 at 16:18

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.