Before looking at TeX itself, you may want to look at a few smaller programs.

The program below, GLUE, has an interesting history. (Reproduced from my answer here.)

In the November 1981 issue of TUGboat, Knuth mentioned that he was developing a system called WEB. Then in the next (March 1982) issue, he published “Fixed-Point Glue Setting: An Example of WEB”, saying

I will soon be publishing a complete manual about WEB, but in the meantime I think it will be useful to have an example of a fairly short piece of code written in “web” form. Therefore I have prepared the accompanying program, which also serves another function: …

You can read the program itself either on this page, or with texdoc glue, or here. The source glue.web is here.

I was able to test this glue.web just now with another Pascal compiler (fpc), by first running tangle glue.web to generate glue.p, then adding {$mode ISO} to the top of glue.p (so that when the program says “integer”, a 32-bit type is used rather than a 16-bit type), then running fpc glue.p to generate the glue binary. (I tried web2js but it crashed.)

Then to test the binary, put the following input (which consists of 7 test cases—pairs of lines—followed by 0) in a file (or type it in at the terminal). This input is the same as that used by Knuth.

200000
30000 40000 50000 60000 0
2000
30000 40000 50000 60000 0
1000000000
8000000 -9000000 8000000 4000 7000000 0
100
8000000 -9000000 8000000 4000 7000000 0
1000000000
800 -900 800 400 700 0
1000000000
800 -900 800 400 -700 0
65555 
-200 199 0
1
60000 -59999 90000 0
0

The output should be (matching that published in TUGboat):

Test data set number 1:
  Glue ratio is 1.1111 (0,14,18205)
               30000          33334
               40000          44445
               50000          55557
               60000          66668
 Totals       180000         200004 (versus 200000)
Test data set number 2:
  Glue ratio is 0.0111 (0,21,23302)
               30000            333
               40000            444
               50000            555
               60000            666
 Totals       180000           1998 (versus 2000)
Test data set number 3:
  Glue ratio is 71.4101 (8,0,18281)
             8000000      571281250
            -9000000     -642686836
             8000000      571281250
                4000         274215
             7000000      499857383
 Totals     14004000     1000007262 (versus 1000000000)
Test data set number 4:
  Glue ratio is 0.0000 (8,24,30670)
             8000000             57
            -9000000            -64
             8000000             57
                4000              0
             7000000             49
 Totals     14004000             99 (versus 100)
Test data set number 5:
  Glue ratio is 2x2x2x2x2x2x8681.0000 (-6,1,17362)
                 800      444467200
                -900     -500025600
                 800      444467200
                 400      222233600
                 700      388908800
 Totals         1800     1000051200 (versus 1000000000)
Test data set number 6:
! Excessive glue.
  Glue ratio is 2x2x2x2x2x2x2x0.0000 (-6,0,0)
                 800              0
                -900              0
                 800              0
                 400              0
                -700              0
 Totals          400              0 (versus 1000000000)
Test data set number 7:
Invalid data (nonpositive sum); this set rejected.
Test data set number 8:
  Glue ratio is 0.0000 (1,30,23861)
               60000              0
              -59999              0
               90000              1
 Totals        90001              1 (versus 1)
To read the program, click on "Fetch modules" below.

That's the end of this page. If you have any feedback about anything on this site, you can contact me here. To go back to the top-level page (if you are not on it already), click here.