ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* context.delayed as parameter of setuphead[before=...]
@ 2020-11-03  2:09 Sylvain Hubert
  2020-11-03  2:28 ` Jairo A. del Rio
  0 siblings, 1 reply; 8+ messages in thread
From: Sylvain Hubert @ 2020-11-03  2:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 297 bytes --]

Dear List,

I'm trying to mirror the context command
  `\setuphead[chapter][before=hello]`
into lua with delayed typesetting of 'hello', but
  `\ctxlua{context.setuphead({'chapter'}, {before=context.delayed'hello'})}`
does not have any effect. Could anyone help me on this? Thanks!

Best,
Sylvain

[-- Attachment #1.2: Type: text/html, Size: 462 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-03  2:09 context.delayed as parameter of setuphead[before=...] Sylvain Hubert
@ 2020-11-03  2:28 ` Jairo A. del Rio
  2020-11-03  3:05   ` Sylvain Hubert
  0 siblings, 1 reply; 8+ messages in thread
From: Jairo A. del Rio @ 2020-11-03  2:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1951 bytes --]

On the Lua side, you'll have to pass strings so your example works, as
tables like those in setuphead({somehead}, {somesettings}) are actual Lua
tables and follow Lua, not TeX, rules (see e.g. Lua reference in
https://www.lua.org/manual/5.4/ or, better, CLD manual in
http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf):


\starttext

\startluacode

--First example

for m = 1, 3 do

context.setuphead({'chapter'}, {before='hello'})

context.startchapter({title="I'm a chapter!"})

for i = 1, 3 do

context.input("knuth")

end

context.stopchapter()

end


--Second example

--We'll pass some strings to TeX

local nice = "ConTeXt is love, ConTeXt is life"

local somehead = 'chapter'

local sometext = 'vallejo-trilce-es'


context.setuphead({somehead}, {before=nice})

context.startchapter({title=somehead})

context.input(sometext)

context.stopchapter()

\stopluacode

\stoptext


I hope examples help.

Regards,

Jairo :)



El lun., 2 de nov. de 2020 a la(s) 21:09, Sylvain Hubert (
champignoom@gmail.com) escribió:

> Dear List,
>
> I'm trying to mirror the context command
>   `\setuphead[chapter][before=hello]`
> into lua with delayed typesetting of 'hello', but
>   `\ctxlua{context.setuphead({'chapter'},
> {before=context.delayed'hello'})}`
> does not have any effect. Could anyone help me on this? Thanks!
>
> Best,
> Sylvain
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 4970 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-03  2:28 ` Jairo A. del Rio
@ 2020-11-03  3:05   ` Sylvain Hubert
  2020-11-03  4:03     ` Jairo A. del Rio
  2020-11-03  8:03     ` Hans Hagen
  0 siblings, 2 replies; 8+ messages in thread
From: Sylvain Hubert @ 2020-11-03  3:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3086 bytes --]

> as tables like those in setuphead({somehead}, {somesettings}) are actual
Lua tables and follow Lua, not TeX, rules
But there are lua apis that support delayed TeX like
`context.chapter(context.delayed'text')`.
Whether or not the function is stored in a table should be theoretically
irrelevant.
I guess there should be a switch somewhere that let the command recognized
delayed function.

On Tue, 3 Nov 2020 at 03:29, Jairo A. del Rio <jairoadelrio6@gmail.com>
wrote:

> On the Lua side, you'll have to pass strings so your example works, as
> tables like those in setuphead({somehead}, {somesettings}) are actual Lua
> tables and follow Lua, not TeX, rules (see e.g. Lua reference in
> https://www.lua.org/manual/5.4/ or, better, CLD manual in
> http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf):
>
>
> \starttext
>
> \startluacode
>
> --First example
>
> for m = 1, 3 do
>
> context.setuphead({'chapter'}, {before='hello'})
>
> context.startchapter({title="I'm a chapter!"})
>
> for i = 1, 3 do
>
> context.input("knuth")
>
> end
>
> context.stopchapter()
>
> end
>
>
> --Second example
>
> --We'll pass some strings to TeX
>
> local nice = "ConTeXt is love, ConTeXt is life"
>
> local somehead = 'chapter'
>
> local sometext = 'vallejo-trilce-es'
>
>
> context.setuphead({somehead}, {before=nice})
>
> context.startchapter({title=somehead})
>
> context.input(sometext)
>
> context.stopchapter()
>
> \stopluacode
>
> \stoptext
>
>
> I hope examples help.
>
> Regards,
>
> Jairo :)
>
>
>
> El lun., 2 de nov. de 2020 a la(s) 21:09, Sylvain Hubert (
> champignoom@gmail.com) escribió:
>
>> Dear List,
>>
>> I'm trying to mirror the context command
>>   `\setuphead[chapter][before=hello]`
>> into lua with delayed typesetting of 'hello', but
>>   `\ctxlua{context.setuphead({'chapter'},
>> {before=context.delayed'hello'})}`
>> does not have any effect. Could anyone help me on this? Thanks!
>>
>> Best,
>> Sylvain
>>
>> ___________________________________________________________________________________
>> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 6827 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-03  3:05   ` Sylvain Hubert
@ 2020-11-03  4:03     ` Jairo A. del Rio
  2020-11-03  8:03     ` Hans Hagen
  1 sibling, 0 replies; 8+ messages in thread
