đź“– How to typeset two texts in parallel on pairs of facing pages?

LaTeX has a package called reledpar, which allows parallel typesetting of critical editions. One of its features is the ability to typeset two texts in parallel on pairs of facing pages, which is extremely useful for bilingual editions: for example, the original text on the left (verso) side and the translation on the right (recto) side. Because often the length of the two texts is not the same, there are several options for synchronisation (see the documentation). The package also supports parallel typesettig in columns (on one page, as opposed to pairs of facing pages).

Is it possible to do the same in Typst? I didn’t find any obvious way to do so with the fundamental functionality provided by Typst itself, nor did I find any package for the said purpose.

1 Like

From a glance at the documentation and tex.stackexchange, it looks like the content of each facing pages or facing paragraphs has to be marked explicitly? See for example here (seems incredibly verbose, please post a better example if you have one!)

It doesn’t seem difficult to do that in typst… For example for each pair of left and right content, you could just use a grid with two cells? Or am I missing something?

The real challenge might be line numbering: I think the Typst 0.12 line numbering is only for the flow of text on the page, while here you’d want a more generic API for numbering lines in a block. (For paragraph numbering it seems easy if all the paragraphs are marked explicitly anyway.)

This is unfortunately impossible right now, at least from what I’ve seen.

I was looking into how pages are organized in the context of doing “folios” or “booklets” (texts that can be printed out and then put together in some way). There’s a package on Typst Universe (bookletic) that kind of does this, but as @sijo mentioned, you have to manually parse the pages and enter them separately.

I toyed with some of the introspection methods, but was unable to get the necessary output from Typst. In other words, I couldn’t figure out how to have Typst render a page and then be able to “place” that content somewhere else. I created an issue on bookletic’s GitHub page to discuss this a bit, so you can see in more detail what I attempted.

Any other solution I’ve seen or can figure out has this same limitation. Something like a box for each column can’t handle page breaks, so you’re still back to having to manually figure out where those page breaks would be and breaking things up accordingly.

It is an issue that the Typst devs are aware of (see here and here), but they’re still deciding whether to implement it. My impression is that they’re worried about feature creep, not unreasonably (and I posted on one of those issues basically saying that I agree with their concerns about this).

I think that, unfortunately, the best approach right now would be to render the two columns as either separate PDFs or separate pages within a given PDF, then use an external tool of some kind to combine them. For example, pdfcpu has a dedicated booklet command that will “convert” a PDF into something printable (by re-arranging the pages, basically).

This is definitely something I’m interested in figuring out too (bilingual texts are a large part of why I wanted to do folios/spreads in the first place). I’d be glad to help if you’re trying to sort it out in the context of a specific project, or if you’d like help coming up with a way to do this in general. So feel free to hit me up if I can be of assistance!

The package also supports parallel typesettig in columns (on one page, as opposed to pairs of facing pages

Somewhat related might be Synchronized multi-column layouts · Issue #2941 · typst/typst · GitHub, which is not too different from doing it on facing pages from a layout perspective.

1 Like

But isn’t this discussing something more fancy than what the LaTeX package is doing? I mean, if the user has to tag explicitly the content for each facing pages or facing paragraphs, it’s easy to do in typst (apart from the line numbering).

Example for numbered paragraphs in parallel columns:

#set page(width: 9cm, height: 10cm, numbering: "1")
#set par(justify: true)

#let lr-blocks = state("lr-blocks", 0)
#let block-number() = context text(0.8em, numbering("1", lr-blocks.get()))

#let lr-columns(a, b) = {
  lr-blocks.update(x => x + 1)
  grid(columns: (1fr, 1fr), column-gutter: 2em,
    place(left, dx: -1.5em, block-number()) + a,
    place(right, dx: 1.5em, block-number()) + b,
  )
}

#counter(page).step()  // start with page 2 (left page)
#lr-columns[ #lorem(10) ][ #lorem(20) ]
#lr-columns[ #lorem(35) ][ #lorem(25) ]
#lr-columns[ #lorem(10) ][ #lorem(15) ]

Example with facing pages, and line numbering reset for each page:

#set page(width: 6cm, height: 7cm, margin: 1cm, numbering: "1")
#set par(justify: true)
#let lr-pages(a, b) = {
  pagebreak(weak: true)
  set par.line(numbering: "1", numbering-scope: "page", number-margin: left)
  a
  pagebreak()
  set par.line(numbering: "1", numbering-scope: "page", number-margin: right)
  set text(red)
  b
}

#counter(page).step() // start with page 2 (left page)
#lr-pages[ #lorem(25) ][ #lorem(20) ]
#lr-pages[ #lorem(18) ][ #lorem(22) ]
]

What would be more difficult is to let typst do the page breaks automatically, but I don’t think the LaTeX package does that.

Also probably difficult would be to have continuous line numbering (not reset on every page).