Is it possible to disallow putting dashes on new lines

Hi! According to rules in Ukrainian rules, it is disallowed to put dashes on new line (I expect this rule to exist in other languages too).

However, Typst puts dashes on new line, example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore - lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore -- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore --- lorem ipsum dolor sit amet.

Is it possible to customize this behavior? Or some kind of workaround?

Okay, here is a workaround:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut \ labore - lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut \ labore -- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut \ labore --- lorem ipsum dolor sit amet.

But is there a way to not edit text? Would that be a relevant feature in Typst?

This is not the best workaround, as if text is justified, then it won’t be justified with backslash:

#set par(justify: true)

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt uta \ labore - lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt uta \ labore  -- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut \ labore --- lorem ipsum dolor sit amet.

Though, I expected something like:

Here is another workaround, but it doesn’t work with the equation as shown in the example. If you in fact want non-breaking spaces you could also consider typing them out. Their shortcut is ~ in markup.

#show: block.with(width: 16.0cm, stroke: 0.3pt)
#set text(lang: "uk")
#show regex("\b -"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b –"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b —"): it => it.text.replace(" ", sym.space.nobreak)
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore - lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore -- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore --- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut $x = 1$ --- lorem ipsum dolor sit amet.


If you really want justification at a linebreak you can use #linebreak(justify: true) for that but it doesn’t produce very nice results. It will stretch the line as far as necessary in that case.

1 Like

Thanks! It works very well for my case!

I’m not sure if the topic should be closed though

The \b in my regex is probably not needed. And the equation use case would maybe have to use a typed out ~. (It seems to be the case that the space after the equation is not reachable in a regex rule, at least not matching the space together with the m-dash)

I also found another exceptional case when I use “code-style” formatting:

#set text(lang: "uk")
#set par(justify: true)

#show: block.with(width: 16.0cm, stroke: 0.3pt)

#show regex("\b -"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b –"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b —"): it => it.text.replace(" ", sym.space.nobreak)

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore --- lorem ipsum dolor sit amet.

lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem: `eiusmods` --- `lorem` --- `lorem`;

But if I use ordinary font, then there is no problem:

#set text(lang: "uk")
#set par(justify: true)

#show: block.with(width: 16.0cm, stroke: 0.3pt)

#show regex("\b -"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b –"): it => it.text.replace(" ", sym.space.nobreak)
#show regex("\b —"): it => it.text.replace(" ", sym.space.nobreak)

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore --- lorem ipsum dolor sit amet.

lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem: eiusmods --- `lorem` --- `lorem`;

Here’s one thought - it will depend on how consistent your document is, but it’s better if you have a command that expands to non-breaking spaces and the hyphens. If en and em-dashes always have spaces around them you could enforce that like this but type them without spaces… Hyphen is trickier because it might have multiple uses (the en-dash too, I realize).

#show "-!": it => [~- ]
#show "–": it => [~#it ]
#show "—": it => [~#it ]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore-!lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore--lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore---lorem ipsum dolor sit amet.
1 Like

Hi. If this is a nation-wide adopted rule, I would assume that it should just work with set text(lang: "uk"). If it doesn’t, then maybe it’s a new feature that can be added. Not sure.

2 Likes

Hi! Sorry, should’ve tried setting the language the first time.

#set text(lang: "uk")

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore - lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore -- lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore --- lorem ipsum dolor sit amet.

Yep, it doesn’t work with #set text(lang: "uk") too

It was tried as one of the first things too :wink:

You already did.

I’m aware, that’s why I’m saying this could be a bug or something that is not yet implemented.