\definemeasure / \dimexpr
I’m constantly struggling with dimension calculations. Is there anything I can read about the possibilities and limitations? e.g. with \definemeasure[PageWidth][132mm] none of the following works: \definemeasure[FlapWidth][0.8 * \measure{PageWidth}] \definemeasure[FlapWidth][.8\measure{PageWidth}] \definemeasure[FlapWidth][\measure{PageWidth} * 0.8] \definemeasure[FlapWidth][\measure{PageWidth}*8/10] \definemeasure[FlapWidth][8\measure{PageWidth}/10] Hraban
On 11/3/2022 9:32 PM, Henning Hraban Ramm via ntg-context wrote:
I’m constantly struggling with dimension calculations. Is there anything I can read about the possibilities and limitations?
e.g. with \definemeasure[PageWidth][132mm] none of the following works: \definemeasure[FlapWidth][0.8 * \measure{PageWidth}]
use \measured (with a "d" to get a dimension)
\definemeasure[FlapWidth][.8\measure{PageWidth}] \definemeasure[FlapWidth][\measure{PageWidth} * 0.8] \definemeasure[FlapWidth][\measure{PageWidth}*8/10] \definemeasure[FlapWidth][8\measure{PageWidth}/10]
Hraban ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am 03.11.22 um 21:51 schrieb Hans Hagen via ntg-context:
On 11/3/2022 9:32 PM, Henning Hraban Ramm via ntg-context wrote:
I’m constantly struggling with dimension calculations. Is there anything I can read about the possibilities and limitations?
e.g. with \definemeasure[PageWidth][132mm] none of the following works: \definemeasure[FlapWidth][0.8 * \measure{PageWidth}]
use \measured (with a "d" to get a dimension)
Only in expressions like that or always? In https://source.contextgarden.net/syst-aux.mkiv it looks like \measured returns a dimension, while \measure returns a string (\the\measured), is this right? So I should use \measure{} in setup keyvals, and \measured in dim expressions? Now, when I use calculated measures for a page size, I get: """ You can't use '\dimexpr' in horizontal mode """ Hraban
Am 03.11.22 um 22:43 schrieb Henning Hraban Ramm via ntg-context:
Am 03.11.22 um 21:51 schrieb Hans Hagen via ntg-context:
On 11/3/2022 9:32 PM, Henning Hraban Ramm via ntg-context wrote:
I’m constantly struggling with dimension calculations. Is there anything I can read about the possibilities and limitations?
e.g. with \definemeasure[PageWidth][132mm] none of the following works: \definemeasure[FlapWidth][0.8 * \measure{PageWidth}]
use \measured (with a "d" to get a dimension)
Only in expressions like that or always?
In https://source.contextgarden.net/syst-aux.mkiv it looks like \measured returns a dimension, while \measure returns a string (\the\measured), is this right?
So I should use \measure{} in setup keyvals, and \measured in dim expressions?
Now, when I use calculated measures for a page size, I get: """ You can't use '\dimexpr' in horizontal mode """
Here’s my MWE: """ \definemeasure[PageWidth][132mm] \definemeasure[FlapWidth][\measured{PageWidth} * 0.8] \starttext FlapWidth: \measure{FlapWidth} \stoptext """ Results in: FlapWidth: 0.0pt.8 Longer example attached. Hraban
Am 04.11.22 um 11:37 schrieb Henning Hraban Ramm via ntg-context:
Am 03.11.22 um 22:43 schrieb Henning Hraban Ramm via ntg-context:
Am 03.11.22 um 21:51 schrieb Hans Hagen via ntg-context:
On 11/3/2022 9:32 PM, Henning Hraban Ramm via ntg-context wrote:
I’m constantly struggling with dimension calculations. Is there anything I can read about the possibilities and limitations?
e.g. with \definemeasure[PageWidth][132mm] none of the following works: \definemeasure[FlapWidth][0.8 * \measure{PageWidth}]
use \measured (with a "d" to get a dimension)
Only in expressions like that or always?
In https://source.contextgarden.net/syst-aux.mkiv it looks like \measured returns a dimension, while \measure returns a string (\the\measured), is this right?
So I should use \measure{} in setup keyvals, and \measured in dim expressions?
Now, when I use calculated measures for a page size, I get: """ You can't use '\dimexpr' in horizontal mode """
Here’s my MWE: """ \definemeasure[PageWidth][132mm]
\definemeasure[FlapWidth][\measured{PageWidth} * 0.8]
\definemeasure[FlapWidth][0.8\measured{PageWidth}] works Herbert
\starttext
FlapWidth: \measure{FlapWidth}
\stoptext """
Results in:
FlapWidth: 0.0pt.8
Longer example attached.
Hraban
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________
Am 04.11.22 um 11:52 schrieb Herbert Voss via ntg-context:
\definemeasure[FlapWidth][\measured{PageWidth} * 0.8]
\definemeasure[FlapWidth][0.8\measured{PageWidth}] works
Yes, thank you! That’s why I asked for the basics in my first post – which operators can I use how, in which order? In my "real work" layout, the above approach was not always possible. I looked into “TeX by topic”, but Eijkhout shows only how to use \multiply and \advance. (Tried that, worked only partly.) I was also thinking about doing the whole thing in Lua (CLD), but it’s mostly setups, and those are usually easier in TeX. (And I’m not sure how to handle dimensions in Lua.) Hraban
One problem left with dimensions that I can’t reproduce in a minimal example: I want to calculate the spine width of the cover from the number of content pages: \useexternalfigure[CONTENT][book.pdf] \getfiguredimensions[CONTENT] \definemeasure[SpineWidth][2mm + (0.135mm * \noffigurepages/2)] That works so far, if I output \measure{SpineWidth} it shows the right size (~42pt). But if I use this measure in \setlayer[width=\measure{SpineWidth}]{...} it’s very small. I guess \noffigurepages is 1 at that point (from another image) and I’d need to expand it first. Am I right that the expansion happens only at the “execution” of \measure? How would I do that? \expanded\noffigurepages doesn’t work. Another issue: 0.135mm is the paper thickness of 90 g/m² (= 0.09mm per sheet) with 1.5 bulk. But \definemeasure[SpineWidth][2mm + (0.09mm * 1.5 * 90)] doesn’t work: """ Missing ) inserted for expression <to be read again> . <macro> \commalistcommand 2mm + (0.09mm * 1. 5 * \noffigurepages /2) <macro> \measured #1->\dimexpr \ifcsname \??measure #1\endcsname \lastnamedcs \else \zeropoint \fi \relax ... """ I also tried 1.5sp since sp should be 1, but it didn’t help. Hraban
Henning Hraban Ramm via ntg-context schrieb am 13.11.2022 um 11:37:
One problem left with dimensions that I can’t reproduce in a minimal example:
I want to calculate the spine width of the cover from the number of content pages:
\useexternalfigure[CONTENT][book.pdf] \getfiguredimensions[CONTENT] \definemeasure[SpineWidth][2mm + (0.135mm * \noffigurepages/2)]
You can try \expanded{\definemeasure[SpineWidth][...]}
That works so far, if I output \measure{SpineWidth} it shows the right size (~42pt).
But if I use this measure in \setlayer[width=\measure{SpineWidth}]{...} it’s very small. I guess \noffigurepages is 1 at that point (from another image) and I’d need to expand it first.
Am I right that the expansion happens only at the “execution” of \measure? How would I do that? \expanded\noffigurepages doesn’t work.
Another issue:
0.135mm is the paper thickness of 90 g/m² (= 0.09mm per sheet) with 1.5 bulk. But \definemeasure[SpineWidth][2mm + (0.09mm * 1.5 * 90)] doesn’t work:
You can use integers to multiply or divide a length, a float is only allowed before a length. e.g. 1.5\scratchdimen or 1.5\dimexpr ...\relax In your case you have to use \definemeasure[SpineWidth][2mm + (0.09mm * 3 * 90 / 2)] or \definemeasure[SpineWidth][2mm + (0.09mm * 135)] Wolfgang
Yes! Finally! Thank you, Wolfgang! Am 13.11.22 um 13:17 schrieb Wolfgang Schuster via ntg-context:
Henning Hraban Ramm via ntg-context schrieb am 13.11.2022 um 11:37:
\definemeasure[SpineWidth][2mm + (0.135mm * \noffigurepages/2)]
You can try \expanded{\definemeasure[SpineWidth][...]}
Yes, that works. I could have thought of that myself.
\definemeasure[SpineWidth][2mm + (0.09mm * 1.5 * 90)] doesn’t work:
You can use integers to multiply or divide a length, a float is only allowed before a length. e.g. 1.5\scratchdimen or 1.5\dimexpr ...\relax
In your case you have to use
\definemeasure[SpineWidth][2mm + (0.09mm * 3 * 90 / 2)]
or
\definemeasure[SpineWidth][2mm + (0.09mm * 135)]
Ah, the float/int usage was the missing link. Now I can document my calculated cover for wiki, CG journal, my book, DTK... Hraban
participants (4)
-
Hans Hagen
-
Henning Hraban Ramm
-
Herbert Voss
-
Wolfgang Schuster