0

i tired the code from this answer to arrange images loaded by includegraphics but got some errors i can not fix. the following code

module(...,package.seeall)

local function get_boxes(parent) local boxes = {} for n in node.traverse(parent.head) do if n.width or n.height or n.depth then table.insert(boxes, { w = n.width, h = n.height + n.depth, box = node.copy(n), }) end end return boxes end

produces this error:

generativelayout.lua:9: attempt to perform arithmetic on a nil value (field 'height')
stack traceback:
        ./generativelayout.lua:9: in upvalue 'get_boxes'
        ./generativelayout.lua:100: in function 'generativelayout.process'
        [\directlua]:1: in main chunk.
\endgenlayout ->\egroup \directlua {gen.process()}

is there a way to fix this?

the code does not work on the proposed fbox nodes (in the example on the link) and also does not work on the nodes generated by includegraphics. of which node type the nodes generated by includegraphics and do they have a width and height?

  • @MarcelKrüger Ah, good to know. I attend to optimize the arrangement of images loaded with includegraphics. Updated my question. – susis strolch May 20 '21 at 18:54

1 Answers1

1

Since you optimize the placement of two dimensional objects, you are only really interested in objects which really extend to two dimensions and therefore need both horizontal (width) and vertical (height and depth) dimensions. Objects which only extend in one direction (e.g. whitespace) are not relevant. Therefore you can just make your test more specific:

Replace

if n.width or n.height or n.depth then

with

if n.width and n.height and n.depth then

to only look at nodes like hlists, vlists, and rules (in LuaTeX, images are internally treated as rules) which contain all three fields.