[Tex/LaTex] Creating a class file vs using packages

document-classesdocumentclass-writingpackages

In my limited LaTeX experience, I've always found that I can accomplish what I want by just using the relevant set of packages, even for more complex formatting. If I were to try and create a configuration for someone else I would be hard-pressed to justify creating a class file; instead, I would just create a config.tex file that includes the relevant packages and commands and then tell them to just \input it in their main file. However, I'm sure that there is some additional flexibility afforded by creating a class, so my question is: When is it actually worth writing class files?

EDIT
Some further clarification of what exactly I'm asking. My question was more meant to address the case where a more specialized class is called for, such as the one in Alan's answer. In the case of, say, maintaining a thesis template for a university, what is the advantage of creating a custom class instead of just using packages? The beamer example is a good instance where the entire layout is different, but in that case what we're doing is creating an entirely different template. In the thesis case, though, I would guess that the base class does a LoadClass of article (or something similar) since we're generically constructing something pretty similar. To that end, I'm trying to understand why that approach would be preferable to the package-based configuration approach I stated above.

Best Answer

I think there are two very different kind of class files: general purpose class files like memoir and KOMA, which strive to create a uniform interface to most aspects of document formatting, and specialized class files for particular document types. Peter Wilson has already addressed the first type in his answer.

But there is another kind of class which is designed to provide predefined formatting for a particular document type. I maintain a thesis class for my university. Being an American institution, it sets out very particular and stupid formatting guidelines which all theses must follow, (in addition to specifying particular wordings in title pages etc.)

For this kind of use, a class file is quite useful. I provide a document class which people can simply "pour" their content into, knowing that the university guidelines will be met without their having to think of them. Crucially, the class does only this: it doesn't load other packages such as font packages or bibliography packages etc., or try to guess what people will need. This is where most naive class files go wrong.

Another class of this sort is beamer, which provides methods for formatting a presentation rather than a printed document. Doing this with just regular packages is really not practical.

The choice between creating a class and using a package is partially conceptual, and partially practical. Conceptually, a thesis is a different document type, and so it makes sense from the user's point of view to define it in the \documentclass command rather than in a package. As a document class it provides the all the specific boiler plate language that my university requires for the title page etc., and this is what is to be expected of a document class. The class defines various components of the document that are logically part of the document class such tables of contents formatting, special pages before appendices, formatting for landscape pages, etc.

On a practical matter, from my point of view as the author, it reduces the complexity of maintenance and documentation: I don't have to worry about people trying to use my package with some other class with which it may be incompatible, or have to maintain extra code for different document classes that are around, and I therefore don't have to document things like "must only be used with class X" etc., which I know from experience people don't tend to read.

Of course some dedicated classes are less useful. I've never been a fan of the letter class, for example, since it has various odd restrictions on the kinds of environments it allows, preferring to use article plus my own letterhead package.

So there are definitely use cases in which a dedicated class is very helpful. For most of my documents I still use the basic classes + packages, but for large documents I prefer the all-in-one classes like memoir.