summaryrefslogtreecommitdiff
path: root/support/texdoc/script/texdoclib-const.tlu
blob: 1088c25e5e7c2a630e4b546e0f991c117a4adce3 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
-- texdoclib-const.tlu: global constants for texdoc
--
-- The TeX Live team, GPLv3, see texdoclib.tlu for details

-- use an empty environment that will become texdoc_env.C (see EOF)
local constants = {}
local kpse = kpse or require 'kpse'
local os = os or require 'os'
local setfenv = setfenv
local texdoc_env

if setfenv then -- Lua <5.2
    texdoc_env = getfenv()
    setfenv(1, constants)
else
    texdoc_env = _ENV
    _ENV = constants
end

-- BEGIN constants

-- progname and version
fullname = kpse.find_file('texdoc/texdoclib', 'lua')
progname = 'Texdoc'
version = '4.0.2'
release_date = '2024-02-02'

-- make sure to update setup_config_from_cl() accordingly
-- and set a default value in setup_config_from_defaults() if relevant
usage_msg = [[
Usage: texdoc [OPTION]... NAME...
   or: texdoc [OPTION]... ACTION

Try to find appropriate TeX documentation for the specified NAME(s).
Alternatively, perform the given ACTION and exit.

Options:
{{mode}}

{{interaction}}

{{debug}}

Actions:
{{action}}

Full manual available via `texdoc texdoc'.

Website: <https://tug.org/texdoc/>
Repository: <https://github.com/TeX-Live/texdoc>
Please email bugs to <texdoc@tug.org>.]]

zsh_completion = [=[
#compdef texdoc

__texdoc() {
  local options=(
    {{action}}
    + mode
    {{mode}}
    + interaction
    {{interaction}}
    + debug
    {{debug}}
  )
  _arguments -C -A $options \
    '*: :->arguments' && return
  case $state in
    arguments)
      local tlpdb="$(kpsewhich -var-value TEXMFROOT)/tlpkg/texlive.tlpdb"
      _values package $(awk '/^name[^.]*$/ {print $2}' $tlpdb)
    ;;
  esac
}

if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
  # autoload from fpath, call function directly
  __texdoc "$@"
else
  # eval/source/. command, register function for later
  compdef __texdoc texdoc
fi
]=]

--[[ structure of the options table

options = {
    {
        desc = <string> description,
        long = <string> long option name,
        short = <string> short option name,
        type = <string> argument type (boolean|string),
        group = <string> group of the option, -- also used for shell completion
        action = <function> to be called
    },
    ...
}
--]]

options = {
    -- action
    {
        desc = 'Print this help message.',
        long = 'help',
        short = 'h',
        type = 'boolean',
        group = 'action'
    },
    {
        desc = 'Print the version number.',
        long = 'version',
        short = 'V',
        type = 'boolean',
        group = 'action'
    },
    {
        desc = 'Print the list of configuration files used.',
        long = 'files',
        short = 'f',
        type = 'boolean',
        group = 'action'
    },
    {
        desc = 'Display FILE, given with full path (no searching).',
        long = 'just-view',
        type = 'string',
        metavar = 'FILE',
        complete = 'files',
        group = 'action'
    },
    {
        desc = 'Print SHELL completion.',
        long = 'print-completion',
        type = 'string',
        metavar = 'SHELL',
        complete = {'zsh'},
        group = 'action',
    },
    -- mode
    {
        desc = 'Use view mode: start a viewer. (default)',
        long = 'view',
        short = 'w',
        type = 'boolean',
        group = 'mode',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'mode', 'view', opt_name})
        end
    },
    {
        desc = 'Use mixed mode (view or list).',
        long = 'mixed',
        short = 'm',
        type = 'boolean',
        group = 'mode',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'mode', 'mixed', opt_name})
        end
    },
    {
        desc = 'Use list mode: show a list of results.',
        long = 'list',
        short = 'l',
        type = 'boolean',
        group = 'mode',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'mode', 'list', opt_name})
        end
    },
    {
        desc = 'Use showall mode: show also "bad" results.',
        long = 'showall',
        short = 's',
        type = 'boolean',
        group = 'mode',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'mode', 'showall', opt_name})
        end
    },
    -- interaction
    {
        desc = 'Use interactive menus. (default)',
        long = 'interact',
        short = 'i',
        type = 'boolean',
        group = 'interaction',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'interact_switch', 'true', opt_name})
        end
    },
    {
        desc = 'Use plain lists, no interaction required.',
        long = 'nointeract',
        short = 'I',
        type = 'boolean',
        group = 'interaction',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'interact_switch', 'false', opt_name})
        end
    },
    -- output format
    {
        desc = 'Machine-readable output for lists (implies -I).',
        long = 'machine',
        short = 'M',
        type = 'boolean',
        group = 'interaction',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'machine_switch', 'true', opt_name})
        end
    },
    -- verbosity
    {
        desc = 'Suppress warnings and most error messages.',
        long = 'quiet',
        short = 'q',
        type = 'boolean',
        group = 'debug',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'verbosity_level', '0', opt_name})
        end
    },
    {
        desc = 'Print additional information (e.g., viewer command).',
        long = 'verbose',
        short = 'v',
        type = 'boolean',
        group = 'debug',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'verbosity_level', '3', opt_name})
        end
    },
    -- debug
    {
        desc = 'Activate all debug output (equal to "--debug=all").',
        short = 'D',
        type = 'boolean',
        group = 'debug',
        action = function(cl_config, opt_name)
            table.insert(cl_config, {'debug_list', 'all', opt_name})
        end
    },
    {
        desc = 'Activate debug output restricted to LIST.',
        long = 'debug',
        short = 'd',
        metavar = 'LIST',
        type = 'string',
        complete = 'debugs',
        group = 'debug',
        action = function(cl_config, opt_name, val)
            if val == true then val = 'all' end
            table.insert(cl_config, {'debug_list', val, opt_name})
        end
    },
    -- config
    {
        desc = 'Set configuration item NAME to VALUE.',
        short = 'c',
        metavar = 'NAME=VALUE',
        type = 'string',
        complete = 'options',
        group = 'debug',
        action = function(cl_config, opt_name, val)
            table.insert(cl_config, {val, nil, opt_name})
        end
    },
}

copyright_msg = [[
Copyright 2008-2024 Manuel Pégourié-Gonnard, Takuto Asakura, the TeX Live Team.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.]]

actions_ph = 'Actions:\n'

known_options = {
    'viewer_.*',
    'mode',
    'interact_switch',
    'machine_switch',
    'ext_list',
    'basename_list',
    'badext_list',
    'badbasename_list',
    'suffix_list',
    'verbosity_level',
    'debug_list',
    'lastfile_switch',
    'rm_dir',
    'rm_file',
    'unzip_.*',
    'zipext_list',
    'max_lines',
    'lang',
    'fuzzy_level',
    'texlive_tlpdb',
    'online_url',
}

error_msg = [[
Try `texdoc --help' for short help, `texdoc texdoc' for full manual.]]

