# Is ConTeXt using TeX or rewriting it?

Just out of curiosity, is ConTeXt using the TeX algorithm in it's entirety, or are some components rewritten?

If it's the latter:

1. Could all of TeX be rewritten in Lua, or are there good reasons against it?
2. How was the pascal translated to Lua - automatically, or did someone understand it in it's entirety and rewrite it?

Feel free to close this as off-topic

• I suspect you mean at least in part LuaTeX rather than ConTeXt here. Also note that the binary part of the ConTeXt Mk IV set up (LuaTeX) is not written in Lua at all, it's written in C. – Joseph Wright Mar 6 '13 at 17:27
• TeX could be rewritten in Lua or any other language, but then you couldn't call it TeX unless it passes the `torture test`. – Yiannis Lazarides Mar 6 '13 at 17:44
• @JosephWright Yes, I meant anything but pascal I suppose. I guess this is more of a luatex question then :-) – Andriy Drozdyuk Mar 6 '13 at 17:45
• ConTeXt MkIV uses extensively Lua functions, as far as I know, but LuaTeX, over which it is based, uses essentially the same algorithms as (pdf)TeX, with the big difference that almost all internal operations are "open" to Lua functions, so in principle almost all TeX working can be modified. LuaTeX has been completely rewritten in C from the start. – egreg Mar 6 '13 at 17:49
• Have a look at History of LuaTeX for details on how ConTeXt and Lua interact. – Aditya Mar 6 '13 at 19:18

ConTeXt is mainly a macro package written in the TeX language. The current version MkIV is written for the TeX backend LuaTeX, which is written in C and opens up part of the TeX internals to a Lua interpreter, which the ConTeXt macros heavily use.

Could all of TeX be rewritten in Lua, or are there good reasons against it?

Sure, nothing prevents you from rewriting TeX in Lua, but it would not make much sense. It already has a brilliant C implementation with Lua interface. What would be the benefit?

How was the pascal translated to Lua - automatically, or did someone understand it in it's entirety and rewrite it?

The pascal code was never translated to Lua. The pascal code has been manually converted to C.

Here are some slides which depict how LuaTeX is comprised: Taco-LuaTeX-talk-2007

• LuaTeX was written in pascal (just like pdfTeX an Aleph), for a good portion of it is history, and the current C code was translated manually not using web2c. – Khaled Hosny Mar 6 '13 at 23:16
• I wonder what's going on with the LuaTeX/ConTeXt -generated PDF documents when many of them, including the one linked in the answer, do not show all of the content text with Google Chrome's PDF viewer. – morbusg Apr 1 '13 at 18:12

The Luatex project, as outlined by Taco in the link Marco gave, isn't about reimplementing Tex, it's about:

1. Exposing Pdftex's internal data structures to Lua;
2. Adding hooks into the Pdftex engine, e.g., callbacks; and
3. Using Lua as a bridge to other code, most importantly Metapost, through mplib.

This allows Lua to be involved in layout, but the that is through configuration, scheduling and controlling the Pdftex engine which does the real work.

Context uses Lua to make scripting easier, and because it can potentially make heavy use of Metapost in layout. But the heart is basically Knuth's algorithms. Note also that Context Mk II did not use Lua, so much of Mk IV's functionality does not depend on what is new with Luatex.