The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE
The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE
eason why such code normally is not written by end users, but by macropackage writers: they need to provide the frameworks where you can plug in code. In ConTEXt we have several such mechanisms and therefore in MkIV this function looks (slightly stripped) as follows: function cases.process(namespace,attribute,head) local done, actions = false, cases.actions for start in node.traverse_id(glyph,head) do local attr = has_attribute(start,attribute) if attr and attr > 0 then unset_attribute(start,attribute) local action = actions[attr] if action then local _, ok = action(start) done = done and ok end end end return head, done end Here we check attributes (these are set at the TEX end) and we have all kind of actions that can be applied, depending on the value of the attribute. Here the function that does the actual uppercasing is dened somewhere else. The cases table provides us a namespace; such namespaces needs to be coordinated by macro package writers. This approach means that the macro code looks completely different; in pseudo code we get: \def\Words#1{{#1}} Or alternatively: \def\StartWords{\begingroup} \def\StopWords {\endgroup} Because starting a paragraph with a group can have unwanted side effects (like \everypar being expanded inside a group) a variant is: \def\StartWords{} \def\StopWords {} So, what happens here is that the users sets an attribute using some high level command, and at some point during the transformation of the input into node lists, some action takes place. At that point commands, expansion and whatever no longer can interfere. 204 The luaTEX Mix
In addition to some infrastructure, macro packages need to carry some knowledge, just as with the \uccode used in \uppercase. The upper function in the rst example looks as follows: local function upper(start) local data, char = characters.data, start.char if data[char] then local uc = data[char].uccode if uc and fonts.ids[start.font].characters[uc] then start.char = uc return true end end return false end Such code is really macro package dependent: LuaTEX only provides the means, not the solutions. In ConTEXt we have collected information about characters in a data table in the characters namespace. There we have stored the uppercase codes (uccode). The, again ConTEXt specic, fonts table keeps track of all dened fonts and before we change the case, we make sure that this character is present in the font. Here id is the number by which LuaTEX keeps track of the used fonts. Each glyph node carries such a reference. In this example, eventually we end up with more code than in TEX, but the solution is much more robust. Just imagine what would happen when in the TEX solution we would have: \Words{\framed[offset=3pt]{hello world}} It simply does not work. On the other hand, the Lua code never sees TEX commands, it only sees the two words represented by glyphs nodes and separated by glue. Of course, there is a danger when we start opening TEX's core features. Currently macro packages know what to expect, they know what TEX can and cannot do. Of course macro writers have exploited every corner of TEX, even the dark ones. Where dirty tricks in the TEXbook had an educational purpose, those of users sometimes have obscene traits. If we just stick to the trickery introduced for parsing input, converting this into that, doing some calculations, and alike, it will be clear that Lua is more than welcome. It may hurt to throw away thousands of lines of impressive code and replace it by a few lines of Lua but that's the price the user pays for abusing TEX. Eventually ConTEXt MkIV will be a decent mix of Lua and TEX code, and hopefully the solutions programmed in those languages are as clean as possible. The luaTEX Mix 205
- Page 156 and 157: dyn_used min:478158, max:554800, pa
- Page 158 and 159: str_ptr min:2131299, max:2136226, p
- Page 160 and 161: if_stack min:0, max:13, pages:326 k
- Page 162 and 163: pdf_refximage min:0, max:7, pages:3
- Page 164 and 165: 162 Collecting garbage
- Page 166 and 167: \definefontfeature[coward] [kern=ye
- Page 168 and 169: We do our tests of a variant of Con
- Page 170 and 171: --make or --ini --run or --fmt= --l
- Page 172 and 173: mtxrun --script font --list --patte
- Page 174 and 175: Opening up TEX started with rewriti
- Page 176 and 177: One can question if a properly work
- Page 178 and 179: ound to fonts (instead of being com
- Page 180 and 181: • TEX primitives Access to and co
- Page 182 and 183: • Open an instance using mplib.ne
- Page 184 and 185: is dened in the les whose names sta
- Page 186 and 187: }, }, ["pen"]={ { ["left_x"]=2.4548
- Page 188 and 189: local tx, ty = p.x_coord, p.y_coord
- Page 190 and 191: \startreusableMPgraphic{test} fill
- Page 192 and 193: vardef textext(expr str) = image (
- Page 194 and 195: local factor = 65536*(7200/7227) fu
- Page 196 and 197: end return t This is a typical exam
- Page 198 and 199: The user interface is downward comp
- Page 200 and 201: key concept. There are few accessib
- Page 202 and 203: \directlua 0 { for i=1,10 do tex.pr
- Page 204 and 205: } end And still it's not okay, sinc
- Page 208 and 209: Of course we can discuss until eter
- Page 210 and 211: some text some more When using Co
- Page 212 and 213: and the document itself is processe
- Page 214 and 215: setups and functions are assigned n
- Page 216: using some kind of api and history
- Page 226 and 227: In LuaTEX with ConTEXt MkIV support
- Page 228 and 229: • Designers (or programmers) may
- Page 230 and 231: 228 OpenType: too open?
- Page 232 and 233: cannot be grabbed and they make the
- Page 234 and 235: 232 It works!
- Page 236 and 237: when writing the result to le, TEX
- Page 238 and 239: 236 Virtual Reality
- Page 240 and 241: \start \textdir TLT one \bidilro tw
- Page 242 and 243: 240 Getting lost
- Page 244 and 245: using a few arabic fonts, some chin
- Page 246 and 247: The core data structure that we nee
- Page 248 and 249: table can contain information about
- Page 250 and 251: The ConTEXt cross reference mechani
- Page 252 and 253: of them. Each lookup has a detailed
- Page 254 and 255: otf.replacements otf.sequences otf.
eason why such code normally is not written by end users, but by macropackage writers:<br />
they need to provide the frameworks where you can plug in code. In ConTEXt we have<br />
several such mechanisms and therefore in MkIV this function looks (slightly stripped) as<br />
follows:<br />
function cases.process(namespace,attribute,head)<br />
local done, actions = false, cases.actions<br />
for start in node.traverse_id(glyph,head) do<br />
local attr = has_attribute(start,attribute)<br />
if attr and attr > 0 then<br />
unset_attribute(start,attribute)<br />
local action = actions[attr]<br />
if action then<br />
local _, ok = action(start)<br />
done = done and ok<br />
end<br />
end<br />
end<br />
return head, done<br />
end<br />
Here we check attributes (these are set at the TEX end) and we have all kind <strong>of</strong> actions<br />
that can be applied, depending on the value <strong>of</strong> the attribute. Here the function that does<br />
the actual uppercasing is dened somewhere else. <strong>The</strong> cases table provides us a namespace;<br />
such namespaces needs to be coordinated by macro package writers.<br />
This approach means that the macro code looks completely different; in pseudo code<br />
we get:<br />
\def\Words#1{{#1}}<br />
Or alternatively:<br />
\def\StartWords{\begingroup}<br />
\def\StopWords {\endgroup}<br />
Because starting a paragraph with a group can have unwanted side effects (like \everypar<br />
being expanded inside a group) a variant is:<br />
\def\StartWords{}<br />
\def\StopWords {}<br />
So, what happens here is that the users sets an attribute using some high level command,<br />
and at some point during the transformation <strong>of</strong> the input into node lists, some action<br />
takes place. At that point commands, expansion and whatever no longer can interfere.<br />
204 <strong>The</strong> <strong>luaTEX</strong> Mix