[NTG-context] How to center with picture taken into consideration

Sietse Brouwer sbbrouwer at gmail.com
Sat Apr 27 14:35:03 CEST 2013


Hello Cecil,

I have a LuaTeX-based start for you, but there is one important thing
I do not know: how to obtain the an image's width and/or height from
Lua. Although that would also depend on whether you want to resize
images to a fixed with, etc. Anyway, now that the typesetting code is
Lua-based, working out the conditional stuff you need will hopefully
be trivial (for 'if you know Lua or have an hour to learn the basics'
values of trivial).

Cheers,
Sietse

% 2013-04-27

\useMPlibrary[dum]

\showframe

\defineparagraphs[persoon]

\setupparagraphs[persoon][1]
   [width=\dimexpr \textwidth - 3.5cm\relax,
    distance=0.5cm,
    align=middle,
    ]
\setuplines[align=middle]

\setupparagraphs[persoon][2][width=3cm]

\starttext

\startluacode
    -- a table containing the material we want to typeset
    local contents = {
        {
            text = [[
                Naam:
                Adres:
                Burgerservicenummer:
            ]],
            image = "pic1"
        },
        {
            text = [[
                Naam: Aapje aapje aapje aapje
                Adres: Olifantje
                Burgerservicenummer: En nu jij
            ]],
            image = "pic2"
        }
    }

    -- typeset each text-image pair
    for k,v in ipairs(contents) do
        -- calculate or specify how wide you want the image and the
paragraphs to be
        imagecolwidth = string.todimen("3cm")
        coldistance   = string.todimen("0.5cm")
        textcolwidth  = tex.dimen.textwidth - imagecolwidth - coldistance

        -- setup the text column
        context.setupparagraphs(
            { "persoon" },
            { 1 },
            { width = textcolwidth .. "sp" })
        -- setup the image column (possibly to width 0?)
        context.setupparagraphs(
            { "persoon" },
            { 2 },
            { width = imagecolwidth .. "sp" })

        -- the actual typesetting code
        context.startpersoon()
            context.startlines()
                context(v.text)
            context.stoplines()
        context.nextpersoon()
            context.externalfigure(
                { v.image},
                {
                    width = imagecolwidth .. "sp",
                    height = "4cm",
                    factor = "fit"
                }
            )
        context.stoppersoon()
    end
\stopluacode

\stoptext


More information about the ntg-context mailing list