Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am more and more interested in the system TeX (and LaTeX) and I want to study it more deeply. I am not telling that I want to learn how to use it, but I want to understand its mechanism now.

The first thing that I can imagine is to download its source code Plain Tex. But

...the current TeX software is written in WEB, a mixture of documentation written in TeX and a Pascal subset in order to ensure portability... (Wikipedia)

I am an amateur C programmer with a little experience of Win32 API, and I always use Microsoft Visual Studio to do programming.

I have totally no idea what to do next with the souce code above, for example, compile it and get outputs (on Windows and on Linux), use the outputs to compile a .tex file and get the output.

Can some expert(s) talk and explain a little about this beautiful sytem, or, at least, tutorials about how to build it, please?

share|improve this question
Could you explain why you need to compile the code, rather than say read it in typeset form and use plain TeX pre-compiled? –  Joseph Wright Apr 29 '13 at 12:10
@Joseph: Because successful compiliation of it make me feel good and confident :) –  user565739 Apr 29 '13 at 12:12
@Kaz: I don't understand your point. I am not interested in Firefox, so I don't want to compile it. –  user565739 Apr 29 '13 at 19:39
Like you, I also wanted to study the TeX code. After all, it was written by an eminent computer scientist, and, for a large piece of software, it is remarkably free of bugs. It looked like something significant could be learned. But, I gave up after a while. Mostly because the code is full of clever tricks to pack data into memory locations to save space. This made sense 30 years ago, but not so much today, and it makes the code very difficult to read (for me, anyway). There is a system called JavaTex, by Tim Murphy, which might be a bit easier to read, maybe. But I ran out of time. –  bubba Apr 30 '13 at 10:31
Also, I agree with vonbrand -- Tex includes a lot of exotic code that was required to make things portable 30 years ago. –  bubba Apr 30 '13 at 10:34

3 Answers 3

up vote 18 down vote accepted

You are linking there to plain.tex which is a file written in TeX not the source of tex-the-program (which is tex.web)

These days if you want to compile from source it is probably best to start with a full download of the texlive build sources.

The sources are at


and that page has hints about where to start if you want to compile. See in particular:


Good luck:-)

share|improve this answer
Thank you, David. But I don't like to build a whole system like TexLive. It is far from what I want to know. My goal is to know the TeX core instead. But thanks again. –  user565739 Apr 29 '13 at 12:27
@user565739 Building just tex without a minimal support stuff for fonts and so one will not give you a workable system. Perhaps take a look at KerTeX if you want something smaller that you can compile. –  Joseph Wright Apr 29 '13 at 12:32
@user565739 well.. the original tex sources are tex.web which is pascal more or less, but you are hard pushed to find a usable pascal compiler these days so you probably want at least web2c if not the whole of texlive. web2c as its name suggests translates web to c so it can be compiled with C but you also need the kpathsea file search library if you want a tex that can handle modern filesystems, and so it goes. It is probably easier to start with texlive and cut things out of the makefiles than to just get the original Knuth sources and try to build on a current system. –  David Carlisle Apr 29 '13 at 12:33
@DavidCarlisle: So now I am curious that how texlive do with tex.web? When I build texlive, it also compile tex.web? –  user565739 Apr 29 '13 at 12:37
@user565739 yes of course the heart of the sources is still tex.web but you need to build the scaffolding before you build the building and web2c provides that. texlive itself of course then goes on to provide all the tex packages and updates mechanisms and stuff which you don't need but still it's easier to download a working build setup and run the build scripts and watch and learn what happens rather than just download the raw web sources and a pascal compiler and then try to recreate a working system as it was in 1982. –  David Carlisle Apr 29 '13 at 12:42

David Carlisle explains how to compile the sources for the modern versions of Tex that are the basis for Texlive (Pdftex, Xetex, and Luatex, among others). These derive from Karl Berry's Web2c fork of Knuth's source code, which is a mechanical way of translating code Web sources to C code that can be compiled just about anywhere.

If you want to compile sources that are closer to what Knuth wrote (and documents in The TeXbook), take a look at:


This project allows you to compile Pascal WEB sources directly, using GNU Pascal. This apparently wasn't trivial; as the author, Wolfgang Helbig, writes:

I was somewhat intrigued while building TeX from its sources, since some of these depend on others to be built and installed. Knuth wrote these programs in the WEB language (WEB is only remotely related to the last W from CERN's WWW). WEB programs are converted to Pascal sources by tangle and to a TeX input file by weave. Of course, tangle and weave are WEB programs as well. So one needs tangle to build tangle---and weave and TeX to read a beautifully typeset WEB program. But don't despair, I cut this indefinite recursion and provided tangle.p, the Pascal source of tangle, and tex.pdf. It shows what, why and how I changed Knuth's program.

His tex.pdf documents in minute detail these changes.

share|improve this answer

All the programs in the TeX series (TeX by itself, but also METAFONT and all the auxiliaries) are written in WEB, but to ease the translation, D. E. Knuth has not really written in a flavour of Pascal, but in some very abstract Pascal; much an Algol: there is not a lot of Pascal idiosyncrazies left specifically to allow to convert the programs to whatever. The simplest, nowadays, is to convert the Pascal like code in raw C.

In kerTeX this is what is made by kertex_M: the matrix, the tools needed to obtain C code. The matrix tools are compiled... on the matrix, to obtain C code that can be compiled for whatever target. (Allowing cross-compilation).

If you want to see the thing, just use kerTeX and with the get_mk_install.sh (or rc) program, when asked if you want the program to remove the intermediary products (including the *.c files in this case), just answer : NO to keep them.

For the bootstrapping problem (tangling tangle), D. E. Knuth has written that the first version was done by hand: he mimicked by hand what tangle would do (this is why such a program has to be basic, the same way a compiler has to be able to bootstrap a more basic version of itself to use itself to compile more complex one). This can also be done with text tools (I have sketched in kertex_M/bin1/tangle/tangleboot.sh such a program; it is not used, and lacks change file support).

The conversion from Pascal to C was needed because Pascal was not standardized, Pascal compilers not ubiquitous etc. And D.E. Knuth has also tried several years ago to encourage the possibility to compile TeX and al. with a Pascal compiler, just to be sure his programs will not be unavailable because of some compiling nightmare. And it was a pain.

It is more simple to convert to C, since it is, on purpose, a very basic Pascal (bibtex is far more hard to convert because it uses Pascal idiosyncrazies).

For information, the conversion from Web to C was web-to-c, initially from Tomas Rokicki. This is still what is used with TeXLive, or what has been used as a basis for kerTeX.

share|improve this answer
Welcome to TeX.sx! –  Peter Jansson Apr 29 '13 at 15:10
No use of ctangle and its ilk then in TeXlive? Strange... –  vonbrand Apr 29 '13 at 18:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.