Programming literature: "Hilbert Curves"
doug at mathemaesthetics.com
Tue Jun 25 02:47:09 CEST 2019
Well, what a long and strange trip (test) it's been!
After many years of both concentrated and sporadic efforts on a variety of fronts, my combined application and/or electronic book ("Hilbert Curves" and/or "Outside-In and Inside-Gone") is now available (for $8) in Apple's App Store for Apple's iPad (and iPhone, but more screen real estate is better).
Of interest to readers of this list, this app/book is, I believe, a first: it is self-typesetting on the user's device from TeX source code. See <http://www.mathemaesthetics.com/HilbertCurves.html> for a few screen shots. The typeset math of course looks great, though it is not very complicated (high-school level).
The app contains its own high-performance TeX-language interpreter, which I've been calling JSBox. The TUGboat article I wrote a while back on how it traces itself is here:
(although in this dedicated eBook's case, none of the tracing code is ever needed, so all the tracing code is conditionally compiled out to save quite a lot of space).
JSBox is a from-the-ground-up rewrite of TeX/e-TeX's engine, but (currently) without any of the back-end primitives for various types of import/export of PDF data. JSBox is not open source (maybe some day). It is a static library written in C that is designed to be incorporated into any other piece of software, such as an iOS or Mac or other GUI application that simulates a document of pages with illustrations.
Lots of work still to be done on it, but I had to get this proof-of-concept eBook/app done before continuing. With respect to this TeX language interpreter's development, I'm still in what's technically called the "eating your own dog food" phase. Sales of my app/eBook will help support further work on JSBox, especially getting LaTeX and the TDS working with it.
Under the hood, each time this iOS application launches, the 160-page simulated book (pages are logically 8.5" by 18"), with its 135+ non-file-based illustrations, is typeset anew, in under a half-second. The book's TeX source code starts by reading and executing a copy of the "plain.tex" macros, followed by the "opmac.tex" (Olsak's Plain Macros) lightweight markup library (with some added override hacks), and another related file of math symbol definitions. There is no format initialization relied upon, needed, or desired. The glyphs and metrics used are from Computer Modern. And when the job is done, all the TeX layout data structures remain in memory for every page, for later use by the app.
The point of it all, over and above the intellectual exercise, was to do an end-run around all static illustration files, most of which are inadequate for my eBook's topic of interest: space-filling curve illustrations each comprising self-avoiding paths of literally (numerically?) tens of millions of tiny line segments in each picture. Every illustration is resolution-independent and zoom-able up to about 300x. There are no accompanying EPSF, PDF, SVG, or MOV illustration files. The app's code is in charge of drawing (and in some cases, animating) each illustration into its anointed reserved box space on a page.
Most illustrations have a set of interactive controls to allow the user/reader to play with various graphic or other parameters. One particular illustration comprises over 77,000 sub-illustrations (a complete enumeration of all possibilities from which the user/reader chooses). Another illustration animates an actual backtrack search as the algorithm runs, to find all solutions to the problem at hand. The reader/user can change pruning strategies as it searches.
All the illustrations are dynamically built by compiled code and drawn at read-time, not at typesetting time. The book's TeX source code thinks it is incorporating PDF files, but the PDF file names are mapped into objects compiled into the client app. Each such illustration object reports back what its bounding box is on any page, and the the JSBox interpreter reserves the space and continues typesetting away in its usual TeX way. The illustrations and all their attendant interactive controls are built and drawn later in the reserved area when the user first turns to that page. Each illustration is zoom-able independently of the simulated page it is on, which nicety PDF doesn't do.
This design allows my app to be distributed as a (mere!) 7MB download in size (and 2MB of that was added by Apple), whereas an equivalent eBook app with PDF or SVG illustrations and MOV animations (for my particular purposes), would otherwise be many, many gigabytes of data.
The idea is to allow a GUI app, coded to draw anything on the device screen in some view, and having any kind of user interface controls and gestures with respect to that interface, to simultaneously surround itself with a set of book (or manual) pages having TeX-quality layout and math.
I've signed up to give a demo of this self-typesetting app/book, and talk about some interesting TeX-related issues, at the upcoming 2019 TUG conference in August.
Onward, into the fog ...
- Doug McKenna
More information about the texhax