Skip to content

Over/underlines extend to CJK-Latin spacing unexpectedly #7475

Open

Description

@YDX-2147483647

Description

If an overline or underline starts or ends with a Han character, and it's adjacent to a Latin letter, then the line will extend to cover the CJK-Latin spacing, which is unwanted.

May relate to #1716.

Workaround: putting an explicit space.

#set text(font: "Noto Sans CJK SC")


- #underline[五日]M // 😓
- #underline[五日] M // ✅
- #underline[五日] // ✅
Image

More examples

#set text(font: "Noto Sans CJK SC")

- M#underline[五日]M
- M #underline[五日] M
- 日#underline[Mn]日
- 日 #underline[Mn] 日
Image

Analysis

Cause

Runge commented on 2025-11-26 (translated from Chinese):

This is basically because add_cjk_latin_spacing does not actually insert spacing. Instead, it adds padding to the Han characters by setting its x_advance and offset.

Desired result

Translating from Chinese in w3c/clreq#716 (comment):

The underline is by default of the same length as the character frame. When two underlines are adjacent, the length of the adjacent side is shortened to visually separate and distinguish them, while the length of the other side remains unchanged.

Additional info

Reproduction URL

No response

Operating system

Web app

Typst version

  • I am using the latest version of Typst

This issue was originally reported by 差 on 2025-11-26.


Edit on 2026-12-20: #7521 has just been rejected.

…this patch (#7521) is too hacky and introduces too much maintainability burden.
What it really shows me is that the CJK-Latin spacing should not be considered part of the glyph advance in the first place, but rather be handles as a separate spacing item or similar, that's inserted.

Activity

  1. added
    bug
    on Nov 26, 2025
  2. RungeCC commented on Nov 26, 2025

    @RungeCC
    Contributor

    More explanation on this:

    This is basically because add_cjk_latin_spacing does not actually insert spacing. Instead, it adds padding to the Han characters by setting its x_advance and offset.

    Typst (in typst_layout) calls decorate to add decoration elements such as underline after shaping frame is built, in which step new Glyph is created whose x_advance and x_offset are based on shaped ShapedGlyph, already adjusted in preparation. During preparation, cjk-spacings are inserted as Glyph offset and/or x_advance, so width will contain them, and during iteration of decorate, glyph metrics will also contain them.

  3. added
    text
    cjk
    on Nov 26, 2025
  4. added a commit that references this issue on Dec 13, 2025
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