What if E-Books just had typst inside? An open source demo included

So, on one hand there is the long-standing interest in generating epub from typst.
And on the other hand, there is some work happening in the opposite direction, for the sake of superior typesetting possibilities, discussed on this forum (the topic is called “A typst based Ebook Reader”).

Which brings us to the question: what if we just had typst inside an ebook instead of html? After all, ebooks need reflowability, but they don’t really need instant reflowability; fast is quite enough. With that question in mind, I prototyped a bundling tool and an Android viewing app.

The simple python tool that bundles a folder of typst sources into a simplified epub-like structure is here: GitHub - antonbryl-code/epubst_misc: Helper files for epubst demo · GitHub

A small sample bundle together with its sources are included. I wholeheartedly apologize for the goofy portmanteau “epubst”; but all the less goofy ones I could think of are taken already.

The sources for an Android viewer that opens a epubst file and formats it to match the screen width (and recompiles if the screen width changes, e.g. through screen rotation) are here: GitHub - antonbryl-code/epubst_demo_app: Simple demo viewer for EPUBst (Android). · GitHub

It is a fairly minimalistic app, but it does the basic job at hand quite successfully.

If you are inspired to experiment with it, note that it relies on the assumption that the page layout is explicitly made overridable by the typst source (see the example supplied together with the bundling tool).

I think it is readily at least a useful format to make research papers and tech reports more convenient to read on mobile screens; if a researcher is writing their paper in typst, the effort of also creating a epubst from it is minimal.

I do not presume that I got every detail of the format right on the first attempt; but I hope it is a decent conversation starter.

Here are a couple screenshots:

3 Likes

The idea of a Typst-based eBook reader sounds promising.

We already have PDF viewers and ePub viewers. Each reads the output of some conversion tool that reads Markdown or Typst or whatever and converts to PDF or ePub.

I say your idea has merit. It would be great if your demo code would work on Linux and on macOS as well so people like me can explore the demo further.

1 Like

This is a cool idea and make me wonder … what is the smallest processor that can easily execute web assembly? Could a Raspberry Pi Pico be convinced to read .typ files from an SD card, run them through the Typst compiler, then drive a display with the results?

Maybe it would be easier to start from the Rust source instead of web assembly.

1 Like

(post deleted by author)

My own setup is Windows on laptop and Android on the phone, so I cannot easily contribute to the versions you need; but I will be happy to help with structure if someone decides to code it (or with prompts is someone decides to vibecode it, it is straightforward enough for a coding agent to do most of the work).

The Android demo linked in the post uses rust, it seemed like an easier option indeed.