Skip to content

Commit

Permalink
Support \kcatcode<c>=15
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kitagawa committed Aug 28, 2023
1 parent f581ba7 commit bc6996d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
3 changes: 3 additions & 0 deletions texk/web2c/nptexdir/kanji.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 6 additions & 4 deletions texk/web2c/nptexdir/memo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions texk/web2c/nptexdir/nptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,6 @@ authorization from the copyright holders.
@define procedure setintone ();
@define function delfamfield();
@define function delcharfield();

@define function kcatcodekey();
@define function getucsblock();
30 changes: 24 additions & 6 deletions texk/web2c/nptexdir/nptex.web
Original file line number Diff line number Diff line change
Expand Up @@ -30000,7 +30000,7 @@ and the font families are declared by |def_family|.
@<Put each...@>=
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@>
Expand Down Expand Up @@ -36788,12 +36788,15 @@ set_kansuji_char: if chr_code>0 then print_esc("kcatcode")

@ @<Assignments@>=
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 @<Set |cjkx_code| to 0 for all characters in a Unicode block @>
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;
Expand Down Expand Up @@ -37579,6 +37582,21 @@ current_cjkx_func_code: print_esc("currentcjkxfunc");
@ @<Cases for fetching an integer value@>=
current_cjkx_func_code: cur_val:=enable_cjkx_func;

@ @<Set |cjkx_code| to 0 for all characters in a Unicode block @>=
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
Expand Down
17 changes: 4 additions & 13 deletions texk/web2c/nptexdir/nptexextra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] */
Expand Down Expand Up @@ -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 <lib/texmfmp.c>

0 comments on commit bc6996d

Please sign in to comment.