Imaginary Text

More on Typst

JMaxMay 6, 2024 colophon, typography

Last November I wrote a post about my experimentation with Typst – a new (as of last year) open-source typesetting software that aims to (a) effectively replace LaTeX in its niche and also bring a modern, free tool to a broader set of use cases. I’ve been playing with it more this spring for various things, and last week I stumbled into a small project where I put it through its paces properly: a proper book layout.

I was on a regular, bi-monthly zoom call with a set of esteemed colleagues; when this group meets, the first order of business is to report on what we’re all reading.[1] This is usually pretty interesting, and this time was no different: I collected four of five browser tabs of the most interesting things people mentioned.

One in particular was Charlotte Anne Moberly and Eleanor Jourdain’s 1911 book, An Adventure, in which, writing under pseudomyms (because of course), they tell the story of a weird paranormal experience they had visiting the Petit Trianon at Versailles – which they took to be something like a time-travel experience back to the time of Marie Antoinette, or at least a projection through time of Marie Antoinette’s memories. The basic story is summarized well enough in Wikipedia’s Moberly-Jourdain Incident.

Following this recommendation, I went to Project Gutenberg to grab the etext. Passing up the EPUBs, I opted, as I usually do, for the plain text version. It occured to me, then and there, that I could run the thing through Typst and have a go at some provisional typesetting. Which is to say: I stopped thinking about this as literature, and started thinking of it as fodder my my text-processing habit.

I’ve done this many times before: for my course on Text Processing at DHSI I typically go to Project Gutenberg for books to fold, spindle, manipulate (we even used to make EPUBs out of them ourselves). I know from experience that it’ll take me about 10 minutes in a text editor to clean and polish a Project Gutenberg text into a markdown-formatted ‘fair copy’ that we can then build upon.

While I was doing this with An Adventure it suddenly dawned on me what this book was. Last year, during the many months of reading Proust, I spent a lot of time with Wikipedia, reading about the sources of that text. I learned, for instance, that the Baron de Charlus, one of the most dramatic figures in Proust’s massive novel, is likely based on a historical character – Robert de Montesquiou – who also likely inspired Huysman’s Against Nature and possibly even Wilde’s Picture of Dorian Gray. Montesquiou is also significant (not just because of his charming portraits with cats) because there’s a pretty solid explanation of the “Moberly-Jourdain Incident” that suggests that these two English ladies did not time travel into Marie Antoinette’s brain circa 1792 so much as they stumbled upon one of Montesquiou’s masquerade parties, and the weird reactions they experienced were more or less what you might expect if a couple of English rubes wandered blithely into a party populated by some of the more colourful characters of Parisian society.

Inspired somewhat by the text, I dug in to Typst, and managed to come up with a template that does a decent job of proper book typography. Not that this is particularly needful thing in the world, except that I do teach Publishing to young folks who will go on to publish books, and as such I find it a little bit heart warming to be able to open up the possibility of not having to rely on the Adobe Creative Suite to do so. To be able to do a full treatment on a book, at a professional level, using only free tools, is a big deal for me and the people I hang around with.

Don’t get me wrong: I am no book designer, nor do I have any particular talent in that direction. But I am at least educated in this, and I think I know a bit about how the job is done. So what I’ve produced in Typst is a basic boilerplate template for the job, easy enough to tweak and evolve it for specific purposes or to the taste of an actual Book Designer. You can judge for yourself here – this is set on 5½ x 8½" pages, in case you wanted to print this on your laser printer and cut the sheets in half (no, I don’t suppose you do).

Download An Adventure – (PDF 854k)

The method here is significant. Typst can be used as hand-coded source – the same way science students have always written their theses in LaTeX. But my approach is rather to start with squeaky-clean text in markdown format, and process it with Pandoc. Pandoc can output typst code (and continue to drive typst to produce the final PDF), and Pandoc will take a named template to manage the process. That’s what I’ve built here: a template for auto-conversion from markdown, through Pandoc, to Typst, to PDF.

The template is, I think, not half bad. It’s 270 lines of code (including a chunk of Pandoc boilerplate) that define things like page size and margin, paragraph typography, headings, quotations, running headers and footers, images, footnotes, a title page, and a compiled table of contents. Now that I’ve built it, the code seems trivial and easy to modify: I did fight pretty hard through Typst’s as-yet basic documentation to get to the point where all of this worked like I wanted. But it does now, and frankly, it works pretty well. An Adventure is actually a good test case: it has five images, 145 footnotes, and a tangle of nested lists (I went back to the scanned version on Internet Archive to sort out what some of the lists were trying to be). Beyond just sorting out how to express myself correctly in Typst code, everything I wanted to do was pretty much ‘on tap.’

Download typst-book.template (txt 6k)

Typst’s significant weakness is still in widow and orphan control: it lacks any kind of fine-tuning around how it keeps lines together, but given the rapid development of the software I think they’ll get that sorted soon enough. Typst’s documentation, while thoughtfully written, is still minimal, especially for template construction like I’m doing here – I hope this too improves, so that we can all hack out way to nice type.


  1. Currently I’m currently on Edith Grossman’s translation of Don Quixote. ↩︎