# Example of using save_pos subtype (luatex)

Luatex manual mention save_pos (page 136) a subtype of whatsit node, Is there anyone who can give us a simple example of its use with lualatex.

• it's the node from \savepos, which is the same as pdftex \pdfsavepos – David Carlisle Oct 21 at 20:06

save_pos is the whatsit that is inserted by \savepos (the LuaTeX name for \pdfsavepos.) Using it directly would be quite rare because you would normally just use \savepos in TeX code or, if you want to access the position though Lua, you just use pdf.getpos() with \latelua directly.

But you could use it to implement you own version on \pdfsavepos:

% plain TeX, but you can also add \documentclass etc. to make it LaTeX...

% Don't do this in regular code, just use \savepos.
\def\pdfsavepos{\directlua{
node.write(node.new("whatsit", "save_pos"))
}}
\pdfsavepos
% Write the coordinates of that point to the log file:
\write-1{The page starts at \the\lastxpos, \the\lastypos.}
\bye


The same example with pdf.getpos() and \latelua:

\latelua{
texio.write_nl('log', ("The page starts at \csstring\%i, \csstring\%i."):format(pdf.getpos()))
}
\bye