ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* filling buffers in cld documents
@ 2022-11-27 12:05 damien thiriet via ntg-context
  2022-11-27 13:04 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: damien thiriet via ntg-context @ 2022-11-27 12:05 UTC (permalink / raw)
  To: ntg-context; +Cc: damien

Hi,


I am used to giving very extensive feedbacks to my pupils.
These are buffers with xtables flushing lua vectors.
Here is their basic structures:

* an environment that stores xtables. Turned into MWE, look like:

    \startenvironment env_corrige.mkiv

    \startluacode
       userdata = userdata or {}
    function userdata.Critere (commentaire,note,notemax)
       context.startxcell {"width=11cm","height=2.75cm"}
          context(Eleve[commentaire])
       context.stopxcell ()
       context.startxcell {"width=1.5cm","align=flushright"}
          context(Eleve[note])
          context("/")
          context(notemax)
       context.stopxcell ()
    end
    \stopluacode

    \startbuffer [grille]
    \startxtable
       \startxrow
          \startxcell
             \ctxlua {userdata.Critere ("structure","NoteStructure",2)}
          \stopxcell
       \stopxrow
    \stopxtable
    \stopbuffer
    \stopenvironment

* The main file is divided in subjects, each one of them
being the feedback to one pupil. In a MWE fashion

    \useenvironment [env_corrige]
    \starttext
    \startsubject[title={Astérix}]
    \startluacode
    Eleve = {
       structure = "analyse très fine",
       NoteStructure = 2,
    }
    \stopluacode
    \getbuffer [grille]
    \stopsubject

    \startsubject[title={Obélix}]
    Eleve = {
       structure = "le détail doit être travaillé. Pensez à la finesse de 
vos menhirs…"
       NoteStructure = 1,
    }
    \stopsubject
    \getbuffer [grille]
    \stoptext

Since whatever I fill in those files is written
inside luacode environment, I tried to switch to
cld documents.

Here is my main file in cld version

    context.useenvironment({"env_corrige"})

    context.starttext()

    context.startsubject({title="Asterix"})

    Eleve = {
       structure = "analyse très fine",
       NoteStructure = 2,
    }
    context.getbuffer({"ExoCorrection"})
    context.stopsubsubject()

    context.startsubject({title="Obélix"})

    Eleve = {
       structure = "le détail doit être travaillé. Pensez à la finesse de 
vos menhirs…"
       NoteStructure = 1,
    }
    context.getbuffer({"ExoCorrection"})
    context.stopsubsubject()
    context.stoptext()

The troubles is that buffers are filled with
the last version of Eleve table.
I guess this is because the whole file
is parsed and then filled in buffers.
My understanding of the cld manuel is that
context.tobuffer()
and
context.direct()

should be used, but couldn't figure out how.
Tried several times, also with context.step but
all failed.
I think I didn't properly understand the "temp"
and str of context.tobuffer description in manual.

What changes should I introduce to my cld files?

Best regards,

Damien Thiriet
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

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

* Re: filling buffers in cld documents
  2022-11-27 12:05 filling buffers in cld documents damien thiriet via ntg-context
@ 2022-11-27 13:04 ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen via ntg-context @ 2022-11-27 13:04 UTC (permalink / raw)
  To: damien thiriet via ntg-context; +Cc: Hans Hagen

