ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \definemeasure / \dimexpr
@ 2022-11-03 20:32 Henning Hraban Ramm via ntg-context
  2022-11-03 20:51 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-03 20:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-03 20:32 \definemeasure / \dimexpr Henning Hraban Ramm via ntg-context
@ 2022-11-03 20:51 ` Hans Hagen via ntg-context
  2022-11-03 21:43   ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Hans Hagen via ntg-context @ 2022-11-03 20:51 UTC (permalink / raw)
  To: Henning Hraban Ramm via ntg-context; +Cc: Hans Hagen

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
-----------------------------------------------------------------

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-03 20:51 ` Hans Hagen via ntg-context
@ 2022-11-03 21:43   ` Henning Hraban Ramm via ntg-context
  2022-11-04 10:37     ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-03 21:43 UTC (permalink / raw)
  To: Hans Hagen via ntg-context; +Cc: Henning Hraban Ramm

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-03 21:43   ` Henning Hraban Ramm via ntg-context
@ 2022-11-04 10:37     ` Henning Hraban Ramm via ntg-context
  2022-11-04 10:52       ` Herbert Voss via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-04 10:37 UTC (permalink / raw)
  To: ntg-context; +Cc: Henning Hraban Ramm

[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]

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

[-- Attachment #2: covertest.tex --]
[-- Type: application/x-tex, Size: 1315 bytes --]

[-- Attachment #3: Type: text/plain, Size: 496 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-04 10:37     ` Henning Hraban Ramm via ntg-context
@ 2022-11-04 10:52       ` Herbert Voss via ntg-context
  2022-11-04 11:09         ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Herbert Voss via ntg-context @ 2022-11-04 10:52 UTC (permalink / raw)
  To: Henning Hraban Ramm via ntg-context; +Cc: Herbert Voss



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
> ___________________________________________________________________________________

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-04 10:52       ` Herbert Voss via ntg-context
@ 2022-11-04 11:09         ` Henning Hraban Ramm via ntg-context
  2022-11-13 10:37           ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-04 11:09 UTC (permalink / raw)
  To: Herbert Voss via ntg-context; +Cc: Henning Hraban Ramm

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-04 11:09         ` Henning Hraban Ramm via ntg-context
@ 2022-11-13 10:37           ` Henning Hraban Ramm via ntg-context
  2022-11-13 12:17             ` Wolfgang Schuster via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-13 10:37 UTC (permalink / raw)
  To: ntg-context; +Cc: Henning Hraban Ramm

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-13 10:37           ` Henning Hraban Ramm via ntg-context
@ 2022-11-13 12:17             ` Wolfgang Schuster via ntg-context
  2022-11-13 14:31               ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Schuster via ntg-context @ 2022-11-13 12:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Wolfgang Schuster

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

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: \definemeasure / \dimexpr
  2022-11-13 12:17             ` Wolfgang Schuster via ntg-context
@ 2022-11-13 14:31               ` Henning Hraban Ramm via ntg-context
  0 siblings, 0 replies; 9+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2022-11-13 14:31 UTC (permalink / raw)
  To: ntg-context; +Cc: Henning Hraban Ramm

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
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-13 14:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 20:32 \definemeasure / \dimexpr Henning Hraban Ramm via ntg-context
2022-11-03 20:51 ` Hans Hagen via ntg-context
2022-11-03 21:43   ` Henning Hraban Ramm via ntg-context
2022-11-04 10:37     ` Henning Hraban Ramm via ntg-context
2022-11-04 10:52       ` Herbert Voss via ntg-context
2022-11-04 11:09         ` Henning Hraban Ramm via ntg-context
2022-11-13 10:37           ` Henning Hraban Ramm via ntg-context
2022-11-13 12:17             ` Wolfgang Schuster via ntg-context
2022-11-13 14:31               ` Henning Hraban Ramm via ntg-context

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).