home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.text.tex
- Path: sparky!uunet!gumby!yale!mintaka.lcs.mit.edu!news
- From: dmjones@theory.lcs.mit.edu (David M. Jones)
- Subject: Re: Repeating command in LaTeX
- In-Reply-To: bjarni@diku.dk (Henrik V. Drab|l)
- Message-ID: <1993Jan26.180907.16678@mintaka.lcs.mit.edu>
- Keywords: Repeating commands
- Sender: news@mintaka.lcs.mit.edu
- Reply-To: dmjones@theory.lcs.mit.edu (David M. Jones)
- Organization: Laboratory for Computer Science, MIT
- References: <1993Jan20.113102.7116@odin.diku.dk>
- Date: Tue, 26 Jan 1993 18:09:07 GMT
- Lines: 38
-
- In article <1993Jan20.113102.7116@odin.diku.dk>, bjarni@diku (Henrik V. Drab|l) writes:
-
- >I wish to write a LaTeX macro, which expands something like this:
- >\x{abc}
- >gives
- >\y{a}\y{b}\y{c}
- >
- >that is: foreach of the letter in the argument return
- >another macro with the letter as an argument.
-
- Look in latex.tex under the section "PROGRAM CONTROL STRUCTURE
- MACROS". There are several macros for doing this sort of thing,
- depending on exactly what you want the input to look at. For example,
- your macro \x can be implemented as follows using the \@tfor command:
-
- \makeatletter
-
- \def\x#1{\@tfor \@tempa := #1 \do {\y{\@tempa}}}
-
- \makeatother
-
- This will execute the command \y for each token in the argument of \x
- before expansion.
-
- If you change \@tfor to \@for above, then you get a macro with
- slightly different semantics: \x would take a comma-separated list of
- items after expansion and execute \y for each element in the list.
- I.e.,
-
- \x{foo,bar,a}
-
- would expand to
-
- \y{foo}\y{bar}\y{a}
-
- --
- David M. Jones "Trifles! Trifles light as air!"
- dmjones@theory.lcs.mit.edu -- the Hystricide
-