Repository navigation
Open
Labels
dependenciesPull requests that update a dependency filei18nAbout language- or script-specific features. May need attention from native speakers.
Description
typst/crates/typst-layout/src/inline/linebreak.rs
Lines 41 to 58 in 64c5e8c
| /// The line break segmenter for Chinese/Japanese text. | |
| /// | |
| /// This is generated by manually overriding the line break properties for curly | |
| /// quotes `U+201C` and `U+201D` from `QU` (`Quotation`) to `OP` | |
| /// (`OpenPunctuation`) and `CP` (`CloseParenthesis`), respectively. | |
| /// | |
| /// This can be combined with [`SEGMENTER`] once ICU4X updates the line | |
| /// segmenter to Unicode 17.0. This will also allow us to remove the `serde` | |
| /// feature from the dependency. | |
| static CJ_SEGMENTER: LazyLock<LineSegmenter> = LazyLock::new(|| { | |
| let blob = typst_assets::icu::ICU_CJ_SEGMENT; | |
| let cj_provider = BlobDataProvider::try_new_from_static_blob(blob).unwrap(); | |
| LineSegmenter::try_new_for_non_complex_scripts_with_buffer_provider( | |
| &cj_provider, | |
| LineBreakOptions::default(), | |
| ) | |
| .unwrap() | |
| }); |
This code should be unnecessary now.
Note that ICU4X supports both Unicode 17 and 18 data here, you can get the 18 data by calling the unstable new_neo constructors (https://docs.rs/icu_segmenter/latest/icu_segmenter/struct.LineSegmenter.html) which use the more modern data format. Those constructors will be the ones that continue to get updated.
Reacted by Y.D.X. and Bastien Voirin
Metadata
Metadata
Assignees
Labels
dependenciesPull requests that update a dependency filei18nAbout language- or script-specific features. May need attention from native speakers.
Activity
Manishearth commentedon Oct 24, 2026
cc @robertbastian
YDX-2147483647 commentedon Oct 25, 2026
About icu4x versions
Relates-to: #8406
That PR updated icu4x from 1.4 to 2.2, and kept the CJ segmenter intentionally in typst/typst-assets#20.
Update:
I've provided more details in #9003 (comment).
In short, the new icu4x APIs (
new_17_*for Unicode 17.0 andnew_neo_*for Unicode 18.0) do eliminate the need of a CJ segmenter patch, but they are unstable (behind theunstablefeature flag) and don't support complex scripts (e.g., Thai) yet.Therefore, I suggest we stay with the old icu4x API (new_{auto,lstm,…}for Unicode 15.1) and keep the CJ patch, until icu4x adds support for complex scripts to the new API in the future.Update 2:
See Peerakarn Junmunee's comment below. It is possible to combine the new APIs with the classic LSTM data.
v0.15.1...admannon:typst:bump-icu-2.3
Advantages of newer icu4x segmenters
I suggest we include these as test cases when upgrading icu4x.
In the descriptions below, Unicode 15 =
LineSegmenter::new_auto, Unicode 17 =LineSegmenter::new_17_for_non_complex_scripts, and Unicode 18 =LineSegmenter::new_neo_for_non_complex_scripts.Details
In Zellkulturschalen und -flaschen, the line should not break after the hanging/suspended hyphen
|Zellkulturschalen |und |-|flaschen||Zellkulturschalen |und |-flaschen|Reported by laalsaas on 2026-11-09 on the forum, tested with icu4x v2.4.0.
This was an intended change to the Unicode Line Breaking Algorithm. See Unicode 16 modifications to UAX
#14: Added LB20a to prevent line breaks after word-initial hyphens.In 《女神·天狗》, the line should not break before the interpunct (U+00B7
·)|《女|神|·|天|狗》||《女|神·|天|狗》|Reported in #6774 on 2025-08-17, tested with icu4x v2.4.0.
This was also intended. See unicode-org/icu4x#7500 (comment).
No-break spaces after hyphens should prevent line breaks
For example,
Test test~--~test(typst markup):|Test |test –| test||Test |test – test|Reported in #6400 on 2025-06-07, tested with icu4x v2.4.0.
This was also intended. See Unicode 18 modifications to UAX
#14: Changed rule LB12a to disallow a break between BA and GL, e.g., between EN DASH and NO-BREAK SPACE.Em spaces in Hebrew should not prevent line breaks
For example:
Unicode 15 gives the wrong result:
| |ישבה על מדוכה זו ברבות מישיבותיה בשנים תשנ"ד–תשס"ה ופעלה נמרצות לשיפור הכללים, |להשלמתם ולעדכונם. |נוסף על כך העמידה הוועדה כללים חדשים רבים –|Unicode 17 and 18 gives the correct result:
| |ישבה |על |מדוכה |זו |ברבות |מישיבותיה |בשנים |תשנ"ד–|תשס"ה |ופעלה |נמרצות |לשיפור |הכללים, |להשלמתם |ולעדכונם. |נוסף |על |כך |העמידה |הוועדה |כללים |חדשים |רבים –|Reported in #8193 on 2026-11-10, tested with icu4x v2.4.0.
This was also intended. See Unicode 16 modifications to UAX
#14: Modified LB21a to restrict its effect to hyphens that separate Hebrew from non-Hebrew.The U+2060 WORD JOINER among Thai texts should be respected.
I don't know the details… Please see the comments below.
admannon commentedon Oct 30, 2026
FWIW, I've already tested Thai with the new ICU4X neo segmenters.
My testing started with Typst #8413, then led to ICU4X unicode-org/icu4x#8243 (WORD JOINER handling), which is now referenced by ICU4X unicode-org/icu4x#7962. I also tried bumping Typst v0.15.1 to ICU4X 2.3 (https://github.com/admannon/typst/tree/bump-icu-2.3) and the results look noticeably better than before.
YDX-2147483647 commentedon Nov 10, 2026
Hi admannon! The word joiner bug you mentioned in #8413 (comment) can be fixed by updating ICU4X without switching to the unstable neo segmenter. And https://github.com/haminic has submitted #9024 to do that.
Perhaps your test case
word_joiner_prevents_break_in_thaishould be added to #9024?admannon commentedon Nov 11, 2026
I agree. word_joiner_prevents_break_in_thai would be a useful regression test.
Besides the original bug, it also covers a practical use case where WORD JOINER can be used to prevent breaks inside specific words (e.g.
กรุงเทพมหานคร) without modifying the dictionary.This can be useful for custom dictionary-like behavior, so I think it is worth adding as a regression test.