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