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
84
85
86
87
88
89
90
91
92
93
94
95
96
|
% engine=luatex
\startluacode
do
document = document or { }
document.setups = {
loaded = { },
root = nil,
used = { },
}
function document.setups.load(filename)
filename = input.find_file(texmf.instance,filename) or ""
if filename ~= "" and not document.setups.loaded[filename] then
local loaded = xml.load(filename)
if loaded then
if document.setups.root then
xml.inject(document.setups.root,"/",loaded)
else
document.setups.root = loaded
end
document.setups.loaded[filename] = true
end
end
end
function document.setups.name(ek)
local at = ek.at
local name = at.name
if at.type == 'environment' then
name = "start" .. name
end
if at.variant then
name = name .. ":" .. at.variant
end
if at.generated == "yes" then
name = name .. "*"
end
return name:lower()
end
function document.setups.show(name)
if document.setups.root then
local name = name:gsub("[<>]","")
local setup = xml.first(document.setups.root,"cd:command[@name='" .. name .. "']")
document.setups.used[#document.setups.used+1] = setup
xml.sprint(setup)
end
end
function document.setups.showused()
if document.setups.root and next(document.setups.used) then
for k,v in ipairs(table.sortedkeys(document.setups.used)) do
xml.sprint(document.setups.used[v])
end
end
end
function document.setups.showall()
if document.setups.root then
local list = { }
xml.each_element(document.setups.root,"cd:command", function(r,d,t)
local ek = d[t]
list[document.setups.name(ek)] = ek
end )
for k,v in ipairs(table.sortedkeys(list)) do
xml.sprint(list[v])
end
end
end
function document.setups.resolve(name)
if document.setups.root then
local e = xml.filter(document.setups.root,string.format("cd:define[@name='%s']/text()",name))
if e then
xml.sprint(e)
end
end
end
end
\stopluacode
\def\mkloadsetups #1{\ctxlua{document.setups.load("#1")}}
\def\mkshowsetup #1{\ctxlua{document.setups.show("#1")}}
\def\mlshowusedsetups {\bgroup\enableXML\ctxlua{document.setups.showused()}\egroup}
\def\mkshowallsetups {\bgroup\enableXML\ctxlua{document.setups.showall ()}\egroup}
\defineXMLenvironmentsave [cd:define] [name=]
{}
\defineXMLsingular [cd:resolve] [name=]
{\enableXML\ignorespaces\ctxlua{document.setups.resolve("\XMLop{name}")}}
\endinput
% \starttext
% \loadsetups[cont-en.xml]
% \setup[goto]
% \placeeverysetup
% \stoptext
|