From: Jairo A. del Rio @ 2020-11-03  4:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4528 bytes --]

Sorry. What I meant is: when you use

context.setuphead({'chapter'}, {title="Some text"})

at the Lua end, {'chapter'} and {title="Some text"} (notice "Some text" is
a string, not a function) are Lua tables. TeX will print "Some text", but
it won't work for context.delayed as it is another table (metatable
trickery to allow nesting, I guess). Try:

\starttext

\startluacode

context(type(context.delayed))

\stopluacode

\stoptext


Long story short: context.cmda(context.delayed.cmdb(something)) will
(possibly) work; context.cmdc({key=context.delayed.cmdd(somethingelse)})
won't.

Hans and Wolfgang can elaborate in case I've missed something.


Jairo :)

El lun., 2 de nov. de 2020 a la(s) 22:06, Sylvain Hubert (
champignoom@gmail.com) escribió:

> > as tables like those in setuphead({somehead}, {somesettings}) are actual
> Lua tables and follow Lua, not TeX, rules
> But there are lua apis that support delayed TeX like
> `context.chapter(context.delayed'text')`.
> Whether or not the function is stored in a table should be theoretically
> irrelevant.
> I guess there should be a switch somewhere that let the command recognized
> delayed function.
>
> On Tue, 3 Nov 2020 at 03:29, Jairo A. del Rio <jairoadelrio6@gmail.com>
> wrote:
>
>> On the Lua side, you'll have to pass strings so your example works, as
>> tables like those in setuphead({somehead}, {somesettings}) are actual Lua
>> tables and follow Lua, not TeX, rules (see e.g. Lua reference in
>> https://www.lua.org/manual/5.4/ or, better, CLD manual in
>> http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf):
>>
>>
>> \starttext
>>
>> \startluacode
>>
>> --First example
>>
>> for m = 1, 3 do
>>
>> context.setuphead({'chapter'}, {before='hello'})
>>
>> context.startchapter({title="I'm a chapter!"})
>>
>> for i = 1, 3 do
>>
>> context.input("knuth")
>>
>> end
>>
>> context.stopchapter()
>>
>> end
>>
>>
>> --Second example
>>
>> --We'll pass some strings to TeX
>>
>> local nice = "ConTeXt is love, ConTeXt is life"
>>
>> local somehead = 'chapter'
>>
>> local sometext = 'vallejo-trilce-es'
>>
>>
>> context.setuphead({somehead}, {before=nice})
>>
>> context.startchapter({title=somehead})
>>
>> context.input(sometext)
>>
>> context.stopchapter()
>>
>> \stopluacode
>>
>> \stoptext
>>
>>
>> I hope examples help.
>>
>> Regards,
>>
>> Jairo :)
>>
>>
>>
>> El lun., 2 de nov. de 2020 a la(s) 21:09, Sylvain Hubert (
>> champignoom@gmail.com) escribió:
>>
>>> Dear List,
>>>
>>> I'm trying to mirror the context command
>>>   `\setuphead[chapter][before=hello]`
>>> into lua with delayed typesetting of 'hello', but
>>>   `\ctxlua{context.setuphead({'chapter'},
>>> {before=context.delayed'hello'})}`
>>> does not have any effect. Could anyone help me on this? Thanks!
>>>
>>> Best,
>>> Sylvain
>>>
>>> ___________________________________________________________________________________
>>> 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
>>
>> ___________________________________________________________________________________
>>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 9628 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-03  3:05   ` Sylvain Hubert
  2020-11-03  4:03     ` Jairo A. del Rio
