Hi, Sylvain.
This is a simple example. It can only handle Chinese right now, but
maybe could serve as a starting point for your further work.
```lmtx
\usetypescriptfile[mscore]
\usebodyfont [mschinese,10.5pt]
\startluacode
Thirddata = Thirddata or {}
local glyph_id = nodes.nodecodes.glyph
local node_insertbefore = node.insertbefore
local node_insertafter = node.insertafter
local node_new = node.new
local tex_sp = tex.sp
local function ischinesechar(c)
-- cjk汉字,不含符号
-- for more ranges:
-- https://wiki.contextgarden.net/List_of_Unicode_blocks
return (c >= 0x04E00 and c <= 0x09FFF) --CJK Unified Ideographs;
cjkunifiedideographs
end
-- 汉字环境中的(非汉字)合法符号
local legalsymbolinchinese = {
[0x00b7] = true, -- · MIDDLE DOT
[0x002D] = true, -- - Hyphen-Minus. Will there be any side effects?
[0x002F] = true, -- / Solidus
}
local function islegalsymbolinchinese(c)
return legalsymbolinchinese[c]
end
function Thirddata.processmystuff(head)
local n = head
while n do
if n.id == glyph_id then
if ischinesechar(n.char) then -- 本字是汉字
local n_prev = n.prev
if n_prev and n_prev.id == glyph_id then
if ischinesechar(n_prev.char) then -- 前字是汉字
elseif not islegalsymbolinchinese(n_prev.char)
then --前字不是汉字也不是合法中文语境符号
local glue = node_new("glue")
glue.width = tex_sp("0.25em")
glue.stretch = tex_sp("0.25em")
--print("insert space before:", utf8.char(n.char))
head, glue = node_insertbefore(head, n, glue)
end
end
local n_next = n.next
if n_next
and n_next.id == glyph_id
and not ischinesechar(n_next.char)
and not islegalsymbolinchinese(n_next.char)
then
local glue = node_new("glue")
glue.width = tex_sp("0.25em")
glue.stretch = tex_sp("0.25em")
--print("insert space after:", utf8.char(n.char))
head, glue = node_insertafter(head, n, glue)
n = glue.next
end
end
end
n = n.next
end
return head, done
end
nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
\stopluacode
\starttext
\dorecurse{50}{口口abc口口123口口abc123口口123abc}
\stoptext
```
Sylvain Hubert <[email protected]> 于2025年12月10日周三 19:55写道:
>
> Dear list,
>
> \setscript[hanzi] fails to find a break point for the following example:
>
> ```
> \mainlanguage[cn]
> \setscript[hanzi]
>
> \definefontfamily[mainfont][rm][simsun] % other chinese fonts should work too
> \setupbodyfont[mainfont]
>
> \starttext
>
> \dorecurse{50}{口abc口123}
>
> \stoptext
> ```
>
> How can one specify break point at cjk and non-cjk char pairs?
>
> Any help is appreciated!
>
> Best,
> Sylvain
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the
> Wiki!
>
> maillist : [email protected] /
> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive : https://github.com/contextgarden/context
> wiki : https://wiki.contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________