3 ms·
Reading TeX original source is easier said than done... I think I managed to get PDF some time ago but took me like 30 minutes of browsing. Not talk about runni
by emmanueloga_ 8y ago
Reading TeX original source is easier said than done... I think I managed to get PDF some time ago but took me like 30 minutes of browsing. Not talk about running it...
- svat 8y agoIt's available as a book (TeX: The Program, volume B of Computers and Typesetting), and Knuth considers the book as the canonical thing to read. You almost surely don't have a PDF of the entire book, but it's easily available in good libraries: http://www.worldcat.org/title/tex-the-program/oclc/826569131 http://www.worldcat.org/title/tex-the-program/oclc/826569131 (or you can buy it: as I was typing this comment I just finally bought a used copy from Amazon for $9 which is pretty good for a hardcover book). If you have a typical TeX distribution installed, you can see an approximation by running `texdoc tex`, which brings up the PDF that is also available online e.g. here: http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf -- but it is a bit hard to make sense of if you're not familiar with the conventions of WEB (the book starts with a "How to read a WEB") -- as a workaround maybe you can read webman (http://texdoc.net/texmf-dist/doc/generic/knuth/web/webman.pdf http://texdoc.net/texmf-dist/doc/generic/knuth/web/webman.pd...) though that's meant for the programmer (working with the raw .web files) rather than the reader (working with the typeset output). And it helps to be familiar with Pascal, and the typical conventions of programming style in the 1970s (e.g. that of the P4 (Pascal) Compiler and Interpreter, also published as a book and also available online: https://homepages.cwi.nl/~steven/pascal/ https://homepages.cwi.nl/~steven/pascal/ ) I've been reading the TeX program in bits and pieces for over a year now, and only now do I have a rough sense of it all :-)
- emmanueloga_ 8y agoCool, very informative! The bad thing about a print book is that you would have to type the code to run it... How would you go about running TeX? I find the most effective way to read source code is to run it (to answer questions like: "what's the output if the input is this thing", etc.) I wish someone who's familiar with the moving pieces would put together a version that runs on a browser.
- svat 8y agoTeX is written in a literate programming system called WEB, that Knuth developed especially for (re-)writing TeX and METAFONT, and knowing that the source code was going to be published as print books (people had asked for it, so he kept this in mind when rewriting them). To overcome the limitations of Pascal (which was the most widely available language at the time at the places where TeX was being used: universities and the like), the WEB system adds quite a few features as a preprocessing step. So, in WEB, the programmer types into a .web file, which runs through a program called TANGLE to produce a .pas Pascal file, and independently through another program called WEAVE to produce a .tex file (which is typeset into what you read). See Figure 1 here: http://www.literateprogramming.com/knuthweb.pdf#page=2 http://www.literateprogramming.com/knuthweb.pdf#page=2 So to run TeX, the idea was that you have to pass the code through TANGLE, then run the resulting Pascal code through a Pascal compiler to get a binary, that you run. Of course Pascal compilers are less common today (and in any case Knuth was writing in the dialect of Pascal available to him at the time, and the language has diverged since) so in practice most TeX distributions pass the WEB (or tangled) code through something that converts (translates) the WEB/Pascal to C, then compiles that C code, etc. So running it is not exactly trivial. (See also: "LuaTeX says goodbye to Pascal" https://www.tug.org/TUGboat/tb30-3/tb96hoekwater-pascal.pdf https://www.tug.org/TUGboat/tb30-3/tb96hoekwater-pascal.pdf and the Introduction to Martin Ruckert's "web2w" project: http://mirrors.ctan.org/web/web2w/web2w.pdf#page=13 http://mirrors.ctan.org/web/web2w/web2w.pdf#page=13) This also makes running TeX under a debugger quite hard (https://tex.stackexchange.com/a/384881/48 https://tex.stackexchange.com/a/384881/48 , http://www.readytext.co.uk/?p=3570 http://www.readytext.co.uk/?p=3570) Nevertheless, putting together a version that runs on a browser is precisely one of my dreams :-) Maybe in a few years! (There is already a version that runs in a browser: http://manuels.github.io/texlive.js/ http://manuels.github.io/texlive.js/ but that's not designed for readability / understandability.) Note that, even if you had the entire program running in a browser, understanding it interactively would not exactly be trivial. The program itself (if viewed at the "raw" Pascal code level, i.e. without the conveniences afforded by the literate programming system) is rather far from modular; it's monolithic, with lots of global state, lots of data structures with the same fields used for different things in different contexts, abundant goto-s, etc. (All of these were the right choices at the time, given the constraints.) It's described by someone at http://wiki.c2.com/?TexTheProgram http://wiki.c2.com/?TexTheProgram as “the last hurrah of procedural/functional structured (read: non-OO) programming. [...] achieved without some of the modern code-structuring tools we have today. I don't think the modern programmer raised in an OO culture could do the same”. But what literate programming gives here is a way to still understand the program despite these impediments -- one could say that, since the 1970s, many programming languages/communities have evolved some solutions for managing complexity, and Knuth's literate programming is an independently evolved different solution to the problem. Of course, one could combine the two...