59

I read on Wikipedia that the first version of TeX was written in SAIL. However, does anyone know what language later versions (i.e the current one) are implemented in?

2 Answers2

54

TeX was rewritten in Pascal. Actually, using a literate programming system called WEB, invented by Knuth himself. This system uses Pascal for the programming and it uses TeX for the documentation.

The source code of TeX was published as a book: http://www.amazon.com/Computers-Typesetting-B-TeX-Program/dp/0201134373.

Cazo
  • 295
  • 1
  • 10
TeXtnik
  • 5,853
  • 15
    Currently, TeXLive uses web2c to compile WEB source in C. Pascal is not longer used since many years... – Paul Gaborit Jan 25 '13 at 22:45
  • 6
    @zunbeltz The commented source is also available in TeX Live with texdoc tex. – egreg Jan 25 '13 at 23:26
  • 2
    I do not agree with the idea that since web2c is used to compile the Pascal parts of the Web code to C, then Pascal is no longer being used or that the code is no longer written in Pascal. – Kaz Jan 26 '13 at 00:07
  • 5
    @Kaz: TeX (& Co.) is written in WEB... The subset of Pascal produced by tangle is just used as an intermediate between WEB and C. – Paul Gaborit Jan 26 '13 at 00:34
  • 7
    @PaulGaborit: If you need to hack a TeX you still have to use Pascal (unless you are hacking LuaTeX which have been ported to C), so it is Pascal for most practical, the web2c translation can be seen as a compilation detail. And there is TeX-GPC where the Pascal code is directly compiled. – خالد حسني Jan 26 '13 at 06:16
  • @KhaledHosny In pdftex sources, we find 42882 lines in .WEB files, 17559 lines in .ch files (.ch files are like Pascal diff files, we can therefore divide their size by 2 or 3) and 194882 lines of .c or .h files... – Paul Gaborit Jan 26 '13 at 08:26
  • 1
    @PaulGaborit: I don’t know where you are looking, but pdftexdir (which is the PDFTeX source) has only 14450 lines of C and headers, almost all of them are for handling fonts and images embedded in PDF files. – خالد حسني Jan 26 '13 at 09:09
  • @KhaledHosny I look into http://mirrors.ctan.org/systems/pdftex/pdftex-1.40.11.zip – Paul Gaborit Jan 26 '13 at 09:40
  • 4
    @PaulGaborit: This tarball includes not only PDFTeX source code, but also the entire web2c system, kpathsea, a bunch of support libraries (zlib, xpdf, libpng, etc.) and even the source code for WEB and CWEB utilities. That is hardly the source code for TeX. – خالد حسني Jan 26 '13 at 11:14
44

TeX is written in WEB (a literate programming language created by D. E. Knuth).

Originally, WEB source was translated into Pascal (a subset of Pascal) via tangle to produce executable and translated into TeX via weave to produce documentation of the code. Both programs have themselves been written in WEB.

Today, TeXLive uses web2c to translate directly WEB source into C... via the Pascal source produced by tangle (web2c is not a Pascal to C translator).

MikTeX must use a similar system to produce C/C++.

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283