From the description of hlist nodes in luatex manual, its field 'shift' seems to be a vertical shift. But when I change it using post_linebreak_filter, it adds horizontal shift to hlist. This overleaf post too describes shift as a vertical shift for hlist: "Another parameter listed in the “metadata” is shift: this is the value of box displacement resulting from applying TeX commands: \raise, \lower (applied to an \hbox);" Have I encountered a bug in luatex, or is my usage pattern incorrect? Either way, I would like select a hlist node, and shift it horizontally and vertically on the page while not affecting other pdf contents on the page (in effect apply pdf translation matrix to the hlist). Unfortunately, pdf_setmatrix
node cannot be used for vertical/horizontal displacement (called translation in PDF 1.7 manual) as pdftex has disabled it (read the definition of \pdfsetmatrix
in pdftex manual), and it warns against using \pdfliteral
(pdftex equivalent of luatex pdf_literal
node). Though am not sure whether the warning is true for luatex during post linebreak phase? If it is, then what's the safest way to achieve horizontal and vertical translation? (My guess for horizontal translation is to add a kern node at the beginning of hlist, is that the cleanest? And am not sure about the cleanest way to do vertical translation...)
Here's a screenshot of output I get, followed by complete code to add vertical and horizontal translations to hlist of line number 3, and below the code are some useful screenshot from documents mentioned in the description above:
code: >>lualatex test.tex
% test.tex
\documentclass[notitlepage,letterpaper]{article}
\usepackage[letterpaper,left=2in,right=2in,top=1in,bottom=1in]{geometry}
\usepackage{blindtext}
\directlua{
function my_post_lb_filter(head,groupcode)
local linenumber=1;
local HLIST = node.id("hlist")
local WHATSIT = node.id("whatsit")
local KERN = node.id("kern")
for n in node.traverse(head) do
if n.id==HLIST then
if linenumber==3 then
% Add vertical translation
n.shift=20*65536; % This should shift linenumber 3 vertically by 20, in reality it shifts horizontally
% Add horizontal translation
local hkern = node.new(KERN)
hkern.subtype=1;
hkern.attr=n.attr;
hkern.kern = 80*65535;
n.head = node.insert_before(n.list,n.head,hkern)
end
linenumber=linenumber+1;
end
end
return head
end
luatexbase.add_to_callback('post_linebreak_filter', my_post_lb_filter, 'Play with luatex node library')
}
\begin{document}
\blindtext[1]
\end{document}
hlist shift description from luatex manual:
pdf object translation:
pdfliteral vs pdfsetmatrix from pdftex manual: