c

cjk-unbreak

@preview

Remove spaces caused by line breaks around CJK.

v0.2.3
MIT

Package Information

Last Updated
Authors
KZNS
Categories
layouttextlanguages

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/cjk-unbreak:0.2.3

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/cjk-unbreak:0.2.3": *

Version History

0.2.3
683a28f014dc...
0.2.2
ee0386267814...
0.2.1
35cd37a00a33...
0.2.0
7ec43cfcb1d0...
0.1.1
bfb7b4e36de1...
0.1.0
777f52450b12...

cjk-unbreak

cjk-unbreak is a package that removes spaces around CJK characters caused by
line breaks in the Typst document.

This allows Typst like:

中文段落中
换行。

to be rendered as:

中文段落中换行。

Usage

Add the following code at the beginning of your document:

#import "@preview/cjk-unbreak:0.2.3": remove-cjk-break-space
#show: remove-cjk-break-space

The remove-cjk-break-space function transforms the content and removes
spaces between the text element such as [ ] in
sequence([中文], [ ], [字符]).

It will not modify spaces within a single text element such as [中文 字符] or
between elements that are not both text such as
sequence([中文], [ ], strong(body: [字符])).

Transform

cjk-unbreak use a function called transform-childs to modify the AST of the
content.
Unlike show in Typst, which applies multiple times until the content
stabilizes, the transform is applid only once.

See the source code of remove-cjk-break-space to learn more about how to use
transform-childs.

Other information

This package is a temporary solution to Typst
Issue#792.

Thanks to admk for providing the idea
to remove [ ] from the sequence,
and to touying, who demonstrated
how to modify the AST of content.