I have a long list in an enumerate environment. I would like to put as header to the page (or in any case to save in a variable to use elsewhere) the number of the last item appearing on it.
A minimal example of what I would like to do is in the following code in luatex (where the only use I make of lua is to have 120 consecutive items to get what I want).
\documentclass{article}
\usepackage[absolute]{textpos}
\let\mycounter=0
\AddToHook{shipout/before}{
\begin{textblock}{40}(0,0)
Last entry: \mycounter
\end{textblock}}
\AddToHook{cmd/item/before}{\let\beginitmpage=\thepage}
\AddToHook{cmd/item/after}{\let\enditmpage=\thepage \ifnum \thepage=\beginitmpage \let\mycounter=\theenumi\fi}
\begin{document}
\begin{enumerate}
\directlua{
for i=1,120,1 do
tex.print("\item Dummy text from page \beginitmpage\ to page \enditmpage")
end}
\end{enumerate}
\end{document}
As it can be seen, at the end of the first page the counter is already at 32 (but the last line printed is 28). Entries 29-32 "believe" to be on page 1 even if they are formatted on page 2.
I know that tex has already processed part of the text which is to appear on the second page and that this is normal, but this is exactly what I would like to avoid. Similar problems occur with the remaining pages.
Is there any simple way to implement what I would like to get in a "simple" way? (i.e. not to get the value of the counter at shipout, but the value of the counter used to construct the page).
\items. The question is then whether the current\itemsplit over two pages or started fresh on the new page. – John Kormylo Jul 02 '23 at 00:30