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
cannot be grabbed and they make the analyzer abort its analysis. There is no way that we can solve this in traditional TEX and in ConTEXt MkII. So how about LuaTEX and ConTEXt MkIV? The macro used in the \framed commands is: \doreshapeframedbox{do something with \box\framebox} In LuaTEX we can manipulate box content at the Lua level. Instead of providing a truckload of extra primitives (which would also introduce new data types at the TEX end) we just delegate the job to Lua. \def\doreshapeframedbox {\ctxlua{commands.doreshapeframedbox(\number\framebox)}} Here \ctxlua is our reserved instance and commands provides the namespace for commands that we delegate to Lua (so, there are more of them). The amount of Lua code is way less than the TEX code which we will not show here; it's in supp-box.tex if you really want to see it. function commands.doreshapeframedbox(n) if tex.wd[n] ~= 0 then local hpack = node.hpack local free = node.free local copy = node.copy_list local noflines, lastlinelength, width = 0, 0, 0 local list = tex.box[n].list local done = false for h in node.traverse_id('hlist',list) do done = true local p = hpack(copy(h.list)) lastlinelength = p.width if lastlinelength > width then width = lastlinelength end free(p) end if done then if width ~= 0 then for h in node.traverse_id('hlist',list) do if h.width ~= width then h.list = hpack(h.list,width,'exactly') h.width = width end end 230 It works!
end end end tex.wd[n] = width end -- we can also do something with lastlinelength In the rst loop we inspect all lines (nodes with type hlist) and repack them to their natural width with node.hpack. In the process we keep track of the maximum natural width. In the second loop we repack the content again, but this time permanently. Now we use the maximum encountered width which is forced by the keyword exactly. Because all glue is still present we automatically get the desired alignment. We create local shortcuts to some node functions which makes it run faster; keep in mind that this is a core function called many times in a regular ConTEXt job. In ConTEXt MkIV you will nd quite some Lua code and often it looks rather complex, especially if you have no clue why it's needed. Think of OpenType font handling which involves locating fonts, loading and caching them, storing features and later on applying them to node lists, etc. However, once we are beyond the stage of developing all the code that is needed to support the basics, we will start doing the things that more relate to the typesetting process itself, like the previous code. One of the candidates for a similar Lua based solution is for instance column balancing. From the previous example code you can deduce that manipulating the node lists from Lua can make that easier. Of course we're a few more years down the road then. It works! 231
- 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 206 and 207: eason why such code normally is not
- 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 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.
- Page 256 and 257: features: analyze=yes, calt=yes, cc
- Page 258 and 259: feature mark, lookup ml_arab_l_16_s
- Page 260 and 261: للِ ه ِ feature init, lo
- Page 262 and 263: features: analyze=yes, calt=yes, cc
- Page 264 and 265: esult: 1: [+TRT] U+6DD: [-TRT]
- Page 266 and 267: 2: [+TRT] U+F01DD: [-TRT] The
- Page 268 and 269: Pro. Dr. Donld E. Knuth feature cal
- Page 270 and 271: 268 Tracking
- Page 272 and 273: The order in which this happens now
- Page 274 and 275: normalizers characters words fonts
- Page 276 and 277: local function hyphenation(head,tai
- Page 278 and 279: 276 The order of things
- Page 280 and 281: of LuaTEX Taco and I worked in para
cannot be grabbed and they make the analyzer abort its analysis. <strong>The</strong>re is no way that we<br />
can solve this in traditional TEX and in ConTEXt MkII.<br />
So how about LuaTEX and ConTEXt MkIV? <strong>The</strong> macro used in the \framed commands is:<br />
\doreshapeframedbox{do something with \box\framebox}<br />
In LuaTEX we can manipulate box content at the Lua level. Instead <strong>of</strong> providing a truckload<br />
<strong>of</strong> extra primitives (which would also introduce new data types at the TEX end) we just<br />
delegate the job to Lua.<br />
\def\doreshapeframedbox<br />
{\ctxlua{commands.doreshapeframedbox(\number\framebox)}}<br />
Here \ctxlua is our reserved instance and commands provides the namespace for commands<br />
that we delegate to Lua (so, there are more <strong>of</strong> them). <strong>The</strong> amount <strong>of</strong> Lua code is<br />
way less than the TEX code which we will not show here; it's in supp-box.tex if you really<br />
want to see it.<br />
function commands.doreshapeframedbox(n)<br />
if tex.wd[n] ~= 0 then<br />
local hpack = node.hpack<br />
local free = node.free<br />
local copy = node.copy_list<br />
local n<strong>of</strong>lines, lastlinelength, width = 0, 0, 0<br />
local list = tex.box[n].list<br />
local done = false<br />
for h in node.traverse_id('hlist',list) do<br />
done = true<br />
local p = hpack(copy(h.list))<br />
lastlinelength = p.width<br />
if lastlinelength > width then<br />
width = lastlinelength<br />
end<br />
free(p)<br />
end<br />
if done then<br />
if width ~= 0 then<br />
for h in node.traverse_id('hlist',list) do<br />
if h.width ~= width then<br />
h.list = hpack(h.list,width,'exactly')<br />
h.width = width<br />
end<br />
end<br />
230 It works!