Setup: TeX file Contains ctxlua{} call lua function reads XML file and calls context() statements, it puts out a \startMPpage METAPOST statements Of which some are textext(\framed[align, so vbox, width defined by lua]{}, the whole TeX string for textext is created in lua and passed whole on to METAPOST as METAPOST is pretty limited on string manipulation compared to lua) \stopMPpage I am running into the following conundrum: If I do give it a width (say a maximum) it will also be that wide when it is mostly empty if there is little text, this interferes with optimal placing If I don’t give a width to the \framed command it may grow far too wide if there is a lot of text instead of wrapping around. The typeset text is rather unpredictable. It may be three very short single-word lines with \\ at the end but it may also be a large paragraph. So, I would like to find a way to let the \framed become a box as narrow as possible, but not growing wider than a pre-set width. This is way too difficult for my meagre skills. What I could do (but I think is clumsy) is pass two \framed commands to METAPOST, have both by typeset with textext() and if the one without a width becomes too wide, take the one with the width set. But I would like a neater option. E.g. call TeX (no need for METAPOST in between) from lua to typeset the \framed without actually typesetting it to the document and getting the dimensions back to lua so I can decide there what to do. Or a \specialframed command where I don’t give it a ‘width', but a ‘maxwidth’ Is one of these doable? If not, I’ll have to implement the ‘clumsy’ route. Preferably (the what is now thought of as ideal solution) I would be able in lua to give a piece of TeX code to TeX and ask it to produce a box and give me the dimensions of that box. That alone would give me an option, e.g. - trial typeset - if box surface (w*h) is more than what is available, shrink font size and lineheight so the total will be within set limits, then typeset it again with the smaller font and max width available - else, if trial box width is more than the width available, typeset again with fixed width - else use the way the trial box was typeset But I’m still puzzling. G PS. Why is the bbox of a textext(\framed[]{}) slightly larger than the frame?