typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
34.81k stars 927 forks source link

Unexpected behaviour of runt cost with long words #5238

Open EpicEricEE opened 2 weeks ago

EpicEricEE commented 2 weeks ago

Description

When setting the runt cost to an extremely high value, I would expect there to always be at least two words in the last line. However, it seems that when the last word is so long that it contains a hyphenation opportunity, it doesn't "glue together" the last two words, but instead the last two parts of the hyphenated word. For example:

#set page(width: 100pt, height: auto)
#set text(costs: (runt: 1000000000000000000%))
#set par(justify: true)

// Works as expected, as "bad" is short
is it good or is it bad 

// Doesn't work as expected, "issue" is alone on its line, as it can be hyphenated as "is-sue"
is it good or is it issue

// Works as expected, as boxes can't be hyphenated
is it good or is it #box[issue]

// Doesn't work as expected, "malicious" is even hyphenated
is it good or malicious

image

(Also tested after 711a2d88079f0b3929bbb6be97bda52139e22aa1)

Reproduction URL

No response

Operating system

Web app

Typst version

Enivex commented 2 weeks ago

While the runt cost is high, the cost of the resulting extremely awful word spacing on the first line may be bad enough to offset that.

(I'm only speculating.)

EpicEricEE commented 2 weeks ago

While the runt cost is high, the cost of the resulting extremely awful word spacing on the first line may be bad enough to offset that.

When using an equally long monosyllabic word (e.g. "scratched" instead of "malicious"), the awful word spacing is accepted, so I think it has something to do with hyphenation.

image

laurmaedje commented 2 weeks ago

Ah yeah, hyphenation makes sense. When there is a hyphenation opportunity, it's not considered unbreakable by the layout engine and does not count as a runt.