Skip to content

Text non-zero tracking with paragraph justify: true creates gutter on right side #8931

Closed

Description

@jean-dao

Description

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:

#set page(width: 10cm)
#set par(justify: true)
#set text(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,
  {
    set text(tracking: 0.5em)
    lorem(50)
  },
)
Image

Operating system

Web app, macOS

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Oct 6, 2026
  2. added
    text
    on Oct 6, 2026
  3. chinzhening commented on Oct 10, 2026

    @chinzhening
    Contributor

    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!

  4. chinzhening commented on Oct 12, 2026

    @chinzhening
    Contributor

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions