core-con.mkxl /size: 34 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=core-con,
3%D        version=1997.26.08,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=Conversion,
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\writestatus{loading}{ConTeXt Core Macros / Conversion}
15
16\registerctxluafile{core-con}{autosuffix}
17
18% todo: iso date ranges (from/to)
19
20\unprotect
21
22\ifdefined\currentlanguage \else \lettonothing\currentlanguage     \fi
23\ifdefined\labeltext       \else \let\labeltext\firstofoneargument \fi
24
25%D This module deals with all kind of conversions from numbers and dates. I
26%D considered splitting this module in a support one and a core one, but to keep
27%D things simple as well as preserve the overview, I decided against splitting.
28
29\aliased\let\spr\firstofoneargument % separator
30\aliased\let\stp\firstofoneargument % stopper
31
32% needed for arab (but can disappear as no ons used it, experiment for idris)
33
34\permanent\protected\def\isolateseparators % even works with list separator overloading
35  {\enforced\permanent\def\spr##1{{##1}}%  % we can probably best mess around with zwj
36   \enforced\permanent\def\stp##1{{##1}}}  % and friends
37
38%D \macros
39%D   {numbers}
40%D
41%D First we deal with the dummy conversion of numbers using the \TEX\ primitive
42%D \type{\number}. The uppercase alternative is only there for compatibility with
43%D the other conversion macros. We could do without \type{#1} but this way we get
44%D rid of unwanted braces. For the savety we also define a non||sence uppercase
45%D alternative.
46%D
47%D \showsetup{numbers}
48%D
49%D \starttyping
50%D \def\numbers#1{\number#1}
51%D \def\Numbers#1{\number#1}
52%D \stoptyping
53%D
54%D Due to read ahead, as in \type{[\pagenumber\space]} the space will disappear,
55%D unless we use:
56
57\permanent\def\numbers#1{\purenumber{#1}}
58\permanent\def\Numbers#1{\purenumber{#1}}
59
60%D \macros
61%D   {romannumerals,Romannumerals}
62%D
63%D \TEX\ the program uses a rather tricky conversion from numbers to their roman
64%D counterparts. This conversion could of course be programmed in \TEX\ itself, but
65%D I guess Knuth found the programming trick worth presenting.
66%D
67%D \showsetup{romannumerals}
68%D \showsetup{Romannumerals}
69
70\permanent\def\romannumerals#1{\clf_romannumerals{#1}}
71\permanent\def\Romannumerals#1{\clf_Romannumerals{#1}}
72
73%D Arabic  etc:
74
75\permanent\def\abjadnumerals     #1{\clf_abjadnumerals     {#1}}
76\permanent\def\abjadnodotnumerals#1{\clf_abjadnodotnumerals{#1}}
77\permanent\def\abjadnaivenumerals#1{\clf_alphabetic        {#1}{arabic}} % okay?
78
79\permanent\def\hebrewnumerals    #1{\clf_hebrewnumerals{#1}}
80\aliased  \let\yiddishnumerals      \hebrewnumerals
81
82\permanent\def\languagecharacters#1{\clf_alphabetic{#1}{\currentlanguage}} % new
83\permanent\def\languageCharacters#1{\clf_Alphabetic{#1}{\currentlanguage}} % new
84
85\permanent\def\alphabeticnumerals#1{\clf_alphabetic{#1}{}}
86\permanent\def\Alphabeticnumerals#1{\clf_Alphabetic{#1}{}}
87
88\permanent\def\thainumerals      #1{\clf_alphabetic{#1}{thai}}
89\permanent\def\devanagarinumerals#1{\clf_decimals  {#1}{devanagari}}
90\permanent\def\malayalamnumerals #1{\clf_decimals  {#1}{malayalam}}
91\permanent\def\tamilnumerals     #1{\clf_decimals  {#1}{tamil}}
92\permanent\def\kannadanumerals   #1{\clf_decimals  {#1}{kannada}}
93\permanent\def\telugunumerals    #1{\clf_decimals  {#1}{telugu}}
94\permanent\def\bengalinumerals   #1{\clf_decimals  {#1}{bengali}}
95\permanent\def\gujaratinumerals  #1{\clf_decimals  {#1}{gujarati}}
96\permanent\def\gurmurkhinumerals #1{\clf_decimals  {#1}{gurmurkhi}}
97\permanent\def\tibetannumerals   #1{\clf_alphabetic{#1}{tibetan}}
98\permanent\def\greeknumerals     #1{\clf_alphabetic{#1}{greek}}
99\permanent\def\Greeknumerals     #1{\clf_Alphabetic{#1}{greek}}
100\permanent\def\arabicnumerals    #1{\clf_alphabetic{#1}{arabic}}
101\permanent\def\persiannumerals   #1{\clf_alphabetic{#1}{persian}}
102\permanent\def\arabicdecimals    #1{\clf_decimals  {#1}{arabic}}
103\permanent\def\persiandecimals   #1{\clf_decimals  {#1}{persian}}
104
105\permanent\def\mathgreeknumerals #1{\im{\clf_alphabetic{#1}{greek}}}
106\permanent\def\mathGreeknumerals #1{\im{\clf_Alphabetic{#1}{greek}}}
107
108\aliased  \let\arabicexnumerals     \persiannumerals
109
110\permanent\def\koreannumerals    #1{\clf_alphabetic{#1}{korean}}
111\permanent\def\koreannumeralsp   #1{\clf_alphabetic{#1}{korean-parenthesis}}
112\permanent\def\koreannumeralsc   #1{\clf_alphabetic{#1}{korean-circle}}
113
114\aliased  \let\koreanparentnumerals     \koreannumeralsp
115\aliased  \let\koreanparenthesisnumerals\koreannumeralsp
116\aliased  \let\koreancirclenumerals     \koreannumeralsc
117
118\permanent\def\chinesenumerals    #1{\clf_chinesenumerals{#1}{normal}}
119\permanent\def\chinesecapnumerals #1{\clf_chinesenumerals{#1}{cap}}
120\permanent\def\chineseallnumerals #1{\clf_chinesenumerals{#1}{all}}
121\permanent\def\chinesedatenumerals#1{\clf_chinesenumerals{#1}{date}}
122
123%D \macros
124%D   {character,Character}
125%D
126%D Converting a number into a character can of course only be done with numbers
127%D less or equal to~26. At the cost of much more macros a faster conversion is
128%D possible, using:
129%D
130%D \starttyping
131%D \setvalue{char1}{a} \def\character#1{\getvalue{char#1}}
132%D \stoptyping
133%D
134%D But we prefer a simpel \type{\case}.
135%D
136%D \showsetup{character}
137%D \showsetup{Character}
138
139\permanent\def\character#1{\clf_character{#1}}
140\permanent\def\Character#1{\clf_Character{#1}}
141
142%D \macros
143%D   {characters,Characters}
144%D
145%D Converting large numbers is supported by the next two macros. This time we
146%D just count on: $\cdots$~x, y, z, aa, ab, ac~$\cdots$.
147%D
148%D \showsetup{characters}
149%D \showsetup{Characters}
150
151\permanent\def\characters#1{\clf_characters{#1}}
152\permanent\def\Characters#1{\clf_Characters{#1}}
153
154%D \macros
155%D   {greeknumerals,Greeknumerals}
156%D
157%D Why should we only honour the romans, and not the greek?
158
159% \let\greeknumerals\gobbleoneargument
160% \let\Greeknumerals\gobbleoneargument
161
162%D \macros
163%D   {oldstylenumerals,oldstyleromannumerals}
164%D
165%D These conversions are dedicated to Frans Goddijn.
166
167\permanent\protected\def\oldstylenumerals#1%
168  {\begingroup
169   \os\number#1%
170   \endgroup}
171
172\permanent\protected\def\oldstyleromannumerals#1% will become obsolete
173  {\dontleavehmode
174   \hbox\bgroup
175   \ss\txx
176   \setbox\scratchbox\hbox \s!spread .15\emwidth{\hss\uppercased{\romannumerals{#1}}\hss}%
177   \scratchwidth \wd\scratchbox
178   \scratchheight\ht\scratchbox
179   \scratchdimen .1\exheight
180   \vrule
181     \s!width \scratchwidth
182     \s!height{\scratchheight+\scratchdimen}%
183     \s!depth {-\scratchheight+\scratchdimen}%
184   \relax
185   \hskip-\scratchwidth
186   \vrule
187     \s!width \scratchwidth
188     \s!height\scratchdimen
189     \s!depth \scratchdimen
190   \relax
191   \hskip-\scratchwidth
192   \box\scratchbox
193   \egroup}
194
195%D \macros
196%D   {normaltime,normalyear,normalmonth,normalday}
197%D
198%D The last part of this module is dedicated to converting dates. Because we want to
199%D use as meaningful commands as possible, and because \TEX\ already uses up some of
200%D those, we save the original meanings. The above are defined already.
201
202%D \macros
203%D   {month,MONTH}
204%D
205%D Converting the month number into a month name is done using a case statement,
206%D abstact values and the label mechanism. This way users can easily redefine a
207%D label from for instance german into austrian.
208%D
209%D \starttyping
210%D \setuplabeltext [de] [january=J\"anner]
211%D \stoptyping
212%D
213%D Anyhow, the conversion looks like:
214
215\permanent\protected\def\monthlong #1{\clf_monthname{#1}}
216\permanent\protected\def\monthshort#1{\clf_monthmnem{#1}}
217\permanent\protected\def\daylong   #1{\clf_dayname{#1}}
218\permanent\protected\def\dayshort  #1{\clf_daymnem{#1}}
219\aliased            \let\convertmonth\monthlong % for old times sake
220
221%D We redefine the \TEX\ primitive \type{\month} as:
222%D
223%D \showsetup{month}
224%D \showsetup{MONTH}
225
226\pushoverloadmode
227
228\aliased\let\month\monthlong
229
230\popoverloadmode
231
232\permanent\protected\def\MONTH     #1{\WORD{\clf_monthname{#1}}}
233\permanent\protected\def\MONTHLONG #1{\WORD{\clf_monthname{#1}}}
234\permanent\protected\def\MONTHSHORT#1{\WORD{\clf_monthmnem{#1}}}
235
236%D We never explicitly needed this, but Tobias Burnus pointed out that it would be
237%D handy to convert to the day of the week. In doing so, we have to calculate the
238%D total number of days, taking leapyears into account. For those who are curious:
239%D
240%D \startitemize[packed]
241%D \item  years that can be divided by 4 are leapyears
242%D \item  exept years that can be divided by 100
243%D \item  unless years can be divided by 400
244%D \stopitemize
245
246%D \macros
247%D   {weekday,WEEKDAY}
248%D
249%D The first one is sort of redundant. It takes the day number argument.
250%D
251%D \showsetup{weekday}
252%D \showsetup{WEEKDAY}
253
254\permanent\protected\def\weekday #1{\clf_dayname{#1}}
255\permanent\protected\def\WEEKDAY #1{\WORD{\clf_dayname{#1}}}
256\permanent\protected\def\DAYLONG #1{\WORD{\clf_dayname{#1}}}
257\permanent\protected\def\DAYSHORT#1{\WORD{\clf_daymnem{#1}}}
258
259%D \macros
260%D   {getdayoftheweek, dayoftheweek}
261
262\newcount\normalweekday
263
264\permanent          \def\dayoftheweek   #1#2#3{\clf_weekdayname{#1}{#2}{#3}}                 % name
265\permanent\protected\def\getdayoftheweek#1#2#3{\normalweekday\clf_weekday{#1}{#2}{#3}\relax} % number
266
267%D Using this macro in
268%D
269%D \startbuffer
270%D monday:   \dayoftheweek  {4} {5} {1992}
271%D friday:   \dayoftheweek {16} {6} {1995}
272%D monday:   \dayoftheweek {25} {8} {1997}
273%D saturday: \dayoftheweek {30} {8} {1997}
274%D tuesday:  \dayoftheweek  {2} {1} {1996}
275%D tuesday:  \dayoftheweek  {7} {1} {1997}
276%D tuesday:  \dayoftheweek {13} {1} {1998}
277%D friday:   \dayoftheweek  {1} {1} {2000}
278%D \stopbuffer
279%D
280%D \typebuffer
281%D
282%D gives
283%D
284%D \startlines
285%D \getbuffer
286%D \stoplines
287%D
288%D The macro \type {\getdayoftheweek} can be used to calculate the number \type
289%D {\normalweekday}.
290
291%D \macros
292%D   {doifleapyearelse,
293%D    getdayspermonth}
294%D
295%D Sometimes we need to know if we're dealing with a leapyear, so here is a
296%D testmacro:
297%D
298%D \starttyping
299%D \doifleapyearelse{year}{yes}{no}
300%D \stoptyping
301%D
302%D An example of its use can be seen in the macro
303%D
304%D \starttyping
305%D \getdayspermonth{year}{month}
306%D \stoptyping
307%D
308%D The number of days is available in the macro \type {\numberofdays}.
309
310\permanent\def\doifelseleapyear#1% expandable check
311  {\clf_doifelseleapyear{#1}}
312
313\aliased\let\doifleapyearelse\doifelseleapyear
314
315\mutable\let\numberofdays\!!zerocount
316
317\permanent\protected\def\getdayspermonth#1#2%
318  {\edef\numberofdays{\clf_nofdays{#1}{#2}}}
319
320\permanent\def\dayspermonth#1#2%
321  {\clf_nofdays{#1}{#2}}
322
323% \dayoftheweek{2006}{9}{15}
324% \doifleapyearelse{2000}{OK}{NOT OK}
325% \doifleapyearelse{2100}{NOT OK}{OK}
326% \doifleapyearelse{2004}{OK}{NOT OK}
327% \doifleapyearelse{2003}{NOT OK}{OK}
328% \dayspermonth{2000}{2}
329% [\the\normaltime=\the\time]
330
331%D \macros
332%D   {currentdate, rawdate, date}
333%D
334%D We use these conversion macros in the date formatting macro:
335%D
336%D \showsetup{currentdate}
337%D
338%D This macro takes care of proper spacing and delivers for instance:
339%D
340%D \startbuffer
341%D \currentdate[weekday,day,month,year]
342%D \currentdate[WEEKDAY,day,MONTH,year]
343%D \stopbuffer
344%D
345%D \startlines
346%D \getbuffer
347%D \stoplines
348%D
349%D depending of course on the keywords. Here we gave:
350%D
351%D \typebuffer
352%D
353%D If needed one can also add non||keywords, like in
354%D
355%D \startbuffer
356%D \currentdate[dd,--,mm,--,yy]
357%D \stopbuffer
358%D
359%D \typebuffer
360%D
361%D or typeset: \getbuffer.
362%D
363%D When no argument is passed, the current date is given as specified per
364%D language (using \type{\installlanguage}).
365%D
366%D \showsetup{currentdate}
367%D
368%D \startbuffer
369%D \date
370%D \date[d=12,m=12,y=1998][weekday]
371%D \date[d=12,m=12,y=1998]
372%D \stopbuffer
373%D
374%D We can also typeset arbitrary dates, using the previous
375%D command.
376%D
377%D \typebuffer
378%D
379%D The date is specified by one character keys. When no date is given, we get the
380%D current date.
381%D
382%D \startlines
383%D \getbuffer
384%D \stoplines
385
386%D \starttabulate[|l|l|]
387%D \HL
388%D \NC year     \NC (\currentdate[year])     \NC\NR
389%D \NC yy       \NC (\currentdate[yy])       \NC\NR
390%D \NC y        \NC (\currentdate[y])        \NC\NR
391%D \NC Y        \NC (\currentdate[Y])        \NC\NR
392%D \HL
393%D \NC month    \NC (\currentdate[month])    \NC\NR
394%D \NC mm       \NC (\currentdate[mm])       \NC\NR
395%D \NC m        \NC (\currentdate[m])        \NC\NR
396%D \NC M        \NC (\currentdate[M])        \NC\NR
397%D \HL
398%D \NC day      \NC (\currentdate[day])      \NC\NR
399%D \NC dd       \NC (\currentdate[dd])       \NC\NR
400%D \NC d        \NC (\currentdate[d])        \NC\NR
401%D \NC D        \NC (\currentdate[D])        \NC\NR
402%D \HL
403%D \NC weekday  \NC (\currentdate[weekday])  \NC\NR
404%D \NC w        \NC (\currentdate[w])        \NC\NR
405%D \NC W        \NC (\currentdate[W])        \NC\NR
406%D \HL
407%D \NC referral \NC (\currentdate[referral]) \NC\NR
408%D \HL
409%D \NC day:mnem \NC (\currentdate[day:mnem]) \NC\NR
410%D \NC dd:mnem  \NC (\currentdate[dd:mnem])  \NC\NR
411%D \NC d:mnem   \NC (\currentdate[d:mnem])   \NC\NR
412%D \NC D:mnem   \NC (\currentdate[D:mnem])   \NC\NR
413%D \HL
414%D \stoptabulate
415%D
416%D \startbuffer
417%D (\currentdate[D,.,M,.,Y])
418%D (\currentdate[day,month,year])
419%D (\currentdate[day,+,month,+,year])
420%D \stopbuffer
421%D
422%D \typebuffer \getbuffer
423%D
424%D Some indirectness and abstraction:
425%D
426%D \starttyping
427%D \definedate[crap][year]
428%D \currentdate[crap]
429%D \stoptyping
430
431\installcorenamespace{date}
432
433\permanent\tolerant\protected\def\definedate[#1]#,[#2]%
434  {\ifarguments\else\defcsname\??date#1\endcsname{#2}\fi}
435
436\def\syst_converters_check_date_specification#1%
437  {\ifcsname\??date#1\endcsname
438     \edef#1{\lastnamedcs}%
439   \fi}
440
441\newtoks\everycurrentdate
442
443\permanent\tolerant\protected\def\currentdate[#1]%
444  {\dontleavehmode
445   \begingroup
446   \expand\everycurrentdate
447   \edef\m_syst_converters_date{#1}%
448   \syst_converters_check_date_specification\m_syst_converters_date
449   \syst_converters_check_date_specification\currentdatespecification
450   \clf_currentdate
451     {\m_syst_converters_date}{\currentdatespecification}{\labellanguage}%
452     \normalyear\normalmonth\normalday
453   \endgroup}
454
455\permanent\tolerant\protected\def\setdate[#1]% sets the date !
456  {\begingroup
457   \letdummyparameter\c!d\normalday
458   \letdummyparameter\c!m\normalmonth
459   \letdummyparameter\c!y\normalyear
460   \getdummyparameters[#1]%
461   \normalexpanded
462     {\endgroup
463      \ifchknumber\directdummyparameter\c!d\or\normalday  \the\lastchknumber\relax\fi
464      \ifchknumber\directdummyparameter\c!m\or\normalmonth\the\lastchknumber\relax\fi
465      \ifchknumber\directdummyparameter\c!y\or\normalyear \the\lastchknumber\relax\fi}}
466
467\permanent\tolerant\protected\def\date[#1]#,[#2]% sets the date !
468  {\dontleavehmode
469   \begingroup
470   \setdate[#1]% sets the date !
471   \expand\everycurrentdate
472   \edef\m_syst_converters_date{#2}%
473   \syst_converters_check_date_specification\m_syst_converters_date
474   \syst_converters_check_date_specification\currentdatespecification
475   \clf_currentdate
476     {\m_syst_converters_date}{\currentdatespecification}{\labellanguage}%
477     \normalyear\normalmonth\normalday
478   \endgroup}
479
480\permanent\def\rawdate[#1]% expandable and no labels
481  {\clf_currentdate
482     {#1}{\currentdatespecification}{}%
483     \normalyear\normalmonth\normalday}
484
485%D \macros
486%D   {currenttime}
487%D
488%D The currenttime is actually the jobtime. You can specify a pattern similar
489%D to the previous date macro using the keys \type {h}, \type {m} and a separator.
490
491\mutable\let\currenthour  \!!plusone
492\mutable\let\currentminute\!!plusone
493\mutable\let\currentsecond\!!plusone
494
495\permanent\protected\def\calculatecurrenttime
496  {\edef\currenthour  {\clf_hour  }%
497   \edef\currentminute{\clf_minute}%
498   \edef\currentsecond{\clf_second}}
499
500% \def\currenttimespecification{h,:,m}
501
502\permanent\protected\def\currenttime
503  {\doifelsenextoptional\syst_converters_current_time_yes\syst_converters_current_time_nop}
504
505\protected\def\syst_converters_current_time_yes[#1]%
506  {\calculatecurrenttime
507   \processallactionsinset[#1][h=>\currenthour,m=>\currentminute,\s!unknown=>\commalistelement]}
508
509\protected\def\syst_converters_current_time_nop
510  {\normalexpanded{\syst_converters_current_time_yes[\currenttimespecification]}}
511
512%D Because we're dealing with dates, we also introduce a few day loops:
513%D
514%D \starttyping
515%D \processmonth{year}{month}{command}
516%D \processyear{year}{command}{before}{after}
517%D \stoptyping
518%D
519%D The counters \type {\normalyear}, \type {\normalmonth} and \type {\normalday}
520%D can be used for for date manipulations.
521
522\permanent\protected\def\processmonth#1#2#3% year month command
523  {\begingroup
524   \getdayspermonth{#1}{#2}%
525   \dostepwiserecurse\plusone\numberofdays\plusone
526     {\normalyear #1\relax
527      \normalmonth#2\relax
528      \normalday  \recurselevel\relax
529      #3}%
530   \endgroup}
531
532\permanent\protected\def\processyear#1#2#3#4% year command before after
533  {\begingroup
534   \dorecurse\plustwelve
535     {\normalyear #1\relax
536      \normalmonth\recurselevel\relax
537      #3\processmonth\normalyear\normalmonth{#2}#4}%
538   \endgroup}
539
540%D \macros
541%D   {defineconversion, convertnumber}
542%D
543%D Conversion involves the macros that we implemented earlier in this module.
544%D
545%D \showsetup{defineconversion}
546%D \showsetup{convertnumber}
547%D
548%D We can feed this command with conversion macros as well as a set of conversion
549%D symbols. Both need a bit different treatment.
550%D
551%D \starttyping
552%D \defineconversion [roman] [\romannumerals]
553%D \defineconversion [set 1] [$\star$,$\bullet$,$\ast$]
554%D \stoptyping
555%D
556%D You can define a language dependent conversion with:
557%D
558%D \starttyping
559%D \defineconversion [en] [whatever] [\something]
560%D \stoptyping
561
562\installcorenamespace {conversion}
563\installcorenamespace {conversionarguments}
564\installcorenamespace {conversionwords}
565
566%D It might be better to move more to \LUA\ as we also need conversion there and
567%D duplicating logic doesn't make things cleaner. It means that all conversions
568%D will get a language argument too. However, we permit definitions at the \TEX\ end
569%D so we have to provide some hybrid method.
570
571% checkedconversion(method,n,language)
572
573\permanent\tolerant\protected\def\defineconversion[#1]#*[#2]#*[#3]% from now on global (maybe local again some day)
574  {\ifparameter#3\or
575     \syst_converters_define_conversion_indeed{#1#2}{#1:#2}{#3}%
576   \else
577     \syst_converters_define_conversion_indeed{#1}{#1}{#2}%
578   \fi}
579
580\def\syst_converters_define_conversion_indeed#1#2#3%
581  {\doifelseinstring{,}{\detokenize{#3}}
582     {\clf_defineconversion{#2}{\detokenize{#3}}% a set e.g. of symbols
583      \gdefcsname\??conversion#1\endcsname{\syst_converters_checked_conversion{#2}}}
584     {\gdefcsname\??conversion#1\endcsname{#3}}}
585
586\def\syst_converters_checked_conversion#1#2%
587  {\clf_checkedconversion{#1}{#2}}
588
589%D If a conversion is just a font switch then we need to make sure that the number
590%D is indeed ends up as number in the input, so we need to handle the second
591%D argument.
592
593\permanent\def\convertnumber#1#2% expandable
594  {\csname\??conversionarguments
595     \ifcsname\??conversion\currentlanguage#1\endcsname1\else
596     \ifcsname\??conversion                #1\endcsname2\else
597                                                       3\fi\fi
598   \endcsname{#1}{\number#2}}
599
600\permanent\protected\def\uconvertnumber % unexpandable
601  {\convertnumber}
602
603\defcsname\??conversionarguments1\endcsname#1{\csname\??conversion\currentlanguage#1\endcsname}
604\defcsname\??conversionarguments2\endcsname#1{\csname\??conversion                #1\endcsname}
605\letcsname\??conversionarguments3\endcsname  \syst_converters_checked_conversion
606
607% we can also add a \ctxcommand{doifelseconversion("#1","\currentlanguage")} to check
608% if we have definitions that are not matched at the lua end .. eventually we might do
609% that when more shows up
610
611\permanent\def\doifelseconversiondefined#1% expandable
612  {\ifcsname\??conversion\currentlanguage#1\endcsname
613     \expandafter\firstoftwoarguments
614   \orelse\ifcsname\??conversion#1\endcsname
615     \expandafter\firstoftwoarguments
616   \else
617     \expandafter\secondoftwoarguments
618   \fi}
619
620\permanent\def\doifelseconversionnumber#1#2% expandable
621  {\ifnum#2>{\clf_nofconversions{#1}}%
622     \expandafter\secondoftwoarguments
623   \else
624     \expandafter\firstoftwoarguments
625   \fi}
626
627\aliased\let\doifconversiondefinedelse\doifelseconversiondefined
628\aliased\let\doifconversionnumberelse \doifelseconversionnumber
629
630%D Handy.
631
632\defcsname\??conversionwords\v!one  \endcsname{1}
633\defcsname\??conversionwords\v!two  \endcsname{2}
634\defcsname\??conversionwords\v!three\endcsname{3}
635\defcsname\??conversionwords\v!four \endcsname{4}
636\defcsname\??conversionwords\v!five \endcsname{5}
637
638\permanent\def\wordtonumber#1#2{\ifcsname\??conversionwords#1\endcsname\lastnamedcs\else#2\fi}
639
640% \defineconversion[ctx][c,o,n,t,e,x,t]
641%
642% \doloop{\doifelseconversionnumber{ctx}{\recurselevel}{[\recurselevel]}{\exitloop}}
643
644%D \macros
645%D   {ordinalnumber, highordinalstr, ordinalstr}
646%D
647%D Efficient general ordinal number converters are sometimes difficult to
648%D implement. Fortunately dates never exceed the number~31.
649
650\permanent\def\highordinalstr#1{\high{\notsmallcapped{#1}}}
651\permanent\def\ordinalstr    #1{\notsmallcapped{#1}}
652\permanent\def\ordinalnumber #1{\clf_ordinal{#1}{\currentlanguage}}
653\permanent\def\Ordinalnumber #1{\Words{\clf_ordinal{#1}{\currentlanguage}}}
654
655\mutable\let\verbosenumberconnector\space
656
657\permanent\def\verbosenumber#1{\clf_verbose{#1}{\currentlanguage}{\verbosenumberconnector}}
658\permanent\def\VerboseNumber#1{\Words{\clf_verbose{#1}{\currentlanguage}{\verbosenumberconnector}}}
659
660%D As longs as symbols are linked to levels or numbers, we can also use the
661%D conversion mechanism, but in for instance the itemization macros, we prefer
662%D symbols because they can more easier be (partially) redefined. Symbols are
663%D implemented in another module.
664
665\permanent\def\smallcappedromannumerals#1{\smallcapped{\romannumerals{#1}}}
666\permanent\def\smallcappedcharacters   #1{\smallcapped{\characters   {#1}}}
667
668\defineconversion []                     [\numbers] % the default conversion
669\defineconversion [\v!empty]             [\gobbleoneargument]
670\defineconversion [\v!none]              [\numbers]
671\defineconversion [\s!default]           [\numbers]
672
673\defineconversion [month]                [\monthlong]
674\defineconversion [month:mnem]           [\monthshort]
675
676\defineconversion [\v!character]         [\character]
677\defineconversion [\v!Character]         [\Character]
678
679\defineconversion [\v!characters]        [\characters]
680\defineconversion [\v!Characters]        [\Characters]
681
682\defineconversion [a]                    [\alphabeticnumerals]
683\defineconversion [A]                    [\Alphabeticnumerals]
684\defineconversion [AK]                   [\smallcappedcharacters]
685\defineconversion [KA]                   [\smallcappedcharacters]
686
687\defineconversion [\v!alphabetic]        [\alphabeticnumerals]
688\defineconversion [\v!Alphabetic]        [\Alphabeticnumerals]
689
690\defineconversion [\v!number]            [\numbers]
691\defineconversion [\v!numbers]           [\numbers]
692\defineconversion [\v!Numbers]           [\Numbers]
693\defineconversion [\v!mediaeval]         [\mediaeval]
694
695\defineconversion [\v!word]              [\verbosenumber]
696\defineconversion [\v!words]             [\verbosenumber]
697
698\defineconversion [\v!Word]              [\VerboseNumber]
699\defineconversion [\v!Words]             [\VerboseNumber]
700
701\defineconversion[\v!ordinal]            [\ordinalnumber]
702\defineconversion[\v!Ordinal]            [\Ordinalnumber]
703
704\defineconversion [n]                    [\numbers]
705\defineconversion [N]                    [\Numbers]
706\defineconversion [m]                    [\mediaeval]
707\defineconversion [o]                    [\oldstylenumerals]
708\defineconversion [O]                    [\oldstylenumerals]
709\defineconversion [or]                   [\oldstyleromannumerals]
710
711\defineconversion [\v!romannumerals]     [\romannumerals]
712\defineconversion [\v!Romannumerals]     [\Romannumerals]
713
714\defineconversion [i]                    [\romannumerals]
715\defineconversion [I]                    [\Romannumerals]
716\defineconversion [r]                    [\romannumerals]
717\defineconversion [R]                    [\Romannumerals]
718
719\defineconversion [KR]                   [\smallcappedromannumerals]
720\defineconversion [RK]                   [\smallcappedromannumerals]
721
722\defineconversion [\v!greek]             [\greeknumerals]
723\defineconversion [\v!Greek]             [\Greeknumerals]
724
725\defineconversion [\s!math:\v!greek]     [\mathgreeknumerals]
726\defineconversion [\s!math:\v!Greek]     [\mathGreeknumerals]
727
728\defineconversion [g]                    [\greeknumerals]
729\defineconversion [G]                    [\Greeknumerals]
730
731%defineconversion [ñ]                    [\spanishnumerals]
732%defineconversion [Ñ]                    [\Spanishnumerals]
733
734\defineconversion [abjadnumerals]        [\abjadnumerals]
735\defineconversion [abjadnodotnumerals]   [\abjadnodotnumerals]
736\defineconversion [abjadnaivenumerals]   [\abjadnaivenumerals]
737
738\defineconversion [hebrewnumerals]       [\hebrewnumerals]
739\defineconversion [yiddishnumerals]      [\yiddishnumerals]
740
741% users can do: \defineconversion [he] [\hebrewnumerals]
742% users can do: \defineconversion [yi] [\hebrewnumerals]
743
744\defineconversion [thainumerals]         [\thainumerals]
745\defineconversion [devanagarinumerals]   [\devanagarinumerals]
746\defineconversion [malayalamnumerals]    [\malayalamnumerals]
747\defineconversion [tamilnumerals]        [\tamilnumerals]
748\defineconversion [kannadanumerals]      [\kannadanumerals]
749\defineconversion [telugunumerals]       [\telugunumerals]
750\defineconversion [bengalinumerals]      [\bengalinumerals]
751\defineconversion [gurmurkhinumerals]    [\gurmurkhinumerals]
752\defineconversion [gujaratinumerals]     [\gujaratinumerals]
753\defineconversion [tibetannumerals]      [\tibetannumerals]
754\defineconversion [greeknumerals]        [\greeknumerals]
755\defineconversion [Greeknumerals]        [\Greeknumerals]
756\defineconversion [arabicnumerals]       [\arabicnumerals]
757\defineconversion [persiannumerals]      [\persiannumerals]
758\defineconversion [arabicexnumerals]     [\arabicexnumerals]
759\defineconversion [arabicdecimals]       [\arabicdecimals]
760\defineconversion [persiandecimals]      [\persiandecimals]
761
762\defineconversion [mathgreeknumerals]    [\mathgreeknumerals]
763\defineconversion [mathGreeknumerals]    [\mathGreeknumerals]
764
765\defineconversion [koreannumerals]       [\koreannumerals]
766\defineconversion [koreanparennumerals]  [\koreanparenthesisnumerals] % for old times sake (for a while)
767\defineconversion [koreanparenthesisnumerals]
768                                         [\koreanparenthesisnumerals]
769\defineconversion [koreancirclenumerals] [\koreancirclenumerals]
770
771\defineconversion [kr]                   [\koreannumerals]
772\defineconversion [kr-p]                 [\koreanparentnumerals]
773\defineconversion [kr-c]                 [\koreancirclenumerals]
774
775\defineconversion [chinesenumerals]      [\chinesenumerals]
776\defineconversion [chinesecapnumerals]   [\chinesecapnumerals]
777\defineconversion [chineseallnumerals]   [\chineseallnumerals]
778\defineconversion [chinesedatenumerals]  [\chinesedatenumerals]
779
780\defineconversion [cn]                   [\chinesenumerals]
781\defineconversion [cn-c]                 [\chinesecapnumerals]
782\defineconversion [cn-a]                 [\chineseallnumerals]
783\defineconversion [cn-d]                 [\chinesedatenumerals]
784
785%D Moved from lang-def.mkiv:
786%D
787%D Define these as the general character enumeration when language is Slovenian. If
788%D you feel uncomfortable with this, mail Mojca, since she promised to to take the
789%D heat. Pablo was next to request this. We changed characters to numerals for this
790%D feature. We do need these definitions for mechanisms like itemize that check
791%D for converters.
792
793\permanent\def\sloveniannumerals#1{\clf_alphabetic{#1}{sl}}
794\permanent\def\slovenianNumerals#1{\clf_Alphabetic{#1}{sl}}
795
796\permanent\def\spanishnumerals  #1{\clf_alphabetic{#1}{es}}
797\permanent\def\spanishNumerals  #1{\clf_Alphabetic{#1}{es}}
798
799\permanent\def\russiannumerals  #1{\clf_alphabetic{#1}{ru}}
800\permanent\def\russianNumerals  #1{\clf_Alphabetic{#1}{ru}}
801
802%defineconversion [\s!sl] [character]  [\sloveniannumerals]
803%defineconversion [\s!sl] [Character]  [\slovenianNumerals]
804%defineconversion [\s!sl] [characters] [\sloveniannumerals]
805%defineconversion [\s!sl] [Characters] [\slovenianNumerals]
806
807\defineconversion [\s!sl] [alphabetic] [\sloveniannumerals]
808\defineconversion [\s!sl] [Alphabetic] [\slovenianNumerals]
809
810\defineconversion [\s!sl] [a]          [\sloveniannumerals]
811\defineconversion [\s!sl] [A]          [\slovenianNumerals]
812\defineconversion [\s!sl] [AK]         [\smallcapped\sloveniannumerals]
813\defineconversion [\s!sl] [KA]         [\smallcapped\sloveniannumerals]
814
815%defineconversion [\s!es] [character]  [\spanishnumerals]
816%defineconversion [\s!es] [Character]  [\spanishNumerals]
817%defineconversion [\s!es] [characters] [\spanishnumerals]
818%defineconversion [\s!es] [Characters] [\spanishNumerals]
819
820\defineconversion [\s!es] [alphabetic] [\spanishnumerals]
821\defineconversion [\s!es] [Alphabetic] [\spanishNumerals]
822
823\defineconversion [\s!es] [a]          [\spanishnumerals]
824\defineconversion [\s!es] [A]          [\spanishNumerals]
825\defineconversion [\s!es] [AK]         [\smallcapped\spanishnumerals]
826\defineconversion [\s!es] [KA]         [\smallcapped\spanishnumerals]
827
828%defineconversion [\s!ru] [character]  [\russiannumerals]
829%defineconversion [\s!ru] [Character]  [\russianNumerals]
830%defineconversion [\s!ru] [characters] [\russiannumerals]
831%defineconversion [\s!ru] [Characters] [\russianNumerals]
832
833\defineconversion [\s!ru] [alphabetic] [\russiannumerals]
834\defineconversion [\s!ru] [Alphabetic] [\russianNumerals]
835
836\defineconversion [\s!ru] [a]          [\russiannumerals]
837\defineconversion [\s!ru] [A]          [\russianNumerals]
838\defineconversion [\s!ru] [AK]         [\smallcapped\russiannumerals]
839\defineconversion [\s!ru] [KA]         [\smallcapped\russiannumerals]
840
841\defineconversion [sloveniannumerals]  [\sloveniannumerals]
842\defineconversion [slovenianNumerals]  [\slovenianNumerals]
843
844\defineconversion [spanishnumerals]    [\spanishnumerals]
845\defineconversion [spanishNumerals]    [\spanishNumerals]
846
847\defineconversion [russiannumerals]    [\russiannumerals]
848\defineconversion [russianNumerals]    [\russianNumerals]
849
850%D In case a font has no greek (WS):
851
852\defineconversion [mathgreek]
853  [\m{α},\m{β},\m{γ},\m{δ},\m{ε},\m{ζ},
854   \m{η},\m{θ},\m{ι},\m{κ},\m{λ},\m{μ},
855   \m{ν},\m{ξ},\m{ο},\m{π},\m{ρ},\m{σ},
856   \m{τ},\m{υ},\m{φ},\m{χ},\m{ψ},\m{ω}]
857
858%D Handy too (expanded!):
859
860\permanent\def\unihex#1{\clf_unihex{#1}}
861
862%D Symbol sets:
863
864\ifdefined\symbol \else \def\symbol[#1]{#1} \fi % todo
865
866% \defineconversion
867%   [set 0]
868%   [{\symbol[bullet]},
869%    {\symbol[dash]},
870%    {\symbol[star]},
871%    {\symbol[triangle]},
872%    {\symbol[circle]},
873%    {\symbol[medcircle]},
874%    {\symbol[bigcircle]},
875%    {\symbol[square]},
876%    {\symbol[checkmark]}]
877
878% \defineconversion
879%   [set 1]
880%   [\mathematics{\star},
881%    \mathematics{\star\star},
882%    \mathematics{\star\star\star},
883%    \mathematics{\ddagger},
884%    \mathematics{\ddagger\ddagger},
885%    \mathematics{\ddagger\ddagger\ddagger},
886%    \mathematics{\ast},
887%    \mathematics{\ast\ast},
888%    \mathematics{\ast\ast\ast}]
889%
890% \defineconversion
891%   [set 2]
892%   [\mathematics{\ast},
893%    \mathematics{\dag},
894%    \mathematics{\ddag},
895%    \mathematics{\ast\ast},
896%    \mathematics{\dag\dag},
897%    \mathematics{\ddag\ddag},
898%    \mathematics{\ast\ast\ast},
899%    \mathematics{\dag\dag\dag},
900%    \mathematics{\ddag\ddag\ddag},
901%    \mathematics{\ast\ast\ast\ast},
902%    \mathematics{\dag\dag\dag\dag},
903%    \mathematics{\ddag\ddag\ddag\ddag}]
904%
905% \defineconversion
906%   [set 3]
907%   [\mathematics{\star},
908%    \mathematics{\star\star},
909%    \mathematics{\star\star\star},
910%    \mathematics{\ddagger},
911%    \mathematics{\ddagger\ddagger},
912%    \mathematics{\ddagger\ddagger\ddagger},
913%    \mathematics{\P},
914%    \mathematics{\P\P},
915%    \mathematics{\P\P\P},
916%    \mathematics{\S},
917%    \mathematics{\S\S},
918%    \mathematics{\S\S\S},
919%    \mathematics{\ast},
920%    \mathematics{\ast\ast},
921%    \mathematics{\ast\ast\ast}]
922
923\defineconversion
924  [set 0]
925  [\symbol{bullet},
926   \symbol{dash},
927   \symbol{star},
928   \symbol{triangle},
929   \symbol{circle},
930   \symbol{medcircle},
931   \symbol{bigcircle},
932   \symbol{square},
933   \symbol{checkmark}]
934
935\defineconversion
936  [set 1x]
937  [\textormathchars{}]
938
939\defineconversion
940  [set 1]
941  [\textormathchars{},
942   \textormathchars{⋆⋆},
943   \textormathchars{⋆⋆⋆},
944   \textormathchars{},
945   \textormathchars{‡‡},
946   \textormathchars{‡‡‡},
947   \textormathchars{},
948   \textormathchars{∗∗},
949   \textormathchars{∗∗∗}]
950
951\defineconversion
952  [set 2]
953  [\textormathchars{},
954   \textormathchars{},
955   \textormathchars{},
956   \textormathchars{∗∗},
957   \textormathchars{††},
958   \textormathchars{‡‡},
959   \textormathchars{∗∗∗},
960   \textormathchars{†††},
961   \textormathchars{‡‡‡},
962   \textormathchars{∗∗∗∗},
963   \textormathchars{††††},
964   \textormathchars{‡‡‡‡}]
965
966\defineconversion
967  [set 3]
968  [\textormathchars{},
969   \textormathchars{⋆⋆},
970   \textormathchars{⋆⋆⋆},
971   \textormathchars{},
972   \textormathchars{‡‡},
973   \textormathchars{‡‡‡},
974   \textormathchars{},
975   \textormathchars{¶¶},
976   \textormathchars{¶¶¶},
977   \textormathchars{§},
978   \textormathchars{§§},
979   \textormathchars{§§§},
980   \textormathchars{},
981   \textormathchars{∗∗},
982   \textormathchars{∗∗∗}]
983
984%D Iteration of suggestion by WS on mailinglist 2010.12.22:
985%D
986%D \starttyping
987%D \setupfloatsplitting[conversion=continued]
988%D \stoptyping
989
990\permanent\protected\def\continuednumber#1%
991  {\labeltext{\ifcase#1\or\else\v!continued\fi}}
992
993\defineconversion
994  [\v!continued]
995  [\continuednumber]
996
997%D Taken from x-asciimath (see digits-001.tex for an example):
998
999\mutable\lettonothing\spaceddigitsmethod    % alternative methods   : 1 default, 2 and 3 only when > 4
1000\mutable\lettonothing\spaceddigitssymbol    % extra splitter symbol : {,}
1001\mutable\lettonothing\spaceddigitsseparator % separator symbol      : {\tocharacter{"2008}}
1002
1003\permanent\protected\def\spaceddigits#1%
1004  {\clf_spaceddigits
1005      method    {\spaceddigitsmethod}%
1006      symbol    {\spaceddigitssymbol}%
1007      separator {\spaceddigitsseparator}%
1008      data      {#1}%
1009   \relax}
1010
1011%D For those who sart counting at zero:
1012%D
1013%D \starttyping
1014%D \defineconversionset [zero] [n,zero] [n]
1015%D
1016%D \setuphead [sectionconversionset=zero]
1017%D
1018%D \starttext
1019%D     \startchapter [title=Introduction]
1020%D         \startsection [title=First topic]  \stopsection
1021%D         \startsection [title=Second topic] \stopsection
1022%D     \stopchapter
1023%D \stoptext
1024%D \stoptyping
1025
1026\permanent\def\zeronumberconversion#1{\tointeger{#1-\plusone}}
1027
1028\defineconversion [zero] [\zeronumberconversion]
1029
1030\protect \endinput
1031