Debian Codegraph @

texmf-dist/tex/plain/pitex/base.ptxlua

raw
1 require"gates.lua"
2
3 pitex = gates.new("pitex")
4 pitex.misc = gates.new("pitex.misc")
5
6 function pitex.log (message, ...)
7 texio.write_nl(string.format("\n" .. message .. "\n", ...))
8 end
9 function pitex.error (...)
10 tex.error ("! PiTeX error: " .. string.format(...) .. ".")
11 end
12
13 pitex.callback = gates.new("pitex.callback")
14
15 -- Creates a gate with a callback's name and put it in that callback, if not
16 -- already there. Adds the subgate(s).
17 function pitex.callback.register (c, f)
18 if pitex.callback.type(c) == 2 then
19 pitex.callback.add(f, c)
20 else
21 pitex.callback.list{c}
22 pitex.callback.add(f, c)
23 callback.register(c, pitex.callback.execute[c])
24 end
25 end
26
27 -- Latin1 to UTF-8.
28 local char = unicode.utf8.char
29 local function convert_char (ch)
30 return char(string.byte(ch))
31 end
32 function pitex.callback.convert (buf)
33 return string.gsub(buf,".",convert_char)
34 end
35
36 pitex.callback.register("process_input_buffer", "convert")
37
38 function remove_conversion ()
39 pitex.callback.close("convert", "process_input_buffer")
40 end
41 function restore_conversion ()
42 pitex.callback.open("convert", "process_input_buffer")
43 end
44
45 require("nodeinspector")
46 new_inspection = nodeinspector.new_inspection
47
48 local french_highmarks = {
49 string.byte("?"),
50 string.byte("!"),
51 string.byte(":"),
52 string.byte(";"),
53 }
54 local french_marks = {
55 string.byte("?"),
56 string.byte("!"),
57 string.byte(":"),
58 string.byte(";"),
59 string.byte(","),
60 string.byte("."),
61 string.byte("("),
62 string.byte("["),
63 string.byte("{"),
64 }
65
66 local function french_punctuation (head, ...)
67 for _, glue in ipairs(arg) do
68 if glue.id == 10 then
69 head = node.remove(head, glue)
70 node.free(glue)
71 end
72 end
73 local kern = node.new(11, 1)
74 kern.kern = tex.sp(".15em")
75 node.insert_after(head, arg[1], kern)
76 end
77
78 pitex.callback.french_punctuation = new_inspection(
79 french_punctuation,
80 {{id = 37, _char = french_marks}, {true, id = 37, char = french_highmarks}},
81 {{id = 10, subtype = 0}, {id = 11, subtype = 0}})
82
83 pitex.callback.register("kerning", "french_punctuation")
84 pitex.callback.original_kerning = node.kerning
85 pitex.callback.register("kerning", "original_kerning")