Skip to main content
added 112 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21

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:"

added 112 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
\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} 
added 1 character in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21

FollowFollowup questions begin herehere:

  1. What is the sequence of execution of late_lua nodes? Is it a FIFO model?
  2. 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?
  3. 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.
  4. luatex manual says the type of data field 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 string savepos.data = "hello world", and it gave a error during shipout [\latelua]:1: syntax error near 'world'.
  5. What is the scope of code that goes in directlua? I tried to print the size of table position_array using \AtBeginShipout of package \usepackage{atbegshi}, and it prints nil on terminal (code is simple print(tostring(table.getn(position_array))) in a \directlua macro). If I remove local from the declaration local position_array = {}, then it prints the correct value of the array (while processing next page).

Follow questions begin here:

  1. What is the sequence of execution of late_lua nodes? Is it a FIFO model?
  2. 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?
  3. 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.
  4. luatex manual says the type of data field 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 string savepos.data = "hello world", and it gave a error during shipout [\latelua]:1: syntax error near 'world'.
  5. What is the scope of code that goes in directlua? I tried to print the size of table position_array using \AtBeginShipout of package \usepackage{atbegshi}, and it prints nil on terminal (code is simple print(tostring(table.getn(position_array))) in a \directlua macro). If I remove local from the declaration local position_array = {}, then it prints the correct value of the array (while processing next page).

Followup questions begin here:

  1. What is the sequence of execution of late_lua nodes? Is it a FIFO model?
  2. 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?
  3. 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.
  4. luatex manual says the type of data field 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 string savepos.data = "hello world", and it gave a error during shipout [\latelua]:1: syntax error near 'world'.
  5. What is the scope of code that goes in directlua? I tried to print the size of table position_array using \AtBeginShipout of package \usepackage{atbegshi}, and it prints nil on terminal (code is simple print(tostring(table.getn(position_array))) in a \directlua macro). If I remove local from the declaration local position_array = {}, then it prints the correct value of the array (while processing next page).
added 1609 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
deleted 8 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
deleted 89 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
deleted 89 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
added 1 character in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
deleted 2 characters in body
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading
Source Link
codepoet
  • 1.3k
  • 10
  • 21
Loading