How to have line breaks in source matter for poetry, liturgy, and ancient texts?

I do various documents which have poetry, or liturgy, or ancient texts. Some common elements with all three of these are that the line breaks matter, and there are often reasons to have a tab stop (or multiple tab stops). For example, with ancient texts and poems it is often useful to have line numbers, and in poetry and liturgy alternate lines might be indented further. In theory I could use a grid but the advantage of plain text disappears when the text is placed into array syntax. (I also noticed that the normal line spacing gets lost when I put text into a grid.)

I imagine that if I were more capable with typst, I could create a function which uses tab characters (or space-alignment) to split up a lines of text into grid cells, but I don’t know how to do this, and I also wonder if this kind of functionality could be quite useful to others?

1 Like

Grid sounds interesting, what do you use grid alignment for, and what are the tab stops for?

I started some simple work on it here, for poems: greenwood-tree · main · bluss / typst-recipes · GitLab and any feedback would be appreciated.

The approach used is to have a raw block in the Typst source to deliver the poem text as just a string, with linebreaks preserved, and then evaluating markup line by line after splitting the source text into lines. It has its limitations.

I have since rewritten it all using elembic for styling instead but it is not yet public. If you or someone was interested we could collaborate to publish this as a package!

(Next week sonetime I’ll be able to share the updated version.)

2 Likes

I believe you could find this post interesting: How to force line breaks without extra spaces
Is this where your package started from @bluss :smiley:?

Yes it did. Since then I think that a show rule on raw is not useful, that inherits the default style settings in a way that’s not easily reversible, a better design is to take a raw block as a body argument in a function, and that’s what the new version does.

@bluss I’m very interested in your package on GitLab. It looks like it covers most of what I’m keen to produce. I am not sure that I am able to contribute much in terms of code, but I can contribute examples if that might be of use?

1 Like

I’ve updated the code in the link, so it now has the version that uses elembic. The output is the same, but the style configuration uses elembic and it has more flexibility, although that mostly affects the stanza and line numbers.

Examples and usage questions/suggestions/feature requests are very welcome, that’s a good way to collaborate too.

The alternate approach in How to force line breaks without extra spaces - #12 by nleanba I’ll need to explore - that’s much more flexible about markup. It’s something I rejected early on but maybe not for good reasons (it doesn’t work with multiline code, but the current solution doesn’t either!); let’s see how it works with line numbering.

1 Like

Very cool!

I wonder if this might be interesting as a comparison package:

One thing I also want to do is include a fixed indentation level after text (i.e. tab stops. The kind of output I’m trying to create is in this PDF attachment, which is not an uncommon layout for this kind of liturgical text.

MP CW short.pdf (248.4 KB)