Re: [NTG-context] Trying to understand this ctxlua error

2020-04-06 Thread Gerben Wierda
On 6 Apr 2020, at 02:54, Wolfgang Schuster  
wrote:
> 
> Gerben Wierda schrieb am 06.04.2020 um 00:41:
>> I got this error after I had changed some lua code:
>> tex error   > tex error on line 272 in file archimate-lua.new: ! 
>> Undefined control sequence
>> warnIfVerbose( "Breaking off the processing of node %s\nNo
>>   l...eak
>>  xsi:type", node)
>> \luat_start_lua_code_indeed ...ormalexpanded {\endgroup \noexpand \directlua 
>> {#1
>>  
>> }}
>> l.272 \stopluacode
>> 
>> The control sequence at the end of the top line of your error message was 
>> never
>> \def'ed. You can just continue as I'll forget about whatever was undefined.
>> I have been looking at that code for over two hours, not seeing anything 
>> wrong with it. But I’ve now finally found the culprit and I still do not get 
>> it.
>> The culprit was:
>>   warnIfVerbose( "Breaking off the processing of %s\n No 
>> elementRef", node)
>> The problem goes away when I use:
>>   warnIfVerbose( "Breaking off the processing of %s\nNo elementRef", 
>> node)
>> (I don’t want the line after the node is printed to begin with a space).
>> But the lack of space between \n and N kills lua (apparently). For 
>> completeness (as string.format and texio.write_nl are also in play):
>> function warnWithLabelIfVerbose( str, ... )
>>   if verboseProgram then
>> texio.write_nl( str .. string.format(...))
>>   end
>> end
>> function warnIfVerbose( ... )
>>   warnWithLabelIfVerbose("-> ", ...)
>> end
>> Is this a lua bug? A ConTeXt bug? Expected behaviour? And if so, why is 
>> reported that on line 272 (where \stopluacode is) is the error? Or is the 
>> error message indeed helpful and do I just lack the know how to interpret it?
> 
> ConTeXt expands TeX commands in a luacode-environment
> and when you have \n followed by text you create a new
> command with starts with \n but since it isn't defined
> you get a error message.
> 
> In the example below the commented block produces
> the same error message as you get.
> 
> \starttext
> 
> %\startluacode
> %print("text\ntext")
> %\stopluacode
> 
> \startluacode
> print("text\n text")
> \stopluacode
> 
> \stoptext

OK, thanks. This means the ConTeXt environment mixes standard TeX (where \nfoo 
would be considered a TeX command) and lua string substitution (where \nfoo 
would mean a newline followed by foo), correct? I understand why that happens 
(otherwise one would have to escape all \ characters directed at TeX) but it 
really took me hours (because I did not understand the error message that 
correctly told me \Nno was the problem). It’s what you see depends on what you 
are looking for, I guess.

Maybe a warning in the documentation (or maybe there is one and I missed it)

G

___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Trying to understand this ctxlua error

2020-04-05 Thread Wolfgang Schuster

Gerben Wierda schrieb am 06.04.2020 um 00:41:

I got this error after I had changed some lua code:

tex error       > tex error on line 272 in file archimate-lua.new: ! 
Undefined control sequence


         warnIfVerbose( "Breaking off the processing of node %s\nNo
       l...eak  
           xsi:type", node)
\luat_start_lua_code_indeed ...ormalexpanded {\endgroup \noexpand 
\directlua {#1
 
         }}

l.272 \stopluacode






The control sequence at the end of the top line of your error message 
was never

\def'ed. You can just continue as I'll forget about whatever was undefined.

I have been looking at that code for over two hours, not seeing anything 
wrong with it. But I’ve now finally found the culprit and I still do not 
get it.


The culprit was:

           warnIfVerbose( "Breaking off the processing of %s\n No 
elementRef", node)


The problem goes away when I use:

           warnIfVerbose( "Breaking off the processing of %s\nNo 
elementRef", node)


(I don’t want the line after the node is printed to begin with a space).

But the lack of space between \n and N kills lua (apparently). For 
completeness (as string.format and texio.write_nl are also in play):


function warnWithLabelIfVerbose( str, ... )
   if verboseProgram then
     texio.write_nl( str .. string.format(...))
   end
end

function warnIfVerbose( ... )
   warnWithLabelIfVerbose("-> ", ...)
end

Is this a lua bug? A ConTeXt bug? Expected behaviour? And if so, why is 
reported that on line 272 (where \stopluacode is) is the error? Or is 
the error message indeed helpful and do I just lack the know how to 
interpret it?


ConTeXt expands TeX commands in a luacode-environment
and when you have \n followed by text you create a new
command with starts with \n but since it isn't defined
you get a error message.

In the example below the commented block produces
the same error message as you get.

\starttext

%\startluacode
%print("text\ntext")
%\stopluacode

\startluacode
print("text\n text")
\stopluacode

\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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] Trying to understand this ctxlua error

2020-04-05 Thread Gerben Wierda
I got this error after I had changed some lua code:

tex error   > tex error on line 272 in file archimate-lua.new: ! Undefined 
control sequence

warnIfVerbose( "Breaking off the processing of node %s\nNo 
  l...eak   
 xsi:type", node)
\luat_start_lua_code_indeed ...ormalexpanded {\endgroup \noexpand \directlua {#1

}}
l.272 \stopluacode





The control sequence at the end of the top line of your error message was never
\def'ed. You can just continue as I'll forget about whatever was undefined.

I have been looking at that code for over two hours, not seeing anything wrong 
with it. But I’ve now finally found the culprit and I still do not get it.

The culprit was:

  warnIfVerbose( "Breaking off the processing of %s\n No elementRef", 
node)

The problem goes away when I use:

  warnIfVerbose( "Breaking off the processing of %s\nNo elementRef", 
node)

(I don’t want the line after the node is printed to begin with a space).

But the lack of space between \n and N kills lua (apparently). For completeness 
(as string.format and texio.write_nl are also in play):

function warnWithLabelIfVerbose( str, ... )
  if verboseProgram then
texio.write_nl( str .. string.format(...))
  end
end

function warnIfVerbose( ... )
  warnWithLabelIfVerbose("-> ", ...)
end

Is this a lua bug? A ConTeXt bug? Expected behaviour? And if so, why is 
reported that on line 272 (where \stopluacode is) is the error? Or is the error 
message indeed helpful and do I just lack the know how to interpret it?

G

(Took me three hours, this one. Just removing that space that happened with 
some other changes was the culprit. Totally unexpected for me.)___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-16 Thread Rudolf Bahr
On Tue, Oct 15, 2019 at 10:15:34AM +0200, Hans Hagen wrote:
> On 10/15/2019 10:04 AM, Taco Hoekwater wrote:
> > Hi Rudolf,
> > 
> > > On 15 Oct 2019, at 00:50, Rudolf Bahr  wrote:
> > > 
> > > Now to your suggestion not to use "assert ()". Indeed it's a solution! My 
> > > program
> > > works! I append again its output (again just for fun!). Did you really 
> > > try it or
> > > has it been just an idea?
> > 
> > First, let me say that embedded lua versions are typically a little bit 
> > different
> > from standalone. Just how much different depends on the embedding program. 
> > Luatex
> > is actually pretty close to standalone lua. Luatex adds a bunch of 
> > extension libraries,
> > but it changes very little of the core language. And all those changes are 
> > documented
> > in the luatex manual. None of those changes affect your minimal example, 
> > except
> > that lua errors are handled a little differently.
> > 
> > Note that standalone lua *also* produces an error, as that is what assert() 
> > is
> > supposed to do. And when lua runs into an error, it ignores the rest of the 
> > current
> > chunk:
> > 
> >“... whenever an error occurs, Lua ends the current chunk and returns
> >to the application.” (from lua.org)
> > 
> > Standalone lua typically sees only one chunk (the file you pass on the 
> > command
> > line) but embedded lua implementation often see (sometimes many) more 
> > chunks.
> > In luatex’s case, each \directlua is a separate chunk (in ConTeXt, that 
> > means every
> > \startluacode block and every \ctxlua call is a separate chunk).
> > 
> > The only unusual thing here is that standalone lua silently quits and 
> > returns a
> > non-zero exit code to the shell, whereas luatex gives you the typical 
> > TeX-style
> > error prompt. The rationale for that is: lua errors can happen in many 
> > places in
> > your input file, and if they were silently ignored, your typeset pages 
> > could be
> > wrong without you realising it.
> > 
> > 
> > And to answer your question above: I did not have to try or guess. I know 
> > about
> > how assert() works because it is documented in the lua manual (and as it 
> > closely
> > mimics the assert() C function, that is easy for me to remember).
> as you say, it's all normal lua behaviour:
> 
> if you do:
> 
>   print(io.open("crap.crap"))
> 
> one gets
> 
>   nil crap.crap: No such file or directory2
> 
> and i think that assert then returns the second returned argument
> 
> but if one does
> 
>   context(io.open("crap.crap") and "yes" or "no")
> 
> then the first argument is checked against
> 
> Hans


Hi Hans, hi Taco!

For your answers and patient explanations I want to thank you, not to forget
[1], [2], [3] for instance! Now it gets clearer to me what the distinctive
features could be which one can encounter when using a combination of even so
wunderful programming languages as ConTeXt and Lua are!

Best wishes,

Rudolf

[1] https://wiki.contextgarden.net/Programming_in_LuaTeX
[2] http://www.luatex.org/svn/trunk/manual/luatex.pdf
[3] http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf

___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-15 Thread Hans Hagen

On 10/15/2019 10:04 AM, Taco Hoekwater wrote:

Hi Rudolf,


On 15 Oct 2019, at 00:50, Rudolf Bahr  wrote:

Now to your suggestion not to use "assert ()". Indeed it's a solution! My 
program
works! I append again its output (again just for fun!). Did you really try it or
has it been just an idea?


First, let me say that embedded lua versions are typically a little bit 
different
from standalone. Just how much different depends on the embedding program. 
Luatex
is actually pretty close to standalone lua. Luatex adds a bunch of extension 
libraries,
but it changes very little of the core language. And all those changes are 
documented
in the luatex manual. None of those changes affect your minimal example, except
that lua errors are handled a little differently.

Note that standalone lua *also* produces an error, as that is what assert() is
supposed to do. And when lua runs into an error, it ignores the rest of the 
current
chunk:

   “... whenever an error occurs, Lua ends the current chunk and returns
   to the application.” (from lua.org)

Standalone lua typically sees only one chunk (the file you pass on the command
line) but embedded lua implementation often see (sometimes many) more chunks.
In luatex’s case, each \directlua is a separate chunk (in ConTeXt, that means 
every
\startluacode block and every \ctxlua call is a separate chunk).

The only unusual thing here is that standalone lua silently quits and returns a
non-zero exit code to the shell, whereas luatex gives you the typical TeX-style
error prompt. The rationale for that is: lua errors can happen in many places in
your input file, and if they were silently ignored, your typeset pages could be
wrong without you realising it.


And to answer your question above: I did not have to try or guess. I know about
how assert() works because it is documented in the lua manual (and as it closely
mimics the assert() C function, that is easy for me to remember).

as you say, it's all normal lua behaviour:

if you do:

  print(io.open("crap.crap"))

one gets

  nil   crap.crap: No such file or directory2

and i think that assert then returns the second returned argument

but if one does

  context(io.open("crap.crap") and "yes" or "no")

then the first argument is checked against

Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-15 Thread Taco Hoekwater
Hi Rudolf,

> On 15 Oct 2019, at 00:50, Rudolf Bahr  wrote:
> 
> Now to your suggestion not to use "assert ()". Indeed it's a solution! My 
> program
> works! I append again its output (again just for fun!). Did you really try it 
> or
> has it been just an idea?

First, let me say that embedded lua versions are typically a little bit 
different 
from standalone. Just how much different depends on the embedding program. 
Luatex 
is actually pretty close to standalone lua. Luatex adds a bunch of extension 
libraries,
but it changes very little of the core language. And all those changes are 
documented
in the luatex manual. None of those changes affect your minimal example, except
that lua errors are handled a little differently.

Note that standalone lua *also* produces an error, as that is what assert() is 
supposed to do. And when lua runs into an error, it ignores the rest of the 
current 
chunk: 

  “... whenever an error occurs, Lua ends the current chunk and returns 
  to the application.” (from lua.org)

Standalone lua typically sees only one chunk (the file you pass on the command
line) but embedded lua implementation often see (sometimes many) more chunks.
In luatex’s case, each \directlua is a separate chunk (in ConTeXt, that means 
every 
\startluacode block and every \ctxlua call is a separate chunk).

The only unusual thing here is that standalone lua silently quits and returns a 
non-zero exit code to the shell, whereas luatex gives you the typical TeX-style 
error prompt. The rationale for that is: lua errors can happen in many places 
in 
your input file, and if they were silently ignored, your typeset pages could be 
wrong without you realising it.


And to answer your question above: I did not have to try or guess. I know about 
how assert() works because it is documented in the lua manual (and as it closely
mimics the assert() C function, that is easy for me to remember).

Best wishes,
Taco

___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Rudolf Bahr
On Mon, Oct 14, 2019 at 09:26:58PM +0200, Taco Hoekwater wrote:
> Hi,
> 
> > On 14 Oct 2019, at 21:08, Rudolf Bahr  wrote:
> > 
> > 
> > 2. But in the case of an not existing file (BBB.lua) the known error 
> > message comes up
> >   again:
> >   "token call, execute: [ctxlua]:8: /home/sam/context-tests/BBB.lua: No 
> > such file or 
> >directory".
> >This, of course, is true, but shouldn't be mentioned in an error message!
> 
> If you do not want the error message, don’t use assert(). You can just do 
> 
> f = io.open(...)
> If f then ... else ... end
> 
> Best wishes,
> Taco


Hi Taco!

Thank you again for your message!

My wish isn't to avoid error messages, if they are justified! In the case of my 
MWE
I want to have a decision in my \startluacode ... \stopluacode environment, 
whether
a certain file exists or not. With this decision I want to branch in my program 
and
with an error message I cannot do it.

Lua is a wonderfull programming language and I'm appreciative to get a way to 
exit
ConTeXt, run Lua code and enter the ConTeXt program at the same location again! 
On
the other side, in the last days I spent some time to eliminate errors in my
\startluacode ...\stopluacode program to change code which causes no error 
messages
in pure Lua.

Now to your suggestion not to use "assert ()". Indeed it's a solution! My 
program
works! I append again its output (again just for fun!). Did you really try it or
has it been just an idea? The MWE is now as follows:

===
\startluacode

userdata = userdata or {}

function userdata.file_exists (name)

   local name = name
   local f= io.open ( name, "r" )

   if f then
  f:close ()
  context ( name )
  context ( "  exists!" )
   else
  context ( name )
  context ( "  doesn't exist!" )
   end
end

\stopluacode


\starttext

\def\lookupfile#1%
{\ctxlua{userdata.file_exists([==[#1]==])}}

\lookupfile{/home/sam/context-tests/AAA.lua}% "AAA.lua" intentionally does 
exist

\par

\lookupfile{/home/sam/context-tests/BBB.lua}% "BBB.lua" intentionally 
doesn't exist

\stoptext
===

R. Ierusalimschy encourages the use of "assert()". But it is apparantly better 
not to
use it under certain circumstances as in \startluacode ... \stopluacode as I've 
learnt
now.
Can I avoid therefore Hans' prefix resolvers code?

Best wishes,
Rudolf


is-file.pdf
Description: Adobe PDF document
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Taco Hoekwater
Hi,

> On 14 Oct 2019, at 21:08, Rudolf Bahr  wrote:
> 
> 
> 2. But in the case of an not existing file (BBB.lua) the known error message 
> comes up
>   again:
>   "token call, execute: [ctxlua]:8: /home/sam/context-tests/BBB.lua: No such 
> file or 
>directory".
>This, of course, is true, but shouldn't be mentioned in an error message!

If you do not want the error message, don’t use assert(). You can just do 

f = io.open(...)
If f then ... else ... end

Best wishes,
Taco
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Rudolf Bahr
On Mon, Oct 14, 2019 at 07:19:53PM +0200, Hans Hagen wrote:
> On 10/14/2019 6:50 PM, Rudolf Bahr wrote:
 
> > THis MWE must be faulty, but where is the error?
> > 
> > 
> > 
> > \startluacode
> > 
> > userdata = userdata or {}
> > 
> > function userdata.file_exists (name)
> > 
> > local name = name
> > local f= assert ( io.open ( name, "r" ))
> > 
> > if f then
> >f:close ()
> >context ( name )
> >context ( "  exists!" )
> > else
> >context ( name )
> >    context ( "  doesn't exist!" )
> > end
> > end
> > 
> > \stopluacode
> > 
> > 
> > \starttext
> > 
> > \def\lookupfile#1%
> > {\ctxlua{userdata.file_exists([==[#1]==])}}
> > 
> > \lookupfile{"$HOME/context-tests/AAA.lua"}  % "AAA.lua" intentionally does  
> >   exist
> > \lookupfile{"$HOME/context-tests/BBB.lua"}  % "BBB.lua" intentionally 
> > doesn't exist
> > 
> > \stoptext
> > 
> > ====
> > 
> > It makes no difference in commenting out the first or the second 
> > "\lookupfile" command.
> > The error message eventually is always nearly the same:
> > 
> > token call, execute: [ctxlua]:8: "$HOME/context-tests/AAA.lua": No such 
> > file or directory
> > token call, execute: [ctxlua]:8: "$HOME/context-tests/BBB.lua": No such 
> > file or directory


Joseph, Taco and Hans, I thank you very much for your quick answers!
I shall try Hans' interesting suggestion on prefix resolvers after I've studied 
it,
for which I certainly need some time!

But before doing so I've a comment:
Your answers, Joseph, Taco and Hans, could  lead to the impression, that giving 
up
"double quotes as part of file names" and/or "$HOME" in the MWE would be the 
solution.
And indeed, not using "double quotes" and "expanding $HOME" by hand partly 
brings success:

1. In the case of an existing file (AAA.lua) the MWE works without error 
message!
   I will append the output-pdf-file here (just for fun!).

2. But in the case of an not existing file (BBB.lua) the known error message 
comes up
   again:
   "token call, execute: [ctxlua]:8: /home/sam/context-tests/BBB.lua: No such 
file or 
directory".
This, of course, is true, but shouldn't be mentioned in an error message!

Within \startluacode ... \stopluacode it seems one has to abandon the normal 
lua world,
at least partly. Are there other "special features"?

Rudolf


is-file.pdf
Description: Adobe PDF document
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Hans Hagen

On 10/14/2019 6:50 PM, Rudolf Bahr wrote:


Dear List!

THis MWE must be faulty, but where is the error?



\startluacode

userdata = userdata or {}

function userdata.file_exists (name)

local name = name
local f= assert ( io.open ( name, "r" ))

if f then
   f:close ()
   context ( name )
   context ( "  exists!" )
else
   context ( name )
   context ( "  doesn't exist!" )
end

end


\stopluacode


\starttext

\def\lookupfile#1%
{\ctxlua{userdata.file_exists([==[#1]==])}}

\lookupfile{"$HOME/context-tests/AAA.lua"}% "AAA.lua" intentionally does
exist
\lookupfile{"$HOME/context-tests/BBB.lua"}% "BBB.lua" intentionally doesn't 
exist

\stoptext



It makes no difference in commenting out the first or the second "\lookupfile" 
command.
The error message eventually is always nearly the same:

token call, execute: [ctxlua]:8: "$HOME/context-tests/AAA.lua": No such file or 
directory
token call, execute: [ctxlua]:8: "$HOME/context-tests/BBB.lua": No such file or 
directory
You're in a tex environment, so no $HOME expansion. You can use the 
prefix resolvers:


\startluacode
function userdata.file_exists(name)
local name = name and resolvers.resolve(name)
if name and lfs.isfile(name) then
context("file %a exists",name)
else
    context("file %a doesn't exist",name)
end
    end
\stopluacode

\starttext

  % \def\lookupfile#1{\ctxlua{userdata.file_exists([==[#1]==])}}

\def\lookupfile{\ctxlua{userdata.file_exists(tokens.scanners.string())}}

\lookupfile{home:context-tests/AAA.lua}{xx}
\lookupfile{home:context-tests/BBB.lua}{xx}

\stoptext



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Taco Hoekwater
Hi,

> On 14 Oct 2019, at 18:51, Rudolf Bahr  wrote:
> 
> 
> Dear List!
> 
> THis MWE must be faulty, but where is the error?
> 
> ===
> \lookupfile{"$HOME/context-tests/AAA.lua"}% "AAA.lua" intentionally does  
>   exist
 
$HOME is an actual literal here, since io.open() does not call out to a shell?

Taco
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] RE : \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Joseph
I suspect the double quotes are part of file names, hence files cannot be 
found. Perhaps try remove them in macro argument.
Hope this helps

De : Rudolf Bahr
Envoyé le :lundi 14 octobre 2019 18:50
À : ntg-context@ntg.nl
Objet :[NTG-context] \ctxlua and \startluacode ... \stopluacode


Dear List!

THis MWE must be faulty, but where is the error?



\startluacode

userdata = userdata or {}

function userdata.file_exists (name)

   local name = name
   local f= assert ( io.open ( name, "r" ))

   if f then
  f:close ()
  context ( name )
  context ( "  exists!" )
   else
  context ( name )
  context ( "  doesn't exist!" )
   end
   
end

\stopluacode


\starttext

\def\lookupfile#1%
{\ctxlua{userdata.file_exists([==[#1]==])}}

\lookupfile{"$HOME/context-tests/AAA.lua"}  % "AAA.lua" intentionally does  
  exist
\lookupfile{"$HOME/context-tests/BBB.lua"}  % "BBB.lua" intentionally 
doesn't exist

\stoptext



It makes no difference in commenting out the first or the second "\lookupfile" 
command.
The error message eventually is always nearly the same:

token call, execute: [ctxlua]:8: "$HOME/context-tests/AAA.lua": No such file or 
directory
token call, execute: [ctxlua]:8: "$HOME/context-tests/BBB.lua": No such file or 
directory

I'm using:
LuaMetaTeX, Version 2.00.0 
ConTeXt  ver: 2019.10.10 18:15 MKIV beta  fmt: 2019.10.12  int: english/english

Please, any ideas?

Regards,
Rudolf

___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] \ctxlua and \startluacode ... \stopluacode

2019-10-14 Thread Rudolf Bahr

Dear List!

THis MWE must be faulty, but where is the error?



\startluacode

userdata = userdata or {}

function userdata.file_exists (name)

   local name = name
   local f= assert ( io.open ( name, "r" ))

   if f then
  f:close ()
  context ( name )
  context ( "  exists!" )
   else
  context ( name )
  context ( "  doesn't exist!" )
   end
   
end

\stopluacode


\starttext

\def\lookupfile#1%
{\ctxlua{userdata.file_exists([==[#1]==])}}

\lookupfile{"$HOME/context-tests/AAA.lua"}  % "AAA.lua" intentionally does  
  exist
\lookupfile{"$HOME/context-tests/BBB.lua"}  % "BBB.lua" intentionally 
doesn't exist

\stoptext



It makes no difference in commenting out the first or the second "\lookupfile" 
command.
The error message eventually is always nearly the same:

token call, execute: [ctxlua]:8: "$HOME/context-tests/AAA.lua": No such file or 
directory
token call, execute: [ctxlua]:8: "$HOME/context-tests/BBB.lua": No such file or 
directory

I'm using:
LuaMetaTeX, Version 2.00.0 
ConTeXt  ver: 2019.10.10 18:15 MKIV beta  fmt: 2019.10.12  int: english/english

Please, any ideas?

Regards,
Rudolf

___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] single command for \ctxlua{context(...)}

2019-03-12 Thread Pablo Rodriguez
On 3/11/19 10:36 PM, Wolfgang Schuster wrote:
> Pablo Rodriguez schrieb am 11.03.19 um 22:23:
>> [...]
>> Is there a single command for \ctxlua{context(...)}?
> 
> \cldcontext{...}

Many thanks for your fast reply, Wolfgang.

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] single command for \ctxlua{context(...)}

2019-03-11 Thread Wolfgang Schuster

Pablo Rodriguez schrieb am 11.03.19 um 22:23:

Dear list,

I know this has been already posted to the list, but I cannot find it
right now.

Is there a single command for \ctxlua{context(...)}?

\cldcontext{...}

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] single command for \ctxlua{context(...)}

2019-03-11 Thread Pablo Rodriguez
Dear list,

I know this has been already posted to the list, but I cannot find it
right now.

Is there a single command for \ctxlua{context(...)}?

Many thanks for your help,

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Hans Hagen

On 3/19/2017 4:51 PM, Thomas A. Schmitz wrote:

On 19.03.2017 16:30, Otared Kavian wrote:

I would like to print in a text the values of a array computed in a
\startluacode …. \stopluacode combination.
How can I do it properly? Please have a look at the example below and
its output, which is not satisfactory because the right parenthesis is
separated from the number by a space. How can I suppress this unwanted
space?
For instance I get (1, 103 ) instead of (1, 103).


Otared,

is there a reason why you don't use context(vecteurY[i]) and
context(vecteurX[i])? This gets rid of the spurious space for me (and
makes your code more consistent). But I assume you must have tried it
because you use the "context" command in other places of your lua code.


always try to use the context command because it deals with catcodes and 
is more robust than a tex.(s)print


Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Hans Hagen

On 3/19/2017 5:56 PM, Wolfgang Schuster wrote:



Otared Kavian 
19. März 2017 um 17:46via Postbox

Hi Aditya,

Thanks, as Thomas, Pablo and you mentioned the right way is to use
context() instead of tex.print()
Actually I just saw that one can also concatenate with context() as in:

context("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

which is equivalent to
tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

You can use the string.formatters function for this.

\starttext

\startluacode

local string_a = "12"
local string_b = "23"

context(string.formatters["(%s,%s)"](string_a,string_b))

\stopluacode

\stoptext


\starttext

\startluacode

local string_a = "12"
local string_b = "23"

context("(%s,%s)",string_a,string_b)

context.formatted.bold("(%s,%s)",string_a,string_b)

\stopluacode

\stoptext


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Otared Kavian
Hi Wolfgang,

Thanks for letting me know the command string.formatters[….]. It allows to 
avoid the concatenation, which is to avoid as Thomas points out.

Now that I have solved the issue with the spurious space, I have one more 
question: how could one print the values (vecteuX[i],vecteurY[i]) in a 
tabulated environment so that when for instance one has 15 such values, one 
gets 3 lines with 5 values on each line?

Best regards: OK

> On 19 Mar 2017, at 17:56, Wolfgang Schuster  
> wrote:
> 
> 
>> Otared Kavian 19. März 2017 um 17:46 via Postbox
>> Hi Aditya,
>> 
>> Thanks, as Thomas, Pablo and you mentioned the right way is to use context() 
>> instead of tex.print()
>> Actually I just saw that one can also concatenate with context() as in:
>> 
>> context("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")
>> 
>> which is equivalent to
>> tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")
> You can use the string.formatters function for this.
> 
> \starttext
> 
> \startluacode
> 
> local string_a = "12"
> local string_b = "23"
> 
> context(string.formatters["(%s,%s)"](string_a,string_b))
> 
> \stopluacode
> 
> \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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Wolfgang Schuster



Otared Kavian 
19. März 2017 um 17:46via Postbox 


Hi Aditya,

Thanks, as Thomas, Pablo and you mentioned the right way is to use 
context() instead of tex.print()

Actually I just saw that one can also concatenate with context() as in:

context("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

which is equivalent to
tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

You can use the string.formatters function for this.

\starttext

\startluacode

local string_a = "12"
local string_b = "23"

context(string.formatters["(%s,%s)"](string_a,string_b))

\stopluacode

\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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Thomas A. Schmitz

On 19.03.2017 16:56, Pablo Rodriguez wrote:

is there any reason not to use the following instead of your way below?

  for i = 1,n do
tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")
  end


I don't think that this is a good approach. Refer to chapter 11.6 of 
"Programming in Lua" to see why string concatenation is computationally 
expensive. (It wouldn't matter in this simple case, but it's not a good 
habit to develop.)


All best

Thomas
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Otared Kavian
Hi Aditya,

Thanks, as Thomas, Pablo and you mentioned the right way is to use context() 
instead of tex.print()
Actually I just saw that one can also concatenate with context() as in:

context("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

which is equivalent to
tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")

Best regards: OK

> On 19 Mar 2017, at 17:37, Aditya Mahajan  wrote:
> 
> On Sun, 19 Mar 2017, Otared Kavian wrote:
> 
>> Hi,
>> 
>> I would like to print in a text the values of a array computed in a  
>> \startluacode …. \stopluacode combination.
>> How can I do it properly? Please have a look at the example below and its 
>> output, which is not satisfactory because the right parenthesis is separated 
>> from the number by a space. How can I suppress this unwanted space?
>> For instance I get (1, 103 ) instead of (1, 103).
> 
> use context() to print instead of tex.print(...).
> 
> Aditya___
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Otared Kavian
Hi Pablo,

Thanks for your answer: actually I did not know that it is possible to 
concatenate so easily in lua… Your solution is indeed simpler than what I did 
and solves also the problem of the spurious space before the closing 
parenthesis.

Best regards: OK

> On 19 Mar 2017, at 16:56, Pablo Rodriguez  wrote:
> 
> On 03/19/2017 04:30 PM, Otared Kavian wrote:
>> Hi,
>> 
>> I would like to print in a text the values of a array computed in a
>> \startluacode …. \stopluacode combination.
>> How can I do it properly? Please have a look at the example below
>> and its output, which is not satisfactory because the right parenthesis is
>> separated from the number by a space. How can I suppress this unwanted
>> space?
>> For instance I get (1, 103 ) instead of (1, 103).
> 
> Hi Otared,
> 
> is there any reason not to use the following instead of your way below?
> 
>  for i = 1,n do
>tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")
>  end
> 
>>  for i = 1,n do
>>  context("(") 
>>  tex.print(vecteurX[i]) 
>>  context(", ") 
>>  tex.print(vecteurY[i])
>>  tex.print(")")
>>  context.par()
>>  end
> 
> I think this is shorter and clearer (to me, at least).
> 
> Just in case it helps,
> 
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Otared Kavian
Hi Thomas,

Thanks for your answer.
Indeed I did not know that I could use directly 
context(vecteurY[i])
Now this solves my problem!

Best regards: OK

> On 19 Mar 2017, at 16:51, Thomas A. Schmitz  
> wrote:
> 
> On 19.03.2017 16:30, Otared Kavian wrote:
>> I would like to print in a text the values of a array computed in a  
>> \startluacode …. \stopluacode combination.
>> How can I do it properly? Please have a look at the example below and its 
>> output, which is not satisfactory because the right parenthesis is separated 
>> from the number by a space. How can I suppress this unwanted space?
>> For instance I get (1, 103 ) instead of (1, 103).
> 
> Otared,
> 
> is there a reason why you don't use context(vecteurY[i]) and 
> context(vecteurX[i])? This gets rid of the spurious space for me (and makes 
> your code more consistent). But I assume you must have tried it because you 
> use the "context" command in other places of your lua code.
> 
> Thomas
> ___
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Aditya Mahajan

On Sun, 19 Mar 2017, Otared Kavian wrote:


Hi,

I would like to print in a text the values of a array computed in a  
\startluacode …. \stopluacode combination.
How can I do it properly? Please have a look at the example below and its 
output, which is not satisfactory because the right parenthesis is separated 
from the number by a space. How can I suppress this unwanted space?
For instance I get (1, 103 ) instead of (1, 103).


use context() to print instead of tex.print(...).

Aditya___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Pablo Rodriguez
On 03/19/2017 04:30 PM, Otared Kavian wrote:
> Hi,
> 
> I would like to print in a text the values of a array computed in a
> \startluacode …. \stopluacode combination.
> How can I do it properly? Please have a look at the example below
> and its output, which is not satisfactory because the right parenthesis is
> separated from the number by a space. How can I suppress this unwanted
> space?
> For instance I get (1, 103 ) instead of (1, 103).

Hi Otared,

is there any reason not to use the following instead of your way below?

  for i = 1,n do
tex.print("(" .. vecteurX[i] .. ", " .. vecteurY[i] .. ")\\par")
  end

>   for i = 1,n do
>   context("(") 
>   tex.print(vecteurX[i]) 
>   context(", ") 
>   tex.print(vecteurY[i])
>   tex.print(")")
>   context.par()
>   end

I think this is shorter and clearer (to me, at least).

Just in case it helps,

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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Thomas A. Schmitz

On 19.03.2017 16:30, Otared Kavian wrote:

I would like to print in a text the values of a array computed in a  
\startluacode …. \stopluacode combination.
How can I do it properly? Please have a look at the example below and its 
output, which is not satisfactory because the right parenthesis is separated 
from the number by a space. How can I suppress this unwanted space?
For instance I get (1, 103 ) instead of (1, 103).


Otared,

is there a reason why you don't use context(vecteurY[i]) and 
context(vecteurX[i])? This gets rid of the spurious space for me (and 
makes your code more consistent). But I assume you must have tried it 
because you use the "context" command in other places of your lua code.


Thomas
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread josephcanedo
Hi,

I think you can use tex.write() instead of tex.print() (pretty much the same as 
in lua io functions).
Hope this helps

Joseph

De : Otared Kavian
Envoyé le :dimanche 19 mars 2017 16:31
À : mailing list for ConTeXt users
Objet :[NTG-context] How to use tex.print in ctxlua

Hi,

I would like to print in a text the values of a array computed in a  
\startluacode …. \stopluacode combination.
How can I do it properly? Please have a look at the example below and its 
output, which is not satisfactory because the right parenthesis is separated 
from the number by a space. How can I suppress this unwanted space? 
For instance I get (1, 103 ) instead of (1, 103).

Thanks in advance for any help,
Best regards: OK

%%% begin ctxlua-print.tex
\starttext
\startluacode
n = 6 ;
vecteurX = {} ;
for i = 1,n do
vecteurX[i] = i ;
end
vecteurY = {} ;
for i = 1,n do
vecteurY[i] = 3*vecteurX[i] + 100 ;
end
for i = 1,n do
context("(") 
tex.print(vecteurX[i]) 
context(", ") 
tex.print(vecteurY[i])
tex.print(")")
context.par()
end
\stopluacode
\stoptext
%%% begin ctxlua-print.tex


___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] How to use tex.print in ctxlua

2017-03-19 Thread Otared Kavian
Hi,

I would like to print in a text the values of a array computed in a  
\startluacode …. \stopluacode combination.
How can I do it properly? Please have a look at the example below and its 
output, which is not satisfactory because the right parenthesis is separated 
from the number by a space. How can I suppress this unwanted space? 
For instance I get (1, 103 ) instead of (1, 103).

Thanks in advance for any help,
Best regards: OK

%%% begin ctxlua-print.tex
\starttext
\startluacode
n = 6 ;
vecteurX = {} ;
for i = 1,n do
vecteurX[i] = i ;
end
vecteurY = {} ;
for i = 1,n do
vecteurY[i] = 3*vecteurX[i] + 100 ;
end
for i = 1,n do
context("(") 
tex.print(vecteurX[i]) 
context(", ") 
tex.print(vecteurY[i])
tex.print(")")
context.par()
end
\stopluacode
\stoptext
%%% begin ctxlua-print.tex



ctxlua-print.pdf
Description: Adobe PDF document
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] call of string.match() inside \ctxlua{}

2017-01-19 Thread Hans Hagen

On 1/19/2017 5:03 PM, DesdeChaves wrote:

Dear Sirs

A have a string where I need to extract one number. But every time I run
this code I found this error message: [ctxlua]:1: unfinished string near


\usemodule[scancsv]

\def\licann#1{% #1 - lesson number with strings
\ctxlua{parsedate=thirddata.scancsv.ParseCSVLine('#1','n.º');%
 local Nlic=(parsedate[2]);%
   Nlic=tonumber(string.match(Nlic, '%d+'));%


%d -> \letterpercent d


 context(Nlic ~=0 and 1 or  0)}}

\starttext

\licann{"lesson nº456Alterada"}

\stoptext


thanks in advance


\startluacode
function document.Licann(s)
local d = string.match(s,"^.-nº(%d+)")
local n = tonumber(d)
context(n ~= 0 and 1 or  0)
end
\stopluacode

\def\licann#1{\ctxlua{document.Licann([[#1]])}}



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] call of string.match() inside \ctxlua{}

2017-01-19 Thread DesdeChaves
Dear Sirs

A have a string where I need to extract one number. But every time I run
this code I found this error message: [ctxlua]:1: unfinished string near


\usemodule[scancsv]

\def\licann#1{% #1 - lesson number with strings
\ctxlua{parsedate=thirddata.scancsv.ParseCSVLine('#1','n.º');%
 local Nlic=(parsedate[2]);%
   Nlic=tonumber(string.match(Nlic, '%d+'));%
 context(Nlic ~=0 and 1 or  0)}}

\starttext

\licann{"lesson nº456Alterada"}

\stoptext


thanks in advance

Have a nice day

jorge
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] escaping quotes in \ctxlua

2015-09-30 Thread Pablo Rodriguez
Dear list,

I have the following sample:

\starttext
\startluacode
tex.print(os.getenv("USER")
\stopluacode

    \ctxlua{tex.print(os.getenv("USER")}
\stoptext

How can I escape the quotes in the \ctxlua command?

Many thanks for your help,


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] escaping quotes in \ctxlua

2015-09-30 Thread Wolfgang Schuster

Pablo Rodriguez <mailto:oi...@gmx.es>
30. September 2015 um 17:07
Dear list,

I have the following sample:

\starttext
\startluacode
tex.print(os.getenv("USER")
\stopluacode

\ctxlua{tex.print(os.getenv("USER")}
\stoptext

How can I escape the quotes in the \ctxlua command?
You have to add a  closing ) for tex.print in both Lua calls but you can 
replace the second version with \cldcontext{os.getenv("USER")}.


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
___

Re: [NTG-context] escaping quotes in \ctxlua

2015-09-30 Thread Tomas Hala
Hello Pablo,
print commands are not balanced, second right parenthesis is missing.
Then it will work.

Tomas

Wed, Sep 30, 2015 ve 05:07:49PM +0200 Pablo Rodriguez napsal(a):
# Dear list,
# 
# I have the following sample:
# 
# \starttext
# \startluacode
# tex.print(os.getenv("USER")
# \stopluacode
# 
#     \ctxlua{tex.print(os.getenv("USER")}
# \stoptext
# 
# How can I escape the quotes in the \ctxlua command?
# 
# Many thanks for your help,
# 
# 
# 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
# 
___

 Tomáš Hála

Mendelova univerzita, Provozně ekonomická fakulta, ústav informatiky
Zemědělská 1, CZ-613 00 Brno,  tel. +420 545 13 22 28

http://akela.mendelu.cz/~thala
___
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] escaping quotes in \ctxlua

2015-09-30 Thread Pablo Rodriguez
On 09/30/2015 05:20 PM, Wolfgang Schuster wrote:
>> Pablo Rodriguez 30. September 2015 um 17:07
>> Dear list,
>>
>> I have the following sample:
>>
>> \starttext
>> \startluacode
>> tex.print(os.getenv("USER")
>> \stopluacode
>>
>> \ctxlua{tex.print(os.getenv("USER")}
>> \stoptext
>>
>> How can I escape the quotes in the \ctxlua command?
> You have to add a  closing ) for tex.print in both Lua calls but you can
> replace the second version with \cldcontext{os.getenv("USER")}.

Many thanks for your replies, Wolfgang and Thomas.

I knew that parentheses need to be closed, but I totally overlooked it
in both tex.print commands.

Many thanks for your help and sorry for the noise,


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
___

[NTG-context] arguments to ctxlua

2010-03-30 Thread Hans van der Meer

When I have a Lua function with 2 arguments:
\startluacode
function f(a,b)
...
\stopluacode

called through:
\def\callf#1#2{\ctxlua{f(#1,#2)}}

and do this actually with one argument:
\callf{one}

then I find that the absent argument b in f(a,b) is not nil but a  
string of length 1.


That is a bit of a nuisance because I would like to use the Lua idiom:
function f(a,b)
local b = b or default
but that is frustrated by the behaviour shown.

Is this an artifact of either luatex or ConTeXt? Can it be avoided  
such that in this case b will be nil?



Hans van der Meer




___
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] arguments to ctxlua

2010-03-30 Thread Hans Hagen

On 30-3-2010 19:45, Hans van der Meer wrote:

When I have a Lua function with 2 arguments:
\startluacode
function f(a,b)
...
\stopluacode

called through:
\def\callf#1#2{\ctxlua{f(#1,#2)}}

and do this actually with one argument:
\callf{one}



so, #1 will be one and #2 will be the next token (whatever that is)


then I find that the absent argument b in f(a,b) is not nil but a string
of length 1.

That is a bit of a nuisance because I would like to use the Lua idiom:
function f(a,b)
local b = b or default
but that is frustrated by the behaviour shown.

Is this an artifact of either luatex or ConTeXt? Can it be avoided such
that in this case b will be nil?


just tex

but in any case even if #2 is empty you need to test like this

local b = b ~=  and b or default

watch the order ... we want b to be set to b when not empty


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: 038 477 53 69 | fax: 038 477 53 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] arguments to ctxlua

2010-03-30 Thread Peter Münster
On Tue, Mar 30 2010, Hans van der Meer wrote:

 called through:
   \def\callf#1#2{\ctxlua{f(#1,#2)}}

 and do this actually with one argument:
   \callf{one}

 then I find that the absent argument b in f(a,b) is not nil but a string of 
 length 1.

Hello Hans,

You want probably something like this:

\startluacode
userdata = userdata or {}
function userdata.f(a, b)
b = b or default value
tex.print(string.format(a = '%s' and b = '%s'\\par, a, b))
end
\stopluacode
\def\callf{\dodoubleempty\docallf}
\def\docallf[#1][#2]{\ctxlua{userdata.f(#1\ifsecondargument, #2\fi)}}
\starttext
\callf[one]
\callf[one][two]
\callf[one][]
\callf[][]
\callf[][two]
\callf[]
\stoptext

Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/


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