You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Text non-zero tracking with paragraph justify: true creates gutter on right side #8931
Setting non-zero tracking on text will leave additional space on the right side of a justified paragraph. As per the tracking documentation, it should add space between characters, not after every character.
Note hyphenated words' - are correctly justified.
Example:
#setpage(width: 10cm)
#setpar(justify: true)
#settext(overhang: false)
// text fills entire width#block(
width: 100%,
fill: green,
lorem(50),
)
// leaves a space on right side, when line ends with a non-hyphenated word#block(
width: 100%,
fill: red,
{
settext(tracking: 0.5em)
lorem(50)
},
)
Operating system
Web app, macOS
Typst version
I am using the latest version of Typst
Reacted by Liara, Bastien Voirin and Chin Zhe Ning
Hi, may I take this? This would be my first time contributing to Typst, and I am unsure how good of a first issue it would be given that a fix will touch typst-layout/inline/line.rs when line attempts are generated. I'd like to give it a try!
Based on my understanding, tracking is added to each glyph’s x_advance in track_and_space, after shaping. When a line is built from a slice of the shaped text, the last glyph of the line can still carry tracking from the character that followed it (usually the trimmed space). Line breaking uses the line’s width to compute cost, so this trailing tracking is counted even though it isn’t part of the visible line. With justification, it also shows up as extra space at the right edge.
Since line breaks are only known once line attempts are generated, line() in typst-layout/src/inline/line.rs seems like the right place to correct this, next to the other line-end adjustments. The proposed fix is to subtract the tracking from the last glyph of the line’s trailing text item.
The difficulty is that not every trailing glyph has tracking applied. For example, the last run of a paragraph, and also the situation where a hyphen added at the line end. Subtracting in those cases would make the line too narrow, so I need a way to tell whether the last glyph actually received tracking. I could add a flag to ShapedText set where the text is sliced, but I’m not sure that’s the right design. Is there an existing way to check this, or would you prefer another approach?
happy to open a draft PR. Any guidance is appreciated, thanks!
Activity
chinzhening commentedon Oct 10, 2026
Hi, may I take this? This would be my first time contributing to Typst, and I am unsure how good of a first issue it would be given that a fix will touch
typst-layout/inline/line.rswhen line attempts are generated. I'd like to give it a try!chinzhening commentedon Oct 12, 2026
Based on my understanding, tracking is added to each glyph’s
x_advanceintrack_and_space, after shaping. When a line is built from a slice of the shaped text, the last glyph of the line can still carry tracking from the character that followed it (usually the trimmed space). Line breaking uses the line’s width to compute cost, so this trailing tracking is counted even though it isn’t part of the visible line. With justification, it also shows up as extra space at the right edge.Since line breaks are only known once line attempts are generated,
line()in typst-layout/src/inline/line.rs seems like the right place to correct this, next to the other line-end adjustments. The proposed fix is to subtract the tracking from the last glyph of the line’s trailing text item.The difficulty is that not every trailing glyph has tracking applied. For example, the last run of a paragraph, and also the situation where a hyphen added at the line end. Subtracting in those cases would make the line too narrow, so I need a way to tell whether the last glyph actually received tracking. I could add a flag to
ShapedTextset where the text is sliced, but I’m not sure that’s the right design. Is there an existing way to check this, or would you prefer another approach?happy to open a draft PR. Any guidance is appreciated, thanks!