blob: 682787843bcdf2bedd496b5a88711014475b7b2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
\input{luatexbase.sty}
%D \startsection[title=Prerequisites]
%D \startparagraph
%D Package loading and the namespacing issue are commented on in
%D \identifier{enigma.lua}.
%D \stopparagraph
\directlua{%
packagedata = packagedata or { }
dofile(kpse.find_file"enigma.lua")
}
%D \startparagraph
%D First, create somthing like \CONTEXT’s asciimode. We found
%D \texmacro{\newluatexcatcodetable} in \identifier{luacode.sty} and it
%D seems to get the job done.
%D \stopparagraph
\newluatexcatcodetable \enigmasetupcatcodes
\bgroup
\def\escapecatcode {0}
\def\begingroupcatcode {1}
\def\endgroupcatcode {2}
\def\spacecatcode {10}
\def\lettercatcode {11}
\setluatexcatcodetable\enigmasetupcatcodes {
\catcode`\^^I = \spacecatcode % tab
\catcode`\ = \spacecatcode
\catcode`\{ = \begingroupcatcode
\catcode`\} = \endgroupcatcode
\catcode`\^^L = \lettercatcode % form feed
\catcode`\^^M = \lettercatcode % eol
}
\egroup
%D \stopsection
%D \startsection[title=Setups]
%D \startparagraph
%D Once the proper catcodes are in place, the setup macro
%D \texmacro{do-setup_enigma} doesn’t to anything besides passing stuff
%D through to Lua.
%D \stoppparagraph
\def\do_setup_enigma#1{%
\directlua{
local enigma = packagedata.enigma
local current_args = enigma.parse_args([====[\detokenize{#1}]====])
enigma.current = enigma.new_callback(enigma.new_machine(current_args, "aaa"))
}%
\egroup%
}
%D The module setup \texmacro{setupenigma} expects key=value, notation.
%D All the logic is at the Lua end, not much to see here …
\def\setupenigma{%
\bgroup
\luatexcatcodetable \enigmasetupcatcodes
\do_setup_enigma%
}
%D \stopsection
%D \startsection[title=Encoding Macros]
%D \startparagraph
%D The environment of \texmacro{\startenigma} and \texmacro{\stopenigma}
%D allow enabling of Enigma encoding in different parts of the document.
%D \stopparagraph
\def\startenigma{%
\bgroup%
\directlua{%
if packagedata.enigma and packagedata.enigma.current then
luatexbase.add_to_callback("pre_linebreak_filter",
packagedata.enigma.current,
"enigma")
end
}%
}
\def\stopenigma{%
\directlua{luatexbase.remove_from_callback("pre_linebreak_filter", "enigma")
packagedata.enigma.current_machine:processed_chars()}%
\egroup%
}
%D \stopsection
% vim:ft=tex:sw=2:ts=2:expandtab:tw=72
|