![](https://secure.gravatar.com/avatar/e0f8d84b235b67d60a3c7fd0e326db8d.jpg?s=120&d=mm&r=g)
On 20 Feb 2024, at 12:59, madiazm.eoicc@gmail.com wrote:
no, I just want to split at the end of each sentence to get the four arguments: now I pass this four lines to my macro \tareaAbc (with the dirty trick of ñ)
In den Büchereien gibt es auch …ñ … Kuchen.ñ … Theater.ñ … Workshops.ñ
and I wish your context.foo(lines[i]) iteration would become a single context.tareaAbc(the four arguments somehow separated so that I can manage each line with the corresponding context formatting)
As you see my definition is: \def\tareaAbc #1ñ#2ñ#3ñ#4ñ{...context formating for each #)}; Its the clue to pass each sentence as an independent argument that I don't get to work. thanks again
A variation on Hans original suggestion is to use a buffer instead of a separate text file, combined with Lua. \startluacode userdata = userdata or {} function userdata.formatTestQuestions() local the_buffer = buffers.getlines("TestQuestions") local tracker = 0 local the_question = {} local letters = {"-", "a", "b", "c"} -- Go through the buffer of questions one line at a time for i = 1,#the_buffer do -- Skip blank lines but 'collect' non-blank lines until we have four -- (which is assumed to be a whole question) if string.strip(the_buffer[i]) == "" then tracker = 0 the_question = {} else tracker = tracker + 1 the_question[tracker] = the_buffer[i] end -- If tracker has got to 4 then we've read four lines if tracker == 4 then context.startlines() context("{\\bf Beispiel:} %s", the_question[1]) context(true) for answer = 2,4 do context("\\qquad %s) %s", letters[answer], the_question[answer]) context(true) end context.stoplines() -- Reset for the next question (in case no blank line) tracker = 0 the_question = {} end end end \stopluacode \def\startTestQuestions {\dostartbuffer[TestQuestions][startTestQuestions][stopTestQuestions]} \def\stopTestQuestions {\ctxlua{userdata.formatTestQuestions()}} \starttext Here are some questions: \startTestQuestions In den Büchereien gibt es auch … … Kuchen. … Theater. … Workshops. In den Büchereien gibt es auch … … Kuchen. … Theater. … Workshops. In den Büchereien gibt es auch … … Kuchen. … Theater. … Workshops. \stopTestQuestions How do you think you did on that test? Here's another one. \startTestQuestions In den Büchereien gibt es auch … … Kuchen. … Theater. … Workshops. \stopTestQuestions \stoptext — Bruce Horrocks Hampshire, UK