Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Tex Source Code (tug.org)
25 points by dangoldin on Jan 10, 2010 | hide | past | favorite | 14 comments


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?


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.


It's also the source of the TEX language but written in a "Literate" style that Knuth pioneered.

I just thought it was pretty interesting while reading Coders at Work since a lot of people refer to it.


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.


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


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.


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!)


To view on a unix system:

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


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?


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.)


That's really missing the beauty of the book form. Cross reference and non-linear reading is made easy by those "see also" sections on every right hand page. They're present in the PDF but they don't work so well on an on-screen version.


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...

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


Notice the version numbers converging to PI


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.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: