Compiling Knuth's tex with GNU Pascal - gpc

by Martin Monperrus
The famous typesetting program TeX is written in Pascal (encapsulated in a literate manner). However, most of the current distributions of Tex (e.g. Texlive or miktex) give a binary produced out of C code. The C code is produced from the Pascal code using a program called web2c.

For sake of elegance, I wanted to compile directly the original Pascal code. It turned out that it's not possible as is. It took me some time to find on the web the hints to compile the Pascal source code of Knuth's tex. I found three solutions.

GNU Pascal

First, Knuth himself published in 2000 a port of tex to GNU Pascal. However, this version is limited to tex v3.14159 and requires a small additional heterogeneous piece of C code.

Second, Waldek Hebisch published a port gor GNU Pascal. It is nicely documented and published on CTAN. It supports the latest version of Knuth's tex (v3.1415926), and has a clean directory scheme for the additional files (eg. fonts). Since it has very limited dependencies to the GPC library (only one call to execute and one to installsignalhandler that are easy to remove), it can be easily compiled in other runtime environments (and maybe with other compilers).


Preferred Wolfgang Helbig has also ported TeX to FreePascal, see, with the latest version from 2020-11-24

See also running tex on a java virtual machine

Note: tex-gpc.pas is compatible with the pretty printer ptop only if you set the linesize to high values. For instance: ptop -l 250 tex-gpc.pas tex-gpc-pretty.pas
Tagged as: