Re: [NTG-context] A macro which gives a random name
Hi Hans, Many thanks for your wonderful code… I modified a little bit the names you use in your code so that it may be used for other purposes as well (for instance if one wishes to select at random a certain number of exercises from different subsets among a huge a dataset of problems). Again, for other people's possible needs, I put the modified code below (I don’t know in what category one might put your solution on the Wiki). If I may ask three questions in order to understand better your code, I would like to know 1) Why is it necessary to have this line (please see below) local ListOfNames = { G , W » } in the luacode. Is it only a sort of intitialisation? 2) You use a built-in function utilities.parsers.settings_to_array(list) is it a ConTeXt function defined somewhere in the core, or a Lua function? 3) Assuming one has a list of names in a file names (say in a comma separated format) in a file named my-list.tex how is it possible to use it in \SetListOfFunctionNames? Using \SetListOfFunctionNames[\input named my-list.tex] results in an error since \directlua does not accept \input. Best regards: OK begin choose-random-names.tex by Hans \startluacode local ListOfNames = { G , W } local ChosenName = ListOfNames[1] function document.SetListOfNames(list) ListOfNames = utilities.parsers.settings_to_array(list) end function document.GetChosenName(new) if new then ChosenName = ListOfNames[math.random(1,#ListOfNames)] end context(ChosenName) end \stopluacode \def\SetListOfFunctionNames[#1]{\ctxlua{document.SetListOfNames(#1)}} \def\NewFunctionName {\ctxlua{document.GetChosenName(true)}} \def\FunctionName {\ctxlua{document.GetChosenName()}} \SetListOfFunctionNames[a,b,c,d] \dorecurse{10}{ Give an example of a function $\NewFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\FunctionName(0) = 1$. \par \hairline\par } \stoptext end choose-random-names.tex by Hans On 18 Apr 2015, at 22:36, Hans Hagen pra...@wxs.nl wrote: On 4/18/2015 10:24 PM, Otared Kavian wrote: Hi again Wolfgang, Thanks to your hint, I could solve the problem… In case someone else would encounter a similar problem to solve, below is a macro which chooses an element from a list, it creates a control sequence (CS) containing that element and it keeps the CS until the next time the macro is invoked again to choose another element. Thanks again and best regards: OK begin choose-element.tex \setuprandomize[1989] % set a seed \starttext % here is a list from which a name is chosen \startluacode ListOfNames = {'F', 'G', 'u', 'v', 'W'} \stopluacode % this macro has two arguments: % the first argument is the control sequence name attached to Chosen, % the second argument is the name of the list from which something is chosen \define[2]\RandomChoice{% \setevalue{Chosen#1}{\ctxlua{% local listsize = \letterhash #2 ; local LName = #2 ; tex.print(LName[math.random(1,listsize)])}}} \dorecurse{10}{\RandomChoice{Function}{ListOfNames}% Give an example of a function $\ChosenFunction : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that ${\ChosenFunction}'(0) = 1$.\par \hairline\par} \stoptext end choose-element.tex \starttext \startluacode local FunctionNames = { G , W } local FunctionName = FunctionNames[1] function document.SetFunctionNames(list) FunctionNames = utilities.parsers.settings_to_array(list) end function document.GetFunctionName(new) if new then FunctionName = FunctionNames[math.random(1,#FunctionNames)] end context(FunctionName) end \stopluacode \def\SetFunctionNames[#1]{\ctxlua{document.SetFunctionNames(#1)}} \def\NewFunctionName {\ctxlua{document.GetFunctionName(true)}} \def\GetFunctionName {\ctxlua{document.GetFunctionName()}} \SetFunctionNames[a,b,c,d] \dorecurse{10}{ Give an example of a function $\NewFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\GetFunctionName(0) = 1$. \par \hairline\par } \stoptext On 18 Apr 2015, at 19:23, Wolfgang Schuster schuster.wolfg...@gmail.com wrote: Am 18.04.2015 um 18:55 schrieb Otared Kavian ota...@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
Re: [NTG-context] A macro which gives a random name
On 4/19/2015 9:51 AM, Otared Kavian wrote: Hi Hans, Many thanks for your wonderful code… I modified a little bit the names you use in your code so that it may be used for other purposes as well (for instance if one wishes to select at random a certain number of exercises from different subsets among a huge a dataset of problems). Again, for other people's possible needs, I put the modified code below (I don’t know in what category one might put your solution on the Wiki). If I may ask three questions in order to understand better your code, I would like to know 1) Why is it necessary to have this line (please see below) local ListOfNames = { G , W » } in the luacode. Is it only a sort of intitialisation? i just wanted a starting point (after all you put them in there) but you can start out local ListOfNames = { unset } 2) You use a built-in function utilities.parsers.settings_to_array(list) is it a ConTeXt function defined somewhere in the core, or a Lua function? no, one of the context ones (see cld manual for more) ... lots of such helpers 3) Assuming one has a list of names in a file names (say in a comma separated format) in a file named my-list.tex how is it possible to use it in \SetListOfFunctionNames? Using \SetListOfFunctionNames[\input named my-list.tex] results in an error since \directlua does not accept \input. something string.strip(io.loaddata(resolvers.findfile(foo.txt))) or \cldloadfile{foo.txt} Best regards: OK begin choose-random-names.tex by Hans \startluacode local ListOfNames = { G , W } local ChosenName = ListOfNames[1] function document.SetListOfNames(list) ListOfNames = utilities.parsers.settings_to_array(list) end function document.GetChosenName(new) if new then ChosenName = ListOfNames[math.random(1,#ListOfNames)] end context(ChosenName) end \stopluacode \def\SetListOfFunctionNames[#1]{\ctxlua{document.SetListOfNames(#1)}} \def\NewFunctionName {\ctxlua{document.GetChosenName(true)}} \def\FunctionName {\ctxlua{document.GetChosenName()}} \SetListOfFunctionNames[a,b,c,d] \dorecurse{10}{ Give an example of a function $\NewFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\FunctionName(0) = 1$. \par \hairline\par } \stoptext end choose-random-names.tex by Hans On 18 Apr 2015, at 22:36, Hans Hagen pra...@wxs.nl wrote: On 4/18/2015 10:24 PM, Otared Kavian wrote: Hi again Wolfgang, Thanks to your hint, I could solve the problem… In case someone else would encounter a similar problem to solve, below is a macro which chooses an element from a list, it creates a control sequence (CS) containing that element and it keeps the CS until the next time the macro is invoked again to choose another element. Thanks again and best regards: OK begin choose-element.tex \setuprandomize[1989] % set a seed \starttext % here is a list from which a name is chosen \startluacode ListOfNames = {'F', 'G', 'u', 'v', 'W'} \stopluacode % this macro has two arguments: % the first argument is the control sequence name attached to Chosen, % the second argument is the name of the list from which something is chosen \define[2]\RandomChoice{% \setevalue{Chosen#1}{\ctxlua{% local listsize = \letterhash #2 ; local LName = #2 ; tex.print(LName[math.random(1,listsize)])}}} \dorecurse{10}{\RandomChoice{Function}{ListOfNames}% Give an example of a function $\ChosenFunction : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that ${\ChosenFunction}'(0) = 1$.\par \hairline\par} \stoptext end choose-element.tex \starttext \startluacode local FunctionNames = { G , W } local FunctionName = FunctionNames[1] function document.SetFunctionNames(list) FunctionNames = utilities.parsers.settings_to_array(list) end function document.GetFunctionName(new) if new then FunctionName = FunctionNames[math.random(1,#FunctionNames)] end context(FunctionName) end \stopluacode \def\SetFunctionNames[#1]{\ctxlua{document.SetFunctionNames(#1)}} \def\NewFunctionName {\ctxlua{document.GetFunctionName(true)}} \def\GetFunctionName {\ctxlua{document.GetFunctionName()}} \SetFunctionNames[a,b,c,d] \dorecurse{10}{ Give an example of a function $\NewFunctionName : {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and such that $\GetFunctionName(0) = 1$. \par \hairline\par } \stoptext On 18 Apr 2015, at 19:23, Wolfgang Schuster schuster.wolfg...@gmail.com wrote: Am 18.04.2015 um 18:55 schrieb Otared Kavian ota...@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
Re: [NTG-context] Index items (additional question)
On 16 Apr 2015, at 15:38 , Hans Hagen pra...@wxs.nl gave me the following: \startluacode document.indexentries = { [rule] = [[Rule(s)]], [ruleimperfect] = [[+ \quote{imperfect to perfect, from}]], [galilei] = [[Galilei, Vincenzo]], } function document.getindexentry(n) context(\\index[%s]{%s},n,document.indexentries[n] or ( .. n .. )) end \stopluacode \unexpanded\def\InEn[#1]% {\ctxlua{document.getindexentry(#1)}} \starttext That this rule \InEn[rule] \InEn[ruleimperfect] was not applied by everybody is for example shown in {\em Fronimo}% \InEn[galilei] etc etc Hi Hans, sorry to bother you again on this topic. This code works beautifully in this way, with only a few index entries at the top of the file, before \starttext. But how can I deal with the thousand or more index items in my project, which I have collected in four separate dedicated files with indexentries, like the three shown in the example-code. I have really no idea what else should be in these files, what sort of name they should have, in particular extension, and how and where I can input them. I use TeXShop as my texteditor but that is probably not relevant here. Can you give me some guidance, please? Thanks in advance. Best regards, Robert Blackstone ___ 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 ___
Re: [NTG-context] Index items (additional question)
On 4/19/2015 9:47 AM, Robert Blackstone wrote: On 16 Apr 2015, at 15:38 , Hans Hagen pra...@wxs.nl gave me the following: \startluacode document.indexentries = { [rule] = [[Rule(s)]], [ruleimperfect] = [[+ \quote{imperfect to perfect, from}]], [galilei] = [[Galilei, Vincenzo]], } function document.getindexentry(n) context(\\index[%s]{%s},n,document.indexentries[n] or ( .. n .. )) end \stopluacode \unexpanded\def\InEn[#1]% {\ctxlua{document.getindexentry(#1)}} \starttext That this rule \InEn[rule] \InEn[ruleimperfect] was not applied by everybody is for example shown in {\em Fronimo}% \InEn[galilei] etc etc Hi Hans, sorry to bother you again on this topic. This code works beautifully in this way, with only a few index entries at the top of the file, before \starttext. But how can I deal with the thousand or more index items in my project, which I have collected in four separate dedicated files with indexentries, like the three shown in the example-code. I have really no idea what else should be in these files, what sort of name they should have, in particular extension, and how and where I can input them. I use TeXShop as my texteditor but that is probably not relevant here. Can you give me some guidance, please? \startluacode document.indexentries = { [rule] = [[Rule(s)]], [ruleimperfect] = [[+ \quote{imperfect to perfect, from}]], [galilei] = [[Galilei, Vincenzo]], } function document.loadindexentries(filename) local fullname = resolvers.findfile(filename) if fullname ~= then local data = io.loaddata(fullname) for a, b in string.gmatch(data,%s*(%S+)%s+([^\n\r]+)) do document.indexentries[a] = b end end end function document.getindexentry(n) local ie = document.indexentries[n] if not ie then logs.report(index,missing entry %a,n) end context(\\index[%s]{%s},n,ie or ( .. n .. )) end \stopluacode \unexpanded\def\LoadInEn[#1]{\ctxlua{document.loadindexentries(#1)}} \unexpanded\def\InEn[#1]{\ctxlua{document.getindexentry(#1)}} \LoadInEn[whatever.txt] \starttext That this rule \InEn[rule] \InEn[ruleimperfect] was not applied by everybody is for example shown in {\em Fronimo}% \InEn[galilei] \InEn[unknown] etc etc \InEn[GalileiFronimo] \InEn[Cadence] \InEn[CadenceP] \InEn[PlagalCad] \index[Fronimo]{{\em Fronimo} (Galilei)} (1584), Vincenzo Galileo's treatise on lute playing and the intabulation% \index[Intabulation]{intabulation} of vocal music. \page whatever.txt: GalileiFronimo +{\em Fronimo} Cadencecadence(s) CadenceP + plagal PlagalCad plagal cadence - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl - ___ 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 ___
Re: [NTG-context] Index items (additional question)
On 19 Apr 2015, at 11:55 , Hans Hagen pra...@wxs.nl wrote On 4/19/2015 9:47 AM, Robert Blackstone wrote: On 16 Apr 2015, at 15:38 , Hans Hagen pra...@wxs.nl gave me the following: \startluacode document.indexentries = { [rule] = [[Rule(s)]], [ruleimperfect] = [[+ \quote{imperfect to perfect, from}]], [galilei] = [[Galilei, Vincenzo]], } function document.getindexentry(n) context(\\index[%s]{%s},n,document.indexentries[n] or ( .. n .. )) end \stopluacode \unexpanded\def\InEn[#1]% {\ctxlua{document.getindexentry(#1)}} \starttext That this rule \InEn[rule] \InEn[ruleimperfect] was not applied by everybody is for example shown in {\em Fronimo}% \InEn[galilei] etc etc This code works beautifully in this way, with only a few index entries at the top of the file, before \starttext. But how can I deal with the thousand or more index items in my project, which I have collected in four separate dedicated files with indexentries, like the three shown in the example-code. I have really no idea what else should be in these files, what sort of name they should have, in particular extension, and how and where I can input them. I use TeXShop as my texteditor but that is probably not relevant here. Can you give me some guidance, please? \startluacode document.indexentries = { [rule] = [[Rule(s)]], [ruleimperfect] = [[+ \quote{imperfect to perfect, from}]], [galilei] = [[Galilei, Vincenzo]], } function document.loadindexentries(filename) local fullname = resolvers.findfile(filename) if fullname ~= then local data = io.loaddata(fullname) for a, b in string.gmatch(data,%s*(%S+)%s+([^\n\r]+)) do document.indexentries[a] = b end end end function document.getindexentry(n) local ie = document.indexentries[n] if not ie then logs.report(index,missing entry %a,n) end context(\\index[%s]{%s},n,ie or ( .. n .. )) end \stopluacode \unexpanded\def\LoadInEn[#1]{\ctxlua{document.loadindexentries(#1)}} \unexpanded\def\InEn[#1]{\ctxlua{document.getindexentry(#1)}} \LoadInEn[whatever.txt] \starttext That this rule \InEn[rule] \InEn[ruleimperfect] was not applied by everybody is for example shown in {\em Fronimo}% \InEn[galilei] \InEn[unknown] etc etc \InEn[GalileiFronimo] \InEn[Cadence] \InEn[CadenceP] \InEn[PlagalCad] \index[Fronimo]{{\em Fronimo} (Galilei)} (1584), Vincenzo Galileo's treatise on lute playing and the intabulation% \index[Intabulation]{intabulation} of vocal music. \page whatever.txt: GalileiFronimo +{\em Fronimo} Cadencecadence(s) CadenceP + plagal PlagalCad plagal cadence Hi Hans, Thank you for your reply. It took me a while to make your code operational in the way I need it. For the new example you gave is still an integral file. My project, like most book-projects, I guess, is modular with a master file Project.tex, into which everything else, setups, .bbl's, front- and backmatter, the various chapters are input. Though strictly speaking it would not be impossible to add some 1000 lines of index entries before \startproject, it would not be especially handy, and I cannot believe that it would be the proper ConTeXt-way to do it. I found that when I split your code, transferred the top part to a new file, which I named IndexItems, and input that into the other half, the text proper, it works. But when I add another file with indexentries, for instance indexitemsnames, then only one of them, the one at the top is used. So it seems that the whole collection of index items must be in one file. Is that the only possibility or are there ways to enable the use of several collections of index items? Best regards, Robert ___ 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 ___
Re: [NTG-context] vertical spacing and makeups
On 04/19/2015 08:50 PM, Wolfgang Schuster wrote: Am 18.04.2015 um 20:29 schrieb Pablo Rodriguez: [...] So the a workaround would be to use \blank instead of \par or a blank line, wouldn’t it be? You can flush the content of the buffer in a \vbox where you set the whitespace at the begin of the box. \def\startSlide {\grabbufferdata[SlideContent][startSlide][stopSlide]} \def\stopSlide {\startmakeup[standard][align=middle] \vbox\bgroup \setupwhitespace[big] \begstrut\getbufferdata[SlideContent]\endstrut \egroup \stopmakeup} Many thanks for your reply, Wolfgang. This is exactly what I needed. Pablo -- http://www.ousia.tk ___ 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 ___
Re: [NTG-context] vertical spacing and makeups
Am 18.04.2015 um 20:29 schrieb Pablo Rodriguez oi...@gmx.es: On 04/18/2015 07:15 PM, Wolfgang Schuster wrote: Am 18.04.2015 um 18:43 schrieb Pablo Rodriguez: [...] The first page shows that \setupwhitespace[big] affects to a single line in a makeup. Shouldn’t white space be added only between paragraphs? The second page is right vertically centered. And the third page shows that the white space isn’t added before the first paragraph in a normal page (no makeup). This is the first issue, isn’t it a bug? Or what am I missing? TeX inserts the \parskip value which is set by \setupwhitespace before your text in the makeup environment. Note that this happens only when you have skip before the text (e.g. with the default top=\vss setting) at the begin of the environment. The following low level example demonstrates this: \setuppapersize[A6] \starttext \dontleavehmode \ruledvbox to 3cm{\hsize=4cm text} \ruledvbox to 3cm{\hsize=4cm\parskip=2ex\relax text} \dontleavehmode \ruledvbox to 3cm{\hsize=4cm\vss text\vss} \ruledvbox to 3cm{\hsize=4cm\parskip=2ex\relax\vss text\vss} \stoptext Many thanks for your reply, Wolfgang. So the a workaround would be to use \blank instead of \par or a blank line, wouldn’t it be? You can flush the content of the buffer in a \vbox where you set the whitespace at the begin of the box. \def\startSlide {\grabbufferdata[SlideContent][startSlide][stopSlide]} \def\stopSlide {\startmakeup[standard][align=middle] \vbox\bgroup \setupwhitespace[big] \begstrut\getbufferdata[SlideContent]\endstrut \egroup \stopmakeup} \setuppapersize[S8] %\setupbodyfont[100pt] \showgrid \starttext \startSlide program content \stopSlide \startSlide descender \stopSlide \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 ___
[NTG-context] Oddity with \definereferenceformat
A reference to the text of a multi-line heading takes on the line breaks of the heading when \definereferenceformat[about] is used. \definereferenceformat[about][type=title,left=,right=] \starttext \startsection[reference={sec:one}, title={Three\\line\\title}] \startparagraph See \about[sec:one]. \stopparagraph \stopsection \stoptext Can this be repaired? Or, am I doing it wrong? -- Rik ___ 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 ___