# How does TeX actually work?

Lots of useful information for human beings, especially in academia. But, what is actually underlying the TeX engine? How does it really work? Does it parse everything and just put the stuff together? Or any special spec info?! Or even any good resources for further reading? How is it possible to write some modules and how to develop something more for the community?

-
The ultimate source here would be The TeXBook. It explains "How TeX [actually] works". – Werner Oct 16 '12 at 19:54
In addition to Werner's comment, I wonder if you mean TeX or LaTeX. Much of the use of TeX in academia is using the LaTeX format, not plain (or even IniTeX). – Joseph Wright Oct 16 '12 at 19:56
I would add to the Werner's comment that TeX by Topic by Victor Eijkhout is also going to help. However, be prepared for a serious studying. The TeXBook and TeX by Topic do not read like NY Times. – Predrag Punosevac Oct 16 '12 at 20:10
Welcome to TeX.SE. There are several questions on this site as to where to start learning. Best really is just to start using it, and go from there as you need more info. For example What is the best book to start learning LaTeX?, or Free intermediate level documentation. – Peter Grill Oct 16 '12 at 21:15
– Qrrbrbirlbel Oct 16 '12 at 22:11

TeX is an interpreter and macro processor (the canonical implementation of which written in WEB, a dialect of pascal) it takes in text files consisting of text and macros, and font files (and a few other possible things) and expands the macros and evaluates some expressions defined in the TeX syntax and produces a file description of a sequence of typeset pages (usually in dvi or pdf format).

Asking "how TeX works" is like asking "how does C work" or "How does Fortran work". It is answerable on several levels depending firstly whether you mean how does one write macros in TeX, or how does the TeX system evaluate the macros. (Compare to asking how one programs in C or how one writes a C complier). The TeXBook and TeX-The-Program fully document the TeX language and the TeX program itself. These books are not available for free (although their source text is) but there is lots of information, not least on this site, about all aspects of TeX programming.

There are other questions on site detailing differences between XeTeX, TeX etc but in brief classic TeX was written in 1970's-80s and at its heart it is based around 8-bit encodings. It can be made to process Unicode files but under the covers the details are less than ideal. XeTeX is an extended system based on the original TeX source but using Unicode encodings and system fonts as far as possible. LuaTeX is a separate extension of TeX again with a unicode base but is more radical in that it also incorporates the separate Lua programming language as an alternative to the traditional TeX macro language.

LaTeX is by far the most popular way of using TeX it is a set of macros but also a mechanism for anyone to contribute additional extension sets of macros known as packages.

last one:-) none of those are defined terms they are just English descriptions, but the "engine" is the underlying interpreter. The original TeX, pdfTeX (a variant that takes the same input but produces pdf rather than dvi) eTeX (a variant of TeX), and the newer engines XeTeX and LuaTeX. LaTeX is written in TeX macros so may be used over any of the engines (hence latex pdflatex xelatex lualatex which are all more or less the same TeX source processed with TeX, pdfTeX, XeTeX and LuaTeX respectively). A distribution like "MikTeX" or "TeXLive" is a complete packaged installation of all the files you need, an update mechanism, matching previewers and editors and stuff. TeX the program is a single executable file, the TeXLive TeX distribution is a dvd full of tens (hundreds?) of thousands of files.

-
That was great David. But could you please describe more about what is something like xelatex or other things like packages and modules and so on... – SMG Oct 16 '12 at 21:17
and once more, if you please explain shortly what is the difference between macro packages, alternative engines, and distributions ? – SMG Oct 16 '12 at 21:47
I feel great now ;) Have fun using it everybody! – SMG Oct 17 '12 at 4:33
@SMG: Wikipedia exists, and there is a TeX FAQ. And this site has a search field at the top right of the page. – Martin Schröder Oct 17 '12 at 9:46