John Lam 1997 — 2026

Leaky abstractions and macro languages

I’ve been working rather extensively with TeX/LaTeX/ConTeXt over the past couple of weeks. For the uninitiated, this is an extremely powerful desktop typesetting system that’s been under development for over 25 years. Donald Knuth implemented the core TeX (pronounced “tech”) system that defines low-level typesetting commands and algorithms. Leslie Lamport implemented LaTeX, which is a set of macros that layer on top of TeX, and Hans Hagen implemented ConTeXt, which is a competing set of macros that layer on top of TeX.

I chose to work initially in LaTeX to avoid the complexities of dealing directly with TeX. In other words, I chose an abstraction over the core technology. In this way, I feel very much like a VB programmer who chose to use an abstraction (VB) that layers on top of the core technology (Win32) as opposed to say a C/C++ programmer who chose to speak directly to the underlying API.

There are certainly pros and cons to this approach. I was able to get a document produced very rapidly using LaTeX. However, my “hello, world” documents had very little relation to the documents that I really wanted to produce - a set of courseware for my company, ObjectSharp. My requirements didn’t fit into the abstractions defined by a couple of standard set of macro packages that I experimented with: the ubiquitous book class and the more powerful memoir class.

So I decided to look further. After a bit of digging in the TeX distribution that I used, MikTeX, I discovered ConTeXt. The sample documents (see the manuals) created under ConTeXt were beautiful - far better than most of the other macro packages that I had seen. So I decided to give ConTeXt a try even though I had already adapted my publishing system to generate LaTeX macros.

At first everything worked quite nicely. Then I wanted to do something simple that I had avoided while working with LaTeX: switch fonts. Fonts are something that neither LaTeX nor ConTeXt do a good job at defining an abstraction for. This led to two very pain-filled days where I attempted to wrestle with the TeX font system. The documentation is sparse, and at times misleading. There are many steps that must be followed precisely otherwise nothing works.

After many attempts and late nights, I finally have the magic incantation that allowed me to import arbitrary PostScript and TrueType fonts that I wanted to use to define the typefaces for my documents. But I still have no idea what I’m doing.

The abstraction that LaTeX and ConTeXt try to present to you is leaky, like all non-trivial abstractions. I don’t have the time required to study the underlying technology (TeX) that they attempt to abstract - I need to get my publishing system working so that I can go back to my real job - creating content. And I’ll take all sorts of shortcuts to try and get me there faster.

My experience with TeX/LaTeX/ConTeXt has given me far more appreciation for the typical day of a VB programmer. They need to understand just enough of the technology to get their jobs done - which in the end involve modeling some sort of business process, and very little with the technology itself.

My job at ObjectSharp is to reflect on my experiences learning a different technology and discover why certain elements caused me pain. When explaining .NET to students, I need to explain how the abstraction that they work with models the underlying technology. I need to explain to them how to figure out what’s going on when something doesn’t work as they expected it to. I need to tell them where to look for more information when they need to do something a little off the beaten path.

That’s the story that I would have loved to have heard about ConTeXt and TeX: how they relate to each other, a look at how TeX works, and details about the abstraction that ConTeXt layers over TeX. I would have loved to learn how to debug my scripts - instead of changing a parameter, recompiling and looking at the results. I would have loved to have some detailed documentation (or at least enough understanding to be able to make sense of the source code for the macros that weren’t documented).

One observation that I do take away from my experience is just how difficult it is to create a uniform API that responds predictably. ConTeXt is far better than LaTeX in this regard: it was developed as a single macro package and is far more uniform in its design than LaTeX.

It also has an awful lot of documentation that ships with the standard distribution. While the quantity and presentation of the documentation is impressive, the story that it presents is awful. It’s little more than a laundry list of features without anything to explain how the features tie together, or how those features are implemented on top of TeX. Furthermore, they don’t provide source code for the manuals, which makes it very difficult to copy-paste-and-tweak the examples.

But overall, I’m very impressed with what I can do with this technology. Hopefully our students will as well.

5 archived reader comments

Sanjay (2004-09-12)

I’ve been recently taking a look at the new Publicon app from Wolfram Research (the guys who make Mathematica). It looks like it gives you all the power of TeX and LaTex without many of the formatting headaches (at least on my first pass).

You may want to check it out too: http://www.wolfram.com/products/publicon/

Jeff Atwood (2004-09-13)

That’s why APIs should be usability tested just like applications.

Roland Kaufmann (2004-09-13)

I took a quick glance at their webpage; What these guys need is an interaction designer. Lot of talk about how you can create professionally-looking documents with ConTeXt, but virtually no cue on *how*. Most of their documentation read like your average Microsoft whitepaper. On the positive side though, the “This Way” magazine seems to be published with source code.

John Lam (2004-09-13)

Roland: what’s worse than the missing “how” (which is what I need right now) it’s missing the “why”. I also ran into a nasty dead-end using ConTeXt today and reverted to my existing LaTeX publishing system. One step forward, two steps back … :(

Sanjay: thanks for pointing out Publicon. It looks promising …

**** (2004-12-01)

You can also check some relevant pages in the field of…