home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / text / tex / 15458 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.7 KB  |  53 lines

  1. Newsgroups: comp.text.tex
  2. Path: sparky!uunet!gumby!yale!mintaka.lcs.mit.edu!news
  3. From: dmjones@theory.lcs.mit.edu (David M. Jones)
  4. Subject: Re: Repeating command in LaTeX
  5. In-Reply-To: bjarni@diku.dk (Henrik V. Drab|l)
  6. Message-ID: <1993Jan26.180907.16678@mintaka.lcs.mit.edu>
  7. Keywords: Repeating commands
  8. Sender: news@mintaka.lcs.mit.edu
  9. Reply-To: dmjones@theory.lcs.mit.edu (David M. Jones)
  10. Organization: Laboratory for Computer Science, MIT
  11. References: <1993Jan20.113102.7116@odin.diku.dk>
  12. Date: Tue, 26 Jan 1993 18:09:07 GMT
  13. Lines: 38
  14.  
  15. In article <1993Jan20.113102.7116@odin.diku.dk>, bjarni@diku (Henrik V. Drab|l) writes:
  16.  
  17. >I wish to write a LaTeX macro, which expands something like this:
  18. >\x{abc}
  19. >gives
  20. >\y{a}\y{b}\y{c}
  21. >
  22. >that is: foreach of the letter in the argument return  
  23. >another macro with the letter as an argument.
  24.  
  25. Look in latex.tex under the section "PROGRAM CONTROL STRUCTURE
  26. MACROS".  There are several macros for doing this sort of thing,
  27. depending on exactly what you want the input to look at.  For example,
  28. your macro \x can be implemented as follows using the \@tfor command:
  29.  
  30.         \makeatletter
  31.  
  32.         \def\x#1{\@tfor \@tempa := #1 \do {\y{\@tempa}}}
  33.  
  34.         \makeatother
  35.  
  36. This will execute the command \y for each token in the argument of \x
  37. before expansion.
  38.  
  39. If you change \@tfor to \@for above, then you get a macro with
  40. slightly different semantics: \x would take a comma-separated list of
  41. items after expansion and execute \y for each element in the list.
  42. I.e.,
  43.  
  44.         \x{foo,bar,a}
  45.  
  46. would expand to
  47.  
  48.         \y{foo}\y{bar}\y{a}
  49.  
  50. --
  51. David M. Jones                              "Trifles! Trifles light as air!"
  52. dmjones@theory.lcs.mit.edu                              -- the Hystricide
  53.