Skip to content

Start of line CJK right-aligned punctuation and non-zero tracking causes left overhang #8959

Closed

Description

@chinzhening

Description

Minimal example to reproduce the issue

#set page(width: 5em)

#for sp in (0em, 0.1em, 0.2em, 0.5em, 1em) {
  block(
    width: 100%,
    fill: yellow,
    {
      set text(tracking: sp, overhang: false)
    [「我」]
    },
  )
}
Image

What I think is happening

location: typst-layout/src/inline
line.rs/adjust_cj_at_line_start shrinks the first right-aligned cjk punctuation glyph on the left through
shrink_left.

The shrink amount is calculated in shaping.rs/calculate_adjustability which calls base_adjustability.
Currently, this sets the shrink left to amount for cjk right aligned punctuation to glyph.x_advance/2.0. Since track_and_space is executed before calculate_adjustability which increments x_advance by tracking...
right aligned CJK punctuation at the start of a line will be offest by an additional tracking/2.0 to the left.

Possible fix

@YDX-2147483647 outlined a possible fix at typst-doc-cn/clreq/#136

Operating system

Windows, Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Oct 16, 2026
  2. changed the title [-]Start of line CJK right-aligned punctuationand non-zero tracking causes left overhang[/-] [+]Start of line CJK right-aligned punctuation and non-zero tracking causes left overhang[/+] on Oct 16, 2026
  3. added
    text
    cjk
    on Oct 20, 2026
  4. YDX-2147483647 commented on Oct 27, 2026

    @YDX-2147483647
    Contributor

    Although this issue has been (and should be) closed after #8985, I want to mention that the result of this case is probably still problematic.

    A member of the W3C's Chinese Layout Task Force once posted an image in w3c/clreq#454, implying that tracking should not affect the distance between the brackets and the texts inside the brackets, or at least the distance should be much shorter than tracking. Personally, I also think that would look nicer.

    The following image illustrates the difference between Typst v0.15.1, Typst main and that approach:

    Image
    Code
    #set text(
      lang: "zh",
      font: "Noto Serif CJK SC",
      top-edge: "ascender",
      bottom-edge: "descender",
    )
    #set page(width: auto, height: auto, margin: 2em)
    #set raw(lang: "typc")
    
    #show: block.with(stroke: (left: green))
    
    = Default result for v0.15.1
    「一」文钱「十」个
    
    = Use `0.75em` tracking with v0.15.1
    #text(tracking: 0.75em)[「一」文钱「十」个]
    
    = Use `0.75em` tracking after \#8985
    // This part should be compiled with `main` (64c5e8c0).
    #text(tracking: 0.75em)[「一」文钱「十」个]
    
    = Ideal result
    #{
      let tracking = 0.75em
      let w = 0.4em // The width of `」`, with visual effects compensated
      show ".": h(calc.max(0em, tracking - 1em + w))
      [「一」.文#h(tracking)钱.「十」.个]
    }

    However, it is quite uncommon to use punctuations with nonzero tracking in Chinese documents. It seems that even CLReq has not seriously discussed about it yet. Therefore, I think we can leave it like this for now. Before CLReq updates, I don't think creating a separate issue would be of any use either.

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

    bugcjktext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions