ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Define color with calculations
@ 2019-02-18  3:37 Mohammad Hossein Bateni
  2019-02-18  4:02 ` Henri Menke
  2019-02-18 21:33 ` Wolfgang Schuster
  0 siblings, 2 replies; 5+ messages in thread
From: Mohammad Hossein Bateni @ 2019-02-18  3:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 176 bytes --]

Hi,

When I use definecolor, (how) can I use computations in setting the value
of a component?  Something like the following...

\definecolor[mycolor][r=0.5*0.7]

Thanks,
~MHB

[-- Attachment #1.2: Type: text/html, Size: 281 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: Define color with calculations
  2019-02-18  3:37 Define color with calculations Mohammad Hossein Bateni
@ 2019-02-18  4:02 ` Henri Menke
  2019-02-18 16:44   ` Mohammad Hossein Bateni
  2019-02-18 21:33 ` Wolfgang Schuster
  1 sibling, 1 reply; 5+ messages in thread
From: Henri Menke @ 2019-02-18  4:02 UTC (permalink / raw)
  To: ntg-context

Use Lua.


\def\eval#1{\ctxlua{%
    local context = context
    local _ENV = math
    context(#1)
}}

\definecolor[mycolor][r=\eval{0.5*0.7}]

\starttext

\color[mycolor]{Hello!}

\stoptext



On 18/02/19 4:37 PM, Mohammad Hossein Bateni wrote:
> Hi,
> 
> When I use definecolor, (how) can I use computations in setting the value
> of a component?  Something like the following...
> 
> \definecolor[mycolor][r=0.5*0.7]
> 
> Thanks,
> ~MHB
> 
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
> 

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

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

* Re: Define color with calculations
  2019-02-18  4:02 ` Henri Menke
@ 2019-02-18 16:44   ` Mohammad Hossein Bateni
  0 siblings, 0 replies; 5+ messages in thread
From: Mohammad Hossein Bateni @ 2019-02-18 16:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1663 bytes --]

Thanks, Henri!  Works like a charm.

On Sun, Feb 17, 2019 at 11:03 PM Henri Menke <henrimenke@gmail.com> wrote:

> Use Lua.
>
>
> \def\eval#1{\ctxlua{%
>     local context = context
>     local _ENV = math
>     context(#1)
> }}
>
> \definecolor[mycolor][r=\eval{0.5*0.7}]
>
> \starttext
>
> \color[mycolor]{Hello!}
>
> \stoptext
>
>
>
> On 18/02/19 4:37 PM, Mohammad Hossein Bateni wrote:
> > Hi,
> >
> > When I use definecolor, (how) can I use computations in setting the value
> > of a component?  Something like the following...
> >
> > \definecolor[mycolor][r=0.5*0.7]
> >
> > Thanks,
> > ~MHB
> >
> >
> >
> ___________________________________________________________________________________
> > 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
> >
> ___________________________________________________________________________________
> >
>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 3100 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: Define color with calculations
  2019-02-18  3:37 Define color with calculations Mohammad Hossein Bateni
  2019-02-18  4:02 ` Henri Menke
@ 2019-02-18 21:33 ` Wolfgang Schuster
  2019-02-18 21:38   ` Henri Menke
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2019-02-18 21:33 UTC (permalink / raw)
  To: mailing users

Mohammad Hossein Bateni schrieb am 18.02.19 um 04:37:
> Hi,
> 
> When I use definecolor, (how) can I use computations in setting the 
> value of a component?  Something like the following...
> 
> \definecolor[mycolor][r=0.5*0.7]

\starttext

\colored[r=\cldcontext{0.5*0.7}]{\cldcontext{0.5*0.7}}

\colored[r=\cldcontext{"\letterpercent 
.3f",0.5*0.7}]{\cldcontext{"\letterpercent .3f",0.5*0.7}}

\stoptext

Wolfgang

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

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

* Re: Define color with calculations
  2019-02-18 21:33 ` Wolfgang Schuster
@ 2019-02-18 21:38   ` Henri Menke
  0 siblings, 0 replies; 5+ messages in thread
From: Henri Menke @ 2019-02-18 21:38 UTC (permalink / raw)
  To: ntg-context

On 19/02/19 10:33 AM, Wolfgang Schuster wrote:
> Mohammad Hossein Bateni schrieb am 18.02.19 um 04:37:
>> Hi,
>>
>> When I use definecolor, (how) can I use computations in setting the
>> value of a component?  Something like the following...
>>
>> \definecolor[mycolor][r=0.5*0.7]
> 
> \starttext
> 
> \colored[r=\cldcontext{0.5*0.7}]{\cldcontext{0.5*0.7}}
> 
> \colored[r=\cldcontext{"\letterpercent
> .3f",0.5*0.7}]{\cldcontext{"\letterpercent .3f",0.5*0.7}}
> 
> \stoptext
> 

Better use \luaexpr.  From the manual:

The \luaexpr command can also better deal with for instance conditions,
 where it returns true or false , while \cldcontext would interpret the
 boolean value as a special signal.

Although I think my solution is superior because you can just type

   \eval{1.0*sin(pi)}

instead of

   \eval{1.0*math.sin(math.pi)}

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

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

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

end of thread, other threads:[~2019-02-18 21:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-18  3:37 Define color with calculations Mohammad Hossein Bateni
2019-02-18  4:02 ` Henri Menke
2019-02-18 16:44   ` Mohammad Hossein Bateni
2019-02-18 21:33 ` Wolfgang Schuster
2019-02-18 21:38   ` Henri Menke

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