I am writing (contributing to) a LuaLaTeX package where a Lua function is used to generate images that are inserted in the LaTeX document.
One piece of information we need is the current page number to determine if we're on an odd or even page (I know that this is not that trivial, and I know about some strategies beyond \thepage
). We set a Lua variable when we're still in the LaTeX part, and so far this works pretty well.
However, now it turns out that the sequence of images we create may be distributed on several pages, and we would really like to reflect that because our images may behave differently on odd and even pages.
Basically what we have is a series of
tex.print('\\includegraphics{something}\\par')
statements, executed in a loop within one Lua function.
Now the question: is there any way to either directly detect a page change between two such graphics or repeatedly retrieve the current page within such a loop?
All the solutions I have found for determining current odd or even state are in LaTeX itself. I know how to use \directlua
to retrieve a value for use in LaTeX, but is there a way to do the opposite - retrieve a LaTeX value from within LUa?
Edit: to respond to TeXnician's comment and answer: When I modify the example code so it produces repetitions of paragraphs it seems that the page counter won't get updated within one Lua chunk:
\documentclass{article}
\newcommand\printluapage{%
\directlua{for i = 1, 60 do tex.print(tex.count['c@page'])
tex.print([[\par]]) end}
}
\begin{document}
\printluapage
New command
\printluapage
New command
\printluapage
\end{document}
The page number is only updated with each new call of \printluapage
.
page
counter of LaTeX directly in Lua or should it be more "correct"?\pageref
or equivalent. consider a long 5-page paragraph, the page counter will not increase until the entire paragraph has been set. During the evaluation of every macro (and every\directlua
) within the paragraph the page counter will have the value it had at the start.