* How to "\processcommalist"? @ 2005-07-01 16:15 Mojca Miklavec 2005-07-01 17:54 ` Taco Hoekwater 0 siblings, 1 reply; 7+ messages in thread From: Mojca Miklavec @ 2005-07-01 16:15 UTC (permalink / raw) I would like to define a command, which would be called in the following way: \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} so that it would be equivalent to: \WeHaveToDo[monday]{tidy up} \WeHaveToDo[wednesday]{tidy up} \WeHaveToDo[thursday]{tidy up} I played a bit with different variants of \processcommalist, but I can't figure out how to use it in this particular case. Is there also a possibility to define a command like \IHaveToDoTheTasks[1-4,7,9-11]{until tomorrow} which would expand into \IHaveToDoTheTask[1]{until tomorrow} \IHaveToDoTheTask[2]{until tomorrow} \IHaveToDoTheTask[3]{until tomorrow} \IHaveToDoTheTask[4]{until tomorrow} \IHaveToDoTheTask[7]{until tomorrow} \IHaveToDoTheTask[9]{until tomorrow} \IHaveToDoTheTask[10]{until tomorrow} \IHaveToDoTheTask[11]{until tomorrow} ? Thanks for any suggestions, Mojca ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? 2005-07-01 16:15 How to "\processcommalist"? Mojca Miklavec @ 2005-07-01 17:54 ` Taco Hoekwater 2005-07-01 18:45 ` Mojca Miklavec 2005-07-01 20:39 ` How to "\processcommalist"? (corrected solution) Taco Hoekwater 0 siblings, 2 replies; 7+ messages in thread From: Taco Hoekwater @ 2005-07-01 17:54 UTC (permalink / raw) Mojca Miklavec wrote: > I would like to define a command, which would be called in the following way: > \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} > > so that it would be equivalent to: > \WeHaveToDo[monday]{tidy up} > \WeHaveToDo[wednesday]{tidy up} > \WeHaveToDo[thursday]{tidy up} > > I played a bit with different variants of \processcommalist, but I > can't figure out how to use it in this particular case. The trick is to store the tidy up inside the processing command, like so: \def\WeHaveToDo[#1]#2{\message{(#1: #2)}} \def\TheBossWantsTheWorkToBeDoneOn[#1]#2% {\begingroup \def\processitem##1{\WeHaveToDo[##1]{#2}}% \processcommalist[#1]\processitem \endgroup } \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} > Is there also a possibility to define a command like > \IHaveToDoTheTasks[1-4,7,9-11]{until tomorrow} There was not, but knowing Hans I trust that soon there will be :-). For now, here is my solution. % a few auxiliary core macros are needed to uncompress the list. % % \uncompresslist is the twin of the already existing \compresslist % which works in the other direction (syst-new) % \unprotect % I guess this function is already available but couldnt find it... % \def\apptomac#1#2% {\ifx#1\empty\def#1{#2}\else \@EA\def\@EA#1\@EA{#1,#2}\fi} % the next macro does this: % % \itemwithdash<<9-11>>- => \dorecurse {<<1+11-9>>} % {\apptomac\uncompressedlist<<9-1+\recurselevel>>} % % (the 1+ and -1 are needed to solve a counter offset.) \def\itemwithdash#1-#2-% {\@EA\dorecurse\@EA {\the\numexpr 1+#2-#1\relax}% {\@EA\apptomac\@EA\uncompressedlist\@EA {\the\numexpr #1-1+\recurselevel\relax}}}% % top level. The result will be in \uncompressedlist \def\uncompresslist[#1]% {\def\uncompressedlist{}% \def\processitem##1% {\doifinstringelse{-}{##1} {\itemwithdash##1-} {\apptomac\uncompressedlist{##1}}}% \processcommalist[#1]\processitem } \protect % end support macros. With these, you can do: \def\IHaveToDoTheTask[#1]#2{\message{(#1: #2)}} \def\IHaveToDoTheTasks[#1]#2% {\begingroup \def\processitem##1{\IHaveToDoTheTask[##1]{#2}}% \uncompresslist[#1]% <= Yeah! \processcommacommand[\uncompressedlist]\processitem \endgroup } I hope you understand what I've done, but otherwise, feel free to ask, of course. Greetings, Taco ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? 2005-07-01 17:54 ` Taco Hoekwater @ 2005-07-01 18:45 ` Mojca Miklavec 2005-07-04 15:12 ` Hans Hagen 2005-07-01 20:39 ` How to "\processcommalist"? (corrected solution) Taco Hoekwater 1 sibling, 1 reply; 7+ messages in thread From: Mojca Miklavec @ 2005-07-01 18:45 UTC (permalink / raw) Taco Hoekwater wrote: > Mojca Miklavec wrote: > > I would like to define a command, which would be called in the following way: > > \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} > > > > so that it would be equivalent to: > > \WeHaveToDo[monday]{tidy up} > > \WeHaveToDo[wednesday]{tidy up} > > \WeHaveToDo[thursday]{tidy up} > > > > I played a bit with different variants of \processcommalist, but I > > can't figure out how to use it in this particular case. > > The trick is to store the tidy up inside the processing command, > like so: > > \def\WeHaveToDo[#1]#2{\message{(#1: #2)}} > > \def\TheBossWantsTheWorkToBeDoneOn[#1]#2% > {\begingroup > \def\processitem##1{\WeHaveToDo[##1]{#2}}% > \processcommalist[#1]\processitem > \endgroup } > > \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} Great, thanks Taco! It works. It seems easier than I thought, but I could have spent hours looking for the proper solution alone. I hope this will land in the t-rsteps module (\OnSteps[1,2,3,6]{...}). > > Is there also a possibility to define a command like > > \IHaveToDoTheTasks[1-4,7,9-11]{until tomorrow} > > There was not, but knowing Hans I trust that soon there will be :-). :) > For now, here is my solution. > > [...] > > With these, you can do: > > \def\IHaveToDoTheTask[#1]#2{\message{(#1: #2)}} > > \def\IHaveToDoTheTasks[#1]#2% > {\begingroup > \def\processitem##1{\IHaveToDoTheTask[##1]{#2}}% > \uncompresslist[#1]% <= Yeah! > \processcommacommand[\uncompressedlist]\processitem > \endgroup } > > I hope you understand what I've done, but otherwise, feel > free to ask, of course. Well, my stomach needs some time to process the latter example. But if I write \def\IHaveToDoTheTask[#1]#2{\message{(#1: #2)}The task #1 has to be done #2.\crlf} \IHaveToDoTheTasks[1-3]{until tomorrow} nothing happens. Thanks again, Mojca ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? 2005-07-01 18:45 ` Mojca Miklavec @ 2005-07-04 15:12 ` Hans Hagen 2005-07-04 21:08 ` Mojca Miklavec 0 siblings, 1 reply; 7+ messages in thread From: Hans Hagen @ 2005-07-04 15:12 UTC (permalink / raw) Cc: Taco Hoekwater Mojca Miklavec wrote: > Taco Hoekwater wrote: > >>Mojca Miklavec wrote: >> >>>I would like to define a command, which would be called in the following way: >>> \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} >>> >>>so that it would be equivalent to: >>> \WeHaveToDo[monday]{tidy up} >>> \WeHaveToDo[wednesday]{tidy up} >>> \WeHaveToDo[thursday]{tidy up} >>> >>>I played a bit with different variants of \processcommalist, but I >>>can't figure out how to use it in this particular case. >> >>The trick is to store the tidy up inside the processing command, >>like so: >> >> \def\WeHaveToDo[#1]#2{\message{(#1: #2)}} >> >> \def\TheBossWantsTheWorkToBeDoneOn[#1]#2% >> {\begingroup >> \def\processitem##1{\WeHaveToDo[##1]{#2}}% >> \processcommalist[#1]\processitem >> \endgroup } >> >> \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} > > > Great, thanks Taco! It works. It seems easier than I thought, but I > could have spent hours looking for the proper solution alone. Actually, there is an easier way to do this; just swap the arguments to WeHaveToDo: \def\TheBossWantsTheWorkToBeDoneOn[#1]#2% {\processcommalist[#1]{\WeHaveToDo{#2}}} \def\WeHaveToDo#1#2{(#2: #1)} \starttext \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} \stoptext btw, nice thread for a wiki entry > I hope this will land in the t-rsteps module (\OnSteps[1,2,3,6]{...}). > > >>>Is there also a possibility to define a command like >>> \IHaveToDoTheTasks[1-4,7,9-11]{until tomorrow} >> >>There was not, but knowing Hans I trust that soon there will be :-). hm, well, it does rain outside, but ... Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? 2005-07-04 15:12 ` Hans Hagen @ 2005-07-04 21:08 ` Mojca Miklavec 2005-07-04 22:20 ` Hans Hagen 0 siblings, 1 reply; 7+ messages in thread From: Mojca Miklavec @ 2005-07-04 21:08 UTC (permalink / raw) Hans Hagen wrote: > Mojca Miklavec wrote: > > Taco Hoekwater wrote: > >>Mojca Miklavec wrote: > >> > >>>I would like to define a command, which would be called in the following way: > >>> \TheBossWantsTheWorkToBeDoneOn[monday,wednesday,thursday]{tidy up} > >>> > >>>so that it would be equivalent to: > >>> \WeHaveToDo[monday]{tidy up} > >>> \WeHaveToDo[wednesday]{tidy up} > >>> \WeHaveToDo[thursday]{tidy up} > > Actually, there is an easier way to do this; just swap the arguments to WeHaveToDo: > > \def\TheBossWantsTheWorkToBeDoneOn[#1]#2% > {\processcommalist[#1]{\WeHaveToDo{#2}}} > > \def\WeHaveToDo#1#2{(#2: #1)} Thanks for the proposal. I included it into Wiki, but in my case the "\WeHaveToDo" was already defined and I needed it exactly in the form that Taco suggested (to call \OnlyStep[#1]{#2} with \OnSteps[1-3,5]{content} in t-rsteps module). > btw, nice thread for a wiki entry I added it to http://contextgarden.net/Inside_ConTeXt#Processing_lists_of_values. > >>>Is there also a possibility to define a command like > >>> \IHaveToDoTheTasks[1-4,7,9-11]{until tomorrow} > >> > >>There was not, but knowing Hans I trust that soon there will be :-). > > hm, well, it does rain outside, but ... Taco's solution already solved my problem, but I believe it would be nice to add some \processenumeratedlist (well, some better name should be given!) command to ConTeXt one day. That way it would be possible to process some commands like \filterpages[file.pdf][1,3,5] also with \filterpages[file.pdf][1-3,5,7-11] Mojca ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? 2005-07-04 21:08 ` Mojca Miklavec @ 2005-07-04 22:20 ` Hans Hagen 0 siblings, 0 replies; 7+ messages in thread From: Hans Hagen @ 2005-07-04 22:20 UTC (permalink / raw) Mojca Miklavec wrote: > Taco's solution already solved my problem, but I believe it would be > nice to add some \processenumeratedlist (well, some better name should > be given!) command to ConTeXt one day. That way it would be possible > to process some commands like > \filterpages[file.pdf][1,3,5] > also with > \filterpages[file.pdf][1-3,5,7-11] ah, you stopped rading page-imp.tex too early, there's also: \def\dowithrange#1#2% #2 takes number {\beforesplitstring#1\at:\to\fromrange \aftersplitstring #1\at:\to\torange \ifx\torange\empty\let\torange\fromrange\fi \dostepwiserecurse\fromrange\torange1{#2{\recurselevel}}} but we can indeed make a nicer looking one Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to "\processcommalist"? (corrected solution) 2005-07-01 17:54 ` Taco Hoekwater 2005-07-01 18:45 ` Mojca Miklavec @ 2005-07-01 20:39 ` Taco Hoekwater 1 sibling, 0 replies; 7+ messages in thread From: Taco Hoekwater @ 2005-07-01 20:39 UTC (permalink / raw) I have to reply to myself, because Mojca discovered an error in my example code. This: Taco Hoekwater wrote: > \def\IHaveToDoTheTasks[#1]#2% > {\begingroup > \def\processitem##1{\IHaveToDoTheTask[##1]{#2}}% > \uncompresslist[#1]% <= Yeah! > \processcommacommand[\uncompressedlist]\processitem > \endgroup } should have been: \def\IHaveToDoTheTasks[#1]#2% {\begingroup \uncompresslist[#1]% <= Yeah! (do this first!) \def\processitem##1{\IHaveToDoTheTask[##1]{#2}}% \processcommacommand[\uncompressedlist]\processitem \endgroup } Greetings again, Taco ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-07-04 22:20 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-01 16:15 How to "\processcommalist"? Mojca Miklavec 2005-07-01 17:54 ` Taco Hoekwater 2005-07-01 18:45 ` Mojca Miklavec 2005-07-04 15:12 ` Hans Hagen 2005-07-04 21:08 ` Mojca Miklavec 2005-07-04 22:20 ` Hans Hagen 2005-07-01 20:39 ` How to "\processcommalist"? (corrected solution) Taco Hoekwater
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).