ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Creating TeX dimensions and counters registers directly in Lua
@ 2012-08-22  7:19 Jaroslav Hajtmar
  2012-08-22  7:43 ` Wolfgang Schuster
  0 siblings, 1 reply; 8+ messages in thread
From: Jaroslav Hajtmar @ 2012-08-22  7:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello all,
Is it possible to create a new dimension ConTeXt register directly in 
Lua, or I have to first create the ConTeXt dimensional register and then 
to subsequently assign it a value?

Here is example:

\starttext
     \newdimen\mydimension
     \directlua{tex.setdimen("mydimension", 123)}
\stoptext

works fine, but all like:

\starttext
     \directlua{tex.print([[\newdimen\myotherdimension]])}
     \directlua{tex.setdimen("myotherdimension", 123)}
     \directlua{tex.newdimen("myotherdimension")}

     etc...

\stoptext

fails.

In addition, I am interested in whether directly in Lua to create a new 
counter as in the previous.

\starttext
\newcount\mycount
\directlua{
tex.setcount("mycount",125)
}

again works, but anything like:

\starttext
     \directlua{tex.print([[\newcount\myothercount]])}
     \directlua{tex.newcount("myothercount")}
     etc...

\stoptext

again fails...

Is there any source or examples to study anything about it?

Thanx Jaroslav

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22  7:19 Creating TeX dimensions and counters registers directly in Lua Jaroslav Hajtmar
@ 2012-08-22  7:43 ` Wolfgang Schuster
  2012-08-22  9:09   ` Jaroslav Hajtmar
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Schuster @ 2012-08-22  7:43 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users


Am 22.08.2012 um 09:19 schrieb Jaroslav Hajtmar <hajtmar@gyza.cz>:

> Hello all,
> Is it possible to create a new dimension ConTeXt register directly in Lua, or I have to first create the ConTeXt dimensional register and then to subsequently assign it a value?
> 
> Here is example:
> 
> \starttext
>    \newdimen\mydimension
>    \directlua{tex.setdimen("mydimension", 123)}
> \stoptext
> 
> works fine, but all like:
> 
> \starttext
>    \directlua{tex.print([[\newdimen\myotherdimension]])}
>    \directlua{tex.setdimen("myotherdimension", 123)}
>    \directlua{tex.newdimen("myotherdimension")}
> 
>    etc...
> 
> \stoptext
> 
> fails.
> 
> In addition, I am interested in whether directly in Lua to create a new counter as in the previous.
> 
> \starttext
> \newcount\mycount
> \directlua{
> tex.setcount("mycount",125)
> }
> 
> again works, but anything like:
> 
> \starttext
>    \directlua{tex.print([[\newcount\myothercount]])}
>    \directlua{tex.newcount("myothercount")}
>    etc...
> 
> \stoptext
> 
> again fails...
> 
> Is there any source or examples to study anything about it?


AFAIK there is no tex.setdimen but what’s the problem to use Lua tables to save the values.

\starttext

\ctxlua{mydimension = number.topoints(10000)}
\ctxlua{context(mydimension)}

\blank

\ctxlua{myotherdimension = 123456}
\ctxlua{context(number.tocentimeters(myotherdimension))}

\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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22  7:43 ` Wolfgang Schuster
@ 2012-08-22  9:09   ` Jaroslav Hajtmar
  2012-08-22 10:32     ` Hans Hagen
  2012-08-22 10:34     ` Peter Münster
  0 siblings, 2 replies; 8+ messages in thread
From: Jaroslav Hajtmar @ 2012-08-22  9:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thanks Wolfgang for the reply,
but I must have misunderstood. My point is, that TeX registers was 
subsequently visible and usable in TeX (eg for width or height of boxes, 
etc.)

Eg. for example, \the\mydimension can see that this does not occur!
In addition, I solve the problem at LuaTEX, so ConTeXt converting 
functions do not work etc. ..

Thanx Jaroslav

Here is another example:

\starttext

\newdimen\mytexdimension
\mytexdimension=100pt


\ctxlua{myluadimension = number.topoints(10000)}
\ctxlua{context(myluadimension)}

\the\mytexdimension
\hbox to\mytexdimension{XXXXX}YYYY

% FAILS
%\the\myluadimension
%\hbox to\myluadimension{XXXXX}YYYY


\stoptext





Dne 22.8.2012 9:43, Wolfgang Schuster napsal(a):
> \starttext
>
> \ctxlua{mydimension = number.topoints(10000)}
> \ctxlua{context(mydimension)}
>
> \blank
>
> \ctxlua{myotherdimension = 123456}
> \ctxlua{context(number.tocentimeters(myotherdimension))}
>
> \stoptext
>    

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22  9:09   ` Jaroslav Hajtmar
@ 2012-08-22 10:32     ` Hans Hagen
  2012-08-22 11:24       ` Jaroslav Hajtmar
  2012-08-22 10:34     ` Peter Münster
  1 sibling, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2012-08-22 10:32 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users

On 22-8-2012 11:09, Jaroslav Hajtmar wrote:
> Thanks Wolfgang for the reply,
> but I must have misunderstood. My point is, that TeX registers was
> subsequently visible and usable in TeX (eg for width or height of boxes,
> etc.)
>
> Eg. for example, \the\mydimension can see that this does not occur!
> In addition, I solve the problem at LuaTEX, so ConTeXt converting
> functions do not work etc. ..
>
> Thanx Jaroslav
>
> Here is another example:
>
> \starttext
>
> \newdimen\mytexdimension
> \mytexdimension=100pt
>
>
> \ctxlua{myluadimension = number.topoints(10000)}
> \ctxlua{context(myluadimension)}
>
> \the\mytexdimension
> \hbox to\mytexdimension{XXXXX}YYYY
>
> % FAILS
> %\the\myluadimension
> %\hbox to\myluadimension{XXXXX}YYYY

Of course that fails: why should the globally defined
lua variable "myluadimension" magically become a \dimen
register at the tex end? And believe it or not, the context
conversion function do work, else mkiv wouldn't work.

> \stoptext

Here is the right code:

\starttext

\newdimen\mytexdimension \mytexdimension 100pt

\ruledhbox to\mytexdimension{\the\mytexdimension}

\ctxlua{document.myluadimension = "200pt"}

\ruledhbox to 
\cldcontext{document.myluadimension}{\cldcontext{document.myluadimension}}

\ctxlua{tex.dimen.mytexdimension = "300pt"}

\ruledhbox to\mytexdimension{\the\mytexdimension}

\stoptext

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22  9:09   ` Jaroslav Hajtmar
  2012-08-22 10:32     ` Hans Hagen
@ 2012-08-22 10:34     ` Peter Münster
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Münster @ 2012-08-22 10:34 UTC (permalink / raw)
  To: hajtmar; +Cc: mailing list for ConTeXt users

