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