ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to define a command...
@ 2012-01-05 20:05 Otared Kavian
  2012-01-05 20:11 ` Meer, H. van der
  2012-01-05 20:17 ` Peter Münster
  0 siblings, 2 replies; 10+ messages in thread
From: Otared Kavian @ 2012-01-05 20:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi all,

I need to define numerical coefficients (essentially at random) and then use them with commands, say like \CoeffAlpha, \CoeffBeta, and so on.
More precisely, how can I define the command \RandomCoeff, so that \RandomCoeff{Beta}{1}{10} yields a command named \CoeffBeta, which is a random number chosen between 1 and 10?

I tried to use the following approach, but could not make it work:

%%% begin random-coeff.tex
\setuprandomize[2012] % set a seed 

\ctxlua{CoeffAlpha = math.random(1,10) ;}
\def\CoeffAlpha{\ctxlua{tex.print(CoeffAlpha)}}

%%%%%
\define[3]\RandomCoeff{%
	\ctxlua{a = math.random(#2,#3)}
%	\csname{Coeff#1}\endcsname{\ctxlua{tex.print(a)}} %% this line does not work as expected...
	}

\starttext
\CoeffAlpha

\RandomCoeff{Beta}{1}{10}

\ctxlua{tex.print(a)}

%\CoeffBeta

\stoptext
%%% end random-coeff.tex

Thanks in advance for any suggestion or hint.
Best regards: OK

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


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

end of thread, other threads:[~2012-01-05 21:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-05 20:05 How to define a command 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
2012-01-05 21:36       ` Otared Kavian
2012-01-05 20:29   ` Otared Kavian

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