Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Thomas Schmitz

On Sat, 18 Dec 2010 19:35:53 +0100
 Wolfgang Schuster schuster.wolfg...@googlemail.com 
wrote:


Am 18.12.2010 um 17:52 schrieb Aditya Mahajan:

I am not sure what you want to do, and why you want to 
use buffers. Wont a simple token list work?


I can only agree with this, token lists are the easiest 
solution but the new cld manuals mentions the 
“context.tobuffer” function which allows one to add 
content to a buffer.


Wolfgang


Aditya, Wolfgang, thanks for your replies. I didn't want 
to bore the list with lengthy explanations, but maybe I 
didn't give enough information. So here comes what I hope 
are the relevant bits: I'm typesetting sheets with 
problems and solutions for a class. Those come from an xml 
database. Unfortunately, there is one catch: depending on 
the type of the problem, some problems don't have an 
explicit solution. The problems are typeset as a numbered 
itemization on page 1; on page 2, I want the solutions, 
with matching numbers. And since I'm lazy, I don't want to 
take care of this myself but have context do it for me. So 
let's begin with the output. I want:


PROBLEMS

1. problem without solution

2. problem with solution

3. problem without solution

4. problem with solution

and then, on a new page:

SOLUTIONS

2. solution to 2

4. solution to 4

So: I have been trying to write a macro that will retrieve 
problems from the database (successful, with help by 
Hans), pack them in an itemize list (successful), and 
store the solution somewhere so it can be typeset on the 
next page (unsuccessful as yet). I thought buffers were 
the natural way to go, but I must admit I didn't know 
about tokenlists. Aditya's suggestion unfortunately 
doesn't seem to work with itemizations. Test files:


This works:

\newtoks\mytoks

