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: A macro which gives a random name
Date: Sat, 18 Apr 2015 21:16:47 +0200	[thread overview]
Message-ID: <9596E5D7-A917-42AE-A182-08D134E1D505@gmail.com> (raw)
In-Reply-To: <088338A7-A713-415A-9DF5-26804CDA9C7F@gmail.com>


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

Hi Wolfgang,

Thanks for your attention, but the problem with your solution is that each instance of \RandomFunctionName changes the name chosen, but I need something wihich remains the same name within a given situation (say each problem) but changes from problem to problem. 

For instance when using your solution with the source code

	Give an example of a function $\RandomFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a 
	derivative only at the origin, and such that $\RandomFunctionName(0) = 1$.
gives:
	Give an example of a function 𝐺 : R ⟶ R which has a derivative only at the origin, and such that 𝑊(0) = 1. 

while what I need is 
	Give an example of a function 𝐺 : R ⟶ R which has a derivative only at the origin, and such that G(0) = 1. 

(The macro I sent earlier does this, but unfortunately it cannot use the solution you sent).
Is there a solution ?

Best regards: OK

> On 18 Apr 2015, at 19:23, Wolfgang Schuster <schuster.wolfgang@gmail.com> wrote:
> 
> 
>> Am 18.04.2015 um 18:55 schrieb Otared Kavian <otared@gmail.com>:
>> 
>> Hi everyone,
>> 
>> In the example below I define a macro which chooses at random a name from a list of names. But I wonder whether this can be done in a more clever way without using a numerical macro created with math.random in Lua. The shortcoming of the macro below is that before hand I must know the nomber of elements in the list of names (for instance 5 in the example below), while it may happen that I need to create as many as random names that there are elements in the list, but sometimes I don’t know what is this number.
>> 
>> Thanks for any insight and help.
>> Best regards: OK
>> %%%% begin random-names.tex
>> \setuprandomize[2015] % set a seed
>> 
>> \starttext
>> 
>> \startluacode
>> 	Name = {'F', 'G', 'u', 'v', 'W'}
>> \stopluacode
>> 
>> \define[3]\RandomName{%
>> 	\setevalue{Named#1}{\ctxlua{tex.print(math.random(#2,#3))}}}
>> \define\RandomFunctionName{\ctxlua{tex.print(Name[\NamedFunctionNumber])}}
>> 
>> \dorecurse{10}{\RandomName{FunctionNumber}{1}{5}%
>> Give an example of a function $\RandomFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\RandomFunctionName(0) = 1$.\par \hairline\par}
>> 
>> \stoptext
>> %%%% begin random-names.tex
> 
> You can access the size of your Name table with #Name but have to replace # with \letterhash when you use it in a TeX command because # is already taken for the TeX arguments.
> 
> \starttext
> 
> \startluacode
> 	Name = {'F', 'G', 'u', 'v', 'W'}
> \stopluacode
> 
> \define\RandomFunctionName
>  {\startlua
>   local listsize    = \letterhash Name ;
>   local randomvalue = math.random(1,listsize) ;
>   context(Name[randomvalue])
>   \stoplua}
> 
> \dorecurse{10}{Give an example of a function $\RandomFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\RandomFunctionName(0) = 1$.\par \hairline\par}
> 
> \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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________


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

[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2015-04-18 19:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-18 16:55 Otared Kavian
2015-04-18 17:23 ` Wolfgang Schuster
2015-04-18 19:16   ` Otared Kavian [this message]
2015-04-18 20:24   ` Otared Kavian
2015-04-18 20:36     ` Hans Hagen
2015-04-19  7:51       ` Otared Kavian
2015-04-19  9:55         ` Hans Hagen

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=9596E5D7-A917-42AE-A182-08D134E1D505@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).