Hi. I’d like to submit a PR that alters layout/inline/mod.rs to support balanced ragged text. While Typst does allow for Knuth-Plass to be used for ragged text, the current implementation does not take into account the glue stretchability at the end of the line, and fn commit() does not allow non-justified text to expand slightly.
Here is a comparison, before:
And after:
There are two options that I’d like to add to the parameter #par(linebreaks: ()):
raggedness – Line-final glue stretchability. Larger values would result in more ragged text, lower values more balanced. This would only apply to non-justified text.
last-line-raggedness – Paragraph-final glue stretchability. Low values would make the last line more balanced with the other lines, and a value of zero would be desirable for headings (see issue #2814). This would apply both to justified and non-justified text.
This change can either be implemented by simply adding these glue stretchability values to line.stretchability(), or, if we want to follow Knuth’s paper, by using negative glue, see page 1139.
I’ve implemented the same functionality in JavaScript here if you wish to see how these parameters can be used for different ragged-ness.
Hi. I’d like to submit a PR that alters
layout/inline/mod.rs
to support balanced ragged text. While Typst does allow for Knuth-Plass to be used for ragged text, the current implementation does not take into account the glue stretchability at the end of the line, andfn commit()
does not allow non-justified text to expand slightly.Here is a comparison, before:
And after:
There are two options that I’d like to add to the parameter
#par(linebreaks: ())
:raggedness
– Line-final glue stretchability. Larger values would result in more ragged text, lower values more balanced. This would only apply to non-justified text.last-line-raggedness
– Paragraph-final glue stretchability. Low values would make the last line more balanced with the other lines, and a value of zero would be desirable for headings (see issue #2814). This would apply both to justified and non-justified text.This change can either be implemented by simply adding these glue stretchability values to
line.stretchability()
, or, if we want to follow Knuth’s paper, by using negative glue, see page 1139.I’ve implemented the same functionality in JavaScript here if you wish to see how these parameters can be used for different ragged-ness.