
Tex Source Code - dangoldin
http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web
======
Skriticos
I wouldn't exactly call it source code.

It's more like a book with extensive description containing all the source
code.. without much structuring.

Somehow it hurts.

.. then again, maybe the dvi/pdf version I saw just missed that. Not very
experienced with TeX, but I guess the output can be rendered nicely. Why did
you post the TeX source edition of a book?

~~~
almost
It's both the source code and a book. This single source file can be compiled
to both the book (weave->tex->dvi2ps) or too Tex itself (tangle->pascal
compiler). It's kind of a beautiful idea I think. I would strongly recommend
getting the printed book form (very cheap second hand on Amazon) as it's a
fascinating read.

------
dangoldin
I posted this as I was reading Coders at Work.

Many of the people interviewed cite this as a great example of clean code. In
addition, it is written in the Literate Programming style so I wanted to take
a look and see what it was all about.

~~~
michael_dorfman
It's available in book form, as well, as are many of Knuth's literate
programs.

One interesting program for the causal reader, found only online at his site,
is Knuth's version of Adventure.

<http://www-cs-faculty.stanford.edu/~knuth/programs.html>

~~~
hga
Wow, thank you very much! I'd missed that the last time(s) I'd checked his
programs page (or feared it was still written in FORTRAN for some inexplicable
reason (that code is hideous)). I had much fun learning the Colossal Cave in
the same summer I learned UNIX, it'll be fun reviewing this.

~~~
hga
Ah, I should go a bit further:

I got introduced to Adventure during Harvard Summer School in 1978, where they
had a mostly idle much hacked UNIX V6 system on their single PDP-11/70 for all
the undergraduates (HRSTS). It had a file system full of goodies and learning
to navigate the Colossal Cave and an hierarchical file system really went well
together.

(Prior to that was punched card FORTRAN IV (really more like a II) on an IBM
1130 ... so that was quite a step up!)

------
glymor
To view on a unix system:

    
    
      weave tex.web
      tex tex.tex
      dvips tex.dvi -o tex.ps

~~~
dmd
In case anybody is too lazy: <http://3e.org/private/tex.pdf>

Does anyone know of a way to generate similar output but with some nice color-
coding, or (even better) hyperlinks from functions and other symbols to their
definitions?

~~~
cduan
It would probably be not too difficult to find the macros that generate the
index and add in the appropriate PdfTeX instructions to make hyperlinks.

Although, as a veteran Knuth code reader, I would say that his code is
intended to be read linearly, like a book, rather than in bits and pieces.
(Think of it like dynamic programming: it's more efficient to start from the
little functions and work your way up, than to start from the big functions
and recurse your way down.)

------
crux_
Relevant: "A Functional Description of T E X's Formula Layout (1997)":

[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.6...](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.601)

They rewrote the formula layout into purely (?) functional SML, and made it
fairly easy to understand along the way.

------
varenc
Notice the version numbers converging to PI

------
Maro
I wonder whether TEX is one of the most bugless codebases in existence. If it
is, it's worth studying how Knuth arrived at it and the tools he used
(literate programming). Personally, based on what I've seen, I don't like
literate programming: code organized into header and source files, divided
into modules (ie. classes) by files with some terse accompanying docs in text
files seems more programmer-friendly. (Poor programmers can produce crap in
both formalisms.)

