Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Learning to write LaTeX classes and packages

There’s nothing particularly magic about the commands you use when writing a package, so you can simply bundle up a set of LaTeX \(re)newcommand and \(re)newenvironment commands, put them in a file package.sty and you have a package.

However, any but the most trivial package will require rather more sophistication. Some details of LaTeX commands for the job are to be found in ‘LaTeX2e for class and package writers’ (clsguide, part of the LaTeX documentation distribution). Beyond this, a good knowledge of TeX itself is valuable: thus books such as the TeXbook or TeX by topic are relevant. With good TeX knowledge it is possible to use the documented source of LaTeX as reference material (dedicated authors will acquaint themselves with the source as a matter of course). A complete set of the documented source of LaTeX may be prepared by processing the file source2e.tex in the LaTeX distribution. Such processing is noticeably tedious, but Heiko Oberdiek has prepared a well-linked PDF version, which is in the file base.tds.zip of his latex-tds distribution. Individual files in the LaTeX distribution may be processed separately with LaTeX, like any well-constructed .dtx file.

Writing good classes is not easy; it’s a good idea to read some established ones (classes.dtx, for example, is the documented source of the standard classes other than Letter, and may itself be formatted with LaTeX). Classes that are not part of the distribution are commonly based on ones that are, and start by loading the standard class with \LoadClass — an example of this technique may be seen in ltxguide.cls

An annotated version of article, as it appears in classes.dtx, was published in TUGboat 28(1). The article, by Peter Flynn, is a good guide to understanding classes.dtx

classes.dtx
macros/latex/base/classes.dtx
clsguide.pdf
macros/latex/doc/clsguide.pdf; catalogue entry
latex-tds collection
macros/latex/contrib/latex-tds; catalogue entry
ltxguide.cls
macros/latex/base/ltxguide.cls
LaTeX documentation
macros/latex/doc (or browse the directory); catalogue entry
source2e.tex
macros/latex/base/source2e.tex

This answer last edited: 2011-07-19


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=writecls

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.28, released on 2014-06-10.