@ 2020-11-03  8:03     ` Hans Hagen
  2020-11-04 15:53       ` Sylvain Hubert
  1 sibling, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2020-11-03  8:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Sylvain Hubert

On 11/3/2020 4:05 AM, Sylvain Hubert wrote:
>  > as tables like those in setuphead({somehead}, {somesettings}) are 
> actual Lua tables and follow Lua, not TeX, rules
> But there are lua apis that support delayed TeX like 
> `context.chapter(context.delayed'text')`.
> Whether or not the function is stored in a table should be theoretically 
> irrelevant.
> I guess there should be a switch somewhere that let the command 
> recognized delayed function.
all is possible but not all is reasonable to support .. adding layer 
upon layed doesn't make it more pretty

anyway, chapter (section) titles go tinto a toc table and storing lua 
delayed function definitions there makes not much sense

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
___________________________________________________________________________________

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-03  8:03     ` Hans Hagen
@ 2020-11-04 15:53       ` Sylvain Hubert
  2020-11-04 16:35         ` Hans Hagen
  0 siblings, 1 reply; 8+ messages in thread
From: Sylvain Hubert @ 2020-11-04 15:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1517 bytes --]

% Hans, sorry for having replied on the wrong channel before.

On Tue, 3 Nov 2020 at 09:03, Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 11/3/2020 4:05 AM, Sylvain Hubert wrote:
> >  > as tables like those in setuphead({somehead}, {somesettings}) are
> > actual Lua tables and follow Lua, not TeX, rules
> > But there are lua apis that support delayed TeX like
> > `context.chapter(context.delayed'text')`.
> > Whether or not the function is stored in a table should be theoretically
> > irrelevant.
> > I guess there should be a switch somewhere that let the command
> > recognized delayed function.
> all is possible but not all is reasonable to support .. adding layer
> upon layed doesn't make it more pretty
>
Indeed, but still it would be nice to have a complete and consistent
interface between tex and lua unless it would harm the functionality.


>
> anyway, chapter (section) titles go tinto a toc table and storing lua
> delayed function definitions there makes not much sense
>
> It might be helpful in cases like alternative coloring. Writing
   "function() local x=1; return function() x=1-x; return ({'black',
'gray'})[x] end end"
can be way much easier for lua speakers than digging up a bunch of
documentations to figure out whether it's implemented, or how it can be
implemented in a language like TeX, or both which is worse. In such cases,
it would also be much natural to write 'before=function()..' than
'before=\ctxlua{function()...}` unless, again, the former harms the
functionality.

Sylvain

