Tuesday, September 21, 2010

LaTeX's architecture

Someone asked about the architecture of LaTeX. After avoiding the question for a day, I decided to answer. Since it's possible the question will be closed and possibly deleted, I figured I'd reproduce the relevant portion of my answer here. Briefly, LaTeX consists of several layers. The lowest layer is the three hundred or so TeX primitives such as \hbox or \vskip. On top of this, there is the LaTeX kernel. This is a set of macros such as \documentclass, \usepackage, or \begin. The documented source of the kernel is documented in the source2e document. Each document written in LaTeX begins (more or less) with \documentclass{foo} which loads the file foo.cls, for example article.cls or book.cls. This file is another set of macros, this time written using a combination of TeX primitives and macros from the LaTeX kernel. These class files can also load another class to extend it or modify the macros from that class. It can also load packages which are up next. LaTeX packages—that is, files ending in .sty (and their related files)—are additional sets of macros written using any combination of macros from lower levels. Some are specific to particular document classes, others are more general. These packages can be loaded using \usepackage from user documents, or \RequirePackage from classes and other packages. At the highest level, the users' documents use a class file and optionally packages. These documents contain macros written using any combination of TeX primitives and class- and package-defined macros as well as the prose, verse, and mathematics to be typeset. There is a lot more detail that one could go into regarding things like fonts and class and package options, but this isn't so "brief" after all.

No comments:

Post a Comment