Lualatex 有回调start_page_number
和stop_page_number
。这些回调在页面被发送出去时被调用,并替换 [1] [2] [3]。等。
问题是他们不提供页面。我想模拟原始行为(打印出“[<>]”),因为我只需要获取页面值。
所以,
function start_page_number()
print("["..page)
end
luatexbase.add_to_callback("start_page_number", start_page_number, "start_page_number")
如果页面正确并且与 latex 匹配,则会执行此操作。肯定有一个 luatex 表,我们可以在其中访问页面值?
谢谢。
答案1
目前尚不清楚您是否想要打印的页码或输出的页数,因此这里我打印与上次相同的文档,但从 lua 和 tex 打印。
当然,打印发生在文档中大致相同的位置,即段落被分成行,行被分成页面的位置。终端输出如下所示
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
]
标准[18]
被替换为mypage=7, 18
在输出的第 7 个绝对页数上表示打印页码为 18。
\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}