Node for startbuffer.
Hello! Given some \startbuffer Blah, blah, blah... \stopbuffer I'd like to get a "node tree" corresponding to how the buffer would be processed at a given point. Using luatex, I'd like to identify certain sub-nodes and change their attributes (to be specific: transparency). Any hint on how to do it? Also, are there any good examples on how to use "nodes"? André Caldas.
On 1/9/2013 2:54 PM, Andre Caldas wrote:
Hello!
Given some
\startbuffer Blah, blah, blah... \stopbuffer
I'd like to get a "node tree" corresponding to how the buffer would be processed at a given point. Using luatex, I'd like to identify certain sub-nodes and change their attributes (to be specific: transparency).
Any hint on how to do it?
here's an example (I'll add it to the cld manual): \starttext \definecolor[mytransparency][a=1,t=.5] \startluacode local enabled = false local count = 0 function userdata.processmystuff(head) if enabled then count = count + 1 for n in node.traverse(head) do logs.report("node","run %s: %s",count,n) if count % 2 == 0 then nodes.tracers.transparencies.set(n,"mytransparency") end end return head, true end return head, false end function userdata.enablemystuff() enabled = true end function userdata.disablemystuff() enabled = false end nodes.tasks.appendaction("processors", "normalizers", "userdata.processmystuff") \stopluacode \startbuffer whatever \hbox{you} want \stopbuffer \ctxlua{userdata.enablemystuff()} \par \getbuffer \par \ctxlua{userdata.disablemystuff()} \stoptext
Also, are there any good examples on how to use "nodes"?
all over context ... Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 1/9/2013 9:57 PM, Andre Caldas wrote:
Another question...
function userdata.processmystuff(head)
Shall I use this? userdata = userdata or {}
\startbuffer whatever \hbox{you} want \stopbuffer
How do I identify a specific node? Like...
\startbuffer Will this be \boxtobechanged{transparent?} \stopbuffer
Here is a start. I've added the markers code to the beta so that we have an abstract way to deal with such matters. \setupbodyfont[dejavu] \definemarker[mymarker] \definecolor[mymarker:1][r=.6] \definecolor[mymarker:2][g=.6] \definecolor[mymarker:3][r=.6,g=.6] \startluacode local setcolor = nodes.tracers.colors.setlist local getmarker = nodes.markers.get local hlist_code = nodes.codes.hlist local traverse_id = node.traverse_id function userdata.processmystuff(head) for n in traverse_id(hlist_code,head) do local m = getmarker(n,"mymarker") if m then setcolor(n.list,"mymarker:" .. m) end end return head, true end nodes.tasks.appendaction("processors", "after", "userdata.processmystuff") nodes.tasks.disableaction("processors", "userdata.processmystuff") \stopluacode \starttext \startluacode nodes.tasks.enableaction("processors", "userdata.processmystuff") \stopluacode Node lists are processed \hbox \boxmarker{mymarker}{1} {nested from \hbox{inside} out} which is not what you might expect. But, \hbox {coloring} does not \hbox {happen} really nested here, more \hbox {in} \hbox \boxmarker{mymarker}{2} {the} \hbox {order} \hbox {of} \hbox \boxmarker{mymarker}{3} {processing}. \startluacode nodes.tasks.disableaction("processors", "userdata.processmystuff") \stopluacode \stoptext It's somewhat experimental. Up to you to update the wiki. I've added the example to the cld manual. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 1/10/2013 1:18 PM, Andre Caldas wrote:
How do I identify a specific node? Like... [...]
Here is a start. I've added the markers code to the beta so that we have an abstract way to deal with such matters. [...] \hbox \boxmarker{mymarker}{2}
Can't the mark be a string?
currently not (not hard to implement, but no time now). ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
I've added the markers code to the beta so that we have an abstract way to deal with such matters. [...] Node lists are processed \hbox \boxmarker{mymarker}{1} {nested from [...]
Does it have to be an "hbox"?
It's somewhat experimental. Up to you to update the wiki.
I've never updated the wiki... I am a bit scared... but I will... :-)
I've added the example to the cld manual.
How can I see it? André Caldas.
On 1/12/2013 3:49 PM, Andre Caldas wrote:
I've added the markers code to the beta so that we have an abstract way to deal with such matters. [...] Node lists are processed \hbox \boxmarker{mymarker}{1} {nested from [...]
Does it have to be an "hbox"?
no, but only a few node types make sense .. it all depends on what you want to do
It's somewhat experimental. Up to you to update the wiki.
I've never updated the wiki... I am a bit scared... but I will... :-)
I bet Sietse will keep an eye on your edits.
I've added the example to the cld manual.
How can I see it?
google for cld-mkiv.pdf or browse the pragma website ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
It's somewhat experimental. Up to you to update the wiki.
Anyone can suggest a category for it? http://wiki.contextgarden.net/Category:Commands Nodes? André Caldas.
Hi André,
Anyone can suggest a category for it? http://wiki.contextgarden.net/Category:Commands
Nodes?
Yep. Creating [[Category:Command/Nodes]] seems like a good idea. To create the command page, navigate to the intended title (e.g. Command/boxmarker), click ‘Create’ in the top right, and copy-and-modify the command page template that you can find here: http://wiki.contextgarden.net/Help:Command_reference#Command_page_template Possibly add it to the category [[Category:Command/LuaTeX]], too. If you find yourself having questions about the wiki, or just wanting help, even for trivial stuff, just poke me on my talk page: http://wiki.contextgarden.net/User_talk:Esteis Or send me a private e-mail, of course, that's also fine. Hans wrote:
I've added the example to the cld manual. ... google for cld-mkiv.pdf or browse the pragma website
For the benefit of future people:
http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf
It's on page 33, in section 4.4, "Node lists".
Cheers,
Sietse
On Tue, Jan 29, 2013 at 9:57 PM, Andre Caldas
It's somewhat experimental. Up to you to update the wiki.
Anyone can suggest a category for it? http://wiki.contextgarden.net/Category:Commands
Nodes?
André Caldas. ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (3)
-
Andre Caldas
-
Hans Hagen
-
Sietse Brouwer