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