What are .cls and .sty files? How are they different?
Will Robertson July 15, 2005
In general, .cls and .sty files are supplementary files that increase the functionality of LATEX. They are the files loaded with the \documentclass{...} and \usepackage{...} commands, respectively. We generally call .cls files ‘classes’, and .sty files ‘style files’, or often just ‘packages’.
They both may contain arbitrary TEX and LATEX code, but they are used in separate ways. Loading a class via \documentclass is mandatory, and may only appear once in a LATEX document; usually, it is the very first command. On the other hand, packages are optional and as many of them may be loaded as one could wish (prior to the beginning of the document itself).
In the ideal case, a class file will completely define the structure of the document. The familiar article class is a good example: it provides commands for typesetting articles, such as \section, \tableofcontents, \author and so on.
Packages, or style files, are then used to provide anything else that the class doesn’t accommodate. These fall into two broad categories: amendments to the class file, or additional functionality. For example, the graphicx package provides methods to include images and apply all manner of graphical effects to elements in a document. This package will work with essentially any class file.
On the other hand, the sectsty package provides methods to customize the section headers in the default LATEX classes (article, report, or book). So, trying to use it with the memoir class, say, will result in it overwriting memoir’s method of creating section headers, and calamity will ensue.
To summarise, .cls and .sty files are loaded by LATEX to provide and improve methods that are used to create documents. Generally speaking, class files implement the specific structure of the document, whereas packages are used to provide either generic functionality to any document, or to ‘style’ the methods provided by a specific class.