Skip to content

Update the line segmenter to Unicode 18, and updated outdated notes and tests - #9057

Draft
YDX-2147483647 wants to merge 1 commit into
typst:mainfrom
YDX-2147483647:icu4xup
Draft

YDX-2147483647 wants to merge 1 commit into
typst:mainfrom
YDX-2147483647:icu4xup

Conversation

@YDX-2147483647

@YDX-2147483647 YDX-2147483647 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Typst uses the icu_segmenter library to determine line break opportunities. This library is part of the ICU4X project developed by the Unicode Consortium, and it implements the Unicode Line Breaking Algorithm (UAX #14).

At present, Typst uses the classic line segmenter targeting Unicode 15.1 provided by ICU4X 2.2 with a CJ patch. In some cases, the UAX #14 algorithm in Unicode 15.1 does not give ideal results.

This PR replaces that with the neo line segmenter targeting Unicode 18.0 provided by ICU4X 2.4, remove the now-unneeded CJ patch, and update outdated comments in codes and tests. The new UAX #14 algorithm fixes a few bugs. See the test cases added to linebreak.rs for the details.

Closes #9002.
Resolves #6400, resolves #6774, resolves #8193.


Note that the neo line segmenter is still behind the unstable feature. https://github.com/Manishearth, a core contributor to ICU4X, once said on 2026-10-27 that it will be stabilized “hopefully in the next release”.

I am publishing this draft PR to record the bugs that Unicode 18 can fix. However, I suggest not merging this PR until ICU4X releases the next version.

Technical details

TODO

…nd tests

The previous line segmenter was Unicode 15.1 with a CJ patch.

Co-authored-by: Peerakarn Junmunee <[email protected]>
Co-authored-by: Manish Goregaokar <[email protected]>
@MDLC01 MDLC01 added text Related to the text category, which is all about text handling, shaping, etc. i18n About language- or script-specific features. May need attention from native speakers. labels Nov 13, 2026
@MDLC01 MDLC01 mentioned this pull request Nov 13, 2026
1 task done
@admannon

Copy link
Copy Markdown

Minimal repro: WJ-joined Thai word becomes unbreakable with the neo segmenter

ICU4X 2.4 (comparing this PR's setup vs #9024):

#set page(width: 50pt)
#set text(lang: "th")
ประกัน\u{2060}ภัยดี

With LineSegmenter::new_neo_for_non_complex_scripts(...) + load_lstm() this produces a single unbreakable segment (ประกัน\u{2060}ภัยดี), so the line overflows. With LineSegmenter::new_lstm(...) (PR #9024) it breaks after ภัย.

Simple ประกัน\u{2060}ภัย is one segment in both; the difference appears when a Thai run follows the WJ-joined word.

Could we add a regression test for this, and consider classic/#9024 as the base until ICU4X resolves the neo run-splitting (unicode-org/icu4x#8381)?

@YDX-2147483647

YDX-2147483647 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi! As I said in this PR's description, I suggest we merge #9024 before merging this PR. So I suggest you contact Haminic (the author of #9024) instead and add that test case to #9024. When #9024 is merged into main, I'll merge the test case into this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n About language- or script-specific features. May need attention from native speakers. text Related to the text category, which is all about text handling, shaping, etc.

Projects

None yet

4 participants