Disallow line break in custom cite suffix and multi-cite in custom cf cite command

Hi Typst community!

I can use @bohnsack2013handbuchprint[p.~213] and “p. 213” will always be on the same page. But I have a custom cite command to also support a prefix (and optionally also a suffix).

#let settings = (citation-style: "apa",)
#let pre-cite(..args, prefix: none, suffix: none) = {
  // If no prefix or suffix, call standard cite and stop.
  if prefix == none and suffix == none {
    cite(..args)
  } else {
    "("
    // Optional Prefix: Removed the invalid # before 'if'
    if prefix != none {
      prefix
    }
    // The standard citation output: Removed the invalid # before 'cite'
    cite(..args, form: "author") 
    ", "
    cite(..args, form: "year")
    // Optional Suffix: Removed the invalid # before 'if'
    if suffix != none {
      ", " + suffix
    }
    ")"
  }
}
#let cf = pre-cite.with(prefix: "cf. ")

2 problems with that approach

  1. Now I can use #cf(<deckerernst2018>, suffix: "pp. 23-25") to nearly achieve the desired result: “(cf. Decker-Ernst, 2018, pp. 23-25)”. But If the “pp. 23-25” is at the end of the line, it may break into “pp.” on the end of the line and “23-25” on the next line - that’s not what I want. But it seems that I can also not include “~” because it’s simply printed in the resulting PDF.
    I understand that there is currently no @deckerernst2018[prefix][suffix] but this would be really helpful here :slight_smile:
  2. For normal citations, I can combine multiple @entry1 @entry2 @entry3 to result in a proper citation in text. If I use my custom #cf(<deckerernst2018>, suffix: "pp. 23-25"), I don’t find a way to add multiple other bibliography entries (easily). Currently, I am using a very cumbersome and hacky solution (cf. #cite(<Przyborski.2021>, form: "author"), #cite(<Przyborski.2021>, form: "year", style: "iso-690-author-date"); #cite(<Bohnsack2014>, form: "author"), #cite(<Bohnsack2014>, form: "year"); #cite(<Nohl.2017>, form: "author"), #cite(<Nohl.2017>, form: "year")) to achieve “(vgl. Przyborski & Wohlrab-Sahr, 2021; Bohnsack, 2014; Nohl, 2017)”.

Do you have any idea how to fix that situation?

The first problem is easy to solve: just wrap suffix in a box, "," + box(suffix), if you want to disable any linebreaks inside suffix (or prefix).

The second problem, I think, can be solved if you will pass the list of labels to cite as an argument to your precite function. You would need to manage these arguments the right way, so that you can separate labels and their supplements. For example, you could pass an array of arrays, like ((label1, supp1), (label2, supp2)), and add a for loop inside precite to iterate these arrays. That wouldn’t be perfectly convenient, but still something not that bad.

Another fix for the first problem is to use content instead of a string: suffix: [pp.~23-25]. In square brackets you give markup, so ~ works there.