Please help me how to register callbacks in lualatex. For example, I need to determine when the page of my document was started or ended and the print number of that page*2. I found in the luatex documentation only how to catch when the end of the page, but it does not work for me. Here is my code:
\documentclass{article}
\usepackage{luacode}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{russian}
\setmainfont{Times New Roman}
\pagestyle{empty}
\thispagestyle{empty}
\begin{luacode}
function f()
tex.print("page "..\thepage*2)
end
id,error=callback.register("finish_pdfpage",f)
tex.sprint(error," ",id)
\end{luacode}
\begin{document}
test
\newpage
new test
\end{document}
But when I compile this document in lualatex, I get the following errors:
C:/Program Files/MiKTeX 2.9/tex/latex/base/ltluatex.lua:109:
Module luatexbase Error: Attempt to use callback.register() directly
(luatexbase) on input line 14
stack traceback:
[C]: in function 'error'
C:/Program Files/MiKTeX 2.9/tex/latex/base/ltluatex.lua:109: in function 'modu
le_error'
C:/Program Files/MiKTeX 2.9/tex/latex/base/ltluatex.lua:116: in function 'luat
exbase_error'
C:/Program Files/MiKTeX 2.9/tex/latex/base/ltluatex.lua:320: in function 'regi
ster'
[\directlua]:4: in main chunk.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }
l.14 \end{luacode}
?
Please also help me to catch the event when a new page is started, e.g. to print the number of this page*2 or the simple number of this page. Thank everybody for help.
texdoc ltluatexto see the documentation latex lua interface. You register a callback withluatexbase.add_to_callbackas shown in Ulrike's answer. – David Carlisle Mar 05 '19 at 20:21texdoc luatex). – user202729 Feb 02 '22 at 10:54