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

I may be mistaken but perhaps have a look at How to provide assets (image files) with a template so that they could eventually be overwritten? - #2 by vmartel08

1 Like

Yes, that’s what I have in mind.

Erna 0.2.0 is out!

This version addresses the issue where passing a relative path to an image results in wrong absolute path resolution. The solution is to pass content, not paths to images, like this:

#import "@preview/erna:0.2.0"

#erna.multiple-rows(
    gutter: 20pt,
    (
        image("opossums-in-a-row.jpg"),
        image("opossum-in-a-tree.jpg"),
    ),
    (
        image("baby-opossum.webp"),
        image("ninja-opossum.jpg"),
        image("opossum-with-teeth.jpg"),
    ),
)

This opened another issue: what if a user passes content that is not an image. After some tinkering, this is now possible and seems to work correctly. So now Erna can lay out any kind of content, or at least many different kinds, like images, shapes, text, etc. Here is a simple example:

#import "@preview/erna:0.2.0"

#erna.multiple-rows(
    gutter: 20pt,
    (
        image("opossums-in-a-row.jpg"),
        image("opossum-in-a-tree.jpg"),
    ),
    (
        rect[
            I think\
            opossums are\
            _really_ cool
        ],
        image("ninja-opossum.jpg"),
    ),
    (
        image("baby-opossum.jpeg"),
        image("opossum-with-teeth.jpg"),
    ),
)

A few more elaborate examples are in the preview document.

Handling content other than images was complicated by this bug:

Eventually I found a workaround, but it took me some time to understand what’s going on.

Because Erna is not only about images now, I renamed the two functions:

  • erna.image-row → erna.row
  • erna.image-rows → erna.multiple-rows

I hope this also makes the difference between them more clear.

Overall, what started as an annoying bug, resulted in a substantial expansion of useful features. I’m quite pleased with the result. The Typst community is very friendly. Thanks to everyone involved! Please let me know if you find Erna useful or have any questions.

7 Likes

In Typst 0.15.0 the path type was added. It is resolved relative to where it is called (e.g. user code) and can also be passed to packages, allowing them to read the file.

That would solve your issue. However, your approach of supporting any content for Erna 0.2.0 is probably even better because it allows customizing how the images are loaded, or as you mention even using arbitrary non-image content.


As side note: It looks like your package currently publicly exports your complete implementation, including seemingly internal functions such as aspect-ratio or solve. You can avoid that by placing your implementation in a separate type Typst file and then only importing (and effectively re-exporting) only the public API in the entrypoint Typst file, see also packages/docs/typst.md at main · typst/packages · GitHub.

2 Likes