[NTG-context] Re: using an end of line as parameter

2024-02-22 Thread madiazm . eoicc
Thanks again Bruce. I will play with the code a bit. 

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-21 Thread Bruce Horrocks


> On 21 Feb 2024, at 08:17, madiazm.eo...@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


tt2.tex
Description: Binary data
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-21 Thread madiazm . eoicc
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.
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-20 Thread Bruce Horrocks


> On 20 Feb 2024, at 12:59, madiazm.eo...@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


tt.tex
Description: Binary data

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-20 Thread madiazm . eoicc
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
Miguel
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-20 Thread Hans Hagen

On 2/20/2024 12:26 PM, madiazm.eo...@gmail.com wrote:

Thanks Hans,
I supposed that lua would be more suitable, but unfortunately I still did not 
learn it (I hope in summer I have time to read the manual)

The problem arises from the fact that for each line i will perform a different 
action and for \def\foo I need four arguments so that I can correctly format 
the lines. How can i get the result of string.splitlines (s) separated into 
four arguments to pass to the macro? then \foo would be 
\def\foo#1SEPARATOR#2SEPARATOR#3SEPARATOR#4

I now use:


\starttext
%now I use the dirty trick of writing an ñ at the end of line so that the macro 
detects each argument; but for each question I have to manually add it, which 
is tedious; therefore I look for a solution to detect lines automatically

%the definition
\def\tareaAbc #1ñ#2ñ#3ñ#4ñ{\item #1
 \startitemgroup[lista1a]
 \item #2
 \item #3
 \item #4
 \stopitemgroup}

%in the document
/startitemgropu[lista1a]   %I manually open the first level of the list 
so the first argument -the question- gets numbered

\tareaAbc In den Büchereien gibt es auch …ñ   %the question; an item of 
first level
… Kuchen.ñ   %option a gets a new list of second level opened and argument 
2 is the first item
… Theater.ñ   %option b another item
… Workshops.ñ  %option c last item and closes the second level list

%some more macros with more questions and options

/stopitemgroup %I manually close the first level list
You have to provide more details about these lines. For instance, do you 
want to split on spaces?


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
-

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-20 Thread madiazm . eoicc
Thanks Hans,
I supposed that lua would be more suitable, but unfortunately I still did not 
learn it (I hope in summer I have time to read the manual)

The problem arises from the fact that for each line i will perform a different 
action and for \def\foo I need four arguments so that I can correctly format 
the lines. How can i get the result of string.splitlines (s) separated into 
four arguments to pass to the macro? then \foo would be 
\def\foo#1SEPARATOR#2SEPARATOR#3SEPARATOR#4

I now use:


\starttext
%now I use the dirty trick of writing an ñ at the end of line so that the macro 
detects each argument; but for each question I have to manually add it, which 
is tedious; therefore I look for a solution to detect lines automatically

%the definition
\def\tareaAbc #1ñ#2ñ#3ñ#4ñ{\item #1
\startitemgroup[lista1a]
\item #2
\item #3
\item #4
\stopitemgroup}

%in the document
/startitemgropu[lista1a]   %I manually open the first level of the list 
so the first argument -the question- gets numbered

\tareaAbc In den Büchereien gibt es auch …ñ   %the question; an item of 
first level
… Kuchen.ñ   %option a gets a new list of second level opened and argument 
2 is the first item
… Theater.ñ   %option b another item
… Workshops.ñ  %option c last item and closes the second level list

%some more macros with more questions and options

/stopitemgroup %I manually close the first level list

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: using an end of line as parameter

2024-02-19 Thread Hans Hagen

On 2/19/2024 1:49 PM, Miguel Diaz wrote:

Dear list,
I want to format some language tests that different people are 
preparing. Each one uses different software and there are always 
problems in format that i want to solve.


for a a/b/c questions I receive text that I will format to a list 
(comments are mine)


In den Büchereien gibt es auch … %the question
… Kuchen. %option a
… Theater. %option b
… Workshops. %option c

I need to detect \par or whatever sign marks the newline character as an 
argument delimiter so that I dont have to paste hundreds of times braces 
for each argument.

For the example, I use this macro definition (which does no work!)

\long\def\prueba 
#1\par#2\par#3\par#4ñ{\framed[frame=off,width=0.8\textwidth,corner=round,offset=1em,align=flushleft]%

{{\bf Beispiel}: #1\\
\qquad  a) #2\\
\qquad  b) {\bf #3}\\
\qquad  c) #4
}

I get: tex error on line 493 in file ./prueba.tex: The file ended when 
scanning an argument.


the macro seems to  read to the end of file not detecting \par; I know 
its the \par that causes the problem; I used ^^M also which I read is a 
sinonym for return but it also does not work.


Help would be appreciated (my computer keyboard would appreciate it too...)

better start thinking something:

\starttext

\def\foo#1{<<<#1\par}

\startluacode
local s = [[
line 1
line 2
line 3
line 4
]]

-- local s - io.loaddata("yourfile.txt")

local lines = string.splitlines(s)

for i=1,#lines do
if lines[i] ~= "" then
context.foo(lines[i])
end
end

\stopluacode

\stoptext


-
  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 / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___