Skip to main content
added 265 characters in body
Source Link
nick2225
  • 299
  • 1
  • 5

Edit 1

Edit. Added Added a MWE for the pre_output_filter attempt I described

\directlua{ dofile("helper.lua") } \def\CreateRef#1{ \directlua{ create_node_reference("#1") } } \CreateRef{Test here on page 1} \vfil \eject \CreateRef{Something on page 2} \vfil \eject 

Edit 2

After a discovery it appears that if there is text (or horizontal material?) right before the directlua call, the node.write appears to not work.

\def\CreateRef#1{ Some text here \directlua{ create_node_reference("#1") } } 

Edit. Added a MWE for the pre_output_filter attempt I described

\directlua{ dofile("helper.lua") } \def\CreateRef#1{ \directlua{ create_node_reference("#1") } } \CreateRef{Test here on page 1} \vfil \eject \CreateRef{Something on page 2} \vfil \eject 

Edit 1

Added a MWE for the pre_output_filter attempt I described

\directlua{ dofile("helper.lua") } \def\CreateRef#1{ \directlua{ create_node_reference("#1") } } \CreateRef{Test here on page 1} \vfil \eject \CreateRef{Something on page 2} \vfil \eject 

Edit 2

After a discovery it appears that if there is text (or horizontal material?) right before the directlua call, the node.write appears to not work.

\def\CreateRef#1{ Some text here \directlua{ create_node_reference("#1") } } 
added '<!-- language: lang-lua -->' and '<!-- language: lang-latex -->' switches
Source Link
Mico
  • 552.5k
  • 57
  • 753
  • 1.3k

Edit:Edit. Added a MWE for the pre_output_filter attempt I described

-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 
-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 

Edit: Added a MWE for the pre_output_filter attempt I described

-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 

Edit. Added a MWE for the pre_output_filter attempt I described

-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 
Removed misleading line
Source Link
nick2225
  • 299
  • 1
  • 5

If anyone has more experience on this or could mention a better way of handling pagerefs in LuaTeX, I would greatly appreciate it. I will also accept, if indeed it is the case, that the coroutine, or letting TeX handle outputting page numbers is

Edit: Added a MWE for the best way.pre_output_filter attempt I described

-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 

Main tex file

\directlua{ dofile("helper.lua") } \def\CreateRef#1{ \directlua{ create_node_reference("#1") } } \CreateRef{Test here on page 1} \vfil \eject \CreateRef{Something on page 2} \vfil \eject 

If anyone has more experience on this or could mention a better way of handling pagerefs in LuaTeX, I would greatly appreciate it. I will also accept, if indeed it is the case, that the coroutine, or letting TeX handle outputting page numbers is the best way.

If anyone has more experience on this or could mention a better way of handling pagerefs in LuaTeX, I would greatly appreciate it.

Edit: Added a MWE for the pre_output_filter attempt I described

-- helper.lua function create_node_reference(name) whatsit_id = node.id("whatsit") user_define_id = node.subtype("user_defined") local new_node = node.new(whatsit_id, user_define_id) new_node.type = 115 -- internal code for a string value new_node.value = name node.write(new_node) end function print_whatsit_nodes_page(head, groupcode, size, packtype, maxdepth) -- traverse_id will only iterate over nodes with the specified id, in this case "whatsit" -- There seems to be no whatsit nodes though in this list for n in node.traverse_id(node.id("whatsit"), head) do print(n) end end callback.register("pre_output_filter", print_whatsit_nodes_page) 

Main tex file

\directlua{ dofile("helper.lua") } \def\CreateRef#1{ \directlua{ create_node_reference("#1") } } \CreateRef{Test here on page 1} \vfil \eject \CreateRef{Something on page 2} \vfil \eject 
Source Link
nick2225
  • 299
  • 1
  • 5
Loading