Skip to content

Language-aware line breakpoints #1009

Closed

Description

@peng1999

Description

Requirements for Chinese Text Layout have Prohibition Rules for Line Start and Line End, and Japanese also has similar rules. This is not implemented correctly in current typst, which uses vanilla UAX#14 directly by xi-unicode.

UAX#14 can be used directly in most latin languages, but is not enough for CJK. In UAX#14 §8 Customization:

A real-world line breaking algorithm has to be tailorable to some degree to meet user or document requirements. …
In Japanese, for example, tighter and looser specifications of prohibited line breaks may be used.

The most noticeable gap between vanilla UAX#14 and Chinese/Japanese convention is the handling of quotation marks. Here is an example:

An example
#set page(width: 5em + 2em, margin: (x: 1em))
#set text(font: "Noto Serif CJK SC")
测试文本,“测”

Current line breaking:

Desired line breaking:

ICU has a tailored line breaking rule for Chinese and Japanese, but unfortunately this is a C library and cannot used in typst.

Related: #276

Reproduction URL

No response

Operating system

No response

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Apr 27, 2023
  2. Jisu-Woniu commented on May 4, 2023

    @Jisu-Woniu

    There is an official icu4x implementation in Rust by Unicode.

  3. peng1999 commented on May 4, 2023

    @peng1999
    ContributorAuthor

    There is an official icu4x implementation in Rust by Unicode.

    Unfortunately icu4x does not support Chinese/Japanese line break tailoring like ICU. See unicode-org/icu4x#3284

  4. added
    text
    on May 9, 2023
  5. changed the title [-]Language aware line breakpoint[/-] [+]Language-aware line breakpoints[/+] on May 9, 2023
  6. peng1999 commented on May 18, 2023

    @peng1999
    ContributorAuthor

    I have found a way to patch the data generater in icu4x, which now allows it to generate a line break rule data for Chinese/Japanese.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions