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