Hacker News new | comments | show | ask | jobs | submit login

Since you asked: Yes, the Pascal-to-C translator was written specifically for TeX.

To be more precise (and add more detail than anyone asked for!):

- TeX is not written in Pascal itself, but in a literate-programming system called WEB [1,2] (a language basically created for writing the TeX program in!), which lets you mix Pascal source code with TeX documentation, and lets you write your program as a “web” of “sections”, each independently understandable, and referring to other sections (with macros etc). The “tangle” program converts the WEB source code to Pascal source code.

- The Pascal used in the TeX program is a limited subset [3] of Pascal (and specifically of what Knuth called “Pascal-H”, the Pascal implementation that was available to him on the DEC PDP-10 system used at Stanford SAIL).

- It is not exactly true that he does not rely on implementation details, but he's conscious about where he does so, and he's included a list of all such places in the index under “system dependencies” [4] — in most places he gives suggestions on what could be done if the compiler didn't work the same way.

- In the early days, when Pascal was the most common language available at the places TeX was usually run (universities, research labs, etc.), the Pascal code (generated by Tangle) was directly compiled into a Pascal program and run.

- With the rise of C (into the wider world outside Bell Labs), there arose both hand-translations of the WEB (or Pascal) source code, and programs to do this automatically.

- Today, major TeX distributions have their own Pascal(WEB)-to-C converters, written specifically for the TeX (and METAFONT) program. For example, TeX Live uses web2c[5], MiKTeX uses its own “C4P”[6], and even the more obscure distributions like KerTeX[7] have their own WEB/Pascal-to-C translators. One interesting project is web2w[8,9], which translates the TeX program from WEB (the Pascal-based literate programming system) to CWEB (the C-based literate programming system).

- The only exception I'm aware of (that does not translate WEB or Pascal to C) is the TeX-GPC distribution [10,11,12], which makes only the changes needed to get the TeX program running with a modern Pascal compiler (GPC, GNU Pascal).

[1]: http://literateprogramming.com/knuthweb.pdf

[2]: http://mirrors.ctan.org/info/knuth/webman.pdf

[3]: http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf#p... (section 3)

[4]: http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf#p... (entry “system dependencies”)

[5]: https://tug.org/web2c/

[6]: http://tug.org/interviews/schenk.html

[7]: https://tex.stackexchange.com/questions/111332/how-to-compil...

[8]: https://w3-o.cs.hm.edu/~ruckert/web2w/index.html

[9]: https://ctan.org/pkg/web2w

[10]: http://www.tex.ac.uk/FAQ-sysunix.html

[11]: http://mirrors.ctan.org/systems/unix/tex-gpc/README

[12]: http://mirrors.ctan.org/systems/unix/tex-gpc/tex.pdf




Thanks for the details! It is amazing to me that TeX has lasted so long. I would conjecture that this abstract style and the resulting portability are a big part of it.

I didn't know the name Pascal-H -- that is analogous to "OPy" in my mind. Although OPy I expect it to diverge from Python for efficiency reasons -- that's the whole point. It will probably look superficially like Python for a long time.

Why are there so many Pascal(WEB)-to-C converters? Why wouldn't they all use the same one? I guess I don't understand what TeX distribution is. Are there multiple maintainers? I would have thought they would have converged over time.

(FWIW the "system dependencies" docs are exactly what I meant. Most programs are littered with implementation details; there is no clear separation between them and their environment. But it sounds like Knuth is highly aware of them, and localizes them within the code. Obviously you need system dependencies to get anything done.)


I don't know why everyone doesn't use the same converter! I haven't looked into any of them in detail… As for what a TeX distribution is: it's all the stuff (beyond the source code of TeX itself, which is maintained solely by Knuth) needed to get TeX and related systems in a usable form. This includes the to-C converter and build scripts, for TeX and for other programs/extensions like pdfTeX, the major macro packages like LaTeX and “format files” for them, font information for commonly used fonts, lots of “packages” written by lots of people over the years, hyphenation rules for languages, other programs like makeindex etc., DVI viewers and converters, TeX editors — the entire ecosystem that a typical TeX user may want. (Some distributions more minimal than others… TeX Live and MiKTeX are probably the two main ones today.)




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

Search: