[NTG-context] image file resolver in Lua?

Procházka Lukáš Ing. LPr at pontex.cz
Tue Feb 6 17:09:32 CET 2018

Hello Henning,

On Tue, 06 Feb 2018 13:13:12 +0100, Henning Hraban Ramm <texml at fiee.net> wrote:

> I’ll try as soon as I get some time, since algorithmic image placement is a recurring problem for me, as I try to replace InDesign in my workflow.
> I thought about providing a module, but each of my projects has so differing needs that either every macro would need a bunch of options, or I need a lot of similar macros. We’ll see...

my experience in these situations:

I'm usually implementing complicated solutions via Lua, with functions with obligatory arg(s) first followed by one optional argument of table type:

- it's  easy to investigate this optional argument and alter the algorithm depending on table keys (presence and/or value),
- you don't have to be afraid of optional arg(s) rearrangement.

To be more concrete:

---- Sample Lua code

MyPlaceFigure = function(figname,
                          opts) -- Optional; .scale = .sc, .rotation = .rot, .label, ...
   opts = opts or {} -- To simplify code bellow

   local scale, rot, lab =
     opts.scale or opts.sc, -- I.e. more keys are allowed in long/short alternative
     opts.rotation or opts.rotate or opts.rot, -- dtto
     opts.label or opts.lab,

   if label then
     -- E.g. use context.placefloat(...)
     context.externalfigure({figname}, {scale = 1000 * scale, orientation = rot, })


Best regards,


> Greetlings, Hraban

Ing. Lukáš Procházka | mailto:LPr at pontex.cz
Pontex s. r. o.      | mailto:pontex at pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn
Bezová 1658
147 14 Praha 4

Mob.: +420 702 033 396

More information about the ntg-context mailing list