I'm trying to record position of glyph nodes while generating a pdf file but I always get values 0 from the call of pdf.getpos() function. How can I fix it? Here is my code and the output is recorded in the output file 'test.txt'.
\documentclass{article}
\usepackage{luacode,luatexbase}
\usepackage[letterpaper,left=1in,right=1in,top=1in,bottom=1in]{geometry}
\begin{document}
\begin{luacode*}
local GLYPH_ID = node.id("glyph")
function getposition(head)
while head do
if head.id == 0 or head.id == 1 then
getposition(head.list)
elseif head.id == GLYPH_ID then
local savepos = node.new("whatsit","save_pos")
local h,v = pdf.getpos()
file = io.open("test.txt", "a")
file:write(tostring(h), " ", tostring(v),"\n")
file:close()
end
head = head.next
end
return true
end
luatexbase.add_to_callback("post_linebreak_filter",getposition,"getposition")
\end{luacode*}
My \emph{text} should be here and it can be really long so the lines can break but I still need to get position of glyph nodes.
\end{document}