-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Over/underlines extend to CJK-Latin spacing unexpectedly #7475
Description
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[五日] // ✅
More examples
#set text(font: "Noto Sans CJK SC")
- M#underline[五日]M
- M #underline[五日] M
- 日#underline[Mn]日
- 日 #underline[Mn] 日
Analysis
Cause
Runge commented on 2025-11-26 (translated from Chinese):
This is basically because
add_cjk_latin_spacingdoes not actually insert spacing. Instead, it adds padding to the Han characters by setting itsx_advanceandoffset.
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.