After looking at TeX, you may want to look at further extensions of it. The most commonly used one is pdfTeX.
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.