How to prevent linebreaks before `em` dashes?

I’m trying to prevent em dashes from starting a line, i.e. prevent linebreaks before em dashes. I think that’s the default behavior in TeX.

Right now the behavior in Typst is that linebreaks can happen both before and after the em dash.

#set page(width: 9em, height: auto)
#set par(justify: true)
#set text(overhang: true, hyphenate: true)

I'm trying to only allow linebreaks to happen after em dashes---it looks better
to me.

I know it’s possible to manually prevent the linebreak with #sym.wj

#set page(width: 9em, height: auto)
#set par(justify: true)
#set text(overhang: true, hyphenate: true)

I'm trying to only allow linebreaks to happen after em dashes#sym.wj;---it looks better
to me.

but is there a better way to apply it automatically, like replacing --- with #sym.wj;--- so I don’t have to do it manually?

Use a text show rule:

#set page(width: 9em, height: auto)
#set par(justify: true)
#set text(overhang: true, hyphenate: true)

#show sym.dash.em: it => sym.wj + it

I'm trying to only allow linebreaks to happen after em dashes---it looks better
to me.

This will compile slower the more em dashes there are. Though you’d need to use 100 000 for it to compile 37% slower, while still taking less than 2 seconds.

1 Like