From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: damien thiriet via ntg-context <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: Re: filling buffers in cld documents
Date: Sun, 27 Nov 2022 14:04:39 +0100 [thread overview]
Message-ID: <3d1614a8-3375-9faa-8436-533eae718db5@freedom.nl> (raw)
In-Reply-To: <275c56b4bee1ed8bf6debfdbbaaa07a4@thiriet.web4me.fr>
[-- 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
___________________________________________________________________________________
prev parent reply other threads:[~2022-11-27 13:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-27 12:05 damien thiriet via ntg-context
2022-11-27 13:04 ` Hans Hagen via ntg-context [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d1614a8-3375-9faa-8436-533eae718db5@freedom.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@freedom.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).