From bc6996d5e5e8a1df4a2d368fdbfaf24b7fa5a9d3 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Tue, 29 Aug 2023 05:25:39 +0900 Subject: [PATCH] Support \kcatcode=15 --- texk/web2c/nptexdir/kanji.h | 3 +++ texk/web2c/nptexdir/memo.txt | 10 ++++++---- texk/web2c/nptexdir/nptex.defines | 3 +++ texk/web2c/nptexdir/nptex.web | 30 ++++++++++++++++++++++++------ texk/web2c/nptexdir/nptexextra.c | 17 ++++------------- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/texk/web2c/nptexdir/kanji.h b/texk/web2c/nptexdir/kanji.h index 017546bc1e..f177bfce87 100644 --- a/texk/web2c/nptexdir/kanji.h +++ b/texk/web2c/nptexdir/kanji.h @@ -8,5 +8,8 @@ #define delcharfield(x) ((unsigned)(x) & 0x1FFFFF) #define delfamfield(x) ((unsigned)(x)>>21) + +extern integer kcatcodekey(integer c); +extern integer getucsblock(integer c); #endif diff --git a/texk/web2c/nptexdir/memo.txt b/texk/web2c/nptexdir/memo.txt index 74c560b299..5f8ddae834 100644 --- a/texk/web2c/nptexdir/memo.txt +++ b/texk/web2c/nptexdir/memo.txt @@ -15,11 +15,15 @@ changes from pTeX \kcatcode=18 ⇔ \catcode=12 and \cjkxcode= mod 8=7 \kcatcode=19 ⇔ \catcode=11 and \cjkxcode= mod 8=4 なお,文字列化すると catcode 12 になることは注意. - * \kcatcode は読み出しのみ可能. + * \kcatcode 読み出し \catcode=12 and \cjkxcode mod 8>=4 --> \kcatcode の返り値は 18 (other_kchar) \catcode=11 and \cjkxcode mod 8=6, 7 --> 返り値 16 (kanji) \catcode=11 and \cjkxocde mod 8=4, 5 --> 返り値 19 (hangul) 他 --> 返り値 15 (non_cjk) + * \kcatcode への代入は 15 のみ可能. + →その文字が属する Unicode ブロックに対して,ブロック内の全文字の \cjkxcode を + 0 にする(ただし,upTeX と同様に Latin-1 Supplement と Halfwidth and Fullwidth Forms + は分割している). * \prebreakpenalty, \postbreakpenalty, \xspcode, \inhibitxspcode →\catcode などと同じように,Unicode全体分のエントリがある. * jchr_widow_penalty_code -> jchar_widow_penalty_code @@ -47,6 +51,4 @@ changes from pTeX * \currentcjktoken, \disablecjktoken, \enablecjktoken, \forcecjktoken →\...cjkxfunc として実装 * \suppresslongerror, \suppressmathparerror, \suppressoutererror - * \synctex - * \hfi, \vfi, \pagefistretch, \odelcode, \odelimiter, \omathaccent, - \omathchar, \omathchardef, \omathcode, \oradical + * \hfi, \vfi, \pagefistretch diff --git a/texk/web2c/nptexdir/nptex.defines b/texk/web2c/nptexdir/nptex.defines index f8924c8789..69a7a552bd 100644 --- a/texk/web2c/nptexdir/nptex.defines +++ b/texk/web2c/nptexdir/nptex.defines @@ -197,3 +197,6 @@ authorization from the copyright holders. @define procedure setintone (); @define function delfamfield(); @define function delcharfield(); + +@define function kcatcodekey(); +@define function getucsblock(); diff --git a/texk/web2c/nptexdir/nptex.web b/texk/web2c/nptexdir/nptex.web index a811285d21..ac5aedefcb 100644 --- a/texk/web2c/nptexdir/nptex.web +++ b/texk/web2c/nptexdir/nptex.web @@ -30000,7 +30000,7 @@ and the font families are declared by |def_family|. @= primitive("catcode",def_code,cat_code_base); @!@:cat_code_}{\.{\\catcode} primitive@> -primitive("cjkxcode",def_code,cjkx_code_base); +primitive("cjkxcode",def_code◆,cjkx_code_base); @!@:cjkx_code_}{\.{\\cjkxcode} primitive@> primitive("prebreakpenalty",def_code,pre_break_penalty_base); @!@:pre_break_penalty_}{\.{\\prebreakpenalty} primitive@> @@ -36788,12 +36788,15 @@ set_kansuji_char: if chr_code>0 then print_esc("kcatcode") @ @= set_kansuji_char: if cur_chr>0 then - begin scan_usv_num; scan_optional_equals; scan_int; - print_err("\kcatcode is read-only integer in npTeX"); + begin scan_usv_num; n:=cur_val; scan_optional_equals; scan_int; + if cur_val=15 then @ + else begin + print_err("Invalid code"); print_int(cur_val); print(") for \kcatcode "); @.kcat_code is read_only@> - help2("You cannot assign \kcatcode in npTeX, so I'm skipping this control sequence.")@/ - ("Use combination of \catcode and \cjkx code instead.");@/ - error; return; + help2("In npTeX, \kcatcode is almost read-only integer. So I'm skipping this")@/ + ("control sequence. Use combination of \catcode and \cjkx code instead.");@/ + error; return; + end; end else begin scan_int; n:=cur_val; scan_optional_equals; scan_usv_num; @@ -37579,6 +37582,21 @@ current_cjkx_func_code: print_esc("currentcjkxfunc"); @ @= current_cjkx_func_code: cur_val:=enable_cjkx_func; +@ @= +begin m:=kcatcodekey(n); +if (m=1)or(m=@"1FD) then begin + for p:=@"80 to @"FF do if kcatcodekey(p)=m then define(cjkx_code_base+p,data,0) + end +else if (m=@"A2)or(m=@"1FE)or(m=@"1FF) then begin + for p:=@"FF00 to @"FFF0 do if kcatcodekey(p)=m then define(cjkx_code_base+p,data,0) + end +else begin cur_val:=get_ucs_block(m); cur_val1:=get_ucs_block(m+1); + for p:=cur_val to cur_val1 do if kcatcodekey(p)=m then define(cjkx_code_base+p,data,0) + end; +end + + + @* \[54] System-dependent changes. This section should be replaced, if necessary, by any special modifications of the program diff --git a/texk/web2c/nptexdir/nptexextra.c b/texk/web2c/nptexdir/nptexextra.c index 71e34f7a15..7534e257c4 100644 --- a/texk/web2c/nptexdir/nptexextra.c +++ b/texk/web2c/nptexdir/nptexextra.c @@ -10,19 +10,6 @@ #define CJK_CHAR_LIMIT 0x1000000 -integer calcpos(integer c) -{ - unsigned char c1, c2; - - if(c>=0 && c<=255) return(c); - c1 = (c>>8)%256; - c2 = c%256; - - c1 = (c1 % 4) * 64; /* c1 = 0, 64, 128, 192 */ - c2 = c2 % 64; /* c2 = 0..63 */ - return(c1 + c2); /* ret = 0..255 */ -} - /* Ref. http://www.unicode.org/Public/UNIDATA/Blocks.txt */ /* # Blocks-15.0.0.txt */ /* # Date: 2022-01-28, 20:58:00 GMT [KW] */ @@ -456,5 +443,9 @@ void initkanji(void) { enable_UPTEX (true); set_enc_string ("utf8", "uptex"); } +integer getucsblock(integer c) { + return ucs_range[c]; +} + /* Hand-coded routines for TeX or Metafont in C. */ #include