“A Functional Description of TeX’s Formula Layout”, Reinhold Heckmann, Reinhard Wilhelm1997-09 (, ; backlinks)⁠:

While the quality of the results of TeX’s mathematical formula layout algorithm is convincing, its original description is hard to understand since it is presented as an imperative program with complex control flow and destructive manipulations of the data structures representing formulae.

In this paper, we present a re-implementation of TeX’s formula layout algorithm in the functional language SML, thereby providing a more readable description of the algorithm, extracted from the monolithic TeX system.


The TeX typesetting system basically consists of two parts: a macro language and certain basic typesetting capabilities, such as placing boxes next to each other, either vertically or horizontally. However, the real documentation for the typesetting capabilities is the TeXbook and the TeX source code.

This paper is truly welcome. The basic typesetting functions used by TeX should become more clear and should be reachable from a decent declarative language, thereby allowing documents to be typeset or generated in a declarative manner.

As ideas are better and better understood, they are expressed in a more and more declarative manner. The work done in this paper shows how this can be done for a very useful algorithm written in a very unreadable form. This sort of work should be done for other algorithms that are commonly used.

Work of the kind done in this paper allows one to perceive the need for more general means for laying out two-dimensional diagrams, with esthetic or other constraints defining the actual placement of atomic components to form more complex diagrams.