On Wed, Aug 22 2012, Jaroslav Hajtmar wrote:

> \ctxlua{myluadimension = number.topoints(10000)}
> \ctxlua{context(myluadimension)}

\def\myluadimension{\ctxlua{context(myluadimension)}}

...

\hbox to\myluadimension{XXXXX}YYYY

-- 
           Peter
___________________________________________________________________________________
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22 10:32     ` Hans Hagen
@ 2012-08-22 11:24       ` Jaroslav Hajtmar
  2012-08-22 12:12         ` Hans Hagen
  0 siblings, 1 reply; 8+ messages in thread
From: Jaroslav Hajtmar @ 2012-08-22 11:24 UTC (permalink / raw)
  Cc: mailing list for ConTeXt users

Thank to Hans and Peter too.
It works in context fine now. I would like realize this same in pure LuaTeX.

I was primarily in the query for it to find Lua equivalent of TeX 
primitives \newdimen and  \newcount (for direct creating new TeX registers)
I could use something like "\directlua{tex.newdimen.mydimen}" that would 
create TeX register "mydimen" and then 
\directlua{tex.dimen.mydimen=200*2^16} which set value of register and 
that should be present in TeX for direct use such as "\the\mydimen" etc.
I apologize for my naivete :-).

Of course, I did not think that the global variable is magically changed 
the registry value, I just did not know how to implement it.
Plus, I had in mind that ConTeXt conversion functions do not work in a 
clean LuaTEX (without reading about some library functions).


One more thanx.
Jaroslav


Here is my pure luatex example. Is there any easy way?

\newdimen\mytexdimension
\mytexdimension 100pt

mytexdimension: .\hbox to\mytexdimension{\the\mytexdimension}.

\directlua{tex.myluadimension = "200pt"}

myluadimension: .\hbox to 
\directlua{tex.print(tex.myluadimension)}{\directlua{tex.print(tex.myluadimension)}}.

\directlua{tex.dimen.mytexdimension = "300pt"}

mytexdimension: .\hbox to\mytexdimension{\the\mytexdimension}.

\def\myluadimension{\directlua{tex.print(tex.myluadimension)}}

myluadimension: .\hbox to\myluadimension{\myluadimension}.

\bye



Dne 22.8.2012 12:32, Hans Hagen napsal(a):
> On 22-8-2012 11:09, Jaroslav Hajtmar wrote:
>> Thanks Wolfgang for the reply,
>> but I must have misunderstood. My point is, that TeX registers was
>> subsequently visible and usable in TeX (eg for width or height of boxes,
>> etc.)
>>
>> Eg. for example, \the\mydimension can see that this does not occur!
>> In addition, I solve the problem at LuaTEX, so ConTeXt converting
>> functions do not work etc. ..
>>
>> Thanx Jaroslav
>>
>> Here is another example:
>>
>> \starttext
>>
>> \newdimen\mytexdimension
>> \mytexdimension=100pt
>>
>>
>> \ctxlua{myluadimension = number.topoints(10000)}
>> \ctxlua{context(myluadimension)}
>>
>> \the\mytexdimension
>> \hbox to\mytexdimension{XXXXX}YYYY
>>
>> % FAILS
>> %\the\myluadimension
>> %\hbox to\myluadimension{XXXXX}YYYY
>
> Of course that fails: why should the globally defined
> lua variable "myluadimension" magically become a \dimen
> register at the tex end? And believe it or not, the context
> conversion function do work, else mkiv wouldn't work.
>
>> \stoptext
>
> Here is the right code:
>
> \starttext
>
> \newdimen\mytexdimension \mytexdimension 100pt
>
> \ruledhbox to\mytexdimension{\the\mytexdimension}
>
> \ctxlua{document.myluadimension = "200pt"}
>
> \ruledhbox to 
> \cldcontext{document.myluadimension}{\cldcontext{document.myluadimension}} 
>
>
> \ctxlua{tex.dimen.mytexdimension = "300pt"}
>
> \ruledhbox to\mytexdimension{\the\mytexdimension}
>
> \stoptext
>
> -----------------------------------------------------------------
>                                           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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22 11:24       ` Jaroslav Hajtmar
@ 2012-08-22 12:12         ` Hans Hagen
  2012-08-22 19:47           ` Jaroslav Hajtmar
  0 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2012-08-22 12:12 UTC (permalink / raw)
  To: hajtmar, mailing list for ConTeXt users

