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
|
#!/usr/bin/env texlua
--[[
Copyright 2008, 2009 Manuel Pégourié-Gonnard.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
Previous work in the public domain:
- Contributions from Reinhard Kotucha (2008).
- First texlua versions by Frank Küster (2007).
- Original shell script by Thomas Esser, David Aspinall, and Simon Wilkinson.
--]]
-- load a local environment, importing symbols from (this function's) _G
-- usage: local L = {} load_env(L, {'a', 'b'})
function load_env(l, symbols)
local _, symb
for _, symb in ipairs(symbols) do
assert(_G[symb] ~= nil,
'Internal error: trying to import undefined symbol '..symb..'.')
l[symb] = _G[symb]
end
setfenv(2, l)
end
-- export symbols from a local environment to (this fonction's) _G
function export_symbols(l, symbols)
local _, symb
for _, symb in ipairs(symbols) do
assert(l[symb] ~= nil,
'Internal error: trying to export undefined symbol '..symb..'.')
assert(_G[symb] == nil,
'Internal error: trying to export existing symbol '..symb..'.')
_G[symb] = l[symb]
end
end
-- load a component of texdoc
function texdoc_load(name)
local f = kpse.find_file('texdoc/'..name..'.tlu', 'texmfscripts')
assert(f, 'Internal error: unable to find texdoc module '..name..'.')
dofile(f)
end
-- initialize kpathsea
kpse.set_program_name(arg[-1], 'texdoc')
-- declare global variables; they will be made read-only later
C = {} -- constants
config = {} -- configuration settings
alias = {} -- aliases
-- actually load the components now
texdoc_load('constants') -- makes C read-only
texdoc_load('functions')
texdoc_load('config') -- makes config and alias read-only
texdoc_load('search')
texdoc_load('score')
texdoc_load('view')
-- execute main()
texdoc_load('main')
-- the end
os.exit(0)
|