Overflow for large space-less strings (e.g. license keys)

I am trying to create a box containing a license key which is too long to fit in a single line. It does not contain any breaks and therefore has to be wrapped into multiple lines. But instead it just runs out of the page. I do not want hyphens in the resulting string nor line-breaks which are preserved when the string is copied out of the document.

How can I achieve this?

What you can usually do is to to intersperse the text with zero width spaces. Then wrapping is allowed after any letter.

#let wrap-text(body) = {
  // alt: h(0.1pt) as separator
  show regex("\\w+"): it => it.text.clusters().intersperse(sym.zws).join()
  body
}
#box(width: 3cm, stroke: 1pt, outset: 0.5em, wrap-text[EoHVbSe8Baj3CU6MDUjudtaq])

However, this can interact weirdly or not well with text selection in the PDF. An alternative “symbol” to put inbetween is a thin space like h(0.1pt) which worked slightly better with selection in the PDF in the PDF viewer I tried. You will probably always have a space in the selection at the line break though.

Issues to improve

  • Best separator for allowing wrapping but treated as contiguous text for selection? Including the line break?