about-expanding.tex /size: 4370 b    last modification: 2023-12-21 09:43
1% engine=luatex macros=mkvi language=us
2
3\startcomponent about-exploring
4
5\environment about-environemnt
6
7\startchapter[title=Still Expanding]
8
9In the beginning of October 2013 Luigi figured out that \LUAJITTEX\ could
10actually deal with \UTF\ identifiers. After we played a bit with this, a patch
11was made for stock \LUATEX\ to provide the same. In the process I found out that
12I needed to adapt the \SCITE\ lexer a bit and that some more characters had to
13get catcode~11 (letter). In the following text screendumps from the editor will
14be used instead of verbatim code. This also demonstrates how \SCITE\ deals with
15syntax highlighting.
16
17\starttexdefinition ShowExample #1
18    \startbaselinecorrection
19        \externalfigure[still-expanding-#1][scale=500]
20    \stopbaselinecorrection
21    \getbuffer
22\stoptexdefinition
23
24First we define a proper font for to deal with \CJK\ characters and a helper
25macro that wraps an example using that font.
26
27\startbuffer
28\definefont
29  [GoodForJapanese]
30  [heiseiminstd-w3]
31  [script=kana,
32   language=jan]
33
34\definestartstop
35  [example]
36  [style=GoodForJapanese]
37\stopbuffer
38
39\ShowExample{1}
40
41According to the Google translator, \example {例題} means example and \example
42{} means number. It doesn't matter much as we only use these characters as
43demo. Of course one can wonder if it makes sense to define functions, variables
44and keys in a script other than basic Latin, but at least it looks kind of
45modern.
46
47\startbuffer
48\startluacode
49    local function 例題(str)
50        context.formatted.example("例題 1.%s: 数 %s",str,str)
51        context.par()
52    end
53
54    for i=1,3 do
55        例題(i)
56    end
57\stopluacode
58\stopbuffer
59
60We only show the first three lines. Because using the formatter gives nicer
61source code we operate in that subnamespace.
62
63\ShowExample{2}
64
65As \CONTEXT\ is already \UTF\ aware for a while you can define macros with such
66characters. It was a sort of coincidence that this specific range of characters
67had not yet gotten the proper catcodes, but that is something users don't need to
68worry about. If your script doesn't work, we just need to initialize a few more
69characters.
70
71\startbuffer
72\def\例題#1{\example{例題 2:  #1}\par}
73
74\例題{2.1}
75\stopbuffer
76
77\ShowExample{3}
78
79Of course this command is now also present at the \LUA\ end:
80
81\startbuffer
82\startluacode
83    context.startexample()
84    context.例題(2.2)
85    context.stopexample()
86\stopluacode
87\stopbuffer
88
89\ShowExample{4}
90
91The \type {MKVI} parser has also been adapted to this phenomena as have the
92alternative ways of defining macros. We could already do this:
93
94\startbuffer
95\starttexdefinition test #1
96    \startexample
97        例題 3:  #1 \par
98    \stopexample
99\stoptexdefinition
100
101\test{3}
102\stopbuffer
103
104\ShowExample{5}
105
106But now we can also do this:
107
108\startbuffer
109\starttexdefinition 例題 #1
110    \startexample
111        例題 4:  #1 \par
112    \stopexample
113\stoptexdefinition
114
115\例題{4}
116\stopbuffer
117
118\ShowExample{6}
119
120Named parameters support a wider range of characters too:
121
122\startbuffer
123\def\例題#{\example{例題 5:  #}\par}
124
125\例題{5}
126\stopbuffer
127
128\ShowExample{7}
129
130So, in the end we can have definitions like this:
131
132\startbuffer
133\starttexdefinition 例題 #
134    \startexample
135        例題 6:  # \par
136    \stopexample
137\stoptexdefinition
138
139\例題{6}
140\stopbuffer
141
142\ShowExample{8}
143
144Of course the optional (first) arguments still are supported but these stay
145Latin.
146
147\startbuffer
148\starttexdefinition unexpanded 例題 #
149    \startexample
150        例題 7:  # \par
151    \stopexample
152\stoptexdefinition
153
154\例題{7}
155\stopbuffer
156
157\ShowExample{9}
158
159Finally Luigi wondered of we could use math symbols too and of course there is no
160reason why not:
161
162\startbuffer
163\startluacode
164    function commands.(...)
165        local t = { ... }
166        local s = 0
167        for i=1,#t do
168            s = s + t[i]
169        end
170        context("% + t = %s",t,s)
171    end
172\stopluacode
173
174\ctxcommand{(1,3,5,7,9)}
175\stopbuffer
176
177\ShowExample{10}
178
179The \CONTEXT\ source code will of course stay \ASCII, although some of the multi
180lingual user interfaces already use characters other than that, for instance
181accented characters or completely different scripts (like Persian). We just went
182a step further and supported it at the \LUA\ end which in turn introduced those
183characters into \MKVI.
184
185\stopchapter
186
187\stopcomponent
188
189