3

Lualatex has the callbacks start_page_number and stop_page_number. These are called when the pages are being shipped out and replace the [1] [2] [3]. etc.

The problem is that they do not supply the page. I would like to simulate the original behavior(printing out "[<>]") as I simply need to get the page value.

So,

function start_page_number()        
    print("["..page)
end

luatexbase.add_to_callback("start_page_number", start_page_number, "start_page_number")

would do it if page was correct and matched what latex does. Surely there is a luatex table somewhere that we can access the page value?

Thanks.

4

It's not clear if you want the printed page number or the count of pages output so here I print both same document as last time, but printing from lua as well as tex.

Of course the printing happens at more or less the same point in the document, at the point the paragraph is split into lines then lines into pages. the terminal output looks like

Page = 15, Line = 95
[ mypage=4, 15
]
Page = 16, Line = 95
[ mypage=5, 16
]
Page = 17, Line = 95
[ mypage=6, 17
]
Page = 18, Line = 97
[ mypage=7, 18
] 

with the standard [18] being replaced by mypage=7, 18 denoting that the printed page number is 18 on the 7th absolute count of pages output.

\documentclass[12pt,oneside]{book}

\usepackage{everypage}

\setlength\textwidth{5cm}
\setlength\textheight{\dimexpr\topskip+20\baselineskip}

\AddEverypageHook{\typeout{Page = \thepage, Line = \the\inputlineno}}

\directlua{
function start_page_number()
    if mypage == nil then mypage=1 else mypage=mypage+1 end        
    print("[ mypage=".. mypage .. ', ' .. tex.count[0])
end
%
luatexbase.add_to_callback("start_page_number", start_page_number, "start_page_number")
}
\raggedright
\begin{document}

\setcounter{page}{12}

One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.\typeout{AAA:Page = \thepage, Line = \the\inputlineno}
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.
One two three four five six seven eight nine ten.
Red yellow blue green purple black white brown.
Apple orange banana grape pear lemon.


\end{document}
  • I guess that would be a "oh duh" moment ;) Since the callback is called for each page in sequence, just using a counter would work fine. Just felt strange to me that there was no way to get the page from the internals(as the above does make assumptions that about when the callback is executed). – AbstractDissonance Feb 9 '17 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.