On 22-8-2012 13:24, Jaroslav Hajtmar wrote:
> Thank to Hans and Peter too.
> It works in context fine now. I would like realize this same in pure
> LuaTeX.
>
> I was primarily in the query for it to find Lua equivalent of TeX
> primitives \newdimen and  \newcount (for direct creating new TeX registers)
> I could use something like "\directlua{tex.newdimen.mydimen}" that would
> create TeX register "mydimen" and then
> \directlua{tex.dimen.mydimen=200*2^16} which set value of register and
> that should be present in TeX for direct use such as "\the\mydimen" etc.
> I apologize for my naivete :-).

Just do:

tex.dimen[20001] = "100pt"

at the lau end and at the tex end:

\dimen20001=100pt

keep in mind that \newdimen is just an allocator that associates a \cs 
and the implementation of that is pretty macro package dependent! 
Starting at 20000 makes sure that you have no clash with existing 
registers.

> Of course, I did not think that the global variable is magically changed
> the registry value, I just did not know how to implement it.
> Plus, I had in mind that ConTeXt conversion functions do not work in a
> clean LuaTEX (without reading about some library functions).

Ok, but keep in mind that clean luatex does not exist. As soon as one 
starts doing things at the lua end that reflects on the tex end, you 
have a dependency.

I will add a context.newdimen function so that one can do:

