Re: [NTG-context] Exchangeing content of variables between luacode and context

2019-11-20 Thread Rudolf Bahr
On Wed, Nov 20, 2019 at 09:24:44AM +0100, Hans Hagen wrote:
> you can store info in the tuc file (there are examplex on the wiki and in
> the test suite) or you cam create a table, save it at the end of the run and
> load it at the start
> 
> (assuming that you cannot just recalculate the values each run, but i assume
> that you have a reason for not doing that)



Hraban and Hans, I thank you for your answers!

Recalculating the results of invoked Luacode functions might be the best
and simplest choice, because finding a good hash key for a lua table which
must be created by the ConTeXt/Luacode program page itself could become rather
difficult (one could get into devil's kitchen, as we say). On the other side
one single lua table only for the current run, similar to .tuc files, is helpful
and necessary to have a look onto the results of the used luacode functions.
Sometimes they are the only help in error finding.

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] Exchangeing content of variables between luacode and context

2019-11-20 Thread Hans Hagen

On 11/19/2019 8:34 PM, Rudolf Bahr wrote:


My 'actual problem' is more or less a design problem: Should in a book project
ConTeXt be the master and Luacode the slave or vice versa? Both seems possible.


nearly always context is th emaster (it is anyway as it manages the 
process)



The task to solve is to set a photo album with say 300 DIN A4 landscape pages.
On every page there should be 1 to 4 columns filled with photos and texts mostly
defined in layers.

Up to now I made all in ConTeXt manually by trying, for instance::
- To estimate the width of layers, if neighboured layers should contain photos 
of
   same height with respect to center horizontally all columns at end of page.


can be done in tex of lua


- To complete abbreviations of long picture names; it's rather annoying doing
   this by copy and paste with hundreds of photo names; instead I'd like to type
   a short code and Luacode should complete it to the full name.


that can be done runtime ...


- To estimate the shift amount of all columns together in order to horizontally
   get them centered on the page.


can be done by tex or lua


All of these tasks can be made best by Luacode functions. And I'd like to save
their results in the ConTeXt program permanently. With 'tokens.setters.macro()'
it's possible only in the same, Luacode calling ConTeXt run. In the following
run, the macro shows its original value again and the Luacode program must be
called again to alter it.


you can store info in the tuc file (there are examplex on the wiki and 
in the test suite) or you cam create a table, save it at the end of the 
run and load it at the start


(assuming that you cannot just recalculate the values each run, but i 
assume that you have a reason for not doing that)



So I've to think about making Luacode the master and ConTeXt the slave. Then 
it'd
be possible to embody Luacode's results permanently in the ConTeXt code. Vice 
versa
a solution could be to store Luacode's results in a flattened Lua table on disc.
But the perfect relating to their ConTeXt page remains difficult when inserting
or deleting of pages in an ensemble of 300 pages should become necessary. 
Another
much simpler solution would be the proposal above, namely, to copy the ConTeXt
program step by step and page by page to another file and introducing the 
Luacode
results simultaneously.


if each page can be recognized you can make a hash of its properties and 
store the page specific data using that hash



In [1] there is a chapter with "stepper" commands, but I didn't understand that,
so I can't say, whether they are suitable for this issue.


unrelated

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] Exchangeing content of variables between luacode and context

2019-11-19 Thread Henning Hraban Ramm
Hi Rudolf,
storing variable states within the script sounds like AppleScript…

Why don’t you write your settings into some file (a Lua table representation 
would make sense, otherwise something like JSON or INI) and read that in in 
every run, if it exists?


Grüßlinge, Hraban
---
https://www.fiee.net
http://wiki.contextgarden.net
https://www.dreiviertelhaus.de
GPG Key ID 1C9B22FD

___
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] Exchangeing content of variables between luacode and context

2019-11-19 Thread Rudolf Bahr
On Tue, Nov 19, 2019 at 04:55:15PM +0100, Wolfgang Schuster wrote:
> 
> Can you make a minimal example of your actual problem.


No, sorry, I can't.

My 'actual problem' is more or less a design problem: Should in a book project
ConTeXt be the master and Luacode the slave or vice versa? Both seems possible.

The task to solve is to set a photo album with say 300 DIN A4 landscape pages.
On every page there should be 1 to 4 columns filled with photos and texts mostly
defined in layers.

Up to now I made all in ConTeXt manually by trying, for instance::
- To estimate the width of layers, if neighboured layers should contain photos 
of
  same height with respect to center horizontally all columns at end of page.
- To complete abbreviations of long picture names; it's rather annoying doing
  this by copy and paste with hundreds of photo names; instead I'd like to type
  a short code and Luacode should complete it to the full name.
- To estimate the shift amount of all columns together in order to horizontally
  get them centered on the page.

All of these tasks can be made best by Luacode functions. And I'd like to save
their results in the ConTeXt program permanently. With 'tokens.setters.macro()'
it's possible only in the same, Luacode calling ConTeXt run. In the following
run, the macro shows its original value again and the Luacode program must be
called again to alter it.

So I've to think about making Luacode the master and ConTeXt the slave. Then 
it'd
be possible to embody Luacode's results permanently in the ConTeXt code. Vice 
versa
a solution could be to store Luacode's results in a flattened Lua table on disc.
But the perfect relating to their ConTeXt page remains difficult when inserting
or deleting of pages in an ensemble of 300 pages should become necessary. 
Another
much simpler solution would be the proposal above, namely, to copy the ConTeXt
program step by step and page by page to another file and introducing the 
Luacode
results simultaneously. 

In [1] there is a chapter with "stepper" commands, but I didn't understand that,
so I can't say, whether they are suitable for this issue.

Rudolf

[1] Hans Hagen, "ConTeXt Lua Documents", January 12, 2018, 3.4, page 30
___
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] Exchangeing content of variables between luacode and context

2019-11-19 Thread Wolfgang Schuster

Rudolf Bahr schrieb am 19.11.2019 um 14:19:

Hello All!

To send variable contents from context to luacode I can put them into the
function invocation or use 'tokens.getters.macro("TestA")',
an interesting and very nice possibility to let luacode itself getting
contents of context macros. The (only?) way back, from luacode to context,
could be done by 'tokens.setters.macro("TestA","a")' [1] .

Now, to store Luacode's variable contents permanently in context programs
I could Luacode let copy my ConTeXt program to another place on disk with
a newly defined macro inside. But, does somebody know (by chance) of another,
more elegant possibility? I think giving back a value by "return" won't work.


Can you make a minimal example of your actual problem.

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
___