mult-ini.mkxl /size: 29 Kb    last modification: 2024-01-16 09:02
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\cdef\c!prefix!{c!}
59\immutable\cdef\k!prefix!{k!}
60\immutable\cdef\e!prefix!{e!}
61\immutable\cdef\f!prefix!{f!} % for the moment we keep this one
62\immutable\cdef\m!prefix!{m!}
63\immutable\cdef\s!prefix!{s!}
64\immutable\cdef\v!prefix!{v!}
65\immutable\cdef\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\cdef\??prefix  {??}
77\immutable\cdef\@@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\cdef\s!next    {next}         \cdef\s!default {default}
83\cdef\s!dummy   {dummy}        \cdef\s!unknown {unknown}
84
85\cdef\s!do      {do}           \cdef\s!dodo    {dodo}
86
87\cdef\s!complex {complex}      \cdef\s!start   {start}
88\cdef\s!simple  {simple}       \cdef\s!stop    {stop}
89
90\cdef\s!true    {true}
91\cdef\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\cdef\s!width      {width}
113\cdef\s!height     {height}
114\cdef\s!depth      {depth}
115\cdef\s!spread     {spread}
116\cdef\s!plus       {plus}
117\cdef\s!minus      {minus}
118\cdef\s!to         {to}
119
120\cdef\s!fil        {fil}
121\cdef\s!fill       {fill}
122\cdef\s!filll      {filll}
123
124\cdef\s!attr       {attr}
125\cdef\s!axis       {axis}
126\cdef\s!both       {both}
127\cdef\s!bottom     {bottom}
128\cdef\s!left       {left}
129\cdef\s!options    {options}
130\cdef\s!orientation{orientation}
131\cdef\s!reverse    {reverse}
132\cdef\s!right      {right}
133\cdef\s!top        {top}
134\cdef\s!xmove      {xmove}
135\cdef\s!xoffset    {xoffset}
136\cdef\s!ymove      {ymove}
137\cdef\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\cdefcsname\c!prefix!#1\endcsname{#2}}
175\permanent\protected\def\defineinterfacevariable#1#2{\immutable\cdefcsname\v!prefix!#1\endcsname{#2}}
176\permanent\protected\def\defineinterfaceelement #1#2{\immutable\cdefcsname\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\cdefcsname\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\cdefcsname\s!prefix!#1\endcsname{#1}}
194\permanent\protected\def\definemessageconstant#1{\immutable\cdefcsname\m!prefix!#1\endcsname{#1}}
195
196%D For now here:
197
198\permanent\protected\def\definetagconstant  #1{\immutable\cdefcsname\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\cdefcsname\??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        \ifempty\currentinterface
246          \let##1=##2%
247        \orelse\ifcsname\s!prefix!##1\endcsname\else
248          \let##1=##2
249        \fi}%
250     \selectinterface\currentinterface\defaultinterface
251     \writestatus{interface}{defining \currentinterface\space interface}%
252    %\writeline
253     \selectinterface\currentresponses\currentinterface
254     \writestatus{interface}{using \currentresponses\space messages}%
255    %\writeline
256     \enforced\permanent\let\selectinterface\relax}
257
258\fi
259
260\ifdefined\currentinterface \else \aliased\let\currentinterface\defaultinterface \fi
261\ifdefined\currentresponses \else \aliased\let\currentresponses\defaultinterface \fi
262
263%D \macros
264%D   {startinterface}
265%D
266%D Sometimes we want to define things only for specific interface languages. This
267%D can be done by means of the selector:
268%D
269%D \starttyping
270%D \startinterface language
271%D
272%D language specific definitions & commands
273%D
274%D \stopinterface
275%D \stoptyping
276
277\permanent\protected\def\startinterface #1
278  {\iftok{#1}{all}%
279     % okay
280   \orelse\ifinset\currentinterface{#1}%
281     % okay
282   \else
283     \expandafter\ignoreupto\expandafter\stopinterface
284   \fi}
285
286\aliased\let\stopinterface\relax
287
288%D \macros
289%D   {startmessages,
290%D    getmessage,
291%D    showmessage,
292%D    makemessage}
293%D
294%D A package as large as \CONTEXT\ can hardly function without a decent message
295%D mechanism. Due to its multi||lingual interface, the message subsystem has to be
296%D multi||lingual too. A major drawback of this feature is that we have to code
297%D messages. As a result, the source becomes less self documented. On the other
298%D hand, consistency will improve.
299%D
300%D Because the overhead in terms of entries in the (already exhausted) hash table
301%D has to be minimal, messages are packed in libraries. We can extract a message
302%D from such a library in three ways:
303%D
304%D \starttyping
305%D \getmessage  {library} {tag}
306%D \showmessage {library} {tag} {data}
307%D \makemessage {library} {tag} {data}
308%D \stoptyping
309%D
310%D The first command gets the message \type {tag} from the \type {library}
311%D specified. The other commands take an extra argument: a list of items to be
312%D inserted in the message text. While \type {\showmessage} shows the message at the
313%D terminal, the other commands generate the message as text. Before we explain the
314%D \type {data} argument, we give an example of a library.
315%D
316%D \starttyping
317%D \startmessages  english  library: alfa
318%D   title: something
319%D       1: first message
320%D       2: second (--) message --
321%D \stopmessages
322%D \stoptyping
323%D
324%D The first message is a simple one and can be shown with:
325%D
326%D \starttyping
327%D \showmessage {alfa} {1} {}
328%D \stoptyping
329%D
330%D The second message on the other hand needs some extra data:
331%D
332%D \starttyping
333%D \showmessage {alfa} {2} {and last,to you}
334%D \stoptyping
335%D
336%D This message is shown as:
337%D
338%D \starttyping
339%D something : second (and last) message to you
340%D \stoptyping
341%D
342%D As we can see, the title entry is shown with the message. The data fields are
343%D comma separated and are specified in the message text by \type {--}.
344%D
345%D It is not required to define all messages in a library at once. We can add
346%D messages to a library in the following way:
347%D
348%D \starttyping
349%D \startmessages  english  library: alfa
350%D      10: tenth message
351%D \stopmessages
352%D \stoptyping
353%D
354%D Because such definitions can take place in different modules, the system gives a
355%D warning when a tag occurs more than once. The first occurrence takes preference
356%D over later ones, so we had better use a save offset, as shown in the example. As
357%D we can see, the title field is specified only the first time!
358%D
359%D Because we want to check for duplicate tags, the macros are a bit more
360%D complicated than neccessary. The \NEWLINE\ token is used as message separator.
361%D
362%D For internal purposes one can use \type {\setmessagetext}, which puts the message
363%D text asked for in \type {\currentmessagetext}.
364%D
365%D These will become obsolete:
366
367\permanent\protected\def\startmessages #1 library: #2 %
368  {\begingroup
369   \ifcsname\m!prefix!#2\endcsname\else\immutable\gdefcsname\m!prefix!#2\endcsname{#2}\fi
370   \catcode\endoflineasciicode\othercatcode
371   \doifelseinset{#1}{\currentresponses,all}\mult_messages_start_yes\mult_messages_start_nop{#2}}
372
373\def\mult_messages_start_yes#1#2\stopmessages
374  {\clf_setinterfacemessages{#1}{#2}%
375   \endgroup}
376
377\def\mult_messages_start_nop#1#2\stopmessages
378  {\endgroup}
379
380\aliased\let\stopmessages\relax
381
382\mutable\lettonothing\currentmessagetext
383
384\permanent\protected\def\setinterfacemessage#1#2#3%
385  {\ifcsname\m!prefix!#1\endcsname\else\immutable\gdefcsname\m!prefix!#1\endcsname{#1}\fi
386   \clf_setinterfacemessage{#1}{#2}{#3}}
387
388% \getmessage       % {tag} {index} -> \currentmessagetext
389% \doifelsemessage  % {tag} {index}
390% \showmessage      % {tag} {index} {detail}
391% \writestatus      % {tag} {string}
392% \message          % {string}
393
394\aliased\let\doifmessageelse\doifelsemessage
395
396\permanent\protected\def\inlinemessage #1{\dontleavehmode{\tttf#1}}
397\permanent\protected\def\displaymessage#1{\blank\inlinemessage{#1}\blank}
398
399% \getsetupstring % {tag} defined at the lua end
400% \rawsetupstring % {tag} defined at the lua end
401
402%D For old times sake:
403
404\aliased\let\showwarning\showmessage
405
406%D \macros
407%D   {dosetvalue,dosetevalue,dosetgvalue,dosetxvalue,docopyvalue,doresetvalue} % dogetvalue
408%D
409%D We already defined these auxiliary macros in the system modules. Starting with
410%D this module however, we have to take multi||linguality a bit more serious.
411%D
412%D In due time, when we exclusively use the parameter handler code, we can drop the
413%D backmapping (\type{\c!k...}) and make \type {\c!c...} similar to \type {\v!...}.
414%D In that case we can simply the following setters.
415
416\pushoverloadmode
417
418\permanent\protected\def\doletvalue     #1#2{\letcsname #1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname}
419\permanent\protected\def\dosetvalue     #1#2{\defcsname #1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname}
420\permanent\protected\def\dosetevalue    #1#2{\edefcsname#1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname}
421\permanent\protected\def\dosetgvalue    #1#2{\gdefcsname#1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname}
422\permanent\protected\def\dosetxvalue    #1#2{\xdefcsname#1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname}
423\permanent\protected\def\doresetvalue   #1#2{\letcsname #1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname\empty}
424\permanent\protected\def\doignorevalue#1#2#3{\letcsname #1\ifcsname\k!prefix!#2\endcsname\csname\k!prefix!#2\endcsname\else#2\fi\endcsname\empty}
425
426\permanent\protected\def\docopyvalue#1#2#3%
427  {\ifcsname\k!prefix!#3\endcsname
428     \defcsname#1\csname\k!prefix!#3\endcsname\expandafter\endcsname\expandafter
429       {\csname#2\csname\k!prefix!#3\endcsname\endcsname}%
430   \else
431     \defcsname#1#3\expandafter\endcsname\expandafter
432       {\csname#2#3\endcsname}%
433   \fi}
434
435\startinterface english
436
437    \permanent\protected\def\doletvalue     #1#2{\letcsname #1#2\endcsname}
438    \permanent\protected\def\dosetvalue     #1#2{\defcsname #1#2\endcsname}
439    \permanent\protected\def\dosetevalue    #1#2{\edefcsname#1#2\endcsname}
440    \permanent\protected\def\dosetgvalue    #1#2{\gdefcsname#1#2\endcsname}
441    \permanent\protected\def\dosetxvalue    #1#2{\xdefcsname#1#2\endcsname}
442    \permanent\protected\def\doresetvalue   #1#2{\letcsname #1#2\endcsname\empty}
443    \permanent\protected\def\doignorevalue#1#2#3{\letcsname #1#2\endcsname\empty}
444
445    \permanent\protected\def\docopyvalue#1#2#3%
446      {\defcsname#1#3\expandafter\endcsname\expandafter
447         {\csname#2#3\endcsname}}
448
449\stopinterface
450
451\popoverloadmode
452
453%D We can now redefine some messages that will be introduced in the multi||lingual
454%D system module.
455
456\permanent\protected\def\showassignerror  #1#2{\showmessage\m!check1{#1,#2}}
457\permanent\protected\def\showargumenterror#1#2{\showmessage\m!check2{#1,#2}}
458\permanent\protected\def\showdefinederror #1#2{\showmessage\m!check3{#1,#2}}
459
460%D \CONTEXT\ is a parameter driven package. This means that users instruct the
461%D system by means of variables, values and keywords. These instructions take the
462%D form:
463%D
464%D \starttyping
465%D \setupsomething[some variable=some value, another one=a keyword]
466%D \stoptyping
467%D
468%D or by keyword only:
469%D
470%D \starttyping
471%D \dosomething[this way,that way,no way]
472%D \stoptyping
473%D
474%D Because the same variables can occur in more than one setup command, we have to
475%D be able to distinguish them. This is achieved by assigning them a unique prefix.
476%D
477%D Imagine a setup command for boxed text, that enables us to specify the height and
478%D width of the box. Behide the scenes the command
479%D
480%D \starttyping
481%D \setupbox [width=12cm, height=3cm]
482%D \stoptyping
483%D
484%D results in something like
485%D
486%D \starttyping
487%D \<box><width>   {12cm}
488%D \<box><height>  {3cm}
489%D \stoptyping
490%D
491%D while a similar command for specifying the page dimensions
492%D of an \cap {A4} page results in:
493%D
494%D \starttyping
495%D \<page><width>  {21.0cm}
496%D \<page><height> {27.9cm}
497%D \stoptyping
498%D
499%D The prefixes \type {<box>} and \type {<page>} are hidden from users and can
500%D therefore be language independant. Variables on the other hand, differ for each
501%D language:
502%D
503%D \starttyping
504%D \<box><color>   {<blue>}
505%D \<box><kleur>   {<blauw>}
506%D \<box><couleur> {<blue>}
507%D \stoptyping
508%D
509%D In this example we can see that the assigned values or keywords are language
510%D dependant too. This will be a complication when defining multi||lingual setup
511%D files.
512%D
513%D A third phenomena is that variables and values can have a similar meaning.
514%D
515%D \starttyping
516%D \<pagenumber><location> {<left>}
517%D \<skip><left>           {12cm}
518%D \stoptyping
519%D
520%D A (minor) complication is that where in english we use \type {<left>}, in dutch
521%D we find both \type {<links>} and \type {<linker>}. This means that when we use
522%D some sort of translation table, we have to distinguish between the variables at
523%D the left side and the fixed values at the right.
524%D
525%D The same goes for commands that are composed of different user supplied and/or
526%D language specific elements. In english we can use:
527%D
528%D \starttyping
529%D \<empty><figure>
530%D \<empty><intermezzo>
531%D \stoptyping
532%D
533%D But in dutch we have the following:
534%D
535%D \starttyping
536%D \<lege><figuur>
537%D \<leeg><intermezzo>
538%D \stoptyping
539%D
540%D These subtle differences automatically lead to a solution where variables,
541%D values, elements and other components have a similar logical name (used in
542%D macro's) but a different meaning (supplied by the user).
543%D
544%D Our solution is one in which the whole system is programmed in terms of
545%D identifiers with language specific meanings. In such an implementation, each
546%D fixed variable is available as:
547%D
548%D \starttyping
549%D \<prefix><variable>
550%D \stoptyping
551%D
552%D This means that for instance:
553%D
554%D \starttyping
555%D \setupbox[width=12cm]
556%D \stoptyping
557%D
558%D expands to something like:
559%D
560%D \starttyping
561%D \def\boxwidth{12cm}
562%D \stoptyping
563%D
564%D because we don't want to recode the source, a setup command in another language
565%D has to expand to this variable, so:
566%D
567%D \starttyping
568%D \setupblock[width=12cm]
569%D \stoptyping
570%D
571%D has to result in the definition of \type {\boxwidth} too. This method enables us
572%D to build compact, fast and readable code.
573%D
574%D An alternative method, which we considered using, uses a more indirect way. In
575%D this case, both calls generate a different variable:
576%D
577%D \starttyping
578%D \def\boxwidth   {12cm}
579%D \def\boxbreedte {12cm}
580%D \stoptyping
581%D
582%D And because we don't want to recode those megabytes of already developed code,
583%D this variable has to be called with something like:
584%D
585%D \starttyping
586%D \valueof\box\width
587%D \stoptyping
588%D
589%D where \type {\valueof} takes care of the translation of \type {width} or \type
590%D {breedte} to \type {width} and combining this with \type {box} to \type
591%D {\boxwidth}.
592%D
593%D One advantage of this other scheme is that, within certain limits, we can
594%D implement an interface that can be switched to another language at will, while
595%D the current approach fixes the interface at startup. There are, by the way, other
596%D reasons too for not choosing this scheme. Switching user generated commands is
597%D for instance impossible and a dual interface would therefore give a strange mix
598%D of languages.
599%D
600%D Now let's work out the first scheme. Although the left hand of the assignment is
601%D a variable from the users point of view, it is a constant in terms of the system.
602%D Both \type {width} and \type {breedte} expand to \type {width} because in the
603%D source we only encounter \type {width}. Such system constants are presented as
604%D
605%D \starttyping
606%D \c!width
607%D \stoptyping
608%D
609%D This constant is always equivalent to \type {width}. As we can see, we use \type
610%D {c!} to mark this one as constant. Its dutch counterpart is:
611%D
612%D \starttyping
613%D breedte
614%D \stoptyping
615%D
616%D When we interpret a setup command each variable is translated to it's \type{c!}
617%D counterpart. This means that \type {breedte} and \type{width} expand to \type
618%D {breedte} and \type {\c!width} which both expand to \type {width}. That way user
619%D variables become system constants.
620%D
621%D The interpretation is done by means of a general setup command \type
622%D {\getparameters} that we introduced in the system module. Let us define some
623%D simple setup command:
624%D
625%D \starttyping
626%D \protected\def\setupbox[#1]%
627%D   {\getparameters[\??bx][#1]}
628%D \stoptyping
629%D
630%D This command can be used as:
631%D
632%D \starttyping
633%D \setupbox [width=3cm, height=1cm]
634%D \stoptyping
635%D
636%D Afterwards we have two variables \type {\@@bxwidth} and \type {\@@bxheight} which
637%D have the values \type {3cm} and \type {1cm} assigned. These variables are a
638%D combinatiom of the setup prefix \type {\??bx}, which expands to \type {@@bx} and
639%D the translated user supplied variables \type {width} and \type {height} or \type
640%D {breedte} and \type {hoogte}, depending on the actual language. In dutch we just
641%D say:
642%D
643%D \starttyping
644%D \stelblokin [breedte=3cm,hoogte=1cm]
645%D \stoptyping
646%D
647%D and get ourselves \type {\@@bxwidth} and \type {\@@bxheight} too. In the source
648%D of \CONTEXT, we can recognize constants and variables on their leading \type
649%D {c!}, \type {v!} etc., prefixes on \type {??} and composed variables on \type
650%D {@@}.
651%D
652%D We already saw that user supplied keywords need some special treatment too. This
653%D time we don't translate the keyword, but instead use in the source a variable
654%D which meaning depends on the interface language.
655%D
656%D \starttyping
657%D \v!left
658%D \stoptyping
659%D
660%D Which can be used in macro's like:
661%D
662%D \starttyping
663%D \processaction
664%D   [\@@bxlocation]
665%D   [  \v!left=>\dosomethingontheleft,
666%D    \v!middle=>\dosomthinginthemiddle,
667%D     \v!right=>\dosomethingontheright]
668%D \stoptyping
669%D
670%D Because variables like \type {\@@bxlocation} can have a lot of meanings,
671%D including tricky expandable tokens, we cannot translate this meaning when we
672%D compare. This means that \type {\@@bxlocation} can be \type {left} of \type
673%D {links} of whatever meaning suits the language. But because \type {\v!left} also
674%D has a meaning that suits the language, we are able to compare.
675%D
676%D Although we know it sounds confusing we want to state two important
677%D characteristics of the interface as described:
678%D
679%D \startnarrower \em
680%D user variables become system constants
681%D \stopnarrower
682%D
683%D and
684%D
685%D \startnarrower \em
686%D user constants (keywords) become system variables
687%D \stopnarrower
688%D
689%D The \type {\c!internal} is a left over from the time that the user interface
690%D documents were not using a specification alongside a keyword specification but
691%D used a shared file in which case we need to go in both directions.
692
693% temporary mkiv hack (we can best just store the whole table in memory)
694
695\permanent\overloaded\protected\def\setinterfaceconstant#1#2%
696  {\clf_setinterfaceconstant{#1}{#2}%
697   \immutable\cdefcsname\c!prefix!#1\endcsname{#1}}
698
699\permanent\overloaded\protected\def\setinterfacevariable#1#2%
700  {\clf_setinterfacevariable{#1}{#2}%
701   \immutable\cdefcsname\v!prefix!#1\endcsname{#2}}
702
703%D \macros
704%D   {defineinterfaceconstant}
705%D
706%D Next we redefine a previously defined macro to take care of interface translation
707%D too. It's a bit redundant, because in these situations we could use the
708%D c||version, but for documentation purposes the x||alternative comes in handy.
709
710\permanent\overloaded\protected\def\defineinterfaceconstant#1#2%
711  {\immutable\cdefcsname\c!prefix!#1\endcsname{#2}}
712
713%D \macros
714%D   {startelements}
715%D
716%D Due to the object oriented nature of \CONTEXT, we also need to define the
717%D elements that are used to build commands.
718%D
719%D Such elements sometimes are the same in different languages, but mostly they
720%D differ. Things can get even confusing when we look at for instance the setup
721%D commands. In english we say \type{\setup<something>}, but in dutch we have: \type
722%D {\stel<iets>in}. Such split elements are no problem, because we just define two
723%D elements. When no second part is needed, we use a \type {-}:
724
725\permanent\overloaded\protected\def\setinterfaceelement#1#2%
726  {\clf_setinterfaceelement{#1}{#2}%
727   \ifcsname\e!prefix!#1\endcsname
728     \doifnotvalue{\e!prefix!#1}{#2}{\enforced\immutable\defcsname\e!prefix!#1\endcsname{#2}}%
729   \else
730     \enforced\immutable\defcsname\e!prefix!#1\endcsname{#2}%
731   \fi}
732
733\permanent\protected\def\setinterfacecommand#1#2% \frozen ? \permanent ?
734  {\iftok{#1}{#2}%
735     % todo: maybe let when already defined
736   \else
737     \defcsname#2\expandafter\endcsname\expandafter{\csname#1\endcsname}%
738   \fi}
739
740%D We just ignore these:
741
742\permanent\protected\def\startvariables{\ignoreupto\stopvariables} \aliased\let\stopvariables\relax
743\permanent\protected\def\startconstants{\ignoreupto\stopconstants} \aliased\let\stopconstants\relax
744\permanent\protected\def\startelements {\ignoreupto\stopelements } \aliased\let\stopelements \relax
745\permanent\protected\def\startcommands {\ignoreupto\stopcommands } \aliased\let\stopcommands \relax
746
747%D For at the \LUA\ end (experiment):
748
749% \def\ui_c#1#2{\immutable\gdefcsname\c!prefix!#1\endcsname{#1}%
750%               \immutable\gdefcsname\k!prefix!#2\endcsname{#1}} % backmapping from non english
751% \def\ui_s  #1{\immutable\gdefcsname\c!prefix!#1\endcsname{#1}%
752%               \immutable\gdefcsname\k!prefix!#1\endcsname{#1}} % backmapping from non english
753% \def\ui_v#1#2{\immutable\gdefcsname\v!prefix!#1\endcsname{#2}}
754% \def\ui_e#1#2{\immutable\gdefcsname\e!prefix!#1\endcsname{#2}}
755% \def\ui_a#1#2{\frozen\protected\def#2{#1}} % will go away
756%
757% \startinterface english
758%
759%     \def\ui_c#1#2{\immutable\gdefcsname\c!prefix!#1\endcsname{#1}}
760%     \def\ui_s  #1{\immutable\gdefcsname\c!prefix!#1\endcsname{#1}}
761%
762% \stopinterface
763
764%D So much for the basic multi||lingual interface commands. The macro's can be
765%D enhanced with more testing facilities, but for the moment they suffice.
766
767% use \tocharacter
768
769\ifdefined\zwnj \else \immutable\edef\zwnj{\tocharacter"200C} \fi % needed for cont-pe % maybe to char-utf.mkiv
770\ifdefined\zwj  \else \immutable\edef\zwj {\tocharacter"200D} \fi % needed for cont-pe % maybe to char-utf.mkiv
771
772%D \macros
773%D   {contextversion, contextversionnumber, contextversionno,
774%D    contextbanner, showcontextbanner, formatversion}
775%D
776%D Out of convenience we define the banners here. This might move to the \LUA\ end.
777
778\pushoverloadmode
779
780\permanent\overloaded\def\contextbanner
781  {ConTeXt \space
782   ver: \contextversion \space \contextmark \space \space
783   fmt: \formatversion \space \space
784   int: \currentinterface/\currentresponses}
785
786\permanent\overloaded\protected\def\showcontextbanner
787  {\writestatus\m!system\empty
788   \writestatus\m!system\contextbanner
789   \writestatus\m!system\empty}
790
791\immutable\overloaded\edef\formatversion
792  {\the\normalyear.\the\normalmonth.\the\normalday}
793
794\newcount\contextversionno
795
796\ifdefined\contextversion \else
797    \immutable\edef\contextversion{\the\normalyear.\the\normalmonth.\the\normalday\space 00:00}
798\fi
799
800\permanent\overloaded\protected\def \contextversionnumber #1.#2.#3 #4:#5\relax{#1#2#3}
801                                    \contextversionno     \expandafter\contextversionnumber\contextversion\relax
802\immutable\overloaded          \edef\contextversionnumber {\the\contextversionno\space\contextmark}
803
804\popoverloadmode
805
806%D \macros
807%D   {everydump}
808%D
809%D This one is only used when we generate the format.
810
811% \ifdefined\everydump \else
812%     \newtoks\everydump
813%     \def\dump{\the\everydump\global\everydump\emptytoks\glet\dump\relax\normaldump}
814% \fi
815
816% \appendtoks \showcontextbanner \to \everydump
817
818\protect \endinput
819