mult-ini.mkiv /size: 28 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mult-ini,
3
%D version=2008.10.22, % 1996.06.01,
4
%D title=\CONTEXT\ Multilingual Macros,
5
%D subtitle=Initialization,
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
%D This module is a stripped down version of \type {mult-ini.tex}, which we keep
15
%D around as \type {mult-kep.tex} for sentimental reasons. There you will find some
16
%D more historic information.
17 18
\writestatus
{
loading
}{
ConTeXt
Multilingual
Macros
/
Initialization
}
19 20
\unprotect
21 22
\registerctxluafile
{
mult
-
ini
}{}
23 24
%D \macros
25
%D [constanten,variabelen,commands]
26
%D {v!,c!,k!,s!,e!,m!,l!,r!,f!,p!,x!,y!}
27
%D
28
%D In the system modules we introduced some prefixed constants, variables (both
29
%D macros) and registers. Apart from a tremendous saving in terms of memory and a
30
%D gain in speed we use from now on prefixes when possible for just another reason:
31
%D consistency and multi||linguality. Systematically using prefixed macros enables
32
%D us to implement a multi||lingual user interface. Redefining these next set of
33
%D prefixes therefore can have desastrous results.
34
%D
35
%D \startlinecorrection
36
%D \starttable[|c|c|c|]
37
%D \HL
38
%D \NC \bf prefix \NC \bf meaning \NC \bf application \NC\SR
39
%D \HL
40
%D \NC \type{\c!prefix!} \NC c! \NC constant (direct) \NC\FR
41
%D \NC \type{\k!prefix!} \NC k! \NC constant (indirect) \NC\FR
42
%D \NC \type{\e!prefix!} \NC e! \NC element \NC\MR
43
%D \NC \type{\f!prefix!} \NC f! \NC file \NC\MR
44
%D \NC \type{\m!prefix!} \NC m! \NC age \NC\MR
45
%D \NC \type{\s!prefix!} \NC s! \NC system \NC\MR
46
%D \NC \type{\v!prefix!} \NC v! \NC variable \NC\MR
47
%D \HL
48
%D \stoptable
49
%D \stoplinecorrection
50
%D
51
%D In the single||lingual version we used \type {!}, \type {!!}, \type {!!!} and
52
%D \type {!!!!}. In the meantime some of these are obsolete (we had some 12
53
%D originally).
54 55
\def
\c!prefix!
{
c
!
}
56
\def
\k!prefix!
{
k
!
}
57
\def
\e!prefix!
{
e
!
}
58
\def
\f!prefix!
{
f
!
}
% for the moment we keep this one
59
\def
\m!prefix!
{
m
!
}
60
\def
\s!prefix!
{
s
!
}
61
\def
\v!prefix!
{
v
!
}
62 63
%D \macros
64
%D [constants,variables,commands]
65
%D {@@,??}
66
%D
67
%D Variables generated by the system can be recognized on their prefix \type {@@}.
68
%D They are composed of a command (class) specific tag, which can be recognized on
69
%D \type {??}, and a system constant, which has the prefix \type {c!}. We'll se some
70
%D more of this.
71 72
\def
\??prefix
{
?
?
}
73
\def
\@@prefix
{
@
@
}
74 75
%D Just to be complete we repeat some of the already defined system constants here.
76
%D Maybe their prefix \type {\s!} now falls into place.
77 78
\def
\s!next
{
next
}
\def
\s!default
{
default
}
79
\def
\s!dummy
{
dummy
}
\def
\s!unknown
{
unknown
}
80 81
\def
\s!do
{
do
}
\def
\s!dodo
{
dodo
}
82 83
\def
\s!complex
{
complex
}
\def
\s!start
{
start
}
84
\def
\s!simple
{
simple
}
\def
\s!stop
{
stop
}
85 86
\def
\s!true
{
true
}
87
\def
\s!false
{
false
}
88 89
%D The word \type {height} takes 6~token memory cells. The control sequence \type
90
%D {\height} on the other hand uses only one. Knowing this, we can improve the
91
%D performance of \TEX, both is terms of speed and memory usage, by using control
92
%D sequences instead of the words written in full.
93
%D
94
%D Where in the \ASCII\ file the second lines takes nine extra characters, \TEX\
95
%D saves us 13~tokens.
96
%D
97
%D \starttyping
98
%D \hrule width 10pt height 2pt depth 1pt
99
%D \hrule \s!width 10pt \s!height 2pt \s!depth 1pt
100
%D \stoptyping
101
%D
102
%D One condition is that we have defined \type {\s!height}, \type {\s!width} and
103
%D \type {\s!depth} as respectively \type {height}, \type {width} and \type {depth}.
104
%D Using this scheme therefore only makes sense when a token sequence is used more
105
%D than once. Savings like this should of course be implemented in english, just
106
%D because \TEX\ is english.
107 108
\def
\s!width
{
width
}
\let
\!!width
\s!width
% obsolete
109
\def
\s!height
{
height
}
\let
\!!height
\s!height
% obsolete
110
\def
\s!depth
{
depth
}
\let
\!!depth
\s!depth
% obsolete
111
\def
\s!spread
{
spread
}
\let
\!!spread
\s!spread
% obsolete
112
\def
\s!plus
{
plus
}
\let
\!!plus
\s!plus
% obsolete
113
\def
\s!minus
{
minus
}
\let
\!!minus
\s!minus
% obsolete
114
\def
\s!left
{
left
}
115
\def
\s!right
{
right
}
116
\def
\s!fil
{
fil
}
117
\def
\s!fill
{
fill
}
\let
\!!fill
\s!fill
% obsolete
118
\def
\s!filll
{
filll
}
119
\def
\s!to
{
to
}
\let
\!!to
\s!to
% obsolete
120
\def
\s!attr
{
attr
}
121
\def
\s!axis
{
axis
}
122 123
\def
\s!bottom
{
bottom
}
124
\def
\s!top
{
top
}
125
\def
\s!both
{
both
}
126 127
\def
\s!reverse
{
reverse
}
128
\def
\s!orientation
{
orientation
}
129
\def
\s!xoffset
{
xoffset
}
130
\def
\s!xmove
{
xmove
}
131
\def
\s!yoffset
{
yoffset
}
132
\def
\s!ymove
{
ymove
}
133 134
%D \macros
135
%D {defineinterfaceconstant,
136
%D defineinterfacevariable,
137
%D defineinterfaceelement,
138
%D definesystemvariable,
139
%D definesystemconstant,
140
%D definemessageconstant,
141
%D definefileconstant}
142
%D
143
%D The first part of this module is dedicated to dealing with multi||lingual
144
%D constants and variables. When \CONTEXT\ grew bigger and bigger in terms of bytes
145
%D and used string space, we switched to predefined constants. At the cost of more
146
%D hash table entries, the macros not only becase more compact, they became much
147
%D faster too. Maybe an even bigger advantage was that mispelling could no longer
148
%D lead to problems. Even a multi||lingual interface became possible.
149
%D
150
%D Constants |<|we'll introduce the concept of variables later on|>| are preceded by
151
%D a type specific prefix, followed by a \type {!}. To force consistency, we provide
152
%D a few commands for defining such constants.
153
%D
154
%D \starttyping
155
%D \defineinterfaceconstant {name} {meaning}
156
%D \defineinterfacevariable {name} {meaning}
157
%D \defineinterfaceelement {name} {meaning}
158
%D \stoptyping
159
%D
160
%D Which is the same as:
161
%D
162
%D \starttyping
163
%D \def\c!name{meaning}
164
%D \def\v!name{meaning}
165
%D \def\e!name{meaning}
166
%D \stoptyping
167 168
\unexpanded
\def
\defineinterfaceconstant
#
1
#
2
{
\expandafter\def\csname
\c!prefix!
#
1
\endcsname
{
#
2
}}
169
\unexpanded
\def
\defineinterfacevariable
#
1
#
2
{
\expandafter\def\csname
\v!prefix!
#
1
\endcsname
{
#
2
}}
170
\unexpanded
\def
\defineinterfaceelement
#
1
#
2
{
\expandafter\def\csname
\e!prefix!
#
1
\endcsname
{
#
2
}}
171 172
%D Next come some interface independant constants:
173
%D
174
%D \starttyping
175
%D \definefileconstant {name} {meaning}
176
%D \stoptyping
177 178
\unexpanded
\def
\definefileconstant
#
1
#
2
{
\expandafter\def\csname
\f!prefix!
#
1
\endcsname
{
#
2
}}
179 180
%D And finaly we have the one argument, space saving constants
181
%D
182
%D \starttyping
183
%D \definesystemconstant {name}
184
%D \definemessageconstant {name}
185
%D \stoptyping
186 187
\unexpanded
\def
\definesystemconstant
#
1
{
\expandafter\def\csname
\s!prefix!
#
1
\endcsname
{
#
1
}}
188
\unexpanded
\def
\definemessageconstant
#
1
{
\expandafter\def\csname
\m!prefix!
#
1
\endcsname
{
#
1
}}
189 190
%D In a parameter driven system, some parameters are shared by more system
191
%D components. In \CONTEXT\ we can distinguish parameters by a unique prefix. Such a
192
%D prefix is defined with:
193
%D
194
%D \starttyping
195
%D \definesystemvariable {name}
196
%D \stoptyping
197 198
\unexpanded
\def
\definesystemvariable
#
1
{
\expandafter\edef\csname
\??prefix
#
1
\endcsname
{
\@@prefix
#
1
}}
199 200
\definesystemvariable
{
ms
}
201 202
%D \macros
203
%D {selectinterface,
204
%D defaultinterface, currentinterface, currentresponses}
205
%D
206
%D With \type {\selectinterface} we specify the language we are going to use. The
207
%D system asks for the language wanted, and defaults to \type {\currentinterface}
208
%D when we just give \type {enter}. By default the message system uses the current
209
%D interface language, but \type {\currentresponses} can specify another language
210
%D too.
211
%D
212
%D Because we want to generate formats directly too, we do not ask for interface
213
%D specifications when these are already defined (like in cont-nl.tex and alike).
214 215
\ifdefined
\defaultinterface
216 217
\def
\selectinterface
218
{
\writestatus
{
interface
}{
defining
\currentinterface\space
interface
}
%
219
%writeline
220
\writestatus
{
interface
}{
using
\currentresponses\space
messages
}
%
221
%\writeline
222
\let
\selectinterface
\relax
}
223 224
\else
225 226
\def
\defaultinterface
{
english
}
227 228
\def
\selectinterface
229
{
\def
\selectinterface
##
1
##
2
%
230
{
\bgroup
231
\endlinechar
\minusone
232
\global\read
1
6
to
##
1
233
\egroup
234
\doifnothing
\currentinterface
{
\let
##
1
=##
2
}
%
235
\doifundefined
{
\s!prefix!
##
1
}{
\let
##
1
=##
2
}}
%
236
\selectinterface
\currentinterface\defaultinterface
237
\writestatus
{
interface
}{
defining
\currentinterface\space
interface
}
%
238
%\writeline
239
\selectinterface
\currentresponses\currentinterface
240
\writestatus
{
interface
}{
using
\currentresponses\space
messages
}
%
241
%\writeline
242
\let
\selectinterface
\relax
}
243 244
\fi
245 246
\ifdefined
\currentinterface
\else
\let
\currentinterface\defaultinterface
\fi
247
\ifdefined
\currentresponses
\else
\let
\currentresponses\defaultinterface
\fi
248 249
%D \macros
250
%D {startinterface}
251
%D
252
%D Sometimes we want to define things only for specific interface languages. This
253
%D can be done by means of the selector:
254
%D
255
%D \starttyping
256
%D \startinterface language
257
%D
258
%D language specific definitions & commands
259
%D
260
%D \stopinterface
261
%D \stoptyping
262 263
\unexpanded
\def
\startinterface
#
1
264
{
\doifnot
{
#
1
}{
all
}{
\doifnotinset
\currentinterface
{
#
1
}{
\gobbleuntil\stopinterface
}}}
265 266
\let
\stopinterface
\relax
267 268
%D \macros
269
%D {startmessages,
270
%D getmessage,
271
%D showmessage,
272
%D makemessage}
273
%D
274
%D A package as large as \CONTEXT\ can hardly function without a decent message
275
%D mechanism. Due to its multi||lingual interface, the message subsystem has to be
276
%D multi||lingual too. A major drawback of this feature is that we have to code
277
%D messages. As a result, the source becomes less self documented. On the other
278
%D hand, consistency will improve.
279
%D
280
%D Because the overhead in terms of entries in the (already exhausted) hash table
281
%D has to be minimal, messages are packed in libraries. We can extract a message
282
%D from such a library in three ways:
283
%D
284
%D \starttyping
285
%D \getmessage {library} {tag}
286
%D \showmessage {library} {tag} {data}
287
%D \makemessage {library} {tag} {data}
288
%D \stoptyping
289
%D
290
%D The first command gets the message \type {tag} from the \type {library}
291
%D specified. The other commands take an extra argument: a list of items to be
292
%D inserted in the message text. While \type {\showmessage} shows the message at the
293
%D terminal, the other commands generate the message as text. Before we explain the
294
%D \type {data} argument, we give an example of a library.
295
%D
296
%D \starttyping
297
%D \startmessages english library: alfa
298
%D title: something
299
%D 1: first message
300
%D 2: second (--) message --
301
%D \stopmessages
302
%D \stoptyping
303
%D
304
%D The first message is a simple one and can be shown with:
305
%D
306
%D \starttyping
307
%D \showmessage {alfa} {1} {}
308
%D \stoptyping
309
%D
310
%D The second message on the other hand needs some extra data:
311
%D
312
%D \starttyping
313
%D \showmessage {alfa} {2} {and last,to you}
314
%D \stoptyping
315
%D
316
%D This message is shown as:
317
%D
318
%D \starttyping
319
%D something : second (and last) message to you
320
%D \stoptyping
321
%D
322
%D As we can see, the title entry is shown with the message. The data fields are
323
%D comma separated and are specified in the message text by \type {--}.
324
%D
325
%D It is not required to define all messages in a library at once. We can add
326
%D messages to a library in the following way:
327
%D
328
%D \starttyping
329
%D \startmessages english library: alfa
330
%D 10: tenth message
331
%D \stopmessages
332
%D \stoptyping
333
%D
334
%D Because such definitions can take place in different modules, the system gives a
335
%D warning when a tag occurs more than once. The first occurrence takes preference
336
%D over later ones, so we had better use a save offset, as shown in the example. As
337
%D we can see, the title field is specified only the first time!
338
%D
339
%D Because we want to check for duplicate tags, the macros are a bit more
340
%D complicated than neccessary. The \NEWLINE\ token is used as message separator.
341
%D
342
%D For internal purposes one can use \type {\setmessagetext}, which puts the message
343
%D text asked for in \type {\currentmessagetext}.
344
%D
345
%D These will become obsolete:
346 347
\unexpanded
\def
\startmessages
#
1
library
:
#
2
%
348
{
\begingroup
349
\ifcsname
\m!prefix!
#
2
\endcsname\else
\setgvalue
{
\m!prefix!
#
2
}{
#
2
}
\fi
350
\catcode
\endoflineasciicode\othercatcode
351
\doifelseinset
{
#
1
}{
\currentresponses
,
all
}
\mult_messages_start_yes
\mult_messages_start_nop
{
#
2
}}
352 353
\def
\mult_messages_start_yes
#
1
#
2
\stopmessages
354
{
\clf_setinterfacemessages
{
#
1
}{
#
2
}
%
355
\endgroup
}
356 357
\def
\mult_messages_start_nop
#
1
#
2
\stopmessages
358
{
\endgroup
}
359 360
\let
\stopmessages
\relax
361 362
\unexpanded
\def
\setinterfacemessage
#
1
#
2
#
3
%
363
{
\ifcsname
\m!prefix!
#
1
\endcsname\else
\setgvalue
{
\m!prefix!
#
1
}{
#
1
}
\fi
364
\clf_setinterfacemessage
{
#
1
}{
#
2
}{
#
3
}}
365 366
\unexpanded
\def
\setmessagetext
#
1
#
2
{
\relax\edef
\currentmessagetext
{
\clf_getmessage
{
#
1
}{
#
2
}}}
367
\unexpanded
\def
\getmessage
#
1
#
2
{
\relax
\clf_getmessage
{
#
1
}{
#
2
}}
368
\unexpanded
\def
\doifelsemessage
#
1
#
2
{
\relax
\clf_doifelsemessage
{
#
1
}{
#
2
}}
369
\unexpanded
\def
\showmessage
#
1
#
2
#
3
{
\relax
\clf_showmessage
{
#
1
}{
#
2
}{
#
3
}}
370
\unexpanded
\def
\writestatus
#
1
#
2
{
\relax
\clf_writestatus
{
#
1
}{
#
2
}}
371
\unexpanded
\def\message
{
\relax
\clf_message
}
372 373
\let
\doifmessageelse\doifelsemessage
374 375
\unexpanded
\def
\inlinemessage
#
1
{
\dontleavehmode
{
\tttf
#
1
}}
376
\unexpanded
\def
\displaymessage
#
1
{
\blank\inlinemessage
{
#
1
}
\blank
}
377 378
\let
\getsetupstring
\clf_getsetupstring
379
\let
\rawsetupstring
\clf_rawsetupstring
380 381
%D For old times sake:
382 383
\let
\showwarning\showmessage
384 385
%D \macros
386
%D {dosetvalue,dosetevalue,dosetgvalue,dosetxvalue,docopyvalue,doresetvalue} % dogetvalue
387
%D
388
%D We already defined these auxiliary macros in the system modules. Starting with
389
%D this module however, we have to take multi||linguality a bit more serious.
390
%D
391
%D In due time, when we exclusively use the parameter handler code, we can drop the
392
%D backmapping (\type{\c!k...}) and make \type {\c!c...} similar to \type {\v!...}.
393
%D In that case we can simply the following setters.
394 395
\unexpanded
\def
\doletvalue
#
1
#
2
{
\expandafter\let
\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
}
396
\unexpanded
\def
\dosetvalue
#
1
#
2
{
\expandafter\def
\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
}
397
\unexpanded
\def
\dosetevalue
#
1
#
2
{
\expandafter\edef\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
}
398
\unexpanded
\def
\dosetgvalue
#
1
#
2
{
\expandafter\gdef\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
}
399
\unexpanded
\def
\dosetxvalue
#
1
#
2
{
\expandafter\xdef\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
}
400
\unexpanded
\def
\doresetvalue
#
1
#
2
{
\expandafter\let
\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
\empty
}
401
\unexpanded
\def
\doignorevalue
#
1
#
2
#
3
{
\expandafter\let
\csname
#
1
\ifcsname
\k!prefix!
#
2
\endcsname\csname
\k!prefix!
#
2
\endcsname\else
#
2
\fi\endcsname
\empty
}
402 403
\unexpanded
\def
\docopyvalue
#
1
#
2
#
3
%
404
{
\ifcsname
\k!prefix!
#
3
\endcsname
405
\expandafter\def\csname
#
1
\csname
\k!prefix!
#
3
\endcsname\expandafter\endcsname\expandafter
406
{
\csname
#
2
\csname
\k!prefix!
#
3
\endcsname\endcsname
}
%
407
\else
408
\expandafter\def\csname
#
1
#
3
\expandafter\endcsname\expandafter
409
{
\csname
#
2
#
3
\endcsname
}
%
410
\fi
}
411 412
\startinterface
english
413 414
\unexpanded
\def
\doletvalue
#
1
#
2
{
\expandafter
\let\csname
#
1
#
2
\endcsname
}
415
\unexpanded
\def
\dosetvalue
#
1
#
2
{
\expandafter
\def\csname
#
1
#
2
\endcsname
}
416
\unexpanded
\def
\dosetevalue
#
1
#
2
{
\expandafter\edef\csname
#
1
#
2
\endcsname
}
417
\unexpanded
\def
\dosetgvalue
#
1
#
2
{
\expandafter\gdef\csname
#
1
#
2
\endcsname
}
418
\unexpanded
\def
\dosetxvalue
#
1
#
2
{
\expandafter\xdef\csname
#
1
#
2
\endcsname
}
419
\unexpanded
\def
\doresetvalue
#
1
#
2
{
\expandafter
\let\csname
#
1
#
2
\endcsname
\empty
}
420
\unexpanded
\def
\doignorevalue
#
1
#
2
#
3
{
\expandafter
\let\csname
#
1
#
2
\endcsname
\empty
}
421 422
\unexpanded
\def
\docopyvalue
#
1
#
2
#
3
%
423
{
\expandafter\def\csname
#
1
#
3
\expandafter\endcsname\expandafter
424
{
\csname
#
2
#
3
\endcsname
}}
425 426
\stopinterface
427 428
%D We can now redefine some messages that will be introduced in the multi||lingual
429
%D system module.
430 431
\unexpanded
\def
\showassignerror
#
1
#
2
{
\showmessage
\m!check
1
{
#
1
,
#
2
}}
432
\unexpanded
\def
\showargumenterror
#
1
#
2
{
\showmessage
\m!check
2
{
#
1
,
#
2
}}
433
\unexpanded
\def
\showdefinederror
#
1
#
2
{
\showmessage
\m!check
3
{
#
1
,
#
2
}}
434 435
%D \CONTEXT\ is a parameter driven package. This means that users instruct the
436
%D system by means of variables, values and keywords. These instructions take the
437
%D form:
438
%D
439
%D \starttyping
440
%D \setupsomething[some variable=some value, another one=a keyword]
441
%D \stoptyping
442
%D
443
%D or by keyword only:
444
%D
445
%D \starttyping
446
%D \dosomething[this way,that way,no way]
447
%D \stoptyping
448
%D
449
%D Because the same variables can occur in more than one setup command, we have to
450
%D be able to distinguish them. This is achieved by assigning them a unique prefix.
451
%D
452
%D Imagine a setup command for boxed text, that enables us to specify the height and
453
%D width of the box. Behide the scenes the command
454
%D
455
%D \starttyping
456
%D \setupbox [width=12cm, height=3cm]
457
%D \stoptyping
458
%D
459
%D results in something like
460
%D
461
%D \starttyping
462
%D \<box><width> {12cm}
463
%D \<box><height> {3cm}
464
%D \stoptyping
465
%D
466
%D while a similar command for specifying the page dimensions
467
%D of an \cap {A4} page results in:
468
%D
469
%D \starttyping
470
%D \<page><width> {21.0cm}
471
%D \<page><height> {27.9cm}
472
%D \stoptyping
473
%D
474
%D The prefixes \type {<box>} and \type {<page>} are hidden from users and can
475
%D therefore be language independant. Variables on the other hand, differ for each
476
%D language:
477
%D
478
%D \starttyping
479
%D \<box><color> {<blue>}
480
%D \<box><kleur> {<blauw>}
481
%D \<box><couleur> {<blue>}
482
%D \stoptyping
483
%D
484
%D In this example we can see that the assigned values or keywords are language
485
%D dependant too. This will be a complication when defining multi||lingual setup
486
%D files.
487
%D
488
%D A third phenomena is that variables and values can have a similar meaning.
489
%D
490
%D \starttyping
491
%D \<pagenumber><location> {<left>}
492
%D \<skip><left> {12cm}
493
%D \stoptyping
494
%D
495
%D A (minor) complication is that where in english we use \type {<left>}, in dutch
496
%D we find both \type {<links>} and \type {<linker>}. This means that when we use
497
%D some sort of translation table, we have to distinguish between the variables at
498
%D the left side and the fixed values at the right.
499
%D
500
%D The same goes for commands that are composed of different user supplied and/or
501
%D language specific elements. In english we can use:
502
%D
503
%D \starttyping
504
%D \<empty><figure>
505
%D \<empty><intermezzo>
506
%D \stoptyping
507
%D
508
%D But in dutch we have the following:
509
%D
510
%D \starttyping
511
%D \<lege><figuur>
512
%D \<leeg><intermezzo>
513
%D \stoptyping
514
%D
515
%D These subtle differences automatically lead to a solution where variables,
516
%D values, elements and other components have a similar logical name (used in
517
%D macro's) but a different meaning (supplied by the user).
518
%D
519
%D Our solution is one in which the whole system is programmed in terms of
520
%D identifiers with language specific meanings. In such an implementation, each
521
%D fixed variable is available as:
522
%D
523
%D \starttyping
524
%D \<prefix><variable>
525
%D \stoptyping
526
%D
527
%D This means that for instance:
528
%D
529
%D \starttyping
530
%D \setupbox[width=12cm]
531
%D \stoptyping
532
%D
533
%D expands to something like:
534
%D
535
%D \starttyping
536
%D \def\boxwidth{12cm}
537
%D \stoptyping
538
%D
539
%D because we don't want to recode the source, a setup command in another language
540
%D has to expand to this variable, so:
541
%D
542
%D \starttyping
543
%D \setupblock[width=12cm]
544
%D \stoptyping
545
%D
546
%D has to result in the definition of \type {\boxwidth} too. This method enables us
547
%D to build compact, fast and readable code.
548
%D
549
%D An alternative method, which we considered using, uses a more indirect way. In
550
%D this case, both calls generate a different variable:
551
%D
552
%D \starttyping
553
%D \def\boxwidth {12cm}
554
%D \def\boxbreedte {12cm}
555
%D \stoptyping
556
%D
557
%D And because we don't want to recode those megabytes of already developed code,
558
%D this variable has to be called with something like:
559
%D
560
%D \starttyping
561
%D \valueof\box\width
562
%D \stoptyping
563
%D
564
%D where \type {\valueof} takes care of the translation of \type {width} or \type
565
%D {breedte} to \type {width} and combining this with \type {box} to \type
566
%D {\boxwidth}.
567
%D
568
%D One advantage of this other scheme is that, within certain limits, we can
569
%D implement an interface that can be switched to another language at will, while
570
%D the current approach fixes the interface at startup. There are, by the way, other
571
%D reasons too for not choosing this scheme. Switching user generated commands is
572
%D for instance impossible and a dual interface would therefore give a strange mix
573
%D of languages.
574
%D
575
%D Now let's work out the first scheme. Although the left hand of the assignment is
576
%D a variable from the users point of view, it is a constant in terms of the system.
577
%D Both \type {width} and \type {breedte} expand to \type {width} because in the
578
%D source we only encounter \type {width}. Such system constants are presented as
579
%D
580
%D \starttyping
581
%D \c!width
582
%D \stoptyping
583
%D
584
%D This constant is always equivalent to \type {width}. As we can see, we use \type
585
%D {c!} to mark this one as constant. Its dutch counterpart is:
586
%D
587
%D \starttyping
588
%D breedte
589
%D \stoptyping
590
%D
591
%D When we interpret a setup command each variable is translated to it's \type{c!}
592
%D counterpart. This means that \type {breedte} and \type{width} expand to \type
593
%D {breedte} and \type {\c!width} which both expand to \type {width}. That way user
594
%D variables become system constants.
595
%D
596
%D The interpretation is done by means of a general setup command \type
597
%D {\getparameters} that we introduced in the system module. Let us define some
598
%D simple setup command:
599
%D
600
%D \starttyping
601
%D \unexpanded\def\setupbox[#1]%
602
%D {\getparameters[\??bx][#1]}
603
%D \stoptyping
604
%D
605
%D This command can be used as:
606
%D
607
%D \starttyping
608
%D \setupbox [width=3cm, height=1cm]
609
%D \stoptyping
610
%D
611
%D Afterwards we have two variables \type {\@@bxwidth} and \type {\@@bxheight} which
612
%D have the values \type {3cm} and \type {1cm} assigned. These variables are a
613
%D combinatiom of the setup prefix \type {\??bx}, which expands to \type {@@bx} and
614
%D the translated user supplied variables \type {width} and \type {height} or \type
615
%D {breedte} and \type {hoogte}, depending on the actual language. In dutch we just
616
%D say:
617
%D
618
%D \starttyping
619
%D \stelblokin [breedte=3cm,hoogte=1cm]
620
%D \stoptyping
621
%D
622
%D and get ourselves \type {\@@bxwidth} and \type {\@@bxheight} too. In the source
623
%D of \CONTEXT, we can recognize constants and variables on their leading \type
624
%D {c!}, \type {v!} etc., prefixes on \type {??} and composed variables on \type
625
%D {@@}.
626
%D
627
%D We already saw that user supplied keywords need some special treatment too. This
628
%D time we don't translate the keyword, but instead use in the source a variable
629
%D which meaning depends on the interface language.
630
%D
631
%D \starttyping
632
%D \v!left
633
%D \stoptyping
634
%D
635
%D Which can be used in macro's like:
636
%D
637
%D \starttyping
638
%D \processaction
639
%D [\@@bxlocation]
640
%D [ \v!left=>\dosomethingontheleft,
641
%D \v!middle=>\dosomthinginthemiddle,
642
%D \v!right=>\dosomethingontheright]
643
%D \stoptyping
644
%D
645
%D Because variables like \type {\@@bxlocation} can have a lot of meanings,
646
%D including tricky expandable tokens, we cannot translate this meaning when we
647
%D compare. This means that \type {\@@bxlocation} can be \type {left} of \type
648
%D {links} of whatever meaning suits the language. But because \type {\v!left} also
649
%D has a meaning that suits the language, we are able to compare.
650
%D
651
%D Although we know it sounds confusing we want to state two important
652
%D characteristics of the interface as described:
653
%D
654
%D \startnarrower \em
655
%D user variables become system constants
656
%D \stopnarrower
657
%D
658
%D and
659
%D
660
%D \startnarrower \em
661
%D user constants (keywords) become system variables
662
%D \stopnarrower
663
%D
664
%D The \type {\c!internal} is a left over from the time that the user interface
665
%D documents were not using a specification alongside a keyword specification but
666
%D used a shared file in which case we need to go in both directions.
667 668
% temporary mkiv hack (we can best just store the whole table in memory)
669 670
\unexpanded
\def
\setinterfaceconstant
#
1
#
2
%
671
{
\clf_setinterfaceconstant
{
#
1
}{
#
2
}
%
672
\expandafter\def\csname
\c!prefix!
#
1
\endcsname
{
#
1
}}
673 674
\unexpanded
\def
\setinterfacevariable
#
1
#
2
%
675
{
\clf_setinterfacevariable
{
#
1
}{
#
2
}
%
676
\expandafter\def\csname
\v!prefix!
#
1
\endcsname
{
#
2
}}
677 678
%D \macros
679
%D {defineinterfaceconstant}
680
%D
681
%D Next we redefine a previously defined macro to take care of interface translation
682
%D too. It's a bit redundant, because in these situations we could use the
683
%D c||version, but for documentation purposes the x||alternative comes in handy.
684 685
\unexpanded
\def
\defineinterfaceconstant
#
1
#
2
%
686
{
\expandafter\def\csname
\c!prefix!
#
1
\endcsname
{
#
2
}}
687 688
%D \macros
689
%D {startelements}
690
%D
691
%D Due to the object oriented nature of \CONTEXT, we also need to define the
692
%D elements that are used to build commands.
693
%D
694
%D Such elements sometimes are the same in different languages, but mostly they
695
%D differ. Things can get even confusing when we look at for instance the setup
696
%D commands. In english we say \type{\setup<something>}, but in dutch we have: \type
697
%D {\stel<iets>in}. Such split elements are no problem, because we just define two
698
%D elements. When no second part is needed, we use a \type {-}:
699 700
\unexpanded
\def
\setinterfaceelement
#
1
#
2
%
701
{
\clf_setinterfaceelement
{
#
1
}{
#
2
}
%
702
\ifcsname
\e!prefix!
#
1
\endcsname
703
\doifnotvalue
{
\e!prefix!
#
1
}{
#
2
}{
\setvalue
{
\e!prefix!
#
1
}{
#
2
}}
%
704
\else
705
\setvalue
{
\e!prefix!
#
1
}{
#
2
}
%
706
\fi
}
707 708
\unexpanded
\def
\setinterfacecommand
#
1
#
2
%
709
{
\doifnot
{
#
1
}{
#
2
}
% todo: let when already defined
710
{
\expandafter\def\csname
#
2
\expandafter\endcsname\expandafter
{
\csname
#
1
\endcsname
}}}
711 712
%D We just ignore these:
713 714
\unexpanded
\def
\startvariables
{
\gobbleuntil
\stopvariables
}
\let
\stopvariables
\relax
715
\unexpanded
\def
\startconstants
{
\gobbleuntil
\stopconstants
}
\let
\stopconstants
\relax
716
\unexpanded
\def
\startelements
{
\gobbleuntil
\stopelements
}
\let
\stopelements
\relax
717
\unexpanded
\def
\startcommands
{
\gobbleuntil
\stopcommands
}
\let
\stopcommands
\relax
718 719
%D For at the \LUA\ end (experiment):
720 721
% \def\do@sicon#1#2{\expandafter\gdef\csname\c!prefix!#1\endcsname{#1}%
722
% \expandafter\gdef\csname\k!prefix!#2\endcsname{#1}} % backmapping from non english
723
% \def\do@sivar#1#2{\expandafter\gdef\csname\v!prefix!#1\endcsname{#2}}
724
% \def\do@siele#1#2{\expandafter\gdef\csname\e!prefix!#1\endcsname{#2}}
725
% \def\do@sicom#1#2{\expandafter\gdef\csname#2\expandafter\endcsname\expandafter{\csname#1\endcsname}}
726
%
727
% \startinterface english
728
%
729
% \def\do@sicon#1#2{\expandafter\gdef\csname\c!prefix!#1\endcsname{#1}}
730
%
731
% \stopinterface
732 733
\def
\ui_c
#
1
#
2
{
\expandafter\gdef\csname
\c!prefix!
#
1
\endcsname
{
#
1
}
%
734
\expandafter\gdef\csname
\k!prefix!
#
2
\endcsname
{
#
1
}}
% backmapping from non english
735
\def
\ui_s
#
1
{
\expandafter\gdef\csname
\c!prefix!
#
1
\endcsname
{
#
1
}
%
736
\expandafter\gdef\csname
\k!prefix!
#
1
\endcsname
{
#
1
}}
% backmapping from non english
737
\def
\ui_v
#
1
#
2
{
\expandafter\gdef\csname
\v!prefix!
#
1
\endcsname
{
#
2
}}
738
\def
\ui_e
#
1
#
2
{
\expandafter\gdef\csname
\e!prefix!
#
1
\endcsname
{
#
2
}}
739
\def
\ui_m
#
1
#
2
{
\expandafter\gdef\csname
#
2
\expandafter\endcsname\expandafter
{
\csname
#
1
\endcsname
}}
740 741
\startinterface
english
742 743
\def
\ui_c
#
1
#
2
{
\expandafter\gdef\csname
\c!prefix!
#
1
\endcsname
{
#
1
}}
744
\def
\ui_s
#
1
{
\expandafter\gdef\csname
\c!prefix!
#
1
\endcsname
{
#
1
}}
745 746
\stopinterface
747 748
%D So much for the basic multi||lingual interface commands. The macro's can be
749
%D enhanced with more testing facilities, but for the moment they suffice.
750 751
\ifdefined
\zwnj
\else
\edef
\zwnj
{
\directlua{
utf
.
char
(
\number
"
200C)}} \fi % needed for cont-pe % maybe to char-utf.mkiv 752\ifdefined\zwj \else \edef\zwj {\directlua{utf.char(\number
"
200
D
)
}
}
\fi
% needed for cont-pe % maybe to char-utf.mkiv
753 754 755
%D \macros
756
%D {contextversion, contextversionnumber, contextversionno,
757
%D contextbanner, showcontextbanner, formatversion}
758
%D
759
%D Out of convenience we define the banners here. This might move to the \LUA\ end.
760 761
\def
\contextbanner
762
{
ConTeXt
\space
763
ver
:
\contextversion
\space
\contextmark
\space
\contextkind
\space
\space
764
fmt
:
\formatversion
\space
\space
765
int
:
\currentinterface
/
\currentresponses
}
766 767
\unexpanded
\def
\showcontextbanner
768
{
\writestatus
\m!system
\empty
769
\writestatus
\m!system
\contextbanner
770
\writestatus
\m!system
\empty
}
771 772
\edef
\formatversion
773
{
\the\normalyear
.
\the\normalmonth
.
\the\normalday
}
774 775
\newcount
\contextversionno
776 777
\ifx
\contextversion\undefined
778
\edef
\contextversion
{
\the\normalyear
.
\the\normalmonth
.
\the\normalday
\space
0
0
:
0
0
}
779
\fi
780 781
% \def\contextversionnumber#1.#2.#3 #4:#5\relax{#1\ifnum#2<10 0\fi\purenumber{#2}\ifnum#3<10 0\fi\purenumber{#3} #4:#5}
782
% \edef\contextversionnumber{\expandafter\contextversionnumber\contextversion\relax\space\contextmark}
783 784
\unexpanded
\def
\contextversionnumber
#
1
.
#
2
.
#
3
#
4
:
#
5
\relax
{
#
1
#
2
#
3
}
785
\contextversionno
\expandafter
\contextversionnumber
\contextversion
\relax
786
\edef
\contextversionnumber
{
\the
\contextversionno
\space
\contextmark
}
787 788
%D \macros
789
%D {everydump}
790
%D
791
%D This one is only used when we generate the format.
792 793
\ifx
\undefined
\everydump
794
\newtoks
\everydump
795
\def\dump
{
\the
\everydump
\normaldump
}
796
\fi
797 798
% \appendtoks \showcontextbanner \to \everydump
799 800
\protect
\endinput
801