Skip to content

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

@YDX-2147483647

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcjkChinese, Japanese, Korean typography.textRelated to the text category, which is all about text handling, shaping, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions