* mkiv: append to buffer @ 2010-12-18 15:51 Thomas Schmitz 2010-12-18 16:52 ` Aditya Mahajan 0 siblings, 1 reply; 9+ messages in thread From: Thomas Schmitz @ 2010-12-18 15:51 UTC (permalink / raw) To: mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-18 15:51 mkiv: append to buffer Thomas Schmitz @ 2010-12-18 16:52 ` Aditya Mahajan 2010-12-18 18:35 ` Wolfgang Schuster 0 siblings, 1 reply; 9+ messages in thread From: Aditya Mahajan @ 2010-12-18 16:52 UTC (permalink / raw) To: mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-18 16:52 ` Aditya Mahajan @ 2010-12-18 18:35 ` Wolfgang Schuster 2010-12-19 11:28 ` Thomas Schmitz 0 siblings, 1 reply; 9+ messages in thread From: Wolfgang Schuster @ 2010-12-18 18:35 UTC (permalink / raw) To: mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-18 18:35 ` Wolfgang Schuster @ 2010-12-19 11:28 ` Thomas Schmitz 2010-12-19 12:21 ` Peter Münster 2010-12-19 21:30 ` Hans Hagen 0 siblings, 2 replies; 9+ messages in thread From: Thomas Schmitz @ 2010-12-19 11:28 UTC (permalink / raw) To: mailing list for ConTeXt users On Sat, 18 Dec 2010 19:35:53 +0100 Wolfgang Schuster <schuster.wolfgang@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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-19 11:28 ` Thomas Schmitz @ 2010-12-19 12:21 ` Peter Münster 2010-12-19 12:47 ` Thomas Schmitz 2010-12-19 21:30 ` Hans Hagen 1 sibling, 1 reply; 9+ messages in thread From: Peter Münster @ 2010-12-19 12:21 UTC (permalink / raw) To: mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-19 12:21 ` Peter Münster @ 2010-12-19 12:47 ` Thomas Schmitz 2010-12-19 14:19 ` Thomas Schmitz 2010-12-20 7:11 ` Peter Münster 0 siblings, 2 replies; 9+ messages in thread From: Thomas Schmitz @ 2010-12-19 12:47 UTC (permalink / raw) To: mailing list for ConTeXt users On Sun, 19 Dec 2010 13:21:26 +0100 Peter Münster <pmlists@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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-19 12:47 ` Thomas Schmitz @ 2010-12-19 14:19 ` Thomas Schmitz 2010-12-20 7:11 ` Peter Münster 1 sibling, 0 replies; 9+ messages in thread From: Thomas Schmitz @ 2010-12-19 14:19 UTC (permalink / raw) To: mailing list for ConTeXt users > > 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-19 12:47 ` Thomas Schmitz 2010-12-19 14:19 ` Thomas Schmitz @ 2010-12-20 7:11 ` Peter Münster 1 sibling, 0 replies; 9+ messages in thread From: Peter Münster @ 2010-12-20 7:11 UTC (permalink / raw) To: mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mkiv: append to buffer 2010-12-19 11:28 ` Thomas Schmitz 2010-12-19 12:21 ` Peter Münster @ 2010-12-19 21:30 ` Hans Hagen 1 sibling, 0 replies; 9+ messages in thread From: Hans Hagen @ 2010-12-19 21:30 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Thomas Schmitz 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-12-20 7:11 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-12-18 15:51 mkiv: append to buffer Thomas Schmitz 2010-12-18 16:52 ` Aditya Mahajan 2010-12-18 18:35 ` Wolfgang Schuster 2010-12-19 11:28 ` Thomas Schmitz 2010-12-19 12:21 ` Peter Münster 2010-12-19 12:47 ` Thomas Schmitz 2010-12-19 14:19 ` Thomas Schmitz 2010-12-20 7:11 ` Peter Münster 2010-12-19 21:30 ` Hans Hagen
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).