How to calculate the height of text of a certain width?
Hello dear All, the following MWE works best: \definelayer[LAY] \starttext \setlayerframed[LAY] [x=0pt,y=20pt] [frame=on, width=300pt, align={right,}] % tolerant}] {\input ward } \flushlayer[LAY] \stoptext Now, it could have a favourable effect on designing a page if the height of a text of certain width could be calculated in advance, depending of the font. Is there a way? As I fear, TeX's means "\setbox" woun't work with aligned texts. Best wishes, remain healthy, Rudolf
Rudolf Bahr schrieb am 24.03.2020 um 12:19:
Hello dear All,
the following MWE works best:
\definelayer[LAY] \starttext
\setlayerframed[LAY] [x=0pt,y=20pt] [frame=on, width=300pt, align={right,}] % tolerant}] {\input ward }
\flushlayer[LAY] \stoptext
Now, it could have a favourable effect on designing a page if the height of a text of certain width could be calculated in advance, depending of the font. Is there a way?
As I fear, TeX's means "\setbox" woun't work with aligned texts.
Can you give more details, I have no idea what you mean with aligned texts (layers?). Wolfgang
On Tue, Mar 24, 2020 at 03:56:18PM +0100, Wolfgang Schuster wrote:
Rudolf Bahr schrieb am 24.03.2020 um 12:19:
Hello dear All,
the following MWE works best:
\definelayer[LAY] \starttext
\setlayerframed[LAY] [x=0pt,y=20pt] [frame=on, width=300pt, align={right,}] % tolerant}] {\input ward } \flushlayer[LAY] \stoptext
Now, it could have a favourable effect on designing a page if the height of a text of certain width could be calculated in advance, depending of the font. Is there a way?
As I fear, TeX's means "\setbox" woun't work with aligned texts.
Can you give more details, I have no idea what you mean with aligned texts (layers?).
Wolfgang
Hi Wolfgang, With "aligned texts" I thought of "align={right,}]" in the above example or text which is "flushed right": \setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0 will both result in 0. With "unflushed" text this means will work perfectly. Sorry for the inconvinience to having been not very clear. Rudolf
On Tue, 24 Mar 2020, Rudolf Bahr wrote:
On Tue, Mar 24, 2020 at 03:56:18PM +0100, Wolfgang Schuster wrote:
Rudolf Bahr schrieb am 24.03.2020 um 12:19:
Hello dear All,
the following MWE works best:
\definelayer[LAY] \starttext
\setlayerframed[LAY] [x=0pt,y=20pt] [frame=on, width=300pt, align={right,}] % tolerant}] {\input ward } \flushlayer[LAY] \stoptext
Now, it could have a favourable effect on designing a page if the height of a text of certain width could be calculated in advance, depending of the font. Is there a way?
As I fear, TeX's means "\setbox" woun't work with aligned texts.
Can you give more details, I have no idea what you mean with aligned texts (layers?).
Wolfgang
Hi Wolfgang,
With "aligned texts" I thought of "align={right,}]" in the above example or text which is "flushed right":
\setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0 will both result in 0. With "unflushed" text this means will work perfectly.
You can do: \definelayer[LAY] \starttext \setbox\scratchbox=\vbox{\framed[width=300pt, align=flushleft]{\input ward\relax}} The height of the box is \the\ht\scratchbox; the width is \the\wd\scratchbox. \unvbox\scratchbox \setlayerframed[LAY][x=0pt, y=20pt][width=300pt, align=flushleft]{\input ward\relax} \flushlayer[LAY] \stoptext Aditya
On Tue, Mar 24, 2020 at 11:36:30AM -0400, Aditya Mahajan wrote:
You can do:
\definelayer[LAY]
\starttext
\setbox\scratchbox=\vbox{\framed[width=300pt, align=flushleft]{\input ward\relax}} The height of the box is \the\ht\scratchbox; the width is \the\wd\scratchbox. \unvbox\scratchbox
\setlayerframed[LAY][x=0pt, y=20pt][width=300pt, align=flushleft]{\input ward\relax} \flushlayer[LAY]
\stoptext
Aditya
Yes, that's essentially the same method I used, but I must have done a mistake with serious consequences concerning flushleft align text. And so I wrote to the list with my question. Thank you for your effort, Aditya! Rudolf
Rudolf Bahr schrieb am 24.03.2020 um 16:29:
On Tue, Mar 24, 2020 at 03:56:18PM +0100, Wolfgang Schuster wrote:
Rudolf Bahr schrieb am 24.03.2020 um 12:19:
Hello dear All,
the following MWE works best:
\definelayer[LAY] \starttext
\setlayerframed[LAY] [x=0pt,y=20pt] [frame=on, width=300pt, align={right,}] % tolerant}] {\input ward } \flushlayer[LAY] \stoptext
Now, it could have a favourable effect on designing a page if the height of a text of certain width could be calculated in advance, depending of the font. Is there a way?
As I fear, TeX's means "\setbox" woun't work with aligned texts.
Can you give more details, I have no idea what you mean with aligned texts (layers?).
Wolfgang
Hi Wolfgang,
With "aligned texts" I thought of "align={right,}]" in the above example or text which is "flushed right":
\setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0 will both result in 0. With "unflushed" text this means will work perfectly.
I have no idea where you get 0 (0pt?). \starttexdefinition NextboxDimension \starttabulate \NC Width \EQ \the\nextboxwd \NC\NR \NC Height \NC \the\nextboxht \NC\NR \stoptabulate \stoptexdefinition \starttext \dowithnextboxcs \NextboxDimension \vbox {\samplefile{ward}} \dowithnextboxcs \NextboxDimension \vbox {\setupalign[flushright] \samplefile{ward}} \dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \samplefile{ward}} \dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \setupalign[flushright] \samplefile{ward}} \stoptext Wolfgang
On Tue, Mar 24, 2020 at 04:43:17PM +0100, Wolfgang Schuster wrote:
\setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0 will both result in 0. With "unflushed" text this means will work perfectly.
I have no idea where you get 0 (0pt?).
Nor do I, in the meantime. Sorry for my noise, I don't know what sort of mistakes I did to get "0.0pt". Corona? :-) This is my test, which is essentially the same what Aditya suggests: ----------------------------------------- \starttext \setbox0=\vbox{\hsize=300pt\input ward } \copy0 wd0=\the\wd0, ht0=\the\ht0 \vskip12pt \startalign[flushleft] \setbox1=\vbox{\hsize=300pt\input ward } \stopalign \copy1 wd1=\the\wd1, ht1=\the\ht1 \stoptext ----------------------------------------- The .pdf-file is appended Now to your proposal, Wolfgang:
\starttexdefinition NextboxDimension \starttabulate \NC Width \EQ \the\nextboxwd \NC\NR \NC Height \NC \the\nextboxht \NC\NR \stoptabulate \stoptexdefinition
\starttext
\dowithnextboxcs \NextboxDimension \vbox {\samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\setupalign[flushright] \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \setupalign[flushright] \samplefile{ward}}
\stoptext
Up to now I cannot say anything about it, because there are some commands which are new to me. I have to study them first. Thank you for your effort! Rudolf
Rudolf Bahr schrieb am 24.03.2020 um 19:04:
On Tue, Mar 24, 2020 at 04:43:17PM +0100, Wolfgang Schuster wrote:
\setbox0=\vbox{... somehow flushed text ...} wount work, i.e \wd0 or \ht0 will both result in 0. With "unflushed" text this means will work perfectly.
I have no idea where you get 0 (0pt?).
Nor do I, in the meantime. Sorry for my noise, I don't know what sort of mistakes I did to get "0.0pt". Corona? :-)
This is my test, which is essentially the same what Aditya suggests: ----------------------------------------- \starttext
\setbox0=\vbox{\hsize=300pt\input ward } \copy0
wd0=\the\wd0, ht0=\the\ht0
\vskip12pt
\startalign[flushleft] \setbox1=\vbox{\hsize=300pt\input ward } \stopalign \copy1
wd1=\the\wd1, ht1=\the\ht1
\stoptext ----------------------------------------- The .pdf-file is appended
When you need the height for the layer offset you can use \dowithnextbox because it hides \setbox etc. \definelayer[TextBox] \showframe[text][text] \starttext \dowithnextbox {\setlayer [TextBox] [x=\the\dimexpr(\textwidth -\nextboxwd)/3\relax, y=\the\dimexpr(\textheight-\nextboxht)/3\relax] {\flushnextbox}} \hbox{\framed[width=300pt,align=normal]{\samplefile{ward}}} \flushlayer[TextBox] \stoptext
Now to your proposal, Wolfgang:
\starttexdefinition NextboxDimension \starttabulate \NC Width \EQ \the\nextboxwd \NC\NR \NC Height \NC \the\nextboxht \NC\NR \stoptabulate \stoptexdefinition
\starttext
\dowithnextboxcs \NextboxDimension \vbox {\samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\setupalign[flushright] \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \setupalign[flushright] \samplefile{ward}}
\stoptext
Up to now I cannot say anything about it, because there are some commands which are new to me. I have to study them first.
The \dowithnextbox command stores the passed argument in the named box \nextbox and performs the content of the first argument (or the command when you use \dowithnextbox*cs*). The get the width and height of the box you can use \wd\nextbox or the wrapper \nextboxwd. The content of the box can be flushed with \flushnextbox but when you need only a copy of it you have to use \copy\nextbox. Wolfgang
On Tue, Mar 24, 2020 at 07:29:26PM +0100, Wolfgang Schuster wrote:
When you need the height for the layer offset you can use \dowithnextbox because it hides \setbox etc.
\definelayer[TextBox]
\showframe[text][text]
\starttext
\dowithnextbox {\setlayer [TextBox] [x=\the\dimexpr(\textwidth -\nextboxwd)/3\relax, y=\the\dimexpr(\textheight-\nextboxht)/3\relax] {\flushnextbox}} \hbox{\framed[width=300pt,align=normal]{\samplefile{ward}}}
\flushlayer[TextBox]
\stoptext
Thank you! I played with the example a bit, all works well with one exception: When I replace "align=normal" by "align=left" the frame gets too wide at it's left edge. I append this pdf-file. But "align=right" works well and that's what I'm using most. Your Example is well suited to be used in page design!
\starttexdefinition NextboxDimension \starttabulate \NC Width \EQ \the\nextboxwd \NC\NR \NC Height \NC \the\nextboxht \NC\NR \stoptabulate \stoptexdefinition
\starttext
\dowithnextboxcs \NextboxDimension \vbox {\samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\setupalign[flushright] \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \samplefile{ward}}
\dowithnextboxcs \NextboxDimension \vbox {\hsize=200pt \setupalign[flushright] \samplefile{ward}}
\stoptext
The \dowithnextbox command stores the passed argument in the named box \nextbox and performs the content of the first argument (or the command when you use \dowithnextbox*cs*).
The get the width and height of the box you can use \wd\nextbox or the wrapper \nextboxwd. The content of the box can be flushed with \flushnextbox but when you need only a copy of it you have to use \copy\nextbox.
Wolfgang
Thank you very much for the example and the explanation therefore! It should be well suitable to evaluate width and height of boxes and to pass them to luacode programs by 'tokens.getters.macro("...")' for instance. Thank you again! Rudolf
participants (3)
-
Aditya Mahajan
-
Rudolf Bahr
-
Wolfgang Schuster