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 [EMAIL PROTECTED]@[EMAIL PROTECTED],#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-%
    [EMAIL PROTECTED]@EA
      {\the\numexpr 1+#2-#1\relax}%
      [EMAIL PROTECTED]@[EMAIL PROTECTED]
        {\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

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to