4 ms·
Cool, 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 mo
by emmanueloga_ 8y ago
Cool, 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...