languages-numbering.tex /size: 11 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\startcomponent languages-numbering
4
5\environment languages-environment
6
7\startchapter[title=Numbering][color=darkgreen]
8
9\startsection[title=Introduction]
10
11Numbering is complex and in \CONTEXT\ it's not easy either. This is because we
12not only have 1, 2, 3 \unknown\ but also sub numbers like 1a, 1b, 1ic \unknown\
13or 1.a, 1.b, 1.c \unknown\ There can be many levels, different separators, final
14symbols. As we're talking languages we only discuss conversion here: the
15mechanism that turns a number in for instance a letter. It happens that the
16mapping from a number onto a letter is language dependent. The next lines show
17how English, Spanish and Slovenian numbers:
18
19\blank
20\startpacked
21\startcolor[maincolor]
22\dontleavehmode
23    {\ttbf\mainlanguage[en]\dorecurse{28}
24        {\hbox to 1.5em{\convertnumber{alphabetic}{#1}\hss}}}\par
25\dontleavehmode
26    {\ttbf\mainlanguage[es]\dorecurse{28}
27        {\hbox to 1.5em{\convertnumber{alphabetic}{#1}\hss}}}\par
28\dontleavehmode
29    {\ttbf\mainlanguage[sl]\dorecurse{28}
30        {\hbox to 1.5em{\convertnumber{alphabetic}{#1}\hss}}}\par
31\stopcolor
32\stoppacked
33\blank
34
35You convert a number into a letter with:
36
37\starttyping
38\convertnumber{alphabetic}{15}
39\stoptyping
40
41There is also \type {\uconvertnumber} which does not expand unless typesetting
42is going on. Normally you don't need to bother about this.
43
44The \type {alphabetic} converter adapts to the current main language. When a
45language has no special alphabet, the regular 26 characters are used.
46
47A converter can also convert to a roman numeral, a language specific ordered
48list, a day or month, an ordinal string and again there can be a language
49specific conversion. The general conversion macro takes a conversion name and
50a number. When a conversion can be set (for instance in an itemized list, or in
51section numbering) you can use these names. You can define additional
52converters if needed, as long as the converter can handle a number.
53
54\starttyping
55\defineconversion [alphabetic] [\alphabeticnumerals]
56\stoptyping
57
58Here \type {\alphabeticnumerals} is a converter. If you look into the source of
59\CONTEXT\ you will see that many converters are calling out to \LUA, where we
60have implemented those specific conversions. The following table has long and
61short names. The short one are historic.
62
63\starttabulate
64\FL
65\NC month                          \NC \type {\monthlong}                 \NC \NR
66\NC month:mnem                     \NC \type {\monthshort}                \NC \NR
67\ML
68\NC character                      \NC \type {\character}                 \NC \NR
69\NC Character                      \NC \type {\Character}                 \NC \NR
70\NC characters                     \NC \type {\characters}                \NC \NR
71\NC Characters                     \NC \type {\Characters}                \NC \NR
72\ML
73\NC AK                             \NC \type {\smallcappedcharacters}     \NC \NR
74\NC KA                             \NC \type {\smallcappedcharacters}     \NC \NR
75\ML
76\NC alphabetic a                   \NC \type {\alphabeticnumerals}        \NC \NR
77\NC Alphabetic A                   \NC \type {\Alphabeticnumerals}        \NC \NR
78\ML
79\NC number numbers n               \NC \type {\numbers}                   \NC \NR
80\NC Numbers N                      \NC \type {\Numbers}                   \NC \NR
81\NC mediaeval m                    \NC \type {\mediaeval}                 \NC \NR
82\ML
83\NC word words                     \NC \type {\verbosenumber}             \NC \NR
84\NC Word Words                     \NC \type {\VerboseNumber}             \NC \NR
85\ML
86\NC ordinal                        \NC \type {\ordinalnumber}             \NC \NR
87\NC Ordinal                        \NC \type {\Ordinalnumber}             \NC \NR
88\ML
89\NC romannumerals i r              \NC \type {\romannumerals}             \NC \NR
90\NC Romannumerals I R              \NC \type {\Romannumerals}             \NC \NR
91\ML
92\NC o                              \NC \type {\oldstylenumerals}          \NC \NR
93\NC O                              \NC \type {\oldstylenumerals}          \NC \NR
94\NC or                             \NC \type {\oldstyleromannumerals}     \NC \NR
95\ML
96\NC KR                             \NC \type {\smallcappedromannumerals}  \NC \NR
97\NC RK                             \NC \type {\smallcappedromannumerals}  \NC \NR
98\ML
99\NC greek g                        \NC \type {\greeknumerals}             \NC \NR
100\NC Greek G                        \NC \type {\Greeknumerals}             \NC \NR
101\NC mathgreek                      \NC \type {\mathgreek}                 \NC \NR
102\ML
103\NC abjadnumerals                  \NC \type {\abjadnumerals}             \NC \NR
104\NC abjadnodotnumerals             \NC \type {\abjadnodotnumerals}        \NC \NR
105\NC abjadnaivenumerals             \NC \type {\abjadnaivenumerals}        \NC \NR
106\ML
107\NC thainumerals                   \NC \type {\thainumerals}              \NC \NR
108\NC devanagarinumerals             \NC \type {\devanagarinumerals}        \NC \NR
109\NC gurmurkhinumerals              \NC \type {\gurmurkhinumerals}         \NC \NR
110\NC gujaratinumerals               \NC \type {\gujaratinumerals}          \NC \NR
111\NC tibetannumerals                \NC \type {\tibetannumerals}           \NC \NR
112\NC greeknumerals                  \NC \type {\greeknumerals}             \NC \NR
113\NC Greeknumerals                  \NC \type {\Greeknumerals}             \NC \NR
114\NC arabicnumerals                 \NC \type {\arabicnumerals}            \NC \NR
115\NC persiannumerals                \NC \type {\persiannumerals}           \NC \NR
116\NC arabicexnumerals               \NC \type {\arabicexnumerals}          \NC \NR
117\NC arabicdecimals                 \NC \type {\arabicdecimals}            \NC \NR
118\NC persiandecimals                \NC \type {\persiandecimals}           \NC \NR
119\ML
120\NC koreannumerals kr              \NC \type {\koreannumerals}            \NC \NR
121\NC koreanparenthesisnumerals kr-p \NC \type {\koreanparenthesisnumerals} \NC \NR
122\NC koreancirclenumerals kr-c      \NC \type {\koreancirclenumerals}      \NC \NR
123\ML
124\NC chinesenumerals cn             \NC \type {\chinesenumerals}           \NC \NR
125\NC chinesecapnumerals cn-c        \NC \type {\chinesecapnumerals}        \NC \NR
126\NC chineseallnumerals cn-a        \NC \type {\chineseallnumerals}        \NC \NR
127\ML
128\NC sloveniannumerals              \NC \type {\sloveniannumerals}         \NC \NR
129\NC slovenianNumerals              \NC \type {\slovenianNumerals}         \NC \NR
130\ML
131\NC spanishnumerals                \NC \type {\spanishnumerals}           \NC \NR
132\NC spanishNumerals                \NC \type {\spanishNumerals}           \NC \NR
133\LR
134\stoptabulate
135
136The \type {alphabetic} and \type {Alphabetic} converters adapt to slovenian and
137spanish as do their small capped alternatives. There are more general helpers for it
138too:
139
140\starttyping
141\languagecharacters{number}
142\languageCharacters{number}
143\stoptyping
144
145Also language related is the \type {\continuednumber} macro. Here we see an
146application:
147
148\startbuffer
1491 \continuednumber{1}
1501, 2 \continuednumber{2}
1511, 2, 3 \continuednumber{3}
152\stopbuffer
153
154\typebuffer
155
156What renders as:
157
158\startlines[color=maincolor]
159\getbuffer
160\stoplines
161
162Such a macro is typically used in combination with counters ant it just typesets
163a label text depending on the valu ebeing non|-|zero.
164
165\startbuffer
166\setuplabeltext[en][continued={and so on}]
1671, 2, 3 \continuednumber{3}
1681, 2, 3 \convertnumber{continued}{3}
169\stopbuffer
170
171\typebuffer
172
173This gives:
174
175\startlines[color=maincolor]
176\getbuffer
177\stoplines
178
179In the rare case that you want to check if a conversion is defined you can use
180
181\starttyping
182\doifelseconversiondefined{name}{true}{false}
183\stoptyping
184
185So,
186
187\startbuffer
188\doifelseconversiondefined{characters}{we can convert}{forget about it}
189\stopbuffer
190
191\typebuffer
192
193Gives:
194
195\startlines[color=maincolor]
196\getbuffer
197\stoplines
198
199There are also some non language related converters that we mention here for
200completeness:
201
202\blank
203\type {set 0}: \startcolor[maincolor]\dorecurse{20}{\convertnumber{set 0}{#1} }\stopcolor\par
204\type {set 1}: \startcolor[maincolor]\dorecurse{20}{\convertnumber{set 1}{#1} }\stopcolor\par
205\type {set 2}: \startcolor[maincolor]\dorecurse{20}{\convertnumber{set 2}{#1} }\stopcolor\par
206\type {set 3}: \startcolor[maincolor]\dorecurse{20}{\convertnumber{set 3}{#1} }\stopcolor\par
207\blank
208
209When a set overruns we start again at the first element.
210
211The ordinal converter produces output like \color [maincolor] {\convertnumber
212{ordinal}{123}} and \color [maincolor] {\convertnumber {ordinal}{654}}. The
213corresponding string renderer is \type {\highordinalstr}.
214
215% quite limited currently op not documented here:
216%
217% \wordtonumber{two}{3}
218% \wordtonumber{fivethousand}{unknown}
219
220\stopsection
221
222\startsection[title=Dates]
223
224Dates are also language dependent. The following macros take a number and return
225the name of the month or day.
226
227\starttabulate
228\NC \type {\monthlong } \NC \monthlong {10} \NC \NR
229\NC \type {\monthshort} \NC \monthshort{10} \NC \NR
230\NC \type {\MONTH     } \NC \MONTH     {10} \NC \NR
231\NC \type {\MONTHLONG } \NC \MONTHLONG {10} \NC \NR
232\NC \type {\MONTHSHORT} \NC \MONTHSHORT{10} \NC \NR
233\NC \type {\weekday   } \NC \weekday   {5}  \NC \NR
234\NC \type {\WEEKDAY   } \NC \WEEKDAY   {5}  \NC \NR
235\stoptabulate
236
237The current date can be typeset with \type {\currentdate} and a
238specific date with \type {\date}, for instance:
239
240\startbuffer
241\currentdate[weekday,day,month,year]
242\currentdate[WEEKDAY,day,MONTH,year]
243\date[d=12,m=12,y=1998][weekday]
244\date[d=12,m=12,y=1998]
245\stopbuffer
246
247\typebuffer
248
249\startlines[color=maincolor]
250\getbuffer
251\stoplines
252
253Possible elements of the specification are:
254
255\starttabulate
256\FL
257\NC + ord      \NC ordinal suffix \NC \NR
258\NC ++ highord \NC high ordinal suffix \NC \NR
259\ML
260\NC mnem:      \NC mnemonic prefix \NC \NR
261\ML
262\NC Y y year   \NC year 4 digits \NC \NR
263\NC yy         \NC year 2 digits \NC \NR
264\ML
265\NC M          \NC month 1 or 2 digits \NC \NR
266\NC mm         \NC month 2 digits \NC \NR
267\ML
268\NC D          \NC day 1 or 2 digits \NC \NR
269\NC dd         \NC day 2 digits \NC \NR
270\ML
271\NC W          \NC 1 digit \NC \NR
272\ML
273\NC month m    \NC language dependent (can be mnemonic) \NC \NR
274\NC day d      \NC language dependent \NC \NR
275\NC weekday w  \NC language dependent \NC \NR
276\ML
277\NC MONTH      \NC month uppercased \NC \NR
278\NC WEEKDAY    \NC weekday uppercased \NC \NR
279\ML
280\NC referral   \NC YYYMMDD \NC \NR
281\ML
282\NC space \\   \NC space \NC \NR
283\NC <word>     \NC word \NC \NR
284\LL
285\stoptabulate
286
287There are also some converters built in (more can be added), for instance:
288
289\startbuffer
290The current {\em gregorian} date \currentdate [month, day, {, }, year] is
291in {\em jalali} \currentdate [jalali:to, month, day, {, }, year] but we
292can also as a specific one, so {\em jalali} \date [y=1395, m=4, d=18]
293[month, day, {, }, year] is {\em gregorian} \date [y=1395, m=4, d=18]
294[jalali:from, month, day, {, }, year].
295\stopbuffer
296
297\typebuffer \startnarrower \getbuffer \stopnarrower
298
299For time we have \type {\currenttime} and here the specification is just an \type
300{h}, \type {m} and whatever connects them. Both date and time are
301pre|-|configured in the language definition file \type {lang-def}.
302
303\stopsection
304
305% \startsection[title=Counters]
306%
307% \stopsection
308
309\stopchapter
310
311\stopcomponent
312