blob: 3869a95db2ed2a805ddea1421b923bbac5df2406 (
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
|
%D \module
%D [ file=mult-aux,
%D version=2010.08.2,
%D title=\CONTEXT\ Multilingual Macros,
%D subtitle=helpers,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D This is a subset of the \MKIV\ variant which has more comments). There
%D is no support for attributes (fonts and color). This code is mostly
%D meant for usage in modules that are backported from \MKIV.
\writestatus{loading}{ConTeXt Multilingual Macros / Helpers}
\unprotect
%D \starttyping
%D \unprotect
%D \def\????aa{@@@@aa}
%D
%D \installparameterhandler \????aa {whatever}
%D \installsetuphandler \????aa {whatever}
%D \installdefinehandler \????aa {whatever} \????aa % #3 == defaultroot
%D
%D % \installcommandhandler \????aa {whatever} \????aa
%D \protect
%D
%D % \whateverparameter \c!test
%D % \whateverparameterhash \c!test
%D % \namedwhateverparameter \mycurrentwhatever \c!test
%D % \everydefinewhatever (sets \currentwhatever)
%D % \everypresetwhatever (can be used to reset parameters as we can redefine)
%D % \everysetupwhatever (sets \currentwhatever)
%D
%D \starttext
%D \definewhatever[first] \definewhatever[second][first]
%D test: \def\currentwhatever{first} \whateverparameter{method} \par
%D \setupwhatever [method=unset] test: \def\currentwhatever{first} \whateverparameter{method} \par
%D \setupwhatever[first] [method=first] test: \def\currentwhatever{first} \whateverparameter{method} \par
%D test: \def\currentwhatever{second} \whateverparameter{method} \par
%D \setupwhatever[second][method=second] test: \def\currentwhatever{second} \whateverparameter{method} \par
%D \stoptext
%D \stoptyping
\unexpanded\def\doinstallparameterhandler#1#2#3#4#5#6#7#8#9%
{\def#3##1{\csname#4{#1#2}{##1}\endcsname}%
\def#4##1##2{\ifcsname##1##2\endcsname##1##2\else\expandafter#5\csname##1\s!parent\endcsname{##2}\fi}%
\def#5##1##2{\ifx##1\relax\s!empty\else#4{##1}{##2}\fi}%
\def#6##1##2{\csname#4{#1##1}{##2}\endcsname}%
\def#7##1{\detokenize\expandafter\expandafter\expandafter{\csname#1##1\endcsname}}% always root
\def#8{\dosetvalue{#1}}% ##1 {##2} (braces are mandate)
\def#9{\doletvalue{#1}}}% ##1 ##2
\unexpanded\def\installparameterhandler#1#2%
{%\message{\detokenize{#1}/\detokenize{#2}}%
\normalexpanded
{\doinstallparameterhandler
{\noexpand#1}% \??aa
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname #2parameter\endcsname
\expandafter\noexpand\csname do#2parameter\endcsname
\expandafter\noexpand\csname do#2parentparameter\endcsname
\expandafter\noexpand\csname named#2parameter\endcsname
\expandafter\noexpand\csname detokenized#2parameter\endcsname
\expandafter\noexpand\csname doset#2parameter\endcsname
\expandafter\noexpand\csname dolet#2parameter\endcsname}}
\unexpanded\def\doinstallparameterhashhandler#1#2#3#4#5%
{\def#3##1{#4{#1#2}{##1}}%
\def#4##1##2{\ifcsname##1##2\endcsname##1\else\expandafter#5\csname##1\s!parent\endcsname{##2}\fi}%
\def#5##1##2{\ifx##1\relax\else#4{##1}{##2}\fi}}
\unexpanded\def\installparameterhashhandler#1#2%
{\normalexpanded
{\doinstallparameterhashhandler
{\noexpand#1}% \??aa
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname #2parameterhash\endcsname
\expandafter\noexpand\csname do#2parameterhash\endcsname
\expandafter\noexpand\csname do#2parentparameterhash\endcsname}}
\unexpanded\def\doinstalldefinehandler#1#2#3#4#5#6#7%
{\unexpanded\def#2{\dotripleempty#5}%
\newtoks#6%
\newtoks#7%
\def#5[##1][##2][##3]% [child][parent][settings]
{\edef#4{##1}% % [child] [settings]
\the#6% predefine % [child][parent]
\ifthirdargument % [child]
\getparameters[#1#4][\s!parent=#1##2,##3]%
\else\ifsecondargument
\doifassignmentelse{##2}
{\getparameters[#1#4][\s!parent=#3,##2]}
{\getparameters[#1#4][\s!parent=#1##2]}%
\else
\getparameters[#1#4][\s!parent=#3]%
\fi\fi
\the#7}}
\unexpanded\def\installdefinehandler#1#2#3%
{\normalexpanded
{\doinstalldefinehandler
{\noexpand#1}% \??aa
\expandafter\noexpand\csname define#2\endcsname
{\noexpand#3}% root
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname d@define#2\endcsname
\expandafter\noexpand\csname everypreset#2\endcsname
\expandafter\noexpand\csname everydefine#2\endcsname}}
\unexpanded\def\doinstallsetuphandler#1#2#3#4#5%
{\unexpanded\def#2{\dodoubleempty#4}%
\newtoks#5%
\def#4[##1][##2]% maybe helper
{\ifsecondargument
\def\docommand####1% we will have a simple one as well
{\edef#3{####1}%
\getparameters[#1#3][##2]%
\the#5}%
\processcommalist[##1]\docommand
\else
\let#3\empty
\getparameters[#1][##1]%
\the#5%
\fi}}
\unexpanded\def\installsetuphandler#1#2%
{\normalexpanded
{\doinstallsetuphandler
{\noexpand#1}% \??aa
\expandafter\noexpand\csname setup#2\endcsname
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname d@setup#2\endcsname
\expandafter\noexpand\csname everysetup#2\endcsname}}
\unexpanded\def\installcommandhandler#1#2#3% \??self name \??parent (can be \??self)
{\installparameterhandler {#1}{#2}%
\installparameterhashhandler{#1}{#2}%
\installdefinehandler {#1}{#2}{#3}%
\installsetuphandler {#1}{#2}}
\unexpanded\def\installnamespace#1%
{\setvalue{????#1}{@@@@#1}}
\protect
|