On 21 Feb 2024, at 08:17, madiazm.eoicc@gmail.com wrote:
Thanks a lot Bruce, that did the trick! definitely I will have to learn a bit lua in summer. I just got an error on \qquad and found searching in internet that it was because escape character conflicts between tex and lua. For the time i removed it and since I will create itemizes I hope I dont get that error if I use \item instead of \qquad. Thanks again, I spent hours of trial and error, error, error... on this matter.
Yes, the \'s need to be escaped in Lua. And it's made me realise that the process of identifying the four lines of the question is separate from the typesetting of the question later. The amended version below uses your \tareaABC macro to format the question so you can more easily change the layout without having to understand ConTeXT Lua Documents in detail. \startluacode userdata = userdata or {} function userdata.formatTestQuestions() local the_buffer = buffers.getlines("TestQuestions") local tracker = 0 local the_question = {} -- 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.tareaAbc( the_question[1], the_question[2], the_question[3], the_question[4]) -- 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()}} \define[4]\tareaAbc{\item #1 \startitemgroup[itemize][a] \item #2 \item #3 \item #4 \stopitemgroup} \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 \stoptext — Bruce Horrocks Hampshire, UK