2 -- luatexja/inputbuf.lua
4 luatexbase.provides_module({
5 name = 'luatexja.inputbuf',
8 description = 'Supressing a space by newline after Japanese characters',
10 module('luatexja.inputbuf', package.seeall)
11 local err, warn, info, log = luatexbase.errwarinf(_NAME)
13 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
15 local node_new = node.new
16 local id_glyph = node.id('glyph')
17 local getcatcode = tex.getcatcode
19 --- the following function is modified from jafontspec.lua (by K. Maeda).
20 --- Instead of "%", we use U+FFFFF for suppressing spaces.
21 function add_comment(buffer)
22 local i = utf.len(buffer)
23 while (i>0) and (getcatcode(utf.byte(buffer, i))==1
24 or getcatcode(utf.byte(buffer, i))==2) do
28 local c = utf.byte(buffer, i)
29 local ct = getcatcode(c)
30 local te = tex.endlinechar
31 local ctl = (te ~= -1) and (getcatcode(te)==5) and (getcatcode(0xFFFFF)==14)
32 -- Is the catcode of endline character is 5 (end-of-line)?
33 -- Is the catcode of U+FFFFF (new comment char) is 14 (comment)?
34 if ((ct==11) or (ct==12)) and ctl then
35 local p = node_new(id_glyph)
37 if ltjc.is_ucs_in_japanese_char(p) then
38 buffer = buffer .. string.char(0xF3,0xBF,0xBF,0xBF) -- U+FFFFF
46 luatexbase.add_to_callback('process_input_buffer',
47 add_comment,'ltj.process_input_buffer')