[Tex/LaTex] Where does the documentclass command look for class files

auxiliary-filesdocument-classesUbuntu

The first line of my latex file is:

\documentclass[english,draft]{ectaart}

latex fails with the following error:

LaTeX Error: File `ectaart.cls' not found.

I copied that file to (on my Ubuntu system):

  • /usr/local/share/texmf
  • /usr/local/share/texmf/tex
  • /usr/local/share/texmf/tex/latex
  • /usr/local/texlive/2012/texmf
  • /usr/local/texlive/2012/texmf/tex
  • /usr/local/texlive/2012/texmf/tex/latex
  • /var/lib/texmf
  • /var/lib/texmf/tex
  • /var/lib/texmf/tex/latex

None of these options worked.

Where should this file go?

(And why doesn't Latex tell me where it looked for the file?)

Best Answer

TeX's first step is to parse the current/working folder for files that are needed. This covers everything from .tex, .sty, .cls, image files, and everything else. If this fails, TeX searches the index made when you run texhash. This index contains the folder and file locations of your TeX distribution in the form of an elementary "hash table" that is used as a lookup. Actually, it's just an alphabetical list of files by folder. Since TeX can be installed wherever you want to, such an accessible table is necessary to identify the locations of the sources. Under TeX Live, this file (ls-R, named based on a Recursive folder listing) is located in your */texmf-dist folder and has the following form:

...

./tex/latex/bhcexam:
BHCexam.cfg
BHCexam.cls

./tex/latex/bibarts:
bibarts.sty

./tex/latex/biblatex:
bbx
biblatex.cfg
biblatex.def
biblatex.sty
biblatex1.sty
biblatex2.sty
blx-compat.def
blx-dm.def
blx-mcite.def
blx-natbib.def
cbx
lbx

...

You can see how this matches the folder structure:

enter image description here

Only the above two locations are searched, in that order, when looking for files.

Note that, even if you place source files inside the TDS (TeX Distribution Structure), it won't be picked up automatically unless you run texhash. ls-R has to be updated to include your newly-placed files, otherwise the files won't be found.


Another reference: Where do I place my own .sty files, to make them available to all my .tex files?