* constructing block content partly with lua
@ 2019-02-05 15:01 Sanjoy Mahajan
2019-02-05 15:24 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: Sanjoy Mahajan @ 2019-02-05 15:01 UTC (permalink / raw)
To: mailing list for ConTeXt users
Dear List,
I've been trying to construct part of a block's content programmatically
with Lua. Despite many experiments and much rereading of the cld manual
(especially chapter 3 on functions), the following attempt fails for
reasons that perplex me. Below is the MNWE (Minimal NonWorking
Example). It fails with these lines in the log file:
structure > sectioning > subject @ level 3 : 0.0.0 -> Answers
tex error > tex error on line 1 in file virtual://block.answer.1: ! Undefined control sequence
l.1 \oneargTestparameter
That is, when the "answer" block is included via \useblocks, somehow the
beginning of the answer, which should be "\onearg{Test parameter}", has
its curly braces and spaces elided.
What characteristic(s) of the Lua interface am I missing? Thank you if
you happen to where I've gone wrong. I've also tried steppers without
much luck (and, admittedly, without really understanding their use).
=============== testluabeginblock.tex ===============
\defineblock[answer]
\hideblocks[answer]
\def\onearg#1{{\bf #1}}
\def\noarg{{\it fixed argument}}
\starttext
\startluacode
context.beginanswer()
context("\\onearg{Test parameter}")
\stopluacode
This is part of the answer.
\endanswer
\subject{Answers}
\useblocks[answer]
\stoptext
=============== end testluabeginblock.tex ===============
-Sanjoy
___________________________________________________________________________________
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] 5+ messages in thread
* Re: constructing block content partly with lua
2019-02-05 15:01 constructing block content partly with lua Sanjoy Mahajan
@ 2019-02-05 15:24 ` Hans Hagen
2019-02-05 15:28 ` Sanjoy Mahajan
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2019-02-05 15:24 UTC (permalink / raw)
To: mailing list for ConTeXt users, Sanjoy Mahajan
On 2/5/2019 4:01 PM, Sanjoy Mahajan wrote:
> Dear List,
>
> I've been trying to construct part of a block's content programmatically
> with Lua. Despite many experiments and much rereading of the cld manual
> (especially chapter 3 on functions), the following attempt fails for
> reasons that perplex me. Below is the MNWE (Minimal NonWorking
> Example). It fails with these lines in the log file:
>
> structure > sectioning > subject @ level 3 : 0.0.0 -> Answers
>
> tex error > tex error on line 1 in file virtual://block.answer.1: ! Undefined control sequence
>
> l.1 \oneargTestparameter
>
>
> That is, when the "answer" block is included via \useblocks, somehow the
> beginning of the answer, which should be "\onearg{Test parameter}", has
> its curly braces and spaces elided.
>
> What characteristic(s) of the Lua interface am I missing? Thank you if
> you happen to where I've gone wrong. I've also tried steppers without
> much luck (and, admittedly, without really understanding their use).
>
> =============== testluabeginblock.tex ===============
> \defineblock[answer]
> \hideblocks[answer]
>
> \def\onearg#1{{\bf #1}}
> \def\noarg{{\it fixed argument}}
>
> \starttext
>
> \startluacode
> context.beginanswer()
> context("\\onearg{Test parameter}")
does
context.onearg("Test parameter")
work?
> \stopluacode
> This is part of the answer.
>
> \endanswer
>
> \subject{Answers}
>
> \useblocks[answer]
>
> \stoptext
> =============== end testluabeginblock.tex ===============
>
> -Sanjoy
>
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
--
-----------------------------------------------------------------
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] 5+ messages in thread
* Re: constructing block content partly with lua
2019-02-05 15:24 ` Hans Hagen
@ 2019-02-05 15:28 ` Sanjoy Mahajan
2019-02-05 16:21 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: Sanjoy Mahajan @ 2019-02-05 15:28 UTC (permalink / raw)
To: Hans Hagen, mailing list for ConTeXt users
On 2019-02-05 16:24, Hans Hagen <j.hagen@xs4all.nl> wrote:
>> \startluacode
>> context.beginanswer()
>> context("\\onearg{Test parameter}")
>
> does
>
> context.onearg("Test parameter")
>
> work?
Sorry, I forgot to say that I had tried that version too but also with
no luck. Also, either version of onerg works as expected if I delete
the context.beginanswer() and the \endanswer lines.
-Sanjoy
___________________________________________________________________________________
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] 5+ messages in thread
* Re: constructing block content partly with lua
2019-02-05 15:28 ` Sanjoy Mahajan
@ 2019-02-05 16:21 ` Hans Hagen
2019-02-06 15:25 ` Sanjoy Mahajan
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2019-02-05 16:21 UTC (permalink / raw)
To: Sanjoy Mahajan, mailing list for ConTeXt users
On 2/5/2019 4:28 PM, Sanjoy Mahajan wrote:
> On 2019-02-05 16:24, Hans Hagen <j.hagen@xs4all.nl> wrote:
>
>>> \startluacode
>>> context.beginanswer()
>>> context("\\onearg{Test parameter}")
>>
>> does
>>
>> context.onearg("Test parameter")
>>
>> work?
>
> Sorry, I forgot to say that I had tried that version too but also with
> no luck. Also, either version of onerg works as expected if I delete
> the context.beginanswer() and the \endanswer lines.
the problem is that you effectively use buffers so you have a different
catcode regime ... i'm not sure what you want but thsi might give a clue
\starttext
\defineblock[foo]
\beginfoo
test 1
\endfoo
\startluacode
buffers.assign("temp","test 2")
structures.blocks.save("foo",nil,nil,"temp")
\stopluacode
\useblocks[foo]
\stoptext
there are mechanisms for templates for constructing more meaningful
content than "test 2" (see test suite)
-----------------------------------------------------------------
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] 5+ messages in thread
* Re: constructing block content partly with lua
2019-02-05 16:21 ` Hans Hagen
@ 2019-02-06 15:25 ` Sanjoy Mahajan
0 siblings, 0 replies; 5+ messages in thread
From: Sanjoy Mahajan @ 2019-02-06 15:25 UTC (permalink / raw)
To: Hans Hagen, mailing list for ConTeXt users
On 2019-02-05 17:21, Hans Hagen <j.hagen@xs4all.nl> wrote:
> i'm not sure what you want but thsi might give a clue
> ...
> \startluacode
> buffers.assign("temp","test 2")
> structures.blocks.save("foo",nil,nil,"temp")
> \stopluacode
Ah, thanks, that looks like what I need, or at least part of it, and
will keep me busy making more experiments.
-Sanjoy
___________________________________________________________________________________
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] 5+ messages in thread
end of thread, other threads:[~2019-02-06 15:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-05 15:01 constructing block content partly with lua Sanjoy Mahajan
2019-02-05 15:24 ` Hans Hagen
2019-02-05 15:28 ` Sanjoy Mahajan
2019-02-05 16:21 ` Hans Hagen
2019-02-06 15:25 ` Sanjoy Mahajan
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).