notfound_msg = [[
Sorry, no local documentation found for "PKGNAME".
You can try the online version of Texdoc at <https://texdoc.org>.
If you are unsure about the name, try full-text searching on CTAN.
Search form: <https://www.ctan.org/search/>]]
notfound_msg_ph = 'PKGNAME'

badmatch_msg = [[
Unfortunately, there are no good matches for "PKGNAME".

Here are the top three matches:
]]
badmatch_msg_ph = 'PKGNAME'
badmatch_prompt = [[
Enter number of file to view, Y to search online, or any other key to exit: ]]

nomatch_msg = [[
Unfortunately, there are no good matches for "PKGNAME".

]]
nomatch_msg_ph = 'PKGNAME'

nolocaldocs_msg = [[
You don't appear to have any local documentation installed.

]]
nolocaldocs_prompt = [[
Would you like to search online? (y/N) ]]

online_msg = [[
There may be online documentation available for "PKGNAME" at
    URL
This documentation may be for a different version than you have installed.

]]
online_msg_url = 'URL'
online_msg_ph = 'PKGNAME'
online_baseurl_ph = 'PKGNAME'

-- exit codes
exit_ok = 0
exit_error = 1  -- apparently hard-coded in Lua
exit_usage = 2
exit_notfound = 3

err_priority = {
    error = 1,
    warning = 2,
    info = 3,
}
min_verbosity = '0'  -- (nothing at all)
max_verbosity = '3'
def_verbosity = '2'

known_debugs = {
    config = {'files'},
    files = {},
    search = {},
    score = {},
    texdocs = {},
    tlpdb = {},
    version = {},
    view = {},
}

-- various cache or non-cache files
cache_name = 'texdoc/cache-tlpdb.lua'  -- relative to TEXMFVAR
data_tlpdb_name = 'texdoc/Data.tlpdb.lua'

place_holder = '%%s'  -- used for viewer commands

-- kpse path separator
kpse_sep = (os.type == 'windows') and ';' or ':'

-- language codes
-- Note: corrected with `find $TEXMFDIST/doc/ | awk 'match(
--       $0, /(.*)-(\w{2}).pdf/, a){print a[2]}'`
lang_codes = {
    cn = 'zh',  -- Chinese (alias)
    cz = 'cz',  -- Chech/Slovak
    de = 'de',  -- German
    ee = 'et',  -- Estonian
    en = 'en',  -- English
    es = 'es',  -- Spanish
    fr = 'fr',  -- French
    it = 'it',  -- Italian
    ja = 'ja',  -- Japanese
    nl = 'nl',  -- Dutch
    pl = 'pl',  -- Polish
    ro = 'ro',  -- Romanian
    ru = 'ru',  -- Russian
    sr = 'sr',  -- Serbian
    zh = 'zh',  -- Chinese
}

-- END constants

-- get our previous environment back
if setfenv then
    setfenv(1, texdoc_env)
else
    _ENV = texdoc_env
end

-- Make table C a read-only proxy to the local <constants>.
-- Note this is not deep read-only: C.known_debugs is read-only, but
-- C.known_debugs.version isn't, for instance.
local C = {}
setmetatable(C, {
    __index = constants,
    __newindew = function()
        error('Internal error: attempt to modify a constant.')
    end
})

return C

-- vim: ft=lua: