core-env.mkxl /size: 25 Kb    last modification: 2021-10-28 13:51
1
%D \module
2
%D [ file=core-env, % was core-new
3
%D version=1995.01.01, % wrong
4
%D title=\CONTEXT\ Core Macros,
5
%D subtitle=New ones,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\writestatus
{
loading
}
{
ConTeXt
Core
Macros
/
Environments
}
15 16
\registerctxluafile
{
core
-
env
}
{
autosuffix
}
17 18
\unprotect
19 20
%D Modes:
21
%D
22
%D \starttyping
23
%D \enablemode[screen,paper,bound]
24
%D
25
%D \doifmodeelse {paper} {this} {that}
26
%D \doifmode {paper,screen} {this}
27
%D \doifnotmode {paper,bound} {that}
28
%D
29
%D \startmode [list]
30
%D \stopmode
31
%D
32
%D \startnotmode [list]
33
%D \stopnotmode
34
%D \stoptyping
35
%D
36
%D system modes have a * as prefix
37
%D
38
%D Sometimes, we want to prevent a mode for being set. Think of situations where a
39
%D style enables a mode, but an outer level style does not want that. Preventing can
40
%D be considered a permanent disabling on forehand.
41 42
\aliased
\let
\systemmodeprefix
\wildcardsymbol
43 44
% we will have \installcorenamespace{mode} but need some hackery at the lua end then
45 46
% TODO: make them mutable, also at the lua end
47 48
\installcorenamespace
{
modestack
}
49 50
\immutable
\def
\??mode
{
mode
>
}
% special namespace, also used at lua end
51 52
\permanent
\protected
\def
\newmode
#
1
{
\ifcsname
\??mode
#
1
\endcsname
\else
\resetmode
{
#
1
}
\fi
}
53
\permanent
\protected
\def
\setmode
#
1
{
\expandafter
\integerdef
\csname
\??mode
#
1
\endcsname
\plusone
}
54
\permanent
\protected
\def
\resetmode
#
1
{
\expandafter
\integerdef
\csname
\??mode
#
1
\endcsname
\zerocount
}
55
\permanent
\protected
\def
\globalsetmode
#
1
{
\global
\expandafter
\integerdef
\csname
\??mode
#
1
\endcsname
\plusone
}
56
\permanent
\protected
\def
\globalresetmode
#
1
{
\global
\expandafter
\integerdef
\csname
\??mode
#
1
\endcsname
\zerocount
}
57 58
\permanent
\protected
\def
\newsystemmode
#
1
{
\ifcsname
\??mode
\systemmodeprefix
#
1
\endcsname
\else
\resetsystemmode
{
#
1
}
\fi
}
59
\permanent
\protected
\def
\setsystemmode
#
1
{
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
\plusone
}
60
\permanent
\protected
\def
\resetsystemmode
#
1
{
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
\zerocount
}
61
\permanent
\protected
\def
\globalsetsystemmode
#
1
{
\global
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
\plusone
}
62
\permanent
\protected
\def
\globalresetsystemmode
#
1
{
\global
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
\zerocount
}
63 64
\expandafter
\appendtoks
65
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
trialtypesetting
\endcsname
\plusone
66
\luacopyinputnodes
\plusone
67
\to
\everysettrialtypesetting
68 69
\expandafter
\appendtoks
70
\expandafter
\integerdef
\csname
\??mode
\systemmodeprefix
trialtypesetting
\endcsname
\zerocount
71
\luacopyinputnodes
\zerocount
72
\to
\everyresettrialtypesetting
73 74
\pushoverloadmode
\newsystemmode
{
trialtypesetting
}
\popoverloadmode
75 76
\the
\everyresettrialtypesetting
77 78
% user ones
79 80
\mutable
\let
\syst_mode_prefix
\relax
81 82
\permanent
\protected
\def
\preventmode
{
\unprotect
\syst_modes_prevent
}
83
\permanent
\protected
\def
\enablemode
{
\unprotect
\syst_modes_enable
}
84
\permanent
\protected
\def
\disablemode
{
\unprotect
\syst_modes_disable
}
85 86
\permanent
\protected
\def
\globalpreventmode
{
\let
\syst_mode_prefix
\global
\unprotect
\syst_modes_prevent
}
87
\permanent
\protected
\def
\globalenablemode
{
\let
\syst_mode_prefix
\global
\unprotect
\syst_modes_enable
}
88
\permanent
\protected
\def
\globaldisablemode
{
\let
\syst_mode_prefix
\global
\unprotect
\syst_modes_disable
}
89 90
\def
\syst_modes_prevent
[
#
1
]
{
\protect
\fastprocesscommacommand
[
#
1
]
\syst_modes_prevent_indeed
\let
\syst_mode_prefix
\relax
}
91
\def
\syst_modes_enable
[
#
1
]
{
\protect
\fastprocesscommacommand
[
#
1
]
\syst_modes_enable_indeed
\let
\syst_mode_prefix
\relax
}
92
\def
\syst_modes_disable
[
#
1
]
{
\protect
\fastprocesscommacommand
[
#
1
]
\syst_modes_disable_indeed
\let
\syst_mode_prefix
\relax
}
93 94
\def
\syst_modes_prevent_indeed
#
1
%
95
{
\ifcsname
\??mode
#
1
\endcsname
\else
\setmode
{
#
1
}
\fi
96
\syst_mode_prefix
\expandafter
\integerdef
\lastnamedcs
\plustwo
}
97 98
\def
\syst_modes_enable_indeed
#
1
% we can speed it up by moving the new outside
99
{
\ifcsname
\??mode
#
1
\endcsname
\else
\setmode
{
#
1
}
\fi
100
\ifnum
\lastnamedcs
=
\plustwo
\else
101
\syst_mode_prefix
\expandafter
\integerdef
\lastnamedcs
\plusone
102
\fi
}
103 104
\def
\syst_modes_disable_indeed
#
1
%
105
{
\ifcsname
\??mode
#
1
\endcsname
\else
\setmode
{
#
1
}
\fi
106
\ifnum
\lastnamedcs
=
\plustwo
\else
107
\syst_mode_prefix
\expandafter
\integerdef
\lastnamedcs
\zerocount
108
\fi
}
109 110
%D If you do a lot of mode testing, it makes sense to define modes (or disable them
111
%D explicitly if unset. This makes testing twice as fast. Often one enables modes
112
%D beforehand, in which case \type {\definemode} would reset the mode. The optional
113
%D second argument \type {keep} will prevent changing the already set mode but defines
114
%D it when undefined.
115 116
\permanent
\protected
\def
\definemode
117
{
\unprotect
118
\syst_modes_define
}
119 120
\tolerant
\def
\syst_modes_define
[
#
1
]
#
*
[
#
2
]
%
121
{
\protect
122
\edef
\m_modes_asked
{
#
2
}
%
123
\fastprocesscommacommand
[
#
1
]
\syst_modes_define_indeed
}
124 125
\def
\syst_modes_define_indeed
#
1
%
126
{
\ifcsname
\??mode
#
1
\endcsname
127
% already set
128
\else
129
\newmode
{
#
1
}
%
130
\fi
131
\ifx
\m_modes_asked
\v!keep
132
% not changes, disabled when undefined
133
\orelse
\ifx
\m_modes_asked
\v!yes
134
\setmode
{
#
1
}
%
135
\else
136
\resetmode
{
#
1
}
%
137
\fi
}
138 139
% handy for mp
140 141
\permanent
\def
\booleanmodevalue
#
1
%
142
{
\ifcsname
\??mode
#
1
\endcsname
143
\ifcase
\lastnamedcs
144
\s!false
145
\or
146
\s!true
147
\else
148
\s!false
149
\fi
150
\else
151
\s!false
152
\fi
}
153 154
% check macros
155 156
\newconditional
\c_checked_mode
157 158
% one
159 160
\def
\syst_modes_check_indeed
#
1
%
161
{
\ifcsname
\??mode
#
1
\endcsname
162
\ifcase
\lastnamedcs
\else
163
\let
\syst_modes_check_step
\gobbleoneargument
164
\fi
165
\fi
}
166 167
\def
\syst_modes_check_nop
#
1
#
2
#
3
%
168
{
\let
\syst_modes_check_step
\syst_modes_check_indeed
169
\fastprocesscommacommand
[
#
3
]
\syst_modes_check_step
170
\ifx
\syst_modes_check_step
\gobbleoneargument
171
\expandafter
#
1
%
172
\else
173
\expandafter
#
2
%
174
\fi
}
175 176
\def
\syst_modes_check_yes
#
1
#
2
#
3
%
177
{
\ifcase
\lastnamedcs
178
\expandafter
#
2
%
179
\or
180
\expandafter
#
1
%
181
\else
182
\expandafter
#
2
%
183
\fi
}
184 185
\def
\syst_modes_check_lr
#
1
#
2
#
3
%
186
{
\ifcsname
\??mode
#
3
\endcsname
187
\expandafter
\syst_modes_check_yes
188
\else
189
\expandafter
\syst_modes_check_nop
190
\fi
#
1
#
2
{
#
3
}
}
191 192
\def
\syst_modes_check_ss
#
1
#
2
[
#
3
]
%
193
{
\ifcsname
\??mode
#
3
\endcsname
194
\expandafter
\syst_modes_check_yes
195
\else
196
\expandafter
\syst_modes_check_nop
197
\fi
#
1
#
2
{
#
3
}
}
198 199
% all
200 201
\let
\syst_modes_check_all_step
\gobbleoneargument
202 203
\def
\syst_modes_check_all_indeed
#
1
%
204
{
\ifcsname
\??mode
#
1
\endcsname
205
\ifcase
\lastnamedcs
206
\let
\syst_modes_check_all_step
\gobbleoneargument
207
\or
208
% enabled
209
\else
210
\let
\syst_modes_check_all_step
\gobbleoneargument
211
\fi
212
\else
213
\let
\syst_modes_check_all_step
\gobbleoneargument
214
\fi
}
215 216
\def
\syst_modes_check_all_lr
#
1
#
2
#
3
%
217
{
\let
\syst_modes_check_all_step
\syst_modes_check_all_indeed
218
\fastprocesscommacommand
[
#
3
]
\syst_modes_check_all_step
219
\ifx
\syst_modes_check_all_step
\gobbleoneargument
220
\expandafter
#
2
%
221
\else
222
\expandafter
#
1
%
223
\fi
}
224 225
\def
\syst_modes_check_all_ss
#
1
#
2
[
#
3
]
%
226
{
\let
\syst_modes_check_all_step
\syst_modes_check_all_indeed
227
\fastprocesscommacommand
[
#
3
]
\syst_modes_check_all_step
228
\ifx
\syst_modes_check_all_step
\gobbleoneargument
229
\expandafter
#
2
%
230
\else
231
\expandafter
#
1
%
232
\fi
}
233 234
\permanent
\protected
\def
\doifelsemode
{
\syst_modes_check_lr
\firstoftwoarguments
\secondoftwoarguments
}
235
\permanent
\protected
\def
\doifmode
{
\syst_modes_check_lr
\firstofoneargument
\gobbleoneargument
}
236
\permanent
\protected
\def
\doifnotmode
{
\syst_modes_check_lr
\gobbleoneargument
\firstofoneargument
}
237
\permanent
\protected
\def
\startmode
{
\syst_modes_check_ss
\donothing
\syst_modes_stop_yes
}
238
\permanent
\protected
\def
\startnotmode
{
\syst_modes_check_ss
\syst_modes_stop_nop
\donothing
}
239
\permanent
\protected
\def
\doifelseallmodes
{
\syst_modes_check_all_lr
\firstoftwoarguments
\secondoftwoarguments
}
240
\permanent
\protected
\def
\doifallmodes
{
\syst_modes_check_all_lr
\firstofoneargument
\gobbleoneargument
}
241
\permanent
\protected
\def
\doifnotallmodes
{
\syst_modes_check_all_lr
\gobbleoneargument
\firstofoneargument
}
242
\permanent
\protected
\def
\startallmodes
{
\syst_modes_check_all_ss
\donothing
\syst_modes_stop_all_yes
}
243
\permanent
\protected
\def
\startnotallmodes
{
\syst_modes_check_all_ss
\syst_modes_stop_all_nop
\donothing
}
244 245
\aliased
\let
\doifmodeelse
\doifelsemode
246
\aliased
\let
\doifallmodeselse
\doifelseallmodes
247 248
\permanent
\protected
\def
\stopmode
{
}
% no relax
249
\permanent
\protected
\def
\stopnotmode
{
}
% no relax
250
\permanent
\protected
\def
\stopallmodes
{
}
% no relax
251
\permanent
\protected
\def
\stopnotallmodes
{
}
% no relax
252 253
\def
\syst_modes_stop_yes
#
1
\stopmode
{
}
254
\def
\syst_modes_stop_nop
#
1
\stopnotmode
{
}
255
\def
\syst_modes_stop_all_yes
#
1
\stopallmodes
{
}
256
\def
\syst_modes_stop_all_nop
#
1
\stopnotallmodes
{
}
257 258
%D Pushing/popping:
259 260
\permanent
\protected
\def
\pushmode
[
#
1
]
{
\expandafter
\pushmacro
\csname
\??mode
#
1
\endcsname
}
261
\permanent
\protected
\def
\popmode
[
#
1
]
{
\expandafter
\popmacro
\csname
\??mode
#
1
\endcsname
}
262 263
\permanent
\protected
\def
\pushsystemmode
#
1
{
\expandafter
\pushmacro
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
}
264
\permanent
\protected
\def
\popsystemmode
#
1
{
\expandafter
\popmacro
\csname
\??mode
\systemmodeprefix
#
1
\endcsname
}
265 266
%D Here is a relatively new variant of mode checking:
267
%D
268
%D \starttyping
269
%D \enablemode[two]
270
%D
271
%D \startmodeset
272
%D [one] {1}
273
%D [two] {2}
274
%D [two] {2}
275
%D [three] {3}
276
%D [default] {?}
277
%D \stopmodeset
278
%D
279
%D \startmodeset
280
%D [one] {1}
281
%D [three] {3}
282
%D [default] {?}
283
%D \stopmodeset
284
%D
285
%D \startmodeset
286
%D [one] {
287
%D \input tufte
288
%D }
289
%D [two] {
290
%D \startmodeset
291
%D [one] {1}
292
%D [two] {2}
293
%D [two] {2}
294
%D [three] {3}
295
%D [default] {?}
296
%D \stopmodeset
297
%D }
298
%D [three] {
299
%D \input zapf
300
%D }
301
%D [default] {
302
%D \input ward
303
%D }
304
%D \stopmodeset
305
%D \stoptyping
306 307
\newconditional
\c_syst_modes_set_done
% conditionals can be pushed/popped
308 309
\installmacrostack
\c_syst_modes_set_done
310 311
\permanent
\protected
\def
\startmodeset
312
{
\push_macro_c_syst_modes_set_done
313
\setfalse
\c_syst_modes_set_done
314
\syst_modes_set_start
}
315 316
\permanent
\protected
\lettonothing
\stopmodeset
317 318
\tolerant
\def
\syst_modes_set_start
#
.
[
#
1
]
% skip spaces and pars
319
{
\edef
\m_mode_case
{
#
1
}
%
320
\ifempty
\m_mode_case
321
\expandafter
\syst_modes_set_quit
322
\orunless
\ifx
\m_mode_case
\s!default
323
\expandafter
\syst_modes_set_check
324
\orelse
\ifconditional
\c_syst_modes_set_done
325
\expandafter
\syst_modes_set_quit
326
\else
327
\expandafter
\syst_modes_set_yes
328
\fi
}
329 330
\def
\syst_modes_set_check
331
{
\syst_modes_check_lr
\syst_modes_set_yes
\syst_modes_set_nop
\m_mode_case
}
332 333
\tolerant
\def
\syst_modes_set_yes
#
1
%
334
{
\settrue
\c_syst_modes_set_done
335
#
1
%
336
\syst_modes_set_start
}
337 338
\tolerant
\def
\syst_modes_set_nop
#
1
%
339
{
\syst_modes_set_start
}
340 341
\def
\syst_modes_set_quit
#
-
\stopmodeset
342
{
\pop_macro_c_syst_modes_set_done
}
343 344
%D Lets now set a few modes:
345 346
\enablemode
[
mkiv
]
\newsystemmode
{
mkiv
}
\setsystemmode
{
mkiv
}
% also mkxl
347
\enablemode
[
lmtx
]
\newsystemmode
{
lmtx
}
\setsystemmode
{
lmtx
}
348 349
%D Setups:
350 351
\installcorenamespace
{
setup
}
% we can probably get rid of some :'s later on
352 353
% \protected\def\startsetups{} % to please dep checker
354
% \protected\def\stopsetups {} % to please dep checker
355
%
356
% \protected\def\setups{\doifelsenextbgroup\syst_setups_a\syst_setups_b} % {..} or [..]
357
% \protected\def\setup {\doifelsenextbgroup\syst_setups \syst_setups_c} % {..} or [..]
358
%
359
% \def\syst_setups_a #1{\processcommacommand[#1]\syst_setups} % {..}
360
% \def\syst_setups_b[#1]{\processcommacommand[#1]\syst_setups} % [..]
361
% \def\syst_setups_c[#1]{\syst_setups{#1}} % [..]
362 363
\permanent
\protected
\tolerant
\def
\setups
[
#
1
]
#
;
#
2
{
\processcommacommand
[
#
1
#
2
]
\syst_setups
}
% {..} or [..]
364
\permanent
\protected
\tolerant
\def
\setup
[
#
1
]
#
;
#
2
{
\syst_setups
{
#
1
#
2
}
}
% {..} or [..]
365 366
\letcsname
\??setup
:
\??empty
\endcsname
\gobbleoneargument
367 368
\permanent
\def
\syst_setups
#
1
% the grid option will be extended to other main modes
369
{
\csname
\??setup
370
\ifgridsnapping
371
\ifcsname
\??setup
\v!grid
:
#
1
\endcsname
\v!grid
:
#
1
\else
:
\ifcsname
\??setup
:
#
1
\endcsname
#
1
\else
\??empty
\fi
\fi
372
\else
373
:
\ifcsname
\??setup
:
#
1
\endcsname
#
1
\else
\??empty
\fi
374
\fi
375
\endcsname
\empty
}
% takes one argument
376 377
% no checking and we assume it being defined:
378 379
\permanent
\def
\fastsetup
#
1
{
\csname
\??setup
:
#
1
\endcsname
\empty
}
380
\permanent
\def
\fastsetupwithargument
#
1
{
\csname
\??setup
:
#
1
\endcsname
}
% swapped per 2015-08-30
381
\permanent
\def
\fastsetupwithargumentswapped
#
1
#
2
{
\csname
\??setup
:
#
2
\endcsname
{
#
1
}
}
% swapped per 2015-09-05
382 383
% the next one is meant for \c!setups situations, hence the check for
384
% a shortcut
385 386
\let
\m_syst_setups_asked
\empty
387 388
\permanent
\protected
\def
\doprocesslocalsetups
#
1
% sort of public, fast local variant
389
{
\edef
\m_syst_setups_asked
{
#
1
}
%
390
\ifempty
\m_syst_setups_asked
\else
391
\expandafter
\syst_setups_process_local
392
\fi
}
393 394
\permanent
\protected
\def
\usesetupsparameter
#
1
%
395
{
\edef
\m_syst_setups_asked
{
#
1
\c!setups
}
%
396
\ifempty
\m_syst_setups_asked
\else
397
\expandafter
\syst_setups_process_local
398
\fi
}
399 400
% setups=S1
401
% setups=lua(S2)
402
% setups=S3
403
% setups={S1,lua(S2),xml(test{123}),S3}
404 405
\def
\syst_setups_process_local
406
{
\clf_autosetups
{
\m_syst_setups_asked
}
%
407
\relax
}
% let's prevent lookahead
408 409
\permanent
\def
\autosetups
#
1
{
\clf_autosetups
{
#
1
}
}
% todo: public implementor
410 411
\permanent
\edef
\setupwithargument
#
1
% saves a few expansions and is faster
412
{
\noexpand
\csname
\??setup
:
\noexpand
\ifcsname
\??setup
:
#
1
\endcsname
#
1
\noexpand
\else
\??empty
\noexpand
\fi
\endcsname
}
413 414
\permanent
\edef
\setupwithargumentswapped
#
1
#
2
% saves a few expansions (can be \let)
415
{
\noexpand
\csname
\??setup
:
\noexpand
\ifcsname
\??setup
:
#
2
\endcsname
#
2
\noexpand
\else
\??empty
\noexpand
\fi
\endcsname
{
#
1
}
}
416 417
\aliased
\let
\directsetup
\syst_setups
418
\aliased
\let
\texsetup
\syst_setups
% nicer than \directsetup and more en par with xmlsetup and luasetup
419 420
\permanent
\protected
\def
\doifelsesetups
#
1
% to be done: grid
421
{
\ifcsname
\??setup
:
#
1
\endcsname
422
\expandafter
\firstoftwoarguments
423
\else
424
\expandafter
\secondoftwoarguments
425
\fi
}
426 427
\aliased
\let
\doifsetupselse
\doifelsesetups
428 429
\permanent
\protected
\def
\doifsetups
#
1
% to be done: grid
430
{
\ifcsname
\??setup
:
#
1
\endcsname
431
\expandafter
\firstofoneargument
432
\else
433
\expandafter
\gobbleoneargument
434
\fi
}
435 436
\permanent
\protected
\def
\doifnotsetups
#
1
% to be done: grid
437
{
\ifcsname
\??setup
:
#
1
\endcsname
438
\expandafter
\gobbleoneargument
439
\else
440
\expandafter
\firstofoneargument
441
\fi
}
442 443
% maybe some day:
444
%
445
% \protected\def\fastsetupfallback#1#2%
446
% {\ifcsname\??setup:#1\endcsname
447
% \expandafter\lastnamedcs
448
% \else
449
% \csname\??setup:#2\expandafter\endcsname
450
% \fi}
451
%
452
% or
453
%
454
% \protected\def\fastsetupfallback#1#2#3% prefix preferred fallback
455
% {\ifcsname\??setup:#1#2\endcsname
456
% \expandafter\lastnamedcs
457
% \else
458
% \csname\??setup:#1#3\expandafter\endcsname
459
% \fi}
460 461
% \startluasetups oeps
462
% context("DONE")
463
% a = 1
464
% b = 1
465
% \stopluasetups
466
%
467
% \luasetup{oeps}
468
%
469
% \startsetups xxx
470
% ziezo
471
% \stopsetups
472
%
473
% \directsetup{xxx}
474
%
475
% \startxmlsetups zzz
476
% [[#1]]
477
% \stopxmlsetups
478
%
479
% \xmlsetup{123}{zzz}
480
%
481
% \startbuffer[what]
482
% context("DONE")
483
% \stopbuffer
484
%
485
% \startbuffer
486
% context("MORE")
487
% \stopbuffer
488
%
489
% \ctxluabuffer[what]
490
%
491
% \ctxluabuffer
492 493
\newtoks
\t_syst_setups_tex
\appendtoks
494
\catcode
\endoflineasciicode
\ignorecatcode
495
\to
\t_syst_setups_tex
496 497
\newtoks
\t_syst_setups_loc
\appendtoks
498
\catcode
\endoflineasciicode
\ignorecatcode
499
\to
\t_syst_setups_loc
500 501
\newtoks
\t_syst_setups_raw
\appendtoks
502
% nothing
503
\to
\t_syst_setups_raw
504 505
\newtoks
\t_syst_setups_xml
\appendtoks
506
\catcode
\endoflineasciicode
\ignorecatcode
507
\catcode
\barasciicode
\othercatcode
508
\to
\t_syst_setups_xml
509 510
\newtoks
\t_syst_setups_lua
\appendtoks
511
\obeyluatokens
512
\to
\t_syst_setups_lua
513 514
% Is doglobal still relevant? Maybe always global? Or never? Anyway, it will become obsolete.
515 516
\permanent
\protected
\def
\startluasetups
{
\begingroup
\doifelsenextoptionalcs
\syst_setups_start_lua_yes
\syst_setups_start_lua_nop
}
\permanent
\protected
\lettonothing
\stopluasetups
517
\permanent
\protected
\def
\startxmlsetups
{
\begingroup
\doifelsenextoptionalcs
\syst_setups_start_xml_yes
\syst_setups_start_xml_nop
}
\permanent
\protected
\lettonothing
\stopxmlsetups
518
\permanent
\protected
\def
\startrawsetups
{
\begingroup
\doifelsenextoptionalcs
\syst_setups_start_raw_yes
\syst_setups_start_raw_nop
}
\permanent
\protected
\lettonothing
\stoprawsetups
519
\permanent
\protected
\def
\startlocalsetups
{
\begingroup
\doifelsenextoptionalcs
\syst_setups_start_loc_yes
\syst_setups_start_loc_nop
}
\permanent
\protected
\lettonothing
\stoplocalsetups
520
\permanent
\protected
\def
\startsetups
{
\begingroup
\doifelsenextoptionalcs
\syst_setups_start_tex_yes
\syst_setups_start_tex_nop
}
\permanent
\protected
\lettonothing
\stopsetups
521 522
\def
\syst_setups_start_lua_two
#
1
#
2
#
+
\stopluasetups
{
\endgroup
\dodoglobal
\instance
\defcsname
\??setup
#
1
:
#
2
\endcsname
#
#
1
{
#
3
}
}
523
\def
\syst_setups_start_xml_two
#
1
#
2
#
+
\stopxmlsetups
{
\endgroup
\dodoglobal
\instance
\defcsname
\??setup
#
1
:
#
2
\endcsname
#
#
1
{
#
3
}
}
524
\def
\syst_setups_start_raw_two
#
1
#
2
#
+
\stoprawsetups
{
\endgroup
\dodoglobal
\instance
\defcsname
\??setup
#
1
:
#
2
\endcsname
#
#
1
{
#
3
}
}
525
\def
\syst_setups_start_loc_two
#
1
#
2
#
+
\stoplocalsetups
{
\endgroup
\dodoglobal
\instance
\defcsname
\??setup
#
1
:
#
2
\endcsname
#
#
1
{
#
3
}
}
526
\def
\syst_setups_start_tex_two
#
1
#
2
#
+
\stopsetups
{
\endgroup
\dodoglobal
\instance
\defcsname
\??setup
#
1
:
#
2
\endcsname
#
#
1
{
#
3
}
}
527 528
\tolerant
\def
\syst_setups_start_lua_yes
[
#
1
]
#
*
[
#
2
]
%
529
{
\the
\t_syst_setups_lua
530
\ifarguments
\expandafter
\syst_setups_start_lua_one
531
\or
\expandafter
\syst_setups_start_lua_one
532
\else
\expandafter
\syst_setups_start_lua_two
533
\fi
{
#
1
}
{
#
2
}
}
534 535
\tolerant
\def
\syst_setups_start_xml_yes
[
#
1
]
#
*
[
#
2
]
%
536
{
\the
\t_syst_setups_xml
537
\ifarguments
\expandafter
\syst_setups_start_xml_one
538
\or
\expandafter
\syst_setups_start_xml_one
539
\else
\expandafter
\syst_setups_start_xml_two
540
\fi
{
#
1
}
{
#
2
}
}
541 542
\tolerant
\def
\syst_setups_start_raw_yes
[
#
1
]
#
*
[
#
2
]
%
543
{
\the
\t_syst_setups_raw
544
\ifarguments
\expandafter
\syst_setups_start_raw_one
545
\or
\expandafter
\syst_setups_start_raw_one
546
\else
\expandafter
\syst_setups_start_raw_two
547
\fi
{
#
1
}
{
#
2
}
}
548 549
\tolerant
\def
\syst_setups_start_loc_yes
[
#
1
]
#
*
[
#
2
]
%
550
{
\the
\t_syst_setups_loc
551
\ifarguments
\expandafter
\syst_setups_start_loc_one
552
\or
\expandafter
\syst_setups_start_loc_one
553
\else
\expandafter
\syst_setups_start_loc_two
554
\fi
{
#
1
}
{
#
2
}
}
555 556
\tolerant
\def
\syst_setups_start_tex_yes
[
#
1
]
#
*
[
#
2
]
%
557
{
\the
\t_syst_setups_tex
558
\ifarguments
\expandafter
\syst_setups_start_tex_one
559
\or
\expandafter
\syst_setups_start_tex_one
560
\else
\expandafter
\syst_setups_start_tex_two
561
\fi
{
#
1
}
{
#
2
}
}
562 563
\def
\syst_setups_start_lua_nop
#
1
{
\the
\t_syst_setups_lua
\syst_setups_start_lua_two
{
}
{
#
1
}
}
% space delimited
564
\def
\syst_setups_start_xml_nop
#
1
{
\the
\t_syst_setups_xml
\syst_setups_start_xml_two
{
}
{
#
1
}
}
% space delimited
565
\def
\syst_setups_start_raw_nop
#
1
{
\the
\t_syst_setups_raw
\syst_setups_start_raw_two
{
}
{
#
1
}
}
% space delimited
566
\def
\syst_setups_start_loc_nop
#
1
{
\the
\t_syst_setups_loc
\syst_setups_start_loc_two
{
}
{
#
1
}
}
% space delimited
567
\def
\syst_setups_start_tex_nop
#
1
{
\the
\t_syst_setups_tex
\syst_setups_start_tex_two
{
}
{
#
1
}
}
% space delimited
568 569
\def
\syst_setups_start_lua_one
#
1
#
2
{
\syst_setups_start_lua_two
{
}
{
#
1
}
}
% [..]
570
\def
\syst_setups_start_xml_one
#
1
#
2
{
\syst_setups_start_xml_two
{
}
{
#
1
}
}
% [..]
571
\def
\syst_setups_start_raw_one
#
1
#
2
{
\syst_setups_start_raw_two
{
}
{
#
1
}
}
% [..]
572
\def
\syst_setups_start_loc_one
#
1
#
2
{
\syst_setups_start_loc_two
{
}
{
#
1
}
}
% [..]
573
\def
\syst_setups_start_tex_one
#
1
#
2
{
\syst_setups_start_tex_two
{
}
{
#
1
}
}
% [..]
574 575
\permanent
\def
\luasetup
#
1
{
\ctxlua{
\syst_setups
{
#
1
}
}
}
576 577
%D System setups:
578 579
\aliased
\let
\systemsetupsprefix
\wildcardsymbol
580 581
\permanent
\def
\systemsetups
#
1
{
\syst_setups
{
\systemsetupsprefix
#
1
}
}
582 583
\permanent
\protected
\def
\resetsetups
[
#
1
]
% see x-fo for usage
584
{
\ifcsname
\??setup
\ifgridsnapping
\v!grid
\fi
:
#
1
\endcsname
585
\dodoglobal
\undefinevalue
{
\??setup
\ifgridsnapping
\v!grid
\fi
:
#
1
}
%
586
\else
587
\dodoglobal
\undefinevalue
{
\??setup
:
#
1
}
%
588
\fi
}
589 590
\permanent
\tolerant
\protected
\def
\copysetups
[
#
1
]
#
*
[
#
2
]
%
591
{
\ifcsname
\??setup
:
#
2
\endcsname
592
\letcsname
\??setup
:
#
1
\expandafter
\endcsname
\lastnamedcs
593
\fi
}
594 595
\permanent
\protected
\def
\showsetupsdefinition
[
#
1
]
%
596
{
\showvalue
{
\??setup
:
#
1
}
}
% temp hack for debugging
597 598
%D \macros
599
%D {setvariables,getvariable,getvariabledefault}
600
%D
601
%D \starttyping
602
%D \setvariables[xx][title=]
603
%D \setvariables[xx][title=test test]
604
%D \setvariables[xx][title=test $x=1$ test] % fatal error reported
605
%D \setvariables[xx][title=test {$x=1$} test]
606
%D \setvariables[xx][title] % fatal error reported
607
%D \setvariables[xx][titletitel=e]
608
%D \stoptyping
609 610
\installcorenamespace
{
variables
}
611 612
\permanent
\protected
\def
\setvariables
{
\syst_variables_set
[
\getrawparameters
]
}
613
\permanent
\protected
\def
\setevariables
{
\syst_variables_set
[
\getraweparameters
]
}
614
\permanent
\protected
\def
\setgvariables
{
\syst_variables_set
[
\getrawgparameters
]
}
615
\permanent
\protected
\def
\setxvariables
{
\syst_variables_set
[
\getrawxparameters
]
}
616 617
\mutable
\let
\currentvariableclass
\empty
618 619
\tolerant
\def
\syst_variables_set
[
#
1
]
#
*
[
#
2
]
#
*
[
#
3
]
% tricky, test on s-pre-60
620
{
\doifelse
{
#
2
}
\currentvariableclass
621
{
#
1
[
\??variables
#
2
:
]
[
#
3
]
}
%
622
{
\pushmacro
\currentvariableclass
623
\def
\currentvariableclass
{
#
2
}
%
624
\getvariable
{
#
2
}
\s!reset
625
#
1
[
\??variables
#
2
:
]
[
#
3
]
%
626
\getvariable
{
#
2
}
\s!set
627
\popmacro
\currentvariableclass
}
}
628 629
\permanent
\protected
\def
\setvariable
#
1
#
2
#
3
{
\defcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
}
630
\permanent
\protected
\def
\setevariable
#
1
#
2
#
3
{
\edefcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
}
631
\permanent
\protected
\def
\setgvariable
#
1
#
2
#
3
{
\defcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
}
632
\permanent
\protected
\def
\setxvariable
#
1
#
2
#
3
{
\xdefcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
}
633 634
\permanent
\def
\getvariable
#
1
#
2
{
\begincsname
\??variables
#
1
:
#
2
\endcsname
}
635
\permanent
\protected
\def
\showvariable
#
1
#
2
{
\showvalue
{
\begincsname
\??variables
#
1
:
#
2
\endcsname
}
}
636 637
\let
\currentvariableclass
\empty
638 639
%D \macros
640
%D {checkvariables}
641
%D
642
%D I'll probably forget that this on exists.
643 644
\let
\m_syst_variables_temp
\empty
645 646
\permanent
\tolerant
\def
\checkvariables
[
#
1
]
#
*
[
#
2
]
%
647
{
\dogetparameters
\syst_variables_check_value
[
#
1
]
[
#
2
]
}
648 649
\def
\syst_variables_check_value
#
1
#
2
#
3
%
650
{
\ifcsname
\??variables
#
1
:
#
2
\endcsname
651
\edef
\m_syst_variables_temp
{
\lastnamedcs
}
%
652
\ifempty
\m_syst_variables_temp
653
\defcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
%
654
\fi
655
\else
656
\defcsname
\??variables
#
1
:
#
2
\endcsname
{
#
3
}
%
657
\fi
}
658 659
%D \macros
660
%D {doifelsevariable,doifvariable,doifnotvariable}
661
%D
662
%D A few trivial macros:
663 664
\permanent
\protected
\def
\doifelsevariable
#
1
#
2
%
665
{
\ifcsname
\??variables
#
1
:
#
2
\endcsname
666
\expandafter
\firstoftwoarguments
667
\else
668
\expandafter
\secondoftwoarguments
669
\fi
}
670 671
\aliased
\let
\doifvariableelse
\doifelsevariable
672 673
\permanent
\protected
\def
\doifvariable
#
1
#
2
%
674
{
\ifcsname
\??variables
#
1
:
#
2
\endcsname
675
\expandafter
\firstofoneargument
676
\else
677
\expandafter
\gobbleoneargument
678
\fi
}
679 680
\permanent
\protected
\def
\doifnotvariable
#
1
#
2
%
681
{
\ifcsname
\??variables
#
1
:
#
2
\endcsname
682
\expandafter
\gobbleoneargument
683
\else
684
\expandafter
\firstofoneargument
685
\fi
}
686 687
%D A few more (we could use a public test variable so that we only need to expand
688
%D once, assuming expandable variables):
689 690
\letcsname
\??variables
:
\endcsname
\empty
691 692
\permanent
\protected
\def
\doifelseemptyvariable
#
1
#
2
%
693
{
\edef
\m_syst_string_one
{
\begincsname
\??variables
#
1
:
#
2
\endcsname
}
%
694
\ifempty
\m_syst_string_one
695
\expandafter
\firstoftwoarguments
696
\else
697
\expandafter
\secondoftwoarguments
698
\fi
}
699 700
\aliased
\let
\doifemptyvariableelse
\doifelseemptyvariable
701 702
\permanent
\protected
\def
\doifemptyvariable
#
1
#
2
%
703
{
\edef
\m_syst_string_one
{
\begincsname
\??variables
#
1
:
#
2
\endcsname
}
%
704
\ifempty
\m_syst_string_one
705
\expandafter
\firstofoneargument
706
\else
707
\expandafter
\gobbleoneargument
708
\fi
}
709 710
\permanent
\protected
\def
\doifnotemptyvariable
#
1
#
2
%
711
{
\edef
\m_syst_string_one
{
\begincsname
\??variables
#
1
:
#
2
\endcsname
}
%
712
\ifempty
\m_syst_string_one
713
\expandafter
\gobbleoneargument
714
\else
715
\expandafter
\firstofoneargument
716
\fi
}
717 718
\permanent
\def
\getvariabledefault
#
1
#
2
% #3% can be command
719
{
\ifcsname
\??variables
#
1
:
#
2
\endcsname
720
\expandafter
\expandafter
\expandafter
\lastnamedcs
\expandafter
\gobbleoneargument
721
\else
722
\expandafter
\firstofoneargument
723
\fi
}
724 725
\permanent
\tolerant
\protected
\def
\setupenv
[
#
1
]
%
726
{
\syst_variables_set
[
\getrawparameters
]
[
\s!environment
]
[
#
1
]
}
727 728
\permanent
\protected
\def
\doifelseenv
{
\doifelsevariable
\s!environment
}
729
\permanent
\protected
\def
\doifenv
{
\doifvariable
\s!environment
}
730
\permanent
\protected
\def
\doifnotenv
{
\doifnotvariable
\s!environment
}
731
\permanent
\def
\env
{
\getvariable
\s!environment
}
732
\permanent
\def
\envvar
{
\getvariabledefault
\s!environment
}
733 734
\aliased
\let
\doifenvelse
\doifelseenv
735 736
%D \macros
737
%D {defineselector,setupselector,select,directselect}
738
%D
739
%D \starttyping
740
%D \defineselector[caption][max=2,n=2]
741
%D
742
%D \start
743
%D \setupselector[caption][n=1]
744
%D \placelist[figure][criterium=all]
745
%D \stop
746
%D
747
%D \starttext
748
%D \placefigure
749
%D {\select{caption}{zapf}{\input zapf \relax}}
750
%D {}
751
%D \stoptext
752
%D \stoptyping
753 754
\installcorenamespace
{
selector
}
755 756
\permanent
\tolerant
\protected
\def
\defineselector
[
#
1
]
#
*
[
#
2
]
{
\getparameters
[
\??selector
#
1
]
[
\c!max
=
\plusone
,
\c!n
=
\plusone
,
#
2
]
}
757
\permanent
\tolerant
\protected
\def
\setupselector
[
#
1
]
#
*
[
#
2
]
{
\getparameters
[
\??selector
#
1
]
[
#
2
]
}
758 759
\permanent
\def
\directselect
#
1
% expandable
760
{
\expandafter
\filterfromnext
761
\csname
\??selector
\ifcsname
\??selector
#
1
\c!max
\endcsname
#
1
\fi
\c!max
\expandafter
\endcsname
762
\csname
\??selector
\ifcsname
\??selector
#
1
\c!n
\endcsname
#
1
\fi
\c!n
\endcsname
}
763 764
\permanent
\protected
\let
\select
\directselect
% we promote to protected
765 766
\letcsname
\??selector
\c!max
\endcsname
\plusone
767
\letcsname
\??selector
\c!n
\endcsname
\plusone
768 769
\protect
\endinput
770