\startluacode

     document.mydimen = context.newdimen("MyDimen")

     tex.dimen[document.mydimen] = "10pt"

\stopluacode

\the\MyDimen

\MyDimen=100pt

\the\MyDimen

\startluacode
     context(number.points(tex.dimen[document.mydimen]))
\stopluacode

Posting the implemenation makes no sense as it refers to low level 
context properties that users should not be troubled with.

PS. From the context point of view I see no advantages of using plain. 
First of all, one can still do pretty plain things in context.

Hans

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Creating TeX dimensions and counters registers directly in Lua
  2012-08-22 12:12         ` Hans Hagen
@ 2012-08-22 19:47           ` Jaroslav Hajtmar
  0 siblings, 0 replies; 8+ messages in thread
From: Jaroslav Hajtmar @ 2012-08-22 19:47 UTC (permalink / raw)
  Cc: mailing list for ConTeXt users

Great!!!
Thanx very much Hans...

Normally I do all things in ConTeXt, but I am preparing a beginning 
tutorial for users of LaTeX and PlainTeX, who would be interested in 
getting to know the basics LuaTEX. Therefore I am seeking a solution 
applicable in LuaLaTeX and LuaPlain too.

Jaroslav Hajtmar



Dne 22.8.2012 14:12, Hans Hagen napsal(a):
> On 22-8-2012 13:24, Jaroslav Hajtmar wrote:
>> Thank to Hans and Peter too.
>> It works in context fine now. I would like realize this same in pure
>> LuaTeX.
>>
>> I was primarily in the query for it to find Lua equivalent of TeX
>> primitives \newdimen and  \newcount (for direct creating new TeX 
>> registers)
>> I could use something like "\directlua{tex.newdimen.mydimen}" that would
>> create TeX register "mydimen" and then
>> \directlua{tex.dimen.mydimen=200*2^16} which set value of register and
>> that should be present in TeX for direct use such as "\the\mydimen" etc.
>> I apologize for my naivete :-).
>
> Just do:
>
> tex.dimen[20001] = "100pt"
>
> at the lau end and at the tex end:
>
> \dimen20001=100pt
>
> keep in mind that \newdimen is just an allocator that associates a \cs 
> and the implementation of that is pretty macro package dependent! 
> Starting at 20000 makes sure that you have no clash with existing 
> registers.
>
>> Of course, I did not think that the global variable is magically changed
>> the registry value, I just did not know how to implement it.
>> Plus, I had in mind that ConTeXt conversion functions do not work in a
>> clean LuaTEX (without reading about some library functions).
>
> Ok, but keep in mind that clean luatex does not exist. As soon as one 
> starts doing things at the lua end that reflects on the tex end, you 
> have a dependency.
>
> I will add a context.newdimen function so that one can do:
>
> \startluacode
>
>     document.mydimen = context.newdimen("MyDimen")
>
>     tex.dimen[document.mydimen] = "10pt"
>
> \stopluacode
>
> \the\MyDimen
>
> \MyDimen=100pt
>
> \the\MyDimen
>
> \startluacode
>     context(number.points(tex.dimen[document.mydimen]))
> \stopluacode
>
> Posting the implemenation makes no sense as it refers to low level 
> context properties that users should not be troubled with.
>
> PS. From the context point of view I see no advantages of using plain. 
> First of all, one can still do pretty plain things in context.
>
> Hans
>
> -----------------------------------------------------------------
>                                           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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-22 19:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-22  7:19 Creating TeX dimensions and counters registers directly in Lua Jaroslav Hajtmar
2012-08-22  7:43 ` Wolfgang Schuster
2012-08-22  9:09   ` Jaroslav Hajtmar
2012-08-22 10:32     ` Hans Hagen
2012-08-22 11:24       ` Jaroslav Hajtmar
2012-08-22 12:12         ` Hans Hagen
2012-08-22 19:47           ` Jaroslav Hajtmar
2012-08-22 10:34     ` Peter Münster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).