After looking at TeX, you may want to look at further extensions of it. The first major/widespread one was e-TeX.
A raw dump of the program is below; will annotate it later. Note that it may take quite a while to load.
Note: This page takes a long time to load fully, and may download about 60 megabytes.To read the program, click on "Fetch modules" below.