ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Gerben Wierda <gerben.wierda@rna.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: \framed[align=] with a 'maxwidth' instead of a width? Or get the size of a \frame returned to lua without typesetting it in a document?
Date: Sun, 26 Apr 2020 23:45:04 +0200	[thread overview]
Message-ID: <406043A5-238C-4F74-A82E-7432C9CBF4AF@rna.nl> (raw)

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?
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

                 reply	other threads:[~2020-04-26 21:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=406043A5-238C-4F74-A82E-7432C9CBF4AF@rna.nl \
    --to=gerben.wierda@rna.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).