Hacker News new | past | comments | ask | show | jobs | submit login
TeX Is Great, What Is TeX? (rjlipton.wordpress.com)
55 points by fogus on Mar 9, 2011 | hide | past | web | favorite | 16 comments



Knuth invented the literate programming methodology and the literate programming tool WEB to write TeX. It is a mistake to say Knuth could ignore all the rules in writing TeX because he was a genius. He could ignore the standard methodology because he had a much better one---literate programming.

Knuth attributes his ability to single-handedly write huge bug-free computer programs like TeX, Metafont, the Stanford GraphBase, and the MMIX simulator to literate programming. In his FAQ, he answers the question "What is your favorite programming language?" with CWEB, the literate programming tool that is the descendent of WEB (and was also written using literate programming).

Knuth has been pushing literate programming for a very long time. He wrote a book on the subject ("Literate Programming"), and a book that was full of examples of literate programs (The Stanford GraphBase), as well as his books containing the literate programs for TeX, Metafont, CWEB, and the MMIX simulator. Still most programmers or computer scientists I talk to about it have never heard of literate programming. Given that he's probably the most famous and respected computer scientist in the world, it's quite astonishing. This web-post is another example of ignoring what Knuth himself says about why he can program so well.


The talk rjlipton described was from the late 70s though, so it may have predated the idea of literate programming.

The quote in primodemus' comment shows that Knuth didn't in fact use the idea of literate programming in his first version of TeX, and he still wrote it in one go on paper ignoring the usual methodology. So maybe "he's a genius" is the right explanation after all.


He certainly is a genius, and you're right that the first version of TeX was not written using literate programming tools; he planned it out on paper instead and programmed it using SAIL.

He had a nasty bootstrapping problem since he needed TeX to exist before he could write a first version of WEB. But once he had a first version of TeX (TeX78), he built WEB, and then he re-wrote TeX from scratch (TeX82) in a different programming language (Pascal/WEB instead of SAIL).


From the Wikipedia article (https://secure.wikimedia.org/wikipedia/en/wiki/Literate_prog...):

The first published literate programming environment was WEB, introduced by Donald Knuth in 1981 for his TeX typesetting system; it uses Pascal as its underlying programming language and TeX for typesetting of the documentation.

That is delicious. He programmed in a way that would generate both the documentation for TeX (in TeX) and the source code for TeX (in Pascal). Compiling the source code generates a program that can process that TeX documentation.

In other words, the documentation is an integral part of the source code, and the compiled source code is an integral tool in producing the documentation.


According to the following extract from 'Coders at Work', Knuth wrote the first version of Tex using pencil and paper:

Seibel: Speaking of practical work, in the middle of working on The Art of Computer Programming you took what turned into a ten-year break to write your typesetting system TeX. I understand you wrote the first version of TeX completely away from the computer.

Knuth: When I wrote TeX originally in 1977 and ’78, of course I didn’t have literate programming but I did have structured programming. I wrote it in a big notebook in longhand, in pencil. Six months later, after I had gone through the whole project, I started typing into the computer. And did the debugging in March of ’78 while I had started writing the program in October of ’77. The code for that is in the Stanford archives—it’s all in pencil—and of course I would come back and change a subroutine as I learned what it should be. This was a first-generation system, so lots of different architectures were possible and had to be discarded until I’d lived with it for a while and knew what was there. And it was a chicken-and-egg problem—you couldn’t typeset until you had fonts but then you couldn’t have fonts until you could typeset. But structured programming gave me the idea of invariants and knowing how to make black boxes that I could understand. So I had the confidence that the code would work when I finally would debug it. I felt that I would be saving a lot of time if I waited six months before testing anything. I had enough confidence that the code was approximately right.

Seibel: And the time savings would be because you wouldn’t spend time building scaffolding and stubs to test incomplete code?

Knuth: Right.


That seems like the kind of thing that would work if you're (a genius like) Knuth, but maybe not so much if you're me. Even though I like to take some time to draw things out on paper, I don't think I'd ever have the confidence (or the skill) to assume that it would just work.


I think text editors and "instant" compile environments have skewed our perspective a bit.

I'd argue that it really doesn't take a genius to write out code longhand and have it work. What it takes is the discipline to write it slowly. The way people talk about it, it sounds like he just scrawled out a program..and it worked. But what he most likely did is think a lot, write a bit, erase, think a lot and write some more. It was written in pencil.

I've personally found that if I force myself to stop, think and re-read code a lot -- not just fragments a few or 5 times, but the whole shebang in context 10 times over -- it's of consistently higher quality. Also, another way to view this is to pretend that's there's a high cost to typing it in the first place -- that helps too, but is harder to stick to :-). This seems to me to be a way of forcing your inner code reviewer to the fore.


I definitely notice that even for simple things. When I was pretty young, probably 8 or something, I was in a class where we had some time to play around with Logo when we finished other things. So I'd write up some stuff I wanted to try out on paper when I wasn't at the computer, and typed it in when I got to use the computer, and it worked pretty frequently. In theory I'm a much better programmer now than I was when I was 8, but I seem less good at writing chunks of error-free code that works on the first try, because there's this strong temptation to just instantly hit compile/run and see what happens, rather than writing it slowly and reading over it repeatedly.


While TeX is great, the language is really get long in the tooth.

Had amazing fun this morning, trying to put a \begin{verbose}...\end{verbose} section inside another command, getting the most insane error messages. In the end I just gave up, and wrote things a different way.


Initially, TeX wasn't meant to be scriptable. It was Guy Steele who convinced Knuth to make TeX an extensible fully programmable language.

So if it wasn't for Guy Steele, we wouldn't have e.g. LaTeX written in TeX macros, but perhaps as a pre-processor.


The typesetting/layout itself also seems like it could be improved, especially given modern computing hardware. Better control over it would be nice anyway. As it is, trying to get figure placement, line-breaking, and page layout to look nice is a crazy trial-and-error-and-magic-constants exercise, and the results in a lot of cases still end up suboptimal.

I'm not too sure why, but there hasn't been a lot of experimentation with it really. I think the figure-placement algorithm is still the same sort-of-works-but-not-really one that Knuth had a student working on improving circa 1980; the student's dissertation proved that optimal pagination was NP-complete instead of improving the algorithm. :P ConTeXt is an interesting experiment that seems to be making some improvements, though.


TeX is great, but it is getting long in the tooth. I find the CMR family of fonts works well for a short paper, but it hurts my eyes to look at a book written in TeX.


Books (or anything else) written in TeX do not have to use the cmr fonts. I agree that the cmr fonts aren't very nice, but that's nothing to do with getting long in the tooth; they were not-very-nice from the day they were first made. (Of course this is a matter of taste; some people may love them.)

TeX is still holding up well against anything else you might care to throw at it, at least as far as quality of output goes. For typesetting mathematics, it's well ahead of anything else I know of. Not quite so great in terms of usability by the masses, though.


Try Times New Roman (\usepackage{times}) with the MathTime Pro 2 fonts from PCTeX (http://www.pctex.com/mtpro2.html), designed by Michael Spivak of the Differential Geometry books fame.

The MathTime fonts aren't free, but they are not expensive for a one-time cost, and they are worth the money. I bought them specifically to use on my dissertation even though I was a poor graduate student at the time. ;-)


Use another font?


Re ``there was no specification'':

Innovation is hard to schedule. -- Dan Fylstra




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

Search: