You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Over/underlines extend to CJK-Latin spacing unexpectedly #7475
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.
#settext(font: "Noto Sans CJK SC")
- #underline[五日]M // 😓
- #underline[五日] M // ✅
- #underline[五日] // ✅
More examples
#settext(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_spacing does not actually insert spacing. Instead, it adds padding to the Han characters by setting its x_advance and offset.
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.
…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.
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 Glyphoffset and/or x_advance, so width will contain them, and during iteration of decorate, glyph metrics will also contain them.
Activity
RungeCC commentedon Nov 26, 2025
More explanation on this:
Typst (in
typst_layout) callsdecorateto add decoration elements such as underline after shaping frame is built, in which step newGlyphis created whosex_advanceandx_offsetare based on shapedShapedGlyph, already adjusted inpreparation. Duringpreparation, cjk-spacings are inserted asGlyphoffsetand/orx_advance, sowidthwill contain them, and during iteration ofdecorate,glyphmetrics will also contain them.docs: Regular minor updates