Erna - a Typst library to scale and align rows of images

I’ve recently discovered Typst, immediately fell in love, and as a way of learning it, I’ve put together a little library. I called it Erna. You can check it out here:

Given some images it:

  • fills all the available width;
  • arrange the images in a rectangle;
  • preserve all aspect ratios.

Like this:

So I want to show and tell, but I also have a few questions.

Am I re-inventing the wheel?

It would be ok, since it was a learning project and a brain-teaser for me, but after cursory research I couldn’t find anything that does what I want. The closest I could find is tessera – Typst Universe, but I don’t think it can keep the cells in a row equally high. Also, because it’s more general-purpose, its API seems more complicated. With Erna I aim for simplicity and non-tech-user friendliness, even at the expense of flexibility.

Code review

I’d appreciate any pointers regarding my implementation. Esp. around the solve function. What I’m currently doing is representing the problem of finding the height and width of every cell as a set of linear equations. I think there is a straight-forward way to solve them, but I haven’t figured it out yet. So instead Erna is recursively dividing the range of possible heights until it reaches approximately right result. It seems performant enough. See the playground.pdf document in the repository to follow my somewhat convoluted thought process.

If there is a better approach, how could I benchmark it against the current one?

Is Erna a promising material for a package?

If it’s not re-inventing the wheel, and the code is not entirely rubbish, should I try to publish it as an @preview package? Any tips on that?

5 Likes