Re: [NTG-context] how to simulate \hss in luametatex?
Hans, thank you. By your and Max's answers, I understand that there must be box.glueset for the glues in the box.list to actually work. Best regards Huang Fusyong(黄复雄) Hans Hagen via ntg-context 于2022年11月11日周五 18:52写道: > > On 11/11/2022 10:53 AM, Max Chernoff via ntg-context wrote: > > Hi, > > > >> I want to simulate \hss in lua end in ConTeXt/luametatex environment. > >> For example, > >> > >> ```ConTeXt > >> a{\raise 1.5ex\hbox to 0pt{\hss b}}c > >> ``` > > > >> And in lua, I do as follows(part of my app seen in attachment): > > > > Your code doesn't compile as is. I think that this is the same thing > > though: > > > > \starttext > > \startluacode > > local a = node.new"glyph" > > a.char = string.byte("a") > > a.font = font.current() > > > > local b = node.new"glyph" > > b.char = string.byte("b") > > b.font = font.current() > > > > local c = node.new"glyph" > > c.char = string.byte("c") > > c.font = font.current() > > > > local hss = node.new("glue") > > hss.stretch = 65536 > > hss.stretchorder = 2 > > hss.shrink = 65536 > > hss.shrinkorder = 2 > > hss.width = 0 > > b = node.insertbefore(b, b, hss) > > > > local box = node.new("hlist", "box") > > box.head = b > > box.width = 0 > > box.shift = -tex.sp("1ex") > > > > tex.forcehmode() > > node.write(a + box + c) > > \stopluacode > > \stoptext > > > >> And got 'b' on top of 'c' in pdf as follows: > >> > >> ```pdf > >>b > >> ac > >> ``` > > > > The \hss isn't the problem here. The problem is actually with the box. > > When you manually make the \hbox like that, I think (although I could be > > wrong) that you're bypassing all of TeX's glue calculations. You should > > probably use "node.hpack" instead: > > > > \starttext > > \startluacode > > local a = node.new"glyph" > > a.char = string.byte("a") > > a.font = font.current() > > > > local b = node.new"glyph" > > b.char = string.byte("b") > > b.font = font.current() > > > > local c = node.new"glyph" > > c.char = string.byte("c") > > c.font = font.current() > > > > local hss = node.new("glue") > > hss.stretch = 65536 > > hss.stretchorder = 2 > > hss.shrink = 65536 > > hss.shrinkorder = 2 > > hss.width = 0 > > > > local box = node.hpack(hss + b, "exactly", 0) > > box.shift = -tex.sp("1ex") > > > > tex.forcehmode() > > a.next = box > > box.next = c > > node.write(a) > > \stopluacode > > \stoptext > indeed, an dafter that you can check it > > box.glueorder : 2 > box.glueset: 6.6683349609375 > box.gluesign : 2 > > which will be applied (in the backend) to glues > > Hans > > - >Hans Hagen | PRAGMA ADE >Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > - > > ___ > If your question is of interest to others as well, please add an entry to the > Wiki! > > maillist : ntg-context@ntg.nl / > https://www.ntg.nl/mailman/listinfo/ntg-context > webpage : https://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : https://contextgarden.net > ___ ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] how to simulate \hss in luametatex?
Dear Max, I am very grateful that you took the time to tweak and test my non-running code snippet and found the problem. > local box = node.hpack(hss + b, "exactly", 0) You are absolutely right, the cause of the problem was that I wasn't using node.hpack(). Actually, I tried to use it, but used it wrong, as follows: local box, _ = node_hpack(list) box.width = 0 box.shift = -tex_sp("1ex") My app works fine now. Also, I learned a lot from your code, like font.current(), hss + b and tex.forcehmode() - I immediately used the last one to set box.shift, making it relative. Best regards Huang Fusyong(黄复雄) Max Chernoff via ntg-context 于2022年11月11日周五 17:55写道: > > Hi, > > > I want to simulate \hss in lua end in ConTeXt/luametatex environment. > > For example, > > > > ```ConTeXt > > a{\raise 1.5ex\hbox to 0pt{\hss b}}c > > ``` > > > And in lua, I do as follows(part of my app seen in attachment): > > Your code doesn't compile as is. I think that this is the same thing > though: > >\starttext >\startluacode >local a = node.new"glyph" >a.char = string.byte("a") >a.font = font.current() > >local b = node.new"glyph" >b.char = string.byte("b") >b.font = font.current() > >local c = node.new"glyph" >c.char = string.byte("c") >c.font = font.current() > >local hss = node.new("glue") >hss.stretch = 65536 >hss.stretchorder = 2 >hss.shrink = 65536 >hss.shrinkorder = 2 >hss.width = 0 >b = node.insertbefore(b, b, hss) > >local box = node.new("hlist", "box") >box.head = b >box.width = 0 >box.shift = -tex.sp("1ex") > >tex.forcehmode() >node.write(a + box + c) >\stopluacode >\stoptext > > > And got 'b' on top of 'c' in pdf as follows: > > > > ```pdf > > b > > ac > > ``` > > The \hss isn't the problem here. The problem is actually with the box. > When you manually make the \hbox like that, I think (although I could be > wrong) that you're bypassing all of TeX's glue calculations. You should > probably use "node.hpack" instead: > >\starttext >\startluacode >local a = node.new"glyph" >a.char = string.byte("a") >a.font = font.current() > >local b = node.new"glyph" >b.char = string.byte("b") >b.font = font.current() > >local c = node.new"glyph" >c.char = string.byte("c") >c.font = font.current() > >local hss = node.new("glue") >hss.stretch = 65536 >hss.stretchorder = 2 >hss.shrink = 65536 >hss.shrinkorder = 2 >hss.width = 0 > >local box = node.hpack(hss + b, "exactly", 0) >box.shift = -tex.sp("1ex") > >tex.forcehmode() >a.next = box >box.next = c >node.write(a) >\stopluacode >\stoptext > > -- Max > > ___ > If your question is of interest to others as well, please add an entry to the > Wiki! > > maillist : ntg-context@ntg.nl / > https://www.ntg.nl/mailman/listinfo/ntg-context > webpage : https://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : https://contextgarden.net > ___ ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] how to simulate \hss in luametatex?
On 11/11/2022 10:53 AM, Max Chernoff via ntg-context wrote: Hi, I want to simulate \hss in lua end in ConTeXt/luametatex environment. For example, ```ConTeXt a{\raise 1.5ex\hbox to 0pt{\hss b}}c ``` And in lua, I do as follows(part of my app seen in attachment): Your code doesn't compile as is. I think that this is the same thing though: \starttext \startluacode local a = node.new"glyph" a.char = string.byte("a") a.font = font.current() local b = node.new"glyph" b.char = string.byte("b") b.font = font.current() local c = node.new"glyph" c.char = string.byte("c") c.font = font.current() local hss = node.new("glue") hss.stretch = 65536 hss.stretchorder = 2 hss.shrink = 65536 hss.shrinkorder = 2 hss.width = 0 b = node.insertbefore(b, b, hss) local box = node.new("hlist", "box") box.head = b box.width = 0 box.shift = -tex.sp("1ex") tex.forcehmode() node.write(a + box + c) \stopluacode \stoptext And got 'b' on top of 'c' in pdf as follows: ```pdf b ac ``` The \hss isn't the problem here. The problem is actually with the box. When you manually make the \hbox like that, I think (although I could be wrong) that you're bypassing all of TeX's glue calculations. You should probably use "node.hpack" instead: \starttext \startluacode local a = node.new"glyph" a.char = string.byte("a") a.font = font.current() local b = node.new"glyph" b.char = string.byte("b") b.font = font.current() local c = node.new"glyph" c.char = string.byte("c") c.font = font.current() local hss = node.new("glue") hss.stretch = 65536 hss.stretchorder = 2 hss.shrink = 65536 hss.shrinkorder = 2 hss.width = 0 local box = node.hpack(hss + b, "exactly", 0) box.shift = -tex.sp("1ex") tex.forcehmode() a.next = box box.next = c node.write(a) \stopluacode \stoptext indeed, an dafter that you can check it box.glueorder : 2 box.glueset: 6.6683349609375 box.gluesign : 2 which will be applied (in the backend) to glues Hans - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] how to simulate \hss in luametatex?
Hi, > I want to simulate \hss in lua end in ConTeXt/luametatex environment. > For example, > > ```ConTeXt > a{\raise 1.5ex\hbox to 0pt{\hss b}}c > ``` > And in lua, I do as follows(part of my app seen in attachment): Your code doesn't compile as is. I think that this is the same thing though: \starttext \startluacode local a = node.new"glyph" a.char = string.byte("a") a.font = font.current() local b = node.new"glyph" b.char = string.byte("b") b.font = font.current() local c = node.new"glyph" c.char = string.byte("c") c.font = font.current() local hss = node.new("glue") hss.stretch = 65536 hss.stretchorder = 2 hss.shrink = 65536 hss.shrinkorder = 2 hss.width = 0 b = node.insertbefore(b, b, hss) local box = node.new("hlist", "box") box.head = b box.width = 0 box.shift = -tex.sp("1ex") tex.forcehmode() node.write(a + box + c) \stopluacode \stoptext > And got 'b' on top of 'c' in pdf as follows: > > ```pdf > b > ac > ``` The \hss isn't the problem here. The problem is actually with the box. When you manually make the \hbox like that, I think (although I could be wrong) that you're bypassing all of TeX's glue calculations. You should probably use "node.hpack" instead: \starttext \startluacode local a = node.new"glyph" a.char = string.byte("a") a.font = font.current() local b = node.new"glyph" b.char = string.byte("b") b.font = font.current() local c = node.new"glyph" c.char = string.byte("c") c.font = font.current() local hss = node.new("glue") hss.stretch = 65536 hss.stretchorder = 2 hss.shrink = 65536 hss.shrinkorder = 2 hss.width = 0 local box = node.hpack(hss + b, "exactly", 0) box.shift = -tex.sp("1ex") tex.forcehmode() a.next = box box.next = c node.write(a) \stopluacode \stoptext -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
[NTG-context] how to simulate \hss in luametatex?
Hi list, I want to simulate \hss in lua end in ConTeXt/luametatex environment. For example, ```ConTeXt a{\raise 1.5ex\hbox to 0pt{\hss b}}c ``` should get 'b' on top of 'a', as follows: ```pdf b ac ``` and in lua, I see a before "b" node, width width:0, stretch:65536, shrink:65536, stretchorder:2, shrinkorder:2 And in lua, I do as follows(part of my app seen in attachment): ```lua local hss = node_new(glue_id) hss.stretch = 65536 hss.stretchorder = 2 hss.shrink = 65536 hss.shrinkorder = 2 hss.width = 0 list,_ = node_insertbefore(list, list, hss) -- b is in the list -- I got a with width:0, stretch:65536, shrink:65536, stretchorder:2, shrinkorder:2 local box = node_new(hlist_id, "box") box.head = list box.width = 0 box.shift = -tex_sp("1ex") -- I got width:0 height:0 deep:0 shift: -503424 head, current = node_insertbefore(head,current, box) -- current is 'c' node ``` And got 'b' on top of 'c' in pdf as follows: ```pdf b ac ``` How can I get 'b' on top of 'a' as \hss do? ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___ t-zhpunc.lua Description: Binary data ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___