Skip to content

Fix uneven CJK-Latin spacing in justified paragraphs#7606

Merged
laurmaedje merged 1 commit intotypst:mainfrom
ryuryu-ymj:main
Jan 20, 2026
Merged

Fix uneven CJK-Latin spacing in justified paragraphs#7606
laurmaedje merged 1 commit intotypst:mainfrom
ryuryu-ymj:main

Conversation

@ryuryu-ymj
Copy link
Contributor

Fixes #6062

This PR ensures that CJK-Latin spacing is applied evenly both before and after Latin glyphs when par is justified.

Previously, Latin glyphs followed by CJK characters were not marked as justifiable, leading to uneven spacing distribution.

Changes

  • Updated the add_cjk_latin_spacing function to set is_justifiable to true for Latin glyphs that are followed by CJ characters.

Testing

#set par(justify: true)
あaあ#linebreak(justify: true)
ああaa aaああ#linebreak(justify: true)

before
before

after
after

@laurmaedje laurmaedje added layout Related to the layout category, which is about composing, positioning, etc. text Related to the text category, which is all about text handling, shaping, etc. fix A bug fix. waiting-on-review This PR is waiting to be reviewed. i18n About language- or script-specific features. May need attention from native speakers. labels Jan 5, 2026
@laurmaedje
Copy link
Member

Thanks!

For the record, my understanding of what's happening here: The is_justifiable property only affects whether spacing can be inserted to the right of the glyph if the line is underfull (i.e. its stretchability does not suffice to fully justify). It might be clearer if it was called "can_justify_after" or something like that, but that's unrelated to this PR.

Extra available spacing is distributed to the right of all justifiable glyphs. Justifiable glyphs include spaces, CJ glyphs, and CJK punctuation. In Latin text, the extra spacing is thus distributed among spaces, and in CJ text, it is distributed to the right of all letters since spaces aren't usually used. However, what we really want is to distribute spacing around the inner CJK glyphs. When two CJK glyphs are next to each other, this is naturally the case since the previous one will get spacing to the right. But for Latin followed by CJK, it is not, and that's what this patch changes.

The implementation seems reasonable to me as it fixes the problem and I don't see any major potential for issues arising from it (it only affects the code path where we overstretch the line and only allows spacing between Latin and CJK, which is precisely what we want). However, I think the overall implementation (not related to this PR), could probably be improved to make this a bit clearer (cf. also #7521 (comment)).

@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Jan 20, 2026
@laurmaedje laurmaedje added this pull request to the merge queue Jan 20, 2026
@laurmaedje laurmaedje added the cjk Chinese, Japanese, Korean typography. label Jan 20, 2026
Merged via the queue into typst:main with commit 6e69141 Jan 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cjk Chinese, Japanese, Korean typography. fix A bug fix. i18n About language- or script-specific features. May need attention from native speakers. layout Related to the layout category, which is about composing, positioning, etc. text Related to the text category, which is all about text handling, shaping, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CJK-latin glues stretch only before latin characters

2 participants