25

There is no doubt that the original Pascal/WEB implementation of TeX is a masterpiece and I have learnt a lot reading through the source code (both weaved and tangled) but it definitely shows its age. Most of the code deals with things like lower-level datastructures and memory management that would be vastly simpler or unnecessary in a more modern language with good libraries.

Have there been efforts to reimplement TeX in a modern language such as Python while keeping full backwards compatibility?

At various times I've endeavoured this myself and have made some progress but I'm interested if other work exists.

  • 9
    You do know that LuaTeX have moved over to C, I guess? Also, are things like Python available truly cross-platform? (I'm thinking mainframes.) – Joseph Wright May 20 '11 at 07:03
  • Just coming across this question. My opinion is that back in the time TeX was written, the compiler was not that good (no code inlining probably? See fast get avail procedure) so it was necessary to hard code several things; although some parts are a bit puzzling (hard coded constants like 400 or 255; and maybe cmd and chr could be packed into a struct/Pascal record? Also not sure about all those one-char var names). On the other hand even programming in C isn't very convenient either (no automatic destructor/something like C++'s for-range for conveniently iterating over linked list. – user202729 Jul 11 '22 at 03:23
  • James, can you share your Python implementation? This makes me curious. – projetmbc Feb 25 '23 at 10:30

6 Answers6

14

There are hundreds of partial reimplementations and nobody could finish it! It is really easy to start such a project but it seems really impossible to finish it ... And yes, LuaTeX maybe more than a start, but at this time it has a lot of bugs.

  • 4
    Lot's of bugs sounds like it is unusable. I think it's unfair to say LuaTeX is just "more than a start". I happily use LuaTeX in a production environment (!) every day, so does the creator of ConTeXt. It certainly depends on the application, but the answer is too negative to be generally true. – topskip May 12 '13 at 13:23
  • sorry, but I compare it with the original TeX and that has no bugs. This is the reason why I call more than 10 bugs a lot: http://tracker.luatex.org/my_view_page.php And, of course, LuaTeX is an extension of TeX and has many more features than TeX itself. –  May 12 '13 at 13:27
  • 7
    Well, some bugs of TeX are deemed features because fixing them would lead to breaking changes in older documents, so I am not completely sure whether saying it has "no bug" is really warranted. – Bruno Le Floch May 12 '13 at 16:41
  • @BrunoLeFloch: LuaTeX also has some features ... ;-) By the way: I am using LuaTeX for all my publications ... –  May 12 '13 at 20:27
10

I've written partial implementations in PHP and in Perl (that's currently a dead link, I'll dig around and resurrect it for posterity). They are by no means full, and were written for specific purposes. As these purposes were for conversion from LaTeX to some other markup then I concentrated on the expansion (TeX's "mouth") than the other pieces.

Also in Perl is LaTeXML.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
9

I am working on a reimplementation in Haskell: hex. It currently doesn't do much besides really simple files, but it has been progressing.

luispedro
  • 221
7

There is NTS, and there are some good lessons to be learnt from it for anyone "reimplementing TeX in a modern language".

  • Isn't that was Patrick mentioned? – raphink Sep 16 '11 at 09:11
  • 1
    @Raphink: NTS is extex's predecessor, but they are not the same, and there no much lessons to learn from extex itself ;). – خالد حسني Sep 16 '11 at 09:21
  • 1
    nts has completely global variables and cannot be count as an reimplementation because it doesn't use anything of what a modern language provides. –  Sep 16 '11 at 15:08
  • @Herbert: because it fall into the trap of being "faithful" reimplementation and "100% backward compatible", you can't put those restriction up front and expect the project to move forward. – خالد حسني Sep 16 '11 at 15:53
  • 2
    one good lesson to be learned from nts is "don't put a committee in charge of the programming effort" -- the guy who was paid to the work didn't want his name associated with the results -- so unlike the situation with luatex and taco h – wasteofspace Sep 16 '11 at 15:54
  • I wrote a question (and answer) about the feasibility of using NTS today: here – ShreevatsaR Feb 01 '18 at 23:21
6

LuaTeX (C)

These days (10+ years later), LuaTeX is completely converted to C and is quite stable.

TeXifier (C++)

TexpadTeX/Texifier claims to convert the source code of TeX completely to C++. (although this one is only available in C++ version)

(Disclaimer: I'm neither associated with TexpadTeX or a user of it, just post here for completion.)

Tectonic (A mix of C/C++/Rust)

Homepage: https://tectonic-typesetting.github.io/

From https://tectonic-typesetting.github.io/en-US/contribute.html#working-on-the-source-code :

Due to its historical baggage, Tectonic is written in a combination of C, C++, and Rust. The aim is to eventually transition it to be fully written in Rust, but that is going to take a long time.

Based on XeTeX. (I'm surprised this is not mentioned earlier.)

user202729
  • 7,143
4

See extex - its a java based implementation. Not used in productive environments, as far as I know, but probably very interesting project.

topskip
  • 37,020