ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Otared Kavian <otared@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: How to define a command...
Date: Thu, 5 Jan 2012 22:24:06 +0100	[thread overview]
Message-ID: <43565B01-31F5-41C8-AF85-60AFA0826805@gmail.com> (raw)
In-Reply-To: <E006D28C-22C2-4A91-8037-83A5AD01A15D@googlemail.com>

Hi again Wolfgang and Peter,

The solution you provided to my problem is great but has a small issue…
Considering the definition

\define[3]\RandomCoeff{%
	\setvalue{Coeff#1}{\ctxlua{tex.print(math.random(#2,#3))}}
	}

after saying 
	\RandomCoeff{Alpha}{1}{10}
one gets \CoeffAlpha, but if I use several times \CoeffAlpha, it takes a new value each time, an effect which is undesirable in what I am willing to do.
Is there a way to somehow « freeze » the value of \CoeffAlpha once it is defined?

Best regards: OK
PS: here is the complete example:

\define[3]\RandomCoeff{%
	\setvalue{Coeff#1}{\ctxlua{tex.print(math.random(#2,#3))}}
	}

\starttext
\RandomCoeff{Alpha}{1}{10}
\RandomCoeff{Beta}{10}{100}

\CoeffAlpha

\CoeffBeta

\CoeffAlpha

\CoeffBeta

\stoptext

On 5 janv. 2012, at 21:18, Wolfgang Schuster wrote:

> 
> Am 05.01.2012 um 21:17 schrieb Peter Münster:
> 
>> On Thu, Jan 05 2012, Otared Kavian wrote:
>> 
>>> \define[3]\RandomCoeff{%
>>> 	\ctxlua{a = math.random(#2,#3)}
>>> %	\csname{Coeff#1}\endcsname{\ctxlua{tex.print(a)}} %% this line does not work as expected...
>> 
>> \setuprandomize[2012]
>> \define[3]\RandomCoeff{%
>> \expandafter\def\csname Coeff#1\endcsname{\ctxlua{tex.print(math.random(#2,#3))}}}
> 
> \setvalue{Coeff#1}{…}
> 
> 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  parent reply	other threads:[~2012-01-05 21:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05 20:05 Otared Kavian
2012-01-05 20:11 ` Meer, H. van der
2012-01-05 20:21   ` Wolfgang Schuster
2012-01-05 20:28   ` Otared Kavian
2012-01-05 20:17 ` Peter Münster
2012-01-05 20:18   ` Wolfgang Schuster
2012-01-05 20:42     ` Otared Kavian
2012-01-05 21:24     ` Otared Kavian [this message]
2012-01-05 21:36       ` Otared Kavian
2012-01-05 20:29   ` Otared Kavian

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=43565B01-31F5-41C8-AF85-60AFA0826805@gmail.com \
    --to=otared@gmail.com \
    --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).