From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/73636 Path: news.gmane.org!not-for-mail From: Otared Kavian Newsgroups: gmane.comp.tex.context Subject: Re: How to define a command... Date: Thu, 5 Jan 2012 21:28:43 +0100 Message-ID: References: <6457E519-6F30-482B-98DC-08BD546F8B2F@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1325795343 27026 80.91.229.12 (5 Jan 2012 20:29:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 20:29:03 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jan 05 21:28:59 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ritvk-0006CF-TS for gctc-ntg-context-518@m.gmane.org; Thu, 05 Jan 2012 21:28:56 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DC52CCB1E1; Thu, 5 Jan 2012 21:28:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2sWI3eQJ-tWd; Thu, 5 Jan 2012 21:28:53 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 66AA3CB1DC; Thu, 5 Jan 2012 21:28:53 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 671B9CB1DC for ; Thu, 5 Jan 2012 21:28:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id phUH8wIPWgZa for ; Thu, 5 Jan 2012 21:28:49 +0100 (CET) Original-Received: from filter4-nij.mf.surf.net (filter4-nij.mf.surf.net [195.169.124.155]) by balder.ntg.nl (Postfix) with ESMTP id BBAC7CB1DB for ; Thu, 5 Jan 2012 21:28:49 +0100 (CET) Original-Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by filter4-nij.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q05KSmNZ000594 for ; Thu, 5 Jan 2012 21:28:48 +0100 Original-Received: by wibhq12 with SMTP id hq12so923097wib.14 for ; Thu, 05 Jan 2012 12:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=6j87D6rOxOm/DvE8uGK/4hJ0AcZf34fXRmnX75+DtFs=; b=IkPPypwbLI/drG5ust0ElGz0kuzLdHJT9YmvSl2VuzMJBDQp6cn16E1qGrOVQch0/5 EAdd9TBq1Ex8DObG8yqK1vPDQhfl89T60V2ZbOF/vy4wORQEYpuRj4vWbgVdKvLF6Jb1 lcpQNm7CZm6KKEpCSxn8fvOin5mNz2yC9AVxo= Original-Received: by 10.180.82.41 with SMTP id f9mr2702927wiy.7.1325795326542; Thu, 05 Jan 2012 12:28:46 -0800 (PST) Original-Received: from [192.168.0.11] (seg75-6-82-236-32-4.fbx.proxad.net. [82.236.32.4]) by mx.google.com with ESMTPS id g26sm39430543wbo.16.2012.01.05.12.28.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jan 2012 12:28:45 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.1251.1) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.212.169; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 04GhUsMEJ - 93ff0c01a9b3 - 20120105 X-Scanned-By: CanIt (www . roaringpenguin . com) on 195.169.124.155 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:73636 Archived-At: Thanks Hans, in another problem I was looking for commands such as \RandomRange, \RandomSeries: I am going to use your ideas! It is incredible that on this list one gets solutions even for problems one didn't dare to ask :-) Best regards: OK On 5 janv. 2012, at 21:11, Meer, H. van der wrote: > Reccently I did something random in ctxlua. I post it in the hope it will be useful. > > Hans van der Meer > > \startluacode > -- Define our namespace as hvdm > hvdm = hvdm or {} > > -- Return random series of numbers 1..n depending on the number of arguments > function hvdm.randomseries (n, straight) > local done = {} > for i = 1, n do > done[i] = i > end > if straight == "false" then > return table.concat(done,",") > end > local result = "" > for i = n, 2, -1 do > local r = math.random(i) > result = result .. done[r] .. "," > table.remove(done,r) > end > result = result .. done[1] > return result > end > \stopluacode > \def\RandomSeed#1{\directlua{math.randomseed(#1)}} > \def\RandomValue{\directlua{tex.print(math.random())}} > \def\RandomRange#1{\directlua{tex.print(math.random(#1))}} > \def\RandomSeries[#1]#2{\ctxlua{tex.print(hvdm.randomseries(#2,"#1"))}% > > > On 5 jan. 2012, at 21:05, Otared Kavian wrote: > >> 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 >> ___________________________________________________________________________________ > > ___________________________________________________________________________________ > 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 > ___________________________________________________________________________________ ___________________________________________________________________________________ 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 ___________________________________________________________________________________