Style/class tutorials

  • Minutes in Less Than Hours is a place to start.

While I cannot point to a pre-built 'how to' guide, I can at least try to provide some pointers here. The first point to remember is that LaTeX2e is rather weak at providing documented 'hooks' for customisation in the kernel. As a result, a lot has to be done by loading support packages.

At the most basic, a class is a collection of instructions to alter the standard formatting. Many simple classes therefore start out as little more than a customised preamble spun out into a separate file. Unless you are very experienced, it is likely that the best place to start a custom class is by loading one of the standard ones, for example

\LoadClass{article}

It's then possible to load a selection of packages (using \RequirePackage rather than \usepackage), to allow modification. Obvious examples here would be geometry, float, caption, various font packages, etc. Quite a lot can be achieved by simply bundling up a group of support packages and appropriate options into one file.

The next thing to consider is providing custom commands. These might be as simply as something like

\newcommand\subject[1]{%
  \begin{center}
    \bfseries
    #1%
  \end{center}
}

which I do in a slightly-customised letter class for my own use. Of course, what makes sense here will depend on what you want. Custom commands might of course depend on packages that you know will be loaded as they are included in the list for the class.

The next thing that people tend to do in custom classes is simple redefinition of LaTeX internals. The most obvious one is \@maketitle, which you may well want to modify. Remember that class files set @ as a letter, so \makeatletter is not needed. At this stage, modifications tend to be made by starting with the existing code and altering it. The LaTeX2e kernel classes (article.cls, report.cls, etc.) and the kernel itself (latex.ltx) are the first port of call for code to modify. Taking the \@maketitle example, the version from article.cls reads

\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}

So obvious changes are to alter the spacing or fonts.

Beyond that, you are in to serious (La)TeX programming, where I'd suggest writing some of the code as a package and requiring it from the class might be better. This is a complex subject, and I think is not the way to start out learning how to write class files!


The LaTeX Companion[1] has a chapter on writing package/class files.

EDIT: The table of content is available online. The relevant chapter is Appendix A and in particular Section A.4. The style of the chapter is pretty much the same as the style of the rest of the book (Chapter 3 is available online) with all needed commands explained in some details and with lots of examples (and counterexamples).

[1] F. Mittelbach and M. Goossens, The LaTeX Companion. Addison-Wesley 2004