[-- Attachment #1: Type: text/plain, Size: 3927 bytes --]

On 11/27/2022 1:05 PM, damien thiriet via ntg-context wrote:
> Hi,
> 
> 
> I am used to giving very extensive feedbacks to my pupils.
> These are buffers with xtables flushing lua vectors.
> Here is their basic structures:
> 
> * an environment that stores xtables. Turned into MWE, look like:
> 
>     \startenvironment env_corrige.mkiv
> 
>     \startluacode
>        userdata = userdata or {}
>     function userdata.Critere (commentaire,note,notemax)
>        context.startxcell {"width=11cm","height=2.75cm"}
>           context(Eleve[commentaire])
>        context.stopxcell ()
>        context.startxcell {"width=1.5cm","align=flushright"}
>           context(Eleve[note])
>           context("/")
>           context(notemax)
>        context.stopxcell ()
>     end
>     \stopluacode
> 
>     \startbuffer [grille]
>     \startxtable
>        \startxrow
>           \startxcell
>              \ctxlua {userdata.Critere ("structure","NoteStructure",2)}
>           \stopxcell
>        \stopxrow
>     \stopxtable
>     \stopbuffer
>     \stopenvironment
> 
> * The main file is divided in subjects, each one of them
> being the feedback to one pupil. In a MWE fashion
> 
>     \useenvironment [env_corrige]
>     \starttext
>     \startsubject[title={Astérix}]
>     \startluacode
>     Eleve = {
>        structure = "analyse très fine",
>        NoteStructure = 2,
>     }
>     \stopluacode
>     \getbuffer [grille]
>     \stopsubject
> 
>     \startsubject[title={Obélix}]
>     Eleve = {
>        structure = "le détail doit être travaillé. Pensez à la finesse 
> de vos menhirs…"
>        NoteStructure = 1,
>     }
>     \stopsubject
>     \getbuffer [grille]
>     \stoptext
> 
> Since whatever I fill in those files is written
> inside luacode environment, I tried to switch to
> cld documents.
> 
> Here is my main file in cld version
> 
>     context.useenvironment({"env_corrige"})
> 
>     context.starttext()
> 
>     context.startsubject({title="Asterix"})
> 
>     Eleve = {
>        structure = "analyse très fine",
>        NoteStructure = 2,
>     }
>     context.getbuffer({"ExoCorrection"})
>     context.stopsubsubject()
> 
>     context.startsubject({title="Obélix"})
> 
>     Eleve = {
>        structure = "le détail doit être travaillé. Pensez à la finesse 
> de vos menhirs…"
>        NoteStructure = 1,
>     }
>     context.getbuffer({"ExoCorrection"})
>     context.stopsubsubject()
>     context.stoptext()
> 
> The troubles is that buffers are filled with
> the last version of Eleve table.
> I guess this is because the whole file
> is parsed and then filled in buffers.
> My understanding of the cld manuel is that
> context.tobuffer()
> and
> context.direct()
> 
> should be used, but couldn't figure out how.
> Tried several times, also with context.step but
> all failed.
> I think I didn't properly understand the "temp"
> and str of context.tobuffer description in manual.
> 
> What changes should I introduce to my cld files?
see attached ... it's more that you overload Eleve ... an alternative is 
to make a function that gets that table as (then local) argument but I 
don't want to touch your code too much

the function wrapper sort of delays (immediate evaluation is a general 
problem, of function driven typesetting, which is why in the end a pure 
function driven one is not better / easier than tex)


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

[-- Attachment #2: env_corrige.tex --]
[-- Type: text/plain, Size: 638 bytes --]

\startenvironment env_corrige

\startluacode

userdata = userdata or {}

function userdata.Critere (commentaire,note,notemax)
  context.startxcell { "width=11cm", "height=2.75cm" }
     context(userdata.Eleve[commentaire])
  context.stopxcell ()
  context.startxcell { "width=1.5cm", "align=flushright" }
     context("%s/%s",userdata.Eleve[note], notemax)
  context.stopxcell ()
end

\stopluacode

\startbuffer [ExoCorrection]
\startxtable
  \startxrow
     \startxcell
        \ctxlua {userdata.Critere ("structure", "NoteStructure", 2)}
     \stopxcell
  \stopxrow
\stopxtable
\stopbuffer

\stopenvironment

[-- Attachment #3: test.cld --]
[-- Type: text/plain, Size: 708 bytes --]

context.useenvironment { "env_corrige" }

context.starttext()

    context(function()
       context.startsubject { title = "Asterix" }
       userdata.Eleve = {
          structure     = "analyse très fine",
          NoteStructure = 2,
       }
       context.getbuffer { "ExoCorrection" }
       context.stopsubsubject()
    end)

    context(function()
        context.startsubject { title = "Obélix" }
        userdata.Eleve = {
          structure     = "le détail doit être travaillé. Pensez à la finesse de vos menhirs…",
          NoteStructure = 1,
        }
       context.getbuffer { "ExoCorrection" }
       context.stopsubsubject()
    end)

context.stoptext()

[-- Attachment #4: Type: text/plain, Size: 496 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2022-11-27 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-27 12:05 filling buffers in cld documents damien thiriet via ntg-context
2022-11-27 13:04 ` Hans Hagen via ntg-context

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