[-- Attachment #1.2: Type: text/html, Size: 2380 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-04 15:53       ` Sylvain Hubert
@ 2020-11-04 16:35         ` Hans Hagen
  2020-11-04 17:17           ` Sylvain Hubert
  0 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2020-11-04 16:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Sylvain Hubert

On 11/4/2020 4:53 PM, Sylvain Hubert wrote:
> % Hans, sorry for having replied on the wrong channel before.
> 
> On Tue, 3 Nov 2020 at 09:03, Hans Hagen <j.hagen@xs4all.nl 
> <mailto:j.hagen@xs4all.nl>> wrote:
> 
>     On 11/3/2020 4:05 AM, Sylvain Hubert wrote:
>      >  > as tables like those in setuphead({somehead}, {somesettings}) are
>      > actual Lua tables and follow Lua, not TeX, rules
>      > But there are lua apis that support delayed TeX like
>      > `context.chapter(context.delayed'text')`.
>      > Whether or not the function is stored in a table should be
>     theoretically
>      > irrelevant.
>      > I guess there should be a switch somewhere that let the command
>      > recognized delayed function.
>     all is possible but not all is reasonable to support .. adding layer
>     upon layed doesn't make it more pretty
> 
> Indeed, but still it would be nice to have a complete and consistent 
> interface between tex and lua unless it would harm the functionality.

it would harm performance because it involves parsing all values and 
also ways around cases where the title is "function" (lieral text).

>     anyway, chapter (section) titles go tinto a toc table and storing lua
>     delayed function definitions there makes not much sense
> 
> It might be helpful in cases like alternative coloring. Writing
>     "function() local x=1; return function() x=1-x; return ({'black', 
> 'gray'})[x] end end"
> can be way much easier for lua speakers than digging up a bunch of 
> documentations to figure out whether it's implemented, or how it can be 
> implemented in a language like TeX, or both which is worse. In such 
> cases, it would also be much natural to write 'before=function()..' than 
> 'before=\ctxlua{function()...}` unless, again, the former harms the 
> functionality.
Really? I have no clue what that function makec clearer than tex. And 
one still needs some documentation that explains what it does.

Often there often is a pretty clean way to do it with less code.

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
___________________________________________________________________________________

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

* Re: context.delayed as parameter of setuphead[before=...]
  2020-11-04 16:35         ` Hans Hagen
@ 2020-11-04 17:17           ` Sylvain Hubert
  0 siblings, 0 replies; 8+ messages in thread
From: Sylvain Hubert @ 2020-11-04 17:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1188 bytes --]

again, sorry for replying on the wrong channel.

On Wed, 4 Nov 2020 at 17:35, Hans Hagen <j.hagen@xs4all.nl> wrote:

>
> it would harm performance because it involves parsing all values and
> also ways around cases where the title is "function" (lieral text).
>

I'm not sure I understand what you mean by literal text "function" here,
but in any case isn't it a one-off <1ms cost to parse a function?

> "function() local x=1; return function() x=1-x; return ({'black',
> > 'gray'})[x] end end"
> > can be way much easier for lua speakers than digging up a bunch of
> > documentations to figure out whether it's implemented, or how it can be
> > implemented in a language like TeX, or both which is worse.
> Really? I have no clue what that function makec clearer than tex. And
> one still needs some documentation that explains what it does.
>
> Often there often is a pretty clean way to do it with less code.
>

For an experienced tex speaker, indeed.
But for an average user who just wants to typeset a bit of fancy stuff,
programming in tex is probably not the most pleasant thing to do and
arguably not the most reasonable either in light of any modern language
like lua.

Sylvain

[-- Attachment #1.2: Type: text/html, Size: 1889 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

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

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

end of thread, other threads:[~2020-11-04 17:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03  2:09 context.delayed as parameter of setuphead[before=...] Sylvain Hubert
2020-11-03  2:28 ` Jairo A. del Rio
2020-11-03  3:05   ` Sylvain Hubert
2020-11-03  4:03     ` Jairo A. del Rio
2020-11-03  8:03     ` Hans Hagen
2020-11-04 15:53       ` Sylvain Hubert
2020-11-04 16:35         ` Hans Hagen
2020-11-04 17:17           ` Sylvain Hubert

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).