\def\TestMacro#1#2#3%
  {\color[darkred]{#1} \color[darkblue]{#2}\endgraf
   \appendtoks \color[darkgreen]{#3} \to\mytoks}

\starttext

\TestMacro{A}{B}{C}

\TestMacro{X}{Y}{Z}

\hairline

\the\mytoks

and this doesn't:

\newtoks\mytoks

\def\TestMacro#1#2#3%
  {\item[#1] #2\par
   \appendtoks \in[#1]: {#3} \to\mytoks}

\starttext

\startitemize[n]

\TestMacro{A}{B}{C}

\TestMacro{X}{Y}{Z}
\stopitemize

\hairline

\the\mytoks

I have absolutely no preference for buffers or 
itemizations or whatever, so if there's a better solution, 
I'm all open. But for the time being, I don't get what I 
want. I'll look into context.tobuffer next...


Thanks for any suggestions, and best wishes

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Peter Münster
On Sun, Dec 19 2010, Thomas Schmitz wrote:

 and this doesn't:
 
 \newtoks\mytoks
 
 \def\TestMacro#1#2#3%
   {\item[#1] #2\par
\appendtoks \in[#1]: {#3} \to\mytoks}


 \doglobal \appendtoks \in[#1]: {#3} \to\mytoks}

Cheers, Peter

-- 
Contact information: http://pmrb.free.fr/contact/
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Thomas Schmitz

On Sun, 19 Dec 2010 13:21:26 +0100
 Peter Münster pmli...@free.fr wrote:

On Sun, Dec 19 2010, Thomas Schmitz wrote:


and this doesn't:

\newtoks\mytoks

\def\TestMacro#1#2#3%
  {\item[#1] #2\par
   \appendtoks \in[#1]: {#3} \to\mytoks}



\doglobal \appendtoks \in[#1]: {#3} \to\mytoks}

Cheers, Peter


Hooray, not it works!!! Thanks a lot, everyone, thanks 
Peter - so easy, yet my knowledge of TeX wasn't advanced 
enough to see this. Is it because I'm inside a group and 
TeX empties the tokenlist once I get out of the group?


All best

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Thomas Schmitz




Hooray, not it works!!! 


s/not/now/

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Hans Hagen

On 19-12-2010 12:28, Thomas Schmitz wrote:


So: I have been trying to write a macro that will retrieve problems from
the database (successful, with help by Hans), pack them in an itemize
list (successful), and store the solution somewhere so it can be typeset


Why do you store the solutions if they're already stored in the xml? You 
can just filter them any time you want, can't you?


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | 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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-19 Thread Peter Münster
On Sun, Dec 19 2010, Thomas Schmitz wrote:

 easy, yet my knowledge of TeX wasn't advanced enough to see this. Is
 it because I'm inside a group and TeX empties the tokenlist once I
 get out of the group?

In this case yes, because the list was empty before the group. In general
you get the value, that you had before entering the group.
Peter

-- 
Contact information: http://pmrb.free.fr/contact/
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] mkiv: append to buffer

2010-12-18 Thread Thomas Schmitz

Hi all,

i guess this is easy, but I can't find an example to help
me: I want to write a macro that will collect one of its
arguments in a buffer and then collect the other argument 
in a buffer. Difficult to make a minimal example since I 
don't know how to do this, so here is some pseudo-code; 
this is what I want to achieve:


\definebuffer[MyBuffer]

\def\MyGreatMacro#1#2#3%
{\item[#1] #2 \par
 \appendtobuffer{MyBuffer}{\in[#1] #3}}

\starttext
\startitemize
\MyGreatMacro{1}{aa}{AA}
\MyGreatMacro{2}{bb}{BB}
\stopitemize

\page
\getbuffer[MyBuffer]
\resetbuffer[MyBuffer] % so I can reuse the buffer
\stoptext

What I want to do with this is typeset exercises for my 
students, with an itemization for problems and solutions 
which use the same numbering. In real life, this will 
involve xml, but I will try and figure that out myself 
once I know how to use buffers...


It looks like buffers.collectcontent should be able to do 
this, but I can't figure out how to use it. Any pointers? 
Thanks a lot!


All best

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-18 Thread Aditya Mahajan

On Sat, 18 Dec 2010, Thomas Schmitz wrote:


i guess this is easy, but I can't find an example to help
me: I want to write a macro that will collect one of its
arguments in a buffer and then collect the other argument in a buffer. 
Difficult to make a minimal example since I don't know how to do this, so 
here is some pseudo-code; this is what I want to achieve:


\definebuffer[MyBuffer]

\def\MyGreatMacro#1#2#3%
{\item[#1] #2 \par
\appendtobuffer{MyBuffer}{\in[#1] #3}}

\starttext
\startitemize
\MyGreatMacro{1}{aa}{AA}
\MyGreatMacro{2}{bb}{BB}
\stopitemize

\page
\getbuffer[MyBuffer]
\resetbuffer[MyBuffer] % so I can reuse the buffer
\stoptext

What I want to do with this is typeset exercises for my students, with an 
itemization for problems and solutions which use the same numbering. In real 
life, this will involve xml, but I will try and figure that out myself once I 
know how to use buffers...


It looks like buffers.collectcontent should be able to do this, but I can't 
figure out how to use it. Any pointers? Thanks a lot!


I am not sure what you want to do, and why you want to use buffers. Wont a 
simple token list work?


% Define a token list
\newtoks\mytoks

% Append to a token list
\appendtoks \in[#1] #3  \to\mytoks

% Recall a token list
\the\mytoks

% Reset a token list
\mytoks\emptytoks

For repeating question and answers, there is also blocks.

Aditya

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] mkiv: append to buffer

2010-12-18 Thread Wolfgang Schuster

Am 18.12.2010 um 17:52 schrieb Aditya Mahajan:

 I am not sure what you want to do, and why you want to use buffers. Wont a 
 simple token list work?

I can only agree with this, token lists are the easiest solution but the new 
cld manuals mentions the “context.tobuffer” function which allows one to add 
content to a buffer.

Wolfgang

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___