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
___