Marcel's answer resolved the original question. I have notedadded followup questions from his answer under my original question (which ends. Followup questions begin with the codea similar block following the sentence "Here's my code so farquote as this stating "Followup questions begin here:")
Marcel's answer resolved the original question. I have noted followup questions under my original question (which ends with the code block following the sentence "Here's my code so far:")
Marcel's answer resolved the original question. I have added followup questions from his answer under my original question. Followup questions begin with a similar block quote as this stating "Followup questions begin here:"
\documentclass[notitlepage,letterpaper]{article} %\usepackage{lua-visual-debug} \usepackage[absolute]{textpos} \usepackage[letterpaper,left=0in,right=0in,top=1in,bottom=1in]{geometry} \usepackage[expansion=alltext,shrink=20,stretch=20]{microtype} \usepackage{fontspec} \usepackage{blindtext} \setmainfont%\setmainfont{Verdana} % Commented this as standard linux installs do not come with Verdana, check Marcel's comment to this question. \directlua{ function my_post_lb_filter(head,groupcode) local HLIST = node.id("hlist") % node.id for a line of text in vertical list for n in node.traverse(head) do % For every subnode within node head if n.id==HLIST then % If its a line of text local savepos = node.new("whatsit","save_pos") n.head = node.insert_after(n.head,node.tail(node.list),savepos) end end return head end luatexbase.add_to_callback('post_linebreak_filter', my_post_lb_filter, 'Play with luatex node library') } \begin{document} \raggedright \newbox\myoddvbox \newbox\myoddvboxsplit \global\setbox\myoddvbox=\vbox{{\hsize=2in \blindtext[1]\endgraf}}% \setbox\myoddvboxsplit=\vsplit\myoddvbox to 4cm \begin{textblock*}{0.5\linewidth}[0,0](2in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvboxsplit% \end{minipage} \end{textblock*} \begin{textblock*}{0.5\linewidth}[0,0](5in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvbox% \end{minipage} \end{textblock*} \null \newpage % replace following line with a iterate function to print all the positions from lastpage \the\lastxpos, \the\lastypos. \end{document} \documentclass[notitlepage,letterpaper]{article} %\usepackage{lua-visual-debug} \usepackage[absolute]{textpos} \usepackage[letterpaper,left=0in,right=0in,top=1in,bottom=1in]{geometry} \usepackage[expansion=alltext,shrink=20,stretch=20]{microtype} \usepackage{fontspec} \usepackage{blindtext} \setmainfont{Verdana} \directlua{ function my_post_lb_filter(head,groupcode) local HLIST = node.id("hlist") % node.id for a line of text in vertical list for n in node.traverse(head) do % For every subnode within node head if n.id==HLIST then % If its a line of text local savepos = node.new("whatsit","save_pos") n.head = node.insert_after(n.head,node.tail(node.list),savepos) end end return head end luatexbase.add_to_callback('post_linebreak_filter', my_post_lb_filter, 'Play with luatex node library') } \begin{document} \raggedright \newbox\myoddvbox \newbox\myoddvboxsplit \global\setbox\myoddvbox=\vbox{{\hsize=2in \blindtext[1]\endgraf}}% \setbox\myoddvboxsplit=\vsplit\myoddvbox to 4cm \begin{textblock*}{0.5\linewidth}[0,0](2in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvboxsplit% \end{minipage} \end{textblock*} \begin{textblock*}{0.5\linewidth}[0,0](5in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvbox% \end{minipage} \end{textblock*} \null \newpage % replace following line with a iterate function to print all the positions from lastpage \the\lastxpos, \the\lastypos. \end{document} \documentclass[notitlepage,letterpaper]{article} %\usepackage{lua-visual-debug} \usepackage[absolute]{textpos} \usepackage[letterpaper,left=0in,right=0in,top=1in,bottom=1in]{geometry} \usepackage[expansion=alltext,shrink=20,stretch=20]{microtype} \usepackage{fontspec} \usepackage{blindtext} %\setmainfont{Verdana} % Commented this as standard linux installs do not come with Verdana, check Marcel's comment to this question. \directlua{ function my_post_lb_filter(head,groupcode) local HLIST = node.id("hlist") % node.id for a line of text in vertical list for n in node.traverse(head) do % For every subnode within node head if n.id==HLIST then % If its a line of text local savepos = node.new("whatsit","save_pos") n.head = node.insert_after(n.head,node.tail(node.list),savepos) end end return head end luatexbase.add_to_callback('post_linebreak_filter', my_post_lb_filter, 'Play with luatex node library') } \begin{document} \raggedright \newbox\myoddvbox \newbox\myoddvboxsplit \global\setbox\myoddvbox=\vbox{{\hsize=2in \blindtext[1]\endgraf}}% \setbox\myoddvboxsplit=\vsplit\myoddvbox to 4cm \begin{textblock*}{0.5\linewidth}[0,0](2in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvboxsplit% \end{minipage} \end{textblock*} \begin{textblock*}{0.5\linewidth}[0,0](5in,2in) \begin{minipage}[t][1cm][t]{0.5\linewidth}% \box\myoddvbox% \end{minipage} \end{textblock*} \null \newpage % replace following line with a iterate function to print all the positions from lastpage \the\lastxpos, \the\lastypos. \end{document} FollowFollowup questions begin herehere:
- What is the sequence of execution of late_lua nodes? Is it a FIFO model?
- What is the nature of data that can be acted on? Can we access and late process hlist node (for instance insert_to) from a latelua function? Or is it too late for that? What is the life of a hlist node anyway, is it freed after a page is shipped out?
- Can we pass arguments to a late_lua function? I tried passing arguments to the function
savepos.data = savepos_func("hello"), and the lua segfaults. - luatex manual says the type of
datafield of late_lua node can be either string or function. When would one assign a string to a late_lua nodenode's data field? I tried assigning a lua stringsavepos.data = "hello world", and it gave a error during shipout[\latelua]:1: syntax error near 'world'. - What is the scope of code that goes in directlua? I tried to print the size of table
position_arrayusing\AtBeginShipoutof package\usepackage{atbegshi}, and it printsnilon terminal (code is simpleprint(tostring(table.getn(position_array)))in a\directluamacro). If I removelocalfrom the declarationlocal position_array = {}, then it prints the correct value of the array (while processing next page).
Follow questions begin here:
- What is the sequence of execution of late_lua nodes? Is it a FIFO model?
- What is the nature of data that can be acted on? Can we access and late process hlist node (for instance insert_to) from a latelua function? Or is it too late for that? What is the life of a hlist node anyway, is it freed after a page is shipped out?
- Can we pass arguments to a late_lua function? I tried passing arguments to the function
savepos.data = savepos_func("hello"), and the lua segfaults. - luatex manual says the type of
datafield of late_lua node can be either string or function. When would one assign a string to a late_lua node? I tried assigning a lua stringsavepos.data = "hello world", and it gave a error during shipout[\latelua]:1: syntax error near 'world'. - What is the scope of code that goes in directlua? I tried to print the size of table
position_arrayusing\AtBeginShipoutof package\usepackage{atbegshi}, and it printsnilon terminal (code is simpleprint(tostring(table.getn(position_array)))in a\directluamacro). If I removelocalfrom the declarationlocal position_array = {}, then it prints the correct value of the array (while processing next page).
Followup questions begin here:
- What is the sequence of execution of late_lua nodes? Is it a FIFO model?
- What is the nature of data that can be acted on? Can we access and late process hlist node (for instance insert_to) from a latelua function? Or is it too late for that? What is the life of a hlist node anyway, is it freed after a page is shipped out?
- Can we pass arguments to a late_lua function? I tried passing arguments to the function
savepos.data = savepos_func("hello"), and the lua segfaults. - luatex manual says the type of
datafield of late_lua node can be either string or function. When would one assign a string to a late_lua node's data field? I tried assigning a lua stringsavepos.data = "hello world", and it gave a error during shipout[\latelua]:1: syntax error near 'world'. - What is the scope of code that goes in directlua? I tried to print the size of table
position_arrayusing\AtBeginShipoutof package\usepackage{atbegshi}, and it printsnilon terminal (code is simpleprint(tostring(table.getn(position_array)))in a\directluamacro). If I removelocalfrom the declarationlocal position_array = {}, then it prints the correct value of the array (while processing next page).
lang-tex