August 31, 2012
Inside TeX Writer

Inside TeX Writer

It is rumored that TeX Writer is running on an emulator. The short answer is NOT. If you ever tried to compile a LaTeX document with TeX Writer, you know that. No way that TeX Writer could run that fast on an emulator. A full listing of the app bundle could help to clear your doubts too. Now, I have a confession to make. I do work on an emulator called Aemula, which is a 486 pc emulator. I wrote this app for running old DOS programs and games on iPad/iPhone. Since we have a lot of DOS games that are very performance demanding, I did a lot of optimization for this emulator. A large part of cpu core is written in ARM assembler.  However, emulator isn't welcome by apple. So I can not put it on App Store. Instead I released it as a free app for jailbroken iDevices. One day, the idea suddenly came, is this emulator fast enough to run TeX? At that time I didn't believe that we can run a native TeX compiler on iOS. It's too messy a code base to port as someone once said. Why not give it a try on the emulator? I told myself. So I began with compiling the original TeX with GPC, based on texgpc. There are a lot of tricky problems. For example, when TeX prompts for input in the emulator, it would be very awful because you can't programmatically tell whether it is busy working or not.  And there are parts in the original implementation involving memory that are not that fast inside emulator. After these problems were sorted out, I ended up having a TeX running decently inside Aemula. Oh, that was an exciting moment. Down side is that it was not that fast, and had a very poor memory capacity. For example, you can typeset a simple LaTeX document with it, like the three-page sample2e, but that would take more than 10 seconds! Then I started looking into the web2c implementation in TeXLive. The whole code base is amazingly huge. This is not unexpected, TeX Live CD is more than 3GB.  I began digging into the source tree, figuring out which part does what. It's a lengthy process. One day I got bored, and thought, why not release a TeX app based on the Aemula and see if anyone was interested or not. That was the TeX Notebook 1.0, and it was a relatively quicker job. After I submitted the app for review,  I returned to the web2c port work, and had a break through. Everything began to fall into places. By the time TeX Notebook was approved (it took Apple about three weeks), I already had a working native version. Then I realized that I need to update the app with the latest build as soon as possible. But it's too late, somebody (actually a developer working on a TeX app and knowing how impossible it is) became so interested into this app, already unpacked the app bundle, discovered the secret, and wrote a post that even got into the front page of hacker news (Funny thing is, when the native and faster version came out, no HNer seems to be interested). A few days later, TeX Notebook was replaced by TeX Writer -- the native version that most of you are running now. That is pretty much the whole story as you know it now.