4 luatexbase.provides_module({
5 name = 'luatexja.compat',
8 description = 'Partial implementation of primitives of pTeX',
10 module('luatexja.compat', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 luatexja.load_module('base'); local ltjb = luatexja.base
14 luatexja.load_module('stack'); local ltjs = luatexja.stack
16 -- \kuten, \jis, \euc, \sjis, \ucs, \kansuji
17 function to_kansuji(num)
18 if not num then num=0; return
20 num = -num; tex.write('-')
25 ltjs.get_penalty_table('ksj', num%10,
26 '', tex.getcount('ltj@@stack'))) .. s
27 num=math.floor(num/10)
34 if type(i)~='number' then
35 ltjb.package_error('luatexja',
36 "invalid character code (".. tostring(i) .. ")",
37 "I'm going to use 0 instead of that illegal character code.")
43 -- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicharacter code 符号位置
44 function from_kuten(i)
45 if type(i)~='number' then
46 ltjb.package_error('luatexja',
47 "invalid character code (".. tostring(i) .. ")",
48 "I'm going to use 0 instead of that illegal character code.")
51 tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i] or 0))
54 -- \euc: EUC-JP による符号位置 => Unicharacter code 符号位置
56 if type(i)~='number' then
57 ltjb.package_error('luatexja',
58 "invalid character code (".. tostring(i) .. ")",
59 "I'm going to use 0 instead of that illegal character code.")
61 elseif i>=0x10000 or i<0xa0a0 then
67 -- \jis: ISO-2022-JP による符号位置 => Unicharacter code 符号位置
69 if (type(i)~='number') or i>=0x10000 or i<0 then
70 ltjb.package_error('luatexja',
71 "invalid character code (".. tostring(i) .. ")",
72 "I'm going to use 0 instead of that illegal character code.")
78 -- \sjis: Shift_JIS による符号位置 => Unicharacter code 符号位置
80 if (type(i)~='number') or i>=0x10000 or i<0 then
81 ltjb.package_error('luatexja',
82 "invalid character code (".. tostring(i) .. ")",
83 "I'm going to use 0 instead of that illegal character code.")
84 tex.write('0'); return
86 local c2 = math.floor(i/256)
88 local shift_jisx0213_s1a3_table = {
89 { [false]= 1, [true]= 8},
90 { [false]= 3, [true]= 4},
91 { [false]= 5, [true]=12},
92 { [false]=13, [true]=14},
95 if c2 >= 0xF0 then -- this if block won't be true
96 if (c2 <= 0xF3 or (c2 == 0xF4 and c1 < 0x9F)) then
97 c2 = 0x100 + shift_jisx0213_s1a3_table[c2 - 0xF0 + 1][(0x9E < c1)];
99 c2 = c2 * 2 - 413 + 0x100; if 0x9E < c1 then c2=c2+1 end
102 if c2<=0x9f then i=0x101 else i=0x181 end
103 c2 = c2 + c2 - i; if 0x9E < c1 then c2=c2+1 end
106 if c1>0x7f then i=0x40 else i=0x3f end
111 from_kuten(c2*256+c1)