Dear list, I have the following sample: \starttext \def\numbersfname {\cldcontext{string.match([[\env{fname}]], "\letterpercent d+")}} \ctxlua{ c = context.getvariable("environment", "fname") or "a" } \ctxlua{ d = [[\env{fname}]] } tex: \numbersfname\\ \doifelse{} {123}{yes}{no}\\ c: \cldcontext{c}\\ \doifelse{\cldcontext{c:match("\letterpercent d+")}} {123}{yes}{no}\\ d: \cldcontext{d}\\ \doifelse{\cldcontext{d:match("\letterpercent d+")}} {123}{yes}{no} \stoptext For compilation, I run the command: context --purgeall --arguments=fname={abc123} test-file.tex These things are failing: 1. I don’t know how to get \numbersfname equal to "123". I don’t know what I’m doing wrong. 2. Is there no Lua version of \getvariable{...}{...}? 3. I’m trying this on a Linux box, but on Windows I would say that Lua variable "d" is empty. I need to get the number from \env{fname} and I don’t know what I’m missing. \doif is the way to test whether it’s right. Could anyone explain me what I’m missing here? Many thanks, Pablo -- http://www.ousia.tk
On Tue, 13 Oct 2020, Pablo Rodriguez wrote:
Dear list,
I have the following sample:
\starttext \def\numbersfname {\cldcontext{string.match([[\env{fname}]], "\letterpercent d+")}} \ctxlua{ c = context.getvariable("environment", "fname") or "a" } \ctxlua{ d = [[\env{fname}]] }
tex: \numbersfname\\ \doifelse{} {123}{yes}{no}\\ c: \cldcontext{c}\\ \doifelse{\cldcontext{c:match("\letterpercent d+")}} {123}{yes}{no}\\ d: \cldcontext{d}\\ \doifelse{\cldcontext{d:match("\letterpercent d+")}} {123}{yes}{no} \stoptext
For compilation, I run the command:
context --purgeall --arguments=fname={abc123} test-file.tex
These things are failing:
1. I don’t know how to get \numbersfname equal to "123". I don’t know what I’m doing wrong.
2. Is there no Lua version of \getvariable{...}{...}?
3. I’m trying this on a Linux box, but on Windows I would say that Lua variable "d" is empty.
I need to get the number from \env{fname} and I don’t know what I’m missing. \doif is the way to test whether it’s right.
Could anyone explain me what I’m missing here?
I find it simpler to write macros where there is clean communicating between tex and lua. For example: \startluacode userdata = userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode \define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}} \starttext \numbersfname{abc123} \numbersfname{\env{fname}} \stoptext Aditya
On 10/13/20 5:54 PM, Aditya Mahajan wrote:
On Tue, 13 Oct 2020, Pablo Rodriguez wrote:
[...] Could anyone explain me what I’m missing here?
Many thanks for your reply, Aditya.
I find it simpler to write macros where there is clean communicating between tex and lua. For example: [...] \define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}}
This is the first time I see that way of wrapping an argument. In any case, I cannot compare to a number: \startluacode userdata = userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode \define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}} \starttext \numbersfname{abc123} \numbersfname{\env{fname}} \doifelse{\numbersfname{\env{fname}}}{123}{yes}{no} \stoptext I don’t know why both strings don’t match. Many thanks for your help, Pablo -- http://www.ousia.tk
Pablo Rodriguez schrieb am 13.10.2020 um 19:06:
On 10/13/20 5:54 PM, Aditya Mahajan wrote:
On Tue, 13 Oct 2020, Pablo Rodriguez wrote:
[...] Could anyone explain me what I’m missing here? Many thanks for your reply, Aditya.
I find it simpler to write macros where there is clean communicating between tex and lua. For example: [...] \define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}} This is the first time I see that way of wrapping an argument.
In any case, I cannot compare to a number:
\startluacode userdata = userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode
\define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}}
Untested: \defineexpandable[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}} Wolfgang
On 10/13/20 7:14 PM, Wolfgang Schuster wrote:
Pablo Rodriguez schrieb am 13.10.2020 um 19:06:
[...] In any case, I cannot compare to a number:
\startluacode userdata = userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode
\define[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}}
Untested:
\defineexpandable[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}}
I’m afraid it doesn’t work. \startluacode userdata = userdata or {} function userdata.numbersfname(name) return string.match(name, "%d+") end \stopluacode \defineexpandable[1]\numbersfname {\cldcontext{userdata.numbersfname([==[#1]==])}} \starttext \numbersfname{abc123} \numbersfname{\env{fname}} \doifelse{\numbersfname{\env{fname}}}{123}{yes}{no} \stoptext Just curious about what the difference might be. Many thanks for your help, Pablo -- http://www.ousia.tk
Pablo Rodriguez schrieb am 13.10.2020 um 17:33:
Dear list,
I have the following sample:
\starttext \def\numbersfname {\cldcontext{string.match([[\env{fname}]], "\letterpercent d+")}} \ctxlua{ c = context.getvariable("environment", "fname") or "a" } \ctxlua{ d = [[\env{fname}]] }
tex: \numbersfname\\ \doifelse{} {123}{yes}{no}\\ c: \cldcontext{c}\\ \doifelse{\cldcontext{c:match("\letterpercent d+")}} {123}{yes}{no}\\ d: \cldcontext{d}\\ \doifelse{\cldcontext{d:match("\letterpercent d+")}} {123}{yes}{no} \stoptext
For compilation, I run the command:
context --purgeall --arguments=fname={abc123} test-file.tex
These things are failing:
1. I don’t know how to get \numbersfname equal to "123". I don’t know what I’m doing wrong.
2. Is there no Lua version of \getvariable{...}{...}?
There is no need because everything is stored in a Lua table. %%%% begin example \starttext \startluacode local argumentlist = document.arguments.arguments local argumenttable = utilities.parsers.settings_to_hash(argumentlist) context(argumenttable["fname"]) \stopluacode \stoptext %%%% end example I tested the example with: context --arguments="fname=abc123" <filename> Wolfgang
On 10/13/20 6:14 PM, Wolfgang Schuster wrote:
Pablo Rodriguez schrieb am 13.10.2020 um 17:33:
[...] 2. Is there no Lua version of \getvariable{...}{...}?
There is no need because everything is stored in a Lua table. [...] local argumentlist = document.arguments.arguments local argumenttable = utilities.parsers.settings_to_hash(argumentlist)
context(argumenttable["fname"])
Many thanks for your reply, Wolfgang. This is exactly what I need. Many thanks for your help, Pablo -- http://www.ousia.tk
On 10/13/20 5:33 PM, Pablo Rodriguez wrote:
[...] \starttext \ctxlua{ d = [[\env{fname}]] }
d: \cldcontext{d}\\ \doifelse{\cldcontext{d:match("\letterpercent d+")}} {123}{yes}{no} \stoptext [...] 3. I’m trying this on a Linux box, but on Windows I would say that Lua variable "d" is empty.
Just for the record, this sample also works in Windows. The Lua variable isn’t empty and the conditional outputs "yes". Pablo -- http://www.ousia.tk
participants (3)
-
Aditya Mahajan
-
Pablo Rodriguez
-
Wolfgang Schuster