Take the 2-minute tour ×

It's late, so I may not be thinking about this clearly enough, but I could have sworn that there exists a macro (possibly not part of a package, but just something that I picked up somewhere along the way) that is able to take some sort of inline list separated by a certain character and replace that character with another string. For example, something like


would produce something like

apples $\cdot$ oranges $\cdot$ peaches $\cdot$ pears

because somewhere I've specified that semicolons should be replaced with $\cdot$.

I have been searching through all the .tex files I've made in recent memory, and I just can't seem to find this, and it's driving me nuts, so any help is greatly appreciated.

share|improve this question
Welcome to TeX.sx! –  Kurt Jan 18 '13 at 12:11
add comment

3 Answers

You can do it in many ways. For instance with xstring:


However this requires you to be very strict in inputting the argument without spaces around the semicolons.

A quite robust solution uses xparse and the LaTeX3 packages:

\NewDocumentCommand{\RealMacro}{ O{~$\cdots$~} m }
  \ryan_change_semicolons:nn { #1 } { #2 }

 \seq_new:N \l_ryan_input_seq

 \cs_new_protected:Npn \ryan_change_semicolons:nn #1 #2
   \seq_set_split:Nnn \l_ryan_input_seq { ; } { #2 }
   \seq_use:Nnnn \l_ryan_input_seq { #1 } { #1 } { #1 }

With this definition you don't have to worry if you input either one of

\RealMacro{apples ; oranges; peaches;pears}

because leading and trailing spaces will be removed. The macro allows also for a call such as

\RealMacro[, ]{apples;oranges;peaches;pears}

and the output would be

apples, oranges, peaches, pears

The default value of the optional argument is <space>$\cdot$<space> as requested.

share|improve this answer
add comment

Just to offer an alternative to looping over the list:

enter image description here


\def\ThisImaginaryMacro#1{\gdef~{\cdot}$\mathcode`\;"8000 \mathrm{#1}$}}


share|improve this answer
add comment

This kind of task is conveniently done by a recursive macro:

%recursive ``low-level'' macro

%user-friendly ``driver'' macro


share|improve this answer
add comment

Your Answer


