* [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
@ 2024-10-02 22:39 hf
2024-10-02 23:45 ` 黄复雄
0 siblings, 1 reply; 5+ messages in thread
From: hf @ 2024-10-02 22:39 UTC (permalink / raw)
To: mailing list for ConTeXt users
I'm curious what Chinese font(s) you are using with ConTeXt? Are they OpenType font,
or TrueType?
October 2, 2024 at 12:56 PM, "黄复雄" <aahuaang@gmail.com> wrote:
> This is a preliminary solution for inserting spaces between Chinese
>
> characters and non-Chinese characters
>
> ```ConTeXt
>
> \mainlanguage[cn]
>
> \language[cn]
>
> \setscript[hanzi]
>
> \usetypescriptfile[mscore]
>
> \usebodyfont [mschinese,12pt]
>
> \showglyphs
>
> \startluacode
>
> Thirddata = Thirddata or {}
>
> local glyph_id = nodes.nodecodes.glyph --node.id("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)
>
> -- for more ranges:
>
> -- https://wiki.contextgarden.net/List_of_Unicode_blocks
>
> return (c >= 0x04E00 and c <= 0x09FFF)
>
> or (c >= 0x03400 and c <= 0x04DBF)
>
> or (c >= 0x20000 and c <= 0x2A6DF)
>
> end
>
> function Thirddata.processmystuff(head)
>
> local n = head
>
> while n do
>
> if n.id == glyph_id and ischinesechar(n.char) then
>
> local n_prev = n.prev
>
> if n_prev
>
> and n_prev.id == glyph_id
>
> and not ischinesechar(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
>
> local n_next = n.next
>
> if n_next
>
> and n_next.id == glyph_id
>
> and not ischinesechar(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
>
> n = n.next
>
> end
>
> return head, done
>
> end
>
> nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
>
> \stopluacode
>
> \starttext
>
> 今天出去买菜花了5000元。
>
> 新MacBook Pro有15\%的CPU性能提升。
>
> \stoptext
>
> ```
>
> On Tue, Oct 1, 2024 at 2:07 PM <ai2472206007@yeah.net> wrote:
>
>> hi,
>>
>> Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
>>
>> I noticed that there is a tracker that tracks character types and annotates them.
>>
>> But I don't know much about lua and the underlying tex.
>>
>> Any suggestions would be greatly appreciated.
>>
>> For example, glue is automatically added between Chinese characters and English or numbers.
>>
>> input: 今天出去买菜花了5000元。
>>
>> will get: 今天出去买菜花了 5000 元。
>>
>> ----------------------------------
>>
>> input: 新MacBook Pro有15%的CPU性能提升。
>>
>> will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
>>
>> Muyik
>>
>> ___________________________________________________________________________________
>>
>> If your question is of interest to others as well, please add an entry to the Wiki!
>>
>> maillist : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
2024-10-02 22:39 [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters? hf
@ 2024-10-02 23:45 ` 黄复雄
0 siblings, 0 replies; 5+ messages in thread
From: 黄复雄 @ 2024-10-02 23:45 UTC (permalink / raw)
To: mailing list for ConTeXt users
I use \usetypescriptfile[mscore], which means using the font
configuration that comes with ConTeXt,
which is suitable for Windows systems. For details, see the
installation file type-imp-mscore.mkiv.
If you set the body font, both OpenType and TrueType are OK.
On Thu, Oct 3, 2024 at 6:42 AM <hf@hongfeng.ch> wrote:
>
> I'm curious what Chinese font(s) you are using with ConTeXt? Are they OpenType font,
> or TrueType?
>
>
>
> October 2, 2024 at 12:56 PM, "黄复雄" <aahuaang@gmail.com> wrote:
>
> > This is a preliminary solution for inserting spaces between Chinese
> >
> > characters and non-Chinese characters
> >
> > ```ConTeXt
> >
> > \mainlanguage[cn]
> >
> > \language[cn]
> >
> > \setscript[hanzi]
> >
> > \usetypescriptfile[mscore]
> >
> > \usebodyfont [mschinese,12pt]
> >
> > \showglyphs
> >
> > \startluacode
> >
> > Thirddata = Thirddata or {}
> >
> > local glyph_id = nodes.nodecodes.glyph --node.id("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)
> >
> > -- for more ranges:
> >
> > -- https://wiki.contextgarden.net/List_of_Unicode_blocks
> >
> > return (c >= 0x04E00 and c <= 0x09FFF)
> >
> > or (c >= 0x03400 and c <= 0x04DBF)
> >
> > or (c >= 0x20000 and c <= 0x2A6DF)
> >
> > end
> >
> > function Thirddata.processmystuff(head)
> >
> > local n = head
> >
> > while n do
> >
> > if n.id == glyph_id and ischinesechar(n.char) then
> >
> > local n_prev = n.prev
> >
> > if n_prev
> >
> > and n_prev.id == glyph_id
> >
> > and not ischinesechar(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
> >
> > local n_next = n.next
> >
> > if n_next
> >
> > and n_next.id == glyph_id
> >
> > and not ischinesechar(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
> >
> > n = n.next
> >
> > end
> >
> > return head, done
> >
> > end
> >
> > nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
> >
> > \stopluacode
> >
> > \starttext
> >
> > 今天出去买菜花了5000元。
> >
> > 新MacBook Pro有15\%的CPU性能提升。
> >
> > \stoptext
> >
> > ```
> >
> > On Tue, Oct 1, 2024 at 2:07 PM <ai2472206007@yeah.net> wrote:
> >
> >> hi,
> >>
> >> Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
> >>
> >> I noticed that there is a tracker that tracks character types and annotates them.
> >>
> >> But I don't know much about lua and the underlying tex.
> >>
> >> Any suggestions would be greatly appreciated.
> >>
> >> For example, glue is automatically added between Chinese characters and English or numbers.
> >>
> >> input: 今天出去买菜花了5000元。
> >>
> >> will get: 今天出去买菜花了 5000 元。
> >>
> >> ----------------------------------
> >>
> >> input: 新MacBook Pro有15%的CPU性能提升。
> >>
> >> will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
> >>
> >> Muyik
> >>
> >> ___________________________________________________________________________________
> >>
> >> If your question is of interest to others as well, please add an entry to the Wiki!
> >>
> >> maillist : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
@ 2024-10-04 23:03 hf
0 siblings, 0 replies; 5+ messages in thread
From: hf @ 2024-10-04 23:03 UTC (permalink / raw)
To: mailing list for ConTeXt users
thank you. I am trying to get some usable OpenType Chinese font for ConTeXt
on GNU/Linux.
Cheers,
Hong
October 3, 2024 at 7:45 AM, "黄复雄" <aahuaang@gmail.com> wrote:
> I use \usetypescriptfile[mscore], which means using the font
>
> configuration that comes with ConTeXt,
>
> which is suitable for Windows systems. For details, see the
>
> installation file type-imp-mscore.mkiv.
>
> If you set the body font, both OpenType and TrueType are OK.
>
> On Thu, Oct 3, 2024 at 6:42 AM <hf@hongfeng.ch> wrote:
>
>> I'm curious what Chinese font(s) you are using with ConTeXt? Are they OpenType font,
>>
>> or TrueType?
>>
>> October 2, 2024 at 12:56 PM, "黄复雄" <aahuaang@gmail.com> wrote:
>>
>> This is a preliminary solution for inserting spaces between Chinese
>>
>> characters and non-Chinese characters
>>
>> ```ConTeXt
>>
>> \mainlanguage[cn]
>>
>> \language[cn]
>>
>> \setscript[hanzi]
>>
>> \usetypescriptfile[mscore]
>>
>> \usebodyfont [mschinese,12pt]
>>
>> \showglyphs
>>
>> \startluacode
>>
>> Thirddata = Thirddata or {}
>>
>> local glyph_id = nodes.nodecodes.glyph --node.id("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)
>>
>> -- for more ranges:
>>
>> -- https://wiki.contextgarden.net/List_of_Unicode_blocks
>>
>> return (c >= 0x04E00 and c <= 0x09FFF)
>>
>> or (c >= 0x03400 and c <= 0x04DBF)
>>
>> or (c >= 0x20000 and c <= 0x2A6DF)
>>
>> end
>>
>> function Thirddata.processmystuff(head)
>>
>> local n = head
>>
>> while n do
>>
>> if n.id == glyph_id and ischinesechar(n.char) then
>>
>> local n_prev = n.prev
>>
>> if n_prev
>>
>> and n_prev.id == glyph_id
>>
>> and not ischinesechar(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
>>
>> local n_next = n.next
>>
>> if n_next
>>
>> and n_next.id == glyph_id
>>
>> and not ischinesechar(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
>>
>> n = n.next
>>
>> end
>>
>> return head, done
>>
>> end
>>
>> nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
>>
>> \stopluacode
>>
>> \starttext
>>
>> 今天出去买菜花了5000元。
>>
>> 新MacBook Pro有15\%的CPU性能提升。
>>
>> \stoptext
>>
>> ```
>>
>> On Tue, Oct 1, 2024 at 2:07 PM <ai2472206007@yeah.net> wrote:
>>
>> hi,
>>
>> Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
>>
>> I noticed that there is a tracker that tracks character types and annotates them.
>>
>> But I don't know much about lua and the underlying tex.
>>
>> Any suggestions would be greatly appreciated.
>>
>> For example, glue is automatically added between Chinese characters and English or numbers.
>>
>> input: 今天出去买菜花了5000元。
>>
>> will get: 今天出去买菜花了 5000 元。
>>
>> ----------------------------------
>>
>> input: 新MacBook Pro有15%的CPU性能提升。
>>
>> will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
>>
>> Muyik
>>
>> ___________________________________________________________________________________
>>
>> If your question is of interest to others as well, please add an entry to the Wiki!
>>
>> maillist : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
@ 2024-10-01 6:02 ai2472206007
2024-10-02 4:56 ` [NTG-context] " 黄复雄
0 siblings, 1 reply; 5+ messages in thread
From: ai2472206007 @ 2024-10-01 6:02 UTC (permalink / raw)
To: ntg-context
hi,
Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
I noticed that there is a tracker that tracks character types and annotates them.
But I don't know much about lua and the underlying tex.
Any suggestions would be greatly appreciated.
For example, glue is automatically added between Chinese characters and English or numbers.
input: 今天出去买菜花了5000元。
will get: 今天出去买菜花了 5000 元。
----------------------------------
input: 新MacBook Pro有15%的CPU性能提升。
will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
Muyik
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
2024-10-01 6:02 [NTG-context] " ai2472206007
@ 2024-10-02 4:56 ` 黄复雄
2024-10-02 11:36 ` ai2472206007
0 siblings, 1 reply; 5+ messages in thread
From: 黄复雄 @ 2024-10-02 4:56 UTC (permalink / raw)
To: mailing list for ConTeXt users
This is a preliminary solution for inserting spaces between Chinese
characters and non-Chinese characters
```ConTeXt
\mainlanguage[cn]
\language[cn]
\setscript[hanzi]
\usetypescriptfile[mscore]
\usebodyfont [mschinese,12pt]
\showglyphs
\startluacode
Thirddata = Thirddata or {}
local glyph_id = nodes.nodecodes.glyph --node.id("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)
-- for more ranges:
-- https://wiki.contextgarden.net/List_of_Unicode_blocks
return (c >= 0x04E00 and c <= 0x09FFF)
or (c >= 0x03400 and c <= 0x04DBF)
or (c >= 0x20000 and c <= 0x2A6DF)
end
function Thirddata.processmystuff(head)
local n = head
while n do
if n.id == glyph_id and ischinesechar(n.char) then
local n_prev = n.prev
if n_prev
and n_prev.id == glyph_id
and not ischinesechar(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
local n_next = n.next
if n_next
and n_next.id == glyph_id
and not ischinesechar(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
n = n.next
end
return head, done
end
nodes.tasks.appendaction("processors", "after", "Thirddata.processmystuff")
\stopluacode
\starttext
今天出去买菜花了5000元。
新MacBook Pro有15\%的CPU性能提升。
\stoptext
```
On Tue, Oct 1, 2024 at 2:07 PM <ai2472206007@yeah.net> wrote:
>
> hi,
> Is there any way to automatically control the spacing between Chinese and non-Chinese characters?
> I noticed that there is a tracker that tracks character types and annotates them.
> But I don't know much about lua and the underlying tex.
> Any suggestions would be greatly appreciated.
>
> For example, glue is automatically added between Chinese characters and English or numbers.
>
> input: 今天出去买菜花了5000元。
> will get: 今天出去买菜花了 5000 元。
> ----------------------------------
> input: 新MacBook Pro有15%的CPU性能提升。
> will get: 新 MacBook Pro 有 15% 的 CPU 性能提升。
>
> Muyik
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / 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 : ntg-context@ntg.nl / 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-04 23:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-02 22:39 [NTG-context] Re: Is there any way to automatically control the spacing between Chinese and non-Chinese characters? hf
2024-10-02 23:45 ` 黄复雄
-- strict thread matches above, loose matches on Subject: below --
2024-10-04 23:03 hf
2024-10-01 6:02 [NTG-context] " ai2472206007
2024-10-02 4:56 ` [NTG-context] " 黄复雄
2024-10-02 11:36 ` ai2472206007
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).